xref: /aoo41x/main/sc/source/ui/namedlg/namedlg.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // System - Includes ---------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // INCLUDE -------------------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "global.hxx"
38*cdf0e10cSrcweir #include "reffact.hxx"
39*cdf0e10cSrcweir #include "document.hxx"
40*cdf0e10cSrcweir #include "docfunc.hxx"
41*cdf0e10cSrcweir #include "scresid.hxx"
42*cdf0e10cSrcweir #include "globstr.hrc"
43*cdf0e10cSrcweir #include "namedlg.hrc"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define _NAMEDLG_CXX
46*cdf0e10cSrcweir #include "namedlg.hxx"
47*cdf0e10cSrcweir #undef _NAMEDLG_CXX
48*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // defines -------------------------------------------------------------------
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define ABS_SREF		  SCA_VALID \
55*cdf0e10cSrcweir 						| SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
56*cdf0e10cSrcweir #define ABS_DREF		  ABS_SREF \
57*cdf0e10cSrcweir 						| SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
58*cdf0e10cSrcweir #define ABS_SREF3D		ABS_SREF | SCA_TAB_3D
59*cdf0e10cSrcweir #define ABS_DREF3D		ABS_DREF | SCA_TAB_3D
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //============================================================================
63*cdf0e10cSrcweir // Hilfsklasse: Merken der aktuellen Bereichsoptionen,
64*cdf0e10cSrcweir // wenn ein Name in der ComboBox gefunden wird.
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir struct SaveData
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	SaveData()
69*cdf0e10cSrcweir 		: bCriteria(sal_False),bPrintArea(sal_False),
70*cdf0e10cSrcweir 		  bColHeader(sal_False),bRowHeader(sal_False),
71*cdf0e10cSrcweir 		  bDirty(sal_False) {}
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	void Clear()
74*cdf0e10cSrcweir 		{
75*cdf0e10cSrcweir 			aStrSymbol.Erase();
76*cdf0e10cSrcweir 			bCriteria  = bPrintArea =
77*cdf0e10cSrcweir 			bColHeader = bRowHeader = sal_False;
78*cdf0e10cSrcweir 			bDirty = sal_True;
79*cdf0e10cSrcweir 		}
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 	String	aStrSymbol;
82*cdf0e10cSrcweir 	sal_Bool	bCriteria:1;
83*cdf0e10cSrcweir 	sal_Bool	bPrintArea:1;
84*cdf0e10cSrcweir 	sal_Bool	bColHeader:1;
85*cdf0e10cSrcweir 	sal_Bool	bRowHeader:1;
86*cdf0e10cSrcweir 	sal_Bool	bDirty:1;
87*cdf0e10cSrcweir };
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir static SaveData* pSaveObj = NULL;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir #define SAVE_DATA() \
92*cdf0e10cSrcweir 	pSaveObj->aStrSymbol = aEdAssign.GetText(); 		\
93*cdf0e10cSrcweir 	pSaveObj->bCriteria  = aBtnCriteria.IsChecked();	\
94*cdf0e10cSrcweir 	pSaveObj->bPrintArea = aBtnPrintArea.IsChecked();	\
95*cdf0e10cSrcweir 	pSaveObj->bColHeader = aBtnColHeader.IsChecked();	\
96*cdf0e10cSrcweir 	pSaveObj->bRowHeader = aBtnRowHeader.IsChecked();	\
97*cdf0e10cSrcweir 	pSaveObj->bDirty	 = sal_True;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir #define RESTORE_DATA() \
100*cdf0e10cSrcweir 	if ( pSaveObj->bDirty ) 							\
101*cdf0e10cSrcweir 	{													\
102*cdf0e10cSrcweir 		aEdAssign.SetText( pSaveObj->aStrSymbol );		\
103*cdf0e10cSrcweir 		aBtnCriteria.Check( pSaveObj->bCriteria );		\
104*cdf0e10cSrcweir 		aBtnPrintArea.Check( pSaveObj->bPrintArea );	\
105*cdf0e10cSrcweir 		aBtnColHeader.Check( pSaveObj->bColHeader );	\
106*cdf0e10cSrcweir 		aBtnRowHeader.Check( pSaveObj->bRowHeader );	\
107*cdf0e10cSrcweir 		pSaveObj->bDirty = sal_False;						\
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute();
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir //============================================================================
114*cdf0e10cSrcweir //	class ScNameDlg
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir //----------------------------------------------------------------------------
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir ScNameDlg::ScNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
119*cdf0e10cSrcweir 					  ScViewData*		ptrViewData,
120*cdf0e10cSrcweir 					  const ScAddress&	aCursorPos )
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	:	ScAnyRefDlg	( pB, pCW, pParent, RID_SCDLG_NAMES ),
123*cdf0e10cSrcweir 		//
124*cdf0e10cSrcweir         aFlName         ( this, ScResId( FL_NAME ) ),
125*cdf0e10cSrcweir 		aEdName 		( this, ScResId( ED_NAME ) ),
126*cdf0e10cSrcweir 		//
127*cdf0e10cSrcweir         aFlAssign       ( this, ScResId( FL_ASSIGN ) ),
128*cdf0e10cSrcweir         aEdAssign       ( this, this, ScResId( ED_ASSIGN ) ),
129*cdf0e10cSrcweir 		aRbAssign		( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
130*cdf0e10cSrcweir 		//
131*cdf0e10cSrcweir 		aFlType 		( this, ScResId( FL_TYPE ) ),
132*cdf0e10cSrcweir 		aBtnPrintArea	( this, ScResId( BTN_PRINTAREA ) ),
133*cdf0e10cSrcweir 		aBtnColHeader	( this, ScResId( BTN_COLHEADER ) ),
134*cdf0e10cSrcweir 		aBtnCriteria	( this, ScResId( BTN_CRITERIA ) ),
135*cdf0e10cSrcweir 		aBtnRowHeader	( this, ScResId( BTN_ROWHEADER ) ),
136*cdf0e10cSrcweir 		//
137*cdf0e10cSrcweir 		aBtnOk			( this, ScResId( BTN_OK ) ),
138*cdf0e10cSrcweir 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
139*cdf0e10cSrcweir 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
140*cdf0e10cSrcweir 		aBtnAdd 		( this, ScResId( BTN_ADD ) ),
141*cdf0e10cSrcweir 		aBtnRemove		( this, ScResId( BTN_REMOVE ) ),
142*cdf0e10cSrcweir 		aBtnMore		( this, ScResId( BTN_MORE ) ),
143*cdf0e10cSrcweir 		//
144*cdf0e10cSrcweir 		bSaved			(sal_False),
145*cdf0e10cSrcweir 		aStrAdd 		( ScResId( STR_ADD ) ),
146*cdf0e10cSrcweir 		aStrModify		( ScResId( STR_MODIFY ) ),
147*cdf0e10cSrcweir 		errMsgInvalidSym( ScResId( STR_INVALIDSYMBOL ) ),
148*cdf0e10cSrcweir 		//
149*cdf0e10cSrcweir 		pViewData		( ptrViewData ),
150*cdf0e10cSrcweir 		pDoc			( ptrViewData->GetDocument() ),
151*cdf0e10cSrcweir 		aLocalRangeName ( *(pDoc->GetRangeName()) ),
152*cdf0e10cSrcweir 		theCursorPos	( aCursorPos )  // zum Berechnen der Referenzen
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir 	pSaveObj = new SaveData;
155*cdf0e10cSrcweir 	Init();
156*cdf0e10cSrcweir 	FreeResource();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	aRbAssign.SetAccessibleRelationMemberOf(&aFlAssign);
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //----------------------------------------------------------------------------
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir __EXPORT ScNameDlg::~ScNameDlg()
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	DELETEZ( pSaveObj );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir //----------------------------------------------------------------------------
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void __EXPORT ScNameDlg::Init()
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir 	String	aAreaStr;
175*cdf0e10cSrcweir 	ScRange aRange;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	DBG_ASSERT( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	aBtnOk.SetClickHdl		( LINK( this, ScNameDlg, OkBtnHdl ) );
180*cdf0e10cSrcweir 	aBtnCancel.SetClickHdl	( LINK( this, ScNameDlg, CancelBtnHdl ) );
181*cdf0e10cSrcweir 	aBtnAdd.SetClickHdl		( LINK( this, ScNameDlg, AddBtnHdl ) );
182*cdf0e10cSrcweir 	aBtnRemove.SetClickHdl	( LINK( this, ScNameDlg, RemoveBtnHdl ) );
183*cdf0e10cSrcweir 	aEdAssign.SetGetFocusHdl( LINK( this, ScNameDlg, AssignGetFocusHdl ) );
184*cdf0e10cSrcweir 	aEdAssign.SetModifyHdl	( LINK( this, ScNameDlg, EdModifyHdl ) );
185*cdf0e10cSrcweir 	aEdName.SetModifyHdl 	( LINK( this, ScNameDlg, EdModifyHdl ) );
186*cdf0e10cSrcweir 	aEdName.SetSelectHdl 	( LINK( this, ScNameDlg, NameSelectHdl ) );
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 	aBtnCriteria .Hide();
189*cdf0e10cSrcweir 	aBtnPrintArea.Hide();
190*cdf0e10cSrcweir 	aBtnColHeader.Hide();
191*cdf0e10cSrcweir 	aBtnRowHeader.Hide();
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	aBtnMore.AddWindow( &aFlType );
194*cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnCriteria );
195*cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnPrintArea );
196*cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnColHeader );
197*cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnRowHeader );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	UpdateNames();
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	pViewData->GetSimpleArea( aRange );
202*cdf0e10cSrcweir 	aRange.Format( aAreaStr, ABS_DREF3D, pDoc,
203*cdf0e10cSrcweir                    ScAddress::Details(pDoc->GetAddressConvention(), 0, 0) );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	theCurSel = Selection( 0, SELECTION_MAX );
206*cdf0e10cSrcweir 	aEdAssign.GrabFocus();
207*cdf0e10cSrcweir 	aEdAssign.SetText( aAreaStr );
208*cdf0e10cSrcweir 	aEdAssign.SetSelection( theCurSel );
209*cdf0e10cSrcweir 	aEdName.GrabFocus();
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	aBtnAdd.Disable();
212*cdf0e10cSrcweir 	aBtnRemove.Disable();
213*cdf0e10cSrcweir 	if ( aEdName.GetEntryCount() > 0 )
214*cdf0e10cSrcweir 		aBtnAdd.SetText( aStrAdd );
215*cdf0e10cSrcweir 	UpdateChecks();
216*cdf0e10cSrcweir 	EdModifyHdl( 0 );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	bSaved=sal_True;
219*cdf0e10cSrcweir 	SAVE_DATA()
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	//@BugID 54702
222*cdf0e10cSrcweir 	//SFX_APPWINDOW->Disable(sal_False);		//! allgemeine Methode im ScAnyRefDlg
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //----------------------------------------------------------------------------
226*cdf0e10cSrcweir sal_Bool ScNameDlg::IsRefInputMode() const
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir 	return aEdAssign.IsEnabled();
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir void ScNameDlg::RefInputDone( sal_Bool bForced)
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir 	ScAnyRefDlg::RefInputDone(bForced);
234*cdf0e10cSrcweir 	EdModifyHdl(&aEdAssign);
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir //----------------------------------------------------------------------------
237*cdf0e10cSrcweir // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
238*cdf0e10cSrcweir // neue Selektion im Referenz-Edit angezeigt wird.
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir void ScNameDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	if ( aEdAssign.IsEnabled() )
244*cdf0e10cSrcweir 	{
245*cdf0e10cSrcweir 		if ( rRef.aStart != rRef.aEnd )
246*cdf0e10cSrcweir 			RefInputStart(&aEdAssign);
247*cdf0e10cSrcweir 		String aRefStr;
248*cdf0e10cSrcweir         rRef.Format( aRefStr, ABS_DREF3D, pDocP,
249*cdf0e10cSrcweir                      ScAddress::Details(pDocP->GetAddressConvention(), 0, 0) );
250*cdf0e10cSrcweir 		aEdAssign.SetRefString( aRefStr );
251*cdf0e10cSrcweir 	}
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir //----------------------------------------------------------------------------
256*cdf0e10cSrcweir sal_Bool __EXPORT ScNameDlg::Close()
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir 	return DoClose( ScNameDlgWrapper::GetChildWindowId() );
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //----------------------------------------------------------------------------
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void ScNameDlg::SetActive()
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	aEdAssign.GrabFocus();
267*cdf0e10cSrcweir 	RefInputDone();
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir //----------------------------------------------------------------------------
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir void __EXPORT ScNameDlg::UpdateChecks()
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir 	sal_uInt16		 nCurPos=0;
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 	if(aLocalRangeName.SearchName( aEdName.GetText(), nCurPos))
278*cdf0e10cSrcweir 	{
279*cdf0e10cSrcweir 		ScRangeData* pData=(ScRangeData*)(aLocalRangeName.At( nCurPos ));
280*cdf0e10cSrcweir 		aBtnCriteria .Check( pData->HasType( RT_CRITERIA ) );
281*cdf0e10cSrcweir 		aBtnPrintArea.Check( pData->HasType( RT_PRINTAREA ) );
282*cdf0e10cSrcweir 		aBtnColHeader.Check( pData->HasType( RT_COLHEADER ) );
283*cdf0e10cSrcweir 		aBtnRowHeader.Check( pData->HasType( RT_ROWHEADER ) );
284*cdf0e10cSrcweir 	}
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 	// Falls Edit-Feld leer ist: Typ-CheckBoxen deaktivieren:
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	if ( aEdName.GetText().Len() != 0 )
289*cdf0e10cSrcweir 	{
290*cdf0e10cSrcweir 		if ( !aFlType.IsEnabled() )
291*cdf0e10cSrcweir 		{
292*cdf0e10cSrcweir 			aFlType 	 .Enable();
293*cdf0e10cSrcweir 			aBtnCriteria .Enable();
294*cdf0e10cSrcweir 			aBtnPrintArea.Enable();
295*cdf0e10cSrcweir 			aBtnColHeader.Enable();
296*cdf0e10cSrcweir 			aBtnRowHeader.Enable();
297*cdf0e10cSrcweir             aFlAssign    .Enable();
298*cdf0e10cSrcweir 			aEdAssign    .Enable();
299*cdf0e10cSrcweir 			aRbAssign    .Enable();
300*cdf0e10cSrcweir 		}
301*cdf0e10cSrcweir 	}
302*cdf0e10cSrcweir 	else if ( aFlType.IsEnabled() )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir 		aFlType 	 .Disable();
305*cdf0e10cSrcweir 		aBtnCriteria .Disable();
306*cdf0e10cSrcweir 		aBtnPrintArea.Disable();
307*cdf0e10cSrcweir 		aBtnColHeader.Disable();
308*cdf0e10cSrcweir 		aBtnRowHeader.Disable();
309*cdf0e10cSrcweir         aFlAssign    .Disable();
310*cdf0e10cSrcweir 		aEdAssign    .Disable();
311*cdf0e10cSrcweir 		aRbAssign    .Disable();
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir //----------------------------------------------------------------------------
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir void __EXPORT ScNameDlg::UpdateNames()
319*cdf0e10cSrcweir {
320*cdf0e10cSrcweir 	sal_uInt16	nRangeCount = aLocalRangeName.GetCount();
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir 	aEdName.SetUpdateMode( sal_False );
323*cdf0e10cSrcweir 	//-----------------------------------------------------------
324*cdf0e10cSrcweir 	sal_uInt16  nNamePos = aEdName.GetTopEntry();
325*cdf0e10cSrcweir 	aEdName.Clear();
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	aEdAssign.SetText( EMPTY_STRING );
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 	if ( nRangeCount > 0 )
330*cdf0e10cSrcweir 	{
331*cdf0e10cSrcweir 		ScRangeData*	pRangeData = NULL;
332*cdf0e10cSrcweir 		String			aString;
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 		for ( sal_uInt16 i=0; i<nRangeCount; i++ )
335*cdf0e10cSrcweir 		{
336*cdf0e10cSrcweir 			pRangeData = (ScRangeData*)(aLocalRangeName.At( i ));
337*cdf0e10cSrcweir 			if ( pRangeData )
338*cdf0e10cSrcweir 			{
339*cdf0e10cSrcweir 				if (   !pRangeData->HasType( RT_DATABASE )
340*cdf0e10cSrcweir 					&& !pRangeData->HasType( RT_SHARED ) )
341*cdf0e10cSrcweir 				{
342*cdf0e10cSrcweir 					pRangeData->GetName( aString );
343*cdf0e10cSrcweir 					aEdName.InsertEntry( aString );
344*cdf0e10cSrcweir 				}
345*cdf0e10cSrcweir 			}
346*cdf0e10cSrcweir 		}
347*cdf0e10cSrcweir 	}
348*cdf0e10cSrcweir 	else
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 		aBtnAdd.SetText( aStrAdd );
351*cdf0e10cSrcweir 		aBtnAdd.Disable();
352*cdf0e10cSrcweir 		aBtnRemove.Disable();
353*cdf0e10cSrcweir 	}
354*cdf0e10cSrcweir 	//-----------------------------------------------------------
355*cdf0e10cSrcweir 	aEdName.SetUpdateMode( sal_True );
356*cdf0e10cSrcweir 	aEdName.SetTopEntry(nNamePos);
357*cdf0e10cSrcweir 	aEdName.Invalidate();
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir //----------------------------------------------------------------------------
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir void __EXPORT ScNameDlg::CalcCurTableAssign( String& aAssign, sal_uInt16 nCurPos )
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir 	ScRangeData* pRangeData = (ScRangeData*)(aLocalRangeName.At( nCurPos ));
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	if ( pRangeData )
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir         rtl::OUStringBuffer sBuffer;
370*cdf0e10cSrcweir 		pRangeData->UpdateSymbol( sBuffer, theCursorPos );
371*cdf0e10cSrcweir         aAssign = sBuffer;
372*cdf0e10cSrcweir 	}
373*cdf0e10cSrcweir 	else
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		aAssign.Erase();
376*cdf0e10cSrcweir 	}
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir //----------------------------------------------------------------------------
381*cdf0e10cSrcweir // Handler:
382*cdf0e10cSrcweir // ========
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir IMPL_LINK( ScNameDlg, OkBtnHdl, void *, EMPTYARG )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir 	if ( aBtnAdd.IsEnabled() )
387*cdf0e10cSrcweir 		AddBtnHdl( 0 );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	if ( !aBtnAdd.IsEnabled() && !aBtnRemove.IsEnabled() )
390*cdf0e10cSrcweir 	{
391*cdf0e10cSrcweir 		ScDocShell* pDocSh = pViewData->GetDocShell();
392*cdf0e10cSrcweir 		ScDocFunc aFunc(*pDocSh);
393*cdf0e10cSrcweir 		aFunc.ModifyRangeNames( aLocalRangeName, sal_False );
394*cdf0e10cSrcweir 		Close();
395*cdf0e10cSrcweir 	}
396*cdf0e10cSrcweir 	return 0;
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir //----------------------------------------------------------------------------
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir IMPL_LINK_INLINE_START( ScNameDlg, CancelBtnHdl, void *, EMPTYARG )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir 	Close();
405*cdf0e10cSrcweir 	return 0;
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir IMPL_LINK_INLINE_END( ScNameDlg, CancelBtnHdl, void *, EMPTYARG )
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir //----------------------------------------------------------------------------
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir IMPL_LINK( ScNameDlg, AddBtnHdl, void *, EMPTYARG )
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir 	sal_Bool	bAdded	  = sal_False;
415*cdf0e10cSrcweir 	String	aNewEntry = aEdName.GetText();
416*cdf0e10cSrcweir 	sal_uInt16  nNamePos = aEdName.GetTopEntry();
417*cdf0e10cSrcweir 	aNewEntry.EraseLeadingChars( ' ' );
418*cdf0e10cSrcweir 	aNewEntry.EraseTrailingChars( ' ' );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	if ( aNewEntry.Len() > 0 )
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		if ( ScRangeData::IsNameValid( aNewEntry, pDoc ) )
423*cdf0e10cSrcweir 		{
424*cdf0e10cSrcweir 			if ( pDoc )
425*cdf0e10cSrcweir 			{
426*cdf0e10cSrcweir 				ScRangeData*	pNewEntry	= NULL;
427*cdf0e10cSrcweir 				RangeType		nType		= RT_NAME;
428*cdf0e10cSrcweir 				sal_uInt16			nFoundAt	= 0;
429*cdf0e10cSrcweir 				String			theSymbol	= aEdAssign.GetText();
430*cdf0e10cSrcweir 				String			aStrPos;
431*cdf0e10cSrcweir 				String			aStrArea;
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 				pNewEntry = new ScRangeData( pDoc,
434*cdf0e10cSrcweir 											 aNewEntry,
435*cdf0e10cSrcweir 											 theSymbol,
436*cdf0e10cSrcweir 											 theCursorPos,
437*cdf0e10cSrcweir 											 nType );
438*cdf0e10cSrcweir 				if (pNewEntry)
439*cdf0e10cSrcweir 				{
440*cdf0e10cSrcweir 					nType = nType
441*cdf0e10cSrcweir 					| (aBtnRowHeader .IsChecked() ? RT_ROWHEADER  : RangeType(0))
442*cdf0e10cSrcweir 					| (aBtnColHeader .IsChecked() ? RT_COLHEADER  : RangeType(0))
443*cdf0e10cSrcweir 					| (aBtnPrintArea .IsChecked() ? RT_PRINTAREA  : RangeType(0))
444*cdf0e10cSrcweir 					| (aBtnCriteria  .IsChecked() ? RT_CRITERIA   : RangeType(0));
445*cdf0e10cSrcweir 					pNewEntry->AddType(nType);
446*cdf0e10cSrcweir 				}
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 				// theSymbol gueltig?
449*cdf0e10cSrcweir 				// (= konnte theSymbol im ScRangeData-Ctor
450*cdf0e10cSrcweir 				//	  in ein Token-Array uebersetzt werden?)
451*cdf0e10cSrcweir 				if ( 0 == pNewEntry->GetErrCode() )
452*cdf0e10cSrcweir 				{
453*cdf0e10cSrcweir 					// Eintrag bereits vorhanden? Dann vorher entfernen (=Aendern)
454*cdf0e10cSrcweir 					if ( aLocalRangeName.SearchName( aNewEntry, nFoundAt ) )
455*cdf0e10cSrcweir 					{									// alten Index uebernehmen
456*cdf0e10cSrcweir 						pNewEntry->SetIndex(
457*cdf0e10cSrcweir 							((ScRangeData*)(aLocalRangeName.At(nFoundAt)))->GetIndex() );
458*cdf0e10cSrcweir 						aLocalRangeName.AtFree( nFoundAt );
459*cdf0e10cSrcweir 					}
460*cdf0e10cSrcweir 					else
461*cdf0e10cSrcweir 						pSaveObj->Clear();
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 					if ( !aLocalRangeName.Insert( pNewEntry ) )
464*cdf0e10cSrcweir 						delete pNewEntry;
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 					UpdateNames();
467*cdf0e10cSrcweir 					bSaved=sal_False;
468*cdf0e10cSrcweir 					RESTORE_DATA()
469*cdf0e10cSrcweir 					aEdName.SetText(EMPTY_STRING);
470*cdf0e10cSrcweir 					aEdName.GrabFocus();
471*cdf0e10cSrcweir 					UpdateChecks();
472*cdf0e10cSrcweir 					aBtnAdd.SetText( aStrAdd );
473*cdf0e10cSrcweir 					aBtnAdd.Disable();
474*cdf0e10cSrcweir 					aBtnRemove.Disable();
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir 					//@BugID 54702 raus mit dem Sch.
477*cdf0e10cSrcweir 					//SFX_APPWINDOW->Disable(sal_False);		//! allgemeine Methode im ScAnyRefDlg
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 					bAdded = sal_True;
480*cdf0e10cSrcweir 				}
481*cdf0e10cSrcweir 				else // theSymbol ungueltig
482*cdf0e10cSrcweir 				{
483*cdf0e10cSrcweir 					delete pNewEntry;
484*cdf0e10cSrcweir 					ERRORBOX( errMsgInvalidSym );
485*cdf0e10cSrcweir 					theCurSel = Selection( 0, SELECTION_MAX );
486*cdf0e10cSrcweir 					aEdAssign.GrabFocus();
487*cdf0e10cSrcweir 				}
488*cdf0e10cSrcweir 			}
489*cdf0e10cSrcweir 		}
490*cdf0e10cSrcweir 		else
491*cdf0e10cSrcweir 		{
492*cdf0e10cSrcweir 			ERRORBOX( ScGlobal::GetRscString(STR_INVALIDNAME) );
493*cdf0e10cSrcweir 			aEdName.SetSelection( Selection( 0, SELECTION_MAX ) );
494*cdf0e10cSrcweir 			aEdName.GrabFocus();
495*cdf0e10cSrcweir 		}
496*cdf0e10cSrcweir 	}
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir     aEdName.SetTopEntry(nNamePos);
499*cdf0e10cSrcweir 	return bAdded;
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir //----------------------------------------------------------------------------
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir IMPL_LINK( ScNameDlg, RemoveBtnHdl, void *, EMPTYARG )
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	sal_uInt16		 nRemoveAt = 0;
508*cdf0e10cSrcweir 	const String aStrEntry = aEdName.GetText();
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 	if ( aLocalRangeName.SearchName( aStrEntry, nRemoveAt ) )
511*cdf0e10cSrcweir 	{
512*cdf0e10cSrcweir 		String aStrDelMsg = ScGlobal::GetRscString( STR_QUERY_DELENTRY );
513*cdf0e10cSrcweir 		String aMsg		  = aStrDelMsg.GetToken( 0, '#' );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 		aMsg += aStrEntry;
516*cdf0e10cSrcweir 		aMsg += aStrDelMsg.GetToken( 1, '#' );
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 		if ( RET_YES ==
519*cdf0e10cSrcweir 			 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
520*cdf0e10cSrcweir 		{
521*cdf0e10cSrcweir 			aLocalRangeName.AtFree( nRemoveAt );
522*cdf0e10cSrcweir 			UpdateNames();
523*cdf0e10cSrcweir 			UpdateChecks();
524*cdf0e10cSrcweir 			bSaved=sal_False;
525*cdf0e10cSrcweir 			RESTORE_DATA()
526*cdf0e10cSrcweir 			theCurSel = Selection( 0, SELECTION_MAX );
527*cdf0e10cSrcweir 			aBtnAdd.SetText( aStrAdd );
528*cdf0e10cSrcweir 			aBtnAdd.Disable();
529*cdf0e10cSrcweir 			aBtnRemove.Disable();
530*cdf0e10cSrcweir 		}
531*cdf0e10cSrcweir 	}
532*cdf0e10cSrcweir 	return 0;
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //----------------------------------------------------------------------------
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir IMPL_LINK( ScNameDlg, NameSelectHdl, void *, EMPTYARG )
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir 	sal_uInt16 nAtPos;
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 	if ( aLocalRangeName.SearchName( aEdName.GetText(), nAtPos ) )
543*cdf0e10cSrcweir 	{
544*cdf0e10cSrcweir 		String		 aSymbol;
545*cdf0e10cSrcweir 		ScRangeData* pData	= (ScRangeData*)(aLocalRangeName.At( nAtPos ));
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		if ( pData )
548*cdf0e10cSrcweir 		{
549*cdf0e10cSrcweir 			pData->GetSymbol( aSymbol );
550*cdf0e10cSrcweir 			CalcCurTableAssign( aSymbol, nAtPos );
551*cdf0e10cSrcweir 			aEdAssign.SetText( aSymbol );
552*cdf0e10cSrcweir 			aBtnAdd.SetText( aStrModify );
553*cdf0e10cSrcweir 			theCurSel = Selection( 0, SELECTION_MAX );
554*cdf0e10cSrcweir 		}
555*cdf0e10cSrcweir 	}
556*cdf0e10cSrcweir 	UpdateChecks();
557*cdf0e10cSrcweir 	return 0;
558*cdf0e10cSrcweir }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir //----------------------------------------------------------------------------
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir IMPL_LINK( ScNameDlg, EdModifyHdl, Edit *, pEd )
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir 	String	theName 	= aEdName.GetText();
566*cdf0e10cSrcweir 	String	theSymbol	= aEdAssign.GetText();
567*cdf0e10cSrcweir 	sal_Bool	bNameFound	= (COMBOBOX_ENTRY_NOTFOUND
568*cdf0e10cSrcweir 						   != aEdName.GetEntryPos( theName ));
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 	if ( pEd == &aEdName )
571*cdf0e10cSrcweir 	{
572*cdf0e10cSrcweir 		if ( theName.Len() == 0 )
573*cdf0e10cSrcweir 		{
574*cdf0e10cSrcweir 			if ( aBtnAdd.GetText() != aStrAdd )
575*cdf0e10cSrcweir 				aBtnAdd.SetText( aStrAdd );
576*cdf0e10cSrcweir 			aBtnAdd.Disable();
577*cdf0e10cSrcweir 			aBtnRemove.Disable();
578*cdf0e10cSrcweir             aFlAssign.Disable();
579*cdf0e10cSrcweir 			aEdAssign.Disable();
580*cdf0e10cSrcweir 			aRbAssign.Disable();
581*cdf0e10cSrcweir 			//@BugID 54702 raus mit dem Sch.
582*cdf0e10cSrcweir 			//SFX_APPWINDOW->Disable(sal_False);		//! allgemeine Methode im ScAnyRefDlg
583*cdf0e10cSrcweir 		}
584*cdf0e10cSrcweir 		else
585*cdf0e10cSrcweir 		{
586*cdf0e10cSrcweir 			if ( bNameFound )
587*cdf0e10cSrcweir 			{
588*cdf0e10cSrcweir 				if ( aBtnAdd.GetText() != aStrModify )
589*cdf0e10cSrcweir 					aBtnAdd.SetText( aStrModify );
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 				aBtnRemove.Enable();
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 				if(!bSaved)
594*cdf0e10cSrcweir 				{
595*cdf0e10cSrcweir 					bSaved=sal_True;
596*cdf0e10cSrcweir 					SAVE_DATA()
597*cdf0e10cSrcweir 				}
598*cdf0e10cSrcweir 				NameSelectHdl( 0 );
599*cdf0e10cSrcweir 			}
600*cdf0e10cSrcweir 			else
601*cdf0e10cSrcweir 			{
602*cdf0e10cSrcweir 				if ( aBtnAdd.GetText() != aStrAdd )
603*cdf0e10cSrcweir 					aBtnAdd.SetText( aStrAdd );
604*cdf0e10cSrcweir 				aBtnRemove.Disable();
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 				bSaved=sal_False;
607*cdf0e10cSrcweir 				RESTORE_DATA()
608*cdf0e10cSrcweir 			}
609*cdf0e10cSrcweir 			theSymbol = aEdAssign.GetText();
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 			if ( theSymbol.Len() > 0 )
612*cdf0e10cSrcweir 				aBtnAdd.Enable();
613*cdf0e10cSrcweir 			else
614*cdf0e10cSrcweir 				aBtnAdd.Disable();
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir             aFlAssign.Enable();
617*cdf0e10cSrcweir 			aEdAssign.Enable();
618*cdf0e10cSrcweir 			aRbAssign.Enable();
619*cdf0e10cSrcweir 			//@BugID 54702 raus mit dem Sch.
620*cdf0e10cSrcweir 			//SFX_APPWINDOW->Enable();
621*cdf0e10cSrcweir 		}
622*cdf0e10cSrcweir 		UpdateChecks();
623*cdf0e10cSrcweir 		theCurSel = Selection( 0, SELECTION_MAX );
624*cdf0e10cSrcweir 	}
625*cdf0e10cSrcweir 	else if ( pEd == &aEdAssign )
626*cdf0e10cSrcweir 	{
627*cdf0e10cSrcweir 		if ( (theName.Len()>0) && (theSymbol.Len()>0) )
628*cdf0e10cSrcweir 		{
629*cdf0e10cSrcweir 			aBtnAdd.Enable();
630*cdf0e10cSrcweir 			if ( bNameFound )
631*cdf0e10cSrcweir 				aBtnRemove.Enable();
632*cdf0e10cSrcweir 		}
633*cdf0e10cSrcweir 		else
634*cdf0e10cSrcweir 		{
635*cdf0e10cSrcweir 			aBtnAdd.Disable();
636*cdf0e10cSrcweir 			aBtnRemove.Disable();
637*cdf0e10cSrcweir 		}
638*cdf0e10cSrcweir 	}
639*cdf0e10cSrcweir 	return 0;
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir //------------------------------------------------------------------------
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir IMPL_LINK_INLINE_START( ScNameDlg, AssignGetFocusHdl, void *, EMPTYARG )
645*cdf0e10cSrcweir {
646*cdf0e10cSrcweir 	EdModifyHdl( &aEdAssign );
647*cdf0e10cSrcweir 	return 0;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir IMPL_LINK_INLINE_END( ScNameDlg, AssignGetFocusHdl, void *, EMPTYARG )
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 
652