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