1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/vclmedit.hxx>
29 #include <svtools/svmedit.hxx>
31 #include "anyrefdg.hxx"
33 // ============================================================================
35 struct ScRefHandlerCaller
{
36 virtual ~ScRefHandlerCaller(){}
38 class ScRefHandlerHelper
41 ScRefHandlerCaller
*m_pHandler
;
42 void (ScRefHandlerCaller::*m_pSetReferenceHdl
)( const ScRange
& , ScDocument
* );
43 void (ScRefHandlerCaller::*m_pSetActiveHdl
)();
44 void (ScRefHandlerCaller::*m_pRefInputStartPreHdl
)( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
);
45 void (ScRefHandlerCaller::*m_pRefInputStartPostHdl
)( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
);
46 void (ScRefHandlerCaller::*m_pRefInputDonePreHdl
)();
47 void (ScRefHandlerCaller::*m_pRefInputDonePostHdl
)();
50 typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE
)( const ScRange
& , ScDocument
* );
51 typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE
)();
52 typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE
)( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
);
54 PFUNCSETREFHDLTYPE
SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl
)
56 PFUNCSETREFHDLTYPE pOldHdl
= m_pSetReferenceHdl
;
57 m_pSetReferenceHdl
= pNewHdl
;
61 PCOMMONHDLTYPE
SetSetActHdl( PCOMMONHDLTYPE pNewHdl
)
63 PCOMMONHDLTYPE pOldHdl
= m_pSetActiveHdl
;
64 m_pSetActiveHdl
= pNewHdl
;
68 ScRefHandlerCaller
*SetHandler( ScRefHandlerCaller
*pNewHandler
)
70 ScRefHandlerCaller
*pOldHandler
= m_pHandler
;
71 m_pHandler
= pNewHandler
;
74 void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl
){ m_pRefInputStartPreHdl
= pNewHdl
; }
75 void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl
)() ){ m_pRefInputDonePostHdl
= pNewHdl
; }
76 void SetRefInputStartPostHdl( PINPUTSTARTDLTYPE pNewHdl
){ m_pRefInputStartPostHdl
= pNewHdl
; }
77 void SetRefInputDonePreHdl( void (ScRefHandlerCaller::*pNewHdl
)() ){ m_pRefInputDonePreHdl
= pNewHdl
; }
79 ScRefHandlerHelper():m_pHandler(NULL
), m_pSetReferenceHdl( NULL
), m_pSetActiveHdl(NULL
), m_pRefInputStartPreHdl( NULL
), m_pRefInputStartPostHdl( NULL
), m_pRefInputDonePreHdl( NULL
), m_pRefInputDonePostHdl( NULL
){}
82 /** The "Validity" tab dialog. */
83 class ScValidationDlg
:public ScRefHdlrImpl
<ScValidationDlg
, SfxTabDialog
, false>, public ScRefHandlerHelper
85 typedef ScRefHdlrImpl
<ScValidationDlg
, SfxTabDialog
, false> ScValidationDlgBase
;
87 DECL_LINK( OkHdl
, Button
* );
91 ScTabViewShell
*m_pTabVwSh
;
93 bool m_bRefInputting
:1;
94 bool EnterRefStatus();
95 bool LeaveRefStatus();
98 explicit ScValidationDlg( Window
* pParent
, const SfxItemSet
* pArgSet
, ScTabViewShell
* pTabViewSh
, SfxBindings
*pB
= NULL
);
99 virtual ~ScValidationDlg();
100 inline static ScValidationDlg
* Find1AliveObject( Window
*pAncestor
);
102 inline ScTabViewShell
* GetTabViewShell();
105 bool RemoveRefDlg( sal_Bool bRestoreModal
= sal_True
);
107 virtual void SetModal( sal_Bool bModal
){ ScValidationDlgBase::SetModalInputMode( bModal
); }
109 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
)
111 if ( m_pHandler
&& m_pSetReferenceHdl
)
112 (m_pHandler
->*m_pSetReferenceHdl
)( rRef
, pDoc
);
115 virtual void SetActive()
117 if ( m_pHandler
&& m_pSetActiveHdl
)
118 (m_pHandler
->*m_pSetActiveHdl
)();
121 void CloseRefDialog()
123 OSL_FAIL( "should not execute here!!!when the edit kill focus, should remove refhandler.\r\n" );
127 else if ( GetStyle() & WB_CLOSEABLE
)
131 bool IsRefInputting(){ return m_bRefInputting
; }
132 Window
* get_refinput_shrink_parent() { return mpHBox
; }
134 virtual void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= NULL
)
136 if( !CanInputStart( pEdit
) )
139 if ( m_pHandler
&& m_pRefInputStartPreHdl
)
140 (m_pHandler
->*m_pRefInputStartPreHdl
)( pEdit
, pButton
);
141 m_bRefInputting
= true;
142 ScValidationDlgBase::RefInputStart( pEdit
, pButton
);
143 if ( m_pHandler
&& m_pRefInputStartPostHdl
)
144 (m_pHandler
->*m_pRefInputStartPostHdl
)( pEdit
, pButton
);
147 virtual void RefInputDone( sal_Bool bForced
= false )
149 if( !CanInputDone( bForced
) )
152 if ( m_pHandler
&& m_pRefInputDonePreHdl
)
153 (m_pHandler
->*m_pRefInputDonePreHdl
)();
155 ScValidationDlgBase::RefInputDone( bForced
);
156 m_bRefInputting
= false;
158 if ( m_pHandler
&& m_pRefInputDonePostHdl
)
159 (m_pHandler
->*m_pRefInputDonePostHdl
)();
162 sal_Bool
IsChildFocus();
164 enum { SLOTID
= SID_VALIDITY_REFERENCE
};
170 // ============================================================================
172 /** The tab page "Criteria" from the Validation dialog. */
173 class ScTPValidationValue
: public ScRefHandlerCaller
, public SfxTabPage
176 explicit ScTPValidationValue( Window
* pParent
, const SfxItemSet
& rArgSet
);
177 virtual ~ScTPValidationValue();
179 static SfxTabPage
* Create( Window
* pParent
, const SfxItemSet
& rArgSet
);
180 static sal_uInt16
* GetRanges();
182 virtual sal_Bool
FillItemSet( SfxItemSet
& rArgSet
);
183 virtual void Reset( const SfxItemSet
& rArgSet
);
188 OUString
GetFirstFormula() const;
189 OUString
GetSecondFormula() const;
191 void SetFirstFormula( const OUString
& rFmlaStr
);
192 void SetSecondFormula( const OUString
& rFmlaStr
);
194 DECL_LINK(SelectHdl
, void *);
195 DECL_LINK(CheckHdl
, void *);
199 CheckBox maCbAllow
; /// Allow blank cells.
200 CheckBox maCbShow
; /// Show selection list in cell.
201 CheckBox maCbSort
; /// Sort selection list in cell.
205 formula::RefEdit maEdMin
;
206 MultiLineEdit maEdList
; /// Entries for explicit list
208 formula::RefEdit maEdMax
;
209 FixedText maFtHint
; /// Hint text for cell range validity.
216 sal_Unicode mcFmlaSep
; /// List separator in formulas.
223 DECL_LINK(EditSetFocusHdl
, void *);
224 DECL_LINK( KillFocusHdl
, Window
*);
225 void OnClick( Button
*pBtn
);
226 formula::RefEdit
* m_pRefEdit
;
227 class ScRefButtonEx
:public ::formula::RefButton
231 ScRefButtonEx( Window
* pParent
, const ResId
& rResId
, formula::RefEdit
* pEdit
= NULL
,
232 ScRefHandler
*pRefHdlr
= NULL
)
233 : ::formula::RefButton( pParent
, rResId
, pEdit
, pRefHdlr
)
237 friend class ScRefButtonEx
;
238 void SetReferenceHdl( const ScRange
& , ScDocument
* );
240 void RefInputStartPreHdl( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
);
241 void RefInputDonePostHdl();
242 ScValidationDlg
* GetValidationDlg();
244 void TidyListBoxes();
246 sal_uInt16
GetAllowEntryPos();
247 OUString
GetMinText();
253 //==================================================================
255 class ScTPValidationHelp
: public SfxTabPage
258 TriStateBox
* pTsbHelp
;
260 VclMultiLineEdit
* pEdInputHelp
;
264 // Handler ------------------------
265 // DECL_LINK( SelectHdl, ListBox * );
268 ScTPValidationHelp( Window
* pParent
, const SfxItemSet
& rArgSet
);
269 ~ScTPValidationHelp();
271 static SfxTabPage
* Create ( Window
* pParent
, const SfxItemSet
& rArgSet
);
272 static sal_uInt16
* GetRanges ();
273 virtual sal_Bool
FillItemSet ( SfxItemSet
& rArgSet
);
274 virtual void Reset ( const SfxItemSet
& rArgSet
);
277 //==================================================================
279 class ScTPValidationError
: public SfxTabPage
282 TriStateBox
* m_pTsbShow
;
283 ListBox
* m_pLbAction
;
284 PushButton
* m_pBtnSearch
;
286 FixedText
* m_pFtError
;
287 VclMultiLineEdit
* m_pEdError
;
291 // Handler ------------------------
292 DECL_LINK(SelectActionHdl
, void *);
293 DECL_LINK(ClickSearchHdl
, void *);
296 ScTPValidationError( Window
* pParent
, const SfxItemSet
& rArgSet
);
297 ~ScTPValidationError();
299 static SfxTabPage
* Create ( Window
* pParent
, const SfxItemSet
& rArgSet
);
300 static sal_uInt16
* GetRanges ();
301 virtual sal_Bool
FillItemSet ( SfxItemSet
& rArgSet
);
302 virtual void Reset ( const SfxItemSet
& rArgSet
);
305 inline ScTabViewShell
*ScValidationDlg::GetTabViewShell()
310 inline ScValidationDlg
* ScValidationDlg::Find1AliveObject( Window
*pAncestor
)
312 return static_cast<ScValidationDlg
*>( SC_MOD()->Find1RefWindow( SLOTID
, pAncestor
) );
315 #endif // SC_VALIDATE_HXX
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */