Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <sfx2/dispatch.hxx>
31 : : #include <vcl/msgbox.hxx>
32 : :
33 : : #include "uiitems.hxx"
34 : : #include "global.hxx"
35 : : #include "document.hxx"
36 : : #include "scresid.hxx"
37 : : #include "sc.hrc"
38 : : #include "reffact.hxx"
39 : : #include "tabopdlg.hrc"
40 : :
41 : : #define _TABOPDLG_CXX
42 : : #include "tabopdlg.hxx"
43 : :
44 : :
45 : : //============================================================================
46 : : // class ScTabOpDlg
47 : : //----------------------------------------------------------------------------
48 : :
49 : 0 : ScTabOpDlg::ScTabOpDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
50 : : ScDocument* pDocument,
51 : : const ScRefAddress& rCursorPos )
52 : :
53 : : : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_TABOP ),
54 : : //
55 : : aFlVariables ( this, ScResId( FL_VARIABLES ) ),
56 : : aFtFormulaRange ( this, ScResId( FT_FORMULARANGE ) ),
57 : : aEdFormulaRange ( this, this, ScResId( ED_FORMULARANGE ) ),
58 : : aRBFormulaRange ( this, ScResId( RB_FORMULARANGE ), &aEdFormulaRange, this ),
59 : : aFtRowCell ( this, ScResId( FT_ROWCELL ) ),
60 : : aEdRowCell ( this, this, ScResId( ED_ROWCELL ) ),
61 : : aRBRowCell ( this, ScResId( RB_ROWCELL ), &aEdRowCell, this ),
62 : : aFtColCell ( this, ScResId( FT_COLCELL ) ),
63 : : aEdColCell ( this, this, ScResId( ED_COLCELL ) ),
64 : : aRBColCell ( this, ScResId( RB_COLCELL ), &aEdColCell, this ),
65 : : aBtnOk ( this, ScResId( BTN_OK ) ),
66 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
67 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
68 : : //
69 : : theFormulaCell ( rCursorPos ),
70 : : pDoc ( pDocument ),
71 : 0 : nCurTab ( theFormulaCell.Tab() ),
72 : : pEdActive ( NULL ),
73 : : bDlgLostFocus ( false ),
74 : : errMsgNoFormula ( ScResId( STR_NOFORMULA ) ),
75 : : errMsgNoColRow ( ScResId( STR_NOCOLROW ) ),
76 : : errMsgWrongFormula ( ScResId( STR_WRONGFORMULA ) ),
77 : : errMsgWrongRowCol ( ScResId( STR_WRONGROWCOL ) ),
78 : : errMsgNoColFormula ( ScResId( STR_NOCOLFORMULA ) ),
79 [ # # ][ # # ]: 0 : errMsgNoRowFormula ( ScResId( STR_NOROWFORMULA ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
80 : : {
81 [ # # ]: 0 : Init();
82 [ # # ]: 0 : FreeResource();
83 : 0 : }
84 : :
85 : : //----------------------------------------------------------------------------
86 : :
87 [ # # ][ # # ]: 0 : ScTabOpDlg::~ScTabOpDlg()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
88 : : {
89 [ # # ]: 0 : Hide();
90 [ # # ]: 0 : }
91 : :
92 : : //----------------------------------------------------------------------------
93 : :
94 : 0 : void ScTabOpDlg::Init()
95 : : {
96 [ # # ]: 0 : aBtnOk. SetClickHdl ( LINK( this, ScTabOpDlg, BtnHdl ) );
97 [ # # ]: 0 : aBtnCancel. SetClickHdl ( LINK( this, ScTabOpDlg, BtnHdl ) );
98 : :
99 [ # # ]: 0 : Link aLink = LINK( this, ScTabOpDlg, GetFocusHdl );
100 : 0 : aEdFormulaRange.SetGetFocusHdl( aLink );
101 : 0 : aRBFormulaRange.SetGetFocusHdl( aLink );
102 : 0 : aEdRowCell. SetGetFocusHdl( aLink );
103 : 0 : aRBRowCell. SetGetFocusHdl( aLink );
104 : 0 : aEdColCell. SetGetFocusHdl( aLink );
105 : 0 : aRBColCell. SetGetFocusHdl( aLink );
106 : :
107 [ # # ]: 0 : aLink = LINK( this, ScTabOpDlg, LoseFocusHdl );
108 : 0 : aEdFormulaRange.SetLoseFocusHdl( aLink );
109 : 0 : aRBFormulaRange.SetLoseFocusHdl( aLink );
110 : 0 : aEdRowCell. SetLoseFocusHdl( aLink );
111 : 0 : aRBRowCell. SetLoseFocusHdl( aLink );
112 : 0 : aEdColCell. SetLoseFocusHdl( aLink );
113 : 0 : aRBColCell. SetLoseFocusHdl( aLink );
114 : :
115 [ # # ]: 0 : aEdFormulaRange.GrabFocus();
116 : 0 : pEdActive = &aEdFormulaRange;
117 : :
118 : : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
119 : : //SFX_APPWINDOW->Enable();
120 : 0 : }
121 : :
122 : : //----------------------------------------------------------------------------
123 : :
124 : 0 : sal_Bool ScTabOpDlg::Close()
125 : : {
126 : 0 : return DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
127 : : }
128 : :
129 : : //----------------------------------------------------------------------------
130 : :
131 : 0 : void ScTabOpDlg::SetActive()
132 : : {
133 [ # # ]: 0 : if ( bDlgLostFocus )
134 : : {
135 : 0 : bDlgLostFocus = false;
136 [ # # ]: 0 : if( pEdActive )
137 : 0 : pEdActive->GrabFocus();
138 : : }
139 : : else
140 : 0 : GrabFocus();
141 : :
142 : 0 : RefInputDone();
143 : 0 : }
144 : :
145 : : //----------------------------------------------------------------------------
146 : :
147 : 0 : void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
148 : : {
149 [ # # ]: 0 : if ( pEdActive )
150 : : {
151 [ # # ]: 0 : ScAddress::Details aDetails(pDocP->GetAddressConvention(), 0, 0);
152 : :
153 [ # # ]: 0 : if ( rRef.aStart != rRef.aEnd )
154 [ # # ]: 0 : RefInputStart(pEdActive);
155 : :
156 [ # # ]: 0 : String aStr;
157 : 0 : sal_uInt16 nFmt = ( rRef.aStart.Tab() == nCurTab )
158 : : ? SCR_ABS
159 [ # # ]: 0 : : SCR_ABS_3D;
160 : :
161 [ # # ]: 0 : if ( pEdActive == &aEdFormulaRange )
162 : : {
163 : 0 : theFormulaCell.Set( rRef.aStart, false, false, false);
164 : 0 : theFormulaEnd.Set( rRef.aEnd, false, false, false);
165 [ # # ]: 0 : rRef.Format( aStr, nFmt, pDocP, aDetails );
166 : : }
167 [ # # ]: 0 : else if ( pEdActive == &aEdRowCell )
168 : : {
169 : 0 : theRowCell.Set( rRef.aStart, false, false, false);
170 [ # # ]: 0 : rRef.aStart.Format( aStr, nFmt, pDocP, aDetails );
171 : : }
172 [ # # ]: 0 : else if ( pEdActive == &aEdColCell )
173 : : {
174 : 0 : theColCell.Set( rRef.aStart, false, false, false);
175 [ # # ]: 0 : rRef.aStart.Format( aStr, nFmt, pDocP, aDetails );
176 : : }
177 : :
178 [ # # ][ # # ]: 0 : pEdActive->SetRefString( aStr );
179 : : }
180 : 0 : }
181 : :
182 : : //----------------------------------------------------------------------------
183 : :
184 : 0 : void ScTabOpDlg::RaiseError( ScTabOpErr eError )
185 : : {
186 : 0 : const String* pMsg = &errMsgNoFormula;
187 : 0 : Edit* pEd = &aEdFormulaRange;
188 : :
189 [ # # # # : 0 : switch ( eError )
# # # # ]
190 : : {
191 : : case TABOPERR_NOFORMULA:
192 : 0 : pMsg = &errMsgNoFormula;
193 : 0 : pEd = &aEdFormulaRange;
194 : 0 : break;
195 : :
196 : : case TABOPERR_NOCOLROW:
197 : 0 : pMsg = &errMsgNoColRow;
198 : 0 : pEd = &aEdRowCell;
199 : 0 : break;
200 : :
201 : : case TABOPERR_WRONGFORMULA:
202 : 0 : pMsg = &errMsgWrongFormula;
203 : 0 : pEd = &aEdFormulaRange;
204 : 0 : break;
205 : :
206 : : case TABOPERR_WRONGROW:
207 : 0 : pMsg = &errMsgWrongRowCol;
208 : 0 : pEd = &aEdRowCell;
209 : 0 : break;
210 : :
211 : : case TABOPERR_NOCOLFORMULA:
212 : 0 : pMsg = &errMsgNoColFormula;
213 : 0 : pEd = &aEdFormulaRange;
214 : 0 : break;
215 : :
216 : : case TABOPERR_WRONGCOL:
217 : 0 : pMsg = &errMsgWrongRowCol;
218 : 0 : pEd = &aEdColCell;
219 : 0 : break;
220 : :
221 : : case TABOPERR_NOROWFORMULA:
222 : 0 : pMsg = &errMsgNoRowFormula;
223 : 0 : pEd = &aEdFormulaRange;
224 : 0 : break;
225 : : }
226 : :
227 [ # # ]: 0 : ErrorBox( this, WinBits( WB_OK_CANCEL | WB_DEF_OK), *pMsg ).Execute();
228 : 0 : pEd->GrabFocus();
229 : 0 : }
230 : :
231 : : //----------------------------------------------------------------------------
232 : :
233 : 0 : sal_Bool lcl_Parse( const String& rString, ScDocument* pDoc, SCTAB nCurTab,
234 : : ScRefAddress& rStart, ScRefAddress& rEnd )
235 : : {
236 : 0 : sal_Bool bRet = false;
237 : 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
238 [ # # ]: 0 : if ( rString.Search(':') != STRING_NOTFOUND )
239 [ # # ]: 0 : bRet = ConvertDoubleRef( pDoc, rString, nCurTab, rStart, rEnd, eConv );
240 : : else
241 : : {
242 [ # # ]: 0 : bRet = ConvertSingleRef( pDoc, rString, nCurTab, rStart, eConv );
243 : 0 : rEnd = rStart;
244 : : }
245 : 0 : return bRet;
246 : : }
247 : :
248 : : //----------------------------------------------------------------------------
249 : : // Handler:
250 : :
251 : 0 : IMPL_LINK( ScTabOpDlg, BtnHdl, PushButton*, pBtn )
252 : : {
253 [ # # ]: 0 : if ( pBtn == &aBtnOk )
254 : : {
255 : 0 : sal_uInt8 nMode = 3;
256 : 0 : sal_uInt16 nError = 0;
257 : :
258 : : // Zu ueberpruefen:
259 : : // 1. enthalten die Strings korrekte Tabellenkoordinaten/def.Namen?
260 : : // 2. IstFormelRang Zeile bei leerer Zeile bzw. Spalte bei leerer Spalte
261 : : // bzw. Einfachreferenz bei beidem?
262 : : // 3. Ist mindestens Zeile oder Spalte und Formel voll?
263 : :
264 [ # # ]: 0 : if (aEdFormulaRange.GetText().Len() == 0)
265 : 0 : nError = TABOPERR_NOFORMULA;
266 [ # # ]: 0 : else if (aEdRowCell.GetText().Len() == 0 &&
[ # # # # ]
[ # # ]
[ # # # # ]
267 [ # # ][ # # ]: 0 : aEdColCell.GetText().Len() == 0)
[ # # ][ # # ]
268 : 0 : nError = TABOPERR_NOCOLROW;
269 [ # # ]: 0 : else if ( !lcl_Parse( aEdFormulaRange.GetText(), pDoc, nCurTab,
270 [ # # ]: 0 : theFormulaCell, theFormulaEnd ) )
271 : 0 : nError = TABOPERR_WRONGFORMULA;
272 : : else
273 : : {
274 : 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
275 [ # # ]: 0 : if (aEdRowCell.GetText().Len() > 0)
276 : : {
277 [ # # ]: 0 : if (!ConvertSingleRef( pDoc, aEdRowCell.GetText(), nCurTab,
278 [ # # ][ # # ]: 0 : theRowCell, eConv ))
[ # # ]
279 : 0 : nError = TABOPERR_WRONGROW;
280 : : else
281 : : {
282 [ # # ]: 0 : if (aEdColCell.GetText().Len() == 0 &&
[ # # # # ]
[ # # ]
[ # # # # ]
283 : 0 : theFormulaCell.Col() != theFormulaEnd.Col())
284 : 0 : nError = TABOPERR_NOCOLFORMULA;
285 : : else
286 : 0 : nMode = 1;
287 : : }
288 : : }
289 [ # # ]: 0 : if (aEdColCell.GetText().Len() > 0)
290 : : {
291 [ # # ]: 0 : if (!ConvertSingleRef( pDoc, aEdColCell.GetText(), nCurTab,
292 [ # # ][ # # ]: 0 : theColCell, eConv ))
[ # # ]
293 : 0 : nError = TABOPERR_WRONGCOL;
294 : : else
295 : : {
296 [ # # ]: 0 : if (nMode == 1) // beides
297 : : {
298 : 0 : nMode = 2;
299 : : ConvertSingleRef( pDoc, aEdFormulaRange.GetText(), nCurTab,
300 [ # # ][ # # ]: 0 : theFormulaCell, eConv );
[ # # ]
301 : : }
302 [ # # ]: 0 : else if (theFormulaCell.Row() != theFormulaEnd.Row())
303 : 0 : nError = TABOPERR_NOROWFORMULA;
304 : : else
305 : 0 : nMode = 0;
306 : : }
307 : : }
308 : : }
309 : :
310 [ # # ]: 0 : if (nError)
311 : 0 : RaiseError( (ScTabOpErr) nError );
312 : : else
313 : : {
314 : : ScTabOpParam aOutParam( theFormulaCell,
315 : : theFormulaEnd,
316 : : theRowCell,
317 : : theColCell,
318 [ # # ]: 0 : nMode );
319 [ # # ]: 0 : ScTabOpItem aOutItem( SID_TABOP, &aOutParam );
320 : :
321 [ # # ]: 0 : SetDispatcherLock( false );
322 [ # # ]: 0 : SwitchToDocument();
323 : 0 : GetBindings().GetDispatcher()->Execute( SID_TABOP,
324 : : SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
325 [ # # ]: 0 : &aOutItem, 0L, 0L );
326 [ # # ][ # # ]: 0 : Close();
327 : : }
328 : : }
329 [ # # ]: 0 : else if ( pBtn == &aBtnCancel )
330 : 0 : Close();
331 : :
332 : 0 : return 0;
333 : : }
334 : :
335 : : //----------------------------------------------------------------------------
336 : :
337 : 0 : IMPL_LINK( ScTabOpDlg, GetFocusHdl, Control*, pCtrl )
338 : : {
339 [ # # ][ # # ]: 0 : if( (pCtrl == (Control*)&aEdFormulaRange) || (pCtrl == (Control*)&aRBFormulaRange) )
340 : 0 : pEdActive = &aEdFormulaRange;
341 [ # # ][ # # ]: 0 : else if( (pCtrl == (Control*)&aEdRowCell) || (pCtrl == (Control*)&aRBRowCell) )
342 : 0 : pEdActive = &aEdRowCell;
343 [ # # ][ # # ]: 0 : else if( (pCtrl == (Control*)&aEdColCell) || (pCtrl == (Control*)&aRBColCell) )
344 : 0 : pEdActive = &aEdColCell;
345 : : else
346 : 0 : pEdActive = NULL;
347 : :
348 [ # # ]: 0 : if( pEdActive )
349 [ # # ]: 0 : pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
350 : :
351 : 0 : return 0;
352 : : }
353 : :
354 : : //----------------------------------------------------------------------------
355 : :
356 : 0 : IMPL_LINK_NOARG(ScTabOpDlg, LoseFocusHdl)
357 : : {
358 : 0 : bDlgLostFocus = !IsActive();
359 : 0 : return 0;
360 : : }
361 : :
362 : :
363 : :
364 : :
365 : :
366 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|