xref: /aoo4110/main/sfx2/inc/sfx2/mnuitem.hxx (revision b1cdbd2c)
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 _SFXMNUITEM_HXX
24 #define _SFXMNUITEM_HXX
25 
26 #include "sal/config.h"
27 #include "sfx2/dllapi.h"
28 
29 class SfxVirtualMenu;
30 class SfxBindings;
31 class SfxModule;
32 class Menu;
33 class PopupMenu;
34 class SfxUnoMenuControl;
35 class SfxUnoControllerItem;
36 struct SfxMenuCtrlFactory;
37 #include <tools/string.hxx>
38 #include <sfx2/ctrlitem.hxx>
39 
40 #include <com/sun/star/frame/XDispatch.hpp>
41 #include <com/sun/star/util/URL.hpp>
42 
43 class SFX2_DLLPUBLIC SfxMenuControl: public SfxControllerItem
44 {
45 //friend SvStream& operator<<( SvStream& rStream, const SfxMenuControl& rItem );
46 //friend SvStream& operator>>( SvStream& rStream, SfxMenuControl& rItem );
47 
48 	String					aTitle;
49 	String					aHelpText;
50 	SfxVirtualMenu* 		pOwnMenu;
51 	SfxVirtualMenu* 		pSubMenu;
52 	sal_Bool					b_ShowStrings;
53 	sal_Bool					b_UnusedDummy;
54 
55 public:
56 							SfxMenuControl();
57 							SfxMenuControl( sal_Bool bShowStrings );
58 							SfxMenuControl( sal_uInt16, SfxBindings&);
59 
60 	static SfxMenuControl* 	CreateImpl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings );
61 	static void 			RegisterControl( sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL );
62 
63 							~SfxMenuControl();
64 
65         using SfxControllerItem::Bind;
66 	void					Bind( SfxVirtualMenu* pOwnMenu, sal_uInt16 nId,
67 								  const String& rTitle, const String &rHelpText,
68 								  SfxBindings & );
69 	void					Bind( SfxVirtualMenu* pOwnMenu, sal_uInt16 nId,
70 								  SfxVirtualMenu& rSubMenu,
71 								  const String& rTitle, const String &rHelpText,
72 								  SfxBindings & );
73 
74 //	SvStream &				Load(SvStream &, SfxBindings*);
75 //	SvStream &				Store(SvStream &);
76 
77 	String					GetTitle() const;
78 	SfxVirtualMenu* 		GetPopupMenu() const;
79 	virtual PopupMenu*		GetPopup() const;
80 	void					SetOwnMenu( SfxVirtualMenu* pMenu );
81 	void 					RemovePopup();
82 
GetHelpText() const83 	const String&			GetHelpText() const { return aHelpText; }
SetHelpText(const String & rStr)84 	void					SetHelpText(const String &rStr) { aHelpText  = rStr; }
85 
86 	virtual void			StateChanged( sal_uInt16 nSID, SfxItemState eState,
87 										  const SfxPoolItem* pState );
88 
89 	static SfxMenuControl*	  CreateControl( sal_uInt16 nId, Menu &, SfxBindings & );
90 	static SfxUnoMenuControl* CreateControl( const String&, sal_uInt16, Menu&, SfxBindings&, SfxVirtualMenu* );
91 	static SfxUnoMenuControl* CreateControl( const String&, sal_uInt16, Menu&, const String& sItemText, const String& sHelpText, SfxBindings&, SfxVirtualMenu* );
92     static sal_Bool             IsSpecialControl( sal_uInt16 nId, SfxModule* );
93     static void             RegisterMenuControl(SfxModule*, SfxMenuCtrlFactory*);
94 
95 };
96 
97 class SfxUnoMenuControl : public SfxMenuControl
98 {
99 	SfxUnoControllerItem*	pUnoCtrl;
100 public:
101 							SfxUnoMenuControl( const String&, sal_uInt16 nId, Menu&,
102 												SfxBindings&, SfxVirtualMenu* );
103 							SfxUnoMenuControl( const String&, sal_uInt16 nId, Menu&,
104 											   const String&, const String&,
105                                                 SfxBindings&, SfxVirtualMenu* );
106 							~SfxUnoMenuControl();
107 	void					Select();
108 };
109 
110 //--------------------------------------------------------------------
111 
112 typedef SfxMenuControl* (*SfxMenuControlCtor)( sal_uInt16 nId, Menu &, SfxBindings & );
113 
114 struct SfxMenuCtrlFactory
115 {
116 	SfxMenuControlCtor	pCtor;
117 	TypeId				nTypeId;
118 	sal_uInt16				nSlotId;
119 
SfxMenuCtrlFactorySfxMenuCtrlFactory120 	SfxMenuCtrlFactory( SfxMenuControlCtor pTheCtor,
121 			TypeId nTheTypeId, sal_uInt16 nTheSlotId ):
122 		pCtor(pTheCtor),
123 		nTypeId(nTheTypeId),
124 		nSlotId(nTheSlotId)
125 	{}
126 };
127 
128 //
129 
GetTitle() const130 inline String SfxMenuControl::GetTitle() const
131 {
132 	return aTitle;
133 }
134 //--------------------------------------------------------------------
135 
136 //
137 
GetPopupMenu() const138 inline SfxVirtualMenu* SfxMenuControl::GetPopupMenu() const
139 {
140 	return pSubMenu;
141 }
142 //--------------------------------------------------------------------
143 
144 #define SFX_DECL_MENU_CONTROL() \
145 		static SfxMenuControl* CreateImpl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings ); \
146 		static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL)
147 
148 #define SFX_IMPL_MENU_CONTROL(Class, nItemClass) \
149 		SfxMenuControl* __EXPORT Class::CreateImpl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings ) \
150 			   { return new Class(nId, rMenu, rBindings); } \
151 		void Class::RegisterControl(sal_uInt16 nSlotId, SfxModule *pMod) \
152                { SfxMenuControl::RegisterMenuControl( pMod, new SfxMenuCtrlFactory( \
153 					Class::CreateImpl, TYPE(nItemClass), nSlotId ) ); }
154 
155 //#if 0 // _SOLAR__PRIVATE
156 
157 class SfxAppMenuControl_Impl : public SfxMenuControl
158 {
159     PopupMenu*	pMenu;
160     sal_uIntPtr       m_nSymbolsStyle;
161     sal_Bool        m_bWasHiContrastMode;
162 	sal_Bool		m_bShowMenuImages;
163 
164 protected:
165 	DECL_LINK( Activate, Menu * ); // Needed to support high contrast images
166 
167 public:
168 	SFX_DECL_MENU_CONTROL();
169     SfxAppMenuControl_Impl( sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings );
170 	~SfxAppMenuControl_Impl();
171 
172     struct ExecuteInfo
173     {
174         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >     xDispatch;
175         ::com::sun::star::util::URL                                                aTargetURL;
176         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >  aArgs;
177     };
178 
179     DECL_STATIC_LINK( SfxAppMenuControl_Impl, ExecuteHdl_Impl, ExecuteInfo* );
180 };
181 
182 //#endif
183 
184 #endif
185