1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef SC_VALIDATE_HXX
25 #define SC_VALIDATE_HXX
26
27 #include <sfx2/tabdlg.hxx>
28 #include <vcl/edit.hxx>
29 #include <vcl/fixed.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <svtools/svmedit.hxx>
32 //<!--Added by PengYunQuan for Validity Cell Range Picker
33 #include "anyrefdg.hxx"
34 //-->Added by PengYunQuan for Validity Cell Range Picker
35
36 // ============================================================================
37
38 //<!--Added by PengYunQuan for Validity Cell Range Picker
39 struct ScRefHandlerCaller{
~ScRefHandlerCallerScRefHandlerCaller40 virtual ~ScRefHandlerCaller(){}
41 };
42 class ScRefHandlerHelper
43 {
44 protected:
45 ScRefHandlerCaller *m_pHandler;
46 void (ScRefHandlerCaller::*m_pSetReferenceHdl)( const ScRange& , ScDocument* );
47 void (ScRefHandlerCaller::*m_pSetActiveHdl)();
48 void (ScRefHandlerCaller::*m_pRefInputStartPreHdl)( ScRefEdit* pEdit, ScRefButton* pButton );
49 void (ScRefHandlerCaller::*m_pRefInputStartPostHdl)( ScRefEdit* pEdit, ScRefButton* pButton );
50 void (ScRefHandlerCaller::*m_pRefInputDonePreHdl)();
51 void (ScRefHandlerCaller::*m_pRefInputDonePostHdl)();
52
53 public:
54 typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE)( const ScRange& , ScDocument* );
55 typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE)();
56 typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE)( ScRefEdit* pEdit, ScRefButton* pButton );
57
SetSetRefHdl(PFUNCSETREFHDLTYPE pNewHdl)58 PFUNCSETREFHDLTYPE SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl )
59 {
60 PFUNCSETREFHDLTYPE pOldHdl = m_pSetReferenceHdl;
61 m_pSetReferenceHdl = pNewHdl;
62 return pOldHdl;
63 }
64
SetSetActHdl(PCOMMONHDLTYPE pNewHdl)65 PCOMMONHDLTYPE SetSetActHdl( PCOMMONHDLTYPE pNewHdl )
66 {
67 PCOMMONHDLTYPE pOldHdl = m_pSetActiveHdl;
68 m_pSetActiveHdl = pNewHdl;
69 return pOldHdl;
70 }
71
SetHandler(ScRefHandlerCaller * pNewHandler)72 ScRefHandlerCaller *SetHandler( ScRefHandlerCaller *pNewHandler )
73 {
74 ScRefHandlerCaller *pOldHandler = m_pHandler;
75 m_pHandler = pNewHandler;
76 return pOldHandler;
77 }
SetRefInputStartPreHdl(PINPUTSTARTDLTYPE pNewHdl)78 void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPreHdl = pNewHdl; }
SetRefInputDonePostHdl(void (ScRefHandlerCaller::* pNewHdl)())79 void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePostHdl = pNewHdl; }
SetRefInputStartPostHdl(PINPUTSTARTDLTYPE pNewHdl)80 void SetRefInputStartPostHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPostHdl = pNewHdl; }
SetRefInputDonePreHdl(void (ScRefHandlerCaller::* pNewHdl)())81 void SetRefInputDonePreHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePreHdl = pNewHdl; }
82
ScRefHandlerHelper()83 ScRefHandlerHelper():m_pHandler(NULL), m_pSetReferenceHdl( NULL ), m_pSetActiveHdl(NULL), m_pRefInputStartPreHdl( NULL ), m_pRefInputStartPostHdl( NULL ), m_pRefInputDonePreHdl( NULL ), m_pRefInputDonePostHdl( NULL ){}
84 };
85 //-->Added by PengYunQuan for Validity Cell Range Picker
86
87 /** The "Validity" tab dialog. */
88 //<!--Modified by PengYunQuan for Validity Cell Range Picker
89 //class ScValidationDlg : public SfxTabDialog
90 class ScValidationDlg :public ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false>, public ScRefHandlerHelper
91 //-->Modified by PengYunQuan for Validity Cell Range Picker
92 {
93 //<!--Added by PengYunQuan for Validity Cell Range Picker
94 typedef ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false> ScValidationDlgBase;
95
96 DECL_LINK( OkHdl, Button * );
97
98 bool m_bOwnRefHdlr:1;
99
100 ScTabViewShell *m_pTabVwSh;
101 bool m_bRefInputting:1;
102 bool EnterRefStatus();
103 bool LeaveRefStatus();
104 //-->Added by PengYunQuan for Validity Cell Range Picker
105 public:
106 //<!--Modified by PengYunQuan for Validity Cell Range Picker
107 //explicit ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet );
108 explicit ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet, ScTabViewShell * pTabViewSh, SfxBindings *pB = NULL );
109 //-->Modified by PengYunQuan for Validity Cell Range Picker
110 //<!--Added by PengYunQuan for Validity Cell Range Picker
111 virtual ~ScValidationDlg();
112 inline static ScValidationDlg * Find1AliveObject( Window *pAncestor );
113 bool IsAlive();
114 inline ScTabViewShell * GetTabViewShell();
115
116 bool SetupRefDlg();
117 bool RemoveRefDlg( sal_Bool bRestoreModal = sal_True );
118
SetModal(sal_Bool bModal)119 virtual void SetModal( sal_Bool bModal ){ ScValidationDlgBase::SetModalInputMode( bModal ); }
120
SetReference(const ScRange & rRef,ScDocument * pDoc)121 virtual void SetReference( const ScRange& rRef, ScDocument* pDoc )
122 {
123 if ( m_pHandler && m_pSetReferenceHdl )
124 (m_pHandler->*m_pSetReferenceHdl)( rRef, pDoc );
125 }
126
SetActive()127 virtual void SetActive()
128 {
129 if ( m_pHandler && m_pSetActiveHdl )
130 (m_pHandler->*m_pSetActiveHdl)();
131 }
132
CloseRefDialog()133 void CloseRefDialog()
134 {
135 DBG_ASSERT( false, "should not execute here!!!when the edit kill focus, should remove refhandler.\r\n" );
136
137 if ( IsInExecute() )
138 EndDialog( sal_False );
139 else if ( GetStyle() & WB_CLOSEABLE )
140 Close();
141 }
142
IsRefInputting()143 bool IsRefInputting(){ return m_bRefInputting; }
144
RefInputStart(ScRefEdit * pEdit,ScRefButton * pButton=NULL)145 virtual void RefInputStart( ScRefEdit* pEdit, ScRefButton* pButton = NULL )
146 {
147 if( !CanInputStart( pEdit ) )
148 return;
149
150 if ( m_pHandler && m_pRefInputStartPreHdl )
151 (m_pHandler->*m_pRefInputStartPreHdl)( pEdit, pButton );
152 m_bRefInputting = true;
153 ScValidationDlgBase::RefInputStart( pEdit, pButton );
154 if ( m_pHandler && m_pRefInputStartPostHdl )
155 (m_pHandler->*m_pRefInputStartPostHdl)( pEdit, pButton );
156 }
157
RefInputDone(sal_Bool bForced=sal_False)158 virtual void RefInputDone( sal_Bool bForced = sal_False )
159 {
160 if( !CanInputDone( bForced ) )
161 return;
162
163 if ( m_pHandler && m_pRefInputDonePreHdl )
164 (m_pHandler->*m_pRefInputDonePreHdl)();
165
166 ScValidationDlgBase::RefInputDone( bForced );
167 m_bRefInputting = false;
168
169 if ( m_pHandler && m_pRefInputDonePostHdl )
170 (m_pHandler->*m_pRefInputDonePostHdl)();
171 }
172
173 sal_Bool IsChildFocus();
174
175 enum { SLOTID = SID_VALIDITY_REFERENCE };
176
177 sal_Bool Close();
178 //-->Added by PengYunQuan for Validity Cell Range Picker
179 };
180
181
182 // ============================================================================
183
184 /** The tab page "Criteria" from the Validation dialog. */
185 //<!--Modified by PengYunQuan for Validity Cell Range Picker
186 //class ScTPValidationValue : public SfxTabPage
187 class ScTPValidationValue : public ScRefHandlerCaller, public SfxTabPage
188 //-->Modified by PengYunQuan for Validity Cell Range Picker
189 {
190 public:
191 explicit ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet );
192 virtual ~ScTPValidationValue();
193
194 static SfxTabPage* Create( Window* pParent, const SfxItemSet& rArgSet );
195 static sal_uInt16* GetRanges();
196
197 virtual sal_Bool FillItemSet( SfxItemSet& rArgSet );
198 virtual void Reset( const SfxItemSet& rArgSet );
199
200 private:
201 void Init();
202
203 String GetFirstFormula() const;
204 String GetSecondFormula() const;
205
206 void SetFirstFormula( const String& rFmlaStr );
207 void SetSecondFormula( const String& rFmlaStr );
208
209 DECL_LINK( SelectHdl, ListBox* );
210 DECL_LINK( CheckHdl, CheckBox* );
211
212 FixedText maFtAllow;
213 ListBox maLbAllow;
214 CheckBox maCbAllow; /// Allow blank cells.
215 CheckBox maCbShow; /// Show selection list in cell.
216 CheckBox maCbSort; /// Sort selection list in cell.
217 FixedText maFtValue;
218 ListBox maLbValue;
219 FixedText maFtMin;
220 //<!--Modified by PengYunQuan for Validity Cell Range Picker
221 //Edit maEdMin;
222 ScRefEdit maEdMin;
223 //-->Modified by PengYunQuan for Validity Cell Range Picker
224 MultiLineEdit maEdList; /// Entries for explicit list
225 FixedText maFtMax;
226 //<!--Modified by PengYunQuan for Validity Cell Range Picker
227 //Edit maEdMax;
228 ScRefEdit maEdMax;
229 //-->Modified by PengYunQuan for Validity Cell Range Picker
230 FixedText maFtHint; /// Hint text for cell range validity.
231
232 String maStrMin;
233 String maStrMax;
234 String maStrValue;
235 String maStrRange;
236 String maStrList;
237 sal_Unicode mcFmlaSep; /// List separator in formulas.
238 //<!--Added by PengYunQuan for Validity Cell Range Picker
239 DECL_LINK( EditSetFocusHdl, Edit *);
240 DECL_LINK( KillFocusHdl, Window *);
241 void OnClick( Button *pBtn );
242 ScRefEdit *m_pRefEdit;
243 class ScRefButtonEx:public ::ScRefButton
244 {
245 void Click();
246 public:
ScRefButtonEx(Window * pParent,const ResId & rResId,ScRefEdit * pEdit=NULL,ScRefHandler * pRefHdlr=NULL)247 ScRefButtonEx( Window* pParent, const ResId& rResId, ScRefEdit* pEdit = NULL, ScRefHandler *pRefHdlr = NULL ): ::ScRefButton( pParent, rResId, pEdit, pRefHdlr ){}
248 }m_btnRef;
249 friend class ScRefButtonEx;
250 void SetReferenceHdl( const ScRange& , ScDocument* );
251 void SetActiveHdl();
252 void RefInputStartPreHdl( ScRefEdit* pEdit, ScRefButton* pButton );
253 void RefInputDonePreHdl();
254 void RefInputDonePostHdl();
255 ScValidationDlg * GetValidationDlg();
256
257 //TYPEINFO();
258 void TidyListBoxes();
259 public:
260 sal_uInt16 GetAllowEntryPos();
261 String GetMinText();
262 void SetupRefDlg();
263 void RemoveRefDlg();
264 //-->Added by PengYunQuan for Validity Cell Range Picker
265 };
266
267
268 //==================================================================
269
270 class ScTPValidationHelp : public SfxTabPage
271 {
272 private:
273 TriStateBox aTsbHelp;
274 FixedLine aFlContent;
275 FixedText aFtTitle;
276 Edit aEdtTitle;
277 FixedText aFtInputHelp;
278 MultiLineEdit aEdInputHelp;
279
280 const SfxItemSet& mrArgSet;
281
282 void Init();
283
284 // Handler ------------------------
285 // DECL_LINK( SelectHdl, ListBox * );
286
287 public:
288 ScTPValidationHelp( Window* pParent, const SfxItemSet& rArgSet );
289 ~ScTPValidationHelp();
290
291 static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
292 static sal_uInt16* GetRanges ();
293 virtual sal_Bool FillItemSet ( SfxItemSet& rArgSet );
294 virtual void Reset ( const SfxItemSet& rArgSet );
295 };
296
297 //==================================================================
298
299 class ScTPValidationError : public SfxTabPage
300 {
301 private:
302 TriStateBox aTsbShow;
303 FixedLine aFlContent;
304 FixedText aFtAction;
305 ListBox aLbAction;
306 PushButton aBtnSearch;
307 FixedText aFtTitle;
308 Edit aEdtTitle;
309 FixedText aFtError;
310 MultiLineEdit aEdError;
311
312 const SfxItemSet& mrArgSet;
313
314 void Init();
315
316 // Handler ------------------------
317 DECL_LINK( SelectActionHdl, ListBox * );
318 DECL_LINK( ClickSearchHdl, PushButton * );
319
320 public:
321 ScTPValidationError( Window* pParent, const SfxItemSet& rArgSet );
322 ~ScTPValidationError();
323
324 static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
325 static sal_uInt16* GetRanges ();
326 virtual sal_Bool FillItemSet ( SfxItemSet& rArgSet );
327 virtual void Reset ( const SfxItemSet& rArgSet );
328 };
329
330 //<!--Added by PengYunQuan for Validity Cell Range Picker
GetTabViewShell()331 inline ScTabViewShell *ScValidationDlg::GetTabViewShell()
332 {
333 return m_pTabVwSh;
334 }
335
Find1AliveObject(Window * pAncestor)336 inline ScValidationDlg * ScValidationDlg::Find1AliveObject( Window *pAncestor )
337 {
338 return static_cast<ScValidationDlg *>( SC_MOD()->Find1RefWindow( SLOTID, pAncestor ) );
339 }
340 //-->Added by PengYunQuan for Validity Cell Range Picker
341 #endif // SC_VALIDATE_HXX
342
343