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