1*c4eee24dSAndrew Rist /**************************************************************
2*c4eee24dSAndrew Rist  *
3*c4eee24dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c4eee24dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c4eee24dSAndrew Rist  * distributed with this work for additional information
6*c4eee24dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c4eee24dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c4eee24dSAndrew Rist  * "License"); you may not use this file except in compliance
9*c4eee24dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c4eee24dSAndrew Rist  *
11*c4eee24dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c4eee24dSAndrew Rist  *
13*c4eee24dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c4eee24dSAndrew Rist  * software distributed under the License is distributed on an
15*c4eee24dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c4eee24dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c4eee24dSAndrew Rist  * specific language governing permissions and limitations
18*c4eee24dSAndrew Rist  * under the License.
19*c4eee24dSAndrew Rist  *
20*c4eee24dSAndrew Rist  *************************************************************/
21*c4eee24dSAndrew Rist 
22*c4eee24dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SVX_THESDLG_IMPL_HXX
25cdf0e10cSrcweir #define _SVX_THESDLG_IMPL_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "thesdlg.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svtools/ehdl.hxx>
30cdf0e10cSrcweir #include <svx/checklbx.hxx>
31cdf0e10cSrcweir #include <vcl/button.hxx>
32cdf0e10cSrcweir #include <vcl/combobox.hxx>
33cdf0e10cSrcweir #include <vcl/edit.hxx>
34cdf0e10cSrcweir #include <vcl/fixed.hxx>
35cdf0e10cSrcweir #include <vcl/image.hxx>
36cdf0e10cSrcweir #include <vcl/lstbox.hxx>
37cdf0e10cSrcweir #include <vcl/menubtn.hxx>
38cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39cdf0e10cSrcweir #include <vcl/svapp.hxx>
40cdf0e10cSrcweir #include <vcl/timer.hxx>
41cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <com/sun/star/linguistic2/XThesaurus.hpp>
44cdf0e10cSrcweir #include <com/sun/star/linguistic2/XMeaning.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <stack>
47cdf0e10cSrcweir #include <map>
48cdf0e10cSrcweir #include <algorithm>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using ::rtl::OUString;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir class SvLBoxEntry;
54cdf0e10cSrcweir class ThesaurusAlternativesCtrl_Impl;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // class LookUpComboBox_Impl --------------------------------------------------
58cdf0e10cSrcweir 
59cdf0e10cSrcweir class LookUpComboBox_Impl : public ComboBox
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     Timer                       m_aModifyTimer;
62cdf0e10cSrcweir     Selection                   m_aSelection;
63cdf0e10cSrcweir     Button *                    m_pBtn;
64cdf0e10cSrcweir     SvxThesaurusDialog_Impl &   m_rDialogImpl;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     // disable copy c-tor and assignment operator
67cdf0e10cSrcweir     LookUpComboBox_Impl( const LookUpComboBox_Impl & );
68cdf0e10cSrcweir     LookUpComboBox_Impl & operator = ( const LookUpComboBox_Impl & );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir public:
71cdf0e10cSrcweir     LookUpComboBox_Impl( Window *pParent, const ResId &rResId, SvxThesaurusDialog_Impl &rImpl );
72cdf0e10cSrcweir     virtual ~LookUpComboBox_Impl();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     DECL_LINK( ModifyTimer_Hdl, Timer * );
75cdf0e10cSrcweir 
SetButton(Button * pBtn)76cdf0e10cSrcweir     void SetButton( Button *pBtn )  { m_pBtn = pBtn; }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     // ComboBox
79cdf0e10cSrcweir     virtual void        Modify();
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // class ReplaceEdit_Impl --------------------------------------------------
83cdf0e10cSrcweir 
84cdf0e10cSrcweir class ReplaceEdit_Impl : public Edit
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     Button *                    m_pBtn;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     // disable copy c-tor and assignment operator
89cdf0e10cSrcweir     ReplaceEdit_Impl( const ReplaceEdit_Impl & );
90cdf0e10cSrcweir     ReplaceEdit_Impl & operator = ( const ReplaceEdit_Impl & );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir public:
93cdf0e10cSrcweir     ReplaceEdit_Impl( Window *pParent, const ResId &rResId );
94cdf0e10cSrcweir     virtual ~ReplaceEdit_Impl();
95cdf0e10cSrcweir 
SetButton(Button * pBtn)96cdf0e10cSrcweir     void SetButton( Button *pBtn )  { m_pBtn = pBtn; }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     // Edit
99cdf0e10cSrcweir     virtual void        Modify();
100cdf0e10cSrcweir     virtual void        SetText( const XubString& rStr );
101cdf0e10cSrcweir     virtual void        SetText( const XubString& rStr, const Selection& rNewSelection );
102cdf0e10cSrcweir };
103cdf0e10cSrcweir 
104cdf0e10cSrcweir // class ThesaurusAlternativesCtrl_Impl ----------------------------------
105cdf0e10cSrcweir 
106cdf0e10cSrcweir class AlternativesExtraData
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	String	sText;
109cdf0e10cSrcweir 	bool    bHeader;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir public:
AlternativesExtraData()112cdf0e10cSrcweir     AlternativesExtraData() : bHeader( false ) {}
AlternativesExtraData(const String & rText,bool bIsHeader)113cdf0e10cSrcweir 	AlternativesExtraData( const String &rText, bool bIsHeader ) :
114cdf0e10cSrcweir 		sText(rText),
115cdf0e10cSrcweir 		bHeader(bIsHeader)
116cdf0e10cSrcweir 		{
117cdf0e10cSrcweir 		}
118cdf0e10cSrcweir 
IsHeader() const119cdf0e10cSrcweir     bool  IsHeader() const          { return bHeader; }
GetText() const120cdf0e10cSrcweir 	const String& GetText() const   { return sText; }
121cdf0e10cSrcweir };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir class AlternativesString_Impl : public SvLBoxString
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     ThesaurusAlternativesCtrl_Impl &    m_rControlImpl;
127cdf0e10cSrcweir public:
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	AlternativesString_Impl( ThesaurusAlternativesCtrl_Impl &rControl,
130cdf0e10cSrcweir         SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
133cdf0e10cSrcweir };
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir class ThesaurusAlternativesCtrl_Impl :
137cdf0e10cSrcweir     public SvxCheckListBox
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     SvxThesaurusDialog_Impl &   m_rDialogImpl;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     typedef std::map< const SvLBoxEntry *, AlternativesExtraData >  UserDataMap_t;
142cdf0e10cSrcweir     UserDataMap_t           m_aUserData;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     // disable copy c-tor and assignment operator
145cdf0e10cSrcweir     ThesaurusAlternativesCtrl_Impl( const ThesaurusAlternativesCtrl_Impl & );
146cdf0e10cSrcweir     ThesaurusAlternativesCtrl_Impl & operator = ( const ThesaurusAlternativesCtrl_Impl & );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir public:
149cdf0e10cSrcweir     ThesaurusAlternativesCtrl_Impl( Window* pParent, SvxThesaurusDialog_Impl &rImpl );
150cdf0e10cSrcweir     virtual ~ThesaurusAlternativesCtrl_Impl();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     SvLBoxEntry *   AddEntry( sal_Int32 nVal, const String &rText, bool bIsHeader );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     void            ClearExtraData();
156cdf0e10cSrcweir     void            SetExtraData( const SvLBoxEntry *pEntry, const AlternativesExtraData &rData );
157cdf0e10cSrcweir     AlternativesExtraData * GetExtraData( const SvLBoxEntry *pEntry );
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     virtual void    KeyInput( const KeyEvent& rKEvt );
160cdf0e10cSrcweir     virtual void    Paint( const Rectangle& rRect );
161cdf0e10cSrcweir };
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // struct SvxThesaurusDialog_Impl ----------------------------------------
165cdf0e10cSrcweir 
166cdf0e10cSrcweir struct SvxThesaurusDialog_Impl
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     SvxThesaurusDialog *    m_pDialog;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     FixedImage              aVendorImageFI;
171cdf0e10cSrcweir     ImageButton             aLeftBtn;
172cdf0e10cSrcweir     FixedText               aWordText;
173cdf0e10cSrcweir     LookUpComboBox_Impl     aWordCB;
174cdf0e10cSrcweir     FixedText               m_aAlternativesText;
175cdf0e10cSrcweir     boost::shared_ptr< ThesaurusAlternativesCtrl_Impl > m_pAlternativesCT;
176cdf0e10cSrcweir     FixedText               aReplaceText;
177cdf0e10cSrcweir     ReplaceEdit_Impl        aReplaceEdit;
178cdf0e10cSrcweir     FixedLine               aFL;
179cdf0e10cSrcweir     HelpButton              aHelpBtn;
180cdf0e10cSrcweir     MenuButton              aLangMBtn;
181cdf0e10cSrcweir     OKButton                aReplaceBtn;
182cdf0e10cSrcweir     CancelButton            aCancelBtn;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	String			aErrStr;
185cdf0e10cSrcweir     Image           aVendorDefaultImage;
186cdf0e10cSrcweir     Image           aVendorDefaultImageHC;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     uno::Reference< linguistic2::XThesaurus >	xThesaurus;
189cdf0e10cSrcweir     OUString                aLookUpText;
190cdf0e10cSrcweir     LanguageType            nLookUpLanguage;
191cdf0e10cSrcweir     std::stack< OUString >  aLookUpHistory;
192cdf0e10cSrcweir     bool                    m_bWordFound;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     // Handler
196cdf0e10cSrcweir     DECL_LINK( LeftBtnHdl_Impl, Button * );
197cdf0e10cSrcweir     DECL_LINK( LanguageHdl_Impl, MenuButton * );
198cdf0e10cSrcweir     DECL_LINK( LookUpHdl_Impl, Button * );
199cdf0e10cSrcweir     DECL_LINK( WordSelectHdl_Impl, ComboBox * );
200cdf0e10cSrcweir     DECL_LINK( AlternativesSelectHdl_Impl, SvxCheckListBox * );
201cdf0e10cSrcweir     DECL_LINK( AlternativesDoubleClickHdl_Impl, SvxCheckListBox * );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     DECL_STATIC_LINK( SvxThesaurusDialog_Impl, SelectFirstHdl_Impl, SvxCheckListBox * );
204cdf0e10cSrcweir     DECL_STATIC_LINK( SvxThesaurusDialog_Impl, VendorImageInitHdl, SvxThesaurusDialog_Impl * );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     SvxThesaurusDialog_Impl( SvxThesaurusDialog * pDialog );
208cdf0e10cSrcweir     ~SvxThesaurusDialog_Impl();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
211cdf0e10cSrcweir             queryMeanings_Impl( ::rtl::OUString& rTerm, const lang::Locale& rLocale, const beans::PropertyValues& rProperties ) throw(lang::IllegalArgumentException, uno::RuntimeException);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     bool    UpdateAlternativesBox_Impl();
214cdf0e10cSrcweir     void    UpdateVendorImage();
215cdf0e10cSrcweir     void    LookUp( const String &rText );
216cdf0e10cSrcweir     void    LookUp_Impl();
217cdf0e10cSrcweir };
218cdf0e10cSrcweir 
219cdf0e10cSrcweir #endif
220cdf0e10cSrcweir 
221