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 INCLUDED_SC_SOURCE_UI_INC_VALIDATE_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_VALIDATE_HXX
23 #include <sfx2/tabdlg.hxx>
25 #include "anyrefdg.hxx"
28 struct ScRefHandlerCaller
{
29 virtual ~ScRefHandlerCaller(){}
32 class ScRefHandlerHelper
35 ScRefHandlerCaller
* m_pHandler
;
36 // workaround VS2013 issue with pointers to things that contain virtual base class
38 #pragma pack(push, 16)
40 void (ScRefHandlerCaller::*m_pSetReferenceHdl
)( const ScRange
& , const ScDocument
* );
41 void (ScRefHandlerCaller::*m_pSetActiveHdl
)();
42 void (ScRefHandlerCaller::*m_pRefInputStartPreHdl
)( formula::RefEdit
* pEdit
, const formula::RefButton
* pButton
);
43 void (ScRefHandlerCaller::*m_pRefInputDonePostHdl
)();
49 typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE
)( const ScRange
& , const ScDocument
* );
50 typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE
)();
51 typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE
)( formula::RefEdit
* pEdit
, const formula::RefButton
* pButton
);
53 void SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl
)
55 m_pSetReferenceHdl
= pNewHdl
;
58 void SetSetActHdl( PCOMMONHDLTYPE pNewHdl
)
60 m_pSetActiveHdl
= pNewHdl
;
63 void SetHandler( ScRefHandlerCaller
*pNewHandler
)
65 m_pHandler
= pNewHandler
;
67 void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl
){ m_pRefInputStartPreHdl
= pNewHdl
; }
68 void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl
)() ){ m_pRefInputDonePostHdl
= pNewHdl
; }
70 ScRefHandlerHelper():m_pHandler(nullptr), m_pSetReferenceHdl( nullptr ), m_pSetActiveHdl(nullptr), m_pRefInputStartPreHdl( nullptr ), m_pRefInputDonePostHdl( nullptr ){}
73 class ScValidationDlg
;
75 /** The tab page "Criteria" from the Validation dialog. */
76 class ScTPValidationValue
: public ScRefHandlerCaller
, public SfxTabPage
78 static const sal_uInt16 pValueRanges
[];
80 explicit ScTPValidationValue(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rArgSet
);
81 static std::unique_ptr
<SfxTabPage
> Create( weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rArgSet
);
82 virtual ~ScTPValidationValue() override
;
84 static const sal_uInt16
* GetRanges() { return pValueRanges
; }
86 virtual bool FillItemSet( SfxItemSet
* rArgSet
) override
;
87 virtual void Reset( const SfxItemSet
* rArgSet
) override
;
92 OUString
GetFirstFormula() const;
93 OUString
GetSecondFormula() const;
95 void SetFirstFormula( const OUString
& rFmlaStr
);
96 void SetSecondFormula( const OUString
& rFmlaStr
);
98 DECL_LINK(SelectHdl
, weld::ComboBox
&, void);
99 DECL_LINK(CheckHdl
, weld::Button
&, void);
101 OUString
const maStrMin
;
102 OUString
const maStrMax
;
103 OUString
const maStrValue
;
104 OUString
const maStrFormula
;
105 OUString
const maStrRange
;
106 OUString
const maStrList
;
107 sal_Unicode mcFmlaSep
; /// List separator in formulas.
109 DECL_LINK( EditSetFocusHdl
, formula::RefEdit
&, void );
110 DECL_LINK( KillEditFocusHdl
, formula::RefEdit
&, void );
111 DECL_LINK( KillButtonFocusHdl
, formula::RefButton
&, void );
112 DECL_LINK( ClickHdl
, formula::RefButton
&, void );
114 formula::RefEdit
* m_pRefEdit
;
116 std::unique_ptr
<weld::ComboBox
> m_xLbAllow
;
117 std::unique_ptr
<weld::CheckButton
> m_xCbAllow
; /// Allow blank cells.
118 std::unique_ptr
<weld::CheckButton
> m_xCbShow
; /// Show selection list in cell.
119 std::unique_ptr
<weld::CheckButton
> m_xCbSort
; /// Sort selection list in cell.
120 std::unique_ptr
<weld::Label
> m_xFtValue
;
121 std::unique_ptr
<weld::ComboBox
> m_xLbValue
;
122 std::unique_ptr
<weld::Label
> m_xFtMin
;
123 std::unique_ptr
<weld::Widget
> m_xMinGrid
;
124 std::unique_ptr
<formula::RefEdit
> m_xEdMin
;
125 std::unique_ptr
<weld::TextView
> m_xEdList
; /// Entries for explicit list
126 std::unique_ptr
<weld::Label
> m_xFtMax
;
127 std::unique_ptr
<formula::RefEdit
> m_xEdMax
;
128 std::unique_ptr
<weld::Label
> m_xFtHint
; /// Hint text for cell range validity.
129 std::unique_ptr
<formula::RefButton
> m_xBtnRef
;
130 std::unique_ptr
<weld::Container
> m_xRefGrid
;
132 weld::Container
* m_pRefEditParent
;
133 weld::Container
* m_pBtnRefParent
;
135 void SetReferenceHdl( const ScRange
& , const ScDocument
* );
137 void RefInputStartPreHdl(formula::RefEdit
* pEdit
, const formula::RefButton
* pButton
);
138 void RefInputDonePostHdl();
139 ScValidationDlg
* GetValidationDlg();
142 void RemoveRefDlg(bool bRestoreModal
);
145 /** The "Validity" tab dialog. */
146 class ScValidationDlg
147 : public ScRefHdlrControllerImpl
<SfxTabDialogController
, false>
148 , public ScRefHandlerHelper
150 typedef ScRefHdlrControllerImpl
<SfxTabDialogController
, false> ScValidationDlgBase
;
152 ScTabViewShell
* const m_pTabVwSh
;
153 OString m_sValuePageId
;
154 bool m_bOwnRefHdlr
:1;
155 bool m_bRefInputting
:1;
157 std::unique_ptr
<weld::Container
> m_xHBox
;
159 bool EnterRefStatus();
160 bool LeaveRefStatus();
163 explicit ScValidationDlg(weld::Window
* pParent
, const SfxItemSet
* pArgSet
, ScTabViewShell
* pTabViewSh
);
164 virtual ~ScValidationDlg() override
;
165 static std::shared_ptr
<SfxDialogController
> Find1AliveObject(const weld::Window
*pAncestor
)
167 return SC_MOD()->Find1RefWindow(SLOTID
, pAncestor
);
169 ScTabViewShell
*GetTabViewShell()
175 bool RemoveRefDlg(bool bRestoreModal
);
177 void SetModal(bool bModal
) { m_xDialog
->set_modal(bModal
); }
179 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
) override
181 if ( m_pHandler
&& m_pSetReferenceHdl
)
182 (m_pHandler
->*m_pSetReferenceHdl
)( rRef
, pDoc
);
185 virtual void SetActive() override
187 if ( m_pHandler
&& m_pSetActiveHdl
)
188 (m_pHandler
->*m_pSetActiveHdl
)();
191 bool IsRefInputting() const { return m_bRefInputting
; }
192 weld::Container
* get_refinput_shrink_parent() { return m_xHBox
.get(); }
194 virtual void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr ) override
196 if( !CanInputStart( pEdit
) )
199 if ( m_pHandler
&& m_pRefInputStartPreHdl
)
200 (m_pHandler
->*m_pRefInputStartPreHdl
)( pEdit
, pButton
);
201 m_bRefInputting
= true;
202 ScValidationDlgBase::RefInputStart( pEdit
, pButton
);
205 virtual void RefInputDone( bool bForced
= false ) override
207 if( !CanInputDone( bForced
) )
210 ScValidationDlgBase::RefInputDone( bForced
);
211 m_bRefInputting
= false;
213 if ( m_pHandler
&& m_pRefInputDonePostHdl
)
214 (m_pHandler
->*m_pRefInputDonePostHdl
)();
217 bool IsChildFocus() const;
219 enum { SLOTID
= SID_VALIDITY_REFERENCE
};
221 virtual void Close() override
225 if (SfxTabPage
* pPage
= GetTabPage(m_sValuePageId
))
226 static_cast<ScTPValidationValue
*>(pPage
)->RemoveRefDlg(false);
228 ScValidationDlgBase::Close();
232 class ScTPValidationHelp
: public SfxTabPage
235 std::unique_ptr
<weld::CheckButton
> m_xTsbHelp
;
236 std::unique_ptr
<weld::Entry
> m_xEdtTitle
;
237 std::unique_ptr
<weld::TextView
> m_xEdInputHelp
;
240 ScTPValidationHelp(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rArgSet
);
241 static std::unique_ptr
<SfxTabPage
> Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rArgSet
);
242 virtual ~ScTPValidationHelp() override
;
244 virtual bool FillItemSet ( SfxItemSet
* rArgSet
) override
;
245 virtual void Reset ( const SfxItemSet
* rArgSet
) override
;
248 class ScTPValidationError
: public SfxTabPage
251 std::unique_ptr
<weld::CheckButton
> m_xTsbShow
;
252 std::unique_ptr
<weld::ComboBox
> m_xLbAction
;
253 std::unique_ptr
<weld::Button
> m_xBtnSearch
;
254 std::unique_ptr
<weld::Entry
> m_xEdtTitle
;
255 std::unique_ptr
<weld::Label
> m_xFtError
;
256 std::unique_ptr
<weld::TextView
> m_xEdError
;
260 // Handler ------------------------
261 DECL_LINK(SelectActionHdl
, weld::ComboBox
&, void);
262 DECL_LINK(ClickSearchHdl
, weld::Button
&, void);
265 ScTPValidationError(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rArgSet
);
266 static std::unique_ptr
<SfxTabPage
> Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rArgSet
);
267 virtual ~ScTPValidationError() override
;
269 virtual bool FillItemSet ( SfxItemSet
* rArgSet
) override
;
270 virtual void Reset ( const SfxItemSet
* rArgSet
) override
;
273 #endif // INCLUDED_SC_SOURCE_UI_INC_VALIDATE_HXX
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */