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 .
20 #include <framework/menuconfiguration.hxx>
22 #include <framework/bmkmenu.hxx>
23 #include <framework/addonmenu.hxx>
24 #include <xml/menudocumenthandler.hxx>
25 #include <xml/saxnamespacefilter.hxx>
28 #include <uielement/rootitemcontainer.hxx>
30 #include <com/sun/star/xml/sax/Parser.hpp>
31 #include <com/sun/star/xml/sax/Writer.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
33 #include <com/sun/star/frame/XFrame.hpp>
34 #include <comphelper/processfactory.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::beans
;
39 using namespace ::com::sun::star::xml::sax
;
40 using namespace ::com::sun::star::container
;
41 using namespace ::com::sun::star::io
;
46 MenuConfiguration::MenuConfiguration(
47 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
)
48 : m_xContext( rxContext
)
52 MenuConfiguration::~MenuConfiguration()
56 Reference
< XIndexAccess
> MenuConfiguration::CreateMenuBarConfigurationFromXML(
57 Reference
< XInputStream
>& rInputStream
)
58 throw (WrappedTargetException
, RuntimeException
)
60 Reference
< XParser
> xParser
= Parser::create( m_xContext
);
62 // connect stream to input stream to the parser
63 InputSource aInputSource
;
65 aInputSource
.aInputStream
= rInputStream
;
68 Reference
< XIndexContainer
> xItemContainer( static_cast< cppu::OWeakObject
*>( new RootItemContainer()), UNO_QUERY
);
70 // create namespace filter and set menudocument handler inside to support xml namespaces
72 Reference
< XDocumentHandler
> xDocHandler( new OReadMenuDocumentHandler( xItemContainer
));
74 Reference
< XDocumentHandler
> xFilter( new SaxNamespaceFilter( xDocHandler
));
76 // connect parser and filter
77 xParser
->setDocumentHandler( xFilter
);
81 xParser
->parseStream( aInputSource
);
82 return xItemContainer
;
84 catch ( const RuntimeException
& e
)
86 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
88 catch( const SAXException
& e
)
90 SAXException aWrappedSAXException
;
92 if ( !( e
.WrappedException
>>= aWrappedSAXException
))
93 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
95 throw WrappedTargetException( aWrappedSAXException
.Message
, Reference
< XInterface
>(), Any() );
97 catch( const ::com::sun::star::io::IOException
& e
)
99 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
103 PopupMenu
* MenuConfiguration::CreateBookmarkMenu(css::uno::Reference
<css::frame::XFrame
>& rFrame
, const OUString
& aURL
)
104 throw (css::lang::WrappedTargetException
,
105 css::uno::RuntimeException
)
107 if ( aURL
== BOOKMARK_NEWMENU
)
108 return new BmkMenu( rFrame
, BmkMenu::BMK_NEWMENU
);
109 else if ( aURL
== BOOKMARK_WIZARDMENU
)
110 return new BmkMenu( rFrame
, BmkMenu::BMK_WIZARDMENU
);
115 void MenuConfiguration::StoreMenuBarConfigurationToXML(
116 Reference
< XIndexAccess
>& rMenuBarConfiguration
,
117 Reference
< XOutputStream
>& rOutputStream
)
118 throw (WrappedTargetException
, RuntimeException
)
120 Reference
< XWriter
> xWriter
= Writer::create(m_xContext
);
121 xWriter
->setOutputStream( rOutputStream
);
125 OWriteMenuDocumentHandler
aWriteMenuDocumentHandler( rMenuBarConfiguration
, xWriter
);
126 aWriteMenuDocumentHandler
.WriteMenuDocument();
128 catch ( const RuntimeException
& e
)
130 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
132 catch ( const SAXException
& e
)
134 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
136 catch ( const ::com::sun::star::io::IOException
& e
)
138 throw WrappedTargetException( e
.Message
, Reference
< XInterface
>(), Any() );
142 sal_uIntPtr
MenuAttributes::CreateAttribute(const OUString
& rFrame
, const OUString
& rImageIdStr
)
144 MenuAttributes
* pAttributes
= new MenuAttributes(rFrame
, rImageIdStr
);
145 pAttributes
->acquire();
146 return reinterpret_cast<sal_uIntPtr
>(pAttributes
);
149 sal_uIntPtr
MenuAttributes::CreateAttribute(const css::uno::WeakReference
<css::frame::XDispatchProvider
>& rDispatchProvider
)
151 MenuAttributes
* pAttributes
= new MenuAttributes(rDispatchProvider
);
152 pAttributes
->acquire();
153 return reinterpret_cast<sal_uIntPtr
>(pAttributes
);
156 void MenuAttributes::ReleaseAttribute(sal_uIntPtr nAttributePtr
)
160 MenuAttributes
* pAttributes
= reinterpret_cast<MenuAttributes
*>(nAttributePtr
);
161 pAttributes
->release();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */