1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <framework/bmkmenu.hxx>
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
;
51 Sequence
< PropertyValue
>& aDynamicMenuEntry
,
60 static sal_uInt16 m_nMID
;
68 static sal_uInt16
GetMID();
71 sal_uInt16
BmkMenu_Impl::m_nMID
= BMKMENU_ITEMID_START
;
73 BmkMenu_Impl::BmkMenu_Impl() :
78 BmkMenu_Impl::~BmkMenu_Impl()
82 sal_uInt16
BmkMenu_Impl::GetMID()
86 m_nMID
= BMKMENU_ITEMID_START
;
90 BmkMenu::BmkMenu( Reference
< XFrame
>& xFrame
, BmkMenu::BmkMenuType nType
)
94 _pImp
= new BmkMenu_Impl();
103 void BmkMenu::Initialize()
105 SAL_INFO( "fwk", "framework (cd100003) ::BmkMenu::Initialize" );
107 if( _pImp
->m_bInitialized
)
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();
124 OUString aTargetFrame
;
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() )
135 if ( aURL
== "private:separator" )
139 sal_uInt16 nId
= CreateMenuId();
141 if ( bShowMenuImages
)
143 bool bImageSet
= false;
145 if ( !aImageId
.isEmpty() )
147 Image aImage
= GetImageFromURL( m_xFrame
, aImageId
, false );
151 InsertItem( nId
, aTitle
, aImage
);
157 Image aImage
= GetImageFromURL( m_xFrame
, aURL
, false );
159 InsertItem( nId
, aTitle
);
161 InsertItem( nId
, aTitle
, aImage
);
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();
182 Sequence
< PropertyValue
>& aDynamicMenuEntry
,
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: */