xref: /aoo42x/main/sc/source/ui/miscdlgs/crnrdlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 // System - Includes ---------------------------------------------------------
32 
33 
34 
35 // INCLUDE -------------------------------------------------------------------
36 
37 #include "reffact.hxx"
38 #include "document.hxx"
39 #include "scresid.hxx"
40 #include "globstr.hrc"
41 #include "crnrdlg.hrc"
42 #include "docsh.hxx"
43 
44 #define _CRNRDLG_CXX
45 #include "crnrdlg.hxx"
46 #undef _CRNRDLG_CXX
47 #include <vcl/msgbox.hxx>
48 
49 
50 //============================================================================
51 
52 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
53 #define QUERYBOX(m) QueryBox(this,WinBits(WB_YES_NO|WB_DEF_YES),m).Execute()
54 
55 const sal_uLong nEntryDataCol = 0;
56 const sal_uLong nEntryDataRow = 1;
57 const sal_uLong nEntryDataDelim = 2;
58 
59 
60 //============================================================================
61 //	class ScColRowNameRangesDlg
62 
63 
64 /*************************************************************************
65 #*	Member:		ScColRowNameRangesDlg						Datum:04.09.97
66 #*------------------------------------------------------------------------
67 #*
68 #*  Klasse:		ScColRowNameRangesDlg
69 #*
70 #*  Funktion:	Konstruktor der Klasse ScColRowNameRangesDlg.
71 #*				Initialisieren der Klassen- Mitglieder,
72 #*				Uebernahme der Range- Angaben und Aufruf
73 #*				der eigentlichen Initialisierungsroutine
74 #*
75 #*  Input:		Sfx- Verknuepfungen
76 #*				Parent- Window
77 #*				SCViewData
78 #*
79 #*	Output:		---
80 #*
81 #************************************************************************/
82 
83 ScColRowNameRangesDlg::ScColRowNameRangesDlg( SfxBindings* pB,
84 								SfxChildWindow* pCW,
85 								Window* pParent,
86 								ScViewData*	ptrViewData )
87 
88 	:	ScAnyRefDlg	( pB, pCW, pParent, RID_SCDLG_COLROWNAMERANGES ),
89 		//
90         aFlAssign       ( this, ScResId( FL_ASSIGN ) ),
91 		aLbRange		( this, ScResId( LB_RANGE ) ),
92 
93         aEdAssign       ( this, this, ScResId( ED_AREA ) ),
94 		aRbAssign		( this, ScResId( RB_AREA ), &aEdAssign, this ),
95 		aBtnColHead		( this, ScResId( BTN_COLHEAD ) ),
96 		aBtnRowHead		( this, ScResId( BTN_ROWHEAD ) ),
97 		aFtAssign2		( this, ScResId( FT_DATA_LABEL ) ),
98         aEdAssign2      ( this, this, ScResId( ED_DATA ) ),
99 		aRbAssign2		( this, ScResId( RB_DATA ), &aEdAssign2, this ),
100 
101 		aBtnOk			( this, ScResId( BTN_OK ) ),
102 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
103 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
104 		aBtnAdd			( this, ScResId( BTN_ADD ) ),
105 		aBtnRemove		( this, ScResId( BTN_REMOVE ) ),
106 
107 		pViewData		( ptrViewData ),
108 		pDoc			( ptrViewData->GetDocument() ),
109 
110 		pEdActive		( NULL ),
111 		bDlgLostFocus	( sal_False )
112 {
113 	xColNameRanges = pDoc->GetColNameRanges()->Clone();
114 	xRowNameRanges = pDoc->GetRowNameRanges()->Clone();
115 	Init();
116 	FreeResource();
117 
118 	aRbAssign.SetAccessibleRelationMemberOf(&aEdAssign);
119 	aRbAssign2.SetAccessibleRelationMemberOf(&aEdAssign);
120 }
121 
122 
123 /*************************************************************************
124 #*	Member:		~ScColRowNameRangesDlg						Datum:04.09.97
125 #*------------------------------------------------------------------------
126 #*
127 #*  Klasse:		ScColRowNameRangesDlg
128 #*
129 #*  Funktion:	Destruktor der Klasse
130 #*
131 #*  Input:		---
132 #*
133 #*	Output:		---
134 #*
135 #************************************************************************/
136 
137 __EXPORT ScColRowNameRangesDlg::~ScColRowNameRangesDlg()
138 {
139 }
140 
141 
142 /*************************************************************************
143 #*	Member:		Init										Datum:04.09.97
144 #*------------------------------------------------------------------------
145 #*
146 #*  Klasse:		ScColRowNameRangesDlg
147 #*
148 #*  Funktion:	Initialisierungs- Routine:
149 #*				Umlenken der Event- Handler und einstellen der
150 #*				Startparameter.
151 #*
152 #*  Input:		---
153 #*
154 #*	Output:		---
155 #*
156 #************************************************************************/
157 
158 void ScColRowNameRangesDlg::Init()
159 {
160 	SCCOL	nStartCol 	= 0;
161 	SCROW	nStartRow 	= 0;
162 	SCTAB	nStartTab 	= 0;
163 	SCCOL	nEndCol 	= 0;
164 	SCROW	nEndRow		= 0;
165 	SCTAB	nEndTab 	= 0;
166 
167 	aBtnOk.SetClickHdl		( LINK( this, ScColRowNameRangesDlg, OkBtnHdl ) );
168 	aBtnCancel.SetClickHdl	( LINK( this, ScColRowNameRangesDlg, CancelBtnHdl ) );
169 	aBtnAdd.SetClickHdl		( LINK( this, ScColRowNameRangesDlg, AddBtnHdl ) );
170 	aBtnRemove.SetClickHdl	( LINK( this, ScColRowNameRangesDlg, RemoveBtnHdl ) );
171 	aLbRange.SetSelectHdl	( LINK( this, ScColRowNameRangesDlg, Range1SelectHdl ) );
172 	aEdAssign.SetModifyHdl	( LINK( this, ScColRowNameRangesDlg, Range1DataModifyHdl ) );
173 	aBtnColHead.SetClickHdl	( LINK( this, ScColRowNameRangesDlg, ColClickHdl ) );
174 	aBtnRowHead.SetClickHdl	( LINK( this, ScColRowNameRangesDlg, RowClickHdl ) );
175 	aEdAssign2.SetModifyHdl	( LINK( this, ScColRowNameRangesDlg, Range2DataModifyHdl ) );
176 
177     Link aLink = LINK( this, ScColRowNameRangesDlg, GetFocusHdl );
178     aEdAssign.SetGetFocusHdl( aLink );
179     aRbAssign.SetGetFocusHdl( aLink );
180     aEdAssign2.SetGetFocusHdl( aLink );
181     aRbAssign2.SetGetFocusHdl( aLink );
182 
183     aLink = LINK( this, ScColRowNameRangesDlg, LoseFocusHdl );
184     aEdAssign.SetLoseFocusHdl( aLink );
185     aRbAssign.SetLoseFocusHdl( aLink );
186     aEdAssign2.SetLoseFocusHdl( aLink );
187     aRbAssign2.SetLoseFocusHdl( aLink );
188 
189 	pEdActive = &aEdAssign;
190 
191 	UpdateNames();
192 
193 	if ( pViewData && pDoc )
194 	{
195 		pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
196 								  nEndCol,	 nEndRow,  nEndTab );
197 		SetColRowData( ScRange( ScAddress( nStartCol, nStartRow, nStartTab ),
198 							  ScAddress( nEndCol,   nEndRow,   nEndTab ) ) );
199 	}
200 	else
201 	{
202 		aBtnColHead.Check( sal_True );
203 		aBtnRowHead.Check( sal_False );
204 		aEdAssign.SetText( EMPTY_STRING );
205 		aEdAssign2.SetText( EMPTY_STRING );
206 	}
207 
208     aLbRange.SetBorderStyle( WINDOW_BORDER_MONO );
209     aBtnColHead.Enable();
210 	aBtnRowHead.Enable();
211 	aEdAssign.Enable();
212 	aEdAssign.GrabFocus();
213     aRbAssign.Enable();
214 	//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
215 	//SFX_APPWINDOW->Enable();		// Ref-Feld hat Focus
216 
217 	Range1SelectHdl( 0 );
218 }
219 
220 
221 /*************************************************************************
222 #*	Member:		SetColRowData								Datum:04.09.97
223 #*------------------------------------------------------------------------
224 #*
225 #*  Klasse:		ScColRowNameRangesDlg
226 #*
227 #*  Funktion:	zugehoerigen Datenbereich eines Beschriftungsbereiches
228 #*				auf default Werte setzen und beide Referenz-Edit-Felder
229 #*				fuellen.
230 #*
231 #*  Input:		Einstellbereich fuer Labels
232 #*
233 #*	Output:		---
234 #*
235 #************************************************************************/
236 
237 void ScColRowNameRangesDlg::SetColRowData( const ScRange& rLabelRange,sal_Bool bRef)
238 {
239 	theCurData = theCurArea = rLabelRange;
240 	sal_Bool bValid = sal_True;
241 	SCCOL nCol1 = theCurArea.aStart.Col();
242 	SCCOL nCol2 = theCurArea.aEnd.Col();
243 	SCROW nRow1 = theCurArea.aStart.Row();
244 	SCROW nRow2 = theCurArea.aEnd.Row();
245 	if ( (static_cast<SCCOLROW>(nCol2 - nCol1) >= nRow2 - nRow1) || (nCol1 == 0 && nCol2 == MAXCOL) )
246 	{	// Spaltenkoepfe und Grenzfall gesamte Tabelle
247 		aBtnColHead.Check( sal_True );
248 		aBtnRowHead.Check( sal_False );
249 		if ( nRow2 == MAXROW  )
250 		{
251 			if ( nRow1 == 0 )
252 				bValid = sal_False;		// Grenzfall gesamte Tabelle
253 			else
254 			{	// Head unten, Data oben
255 				theCurData.aStart.SetRow( 0 );
256 				theCurData.aEnd.SetRow( nRow1 - 1 );
257 			}
258 		}
259 		else
260 		{	// Head oben, Data unten
261 			theCurData.aStart.SetRow( nRow2 + 1 );
262 			theCurData.aEnd.SetRow( MAXROW );
263 		}
264 	}
265 	else
266 	{	// Zeilenkoepfe
267 		aBtnRowHead.Check( sal_True );
268 		aBtnColHead.Check( sal_False );
269 		if ( nCol2 == MAXCOL )
270 		{	// Head rechts, Data links
271 			theCurData.aStart.SetCol( 0 );
272 			theCurData.aEnd.SetCol( nCol2 - 1 );
273 		}
274 		else
275 		{	// Head links, Data rechts
276 			theCurData.aStart.SetCol( nCol2 + 1 );
277 			theCurData.aEnd.SetCol( MAXCOL );
278 		}
279 	}
280 	if ( bValid )
281 	{
282         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
283 		String aStr;
284 		theCurArea.Format( aStr, SCR_ABS_3D, pDoc, eConv );
285 
286 		if(bRef)
287 			aEdAssign.SetRefString( aStr );
288 		else
289 			aEdAssign.SetText( aStr );
290 
291 		aEdAssign.SetSelection( Selection( SELECTION_MAX, SELECTION_MAX ) );
292 		theCurData.Format( aStr, SCR_ABS_3D, pDoc, eConv );
293 
294 		if(bRef)
295 			aEdAssign2.SetRefString( aStr );
296 		else
297 			aEdAssign2.SetText( aStr );
298 	}
299 	else
300 	{
301 		theCurData = theCurArea = ScRange();
302 
303 		if(bRef)
304 		{
305 			aEdAssign.SetRefString( EMPTY_STRING );
306 			aEdAssign2.SetRefString( EMPTY_STRING );
307 		}
308 		else
309 		{
310 			aEdAssign.SetText( EMPTY_STRING );
311 			aEdAssign2.SetText( EMPTY_STRING );
312 		}
313 
314 		aBtnColHead.Disable();
315 		aBtnRowHead.Disable();
316 		aEdAssign2.Disable();
317         aRbAssign2.Disable();
318 	}
319 }
320 
321 
322 /*************************************************************************
323 #*	Member:		AdjustColRowData							Datum:04.09.97
324 #*------------------------------------------------------------------------
325 #*
326 #*  Klasse:		ScColRowNameRangesDlg
327 #*
328 #*  Funktion:	zugehoerigen Datenbereich eines Beschriftungsbereiches
329 #*				anpassen und Data-Referenz-Edit-Feld fuellen.
330 #*
331 #*  Input:		Bereich fuer Labels
332 #*
333 #*	Output:		---
334 #*
335 #************************************************************************/
336 
337 void ScColRowNameRangesDlg::AdjustColRowData( const ScRange& rDataRange,sal_Bool bRef)
338 {
339 	theCurData = rDataRange;
340 	if ( aBtnColHead.IsChecked() )
341 	{	// Datenbereich gleiche Spalten wie Koepfe
342 		theCurData.aStart.SetCol( theCurArea.aStart.Col() );
343 		theCurData.aEnd.SetCol( theCurArea.aEnd.Col() );
344 		if ( theCurData.Intersects( theCurArea ) )
345 		{
346 			SCROW nRow1 = theCurArea.aStart.Row();
347 			SCROW nRow2 = theCurArea.aEnd.Row();
348 			if ( nRow1 > 0
349 			  && (theCurData.aEnd.Row() < nRow2 || nRow2 == MAXROW) )
350 			{	// Data oben
351 				theCurData.aEnd.SetRow( nRow1 - 1 );
352 				if ( theCurData.aStart.Row() > theCurData.aEnd.Row() )
353 					theCurData.aStart.SetRow( theCurData.aEnd.Row() );
354 			}
355 			else
356 			{	// Data unten
357 				theCurData.aStart.SetRow( nRow2 + 1 );
358 				if ( theCurData.aStart.Row() > theCurData.aEnd.Row() )
359 					theCurData.aEnd.SetRow( theCurData.aStart.Row() );
360 			}
361 		}
362 	}
363 	else
364 	{	// Datenbereich gleiche Zeilen wie Koepfe
365 		theCurData.aStart.SetRow( theCurArea.aStart.Row() );
366 		theCurData.aEnd.SetRow( theCurArea.aEnd.Row() );
367 		if ( theCurData.Intersects( theCurArea ) )
368 		{
369 			SCCOL nCol1 = theCurArea.aStart.Col();
370 			SCCOL nCol2 = theCurArea.aEnd.Col();
371 			if ( nCol1 > 0
372 			  && (theCurData.aEnd.Col() < nCol2 || nCol2 == MAXCOL) )
373 			{	// Data links
374 				theCurData.aEnd.SetCol( nCol1 - 1 );
375 				if ( theCurData.aStart.Col() > theCurData.aEnd.Col() )
376 					theCurData.aStart.SetCol( theCurData.aEnd.Col() );
377 			}
378 			else
379 			{	// Data rechts
380 				theCurData.aStart.SetCol( nCol2 + 1 );
381 				if ( theCurData.aStart.Col() > theCurData.aEnd.Col() )
382 					theCurData.aEnd.SetCol( theCurData.aStart.Col() );
383 			}
384 		}
385 	}
386 	String aStr;
387 	theCurData.Format( aStr, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
388 
389 	if(bRef)
390 		aEdAssign2.SetRefString( aStr );
391 	else
392 		aEdAssign2.SetText( aStr );
393 
394 	aEdAssign2.SetSelection( Selection( SELECTION_MAX, SELECTION_MAX ) );
395 }
396 
397 
398 /*************************************************************************
399 #*	Member:		SetReference								Datum:04.09.97
400 #*------------------------------------------------------------------------
401 #*
402 #*  Klasse:		ScColRowNameRangesDlg
403 #*
404 #*  Funktion:	Uebergabe eines mit der Maus selektierten Tabellen-
405 #*				bereiches, der dann als neue Selektion im Referenz-
406 #*				Fenster angezeigt wird.
407 #*
408 #*  Input:		Bereich fuer Labels
409 #*				Dokumentklasse
410 #*
411 #*	Output:		---
412 #*
413 #************************************************************************/
414 
415 void ScColRowNameRangesDlg::SetReference( const ScRange& rRef, ScDocument* /* pDoc */ )
416 {
417 	if ( pEdActive )
418 	{
419 		if ( rRef.aStart != rRef.aEnd )
420 			RefInputStart( pEdActive );
421 
422 		String aRefStr;
423 		if ( pEdActive == &aEdAssign )
424 			SetColRowData( rRef, sal_True );
425 		else
426 			AdjustColRowData( rRef, sal_True );
427 		aBtnColHead.Enable();
428 		aBtnRowHead.Enable();
429 		aBtnAdd.Enable();
430 		aBtnRemove.Disable();
431 	}
432 }
433 
434 
435 /*************************************************************************
436 #*	Member:		Close										Datum:04.09.97
437 #*------------------------------------------------------------------------
438 #*
439 #*  Klasse:		ScColRowNameRangesDlg
440 #*
441 #*  Funktion:	Schliessen des Fensters
442 #*
443 #*  Input:		---
444 #*
445 #*	Output:		---
446 #*
447 #************************************************************************/
448 
449 sal_Bool __EXPORT ScColRowNameRangesDlg::Close()
450 {
451 	return DoClose( ScColRowNameRangesDlgWrapper::GetChildWindowId() );
452 }
453 
454 
455 /*************************************************************************
456 #*	Member:		SetActive									Datum:04.09.97
457 #*------------------------------------------------------------------------
458 #*
459 #*  Klasse:		ScColRowNameRangesDlg
460 #*
461 #*  Funktion:	Aktivieren des Fensters
462 #*
463 #*  Input:		---
464 #*
465 #*	Output:		---
466 #*
467 #************************************************************************/
468 
469 void ScColRowNameRangesDlg::SetActive()
470 {
471     if ( bDlgLostFocus )
472     {
473         bDlgLostFocus = sal_False;
474         if( pEdActive )
475             pEdActive->GrabFocus();
476     }
477     else
478         GrabFocus();
479 
480     if( pEdActive == &aEdAssign )
481         Range1DataModifyHdl( 0 );
482     else if( pEdActive == &aEdAssign2 )
483         Range2DataModifyHdl( 0 );
484 
485     RefInputDone();
486 }
487 
488 
489 /*************************************************************************
490 #*	Member:		UpdateNames									Datum:04.09.97
491 #*------------------------------------------------------------------------
492 #*
493 #*  Klasse:		ScColRowNameRangesDlg
494 #*
495 #*  Funktion:	Aktualisieren der Namen
496 #*
497 #*  Input:		---
498 #*
499 #*	Output:		---
500 #*
501 #************************************************************************/
502 
503 void ScColRowNameRangesDlg::UpdateNames()
504 {
505 	aLbRange.SetUpdateMode( sal_False );
506 	//-----------------------------------------------------------
507 	aLbRange.Clear();
508     aRangeMap.clear();
509 	aEdAssign.SetText( EMPTY_STRING );
510 
511 	sal_uLong nCount, j;
512 	sal_uInt16 nPos; //@008 Hilfsvariable q eingefuegt
513 
514 	SCCOL nCol1;	//@008 04.09.97
515 	SCROW nRow1;	//Erweiterung fuer Bereichsnamen
516 	SCTAB nTab1;
517 	SCCOL nCol2;
518 	SCROW nRow2;
519 	SCTAB nTab2;
520 	String rString;
521 	String strShow;
522     const ScAddress::Details aDetails(pDoc->GetAddressConvention());
523 
524 	String aString;
525 	String strDelim = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( " --- " ));
526 	aString = strDelim;
527 	aString += ScGlobal::GetRscString( STR_COLUMN );
528 	aString += strDelim;
529 	nPos = aLbRange.InsertEntry( aString );
530 	aLbRange.SetEntryData( nPos, (void*)nEntryDataDelim );
531 	if ( (nCount = xColNameRanges->Count()) > 0 )
532 	{
533 		ScRangePair** ppSortArray = xColNameRanges->CreateNameSortedArray(
534 			nCount, pDoc );
535 		for ( j=0; j < nCount; j++ )
536 		{
537             const ScRange aRange(ppSortArray[j]->GetRange(0));
538 			aRange.Format( aString, SCR_ABS_3D, pDoc, aDetails );
539 
540 			//@008 Hole Bereichsparameter aus Dok
541 			ppSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
542 											nCol2, nRow2, nTab2 );
543 			SCCOL q=nCol1+3;
544 			if(q>nCol2) q=nCol2;
545 			//@008 Baue String zusammen
546 			strShow.AssignAscii(RTL_CONSTASCII_STRINGPARAM(" ["));
547 			if(pDoc!=NULL)
548 			{
549 				pDoc->GetString(nCol1, nRow1, nTab1,rString);
550 				strShow	+=rString;
551 				for(SCCOL i=nCol1+1;i<=q;i++)
552 				{
553 					strShow.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
554 					pDoc->GetString(i, nRow1, nTab1,rString);
555 					strShow	+= rString;
556 				}
557 			}
558 			if(q<nCol2) // Zu lang? Ergaenzen um ",..."
559 			{
560 				strShow.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ..."));
561 			}
562 			strShow += ']';
563 
564 			//@008 String einfuegen in Listbox
565 			String aInsStr = aString;
566 			aInsStr += strShow;
567 			nPos = aLbRange.InsertEntry( aInsStr );
568             aRangeMap.insert( NameRangeMap::value_type(aInsStr, aRange) );
569 			aLbRange.SetEntryData( nPos, (void*)nEntryDataCol );
570 		}
571 		delete [] ppSortArray;
572 	}
573 	aString = strDelim;
574 	aString += ScGlobal::GetRscString( STR_ROW );
575 	aString += strDelim;
576 	nPos = aLbRange.InsertEntry( aString );
577 	aLbRange.SetEntryData( nPos, (void*)nEntryDataDelim );
578 	if ( (nCount = xRowNameRanges->Count()) > 0 )
579 	{
580 		ScRangePair** ppSortArray = xRowNameRanges->CreateNameSortedArray(
581 			nCount, pDoc );
582 		for ( j=0; j < nCount; j++ )
583 		{
584             const ScRange aRange(ppSortArray[j]->GetRange(0));
585 			aRange.Format( aString, SCR_ABS_3D, pDoc, aDetails );
586 
587 			//@008 Ab hier baue String fuer Zeilen
588 			ppSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
589 											nCol2, nRow2, nTab2 );
590 			SCROW q=nRow1+3;
591 			if(q>nRow2) q=nRow2;
592 			strShow.AssignAscii(RTL_CONSTASCII_STRINGPARAM(" ["));
593 			if(pDoc!=NULL)
594 			{
595 				pDoc->GetString(nCol1, nRow1, nTab1,rString);
596 				strShow	+= rString;
597 				for(SCROW i=nRow1+1;i<=q;i++)
598 				{
599 					strShow.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
600 					pDoc->GetString(nCol1, i, nTab1,rString);
601 					strShow	+= rString;
602 				}
603 			}
604 			if(q<nRow2)
605 			{
606 				strShow.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ..."));
607 			}
608 			strShow += ']';
609 
610 			String aInsStr = aString;
611 			aInsStr += strShow;
612 			nPos = aLbRange.InsertEntry( aInsStr );
613             aRangeMap.insert( NameRangeMap::value_type(aInsStr, aRange) );
614 			aLbRange.SetEntryData( nPos, (void*)nEntryDataRow );
615 		}
616 		delete [] ppSortArray;
617 	}
618 	//-----------------------------------------------------------
619 	aLbRange.SetUpdateMode( sal_True );
620 	aLbRange.Invalidate();
621 }
622 
623 
624 /*************************************************************************
625 #*	Member:		UpdateRangeData								Datum:04.09.97
626 #*------------------------------------------------------------------------
627 #*
628 #*  Klasse:		ScColRowNameRangesDlg
629 #*
630 #*  Funktion:	Aktualisieren der Bereichsdaten
631 #*
632 #*  Input:		Bereichs-String
633 #*				Flag fuer Spalten
634 #*
635 #*	Output:		---
636 #*
637 #************************************************************************/
638 
639 void ScColRowNameRangesDlg::UpdateRangeData( const ScRange& rRange, sal_Bool bColName )
640 {
641     ScRangePair* pPair = NULL;
642 	sal_Bool bFound = sal_False;
643     if ( bColName && (pPair = xColNameRanges->Find( rRange )) != NULL )
644 		bFound = sal_True;
645     else if ( !bColName && (pPair = xRowNameRanges->Find( rRange )) != NULL )
646 		bFound = sal_True;
647 
648 	if ( bFound )
649 	{
650         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
651 		String aStr;
652 		theCurArea = rRange;
653 		theCurArea.Format( aStr, SCR_ABS_3D, pDoc, eConv );
654 		aEdAssign.SetText( aStr );
655 		aBtnAdd.Disable();
656 		aBtnRemove.Enable();
657 		aBtnColHead.Check( bColName );
658 		aBtnRowHead.Check( !bColName );
659 		theCurData = pPair->GetRange(1);
660 		theCurData.Format( aStr, SCR_ABS_3D, pDoc, eConv );
661 		aEdAssign2.SetText( aStr );
662 	}
663 	else
664 	{
665 		aBtnAdd.Enable();
666 		aBtnRemove.Disable();
667 	}
668 	aBtnColHead.Enable();
669 	aBtnRowHead.Enable();
670 	aEdAssign2.Enable();
671     aRbAssign2.Enable();
672 }
673 
674 
675 /*************************************************************************
676 #*	Member:		IsRefInputMode								Datum:04.09.97
677 #*------------------------------------------------------------------------
678 #*
679 #*  Klasse:		ScColRowNameRangesDlg
680 #*
681 #*  Funktion:	Abfragefunktion fuer Referenz- Input- Mode.
682 #*
683 #*  Input:		Bereichs-String
684 #*				Flag fuer Spalten
685 #*
686 #*	Output:		true, wenn Referenz- Input- Mode
687 #*
688 #************************************************************************/
689 
690 sal_Bool ScColRowNameRangesDlg::IsRefInputMode() const
691 {
692 	return (pEdActive != NULL);
693 }
694 
695 //------------------------------------------------------------------------
696 // Handler:
697 // ========
698 
699 /*************************************************************************
700 #*	Handler:	OkBtnHdl									Datum:04.09.97
701 #*------------------------------------------------------------------------
702 #*
703 #*  Klasse:		ScColRowNameRangesDlg
704 #*
705 #*  Funktion:   Wird ausgeloest, wenn der OK- Button gedrueckt wurde.
706 #*				Hinzufuegen- Button ausloesen, und die neu einge-
707 #*				stellten Bereiche ans Dokument uebergeben.
708 #*				Fensterschliessen- Anweisung ausloesen.
709 #*  Input:		---
710 #*
711 #*	Output:		---
712 #*
713 #************************************************************************/
714 
715 IMPL_LINK( ScColRowNameRangesDlg, OkBtnHdl, void *, EMPTYARG )
716 {
717 	AddBtnHdl( 0 );
718 
719 	// die RangeLists den Refs am Doc zuweisen
720 	pDoc->GetColNameRangesRef() = xColNameRanges;
721 	pDoc->GetRowNameRangesRef() = xRowNameRanges;
722 	// geaenderte Datenbereiche muessen sich auswirken
723 	pDoc->CompileColRowNameFormula();
724 	ScDocShell* pDocShell = pViewData->GetDocShell();
725 	pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID );
726 	pDocShell->SetDocumentModified();
727 
728 	Close();
729 	return 0;
730 }
731 
732 
733 /*************************************************************************
734 #*	Handler:	CancelBtnHdl								Datum:04.09.97
735 #*------------------------------------------------------------------------
736 #*
737 #*  Klasse:		ScColRowNameRangesDlg
738 #*
739 #*  Funktion:	Fensterschliessen- Anweisung ausloesen.
740 #*
741 #*  Input:		---
742 #*
743 #*	Output:		---
744 #*
745 #************************************************************************/
746 
747 IMPL_LINK_INLINE_START( ScColRowNameRangesDlg, CancelBtnHdl, void *, EMPTYARG )
748 {
749 	Close();
750 	return 0;
751 }
752 IMPL_LINK_INLINE_END( ScColRowNameRangesDlg, CancelBtnHdl, void *, EMPTYARG )
753 
754 
755 /*************************************************************************
756 #*	Handler:	AddBtnHdl									Datum:04.09.97
757 #*------------------------------------------------------------------------
758 #*
759 #*  Klasse:		ScColRowNameRangesDlg
760 #*
761 #*  Funktion:	Nach betaetigen des Hinzufuegen- Buttons, werden
762 #*				die Bereichsangaben eingestellt und in der
763 #*				Listbox dargestellt.
764 #*
765 #*  Input:		---
766 #*
767 #*	Output:		---
768 #*
769 #************************************************************************/
770 
771 IMPL_LINK( ScColRowNameRangesDlg, AddBtnHdl, void *, EMPTYARG )
772 {
773 	String aNewArea( aEdAssign.GetText() );
774 	String aNewData( aEdAssign2.GetText() );
775 
776 	if ( aNewArea.Len() > 0 && aNewData.Len() > 0 )
777 	{
778         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
779 		ScRange aRange1, aRange2;
780 		sal_Bool bOk1;
781         if ( (bOk1 = ((aRange1.ParseAny( aNewArea, pDoc, eConv ) & SCA_VALID) == SCA_VALID)) != sal_False
782 		  && ((aRange2.ParseAny( aNewData, pDoc, eConv ) & SCA_VALID) == SCA_VALID) )
783 		{
784 			theCurArea = aRange1;
785 			AdjustColRowData( aRange2 );
786 			ScRangePair* pPair;
787             if ( ( pPair = xColNameRanges->Find( theCurArea ) ) != NULL )
788 			{
789 				xColNameRanges->Remove( pPair );
790 				delete pPair;
791 			}
792             if ( ( pPair = xRowNameRanges->Find( theCurArea ) ) != NULL )
793 			{
794 				xRowNameRanges->Remove( pPair );
795 				delete pPair;
796 			}
797 			if ( aBtnColHead.IsChecked() )
798 				xColNameRanges->Join( ScRangePair( theCurArea, theCurData ) );
799 			else
800 				xRowNameRanges->Join( ScRangePair( theCurArea, theCurData ) );
801 
802 			UpdateNames();
803 
804 			aEdAssign.GrabFocus();
805 			aBtnAdd.Disable();
806 			aBtnRemove.Disable();
807 			aEdAssign.SetText( EMPTY_STRING );
808 			aBtnColHead.Check( sal_True );
809 			aBtnRowHead.Check( sal_False );
810 			aEdAssign2.SetText( EMPTY_STRING );
811 			theCurArea = ScRange();
812 			theCurData = theCurArea;
813 			Range1SelectHdl( 0 );
814 		}
815 		else
816 		{
817 			ERRORBOX( ScGlobal::GetRscString(STR_INVALIDTABNAME) );
818 			if ( !bOk1 )
819 				aEdAssign.GrabFocus();
820 			else
821 				aEdAssign2.GrabFocus();
822 		}
823 	}
824 	return 0;
825 }
826 
827 
828 /*************************************************************************
829 #*	Handler:	RemoveBtnHdl								Datum:04.09.97
830 #*------------------------------------------------------------------------
831 #*
832 #*  Klasse:		ScColRowNameRangesDlg
833 #*
834 #*  Funktion:	Nach betaetigen des Loeschen- Buttons, wird
835 #*				die markierte Bereichsangabe geloescht.
836 #*
837 #*  Input:		---
838 #*
839 #*	Output:		---
840 #*
841 #************************************************************************/
842 
843 IMPL_LINK( ScColRowNameRangesDlg, RemoveBtnHdl, void *, EMPTYARG )
844 {
845 	String aRangeStr = aLbRange.GetSelectEntry();
846 	sal_uInt16 nSelectPos = aLbRange.GetSelectEntryPos();
847 	sal_Bool bColName =
848 		((sal_uLong)aLbRange.GetEntryData( nSelectPos ) == nEntryDataCol);
849     NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
850     if (itr == aRangeMap.end())
851         return 0;
852     const ScRange& rRange = itr->second;
853 
854     ScRangePair* pPair = NULL;
855 	sal_Bool bFound = sal_False;
856     if ( bColName && (pPair = xColNameRanges->Find( rRange )) != NULL )
857 		bFound = sal_True;
858     else if ( !bColName && (pPair = xRowNameRanges->Find( rRange )) != NULL )
859 		bFound = sal_True;
860 	if ( bFound )
861 	{
862 		String aStrDelMsg = ScGlobal::GetRscString( STR_QUERY_DELENTRY );
863 		String aMsg		  = aStrDelMsg.GetToken( 0, '#' );
864 
865 		aMsg += aRangeStr;
866 		aMsg += aStrDelMsg.GetToken( 1, '#' );
867 
868 		if ( RET_YES == QUERYBOX(aMsg) )
869 		{
870 			if ( bColName )
871 				xColNameRanges->Remove( pPair );
872 			else
873 				xRowNameRanges->Remove( pPair );
874 			delete pPair;
875 
876 			UpdateNames();
877 			sal_uInt16 nCnt = aLbRange.GetEntryCount();
878 			if ( nSelectPos >= nCnt )
879 			{
880 				if ( nCnt )
881 					nSelectPos = nCnt - 1;
882 				else
883 					nSelectPos = 0;
884 			}
885 			aLbRange.SelectEntryPos( nSelectPos );
886 			if ( nSelectPos &&
887 					(sal_uLong)aLbRange.GetEntryData( nSelectPos ) == nEntryDataDelim )
888 				aLbRange.SelectEntryPos( --nSelectPos );	// ---Zeile---
889 
890 			aLbRange.GrabFocus();
891 			aBtnAdd.Disable();
892 			aBtnRemove.Disable();
893 			aEdAssign.SetText( EMPTY_STRING );
894 			theCurArea = theCurData = ScRange();
895 			aBtnColHead.Check( sal_True );
896 			aBtnRowHead.Check( sal_False );
897 			aEdAssign2.SetText( EMPTY_STRING );
898 			Range1SelectHdl( 0 );
899 		}
900 	}
901 	return 0;
902 }
903 
904 
905 /*************************************************************************
906 #*	Handler:	Range1SelectHdl								Datum:04.09.97
907 #*------------------------------------------------------------------------
908 #*
909 #*  Klasse:		ScColRowNameRangesDlg
910 #*
911 #*  Funktion:	Wenn Zeile in Listbox ausgewaehlt wird,
912 #*				werden die Eingabefelder entsprechend
913 #*				eingestellt.
914 #*
915 #*  Input:		---
916 #*
917 #*	Output:		---
918 #*
919 #************************************************************************/
920 
921 IMPL_LINK( ScColRowNameRangesDlg, Range1SelectHdl, void *, EMPTYARG )
922 {
923 	sal_uInt16 nSelectPos = aLbRange.GetSelectEntryPos();
924 	sal_uInt16 nCnt = aLbRange.GetEntryCount();
925 	sal_uInt16 nMoves = 0;
926 	while ( nSelectPos < nCnt
927 			&& (sal_uLong)aLbRange.GetEntryData( nSelectPos ) == nEntryDataDelim )
928 	{	// skip Delimiter
929 		++nMoves;
930 		aLbRange.SelectEntryPos( ++nSelectPos );
931 	}
932 	String aRangeStr = aLbRange.GetSelectEntry();
933 	if ( nMoves )
934 	{
935 		if ( nSelectPos > 1 && nSelectPos >= nCnt )
936 		{	// am Ende nicht auf dem " --- Zeile --- " Delimiter stehenbleiben
937 			// wenn davor Eintraege existieren
938 			nSelectPos = nCnt - 2;
939 			aLbRange.SelectEntryPos( nSelectPos );
940 			aRangeStr = aLbRange.GetSelectEntry();
941 		}
942 		else if ( nSelectPos > 2 && nSelectPos < nCnt && aRangeStr.Len()
943 				&& aRangeStr == aEdAssign.GetText() )
944 		{	// nach oben wandern statt nach unten auf die vorherige Position
945 			nSelectPos -= 2;
946 			aLbRange.SelectEntryPos( nSelectPos );
947 			aRangeStr = aLbRange.GetSelectEntry();
948 		}
949 	}
950     NameRangeMap::const_iterator itr = aRangeMap.find(aRangeStr);
951     if ( itr != aRangeMap.end() )
952 	{
953 		sal_Bool bColName =
954 			((sal_uLong)aLbRange.GetEntryData( nSelectPos ) == nEntryDataCol);
955 		UpdateRangeData( itr->second, bColName );
956 		aBtnAdd.Disable();
957 		aBtnRemove.Enable();
958 	}
959 	else
960 	{
961 		if ( aEdAssign.GetText().Len() > 0 )
962 		{
963 			if ( aEdAssign2.GetText().Len() > 0 )
964 				aBtnAdd.Enable();
965 			else
966 				aBtnAdd.Disable();
967 			aBtnColHead.Enable();
968 			aBtnRowHead.Enable();
969 			aEdAssign2.Enable();
970             aRbAssign2.Enable();
971 		}
972 		else
973 		{
974 			aBtnAdd.Disable();
975 			aBtnColHead.Disable();
976 			aBtnRowHead.Disable();
977 			aEdAssign2.Disable();
978             aRbAssign2.Disable();
979 		}
980 		aBtnRemove.Disable();
981 		aEdAssign.GrabFocus();
982 	}
983 
984 	aEdAssign.Enable();
985 	aRbAssign.Enable();
986 
987 	//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
988 	//SFX_APPWINDOW->Enable();
989 	return 0;
990 }
991 
992 
993 /*************************************************************************
994 #*	Handler:	Range1DataModifyHdl							Datum:04.09.97
995 #*------------------------------------------------------------------------
996 #*
997 #*  Klasse:		ScColRowNameRangesDlg
998 #*
999 #*  Funktion:	Wird ausgeloest, wenn in der Tabelle, der Label-
1000 #*				Bereich geaendert wurde.
1001 #*
1002 #*  Input:		---
1003 #*
1004 #*	Output:		---
1005 #*
1006 #************************************************************************/
1007 
1008 IMPL_LINK( ScColRowNameRangesDlg, Range1DataModifyHdl, void *, EMPTYARG )
1009 {
1010 	String aNewArea( aEdAssign.GetText() );
1011 	sal_Bool bValid = sal_False;
1012 	if ( aNewArea.Len() > 0 )
1013 	{
1014 		ScRange aRange;
1015 		if ( (aRange.ParseAny( aNewArea, pDoc, pDoc->GetAddressConvention() ) & SCA_VALID) == SCA_VALID )
1016 		{
1017 			SetColRowData( aRange );
1018 			bValid = sal_True;
1019 		}
1020 	}
1021 	if ( bValid )
1022 	{
1023 		aBtnAdd.Enable();
1024 		aBtnColHead.Enable();
1025 		aBtnRowHead.Enable();
1026 		aEdAssign2.Enable();
1027         aRbAssign2.Enable();
1028 	}
1029 	else
1030 	{
1031 		aBtnAdd.Disable();
1032 		aBtnColHead.Disable();
1033 		aBtnRowHead.Disable();
1034 		aEdAssign2.Disable();
1035         aRbAssign2.Disable();
1036 	}
1037 	aBtnRemove.Disable();
1038 	return 0;
1039 }
1040 
1041 
1042 /*************************************************************************
1043 #*	Handler:	Range2DataModifyHdl							Datum:04.09.97
1044 #*------------------------------------------------------------------------
1045 #*
1046 #*  Klasse:		ScColRowNameRangesDlg
1047 #*
1048 #*  Funktion:	Wird ausgeloest, wenn in der Tabelle, der Daten-
1049 #*				Bereich geaendert wurde
1050 #*
1051 #*  Input:		---
1052 #*
1053 #*	Output:		---
1054 #*
1055 #************************************************************************/
1056 
1057 IMPL_LINK( ScColRowNameRangesDlg, Range2DataModifyHdl, void *, EMPTYARG )
1058 {
1059 	String aNewData( aEdAssign2.GetText() );
1060 	if ( aNewData.Len() > 0 )
1061 	{
1062 		ScRange aRange;
1063 		if ( (aRange.ParseAny( aNewData, pDoc, pDoc->GetAddressConvention() ) & SCA_VALID) == SCA_VALID )
1064 		{
1065 			AdjustColRowData( aRange );
1066 			aBtnAdd.Enable();
1067 		}
1068 		else
1069 			aBtnAdd.Disable();
1070 	}
1071 	else
1072 	{
1073 		aBtnAdd.Disable();
1074 	}
1075 	return 0;
1076 }
1077 
1078 
1079 /*************************************************************************
1080 #*	Handler:	ColClickHdl									Datum:04.09.97
1081 #*------------------------------------------------------------------------
1082 #*
1083 #*  Klasse:		ScColRowNameRangesDlg
1084 #*
1085 #*  Funktion:	Radiobutton fuer Spalten wurde betaetigt,
1086 #*				die entsprechenden Einstellungen werden
1087 #*				vorgenommen
1088 #*
1089 #*  Input:		---
1090 #*
1091 #*	Output:		---
1092 #*
1093 #************************************************************************/
1094 
1095 IMPL_LINK( ScColRowNameRangesDlg, ColClickHdl, void *, EMPTYARG )
1096 {
1097 	if ( !aBtnColHead.GetSavedValue() )
1098 	{
1099 		aBtnColHead.Check( sal_True );
1100 		aBtnRowHead.Check( sal_False );
1101 		if ( theCurArea.aStart.Row() == 0 && theCurArea.aEnd.Row() == MAXROW )
1102 		{
1103 			theCurArea.aEnd.SetRow( MAXROW - 1 );
1104 			String aStr;
1105 			theCurArea.Format( aStr, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
1106 			aEdAssign.SetText( aStr );
1107 		}
1108 		ScRange aRange( theCurData );
1109 		aRange.aStart.SetRow( Min( (long)(theCurArea.aEnd.Row() + 1), (long)MAXROW ) );
1110 		aRange.aEnd.SetRow( MAXROW );
1111 		AdjustColRowData( aRange );
1112 	}
1113 	return 0;
1114 }
1115 
1116 
1117 /*************************************************************************
1118 #*	Handler:	RowClickHdl									Datum:04.09.97
1119 #*------------------------------------------------------------------------
1120 #*
1121 #*  Klasse:		ScColRowNameRangesDlg
1122 #*
1123 #*  Funktion:	Radiobutton fuer Zeilen wurde betaetigt,
1124 #*				die entsprechenden Einstellungen werden
1125 #*				vorgenommen
1126 #*
1127 #*  Input:		---
1128 #*
1129 #*	Output:		---
1130 #*
1131 #************************************************************************/
1132 
1133 IMPL_LINK( ScColRowNameRangesDlg, RowClickHdl, void *, EMPTYARG )
1134 {
1135 	if ( !aBtnRowHead.GetSavedValue() )
1136 	{
1137 		aBtnRowHead.Check( sal_True );
1138 		aBtnColHead.Check( sal_False );
1139 		if ( theCurArea.aStart.Col() == 0 && theCurArea.aEnd.Col() == MAXCOL )
1140 		{
1141 			theCurArea.aEnd.SetCol( MAXCOL - 1 );
1142 			String aStr;
1143 			theCurArea.Format( aStr, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
1144 			aEdAssign.SetText( aStr );
1145 		}
1146 		ScRange aRange( theCurData );
1147 		aRange.aStart.SetCol( static_cast<SCCOL>(Min( (long)(theCurArea.aEnd.Col() + 1), (long)MAXCOL )) );
1148 		aRange.aEnd.SetCol( MAXCOL );
1149 		AdjustColRowData( aRange );
1150 	}
1151 	return 0;
1152 }
1153 
1154 
1155 IMPL_LINK( ScColRowNameRangesDlg, GetFocusHdl, Control*, pCtrl )
1156 {
1157     if( (pCtrl == (Control*)&aEdAssign) || (pCtrl == (Control*)&aRbAssign) )
1158         pEdActive = &aEdAssign;
1159     else if( (pCtrl == (Control*)&aEdAssign2) || (pCtrl == (Control*)&aRbAssign2) )
1160         pEdActive = &aEdAssign2;
1161     else
1162         pEdActive = NULL;
1163 
1164     if( pEdActive )
1165         pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
1166 
1167 	return 0;
1168 }
1169 
1170 
1171 IMPL_LINK( ScColRowNameRangesDlg, LoseFocusHdl, Control*, EMPTYARG )
1172 {
1173 	bDlgLostFocus = !IsActive();
1174 	return 0;
1175 }
1176