16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
56d739b60SAndrew Rist * distributed with this work for additional information
66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist * software distributed under the License is distributed on an
156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist * KIND, either express or implied. See the License for the
176d739b60SAndrew Rist * specific language governing permissions and limitations
186d739b60SAndrew Rist * under the License.
19cdf0e10cSrcweir *
206d739b60SAndrew Rist *************************************************************/
216d739b60SAndrew Rist
226d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <uielement/controlmenucontroller.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir //_________________________________________________________________________________________________________________
29cdf0e10cSrcweir // my own includes
30cdf0e10cSrcweir //_________________________________________________________________________________________________________________
31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32cdf0e10cSrcweir #include "services.h"
33cdf0e10cSrcweir
34cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35cdf0e10cSrcweir // interface includes
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
39cdf0e10cSrcweir #include <com/sun/star/awt/MenuItemStyle.hpp>
40cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
41cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
44cdf0e10cSrcweir
45cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46cdf0e10cSrcweir // includes of other projects
47cdf0e10cSrcweir //_________________________________________________________________________________________________________________
48cdf0e10cSrcweir
49cdf0e10cSrcweir #include <vcl/menu.hxx>
50cdf0e10cSrcweir #include <vcl/svapp.hxx>
51cdf0e10cSrcweir #include <vcl/i18nhelp.hxx>
52cdf0e10cSrcweir #include <tools/urlobj.hxx>
53cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
54cdf0e10cSrcweir #include <rtl/strbuf.hxx>
55cdf0e10cSrcweir #include <svl/solar.hrc>
56cdf0e10cSrcweir #include <tools/rcid.h>
57cdf0e10cSrcweir #include <vcl/image.hxx>
58cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
59cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx>
60cdf0e10cSrcweir #include <vos/mutex.hxx>
61cdf0e10cSrcweir
62cdf0e10cSrcweir // Copied from svx
63cdf0e10cSrcweir // Function-Id's
64cdf0e10cSrcweir #define RID_FMSHELL_CONVERSIONMENU (RID_FORMS_START + 4)
65cdf0e10cSrcweir #define RID_SVXIMGLIST_FMEXPL (RID_FORMS_START + 0)
66cdf0e10cSrcweir #define RID_SVXIMGLIST_FMEXPL_HC (RID_FORMS_START + 2)
67cdf0e10cSrcweir
68cdf0e10cSrcweir // Forms - Ids, used to address images from image list
69cdf0e10cSrcweir #define SID_FMSLOTS_START (SID_SVX_START + 592)
70cdf0e10cSrcweir #define SID_MORE_FMSLOTS_START (SID_SVX_START + 702)
71cdf0e10cSrcweir
72cdf0e10cSrcweir #define SID_FM_CONVERTTO_EDIT (SID_MORE_FMSLOTS_START + 32)
73cdf0e10cSrcweir #define SID_FM_CONVERTTO_BUTTON (SID_MORE_FMSLOTS_START + 33)
74cdf0e10cSrcweir #define SID_FM_CONVERTTO_FIXEDTEXT (SID_MORE_FMSLOTS_START + 34)
75cdf0e10cSrcweir #define SID_FM_CONVERTTO_LISTBOX (SID_MORE_FMSLOTS_START + 35)
76cdf0e10cSrcweir #define SID_FM_CONVERTTO_CHECKBOX (SID_MORE_FMSLOTS_START + 36)
77cdf0e10cSrcweir #define SID_FM_CONVERTTO_RADIOBUTTON (SID_MORE_FMSLOTS_START + 37)
78cdf0e10cSrcweir #define SID_FM_CONVERTTO_GROUPBOX (SID_MORE_FMSLOTS_START + 38)
79cdf0e10cSrcweir #define SID_FM_CONVERTTO_COMBOBOX (SID_MORE_FMSLOTS_START + 39)
80cdf0e10cSrcweir #define SID_FM_CONVERTTO_GRID (SID_MORE_FMSLOTS_START + 40)
81cdf0e10cSrcweir #define SID_FM_CONVERTTO_IMAGEBUTTON (SID_MORE_FMSLOTS_START + 41)
82cdf0e10cSrcweir #define SID_FM_CONVERTTO_FILECONTROL (SID_MORE_FMSLOTS_START + 42)
83cdf0e10cSrcweir #define SID_FM_CONVERTTO_DATE (SID_MORE_FMSLOTS_START + 43)
84cdf0e10cSrcweir #define SID_FM_CONVERTTO_TIME (SID_MORE_FMSLOTS_START + 44)
85cdf0e10cSrcweir #define SID_FM_CONVERTTO_NUMERIC (SID_MORE_FMSLOTS_START + 45)
86cdf0e10cSrcweir #define SID_FM_CONVERTTO_CURRENCY (SID_MORE_FMSLOTS_START + 46)
87cdf0e10cSrcweir #define SID_FM_CONVERTTO_PATTERN (SID_MORE_FMSLOTS_START + 47)
88cdf0e10cSrcweir #define SID_FM_CONVERTTO_IMAGECONTROL (SID_MORE_FMSLOTS_START + 48)
89cdf0e10cSrcweir #define SID_FM_CONVERTTO_FORMATTED (SID_MORE_FMSLOTS_START + 49)
90cdf0e10cSrcweir #define SID_FM_CONVERTTO_SCROLLBAR (SID_MORE_FMSLOTS_START + 68)
91cdf0e10cSrcweir #define SID_FM_CONVERTTO_SPINBUTTON (SID_MORE_FMSLOTS_START + 69)
92cdf0e10cSrcweir
93cdf0e10cSrcweir #define SID_FM_DATEFIELD (SID_MORE_FMSLOTS_START + 2)
94cdf0e10cSrcweir #define SID_FM_TIMEFIELD (SID_MORE_FMSLOTS_START + 3)
95cdf0e10cSrcweir #define SID_FM_NUMERICFIELD (SID_MORE_FMSLOTS_START + 4)
96cdf0e10cSrcweir #define SID_FM_CURRENCYFIELD (SID_MORE_FMSLOTS_START + 5)
97cdf0e10cSrcweir #define SID_FM_PATTERNFIELD (SID_MORE_FMSLOTS_START + 6)
98cdf0e10cSrcweir #define SID_FM_IMAGECONTROL (SID_MORE_FMSLOTS_START + 8)
99cdf0e10cSrcweir #define SID_FM_FORMATTEDFIELD (SID_MORE_FMSLOTS_START + 26)
100cdf0e10cSrcweir #define SID_FM_SCROLLBAR (SID_MORE_FMSLOTS_START + 66)
101cdf0e10cSrcweir #define SID_FM_SPINBUTTON (SID_MORE_FMSLOTS_START + 67)
102cdf0e10cSrcweir #define SID_FM_CONFIG (SID_FMSLOTS_START + 1)
103cdf0e10cSrcweir #define SID_FM_PUSHBUTTON (SID_FMSLOTS_START + 2)
104cdf0e10cSrcweir #define SID_FM_RADIOBUTTON (SID_FMSLOTS_START + 3)
105cdf0e10cSrcweir #define SID_FM_CHECKBOX (SID_FMSLOTS_START + 4)
106cdf0e10cSrcweir #define SID_FM_FIXEDTEXT (SID_FMSLOTS_START + 5)
107cdf0e10cSrcweir #define SID_FM_GROUPBOX (SID_FMSLOTS_START + 6)
108cdf0e10cSrcweir #define SID_FM_EDIT (SID_FMSLOTS_START + 7)
109cdf0e10cSrcweir #define SID_FM_LISTBOX (SID_FMSLOTS_START + 8)
110cdf0e10cSrcweir #define SID_FM_COMBOBOX (SID_FMSLOTS_START + 9)
111cdf0e10cSrcweir #define SID_FM_URLBUTTON (SID_FMSLOTS_START + 10)
112cdf0e10cSrcweir #define SID_FM_DBGRID (SID_FMSLOTS_START + 11)
113cdf0e10cSrcweir #define SID_FM_IMAGEBUTTON (SID_FMSLOTS_START + 12)
114cdf0e10cSrcweir #define SID_FM_FILECONTROL (SID_FMSLOTS_START + 13)
115cdf0e10cSrcweir
116cdf0e10cSrcweir sal_Int16 nConvertSlots[] =
117cdf0e10cSrcweir {
118cdf0e10cSrcweir SID_FM_CONVERTTO_EDIT,
119cdf0e10cSrcweir SID_FM_CONVERTTO_BUTTON,
120cdf0e10cSrcweir SID_FM_CONVERTTO_FIXEDTEXT,
121cdf0e10cSrcweir SID_FM_CONVERTTO_LISTBOX,
122cdf0e10cSrcweir SID_FM_CONVERTTO_CHECKBOX,
123cdf0e10cSrcweir SID_FM_CONVERTTO_RADIOBUTTON,
124cdf0e10cSrcweir SID_FM_CONVERTTO_GROUPBOX,
125cdf0e10cSrcweir SID_FM_CONVERTTO_COMBOBOX,
126cdf0e10cSrcweir // SID_FM_CONVERTTO_GRID,
127cdf0e10cSrcweir SID_FM_CONVERTTO_IMAGEBUTTON,
128cdf0e10cSrcweir SID_FM_CONVERTTO_FILECONTROL,
129cdf0e10cSrcweir SID_FM_CONVERTTO_DATE,
130cdf0e10cSrcweir SID_FM_CONVERTTO_TIME,
131cdf0e10cSrcweir SID_FM_CONVERTTO_NUMERIC,
132cdf0e10cSrcweir SID_FM_CONVERTTO_CURRENCY,
133cdf0e10cSrcweir SID_FM_CONVERTTO_PATTERN,
134cdf0e10cSrcweir SID_FM_CONVERTTO_IMAGECONTROL,
135cdf0e10cSrcweir SID_FM_CONVERTTO_FORMATTED,
136cdf0e10cSrcweir SID_FM_CONVERTTO_SCROLLBAR,
137cdf0e10cSrcweir SID_FM_CONVERTTO_SPINBUTTON
138cdf0e10cSrcweir };
139cdf0e10cSrcweir
140cdf0e10cSrcweir sal_Int16 nCreateSlots[] =
141cdf0e10cSrcweir {
142cdf0e10cSrcweir SID_FM_EDIT,
143cdf0e10cSrcweir SID_FM_PUSHBUTTON,
144cdf0e10cSrcweir SID_FM_FIXEDTEXT,
145cdf0e10cSrcweir SID_FM_LISTBOX,
146cdf0e10cSrcweir SID_FM_CHECKBOX,
147cdf0e10cSrcweir SID_FM_RADIOBUTTON,
148cdf0e10cSrcweir SID_FM_GROUPBOX,
149cdf0e10cSrcweir SID_FM_COMBOBOX,
150cdf0e10cSrcweir // SID_FM_DBGRID,
151cdf0e10cSrcweir SID_FM_IMAGEBUTTON,
152cdf0e10cSrcweir SID_FM_FILECONTROL,
153cdf0e10cSrcweir SID_FM_DATEFIELD,
154cdf0e10cSrcweir SID_FM_TIMEFIELD,
155cdf0e10cSrcweir SID_FM_NUMERICFIELD,
156cdf0e10cSrcweir SID_FM_CURRENCYFIELD,
157cdf0e10cSrcweir SID_FM_PATTERNFIELD,
158cdf0e10cSrcweir SID_FM_IMAGECONTROL,
159cdf0e10cSrcweir SID_FM_FORMATTEDFIELD,
160cdf0e10cSrcweir SID_FM_SCROLLBAR,
161cdf0e10cSrcweir SID_FM_SPINBUTTON
162cdf0e10cSrcweir };
163cdf0e10cSrcweir
164cdf0e10cSrcweir const char* aCommands[] =
165cdf0e10cSrcweir {
166cdf0e10cSrcweir ".uno:ConvertToEdit",
167cdf0e10cSrcweir ".uno:ConvertToButton",
168cdf0e10cSrcweir ".uno:ConvertToFixed",
169cdf0e10cSrcweir ".uno:ConvertToList",
170cdf0e10cSrcweir ".uno:ConvertToCheckBox",
171cdf0e10cSrcweir ".uno:ConvertToRadio",
172cdf0e10cSrcweir ".uno:ConvertToGroup",
173cdf0e10cSrcweir ".uno:ConvertToCombo",
174cdf0e10cSrcweir // ".uno:ConvertToGrid",
175cdf0e10cSrcweir ".uno:ConvertToImageBtn",
176cdf0e10cSrcweir ".uno:ConvertToFileControl",
177cdf0e10cSrcweir ".uno:ConvertToDate",
178cdf0e10cSrcweir ".uno:ConvertToTime",
179cdf0e10cSrcweir ".uno:ConvertToNumeric",
180cdf0e10cSrcweir ".uno:ConvertToCurrency",
181cdf0e10cSrcweir ".uno:ConvertToPattern",
182cdf0e10cSrcweir ".uno:ConvertToImageControl",
183cdf0e10cSrcweir ".uno:ConvertToFormatted",
184cdf0e10cSrcweir ".uno:ConvertToScrollBar",
185cdf0e10cSrcweir ".uno:ConvertToSpinButton"
186cdf0e10cSrcweir };
187cdf0e10cSrcweir
188cdf0e10cSrcweir //_________________________________________________________________________________________________________________
189cdf0e10cSrcweir // Defines
190cdf0e10cSrcweir //_________________________________________________________________________________________________________________
191cdf0e10cSrcweir //
192cdf0e10cSrcweir
193cdf0e10cSrcweir using namespace com::sun::star::uno;
194cdf0e10cSrcweir using namespace com::sun::star::lang;
195cdf0e10cSrcweir using namespace com::sun::star::frame;
196cdf0e10cSrcweir using namespace com::sun::star::beans;
197cdf0e10cSrcweir using namespace com::sun::star::util;
198cdf0e10cSrcweir using namespace com::sun::star::style;
199cdf0e10cSrcweir using namespace com::sun::star::container;
200cdf0e10cSrcweir
201cdf0e10cSrcweir namespace framework
202cdf0e10cSrcweir {
203cdf0e10cSrcweir
DEFINE_XSERVICEINFO_MULTISERVICE(ControlMenuController,OWeakObject,SERVICENAME_POPUPMENUCONTROLLER,IMPLEMENTATIONNAME_CONTROLMENUCONTROLLER)204cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( ControlMenuController ,
205cdf0e10cSrcweir OWeakObject ,
206cdf0e10cSrcweir SERVICENAME_POPUPMENUCONTROLLER ,
207cdf0e10cSrcweir IMPLEMENTATIONNAME_CONTROLMENUCONTROLLER
208cdf0e10cSrcweir )
209cdf0e10cSrcweir
210cdf0e10cSrcweir DEFINE_INIT_SERVICE ( ControlMenuController, {} )
211cdf0e10cSrcweir
212cdf0e10cSrcweir ControlMenuController::ControlMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
213cdf0e10cSrcweir svt::PopupMenuControllerBase( xServiceManager ),
214cdf0e10cSrcweir m_pResPopupMenu( 0 )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
217cdf0e10cSrcweir m_bWasHiContrast = rSettings.GetHighContrastMode();
218cdf0e10cSrcweir m_bShowMenuImages = rSettings.GetUseImagesInMenus();
219cdf0e10cSrcweir
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
~ControlMenuController()222cdf0e10cSrcweir ControlMenuController::~ControlMenuController()
223cdf0e10cSrcweir {
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir // private function
updateImagesPopupMenu(PopupMenu * pPopupMenu)227cdf0e10cSrcweir void ControlMenuController::updateImagesPopupMenu( PopupMenu* pPopupMenu )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir rtl::OUString aResName( RTL_CONSTASCII_USTRINGPARAM( "svx" ));
230cdf0e10cSrcweir
231*24c56ab9SHerbert Dürr ResMgr* pResMgr = ResMgr::CreateResMgr( rtl::OUStringToOString( aResName, RTL_TEXTENCODING_ASCII_US ).getStr() );
232cdf0e10cSrcweir ResId aResId( m_bWasHiContrast ? RID_SVXIMGLIST_FMEXPL_HC : RID_SVXIMGLIST_FMEXPL, *pResMgr );
233cdf0e10cSrcweir aResId.SetRT( RSC_IMAGELIST );
234cdf0e10cSrcweir
235cdf0e10cSrcweir if ( pResMgr->IsAvailable( aResId ))
236cdf0e10cSrcweir {
237cdf0e10cSrcweir ImageList aImageList( aResId );
238cdf0e10cSrcweir for ( sal_uInt32 i=0; i < sizeof(nConvertSlots)/sizeof(nConvertSlots[0]); ++i )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir // das entsprechende Image dran
241cdf0e10cSrcweir if ( m_bShowMenuImages )
242cdf0e10cSrcweir pPopupMenu->SetItemImage( nConvertSlots[i], aImageList.GetImage(nCreateSlots[i]));
243cdf0e10cSrcweir else
244cdf0e10cSrcweir pPopupMenu->SetItemImage( nConvertSlots[i], Image() );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir delete pResMgr;
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir // private function
fillPopupMenu(Reference<css::awt::XPopupMenu> & rPopupMenu)252cdf0e10cSrcweir void ControlMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
255cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = 0;
256cdf0e10cSrcweir
257cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
258cdf0e10cSrcweir
259cdf0e10cSrcweir resetPopupMenu( rPopupMenu );
260cdf0e10cSrcweir if ( pPopupMenu )
261cdf0e10cSrcweir pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
262cdf0e10cSrcweir
263cdf0e10cSrcweir if ( pVCLPopupMenu && m_pResPopupMenu )
264cdf0e10cSrcweir *pVCLPopupMenu = *m_pResPopupMenu;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
267cdf0e10cSrcweir // XEventListener
disposing(const EventObject &)268cdf0e10cSrcweir void SAL_CALL ControlMenuController::disposing( const EventObject& ) throw ( RuntimeException )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
271cdf0e10cSrcweir
272cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex );
273cdf0e10cSrcweir m_xFrame.clear();
274cdf0e10cSrcweir m_xDispatch.clear();
275cdf0e10cSrcweir m_xServiceManager.clear();
276cdf0e10cSrcweir
277cdf0e10cSrcweir if ( m_xPopupMenu.is() )
278cdf0e10cSrcweir m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
279cdf0e10cSrcweir m_xPopupMenu.clear();
280cdf0e10cSrcweir delete m_pResPopupMenu;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir // XStatusListener
statusChanged(const FeatureStateEvent & Event)284cdf0e10cSrcweir void SAL_CALL ControlMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
285cdf0e10cSrcweir {
286cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex );
287cdf0e10cSrcweir
288cdf0e10cSrcweir sal_uInt16 nMenuId = 0;
289cdf0e10cSrcweir for (sal_uInt32 i=0; i < sizeof(aCommands)/sizeof(aCommands[0]); ++i)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir if ( Event.FeatureURL.Complete.equalsAscii( aCommands[i] ))
292cdf0e10cSrcweir {
293cdf0e10cSrcweir nMenuId = nConvertSlots[i];
294cdf0e10cSrcweir break;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir if ( nMenuId )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( m_xPopupMenu );
301cdf0e10cSrcweir
302cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
303cdf0e10cSrcweir
304cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
305cdf0e10cSrcweir
306cdf0e10cSrcweir if ( !Event.IsEnabled && pVCLPopupMenu->GetItemPos( nMenuId ) != MENU_ITEM_NOTFOUND )
307cdf0e10cSrcweir pVCLPopupMenu->RemoveItem( pVCLPopupMenu->GetItemPos( nMenuId ));
308cdf0e10cSrcweir else if ( Event.IsEnabled && pVCLPopupMenu->GetItemPos( nMenuId ) == MENU_ITEM_NOTFOUND )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir sal_Int16 nSourcePos = m_pResPopupMenu->GetItemPos(nMenuId);
311cdf0e10cSrcweir sal_Int16 nPrevInSource = nSourcePos;
312cdf0e10cSrcweir sal_uInt16 nPrevInConversion = MENU_ITEM_NOTFOUND;
313cdf0e10cSrcweir while (nPrevInSource>0)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir sal_Int16 nPrevId = m_pResPopupMenu->GetItemId(--nPrevInSource);
316cdf0e10cSrcweir
317cdf0e10cSrcweir // do we have the source's predecessor in our conversion menu, too ?
318cdf0e10cSrcweir nPrevInConversion = pVCLPopupMenu->GetItemPos( nPrevId );
319cdf0e10cSrcweir if ( nPrevInConversion != MENU_ITEM_NOTFOUND )
320cdf0e10cSrcweir break;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
323cdf0e10cSrcweir if ( MENU_ITEM_NOTFOUND == nPrevInConversion )
324cdf0e10cSrcweir // none of the items which precede the nSID-slot in the source menu are present in our conversion menu
325cdf0e10cSrcweir nPrevInConversion = sal::static_int_cast< sal_uInt16 >(-1); // put the item at the first position
326cdf0e10cSrcweir
327cdf0e10cSrcweir pVCLPopupMenu->InsertItem( nMenuId, m_pResPopupMenu->GetItemText( nMenuId ), m_pResPopupMenu->GetItemBits( nMenuId ), ++nPrevInConversion );
328cdf0e10cSrcweir pVCLPopupMenu->SetItemImage( nMenuId, m_pResPopupMenu->GetItemImage( nMenuId ));
329cdf0e10cSrcweir pVCLPopupMenu->SetHelpId( nMenuId, m_pResPopupMenu->GetHelpId( nMenuId ));
330cdf0e10cSrcweir }
331cdf0e10cSrcweir }
332cdf0e10cSrcweir }
333cdf0e10cSrcweir
334cdf0e10cSrcweir // XMenuListener
impl_select(const Reference<XDispatch> &,const::com::sun::star::util::URL & aURL)335cdf0e10cSrcweir void ControlMenuController::impl_select(const Reference< XDispatch >& /*_xDispatch*/,const ::com::sun::star::util::URL& aURL)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir UrlToDispatchMap::iterator pIter = m_aURLToDispatchMap.find( aURL.Complete );
338cdf0e10cSrcweir if ( pIter != m_aURLToDispatchMap.end() )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir Sequence<PropertyValue> aArgs;
341cdf0e10cSrcweir Reference< XDispatch > xDispatch = pIter->second;
342cdf0e10cSrcweir if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
343cdf0e10cSrcweir UiEventLogHelper(::rtl::OUString::createFromAscii("ControlMenuController")).log(m_xServiceManager, m_xFrame, aURL, aArgs);
344cdf0e10cSrcweir if ( xDispatch.is() )
345cdf0e10cSrcweir xDispatch->dispatch( aURL, aArgs );
346cdf0e10cSrcweir }
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
itemActivated(const css::awt::MenuEvent &)349d026be40SAriel Constenla-Haile void SAL_CALL ControlMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex );
352cdf0e10cSrcweir
353cdf0e10cSrcweir if ( m_xPopupMenu.is() )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
356cdf0e10cSrcweir
357cdf0e10cSrcweir // Check if some modes have changed so we have to update our menu images
358cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
359cdf0e10cSrcweir sal_Bool bIsHiContrast = rSettings.GetHighContrastMode();
360cdf0e10cSrcweir sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
361cdf0e10cSrcweir sal_Bool bUpdateImages = (( m_bWasHiContrast != bIsHiContrast ) || ( bShowMenuImages != m_bShowMenuImages ));
362cdf0e10cSrcweir
363cdf0e10cSrcweir if ( bUpdateImages )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir // The mode has changed or the complete menu so we have to retrieve all images again
366cdf0e10cSrcweir m_bWasHiContrast = bIsHiContrast;
367cdf0e10cSrcweir m_bShowMenuImages = bShowMenuImages;
368cdf0e10cSrcweir
369cdf0e10cSrcweir VCLXPopupMenu* pPopupMenu = (VCLXPopupMenu *)VCLXPopupMenu::GetImplementation( m_xPopupMenu );
370cdf0e10cSrcweir if ( pPopupMenu )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir PopupMenu* pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
373cdf0e10cSrcweir if ( pVCLPopupMenu && bUpdateImages )
374cdf0e10cSrcweir updateImagesPopupMenu( pVCLPopupMenu );
375cdf0e10cSrcweir }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir }
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
380cdf0e10cSrcweir // XPopupMenuController
impl_setPopupMenu()381cdf0e10cSrcweir void ControlMenuController::impl_setPopupMenu()
382cdf0e10cSrcweir {
383cdf0e10cSrcweir if ( m_pResPopupMenu == 0 )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir rtl::OStringBuffer aBuf( 32 );
386cdf0e10cSrcweir aBuf.append( "svx" );
387cdf0e10cSrcweir
388cdf0e10cSrcweir ResMgr* pResMgr = ResMgr::CreateResMgr( aBuf.getStr() );
389cdf0e10cSrcweir if ( pResMgr )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir ResId aResId( RID_FMSHELL_CONVERSIONMENU, *pResMgr );
392cdf0e10cSrcweir aResId.SetRT( RSC_MENU );
393cdf0e10cSrcweir if ( pResMgr->IsAvailable( aResId ))
394cdf0e10cSrcweir m_pResPopupMenu = new PopupMenu( aResId );
395cdf0e10cSrcweir
396cdf0e10cSrcweir updateImagesPopupMenu( m_pResPopupMenu );
397cdf0e10cSrcweir delete pResMgr;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir } // if ( m_pResPopupMenu == 0 )
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
updatePopupMenu()402cdf0e10cSrcweir void SAL_CALL ControlMenuController::updatePopupMenu() throw (::com::sun::star::uno::RuntimeException)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex );
405cdf0e10cSrcweir
406cdf0e10cSrcweir throwIfDisposed();
407cdf0e10cSrcweir
408cdf0e10cSrcweir if ( m_xFrame.is() && m_xPopupMenu.is() )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir URL aTargetURL;
411cdf0e10cSrcweir Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
412cdf0e10cSrcweir fillPopupMenu( m_xPopupMenu );
413cdf0e10cSrcweir m_aURLToDispatchMap.free();
414cdf0e10cSrcweir
415cdf0e10cSrcweir for (sal_uInt32 i=0; i<sizeof(aCommands)/sizeof(aCommands[0]); ++i)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir aTargetURL.Complete = rtl::OUString::createFromAscii( aCommands[i] );
418cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL );
419cdf0e10cSrcweir
420cdf0e10cSrcweir Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
421cdf0e10cSrcweir if ( xDispatch.is() )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir xDispatch->addStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL );
424cdf0e10cSrcweir xDispatch->removeStatusListener( SAL_STATIC_CAST( XStatusListener*, this ), aTargetURL );
425cdf0e10cSrcweir m_aURLToDispatchMap.insert( UrlToDispatchMap::value_type( aTargetURL.Complete, xDispatch ));
426cdf0e10cSrcweir }
427cdf0e10cSrcweir }
428cdf0e10cSrcweir }
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & aArguments)432cdf0e10cSrcweir void SAL_CALL ControlMenuController::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir osl::ResettableMutexGuard aLock( m_aMutex );
435cdf0e10cSrcweir svt::PopupMenuControllerBase::initialize(aArguments);
436cdf0e10cSrcweir m_aBaseURL = ::rtl::OUString();
437cdf0e10cSrcweir }
438cdf0e10cSrcweir
439cdf0e10cSrcweir }
440