xref: /aoo42x/main/sc/source/ui/inc/anyrefdg.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_ANYREFDG_HXX
25 #define SC_ANYREFDG_HXX
26 
27 #ifndef _IMAGEBTN_HXX
28 #include <vcl/button.hxx>
29 #endif
30 #ifndef _EDIT_HXX
31 #include <vcl/edit.hxx>
32 #endif
33 #ifndef _ACCEL_HXX
34 #include <vcl/accel.hxx>
35 #endif
36 #include <sfx2/basedlgs.hxx>
37 #include "address.hxx"
38 #include "cell.hxx"
39 #include "compiler.hxx"
40 #include "formula/funcutl.hxx"
41 #include "IAnyRefDialog.hxx"
42 #include "scresid.hxx"
43 #include <memory>
44 
45 class SfxObjectShell;
46 class ScRange;
47 class ScDocument;
48 class ScTabViewShell;
49 //The class of ScAnyRefDlg is rewritten by PengYunQuan for Validity Cell Range Picker
50 //class ScAnyRefDlg;
51 class ScRefHandler;
52 class ScRangeList;
53 //<!--Added by PengYunQuan for Validity Cell Range Picker
54 class SfxShell;
55 #include "scmod.hxx"
56 
57 typedef    formula::RefButton	ScRefButton;
58 typedef        formula::RefEdit	ScRefEdit;
59 //-->Added by PengYunQuan for Validity Cell Range Picker
60 class ScFormulaReferenceHelper
61 {
62     IAnyRefDialog*      m_pDlg;
63     ::std::auto_ptr<ScFormulaCell>      pRefCell;
64     ::std::auto_ptr<ScCompiler>         pRefComp;
65     formula::RefEdit*    pRefEdit;               // aktives Eingabefeld
66     formula::RefButton*  pRefBtn;                // Button dazu
67     Window*             m_pWindow;
68     SfxBindings*        m_pBindings;
69     ::std::auto_ptr<Accelerator>
70                         pAccel;                 // fuer Enter/Escape
71     sal_Bool*               pHiddenMarks;           // Merkfeld fuer versteckte Controls
72     SCTAB               nRefTab;                // used for ShowReference
73 
74     String              sOldDialogText;         // Originaltitel des Dialogfensters
75     Size                aOldDialogSize;         // Originalgroesse Dialogfenster
76     Point               aOldEditPos;            // Originalposition des Eingabefeldes
77     Size                aOldEditSize;           // Originalgroesse des Eingabefeldes
78     Point               aOldButtonPos;          // Originalpositiuon des Buttons
79 
80     sal_Bool                bEnableColorRef;
81     sal_Bool                bHighLightRef;
82     sal_Bool                bAccInserted;
83 
84     DECL_LINK( AccelSelectHdl, Accelerator* );
85 
86 public:
87     ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings);
88     ~ScFormulaReferenceHelper();
89 
90     void                ShowSimpleReference( const XubString& rStr );
91     void                ShowFormulaReference( const XubString& rStr );
92     bool                ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc );
93     void                Init();
94 
95     void                ShowReference( const XubString& rStr );
96     void                ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
97     void                HideReference( sal_Bool bDoneRefMode = sal_True );
98     void                RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
99     void                RefInputDone( sal_Bool bForced = sal_False );
100     void                ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
101 
SetWindow(Window * _pWindow)102     inline void         SetWindow(Window* _pWindow) { m_pWindow = _pWindow; }
103     sal_Bool                DoClose( sal_uInt16 nId );
104     void                SetDispatcherLock( sal_Bool bLock );
105     void                EnableSpreadsheets( sal_Bool bFlag = sal_True, sal_Bool bChilds = sal_True );
106     void                ViewShellChanged( ScTabViewShell* pScViewShell );
107 
108     static              void enableInput(sal_Bool _bInput);
109 //<!--Added by PengYunQuan for Validity Cell Range Picker
110 protected:
GetWindow()111 	Window		*		GetWindow(){ return m_pWindow; }
112 public:
CanInputStart(const ScRefEdit * pEdit)113 	bool				CanInputStart( const ScRefEdit *pEdit ){ return !!pEdit; }
CanInputDone(sal_Bool bForced)114 	bool				CanInputDone( sal_Bool bForced ){	return pRefEdit && (bForced || !pRefBtn);	}
115 //<!--Added by PengYunQuan for Validity Cell Range Picker
116 };
117 //============================================================================
118 
119 //The class of ScAnyRefDlg is rewritten by PengYunQuan for Validity Cell Range Picker
120 class SC_DLLPUBLIC ScRefHandler : //public SfxModelessDialog,
121                     public IAnyRefDialog
122 {
123 //<!--Added by PengYunQuan for Validity Cell Range Picker
124 	Window &	m_rWindow;
125 	bool		m_bInRefMode;
126 public:
operator Window*()127 	operator Window	*(){ return &m_rWindow; }
operator ->()128 	Window	* operator ->() { return static_cast<Window	*>(*this); }
129 	template<class,bool> friend class ScRefHdlrImplBase;
130 //-->Added by PengYunQuan for Validity Cell Range Picker
131     friend class        formula::RefButton;
132     friend class        formula::RefEdit;
133 
134 private:
135     ScFormulaReferenceHelper
136                         m_aHelper;
137     SfxBindings*        pMyBindings;
138 
139     Window*             pActiveWin;
140     Timer               aTimer;
141     String              aDocName;               // document on which the dialog was opened
142 
143     DECL_LINK( UpdateFocusHdl, Timer* );
144 
145 
146 protected:
147     virtual sal_Bool        DoClose( sal_uInt16 nId );
148 
149     void                SetDispatcherLock( sal_Bool bLock );
150 
151 	//Overwrite TWindow will implemented by ScRefHdlrImplBase
152     //virtual long        PreNotify( NotifyEvent& rNEvt );
153 
154     virtual void        RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
155     virtual void        RefInputDone( sal_Bool bForced = sal_False );
156     void                ShowSimpleReference( const XubString& rStr );
157     void                ShowFormulaReference( const XubString& rStr );
158 
159     bool                ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc );
160 
161 public:
162                         ScRefHandler( Window &rWindow, SfxBindings* pB/*, SfxChildWindow* pCW,
163                                      Window* pParent, sal_uInt16 nResId*/, bool bBindRef );
164     virtual             ~ScRefHandler();
165 
166     virtual void        SetReference( const ScRange& rRef, ScDocument* pDoc ) = 0;
167     virtual void        AddRefEntry();
168 
169     virtual sal_Bool        IsRefInputMode() const;
170     virtual sal_Bool        IsTableLocked() const;
171     virtual sal_Bool        IsDocAllowed( SfxObjectShell* pDocSh ) const;
172 
173     virtual void        ShowReference( const XubString& rStr );
174     virtual void        HideReference( sal_Bool bDoneRefMode = sal_True );
175 
176     virtual void        ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
177     virtual void        ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
178 
179     virtual void        ViewShellChanged( ScTabViewShell* pScViewShell );
180     void                SwitchToDocument();
181     //SfxBindings&        GetBindings();
182 
183     virtual void        SetActive() = 0;
184 //  virtual sal_Bool        Close();
185 	//Overwrite TWindow will implemented by ScRefHdlrImplBase
186     //virtual void        StateChanged( StateChangedType nStateChange );
187 
188 //<!--Added by PengYunQuan for Validity Cell Range Picker
189 public:
190     bool                EnterRefMode();
191     bool                LeaveRefMode();
192 	inline	bool		CanInputStart( const ScRefEdit *pEdit );
193 	inline	bool		CanInputDone( sal_Bool bForced );
194 //-->Added by PengYunQuan for Validity Cell Range Picker
195 };
196 
197 
198 //============================================================================
199 //<!--Added by PengYunQuan for Validity Cell Range Picker
200 template<  class TWindow, bool bBindRef = true >
201 class ScRefHdlrImplBase:public TWindow, public ScRefHandler
202 {
203 public:
204 	//Overwrite TWindow
205 	virtual long        PreNotify( NotifyEvent& rNEvt );
206 	virtual void        StateChanged( StateChangedType nStateChange );
207 
208 private:
209 	template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
210 	ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
211 		TParentWindow* pParent, TResId nResId);
212 
213 	template<class TParentWindow, class TResId, class TArg>
214 	ScRefHdlrImplBase( TParentWindow* pParent, TResId nResId, const TArg &rArg, SfxBindings *pB = NULL );
215 
216 	~ScRefHdlrImplBase();
217 
218 	template<class, class, bool> friend struct ScRefHdlrImpl;
219 };
220 
221 template<class TWindow, bool bBindRef>
222 template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
ScRefHdlrImplBase(TBindings * pB,TChildWindow * pCW,TParentWindow * pParent,TResId nResId)223 ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
224 				 TParentWindow* pParent, TResId nResId):TWindow(pB, pCW, pParent, ScResId(static_cast<sal_uInt16>( nResId ) ) ), ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef ){}
225 
226 template<class TWindow, bool bBindRef >
227 template<class TParentWindow, class TResId, class TArg>
ScRefHdlrImplBase(TParentWindow * pParent,TResId nResIdP,const TArg & rArg,SfxBindings * pB)228 ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, TResId nResIdP, const TArg &rArg, SfxBindings *pB /*= NULL*/ )
229 :TWindow( pParent, ScResId(static_cast<sal_uInt16>( nResIdP )), rArg ), ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef ){}
230 
231 template<class TWindow, bool bBindRef >
~ScRefHdlrImplBase()232 ScRefHdlrImplBase<TWindow,bBindRef>::~ScRefHdlrImplBase(){}
233 
234 //============================================================================
235 template<class TDerived, class TBase, bool bBindRef = true>
236 struct ScRefHdlrImpl: ScRefHdlrImplBase<TBase, bBindRef >
237 {
238 	enum { UNKNOWN_SLOTID = 0U, SLOTID = UNKNOWN_SLOTID };
239 
240 	template<class T1, class T2, class T3, class T4>
ScRefHdlrImplScRefHdlrImpl241 	ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3 & rt3, const T4 & rt4 ):ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4 )
242 	{
243 		SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
244 	}
245 
~ScRefHdlrImplScRefHdlrImpl246 	~ScRefHdlrImpl()
247 	{
248 		SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16>( static_cast<TDerived*>(this)->SLOTID ), this );
249 	}
250 };
251 //============================================================================
252 struct ScAnyRefDlg : ::ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>
253 {
254 	template<class T1, class T2, class T3, class T4>
ScAnyRefDlgScAnyRefDlg255 	ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3 & rt3, const T4 & rt4 ):ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4){}
256 };
257 //============================================================================
258 
CanInputStart(const ScRefEdit * pEdit)259 inline bool ScRefHandler::CanInputStart( const ScRefEdit *pEdit )
260 {
261 	return m_aHelper.CanInputStart( pEdit );
262 }
263 
CanInputDone(sal_Bool bForced)264 inline	bool ScRefHandler::CanInputDone( sal_Bool bForced )
265 {
266 	return m_aHelper.CanInputDone( bForced );
267 }
268 
269 template <> SC_DLLPUBLIC void ScRefHdlrImplBase<SfxModelessDialog,true>::StateChanged( StateChangedType nStateChange );
270 template <> SC_DLLPUBLIC long ScRefHdlrImplBase<SfxModelessDialog,true>::PreNotify( NotifyEvent& rNEvt );
271 #include <sfx2/tabdlg.hxx>
272 template <> SC_DLLPUBLIC void ScRefHdlrImplBase<SfxTabDialog,false>::StateChanged( StateChangedType nStateChange );
273 template <> SC_DLLPUBLIC long ScRefHdlrImplBase<SfxTabDialog,false>::PreNotify( NotifyEvent& rNEvt );
274 
275 //<!--Added by PengYunQuan for Validity Cell Range Picker
276 #endif // SC_ANYREFDG_HXX
277 
278