fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uifactory / menubarfactory.cxx
blob55afe317e5b6570103bb4662ad74d70c3051b870
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 <uifactory/menubarfactory.hxx>
22 #include <uielement/menubarwrapper.hxx>
24 #include <com/sun/star/frame/ModuleManager.hpp>
25 #include <com/sun/star/frame/XFrame.hpp>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
29 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <vcl/menu.hxx>
33 #include <vcl/svapp.hxx>
34 #include <rtl/ustrbuf.hxx>
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::frame;
39 using namespace com::sun::star::beans;
40 using namespace com::sun::star::util;
41 using namespace ::com::sun::star::ui;
43 namespace framework
46 MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext )
47 : m_xContext( xContext )
51 MenuBarFactory::~MenuBarFactory()
55 // XUIElementFactory
56 Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
57 const OUString& ResourceURL,
58 const Sequence< PropertyValue >& Args )
59 throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception )
61 Reference< ::com::sun::star::ui::XUIElement > xMenuBar(
62 static_cast<OWeakObject *>(new MenuBarWrapper(m_xContext)), UNO_QUERY);
63 CreateUIElement(ResourceURL, Args, "MenuOnly", "private:resource/menubar/", xMenuBar, m_xContext);
64 return xMenuBar;
67 void MenuBarFactory::CreateUIElement(const OUString& ResourceURL
68 ,const Sequence< PropertyValue >& Args
69 ,const char* _pExtraMode
70 ,const OUString& ResourceType
71 ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
72 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
74 Reference< XUIConfigurationManager > xCfgMgr;
75 Reference< XUIConfigurationManager > xConfigSource;
76 Reference< XFrame > xFrame;
77 OUString aResourceURL( ResourceURL );
78 bool bPersistent( true );
79 bool bExtraMode( false );
81 for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
83 if ( Args[n].Name == "ConfigurationSource" )
84 Args[n].Value >>= xConfigSource;
85 else if ( Args[n].Name == "Frame" )
86 Args[n].Value >>= xFrame;
87 else if ( Args[n].Name == "ResourceURL" )
88 Args[n].Value >>= aResourceURL;
89 else if ( Args[n].Name == "Persistent" )
90 Args[n].Value >>= bPersistent;
91 else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
92 Args[n].Value >>= bExtraMode;
94 if (!aResourceURL.startsWith(ResourceType))
95 throw IllegalArgumentException();
97 // Identify frame and determine document based ui configuration manager/module ui configuration manager
98 if ( xFrame.is() && !xConfigSource.is() )
100 bool bHasSettings( false );
101 Reference< XModel > xModel;
103 Reference< XController > xController = xFrame->getController();
104 if ( xController.is() )
105 xModel = xController->getModel();
107 if ( xModel.is() )
109 Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
110 if ( xUIConfigurationManagerSupplier.is() )
112 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
113 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
117 if ( !bHasSettings )
119 Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager =
120 ModuleManager::create( _rxContext );
121 OUString aModuleIdentifier = xModuleManager->identify( Reference<XInterface>( xFrame, UNO_QUERY ) );
122 if ( !aModuleIdentifier.isEmpty() )
124 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
125 theModuleUIConfigurationManagerSupplier::get( _rxContext );
126 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
127 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
132 PropertyValue aPropValue;
133 Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
134 aPropValue.Name = "Frame";
135 aPropValue.Value <<= xFrame;
136 aPropSeq[0] <<= aPropValue;
137 aPropValue.Name = "ConfigurationSource";
138 aPropValue.Value <<= xCfgMgr;
139 aPropSeq[1] <<= aPropValue;
140 aPropValue.Name = "ResourceURL";
141 aPropValue.Value <<= aResourceURL;
142 aPropSeq[2] <<= aPropValue;
143 aPropValue.Name = "Persistent";
144 aPropValue.Value <<= bPersistent;
145 aPropSeq[3] <<= aPropValue;
146 if ( _pExtraMode )
148 aPropValue.Name = OUString::createFromAscii(_pExtraMode);
149 aPropValue.Value <<= bExtraMode;
150 aPropSeq[4] <<= aPropValue;
153 SolarMutexGuard aGuard;
154 Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
155 xInit->initialize( aPropSeq );
158 } // namespace framework
160 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
161 com_sun_star_comp_framework_MenuBarFactory_get_implementation(
162 css::uno::XComponentContext *context,
163 css::uno::Sequence<css::uno::Any> const &)
165 return cppu::acquire(new framework::MenuBarFactory(context));
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */