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