Update ooo320-m1
[ooovba.git] / svx / source / options / optlingu.cxx
blobd594a1811bbb35cf8f9378061403c5f91b814907
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: optlingu.cxx,v $
10 * $Revision: 1.68 $
12 * This file is part of OpenOffice.org.
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.
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).
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
36 #define _SVSTDARR_STRINGSDTOR
37 #define _SVSTDARR_USHORTS
38 //#ifndef _SVSTDARR_HXX
39 //#include <svtools/svstdarr.hxx>
40 //#endif
41 #include <vcl/msgbox.hxx>
42 #include <vcl/field.hxx>
43 #include <vcl/fixed.hxx>
44 #include <tools/shl.hxx>
45 #include <tools/dynary.hxx>
46 #include <i18npool/mslangid.hxx>
47 //#include <svtools/svarray.hxx>
48 #include <svtools/lingucfg.hxx>
49 #include <unolingu.hxx>
50 #include <dlgutil.hxx>
51 #include <linguistic/lngprops.hxx>
52 #include <linguistic/misc.hxx>
53 #include <unolingu.hxx>
54 #include <sfx2/sfxuno.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <tools/urlobj.hxx>
57 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
58 #include <comphelper/processfactory.hxx>
59 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
60 #include <com/sun/star/linguistic2/XProofreader.hpp>
61 #include <com/sun/star/linguistic2/XHyphenator.hpp>
62 #include <com/sun/star/linguistic2/XThesaurus.hpp>
63 #include <com/sun/star/linguistic2/XAvailableLocales.hpp>
64 #include <com/sun/star/lang/XServiceDisplayName.hpp>
65 #include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
66 #include <com/sun/star/linguistic2/DictionaryListEvent.hpp>
67 #include <com/sun/star/linguistic2/XDictionaryListEventListener.hpp>
68 #include <com/sun/star/linguistic2/XDictionaryList.hpp>
69 #include <com/sun/star/frame/XStorable.hpp>
70 #include <com/sun/star/ucb/CommandAbortedException.hpp>
71 #include <com/sun/star/system/XSystemShellExecute.hpp>
72 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
73 #include <svtools/extendedsecurityoptions.hxx>
74 #include <svtools/svlbox.hxx>
75 #include <svtools/eitem.hxx>
76 #include <svtools/intitem.hxx>
77 #include <sfx2/viewfrm.hxx>
78 #include <vcl/svapp.hxx>
79 #define _SVX_OPTLINGU_CXX
81 #include "optlingu.hrc"
83 #include <svx/svxdlg.hxx>
84 #include "optitems.hxx"
85 #include <svx/optlingu.hxx>
86 #include <svx/dialmgr.hxx>
87 #include <svx/dialogs.hrc>
88 #include "helpid.hrc"
90 #include <ucbhelper/content.hxx>
92 #include <vector>
93 #include <map>
96 using namespace ::ucbhelper;
97 using namespace ::rtl;
98 using namespace ::com::sun::star;
99 using namespace ::com::sun::star::lang;
100 using namespace ::com::sun::star::uno;
101 using namespace ::com::sun::star::linguistic2;
102 using namespace ::com::sun::star::beans;
103 namespace css = com::sun::star;
105 #define C2U(cChar) OUString::createFromAscii(cChar)
106 #define SVX_MAX_USERDICTS 20
107 #define CBCOL_FIRST 0
108 #define CBCOL_SECOND 1
109 #define CBCOL_BOTH 2
111 static const sal_Char cSpell[] = SN_SPELLCHECKER;
112 static const sal_Char cGrammar[] = SN_GRAMMARCHECKER;
113 static const sal_Char cHyph[] = SN_HYPHENATOR;
114 static const sal_Char cThes[] = SN_THESAURUS;
116 // static ----------------------------------------------------------------
118 static Sequence< INT16 > lcl_LocaleSeqToLangSeq( const Sequence< Locale > &rSeq )
120 INT32 nLen = rSeq.getLength();
121 Sequence< INT16 > aRes( nLen );
122 INT16 *pRes = aRes.getArray();
123 const Locale *pSeq = rSeq.getConstArray();
124 for (INT32 i = 0; i < nLen; ++i)
126 pRes[i] = SvxLocaleToLanguage( pSeq[i] );
128 return aRes;
132 static BOOL lcl_SeqHasLang( const Sequence< INT16 > &rSeq, INT16 nLang )
134 INT32 nLen = rSeq.getLength();
135 const INT16 *pLang = rSeq.getConstArray();
136 INT32 nPos = -1;
137 for (INT32 i = 0; i < nLen && nPos < 0; ++i)
139 if (nLang == pLang[i])
140 nPos = i;
142 return nPos < 0 ? FALSE : TRUE;
146 static INT32 lcl_SeqGetEntryPos(
147 const Sequence< OUString > &rSeq, const OUString &rEntry )
149 INT32 i;
150 INT32 nLen = rSeq.getLength();
151 const OUString *pItem = rSeq.getConstArray();
152 for (i = 0; i < nLen; ++i)
154 if (rEntry == pItem[i])
155 break;
157 return i < nLen ? i : -1;
160 static void lcl_OpenURL( const ::rtl::OUString& rURL )
162 if ( rURL.getLength() > 0 )
166 uno::Reference< lang::XMultiServiceFactory > xSMGR =
167 ::comphelper::getProcessServiceFactory();
168 uno::Reference< css::system::XSystemShellExecute > xSystemShell(
169 xSMGR->createInstance( ::rtl::OUString(
170 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
171 uno::UNO_QUERY_THROW );
172 if ( xSystemShell.is() )
173 xSystemShell->execute( rURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::DEFAULTS );
175 catch( const uno::Exception& e )
177 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
178 rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
183 /*--------------------------------------------------
184 --------------------------------------------------*/
186 static const sal_uInt16 nNameLen = 8;
188 static sal_uInt16 pRanges[] =
190 SID_ATTR_SPELL,
191 SID_ATTR_SPELL,
195 sal_Bool KillFile_Impl( const String& rURL )
197 sal_Bool bRet = sal_True;
200 Content aCnt( rURL, uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
201 aCnt.executeCommand( OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) );
203 catch( ::com::sun::star::ucb::CommandAbortedException& )
205 DBG_ERRORFILE( "KillFile: CommandAbortedException" );
206 bRet = sal_False;
208 catch( ... )
210 DBG_ERRORFILE( "KillFile: Any other exception" );
211 bRet = sal_False;
214 return bRet;
216 /* -----------------------------27.11.00 14:07--------------------------------
218 ---------------------------------------------------------------------------*/
219 // 0x 0p 0t 0c nn
220 // p: 1 -> parent
221 // t: 1 -> spell, 2 -> hyph, 3 -> thes, 4 -> grammar
222 // c: 1 -> checked 0 -> unchecked
223 // n: index
225 #define TYPE_SPELL (BYTE)1
226 #define TYPE_GRAMMAR (BYTE)2
227 #define TYPE_HYPH (BYTE)3
228 #define TYPE_THES (BYTE)4
230 class ModuleUserData_Impl
232 BOOL bParent;
233 BOOL bIsChecked;
234 BYTE nType;
235 BYTE nIndex;
236 String sImplName;
238 public:
239 ModuleUserData_Impl( String sImpName, BOOL bIsParent, BOOL bChecked, BYTE nSetType, BYTE nSetIndex ) :
240 bParent(bIsParent),
241 bIsChecked(bChecked),
242 nType(nSetType),
243 nIndex(nSetIndex),
244 sImplName(sImpName)
247 BOOL IsParent() const {return bParent;}
248 BYTE GetType() const {return nType;}
249 BOOL IsChecked() const {return bIsChecked;}
250 BYTE GetIndex() const {return nIndex;}
251 void SetIndex(BYTE nSet) {nIndex = nSet;}
252 const String& GetImplName() const {return sImplName;}
256 /*--------------------------------------------------
257 --------------------------------------------------*/
259 // User for user-dictionaries (XDictionary interface)
261 class DicUserData
263 ULONG nVal;
265 public:
266 DicUserData( ULONG nUserData ) : nVal( nUserData ) {}
267 DicUserData( USHORT nEID,
268 BOOL bChecked, BOOL bEditable, BOOL bDeletable );
270 ULONG GetUserData() const { return nVal; }
271 USHORT GetEntryId() const { return (USHORT)(nVal >> 16); }
272 BOOL IsChecked() const { return (BOOL)(nVal >> 8) & 0x01; }
273 BOOL IsEditable() const { return (BOOL)(nVal >> 9) & 0x01; }
274 BOOL IsDeletable() const { return (BOOL)(nVal >> 10) & 0x01; }
276 void SetChecked( BOOL bVal );
280 DicUserData::DicUserData(
281 USHORT nEID,
282 BOOL bChecked, BOOL bEditable, BOOL bDeletable )
284 DBG_ASSERT( nEID < 65000, "Entry Id out of range" );
285 nVal = ((ULONG)(0xFFFF & nEID) << 16) |
286 ((ULONG)(bChecked ? 1 : 0) << 8) |
287 ((ULONG)(bEditable ? 1 : 0) << 9) |
288 ((ULONG)(bDeletable ? 1 : 0) << 10);
292 void DicUserData::SetChecked( BOOL bVal )
294 nVal &= ~(1UL << 8);
295 nVal |= (ULONG)(bVal ? 1 : 0) << 8;
299 // class BrwString_Impl -------------------------------------------------
301 void lcl_SetCheckButton( SvLBoxEntry* pEntry, BOOL bCheck )
303 SvLBoxButton* pItem = (SvLBoxButton*)(pEntry->GetFirstItem(SV_ITEM_ID_LBOXBUTTON));
305 DBG_ASSERT(pItem,"SetCheckButton:Item not found");
306 if (((SvLBoxItem*)pItem)->IsA() == SV_ITEM_ID_LBOXBUTTON)
308 if (bCheck)
309 pItem->SetStateChecked();
310 else
311 pItem->SetStateUnchecked();
312 //InvalidateEntry( pEntry );
317 class BrwStringDic_Impl : public SvLBoxString
319 public:
321 BrwStringDic_Impl( SvLBoxEntry* pEntry, USHORT nFlags,
322 const String& rStr ) : SvLBoxString( pEntry, nFlags, rStr ) {}
324 virtual void Paint( const Point& rPos, SvLBox& rDev, USHORT nFlags,
325 SvLBoxEntry* pEntry);
328 void BrwStringDic_Impl::Paint( const Point& rPos, SvLBox& rDev, USHORT,
329 SvLBoxEntry* pEntry )
331 ModuleUserData_Impl* pData = (ModuleUserData_Impl*)pEntry->GetUserData();
332 Point aPos(rPos);
333 Font aOldFont( rDev.GetFont());
334 if(pData->IsParent())
336 Font aFont( aOldFont );
337 aFont.SetWeight( WEIGHT_BOLD );
338 rDev.SetFont( aFont );
339 aPos.X() = 0;
341 else
342 aPos.X() += 5;
343 rDev.DrawText( aPos, GetText() );
344 rDev.SetFont( aOldFont );
348 /*--------------------------------------------------
349 --------------------------------------------------*/
351 class OptionsBreakSet : public ModalDialog
353 OKButton aOKPB;
354 CancelButton aCancelPB;
355 FixedLine aValFL;
356 NumericField aValNF;
358 public:
359 OptionsBreakSet(Window* pParent, int nRID) :
360 ModalDialog(pParent, SVX_RES(RID_SVXDLG_LNG_ED_NUM_PREBREAK )),
361 aOKPB (this, SVX_RES(BT_OK_PREBREAK)),
362 aCancelPB (this, SVX_RES(BT_CANCEL_PREBREAK)),
363 aValFL (this, SVX_RES(FL_NUMVAL_PREBREAK)),
364 aValNF (this, SVX_RES(ED_PREBREAK))
366 DBG_ASSERT( STR_NUM_PRE_BREAK_DLG == nRID ||
367 STR_NUM_POST_BREAK_DLG == nRID ||
368 STR_NUM_MIN_WORDLEN_DLG == nRID, "unexpected RID" );
370 if (nRID != -1)
371 aValFL.SetText( String( SVX_RES(nRID) ) );
372 FreeResource();
375 NumericField& GetNumericFld() { return aValNF; }
379 /*--------------------------------------------------
380 Entry IDs for options listbox of dialog
381 --------------------------------------------------*/
383 enum EID_OPTIONS
385 EID_SPELL_AUTO,
386 EID_GRAMMAR_AUTO,
387 EID_CAPITAL_WORDS,
388 EID_WORDS_WITH_DIGITS,
389 EID_CAPITALIZATION,
390 EID_SPELL_SPECIAL,
391 EID_NUM_MIN_WORDLEN,
392 EID_NUM_PRE_BREAK,
393 EID_NUM_POST_BREAK,
394 EID_HYPH_AUTO,
395 EID_HYPH_SPECIAL
398 //! this array must have an entry for every value of EID_OPTIONS.
399 // It is used to get the respective property name.
400 static const char * aEidToPropName[] =
402 UPN_IS_SPELL_AUTO, // EID_SPELL_AUTO
403 UPN_IS_GRAMMAR_AUTO, // EID_GRAMMAR_AUTO
404 UPN_IS_SPELL_UPPER_CASE, // EID_CAPITAL_WORDS
405 UPN_IS_SPELL_WITH_DIGITS, // EID_WORDS_WITH_DIGITS
406 UPN_IS_SPELL_CAPITALIZATION, // EID_CAPITALIZATION
407 UPN_IS_SPELL_SPECIAL, // EID_SPELL_SPECIAL
408 UPN_HYPH_MIN_WORD_LENGTH, // EID_NUM_MIN_WORDLEN,
409 UPN_HYPH_MIN_LEADING, // EID_NUM_PRE_BREAK
410 UPN_HYPH_MIN_TRAILING, // EID_NUM_POST_BREAK
411 UPN_IS_HYPH_AUTO, // EID_HYPH_AUTO
412 UPN_IS_HYPH_SPECIAL // EID_HYPH_SPECIAL
416 static inline String lcl_GetPropertyName( EID_OPTIONS eEntryId )
418 DBG_ASSERT( (unsigned int) eEntryId < sizeof(aEidToPropName) / sizeof(aEidToPropName[0]), "index out of range" );
419 return String::CreateFromAscii( aEidToPropName[ (int) eEntryId ] );
422 // class OptionsUserData -------------------------------------------------
424 class OptionsUserData
426 ULONG nVal;
428 void SetModified();
430 public:
431 OptionsUserData( ULONG nUserData ) : nVal( nUserData ) {}
432 OptionsUserData( USHORT nEID,
433 BOOL bHasNV, USHORT nNumVal,
434 BOOL bCheckable, BOOL bChecked );
436 ULONG GetUserData() const { return nVal; }
437 USHORT GetEntryId() const { return (USHORT)(nVal >> 16); }
438 BOOL HasNumericValue() const { return (BOOL)(nVal >> 10) & 0x01; }
439 USHORT GetNumericValue() const { return (USHORT)(nVal & 0xFF); }
440 BOOL IsChecked() const { return (BOOL)(nVal >> 8) & 0x01; }
441 BOOL IsCheckable() const { return (BOOL)(nVal >> 9) & 0x01; }
442 BOOL IsModified() const { return (BOOL)(nVal >> 11) & 0x01; }
444 void SetChecked( BOOL bVal );
445 void SetNumericValue( BYTE nNumVal );
448 OptionsUserData::OptionsUserData( USHORT nEID,
449 BOOL bHasNV, USHORT nNumVal,
450 BOOL bCheckable, BOOL bChecked )
452 DBG_ASSERT( nEID < 65000, "Entry Id out of range" );
453 DBG_ASSERT( nNumVal < 256, "value out of range" );
454 nVal = ((ULONG)(0xFFFF & nEID) << 16) |
455 ((ULONG)(bHasNV ? 1 : 0) << 10) |
456 ((ULONG)(bCheckable ? 1 : 0) << 9) |
457 ((ULONG)(bChecked ? 1 : 0) << 8) |
458 ((ULONG)(0xFF & nNumVal));
461 void OptionsUserData::SetChecked( BOOL bVal )
463 if (IsCheckable() && (IsChecked() != bVal))
465 nVal &= ~(1UL << 8);
466 nVal |= (ULONG)(bVal ? 1 : 0) << 8;
467 SetModified();
471 void OptionsUserData::SetNumericValue( BYTE nNumVal )
473 // DBG_ASSERT( nNumVal < 256, "value out of range" );
474 if (HasNumericValue() && (GetNumericValue() != nNumVal))
476 nVal &= 0xffffff00;
477 nVal |= (nNumVal);
478 SetModified();
482 void OptionsUserData::SetModified()
484 nVal |= (ULONG)1 << 11;
487 // class BrwString_Impl -------------------------------------------------
489 class BrwString_Impl : public SvLBoxString
491 public:
493 BrwString_Impl( SvLBoxEntry* pEntry, USHORT nFlags,
494 const String& rStr ) : SvLBoxString( pEntry, nFlags, rStr ) {}
496 virtual void Paint( const Point& rPos, SvLBox& rDev, USHORT nFlags,
497 SvLBoxEntry* pEntry);
500 void BrwString_Impl::Paint( const Point& rPos, SvLBox& rDev, USHORT,
501 SvLBoxEntry* pEntry )
503 Point aPos(rPos);
504 aPos.X() += 20;
505 rDev.DrawText( aPos, GetText() );
506 if(pEntry->GetUserData())
508 Point aNewPos(aPos);
509 aNewPos.X() += rDev.GetTextWidth(GetText());
510 Font aOldFont( rDev.GetFont());
511 Font aFont( aOldFont );
512 aFont.SetWeight( WEIGHT_BOLD );
514 // BOOL bFett = TRUE;
515 // USHORT nPos = 0;
516 //??? das untere byte aus dem user data in string wandeln
517 OptionsUserData aData( (ULONG) pEntry->GetUserData() );
518 if(aData.HasNumericValue())
520 String sTxt( ' ' );
521 sTxt += String::CreateFromInt32( aData.GetNumericValue() );
522 rDev.SetFont( aFont );
523 rDev.DrawText( aNewPos, sTxt );
526 // if( STRING_NOTFOUND != nPos )
527 // aNewPos.X() += rDev.GetTextWidth( sTxt );
529 rDev.SetFont( aOldFont );
533 // ServiceInfo_Impl ----------------------------------------------------
535 struct ServiceInfo_Impl
537 OUString sDisplayName;
538 OUString sSpellImplName;
539 OUString sHyphImplName;
540 OUString sThesImplName;
541 OUString sGrammarImplName;
542 uno::Reference< XSpellChecker > xSpell;
543 uno::Reference< XHyphenator > xHyph;
544 uno::Reference< XThesaurus > xThes;
545 uno::Reference< XProofreader > xGrammar;
546 BOOL bConfigured;
548 ServiceInfo_Impl() : bConfigured(sal_False) {}
551 typedef std::vector< ServiceInfo_Impl > ServiceInfoArr;
552 typedef std::map< INT16 /*LanguageType*/, Sequence< OUString > > LangImplNameTable;
555 // SvxLinguData_Impl ----------------------------------------------------
557 class SvxLinguData_Impl
559 //contains services and implementation names sorted by implementation names
560 ServiceInfoArr aDisplayServiceArr;
561 ULONG nDisplayServices;
563 Sequence< Locale > aAllServiceLocales;
564 LangImplNameTable aCfgSpellTable;
565 LangImplNameTable aCfgHyphTable;
566 LangImplNameTable aCfgThesTable;
567 LangImplNameTable aCfgGrammarTable;
568 uno::Reference< XMultiServiceFactory > xMSF;
569 uno::Reference< XLinguServiceManager > xLinguSrvcMgr;
572 sal_Bool AddRemove( Sequence< OUString > &rConfigured,
573 const OUString &rImplName, BOOL bAdd );
575 public:
576 SvxLinguData_Impl();
577 SvxLinguData_Impl( const SvxLinguData_Impl &rData );
578 ~SvxLinguData_Impl();
580 SvxLinguData_Impl & operator = (const SvxLinguData_Impl &rData);
582 uno::Reference<XLinguServiceManager> & GetManager() { return xLinguSrvcMgr; }
584 void SetChecked( const Sequence< OUString > &rConfiguredServices );
585 void Reconfigure( const OUString &rDisplayName, BOOL bEnable );
587 const Sequence<Locale> & GetAllSupportedLocales() { return aAllServiceLocales; }
589 const LangImplNameTable & GetSpellTable() const { return aCfgSpellTable; }
590 LangImplNameTable & GetSpellTable() { return aCfgSpellTable; }
591 const LangImplNameTable & GetHyphTable() const { return aCfgHyphTable; }
592 LangImplNameTable & GetHyphTable() { return aCfgHyphTable; }
593 const LangImplNameTable & GetThesTable() const { return aCfgThesTable; }
594 LangImplNameTable & GetThesTable() { return aCfgThesTable; }
595 const LangImplNameTable & GetGrammarTable() const { return aCfgGrammarTable; }
596 LangImplNameTable & GetGrammarTable() { return aCfgGrammarTable; }
598 const ServiceInfoArr & GetDisplayServiceArray() const { return aDisplayServiceArr; }
599 ServiceInfoArr & GetDisplayServiceArray() { return aDisplayServiceArr; }
601 const ULONG & GetDisplayServiceCount() const { return nDisplayServices; }
602 void SetDisplayServiceCount( ULONG nVal ) { nDisplayServices = nVal; }
604 // returns the list of service implementation names for the specified
605 // language and service (TYPE_SPELL, TYPE_HYPH, TYPE_THES) sorted in
606 // the proper order for the SvxEditModulesDlg (the ones from the
607 // configuration (keeping that order!) first and then the other ones.
608 // I.e. the ones available but not configured in arbitrary order).
609 // They available ones may contain names that do not(!) support that
610 // language.
611 Sequence< OUString > GetSortedImplNames( INT16 nLang, BYTE nType );
613 ServiceInfo_Impl * GetInfoByImplName( const OUString &rSvcImplName );
617 INT32 lcl_SeqGetIndex( const Sequence< OUString > &rSeq, const OUString &rTxt )
619 INT32 nRes = -1;
620 INT32 nLen = rSeq.getLength();
621 const OUString *pString = rSeq.getConstArray();
622 for (INT32 i = 0; i < nLen && nRes == -1; ++i)
624 if (pString[i] == rTxt)
625 nRes = i;
627 return nRes;
631 Sequence< OUString > SvxLinguData_Impl::GetSortedImplNames( INT16 nLang, BYTE nType )
633 LangImplNameTable *pTable = 0;
634 switch (nType)
636 case TYPE_SPELL : pTable = &aCfgSpellTable; break;
637 case TYPE_HYPH : pTable = &aCfgHyphTable; break;
638 case TYPE_THES : pTable = &aCfgThesTable; break;
639 case TYPE_GRAMMAR : pTable = &aCfgGrammarTable; break;
641 Sequence< OUString > aRes;
642 if (pTable->count( nLang ))
643 aRes = (*pTable)[ nLang ]; // add configured services
644 INT32 nIdx = aRes.getLength();
645 DBG_ASSERT( (INT32) nDisplayServices >= nIdx, "size mismatch" );
646 aRes.realloc( nDisplayServices );
647 OUString *pRes = aRes.getArray();
649 // add not configured services
650 for (INT32 i = 0; i < (INT32) nDisplayServices; ++i)
652 const ServiceInfo_Impl &rInfo = aDisplayServiceArr[ i ];
653 OUString aImplName;
654 switch (nType)
656 case TYPE_SPELL : aImplName = rInfo.sSpellImplName; break;
657 case TYPE_HYPH : aImplName = rInfo.sHyphImplName; break;
658 case TYPE_THES : aImplName = rInfo.sThesImplName; break;
659 case TYPE_GRAMMAR : aImplName = rInfo.sGrammarImplName; break;
662 if (aImplName.getLength() && (lcl_SeqGetIndex( aRes, aImplName) == -1)) // name not yet added
664 DBG_ASSERT( nIdx < aRes.getLength(), "index out of range" );
665 if (nIdx < aRes.getLength())
666 pRes[ nIdx++ ] = aImplName;
669 // don't forget to put aRes back to its actual size just in case you allocated too much
670 // since all of the names may have already been added
671 // otherwise you get duplicate entries in the edit dialog
672 aRes.realloc( nIdx );
673 return aRes;
677 ServiceInfo_Impl * SvxLinguData_Impl::GetInfoByImplName( const OUString &rSvcImplName )
679 ServiceInfo_Impl* pInfo = 0;
680 for (ULONG i = 0; i < nDisplayServices && !pInfo; ++i)
682 ServiceInfo_Impl &rTmp = aDisplayServiceArr[ i ];
683 if (rTmp.sSpellImplName == rSvcImplName ||
684 rTmp.sHyphImplName == rSvcImplName ||
685 rTmp.sThesImplName == rSvcImplName ||
686 rTmp.sGrammarImplName == rSvcImplName)
687 pInfo = &rTmp;
689 return pInfo;
693 //-----------------------------------------------------------------------------
695 void lcl_MergeLocales(Sequence< Locale >& aAllLocales, const Sequence< Locale >& rAdd)
697 const Locale* pAdd = rAdd.getConstArray();
698 Sequence<Locale> aLocToAdd(rAdd.getLength());
699 const Locale* pAllLocales = aAllLocales.getConstArray();
700 Locale* pLocToAdd = aLocToAdd.getArray();
701 sal_Int32 nFound = 0;
702 sal_Int32 i;
703 for(i = 0; i < rAdd.getLength(); i++)
705 sal_Bool bFound = sal_False;
706 for(sal_Int32 j = 0; j < aAllLocales.getLength() && !bFound; j++)
708 bFound = pAdd[i].Language == pAllLocales[j].Language &&
709 pAdd[i].Country == pAllLocales[j].Country;
711 if(!bFound)
713 pLocToAdd[nFound++] = pAdd[i];
716 sal_Int32 nLength = aAllLocales.getLength();
717 aAllLocales.realloc( nLength + nFound);
718 Locale* pAllLocales2 = aAllLocales.getArray();
719 for(i = 0; i < nFound; i++)
720 pAllLocales2[nLength++] = pLocToAdd[i];
722 /* -----------------------------27.11.00 16:48--------------------------------
724 ---------------------------------------------------------------------------*/
725 void lcl_MergeDisplayArray(
726 SvxLinguData_Impl &rData,
727 const ServiceInfo_Impl &rToAdd )
729 ULONG nCnt = 0;
731 ServiceInfoArr &rSvcInfoArr = rData.GetDisplayServiceArray();
732 ULONG nEntries = rData.GetDisplayServiceCount();
734 ServiceInfo_Impl* pEntry;
735 for (ULONG i = 0; i < nEntries; ++i)
737 pEntry = &rSvcInfoArr[i];
738 if (pEntry && pEntry->sDisplayName == rToAdd.sDisplayName)
740 if(rToAdd.xSpell.is())
742 DBG_ASSERT( !pEntry->xSpell.is() &&
743 pEntry->sSpellImplName.getLength() == 0,
744 "merge conflict" );
745 pEntry->sSpellImplName = rToAdd.sSpellImplName;
746 pEntry->xSpell = rToAdd.xSpell;
748 if(rToAdd.xGrammar.is())
750 DBG_ASSERT( !pEntry->xGrammar.is() &&
751 pEntry->sGrammarImplName.getLength() == 0,
752 "merge conflict" );
753 pEntry->sGrammarImplName = rToAdd.sGrammarImplName;
754 pEntry->xGrammar = rToAdd.xGrammar;
756 if(rToAdd.xHyph.is())
758 DBG_ASSERT( !pEntry->xHyph.is() &&
759 pEntry->sHyphImplName.getLength() == 0,
760 "merge conflict" );
761 pEntry->sHyphImplName = rToAdd.sHyphImplName;
762 pEntry->xHyph = rToAdd.xHyph;
764 if(rToAdd.xThes.is())
766 DBG_ASSERT( !pEntry->xThes.is() &&
767 pEntry->sThesImplName.getLength() == 0,
768 "merge conflict" );
769 pEntry->sThesImplName = rToAdd.sThesImplName;
770 pEntry->xThes = rToAdd.xThes;
772 return ;
774 ++nCnt;
776 rData.GetDisplayServiceArray().push_back( rToAdd );
777 rData.SetDisplayServiceCount( nCnt + 1 );
779 /* -----------------------------26.11.00 18:07--------------------------------
781 ---------------------------------------------------------------------------*/
782 SvxLinguData_Impl::SvxLinguData_Impl() :
783 nDisplayServices (0)
785 xMSF = ::comphelper::getProcessServiceFactory();
786 uno::Reference < XInterface > xI = xMSF->createInstance(
787 C2U( "com.sun.star.linguistic2.LinguServiceManager" ) );
788 xLinguSrvcMgr = uno::Reference<XLinguServiceManager>(xI, UNO_QUERY);
789 DBG_ASSERT(xLinguSrvcMgr.is(), "No linguistic service available!");
790 if(xLinguSrvcMgr.is())
792 Locale aCurrentLocale;
793 LanguageType eLang = Application::GetSettings().GetLanguage();
794 SvxLanguageToLocale(aCurrentLocale, eLang);
795 Sequence<Any> aArgs(2);//second arguments has to be empty!
796 aArgs.getArray()[0] <<= SvxGetLinguPropertySet();
798 //read spell checker
799 Sequence< OUString > aSpellNames = xLinguSrvcMgr->getAvailableServices(
800 C2U(cSpell), Locale() );
801 const OUString* pSpellNames = aSpellNames.getConstArray();
803 sal_Int32 nIdx;
804 for(nIdx = 0; nIdx < aSpellNames.getLength(); nIdx++)
806 ServiceInfo_Impl aInfo;
807 aInfo.sSpellImplName = pSpellNames[nIdx];
808 aInfo.xSpell = uno::Reference<XSpellChecker>(
809 xMSF->createInstanceWithArguments(aInfo.sSpellImplName, aArgs), UNO_QUERY);
811 uno::Reference<XServiceDisplayName> xDispName(aInfo.xSpell, UNO_QUERY);
812 if(xDispName.is())
813 aInfo.sDisplayName = xDispName->getServiceDisplayName( aCurrentLocale );
815 const Sequence< Locale > aLocales( aInfo.xSpell->getLocales() );
816 //! suppress display of entries with no supported languages (see feature 110994)
817 if (aLocales.getLength())
819 lcl_MergeLocales( aAllServiceLocales, aLocales );
820 lcl_MergeDisplayArray( *this, aInfo );
824 //read grammar checker
825 Sequence< OUString > aGrammarNames = xLinguSrvcMgr->getAvailableServices(
826 C2U(cGrammar), Locale() );
827 const OUString* pGrammarNames = aGrammarNames.getConstArray();
828 for(nIdx = 0; nIdx < aGrammarNames.getLength(); nIdx++)
830 ServiceInfo_Impl aInfo;
831 aInfo.sGrammarImplName = pGrammarNames[nIdx];
832 aInfo.xGrammar = uno::Reference<XProofreader>(
833 xMSF->createInstanceWithArguments(aInfo.sGrammarImplName, aArgs), UNO_QUERY);
835 uno::Reference<XServiceDisplayName> xDispName(aInfo.xGrammar, UNO_QUERY);
836 if(xDispName.is())
837 aInfo.sDisplayName = xDispName->getServiceDisplayName( aCurrentLocale );
839 const Sequence< Locale > aLocales( aInfo.xGrammar->getLocales() );
840 //! suppress display of entries with no supported languages (see feature 110994)
841 if (aLocales.getLength())
843 lcl_MergeLocales( aAllServiceLocales, aLocales );
844 lcl_MergeDisplayArray( *this, aInfo );
848 //read hyphenator
849 Sequence< OUString > aHyphNames = xLinguSrvcMgr->getAvailableServices(
850 C2U(cHyph), Locale() );
851 const OUString* pHyphNames = aHyphNames.getConstArray();
852 for(nIdx = 0; nIdx < aHyphNames.getLength(); nIdx++)
854 ServiceInfo_Impl aInfo;
855 aInfo.sHyphImplName = pHyphNames[nIdx];
856 aInfo.xHyph = uno::Reference<XHyphenator>(
857 xMSF->createInstanceWithArguments(aInfo.sHyphImplName, aArgs), UNO_QUERY);
859 uno::Reference<XServiceDisplayName> xDispName(aInfo.xHyph, UNO_QUERY);
860 if(xDispName.is())
861 aInfo.sDisplayName = xDispName->getServiceDisplayName( aCurrentLocale );
863 const Sequence< Locale > aLocales( aInfo.xHyph->getLocales() );
864 //! suppress display of entries with no supported languages (see feature 110994)
865 if (aLocales.getLength())
867 lcl_MergeLocales( aAllServiceLocales, aLocales );
868 lcl_MergeDisplayArray( *this, aInfo );
872 //read thesauri
873 Sequence< OUString > aThesNames = xLinguSrvcMgr->getAvailableServices(
874 C2U(cThes), Locale() );
875 const OUString* pThesNames = aThesNames.getConstArray();
876 for(nIdx = 0; nIdx < aThesNames.getLength(); nIdx++)
878 ServiceInfo_Impl aInfo;
879 aInfo.sThesImplName = pThesNames[nIdx];
880 aInfo.xThes = uno::Reference<XThesaurus>(
881 xMSF->createInstanceWithArguments(aInfo.sThesImplName, aArgs), UNO_QUERY);
883 uno::Reference<XServiceDisplayName> xDispName(aInfo.xThes, UNO_QUERY);
884 if(xDispName.is())
885 aInfo.sDisplayName = xDispName->getServiceDisplayName( aCurrentLocale );
887 const Sequence< Locale > aLocales( aInfo.xThes->getLocales() );
888 //! suppress display of entries with no supported languages (see feature 110994)
889 if (aLocales.getLength())
891 lcl_MergeLocales( aAllServiceLocales, aLocales );
892 lcl_MergeDisplayArray( *this, aInfo );
896 Sequence< OUString > aCfgSvcs;
897 const Locale* pAllLocales = aAllServiceLocales.getConstArray();
898 for(sal_Int32 nLocale = 0; nLocale < aAllServiceLocales.getLength(); nLocale++)
900 INT16 nLang = SvxLocaleToLanguage( pAllLocales[nLocale] );
902 aCfgSvcs = xLinguSrvcMgr->getConfiguredServices(C2U(cSpell), pAllLocales[nLocale]);
903 SetChecked( aCfgSvcs );
904 if (aCfgSvcs.getLength())
905 aCfgSpellTable[ nLang ] = aCfgSvcs;
907 aCfgSvcs = xLinguSrvcMgr->getConfiguredServices(C2U(cGrammar), pAllLocales[nLocale]);
908 SetChecked( aCfgSvcs );
909 if (aCfgSvcs.getLength())
910 aCfgGrammarTable[ nLang ] = aCfgSvcs;
912 aCfgSvcs = xLinguSrvcMgr->getConfiguredServices(C2U(cHyph), pAllLocales[nLocale]);
913 SetChecked( aCfgSvcs );
914 if (aCfgSvcs.getLength())
915 aCfgHyphTable[ nLang ] = aCfgSvcs;
917 aCfgSvcs = xLinguSrvcMgr->getConfiguredServices(C2U(cThes), pAllLocales[nLocale]);
918 SetChecked( aCfgSvcs );
919 if (aCfgSvcs.getLength())
920 aCfgThesTable[ nLang ] = aCfgSvcs;
924 /* -----------------------------22.05.01 10:43--------------------------------
926 ---------------------------------------------------------------------------*/
927 SvxLinguData_Impl::SvxLinguData_Impl( const SvxLinguData_Impl &rData ) :
928 aDisplayServiceArr (rData.aDisplayServiceArr),
929 nDisplayServices (rData.nDisplayServices),
930 aAllServiceLocales (rData.aAllServiceLocales),
931 aCfgSpellTable (rData.aCfgSpellTable),
932 aCfgHyphTable (rData.aCfgHyphTable),
933 aCfgThesTable (rData.aCfgThesTable),
934 aCfgGrammarTable (rData.aCfgGrammarTable),
935 xMSF (rData.xMSF),
936 xLinguSrvcMgr (rData.xLinguSrvcMgr)
939 /* -----------------------------22.05.01 10:43--------------------------------
941 ---------------------------------------------------------------------------*/
942 SvxLinguData_Impl & SvxLinguData_Impl::operator = (const SvxLinguData_Impl &rData)
944 xMSF = rData.xMSF;
945 xLinguSrvcMgr = rData.xLinguSrvcMgr;
946 aAllServiceLocales = rData.aAllServiceLocales;
947 aCfgSpellTable = rData.aCfgSpellTable;
948 aCfgHyphTable = rData.aCfgHyphTable;
949 aCfgThesTable = rData.aCfgThesTable;
950 aCfgGrammarTable = rData.aCfgGrammarTable;
951 aDisplayServiceArr = rData.aDisplayServiceArr;
952 nDisplayServices = rData.nDisplayServices;
953 return *this;
955 /* -----------------------------26.11.00 18:08--------------------------------
957 ---------------------------------------------------------------------------*/
958 SvxLinguData_Impl::~SvxLinguData_Impl()
961 /* -----------------------------26.11.00 19:42--------------------------------
963 ---------------------------------------------------------------------------*/
964 void SvxLinguData_Impl::SetChecked(const Sequence<OUString>& rConfiguredServices)
966 const OUString* pConfiguredServices = rConfiguredServices.getConstArray();
967 for(sal_Int32 n = 0; n < rConfiguredServices.getLength(); n++)
969 ServiceInfo_Impl* pEntry;
970 for (ULONG i = 0; i < nDisplayServices; ++i)
972 pEntry = &aDisplayServiceArr[i];
973 if (pEntry && !pEntry->bConfigured)
975 const OUString &rSrvcImplName = pConfiguredServices[n];
976 if (rSrvcImplName.getLength() &&
977 (pEntry->sSpellImplName == rSrvcImplName ||
978 pEntry->sGrammarImplName == rSrvcImplName ||
979 pEntry->sHyphImplName == rSrvcImplName ||
980 pEntry->sThesImplName == rSrvcImplName))
982 pEntry->bConfigured = sal_True;
983 break;
989 /* -----------------------------26.11.00 20:43--------------------------------
991 ---------------------------------------------------------------------------*/
993 sal_Bool SvxLinguData_Impl::AddRemove(
994 Sequence< OUString > &rConfigured,
995 const OUString &rImplName, BOOL bAdd )
997 sal_Bool bRet = sal_False; // modified?
999 INT32 nEntries = rConfigured.getLength();
1000 INT32 nPos = lcl_SeqGetEntryPos(rConfigured, rImplName);
1001 if (bAdd && nPos < 0) // add new entry
1003 rConfigured.realloc( ++nEntries );
1004 OUString *pConfigured = rConfigured.getArray();
1005 pConfigured = rConfigured.getArray();
1006 pConfigured[nEntries - 1] = rImplName;
1007 bRet = sal_True;
1009 else if (!bAdd && nPos >= 0) // remove existing entry
1011 OUString *pConfigured = rConfigured.getArray();
1012 for (INT32 i = nPos; i < nEntries - 1; ++i)
1013 pConfigured[i] = pConfigured[i + 1];
1014 rConfigured.realloc(--nEntries);
1015 bRet = sal_True;
1018 return bRet;
1022 void SvxLinguData_Impl::Reconfigure( const OUString &rDisplayName, BOOL bEnable )
1024 DBG_ASSERT( rDisplayName.getLength(), "empty DisplayName" );
1026 ServiceInfo_Impl *pInfo = 0;
1027 ServiceInfo_Impl *pTmp = 0;
1028 for (ULONG i = 0; i < nDisplayServices; ++i)
1030 pTmp = &aDisplayServiceArr[i];
1031 if (pTmp && pTmp->sDisplayName == rDisplayName)
1033 pInfo = pTmp;
1034 break;
1037 DBG_ASSERT( pInfo, "DisplayName entry not found" );
1038 if (pInfo)
1040 pInfo->bConfigured = bEnable;
1042 Sequence< Locale > aLocales;
1043 const Locale *pLocale = 0;
1044 INT32 nLocales = 0;
1045 INT32 i;
1047 // update configured spellchecker entries
1048 if (pInfo->xSpell.is())
1050 aLocales = pInfo->xSpell->getLocales();
1051 pLocale = aLocales.getConstArray();
1052 nLocales = aLocales.getLength();
1053 for (i = 0; i < nLocales; ++i)
1055 INT16 nLang = SvxLocaleToLanguage( pLocale[i] );
1056 if (!aCfgSpellTable.count( nLang ) && bEnable)
1057 aCfgSpellTable[ nLang ] = Sequence< OUString >();
1058 if (aCfgSpellTable.count( nLang ))
1059 AddRemove( aCfgSpellTable[ nLang ], pInfo->sSpellImplName, bEnable );
1063 // update configured grammar checker entries
1064 if (pInfo->xGrammar.is())
1066 aLocales = pInfo->xGrammar->getLocales();
1067 pLocale = aLocales.getConstArray();
1068 nLocales = aLocales.getLength();
1069 for (i = 0; i < nLocales; ++i)
1071 INT16 nLang = SvxLocaleToLanguage( pLocale[i] );
1072 if (!aCfgGrammarTable.count( nLang ) && bEnable)
1073 aCfgGrammarTable[ nLang ] = Sequence< OUString >();
1074 if (aCfgGrammarTable.count( nLang ))
1075 AddRemove( aCfgGrammarTable[ nLang ], pInfo->sGrammarImplName, bEnable );
1079 // update configured hyphenator entries
1080 if (pInfo->xHyph.is())
1082 aLocales = pInfo->xHyph->getLocales();
1083 pLocale = aLocales.getConstArray();
1084 nLocales = aLocales.getLength();
1085 for (i = 0; i < nLocales; ++i)
1087 INT16 nLang = SvxLocaleToLanguage( pLocale[i] );
1088 if (!aCfgHyphTable.count( nLang ) && bEnable)
1089 aCfgHyphTable[ nLang ] = Sequence< OUString >();
1090 if (aCfgHyphTable.count( nLang ))
1091 AddRemove( aCfgHyphTable[ nLang ], pInfo->sHyphImplName, bEnable );
1095 // update configured spellchecker entries
1096 if (pInfo->xThes.is())
1098 aLocales = pInfo->xThes->getLocales();
1099 pLocale = aLocales.getConstArray();
1100 nLocales = aLocales.getLength();
1101 for (i = 0; i < nLocales; ++i)
1103 INT16 nLang = SvxLocaleToLanguage( pLocale[i] );
1104 if (!aCfgThesTable.count( nLang ) && bEnable)
1105 aCfgThesTable[ nLang ] = Sequence< OUString >();
1106 if (aCfgThesTable.count( nLang ))
1107 AddRemove( aCfgThesTable[ nLang ], pInfo->sThesImplName, bEnable );
1114 // class SvxLinguTabPage -------------------------------------------------
1116 #define CBCOL_FIRST 0
1117 #define CBCOL_SECOND 1
1118 #define CBCOL_BOTH 2
1120 SvxLinguTabPage::SvxLinguTabPage( Window* pParent,
1121 const SfxItemSet& rSet ):
1123 SfxTabPage( pParent, SVX_RES( RID_SFXPAGE_LINGU ), rSet ),
1125 aLinguisticFL ( this, SVX_RES( FL_LINGUISTIC ) ),
1126 aLinguModulesFT ( this, SVX_RES( FT_LINGU_MODULES ) ),
1127 aLinguModulesCLB ( this, SVX_RES( CLB_LINGU_MODULES ) ),
1128 aLinguModulesEditPB ( this, SVX_RES( PB_LINGU_MODULES_EDIT ) ),
1129 aLinguDicsFT ( this, SVX_RES( FT_LINGU_DICS ) ),
1130 aLinguDicsCLB ( this, SVX_RES( CLB_LINGU_DICS ) ),
1131 aLinguDicsNewPB ( this, SVX_RES( PB_LINGU_DICS_NEW_DIC ) ),
1132 aLinguDicsEditPB ( this, SVX_RES( PB_LINGU_DICS_EDIT_DIC ) ),
1133 aLinguDicsDelPB ( this, SVX_RES( PB_LINGU_DICS_DEL_DIC ) ),
1134 aLinguOptionsFT ( this, SVX_RES( FT_LINGU_OPTIONS ) ),
1135 aLinguOptionsCLB ( this, SVX_RES( CLB_LINGU_OPTIONS ) ),
1136 aLinguOptionsEditPB ( this, SVX_RES( PB_LINGU_OPTIONS_EDIT ) ),
1137 aMoreDictsLink ( this, SVX_RES( FT_LINGU_OPTIONS_MOREDICTS ) ),
1138 sCapitalWords ( SVX_RES( STR_CAPITAL_WORDS ) ),
1139 sWordsWithDigits ( SVX_RES( STR_WORDS_WITH_DIGITS ) ),
1140 sCapitalization ( SVX_RES( STR_CAPITALIZATION ) ),
1141 sSpellSpecial ( SVX_RES( STR_SPELL_SPECIAL ) ),
1142 sSpellAuto ( SVX_RES( STR_SPELL_AUTO ) ),
1143 sGrammarAuto ( SVX_RES( STR_GRAMMAR_AUTO ) ),
1144 sNumMinWordlen ( SVX_RES( STR_NUM_MIN_WORDLEN ) ),
1145 sNumPreBreak ( SVX_RES( STR_NUM_PRE_BREAK ) ),
1146 sNumPostBreak ( SVX_RES( STR_NUM_POST_BREAK ) ),
1147 sHyphAuto ( SVX_RES( STR_HYPH_AUTO ) ),
1148 sHyphSpecial ( SVX_RES( STR_HYPH_SPECIAL ) ),
1150 pLinguData ( NULL )
1152 pCheckButtonData = NULL;
1154 aLinguModulesCLB.SetWindowBits( WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
1155 aLinguModulesCLB.SetHelpId(HID_CLB_LINGU_MODULES );
1156 aLinguModulesCLB.SetHighlightRange();
1157 aLinguModulesCLB.SetSelectHdl( LINK( this, SvxLinguTabPage, SelectHdl_Impl ));
1158 aLinguModulesCLB.SetDoubleClickHdl(LINK(this, SvxLinguTabPage, BoxDoubleClickHdl_Impl));
1159 aLinguModulesCLB.SetCheckButtonHdl(LINK(this, SvxLinguTabPage, BoxCheckButtonHdl_Impl));
1161 aLinguModulesEditPB.SetClickHdl( LINK( this, SvxLinguTabPage, ClickHdl_Impl ));
1162 aLinguOptionsEditPB.SetClickHdl( LINK( this, SvxLinguTabPage, ClickHdl_Impl ));
1164 aLinguDicsCLB.SetWindowBits( WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
1165 aLinguDicsCLB.SetHelpId(HID_CLB_EDIT_MODULES_DICS );
1166 aLinguDicsCLB.SetHighlightRange();
1167 aLinguDicsCLB.SetSelectHdl( LINK( this, SvxLinguTabPage, SelectHdl_Impl ));
1168 aLinguDicsCLB.SetCheckButtonHdl(LINK(this, SvxLinguTabPage, BoxCheckButtonHdl_Impl));
1170 aLinguDicsNewPB.SetClickHdl( LINK( this, SvxLinguTabPage, ClickHdl_Impl ));
1171 aLinguDicsEditPB.SetClickHdl( LINK( this, SvxLinguTabPage, ClickHdl_Impl ));
1172 aLinguDicsDelPB.SetClickHdl( LINK( this, SvxLinguTabPage, ClickHdl_Impl ));
1174 aLinguOptionsCLB.SetWindowBits( WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
1175 aLinguOptionsCLB.SetHelpId(HID_CLB_LINGU_OPTIONS );
1176 aLinguOptionsCLB.SetHighlightRange();
1177 aLinguOptionsCLB.SetSelectHdl( LINK( this, SvxLinguTabPage, SelectHdl_Impl ));
1178 aLinguOptionsCLB.SetDoubleClickHdl(LINK(this, SvxLinguTabPage, BoxDoubleClickHdl_Impl));
1180 if ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
1181 != SvtExtendedSecurityOptions::OPEN_NEVER )
1183 aMoreDictsLink.SetURL( String(
1184 RTL_CONSTASCII_STRINGPARAM( "http://extensions.go-oo.org/dictionary?cid=926386" ) ) );
1185 aMoreDictsLink.SetClickHdl( LINK( this, SvxLinguTabPage, OpenURLHdl_Impl ) );
1187 else
1188 aMoreDictsLink.Hide();
1191 // force recalculation of hash value used for checking the need of updating
1192 // because new dictionaries might be installed / downloaded.
1193 //! Thus it needs to be called now since it may infuence the supported languages
1194 //! to be reported AND the found user-dictionaries(!) as well.
1195 SvxLinguConfigUpdate::UpdateAll( sal_True );
1197 xProp = uno::Reference< XPropertySet >( SvxGetLinguPropertySet(), UNO_QUERY );
1198 xDicList = uno::Reference< XDictionaryList >( SvxGetDictionaryList(), UNO_QUERY );
1199 if (xDicList.is())
1201 // keep references to all **currently** available dictionaries,
1202 // since the diclist may get changed meanwhile (e.g. through the API).
1203 // We want the dialog to operate on the same set of dictionaries it
1204 // was started with.
1205 // Also we have to take care to not loose the last reference when
1206 // someone else removes a dictionary from the list.
1207 // removed dics will be replaced by NULL new entries be added to the end
1208 // Thus we may use indizes as consistent references.
1209 aDics = xDicList->getDictionaries();
1211 UpdateDicBox_Impl();
1213 else
1215 aLinguDicsFT.Disable();
1216 aLinguDicsCLB.Disable();
1217 aLinguDicsNewPB.Disable();
1218 aLinguDicsEditPB.Disable();
1219 aLinguDicsDelPB.Disable();
1222 const SfxSpellCheckItem* pItem = 0;
1223 SfxItemState eItemState = SFX_ITEM_UNKNOWN;
1225 eItemState = rSet.GetItemState( GetWhich( SID_ATTR_SPELL ),
1226 sal_False, (const SfxPoolItem**)&pItem );
1228 // handelt es sich um ein Default-Item?
1229 if ( eItemState == SFX_ITEM_DEFAULT )
1230 pItem = (const SfxSpellCheckItem*)&(rSet.Get( GetWhich( SID_ATTR_SPELL ) ) );
1231 else if ( eItemState == SFX_ITEM_DONTCARE )
1232 pItem = NULL;
1234 FreeResource();
1237 // -----------------------------------------------------------------------
1239 SvxLinguTabPage::~SvxLinguTabPage()
1241 if (pLinguData)
1242 delete pLinguData;
1245 //------------------------------------------------------------------------
1247 //nicht �berladen wegschmeissen
1248 sal_uInt16* SvxLinguTabPage::GetRanges()
1250 //TL???
1251 return pRanges;
1254 //------------------------------------------------------------------------
1256 SfxTabPage* SvxLinguTabPage::Create( Window* pParent,
1257 const SfxItemSet& rAttrSet )
1259 return ( new SvxLinguTabPage( pParent, rAttrSet ) );
1262 //------------------------------------------------------------------------
1264 Any lcl_Bool2Any(BOOL bVal)
1266 Any aRet(&bVal, ::getBooleanCppuType());
1267 return aRet;
1271 sal_Bool lcl_Bool2Any(Any& rVal)
1273 return *(sal_Bool*)rVal.getValue();
1277 sal_Bool SvxLinguTabPage::FillItemSet( SfxItemSet& rCoreSet )
1279 sal_Bool bModified = sal_True; // !!!!
1281 // if not HideGroups was called with GROUP_MODULES...
1282 if (aLinguModulesCLB.IsVisible())
1284 DBG_ASSERT( pLinguData, "pLinguData not yet initialized" );
1285 if (!pLinguData)
1286 pLinguData = new SvxLinguData_Impl;
1288 LangImplNameTable::const_iterator aIt;
1290 // update spellchecker configuration entries
1291 const LangImplNameTable *pTable = &pLinguData->GetSpellTable();
1292 for (aIt = pTable->begin(); aIt != pTable->end(); ++aIt)
1294 INT16 nLang = aIt->first;
1295 const Sequence< OUString > aImplNames( aIt->second );
1296 #if OSL_DEBUG_LEVEL > 1
1297 const OUString *pTmpStr;
1298 pTmpStr = aImplNames.getConstArray();
1299 #endif
1300 uno::Reference< XLinguServiceManager > xMgr( pLinguData->GetManager() );
1301 Locale aLocale( SvxCreateLocale(nLang) );
1302 if (xMgr.is())
1303 xMgr->setConfiguredServices( C2U(cSpell), aLocale, aImplNames );
1306 // update grammar checker configuration entries
1307 pTable = &pLinguData->GetGrammarTable();
1308 for (aIt = pTable->begin(); aIt != pTable->end(); ++aIt)
1310 INT16 nLang = aIt->first;
1311 const Sequence< OUString > aImplNames( aIt->second );
1312 #if OSL_DEBUG_LEVEL > 1
1313 const OUString *pTmpStr;
1314 pTmpStr = aImplNames.getConstArray();
1315 #endif
1316 uno::Reference< XLinguServiceManager > xMgr( pLinguData->GetManager() );
1317 Locale aLocale( SvxCreateLocale(nLang) );
1318 if (xMgr.is())
1319 xMgr->setConfiguredServices( C2U(cGrammar), aLocale, aImplNames );
1322 // update hyphenator configuration entries
1323 pTable = &pLinguData->GetHyphTable();
1324 for (aIt = pTable->begin(); aIt != pTable->end(); ++aIt)
1326 INT16 nLang = aIt->first;
1327 const Sequence< OUString > aImplNames( aIt->second );
1328 #if OSL_DEBUG_LEVEL > 1
1329 const OUString *pTmpStr;
1330 pTmpStr = aImplNames.getConstArray();
1331 #endif
1332 uno::Reference< XLinguServiceManager > xMgr( pLinguData->GetManager() );
1333 Locale aLocale( SvxCreateLocale(nLang) );
1334 if (xMgr.is())
1335 xMgr->setConfiguredServices( C2U(cHyph), aLocale, aImplNames );
1338 // update thesaurus configuration entries
1339 pTable = &pLinguData->GetThesTable();
1340 for (aIt = pTable->begin(); aIt != pTable->end(); ++aIt)
1342 INT16 nLang = aIt->first;
1343 const Sequence< OUString > aImplNames( aIt->second );
1344 #if OSL_DEBUG_LEVEL > 1
1345 const OUString *pTmpStr;
1346 pTmpStr = aImplNames.getConstArray();
1347 #endif
1348 uno::Reference< XLinguServiceManager > xMgr( pLinguData->GetManager() );
1349 Locale aLocale( SvxCreateLocale(nLang) );
1350 if (xMgr.is())
1351 xMgr->setConfiguredServices( C2U(cThes), aLocale, aImplNames );
1357 // activate dictionaries according to checkbox state
1359 Sequence< OUString > aActiveDics;
1360 INT32 nActiveDics = 0;
1361 ULONG nEntries = aLinguDicsCLB.GetEntryCount();
1362 for (ULONG i = 0; i < nEntries; ++i)
1364 INT32 nDics = aDics.getLength();
1365 // const uno::Reference< XDictionary > *pDic = aDics.getConstArray();
1367 aActiveDics.realloc( nDics );
1368 OUString *pActiveDic = aActiveDics.getArray();
1370 SvLBoxEntry *pEntry = aLinguDicsCLB.GetEntry( i );
1371 if (pEntry)
1373 DicUserData aData( (ULONG)pEntry->GetUserData() );
1374 if (aData.GetEntryId() < nDics)
1376 BOOL bChecked = aLinguDicsCLB.IsChecked( (USHORT) i );
1377 uno::Reference< XDictionary > xDic( aDics.getConstArray()[ i ] );
1378 if (xDic.is())
1380 if (SvxGetIgnoreAllList() == xDic)
1381 bChecked = TRUE;
1382 xDic->setActive( bChecked );
1384 if (bChecked)
1386 String aDicName( xDic->getName() );
1387 pActiveDic[ nActiveDics++ ] = aDicName;
1394 aActiveDics.realloc( nActiveDics );
1395 Any aTmp;
1396 aTmp <<= aActiveDics;
1397 SvtLinguConfig aLngCfg;
1398 aLngCfg.SetProperty( UPH_ACTIVE_DICTIONARIES, aTmp );
1401 nEntries = aLinguOptionsCLB.GetEntryCount();
1402 for (USHORT j = 0; j < nEntries; ++j)
1404 SvLBoxEntry *pEntry = aLinguOptionsCLB.GetEntry( j );
1406 OptionsUserData aData( (ULONG)pEntry->GetUserData() );
1407 String aPropName( lcl_GetPropertyName( (EID_OPTIONS) aData.GetEntryId() ) );
1409 Any aAny;
1410 if (aData.IsCheckable())
1412 BOOL bChecked = aLinguOptionsCLB.IsChecked( j );
1413 aAny <<= bChecked;
1415 else if (aData.HasNumericValue())
1417 INT16 nVal = aData.GetNumericValue();
1418 aAny <<= nVal;
1421 if (xProp.is())
1422 xProp->setPropertyValue( aPropName, aAny );
1423 aLngCfg.SetProperty( aPropName, aAny );
1426 SvLBoxEntry *pPreBreakEntry = aLinguOptionsCLB.GetEntry( (USHORT) EID_NUM_PRE_BREAK );
1427 SvLBoxEntry *pPostBreakEntry = aLinguOptionsCLB.GetEntry( (USHORT) EID_NUM_POST_BREAK );
1428 DBG_ASSERT( pPreBreakEntry, "NULL Pointer" );
1429 DBG_ASSERT( pPostBreakEntry, "NULL Pointer" );
1430 if (pPreBreakEntry && pPostBreakEntry)
1432 OptionsUserData aPreBreakData( (ULONG)pPreBreakEntry->GetUserData() );
1433 OptionsUserData aPostBreakData( (ULONG)pPostBreakEntry->GetUserData() );
1434 if ( aPreBreakData.IsModified() || aPostBreakData.IsModified() )
1436 SfxHyphenRegionItem aHyp( GetWhich( SID_ATTR_HYPHENREGION ) );
1437 aHyp.GetMinLead() = (UINT8) aPreBreakData.GetNumericValue();
1438 aHyp.GetMinTrail() = (UINT8) aPostBreakData.GetNumericValue();
1439 rCoreSet.Put( aHyp );
1444 // automatic spell checking
1445 BOOL bNewAutoCheck = aLinguOptionsCLB.IsChecked( (USHORT) EID_SPELL_AUTO );
1446 const SfxPoolItem* pOld = GetOldItem( rCoreSet, SID_AUTOSPELL_CHECK );
1447 if ( !pOld || ( (SfxBoolItem*)pOld )->GetValue() != bNewAutoCheck )
1449 rCoreSet.Put( SfxBoolItem( GetWhich( SID_AUTOSPELL_CHECK ),
1450 bNewAutoCheck ) );
1451 bModified |= sal_True;
1454 return bModified;
1457 // ----------------------------------------------------------------------
1459 ULONG SvxLinguTabPage::GetDicUserData( const uno::Reference< XDictionary > &rxDic, USHORT nIdx )
1461 ULONG nRes = 0;
1462 DBG_ASSERT( rxDic.is(), "dictionary not supplied" );
1463 if (rxDic.is())
1465 uno::Reference< frame::XStorable > xStor( rxDic, UNO_QUERY );
1467 // ULONG nUserData = 0;
1468 BOOL bChecked = rxDic->isActive();
1469 BOOL bEditable = !xStor.is() || !xStor->isReadonly();
1470 BOOL bDeletable = bEditable;
1471 // BOOL bNegativ = rxDic->getDictionaryType() == DictionaryType_NEGATIVE;
1473 nRes = DicUserData( nIdx,
1474 bChecked, bEditable, bDeletable ).GetUserData();
1476 return nRes;
1480 void SvxLinguTabPage::AddDicBoxEntry(
1481 const uno::Reference< XDictionary > &rxDic,
1482 USHORT nIdx )
1484 aLinguDicsCLB.SetUpdateMode(FALSE);
1486 String aTxt( ::GetDicInfoStr( rxDic->getName(),
1487 SvxLocaleToLanguage( rxDic->getLocale() ),
1488 DictionaryType_NEGATIVE == rxDic->getDictionaryType() ) );
1489 aLinguDicsCLB.InsertEntry( aTxt, (USHORT)LISTBOX_APPEND ); // append at end
1490 SvLBoxEntry* pEntry = aLinguDicsCLB.GetEntry( aLinguDicsCLB.GetEntryCount() - 1 );
1491 DBG_ASSERT( pEntry, "failed to add entry" );
1492 if (pEntry)
1494 DicUserData aData( GetDicUserData( rxDic, nIdx ) );
1495 pEntry->SetUserData( (void *) aData.GetUserData() );
1496 lcl_SetCheckButton( pEntry, aData.IsChecked() );
1499 aLinguDicsCLB.SetUpdateMode(TRUE);
1502 // ----------------------------------------------------------------------
1504 void SvxLinguTabPage::UpdateDicBox_Impl()
1506 aLinguDicsCLB.SetUpdateMode(FALSE);
1507 aLinguDicsCLB.Clear();
1509 INT32 nDics = aDics.getLength();
1510 const uno::Reference< XDictionary > *pDic = aDics.getConstArray();
1511 for (INT32 i = 0; i < nDics; ++i)
1513 const uno::Reference< XDictionary > &rDic = pDic[i];
1514 if (rDic.is())
1515 AddDicBoxEntry( rDic, (USHORT)i );
1518 aLinguDicsCLB.SetUpdateMode(TRUE);
1521 // ----------------------------------------------------------------------
1523 void SvxLinguTabPage::UpdateModulesBox_Impl()
1525 if (pLinguData)
1527 const ServiceInfoArr &rAllDispSrvcArr = pLinguData->GetDisplayServiceArray();
1528 const ULONG nDispSrvcCount = pLinguData->GetDisplayServiceCount();
1530 aLinguModulesCLB.Clear();
1532 for (USHORT i = 0; i < nDispSrvcCount; ++i)
1534 const ServiceInfo_Impl &rInfo = rAllDispSrvcArr[i];
1535 aLinguModulesCLB.InsertEntry( rInfo.sDisplayName, (USHORT)LISTBOX_APPEND );
1536 SvLBoxEntry* pEntry = aLinguModulesCLB.GetEntry(i);
1537 pEntry->SetUserData( (void *) &rInfo );
1538 aLinguModulesCLB.CheckEntryPos( i, rInfo.bConfigured );
1540 aLinguModulesEditPB.Enable( nDispSrvcCount > 0 );
1544 //------------------------------------------------------------------------
1546 void SvxLinguTabPage::Reset( const SfxItemSet& rSet )
1548 // if not HideGroups was called with GROUP_MODULES...
1549 if (aLinguModulesCLB.IsVisible())
1551 if (!pLinguData)
1552 pLinguData = new SvxLinguData_Impl;
1553 UpdateModulesBox_Impl();
1558 // get data from configuration
1561 SvtLinguConfig aLngCfg;
1563 aLinguOptionsCLB.SetUpdateMode(FALSE);
1564 aLinguOptionsCLB.Clear();
1566 SvLBoxTreeList *pModel = aLinguOptionsCLB.GetModel();
1567 SvLBoxEntry* pEntry = NULL;
1569 INT16 nVal = 0;
1570 BOOL bVal = FALSE;
1571 ULONG nUserData = 0;
1573 pEntry = CreateEntry( sSpellAuto, CBCOL_FIRST );
1574 aLngCfg.GetProperty( C2U(UPN_IS_SPELL_AUTO) ) >>= bVal;
1575 const SfxPoolItem* pItem = GetItem( rSet, SID_AUTOSPELL_CHECK );
1576 if (pItem)
1577 bVal = ((SfxBoolItem *) pItem)->GetValue();
1578 nUserData = OptionsUserData( EID_SPELL_AUTO, FALSE, 0, TRUE, bVal).GetUserData();
1579 pEntry->SetUserData( (void *)nUserData );
1580 pModel->Insert( pEntry );
1581 lcl_SetCheckButton( pEntry, bVal );
1583 pEntry = CreateEntry( sGrammarAuto, CBCOL_FIRST );
1584 aLngCfg.GetProperty( C2U(UPN_IS_GRAMMAR_AUTO) ) >>= bVal;
1585 // const SfxPoolItem* pItem = GetItem( rSet, SID_AUTOSPELL_CHECK );
1586 // if (pItem)
1587 // bVal = ((SfxBoolItem *) pItem)->GetValue();
1588 nUserData = OptionsUserData( EID_GRAMMAR_AUTO, FALSE, 0, TRUE, bVal).GetUserData();
1589 pEntry->SetUserData( (void *)nUserData );
1590 pModel->Insert( pEntry );
1591 lcl_SetCheckButton( pEntry, bVal );
1593 pEntry = CreateEntry( sCapitalWords, CBCOL_FIRST );
1594 aLngCfg.GetProperty( C2U(UPN_IS_SPELL_UPPER_CASE) ) >>= bVal;
1595 nUserData = OptionsUserData( EID_CAPITAL_WORDS, FALSE, 0, TRUE, bVal).GetUserData();
1596 pEntry->SetUserData( (void *)nUserData );
1597 pModel->Insert( pEntry );
1598 lcl_SetCheckButton( pEntry, bVal );
1600 pEntry = CreateEntry( sWordsWithDigits, CBCOL_FIRST );
1601 aLngCfg.GetProperty( C2U(UPN_IS_SPELL_WITH_DIGITS) ) >>= bVal;
1602 nUserData = OptionsUserData( EID_WORDS_WITH_DIGITS, FALSE, 0, TRUE, bVal).GetUserData();
1603 pEntry->SetUserData( (void *)nUserData );
1604 pModel->Insert( pEntry );
1605 lcl_SetCheckButton( pEntry, bVal );
1607 pEntry = CreateEntry( sCapitalization, CBCOL_FIRST );
1608 aLngCfg.GetProperty( C2U(UPN_IS_SPELL_CAPITALIZATION) ) >>= bVal;
1609 nUserData = OptionsUserData( EID_CAPITALIZATION, FALSE, 0, TRUE, bVal).GetUserData();
1610 pEntry->SetUserData( (void *)nUserData );
1611 pModel->Insert( pEntry );
1612 lcl_SetCheckButton( pEntry, bVal );
1614 pEntry = CreateEntry( sSpellSpecial, CBCOL_FIRST );
1615 aLngCfg.GetProperty( C2U(UPN_IS_SPELL_SPECIAL) ) >>= bVal;
1616 nUserData = OptionsUserData( EID_SPELL_SPECIAL, FALSE, 0, TRUE, bVal).GetUserData();
1617 pEntry->SetUserData( (void *)nUserData );
1618 pModel->Insert( pEntry );
1619 lcl_SetCheckButton( pEntry, bVal );
1621 pEntry = CreateEntry( sNumMinWordlen, CBCOL_SECOND );
1622 aLngCfg.GetProperty( C2U(UPN_HYPH_MIN_WORD_LENGTH) ) >>= nVal;
1623 nUserData = OptionsUserData( EID_NUM_MIN_WORDLEN, TRUE, (USHORT)nVal, FALSE, FALSE).GetUserData();
1624 pEntry->SetUserData( (void *)nUserData );
1625 pModel->Insert( pEntry );
1627 const SfxHyphenRegionItem *pHyp = NULL;
1628 USHORT nWhich = GetWhich( SID_ATTR_HYPHENREGION );
1629 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
1630 pHyp = &( (const SfxHyphenRegionItem &) rSet.Get( nWhich ) );
1632 pEntry = CreateEntry( sNumPreBreak, CBCOL_SECOND );
1633 aLngCfg.GetProperty( C2U(UPN_HYPH_MIN_LEADING) ) >>= nVal;
1634 if (pHyp)
1635 nVal = (INT16) pHyp->GetMinLead();
1636 nUserData = OptionsUserData( EID_NUM_PRE_BREAK, TRUE, (USHORT)nVal, FALSE, FALSE).GetUserData();
1637 pEntry->SetUserData( (void *)nUserData );
1638 pModel->Insert( pEntry );
1640 pEntry = CreateEntry( sNumPostBreak, CBCOL_SECOND );
1641 aLngCfg.GetProperty( C2U(UPN_HYPH_MIN_TRAILING) ) >>= nVal;
1642 if (pHyp)
1643 nVal = (INT16) pHyp->GetMinTrail();
1644 nUserData = OptionsUserData( EID_NUM_POST_BREAK, TRUE, (USHORT)nVal, FALSE, FALSE).GetUserData();
1645 pEntry->SetUserData( (void *)nUserData );
1646 pModel->Insert( pEntry );
1648 pEntry = CreateEntry( sHyphAuto, CBCOL_FIRST );
1649 aLngCfg.GetProperty( C2U(UPN_IS_HYPH_AUTO) ) >>= bVal;
1650 nUserData = OptionsUserData( EID_HYPH_AUTO, FALSE, 0, TRUE, bVal).GetUserData();
1651 pEntry->SetUserData( (void *)nUserData );
1652 pModel->Insert( pEntry );
1653 lcl_SetCheckButton( pEntry, bVal );
1655 pEntry = CreateEntry( sHyphSpecial, CBCOL_FIRST );
1656 aLngCfg.GetProperty( C2U(UPN_IS_HYPH_SPECIAL) ) >>= bVal;
1657 nUserData = OptionsUserData( EID_HYPH_SPECIAL, FALSE, 0, TRUE, bVal).GetUserData();
1658 pEntry->SetUserData( (void *)nUserData );
1659 pModel->Insert( pEntry );
1660 lcl_SetCheckButton( pEntry, bVal );
1662 aLinguOptionsCLB.SetUpdateMode(TRUE);
1665 // -----------------------------------------------------------------------
1667 IMPL_LINK( SvxLinguTabPage, BoxDoubleClickHdl_Impl, SvTreeListBox *, pBox )
1669 if (pBox == &aLinguModulesCLB)
1671 //! in order to avoid a bug causing a GPF when double clicking
1672 //! on a module entry and exiting the "Edit Modules" dialog
1673 //! after that.
1674 Application::PostUserEvent( LINK(
1675 this, SvxLinguTabPage, PostDblClickHdl_Impl ) );
1677 else if (pBox == &aLinguOptionsCLB)
1679 ClickHdl_Impl(&aLinguOptionsEditPB);
1681 return 0;
1684 // -----------------------------------------------------------------------
1686 IMPL_LINK( SvxLinguTabPage, PostDblClickHdl_Impl, SvTreeListBox *, EMPTYARG )
1688 ClickHdl_Impl(&aLinguModulesEditPB);
1689 return 0;
1692 // -----------------------------------------------------------------------
1694 IMPL_LINK( SvxLinguTabPage, OpenURLHdl_Impl, svt::FixedHyperlink *, EMPTYARG )
1696 ::rtl::OUString sURL( aMoreDictsLink.GetURL() );
1697 lcl_OpenURL( sURL );
1698 return 0;
1701 // -----------------------------------------------------------------------
1703 IMPL_LINK( SvxLinguTabPage, BoxCheckButtonHdl_Impl, SvTreeListBox *, pBox )
1705 if (pBox == &aLinguModulesCLB)
1707 DBG_ASSERT( pLinguData, "NULL pointer, LinguData missing" );
1708 USHORT nPos = aLinguModulesCLB.GetSelectEntryPos();
1709 if (nPos != LISTBOX_ENTRY_NOTFOUND && pLinguData)
1711 pLinguData->Reconfigure( aLinguModulesCLB.GetText( nPos ),
1712 aLinguModulesCLB.IsChecked( nPos ) );
1715 else if (pBox == &aLinguDicsCLB)
1717 USHORT nPos = aLinguDicsCLB.GetSelectEntryPos();
1718 if (nPos != LISTBOX_ENTRY_NOTFOUND)
1720 const uno::Reference< XDictionary > &rDic = aDics.getConstArray()[ nPos ];
1721 if (SvxGetIgnoreAllList() == rDic)
1723 SvLBoxEntry* pEntry = aLinguDicsCLB.GetEntry( nPos );
1724 if (pEntry)
1725 lcl_SetCheckButton( pEntry, TRUE );
1729 return 0;
1732 // -----------------------------------------------------------------------
1734 IMPL_LINK( SvxLinguTabPage, ClickHdl_Impl, PushButton *, pBtn )
1736 if (&aLinguModulesEditPB == pBtn)
1738 if (!pLinguData)
1739 pLinguData = new SvxLinguData_Impl;
1741 SvxLinguData_Impl aOldLinguData( *pLinguData );
1742 SvxEditModulesDlg aDlg( this, *pLinguData );
1743 if (aDlg.Execute() != RET_OK)
1744 *pLinguData = aOldLinguData;
1746 // evaluate new status of 'bConfigured' flag
1747 ULONG nLen = pLinguData->GetDisplayServiceCount();
1748 for (ULONG i = 0; i < nLen; ++i)
1749 pLinguData->GetDisplayServiceArray()[i].bConfigured = FALSE;
1750 const Locale* pAllLocales = pLinguData->GetAllSupportedLocales().getConstArray();
1751 INT32 nLocales = pLinguData->GetAllSupportedLocales().getLength();
1752 for (INT32 k = 0; k < nLocales; ++k)
1754 INT16 nLang = SvxLocaleToLanguage( pAllLocales[k] );
1755 if (pLinguData->GetSpellTable().count( nLang ))
1756 pLinguData->SetChecked( pLinguData->GetSpellTable()[ nLang ] );
1757 if (pLinguData->GetGrammarTable().count( nLang ))
1758 pLinguData->SetChecked( pLinguData->GetGrammarTable()[ nLang ] );
1759 if (pLinguData->GetHyphTable().count( nLang ))
1760 pLinguData->SetChecked( pLinguData->GetHyphTable()[ nLang ] );
1761 if (pLinguData->GetThesTable().count( nLang ))
1762 pLinguData->SetChecked( pLinguData->GetThesTable()[ nLang ] );
1765 // show new status of modules
1766 UpdateModulesBox_Impl();
1768 else if (&aLinguDicsNewPB == pBtn)
1770 uno::Reference< XSpellChecker1 > xSpellChecker1;
1771 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1772 if(pFact)
1774 AbstractSvxNewDictionaryDialog* aDlg = pFact->CreateSvxNewDictionaryDialog( this, xSpellChecker1, RID_SFXDLG_NEWDICT );
1775 DBG_ASSERT(aDlg, "Dialogdiet fail!");
1776 uno::Reference< XDictionary > xNewDic;
1777 if ( aDlg->Execute() == RET_OK )
1778 xNewDic = uno::Reference< XDictionary >( aDlg->GetNewDictionary(), UNO_QUERY );
1779 if ( xNewDic.is() )
1781 // add new dics to the end
1782 INT32 nLen = aDics.getLength();
1783 aDics.realloc( nLen + 1 );
1785 aDics.getArray()[ nLen ] = xNewDic;
1787 AddDicBoxEntry( xNewDic, (USHORT) nLen );
1789 delete aDlg; //add by CHINA001
1792 else if (&aLinguDicsEditPB == pBtn)
1794 SvLBoxEntry *pEntry = aLinguDicsCLB.GetCurEntry();
1795 if (pEntry)
1797 DicUserData aData( (ULONG) pEntry->GetUserData() );
1798 USHORT nDicPos = aData.GetEntryId();
1799 INT32 nDics = aDics.getLength();
1800 if (nDicPos < nDics)
1802 uno::Reference< XDictionary > xDic;
1803 xDic = aDics.getConstArray()[ nDicPos ];
1804 if (xDic.is())
1806 uno::Reference< XSpellChecker1 > xSpellChecker1;
1807 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1808 if(pFact)
1810 VclAbstractDialog* aDlg = pFact->CreateSvxEditDictionaryDialog( this, xDic->getName(), xSpellChecker1, RID_SFXDLG_EDITDICT );
1811 DBG_ASSERT(aDlg, "Dialogdiet fail!");
1812 aDlg->Execute();
1813 delete aDlg;
1819 else if (&aLinguDicsDelPB == pBtn)
1821 if ( RET_NO ==
1822 QueryBox( this, SVX_RES( RID_SFXQB_DELDICT ) ).Execute() )
1823 return 0;
1825 SvLBoxEntry *pEntry = aLinguDicsCLB.GetCurEntry();
1826 if (pEntry)
1828 DicUserData aData( (ULONG) pEntry->GetUserData() );
1829 USHORT nDicPos = aData.GetEntryId();
1830 INT32 nDics = aDics.getLength();
1831 if (nDicPos < nDics)
1833 uno::Reference< XDictionary > xDic;
1834 xDic = aDics.getConstArray()[ nDicPos ];
1835 if (xDic.is())
1837 if (SvxGetIgnoreAllList() == xDic)
1838 xDic->clear();
1839 else
1841 if (xDicList.is())
1842 xDicList->removeDictionary( xDic );
1844 uno::Reference< frame::XStorable > xStor( xDic, UNO_QUERY );
1845 if ( xStor->hasLocation() && !xStor->isReadonly() )
1847 String sURL = xStor->getLocation();
1848 INetURLObject aObj(sURL);
1849 DBG_ASSERT( aObj.GetProtocol() == INET_PROT_FILE,
1850 "non-file URLs cannot be deleted" );
1851 if ( aObj.GetProtocol() == INET_PROT_FILE )
1853 KillFile_Impl( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1857 aDics.getArray()[ nDicPos ] = 0;
1859 // remove entry from checklistbox
1860 ULONG nCnt = aLinguDicsCLB.GetEntryCount();
1861 for (ULONG i = 0; i < nCnt; ++i)
1863 SvLBoxEntry *pDicEntry = aLinguDicsCLB.GetEntry( i );
1864 DBG_ASSERT( pDicEntry, "missing entry" );
1865 if (pDicEntry)
1867 DicUserData aDicData( (ULONG) pDicEntry->GetUserData() );
1868 if (aDicData.GetEntryId() == nDicPos )
1870 aLinguDicsCLB.RemoveEntry( (USHORT) i );
1871 break;
1875 DBG_ASSERT( nCnt > aLinguDicsCLB.GetEntryCount(),
1876 "remove failed ?");
1882 else if (&aLinguOptionsEditPB == pBtn)
1884 SvLBoxEntry *pEntry = aLinguOptionsCLB.GetCurEntry();
1885 DBG_ASSERT( pEntry, "no entry selected" );
1886 if (pEntry)
1888 long nVal = -1;
1889 OptionsUserData aData( (ULONG)pEntry->GetUserData() );
1890 if(aData.HasNumericValue())
1892 int nRID = -1;
1893 switch (aData.GetEntryId())
1895 case EID_NUM_PRE_BREAK : nRID = STR_NUM_PRE_BREAK_DLG; break;
1896 case EID_NUM_POST_BREAK : nRID = STR_NUM_POST_BREAK_DLG; break;
1897 case EID_NUM_MIN_WORDLEN: nRID = STR_NUM_MIN_WORDLEN_DLG; break;
1898 default:
1899 DBG_ERROR( "unexpected case" );
1902 OptionsBreakSet aDlg( this, nRID );
1903 aDlg.GetNumericFld().SetValue( aData.GetNumericValue() );
1904 if (RET_OK == aDlg.Execute() )
1906 nVal = static_cast<long>(aDlg.GetNumericFld().GetValue());
1907 if (-1 != nVal && aData.GetNumericValue() != nVal)
1909 aData.SetNumericValue( (BYTE)nVal ); //! sets IsModified !
1910 pEntry->SetUserData( (void *) aData.GetUserData() );
1911 aLinguOptionsCLB.Invalidate();
1917 else
1919 DBG_ERROR( "pBtn unexpected value" );
1922 return 0;
1925 // -----------------------------------------------------------------------
1927 IMPL_LINK( SvxLinguTabPage, SelectHdl_Impl, SvxCheckListBox *, pBox )
1929 if (&aLinguModulesCLB == pBox)
1932 else if (&aLinguDicsCLB == pBox)
1934 SvLBoxEntry *pEntry = pBox->GetCurEntry();
1935 if (pEntry)
1937 DicUserData aData( (ULONG) pEntry->GetUserData() );
1939 // always allow to edit (i.e. at least view the content of the dictionary)
1940 aLinguDicsEditPB.Enable( true/*aData.IsEditable()*/ );
1941 aLinguDicsDelPB .Enable( aData.IsDeletable() );
1944 else if (&aLinguOptionsCLB == pBox)
1946 SvLBoxEntry *pEntry = pBox->GetCurEntry();
1947 if (pEntry)
1949 OptionsUserData aData( (ULONG) pEntry->GetUserData() );
1950 aLinguOptionsEditPB.Enable( aData.HasNumericValue() );
1953 else
1955 DBG_ERROR( "pBox unexpected value" );
1958 return 0;
1961 // -----------------------------------------------------------------------
1963 SvLBoxEntry* SvxLinguTabPage::CreateEntry( String& rTxt, USHORT nCol )
1965 SvLBoxEntry* pEntry = new SvLBoxEntry;
1967 if( !pCheckButtonData )
1968 pCheckButtonData = new SvLBoxButtonData( &aLinguOptionsCLB );
1970 String sEmpty;
1971 if (CBCOL_FIRST == nCol)
1972 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
1973 if (CBCOL_SECOND == nCol)
1974 pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) ); // Leerspalte
1975 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0)); // Sonst Puff!
1976 pEntry->AddItem( new BrwString_Impl( pEntry, 0, rTxt ) );
1978 return pEntry;
1981 // -----------------------------------------------------------------------
1983 void SvxLinguTabPage::HideGroups( sal_uInt16 nGrp )
1985 if ( 0 != ( GROUP_MODULES & nGrp ) )
1987 aLinguModulesFT.Hide();
1988 aLinguModulesCLB.Hide();
1989 aLinguModulesEditPB.Hide();
1991 // reposition / resize remaining controls
1992 long nDeltaY = aLinguDicsFT.GetPosPixel().Y() -
1993 aLinguModulesFT.GetPosPixel().Y();
1994 DBG_ASSERT( nDeltaY >= 0, "move/resize value is negative" );
1995 Point aPos;
1997 aPos = aLinguDicsFT.GetPosPixel();
1998 aPos.Y() -= nDeltaY;
1999 aLinguDicsFT.SetPosPixel( aPos );
2000 aPos = aLinguDicsCLB.GetPosPixel();
2001 aPos.Y() -= nDeltaY;
2002 aLinguDicsCLB.SetPosPixel( aPos );
2003 aPos = aLinguDicsNewPB.GetPosPixel();
2004 aPos.Y() -= nDeltaY;
2005 aLinguDicsNewPB.SetPosPixel( aPos );
2006 aPos = aLinguDicsEditPB.GetPosPixel();
2007 aPos.Y() -= nDeltaY;
2008 aLinguDicsEditPB.SetPosPixel( aPos );
2009 aPos = aLinguDicsDelPB.GetPosPixel();
2010 aPos.Y() -= nDeltaY;
2011 aLinguDicsDelPB.SetPosPixel( aPos );
2013 aPos = aLinguOptionsFT.GetPosPixel();
2014 aPos.Y() -= nDeltaY;
2015 aLinguOptionsFT.SetPosPixel( aPos );
2016 aPos = aLinguOptionsCLB.GetPosPixel();
2017 aPos.Y() -= nDeltaY;
2018 aLinguOptionsCLB.SetPosPixel( aPos );
2019 aPos = aLinguOptionsEditPB.GetPosPixel();
2020 aPos.Y() -= nDeltaY;
2021 aLinguOptionsEditPB.SetPosPixel( aPos );
2023 Size aSize( aLinguOptionsCLB.GetSizePixel() );
2024 aSize.Height() += nDeltaY;
2025 aLinguOptionsCLB.SetSizePixel( aSize );
2027 if ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
2028 != SvtExtendedSecurityOptions::OPEN_NEVER )
2030 aSize = GetOutputSizePixel();
2031 aSize.Height() += ( aMoreDictsLink.GetSizePixel().Height() * 11 / 8 );
2032 SetSizePixel( aSize );
2033 aMoreDictsLink.Show();
2037 /*--------------------------------------------------
2038 --------------------------------------------------*/
2040 SvxEditModulesDlg::SvxEditModulesDlg(Window* pParent, SvxLinguData_Impl& rData) :
2041 ModalDialog( pParent, SVX_RES(RID_SVXDLG_EDIT_MODULES ) ),
2042 aModulesFL ( this, SVX_RES( FL_EDIT_MODULES_OPTIONS ) ),
2043 aLanguageFT ( this, SVX_RES( FT_EDIT_MODULES_LANGUAGE ) ),
2044 aLanguageLB ( this, SVX_RES( LB_EDIT_MODULES_LANGUAGE ), FALSE ),
2045 aModulesCLB ( this, SVX_RES( CLB_EDIT_MODULES_MODULES ) ),
2046 aPrioUpPB ( this, SVX_RES( PB_EDIT_MODULES_PRIO_UP ) ),
2047 aPrioDownPB ( this, SVX_RES( PB_EDIT_MODULES_PRIO_DOWN ) ),
2048 aBackPB ( this, SVX_RES( PB_EDIT_MODULES_PRIO_BACK ) ),
2049 aMoreDictsLink ( this, SVX_RES( FT_EDIT_MODULES_NEWDICTSLINK ) ),
2050 aButtonsFL ( this, SVX_RES( FL_EDIT_MODULES_BUTTONS ) ),
2051 aHelpPB ( this, SVX_RES( PB_HELP ) ),
2052 aClosePB ( this, SVX_RES( PB_OK ) ),
2053 sSpell ( SVX_RES( ST_SPELL ) ),
2054 sHyph ( SVX_RES( ST_HYPH ) ),
2055 sThes ( SVX_RES( ST_THES ) ),
2056 sGrammar ( SVX_RES( ST_GRAMMAR ) ),
2057 rLinguData ( rData )
2059 pCheckButtonData = NULL;
2060 FreeResource();
2062 pDefaultLinguData = new SvxLinguData_Impl( rLinguData );
2064 aModulesCLB.SetWindowBits( WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
2065 aModulesCLB.SetHighlightRange();
2066 aModulesCLB.SetHelpId(HID_CLB_EDIT_MODULES_MODULES );
2067 aModulesCLB.SetSelectHdl( LINK( this, SvxEditModulesDlg, SelectHdl_Impl ));
2068 aModulesCLB.SetCheckButtonHdl( LINK( this, SvxEditModulesDlg, BoxCheckButtonHdl_Impl) );
2070 aClosePB .SetClickHdl( LINK( this, SvxEditModulesDlg, ClickHdl_Impl ));
2071 aPrioUpPB .SetClickHdl( LINK( this, SvxEditModulesDlg, UpDownHdl_Impl ));
2072 aPrioDownPB.SetClickHdl( LINK( this, SvxEditModulesDlg, UpDownHdl_Impl ));
2073 aBackPB .SetClickHdl( LINK( this, SvxEditModulesDlg, BackHdl_Impl ));
2074 // in case of not installed language modules
2075 aPrioUpPB .Enable( FALSE );
2076 aPrioDownPB.Enable( FALSE );
2078 if ( SvtExtendedSecurityOptions().GetOpenHyperlinkMode()
2079 != SvtExtendedSecurityOptions::OPEN_NEVER )
2081 aMoreDictsLink.SetURL( String(
2082 RTL_CONSTASCII_STRINGPARAM( "http://extensions.go-oo.org/dictionary?cid=926386" ) ) );
2083 aMoreDictsLink.SetClickHdl( LINK( this, SvxEditModulesDlg, OpenURLHdl_Impl ) );
2085 else
2087 aMoreDictsLink.Hide();
2088 long nPos = aMoreDictsLink.GetPosPixel().Y() + aMoreDictsLink.GetSizePixel().Height();
2089 Size aSize = aModulesCLB.GetSizePixel();
2090 aSize.Height() += ( nPos - ( aModulesCLB.GetPosPixel().Y() + aSize.Height() ) );
2091 aModulesCLB.SetSizePixel( aSize );
2095 //fill language box
2097 Sequence< INT16 > aAvailLang;
2098 uno::Reference< XAvailableLocales > xAvail( rLinguData.GetManager(), UNO_QUERY );
2099 if (xAvail.is())
2101 aAvailLang = lcl_LocaleSeqToLangSeq(
2102 xAvail->getAvailableLocales( C2U(cSpell) ) );
2104 const Sequence< Locale >& rLoc = rLinguData.GetAllSupportedLocales();
2105 const Locale* pLocales = rLoc.getConstArray();
2106 aLanguageLB.Clear();
2107 for(long i = 0; i < rLoc.getLength(); i++)
2109 INT16 nLang = SvxLocaleToLanguage( pLocales[i] );
2110 aLanguageLB.InsertLanguage( nLang, lcl_SeqHasLang( aAvailLang, nLang ) );
2112 LanguageType eSysLang = MsLangId::getSystemLanguage();
2113 aLanguageLB.SelectLanguage( eSysLang );
2114 if(!aLanguageLB.IsLanguageSelected( eSysLang ) )
2115 aLanguageLB.SelectEntryPos(0);
2117 aLanguageLB.SetSelectHdl( LINK( this, SvxEditModulesDlg, LangSelectHdl_Impl ));
2118 LangSelectHdl_Impl(&aLanguageLB);
2122 SvxEditModulesDlg::~SvxEditModulesDlg()
2124 delete pDefaultLinguData;
2128 SvLBoxEntry* SvxEditModulesDlg::CreateEntry( String& rTxt, USHORT nCol )
2130 SvLBoxEntry* pEntry = new SvLBoxEntry;
2131 if( !pCheckButtonData )
2133 pCheckButtonData = new SvLBoxButtonData( &aModulesCLB );
2134 pCheckButtonData->SetLink( aModulesCLB.GetCheckButtonHdl() );
2137 String sEmpty;
2138 if (CBCOL_FIRST == nCol)
2139 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox, 0, pCheckButtonData ) );
2140 if (CBCOL_SECOND == nCol)
2141 pEntry->AddItem( new SvLBoxString( pEntry, 0, sEmpty) ); // Leerspalte
2142 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0)); // Sonst Puff!
2143 pEntry->AddItem( new BrwStringDic_Impl( pEntry, 0, rTxt ) );
2145 return pEntry;
2148 /* ---------------------------------------------------------------------------
2150 ---------------------------------------------------------------------------*/
2151 IMPL_LINK( SvxEditModulesDlg, SelectHdl_Impl, SvxCheckListBox *, pBox )
2153 if (&aModulesCLB == pBox)
2155 sal_Bool bDisableUp = sal_True;
2156 sal_Bool bDisableDown = sal_True;
2157 SvLBoxEntry *pEntry = pBox->GetCurEntry();
2158 if (pEntry)
2160 ModuleUserData_Impl* pData = (ModuleUserData_Impl*)pEntry->GetUserData();
2161 if(!pData->IsParent() && pData->GetType() != TYPE_HYPH)
2163 USHORT nCurPos = pBox->GetSelectEntryPos();
2164 if(nCurPos < pBox->GetEntryCount() - 1)
2166 bDisableDown = ((ModuleUserData_Impl*)pBox->
2167 GetEntry(nCurPos + 1)->GetUserData())->IsParent();
2169 if(nCurPos > 1)
2171 bDisableUp = ((ModuleUserData_Impl*)pBox->
2172 GetEntry(nCurPos - 1)->GetUserData())->IsParent();
2175 aPrioUpPB.Enable(!bDisableUp);
2176 aPrioDownPB.Enable(!bDisableDown);
2179 else
2181 DBG_ERROR( "pBox unexpected value" );
2184 return 0;
2186 /* -----------------------------28.05.01 11:00--------------------------------
2188 ---------------------------------------------------------------------------*/
2189 IMPL_LINK( SvxEditModulesDlg, BoxCheckButtonHdl_Impl, SvTreeListBox *, pBox )
2191 // if (pBox == (SvTreeListBox *) &aModulesCLB)
2192 // {
2193 pBox = &aModulesCLB;
2194 SvLBoxEntry *pCurEntry = pBox->GetCurEntry();
2195 if (pCurEntry)
2197 ModuleUserData_Impl* pData = (ModuleUserData_Impl *)
2198 pCurEntry->GetUserData();
2199 if (!pData->IsParent() && pData->GetType() == TYPE_HYPH)
2201 // make hyphenator checkboxes function as radio-buttons
2202 // (at most one box may be checked)
2203 SvLBoxEntry *pEntry = pBox->First();
2204 while (pEntry)
2206 pData = (ModuleUserData_Impl *) pEntry->GetUserData();
2207 if (!pData->IsParent() &&
2208 pData->GetType() == TYPE_HYPH &&
2209 pEntry != pCurEntry)
2211 lcl_SetCheckButton( pEntry, FALSE );
2212 pBox->InvalidateEntry( pEntry );
2214 pEntry = pBox->Next( pEntry );
2218 // }
2219 return 0;
2221 /* -----------------------------27.11.00 14:00--------------------------------
2223 ---------------------------------------------------------------------------*/
2224 OUString lcl_GetServiceName(BYTE nType)
2226 switch(nType)
2228 case TYPE_SPELL : return C2U(cSpell);
2229 case TYPE_GRAMMAR : return C2U(cGrammar);
2230 case TYPE_HYPH : return C2U(cHyph);
2231 case TYPE_THES : return C2U(cThes);
2233 return OUString();
2237 IMPL_LINK( SvxEditModulesDlg, LangSelectHdl_Impl, ListBox *, pBox )
2239 LanguageType eCurLanguage = aLanguageLB.GetSelectLanguage();
2240 static Locale aLastLocale;
2241 Locale aCurLocale;
2242 SvxLanguageToLocale(aCurLocale, eCurLanguage);
2243 SvLBoxTreeList *pModel = aModulesCLB.GetModel();
2244 // uno::Reference<XLinguServiceManager>& xMgr = rLinguData.GetManager();
2246 if (pBox)
2248 // save old probably changed settings
2249 // before switching to new language entries
2251 INT16 nLang = SvxLocaleToLanguage( aLastLocale );
2253 sal_Int32 nStart = 0, nLocalIndex = 0;
2254 Sequence< OUString > aChange;
2255 sal_Bool bChanged = FALSE;
2256 for(USHORT i = 0; i < aModulesCLB.GetEntryCount(); i++)
2258 SvLBoxEntry *pEntry = aModulesCLB.GetEntry(i);
2259 ModuleUserData_Impl* pData = (ModuleUserData_Impl*)pEntry->GetUserData();
2260 if(pData->IsParent())
2262 if(bChanged)
2264 LangImplNameTable *pTable = 0;
2265 BYTE nType = pData->GetType();
2266 switch (nType - 1)
2268 case TYPE_SPELL : pTable = &rLinguData.GetSpellTable(); break;
2269 case TYPE_GRAMMAR : pTable = &rLinguData.GetGrammarTable(); break;
2270 case TYPE_HYPH : pTable = &rLinguData.GetHyphTable(); break;
2271 case TYPE_THES : pTable = &rLinguData.GetThesTable(); break;
2273 if (pTable)
2275 aChange.realloc(nStart);
2276 (*pTable)[ nLang ] = aChange;
2279 nLocalIndex = nStart = 0;
2280 aChange.realloc(aModulesCLB.GetEntryCount());
2281 bChanged = FALSE;
2283 else
2285 OUString* pChange = aChange.getArray();
2286 pChange[nStart] = pData->GetImplName();
2287 bChanged |= pData->GetIndex() != nLocalIndex ||
2288 pData->IsChecked() != aModulesCLB.IsChecked(i);
2289 if(aModulesCLB.IsChecked(i))
2290 nStart++;
2291 ++nLocalIndex;
2294 if(bChanged)
2296 aChange.realloc(nStart);
2297 rLinguData.GetThesTable()[ nLang ] = aChange;
2301 for(ULONG i = 0; i < aModulesCLB.GetEntryCount(); i++)
2302 delete (ModuleUserData_Impl*)aModulesCLB.GetEntry(i)->GetUserData();
2305 // display entries for new selected language
2307 aModulesCLB.Clear();
2308 if(LANGUAGE_DONTKNOW != eCurLanguage)
2310 // sal_Int32 nEntryPos = 1;
2312 ULONG n;
2313 ServiceInfo_Impl* pInfo;
2316 // spellchecker entries
2318 SvLBoxEntry* pEntry = CreateEntry( sSpell, CBCOL_SECOND );
2319 ModuleUserData_Impl* pUserData = new ModuleUserData_Impl(
2320 String(), TRUE, FALSE, TYPE_SPELL, 0 );
2321 pEntry->SetUserData( (void *)pUserData );
2322 pModel->Insert( pEntry );
2324 Sequence< OUString > aNames( rLinguData.GetSortedImplNames( eCurLanguage, TYPE_SPELL ) );
2325 const OUString *pName = aNames.getConstArray();
2326 ULONG nNames = (ULONG) aNames.getLength();
2327 sal_Int32 nLocalIndex = 0; // index relative to parent
2328 for (n = 0; n < nNames; ++n)
2330 OUString aImplName;
2331 BOOL bIsSuppLang = FALSE;
2333 pInfo = rLinguData.GetInfoByImplName( pName[n] );
2334 if (pInfo)
2336 bIsSuppLang = pInfo->xSpell.is() &&
2337 pInfo->xSpell->hasLocale( aCurLocale );
2338 aImplName = pInfo->sSpellImplName;
2340 if (aImplName.getLength() && bIsSuppLang)
2342 String aTxt( pInfo->sDisplayName );
2343 SvLBoxEntry* pNewEntry = CreateEntry( aTxt, CBCOL_FIRST );
2345 LangImplNameTable &rTable = rLinguData.GetSpellTable();
2346 const bool bHasLang = rTable.count( eCurLanguage );
2347 if (!bHasLang)
2349 DBG_WARNING( "language entry missing" ); // only relevant if all languages found should be supported
2351 const bool bCheck = bHasLang && lcl_SeqGetEntryPos( rTable[ eCurLanguage ], aImplName ) >= 0;
2352 lcl_SetCheckButton( pNewEntry, bCheck );
2353 pUserData = new ModuleUserData_Impl( aImplName, FALSE,
2354 bCheck, TYPE_SPELL, (BYTE)nLocalIndex++ );
2355 pNewEntry->SetUserData( (void *)pUserData );
2356 pModel->Insert( pNewEntry );
2361 // grammar checker entries
2363 pEntry = CreateEntry( sGrammar, CBCOL_SECOND );
2364 pUserData = new ModuleUserData_Impl( String(), TRUE, FALSE, TYPE_GRAMMAR, 0 );
2365 pEntry->SetUserData( (void *)pUserData );
2366 pModel->Insert( pEntry );
2368 aNames = rLinguData.GetSortedImplNames( eCurLanguage, TYPE_GRAMMAR );
2369 pName = aNames.getConstArray();
2370 nNames = (ULONG) aNames.getLength();
2371 nLocalIndex = 0;
2372 for (n = 0; n < nNames; ++n)
2374 OUString aImplName;
2375 BOOL bIsSuppLang = FALSE;
2377 pInfo = rLinguData.GetInfoByImplName( pName[n] );
2378 if (pInfo)
2380 bIsSuppLang = pInfo->xGrammar.is() &&
2381 pInfo->xGrammar->hasLocale( aCurLocale );
2382 aImplName = pInfo->sGrammarImplName;
2384 if (aImplName.getLength() && bIsSuppLang)
2386 String aTxt( pInfo->sDisplayName );
2387 SvLBoxEntry* pNewEntry = CreateEntry( aTxt, CBCOL_FIRST );
2389 LangImplNameTable &rTable = rLinguData.GetGrammarTable();
2390 const bool bHasLang = rTable.count( eCurLanguage );
2391 if (!bHasLang)
2393 DBG_WARNING( "language entry missing" ); // only relevant if all languages found should be supported
2395 const bool bCheck = bHasLang && lcl_SeqGetEntryPos( rTable[ eCurLanguage ], aImplName ) >= 0;
2396 lcl_SetCheckButton( pNewEntry, bCheck );
2397 pUserData = new ModuleUserData_Impl( aImplName, FALSE,
2398 bCheck, TYPE_GRAMMAR, (BYTE)nLocalIndex++ );
2399 pNewEntry->SetUserData( (void *)pUserData );
2400 pModel->Insert( pNewEntry );
2405 // hyphenator entries
2407 pEntry = CreateEntry( sHyph, CBCOL_SECOND );
2408 pUserData = new ModuleUserData_Impl( String(), TRUE, FALSE, TYPE_HYPH, 0 );
2409 pEntry->SetUserData( (void *)pUserData );
2410 pModel->Insert( pEntry );
2412 aNames = rLinguData.GetSortedImplNames( eCurLanguage, TYPE_HYPH );
2413 pName = aNames.getConstArray();
2414 nNames = (ULONG) aNames.getLength();
2415 nLocalIndex = 0;
2416 for (n = 0; n < nNames; ++n)
2418 OUString aImplName;
2419 BOOL bIsSuppLang = FALSE;
2421 pInfo = rLinguData.GetInfoByImplName( pName[n] );
2422 if (pInfo)
2424 bIsSuppLang = pInfo->xHyph.is() &&
2425 pInfo->xHyph->hasLocale( aCurLocale );
2426 aImplName = pInfo->sHyphImplName;
2428 if (aImplName.getLength() && bIsSuppLang)
2430 String aTxt( pInfo->sDisplayName );
2431 SvLBoxEntry* pNewEntry = CreateEntry( aTxt, CBCOL_FIRST );
2433 LangImplNameTable &rTable = rLinguData.GetHyphTable();
2434 const bool bHasLang = rTable.count( eCurLanguage );
2435 if (!bHasLang)
2437 DBG_WARNING( "language entry missing" ); // only relevant if all languages found should be supported
2439 const bool bCheck = bHasLang && lcl_SeqGetEntryPos( rTable[ eCurLanguage ], aImplName ) >= 0;
2440 lcl_SetCheckButton( pNewEntry, bCheck );
2441 pUserData = new ModuleUserData_Impl( aImplName, FALSE,
2442 bCheck, TYPE_HYPH, (BYTE)nLocalIndex++ );
2443 pNewEntry->SetUserData( (void *)pUserData );
2444 pModel->Insert( pNewEntry );
2449 // thesaurus entries
2451 pEntry = CreateEntry( sThes, CBCOL_SECOND );
2452 pUserData = new ModuleUserData_Impl( String(), TRUE, FALSE, TYPE_THES, 0 );
2453 pEntry->SetUserData( (void *)pUserData );
2454 pModel->Insert( pEntry );
2456 aNames = rLinguData.GetSortedImplNames( eCurLanguage, TYPE_THES );
2457 pName = aNames.getConstArray();
2458 nNames = (ULONG) aNames.getLength();
2459 nLocalIndex = 0;
2460 for (n = 0; n < nNames; ++n)
2462 OUString aImplName;
2463 BOOL bIsSuppLang = FALSE;
2465 pInfo = rLinguData.GetInfoByImplName( pName[n] );
2466 if (pInfo)
2468 bIsSuppLang = pInfo->xThes.is() &&
2469 pInfo->xThes->hasLocale( aCurLocale );
2470 aImplName = pInfo->sThesImplName;
2472 if (aImplName.getLength() && bIsSuppLang)
2474 String aTxt( pInfo->sDisplayName );
2475 SvLBoxEntry* pNewEntry = CreateEntry( aTxt, CBCOL_FIRST );
2477 LangImplNameTable &rTable = rLinguData.GetThesTable();
2478 const bool bHasLang = rTable.count( eCurLanguage );
2479 if (!bHasLang)
2481 DBG_WARNING( "language entry missing" ); // only relevant if all languages found should be supported
2483 const bool bCheck = bHasLang && lcl_SeqGetEntryPos( rTable[ eCurLanguage ], aImplName ) >= 0;
2484 lcl_SetCheckButton( pNewEntry, bCheck );
2485 pUserData = new ModuleUserData_Impl( aImplName, FALSE,
2486 bCheck, TYPE_THES, (BYTE)nLocalIndex++ );
2487 pNewEntry->SetUserData( (void *)pUserData );
2488 pModel->Insert( pNewEntry );
2492 aLastLocale.Language = aCurLocale.Language;
2493 aLastLocale.Country = aCurLocale.Country;
2494 return 0;
2496 /* -----------------------------27.11.00 19:50--------------------------------
2498 ---------------------------------------------------------------------------*/
2499 IMPL_LINK( SvxEditModulesDlg, UpDownHdl_Impl, PushButton *, pBtn )
2501 sal_Bool bUp = &aPrioUpPB == pBtn;
2502 USHORT nCurPos = aModulesCLB.GetSelectEntryPos();
2503 SvLBoxEntry* pEntry;
2504 if (nCurPos != LISTBOX_ENTRY_NOTFOUND &&
2505 0 != (pEntry = aModulesCLB.GetEntry(nCurPos)))
2507 aModulesCLB.SetUpdateMode(FALSE);
2508 SvLBoxTreeList *pModel = aModulesCLB.GetModel();
2510 ModuleUserData_Impl* pData = (ModuleUserData_Impl*)pEntry->GetUserData();
2511 String aStr(aModulesCLB.GetEntryText(pEntry));
2512 SvLBoxEntry* pToInsert = CreateEntry( aStr, CBCOL_FIRST );
2513 pToInsert->SetUserData( (void *)pData);
2514 BOOL bIsChecked = aModulesCLB.IsChecked(nCurPos);
2516 pModel->Remove(pEntry);
2518 USHORT nDestPos = bUp ? nCurPos - 1 : nCurPos + 1;
2519 pModel->Insert(pToInsert, nDestPos);
2520 aModulesCLB.CheckEntryPos(nDestPos, bIsChecked );
2521 aModulesCLB.SelectEntryPos(nDestPos );
2522 SelectHdl_Impl(&aModulesCLB);
2523 aModulesCLB.SetUpdateMode(TRUE);
2525 return 0;
2527 /* ---------------------------------------------------------------------------
2529 ---------------------------------------------------------------------------*/
2530 IMPL_LINK( SvxEditModulesDlg, ClickHdl_Impl, PushButton *, pBtn )
2532 if (&aClosePB == pBtn)
2534 // store language config
2535 LangSelectHdl_Impl(&aLanguageLB);
2536 EndDialog( RET_OK );
2538 else
2540 DBG_ERROR( "pBtn unexpected value" );
2543 return 0;
2545 /* -----------------------------27.11.00 20:31--------------------------------
2547 ---------------------------------------------------------------------------*/
2548 IMPL_LINK( SvxEditModulesDlg, BackHdl_Impl, PushButton *, EMPTYARG )
2550 rLinguData = *pDefaultLinguData;
2551 LangSelectHdl_Impl(0);
2552 return 0;
2555 // -----------------------------------------------------------------------
2557 IMPL_LINK( SvxEditModulesDlg, OpenURLHdl_Impl, svt::FixedHyperlink *, EMPTYARG )
2559 ::rtl::OUString sURL( aMoreDictsLink.GetURL() );
2560 lcl_OpenURL( sURL );
2561 return 0;