Update ooo320-m1
[ooovba.git] / framework / source / classes / bmkmenu.cxx
blob6bee8c399df89fdc9841b9885289c8089ad8d4f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bmkmenu.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
38 #include <limits.h>
40 #include "classes/bmkmenu.hxx"
41 #include <general.h>
42 #include <macros/debug/assertion.hxx>
43 #include <helper/imageproducer.hxx>
44 #include <xml/menuconfiguration.hxx>
46 //_________________________________________________________________________________________________________________
47 // interface includes
48 //_________________________________________________________________________________________________________________
49 #include <com/sun/star/uno/Reference.h>
50 #include <com/sun/star/util/URL.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
53 #include <comphelper/processfactory.hxx>
54 #endif
55 #include <com/sun/star/util/XURLTransformer.hpp>
56 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
57 #include <com/sun/star/util/DateTime.hpp>
59 //_________________________________________________________________________________________________________________
60 // includes of other projects
61 //_________________________________________________________________________________________________________________
62 #include <tools/config.hxx>
63 #include <vcl/svapp.hxx>
64 #include <svtools/dynamicmenuoptions.hxx>
65 #include <svtools/menuoptions.hxx>
66 #include <rtl/logfile.hxx>
68 //_________________________________________________________________________________________________________________
69 // namespace
70 //_________________________________________________________________________________________________________________
72 using namespace ::comphelper;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::lang;
75 using namespace ::com::sun::star::util;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::beans;
79 namespace framework
82 void GetMenuEntry(
83 Sequence< PropertyValue >& aDynamicMenuEntry,
84 ::rtl::OUString& rTitle,
85 ::rtl::OUString& rURL,
86 ::rtl::OUString& rFrame,
87 ::rtl::OUString& rImageId );
89 class BmkMenu_Impl
91 private:
92 static USHORT m_nMID;
94 public:
95 BmkMenu* m_pRoot;
96 BOOL m_bInitialized;
98 BmkMenu_Impl( BmkMenu* pRoot );
99 BmkMenu_Impl();
100 ~BmkMenu_Impl();
102 static USHORT GetMID();
105 USHORT BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
107 BmkMenu_Impl::BmkMenu_Impl( BmkMenu* pRoot ) :
108 m_pRoot(pRoot),
109 m_bInitialized(FALSE)
113 BmkMenu_Impl::BmkMenu_Impl() :
114 m_pRoot(0),
115 m_bInitialized(FALSE)
119 BmkMenu_Impl::~BmkMenu_Impl()
123 USHORT BmkMenu_Impl::GetMID()
125 m_nMID++;
126 if( !m_nMID )
127 m_nMID = BMKMENU_ITEMID_START;
128 return m_nMID;
131 // ------------------------------------------------------------------------
133 BmkMenu::BmkMenu( com::sun::star::uno::Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType, BmkMenu* pRoot )
134 :AddonMenu(xFrame)
135 ,m_nType( nType )
137 _pImp = new BmkMenu_Impl( pRoot );
138 Initialize();
141 BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
142 :AddonMenu(xFrame)
143 ,m_nType( nType )
145 _pImp = new BmkMenu_Impl();
146 Initialize();
149 BmkMenu::~BmkMenu()
151 delete _pImp;
154 void BmkMenu::Initialize()
156 RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::BmkMenu::Initialize" );
158 if( _pImp->m_bInitialized )
159 return;
161 _pImp->m_bInitialized = TRUE;
163 Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
165 if ( m_nType == BmkMenu::BMK_NEWMENU )
166 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
167 else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
168 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
170 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
171 BOOL bShowMenuImages = rSettings.GetUseImagesInMenus();
173 ::rtl::OUString aTitle;
174 ::rtl::OUString aURL;
175 ::rtl::OUString aTargetFrame;
176 ::rtl::OUString aImageId;
178 BOOL bIsHiContrastMode = rSettings.GetHighContrastMode();
180 UINT32 i, nCount = aDynamicMenuEntries.getLength();
181 for ( i = 0; i < nCount; ++i )
183 GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
185 if ( !aTitle.getLength() && !aURL.getLength() )
186 continue;
188 if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" )))
189 InsertSeparator();
190 else
192 sal_Bool bImageSet = sal_False;
193 USHORT nId = CreateMenuId();
195 if ( bShowMenuImages )
197 if ( aImageId.getLength() > 0 )
199 Image aImage = GetImageFromURL( m_xFrame, aImageId, FALSE, bIsHiContrastMode );
200 if ( !!aImage )
202 bImageSet = sal_True;
203 InsertItem( nId, aTitle, aImage );
207 if ( !bImageSet )
209 Image aImage = GetImageFromURL( m_xFrame, aURL, FALSE, bIsHiContrastMode );
210 if ( !aImage )
211 InsertItem( nId, aTitle );
212 else
213 InsertItem( nId, aTitle, aImage );
216 else
217 InsertItem( nId, aTitle );
219 // Store values from configuration to the New and Wizard menu entries to enable
220 // sfx2 based code to support high contrast mode correctly!
221 MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
222 SetUserValue( nId, (ULONG)pUserAttributes );
224 SetItemCommand( nId, aURL );
229 USHORT BmkMenu::CreateMenuId()
231 return BmkMenu_Impl::GetMID();
234 void GetMenuEntry
236 Sequence< PropertyValue >& aDynamicMenuEntry,
237 ::rtl::OUString& rTitle,
238 ::rtl::OUString& rURL,
239 ::rtl::OUString& rFrame,
240 ::rtl::OUString& rImageId
243 for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
245 if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
246 aDynamicMenuEntry[i].Value >>= rURL;
247 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
248 aDynamicMenuEntry[i].Value >>= rTitle;
249 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
250 aDynamicMenuEntry[i].Value >>= rImageId;
251 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
252 aDynamicMenuEntry[i].Value >>= rFrame;