Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef SC_VALIDATE_HXX
21 : #define SC_VALIDATE_HXX
22 :
23 : #include <sfx2/tabdlg.hxx>
24 : #include <vcl/edit.hxx>
25 : #include <vcl/fixed.hxx>
26 : #include <vcl/layout.hxx>
27 : #include <vcl/lstbox.hxx>
28 : #include <vcl/vclmedit.hxx>
29 : #include <svtools/svmedit.hxx>
30 :
31 : #include "anyrefdg.hxx"
32 :
33 0 : struct ScRefHandlerCaller{
34 0 : virtual ~ScRefHandlerCaller(){}
35 : };
36 : class ScRefHandlerHelper
37 : {
38 : protected:
39 : ScRefHandlerCaller *m_pHandler;
40 : void (ScRefHandlerCaller::*m_pSetReferenceHdl)( const ScRange& , ScDocument* );
41 : void (ScRefHandlerCaller::*m_pSetActiveHdl)();
42 : void (ScRefHandlerCaller::*m_pRefInputStartPreHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
43 : void (ScRefHandlerCaller::*m_pRefInputStartPostHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
44 : void (ScRefHandlerCaller::*m_pRefInputDonePreHdl)();
45 : void (ScRefHandlerCaller::*m_pRefInputDonePostHdl)();
46 :
47 : public:
48 : typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE)( const ScRange& , ScDocument* );
49 : typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE)();
50 : typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE)( formula::RefEdit* pEdit, formula::RefButton* pButton );
51 :
52 0 : PFUNCSETREFHDLTYPE SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl )
53 : {
54 0 : PFUNCSETREFHDLTYPE pOldHdl = m_pSetReferenceHdl;
55 0 : m_pSetReferenceHdl = pNewHdl;
56 0 : return pOldHdl;
57 : }
58 :
59 0 : PCOMMONHDLTYPE SetSetActHdl( PCOMMONHDLTYPE pNewHdl )
60 : {
61 0 : PCOMMONHDLTYPE pOldHdl = m_pSetActiveHdl;
62 0 : m_pSetActiveHdl = pNewHdl;
63 0 : return pOldHdl;
64 : }
65 :
66 0 : ScRefHandlerCaller *SetHandler( ScRefHandlerCaller *pNewHandler )
67 : {
68 0 : ScRefHandlerCaller *pOldHandler = m_pHandler;
69 0 : m_pHandler = pNewHandler;
70 0 : return pOldHandler;
71 : }
72 0 : void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPreHdl = pNewHdl; }
73 0 : void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePostHdl = pNewHdl; }
74 : void SetRefInputStartPostHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPostHdl = pNewHdl; }
75 : void SetRefInputDonePreHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePreHdl = pNewHdl; }
76 :
77 0 : ScRefHandlerHelper():m_pHandler(NULL), m_pSetReferenceHdl( NULL ), m_pSetActiveHdl(NULL), m_pRefInputStartPreHdl( NULL ), m_pRefInputStartPostHdl( NULL ), m_pRefInputDonePreHdl( NULL ), m_pRefInputDonePostHdl( NULL ){}
78 : };
79 :
80 : /** The "Validity" tab dialog. */
81 : class ScValidationDlg
82 : : public ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false>
83 : , public ScRefHandlerHelper
84 : {
85 : typedef ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false> ScValidationDlgBase;
86 :
87 : DECL_LINK( OkHdl, Button * );
88 :
89 : ScTabViewShell *m_pTabVwSh;
90 : VclHBox* m_pHBox;
91 : sal_uInt16 m_nValuePageId;
92 : bool m_bOwnRefHdlr:1;
93 : bool m_bRefInputting:1;
94 :
95 : bool EnterRefStatus();
96 : bool LeaveRefStatus();
97 :
98 : public:
99 : explicit ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet, ScTabViewShell * pTabViewSh, SfxBindings *pB = NULL );
100 : virtual ~ScValidationDlg();
101 0 : static ScValidationDlg * Find1AliveObject( Window *pAncestor )
102 : {
103 0 : return static_cast<ScValidationDlg *>( SC_MOD()->Find1RefWindow( SLOTID, pAncestor ) );
104 : }
105 0 : ScTabViewShell *GetTabViewShell()
106 : {
107 0 : return m_pTabVwSh;
108 : }
109 :
110 : bool SetupRefDlg();
111 : bool RemoveRefDlg( bool bRestoreModal = true );
112 :
113 0 : virtual void SetModal( bool bModal ){ ScValidationDlgBase::SetModalInputMode( bModal ); }
114 :
115 0 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE
116 : {
117 0 : if ( m_pHandler && m_pSetReferenceHdl )
118 0 : (m_pHandler->*m_pSetReferenceHdl)( rRef, pDoc );
119 0 : }
120 :
121 0 : virtual void SetActive() SAL_OVERRIDE
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( RET_CANCEL );
133 : else if ( GetStyle() & WB_CLOSEABLE )
134 : Close();
135 : }
136 :
137 0 : bool IsRefInputting(){ return m_bRefInputting; }
138 0 : Window* get_refinput_shrink_parent() { return m_pHBox; }
139 :
140 0 : virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE
141 : {
142 0 : if( !CanInputStart( pEdit ) )
143 0 : return;
144 :
145 0 : if ( m_pHandler && m_pRefInputStartPreHdl )
146 0 : (m_pHandler->*m_pRefInputStartPreHdl)( pEdit, pButton );
147 0 : m_bRefInputting = true;
148 0 : ScValidationDlgBase::RefInputStart( pEdit, pButton );
149 0 : if ( m_pHandler && m_pRefInputStartPostHdl )
150 0 : (m_pHandler->*m_pRefInputStartPostHdl)( pEdit, pButton );
151 : }
152 :
153 0 : virtual void RefInputDone( bool bForced = false ) SAL_OVERRIDE
154 : {
155 0 : if( !CanInputDone( bForced ) )
156 0 : return;
157 :
158 0 : if ( m_pHandler && m_pRefInputDonePreHdl )
159 0 : (m_pHandler->*m_pRefInputDonePreHdl)();
160 :
161 0 : ScValidationDlgBase::RefInputDone( bForced );
162 0 : m_bRefInputting = false;
163 :
164 0 : if ( m_pHandler && m_pRefInputDonePostHdl )
165 0 : (m_pHandler->*m_pRefInputDonePostHdl)();
166 : }
167 :
168 : bool IsChildFocus();
169 :
170 : enum { SLOTID = SID_VALIDITY_REFERENCE };
171 :
172 : bool Close() SAL_OVERRIDE;
173 : };
174 :
175 :
176 : /** The tab page "Criteria" from the Validation dialog. */
177 0 : class ScTPValidationValue : public ScRefHandlerCaller, public SfxTabPage
178 : {
179 : public:
180 : explicit ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet );
181 :
182 : static SfxTabPage* Create( Window* pParent, const SfxItemSet& rArgSet );
183 : static sal_uInt16* GetRanges();
184 :
185 : virtual bool FillItemSet( SfxItemSet& rArgSet ) SAL_OVERRIDE;
186 : virtual void Reset( const SfxItemSet& rArgSet ) SAL_OVERRIDE;
187 :
188 : private:
189 : void Init();
190 :
191 : OUString GetFirstFormula() const;
192 : OUString GetSecondFormula() const;
193 :
194 : void SetFirstFormula( const OUString& rFmlaStr );
195 : void SetSecondFormula( const OUString& rFmlaStr );
196 :
197 : DECL_LINK(SelectHdl, void *);
198 : DECL_LINK(CheckHdl, void *);
199 :
200 : ListBox* m_pLbAllow;
201 : CheckBox* m_pCbAllow; /// Allow blank cells.
202 : CheckBox* m_pCbShow; /// Show selection list in cell.
203 : CheckBox* m_pCbSort; /// Sort selection list in cell.
204 : FixedText* m_pFtValue;
205 : ListBox* m_pLbValue;
206 : FixedText* m_pFtMin;
207 : VclContainer* m_pMinGrid;
208 : formula::RefEdit* m_pEdMin;
209 : VclMultiLineEdit* m_pEdList; /// Entries for explicit list
210 : FixedText* m_pFtMax;
211 : formula::RefEdit* m_pEdMax;
212 : FixedText* m_pFtHint; /// Hint text for cell range validity.
213 :
214 : OUString maStrMin;
215 : OUString maStrMax;
216 : OUString maStrValue;
217 : OUString maStrRange;
218 : OUString maStrList;
219 : sal_Unicode mcFmlaSep; /// List separator in formulas.
220 :
221 : DECL_LINK(EditSetFocusHdl, void *);
222 : DECL_LINK( KillFocusHdl, Window *);
223 : void OnClick( Button *pBtn );
224 : formula::RefEdit* m_pRefEdit;
225 : public:
226 0 : class ScRefButtonEx : public ::formula::RefButton
227 : {
228 : ScTPValidationValue* m_pPage;
229 : virtual void Click() SAL_OVERRIDE;
230 : public:
231 0 : ScRefButtonEx(Window* pParent, WinBits nStyle)
232 : : ::formula::RefButton(pParent, nStyle)
233 0 : , m_pPage(NULL)
234 : {
235 0 : }
236 0 : void SetParentPage(ScTPValidationValue *pPage)
237 : {
238 0 : m_pPage = pPage;
239 0 : }
240 0 : ScTPValidationValue* GetParentPage()
241 : {
242 0 : return m_pPage;
243 : }
244 : };
245 : private:
246 : ScRefButtonEx* m_pBtnRef;
247 : VclContainer* m_pRefGrid;
248 : friend class ScRefButtonEx;
249 : void SetReferenceHdl( const ScRange& , ScDocument* );
250 : void SetActiveHdl();
251 : void RefInputStartPreHdl( formula::RefEdit* pEdit, formula::RefButton* pButton );
252 : void RefInputDonePostHdl();
253 : ScValidationDlg * GetValidationDlg();
254 : public:
255 : sal_uInt16 GetAllowEntryPos();
256 : OUString GetMinText();
257 : void SetupRefDlg();
258 : void RemoveRefDlg();
259 : };
260 :
261 :
262 : class ScTPValidationHelp : public SfxTabPage
263 : {
264 : private:
265 : TriStateBox* pTsbHelp;
266 : Edit* pEdtTitle;
267 : VclMultiLineEdit* pEdInputHelp;
268 :
269 : void Init();
270 :
271 : // Handler ------------------------
272 : // DECL_LINK( SelectHdl, ListBox * );
273 :
274 : public:
275 : ScTPValidationHelp( Window* pParent, const SfxItemSet& rArgSet );
276 : virtual ~ScTPValidationHelp();
277 :
278 : static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
279 : virtual bool FillItemSet ( SfxItemSet& rArgSet ) SAL_OVERRIDE;
280 : virtual void Reset ( const SfxItemSet& rArgSet ) SAL_OVERRIDE;
281 : };
282 :
283 : class ScTPValidationError : public SfxTabPage
284 : {
285 : private:
286 : TriStateBox* m_pTsbShow;
287 : ListBox* m_pLbAction;
288 : PushButton* m_pBtnSearch;
289 : Edit* m_pEdtTitle;
290 : FixedText* m_pFtError;
291 : VclMultiLineEdit* m_pEdError;
292 :
293 : void Init();
294 :
295 : // Handler ------------------------
296 : DECL_LINK(SelectActionHdl, void *);
297 : DECL_LINK(ClickSearchHdl, void *);
298 :
299 : public:
300 : ScTPValidationError( Window* pParent, const SfxItemSet& rArgSet );
301 : virtual ~ScTPValidationError();
302 :
303 : static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
304 : virtual bool FillItemSet ( SfxItemSet& rArgSet ) SAL_OVERRIDE;
305 : virtual void Reset ( const SfxItemSet& rArgSet ) SAL_OVERRIDE;
306 : };
307 :
308 : #endif // SC_VALIDATE_HXX
309 :
310 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|