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
private:
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::lang::XSingleComponentFactory > m_xContainerFactory;
}; // OReadMenuDocumentHandler
......@@ -254,7 +255,8 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler
public:
OWriteMenuDocumentHandler(
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();
void WriteMenuDocument() throw
......@@ -270,6 +272,7 @@ class FWE_DLLPUBLIC OWriteMenuDocumentHandler
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
css::uno::Reference< css::xml::sax::XAttributeList > m_xEmptyList;
OUString m_aAttributeType;
bool m_bIsMenuBar;
};
} // namespace framework
......
......@@ -114,7 +114,7 @@ PopupMenu* MenuConfiguration::CreateBookmarkMenu(css::uno::Reference<css::frame:
void MenuConfiguration::StoreMenuBarConfigurationToXML(
Reference< XIndexAccess >& rMenuBarConfiguration,
Reference< XOutputStream >& rOutputStream )
Reference< XOutputStream >& rOutputStream, bool bIsMenuBar )
throw (WrappedTargetException, RuntimeException)
{
Reference< XWriter > xWriter = Writer::create(m_xContext);
......@@ -122,7 +122,7 @@ void MenuConfiguration::StoreMenuBarConfigurationToXML(
try
{
OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter );
OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter, bIsMenuBar );
aWriteMenuDocumentHandler.WriteMenuDocument();
}
catch ( const RuntimeException& e )
......
......@@ -217,7 +217,7 @@ void ReadMenuDocumentHandlerBase::initPropertyCommon(
OReadMenuDocumentHandler::OReadMenuDocumentHandler(
const Reference< XIndexContainer >& rMenuBarContainer )
: m_nElementDepth( 0 ),
m_bMenuBarMode( false ),
m_eReaderMode( ReaderMode::None ),
m_xMenuBarContainer( rMenuBarContainer ),
m_xContainerFactory( rMenuBarContainer, UNO_QUERY )
{
......@@ -247,17 +247,24 @@ void SAL_CALL OReadMenuDocumentHandler::startElement(
const OUString& aName, const Reference< XAttributeList > &xAttrList )
throw( SAXException, RuntimeException, std::exception )
{
if ( m_bMenuBarMode )
if ( m_eReaderMode != ReaderMode::None )
{
++m_nElementDepth;
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_bMenuBarMode = true;
m_xReader.set( new OReadMenuBarHandler( m_xMenuBarContainer, m_xContainerFactory ));
m_xReader->startDocument();
}
}
......@@ -270,7 +277,7 @@ throw( SAXException, RuntimeException, std::exception )
void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName )
throw( SAXException, RuntimeException, std::exception )
{
if ( m_bMenuBarMode )
if ( m_eReaderMode != ReaderMode::None )
{
--m_nElementDepth;
m_xReader->endElement( aName );
......@@ -278,13 +285,19 @@ void SAL_CALL OReadMenuDocumentHandler::endElement( const OUString& aName )
{
m_xReader->endDocument();
m_xReader.clear();
m_bMenuBarMode = false;
if ( aName != ELEMENT_MENUBAR )
if ( m_eReaderMode == ReaderMode::MenuBar && aName != ELEMENT_MENUBAR )
{
OUString aErrorMessage = getErrorLineString();
aErrorMessage += "closing element menubar expected!";
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 )
OWriteMenuDocumentHandler::OWriteMenuDocumentHandler(
const Reference< XIndexAccess >& rMenuBarContainer,
const Reference< XDocumentHandler >& rDocumentHandler ) :
const Reference< XDocumentHandler >& rDocumentHandler,
bool bIsMenuBar ) :
m_xMenuBarContainer( rMenuBarContainer ),
m_xWriteDocumentHandler( rDocumentHandler )
m_xWriteDocumentHandler( rDocumentHandler ),
m_bIsMenuBar( bIsMenuBar )
{
::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
m_xEmptyList.set( static_cast<XAttributeList *>(pList), UNO_QUERY );
......@@ -751,7 +766,7 @@ throw ( SAXException, RuntimeException )
// write DOCTYPE line!
Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
if ( xExtendedDocHandler.is() )
if ( m_bIsMenuBar /*FIXME*/ && xExtendedDocHandler.is() )
{
xExtendedDocHandler->unknown( MENUBAR_DOCTYPE );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
......@@ -761,17 +776,23 @@ throw ( SAXException, RuntimeException )
m_aAttributeType,
OUString( XMLNS_MENU ) );
pList->AddAttribute( OUString( ATTRIBUTE_NS_ID ),
m_aAttributeType,
OUString( "menubar" ) );
if ( m_bIsMenuBar ) //FIXME
pList->AddAttribute( OUString( ATTRIBUTE_NS_ID ),
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() );
WriteMenu( m_xMenuBarContainer );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
m_xWriteDocumentHandler->endElement( ELEMENT_NS_MENUBAR );
m_xWriteDocumentHandler->endElement( aRootElement );
m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
m_xWriteDocumentHandler->endDocument();
}
......
......@@ -64,6 +64,7 @@ using namespace framework;
#define RESOURCETYPE_MENUBAR "menubar"
#define RESOURCETYPE_TOOLBAR "toolbar"
#define RESOURCETYPE_STATUSBAR "statusbar"
#define RESOURCETYPE_POPUPMENU "popupmenu"
namespace {
......@@ -429,6 +430,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
break;
case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{
try
{
......@@ -447,11 +449,6 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
}
break;
case css::ui::UIElementType::POPUPMENU:
{
break;
}
case css::ui::UIElementType::TOOLBAR:
{
try
......@@ -570,11 +567,13 @@ void ModuleUIConfigurationManager::impl_storeElementTypeData( Reference< XStorag
switch( rElementType.nElementType )
{
case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{
try
{
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& )
{
......@@ -891,6 +890,8 @@ ModuleUIConfigurationManager::ModuleUIConfigurationManager(
aResourceType = RESOURCETYPE_TOOLBAR;
else if ( i == css::ui::UIElementType::STATUSBAR )
aResourceType = RESOURCETYPE_STATUSBAR;
else if ( i == css::ui::UIElementType::POPUPMENU )
aResourceType = RESOURCETYPE_POPUPMENU;
if ( !aResourceType.isEmpty() )
{
......
......@@ -347,6 +347,7 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType,
break;
case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{
try
{
......@@ -365,11 +366,6 @@ void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType,
}
break;
case css::ui::UIElementType::POPUPMENU:
{
break;
}
case css::ui::UIElementType::TOOLBAR:
{
try
......@@ -479,11 +475,13 @@ void UIConfigurationManager::impl_storeElementTypeData( Reference< XStorage >& x
switch( rElementType.nElementType )
{
case css::ui::UIElementType::MENUBAR:
case css::ui::UIElementType::POPUPMENU:
{
try
{
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& )
{
......
......@@ -118,7 +118,8 @@ public:
void StoreMenuBarConfigurationToXML(
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);
private:
......
......@@ -418,4 +418,22 @@ $(foreach toolbarfile,$(2),$(call gb_UIConfig_add_toolbarfile,$(1),$(toolbarfile
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:
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