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