1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2008 by Sun Microsystems, Inc.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile:  $
10  * $Revision: $
11  *
12  * This file is part of OpenOffice.org.
13  *
14  * OpenOffice.org is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 3
16  * only, as published by the Free Software Foundation.
17  *
18  * OpenOffice.org is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License version 3 for more details
22  * (a copy is included in the LICENSE file that accompanied this code).
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * version 3 along with OpenOffice.org.  If not, see
26  * <http://www.openoffice.org/license.html>
27  * for a copy of the LGPLv3 License.
28  *
29  ************************************************************************/
30 
31 #ifndef _SVX_THESDLG_IMPL_HXX
32 #define _SVX_THESDLG_IMPL_HXX
33 
34 #include "thesdlg.hxx"
35 
36 #include <svtools/ehdl.hxx>
37 #include <svx/checklbx.hxx>
38 #include <vcl/button.hxx>
39 #include <vcl/combobox.hxx>
40 #include <vcl/edit.hxx>
41 #include <vcl/fixed.hxx>
42 #include <vcl/image.hxx>
43 #include <vcl/lstbox.hxx>
44 #include <vcl/menubtn.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/timer.hxx>
48 #include <vcl/wrkwin.hxx>
49 
50 #include <com/sun/star/linguistic2/XThesaurus.hpp>
51 #include <com/sun/star/linguistic2/XMeaning.hpp>
52 
53 #include <stack>
54 #include <map>
55 #include <algorithm>
56 
57 using namespace ::com::sun::star;
58 using ::rtl::OUString;
59 
60 class SvLBoxEntry;
61 class ThesaurusAlternativesCtrl_Impl;
62 
63 
64 // class LookUpComboBox_Impl --------------------------------------------------
65 
66 class LookUpComboBox_Impl : public ComboBox
67 {
68     Timer                       m_aModifyTimer;
69     Selection                   m_aSelection;
70     Button *                    m_pBtn;
71     SvxThesaurusDialog_Impl &   m_rDialogImpl;
72 
73     // disable copy c-tor and assignment operator
74     LookUpComboBox_Impl( const LookUpComboBox_Impl & );
75     LookUpComboBox_Impl & operator = ( const LookUpComboBox_Impl & );
76 
77 public:
78     LookUpComboBox_Impl( Window *pParent, const ResId &rResId, SvxThesaurusDialog_Impl &rImpl );
79     virtual ~LookUpComboBox_Impl();
80 
81     DECL_LINK( ModifyTimer_Hdl, Timer * );
82 
83     void SetButton( Button *pBtn )  { m_pBtn = pBtn; }
84 
85     // ComboBox
86     virtual void        Modify();
87 };
88 
89 // class ReplaceEdit_Impl --------------------------------------------------
90 
91 class ReplaceEdit_Impl : public Edit
92 {
93     Button *                    m_pBtn;
94 
95     // disable copy c-tor and assignment operator
96     ReplaceEdit_Impl( const ReplaceEdit_Impl & );
97     ReplaceEdit_Impl & operator = ( const ReplaceEdit_Impl & );
98 
99 public:
100     ReplaceEdit_Impl( Window *pParent, const ResId &rResId );
101     virtual ~ReplaceEdit_Impl();
102 
103     void SetButton( Button *pBtn )  { m_pBtn = pBtn; }
104 
105     // Edit
106     virtual void        Modify();
107     virtual void        SetText( const XubString& rStr );
108     virtual void        SetText( const XubString& rStr, const Selection& rNewSelection );
109 };
110 
111 // class ThesaurusAlternativesCtrl_Impl ----------------------------------
112 
113 class AlternativesExtraData
114 {
115 	String	sText;
116 	bool    bHeader;
117 
118 public:
119     AlternativesExtraData() : bHeader( false ) {}
120 	AlternativesExtraData( const String &rText, bool bIsHeader ) :
121 		sText(rText),
122 		bHeader(bIsHeader)
123 		{
124 		}
125 
126     bool  IsHeader() const          { return bHeader; }
127 	const String& GetText() const   { return sText; }
128 };
129 
130 
131 class AlternativesString_Impl : public SvLBoxString
132 {
133     ThesaurusAlternativesCtrl_Impl &    m_rControlImpl;
134 public:
135 
136 	AlternativesString_Impl( ThesaurusAlternativesCtrl_Impl &rControl,
137         SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr );
138 
139 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
140 };
141 
142 
143 class ThesaurusAlternativesCtrl_Impl :
144     public SvxCheckListBox
145 {
146     SvxThesaurusDialog_Impl &   m_rDialogImpl;
147 
148     typedef std::map< const SvLBoxEntry *, AlternativesExtraData >  UserDataMap_t;
149     UserDataMap_t           m_aUserData;
150 
151     // disable copy c-tor and assignment operator
152     ThesaurusAlternativesCtrl_Impl( const ThesaurusAlternativesCtrl_Impl & );
153     ThesaurusAlternativesCtrl_Impl & operator = ( const ThesaurusAlternativesCtrl_Impl & );
154 
155 public:
156     ThesaurusAlternativesCtrl_Impl( Window* pParent, SvxThesaurusDialog_Impl &rImpl );
157     virtual ~ThesaurusAlternativesCtrl_Impl();
158 
159 
160     SvLBoxEntry *   AddEntry( sal_Int32 nVal, const String &rText, bool bIsHeader );
161 
162     void            ClearExtraData();
163     void            SetExtraData( const SvLBoxEntry *pEntry, const AlternativesExtraData &rData );
164     AlternativesExtraData * GetExtraData( const SvLBoxEntry *pEntry );
165 
166     virtual void    KeyInput( const KeyEvent& rKEvt );
167     virtual void    Paint( const Rectangle& rRect );
168 };
169 
170 
171 // struct SvxThesaurusDialog_Impl ----------------------------------------
172 
173 struct SvxThesaurusDialog_Impl
174 {
175     SvxThesaurusDialog *    m_pDialog;
176 
177     FixedImage              aVendorImageFI;
178     ImageButton             aLeftBtn;
179     FixedText               aWordText;
180     LookUpComboBox_Impl     aWordCB;
181     FixedText               m_aAlternativesText;
182     boost::shared_ptr< ThesaurusAlternativesCtrl_Impl > m_pAlternativesCT;
183     FixedText               aReplaceText;
184     ReplaceEdit_Impl        aReplaceEdit;
185     FixedLine               aFL;
186     HelpButton              aHelpBtn;
187     MenuButton              aLangMBtn;
188     OKButton                aReplaceBtn;
189     CancelButton            aCancelBtn;
190 
191 	String			aErrStr;
192     Image           aVendorDefaultImage;
193     Image           aVendorDefaultImageHC;
194 
195     uno::Reference< linguistic2::XThesaurus >	xThesaurus;
196     OUString                aLookUpText;
197     LanguageType            nLookUpLanguage;
198     std::stack< OUString >  aLookUpHistory;
199     bool                    m_bWordFound;
200 
201 
202     // Handler
203     DECL_LINK( LeftBtnHdl_Impl, Button * );
204     DECL_LINK( LanguageHdl_Impl, MenuButton * );
205     DECL_LINK( LookUpHdl_Impl, Button * );
206     DECL_LINK( WordSelectHdl_Impl, ComboBox * );
207     DECL_LINK( AlternativesSelectHdl_Impl, SvxCheckListBox * );
208     DECL_LINK( AlternativesDoubleClickHdl_Impl, SvxCheckListBox * );
209 
210     DECL_STATIC_LINK( SvxThesaurusDialog_Impl, SelectFirstHdl_Impl, SvxCheckListBox * );
211     DECL_STATIC_LINK( SvxThesaurusDialog_Impl, VendorImageInitHdl, SvxThesaurusDialog_Impl * );
212 
213 
214     SvxThesaurusDialog_Impl( SvxThesaurusDialog * pDialog );
215     ~SvxThesaurusDialog_Impl();
216 
217     uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL
218             queryMeanings_Impl( ::rtl::OUString& rTerm, const lang::Locale& rLocale, const beans::PropertyValues& rProperties ) throw(lang::IllegalArgumentException, uno::RuntimeException);
219 
220     bool    UpdateAlternativesBox_Impl();
221     void    UpdateVendorImage();
222     void    LookUp( const String &rText );
223     void    LookUp_Impl();
224 };
225 
226 #endif
227 
228