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