Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <limits.h>
21 :
22 : #include "framework/bmkmenu.hxx"
23 : #include <general.h>
24 : #include <framework/imageproducer.hxx>
25 : #include <framework/menuconfiguration.hxx>
26 :
27 : #include <com/sun/star/uno/Reference.h>
28 : #include <com/sun/star/util/URL.hpp>
29 : #include <com/sun/star/beans/PropertyValue.hpp>
30 : #include <comphelper/processfactory.hxx>
31 : #include <com/sun/star/util/XURLTransformer.hpp>
32 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 : #include <com/sun/star/util/DateTime.hpp>
34 :
35 : #include <vcl/svapp.hxx>
36 : #include <vcl/settings.hxx>
37 : #include <unotools/dynamicmenuoptions.hxx>
38 : #include <svtools/menuoptions.hxx>
39 :
40 : using namespace ::comphelper;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::lang;
43 : using namespace ::com::sun::star::util;
44 : using namespace ::com::sun::star::frame;
45 : using namespace ::com::sun::star::beans;
46 :
47 : namespace framework
48 : {
49 :
50 : void GetMenuEntry(
51 : Sequence< PropertyValue >& aDynamicMenuEntry,
52 : OUString& rTitle,
53 : OUString& rURL,
54 : OUString& rFrame,
55 : OUString& rImageId );
56 :
57 : class BmkMenu_Impl
58 : {
59 : private:
60 : static sal_uInt16 m_nMID;
61 :
62 : public:
63 : bool m_bInitialized;
64 :
65 : BmkMenu_Impl();
66 : ~BmkMenu_Impl();
67 :
68 : static sal_uInt16 GetMID();
69 : };
70 :
71 : sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
72 :
73 0 : BmkMenu_Impl::BmkMenu_Impl() :
74 0 : m_bInitialized(false)
75 : {
76 0 : }
77 :
78 0 : BmkMenu_Impl::~BmkMenu_Impl()
79 : {
80 0 : }
81 :
82 0 : sal_uInt16 BmkMenu_Impl::GetMID()
83 : {
84 0 : m_nMID++;
85 0 : if( !m_nMID )
86 0 : m_nMID = BMKMENU_ITEMID_START;
87 0 : return m_nMID;
88 : }
89 :
90 0 : BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
91 : :AddonMenu(xFrame)
92 0 : ,m_nType( nType )
93 : {
94 0 : _pImp = new BmkMenu_Impl();
95 0 : Initialize();
96 0 : }
97 :
98 0 : BmkMenu::~BmkMenu()
99 : {
100 0 : delete _pImp;
101 0 : }
102 :
103 0 : void BmkMenu::Initialize()
104 : {
105 : SAL_INFO( "fwk", "framework (cd100003) ::BmkMenu::Initialize" );
106 :
107 0 : if( _pImp->m_bInitialized )
108 0 : return;
109 :
110 0 : _pImp->m_bInitialized = true;
111 :
112 0 : Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
113 :
114 0 : if ( m_nType == BmkMenu::BMK_NEWMENU )
115 0 : aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
116 0 : else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
117 0 : aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
118 :
119 0 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
120 0 : bool bShowMenuImages = rSettings.GetUseImagesInMenus();
121 :
122 0 : OUString aTitle;
123 0 : OUString aURL;
124 0 : OUString aTargetFrame;
125 0 : OUString aImageId;
126 :
127 0 : sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
128 0 : for ( i = 0; i < nCount; ++i )
129 : {
130 0 : GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
131 :
132 0 : if ( aTitle.isEmpty() && aURL.isEmpty() )
133 0 : continue;
134 :
135 0 : if ( aURL == "private:separator" )
136 0 : InsertSeparator();
137 : else
138 : {
139 0 : bool bImageSet = false;
140 0 : sal_uInt16 nId = CreateMenuId();
141 :
142 0 : if ( bShowMenuImages )
143 : {
144 0 : if ( !aImageId.isEmpty() )
145 : {
146 0 : Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
147 0 : if ( !!aImage )
148 : {
149 0 : bImageSet = true;
150 0 : InsertItem( nId, aTitle, aImage );
151 0 : }
152 : }
153 :
154 0 : if ( !bImageSet )
155 : {
156 0 : Image aImage = GetImageFromURL( m_xFrame, aURL, false );
157 0 : if ( !aImage )
158 0 : InsertItem( nId, aTitle );
159 : else
160 0 : InsertItem( nId, aTitle, aImage );
161 : }
162 : }
163 : else
164 0 : InsertItem( nId, aTitle );
165 :
166 0 : MenuConfiguration::Attributes* pUserAttributes = new MenuConfiguration::Attributes( aTargetFrame, aImageId );
167 0 : SetUserValue( nId, (sal_uIntPtr)pUserAttributes );
168 :
169 0 : SetItemCommand( nId, aURL );
170 : }
171 0 : }
172 : }
173 :
174 0 : sal_uInt16 BmkMenu::CreateMenuId()
175 : {
176 0 : return BmkMenu_Impl::GetMID();
177 : }
178 :
179 0 : void GetMenuEntry
180 : (
181 : Sequence< PropertyValue >& aDynamicMenuEntry,
182 : OUString& rTitle,
183 : OUString& rURL,
184 : OUString& rFrame,
185 : OUString& rImageId
186 : )
187 : {
188 0 : for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
189 : {
190 0 : if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
191 0 : aDynamicMenuEntry[i].Value >>= rURL;
192 0 : else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
193 0 : aDynamicMenuEntry[i].Value >>= rTitle;
194 0 : else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
195 0 : aDynamicMenuEntry[i].Value >>= rImageId;
196 0 : else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
197 0 : aDynamicMenuEntry[i].Value >>= rFrame;
198 : }
199 0 : }
200 :
201 : }
202 :
203 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|