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 $
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 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
40 #include "classes/bmkmenu.hxx"
42 #include <macros/debug/assertion.hxx>
43 #include <helper/imageproducer.hxx>
44 #include <xml/menuconfiguration.hxx>
46 //_________________________________________________________________________________________________________________
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>
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 //_________________________________________________________________________________________________________________
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
;
83 Sequence
< PropertyValue
>& aDynamicMenuEntry
,
84 ::rtl::OUString
& rTitle
,
85 ::rtl::OUString
& rURL
,
86 ::rtl::OUString
& rFrame
,
87 ::rtl::OUString
& rImageId
);
98 BmkMenu_Impl( BmkMenu
* pRoot
);
102 static USHORT
GetMID();
105 USHORT
BmkMenu_Impl::m_nMID
= BMKMENU_ITEMID_START
;
107 BmkMenu_Impl::BmkMenu_Impl( BmkMenu
* pRoot
) :
109 m_bInitialized(FALSE
)
113 BmkMenu_Impl::BmkMenu_Impl() :
115 m_bInitialized(FALSE
)
119 BmkMenu_Impl::~BmkMenu_Impl()
123 USHORT
BmkMenu_Impl::GetMID()
127 m_nMID
= BMKMENU_ITEMID_START
;
131 // ------------------------------------------------------------------------
133 BmkMenu::BmkMenu( com::sun::star::uno::Reference
< XFrame
>& xFrame
, BmkMenu::BmkMenuType nType
, BmkMenu
* pRoot
)
137 _pImp
= new BmkMenu_Impl( pRoot
);
141 BmkMenu::BmkMenu( Reference
< XFrame
>& xFrame
, BmkMenu::BmkMenuType nType
)
145 _pImp
= new BmkMenu_Impl();
154 void BmkMenu::Initialize()
156 RTL_LOGFILE_CONTEXT( aLog
, "framework (cd100003) ::BmkMenu::Initialize" );
158 if( _pImp
->m_bInitialized
)
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() )
188 if ( aURL
== ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:separator" )))
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
);
202 bImageSet
= sal_True
;
203 InsertItem( nId
, aTitle
, aImage
);
209 Image aImage
= GetImageFromURL( m_xFrame
, aURL
, FALSE
, bIsHiContrastMode
);
211 InsertItem( nId
, aTitle
);
213 InsertItem( nId
, aTitle
, aImage
);
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();
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
;