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