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 SC_ANYREFDG_HXX
21 #define SC_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::auto_ptr
<ScCompiler
> pRefComp
;
48 formula::RefEdit
* pRefEdit
; // active input field
49 formula::RefButton
* pRefBtn
; // associated button
51 SfxBindings
* m_pBindings
;
52 ::std::auto_ptr
<Accelerator
>
53 pAccel
; // for Enter/Escape
54 ::std::vector
<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 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( AccelSelectHdl
, Accelerator
* );
75 ScFormulaReferenceHelper(IAnyRefDialog
* _pDlg
,SfxBindings
* _pBindings
);
76 ~ScFormulaReferenceHelper();
78 void ShowSimpleReference(const OUString
& rStr
);
79 void ShowFormulaReference(const OUString
& rStr
);
80 bool ParseWithNames( ScRangeList
& rRanges
, const OUString
& rStr
, ScDocument
* pDoc
);
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
);
90 inline void SetWindow(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();
96 static void enableInput(bool _bInput
);
99 Window
* GetWindow(){ return m_pWindow
; }
102 bool CanInputStart( const formula::RefEdit
*pEdit
){ return !!pEdit
; }
103 bool CanInputDone( bool bForced
){ return pRefEdit
&& (bForced
|| !pRefBtn
); }
106 //============================================================================
108 class SC_DLLPUBLIC ScRefHandler
:
115 operator Window
*(){ return &m_rWindow
; }
116 Window
* operator ->() { return static_cast<Window
*>(*this); }
117 friend class formula::RefButton
;
118 friend class formula::RefEdit
;
121 ScFormulaReferenceHelper
123 SfxBindings
* pMyBindings
;
127 OUString aDocName
; // document on which the dialog was opened
129 DECL_LINK( UpdateFocusHdl
, void* );
133 virtual sal_Bool
DoClose( sal_uInt16 nId
);
135 void SetDispatcherLock( bool bLock
);
137 virtual void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= NULL
);
138 virtual void RefInputDone( sal_Bool bForced
= false );
139 void ShowSimpleReference(const OUString
& rStr
);
140 void ShowFormulaReference(const OUString
& rStr
);
142 bool ParseWithNames( ScRangeList
& rRanges
, const OUString
& rStr
, ScDocument
* pDoc
);
144 void preNotify(const NotifyEvent
& rEvent
, const bool bBindRef
);
145 void stateChanged(const StateChangedType nStateChange
, const bool bBindRef
);
148 ScRefHandler( Window
&rWindow
, SfxBindings
* pB
, bool bBindRef
);
149 virtual ~ScRefHandler();
151 virtual void SetReference( const ScRange
& rRef
, ScDocument
* pDoc
) = 0;
152 virtual void AddRefEntry();
154 virtual sal_Bool
IsRefInputMode() const;
155 virtual sal_Bool
IsTableLocked() const;
156 virtual sal_Bool
IsDocAllowed( SfxObjectShell
* pDocSh
) const;
158 virtual void ShowReference(const OUString
& rStr
);
159 virtual void HideReference( sal_Bool bDoneRefMode
= sal_True
);
161 virtual void ToggleCollapsed( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= NULL
);
162 virtual void ReleaseFocus( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= NULL
);
164 virtual void ViewShellChanged();
165 void SwitchToDocument();
167 virtual void SetActive() = 0;
172 inline bool CanInputStart( const formula::RefEdit
*pEdit
);
173 inline bool CanInputDone( sal_Bool bForced
);
176 //============================================================================
179 class ScRefHdlModalImpl
: public ModalDialog
, public ScRefHandler
183 virtual long PreNotify( NotifyEvent
& rNEvt
);
184 virtual void StateChanged( StateChangedType nStateChange
);
186 ScRefHdlModalImpl( Window
* pParent
, const ResId
& rResId
);
191 template< class TWindow
, bool bBindRef
= true >
192 class ScRefHdlrImplBase
: public TWindow
, public ScRefHandler
195 virtual long PreNotify( NotifyEvent
& rNEvt
);
196 virtual void StateChanged( StateChangedType nStateChange
);
199 template<class TBindings
, class TChildWindow
, class TParentWindow
, class TResId
>
200 ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
201 TParentWindow
* pParent
, TResId nResId
);
203 template<class TBindings
, class TChildWindow
, class TParentWindow
>
204 ScRefHdlrImplBase( TBindings
* pB
, TChildWindow
* pCW
,
205 TParentWindow
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
);
207 template<class TParentWindow
, class TResId
, class TArg
>
208 ScRefHdlrImplBase( TParentWindow
* pParent
, TResId nResId
, const TArg
&rArg
, SfxBindings
*pB
= NULL
);
210 ~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 OString
& 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 ScRefHdlrImplBase
<TWindow
,bBindRef
>::~ScRefHdlrImplBase(){}
244 template<class TWindow
, bool bBindRef
>
245 long ScRefHdlrImplBase
<TWindow
, bBindRef
>::PreNotify( NotifyEvent
& rNEvt
)
247 ScRefHandler::preNotify( rNEvt
, bBindRef
);
248 return TWindow::PreNotify( rNEvt
);
251 template<class TWindow
, bool bBindRef
>
252 void ScRefHdlrImplBase
<TWindow
, bBindRef
>::StateChanged( StateChangedType nStateChange
)
254 TWindow::StateChanged( nStateChange
);
255 ScRefHandler::stateChanged( nStateChange
, bBindRef
);
258 class ScAnyRefModalDlg
: public ScRefHdlModalImpl
261 ScAnyRefModalDlg(Window
* pParent
, const ResId
& rResId
);
264 //============================================================================
265 template<class TDerived
, class TBase
, bool bBindRef
= true>
266 struct ScRefHdlrImpl
: ScRefHdlrImplBase
< TBase
, bBindRef
>
268 enum { UNKNOWN_SLOTID
= 0U, SLOTID
= UNKNOWN_SLOTID
};
270 template<class T1
, class T2
, class T3
, class T4
>
271 ScRefHdlrImpl( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
)
272 : ScRefHdlrImplBase
<TBase
, bBindRef
>(rt1
, rt2
, rt3
, rt4
)
274 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16
>( static_cast<TDerived
*>(this)->SLOTID
), this );
277 template<class T1
, class T2
, class T3
, class T4
, class T5
>
278 ScRefHdlrImpl( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
, const T5
& rt5
)
279 : ScRefHdlrImplBase
<TBase
, bBindRef
>(rt1
, rt2
, rt3
, rt4
, rt5
)
281 SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16
>( static_cast<TDerived
*>(this)->SLOTID
), this );
286 SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16
>( static_cast<TDerived
*>(this)->SLOTID
), this );
289 //============================================================================
290 struct ScAnyRefDlg
: ::ScRefHdlrImpl
< ScAnyRefDlg
, SfxModelessDialog
>
292 template<class T1
, class T2
, class T3
, class T4
>
293 ScAnyRefDlg( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
)
294 : ScRefHdlrImpl
< ScAnyRefDlg
, SfxModelessDialog
>(rt1
, rt2
, rt3
, rt4
)
298 template<class T1
, class T2
, class T3
, class T4
, class T5
>
299 ScAnyRefDlg( const T1
& rt1
, const T2
& rt2
, const T3
& rt3
, const T4
& rt4
, const T5
& rt5
)
300 : ScRefHdlrImpl
< ScAnyRefDlg
, SfxModelessDialog
>(rt1
, rt2
, rt3
, rt4
, rt5
)
304 //============================================================================
306 inline bool ScRefHandler::CanInputStart( const formula::RefEdit
*pEdit
)
308 return m_aHelper
.CanInputStart( pEdit
);
311 inline bool ScRefHandler::CanInputDone( sal_Bool bForced
)
313 return m_aHelper
.CanInputDone( bForced
);
316 #endif // SC_ANYREFDG_HXX
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */