fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sc / source / ui / miscdlgs / tabopdlg.cxx
blob443b87e4bcf5b0dc7b8f1436dffef4a23dd0a8a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scitems.hxx"
21 #include <sfx2/dispatch.hxx>
22 #include <vcl/msgbox.hxx>
24 #include "uiitems.hxx"
25 #include "global.hxx"
26 #include "document.hxx"
27 #include "scresid.hxx"
28 #include "sc.hrc"
29 #include "reffact.hxx"
30 #include "tabopdlg.hrc"
32 #define _TABOPDLG_CXX
33 #include "tabopdlg.hxx"
36 //============================================================================
37 // class ScTabOpDlg
38 //----------------------------------------------------------------------------
40 ScTabOpDlg::ScTabOpDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
41 ScDocument* pDocument,
42 const ScRefAddress& rCursorPos )
44 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_TABOP ),
46 aFlVariables ( this, ScResId( FL_VARIABLES ) ),
47 aFtFormulaRange ( this, ScResId( FT_FORMULARANGE ) ),
48 aEdFormulaRange ( this, this, &aFtFormulaRange, ScResId( ED_FORMULARANGE ) ),
49 aRBFormulaRange ( this, ScResId( RB_FORMULARANGE ), &aEdFormulaRange, this ),
50 aFtRowCell ( this, ScResId( FT_ROWCELL ) ),
51 aEdRowCell ( this, this, &aFtRowCell, ScResId( ED_ROWCELL ) ),
52 aRBRowCell ( this, ScResId( RB_ROWCELL ), &aEdRowCell, this ),
53 aFtColCell ( this, ScResId( FT_COLCELL ) ),
54 aEdColCell ( this, this, &aFtColCell, ScResId( ED_COLCELL ) ),
55 aRBColCell ( this, ScResId( RB_COLCELL ), &aEdColCell, this ),
56 aBtnOk ( this, ScResId( BTN_OK ) ),
57 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
58 aBtnHelp ( this, ScResId( BTN_HELP ) ),
60 theFormulaCell ( rCursorPos ),
61 pDoc ( pDocument ),
62 nCurTab ( theFormulaCell.Tab() ),
63 pEdActive ( NULL ),
64 bDlgLostFocus ( false ),
65 errMsgNoFormula ( ScResId( STR_NOFORMULA ) ),
66 errMsgNoColRow ( ScResId( STR_NOCOLROW ) ),
67 errMsgWrongFormula ( ScResId( STR_WRONGFORMULA ) ),
68 errMsgWrongRowCol ( ScResId( STR_WRONGROWCOL ) ),
69 errMsgNoColFormula ( ScResId( STR_NOCOLFORMULA ) ),
70 errMsgNoRowFormula ( ScResId( STR_NOROWFORMULA ) )
72 Init();
73 FreeResource();
76 //----------------------------------------------------------------------------
78 ScTabOpDlg::~ScTabOpDlg()
80 Hide();
83 //----------------------------------------------------------------------------
85 void ScTabOpDlg::Init()
87 aBtnOk. SetClickHdl ( LINK( this, ScTabOpDlg, BtnHdl ) );
88 aBtnCancel. SetClickHdl ( LINK( this, ScTabOpDlg, BtnHdl ) );
90 Link aLink = LINK( this, ScTabOpDlg, GetFocusHdl );
91 aEdFormulaRange.SetGetFocusHdl( aLink );
92 aRBFormulaRange.SetGetFocusHdl( aLink );
93 aEdRowCell. SetGetFocusHdl( aLink );
94 aRBRowCell. SetGetFocusHdl( aLink );
95 aEdColCell. SetGetFocusHdl( aLink );
96 aRBColCell. SetGetFocusHdl( aLink );
98 aLink = LINK( this, ScTabOpDlg, LoseFocusHdl );
99 aEdFormulaRange.SetLoseFocusHdl( aLink );
100 aRBFormulaRange.SetLoseFocusHdl( aLink );
101 aEdRowCell. SetLoseFocusHdl( aLink );
102 aRBRowCell. SetLoseFocusHdl( aLink );
103 aEdColCell. SetLoseFocusHdl( aLink );
104 aRBColCell. SetLoseFocusHdl( aLink );
106 aEdFormulaRange.GrabFocus();
107 pEdActive = &aEdFormulaRange;
109 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
110 //SFX_APPWINDOW->Enable();
113 //----------------------------------------------------------------------------
115 sal_Bool ScTabOpDlg::Close()
117 return DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
120 //----------------------------------------------------------------------------
122 void ScTabOpDlg::SetActive()
124 if ( bDlgLostFocus )
126 bDlgLostFocus = false;
127 if( pEdActive )
128 pEdActive->GrabFocus();
130 else
131 GrabFocus();
133 RefInputDone();
136 //----------------------------------------------------------------------------
138 void ScTabOpDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
140 if ( pEdActive )
142 ScAddress::Details aDetails(pDocP->GetAddressConvention(), 0, 0);
144 if ( rRef.aStart != rRef.aEnd )
145 RefInputStart(pEdActive);
147 String aStr;
148 sal_uInt16 nFmt = ( rRef.aStart.Tab() == nCurTab )
149 ? SCR_ABS
150 : SCR_ABS_3D;
152 if ( pEdActive == &aEdFormulaRange )
154 theFormulaCell.Set( rRef.aStart, false, false, false);
155 theFormulaEnd.Set( rRef.aEnd, false, false, false);
156 rRef.Format( aStr, nFmt, pDocP, aDetails );
158 else if ( pEdActive == &aEdRowCell )
160 theRowCell.Set( rRef.aStart, false, false, false);
161 rRef.aStart.Format( aStr, nFmt, pDocP, aDetails );
163 else if ( pEdActive == &aEdColCell )
165 theColCell.Set( rRef.aStart, false, false, false);
166 rRef.aStart.Format( aStr, nFmt, pDocP, aDetails );
169 pEdActive->SetRefString( aStr );
173 //----------------------------------------------------------------------------
175 void ScTabOpDlg::RaiseError( ScTabOpErr eError )
177 const String* pMsg = &errMsgNoFormula;
178 Edit* pEd = &aEdFormulaRange;
180 switch ( eError )
182 case TABOPERR_NOFORMULA:
183 pMsg = &errMsgNoFormula;
184 pEd = &aEdFormulaRange;
185 break;
187 case TABOPERR_NOCOLROW:
188 pMsg = &errMsgNoColRow;
189 pEd = &aEdRowCell;
190 break;
192 case TABOPERR_WRONGFORMULA:
193 pMsg = &errMsgWrongFormula;
194 pEd = &aEdFormulaRange;
195 break;
197 case TABOPERR_WRONGROW:
198 pMsg = &errMsgWrongRowCol;
199 pEd = &aEdRowCell;
200 break;
202 case TABOPERR_NOCOLFORMULA:
203 pMsg = &errMsgNoColFormula;
204 pEd = &aEdFormulaRange;
205 break;
207 case TABOPERR_WRONGCOL:
208 pMsg = &errMsgWrongRowCol;
209 pEd = &aEdColCell;
210 break;
212 case TABOPERR_NOROWFORMULA:
213 pMsg = &errMsgNoRowFormula;
214 pEd = &aEdFormulaRange;
215 break;
218 ErrorBox( this, WinBits( WB_OK_CANCEL | WB_DEF_OK), *pMsg ).Execute();
219 pEd->GrabFocus();
222 //----------------------------------------------------------------------------
224 static sal_Bool lcl_Parse( const String& rString, ScDocument* pDoc, SCTAB nCurTab,
225 ScRefAddress& rStart, ScRefAddress& rEnd )
227 sal_Bool bRet = false;
228 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
229 if ( rString.Search(':') != STRING_NOTFOUND )
230 bRet = ConvertDoubleRef( pDoc, rString, nCurTab, rStart, rEnd, eConv );
231 else
233 bRet = ConvertSingleRef( pDoc, rString, nCurTab, rStart, eConv );
234 rEnd = rStart;
236 return bRet;
239 //----------------------------------------------------------------------------
240 // Handler:
242 IMPL_LINK( ScTabOpDlg, BtnHdl, PushButton*, pBtn )
244 if ( pBtn == &aBtnOk )
246 sal_uInt8 nMode = 3;
247 sal_uInt16 nError = 0;
249 // Zu ueberpruefen:
250 // 1. enthalten die Strings korrekte Tabellenkoordinaten/def.Namen?
251 // 2. IstFormelRang Zeile bei leerer Zeile bzw. Spalte bei leerer Spalte
252 // bzw. Einfachreferenz bei beidem?
253 // 3. Ist mindestens Zeile oder Spalte und Formel voll?
255 if (aEdFormulaRange.GetText().isEmpty())
256 nError = TABOPERR_NOFORMULA;
257 else if (aEdRowCell.GetText().isEmpty() &&
258 aEdColCell.GetText().isEmpty())
259 nError = TABOPERR_NOCOLROW;
260 else if ( !lcl_Parse( aEdFormulaRange.GetText(), pDoc, nCurTab,
261 theFormulaCell, theFormulaEnd ) )
262 nError = TABOPERR_WRONGFORMULA;
263 else
265 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
266 if (!aEdRowCell.GetText().isEmpty())
268 if (!ConvertSingleRef( pDoc, aEdRowCell.GetText(), nCurTab,
269 theRowCell, eConv ))
270 nError = TABOPERR_WRONGROW;
271 else
273 if (aEdColCell.GetText().isEmpty() &&
274 theFormulaCell.Col() != theFormulaEnd.Col())
275 nError = TABOPERR_NOCOLFORMULA;
276 else
277 nMode = 1;
280 if (!aEdColCell.GetText().isEmpty())
282 if (!ConvertSingleRef( pDoc, aEdColCell.GetText(), nCurTab,
283 theColCell, eConv ))
284 nError = TABOPERR_WRONGCOL;
285 else
287 if (nMode == 1) // beides
289 nMode = 2;
290 ConvertSingleRef( pDoc, aEdFormulaRange.GetText(), nCurTab,
291 theFormulaCell, eConv );
293 else if (theFormulaCell.Row() != theFormulaEnd.Row())
294 nError = TABOPERR_NOROWFORMULA;
295 else
296 nMode = 0;
301 if (nError)
302 RaiseError( (ScTabOpErr) nError );
303 else
305 ScTabOpParam aOutParam( theFormulaCell,
306 theFormulaEnd,
307 theRowCell,
308 theColCell,
309 nMode );
310 ScTabOpItem aOutItem( SID_TABOP, &aOutParam );
312 SetDispatcherLock( false );
313 SwitchToDocument();
314 GetBindings().GetDispatcher()->Execute( SID_TABOP,
315 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
316 &aOutItem, 0L, 0L );
317 Close();
320 else if ( pBtn == &aBtnCancel )
321 Close();
323 return 0;
326 //----------------------------------------------------------------------------
328 IMPL_LINK( ScTabOpDlg, GetFocusHdl, Control*, pCtrl )
330 if( (pCtrl == (Control*)&aEdFormulaRange) || (pCtrl == (Control*)&aRBFormulaRange) )
331 pEdActive = &aEdFormulaRange;
332 else if( (pCtrl == (Control*)&aEdRowCell) || (pCtrl == (Control*)&aRBRowCell) )
333 pEdActive = &aEdRowCell;
334 else if( (pCtrl == (Control*)&aEdColCell) || (pCtrl == (Control*)&aRBColCell) )
335 pEdActive = &aEdColCell;
336 else
337 pEdActive = NULL;
339 if( pEdActive )
340 pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
342 return 0;
345 //----------------------------------------------------------------------------
347 IMPL_LINK_NOARG(ScTabOpDlg, LoseFocusHdl)
349 bDlgLostFocus = !IsActive();
350 return 0;
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */