xref: /aoo41x/main/sc/source/ui/pagedlg/areasdlg.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 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //----------------------------------------------------------------------------
34*cdf0e10cSrcweir #include <rangelst.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
37*cdf0e10cSrcweir #include <svl/stritem.hxx>
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #include <unotools/charclass.hxx>
40*cdf0e10cSrcweir #include <stdlib.h>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #define _AREASDLG_CXX
43*cdf0e10cSrcweir #include "areasdlg.hxx"
44*cdf0e10cSrcweir #undef _AREASDLG_CXX
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "scresid.hxx"
47*cdf0e10cSrcweir #include "rangenam.hxx"
48*cdf0e10cSrcweir #include "reffact.hxx"
49*cdf0e10cSrcweir #include "tabvwsh.hxx"
50*cdf0e10cSrcweir #include "docsh.hxx"
51*cdf0e10cSrcweir #include "globstr.hrc"
52*cdf0e10cSrcweir #include "pagedlg.hrc"
53*cdf0e10cSrcweir #include "compiler.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // STATIC DATA ---------------------------------------------------------------
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // List box positions for print range (PR)
58*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_PR_NONE    = 0;
59*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_PR_ENTIRE  = 1;
60*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_PR_USER    = 2;
61*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_PR_SELECT  = 3;
62*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_PR_OFFSET  = 4;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // List box positions for repeat ranges (RR)
65*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_RR_NONE    = 0;
66*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_RR_USER    = 1;
67*cdf0e10cSrcweir const sal_uInt16 SC_AREASDLG_RR_OFFSET  = 2;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir //============================================================================
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #define HDL(hdl)			LINK( this, ScPrintAreasDlg, hdl )
72*cdf0e10cSrcweir #define ERRORBOX(nId)		ErrorBox( this, WinBits(WB_OK|WB_DEF_OK), \
73*cdf0e10cSrcweir 							ScGlobal::GetRscString( nId ) ).Execute()
74*cdf0e10cSrcweir #define SWAP(x1,x2)			{ int n=x1; x1=x2; x2=n; }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // globale Funktionen (->am Ende der Datei):
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir bool    lcl_CheckRepeatString( const String& rStr, ScDocument* pDoc, bool bIsRow, ScRange* pRange );
79*cdf0e10cSrcweir void	lcl_GetRepeatRangeString( const ScRange* pRange, ScDocument* pDoc, bool bIsRow, String& rStr );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir #if 0
82*cdf0e10cSrcweir static void printAddressFlags(sal_uInt16 nFlag)
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     if ((nFlag & SCA_COL_ABSOLUTE  ) == SCA_COL_ABSOLUTE  )  printf("SCA_COL_ABSOLUTE \n");
85*cdf0e10cSrcweir     if ((nFlag & SCA_ROW_ABSOLUTE  ) == SCA_ROW_ABSOLUTE  )  printf("SCA_ROW_ABSOLUTE \n");
86*cdf0e10cSrcweir     if ((nFlag & SCA_TAB_ABSOLUTE  ) == SCA_TAB_ABSOLUTE  )  printf("SCA_TAB_ABSOLUTE \n");
87*cdf0e10cSrcweir     if ((nFlag & SCA_TAB_3D        ) == SCA_TAB_3D        )  printf("SCA_TAB_3D       \n");
88*cdf0e10cSrcweir     if ((nFlag & SCA_COL2_ABSOLUTE ) == SCA_COL2_ABSOLUTE )  printf("SCA_COL2_ABSOLUTE\n");
89*cdf0e10cSrcweir     if ((nFlag & SCA_ROW2_ABSOLUTE ) == SCA_ROW2_ABSOLUTE )  printf("SCA_ROW2_ABSOLUTE\n");
90*cdf0e10cSrcweir     if ((nFlag & SCA_TAB2_ABSOLUTE ) == SCA_TAB2_ABSOLUTE )  printf("SCA_TAB2_ABSOLUTE\n");
91*cdf0e10cSrcweir     if ((nFlag & SCA_TAB2_3D       ) == SCA_TAB2_3D       )  printf("SCA_TAB2_3D      \n");
92*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_ROW     ) == SCA_VALID_ROW     )  printf("SCA_VALID_ROW    \n");
93*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_COL     ) == SCA_VALID_COL     )  printf("SCA_VALID_COL    \n");
94*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_TAB     ) == SCA_VALID_TAB     )  printf("SCA_VALID_TAB    \n");
95*cdf0e10cSrcweir     if ((nFlag & SCA_FORCE_DOC     ) == SCA_FORCE_DOC     )  printf("SCA_FORCE_DOC    \n");
96*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_ROW2    ) == SCA_VALID_ROW2    )  printf("SCA_VALID_ROW2   \n");
97*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_COL2    ) == SCA_VALID_COL2    )  printf("SCA_VALID_COL2   \n");
98*cdf0e10cSrcweir     if ((nFlag & SCA_VALID_TAB2    ) == SCA_VALID_TAB2    )  printf("SCA_VALID_TAB2   \n");
99*cdf0e10cSrcweir     if ((nFlag & SCA_VALID         ) == SCA_VALID         )  printf("SCA_VALID        \n");
100*cdf0e10cSrcweir     if ((nFlag & SCA_ABS           ) == SCA_ABS           )  printf("SCA_ABS          \n");
101*cdf0e10cSrcweir     if ((nFlag & SCR_ABS           ) == SCR_ABS           )  printf("SCR_ABS          \n");
102*cdf0e10cSrcweir     if ((nFlag & SCA_ABS_3D        ) == SCA_ABS_3D        )  printf("SCA_ABS_3D       \n");
103*cdf0e10cSrcweir     if ((nFlag & SCR_ABS_3D        ) == SCR_ABS_3D        )  printf("SCR_ABS_3D       \n");
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir #endif
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir //============================================================================
108*cdf0e10cSrcweir //	class ScPrintAreasDlg
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir //----------------------------------------------------------------------------
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir ScPrintAreasDlg::ScPrintAreasDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent )
113*cdf0e10cSrcweir 	:	ScAnyRefDlg		( pB, pCW, pParent, RID_SCDLG_AREAS),
114*cdf0e10cSrcweir 		//
115*cdf0e10cSrcweir 		aFlPrintArea    ( this, ScResId( FL_PRINTAREA ) ),
116*cdf0e10cSrcweir 		aLbPrintArea	( this, ScResId( LB_PRINTAREA ) ),
117*cdf0e10cSrcweir         aEdPrintArea    ( this, this, ScResId( ED_PRINTAREA ) ),
118*cdf0e10cSrcweir 		aRbPrintArea	( this, ScResId( RB_PRINTAREA ), &aEdPrintArea, this ),
119*cdf0e10cSrcweir 		//
120*cdf0e10cSrcweir 		aFlRepeatRow    ( this, ScResId( FL_REPEATROW ) ),
121*cdf0e10cSrcweir 		aLbRepeatRow	( this, ScResId( LB_REPEATROW ) ),
122*cdf0e10cSrcweir         aEdRepeatRow    ( this, this, ScResId( ED_REPEATROW ) ),
123*cdf0e10cSrcweir 		aRbRepeatRow	( this, ScResId( RB_REPEATROW ), &aEdRepeatRow, this ),
124*cdf0e10cSrcweir 		//
125*cdf0e10cSrcweir 		aFlRepeatCol    ( this, ScResId( FL_REPEATCOL ) ),
126*cdf0e10cSrcweir 		aLbRepeatCol	( this, ScResId( LB_REPEATCOL ) ),
127*cdf0e10cSrcweir         aEdRepeatCol    ( this, this, ScResId( ED_REPEATCOL ) ),
128*cdf0e10cSrcweir 		aRbRepeatCol	( this, ScResId( RB_REPEATCOL ), &aEdRepeatCol, this ),
129*cdf0e10cSrcweir 		//
130*cdf0e10cSrcweir 		aBtnOk			( this, ScResId( BTN_OK ) ),
131*cdf0e10cSrcweir 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
132*cdf0e10cSrcweir 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
133*cdf0e10cSrcweir 		//
134*cdf0e10cSrcweir 		bDlgLostFocus	( sal_False ),
135*cdf0e10cSrcweir 		pRefInputEdit	( &aEdPrintArea ),
136*cdf0e10cSrcweir 		pDoc			( NULL ),
137*cdf0e10cSrcweir 		pViewData		( NULL ),
138*cdf0e10cSrcweir 		nCurTab 		( 0 )
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	ScTabViewShell* pScViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
141*cdf0e10cSrcweir 	ScDocShell*		pScDocSh  = PTR_CAST( ScDocShell,     SfxObjectShell::Current() );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	DBG_ASSERT( pScDocSh, "Current DocumentShell not found :-(" );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	pDoc = pScDocSh->GetDocument();
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	if ( pScViewSh )
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		pViewData = pScViewSh->GetViewData();
150*cdf0e10cSrcweir 		nCurTab   = pViewData->GetTabNo();
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	Impl_Reset();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
156*cdf0e10cSrcweir 	//SFX_APPWINDOW->Enable();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	FreeResource();
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //----------------------------------------------------------------------------
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir ScPrintAreasDlg::~ScPrintAreasDlg()
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	// Extra-Data an ListBox-Entries abraeumen
167*cdf0e10cSrcweir 	ListBox* pLb[3] = { &aLbPrintArea, &aLbRepeatRow, &aLbRepeatCol };
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	for ( sal_uInt16 i=0; i<3; i++ )
170*cdf0e10cSrcweir 	{
171*cdf0e10cSrcweir 		sal_uInt16 nCount = pLb[i]->GetEntryCount();
172*cdf0e10cSrcweir 		for ( sal_uInt16 j=0; j<nCount; j++ )
173*cdf0e10cSrcweir 			delete (String*)pLb[i]->GetEntryData(j);
174*cdf0e10cSrcweir 	}
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //----------------------------------------------------------------------------
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir sal_Bool ScPrintAreasDlg::Close()
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	return DoClose( ScPrintAreasDlgWrapper::GetChildWindowId() );
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //----------------------------------------------------------------------------
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir sal_Bool ScPrintAreasDlg::IsTableLocked() const
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	//	Druckbereiche gelten pro Tabelle, darum macht es keinen Sinn,
191*cdf0e10cSrcweir 	//	bei der Eingabe die Tabelle umzuschalten
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	return sal_True;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //----------------------------------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir void ScPrintAreasDlg::SetReference( const ScRange& rRef, ScDocument* /* pDoc */ )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	if ( pRefInputEdit )
202*cdf0e10cSrcweir 	{
203*cdf0e10cSrcweir 		if ( rRef.aStart != rRef.aEnd )
204*cdf0e10cSrcweir 			RefInputStart( pRefInputEdit );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		String	aStr;
207*cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		if ( &aEdPrintArea == pRefInputEdit )
210*cdf0e10cSrcweir 		{
211*cdf0e10cSrcweir 			rRef.Format( aStr, SCR_ABS, pDoc, eConv );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir //			aEdPrintArea.ReplaceSelected( aStr );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 			String aVal = aEdPrintArea.GetText();
216*cdf0e10cSrcweir 			Selection aSel = aEdPrintArea.GetSelection();
217*cdf0e10cSrcweir             aSel.Justify();
218*cdf0e10cSrcweir 			aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
219*cdf0e10cSrcweir 			aVal.Insert( aStr, (xub_StrLen)aSel.Min() );
220*cdf0e10cSrcweir 			Selection aNewSel( aSel.Min(), aSel.Min()+aStr.Len() );
221*cdf0e10cSrcweir 			aEdPrintArea.SetRefString( aVal );
222*cdf0e10cSrcweir 			aEdPrintArea.SetSelection( aNewSel );
223*cdf0e10cSrcweir 		}
224*cdf0e10cSrcweir 		else
225*cdf0e10cSrcweir 		{
226*cdf0e10cSrcweir 			sal_Bool bRow = ( &aEdRepeatRow == pRefInputEdit );
227*cdf0e10cSrcweir             lcl_GetRepeatRangeString(&rRef, pDoc, bRow, aStr);
228*cdf0e10cSrcweir 			pRefInputEdit->SetRefString( aStr );
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 	}
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	Impl_ModifyHdl( pRefInputEdit );
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir //----------------------------------------------------------------------------
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir void ScPrintAreasDlg::AddRefEntry()
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	if ( pRefInputEdit == &aEdPrintArea )
241*cdf0e10cSrcweir 	{
242*cdf0e10cSrcweir         const sal_Unicode sep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
243*cdf0e10cSrcweir 		String aVal = aEdPrintArea.GetText();
244*cdf0e10cSrcweir 		aVal += sep;
245*cdf0e10cSrcweir 		aEdPrintArea.SetText(aVal);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		xub_StrLen nLen = aVal.Len();
248*cdf0e10cSrcweir 		aEdPrintArea.SetSelection( Selection( nLen, nLen ) );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 		Impl_ModifyHdl( &aEdPrintArea );
251*cdf0e10cSrcweir 	}
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir //----------------------------------------------------------------------------
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir void ScPrintAreasDlg::Deactivate()
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir 	bDlgLostFocus = sal_True;
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir //----------------------------------------------------------------------------
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir void ScPrintAreasDlg::SetActive()
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir 	if ( bDlgLostFocus )
268*cdf0e10cSrcweir 	{
269*cdf0e10cSrcweir 		bDlgLostFocus = sal_False;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 		if ( pRefInputEdit )
272*cdf0e10cSrcweir 		{
273*cdf0e10cSrcweir 			pRefInputEdit->GrabFocus();
274*cdf0e10cSrcweir 			Impl_ModifyHdl( pRefInputEdit );
275*cdf0e10cSrcweir 		}
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir 	else
278*cdf0e10cSrcweir 		GrabFocus();
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	RefInputDone();
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir //----------------------------------------------------------------------------
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir void ScPrintAreasDlg::Impl_Reset()
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir 	String			aStrRange;
289*cdf0e10cSrcweir 	const ScRange*	pRepeatColRange = pDoc->GetRepeatColRange( nCurTab );
290*cdf0e10cSrcweir 	const ScRange*	pRepeatRowRange = pDoc->GetRepeatRowRange( nCurTab );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 	aEdPrintArea.SetModifyHdl	( HDL(Impl_ModifyHdl) );
293*cdf0e10cSrcweir 	aEdRepeatRow.SetModifyHdl	( HDL(Impl_ModifyHdl) );
294*cdf0e10cSrcweir 	aEdRepeatCol.SetModifyHdl	( HDL(Impl_ModifyHdl) );
295*cdf0e10cSrcweir 	aEdPrintArea.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
296*cdf0e10cSrcweir 	aEdRepeatRow.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
297*cdf0e10cSrcweir 	aEdRepeatCol.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
298*cdf0e10cSrcweir 	aLbPrintArea.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
299*cdf0e10cSrcweir 	aLbRepeatRow.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
300*cdf0e10cSrcweir 	aLbRepeatCol.SetGetFocusHdl( HDL(Impl_GetFocusHdl) );
301*cdf0e10cSrcweir 	aLbPrintArea.SetSelectHdl	( HDL(Impl_SelectHdl) );
302*cdf0e10cSrcweir 	aLbRepeatRow.SetSelectHdl	( HDL(Impl_SelectHdl) );
303*cdf0e10cSrcweir 	aLbRepeatCol.SetSelectHdl	( HDL(Impl_SelectHdl) );
304*cdf0e10cSrcweir 	aBtnOk		.SetClickHdl 	( HDL(Impl_BtnHdl)    );
305*cdf0e10cSrcweir 	aBtnCancel	.SetClickHdl 	( HDL(Impl_BtnHdl)    );
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	Impl_FillLists();
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	//-------------------------
310*cdf0e10cSrcweir 	// Druckbereich
311*cdf0e10cSrcweir 	//-------------------------
312*cdf0e10cSrcweir 	aStrRange.Erase();
313*cdf0e10cSrcweir     String aOne;
314*cdf0e10cSrcweir     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
315*cdf0e10cSrcweir     const sal_Unicode sep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
316*cdf0e10cSrcweir     sal_uInt16 nRangeCount = pDoc->GetPrintRangeCount( nCurTab );
317*cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nRangeCount; i++)
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir         const ScRange* pPrintRange = pDoc->GetPrintRange( nCurTab, i );
320*cdf0e10cSrcweir         if (pPrintRange)
321*cdf0e10cSrcweir         {
322*cdf0e10cSrcweir             if ( aStrRange.Len() )
323*cdf0e10cSrcweir                 aStrRange += sep;
324*cdf0e10cSrcweir             pPrintRange->Format( aOne, SCR_ABS, pDoc, eConv );
325*cdf0e10cSrcweir             aStrRange += aOne;
326*cdf0e10cSrcweir         }
327*cdf0e10cSrcweir     }
328*cdf0e10cSrcweir     aEdPrintArea.SetText( aStrRange );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	//-------------------------------
331*cdf0e10cSrcweir 	// Wiederholungszeile
332*cdf0e10cSrcweir 	//-------------------------------
333*cdf0e10cSrcweir     lcl_GetRepeatRangeString(pRepeatRowRange, pDoc, true, aStrRange);
334*cdf0e10cSrcweir 	aEdRepeatRow.SetText( aStrRange );
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	//--------------------------------
337*cdf0e10cSrcweir 	// Wiederholungsspalte
338*cdf0e10cSrcweir 	//--------------------------------
339*cdf0e10cSrcweir     lcl_GetRepeatRangeString(pRepeatColRange, pDoc, false, aStrRange);
340*cdf0e10cSrcweir 	aEdRepeatCol.SetText( aStrRange );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	Impl_ModifyHdl( &aEdPrintArea );
343*cdf0e10cSrcweir 	Impl_ModifyHdl( &aEdRepeatRow );
344*cdf0e10cSrcweir 	Impl_ModifyHdl( &aEdRepeatCol );
345*cdf0e10cSrcweir     if( pDoc->IsPrintEntireSheet( nCurTab ) )
346*cdf0e10cSrcweir         aLbPrintArea.SelectEntryPos( SC_AREASDLG_PR_ENTIRE );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	aEdPrintArea.SaveValue();	// fuer FillItemSet() merken:
349*cdf0e10cSrcweir 	aEdRepeatRow.SaveValue();
350*cdf0e10cSrcweir 	aEdRepeatCol.SaveValue();
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir //----------------------------------------------------------------------------
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir sal_Bool ScPrintAreasDlg::Impl_GetItem( Edit* pEd, SfxStringItem& rItem )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir 	String	aRangeStr = pEd->GetText();
359*cdf0e10cSrcweir 	sal_Bool	bDataChanged = (pEd->GetSavedValue() != aRangeStr);
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	if ( (aRangeStr.Len() > 0) && &aEdPrintArea != pEd )
362*cdf0e10cSrcweir 	{
363*cdf0e10cSrcweir 		ScRange aRange;
364*cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
365*cdf0e10cSrcweir         lcl_CheckRepeatString(aRangeStr, pDoc, &aEdRepeatRow == pEd, &aRange);
366*cdf0e10cSrcweir 		aRange.Format(aRangeStr, SCR_ABS, pDoc, eConv);
367*cdf0e10cSrcweir 	}
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	rItem.SetValue( aRangeStr );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	return bDataChanged;
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir //----------------------------------------------------------------------------
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir sal_Bool ScPrintAreasDlg::Impl_CheckRefStrings()
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir 	sal_Bool		bOk = sal_False;
380*cdf0e10cSrcweir 	String		aStrPrintArea	= aEdPrintArea.GetText();
381*cdf0e10cSrcweir 	String		aStrRepeatRow	= aEdRepeatRow.GetText();
382*cdf0e10cSrcweir 	String		aStrRepeatCol	= aEdRepeatCol.GetText();
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 	sal_Bool bPrintAreaOk = sal_True;
385*cdf0e10cSrcweir 	if ( aStrPrintArea.Len() )
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir         const sal_uInt16 nValidAddr  = SCA_VALID | SCA_VALID_ROW | SCA_VALID_COL;
388*cdf0e10cSrcweir         const sal_uInt16 nValidRange = nValidAddr | SCA_VALID_ROW2 | SCA_VALID_COL2;
389*cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
390*cdf0e10cSrcweir         const sal_Unicode sep  = ScCompiler::GetNativeSymbol(ocSep).GetChar(0);
391*cdf0e10cSrcweir         // const sal_Unicode rsep = ScCompiler::GetNativeSymbol(ocRange).GetChar(0);
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         ScAddress aAddr;
394*cdf0e10cSrcweir 		ScRange aRange;
395*cdf0e10cSrcweir 		xub_StrLen nSepCount = aStrPrintArea.GetTokenCount(sep);
396*cdf0e10cSrcweir 		for ( xub_StrLen i = 0; i < nSepCount && bPrintAreaOk; ++i )
397*cdf0e10cSrcweir 		{
398*cdf0e10cSrcweir 			String aOne = aStrPrintArea.GetToken(i, sep);
399*cdf0e10cSrcweir             sal_uInt16 nResult = aRange.Parse( aOne, pDoc, eConv );
400*cdf0e10cSrcweir             if ((nResult & nValidRange) != nValidRange)
401*cdf0e10cSrcweir             {
402*cdf0e10cSrcweir                 sal_uInt16 nAddrResult = aAddr.Parse( aOne, pDoc, eConv );
403*cdf0e10cSrcweir                 if ((nAddrResult & nValidAddr) != nValidAddr)
404*cdf0e10cSrcweir                     bPrintAreaOk = sal_False;
405*cdf0e10cSrcweir             }
406*cdf0e10cSrcweir 		}
407*cdf0e10cSrcweir 	}
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	sal_Bool bRepeatRowOk = (aStrRepeatRow.Len() == 0);
410*cdf0e10cSrcweir 	if ( !bRepeatRowOk )
411*cdf0e10cSrcweir         bRepeatRowOk = lcl_CheckRepeatString(aStrRepeatRow, pDoc, true, NULL);
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	sal_Bool bRepeatColOk = (aStrRepeatCol.Len() == 0);
414*cdf0e10cSrcweir 	if ( !bRepeatColOk )
415*cdf0e10cSrcweir         bRepeatColOk = lcl_CheckRepeatString(aStrRepeatCol, pDoc, false, NULL);
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	// Fehlermeldungen
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 	bOk = (bPrintAreaOk && bRepeatRowOk && bRepeatColOk);
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 	if ( !bOk )
422*cdf0e10cSrcweir 	{
423*cdf0e10cSrcweir 		Edit* pEd = NULL;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 			 if ( !bPrintAreaOk ) pEd = &aEdPrintArea;
426*cdf0e10cSrcweir 		else if ( !bRepeatRowOk ) pEd = &aEdRepeatRow;
427*cdf0e10cSrcweir 		else if ( !bRepeatColOk ) pEd = &aEdRepeatCol;
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir 		ERRORBOX( STR_INVALID_TABREF );
430*cdf0e10cSrcweir 		pEd->GrabFocus();
431*cdf0e10cSrcweir 	}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	return bOk;
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir //----------------------------------------------------------------------------
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir void ScPrintAreasDlg::Impl_FillLists()
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	//------------------------------------------------------
442*cdf0e10cSrcweir 	// Selektion holen und String in PrintArea-ListBox merken
443*cdf0e10cSrcweir 	//------------------------------------------------------
444*cdf0e10cSrcweir 	ScRange	aRange;
445*cdf0e10cSrcweir 	String	aStrRange;
446*cdf0e10cSrcweir 	sal_Bool bSimple = sal_True;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	if ( pViewData )
449*cdf0e10cSrcweir 		bSimple = (pViewData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE);
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 	if ( bSimple )
454*cdf0e10cSrcweir 		aRange.Format( aStrRange, SCR_ABS, pDoc, eConv );
455*cdf0e10cSrcweir 	else
456*cdf0e10cSrcweir 	{
457*cdf0e10cSrcweir 		ScRangeListRef aList( new ScRangeList );
458*cdf0e10cSrcweir 		pViewData->GetMarkData().FillRangeListWithMarks( aList, sal_False );
459*cdf0e10cSrcweir 		aList->Format( aStrRange, SCR_ABS, pDoc, eConv );
460*cdf0e10cSrcweir 	}
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     aLbPrintArea.SetEntryData( SC_AREASDLG_PR_SELECT, new String( aStrRange ) );
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 	//------------------------------------------------------
465*cdf0e10cSrcweir 	// Ranges holen und in ListBoxen merken
466*cdf0e10cSrcweir 	//------------------------------------------------------
467*cdf0e10cSrcweir 	ScRangeName*	pRangeNames = pDoc->GetRangeName();
468*cdf0e10cSrcweir 	const sal_uInt16	nCount		= pRangeNames ? pRangeNames->GetCount() : 0;
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 	if ( nCount > 0 )
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		String			aName;
473*cdf0e10cSrcweir 		String			aSymbol;
474*cdf0e10cSrcweir //        ScRange         aRange;
475*cdf0e10cSrcweir 		ScRangeData*	pData = NULL;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 		for ( sal_uInt16 i=0; i<nCount; i++ )
478*cdf0e10cSrcweir 		{
479*cdf0e10cSrcweir 			pData = (ScRangeData*)(pRangeNames->At( i ));
480*cdf0e10cSrcweir 			if ( pData )
481*cdf0e10cSrcweir 			{
482*cdf0e10cSrcweir 				if (   pData->HasType( RT_ABSAREA )
483*cdf0e10cSrcweir 					|| pData->HasType( RT_REFAREA )
484*cdf0e10cSrcweir 					|| pData->HasType( RT_ABSPOS ) )
485*cdf0e10cSrcweir 				{
486*cdf0e10cSrcweir 					pData->GetName( aName );
487*cdf0e10cSrcweir 					pData->GetSymbol( aSymbol );
488*cdf0e10cSrcweir 					if ( aRange.ParseAny( aSymbol, pDoc, eConv ) & SCA_VALID )
489*cdf0e10cSrcweir 					{
490*cdf0e10cSrcweir 						if ( pData->HasType( RT_PRINTAREA ) )
491*cdf0e10cSrcweir 						{
492*cdf0e10cSrcweir 							aRange.Format( aSymbol, SCR_ABS, pDoc, eConv );
493*cdf0e10cSrcweir 							aLbPrintArea.SetEntryData(
494*cdf0e10cSrcweir 								aLbPrintArea.InsertEntry( aName ),
495*cdf0e10cSrcweir 								new String( aSymbol ) );
496*cdf0e10cSrcweir 						}
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 						if ( pData->HasType( RT_ROWHEADER ) )
499*cdf0e10cSrcweir 						{
500*cdf0e10cSrcweir                             lcl_GetRepeatRangeString(&aRange, pDoc, true, aSymbol);
501*cdf0e10cSrcweir 							aLbRepeatRow.SetEntryData(
502*cdf0e10cSrcweir 								aLbRepeatRow.InsertEntry( aName ),
503*cdf0e10cSrcweir 								new String( aSymbol ) );
504*cdf0e10cSrcweir 						}
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 						if ( pData->HasType( RT_COLHEADER ) )
507*cdf0e10cSrcweir 						{
508*cdf0e10cSrcweir                             lcl_GetRepeatRangeString(&aRange, pDoc, false, aSymbol);
509*cdf0e10cSrcweir 							aLbRepeatCol.SetEntryData(
510*cdf0e10cSrcweir 								aLbRepeatCol.InsertEntry( aName ),
511*cdf0e10cSrcweir 								new String( aSymbol ) );
512*cdf0e10cSrcweir 						}
513*cdf0e10cSrcweir 					}
514*cdf0e10cSrcweir 				}
515*cdf0e10cSrcweir 			}
516*cdf0e10cSrcweir 		}
517*cdf0e10cSrcweir 	}
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir //----------------------------------------------------------------------------
522*cdf0e10cSrcweir // Handler:
523*cdf0e10cSrcweir //----------------------------------------------------------------------------
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir IMPL_LINK( ScPrintAreasDlg, Impl_BtnHdl, PushButton*, pBtn )
526*cdf0e10cSrcweir {
527*cdf0e10cSrcweir 	if ( &aBtnOk == pBtn )
528*cdf0e10cSrcweir 	{
529*cdf0e10cSrcweir 		if ( Impl_CheckRefStrings() )
530*cdf0e10cSrcweir 		{
531*cdf0e10cSrcweir 			sal_Bool			bDataChanged = sal_False;
532*cdf0e10cSrcweir 			String			aStr;
533*cdf0e10cSrcweir 			SfxStringItem	aPrintArea( SID_CHANGE_PRINTAREA, aStr );
534*cdf0e10cSrcweir 			SfxStringItem	aRepeatRow( FN_PARAM_2, aStr );
535*cdf0e10cSrcweir 			SfxStringItem 	aRepeatCol( FN_PARAM_3, aStr );
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 			//-------------------------
538*cdf0e10cSrcweir 			// Druckbereich veraendert?
539*cdf0e10cSrcweir 			//-------------------------
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir             // first try the list box, if "Entite sheet" is selected
542*cdf0e10cSrcweir             sal_Bool bEntireSheet = (aLbPrintArea.GetSelectEntryPos() == SC_AREASDLG_PR_ENTIRE);
543*cdf0e10cSrcweir             SfxBoolItem aEntireSheet( FN_PARAM_4, bEntireSheet );
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir             bDataChanged = bEntireSheet != pDoc->IsPrintEntireSheet( nCurTab );
546*cdf0e10cSrcweir             if( !bEntireSheet )
547*cdf0e10cSrcweir             {
548*cdf0e10cSrcweir                 // if new list box selection is not "Entire sheet", get the edit field contents
549*cdf0e10cSrcweir                 bDataChanged |= Impl_GetItem( &aEdPrintArea, aPrintArea );
550*cdf0e10cSrcweir             }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 			//-------------------------------
553*cdf0e10cSrcweir 			// Wiederholungszeile veraendert?
554*cdf0e10cSrcweir 			//-------------------------------
555*cdf0e10cSrcweir 			bDataChanged |= Impl_GetItem( &aEdRepeatRow, aRepeatRow );
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir 			//--------------------------------
558*cdf0e10cSrcweir 			// Wiederholungsspalte veraendert?
559*cdf0e10cSrcweir 			//--------------------------------
560*cdf0e10cSrcweir 			bDataChanged |= Impl_GetItem( &aEdRepeatCol, aRepeatCol );
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 			if ( bDataChanged )
563*cdf0e10cSrcweir 			{
564*cdf0e10cSrcweir 				SetDispatcherLock( sal_False );
565*cdf0e10cSrcweir 				SwitchToDocument();
566*cdf0e10cSrcweir 				GetBindings().GetDispatcher()->Execute( SID_CHANGE_PRINTAREA,
567*cdf0e10cSrcweir 										  SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
568*cdf0e10cSrcweir                                           &aPrintArea, &aRepeatRow, &aRepeatCol, &aEntireSheet, 0L );
569*cdf0e10cSrcweir 			}
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 			Close();
572*cdf0e10cSrcweir 		}
573*cdf0e10cSrcweir 	}
574*cdf0e10cSrcweir 	else if ( &aBtnCancel == pBtn )
575*cdf0e10cSrcweir 		Close();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 	return 0;
578*cdf0e10cSrcweir }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir //----------------------------------------------------------------------------
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir IMPL_LINK( ScPrintAreasDlg, Impl_GetFocusHdl, Control*, pCtr )
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir 	if ( pCtr ==(Control *) &aEdPrintArea ||
586*cdf0e10cSrcweir 		 pCtr ==(Control *) &aEdRepeatRow ||
587*cdf0e10cSrcweir 		 pCtr ==(Control *) &aEdRepeatCol)
588*cdf0e10cSrcweir 	{
589*cdf0e10cSrcweir 		 pRefInputEdit = (formula::RefEdit*) pCtr;
590*cdf0e10cSrcweir 	}
591*cdf0e10cSrcweir 	else if ( pCtr ==(Control *) &aLbPrintArea)
592*cdf0e10cSrcweir 	{
593*cdf0e10cSrcweir 		pRefInputEdit = &aEdPrintArea;
594*cdf0e10cSrcweir 	}
595*cdf0e10cSrcweir 	else if ( pCtr ==(Control *) &aLbRepeatRow)
596*cdf0e10cSrcweir 	{
597*cdf0e10cSrcweir 		pRefInputEdit = &aEdRepeatRow;
598*cdf0e10cSrcweir 	}
599*cdf0e10cSrcweir 	else if ( pCtr ==(Control *) &aLbRepeatCol)
600*cdf0e10cSrcweir 	{
601*cdf0e10cSrcweir 		pRefInputEdit = &aEdRepeatCol;
602*cdf0e10cSrcweir 	}
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 	return 0;
605*cdf0e10cSrcweir }
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir //----------------------------------------------------------------------------
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir IMPL_LINK( ScPrintAreasDlg, Impl_SelectHdl, ListBox*, pLb )
611*cdf0e10cSrcweir {
612*cdf0e10cSrcweir     sal_uInt16 nSelPos = pLb->GetSelectEntryPos();
613*cdf0e10cSrcweir     Edit* pEd = NULL;
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     // list box positions of specific entries, default to "repeat row/column" list boxes
616*cdf0e10cSrcweir     sal_uInt16 nAllSheetPos = SC_AREASDLG_RR_NONE;
617*cdf0e10cSrcweir     sal_uInt16 nUserDefPos = SC_AREASDLG_RR_USER;
618*cdf0e10cSrcweir     sal_uInt16 nFirstCustomPos = SC_AREASDLG_RR_OFFSET;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     // find edit field for list box, and list box positions
621*cdf0e10cSrcweir     if( pLb == &aLbPrintArea )
622*cdf0e10cSrcweir     {
623*cdf0e10cSrcweir         pEd = &aEdPrintArea;
624*cdf0e10cSrcweir         nAllSheetPos = SC_AREASDLG_PR_ENTIRE;
625*cdf0e10cSrcweir         nUserDefPos = SC_AREASDLG_PR_USER;
626*cdf0e10cSrcweir         nFirstCustomPos = SC_AREASDLG_PR_SELECT;    // "Selection" and following
627*cdf0e10cSrcweir     }
628*cdf0e10cSrcweir     else if( pLb == &aLbRepeatCol )
629*cdf0e10cSrcweir         pEd = &aEdRepeatCol;
630*cdf0e10cSrcweir     else if( pLb == &aLbRepeatRow )
631*cdf0e10cSrcweir         pEd = &aEdRepeatRow;
632*cdf0e10cSrcweir     else
633*cdf0e10cSrcweir         return 0;
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     // fill edit field according to list box selection
636*cdf0e10cSrcweir     if( (nSelPos == 0) || (nSelPos == nAllSheetPos) )
637*cdf0e10cSrcweir         pEd->SetText( EMPTY_STRING );
638*cdf0e10cSrcweir     else if( nSelPos == nUserDefPos && !pLb->IsTravelSelect() && pEd->GetText().Len() == 0 )
639*cdf0e10cSrcweir         pLb->SelectEntryPos( 0 );
640*cdf0e10cSrcweir     else if( nSelPos >= nFirstCustomPos )
641*cdf0e10cSrcweir         pEd->SetText( *static_cast< String* >( pLb->GetEntryData( nSelPos ) ) );
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     return 0;
644*cdf0e10cSrcweir }
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir //----------------------------------------------------------------------------
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir IMPL_LINK( ScPrintAreasDlg, Impl_ModifyHdl, formula::RefEdit*, pEd )
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir     ListBox* pLb = NULL;
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir     // list box positions of specific entries, default to "repeat row/column" list boxes
654*cdf0e10cSrcweir     sal_uInt16 nUserDefPos = SC_AREASDLG_RR_USER;
655*cdf0e10cSrcweir     sal_uInt16 nFirstCustomPos = SC_AREASDLG_RR_OFFSET;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir     if( pEd == &aEdPrintArea )
658*cdf0e10cSrcweir     {
659*cdf0e10cSrcweir         pLb = &aLbPrintArea;
660*cdf0e10cSrcweir         nUserDefPos = SC_AREASDLG_PR_USER;
661*cdf0e10cSrcweir         nFirstCustomPos = SC_AREASDLG_PR_SELECT;    // "Selection" and following
662*cdf0e10cSrcweir     }
663*cdf0e10cSrcweir     else if( pEd == &aEdRepeatCol )
664*cdf0e10cSrcweir 		pLb = &aLbRepeatCol;
665*cdf0e10cSrcweir     else if( pEd == &aEdRepeatRow )
666*cdf0e10cSrcweir 		pLb = &aLbRepeatRow;
667*cdf0e10cSrcweir     else
668*cdf0e10cSrcweir         return 0;
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir     // set list box selection according to edit field
671*cdf0e10cSrcweir 	sal_uInt16	nEntryCount = pLb->GetEntryCount();
672*cdf0e10cSrcweir 	String	aStrEd( pEd->GetText() );
673*cdf0e10cSrcweir 	String	aEdUpper = aStrEd;
674*cdf0e10cSrcweir 	aEdUpper.ToUpperAscii();
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir     if ( (nEntryCount > nFirstCustomPos) && aStrEd.Len() > 0 )
677*cdf0e10cSrcweir 	{
678*cdf0e10cSrcweir 		sal_Bool	bFound	= sal_False;
679*cdf0e10cSrcweir 		String* pSymbol	= NULL;
680*cdf0e10cSrcweir 		sal_uInt16 i;
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir         for ( i=nFirstCustomPos; i<nEntryCount && !bFound; i++ )
683*cdf0e10cSrcweir 		{
684*cdf0e10cSrcweir 			pSymbol = (String*)pLb->GetEntryData( i );
685*cdf0e10cSrcweir 			bFound  = ( (*pSymbol == aStrEd) || (*pSymbol == aEdUpper) );
686*cdf0e10cSrcweir 		}
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir         pLb->SelectEntryPos( bFound ? i-1 : nUserDefPos );
689*cdf0e10cSrcweir 	}
690*cdf0e10cSrcweir 	else
691*cdf0e10cSrcweir         pLb->SelectEntryPos( aStrEd.Len() ? nUserDefPos : 0 );
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 	return 0;
694*cdf0e10cSrcweir }
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir //============================================================================
698*cdf0e10cSrcweir // globale Funktionen:
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir // ----------------------------------------------------------------------------
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir // TODO: It might make sense to move these functions to address.?xx. -kohei
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir bool lcl_CheckOne_OOO( const String& rStr, bool bIsRow, SCCOLROW& rVal )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir 	// Zulaessige Syntax fuer rStr:
707*cdf0e10cSrcweir 	// Row: [$]1-MAXTAB
708*cdf0e10cSrcweir 	// Col: [$]A-IV
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 	String	aStr	= rStr;
711*cdf0e10cSrcweir 	xub_StrLen nLen = aStr.Len();
712*cdf0e10cSrcweir 	SCCOLROW	nNum	= 0;
713*cdf0e10cSrcweir 	sal_Bool	bStrOk  = ( nLen > 0 ) && ( bIsRow ? ( nLen < 6 ) : ( nLen < 4 ) );
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir 	if ( bStrOk )
716*cdf0e10cSrcweir 	{
717*cdf0e10cSrcweir 		if ( '$' == aStr.GetChar(0) )
718*cdf0e10cSrcweir 			aStr.Erase( 0, 1 );
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir 		if ( bIsRow )
721*cdf0e10cSrcweir 		{
722*cdf0e10cSrcweir 			bStrOk = CharClass::isAsciiNumeric(aStr);
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 			if ( bStrOk )
725*cdf0e10cSrcweir 			{
726*cdf0e10cSrcweir 				sal_Int32 n = aStr.ToInt32();
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir                 if ( ( bStrOk = (n > 0) && ( n <= MAXROWCOUNT ) ) != sal_False )
729*cdf0e10cSrcweir 					nNum = static_cast<SCCOLROW>(n - 1);
730*cdf0e10cSrcweir 			}
731*cdf0e10cSrcweir 		}
732*cdf0e10cSrcweir 		else
733*cdf0e10cSrcweir 		{
734*cdf0e10cSrcweir             SCCOL nCol = 0;
735*cdf0e10cSrcweir 			bStrOk = ::AlphaToCol( nCol, aStr);
736*cdf0e10cSrcweir             nNum = nCol;
737*cdf0e10cSrcweir 		}
738*cdf0e10cSrcweir 	}
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 	if ( bStrOk )
741*cdf0e10cSrcweir 		rVal = nNum;
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir 	return bStrOk;
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir bool lcl_CheckOne_XL_A1( const String& rStr, bool bIsRow, SCCOLROW& rVal )
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir     // XL A1 style is identical to OOO one for print range formats.
749*cdf0e10cSrcweir     return lcl_CheckOne_OOO(rStr, bIsRow, rVal);
750*cdf0e10cSrcweir }
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir bool lcl_CheckOne_XL_R1C1( const String& rStr, bool bIsRow, SCCOLROW& rVal )
753*cdf0e10cSrcweir {
754*cdf0e10cSrcweir     xub_StrLen nLen = rStr.Len();
755*cdf0e10cSrcweir     if (nLen <= 1)
756*cdf0e10cSrcweir         // There must be at least two characters.
757*cdf0e10cSrcweir         return false;
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir     const sal_Unicode preUpper = bIsRow ? 'R' : 'C';
760*cdf0e10cSrcweir     const sal_Unicode preLower = bIsRow ? 'r' : 'c';
761*cdf0e10cSrcweir     if (rStr.GetChar(0) != preUpper && rStr.GetChar(0) != preLower)
762*cdf0e10cSrcweir         return false;
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir     String aNumStr = rStr.Copy(1);
765*cdf0e10cSrcweir     if (!CharClass::isAsciiNumeric(aNumStr))
766*cdf0e10cSrcweir         return false;
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir     sal_Int32 nNum = aNumStr.ToInt32();
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir     if (nNum <= 0)
771*cdf0e10cSrcweir         return false;
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir     if ((bIsRow && nNum > MAXROWCOUNT) || (!bIsRow && nNum > MAXCOLCOUNT))
774*cdf0e10cSrcweir         return false;
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir     rVal = static_cast<SCCOLROW>(nNum-1);
777*cdf0e10cSrcweir     return true;
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir bool lcl_CheckRepeatOne( const String& rStr, formula::FormulaGrammar::AddressConvention eConv, bool bIsRow, SCCOLROW& rVal )
781*cdf0e10cSrcweir {
782*cdf0e10cSrcweir     switch (eConv)
783*cdf0e10cSrcweir     {
784*cdf0e10cSrcweir         case formula::FormulaGrammar::CONV_OOO:
785*cdf0e10cSrcweir             return lcl_CheckOne_OOO(rStr, bIsRow, rVal);
786*cdf0e10cSrcweir         case formula::FormulaGrammar::CONV_XL_A1:
787*cdf0e10cSrcweir             return lcl_CheckOne_XL_A1(rStr, bIsRow, rVal);
788*cdf0e10cSrcweir         case formula::FormulaGrammar::CONV_XL_R1C1:
789*cdf0e10cSrcweir             return lcl_CheckOne_XL_R1C1(rStr, bIsRow, rVal);
790*cdf0e10cSrcweir         default:
791*cdf0e10cSrcweir         {
792*cdf0e10cSrcweir             // added to avoid warnings
793*cdf0e10cSrcweir         }
794*cdf0e10cSrcweir     }
795*cdf0e10cSrcweir     return false;
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir bool lcl_CheckRepeatString( const String& rStr, ScDocument* pDoc, bool bIsRow, ScRange* pRange )
799*cdf0e10cSrcweir {
800*cdf0e10cSrcweir     // Row: [valid row] rsep [valid row]
801*cdf0e10cSrcweir     // Col: [valid col] rsep [valid col]
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
804*cdf0e10cSrcweir     const sal_Unicode rsep = ScCompiler::GetNativeSymbol(ocRange).GetChar(0);
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     if (pRange)
807*cdf0e10cSrcweir     {
808*cdf0e10cSrcweir         // initialize the range value.
809*cdf0e10cSrcweir         pRange->aStart.SetCol(0);
810*cdf0e10cSrcweir         pRange->aStart.SetRow(0);
811*cdf0e10cSrcweir         pRange->aEnd.SetCol(0);
812*cdf0e10cSrcweir         pRange->aEnd.SetRow(0);
813*cdf0e10cSrcweir     }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir     String aBuf;
816*cdf0e10cSrcweir     SCCOLROW nVal = 0;
817*cdf0e10cSrcweir     xub_StrLen nLen = rStr.Len();
818*cdf0e10cSrcweir     bool bEndPos = false;
819*cdf0e10cSrcweir     for (xub_StrLen i = 0; i < nLen; ++i)
820*cdf0e10cSrcweir     {
821*cdf0e10cSrcweir         const sal_Unicode c = rStr.GetChar(i);
822*cdf0e10cSrcweir         if (c == rsep)
823*cdf0e10cSrcweir         {
824*cdf0e10cSrcweir             if (bEndPos)
825*cdf0e10cSrcweir                 // We aren't supposed to have more than one range separator.
826*cdf0e10cSrcweir                 return false;
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir             // range separator
829*cdf0e10cSrcweir             if (aBuf.Len() == 0)
830*cdf0e10cSrcweir                 return false;
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir             bool bRes = lcl_CheckRepeatOne(aBuf, eConv, bIsRow, nVal);
833*cdf0e10cSrcweir             if (!bRes)
834*cdf0e10cSrcweir                 return false;
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir             if (pRange)
837*cdf0e10cSrcweir             {
838*cdf0e10cSrcweir                 if (bIsRow)
839*cdf0e10cSrcweir                 {
840*cdf0e10cSrcweir                     pRange->aStart.SetRow(static_cast<SCROW>(nVal));
841*cdf0e10cSrcweir                     pRange->aEnd.SetRow(static_cast<SCROW>(nVal));
842*cdf0e10cSrcweir                 }
843*cdf0e10cSrcweir                 else
844*cdf0e10cSrcweir                 {
845*cdf0e10cSrcweir                     pRange->aStart.SetCol(static_cast<SCCOL>(nVal));
846*cdf0e10cSrcweir                     pRange->aEnd.SetCol(static_cast<SCCOL>(nVal));
847*cdf0e10cSrcweir                 }
848*cdf0e10cSrcweir             }
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir             aBuf.Erase();
851*cdf0e10cSrcweir             bEndPos = true;
852*cdf0e10cSrcweir         }
853*cdf0e10cSrcweir         else
854*cdf0e10cSrcweir             aBuf.Append(c);
855*cdf0e10cSrcweir     }
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir     if (aBuf.Len() > 0)
858*cdf0e10cSrcweir     {
859*cdf0e10cSrcweir         bool bRes = lcl_CheckRepeatOne(aBuf, eConv, bIsRow, nVal);
860*cdf0e10cSrcweir         if (!bRes)
861*cdf0e10cSrcweir             return false;
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir         if (pRange)
864*cdf0e10cSrcweir         {
865*cdf0e10cSrcweir             if (bIsRow)
866*cdf0e10cSrcweir             {
867*cdf0e10cSrcweir                 if (!bEndPos)
868*cdf0e10cSrcweir                     pRange->aStart.SetRow(static_cast<SCROW>(nVal));
869*cdf0e10cSrcweir                 pRange->aEnd.SetRow(static_cast<SCROW>(nVal));
870*cdf0e10cSrcweir             }
871*cdf0e10cSrcweir             else
872*cdf0e10cSrcweir             {
873*cdf0e10cSrcweir                 if (!bEndPos)
874*cdf0e10cSrcweir                     pRange->aStart.SetCol(static_cast<SCCOL>(nVal));
875*cdf0e10cSrcweir                 pRange->aEnd.SetCol(static_cast<SCCOL>(nVal));
876*cdf0e10cSrcweir             }
877*cdf0e10cSrcweir         }
878*cdf0e10cSrcweir     }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir     return true;
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir // ----------------------------------------------------------------------------
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir void lcl_GetRepeatRangeString( const ScRange* pRange, ScDocument* pDoc, bool bIsRow, String& rStr )
886*cdf0e10cSrcweir {
887*cdf0e10cSrcweir     rStr.Erase();
888*cdf0e10cSrcweir     if (!pRange)
889*cdf0e10cSrcweir         return;
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
892*cdf0e10cSrcweir     const ScAddress& rStart = pRange->aStart;
893*cdf0e10cSrcweir     const ScAddress& rEnd   = pRange->aEnd;
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir     const sal_uInt16 nFmt = bIsRow ? (SCA_VALID_ROW | SCA_ROW_ABSOLUTE) : (SCA_VALID_COL | SCA_COL_ABSOLUTE);
896*cdf0e10cSrcweir     String aTmpStr;
897*cdf0e10cSrcweir     rStart.Format(aTmpStr, nFmt, pDoc, eConv);
898*cdf0e10cSrcweir     rStr += aTmpStr;
899*cdf0e10cSrcweir     if ((bIsRow && rStart.Row() != rEnd.Row()) || (!bIsRow && rStart.Col() != rEnd.Col()))
900*cdf0e10cSrcweir     {
901*cdf0e10cSrcweir         rStr += ScCompiler::GetNativeSymbol(ocRange);
902*cdf0e10cSrcweir         rEnd.Format(aTmpStr, nFmt, pDoc, eConv);
903*cdf0e10cSrcweir         rStr += aTmpStr;
904*cdf0e10cSrcweir     }
905*cdf0e10cSrcweir }
906*cdf0e10cSrcweir 
907