/src/libreoffice/sc/source/ui/inc/validate.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <sfx2/tabdlg.hxx> |
23 | | #include <vcl/weld/ComboBox.hxx> |
24 | | #include <vcl/weld/Dialog.hxx> |
25 | | #include <vcl/weld/Entry.hxx> |
26 | | #include <vcl/weld/TextView.hxx> |
27 | | |
28 | | #include "anyrefdg.hxx" |
29 | | #include <sc.hrc> |
30 | | #include <scmod.hxx> |
31 | | |
32 | | struct ScRefHandlerCaller{ |
33 | 0 | virtual ~ScRefHandlerCaller(){} |
34 | | }; |
35 | | |
36 | | class ScRefHandlerHelper |
37 | | { |
38 | | protected: |
39 | | ScRefHandlerCaller* m_pHandler; |
40 | | // workaround VS2013 issue with pointers to things that contain virtual base class |
41 | | #ifdef _WIN32 |
42 | | #pragma pack(push, 16) |
43 | | #endif |
44 | | void (ScRefHandlerCaller::*m_pSetReferenceHdl)( const ScRange& , const ScDocument& ); |
45 | | void (ScRefHandlerCaller::*m_pSetActiveHdl)(); |
46 | | void (ScRefHandlerCaller::*m_pRefInputStartPreHdl)( formula::RefEdit* pEdit, const formula::RefButton* pButton ); |
47 | | void (ScRefHandlerCaller::*m_pRefInputDonePostHdl)(); |
48 | | #if defined( _WIN32) |
49 | | #pragma pack(pop) |
50 | | #endif |
51 | | |
52 | | public: |
53 | | typedef void (ScRefHandlerCaller::*PFUNCSETREFHDLTYPE)( const ScRange& , const ScDocument& ); |
54 | | typedef void (ScRefHandlerCaller::*PCOMMONHDLTYPE)(); |
55 | | typedef void (ScRefHandlerCaller::*PINPUTSTARTDLTYPE)( formula::RefEdit* pEdit, const formula::RefButton* pButton ); |
56 | | |
57 | | void SetSetRefHdl( PFUNCSETREFHDLTYPE pNewHdl ) |
58 | 0 | { |
59 | 0 | m_pSetReferenceHdl = pNewHdl; |
60 | 0 | } |
61 | | |
62 | | void SetSetActHdl( PCOMMONHDLTYPE pNewHdl ) |
63 | 0 | { |
64 | 0 | m_pSetActiveHdl = pNewHdl; |
65 | 0 | } |
66 | | |
67 | | void SetHandler( ScRefHandlerCaller *pNewHandler ) |
68 | 0 | { |
69 | 0 | m_pHandler = pNewHandler; |
70 | 0 | } |
71 | 0 | void SetRefInputStartPreHdl( PINPUTSTARTDLTYPE pNewHdl ){ m_pRefInputStartPreHdl = pNewHdl; } |
72 | 0 | void SetRefInputDonePostHdl( void (ScRefHandlerCaller::*pNewHdl)() ){ m_pRefInputDonePostHdl = pNewHdl; } |
73 | | |
74 | 0 | ScRefHandlerHelper():m_pHandler(nullptr), m_pSetReferenceHdl( nullptr ), m_pSetActiveHdl(nullptr), m_pRefInputStartPreHdl( nullptr ), m_pRefInputDonePostHdl( nullptr ){} |
75 | | }; |
76 | | |
77 | | class ScValidationDlg; |
78 | | |
79 | | /** The tab page "Criteria" from the Validation dialog. */ |
80 | | class ScTPValidationValue : public ScRefHandlerCaller, public SfxTabPage |
81 | | { |
82 | | static const WhichRangesContainer pValueRanges; |
83 | | public: |
84 | | explicit ScTPValidationValue(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rArgSet); |
85 | | static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rArgSet ); |
86 | | virtual ~ScTPValidationValue() override; |
87 | | |
88 | 0 | static const WhichRangesContainer& GetRanges() { return pValueRanges; } |
89 | | |
90 | | virtual bool FillItemSet( SfxItemSet* rArgSet ) override; |
91 | | virtual void Reset( const SfxItemSet* rArgSet ) override; |
92 | | |
93 | | private: |
94 | | void Init(); |
95 | | |
96 | | OUString GetFirstFormula() const; |
97 | | OUString GetSecondFormula() const; |
98 | | |
99 | | void SetFirstFormula( const OUString& rFmlaStr ); |
100 | | void SetSecondFormula( const OUString& rFmlaStr ); |
101 | | |
102 | | DECL_LINK(SelectHdl, weld::ComboBox&, void); |
103 | | DECL_LINK(CheckHdl, weld::Toggleable&, void); |
104 | | |
105 | | OUString maStrMin; |
106 | | OUString maStrMax; |
107 | | OUString maStrValue; |
108 | | OUString maStrFormula; |
109 | | OUString maStrRange; |
110 | | OUString maStrList; |
111 | | sal_Unicode mcFmlaSep; /// List separator in formulas. |
112 | | |
113 | | DECL_LINK( EditSetFocusHdl, formula::RefEdit&, void ); |
114 | | DECL_LINK( KillEditFocusHdl, formula::RefEdit&, void ); |
115 | | DECL_LINK( KillButtonFocusHdl, formula::RefButton&, void ); |
116 | | DECL_LINK( ClickHdl, formula::RefButton&, void ); |
117 | | |
118 | | formula::RefEdit* m_pRefEdit; |
119 | | |
120 | | std::unique_ptr<weld::ComboBox> m_xLbAllow; |
121 | | std::unique_ptr<weld::CheckButton> m_xCbAllow; /// Allow blank cells. |
122 | | std::unique_ptr<weld::CheckButton> m_xCbCaseSens; /// Allow Case sensitive. |
123 | | std::unique_ptr<weld::CheckButton> m_xCbShow; /// Show selection list in cell. |
124 | | std::unique_ptr<weld::CheckButton> m_xCbSort; /// Sort selection list in cell. |
125 | | std::unique_ptr<weld::Label> m_xFtValue; |
126 | | std::unique_ptr<weld::ComboBox> m_xLbValue; |
127 | | std::unique_ptr<weld::Label> m_xFtMin; |
128 | | std::unique_ptr<weld::Widget> m_xMinGrid; |
129 | | std::unique_ptr<formula::RefEdit> m_xEdMin; |
130 | | std::unique_ptr<weld::TextView> m_xEdList; /// Entries for explicit list |
131 | | std::unique_ptr<weld::Label> m_xFtMax; |
132 | | std::unique_ptr<formula::RefEdit> m_xEdMax; |
133 | | std::unique_ptr<weld::Label> m_xFtHint; /// Hint text for cell range validity. |
134 | | std::unique_ptr<formula::RefButton> m_xBtnRef; |
135 | | std::unique_ptr<weld::Grid> m_xRefGrid; |
136 | | |
137 | | weld::Container* m_pRefEditParent; |
138 | | weld::Container* m_pBtnRefParent; |
139 | | |
140 | | void SetReferenceHdl( const ScRange& , const ScDocument& ); |
141 | | void SetActiveHdl(); |
142 | | void RefInputStartPreHdl(formula::RefEdit* pEdit, const formula::RefButton* pButton); |
143 | | void RefInputDonePostHdl(); |
144 | | ScValidationDlg * GetValidationDlg(); |
145 | | public: |
146 | | void SetupRefDlg(); |
147 | | void RemoveRefDlg(bool bRestoreModal); |
148 | | }; |
149 | | |
150 | | /** The "Validity" tab dialog. */ |
151 | | class ScValidationDlg |
152 | | : public ScRefHdlrControllerImpl<SfxTabDialogController, false> |
153 | | , public ScRefHandlerHelper |
154 | | { |
155 | | typedef ScRefHdlrControllerImpl<SfxTabDialogController, false> ScValidationDlgBase; |
156 | | |
157 | | ScTabViewShell * m_pTabVwSh; |
158 | | OUString m_sValuePageId; |
159 | | bool m_bOwnRefHdlr:1; |
160 | | bool m_bRefInputting:1; |
161 | | |
162 | | std::unique_ptr<weld::Container> m_xHBox; |
163 | | |
164 | | bool EnterRefStatus(); |
165 | | bool LeaveRefStatus(); |
166 | | |
167 | | void ImplDestroy(); |
168 | | |
169 | | public: |
170 | | explicit ScValidationDlg(weld::Window* pParent, const SfxItemSet* pArgSet, ScTabViewShell* pTabViewSh); |
171 | | virtual ~ScValidationDlg() override; |
172 | | static std::shared_ptr<SfxDialogController> Find1AliveObject(const weld::Window *pAncestor) |
173 | 0 | { |
174 | 0 | return ScModule::get()->Find1RefWindow(SLOTID, pAncestor); |
175 | 0 | } |
176 | | ScTabViewShell *GetTabViewShell() |
177 | 0 | { |
178 | 0 | return m_pTabVwSh; |
179 | 0 | } |
180 | | |
181 | | bool SetupRefDlg(); |
182 | | bool RemoveRefDlg(bool bRestoreModal); |
183 | | |
184 | 0 | void SetModal(bool bModal) { m_xDialog->set_modal(bModal); } |
185 | | |
186 | | virtual void EndDialog(int nResponse) override; |
187 | | |
188 | 0 | virtual bool CloseOnHide() const override { return false; } |
189 | | |
190 | | virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override |
191 | 0 | { |
192 | 0 | if ( m_pHandler && m_pSetReferenceHdl ) |
193 | 0 | (m_pHandler->*m_pSetReferenceHdl)( rRef, rDoc ); |
194 | 0 | } |
195 | | |
196 | | virtual void SetActive() override |
197 | 0 | { |
198 | 0 | if ( m_pHandler && m_pSetActiveHdl ) |
199 | 0 | (m_pHandler->*m_pSetActiveHdl)(); |
200 | 0 | } |
201 | | |
202 | 0 | bool IsRefInputting() const { return m_bRefInputting; } |
203 | 0 | weld::Container* get_refinput_shrink_parent() { return m_xHBox.get(); } |
204 | | |
205 | | virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = nullptr ) override |
206 | 0 | { |
207 | 0 | if( !CanInputStart( pEdit ) ) |
208 | 0 | return; |
209 | | |
210 | 0 | if ( m_pHandler && m_pRefInputStartPreHdl ) |
211 | 0 | (m_pHandler->*m_pRefInputStartPreHdl)( pEdit, pButton ); |
212 | 0 | m_bRefInputting = true; |
213 | 0 | ScValidationDlgBase::RefInputStart( pEdit, pButton ); |
214 | 0 | } |
215 | | |
216 | | virtual void RefInputDone( bool bForced = false ) override |
217 | 0 | { |
218 | 0 | if( !CanInputDone( bForced ) ) |
219 | 0 | return; |
220 | | |
221 | 0 | ScValidationDlgBase::RefInputDone( bForced ); |
222 | 0 | m_bRefInputting = false; |
223 | |
|
224 | 0 | if ( m_pHandler && m_pRefInputDonePostHdl ) |
225 | 0 | (m_pHandler->*m_pRefInputDonePostHdl)(); |
226 | 0 | } |
227 | | |
228 | | bool IsChildFocus() const; |
229 | | |
230 | | enum { SLOTID = SID_VALIDITY_REFERENCE }; |
231 | | |
232 | | virtual void Close() override |
233 | 0 | { |
234 | 0 | if (m_bOwnRefHdlr) |
235 | 0 | { |
236 | 0 | if (SfxTabPage* pPage = GetTabPage(m_sValuePageId)) |
237 | 0 | static_cast<ScTPValidationValue*>(pPage)->RemoveRefDlg(false); |
238 | 0 | } |
239 | 0 | ScValidationDlgBase::Close(); |
240 | 0 | } |
241 | | }; |
242 | | |
243 | | class ScTPValidationHelp : public SfxTabPage |
244 | | { |
245 | | private: |
246 | | std::unique_ptr<weld::CheckButton> m_xTsbHelp; |
247 | | std::unique_ptr<weld::Entry> m_xEdtTitle; |
248 | | std::unique_ptr<weld::TextView> m_xEdInputHelp; |
249 | | |
250 | | public: |
251 | | ScTPValidationHelp(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rArgSet); |
252 | | static std::unique_ptr<SfxTabPage> Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rArgSet); |
253 | | virtual ~ScTPValidationHelp() override; |
254 | | |
255 | | virtual bool FillItemSet ( SfxItemSet* rArgSet ) override; |
256 | | virtual void Reset ( const SfxItemSet* rArgSet ) override; |
257 | | }; |
258 | | |
259 | | class ScTPValidationError : public SfxTabPage |
260 | | { |
261 | | private: |
262 | | std::unique_ptr<weld::CheckButton> m_xTsbShow; |
263 | | std::unique_ptr<weld::ComboBox> m_xLbAction; |
264 | | std::unique_ptr<weld::Button> m_xBtnSearch; |
265 | | std::unique_ptr<weld::Entry> m_xEdtTitle; |
266 | | std::unique_ptr<weld::Label> m_xFtError; |
267 | | std::unique_ptr<weld::Label> m_xFtTitle; |
268 | | std::unique_ptr<weld::Label> m_xFtAction; |
269 | | std::unique_ptr<weld::TextView> m_xEdError; |
270 | | |
271 | | void Init(); |
272 | | |
273 | | // Handler ------------------------ |
274 | | DECL_LINK(ToggleErrorMessage, weld::Toggleable&, void); |
275 | | DECL_LINK(SelectActionHdl, weld::ComboBox&, void); |
276 | | DECL_LINK(ClickSearchHdl, weld::Button&, void); |
277 | | |
278 | | public: |
279 | | ScTPValidationError(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rArgSet); |
280 | | static std::unique_ptr<SfxTabPage> Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rArgSet); |
281 | | virtual ~ScTPValidationError() override; |
282 | | |
283 | | virtual bool FillItemSet ( SfxItemSet* rArgSet ) override; |
284 | | virtual void Reset ( const SfxItemSet* rArgSet ) override; |
285 | | }; |
286 | | |
287 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |