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 #ifndef _SFXTBXCTRL_HXX 24 #define _SFXTBXCTRL_HXX 25 26 #include "sal/config.h" 27 #include "sfx2/dllapi.h" 28 #include "sal/types.h" 29 #include <vcl/timer.hxx> 30 #ifndef _MENU_HXX //autogen 31 #include <vcl/menu.hxx> 32 #endif 33 #ifndef _FIXED_HXX //autogen 34 #include <vcl/fixed.hxx> 35 #endif 36 #ifndef _FLOATWIN_HXX //autogen 37 #include <vcl/floatwin.hxx> 38 #endif 39 #include <sfx2/ctrlitem.hxx> 40 #include <sfx2/sfxstatuslistener.hxx> 41 #include <svtools/toolboxcontroller.hxx> 42 #include <svtools/framestatuslistener.hxx> 43 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 44 #include <com/sun/star/frame/XDispatchProvider.hpp> 45 #include <com/sun/star/frame/XFrame.hpp> 46 #include <com/sun/star/awt/XDockableWindowListener.hpp> 47 #include <com/sun/star/awt/XDockableWindow.hpp> 48 #include <com/sun/star/frame/XSubToolbarController.hpp> 49 50 //------------------------------------------------------------------ 51 52 class SfxUnoToolBoxControl; 53 class SfxToolBoxControl; 54 class SfxBindings; 55 class SfxModule; 56 class SfxUnoControllerItem; 57 58 svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const ::rtl::OUString& aCommandURL ); 59 60 //typedef SfxToolBoxControl* (*SfxToolBoxControlCtor)( sal_uInt16 nId, ToolBox &rTbx, SfxBindings & ); 61 typedef SfxToolBoxControl* (*SfxToolBoxControlCtor)( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ); 62 63 struct SfxTbxCtrlFactory 64 { 65 SfxToolBoxControlCtor pCtor; 66 TypeId nTypeId; 67 sal_uInt16 nSlotId; 68 SfxTbxCtrlFactorySfxTbxCtrlFactory69 SfxTbxCtrlFactory( SfxToolBoxControlCtor pTheCtor, 70 TypeId nTheTypeId, sal_uInt16 nTheSlotId ): 71 pCtor(pTheCtor), 72 nTypeId(nTheTypeId), 73 nSlotId(nTheSlotId) 74 {} 75 }; 76 77 //------------------------------------------------------------------ 78 79 enum SfxPopupWindowType 80 { 81 SFX_POPUPWINDOW_NONE, 82 SFX_POPUPWINDOW_ONCLICK, 83 SFX_POPUPWINDOW_ONTIMEOUT, 84 SFX_POPUPWINDOW_ONCLICKANDMOVE, 85 SFX_POPUPWINDOW_ONTIMEOUTANDMOVE, 86 SFX_POPUPWINDOW_CONTEXTMENU 87 }; 88 89 //------------------------------------------------------------------ 90 91 class SfxFrameStatusListener : public svt::FrameStatusListener 92 { 93 public: 94 SfxFrameStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager, 95 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, 96 SfxStatusListenerInterface* pCallee ); 97 virtual ~SfxFrameStatusListener(); 98 99 // XStatusListener 100 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) 101 throw ( ::com::sun::star::uno::RuntimeException ); 102 103 private: 104 SfxStatusListenerInterface* m_pCallee; 105 }; 106 107 //------------------------------------------------------------------ 108 109 /* FloatingWindows, die aus ToolBoxen abgerissen werden k"onnen, sollten 110 dieser Klasse abgeleitet werden. Da sie ebenfalls von SfxControllerItem 111 abgeleitet ist, erhalten ihre Instanzen auch die StateChanged Aufrufe. 112 */ 113 114 class SFX2_DLLPUBLIC SfxPopupWindow: public FloatingWindow, public SfxStatusListenerInterface 115 { 116 friend class SfxToolBox_Impl; 117 sal_Bool m_bFloating; 118 sal_uIntPtr m_nEventId; 119 sal_Bool m_bCascading; 120 Link m_aDeleteLink; 121 sal_uInt16 m_nId; 122 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xFrame; 123 SfxFrameStatusListener* m_pStatusListener; 124 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xStatusListener; 125 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager; 126 127 private: 128 SfxFrameStatusListener* GetOrCreateStatusListener(); 129 130 SAL_DLLPRIVATE SfxPopupWindow(SfxPopupWindow &); // not defined 131 SAL_DLLPRIVATE void operator =(SfxPopupWindow &); // not defined 132 133 //#if 0 // _SOLAR__PRIVATE 134 DECL_DLLPRIVATE_LINK( Delete, void * ); 135 //#endif 136 137 protected: 138 virtual void PopupModeEnd(); 139 virtual sal_Bool Close(); 140 virtual void DeleteFloatingWindow(); 141 GetId() const142 sal_uInt16 GetId() const { return m_nId; } GetFrame() const143 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& GetFrame() const { return m_xFrame; } GetServiceManager() const144 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& GetServiceManager() const { return m_xServiceManager; } 145 146 void BindListener(); 147 void UnbindListener(); 148 void AddStatusListener( const rtl::OUString& rCommandURL ); 149 void RemoveStatusListener( const rtl::OUString& rCommandURL ); 150 void UpdateStatus( const rtl::OUString& rCommandURL ); 151 152 // SfxStatusListenerInterface 153 using FloatingWindow::StateChanged; 154 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, 155 const SfxPoolItem* pState ); 156 157 public: 158 SfxPopupWindow( sal_uInt16 nId, 159 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 160 WinBits nBits ); 161 SfxPopupWindow( sal_uInt16 nId, 162 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 163 const ResId &rId ); 164 SfxPopupWindow( sal_uInt16 nId, 165 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 166 Window* pParentWindow, 167 const ResId &rId ); 168 SfxPopupWindow( sal_uInt16 nId, 169 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 170 Window* pParentWindow, 171 WinBits nBits ); 172 ~SfxPopupWindow(); 173 174 virtual SfxPopupWindow* Clone() const; 175 virtual void MouseMove( const MouseEvent& rMEvt ); 176 177 void StartCascading(); 178 void EndCascading(); SetDeleteLink_Impl(const Link & rLink)179 SAL_DLLPRIVATE void SetDeleteLink_Impl( const Link& rLink ) 180 { 181 m_aDeleteLink = rLink; 182 } 183 }; 184 185 //------------------------------------------------------------------ 186 //------------------------------------------------------------------ 187 188 #define SFX_DECL_TOOLBOX_CONTROL() \ 189 static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ); \ 190 static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL) 191 192 /* F"ur spezielle ToolBox-Controls, z.B. eine Font-Auswahl-Box oder 193 aus ToolBoxen abrei"sbare FloatingWindows mu"s passend zur Item-Subclass 194 eine Subclass von SfxTooBoxControl implementiert werden. 195 196 Diese Klasse mu"s in SfxApplication::Init() mit der statischen Methode 197 RegisterControl() registriert werden. Der SFx erzeugt dann automatisch 198 diese Controls in ToolBoxen, wenn die dazugeh"origen Slots von dem 199 angegebenen Typ sind. 200 */ 201 202 struct SfxToolBoxControl_Impl; 203 class SFX2_DLLPUBLIC SfxToolBoxControl: 204 public ::com::sun::star::awt::XDockableWindowListener, 205 public ::com::sun::star::frame::XSubToolbarController, 206 public svt::ToolboxController 207 208 { 209 friend class SfxToolbox; 210 friend class SfxToolBox_Impl; 211 friend class SfxToolboxCustomizer; 212 friend class SfxPopupWindow; 213 friend struct SfxTbxCtrlFactory; 214 215 SfxToolBoxControl_Impl* pImpl; 216 217 protected: 218 DECL_LINK( PopupModeEndHdl, void * ); 219 DECL_LINK( ClosePopupWindow, SfxPopupWindow * ); 220 221 // old SfxToolBoxControl methods 222 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 223 virtual void Select( sal_Bool bMod1 = sal_False ); 224 virtual void Select( sal_uInt16 nModifier ); 225 226 virtual void DoubleClick(); 227 virtual void Click(); 228 virtual SfxPopupWindowType GetPopupWindowType() const; 229 virtual SfxPopupWindow* CreatePopupWindow(); 230 virtual SfxPopupWindow* CreatePopupWindowCascading(); 231 virtual Window* CreateItemWindow( Window *pParent ); 232 233 // Must be called by subclass to set a new popup window instance 234 void SetPopupWindow( SfxPopupWindow* pWindow ); 235 236 // XInterface 237 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 238 virtual void SAL_CALL acquire() throw(); 239 virtual void SAL_CALL release() throw(); 240 241 // XEventListener 242 using ::cppu::OPropertySetHelper::disposing; 243 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw( ::com::sun::star::uno::RuntimeException ); 244 245 // XComponent 246 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 247 248 // new controller API 249 // XStatusListener 250 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) 251 throw ( ::com::sun::star::uno::RuntimeException ); 252 253 // XToolbarController 254 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) 255 throw (::com::sun::star::uno::RuntimeException); 256 virtual void SAL_CALL click() 257 throw (::com::sun::star::uno::RuntimeException); 258 virtual void SAL_CALL doubleClick() 259 throw (::com::sun::star::uno::RuntimeException); 260 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() 261 throw (::com::sun::star::uno::RuntimeException); 262 virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& rParent ) 263 throw (::com::sun::star::uno::RuntimeException); 264 265 // XSubToolbarController 266 virtual ::sal_Bool SAL_CALL opensSubToolbar( ) throw (::com::sun::star::uno::RuntimeException); 267 virtual ::rtl::OUString SAL_CALL getSubToolbarName( ) throw (::com::sun::star::uno::RuntimeException); 268 virtual void SAL_CALL functionSelected( const ::rtl::OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException); 269 virtual void SAL_CALL updateImage( ) throw (::com::sun::star::uno::RuntimeException); 270 271 // XDockableWindowListener 272 virtual void SAL_CALL startDocking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException); 273 virtual ::com::sun::star::awt::DockingData SAL_CALL docking( const ::com::sun::star::awt::DockingEvent& e ) throw (::com::sun::star::uno::RuntimeException); 274 virtual void SAL_CALL endDocking( const ::com::sun::star::awt::EndDockingEvent& e ) throw (::com::sun::star::uno::RuntimeException); 275 virtual sal_Bool SAL_CALL prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 276 virtual void SAL_CALL toggleFloatingMode( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 277 virtual void SAL_CALL closed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 278 virtual void SAL_CALL endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& e ) throw (::com::sun::star::uno::RuntimeException); 279 280 // helper methods 281 void createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName ); 282 ::Size getPersistentFloatingSize( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rSubToolBarResName ); 283 284 public: 285 SFX_DECL_TOOLBOX_CONTROL(); 286 287 SfxToolBoxControl( sal_uInt16 nSlotID, sal_uInt16 nId, ToolBox& rBox, sal_Bool bShowStrings = sal_False ); 288 virtual ~SfxToolBoxControl(); 289 290 ToolBox& GetToolBox() const; 291 unsigned short GetId() const; 292 unsigned short GetSlotId() const; 293 294 void Dispatch( const ::rtl::OUString& aCommand, 295 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ); 296 static void Dispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider, 297 const rtl::OUString& rCommand, 298 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ); 299 300 static SfxItemState GetItemState( const SfxPoolItem* pState ); 301 static SfxToolBoxControl* CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule *pMod ); 302 static void RegisterToolBoxControl( SfxModule*, SfxTbxCtrlFactory*); 303 }; 304 305 #define SFX_IMPL_TOOLBOX_CONTROL(Class, nItemClass) \ 306 SfxToolBoxControl* __EXPORT Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \ 307 { return new Class( nSlotId, nId, rTbx ); } \ 308 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \ 309 { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \ 310 Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); } 311 312 #define SFX_IMPL_TOOLBOX_CONTROL_ARG(Class, nItemClass, Arg) \ 313 SfxToolBoxControl* __EXPORT Class::CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx ) \ 314 { return new Class( nSlotId, nId, rTbx, Arg); } \ 315 void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \ 316 { SfxToolBoxControl::RegisterToolBoxControl( pMod, new SfxTbxCtrlFactory( \ 317 Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); } 318 319 //========================================================================= 320 321 //#if 0 // _SOLAR__PRIVATE 322 323 class SfxDragButton_Impl : public FixedImage 324 { 325 public: 326 327 SfxDragButton_Impl( Window *pParent ); 328 virtual void Command ( const CommandEvent& rCEvt ); 329 virtual void MouseMove( const MouseEvent& rMEvt ); 330 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 331 }; 332 333 class SfxDragToolBoxControl_Impl : public SfxToolBoxControl 334 /* [Beschreibung] 335 336 */ 337 338 { 339 public: 340 SFX_DECL_TOOLBOX_CONTROL(); 341 SfxDragToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox ); 342 virtual Window* CreateItemWindow( Window *pParent ); 343 using SfxToolBoxControl::Select; 344 virtual void Select( sal_Bool bMod1 = sal_False ); 345 }; 346 347 //------------------------------------------------------------------------ 348 349 class SfxHistoryToolBoxControl_Impl : public SfxToolBoxControl 350 { 351 Timer aTimer; 352 353 private: 354 DECL_LINK( Timeout, Timer * ); 355 356 protected: 357 virtual void Click( ); 358 using SfxToolBoxControl::Select; 359 virtual void Select( sal_Bool ); 360 361 public: 362 SFX_DECL_TOOLBOX_CONTROL(); 363 SfxHistoryToolBoxControl_Impl( sal_uInt16 nId, ToolBox& rBox ); 364 }; 365 366 class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl 367 { 368 protected: 369 using SfxToolBoxControl::Select; 370 virtual void Select( sal_uInt16 nSelectModifier ); 371 372 public: 373 SFX_DECL_TOOLBOX_CONTROL(); 374 SfxReloadToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ); 375 }; 376 377 class SfxPopupMenuManager; 378 class SfxAddonsToolBoxControl_Impl : public SfxToolBoxControl 379 380 /* [Description] 381 382 Internal helper class to provide the addons popup menu through the addons 383 toolbox button. 384 */ 385 386 { 387 sal_Bool bBigImages; 388 PopupMenu* pMenu; 389 sal_Bool m_bWasHiContrastMode; 390 sal_Bool m_bShowMenuImages; 391 392 protected: 393 virtual void Click(); 394 using SfxToolBoxControl::Select; 395 virtual void Select( sal_Bool ); 396 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ); 397 DECL_LINK( Activate, Menu * ); // Needed to support high contrast images 398 public: 399 SFX_DECL_TOOLBOX_CONTROL(); 400 SfxAddonsToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ); 401 ~SfxAddonsToolBoxControl_Impl(); 402 403 void RefreshMenuImages( Menu* pMenu ); 404 }; 405 406 //#endif 407 408 #endif 409