Link Here
|
33 |
#include <macros/debug/assertion.hxx> |
33 |
#include <macros/debug/assertion.hxx> |
34 |
#include <framework/imageproducer.hxx> |
34 |
#include <framework/imageproducer.hxx> |
35 |
#include <framework/menuconfiguration.hxx> |
35 |
#include <framework/menuconfiguration.hxx> |
|
|
36 |
#include <services.h> |
36 |
|
37 |
|
37 |
//_________________________________________________________________________________________________________________ |
38 |
//_________________________________________________________________________________________________________________ |
38 |
// interface includes |
39 |
// interface includes |
Link Here
|
40 |
#include <com/sun/star/uno/Reference.hxx> |
41 |
#include <com/sun/star/uno/Reference.hxx> |
41 |
#include <com/sun/star/util/URL.hpp> |
42 |
#include <com/sun/star/util/URL.hpp> |
42 |
#include <com/sun/star/util/XURLTransformer.hpp> |
43 |
#include <com/sun/star/util/XURLTransformer.hpp> |
43 |
#include <com/sun/star/lang/XServiceInfo.hpp> |
44 |
#include <com/sun/star/frame/XModuleManager.hpp> |
44 |
|
45 |
|
45 |
//_________________________________________________________________________________________________________________ |
46 |
//_________________________________________________________________________________________________________________ |
46 |
// includes of other projects |
47 |
// includes of other projects |
Link Here
|
108 |
|
109 |
|
109 |
// ------------------------------------------------------------------------ |
110 |
// ------------------------------------------------------------------------ |
110 |
|
111 |
|
111 |
static Reference< XModel > GetModelFromFrame( const Reference< XFrame >& rFrame ) |
112 |
static ::rtl::OUString GetModuleIdentifier( const Reference< XMultiServiceFactory >& rServiceManager, |
|
|
113 |
const Reference< XFrame >& rFrame ) |
112 |
{ |
114 |
{ |
113 |
// Query for the model to get check the context information |
115 |
Reference< XModuleManager > xModuleManager( rServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY ); |
114 |
Reference< XModel > xModel; |
116 |
if ( xModuleManager.is() ) |
115 |
if ( rFrame.is() ) |
117 |
{ |
116 |
{ |
118 |
try |
117 |
Reference< XController > xController( rFrame->getController(), UNO_QUERY ); |
119 |
{ |
118 |
if ( xController.is() ) |
120 |
return xModuleManager->identify( rFrame ); |
119 |
xModel = xController->getModel(); |
121 |
} |
120 |
} |
122 |
catch ( Exception& ) |
121 |
|
123 |
{ |
122 |
return xModel; |
124 |
} |
|
|
125 |
} |
126 |
return ::rtl::OUString(); |
123 |
} |
127 |
} |
124 |
|
128 |
|
125 |
// ------------------------------------------------------------------------ |
129 |
// ------------------------------------------------------------------------ |
Link Here
|
146 |
} |
150 |
} |
147 |
|
151 |
|
148 |
// Create the Add-Ons menu |
152 |
// Create the Add-Ons menu |
149 |
AddonMenu* AddonMenuManager::CreateAddonMenu( const Reference< XFrame >& rFrame ) |
153 |
AddonMenu* AddonMenuManager::CreateAddonMenu( const Reference< XFrame >& rFrame, |
|
|
154 |
const Reference< XMultiServiceFactory >& rServiceManager ) |
150 |
{ |
155 |
{ |
151 |
AddonsOptions aOptions; |
156 |
AddonsOptions aOptions; |
152 |
AddonMenu* pAddonMenu = NULL; |
157 |
AddonMenu* pAddonMenu = NULL; |
Link Here
|
156 |
if ( rAddonMenuEntries.getLength() > 0 ) |
161 |
if ( rAddonMenuEntries.getLength() > 0 ) |
157 |
{ |
162 |
{ |
158 |
pAddonMenu = (AddonMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_MENU, rFrame ); |
163 |
pAddonMenu = (AddonMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_MENU, rFrame ); |
159 |
Reference< XModel > xModel = GetModelFromFrame( rFrame ); |
164 |
::rtl::OUString aModuleIdentifier = GetModuleIdentifier( rServiceManager, rFrame ); |
160 |
AddonMenuManager::BuildMenu( pAddonMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, rAddonMenuEntries, rFrame, xModel ); |
165 |
AddonMenuManager::BuildMenu( pAddonMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, rAddonMenuEntries, rFrame, aModuleIdentifier ); |
161 |
|
166 |
|
162 |
// Don't return an empty Add-On menu |
167 |
// Don't return an empty Add-On menu |
163 |
if ( pAddonMenu->GetItemCount() == 0 ) |
168 |
if ( pAddonMenu->GetItemCount() == 0 ) |
Link Here
|
194 |
|
199 |
|
195 |
|
200 |
|
196 |
// Merge the Add-Ons help menu items into the given menu bar at a defined pos |
201 |
// Merge the Add-Ons help menu items into the given menu bar at a defined pos |
197 |
void AddonMenuManager::MergeAddonHelpMenu( const Reference< XFrame >& rFrame, MenuBar* pMergeMenuBar ) |
202 |
void AddonMenuManager::MergeAddonHelpMenu( const Reference< XFrame >& rFrame, |
|
|
203 |
MenuBar* pMergeMenuBar, |
204 |
const Reference< XMultiServiceFactory >& rServiceManager ) |
198 |
{ |
205 |
{ |
199 |
if ( pMergeMenuBar ) |
206 |
if ( pMergeMenuBar ) |
200 |
{ |
207 |
{ |
Link Here
|
245 |
if ( nInsPos < nItemCount && pHelpMenu->GetItemType( nInsPos ) != MENUITEM_SEPARATOR ) |
252 |
if ( nInsPos < nItemCount && pHelpMenu->GetItemType( nInsPos ) != MENUITEM_SEPARATOR ) |
246 |
nInsSepAfterPos = nInsPos; |
253 |
nInsSepAfterPos = nInsPos; |
247 |
|
254 |
|
248 |
Reference< XModel > xModel = GetModelFromFrame( rFrame ); |
255 |
::rtl::OUString aModuleIdentifier = GetModuleIdentifier( rServiceManager, rFrame ); |
249 |
AddonMenuManager::BuildMenu( pHelpMenu, ADDON_MENU, nInsPos, nUniqueMenuId, rAddonHelpMenuEntries, rFrame, xModel ); |
256 |
AddonMenuManager::BuildMenu( pHelpMenu, ADDON_MENU, nInsPos, nUniqueMenuId, rAddonHelpMenuEntries, rFrame, aModuleIdentifier ); |
250 |
|
257 |
|
251 |
if ( pHelpMenu->GetItemCount() > nItemCount ) |
258 |
if ( pHelpMenu->GetItemCount() > nItemCount ) |
252 |
{ |
259 |
{ |
Link Here
|
267 |
|
274 |
|
268 |
// Merge the addon popup menus into the given menu bar at the provided pos. |
275 |
// Merge the addon popup menus into the given menu bar at the provided pos. |
269 |
void AddonMenuManager::MergeAddonPopupMenus( const Reference< XFrame >& rFrame, |
276 |
void AddonMenuManager::MergeAddonPopupMenus( const Reference< XFrame >& rFrame, |
270 |
const Reference< XModel >& rModel, |
|
|
271 |
sal_uInt16 nMergeAtPos, |
277 |
sal_uInt16 nMergeAtPos, |
272 |
MenuBar* pMergeMenuBar ) |
278 |
MenuBar* pMergeMenuBar, |
|
|
279 |
const Reference< XMultiServiceFactory >& rServiceManager ) |
273 |
{ |
280 |
{ |
274 |
if ( pMergeMenuBar ) |
281 |
if ( pMergeMenuBar ) |
275 |
{ |
282 |
{ |
Link Here
|
283 |
::rtl::OUString aContext; |
290 |
::rtl::OUString aContext; |
284 |
Sequence< Sequence< PropertyValue > > aAddonSubMenu; |
291 |
Sequence< Sequence< PropertyValue > > aAddonSubMenu; |
285 |
sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; |
292 |
sal_uInt16 nUniqueMenuId = ADDONMENU_ITEMID_START; |
|
|
293 |
::rtl::OUString aModuleIdentifier = GetModuleIdentifier( rServiceManager, rFrame ); |
286 |
|
294 |
|
287 |
const Sequence< Sequence< PropertyValue > >& rAddonMenuEntries = aAddonsOptions.GetAddonsMenuBarPart(); |
295 |
const Sequence< Sequence< PropertyValue > >& rAddonMenuEntries = aAddonsOptions.GetAddonsMenuBarPart(); |
288 |
for ( sal_Int32 i = 0; i < rAddonMenuEntries.getLength(); i++ ) |
296 |
for ( sal_Int32 i = 0; i < rAddonMenuEntries.getLength(); i++ ) |
Link Here
|
297 |
if ( aTitle.getLength() > 0 && |
305 |
if ( aTitle.getLength() > 0 && |
298 |
aURL.getLength() > 0 && |
306 |
aURL.getLength() > 0 && |
299 |
aAddonSubMenu.getLength() > 0 && |
307 |
aAddonSubMenu.getLength() > 0 && |
300 |
AddonMenuManager::IsCorrectContext( rModel, aContext )) |
308 |
AddonMenuManager::IsCorrectContext( aModuleIdentifier, aContext )) |
301 |
{ |
309 |
{ |
302 |
sal_uInt16 nId = nUniqueMenuId++; |
310 |
sal_uInt16 nId = nUniqueMenuId++; |
303 |
AddonPopupMenu* pAddonPopupMenu = (AddonPopupMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_POPUPMENU, rFrame ); |
311 |
AddonPopupMenu* pAddonPopupMenu = (AddonPopupMenu *)AddonMenuManager::CreatePopupMenuType( ADDON_POPUPMENU, rFrame ); |
304 |
|
312 |
|
305 |
AddonMenuManager::BuildMenu( pAddonPopupMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, rModel ); |
313 |
AddonMenuManager::BuildMenu( pAddonPopupMenu, ADDON_MENU, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, aModuleIdentifier ); |
306 |
|
314 |
|
307 |
if ( pAddonPopupMenu->GetItemCount() > 0 ) |
315 |
if ( pAddonPopupMenu->GetItemCount() > 0 ) |
308 |
{ |
316 |
{ |
Link Here
|
327 |
sal_uInt16& nUniqueMenuId, |
335 |
sal_uInt16& nUniqueMenuId, |
328 |
Sequence< Sequence< PropertyValue > > aAddonMenuDefinition, |
336 |
Sequence< Sequence< PropertyValue > > aAddonMenuDefinition, |
329 |
const Reference< XFrame >& rFrame, |
337 |
const Reference< XFrame >& rFrame, |
330 |
const Reference< XModel >& rModel ) |
338 |
const ::rtl::OUString& rModuleIdentifier ) |
331 |
{ |
339 |
{ |
332 |
Sequence< Sequence< PropertyValue > > aAddonSubMenu; |
340 |
Sequence< Sequence< PropertyValue > > aAddonSubMenu; |
333 |
sal_Bool bInsertSeparator = sal_False; |
341 |
sal_Bool bInsertSeparator = sal_False; |
Link Here
|
346 |
{ |
354 |
{ |
347 |
GetMenuEntry( aAddonMenuDefinition[i], aTitle, aURL, aTarget, aImageId, aContext, aAddonSubMenu ); |
355 |
GetMenuEntry( aAddonMenuDefinition[i], aTitle, aURL, aTarget, aImageId, aContext, aAddonSubMenu ); |
348 |
|
356 |
|
349 |
if ( !IsCorrectContext( rModel, aContext ) || ( !aTitle.getLength() && !aURL.getLength() )) |
357 |
if ( !IsCorrectContext( rModuleIdentifier, aContext ) || ( !aTitle.getLength() && !aURL.getLength() )) |
350 |
continue; |
358 |
continue; |
351 |
|
359 |
|
352 |
if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" ))) |
360 |
if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" ))) |
Link Here
|
357 |
if ( aAddonSubMenu.getLength() > 0 ) |
365 |
if ( aAddonSubMenu.getLength() > 0 ) |
358 |
{ |
366 |
{ |
359 |
pSubMenu = AddonMenuManager::CreatePopupMenuType( nSubMenuType, rFrame ); |
367 |
pSubMenu = AddonMenuManager::CreatePopupMenuType( nSubMenuType, rFrame ); |
360 |
AddonMenuManager::BuildMenu( pSubMenu, nSubMenuType, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, rModel ); |
368 |
AddonMenuManager::BuildMenu( pSubMenu, nSubMenuType, MENU_APPEND, nUniqueMenuId, aAddonSubMenu, rFrame, rModuleIdentifier ); |
361 |
|
369 |
|
362 |
// Don't create a menu item for an empty sub menu |
370 |
// Don't create a menu item for an empty sub menu |
363 |
if ( pSubMenu->GetItemCount() == 0 ) |
371 |
if ( pSubMenu->GetItemCount() == 0 ) |
Link Here
|
426 |
} |
434 |
} |
427 |
|
435 |
|
428 |
// Check if the context string matches the provided xModel context |
436 |
// Check if the context string matches the provided xModel context |
429 |
sal_Bool AddonMenuManager::IsCorrectContext( const Reference< XModel >& rModel, const ::rtl::OUString& aContext ) |
437 |
sal_Bool AddonMenuManager::IsCorrectContext( const ::rtl::OUString& rModuleIdentifier, const ::rtl::OUString& aContext ) |
430 |
{ |
438 |
{ |
431 |
if ( rModel.is() ) |
439 |
if ( aContext.isEmpty() ) |
432 |
{ |
440 |
return sal_True; |
433 |
Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( rModel, UNO_QUERY ); |
441 |
|
434 |
if ( xServiceInfo.is() ) |
442 |
if ( !rModuleIdentifier.isEmpty() ) |
435 |
{ |
443 |
{ |
436 |
sal_Int32 nIndex = 0; |
444 |
sal_Int32 nIndex = aContext.indexOf( rModuleIdentifier ); |
437 |
do |
445 |
return ( nIndex >= 0 ); |
438 |
{ |
446 |
} |
439 |
::rtl::OUString aToken = aContext.getToken( 0, ',', nIndex ); |
447 |
|
440 |
|
448 |
return sal_False; |
441 |
if ( xServiceInfo->supportsService( aToken )) |
|
|
442 |
return sal_True; |
443 |
} |
444 |
while ( nIndex >= 0 ); |
445 |
} |
446 |
} |
447 |
|
448 |
return ( aContext.getLength() == 0 ); |
449 |
} |
449 |
} |
450 |
|
450 |
|
451 |
} |
451 |
} |