Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "hyphen.hxx"
30 : : #include "hyphen.hrc"
31 : : #include "cuires.hrc"
32 : : #include "dialmgr.hxx"
33 : :
34 : : #include <editeng/splwrap.hxx>
35 : : #include <editeng/svxenum.hxx>
36 : : #include <editeng/unolingu.hxx>
37 : : #include <svtools/langtab.hxx>
38 : : #include <svx/dialmgr.hxx>
39 : : #include <svx/dlgutil.hxx>
40 : : #include <tools/shl.hxx>
41 : : #include <vcl/msgbox.hxx>
42 : :
43 : : #include <com/sun/star/linguistic2/XPossibleHyphens.hpp>
44 : :
45 : : using namespace ::com::sun::star;
46 : :
47 : :
48 : : #define HYPH_POS_CHAR '='
49 : : #define CONTINUE_HYPH USHRT_MAX
50 : :
51 : : #define CUR_HYPH_POS_CHAR '-'
52 : :
53 : :
54 : : // class HyphenEdit_Impl -------------------------------------------------------
55 : :
56 [ # # ]: 0 : class HyphenEdit_Impl : public Edit
57 : : {
58 : : public:
59 : : HyphenEdit_Impl( Window* pParent, const ResId& rResId );
60 : :
61 : : protected:
62 : : virtual void KeyInput( const KeyEvent &rKEvt );
63 : : };
64 : :
65 : :
66 : 0 : HyphenEdit_Impl::HyphenEdit_Impl( Window* pParent, const ResId& rResId ) :
67 : 0 : Edit( pParent, rResId )
68 : : {
69 : 0 : }
70 : :
71 : :
72 : 0 : void HyphenEdit_Impl::KeyInput( const KeyEvent& rKEvt )
73 : : {
74 : 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
75 : :
76 [ # # # # ]: 0 : switch ( nCode )
77 : : {
78 : : case KEY_LEFT:
79 : 0 : ( (SvxHyphenWordDialog*)GetParent() )->SelLeft();
80 : 0 : break;
81 : :
82 : : case KEY_RIGHT:
83 : 0 : ( (SvxHyphenWordDialog*)GetParent() )->SelRight();
84 : 0 : break;
85 : :
86 : : case KEY_TAB:
87 : : case KEY_ESCAPE:
88 : : case KEY_RETURN:
89 : 0 : Edit::KeyInput(rKEvt);
90 : 0 : break;
91 : : default:
92 : 0 : Control::KeyInput( rKEvt ); // pass on to the dialog
93 : 0 : break;
94 : : }
95 : 0 : }
96 : :
97 : :
98 : : // struct SvxHyphenWordDialog_Impl ---------------------------------------------
99 : :
100 : : struct SvxHyphenWordDialog_Impl
101 : : {
102 : : SvxHyphenWordDialog * m_pDialog;
103 : :
104 : : FixedText aWordFT;
105 : : HyphenEdit_Impl aWordEdit;
106 : : ImageButton aLeftBtn;
107 : : ImageButton aRightBtn;
108 : : OKButton aOkBtn;
109 : : PushButton aContBtn;
110 : : PushButton aDelBtn;
111 : : FixedLine aFLBottom;
112 : : HelpButton aHelpBtn;
113 : : PushButton aHyphAll;
114 : : CancelButton aCancelBtn;
115 : : String aLabel;
116 : : SvxSpellWrapper* pHyphWrapper;
117 : : uno::Reference< linguistic2::XHyphenator > xHyphenator;
118 : : uno::Reference< linguistic2::XPossibleHyphens > xPossHyph;
119 : : String aEditWord; // aEditWord and aWordEdit.GetText() differ only by the character for the current selected hyphenation position
120 : : String aActWord; // actual word to be hyphenated
121 : : LanguageType nActLanguage; // and its language
122 : : sal_uInt16 nMaxHyphenationPos; // right most valid hyphenation pos
123 : : sal_uInt16 nHyphPos;
124 : : sal_uInt16 nOldPos;
125 : : sal_Int32 nHyphenationPositionsOffset;
126 : : sal_Bool bBusy;
127 : :
128 : :
129 : : void EnableLRBtn_Impl();
130 : : String EraseUnusableHyphens_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XPossibleHyphens > &rxPossHyph, sal_uInt16 nMaxHyphenationPos );
131 : :
132 : : void InitControls_Impl();
133 : : void ContinueHyph_Impl( sal_uInt16 nInsPos = 0 );
134 : : sal_uInt16 GetHyphIndex_Impl();
135 : : void SelLeft_Impl();
136 : : void SelRight_Impl();
137 : :
138 : : DECL_LINK(Left_Impl, void *);
139 : : DECL_LINK(Right_Impl, void *);
140 : : DECL_LINK(CutHdl_Impl, void *);
141 : : DECL_LINK(ContinueHdl_Impl, void *);
142 : : DECL_LINK(DeleteHdl_Impl, void *);
143 : : DECL_LINK( HyphenateAllHdl_Impl, Button* );
144 : : DECL_LINK(CancelHdl_Impl, void *);
145 : : DECL_LINK(GetFocusHdl_Impl, void *);
146 : :
147 : :
148 : : SvxHyphenWordDialog_Impl(
149 : : SvxHyphenWordDialog * pDialog,
150 : : const String &rWord,
151 : : LanguageType nLang,
152 : : uno::Reference< linguistic2::XHyphenator > &xHyphen,
153 : : SvxSpellWrapper* pWrapper );
154 : : ~SvxHyphenWordDialog_Impl();
155 : : };
156 : :
157 : :
158 : 0 : SvxHyphenWordDialog_Impl::SvxHyphenWordDialog_Impl(
159 : : SvxHyphenWordDialog * pDialog,
160 : : const String &rWord,
161 : : LanguageType nLang,
162 : : uno::Reference< linguistic2::XHyphenator > &xHyphen,
163 : : SvxSpellWrapper* pWrapper ) :
164 : :
165 : : m_pDialog ( pDialog ),
166 : 0 : aWordFT ( pDialog, CUI_RES( FT_WORD ) ),
167 [ # # ]: 0 : aWordEdit ( pDialog, CUI_RES( ED_WORD ) ),
168 [ # # ]: 0 : aLeftBtn ( pDialog, CUI_RES( BTN_LEFT ) ),
169 [ # # ]: 0 : aRightBtn ( pDialog, CUI_RES( BTN_RIGHT ) ),
170 [ # # ]: 0 : aOkBtn ( pDialog, CUI_RES( BTN_HYPH_CUT ) ),
171 [ # # ]: 0 : aContBtn ( pDialog, CUI_RES( BTN_HYPH_CONTINUE ) ),
172 [ # # ]: 0 : aDelBtn ( pDialog, CUI_RES( BTN_HYPH_DELETE ) ),
173 [ # # ]: 0 : aFLBottom ( pDialog, CUI_RES( FL_BOTTOM ) ),
174 [ # # ]: 0 : aHelpBtn ( pDialog, CUI_RES( BTN_HYPH_HELP ) ),
175 [ # # ]: 0 : aHyphAll ( pDialog, CUI_RES( BTN_HYPH_ALL ) ),
176 [ # # ]: 0 : aCancelBtn ( pDialog, CUI_RES( BTN_HYPH_CANCEL ) ),
177 : 0 : aLabel ( pDialog->GetText() ),
178 : : pHyphWrapper ( NULL ),
179 : : xHyphenator ( NULL ),
180 : : xPossHyph ( NULL ),
181 : : aActWord ( ),
182 : : nActLanguage ( LANGUAGE_NONE ),
183 : : nMaxHyphenationPos ( 0 ),
184 : : nHyphPos ( 0 ),
185 : : nOldPos ( 0 ),
186 : : nHyphenationPositionsOffset( 0 ),
187 [ # # ][ # # ]: 0 : bBusy ( sal_False )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
188 : : {
189 [ # # ]: 0 : aActWord = rWord;
190 : 0 : nActLanguage = nLang;
191 [ # # ]: 0 : xHyphenator = xHyphen;
192 : 0 : pHyphWrapper = pWrapper;
193 : :
194 : : uno::Reference< linguistic2::XHyphenatedWord > xHyphWord( pHyphWrapper ?
195 [ # # ][ # # ]: 0 : pHyphWrapper->GetLast() : NULL, uno::UNO_QUERY );
[ # # ][ # # ]
196 : : DBG_ASSERT( xHyphWord.is(), "hyphenation result missing" );
197 [ # # ]: 0 : if (xHyphWord.is())
198 : : {
199 : : DBG_ASSERT( aActWord == String( xHyphWord->getWord() ), "word mismatch" );
200 : : DBG_ASSERT( nActLanguage == SvxLocaleToLanguage( xHyphWord->getLocale() ), "language mismatch" );
201 [ # # ][ # # ]: 0 : nMaxHyphenationPos = xHyphWord->getHyphenationPos();
202 : : }
203 : :
204 [ # # ]: 0 : InitControls_Impl();
205 [ # # ]: 0 : aWordEdit.GrabFocus();
206 : :
207 [ # # ]: 0 : aLeftBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, Left_Impl ) );
208 [ # # ]: 0 : aRightBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, Right_Impl ) );
209 [ # # ]: 0 : aOkBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, CutHdl_Impl ) );
210 [ # # ]: 0 : aContBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, ContinueHdl_Impl ) );
211 [ # # ]: 0 : aDelBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, DeleteHdl_Impl ) );
212 [ # # ]: 0 : aHyphAll.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, HyphenateAllHdl_Impl ) );
213 [ # # ]: 0 : aCancelBtn.SetClickHdl( LINK( this, SvxHyphenWordDialog_Impl, CancelHdl_Impl ) );
214 [ # # ]: 0 : aWordEdit.SetGetFocusHdl( LINK( this, SvxHyphenWordDialog_Impl, GetFocusHdl_Impl ) );
215 : 0 : }
216 : :
217 : :
218 [ # # ][ # # ]: 0 : SvxHyphenWordDialog_Impl::~SvxHyphenWordDialog_Impl()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
219 : : {
220 : 0 : }
221 : :
222 : :
223 : 0 : void SvxHyphenWordDialog_Impl::EnableLRBtn_Impl()
224 : : {
225 [ # # ]: 0 : String aTxt( aEditWord );
226 : 0 : xub_StrLen nLen = aTxt.Len();
227 : : xub_StrLen i;
228 : :
229 [ # # ]: 0 : aRightBtn.Disable();
230 [ # # ]: 0 : for ( i = nOldPos + 2; i < nLen; ++i )
231 : : {
232 [ # # ]: 0 : if ( aTxt.GetChar( i ) == sal_Unicode( HYPH_POS_CHAR ) )
233 : : {
234 [ # # ]: 0 : aRightBtn.Enable();
235 : 0 : break;
236 : : }
237 : : }
238 : :
239 : : DBG_ASSERT(nOldPos < aTxt.Len(), "nOldPos out of range");
240 [ # # ]: 0 : if (nOldPos >= aTxt.Len())
241 : 0 : nOldPos = aTxt.Len() - 1;
242 [ # # ]: 0 : aLeftBtn.Disable();
243 [ # # ]: 0 : for ( i = nOldPos; i-- > 0; )
244 : : {
245 [ # # ]: 0 : if ( aTxt.GetChar( i ) == sal_Unicode( HYPH_POS_CHAR ) )
246 : : {
247 [ # # ]: 0 : aLeftBtn.Enable();
248 : 0 : break;
249 : : }
250 [ # # ]: 0 : }
251 : 0 : }
252 : :
253 : :
254 : 0 : String SvxHyphenWordDialog_Impl::EraseUnusableHyphens_Impl(
255 : : uno::Reference< linguistic2::XPossibleHyphens > &rxPossHyph,
256 : : sal_uInt16 _nMaxHyphenationPos )
257 : : {
258 : : // returns a String showing only those hyphen positions which will result
259 : : // in a line break if hyphenation is done there
260 : : // 1) we will need to discard all hyphenation positions at th end that
261 : : // will not result in a line break where the text to the left still fits
262 : : // on the line.
263 : : // 2) since as from OOo 3.2 '-' are part of a word an thus text like
264 : : // 'multi-line-editor' is regarded as single word we also need to discard those
265 : : // hyphenation positions to the left of the rightmost '-' that is still left of
266 : : // the rightmost valid hyphenation position according to 1)
267 : : //
268 : : // Example:
269 : : // If the possible hyphenation position in 'multi-line-editor' are to eb marked
270 : : // by '=' then the text will look like this 'mul=ti-line-ed=it=or'.
271 : : // If now the first line is only large enough for 'multi-line-edi' we need to discard
272 : : // the last possible hyphnation point because of 1). The the right most valid
273 : : // hyphenation position is "ed=itor". The first '-' left of this position is
274 : : // "line-ed", thus because of 2) we now need to discard all possible hyphneation
275 : : // positions to the left of that as well. Thus in the end leaving us with just
276 : : // 'multi-line-ed=itor' as return value for this function. (Just one valid hyphenation
277 : : // position for the user too choose from. However ALL the '-' characters in the word
278 : : // will ALWAYS be valid implicit hyphenation positions for the core to choose from!
279 : : // And thus even if this word is skipped in the hyphenation dialog it will still be broken
280 : : // right after 'multi-line-' (actually it might already be broken up that way before
281 : : // the hyphenation dialog is called!).
282 : : // Thus rule 2) just eliminates those positions which will not be used by the core at all
283 : : // even if the user were to select one of them.
284 : :
285 : 0 : String aTxt;
286 : : DBG_ASSERT(rxPossHyph.is(), "missing possible hyphens");
287 [ # # ]: 0 : if (rxPossHyph.is())
288 : : {
289 : : DBG_ASSERT( aActWord == String( rxPossHyph->getWord() ), "word mismatch" );
290 : :
291 [ # # ][ # # ]: 0 : aTxt = String( rxPossHyph->getPossibleHyphens() );
[ # # ][ # # ]
[ # # ]
292 : :
293 : 0 : nHyphenationPositionsOffset = 0;
294 : : uno::Sequence< sal_Int16 > aHyphenationPositions(
295 [ # # ][ # # ]: 0 : rxPossHyph->getHyphenationPositions() );
296 : 0 : sal_Int32 nLen = aHyphenationPositions.getLength();
297 : 0 : const sal_Int16 *pHyphenationPos = aHyphenationPositions.getConstArray();
298 : :
299 : : // find position nIdx after which all hyphen positions are unusable
300 : 0 : xub_StrLen nIdx = STRING_NOTFOUND;
301 : 0 : xub_StrLen nPos = 0, nPos1 = 0, nPos2 = 0;
302 [ # # ]: 0 : if (nLen)
303 : : {
304 : 0 : xub_StrLen nStart = 0;
305 [ # # ]: 0 : for (sal_Int32 i = 0; i < nLen; ++i)
306 : : {
307 [ # # ]: 0 : if (pHyphenationPos[i] > _nMaxHyphenationPos)
308 : 0 : break;
309 : : else
310 : : {
311 : : // find corresponding hyphen pos in string
312 [ # # ]: 0 : nPos = aTxt.Search( sal_Unicode( HYPH_POS_CHAR ), nStart );
313 : :
314 [ # # ]: 0 : if (nStart == STRING_NOTFOUND)
315 : 0 : break;
316 : : else
317 : : {
318 : 0 : nIdx = nPos;
319 : 0 : nStart = nPos + 1;
320 : : }
321 : : }
322 : : }
323 : : }
324 : : DBG_ASSERT(nIdx != STRING_NOTFOUND, "no usable hyphenation position");
325 : :
326 : : // 1) remove all not usable hyphenation positions from the end of the string
327 [ # # ]: 0 : nPos = nIdx == STRING_NOTFOUND ? 0 : nIdx + 1;
328 : 0 : nPos1 = nPos; //save for later use in 2) below
329 : 0 : const rtl::OUString aTmp( sal_Unicode( HYPH_POS_CHAR ) );
330 : 0 : const rtl::OUString aEmpty;
331 [ # # ]: 0 : while (nPos != STRING_NOTFOUND)
332 [ # # ][ # # ]: 0 : nPos = aTxt.SearchAndReplace( aTmp, aEmpty, nPos + 1 );
[ # # ][ # # ]
[ # # ]
333 : :
334 : : // 2) remove all hyphenation positions from the start that are not considered by the core
335 [ # # ]: 0 : const String aSearchRange( aTxt.Copy( 0, nPos1 ) );
336 [ # # ]: 0 : nPos2 = aSearchRange.SearchBackward( '-' ); // the '-' position the core will use by default
337 [ # # ]: 0 : if (nPos2 != STRING_NOTFOUND)
338 : : {
339 [ # # ]: 0 : String aLeft( aSearchRange.Copy( 0, nPos2 ) );
340 : 0 : nPos = 0;
341 [ # # ]: 0 : while (nPos != STRING_NOTFOUND)
342 : : {
343 [ # # ][ # # ]: 0 : nPos = aLeft.SearchAndReplace( aTmp, aEmpty, nPos + 1 );
[ # # ][ # # ]
[ # # ]
344 [ # # ]: 0 : if (nPos != STRING_NOTFOUND)
345 : 0 : ++nHyphenationPositionsOffset;
346 : : }
347 [ # # ][ # # ]: 0 : aTxt.Replace( 0, nPos2, aLeft );
348 [ # # ][ # # ]: 0 : }
349 : : }
350 : 0 : return aTxt;
351 : : }
352 : :
353 : :
354 : 0 : void SvxHyphenWordDialog_Impl::InitControls_Impl()
355 : : {
356 : 0 : xPossHyph = NULL;
357 [ # # ]: 0 : if (xHyphenator.is())
358 : : {
359 [ # # ]: 0 : lang::Locale aLocale( SvxCreateLocale(nActLanguage) );
360 [ # # ]: 0 : xPossHyph = xHyphenator->createPossibleHyphens( aActWord, aLocale,
361 [ # # ][ # # ]: 0 : uno::Sequence< beans::PropertyValue >() );
[ # # ][ # # ]
[ # # ]
362 [ # # ]: 0 : if (xPossHyph.is())
363 [ # # ][ # # ]: 0 : aEditWord = EraseUnusableHyphens_Impl( xPossHyph, nMaxHyphenationPos );
[ # # ]
364 : : }
365 : 0 : aWordEdit.SetText( aEditWord );
366 : :
367 : 0 : nOldPos = aEditWord.Len();
368 : 0 : SelLeft_Impl();
369 : 0 : EnableLRBtn_Impl();
370 : 0 : }
371 : :
372 : :
373 : 0 : void SvxHyphenWordDialog_Impl::ContinueHyph_Impl( sal_uInt16 nInsPos )
374 : : {
375 [ # # ][ # # ]: 0 : if ( nInsPos != CONTINUE_HYPH && xPossHyph.is())
[ # # ]
376 : : {
377 [ # # ]: 0 : if (nInsPos)
378 : : {
379 [ # # ]: 0 : String aTmp( aEditWord );
380 : : DBG_ASSERT(nInsPos <= aTmp.Len() - 2, "wrong hyphen position");
381 : :
382 : 0 : sal_Int16 nIdxPos = -1;
383 [ # # ]: 0 : for (sal_uInt16 i = 0; i <= nInsPos; ++i)
384 : : {
385 [ # # ]: 0 : if (HYPH_POS_CHAR == aTmp.GetChar( i ))
386 : 0 : nIdxPos++;
387 : : }
388 : : // take the possible hyphenation positions that got removed from the
389 : : // start of the wor dinot account:
390 : 0 : nIdxPos += nHyphenationPositionsOffset;
391 : :
392 [ # # ][ # # ]: 0 : uno::Sequence< sal_Int16 > aSeq = xPossHyph->getHyphenationPositions();
393 : 0 : sal_Int32 nLen = aSeq.getLength();
394 : : DBG_ASSERT(nLen, "empty sequence");
395 : : DBG_ASSERT(0 <= nIdxPos && nIdxPos < nLen, "index out of range");
396 [ # # ][ # # ]: 0 : if (nLen && 0 <= nIdxPos && nIdxPos < nLen)
[ # # ]
397 : : {
398 : 0 : nInsPos = aSeq.getConstArray()[ nIdxPos ];
399 [ # # ]: 0 : pHyphWrapper->InsertHyphen( nInsPos );
400 [ # # ][ # # ]: 0 : }
401 : : }
402 : : else
403 : : {
404 : : //! calling with 0 as argument will remove hyphens!
405 : 0 : pHyphWrapper->InsertHyphen( nInsPos );
406 : : }
407 : : }
408 : :
409 [ # # ]: 0 : if ( pHyphWrapper->FindSpellError() )
410 : : {
411 [ # # ][ # # ]: 0 : uno::Reference< linguistic2::XHyphenatedWord > xHyphWord( pHyphWrapper->GetLast(), uno::UNO_QUERY );
412 : :
413 : : // adapt actual word and language to new found hyphenation result
414 [ # # ]: 0 : if(xHyphWord.is())
415 : : {
416 [ # # ][ # # ]: 0 : aActWord = String( xHyphWord->getWord() );
[ # # ][ # # ]
[ # # ]
417 [ # # ][ # # ]: 0 : nActLanguage = SvxLocaleToLanguage( xHyphWord->getLocale() );
[ # # ]
418 [ # # ][ # # ]: 0 : nMaxHyphenationPos = xHyphWord->getHyphenationPos();
419 [ # # ]: 0 : InitControls_Impl();
420 [ # # ]: 0 : m_pDialog->SetWindowTitle( nActLanguage );
421 : 0 : }
422 : : }
423 : : else
424 : 0 : m_pDialog->EndDialog( RET_OK );
425 : 0 : }
426 : :
427 : :
428 : 0 : sal_uInt16 SvxHyphenWordDialog_Impl::GetHyphIndex_Impl()
429 : : {
430 : 0 : sal_uInt16 nPos = 0;
431 [ # # ]: 0 : String aTxt( aWordEdit.GetText() );
432 : :
433 [ # # ]: 0 : for ( sal_uInt16 i=0 ; i < aTxt.Len(); ++i )
434 : : {
435 : 0 : sal_Unicode cChar = aTxt.GetChar( i );
436 [ # # ]: 0 : if ( cChar == CUR_HYPH_POS_CHAR )
437 : 0 : break;
438 [ # # ]: 0 : if ( cChar != HYPH_POS_CHAR )
439 : 0 : nPos++;
440 : : }
441 [ # # ]: 0 : return nPos;
442 : : }
443 : :
444 : :
445 : 0 : void SvxHyphenWordDialog_Impl::SelLeft_Impl()
446 : : {
447 : : DBG_ASSERT( nOldPos > 0, "invalid hyphenation position" );
448 [ # # ]: 0 : if (nOldPos > 0)
449 : : {
450 [ # # ]: 0 : String aTxt( aEditWord );
451 [ # # ]: 0 : for ( xub_StrLen i = nOldPos - 1; i > 0; --i)
452 : : {
453 : : DBG_ASSERT(i <= aTxt.Len(), "index out of range");
454 [ # # ]: 0 : if (aTxt.GetChar( i ) == sal_Unicode( HYPH_POS_CHAR ))
455 : : {
456 [ # # ]: 0 : aTxt.SetChar( i, sal_Unicode( CUR_HYPH_POS_CHAR ) );
457 : :
458 : 0 : nOldPos = i;
459 [ # # ]: 0 : aWordEdit.SetText( aTxt );
460 [ # # ]: 0 : aWordEdit.GrabFocus();
461 [ # # ]: 0 : aWordEdit.SetSelection( Selection( i, i + 1 ) );
462 : 0 : break;
463 : : }
464 : : }
465 [ # # ]: 0 : nHyphPos = GetHyphIndex_Impl();
466 [ # # ][ # # ]: 0 : EnableLRBtn_Impl();
467 : : }
468 : 0 : }
469 : :
470 : :
471 : 0 : void SvxHyphenWordDialog_Impl::SelRight_Impl()
472 : : {
473 [ # # ]: 0 : String aTxt( aEditWord );
474 [ # # ]: 0 : for ( xub_StrLen i = nOldPos + 1; i < aTxt.Len(); ++i )
475 : : {
476 [ # # ]: 0 : if (aTxt.GetChar( i ) == sal_Unicode( HYPH_POS_CHAR ))
477 : : {
478 [ # # ]: 0 : aTxt.SetChar( i, sal_Unicode( CUR_HYPH_POS_CHAR ) );
479 : :
480 : 0 : nOldPos = i;
481 [ # # ]: 0 : aWordEdit.SetText( aTxt );
482 [ # # ]: 0 : aWordEdit.GrabFocus();
483 [ # # ]: 0 : aWordEdit.SetSelection( Selection( i, i + 1 ) );
484 : 0 : break;
485 : : }
486 : : }
487 [ # # ]: 0 : nHyphPos = GetHyphIndex_Impl();
488 [ # # ][ # # ]: 0 : EnableLRBtn_Impl();
489 : 0 : }
490 : :
491 : :
492 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, CutHdl_Impl)
493 : : {
494 [ # # ]: 0 : if( !bBusy )
495 : : {
496 : 0 : bBusy = sal_True;
497 : 0 : ContinueHyph_Impl( /*nHyphPos*/nOldPos );
498 : 0 : bBusy = sal_False;
499 : : }
500 : 0 : return 0;
501 : : }
502 : :
503 : :
504 : 0 : IMPL_LINK( SvxHyphenWordDialog_Impl, HyphenateAllHdl_Impl, Button *, EMPTYARG /*pButton*/ )
505 : : {
506 [ # # ]: 0 : if( !bBusy )
507 : : {
508 : : try
509 : : {
510 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProp( SvxGetLinguPropertySet() );
511 [ # # ]: 0 : const rtl::OUString aName( RTL_CONSTASCII_USTRINGPARAM( "IsHyphAuto" ) );
512 : 0 : uno::Any aAny;
513 : :
514 [ # # ]: 0 : aAny <<= sal_True;
515 [ # # ][ # # ]: 0 : xProp->setPropertyValue( aName, aAny );
516 : :
517 : 0 : bBusy = sal_True;
518 [ # # ]: 0 : ContinueHyph_Impl( /*nHyphPos*/nOldPos );
519 : 0 : bBusy = sal_False;
520 : :
521 [ # # ]: 0 : aAny <<= sal_False;
522 [ # # ][ # # ]: 0 : xProp->setPropertyValue( aName, aAny );
[ # # ]
523 : : }
524 : 0 : catch (uno::Exception &e)
525 : : {
526 : : (void) e;
527 : : DBG_ASSERT( 0, "Hyphenate All failed" );
528 : : }
529 : : }
530 : 0 : return 0;
531 : : }
532 : :
533 : :
534 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, DeleteHdl_Impl)
535 : : {
536 [ # # ]: 0 : if( !bBusy )
537 : : {
538 : 0 : bBusy = sal_True;
539 : 0 : ContinueHyph_Impl();
540 : 0 : bBusy = sal_False;
541 : : }
542 : 0 : return 0;
543 : : }
544 : :
545 : :
546 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, ContinueHdl_Impl)
547 : : {
548 [ # # ]: 0 : if( !bBusy )
549 : : {
550 : 0 : bBusy = sal_True;
551 : 0 : ContinueHyph_Impl( CONTINUE_HYPH );
552 : 0 : bBusy = sal_False;
553 : : }
554 : 0 : return 0;
555 : : }
556 : :
557 : :
558 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, CancelHdl_Impl)
559 : : {
560 [ # # ]: 0 : if( !bBusy )
561 : : {
562 : 0 : bBusy = sal_True;
563 : 0 : pHyphWrapper->SpellEnd();
564 : 0 : m_pDialog->EndDialog( RET_CANCEL );
565 : 0 : bBusy = sal_False;
566 : : }
567 : 0 : return 0;
568 : : }
569 : :
570 : :
571 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, Left_Impl)
572 : : {
573 [ # # ]: 0 : if( !bBusy )
574 : : {
575 : 0 : bBusy = sal_True;
576 : 0 : SelLeft_Impl();
577 : 0 : bBusy = sal_False;
578 : : }
579 : 0 : return 0;
580 : : }
581 : :
582 : :
583 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, Right_Impl)
584 : : {
585 [ # # ]: 0 : if( !bBusy )
586 : : {
587 : 0 : bBusy = sal_True;
588 : 0 : SelRight_Impl();
589 : 0 : bBusy = sal_False;
590 : : }
591 : 0 : return 0;
592 : : }
593 : :
594 : :
595 : 0 : IMPL_LINK_NOARG(SvxHyphenWordDialog_Impl, GetFocusHdl_Impl)
596 : : {
597 [ # # ]: 0 : aWordEdit.SetSelection( Selection( nOldPos, nOldPos + 1 ) );
598 : 0 : return 0;
599 : : }
600 : :
601 : :
602 : : // class SvxHyphenWordDialog ---------------------------------------------
603 : :
604 : 0 : SvxHyphenWordDialog::SvxHyphenWordDialog(
605 : : const String &rWord, LanguageType nLang,
606 : : Window* pParent,
607 : : uno::Reference< linguistic2::XHyphenator > &xHyphen,
608 : : SvxSpellWrapper* pWrapper ) :
609 : :
610 [ # # ]: 0 : SfxModalDialog( pParent, CUI_RES( RID_SVXDLG_HYPHENATE ) )
611 : : {
612 : : m_pImpl = std::auto_ptr< SvxHyphenWordDialog_Impl >(
613 [ # # ][ # # ]: 0 : new SvxHyphenWordDialog_Impl( this, rWord, nLang, xHyphen, pWrapper ) );
[ # # ]
614 : :
615 [ # # ]: 0 : FreeResource();
616 : :
617 [ # # ]: 0 : SetWindowTitle( nLang );
618 : :
619 : : // disable controls if service is not available
620 [ # # ]: 0 : if (!m_pImpl->xHyphenator.is())
621 [ # # ]: 0 : Enable( sal_False );
622 : 0 : }
623 : :
624 : :
625 [ # # ]: 0 : SvxHyphenWordDialog::~SvxHyphenWordDialog()
626 : : {
627 [ # # ]: 0 : }
628 : :
629 : :
630 : 0 : void SvxHyphenWordDialog::SetWindowTitle( LanguageType nLang )
631 : : {
632 [ # # ]: 0 : String aLangStr( SvtLanguageTable::GetLanguageString( nLang ) );
633 [ # # ]: 0 : String aTmp( m_pImpl->aLabel );
634 [ # # ]: 0 : aTmp.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " (" ) );
635 [ # # ]: 0 : aTmp.Append( aLangStr );
636 [ # # ]: 0 : aTmp.Append( sal_Unicode( ')' ) );
637 [ # # ][ # # ]: 0 : SetText( aTmp );
[ # # ]
638 : 0 : }
639 : :
640 : :
641 : 0 : void SvxHyphenWordDialog::SelLeft()
642 : : {
643 : 0 : m_pImpl->SelLeft_Impl();
644 : 0 : }
645 : :
646 : :
647 : 0 : void SvxHyphenWordDialog::SelRight()
648 : : {
649 : 0 : m_pImpl->SelRight_Impl();
650 : 0 : }
651 : :
652 : :
653 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|