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