bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / inc / validate.hxx
blob8a0a3faff483645a68530bf10516085efd94cba9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_VALIDATE_HXX
21 #define SC_VALIDATE_HXX
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 <svtools/svmedit.hxx>
30 #include "anyrefdg.hxx"
32 // ============================================================================
34 struct ScRefHandlerCaller{
35 virtual ~ScRefHandlerCaller(){}
37 class ScRefHandlerHelper
39 protected:
40 ScRefHandlerCaller *m_pHandler;
41 void (ScRefHandlerCaller::*m_pSetReferenceHdl)( const ScRange& , ScDocument* );
42 void (ScRefHandlerCaller::*m_pSetActiveHdl)();
43 void (ScRefHandlerCaller::*m_pRefInputStartPreHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
44 void (ScRefHandlerCaller::*m_pRefInputStartPostHdl)( formula::RefEdit* pEdit, formula::RefButton* pButton );
45 void (ScRefHandlerCaller::*m_pRefInputDonePreHdl)();
46 void (ScRefHandlerCaller::*m_pRefInputDonePostHdl)();
48 public:
49 typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE)( const ScRange& , ScDocument* );
50 typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE)();
51 typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE)( formula::RefEdit* pEdit, formula::RefButton* pButton );
53 PFUNCSETREFHDLTYPE SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl )
55 PFUNCSETREFHDLTYPE pOldHdl = m_pSetReferenceHdl;
56 m_pSetReferenceHdl = pNewHdl;
57 return pOldHdl;
60 PCOMMONHDLTYPE SetSetActHdl( PCOMMONHDLTYPE pNewHdl )
62 PCOMMONHDLTYPE pOldHdl = m_pSetActiveHdl;
63 m_pSetActiveHdl = pNewHdl;
64 return pOldHdl;
67 ScRefHandlerCaller *SetHandler( ScRefHandlerCaller *pNewHandler )
69 ScRefHandlerCaller *pOldHandler = m_pHandler;
70 m_pHandler = pNewHandler;
71 return pOldHandler;
73 void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPreHdl = pNewHdl; }
74 void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePostHdl = pNewHdl; }
75 void SetRefInputStartPostHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPostHdl = pNewHdl; }
76 void SetRefInputDonePreHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePreHdl = pNewHdl; }
78 ScRefHandlerHelper():m_pHandler(NULL), m_pSetReferenceHdl( NULL ), m_pSetActiveHdl(NULL), m_pRefInputStartPreHdl( NULL ), m_pRefInputStartPostHdl( NULL ), m_pRefInputDonePreHdl( NULL ), m_pRefInputDonePostHdl( NULL ){}
81 /** The "Validity" tab dialog. */
82 class ScValidationDlg :public ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false>, public ScRefHandlerHelper
84 typedef ScRefHdlrImpl<ScValidationDlg, SfxTabDialog, false> ScValidationDlgBase;
86 DECL_LINK( OkHdl, Button * );
88 bool m_bOwnRefHdlr:1;
90 ScTabViewShell *m_pTabVwSh;
91 VclHBox* mpHBox;
92 bool m_bRefInputting:1;
93 bool EnterRefStatus();
94 bool LeaveRefStatus();
96 public:
97 explicit ScValidationDlg( Window* pParent, const SfxItemSet* pArgSet, ScTabViewShell * pTabViewSh, SfxBindings *pB = NULL );
98 virtual ~ScValidationDlg();
99 inline static ScValidationDlg * Find1AliveObject( Window *pAncestor );
100 bool IsAlive();
101 inline ScTabViewShell * GetTabViewShell();
103 bool SetupRefDlg();
104 bool RemoveRefDlg( sal_Bool bRestoreModal = sal_True );
106 virtual void SetModal( sal_Bool bModal ){ ScValidationDlgBase::SetModalInputMode( bModal ); }
108 virtual void SetReference( const ScRange& rRef, ScDocument* pDoc )
110 if ( m_pHandler && m_pSetReferenceHdl )
111 (m_pHandler->*m_pSetReferenceHdl)( rRef, pDoc );
114 virtual void SetActive()
116 if ( m_pHandler && m_pSetActiveHdl )
117 (m_pHandler->*m_pSetActiveHdl)();
120 void CloseRefDialog()
122 OSL_FAIL( "should not execute here!!!when the edit kill focus, should remove refhandler.\r\n" );
124 if ( IsInExecute() )
125 EndDialog( false );
126 else if ( GetStyle() & WB_CLOSEABLE )
127 Close();
130 bool IsRefInputting(){ return m_bRefInputting; }
131 Window* get_refinput_shrink_parent() { return mpHBox; }
133 virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL )
135 if( !CanInputStart( pEdit ) )
136 return;
138 if ( m_pHandler && m_pRefInputStartPreHdl )
139 (m_pHandler->*m_pRefInputStartPreHdl)( pEdit, pButton );
140 m_bRefInputting = true;
141 ScValidationDlgBase::RefInputStart( pEdit, pButton );
142 if ( m_pHandler && m_pRefInputStartPostHdl )
143 (m_pHandler->*m_pRefInputStartPostHdl)( pEdit, pButton );
146 virtual void RefInputDone( sal_Bool bForced = false )
148 if( !CanInputDone( bForced ) )
149 return;
151 if ( m_pHandler && m_pRefInputDonePreHdl )
152 (m_pHandler->*m_pRefInputDonePreHdl)();
154 ScValidationDlgBase::RefInputDone( bForced );
155 m_bRefInputting = false;
157 if ( m_pHandler && m_pRefInputDonePostHdl )
158 (m_pHandler->*m_pRefInputDonePostHdl)();
161 sal_Bool IsChildFocus();
163 enum { SLOTID = SID_VALIDITY_REFERENCE };
165 sal_Bool Close();
169 // ============================================================================
171 /** The tab page "Criteria" from the Validation dialog. */
172 class ScTPValidationValue : public ScRefHandlerCaller, public SfxTabPage
174 public:
175 explicit ScTPValidationValue( Window* pParent, const SfxItemSet& rArgSet );
176 virtual ~ScTPValidationValue();
178 static SfxTabPage* Create( Window* pParent, const SfxItemSet& rArgSet );
179 static sal_uInt16* GetRanges();
181 virtual sal_Bool FillItemSet( SfxItemSet& rArgSet );
182 virtual void Reset( const SfxItemSet& rArgSet );
184 private:
185 void Init();
187 String GetFirstFormula() const;
188 String GetSecondFormula() const;
190 void SetFirstFormula( const OUString& rFmlaStr );
191 void SetSecondFormula( const String& rFmlaStr );
193 DECL_LINK(SelectHdl, void *);
194 DECL_LINK(CheckHdl, void *);
196 FixedText maFtAllow;
197 ListBox maLbAllow;
198 CheckBox maCbAllow; /// Allow blank cells.
199 CheckBox maCbShow; /// Show selection list in cell.
200 CheckBox maCbSort; /// Sort selection list in cell.
201 FixedText maFtValue;
202 ListBox maLbValue;
203 FixedText maFtMin;
204 formula::RefEdit maEdMin;
205 MultiLineEdit maEdList; /// Entries for explicit list
206 FixedText maFtMax;
207 formula::RefEdit maEdMax;
208 FixedText maFtHint; /// Hint text for cell range validity.
210 String maStrMin;
211 String maStrMax;
212 String maStrValue;
213 String maStrRange;
214 String maStrList;
215 sal_Unicode mcFmlaSep; /// List separator in formulas.
217 Point maRefEditPos;
218 Point maBtnRefPos;
219 Size maRefEditSize;
220 Size maBtnRefSize;
222 DECL_LINK(EditSetFocusHdl, void *);
223 DECL_LINK( KillFocusHdl, Window *);
224 void OnClick( Button *pBtn );
225 formula::RefEdit* m_pRefEdit;
226 class ScRefButtonEx:public ::formula::RefButton
228 void Click();
229 public:
230 ScRefButtonEx( Window* pParent, const ResId& rResId, formula::RefEdit* pEdit = NULL,
231 ScRefHandler *pRefHdlr = NULL )
232 : ::formula::RefButton( pParent, rResId, pEdit, pRefHdlr )
235 }m_btnRef;
236 friend class ScRefButtonEx;
237 void SetReferenceHdl( const ScRange& , ScDocument* );
238 void SetActiveHdl();
239 void RefInputStartPreHdl( formula::RefEdit* pEdit, formula::RefButton* pButton );
240 void RefInputDonePostHdl();
241 ScValidationDlg * GetValidationDlg();
243 void TidyListBoxes();
244 public:
245 sal_uInt16 GetAllowEntryPos();
246 String GetMinText();
247 void SetupRefDlg();
248 void RemoveRefDlg();
252 //==================================================================
254 class ScTPValidationHelp : public SfxTabPage
256 private:
257 TriStateBox aTsbHelp;
258 FixedLine aFlContent;
259 FixedText aFtTitle;
260 Edit aEdtTitle;
261 FixedText aFtInputHelp;
262 MultiLineEdit aEdInputHelp;
264 void Init();
266 // Handler ------------------------
267 // DECL_LINK( SelectHdl, ListBox * );
269 public:
270 ScTPValidationHelp( Window* pParent, const SfxItemSet& rArgSet );
271 ~ScTPValidationHelp();
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 );
279 //==================================================================
281 class ScTPValidationError : public SfxTabPage
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;
294 void Init();
296 // Handler ------------------------
297 DECL_LINK(SelectActionHdl, void *);
298 DECL_LINK(ClickSearchHdl, void *);
300 public:
301 ScTPValidationError( Window* pParent, const SfxItemSet& rArgSet );
302 ~ScTPValidationError();
304 static SfxTabPage* Create ( Window* pParent, const SfxItemSet& rArgSet );
305 static sal_uInt16* GetRanges ();
306 virtual sal_Bool FillItemSet ( SfxItemSet& rArgSet );
307 virtual void Reset ( const SfxItemSet& rArgSet );
310 inline ScTabViewShell *ScValidationDlg::GetTabViewShell()
312 return m_pTabVwSh;
315 inline ScValidationDlg * ScValidationDlg::Find1AliveObject( Window *pAncestor )
317 return static_cast<ScValidationDlg *>( SC_MOD()->Find1RefWindow( SLOTID, pAncestor ) );
320 #endif // SC_VALIDATE_HXX
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */