Kaydet (Commit) 0c6305a0 authored tarafından Maxim Monastirsky's avatar Maxim Monastirsky

Support of popupmenu resource type

Reusing the same xml format as the menubar, except that
a popup menu use menu:menupopup as the root element.

Change-Id: I2987af0dc698b09aeeb757cff828617515bc3009
üst 281be263
...@@ -127,7 +127,8 @@ class FWE_DLLPUBLIC OReadMenuDocumentHandler : public ReadMenuDocumentHandlerBas ...@@ -127,7 +127,8 @@ class FWE_DLLPUBLIC OReadMenuDocumentHandler : public ReadMenuDocumentHandlerBas
private: private:
int m_nElementDepth; int m_nElementDepth;
bool m_bMenuBarMode; enum class ReaderMode { None, MenuBar, MenuPopup };
ReaderMode m_eReaderMode;
css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer; css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer;
css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory; css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory;
}; // OReadMenuDocumentHandler }; // OReadMenuDocumentHandler
...@@ -254,7 +255,8 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler ...@@ -254,7 +255,8 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler
public: public:
OWriteMenuDocumentHandler( OWriteMenuDocumentHandler(
const css::uno::Reference< css::container::XIndexAccess >& rMenuBarContainer, const css::uno::Reference< css::container::XIndexAccess >& rMenuBarContainer,
const css::uno::Reference< css::xml::sax::XDocumentHandler >& rDocumentHandler ); const css::uno::Reference< css::xml::sax::XDocumentHandler >& rDocumentHandler,
bool bIsMenuBar );
virtual ~OWriteMenuDocumentHandler(); virtual ~OWriteMenuDocumentHandler();
void WriteMenuDocument() throw void WriteMenuDocument() throw
...@@ -270,6 +272,7 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler ...@@ -270,6 +272,7 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler; css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
css::uno::Reference< css::xml::sax::XAttributeList > m_xEmptyList; css::uno::Reference< css::xml::sax::XAttributeList > m_xEmptyList;
OUString m_aAttributeType; OUString m_aAttributeType;
bool m_bIsMenuBar;
}; };
} // namespace framework } // namespace framework
......
...@@ -114,7 +114,7 @@ PopupMenu* MenuConfiguration::CreateBookmarkMenu(css::uno::Reference<css::frame: ...@@ -114,7 +114,7 @@ PopupMenu* MenuConfiguration::CreateBookmarkMenu(css::uno::Reference<css::frame:
void MenuConfiguration::StoreMenuBarConfigurationToXML( void MenuConfiguration::StoreMenuBarConfigurationToXML(
Reference< XIndexAccess >& rMenuBarConfiguration, Reference< XIndexAccess >& rMenuBarConfiguration,
Reference< XOutputStream >& rOutputStream ) Reference< XOutputStream >& rOutputStream, bool bIsMenuBar )
throw (WrappedTargetException, RuntimeException) throw (WrappedTargetException, RuntimeException)
{ {
Reference< XWriter > xWriter = Writer::create(m_xContext); Reference< XWriter > xWriter = Writer::create(m_xContext);
...@@ -122,7 +122,7 @@ void MenuConfiguration::StoreMenuBarConfigurationToXML( ...@@ -122,7 +122,7 @@ void MenuConfiguration::StoreMenuBarConfigurationToXML(
try try
{ {
OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter ); OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter, bIsMenuBar );
aWriteMenuDocumentHandler.WriteMenuDocument(); aWriteMenuDocumentHandler.WriteMenuDocument();
} }
catch ( const RuntimeException& e ) catch ( const RuntimeException& e )
......
...@@ -217,7 +217,7 @@ void ReadMenuDocumentHandlerBase::initPropertyCommon( ...@@ -217,7 +217,7 @@ void ReadMenuDocumentHandlerBase::initPropertyCommon(
OReadMenuDocumentHandler::OReadMenuDocumentHandler( OReadMenuDocumentHandler::OReadMenuDocumentHandler(
const Reference< XIndexContainer >& rMenuBarContainer ) const Reference< XIndexContainer >& rMenuBarContainer )
: m_nElementDepth( 0 ), : m_nElementDepth( 0 ),
m_bMenuBarMode( false ), m_eReaderMode( ReaderMode::None ),
m_xMenuBarContainer( rMenuBarContainer ), m_xMenuBarContainer( rMenuBarContainer ),
m_xContainerFactory( rMenuBarContainer, UNO_QUERY ) m_xContainerFactory( rMenuBarContainer, UNO_QUERY )
{ {
...@@ -247,17 +247,24 @@ void SAL_CALL OReadMenuDocumentHandler::startElement( ...@@ -247,17 +247,24 @@ void SAL_CALL OReadMenuDocumentHandler::startElement(
const OUString& aName, const Reference< XAttributeList > &xAttrList ) const OUString& aName, const Reference< XAttributeList > &xAttrList )
throw( SAXException, RuntimeException, std::exception ) throw( SAXException, RuntimeException, std::exception )
{ {
if ( m_bMenuBarMode ) if ( m_eReaderMode != ReaderMode::None )
{ {
++m_nElementDepth; ++m_nElementDepth;
m_xReader->startElement( aName, xAttrList ); m_xReader->startElement( aName, xAttrList );
} }
else if ( aName == ELEMENT_MENUBAR ) else
{ {
if ( aName == ELEMENT_MENUBAR )
{
m_eReaderMode = ReaderMode::MenuBar;
m_xReader.set( new OReadMenuBarHandler( m_xMenuBarContainer, m_xContainerFactory ));
}
else if ( aName == ELEMENT_MENUPOPUP )
{
m_eReaderMode = ReaderMode::MenuPopup;
m_xReader.set( new OReadMenuPopupHandler( m_xMenuBarContainer, m_xContainerFactory ));
}
++m_nElementDepth; ++m_nElementDepth;
m_bMenuBarMode = true;
m_xReader.set( new OReadMenuBarHandler( m_xMenuBarContainer, m_xContainerFactory ));
m_xReader->startDocument(); m_xReader->startDocument();
} }
} }
...@@ -270,7 +277,7 @@ throw( SAXException, RuntimeException, std::exception ) ...@@ -270,7 +277,7 @@ throw( SAXException, RuntimeException, std::exception )
void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName ) void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName )
throw( SAXException, RuntimeException, std::exception ) throw( SAXException, RuntimeException, std::exception )
{ {
if ( m_bMenuBarMode ) if ( m_eReaderMode != ReaderMode::None )
{ {
--m_nElementDepth; --m_nElementDepth;
m_xReader->endElement( aName ); m_xReader->endElement( aName );
...@@ -278,13 +285,19 @@ void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName ) ...@@ -278,13 +285,19 @@ void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName )
{ {
m_xReader->endDocument(); m_xReader->endDocument();
m_xReader.clear(); m_xReader.clear();
m_bMenuBarMode = false; if ( m_eReaderMode == ReaderMode::MenuBar && aName != ELEMENT_MENUBAR )
if ( aName != ELEMENT_MENUBAR )
{ {
OUString aErrorMessage = getErrorLineString(); OUString aErrorMessage = getErrorLineString();
aErrorMessage += "closing element menubar expected!"; aErrorMessage += "closing element menubar expected!";
throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
} }
else if ( m_eReaderMode == ReaderMode::MenuPopup && aName != ELEMENT_MENUPOPUP )
{
OUString aErrorMessage = getErrorLineString();
aErrorMessage += "closing element menupopup expected!";
throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
}
m_eReaderMode = ReaderMode::None;
} }
} }
} }
...@@ -728,9 +741,11 @@ void SAL_CALL OReadMenuPopupHandler::endElement( const OUString& aName ) ...@@ -728,9 +741,11 @@ void SAL_CALL OReadMenuPopupHandler::endElement( const OUString& aName )
OWriteMenuDocumentHandler::OWriteMenuDocumentHandler( OWriteMenuDocumentHandler::OWriteMenuDocumentHandler(
const Reference< XIndexAccess >& rMenuBarContainer, const Reference< XIndexAccess >& rMenuBarContainer,
const Reference< XDocumentHandler >& rDocumentHandler ) : const Reference< XDocumentHandler >& rDocumentHandler,
bool bIsMenuBar ) :
m_xMenuBarContainer( rMenuBarContainer ), m_xMenuBarContainer( rMenuBarContainer ),
m_xWriteDocumentHandler( rDocumentHandler ) m_xWriteDocumentHandler( rDocumentHandler ),
m_bIsMenuBar( bIsMenuBar )
{ {
::comphelper::AttributeList* pList = new ::comphelper::AttributeList; ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
m_xEmptyList.set( static_cast<XAttributeList *>(pList), UNO_QUERY ); m_xEmptyList.set( static_cast<XAttributeList *>(pList), UNO_QUERY );
...@@ -751,7 +766,7 @@ throw ( SAXException, RuntimeException ) ...@@ -751,7 +766,7 @@ throw ( SAXException, RuntimeException )
// write DOCTYPE line! // write DOCTYPE line!
Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY ); Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
if ( xExtendedDocHandler.is() ) if ( m_bIsMenuBar /*FIXME*/ && xExtendedDocHandler.is() )
{ {
xExtendedDocHandler->unknown( MENUBAR_DOCTYPE ); xExtendedDocHandler->unknown( MENUBAR_DOCTYPE );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
...@@ -761,17 +776,23 @@ throw ( SAXException, RuntimeException ) ...@@ -761,17 +776,23 @@ throw ( SAXException, RuntimeException )
m_aAttributeType, m_aAttributeType,
OUString( XMLNS_MENU ) ); OUString( XMLNS_MENU ) );
pList->AddAttribute( OUString( ATTRIBUTE_NS_ID ), if ( m_bIsMenuBar ) //FIXME
m_aAttributeType, pList->AddAttribute( OUString( ATTRIBUTE_NS_ID ),
OUString( "menubar" ) ); m_aAttributeType,
OUString( "menubar" ) );
m_xWriteDocumentHandler->startElement( ELEMENT_NS_MENUBAR, pList ); OUString aRootElement;
if ( m_bIsMenuBar )
aRootElement = ELEMENT_NS_MENUBAR;
else
aRootElement = ELEMENT_NS_MENUPOPUP;
m_xWriteDocumentHandler->startElement( aRootElement, pList );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
WriteMenu( m_xMenuBarContainer ); WriteMenu( m_xMenuBarContainer );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
m_xWriteDocumentHandler->endElement( ELEMENT_NS_MENUBAR ); m_xWriteDocumentHandler->endElement( aRootElement );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
m_xWriteDocumentHandler->endDocument(); m_xWriteDocumentHandler->endDocument();
} }
......
...@@ -64,6 +64,7 @@ using namespace framework; ...@@ -64,6 +64,7 @@ using namespace framework;
#define RESOURCETYPE_MENUBAR "menubar" #define RESOURCETYPE_MENUBAR "menubar"
#define RESOURCETYPE_TOOLBAR "toolbar" #define RESOURCETYPE_TOOLBAR "toolbar"
#define RESOURCETYPE_STATUSBAR "statusbar" #define RESOURCETYPE_STATUSBAR "statusbar"
#define RESOURCETYPE_POPUPMENU "popupmenu"
namespace { namespace {
...@@ -429,6 +430,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement ...@@ -429,6 +430,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
break; break;
case css::ui::UIElementType::MENUBAR: case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{ {
try try
{ {
...@@ -447,11 +449,6 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement ...@@ -447,11 +449,6 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
} }
break; break;
case css::ui::UIElementType::POPUPMENU:
{
break;
}
case css::ui::UIElementType::TOOLBAR: case css::ui::UIElementType::TOOLBAR:
{ {
try try
...@@ -570,11 +567,13 @@ void ModuleUIConfigurationManager::impl_storeElementTypeData( Reference< XStorag ...@@ -570,11 +567,13 @@ void ModuleUIConfigurationManager::impl_storeElementTypeData( Reference< XStorag
switch( rElementType.nElementType ) switch( rElementType.nElementType )
{ {
case css::ui::UIElementType::MENUBAR: case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{ {
try try
{ {
MenuConfiguration aMenuCfg( m_xContext ); MenuConfiguration aMenuCfg( m_xContext );
aMenuCfg.StoreMenuBarConfigurationToXML( rElement.xSettings, xOutputStream ); aMenuCfg.StoreMenuBarConfigurationToXML(
rElement.xSettings, xOutputStream, rElementType.nElementType == css::ui::UIElementType::MENUBAR );
} }
catch ( const css::lang::WrappedTargetException& ) catch ( const css::lang::WrappedTargetException& )
{ {
...@@ -891,6 +890,8 @@ ModuleUIConfigurationManager::ModuleUIConfigurationManager( ...@@ -891,6 +890,8 @@ ModuleUIConfigurationManager::ModuleUIConfigurationManager(
aResourceType = RESOURCETYPE_TOOLBAR; aResourceType = RESOURCETYPE_TOOLBAR;
else if ( i == css::ui::UIElementType::STATUSBAR ) else if ( i == css::ui::UIElementType::STATUSBAR )
aResourceType = RESOURCETYPE_STATUSBAR; aResourceType = RESOURCETYPE_STATUSBAR;
else if ( i == css::ui::UIElementType::POPUPMENU )
aResourceType = RESOURCETYPE_POPUPMENU;
if ( !aResourceType.isEmpty() ) if ( !aResourceType.isEmpty() )
{ {
......
...@@ -347,6 +347,7 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType, ...@@ -347,6 +347,7 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType,
break; break;
case css::ui::UIElementType::MENUBAR: case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{ {
try try
{ {
...@@ -365,11 +366,6 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType, ...@@ -365,11 +366,6 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType,
} }
break; break;
case css::ui::UIElementType::POPUPMENU:
{
break;
}
case css::ui::UIElementType::TOOLBAR: case css::ui::UIElementType::TOOLBAR:
{ {
try try
...@@ -479,11 +475,13 @@ void UIConfigurationManager::impl_storeElementTypeData( Reference< XStorage >& x ...@@ -479,11 +475,13 @@ void UIConfigurationManager::impl_storeElementTypeData( Reference< XStorage >& x
switch( rElementType.nElementType ) switch( rElementType.nElementType )
{ {
case css::ui::UIElementType::MENUBAR: case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{ {
try try
{ {
MenuConfiguration aMenuCfg( m_xContext ); MenuConfiguration aMenuCfg( m_xContext );
aMenuCfg.StoreMenuBarConfigurationToXML( rElement.xSettings, xOutputStream ); aMenuCfg.StoreMenuBarConfigurationToXML(
rElement.xSettings, xOutputStream, rElementType.nElementType == css::ui::UIElementType::MENUBAR );
} }
catch ( const css::lang::WrappedTargetException& ) catch ( const css::lang::WrappedTargetException& )
{ {
......
...@@ -118,7 +118,8 @@ public: ...@@ -118,7 +118,8 @@ public:
void StoreMenuBarConfigurationToXML( void StoreMenuBarConfigurationToXML(
css::uno::Reference< css::container::XIndexAccess >& rMenuBarConfiguration, css::uno::Reference< css::container::XIndexAccess >& rMenuBarConfiguration,
css::uno::Reference< css::io::XOutputStream >& rOutputStream ) css::uno::Reference< css::io::XOutputStream >& rOutputStream,
bool bIsMenuBar )
throw (css::lang::WrappedTargetException, css::uno::RuntimeException); throw (css::lang::WrappedTargetException, css::uno::RuntimeException);
private: private:
......
...@@ -418,4 +418,22 @@ $(foreach toolbarfile,$(2),$(call gb_UIConfig_add_toolbarfile,$(1),$(toolbarfile ...@@ -418,4 +418,22 @@ $(foreach toolbarfile,$(2),$(call gb_UIConfig_add_toolbarfile,$(1),$(toolbarfile
endef endef
# Add popupmenu config file to the package.
#
# The file is relative to $(SRCDIR) and without extension.
#
# gb_UIConfig_add_popupmenufile target file
define gb_UIConfig_add_popupmenufile
$(call gb_UIConfig__add_xmlfile,$(1),$(1),popupmenu,$(2))
endef
# Adds multiple popupmenu config files to the package.
#
# gb_UIConfig_add_popupmenufiles target file(s)
define gb_UIConfig_add_popupmenufiles
$(foreach popupmenufile,$(2),$(call gb_UIConfig_add_popupmenufile,$(1),$(popupmenufile)))
endef
# vim: set noet sw=4 ts=4: # vim: set noet sw=4 ts=4:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment