Line data Source code
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 : #ifndef INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
21 : #define INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
22 :
23 : #include <vcl/button.hxx>
24 : #include <vcl/edit.hxx>
25 : #include <vcl/accel.hxx>
26 : #include <sfx2/basedlgs.hxx>
27 : #include <sfx2/tabdlg.hxx>
28 : #include "address.hxx"
29 : #include "compiler.hxx"
30 : #include <formula/funcutl.hxx>
31 : #include "IAnyRefDialog.hxx"
32 : #include "scresid.hxx"
33 : #include "scmod.hxx"
34 :
35 : #include <memory>
36 :
37 : class SfxObjectShell;
38 : class ScRange;
39 : class ScDocument;
40 : class ScTabViewShell;
41 : class ScRefHandler;
42 : class ScRangeList;
43 :
44 : class ScFormulaReferenceHelper
45 : {
46 : IAnyRefDialog* m_pDlg;
47 : ::std::unique_ptr<ScCompiler> pRefComp;
48 : formula::RefEdit* pRefEdit; // active input field
49 : formula::RefButton* pRefBtn; // associated button
50 : vcl::Window* m_pWindow;
51 : SfxBindings* m_pBindings;
52 : ::std::unique_ptr<Accelerator>
53 : pAccel; // for Enter/Escape
54 : ::std::vector<vcl::Window*> m_aHiddenWidgets; // vector of hidden Controls
55 : sal_Int32 m_nOldBorderWidth; // border width for expanded dialog
56 : SCTAB nRefTab; // used for ShowReference
57 :
58 : OUString sOldDialogText; // Original title of the dialog window
59 : Size aOldDialogSize; // Original size of the dialog window
60 : Point aOldEditPos; // Original position of the input field
61 : Size aOldEditSize; // Original size of the input field
62 : long mnOldEditWidthReq;
63 : Point aOldButtonPos; // Original position of the button
64 : vcl::Window* mpOldEditParent; // Original parent of the edit field and the button
65 : bool mbOldDlgLayoutEnabled; // Original layout state of parent dialog
66 : bool mbOldEditParentLayoutEnabled; // Original layout state of edit widget parent
67 :
68 : bool bEnableColorRef;
69 : bool bHighlightRef;
70 : bool bAccInserted;
71 :
72 : DECL_LINK( AccelSelectHdl, Accelerator* );
73 :
74 : public:
75 : ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings);
76 : ~ScFormulaReferenceHelper();
77 :
78 : void ShowSimpleReference(const OUString& rStr);
79 : void ShowFormulaReference(const OUString& rStr);
80 : bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
81 : void Init();
82 :
83 : void ShowReference(const OUString& rStr);
84 : void ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
85 : void HideReference( bool bDoneRefMode = true );
86 : void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
87 : void RefInputDone( bool bForced = false );
88 : void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
89 :
90 0 : inline void SetWindow(vcl::Window* _pWindow) { m_pWindow = _pWindow; }
91 : bool DoClose( sal_uInt16 nId );
92 : void SetDispatcherLock( bool bLock );
93 : void EnableSpreadsheets( bool bFlag = true, bool bChildren = true );
94 : void ViewShellChanged();
95 :
96 : static void enableInput(bool _bInput);
97 :
98 : protected:
99 : vcl::Window* GetWindow(){ return m_pWindow; }
100 :
101 : public:
102 0 : bool CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
103 0 : bool CanInputDone( bool bForced ){ return pRefEdit && (bForced || !pRefBtn); }
104 : };
105 :
106 : class SC_DLLPUBLIC ScRefHandler :
107 : public IAnyRefDialog
108 : {
109 : vcl::Window & m_rWindow;
110 : bool m_bInRefMode;
111 :
112 : public:
113 0 : operator vcl::Window *(){ return &m_rWindow; }
114 : vcl::Window* operator ->() { return static_cast<vcl::Window *>(*this); }
115 : friend class formula::RefButton;
116 : friend class formula::RefEdit;
117 :
118 : private:
119 : ScFormulaReferenceHelper
120 : m_aHelper;
121 : SfxBindings* pMyBindings;
122 :
123 : vcl::Window* pActiveWin;
124 : Timer aTimer;
125 : OUString aDocName; // document on which the dialog was opened
126 :
127 : DECL_LINK( UpdateFocusHdl, void* );
128 :
129 : protected:
130 : virtual bool DoClose( sal_uInt16 nId );
131 :
132 : void SetDispatcherLock( bool bLock );
133 :
134 : virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
135 : virtual void RefInputDone( bool bForced = false ) SAL_OVERRIDE;
136 : void ShowSimpleReference(const OUString& rStr);
137 : void ShowFormulaReference(const OUString& rStr);
138 :
139 : bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
140 :
141 : void preNotify(const NotifyEvent& rEvent, const bool bBindRef);
142 : void stateChanged(const StateChangedType nStateChange, const bool bBindRef);
143 :
144 : public:
145 : ScRefHandler( vcl::Window &rWindow, SfxBindings* pB, bool bBindRef );
146 : virtual ~ScRefHandler();
147 :
148 : virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE = 0;
149 : virtual void AddRefEntry() SAL_OVERRIDE;
150 :
151 : virtual bool IsRefInputMode() const SAL_OVERRIDE;
152 : virtual bool IsTableLocked() const SAL_OVERRIDE;
153 : virtual bool IsDocAllowed( SfxObjectShell* pDocSh ) const SAL_OVERRIDE;
154 :
155 : virtual void ShowReference(const OUString& rStr) SAL_OVERRIDE;
156 : virtual void HideReference( bool bDoneRefMode = true ) SAL_OVERRIDE;
157 :
158 : virtual void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
159 : virtual void ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
160 :
161 : virtual void ViewShellChanged() SAL_OVERRIDE;
162 : void SwitchToDocument();
163 :
164 : virtual void SetActive() SAL_OVERRIDE = 0;
165 :
166 : public:
167 : bool EnterRefMode();
168 : bool LeaveRefMode();
169 : inline bool CanInputStart( const formula::RefEdit *pEdit );
170 : inline bool CanInputDone( bool bForced );
171 : };
172 :
173 0 : class ScRefHdlModalImpl : public ModalDialog, public ScRefHandler
174 : {
175 : public:
176 :
177 : virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
178 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
179 : protected:
180 : ScRefHdlModalImpl(vcl::Window* pParent, const OString& rID,
181 : const OUString& rUIXMLDescription);
182 :
183 : private:
184 : };
185 :
186 : template< class TWindow, bool bBindRef = true >
187 : class ScRefHdlrImplBase: public TWindow, public ScRefHandler
188 : {
189 : public:
190 : virtual bool PreNotify( NotifyEvent& rNEvt );
191 : virtual void StateChanged( StateChangedType nStateChange );
192 :
193 : private:
194 : template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
195 : ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
196 : TParentWindow* pParent, TResId nResId );
197 :
198 : template<class TBindings, class TChildWindow, class TParentWindow >
199 : ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
200 : TParentWindow* pParent, const OString& rID, const OUString& rUIXMLDescription );
201 :
202 : template<class TParentWindow, class TResId, class TArg>
203 : ScRefHdlrImplBase( TParentWindow* pParent, TResId nResId, const TArg &rArg, SfxBindings *pB = NULL );
204 :
205 : template<class TParentWindow, class TArg>
206 : ScRefHdlrImplBase( TParentWindow* pParent, const OString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB = NULL );
207 :
208 : virtual ~ScRefHdlrImplBase();
209 :
210 : template<class, class, bool> friend struct ScRefHdlrImpl;
211 : };
212 :
213 : template<class TWindow, bool bBindRef>
214 : template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
215 : ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
216 : TParentWindow* pParent, TResId nResId)
217 : : TWindow(pB, pCW, pParent, ScResId(static_cast<sal_uInt16>( nResId ) ) )
218 : , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
219 : {
220 : }
221 :
222 : template<class TWindow, bool bBindRef>
223 : template<class TBindings, class TChildWindow, class TParentWindow>
224 0 : ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
225 : TParentWindow* pParent, const OString& rID, const OUString& rUIXMLDescription )
226 : : TWindow(pB, pCW, pParent, rID, rUIXMLDescription )
227 0 : , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
228 : {
229 0 : }
230 :
231 : template<class TWindow, bool bBindRef >
232 : template<class TParentWindow, class TResId, class TArg>
233 : ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, TResId nResIdP, const TArg &rArg, SfxBindings *pB )
234 : : TWindow( pParent, ScResId(static_cast<sal_uInt16>( nResIdP )), rArg ),
235 : ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
236 : {
237 : }
238 :
239 : template<class TWindow, bool bBindRef >
240 : template<class TParentWindow, class TArg>
241 0 : ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, const OString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB )
242 : : TWindow( pParent, rID, rUIXMLDescription, rArg ),
243 0 : ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
244 : {
245 0 : }
246 :
247 : template<class TWindow, bool bBindRef >
248 0 : ScRefHdlrImplBase<TWindow,bBindRef>::~ScRefHdlrImplBase(){}
249 :
250 : template<class TWindow, bool bBindRef>
251 0 : bool ScRefHdlrImplBase<TWindow, bBindRef>::PreNotify( NotifyEvent& rNEvt )
252 : {
253 0 : ScRefHandler::preNotify( rNEvt, bBindRef );
254 0 : return TWindow::PreNotify( rNEvt );
255 : }
256 :
257 : template<class TWindow, bool bBindRef>
258 0 : void ScRefHdlrImplBase<TWindow, bBindRef>::StateChanged( StateChangedType nStateChange )
259 : {
260 0 : TWindow::StateChanged( nStateChange );
261 0 : ScRefHandler::stateChanged( nStateChange, bBindRef );
262 0 : }
263 :
264 0 : class ScAnyRefModalDlg : public ScRefHdlModalImpl
265 : {
266 : public:
267 : ScAnyRefModalDlg(vcl::Window* pParent, const OString& rID,
268 : const OUString& rUIXMLDescription);
269 : };
270 :
271 : template<class TDerived, class TBase, bool bBindRef = true>
272 : struct ScRefHdlrImpl: ScRefHdlrImplBase< TBase, bBindRef >
273 : {
274 : enum { UNKNOWN_SLOTID = 0U, SLOTID = UNKNOWN_SLOTID };
275 :
276 : template<class T1, class T2, class T3, class T4>
277 : ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
278 : : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4)
279 : {
280 : SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
281 : }
282 :
283 : template<class T1, class T2, class T3, class T4, class T5>
284 0 : ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
285 0 : : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4, rt5)
286 : {
287 0 : SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
288 0 : }
289 :
290 0 : ~ScRefHdlrImpl()
291 : {
292 0 : SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
293 0 : }
294 : };
295 :
296 0 : struct ScAnyRefDlg : ::ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>
297 : {
298 : template<class T1, class T2, class T3, class T4>
299 : ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
300 : : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4)
301 : {
302 : }
303 :
304 : template<class T1, class T2, class T3, class T4, class T5>
305 0 : ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
306 0 : : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4, rt5)
307 : {
308 0 : }
309 : };
310 :
311 0 : inline bool ScRefHandler::CanInputStart( const formula::RefEdit *pEdit )
312 : {
313 0 : return m_aHelper.CanInputStart( pEdit );
314 : }
315 :
316 0 : inline bool ScRefHandler::CanInputDone( bool bForced )
317 : {
318 0 : return m_aHelper.CanInputDone( bForced );
319 : }
320 :
321 : #endif // INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
322 :
323 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|