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 <svtools/svmedit.hxx>
30 #include "anyrefdg.hxx"
32 // ============================================================================
34 struct ScRefHandlerCaller
{
35 virtual ~ScRefHandlerCaller(){}
37 class ScRefHandlerHelper
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
)();
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
;
60 PCOMMONHDLTYPE
SetSetActHdl( PCOMMONHDLTYPE pNewHdl
)
62 PCOMMONHDLTYPE pOldHdl
= m_pSetActiveHdl
;
63 m_pSetActiveHdl
= pNewHdl
;
67 ScRefHandlerCaller
*SetHandler( ScRefHandlerCaller
*pNewHandler
)
69 ScRefHandlerCaller
*pOldHandler
= m_pHandler
;
70 m_pHandler
= pNewHandler
;
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
* );
90 ScTabViewShell
*m_pTabVwSh
;
92 bool m_bRefInputting
:1;
93 bool EnterRefStatus();
94 bool LeaveRefStatus();
97 explicit ScValidationDlg( Window
* pParent
, const SfxItemSet
* pArgSet
, ScTabViewShell
* pTabViewSh
, SfxBindings
*pB
= NULL
);
98 virtual ~ScValidationDlg();
99 inline static ScValidationDlg
* Find1AliveObject( Window
*pAncestor
);
101 inline ScTabViewShell
* GetTabViewShell();
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" );
126 else if ( GetStyle() & WB_CLOSEABLE
)
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
) )
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
) )
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
};
169 // ============================================================================
171 /** The tab page "Criteria" from the Validation dialog. */
172 class ScTPValidationValue
: public ScRefHandlerCaller
, public SfxTabPage
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
);
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 *);
198 CheckBox maCbAllow
; /// Allow blank cells.
199 CheckBox maCbShow
; /// Show selection list in cell.
200 CheckBox maCbSort
; /// Sort selection list in cell.
204 formula::RefEdit maEdMin
;
205 MultiLineEdit maEdList
; /// Entries for explicit list
207 formula::RefEdit maEdMax
;
208 FixedText maFtHint
; /// Hint text for cell range validity.
215 sal_Unicode mcFmlaSep
; /// List separator in formulas.
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
230 ScRefButtonEx( Window
* pParent
, const ResId
& rResId
, formula::RefEdit
* pEdit
= NULL
,
231 ScRefHandler
*pRefHdlr
= NULL
)
232 : ::formula::RefButton( pParent
, rResId
, pEdit
, pRefHdlr
)
236 friend class ScRefButtonEx
;
237 void SetReferenceHdl( const ScRange
& , ScDocument
* );
239 void RefInputStartPreHdl( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
);
240 void RefInputDonePostHdl();
241 ScValidationDlg
* GetValidationDlg();
243 void TidyListBoxes();
245 sal_uInt16
GetAllowEntryPos();
252 //==================================================================
254 class ScTPValidationHelp
: public SfxTabPage
257 TriStateBox aTsbHelp
;
258 FixedLine aFlContent
;
261 FixedText aFtInputHelp
;
262 MultiLineEdit aEdInputHelp
;
266 // Handler ------------------------
267 // DECL_LINK( SelectHdl, ListBox * );
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
284 TriStateBox aTsbShow
;
285 FixedLine aFlContent
;
288 PushButton aBtnSearch
;
292 MultiLineEdit aEdError
;
296 // Handler ------------------------
297 DECL_LINK(SelectActionHdl
, void *);
298 DECL_LINK(ClickSearchHdl
, void *);
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()
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: */