fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / inc / anyrefdg.hxx
blob249a8b851ec2bade94ba8d2e547efcd9b308a869
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_ANYREFDG_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
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"
35 #include <memory>
37 class SfxObjectShell;
38 class ScRange;
39 class ScDocument;
40 class ScTabViewShell;
41 class ScRefHandler;
42 class ScRangeList;
44 class ScFormulaReferenceHelper
46 IAnyRefDialog* m_pDlg;
47 ::std::unique_ptr<ScCompiler> pRefComp;
48 VclPtr<formula::RefEdit> pRefEdit; // active input field
49 VclPtr<formula::RefButton> pRefBtn; // associated button
50 VclPtr<vcl::Window> m_pWindow;
51 SfxBindings* m_pBindings;
52 ::std::unique_ptr<Accelerator>
53 pAccel; // for Enter/Escape
54 ::std::vector<VclPtr<vcl::Window> > m_aHiddenWidgets; // vector of hidden Controls
55 sal_Int32 m_nOldBorderWidth; // border width for expanded dialog
56 SCTAB nRefTab; // used for ShowReference
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 VclPtr<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
68 bool bEnableColorRef;
69 bool bHighlightRef;
70 bool bAccInserted;
72 DECL_LINK( AccelSelectHdl, Accelerator* );
74 public:
75 ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings);
76 ~ScFormulaReferenceHelper();
77 void dispose();
79 void ShowSimpleReference(const OUString& rStr);
80 void ShowFormulaReference(const OUString& rStr);
81 bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
82 void Init();
84 void ShowReference(const OUString& rStr);
85 void ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
86 void HideReference( bool bDoneRefMode = true );
87 void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
88 void RefInputDone( bool bForced = false );
89 void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
91 inline void SetWindow(vcl::Window* _pWindow) { m_pWindow = _pWindow; }
92 bool DoClose( sal_uInt16 nId );
93 static void SetDispatcherLock( bool bLock );
94 static void EnableSpreadsheets( bool bFlag = true, bool bChildren = true );
95 static void ViewShellChanged();
97 static void enableInput(bool _bInput);
99 protected:
100 vcl::Window* GetWindow(){ return m_pWindow; }
102 public:
103 static bool CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
104 bool CanInputDone( bool bForced ){ return pRefEdit && (bForced || !pRefBtn); }
107 class SC_DLLPUBLIC ScRefHandler :
108 public IAnyRefDialog
110 VclPtr<vcl::Window> m_rWindow;
111 bool m_bInRefMode;
113 public:
114 operator vcl::Window *(){ return m_rWindow.get(); }
115 vcl::Window* operator ->() { return static_cast<vcl::Window *>(*this); }
116 friend class formula::RefButton;
117 friend class formula::RefEdit;
119 private:
120 ScFormulaReferenceHelper
121 m_aHelper;
122 SfxBindings* pMyBindings;
124 VclPtr<vcl::Window> pActiveWin;
125 Idle aIdle;
126 OUString aDocName; // document on which the dialog was opened
128 DECL_LINK_TYPED( UpdateFocusHdl, Idle*, void );
130 protected:
131 void disposeRefHandler();
132 bool DoClose( sal_uInt16 nId );
134 static void SetDispatcherLock( bool bLock );
136 virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
137 virtual void RefInputDone( bool bForced = false ) SAL_OVERRIDE;
138 void ShowSimpleReference(const OUString& rStr);
139 void ShowFormulaReference(const OUString& rStr);
141 bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
143 void preNotify(const NotifyEvent& rEvent, const bool bBindRef);
144 void stateChanged(const StateChangedType nStateChange, const bool bBindRef);
146 public:
147 ScRefHandler( vcl::Window &rWindow, SfxBindings* pB, bool bBindRef );
148 virtual ~ScRefHandler();
150 virtual void SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE = 0;
151 virtual void AddRefEntry() SAL_OVERRIDE;
153 virtual bool IsRefInputMode() const SAL_OVERRIDE;
154 virtual bool IsTableLocked() const SAL_OVERRIDE;
155 virtual bool IsDocAllowed( SfxObjectShell* pDocSh ) const SAL_OVERRIDE;
157 virtual void ShowReference(const OUString& rStr) SAL_OVERRIDE;
158 virtual void HideReference( bool bDoneRefMode = true ) SAL_OVERRIDE;
160 virtual void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
161 virtual void ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
163 virtual void ViewShellChanged() SAL_OVERRIDE;
164 void SwitchToDocument();
166 virtual void SetActive() SAL_OVERRIDE = 0;
168 public:
169 bool EnterRefMode();
170 bool LeaveRefMode();
171 static inline bool CanInputStart( const formula::RefEdit *pEdit );
172 inline bool CanInputDone( bool bForced );
175 class ScRefHdlModalImpl : public ModalDialog, public ScRefHandler
177 public:
179 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
180 virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
181 protected:
182 ScRefHdlModalImpl(vcl::Window* pParent, const OUString& rID,
183 const OUString& rUIXMLDescription);
185 private:
188 template< class TWindow, bool bBindRef = true >
189 class ScRefHdlrImplBase: public TWindow, public ScRefHandler
191 public:
192 virtual bool PreNotify( NotifyEvent& rNEvt );
193 virtual void StateChanged( StateChangedType nStateChange );
195 private:
196 template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
197 ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
198 TParentWindow* pParent, TResId nResId );
200 template<class TBindings, class TChildWindow, class TParentWindow >
201 ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
202 TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription );
204 template<class TParentWindow, class TResId, class TArg>
205 ScRefHdlrImplBase( TParentWindow* pParent, TResId nResId, const TArg &rArg, SfxBindings *pB = NULL );
207 template<class TParentWindow, class TArg>
208 ScRefHdlrImplBase( TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB = NULL );
210 virtual ~ScRefHdlrImplBase();
212 template<class, class, bool> friend struct ScRefHdlrImpl;
215 template<class TWindow, bool bBindRef>
216 template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
217 ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
218 TParentWindow* pParent, TResId nResId)
219 : TWindow(pB, pCW, pParent, ScResId(static_cast<sal_uInt16>( nResId ) ) )
220 , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
224 template<class TWindow, bool bBindRef>
225 template<class TBindings, class TChildWindow, class TParentWindow>
226 ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
227 TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription )
228 : TWindow(pB, pCW, pParent, rID, rUIXMLDescription )
229 , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
233 template<class TWindow, bool bBindRef >
234 template<class TParentWindow, class TResId, class TArg>
235 ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, TResId nResIdP, const TArg &rArg, SfxBindings *pB )
236 : TWindow( pParent, ScResId(static_cast<sal_uInt16>( nResIdP )), rArg ),
237 ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
241 template<class TWindow, bool bBindRef >
242 template<class TParentWindow, class TArg>
243 ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB )
244 : TWindow( pParent, rID, rUIXMLDescription, rArg ),
245 ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
249 template<class TWindow, bool bBindRef >
250 ScRefHdlrImplBase<TWindow,bBindRef>::~ScRefHdlrImplBase(){}
252 template<class TWindow, bool bBindRef>
253 bool ScRefHdlrImplBase<TWindow, bBindRef>::PreNotify( NotifyEvent& rNEvt )
255 ScRefHandler::preNotify( rNEvt, bBindRef );
256 return TWindow::PreNotify( rNEvt );
259 template<class TWindow, bool bBindRef>
260 void ScRefHdlrImplBase<TWindow, bBindRef>::StateChanged( StateChangedType nStateChange )
262 TWindow::StateChanged( nStateChange );
263 ScRefHandler::stateChanged( nStateChange, bBindRef );
266 template<class TDerived, class TBase, bool bBindRef = true>
267 struct ScRefHdlrImpl: ScRefHdlrImplBase< TBase, bBindRef >
269 enum { UNKNOWN_SLOTID = 0U, SLOTID = UNKNOWN_SLOTID };
271 template<class T1, class T2, class T3, class T4>
272 ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
273 : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4)
275 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
278 template<class T1, class T2, class T3, class T4, class T5>
279 ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
280 : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4, rt5)
282 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
285 virtual void dispose() SAL_OVERRIDE
287 SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
288 ScRefHdlrImplBase<TBase, bBindRef >::disposeRefHandler();
289 TBase::dispose();
292 ~ScRefHdlrImpl()
294 TBase::disposeOnce();
298 struct ScAnyRefDlg : ::ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>
300 template<class T1, class T2, class T3, class T4>
301 ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
302 : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4)
306 template<class T1, class T2, class T3, class T4, class T5>
307 ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
308 : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4, rt5)
313 inline bool ScRefHandler::CanInputStart( const formula::RefEdit *pEdit )
315 return ScFormulaReferenceHelper::CanInputStart( pEdit );
318 inline bool ScRefHandler::CanInputDone( bool bForced )
320 return m_aHelper.CanInputDone( bForced );
323 #endif // INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */