1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabopdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //----------------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <sfx2/dispatch.hxx>
40 #include <vcl/msgbox.hxx>
42 #include "uiitems.hxx"
44 #include "document.hxx"
45 #include "scresid.hxx"
47 #include "reffact.hxx"
48 #include "tabopdlg.hrc"
51 #include "tabopdlg.hxx"
54 //============================================================================
56 //----------------------------------------------------------------------------
58 ScTabOpDlg::ScTabOpDlg( SfxBindings
* pB
, SfxChildWindow
* pCW
, Window
* pParent
,
59 ScDocument
* pDocument
,
60 const ScRefAddress
& rCursorPos
)
62 : ScAnyRefDlg ( pB
, pCW
, pParent
, RID_SCDLG_TABOP
),
64 aFlVariables ( this, ScResId( FL_VARIABLES
) ),
65 aFtFormulaRange ( this, ScResId( FT_FORMULARANGE
) ),
66 aEdFormulaRange ( this, this, ScResId( ED_FORMULARANGE
) ),
67 aRBFormulaRange ( this, ScResId( RB_FORMULARANGE
), &aEdFormulaRange
, this ),
68 aFtRowCell ( this, ScResId( FT_ROWCELL
) ),
69 aEdRowCell ( this, this, ScResId( ED_ROWCELL
) ),
70 aRBRowCell ( this, ScResId( RB_ROWCELL
), &aEdRowCell
, this ),
71 aFtColCell ( this, ScResId( FT_COLCELL
) ),
72 aEdColCell ( this, this, ScResId( ED_COLCELL
) ),
73 aRBColCell ( this, ScResId( RB_COLCELL
), &aEdColCell
, this ),
74 aBtnOk ( this, ScResId( BTN_OK
) ),
75 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
76 aBtnHelp ( this, ScResId( BTN_HELP
) ),
78 theFormulaCell ( rCursorPos
),
80 nCurTab ( theFormulaCell
.Tab() ),
82 bDlgLostFocus ( FALSE
),
83 errMsgNoFormula ( ScResId( STR_NOFORMULA
) ),
84 errMsgNoColRow ( ScResId( STR_NOCOLROW
) ),
85 errMsgWrongFormula ( ScResId( STR_WRONGFORMULA
) ),
86 errMsgWrongRowCol ( ScResId( STR_WRONGROWCOL
) ),
87 errMsgNoColFormula ( ScResId( STR_NOCOLFORMULA
) ),
88 errMsgNoRowFormula ( ScResId( STR_NOROWFORMULA
) )
94 //----------------------------------------------------------------------------
96 __EXPORT
ScTabOpDlg::~ScTabOpDlg()
101 //----------------------------------------------------------------------------
103 void __EXPORT
ScTabOpDlg::Init()
105 aBtnOk
. SetClickHdl ( LINK( this, ScTabOpDlg
, BtnHdl
) );
106 aBtnCancel
. SetClickHdl ( LINK( this, ScTabOpDlg
, BtnHdl
) );
108 Link aLink
= LINK( this, ScTabOpDlg
, GetFocusHdl
);
109 aEdFormulaRange
.SetGetFocusHdl( aLink
);
110 aRBFormulaRange
.SetGetFocusHdl( aLink
);
111 aEdRowCell
. SetGetFocusHdl( aLink
);
112 aRBRowCell
. SetGetFocusHdl( aLink
);
113 aEdColCell
. SetGetFocusHdl( aLink
);
114 aRBColCell
. SetGetFocusHdl( aLink
);
116 aLink
= LINK( this, ScTabOpDlg
, LoseFocusHdl
);
117 aEdFormulaRange
.SetLoseFocusHdl( aLink
);
118 aRBFormulaRange
.SetLoseFocusHdl( aLink
);
119 aEdRowCell
. SetLoseFocusHdl( aLink
);
120 aRBRowCell
. SetLoseFocusHdl( aLink
);
121 aEdColCell
. SetLoseFocusHdl( aLink
);
122 aRBColCell
. SetLoseFocusHdl( aLink
);
124 aEdFormulaRange
.GrabFocus();
125 pEdActive
= &aEdFormulaRange
;
127 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
128 //SFX_APPWINDOW->Enable();
131 //----------------------------------------------------------------------------
133 BOOL __EXPORT
ScTabOpDlg::Close()
135 return DoClose( ScTabOpDlgWrapper::GetChildWindowId() );
138 //----------------------------------------------------------------------------
140 void ScTabOpDlg::SetActive()
144 bDlgLostFocus
= FALSE
;
146 pEdActive
->GrabFocus();
154 //----------------------------------------------------------------------------
156 void ScTabOpDlg::SetReference( const ScRange
& rRef
, ScDocument
* pDocP
)
160 ScAddress::Details
aDetails(pDocP
->GetAddressConvention(), 0, 0);
162 if ( rRef
.aStart
!= rRef
.aEnd
)
163 RefInputStart(pEdActive
);
166 USHORT nFmt
= ( rRef
.aStart
.Tab() == nCurTab
)
170 if ( pEdActive
== &aEdFormulaRange
)
172 theFormulaCell
.Set( rRef
.aStart
, false, false, false);
173 theFormulaEnd
.Set( rRef
.aEnd
, false, false, false);
174 rRef
.Format( aStr
, nFmt
, pDocP
, aDetails
);
176 else if ( pEdActive
== &aEdRowCell
)
178 theRowCell
.Set( rRef
.aStart
, false, false, false);
179 rRef
.aStart
.Format( aStr
, nFmt
, pDocP
, aDetails
);
181 else if ( pEdActive
== &aEdColCell
)
183 theColCell
.Set( rRef
.aStart
, false, false, false);
184 rRef
.aStart
.Format( aStr
, nFmt
, pDocP
, aDetails
);
187 pEdActive
->SetRefString( aStr
);
191 //----------------------------------------------------------------------------
193 void ScTabOpDlg::RaiseError( ScTabOpErr eError
)
195 const String
* pMsg
= &errMsgNoFormula
;
196 Edit
* pEd
= &aEdFormulaRange
;
200 case TABOPERR_NOFORMULA
:
201 pMsg
= &errMsgNoFormula
;
202 pEd
= &aEdFormulaRange
;
205 case TABOPERR_NOCOLROW
:
206 pMsg
= &errMsgNoColRow
;
210 case TABOPERR_WRONGFORMULA
:
211 pMsg
= &errMsgWrongFormula
;
212 pEd
= &aEdFormulaRange
;
215 case TABOPERR_WRONGROW
:
216 pMsg
= &errMsgWrongRowCol
;
220 case TABOPERR_NOCOLFORMULA
:
221 pMsg
= &errMsgNoColFormula
;
222 pEd
= &aEdFormulaRange
;
225 case TABOPERR_WRONGCOL
:
226 pMsg
= &errMsgWrongRowCol
;
230 case TABOPERR_NOROWFORMULA
:
231 pMsg
= &errMsgNoRowFormula
;
232 pEd
= &aEdFormulaRange
;
236 ErrorBox( this, WinBits( WB_OK_CANCEL
| WB_DEF_OK
), *pMsg
).Execute();
240 //----------------------------------------------------------------------------
242 BOOL
lcl_Parse( const String
& rString
, ScDocument
* pDoc
, SCTAB nCurTab
,
243 ScRefAddress
& rStart
, ScRefAddress
& rEnd
)
246 const formula::FormulaGrammar::AddressConvention eConv
= pDoc
->GetAddressConvention();
247 if ( rString
.Search(':') != STRING_NOTFOUND
)
248 bRet
= ConvertDoubleRef( pDoc
, rString
, nCurTab
, rStart
, rEnd
, eConv
);
251 bRet
= ConvertSingleRef( pDoc
, rString
, nCurTab
, rStart
, eConv
);
257 //----------------------------------------------------------------------------
260 IMPL_LINK( ScTabOpDlg
, BtnHdl
, PushButton
*, pBtn
)
262 if ( pBtn
== &aBtnOk
)
268 // 1. enthalten die Strings korrekte Tabellenkoordinaten/def.Namen?
269 // 2. IstFormelRang Zeile bei leerer Zeile bzw. Spalte bei leerer Spalte
270 // bzw. Einfachreferenz bei beidem?
271 // 3. Ist mindestens Zeile oder Spalte und Formel voll?
273 if (aEdFormulaRange
.GetText().Len() == 0)
274 nError
= TABOPERR_NOFORMULA
;
275 else if (aEdRowCell
.GetText().Len() == 0 &&
276 aEdColCell
.GetText().Len() == 0)
277 nError
= TABOPERR_NOCOLROW
;
278 else if ( !lcl_Parse( aEdFormulaRange
.GetText(), pDoc
, nCurTab
,
279 theFormulaCell
, theFormulaEnd
) )
280 nError
= TABOPERR_WRONGFORMULA
;
283 const formula::FormulaGrammar::AddressConvention eConv
= pDoc
->GetAddressConvention();
284 if (aEdRowCell
.GetText().Len() > 0)
286 if (!ConvertSingleRef( pDoc
, aEdRowCell
.GetText(), nCurTab
,
288 nError
= TABOPERR_WRONGROW
;
291 if (aEdColCell
.GetText().Len() == 0 &&
292 theFormulaCell
.Col() != theFormulaEnd
.Col())
293 nError
= TABOPERR_NOCOLFORMULA
;
298 if (aEdColCell
.GetText().Len() > 0)
300 if (!ConvertSingleRef( pDoc
, aEdColCell
.GetText(), nCurTab
,
302 nError
= TABOPERR_WRONGCOL
;
305 if (nMode
== 1) // beides
308 ConvertSingleRef( pDoc
, aEdFormulaRange
.GetText(), nCurTab
,
309 theFormulaCell
, eConv
);
311 else if (theFormulaCell
.Row() != theFormulaEnd
.Row())
312 nError
= TABOPERR_NOROWFORMULA
;
320 RaiseError( (ScTabOpErr
) nError
);
323 ScTabOpParam
aOutParam( theFormulaCell
,
328 ScTabOpItem
aOutItem( SID_TABOP
, &aOutParam
);
330 SetDispatcherLock( FALSE
);
332 GetBindings().GetDispatcher()->Execute( SID_TABOP
,
333 SFX_CALLMODE_SLOT
| SFX_CALLMODE_RECORD
,
338 else if ( pBtn
== &aBtnCancel
)
344 //----------------------------------------------------------------------------
346 IMPL_LINK( ScTabOpDlg
, GetFocusHdl
, Control
*, pCtrl
)
348 if( (pCtrl
== (Control
*)&aEdFormulaRange
) || (pCtrl
== (Control
*)&aRBFormulaRange
) )
349 pEdActive
= &aEdFormulaRange
;
350 else if( (pCtrl
== (Control
*)&aEdRowCell
) || (pCtrl
== (Control
*)&aRBRowCell
) )
351 pEdActive
= &aEdRowCell
;
352 else if( (pCtrl
== (Control
*)&aEdColCell
) || (pCtrl
== (Control
*)&aRBColCell
) )
353 pEdActive
= &aEdColCell
;
358 pEdActive
->SetSelection( Selection( 0, SELECTION_MAX
) );
363 //----------------------------------------------------------------------------
365 IMPL_LINK( ScTabOpDlg
, LoseFocusHdl
, Control
*, EMPTYARG
)
367 bDlgLostFocus
= !IsActive();