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 : : #ifndef SC_VALIDATE_HXX
30 : : #define SC_VALIDATE_HXX
31 : :
32 : : #include <sfx2/tabdlg.hxx>
33 : : #include <vcl/edit.hxx>
34 : : #include <vcl/fixed.hxx>
35 : : #include <vcl/lstbox.hxx>
36 : : #include <svtools/svmedit.hxx>
37 : :
38 : : #include "anyrefdg.hxx"
39 : :
40 : : // ============================================================================
41 : :
42 : 0 : struct ScRefHandlerCaller{
43 [ # # ]: 0 : virtual ~ScRefHandlerCaller(){}
44 : : };
45 : : class ScRefHandlerHelper
46 : : {
47 : : protected:
48 : : ScRefHandlerCaller *m_pHandler;
49 : : void (ScRefHandlerCaller::*m_pSetReferenceHdl)( const ScRange& , ScDocument* );
50 : : void (ScRefHandlerCaller::*m_pSetActiveHdl)();
51 : : void (ScRefHandlerCaller::*m_pRefInputStartPreHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
52 : : void (ScRefHandlerCaller::*m_pRefInputStartPostHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
53 : : void (ScRefHandlerCaller::*m_pRefInputDonePreHdl)();
54 : : void (ScRefHandlerCaller::*m_pRefInputDonePostHdl)();
55 : :
56 : : public:
57 : : typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE)( const ScRange& , ScDocument* );
58 : : typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE)();
59 : : typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE)( formula::RefEdit* pEdit, formula::RefButton* pButton );
60 : :
61 : 0 : PFUNCSETREFHDLTYPE SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl )
62 : : {
63 : 0 : PFUNCSETREFHDLTYPE pOldHdl = m_pSetReferenceHdl;
64 : 0 : m_pSetReferenceHdl = pNewHdl;
65 : 0 : return pOldHdl;
66 : : }
67 : :
68 : 0 : PCOMMONHDLTYPE SetSetActHdl( PCOMMONHDLTYPE pNewHdl )
69 : : {
70 : 0 : PCOMMONHDLTYPE pOldHdl = m_pSetActiveHdl;
71 : 0 : m_pSetActiveHdl = pNewHdl;
72 : 0 : return pOldHdl;
73 : : }
74 : :
75 : 0 : ScRefHandlerCaller *SetHandler( ScRefHandlerCaller *pNewHandler )
76 : : {
77 : 0 : ScRefHandlerCaller *pOldHandler = m_pHandler;
78 : 0 : m_pHandler = pNewHandler;
79 : 0 : return pOldHandler;
80 : : }
81 : 0 : void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPreHdl = pNewHdl; }
82 : 0 : void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePostHdl = pNewHdl; }
83 : : void SetRefInputStartPostHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPostHdl = pNewHdl; }
84 : 0 : void SetRefInputDonePreHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePreHdl = pNewHdl; }
85 : :
86 : 0 : ScRefHandlerHelper():m_pHandler(NULL), m_pSetReferenceHdl( NULL ), m_pSetActiveHdl(NULL), m_pRefInputStartPreHdl( NULL ), m_pRefInputStartPostHdl( NULL ), m_pRefInputDonePreHdl( NULL ), m_pRefInputDonePostHdl( NULL ){}
87 : : };
88 : :
89 : : /** The "Validity" tab dialog. */
90 : : class ScValidationDlg :public ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false>, public ScRefHandlerHelper
91 : : {
92 : : typedef ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false> ScValidationDlgBase;
93 : :
94 : : DECL_LINK( OkHdl, Button * );
95 : :
96 : : bool m_bOwnRefHdlr:1;
97 : :
98 : : ScTabViewShell *m_pTabVwSh;
99 : : bool m_bRefInputting:1;
100 : : bool EnterRefStatus();
101 : : bool LeaveRefStatus();
102 : :
103 : : public:
104 : : explicit ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet, ScTabViewShell * pTabViewSh, SfxBindings *pB = NULL );
105 : : virtual ~ScValidationDlg();
106 : : inline static ScValidationDlg * Find1AliveObject( Window *pAncestor );
107 : : bool IsAlive();
108 : : inline ScTabViewShell * GetTabViewShell();
109 : :
110 : : bool SetupRefDlg();
111 : : bool RemoveRefDlg( sal_Bool bRestoreModal = sal_True );
112 : :
113 : 0 : virtual void SetModal( sal_Bool bModal ){ ScValidationDlgBase::SetModalInputMode( bModal ); }
114 : :
115 : 0 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc )
116 : : {
117 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pSetReferenceHdl )
118 [ # # ]: 0 : (m_pHandler->*m_pSetReferenceHdl)( rRef, pDoc );
119 : 0 : }
120 : :
121 : 0 : virtual void SetActive()
122 : : {
123 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pSetActiveHdl )
124 [ # # ]: 0 : (m_pHandler->*m_pSetActiveHdl)();
125 : 0 : }
126 : :
127 : : void CloseRefDialog()
128 : : {
129 : : OSL_FAIL( "should not execute here!!!when the edit kill focus, should remove refhandler.\r\n" );
130 : :
131 : : if ( IsInExecute() )
132 : : EndDialog( false );
133 : : else if ( GetStyle() & WB_CLOSEABLE )
134 : : Close();
135 : : }
136 : :
137 : 0 : bool IsRefInputting(){ return m_bRefInputting; }
138 : :
139 : 0 : virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL )
140 : : {
141 [ # # ]: 0 : if( !CanInputStart( pEdit ) )
142 : 0 : return;
143 : :
144 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pRefInputStartPreHdl )
145 [ # # ]: 0 : (m_pHandler->*m_pRefInputStartPreHdl)( pEdit, pButton );
146 : 0 : m_bRefInputting = true;
147 : 0 : ScValidationDlgBase::RefInputStart( pEdit, pButton );
148 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pRefInputStartPostHdl )
149 [ # # ]: 0 : (m_pHandler->*m_pRefInputStartPostHdl)( pEdit, pButton );
150 : : }
151 : :
152 : 0 : virtual void RefInputDone( sal_Bool bForced = false )
153 : : {
154 [ # # ]: 0 : if( !CanInputDone( bForced ) )
155 : 0 : return;
156 : :
157 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pRefInputDonePreHdl )
158 [ # # ]: 0 : (m_pHandler->*m_pRefInputDonePreHdl)();
159 : :
160 : 0 : ScValidationDlgBase::RefInputDone( bForced );
161 : 0 : m_bRefInputting = false;
162 : :
163 [ # # ][ # # ]: 0 : if ( m_pHandler && m_pRefInputDonePostHdl )
164 [ # # ]: 0 : (m_pHandler->*m_pRefInputDonePostHdl)();
165 : : }
166 : :
167 : : sal_Bool IsChildFocus();
168 : :
169 : : enum { SLOTID = SID_VALIDITY_REFERENCE };
170 : :
171 : : sal_Bool Close();
172 : : };
173 : :
174 : :
175 : : // ============================================================================
176 : :
177 : : /** The tab page "Criteria" from the Validation dialog. */
178 : : class ScTPValidationValue : public ScRefHandlerCaller, public SfxTabPage
179 : : {
180 : : public:
181 : : explicit ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet );
182 : : virtual ~ScTPValidationValue();
183 : :
184 : : static SfxTabPage* Create( Window* pParent, const SfxItemSet& rArgSet );
185 : : static sal_uInt16* GetRanges();
186 : :
187 : : virtual sal_Bool FillItemSet( SfxItemSet& rArgSet );
188 : : virtual void Reset( const SfxItemSet& rArgSet );
189 : :
190 : : private:
191 : : void Init();
192 : :
193 : : String GetFirstFormula() const;
194 : : String GetSecondFormula() const;
195 : :
196 : : void SetFirstFormula( const String& rFmlaStr );
197 : : void SetSecondFormula( const String& rFmlaStr );
198 : :
199 : : DECL_LINK(SelectHdl, void *);
200 : : DECL_LINK(CheckHdl, void *);
201 : :
202 : : FixedText maFtAllow;
203 : : ListBox maLbAllow;
204 : : CheckBox maCbAllow; /// Allow blank cells.
205 : : CheckBox maCbShow; /// Show selection list in cell.
206 : : CheckBox maCbSort; /// Sort selection list in cell.
207 : : FixedText maFtValue;
208 : : ListBox maLbValue;
209 : : FixedText maFtMin;
210 : : formula::RefEdit maEdMin;
211 : : MultiLineEdit maEdList; /// Entries for explicit list
212 : : FixedText maFtMax;
213 : : formula::RefEdit maEdMax;
214 : : FixedText maFtHint; /// Hint text for cell range validity.
215 : :
216 : : String maStrMin;
217 : : String maStrMax;
218 : : String maStrValue;
219 : : String maStrRange;
220 : : String maStrList;
221 : : sal_Unicode mcFmlaSep; /// List separator in formulas.
222 : :
223 : : DECL_LINK(EditSetFocusHdl, void *);
224 : : DECL_LINK( KillFocusHdl, Window *);
225 : : void OnClick( Button *pBtn );
226 : : formula::RefEdit* m_pRefEdit;
227 : 0 : class ScRefButtonEx:public ::formula::RefButton
228 : : {
229 : : void Click();
230 : : public:
231 : 0 : ScRefButtonEx( Window* pParent, const ResId& rResId, formula::RefEdit* pEdit = NULL, ScRefHandler *pRefHdlr = NULL ): ::formula::RefButton( pParent, rResId, pEdit, pRefHdlr ){}
232 : : }m_btnRef;
233 : : friend class ScRefButtonEx;
234 : : void SetReferenceHdl( const ScRange& , ScDocument* );
235 : : void SetActiveHdl();
236 : : void RefInputStartPreHdl( formula::RefEdit* pEdit, formula::RefButton* pButton );
237 : : void RefInputDonePreHdl();
238 : : void RefInputDonePostHdl();
239 : : ScValidationDlg * GetValidationDlg();
240 : :
241 : : void TidyListBoxes();
242 : : public:
243 : : sal_uInt16 GetAllowEntryPos();
244 : : String GetMinText();
245 : : void SetupRefDlg();
246 : : void RemoveRefDlg();
247 : : };
248 : :
249 : :
250 : : //==================================================================
251 : :
252 : : class ScTPValidationHelp : public SfxTabPage
253 : : {
254 : : private:
255 : : TriStateBox aTsbHelp;
256 : : FixedLine aFlContent;
257 : : FixedText aFtTitle;
258 : : Edit aEdtTitle;
259 : : FixedText aFtInputHelp;
260 : : MultiLineEdit aEdInputHelp;
261 : :
262 : : const SfxItemSet& mrArgSet;
263 : :
264 : : void Init();
265 : :
266 : : // Handler ------------------------
267 : : // DECL_LINK( SelectHdl, ListBox * );
268 : :
269 : : public:
270 : : ScTPValidationHelp( Window* pParent, const SfxItemSet& rArgSet );
271 : : ~ScTPValidationHelp();
272 : :
273 : : static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
274 : : static sal_uInt16* GetRanges ();
275 : : virtual sal_Bool FillItemSet ( SfxItemSet& rArgSet );
276 : : virtual void Reset ( const SfxItemSet& rArgSet );
277 : : };
278 : :
279 : : //==================================================================
280 : :
281 : : class ScTPValidationError : public SfxTabPage
282 : : {
283 : : private:
284 : : TriStateBox aTsbShow;
285 : : FixedLine aFlContent;
286 : : FixedText aFtAction;
287 : : ListBox aLbAction;
288 : : PushButton aBtnSearch;
289 : : FixedText aFtTitle;
290 : : Edit aEdtTitle;
291 : : FixedText aFtError;
292 : : MultiLineEdit aEdError;
293 : :
294 : : const SfxItemSet& mrArgSet;
295 : :
296 : : void Init();
297 : :
298 : : // Handler ------------------------
299 : : DECL_LINK(SelectActionHdl, void *);
300 : : DECL_LINK(ClickSearchHdl, void *);
301 : :
302 : : public:
303 : : ScTPValidationError( Window* pParent, const SfxItemSet& rArgSet );
304 : : ~ScTPValidationError();
305 : :
306 : : static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
307 : : static sal_uInt16* GetRanges ();
308 : : virtual sal_Bool FillItemSet ( SfxItemSet& rArgSet );
309 : : virtual void Reset ( const SfxItemSet& rArgSet );
310 : : };
311 : :
312 : 0 : inline ScTabViewShell *ScValidationDlg::GetTabViewShell()
313 : : {
314 : 0 : return m_pTabVwSh;
315 : : }
316 : :
317 : 0 : inline ScValidationDlg * ScValidationDlg::Find1AliveObject( Window *pAncestor )
318 : : {
319 : 0 : return static_cast<ScValidationDlg *>( SC_MOD()->Find1RefWindow( SLOTID, pAncestor ) );
320 : : }
321 : :
322 : : #endif // SC_VALIDATE_HXX
323 : :
324 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|