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 _TEXTCONVERSIONDLGS_CHINESE_DICTIONARYDLG_HXX 25 #define _TEXTCONVERSIONDLGS_CHINESE_DICTIONARYDLG_HXX 26 27 #include <vcl/dialog.hxx> 28 // header for class FixedLine 29 #include <vcl/fixed.hxx> 30 // header for class RadioButton 31 #ifndef _SV_BUTTON_HXX 32 #include <vcl/button.hxx> 33 #endif 34 // header for class Edit 35 #include <vcl/edit.hxx> 36 // header for class ListBox 37 #include <vcl/lstbox.hxx> 38 // header for class SvHeaderTabListBox 39 #include <svtools/svtabbx.hxx> 40 #include <com/sun/star/uno/XComponentContext.hpp> 41 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 42 #include <com/sun/star/linguistic2/XConversionDictionary.hpp> 43 44 #include <vector> 45 46 //............................................................................. 47 namespace textconversiondlgs 48 { 49 //............................................................................. 50 51 //----------------------------------------------------------------------------- 52 /** 53 */ 54 55 struct DictionaryEntry 56 { 57 DictionaryEntry( const rtl::OUString& rTerm, const rtl::OUString& rMapping 58 , sal_Int16 nConversionPropertyType //linguistic2::ConversionPropertyType 59 , sal_Bool bNewEntry = sal_False ); 60 61 virtual ~DictionaryEntry(); 62 63 bool operator==( const DictionaryEntry& rE ) const; 64 65 rtl::OUString m_aTerm; 66 rtl::OUString m_aMapping; 67 sal_Int16 m_nConversionPropertyType; //linguistic2::ConversionPropertyType 68 69 sal_Bool m_bNewEntry; 70 }; 71 72 class DictionaryList : public SvHeaderTabListBox 73 { 74 public: 75 DictionaryList( Window* pParent, const ResId& ); 76 DictionaryList( Window* pParent ); 77 virtual ~DictionaryList(); 78 79 HeaderBar* createHeaderBar( const String& rColumn1, const String& rColumn2, const String& rColumn3 80 , long nWidth1, long nWidth2, long nWidth3 ); 81 82 void initDictionaryControl( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionary>& xDictionary 83 , ListBox* pPropertyTypeNameListBox ); 84 void activate( HeaderBar* pHeaderBar ); 85 void deleteAll(); 86 void refillFromDictionary( sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ ); 87 void save(); 88 89 DictionaryEntry* getTermEntry( const rtl::OUString& rTerm ) const; 90 bool hasTerm( const rtl::OUString& rTerm ) const; 91 92 void addEntry( const rtl::OUString& rTerm, const rtl::OUString& rMapping 93 , sal_Int16 nConversionPropertyType /*linguistic2::ConversionPropertyType*/, sal_uIntPtr nPos = LIST_APPEND ); 94 sal_uIntPtr deleteEntries( const rtl::OUString& rTerm ); //return lowest position of deleted entries or LIST_APPEND if no entry was deleted 95 void deleteEntryOnPos( sal_Int32 nPos ); 96 DictionaryEntry* getEntryOnPos( sal_Int32 nPos ) const; 97 DictionaryEntry* getFirstSelectedEntry() const; 98 99 void sortByColumn( sal_uInt16 nSortColumnIndex, bool bSortAtoZ ); 100 sal_uInt16 getSortColumn() const; 101 102 virtual void Resize(); 103 104 private: 105 String getPropertyTypeName( sal_Int16 nConversionPropertyType /*linguistic2::ConversionPropertyType*/ ) const; 106 String makeTabString( const DictionaryEntry& rEntry ) const; 107 108 DECL_LINK( CompareHdl, SvSortData* ); 109 StringCompare ColumnCompare( SvLBoxEntry* pLeft, SvLBoxEntry* pRight ); 110 SvLBoxItem* getItemAtColumn( SvLBoxEntry* pEntry, sal_uInt16 nColumn ) const; 111 112 public: 113 ::com::sun::star::uno::Reference< 114 ::com::sun::star::linguistic2::XConversionDictionary> m_xDictionary; 115 116 private: 117 HeaderBar* m_pHeaderBar; 118 ListBox* m_pPropertyTypeNameListBox; 119 120 std::vector< DictionaryEntry* > m_aToBeDeleted; 121 122 sal_uInt16 m_nSortColumnIndex; 123 }; 124 125 class ChineseDictionaryDialog : public ModalDialog 126 { 127 public: 128 ChineseDictionaryDialog( Window* pParent ); 129 virtual ~ChineseDictionaryDialog(); 130 131 //this method should be called once before calling execute 132 void setDirectionAndTextConversionOptions( bool bDirectionToSimplified, sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ ); 133 134 virtual short Execute(); 135 136 private: 137 DECL_LINK( DirectionHdl, void* ); 138 DECL_LINK( EditFieldsHdl, Control* ); 139 DECL_LINK( MappingSelectHdl, void* ); 140 DECL_LINK( AddHdl, void* ); 141 DECL_LINK( ModifyHdl, void* ); 142 DECL_LINK( DeleteHdl, void* ); 143 DECL_LINK( HeaderBarClick, void* ); 144 145 void updateAfterDirectionChange(); 146 void updateButtons(); 147 148 bool isEditFieldsHaveContent() const; 149 bool isEditFieldsContentEqualsSelectedListContent() const; 150 151 DictionaryList& getActiveDictionary(); 152 DictionaryList& getReverseDictionary(); 153 154 const DictionaryList& getActiveDictionary() const; 155 const DictionaryList& getReverseDictionary() const; 156 157 private: 158 sal_Int32 m_nTextConversionOptions; //i18n::TextConversionOption 159 160 RadioButton m_aRB_To_Simplified; 161 RadioButton m_aRB_To_Traditional; 162 163 CheckBox m_aCB_Reverse; 164 165 FixedText m_aFT_Term; 166 Edit m_aED_Term; 167 168 FixedText m_aFT_Mapping; 169 Edit m_aED_Mapping; 170 171 FixedText m_aFT_Property; 172 ListBox m_aLB_Property; 173 174 HeaderBar* m_pHeaderBar; 175 DictionaryList m_aCT_DictionaryToSimplified; 176 DictionaryList m_aCT_DictionaryToTraditional; 177 178 PushButton m_aPB_Add; 179 PushButton m_aPB_Modify; 180 PushButton m_aPB_Delete; 181 182 FixedLine m_aFL_Bottomline; 183 184 OKButton m_aBP_OK; 185 CancelButton m_aBP_Cancel; 186 HelpButton m_aBP_Help; 187 188 ::com::sun::star::uno::Reference< 189 ::com::sun::star::uno::XComponentContext > m_xContext; 190 ::com::sun::star::uno::Reference< 191 ::com::sun::star::lang::XMultiComponentFactory> m_xFactory; 192 }; 193 194 //............................................................................. 195 } //end namespace 196 //............................................................................. 197 #endif 198