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