1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32*cdf0e10cSrcweir //	my own includes
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <limits.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "framework/bmkmenu.hxx"
38*cdf0e10cSrcweir #include <general.h>
39*cdf0e10cSrcweir #include <macros/debug/assertion.hxx>
40*cdf0e10cSrcweir #include <framework/imageproducer.hxx>
41*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir //	interface includes
45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
47*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
49*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
50*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57*cdf0e10cSrcweir //	includes of other projects
58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
59*cdf0e10cSrcweir #include <tools/config.hxx>
60*cdf0e10cSrcweir #include <vcl/svapp.hxx>
61*cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx>
62*cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
63*cdf0e10cSrcweir #include <rtl/logfile.hxx>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
66*cdf0e10cSrcweir //	namespace
67*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir using namespace ::comphelper;
70*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
71*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
72*cdf0e10cSrcweir using namespace ::com::sun::star::util;
73*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
74*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir namespace framework
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void GetMenuEntry(
80*cdf0e10cSrcweir 	Sequence< PropertyValue >&	aDynamicMenuEntry,
81*cdf0e10cSrcweir 	::rtl::OUString&			rTitle,
82*cdf0e10cSrcweir 	::rtl::OUString&			rURL,
83*cdf0e10cSrcweir 	::rtl::OUString&			rFrame,
84*cdf0e10cSrcweir 	::rtl::OUString&			rImageId );
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir class BmkMenu_Impl
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	private:
89*cdf0e10cSrcweir 		static sal_uInt16		 m_nMID;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	public:
92*cdf0e10cSrcweir 		BmkMenu*			 m_pRoot;
93*cdf0e10cSrcweir 		sal_Bool                 m_bInitialized;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 		BmkMenu_Impl( BmkMenu* pRoot );
96*cdf0e10cSrcweir 		BmkMenu_Impl();
97*cdf0e10cSrcweir 		~BmkMenu_Impl();
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 		static sal_uInt16		GetMID();
100*cdf0e10cSrcweir };
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir BmkMenu_Impl::BmkMenu_Impl( BmkMenu* pRoot ) :
105*cdf0e10cSrcweir 	m_pRoot(pRoot),
106*cdf0e10cSrcweir 	m_bInitialized(sal_False)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir BmkMenu_Impl::BmkMenu_Impl() :
111*cdf0e10cSrcweir 	m_pRoot(0),
112*cdf0e10cSrcweir 	m_bInitialized(sal_False)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir BmkMenu_Impl::~BmkMenu_Impl()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir sal_uInt16 BmkMenu_Impl::GetMID()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	m_nMID++;
123*cdf0e10cSrcweir 	if( !m_nMID )
124*cdf0e10cSrcweir         m_nMID = BMKMENU_ITEMID_START;
125*cdf0e10cSrcweir 	return m_nMID;
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir // ------------------------------------------------------------------------
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir BmkMenu::BmkMenu( com::sun::star::uno::Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType, BmkMenu* pRoot )
131*cdf0e10cSrcweir     :AddonMenu(xFrame)
132*cdf0e10cSrcweir     ,m_nType( nType )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     _pImp = new BmkMenu_Impl( pRoot );
135*cdf0e10cSrcweir     Initialize();
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
139*cdf0e10cSrcweir     :AddonMenu(xFrame)
140*cdf0e10cSrcweir     ,m_nType( nType )
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     _pImp = new BmkMenu_Impl();
143*cdf0e10cSrcweir     Initialize();
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir BmkMenu::~BmkMenu()
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir 	delete _pImp;
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir void BmkMenu::Initialize()
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT( aLog, "framework (cd100003) ::BmkMenu::Initialize" );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     if( _pImp->m_bInitialized )
156*cdf0e10cSrcweir 		return;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     _pImp->m_bInitialized = sal_True;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	if ( m_nType == BmkMenu::BMK_NEWMENU )
163*cdf0e10cSrcweir 		aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
164*cdf0e10cSrcweir 	else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
165*cdf0e10cSrcweir 		aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
168*cdf0e10cSrcweir 	sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	::rtl::OUString aTitle;
171*cdf0e10cSrcweir 	::rtl::OUString aURL;
172*cdf0e10cSrcweir 	::rtl::OUString aTargetFrame;
173*cdf0e10cSrcweir 	::rtl::OUString aImageId;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode();
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
178*cdf0e10cSrcweir 	for ( i = 0; i < nCount; ++i )
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 		if ( !aTitle.getLength() && !aURL.getLength() )
183*cdf0e10cSrcweir 			continue;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         if ( aURL == ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" )))
186*cdf0e10cSrcweir 			InsertSeparator();
187*cdf0e10cSrcweir 		else
188*cdf0e10cSrcweir 		{
189*cdf0e10cSrcweir 			sal_Bool	bImageSet = sal_False;
190*cdf0e10cSrcweir 			sal_uInt16		nId = CreateMenuId();
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 			if ( bShowMenuImages )
193*cdf0e10cSrcweir 			{
194*cdf0e10cSrcweir 				if ( aImageId.getLength() > 0 )
195*cdf0e10cSrcweir 				{
196*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( m_xFrame, aImageId, sal_False, bIsHiContrastMode );
197*cdf0e10cSrcweir 					if ( !!aImage )
198*cdf0e10cSrcweir 					{
199*cdf0e10cSrcweir 						bImageSet = sal_True;
200*cdf0e10cSrcweir 						InsertItem( nId, aTitle, aImage );
201*cdf0e10cSrcweir 					}
202*cdf0e10cSrcweir 				}
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 				if ( !bImageSet )
205*cdf0e10cSrcweir 				{
206*cdf0e10cSrcweir 					Image aImage = GetImageFromURL( m_xFrame, aURL, sal_False, bIsHiContrastMode );
207*cdf0e10cSrcweir 					if ( !aImage )
208*cdf0e10cSrcweir 						InsertItem( nId, aTitle );
209*cdf0e10cSrcweir 					else
210*cdf0e10cSrcweir 						InsertItem( nId, aTitle, aImage );
211*cdf0e10cSrcweir 				}
212*cdf0e10cSrcweir 			}
213*cdf0e10cSrcweir 			else
214*cdf0e10cSrcweir 				InsertItem( nId, aTitle );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 			// Store values from configuration to the New and Wizard menu entries to enable
217*cdf0e10cSrcweir 			// sfx2 based code to support high contrast mode correctly!
218*cdf0e10cSrcweir 			MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
219*cdf0e10cSrcweir 			SetUserValue( nId, (sal_uIntPtr)pUserAttributes );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 			SetItemCommand( nId, aURL );
222*cdf0e10cSrcweir 		}
223*cdf0e10cSrcweir 	}
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir sal_uInt16 BmkMenu::CreateMenuId()
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     return BmkMenu_Impl::GetMID();
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir void GetMenuEntry
232*cdf0e10cSrcweir (
233*cdf0e10cSrcweir 	Sequence< PropertyValue >& aDynamicMenuEntry,
234*cdf0e10cSrcweir 	::rtl::OUString& rTitle,
235*cdf0e10cSrcweir 	::rtl::OUString& rURL,
236*cdf0e10cSrcweir     ::rtl::OUString& rFrame,
237*cdf0e10cSrcweir 	::rtl::OUString& rImageId
238*cdf0e10cSrcweir )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
241*cdf0e10cSrcweir 	{
242*cdf0e10cSrcweir 		if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
243*cdf0e10cSrcweir 			aDynamicMenuEntry[i].Value >>= rURL;
244*cdf0e10cSrcweir 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
245*cdf0e10cSrcweir 			aDynamicMenuEntry[i].Value >>= rTitle;
246*cdf0e10cSrcweir 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
247*cdf0e10cSrcweir 			aDynamicMenuEntry[i].Value >>= rImageId;
248*cdf0e10cSrcweir 		else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
249*cdf0e10cSrcweir 			aDynamicMenuEntry[i].Value >>= rFrame;
250*cdf0e10cSrcweir 	}
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255