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