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