1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_XML_TOOLBOXDOCUMENTHANDLER_HXX_ 25 #define __FRAMEWORK_XML_TOOLBOXDOCUMENTHANDLER_HXX_ 26 27 #include <framework/toolboxconfiguration.hxx> 28 29 //_________________________________________________________________________________________________________________ 30 // interface includes 31 //_________________________________________________________________________________________________________________ 32 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 33 #include <com/sun/star/beans/PropertyValue.hpp> 34 35 //_________________________________________________________________________________________________________________ 36 // other includes 37 //_________________________________________________________________________________________________________________ 38 #include <threadhelp/threadhelpbase.hxx> 39 #include <rtl/ustring.hxx> 40 #include <cppuhelper/implbase1.hxx> 41 #include <stdtypes.h> 42 #include <framework/fwedllapi.h> 43 44 //_________________________________________________________________________________________________________________ 45 // namespace 46 //_________________________________________________________________________________________________________________ 47 48 namespace framework{ 49 50 //***************************************************************************************************************** 51 // Hash code function for using in all hash maps of follow implementation. 52 53 class FWE_DLLPUBLIC OReadToolBoxDocumentHandler : private ThreadHelpBase, // Struct for right initialization of lock member! Must be first of baseclasses. 54 public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler > 55 { 56 public: 57 enum ToolBox_XML_Entry 58 { 59 TB_ELEMENT_TOOLBAR, 60 TB_ELEMENT_TOOLBARITEM, 61 TB_ELEMENT_TOOLBARSPACE, 62 TB_ELEMENT_TOOLBARBREAK, 63 TB_ELEMENT_TOOLBARSEPARATOR, 64 TB_ATTRIBUTE_TEXT, 65 TB_ATTRIBUTE_BITMAP, 66 TB_ATTRIBUTE_URL, 67 TB_ATTRIBUTE_ITEMBITS, 68 TB_ATTRIBUTE_VISIBLE, 69 TB_ATTRIBUTE_WIDTH, 70 TB_ATTRIBUTE_USER, 71 TB_ATTRIBUTE_HELPID, 72 TB_ATTRIBUTE_STYLE, 73 TB_ATTRIBUTE_UINAME, 74 TB_ATTRIBUTE_TOOLTIP, 75 TB_XML_ENTRY_COUNT 76 }; 77 78 enum ToolBox_XML_Namespace 79 { 80 TB_NS_TOOLBAR, 81 TB_NS_XLINK, 82 TB_XML_NAMESPACES_COUNT 83 }; 84 85 OReadToolBoxDocumentHandler( const ::com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer >& rItemContainer ); 86 virtual ~OReadToolBoxDocumentHandler(); 87 88 // XDocumentHandler 89 virtual void SAL_CALL startDocument(void); 90 91 virtual void SAL_CALL endDocument(void); 92 93 virtual void SAL_CALL startElement( 94 const rtl::OUString& aName, 95 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs); 96 97 virtual void SAL_CALL endElement(const rtl::OUString& aName); 98 99 virtual void SAL_CALL characters(const rtl::OUString& aChars); 100 101 virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces); 102 103 virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget, 104 const rtl::OUString& aData); 105 106 virtual void SAL_CALL setDocumentLocator( 107 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator); 108 109 private: 110 ::rtl::OUString getErrorLineString(); 111 112 class ToolBoxHashMap : public ::std::hash_map< ::rtl::OUString , 113 ToolBox_XML_Entry , 114 rtl::OUStringHash, 115 ::std::equal_to< ::rtl::OUString > > 116 { 117 public: free()118 inline void free() 119 { 120 ToolBoxHashMap().swap( *this ); 121 } 122 }; 123 124 sal_Bool m_bToolBarStartFound : 1; 125 sal_Bool m_bToolBarEndFound : 1; 126 sal_Bool m_bToolBarItemStartFound : 1; 127 sal_Bool m_bToolBarSpaceStartFound : 1; 128 sal_Bool m_bToolBarBreakStartFound : 1; 129 sal_Bool m_bToolBarSeparatorStartFound : 1; 130 ToolBoxHashMap m_aToolBoxMap; 131 com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer > m_rItemContainer; 132 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; 133 134 sal_Int32 m_nHashCode_Style_Radio; 135 sal_Int32 m_nHashCode_Style_Auto; 136 sal_Int32 m_nHashCode_Style_Left; 137 sal_Int32 m_nHashCode_Style_AutoSize; 138 sal_Int32 m_nHashCode_Style_DropDown; 139 sal_Int32 m_nHashCode_Style_Repeat; 140 sal_Int32 m_nHashCode_Style_DropDownOnly; 141 sal_Int32 m_nHashCode_Style_Text; 142 sal_Int32 m_nHashCode_Style_Image; 143 rtl::OUString m_aType; 144 rtl::OUString m_aLabel; 145 rtl::OUString m_aStyle; 146 rtl::OUString m_aHelpURL; 147 rtl::OUString m_aTooltip; 148 rtl::OUString m_aIsVisible; 149 rtl::OUString m_aCommandURL; 150 }; 151 152 153 class FWE_DLLPUBLIC OWriteToolBoxDocumentHandler : private ThreadHelpBase // Struct for right initialization of lock member! Must be first of baseclasses. 154 { 155 public: 156 OWriteToolBoxDocumentHandler( 157 const ::com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess >& rItemAccess, 158 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rDocumentHandler ); 159 virtual ~OWriteToolBoxDocumentHandler(); 160 161 void WriteToolBoxDocument(); 162 163 protected: 164 virtual void WriteToolBoxItem( const rtl::OUString& aCommandURL, const rtl::OUString& aLabel, const rtl::OUString& aHelpURL, const rtl::OUString& aTooltip, sal_Int16 nStyle, 165 sal_Int16 nWidth, sal_Bool bVisible ); 166 167 virtual void WriteToolBoxSpace(); 168 169 virtual void WriteToolBoxBreak(); 170 171 virtual void WriteToolBoxSeparator(); 172 173 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler; 174 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList; 175 com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > m_rItemAccess; 176 ::rtl::OUString m_aXMLToolbarNS; 177 ::rtl::OUString m_aXMLXlinkNS; 178 ::rtl::OUString m_aAttributeType; 179 ::rtl::OUString m_aAttributeURL; 180 }; 181 182 } // namespace framework 183 184 #endif 185