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