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_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"
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
72 DECL_LINK_TYPED( AccelSelectHdl
, Accelerator
&, void );
75 ScFormulaReferenceHelper(IAnyRefDialog
* _pDlg
,SfxBindings
* _pBindings
);
76 ~ScFormulaReferenceHelper();
79 void ShowSimpleReference(const OUString
& rStr
);
80 void ShowFormulaReference(const OUString
& rStr
);
81 bool ParseWithNames( ScRangeList
& rRanges
, const OUString
& rStr
, ScDocument
* pDoc
);
84 void ShowReference(const OUString
& rStr
);
85 void ReleaseFocus( formula::RefEdit
* pEdit
);
86 void HideReference( bool bDoneRefMode
= true );
87 void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr );
88 void RefInputDone( bool bForced
= false );
89 void ToggleCollapsed( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr );
91 inline void SetWindow(vcl::Window
* _pWindow
) { m_pWindow
= _pWindow
; }
92 void DoClose( sal_uInt16 nId
);
93 static void SetDispatcherLock( bool bLock
);
94 static void EnableSpreadsheets( bool bFlag
= true );
95 static void ViewShellChanged();
97 static void enableInput(bool _bInput
);
100 static bool CanInputStart( const formula::RefEdit
*pEdit
){ return !!pEdit
; }
101 bool CanInputDone( bool bForced
){ return pRefEdit
&& (bForced
|| !pRefBtn
); }
104 class SC_DLLPUBLIC ScRefHandler
:
107 VclPtr
<vcl::Window
> m_rWindow
;
111 operator vcl::Window
*(){ return m_rWindow
.get(); }
112 friend class formula::RefButton
;
113 friend class formula::RefEdit
;
116 ScFormulaReferenceHelper
118 SfxBindings
* pMyBindings
;
120 VclPtr
<vcl::Window
> pActiveWin
;
122 OUString aDocName
; // document on which the dialog was opened
124 DECL_LINK_TYPED( UpdateFocusHdl
, Idle
*, void );
127 void disposeRefHandler();
128 bool DoClose( sal_uInt16 nId
);
130 static void SetDispatcherLock( bool bLock
);
132 virtual void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr ) override
;
133 virtual void RefInputDone( bool bForced
= false ) override
;
135 bool ParseWithNames( ScRangeList
& rRanges
, const OUString
& rStr
, ScDocument
* pDoc
);
138 ScRefHandler( vcl::Window
&rWindow
, SfxBindings
* pB
, bool bBindRef
);
139 virtual ~ScRefHandler();
141 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
) override
= 0;
142 virtual void AddRefEntry() override
;
144 virtual bool IsRefInputMode() const override
;
145 virtual bool IsTableLocked() const override
;
146 virtual bool IsDocAllowed( SfxObjectShell
* pDocSh
) const override
;
148 virtual void ShowReference(const OUString
& rStr
) override
;
149 virtual void HideReference( bool bDoneRefMode
= true ) override
;
151 virtual void ToggleCollapsed( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr ) override
;
152 virtual void ReleaseFocus( formula::RefEdit
* pEdit
) override
;
154 virtual void ViewShellChanged() override
;
155 void SwitchToDocument();
157 virtual void SetActive() override
= 0;
162 static inline bool CanInputStart( const formula::RefEdit
*pEdit
);
163 inline bool CanInputDone( bool bForced
);
166 template< class TWindow
, bool bBindRef
= true >
167 class ScRefHdlrImplBase
: public TWindow
, public ScRefHandler
170 template<class TBindings
, class TChildWindow
, class TParentWindow
, class TResId
>
171 ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
172 TParentWindow
* pParent
, TResId nResId
);
174 template<class TBindings
, class TChildWindow
, class TParentWindow
>
175 ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
176 TParentWindow
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
);
178 template<class TParentWindow
, class TResId
, class TArg
>
179 ScRefHdlrImplBase( TParentWindow
* pParent
, TResId nResId
, const TArg
&rArg
, SfxBindings
*pB
= nullptr );
181 template<class TParentWindow
, class TArg
>
182 ScRefHdlrImplBase( TParentWindow
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
, const TArg
&rArg
, SfxBindings
*pB
= nullptr );
184 virtual ~ScRefHdlrImplBase();
186 template<class, class, bool> friend struct ScRefHdlrImpl
;
189 template<class TWindow
, bool bBindRef
>
190 template<class TBindings
, class TChildWindow
, class TParentWindow
, class TResId
>
191 ScRefHdlrImplBase
<TWindow
, bBindRef
>::ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
192 TParentWindow
* pParent
, TResId nResId
)
193 : TWindow(pB
, pCW
, pParent
, ScResId(static_cast<sal_uInt16
>( nResId
) ) )
194 , ScRefHandler( *static_cast<TWindow
*>(this), pB
, bBindRef
)
198 template<class TWindow
, bool bBindRef
>
199 template<class TBindings
, class TChildWindow
, class TParentWindow
>
200 ScRefHdlrImplBase
<TWindow
, bBindRef
>::ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
201 TParentWindow
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
)
202 : TWindow(pB
, pCW
, pParent
, rID
, rUIXMLDescription
)
203 , ScRefHandler( *static_cast<TWindow
*>(this), pB
, bBindRef
)
207 template<class TWindow
, bool bBindRef
>
208 template<class TParentWindow
, class TResId
, class TArg
>
209 ScRefHdlrImplBase
<TWindow
,bBindRef
>::ScRefHdlrImplBase( TParentWindow
* pParent
, TResId nResIdP
, const TArg
&rArg
, SfxBindings
*pB
)
210 : TWindow( pParent
, ScResId(static_cast<sal_uInt16
>( nResIdP
)), rArg
),
211 ScRefHandler( *static_cast<TWindow
*>(this), pB
, bBindRef
)
215 template<class TWindow
, bool bBindRef
>
216 template<class TParentWindow
, class TArg
>
217 ScRefHdlrImplBase
<TWindow
,bBindRef
>::ScRefHdlrImplBase( TParentWindow
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
, const TArg
&rArg
, SfxBindings
*pB
)
218 : TWindow( pParent
, rID
, rUIXMLDescription
, rArg
),
219 ScRefHandler( *static_cast<TWindow
*>(this), pB
, bBindRef
)
223 template<class TWindow
, bool bBindRef
>
224 ScRefHdlrImplBase
<TWindow
,bBindRef
>::~ScRefHdlrImplBase(){}
226 template<class TDerived
, class TBase
, bool bBindRef
= true>
227 struct ScRefHdlrImpl
: ScRefHdlrImplBase
< TBase
, bBindRef
>
229 enum { UNKNOWN_SLOTID
= 0U, SLOTID
= UNKNOWN_SLOTID
};
231 template<class T1
, class T2
, class T3
, class T4
>
232 ScRefHdlrImpl( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
)
233 : ScRefHdlrImplBase
<TBase
, bBindRef
>(rt1
, rt2
, rt3
, rt4
)
235 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16
>( TDerived::SLOTID
), this );
238 template<class T1
, class T2
, class T3
, class T4
, class T5
>
239 ScRefHdlrImpl( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
, const T5
& rt5
)
240 : ScRefHdlrImplBase
<TBase
, bBindRef
>(rt1
, rt2
, rt3
, rt4
, rt5
)
242 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16
>( TDerived::SLOTID
), this );
245 virtual void dispose() override
247 SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16
>( TDerived::SLOTID
), this );
248 ScRefHdlrImplBase
<TBase
, bBindRef
>::disposeRefHandler();
254 TBase::disposeOnce();
258 struct ScAnyRefDlg
: ::ScRefHdlrImpl
< ScAnyRefDlg
, SfxModelessDialog
>
260 template<class T1
, class T2
, class T3
, class T4
, class T5
>
261 ScAnyRefDlg( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
, const T5
& rt5
)
262 : ScRefHdlrImpl
< ScAnyRefDlg
, SfxModelessDialog
>(rt1
, rt2
, rt3
, rt4
, rt5
)
267 inline bool ScRefHandler::CanInputStart( const formula::RefEdit
*pEdit
)
269 return ScFormulaReferenceHelper::CanInputStart( pEdit
);
272 inline bool ScRefHandler::CanInputDone( bool bForced
)
274 return m_aHelper
.CanInputDone( bForced
);
277 #endif // INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */