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 24 #ifndef _SVTOOLS_TOOLBARMENU_HXX_ 25 #define _SVTOOLS_TOOLBARMENU_HXX_ 26 27 #include "svtools/svtdllapi.h" 28 29 #include <com/sun/star/frame/FeatureStateEvent.hpp> 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 #include <com/sun/star/frame/XFrame.hpp> 32 33 #include <vector> 34 35 #include <rtl/ref.hxx> 36 37 #include <vcl/ctrl.hxx> 38 #include <vcl/menu.hxx> 39 #include <vcl/dockwin.hxx> 40 41 class ValueSet; 42 43 namespace svtools { 44 45 class ToolbarMenuEntry; 46 struct ToolbarMenu_Impl; 47 48 class SVT_DLLPUBLIC ToolbarMenu : public DockingWindow 49 { 50 friend class ToolbarMenuStatusListener; 51 friend struct ToolbarMenu_Impl; 52 public: 53 ToolbarMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 54 Window* pParentWindow, 55 WinBits nBits ); 56 57 ToolbarMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, 58 Window* pParentWindow, 59 const ResId& rResId ); 60 61 ~ToolbarMenu(); 62 63 virtual void MouseMove( const MouseEvent& rMEvt ); 64 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 65 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 66 virtual void KeyInput( const KeyEvent& rKEvent ); 67 virtual void Command( const CommandEvent& rCEvt ); 68 virtual void Paint( const Rectangle& rRect ); 69 virtual void RequestHelp( const HelpEvent& rHEvt ); 70 virtual void GetFocus(); 71 virtual void LoseFocus(); 72 73 void appendEntry( int nEntryId, const String& rStr, MenuItemBits nItemBits = 0 ); 74 void appendEntry( int nEntryId, const Image& rImage, MenuItemBits nItemBits = 0 ); 75 void appendEntry( int nEntryId, const String& rStr, const Image& rImage, MenuItemBits nItemBits = 0 ); 76 void appendEntry( int nEntryId, Control* pControl, MenuItemBits nItemBits = 0 ); 77 void appendSeparator(); 78 79 /** creates an empty ValueSet that is initialized and can be inserted with appendEntry. */ 80 ValueSet* createEmptyValueSetControl(); 81 82 void checkEntry( int nEntryId, bool bCheck = true ); 83 bool isEntryChecked( int nEntryId ) const; 84 85 void enableEntry( int nEntryId, bool bEnable = true ); 86 bool isEntryEnabled( int nEntryId ) const; 87 88 void setEntryText( int nEntryId, const String& rStr ); 89 const String& getEntryText( int nEntryId ) const; 90 91 void setEntryImage( int nEntryId, const Image& rImage ); 92 const Image& getEntryImage( int nEntryId ) const; 93 94 const Size& getMenuSize() const; 95 96 void SetSelectHdl( const Link& rLink ); 97 const Link& GetSelectHdl() const; 98 99 int getSelectedEntryId() const; 100 int getHighlightedEntryId() const; 101 102 void highlightFirstEntry(); 103 104 protected: 105 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); 106 107 // todo: move to new base class that will replace SfxPopupWindow 108 void AddStatusListener( const rtl::OUString& rCommandURL ); 109 void RemoveStatusListener( const rtl::OUString& rCommandURL ); 110 void UpdateStatus( const rtl::OUString& rCommandURL ); 111 112 bool IsInPopupMode(); 113 void EndPopupMode(); 114 115 // XStatusListener (subclasses must override this one to get the status updates 116 virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ); 117 118 void StateChanged( StateChangedType nType ); 119 void DataChanged( const DataChangedEvent& rDCEvt ); 120 121 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > GetFrame() const; 122 private: 123 DECL_LINK( HighlightHdl, Control * ); 124 125 void initStatusListener(); 126 127 void implInit( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame ); 128 void initWindow(); 129 130 Size implCalcSize(); 131 132 void appendEntry( ToolbarMenuEntry* pEntry ); 133 134 void implPaint( ToolbarMenuEntry* pThisOnly = NULL, bool bHighlight = false ); 135 136 void implHighlightEntry( int nHighlightEntry, bool bHighlight ); 137 void implHighlightEntry( const MouseEvent& rMEvt, bool bMBDown ); 138 139 void implChangeHighlightEntry( int nEntry ); 140 void implSelectEntry( int nSelectedEntry ); 141 142 ToolbarMenuEntry* implCursorUpDown( bool bUp, bool bHomeEnd ); 143 ToolbarMenuEntry* implGetEntry( int nEntry ) const; 144 ToolbarMenuEntry* implSearchEntry( int nEntryId ) const; 145 146 ToolbarMenu_Impl* mpImpl; 147 }; 148 149 } // namespace svtools 150 151 #endif 152