fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwe / classes / bmkmenu.cxx
blobcc9c31f4617b4e18385dcae5967e10c692e2a67f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <limits.h>
22 #include <framework/bmkmenu.hxx>
23 #include <general.h>
24 #include <framework/imageproducer.hxx>
25 #include <framework/menuconfiguration.hxx>
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>
35 #include <vcl/svapp.hxx>
36 #include <vcl/settings.hxx>
37 #include <unotools/dynamicmenuoptions.hxx>
38 #include <svtools/menuoptions.hxx>
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;
47 namespace framework
50 void GetMenuEntry(
51 Sequence< PropertyValue >& aDynamicMenuEntry,
52 OUString& rTitle,
53 OUString& rURL,
54 OUString& rFrame,
55 OUString& rImageId );
57 class BmkMenu_Impl
59 private:
60 static sal_uInt16 m_nMID;
62 public:
63 bool m_bInitialized;
65 BmkMenu_Impl();
66 ~BmkMenu_Impl();
68 static sal_uInt16 GetMID();
71 sal_uInt16 BmkMenu_Impl::m_nMID = BMKMENU_ITEMID_START;
73 BmkMenu_Impl::BmkMenu_Impl() :
74 m_bInitialized(false)
78 BmkMenu_Impl::~BmkMenu_Impl()
82 sal_uInt16 BmkMenu_Impl::GetMID()
84 m_nMID++;
85 if( !m_nMID )
86 m_nMID = BMKMENU_ITEMID_START;
87 return m_nMID;
90 BmkMenu::BmkMenu( Reference< XFrame >& xFrame, BmkMenu::BmkMenuType nType )
91 :AddonMenu(xFrame)
92 ,m_nType( nType )
94 _pImp = new BmkMenu_Impl();
95 Initialize();
98 BmkMenu::~BmkMenu()
100 delete _pImp;
103 void BmkMenu::Initialize()
105 SAL_INFO( "fwk", "framework (cd100003) ::BmkMenu::Initialize" );
107 if( _pImp->m_bInitialized )
108 return;
110 _pImp->m_bInitialized = true;
112 Sequence< Sequence< PropertyValue > > aDynamicMenuEntries;
114 if ( m_nType == BmkMenu::BMK_NEWMENU )
115 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_NEWMENU );
116 else if ( m_nType == BmkMenu::BMK_WIZARDMENU )
117 aDynamicMenuEntries = SvtDynamicMenuOptions().GetMenu( E_WIZARDMENU );
119 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
120 bool bShowMenuImages = rSettings.GetUseImagesInMenus();
122 OUString aTitle;
123 OUString aURL;
124 OUString aTargetFrame;
125 OUString aImageId;
127 sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
128 for ( i = 0; i < nCount; ++i )
130 GetMenuEntry( aDynamicMenuEntries[i], aTitle, aURL, aTargetFrame, aImageId );
132 if ( aTitle.isEmpty() && aURL.isEmpty() )
133 continue;
135 if ( aURL == "private:separator" )
136 InsertSeparator();
137 else
139 sal_uInt16 nId = CreateMenuId();
141 if ( bShowMenuImages )
143 bool bImageSet = false;
145 if ( !aImageId.isEmpty() )
147 Image aImage = GetImageFromURL( m_xFrame, aImageId, false );
148 if ( !!aImage )
150 bImageSet = true;
151 InsertItem( nId, aTitle, aImage );
155 if ( !bImageSet )
157 Image aImage = GetImageFromURL( m_xFrame, aURL, false );
158 if ( !aImage )
159 InsertItem( nId, aTitle );
160 else
161 InsertItem( nId, aTitle, aImage );
164 else
165 InsertItem( nId, aTitle );
167 sal_uIntPtr nAttributePtr = MenuAttributes::CreateAttribute(aTargetFrame, aImageId);
168 SetUserValue(nId, nAttributePtr, MenuAttributes::ReleaseAttribute);
170 SetItemCommand( nId, aURL );
175 sal_uInt16 BmkMenu::CreateMenuId()
177 return BmkMenu_Impl::GetMID();
180 void GetMenuEntry
182 Sequence< PropertyValue >& aDynamicMenuEntry,
183 OUString& rTitle,
184 OUString& rURL,
185 OUString& rFrame,
186 OUString& rImageId
189 for ( int i = 0; i < aDynamicMenuEntry.getLength(); i++ )
191 if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_URL )
192 aDynamicMenuEntry[i].Value >>= rURL;
193 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
194 aDynamicMenuEntry[i].Value >>= rTitle;
195 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
196 aDynamicMenuEntry[i].Value >>= rImageId;
197 else if ( aDynamicMenuEntry[i].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
198 aDynamicMenuEntry[i].Value >>= rFrame;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */