xref: /trunk/main/sw/source/ui/lingu/olmenu.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "SwRewriter.hxx"
28cdf0e10cSrcweir #include "chrdlg.hrc"
29cdf0e10cSrcweir #include "cmdid.h"
30cdf0e10cSrcweir #include "comcore.hrc"
31cdf0e10cSrcweir #include "crsskip.hxx"
32cdf0e10cSrcweir #include "doc.hxx"
33cdf0e10cSrcweir #include "docsh.hxx"        //CheckSpellChanges
34cdf0e10cSrcweir #include "edtwin.hxx"
35cdf0e10cSrcweir #include "helpid.h"
36cdf0e10cSrcweir #include "hintids.hxx"
37cdf0e10cSrcweir #include "langhelper.hxx"
38cdf0e10cSrcweir #include "ndtxt.hxx"
39cdf0e10cSrcweir #include "olmenu.hrc"
40cdf0e10cSrcweir #include "olmenu.hxx"
41cdf0e10cSrcweir #include "swabstdlg.hxx"
42cdf0e10cSrcweir #include "swmodule.hxx"
43cdf0e10cSrcweir #include "swtypes.hxx"
44cdf0e10cSrcweir #include "swundo.hxx"
45cdf0e10cSrcweir #include "uitool.hxx"
46cdf0e10cSrcweir #include "unomid.h"
47cdf0e10cSrcweir #include "view.hxx"
48cdf0e10cSrcweir #include "viewopt.hxx"
49cdf0e10cSrcweir #include "wrtsh.hxx"
50cdf0e10cSrcweir #include "wview.hxx"
51cdf0e10cSrcweir #include "swabstdlg.hxx"
52cdf0e10cSrcweir #include "chrdlg.hrc"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #ifndef _SVSTDARR_HXX
56cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
57cdf0e10cSrcweir #include <svl/svstdarr.hxx>
58cdf0e10cSrcweir #endif
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
61cdf0e10cSrcweir #include <editeng/acorrcfg.hxx>
62cdf0e10cSrcweir #include <editeng/svxacorr.hxx>
63cdf0e10cSrcweir #include <editeng/langitem.hxx>
64cdf0e10cSrcweir #include <editeng/splwrap.hxx>
65cdf0e10cSrcweir #include <editeng/brshitem.hxx>
66cdf0e10cSrcweir #include <editeng/unolingu.hxx>
67cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
68cdf0e10cSrcweir #include <linguistic/lngprops.hxx>
69cdf0e10cSrcweir #include <linguistic/misc.hxx>
70cdf0e10cSrcweir #include <osl/file.hxx>
71cdf0e10cSrcweir #include <rtl/string.hxx>
72cdf0e10cSrcweir #include <svtools/filter.hxx>
73cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
74cdf0e10cSrcweir #include <sfx2/imagemgr.hxx>
75cdf0e10cSrcweir #include <sfx2/request.hxx>
76cdf0e10cSrcweir #include <sfx2/sfxdlg.hxx>
77cdf0e10cSrcweir #include <svl/itemset.hxx>
78cdf0e10cSrcweir #include <svl/languageoptions.hxx>
79cdf0e10cSrcweir #include <svl/stritem.hxx>
80cdf0e10cSrcweir #include <svtools/filter.hxx>
81cdf0e10cSrcweir #include <svtools/langtab.hxx>
82cdf0e10cSrcweir #include <svx/dlgutil.hxx>
83cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
84cdf0e10cSrcweir #include <unotools/linguprops.hxx>
85cdf0e10cSrcweir #include <vcl/msgbox.hxx>
86cdf0e10cSrcweir #include <vcl/settings.hxx>
87cdf0e10cSrcweir #include <vcl/svapp.hxx>
88cdf0e10cSrcweir 
89cdf0e10cSrcweir #include <map>
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
92cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
93cdf0e10cSrcweir #include <com/sun/star/document/XDocumentLanguages.hpp>
94cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
95cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
96cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
97cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
98cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
99cdf0e10cSrcweir #include <com/sun/star/linguistic2/SingleProofreadingError.hpp>
100cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
101cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
102cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir using namespace ::com::sun::star;
106cdf0e10cSrcweir using ::rtl::OUString;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir extern void lcl_CharDialog( SwWrtShell &rWrtSh, sal_Bool bUseDialog, sal_uInt16 nSlot,const SfxItemSet *pArgs, SfxRequest *pReq );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir /*--------------------------------------------------------------------------
112cdf0e10cSrcweir 
113cdf0e10cSrcweir ---------------------------------------------------------------------------*/
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // tries to determine the language of 'rText'
116cdf0e10cSrcweir //
lcl_CheckLanguage(const OUString & rText,uno::Reference<linguistic2::XSpellChecker1> xSpell,uno::Reference<linguistic2::XLanguageGuessing> xLangGuess,sal_Bool bIsParaText)117cdf0e10cSrcweir LanguageType lcl_CheckLanguage(
118cdf0e10cSrcweir     const OUString &rText,
119cdf0e10cSrcweir     uno::Reference< linguistic2::XSpellChecker1 > xSpell,
120cdf0e10cSrcweir     uno::Reference< linguistic2::XLanguageGuessing > xLangGuess,
121cdf0e10cSrcweir     sal_Bool bIsParaText )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     LanguageType  nLang = LANGUAGE_NONE;
124cdf0e10cSrcweir     if (bIsParaText)    // check longer texts with language-guessing...
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         if (!xLangGuess.is())
127cdf0e10cSrcweir             return nLang;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         lang::Locale aLocale( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         // get language as from "Tools/Options - Language Settings - Languages: Locale setting"
132cdf0e10cSrcweir         LanguageType nTmpLang = Application::GetSettings().GetLanguage();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // if the result from language guessing does not provide a 'Country' part
135cdf0e10cSrcweir         // try to get it by looking up the locale setting of the office.
136cdf0e10cSrcweir         if (aLocale.Country.getLength() == 0)
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             lang::Locale aTmpLocale = SvxCreateLocale( nTmpLang );
139cdf0e10cSrcweir             if (aTmpLocale.Language == aLocale.Language)
140cdf0e10cSrcweir                 nLang = nTmpLang;
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir         if (nLang == LANGUAGE_NONE) // language not found by looking up the system language...
143cdf0e10cSrcweir             nLang = MsLangId::convertLocaleToLanguageWithFallback( aLocale );
144cdf0e10cSrcweir         if (nLang == LANGUAGE_SYSTEM)
145cdf0e10cSrcweir             nLang = nTmpLang;
146cdf0e10cSrcweir         if (nLang == LANGUAGE_DONTKNOW)
147cdf0e10cSrcweir             nLang = LANGUAGE_NONE;
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     else    // check single word
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir             if (!xSpell.is())
152cdf0e10cSrcweir             return nLang;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         //
155cdf0e10cSrcweir         // build list of languages to check
156cdf0e10cSrcweir         //
157cdf0e10cSrcweir         LanguageType aLangList[4];
158cdf0e10cSrcweir         const AllSettings& rSettings  = Application::GetSettings();
159cdf0e10cSrcweir         SvtLinguOptions aLinguOpt;
160cdf0e10cSrcweir         SvtLinguConfig().GetOptions( aLinguOpt );
161cdf0e10cSrcweir         // The default document language from "Tools/Options - Language Settings - Languages: Western"
162cdf0e10cSrcweir         aLangList[0] = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
163cdf0e10cSrcweir         // The one from "Tools/Options - Language Settings - Languages: User interface"
164cdf0e10cSrcweir         aLangList[1] = rSettings.GetUILanguage();
165cdf0e10cSrcweir         // The one from "Tools/Options - Language Settings - Languages: Locale setting"
166cdf0e10cSrcweir         aLangList[2] = rSettings.GetLanguage();
167cdf0e10cSrcweir         // en-US
168cdf0e10cSrcweir         aLangList[3] = LANGUAGE_ENGLISH_US;
169cdf0e10cSrcweir #ifdef DEBUG
170cdf0e10cSrcweir         lang::Locale a0( SvxCreateLocale( aLangList[0] ) );
171cdf0e10cSrcweir         lang::Locale a1( SvxCreateLocale( aLangList[1] ) );
172cdf0e10cSrcweir         lang::Locale a2( SvxCreateLocale( aLangList[2] ) );
173cdf0e10cSrcweir         lang::Locale a3( SvxCreateLocale( aLangList[3] ) );
174cdf0e10cSrcweir #endif
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         sal_Int32   nCount = sizeof(aLangList) / sizeof(aLangList[0]);
177cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nCount;  i++)
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir             sal_Int16 nTmpLang = aLangList[i];
180cdf0e10cSrcweir             if (nTmpLang != LANGUAGE_NONE  &&  nTmpLang != LANGUAGE_DONTKNOW)
181cdf0e10cSrcweir             {
182cdf0e10cSrcweir                 if (xSpell->hasLanguage( nTmpLang ) &&
183cdf0e10cSrcweir                     xSpell->isValid( rText, nTmpLang, uno::Sequence< beans::PropertyValue >() ))
184cdf0e10cSrcweir                 {
185cdf0e10cSrcweir                     nLang = nTmpLang;
186cdf0e10cSrcweir                     break;
187cdf0e10cSrcweir                 }
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     return nLang;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir /// @returns : the language for the selected text that is set for the
197cdf0e10cSrcweir ///     specified attribute (script type).
198cdf0e10cSrcweir ///     If there are more than one languages used LANGUAGE_DONTKNOW will be returned.
199cdf0e10cSrcweir /// @param nLangWhichId : one of
200cdf0e10cSrcweir ///     RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
201cdf0e10cSrcweir /// @returns: the language in use for the selected text.
202cdf0e10cSrcweir ///     'In use' means the language(s) matching the script type(s) of the
203cdf0e10cSrcweir ///     selected text. Or in other words, the language a spell checker would use.
204cdf0e10cSrcweir ///     If there is more than one language LANGUAGE_DONTKNOW will be returned.
205cdf0e10cSrcweir // check if nScriptType includes the script type associated to nLang
lcl_checkScriptType(sal_Int16 nScriptType,LanguageType nLang)206cdf0e10cSrcweir inline bool lcl_checkScriptType( sal_Int16 nScriptType, LanguageType nLang )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
fillLangPopupMenu(PopupMenu * pPopupMenu,sal_uInt16 nLangItemIdStart,uno::Sequence<OUString> aSeq,SwWrtShell * pWrtSh,std::map<sal_Int16,::rtl::OUString> & rLangTable)211cdf0e10cSrcweir void SwSpellPopup::fillLangPopupMenu(
212cdf0e10cSrcweir     PopupMenu *pPopupMenu,
213cdf0e10cSrcweir     sal_uInt16 nLangItemIdStart,
214cdf0e10cSrcweir     uno::Sequence< OUString > aSeq,
215cdf0e10cSrcweir     SwWrtShell* pWrtSh,
216cdf0e10cSrcweir     std::map< sal_Int16, ::rtl::OUString > &rLangTable )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     if (!pPopupMenu)
219cdf0e10cSrcweir         return;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     SvtLanguageTable    aLanguageTable;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     // set of languages to be displayed in the sub menus
224cdf0e10cSrcweir     std::set< OUString > aLangItems;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     OUString    aCurLang( aSeq[0] );
227cdf0e10cSrcweir     sal_uInt16      nScriptType = static_cast< sal_Int16 >(aSeq[1].toInt32());
228cdf0e10cSrcweir     OUString    aKeyboardLang( aSeq[2] );
229cdf0e10cSrcweir     OUString    aGuessedTextLang( aSeq[3] );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     if (aCurLang != OUString() &&
232cdf0e10cSrcweir         LANGUAGE_DONTKNOW != aLanguageTable.GetType( aCurLang ))
233cdf0e10cSrcweir         aLangItems.insert( aCurLang );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     //2--System
236cdf0e10cSrcweir     const AllSettings& rAllSettings = Application::GetSettings();
237cdf0e10cSrcweir     LanguageType rSystemLanguage = rAllSettings.GetLanguage();
238cdf0e10cSrcweir     if (rSystemLanguage != LANGUAGE_DONTKNOW)
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         if (lcl_checkScriptType( nScriptType, rSystemLanguage ))
241cdf0e10cSrcweir             aLangItems.insert( aLanguageTable.GetString(rSystemLanguage) );
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     //3--UI
245cdf0e10cSrcweir     LanguageType rUILanguage = rAllSettings.GetUILanguage();
246cdf0e10cSrcweir     if (rUILanguage != LANGUAGE_DONTKNOW)
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         if (lcl_checkScriptType(nScriptType, rUILanguage ))
249cdf0e10cSrcweir             aLangItems.insert( aLanguageTable.GetString(rUILanguage) );
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     //4--guessed language
253cdf0e10cSrcweir     if (aGuessedTextLang.getLength() > 0)
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         if (lcl_checkScriptType(nScriptType, aLanguageTable.GetType(aGuessedTextLang)))
256cdf0e10cSrcweir             aLangItems.insert( aGuessedTextLang );
257cdf0e10cSrcweir     }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     //5--keyboard language
260cdf0e10cSrcweir     if (aKeyboardLang.getLength() > 0)
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         if (lcl_checkScriptType(nScriptType, aLanguageTable.GetType(aKeyboardLang)))
263cdf0e10cSrcweir             aLangItems.insert( aKeyboardLang );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     //6--all languages used in current document
267cdf0e10cSrcweir     uno::Reference< com::sun::star::frame::XModel > xModel;
268cdf0e10cSrcweir     uno::Reference< com::sun::star::frame::XController > xController( pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface()->getController(), uno::UNO_QUERY );
269cdf0e10cSrcweir     if ( xController.is() )
270cdf0e10cSrcweir         xModel = xController->getModel();
271cdf0e10cSrcweir     uno::Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, uno::UNO_QUERY );
272cdf0e10cSrcweir     /*the description of nScriptType flags
273cdf0e10cSrcweir       LATIN :   0x0001
274cdf0e10cSrcweir       ASIAN :   0x0002
275cdf0e10cSrcweir       COMPLEX:  0x0004
276cdf0e10cSrcweir     */
277cdf0e10cSrcweir     const sal_Int16 nMaxCount = 7;
278cdf0e10cSrcweir     if (xDocumentLanguages.is())
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         uno::Sequence< lang::Locale > rLocales( xDocumentLanguages->getDocumentLanguages( nScriptType, nMaxCount ) );
281cdf0e10cSrcweir         if (rLocales.getLength() > 0)
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             for (sal_uInt16 i = 0; i < rLocales.getLength(); ++i)
284cdf0e10cSrcweir             {
285cdf0e10cSrcweir                 if (aLangItems.size() == (size_t)nMaxCount)
286cdf0e10cSrcweir                     break;
287cdf0e10cSrcweir                 const lang::Locale& rLocale = rLocales[i];
288cdf0e10cSrcweir                 if (lcl_checkScriptType( nScriptType, aLanguageTable.GetType( rLocale.Language )))
289cdf0e10cSrcweir                     aLangItems.insert( rLocale.Language );
290cdf0e10cSrcweir             }
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     sal_uInt16 nItemId = nLangItemIdStart;
296cdf0e10cSrcweir     const OUString sAsterix(RTL_CONSTASCII_USTRINGPARAM("*"));  // multiple languages in current selection
297cdf0e10cSrcweir     const OUString sEmpty;  // 'no language found' from language guessing
298cdf0e10cSrcweir     std::set< OUString >::const_iterator it;
299cdf0e10cSrcweir     for (it = aLangItems.begin(); it != aLangItems.end(); ++it)
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         OUString aEntryTxt( *it );
302cdf0e10cSrcweir         if (aEntryTxt != OUString( aLanguageTable.GetString( LANGUAGE_NONE ) )&&
303cdf0e10cSrcweir             aEntryTxt != sAsterix &&
304cdf0e10cSrcweir             aEntryTxt != sEmpty)
305cdf0e10cSrcweir         {
306cdf0e10cSrcweir             DBG_ASSERT( nLangItemIdStart <= nItemId && nItemId <= nLangItemIdStart + MN_MAX_NUM_LANG,
307cdf0e10cSrcweir                     "nItemId outside of expected range!" );
308cdf0e10cSrcweir             pPopupMenu->InsertItem( nItemId, aEntryTxt, MIB_RADIOCHECK );
309cdf0e10cSrcweir             if (aEntryTxt == aCurLang)
310cdf0e10cSrcweir             {
311cdf0e10cSrcweir                 //make a check mark for the current language
312cdf0e10cSrcweir                 pPopupMenu->CheckItem( nItemId, sal_True );
313cdf0e10cSrcweir             }
314cdf0e10cSrcweir             rLangTable[ nItemId ] = aEntryTxt;
315cdf0e10cSrcweir             ++nItemId;
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     pPopupMenu->InsertItem( nLangItemIdStart + MN_NONE_OFFSET,  String(SW_RES( STR_LANGSTATUS_NONE )), MIB_RADIOCHECK );
320cdf0e10cSrcweir     pPopupMenu->InsertItem( nLangItemIdStart + MN_RESET_OFFSET, String(SW_RES( STR_RESET_TO_DEFAULT_LANGUAGE )), MIB_RADIOCHECK );
321cdf0e10cSrcweir     pPopupMenu->InsertItem( nLangItemIdStart + MN_MORE_OFFSET,  String(SW_RES( STR_LANGSTATUS_MORE )), MIB_RADIOCHECK );
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
lcl_GetImageFromPngUrl(const OUString & rFileUrl)325cdf0e10cSrcweir static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir     Image aRes;
328cdf0e10cSrcweir     OUString aTmp;
329cdf0e10cSrcweir     osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
330cdf0e10cSrcweir //    ::rtl::OString aPath = OString( aTmp.getStr(), aTmp.getLength(), osl_getThreadTextEncoding() );
331cdf0e10cSrcweir #if defined(WNT)
332cdf0e10cSrcweir //    aTmp = lcl_Win_GetShortPathName( aTmp );
333cdf0e10cSrcweir #endif
334cdf0e10cSrcweir     Graphic aGraphic;
335cdf0e10cSrcweir     const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) );
336cdf0e10cSrcweir     if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         aRes = Image( aGraphic.GetBitmapEx() );
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir     return aRes;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 
RetrieveLabelFromCommand(const OUString & aCmdURL)344cdf0e10cSrcweir OUString RetrieveLabelFromCommand( const OUString& aCmdURL )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir     OUString aLabel;
347cdf0e10cSrcweir     if ( aCmdURL.getLength() )
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         try
350cdf0e10cSrcweir         {
351cdf0e10cSrcweir             uno::Reference< container::XNameAccess > xNameAccess( ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.frame.UICommandDescription") ), uno::UNO_QUERY );
352cdf0e10cSrcweir             if ( xNameAccess.is() )
353cdf0e10cSrcweir             {
354cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xUICommandLabels;
355cdf0e10cSrcweir                 const OUString aModule( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) );
356cdf0e10cSrcweir                 uno::Any a = xNameAccess->getByName( aModule );
357cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xUICommands;
358cdf0e10cSrcweir                 a >>= xUICommandLabels;
359cdf0e10cSrcweir                 OUString aStr;
360cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aPropSeq;
361cdf0e10cSrcweir                 a = xUICommandLabels->getByName( aCmdURL );
362cdf0e10cSrcweir                 if ( a >>= aPropSeq )
363cdf0e10cSrcweir                 {
364cdf0e10cSrcweir                     for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
365cdf0e10cSrcweir                     {
366cdf0e10cSrcweir                         if ( aPropSeq[i].Name.equalsAscii( "Name" ))
367cdf0e10cSrcweir                         {
368cdf0e10cSrcweir                             aPropSeq[i].Value >>= aStr;
369cdf0e10cSrcweir                             break;
370cdf0e10cSrcweir                         }
371cdf0e10cSrcweir                     }
372cdf0e10cSrcweir                 }
373cdf0e10cSrcweir                 aLabel = aStr;
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir         catch ( uno::Exception& )
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     return aLabel;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 
SwSpellPopup(SwWrtShell * pWrtSh,const uno::Reference<linguistic2::XSpellAlternatives> & xAlt,const String & rParaText)385cdf0e10cSrcweir SwSpellPopup::SwSpellPopup(
386cdf0e10cSrcweir         SwWrtShell* pWrtSh,
387cdf0e10cSrcweir         const uno::Reference< linguistic2::XSpellAlternatives >  &xAlt,
388cdf0e10cSrcweir         const String &rParaText ) :
389cdf0e10cSrcweir PopupMenu( SW_RES(MN_SPELL_POPUP) ),
390cdf0e10cSrcweir pSh( pWrtSh ),
391cdf0e10cSrcweir xSpellAlt(xAlt),
392cdf0e10cSrcweir bGrammarResults(false)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir     DBG_ASSERT(xSpellAlt.is(), "no spelling alternatives available");
395cdf0e10cSrcweir 
396cdf0e10cSrcweir //    CreateAutoMnemonics();
397cdf0e10cSrcweir     SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     nCheckedLanguage = LANGUAGE_NONE;
400cdf0e10cSrcweir     if (xSpellAlt.is())
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         nCheckedLanguage = SvxLocaleToLanguage( xSpellAlt->getLocale() );
403cdf0e10cSrcweir         aSuggestions = xSpellAlt->getAlternatives();
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir     sal_Int16 nStringCount = static_cast< sal_Int16 >( aSuggestions.getLength() );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     SvtLinguConfig aCfg;
408cdf0e10cSrcweir     const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     PopupMenu *pMenu = GetPopupMenu(MN_AUTOCORR);
411cdf0e10cSrcweir     pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
412cdf0e10cSrcweir     sal_Bool bEnable = sal_False;
413cdf0e10cSrcweir     if( nStringCount )
414cdf0e10cSrcweir     {
415cdf0e10cSrcweir         Image aImage;
416cdf0e10cSrcweir         OUString aSuggestionImageUrl;
417cdf0e10cSrcweir         uno::Reference< container::XNamed > xNamed( xSpellAlt, uno::UNO_QUERY );
418cdf0e10cSrcweir         if (xNamed.is())
419cdf0e10cSrcweir         {
420cdf0e10cSrcweir             aSuggestionImageUrl = aCfg.GetSpellAndGrammarContextSuggestionImage( xNamed->getName(), bHC );
421cdf0e10cSrcweir             aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
422cdf0e10cSrcweir         }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir         InsertSeparator(0);
425cdf0e10cSrcweir         bEnable = sal_True;
426cdf0e10cSrcweir         sal_uInt16 nAutoCorrItemId  = MN_AUTOCORR_START;
427cdf0e10cSrcweir         sal_uInt16 nItemId          = MN_SUGGESTION_START;
428cdf0e10cSrcweir         for (sal_uInt16 i = 0; i < nStringCount; ++i)
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             const String aEntry = aSuggestions[ i ];
431cdf0e10cSrcweir             InsertItem( nItemId, aEntry, 0, i );
432cdf0e10cSrcweir             SetHelpId( nItemId, HID_LINGU_REPLACE);
433cdf0e10cSrcweir             if (aSuggestionImageUrl.getLength() > 0)
434cdf0e10cSrcweir                 SetItemImage( nItemId, aImage );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir             pMenu->InsertItem( nAutoCorrItemId, aEntry );
437cdf0e10cSrcweir             pMenu->SetHelpId( nAutoCorrItemId, HID_LINGU_AUTOCORR);
438cdf0e10cSrcweir 
439cdf0e10cSrcweir             ++nAutoCorrItemId;
440cdf0e10cSrcweir             ++nItemId;
441cdf0e10cSrcweir         }
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     OUString aIgnoreSelection( String( SW_RES( STR_IGNORE_SELECTION ) ) );
445cdf0e10cSrcweir     OUString aSpellingAndGrammar = RetrieveLabelFromCommand( C2U(".uno:SpellingAndGrammarDialog") );
446cdf0e10cSrcweir     SetItemText( MN_SPELLING_DLG, aSpellingAndGrammar );
447cdf0e10cSrcweir     sal_uInt16 nItemPos = GetItemPos( MN_IGNORE_WORD );
448cdf0e10cSrcweir     InsertItem( MN_IGNORE_SELECTION, aIgnoreSelection, 0, nItemPos );
449cdf0e10cSrcweir     SetHelpId( MN_IGNORE_SELECTION, HID_LINGU_IGNORE_SELECTION);
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     EnableItem( MN_AUTOCORR, bEnable );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     uno::Reference< linguistic2::XLanguageGuessing > xLG = SW_MOD()->GetLanguageGuesser();
454cdf0e10cSrcweir     nGuessLangWord = LANGUAGE_NONE;
455cdf0e10cSrcweir     nGuessLangPara = LANGUAGE_NONE;
456cdf0e10cSrcweir     if (xSpellAlt.is() && xLG.is())
457cdf0e10cSrcweir     {
458cdf0e10cSrcweir         nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), ::GetSpellChecker(), xLG, sal_False );
459cdf0e10cSrcweir         nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, sal_True );
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir     if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
462cdf0e10cSrcweir     {
463cdf0e10cSrcweir         // make sure LANGUAGE_NONE gets not used as menu entry
464cdf0e10cSrcweir         if (nGuessLangWord == LANGUAGE_NONE)
465cdf0e10cSrcweir             nGuessLangWord = nGuessLangPara;
466cdf0e10cSrcweir         if (nGuessLangPara == LANGUAGE_NONE)
467cdf0e10cSrcweir             nGuessLangPara = nGuessLangWord;
468cdf0e10cSrcweir     }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_ADD_TO_DIC);
471cdf0e10cSrcweir //    pMenu->CreateAutoMnemonics();
472cdf0e10cSrcweir     pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);     //! necessary to retrieve the correct dictionary name in 'Execute' below
473cdf0e10cSrcweir     bEnable = sal_False;    // enable MN_ADD_TO_DIC?
474cdf0e10cSrcweir     uno::Reference< linguistic2::XDictionaryList >    xDicList( SvxGetDictionaryList() );
475cdf0e10cSrcweir     if (xDicList.is())
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir         // add the default positive dictionary to dic-list (if not already done).
478cdf0e10cSrcweir         // This is to ensure that there is at least one dictionary to which
479cdf0e10cSrcweir         // words could be added.
480cdf0e10cSrcweir         uno::Reference< linguistic2::XDictionary >  xDic( SvxGetOrCreatePosDic( xDicList ) );
481cdf0e10cSrcweir         if (xDic.is())
482cdf0e10cSrcweir             xDic->setActive( sal_True );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir         aDics = xDicList->getDictionaries();
485cdf0e10cSrcweir         const uno::Reference< linguistic2::XDictionary >  *pDic = aDics.getConstArray();
486cdf0e10cSrcweir         sal_uInt16 nDicCount = static_cast< sal_uInt16 >(aDics.getLength());
487cdf0e10cSrcweir 
488cdf0e10cSrcweir         sal_uInt16 nItemId = MN_DICTIONARIES_START;
489cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < nDicCount; i++ )
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             uno::Reference< linguistic2::XDictionary >  xDicTmp( pDic[i], uno::UNO_QUERY );
492cdf0e10cSrcweir             if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
493cdf0e10cSrcweir                 continue;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir             uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
496cdf0e10cSrcweir             LanguageType nActLanguage = SvxLocaleToLanguage( xDicTmp->getLocale() );
497cdf0e10cSrcweir             if( xDicTmp->isActive()
498cdf0e10cSrcweir                 &&  xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
499cdf0e10cSrcweir                 && (nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
500cdf0e10cSrcweir                 && (!xStor.is() || !xStor->isReadonly()) )
501cdf0e10cSrcweir             {
502cdf0e10cSrcweir                 // the extra 1 is because of the (possible) external
503cdf0e10cSrcweir                 // linguistic entry above
504cdf0e10cSrcweir                 pMenu->InsertItem( nItemId, xDicTmp->getName() );
505cdf0e10cSrcweir                 bEnable = sal_True;
506cdf0e10cSrcweir 
507cdf0e10cSrcweir                 uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
508cdf0e10cSrcweir                 if (xSvcInfo.is())
509cdf0e10cSrcweir                 {
510cdf0e10cSrcweir                     OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
511cdf0e10cSrcweir                             xSvcInfo->getImplementationName(), bHC) );
512cdf0e10cSrcweir                     if (aDictionaryImageUrl.getLength() > 0)
513cdf0e10cSrcweir                     {
514cdf0e10cSrcweir                         Image aImage( lcl_GetImageFromPngUrl( aDictionaryImageUrl ) );
515cdf0e10cSrcweir                         pMenu->SetItemImage( nItemId, aImage );
516cdf0e10cSrcweir                     }
517cdf0e10cSrcweir                 }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir                 ++nItemId;
520cdf0e10cSrcweir             }
521cdf0e10cSrcweir         }
522cdf0e10cSrcweir     }
523cdf0e10cSrcweir     EnableItem( MN_ADD_TO_DIC, bEnable );
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     //ADD NEW LANGUAGE MENU ITEM
526cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////////////////
527cdf0e10cSrcweir     String aScriptTypesInUse( String::CreateFromInt32( pWrtSh->GetScriptType() ) );
528cdf0e10cSrcweir     SvtLanguageTable aLanguageTable;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir     // get keyboard language
531cdf0e10cSrcweir     String aKeyboardLang;
532cdf0e10cSrcweir     LanguageType nLang = LANGUAGE_DONTKNOW;
533cdf0e10cSrcweir     SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
534cdf0e10cSrcweir     nLang = rEditWin.GetInputLanguage();
535cdf0e10cSrcweir     if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
536cdf0e10cSrcweir         aKeyboardLang = aLanguageTable.GetString( nLang );
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     // get the language that is in use
539cdf0e10cSrcweir     const String aMultipleLanguages = String::CreateFromAscii("*");
540cdf0e10cSrcweir     String aCurrentLang = aMultipleLanguages;
541cdf0e10cSrcweir     nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh );
542cdf0e10cSrcweir     if (nLang != LANGUAGE_DONTKNOW)
543cdf0e10cSrcweir         aCurrentLang = aLanguageTable.GetString( nLang );
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     // build sequence for status value
546cdf0e10cSrcweir     uno::Sequence< OUString > aSeq( 4 );
547cdf0e10cSrcweir     aSeq[0] = aCurrentLang;
548cdf0e10cSrcweir     aSeq[1] = aScriptTypesInUse;
549cdf0e10cSrcweir     aSeq[2] = aKeyboardLang;
550cdf0e10cSrcweir     aSeq[3] = aLanguageTable.GetString(nGuessLangWord);
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_SET_LANGUAGE_SELECTION);
553cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_SELECTION_START, aSeq, pWrtSh, aLangTable_Text );
554cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_SELECTION, true );
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_SET_LANGUAGE_PARAGRAPH);
557cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_PARAGRAPH_START, aSeq, pWrtSh, aLangTable_Paragraph );
558cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_PARAGRAPH, true );
559cdf0e10cSrcweir /*
560cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_SET_LANGUAGE_ALL_TEXT);
561cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_ALL_TEXT_START, aSeq, pWrtSh, aLangTable_Document );
562cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_ALL_TEXT, true );
563cdf0e10cSrcweir */
564cdf0e10cSrcweir     uno::Reference< frame::XFrame > xFrame = pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface();
565cdf0e10cSrcweir     Image rImg = ::GetImage( xFrame,
566cdf0e10cSrcweir             OUString::createFromAscii(".uno:SpellingAndGrammarDialog"), sal_False,
567cdf0e10cSrcweir             Application::GetSettings().GetStyleSettings().GetHighContrastMode() );
568cdf0e10cSrcweir     SetItemImage( MN_SPELLING_DLG, rImg );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////////////////
571cdf0e10cSrcweir 
572cdf0e10cSrcweir     RemoveDisabledEntries( sal_True, sal_True );
573cdf0e10cSrcweir }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir /*--------------------------------------------------------------------------
576cdf0e10cSrcweir 
577cdf0e10cSrcweir ---------------------------------------------------------------------------*/
578cdf0e10cSrcweir 
SwSpellPopup(SwWrtShell * pWrtSh,const linguistic2::ProofreadingResult & rResult,sal_Int32 nErrorInResult,const uno::Sequence<OUString> & rSuggestions,const String & rParaText)579cdf0e10cSrcweir SwSpellPopup::SwSpellPopup(
580cdf0e10cSrcweir     SwWrtShell *pWrtSh,
581cdf0e10cSrcweir     const linguistic2::ProofreadingResult &rResult,
582cdf0e10cSrcweir     sal_Int32 nErrorInResult,
583cdf0e10cSrcweir     const uno::Sequence< OUString > &rSuggestions,
584cdf0e10cSrcweir     const String &rParaText ) :
585cdf0e10cSrcweir PopupMenu( SW_RES(MN_SPELL_POPUP) ),
586cdf0e10cSrcweir pSh( pWrtSh ),
587cdf0e10cSrcweir aSuggestions( rSuggestions ),
588cdf0e10cSrcweir bGrammarResults( true ),
589cdf0e10cSrcweir aInfo16( SW_RES(IMG_INFO_16) )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir     nCheckedLanguage = SvxLocaleToLanguage( rResult.aLocale );
592cdf0e10cSrcweir 
593cdf0e10cSrcweir     sal_uInt16 nPos = 0;
594cdf0e10cSrcweir     OUString aMessageText( rResult.aErrors[ nErrorInResult ].aShortComment );
595cdf0e10cSrcweir     InsertSeparator( nPos++ );
596cdf0e10cSrcweir     InsertItem( MN_SHORT_COMMENT, aMessageText, MIB_NOSELECT, nPos++ );
597cdf0e10cSrcweir     SetItemImage( MN_SHORT_COMMENT, aInfo16 );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir //    CreateAutoMnemonics();
600cdf0e10cSrcweir     SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir     InsertSeparator( nPos++ );
603cdf0e10cSrcweir     sal_Int32 nStringCount = aSuggestions.getLength();
604cdf0e10cSrcweir     if ( nStringCount )     // suggestions available...
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         Image aImage;
607cdf0e10cSrcweir         OUString aSuggestionImageUrl;
608cdf0e10cSrcweir         uno::Reference< lang::XServiceInfo > xInfo( rResult.xProofreader, uno::UNO_QUERY );
609cdf0e10cSrcweir         if (xInfo.is())
610cdf0e10cSrcweir         {
611cdf0e10cSrcweir             aSuggestionImageUrl = SvtLinguConfig().GetSpellAndGrammarContextSuggestionImage( xInfo->getImplementationName() );
612cdf0e10cSrcweir             aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
613cdf0e10cSrcweir         }
614cdf0e10cSrcweir 
615cdf0e10cSrcweir         sal_uInt16 nItemId = MN_SUGGESTION_START;
616cdf0e10cSrcweir         for (sal_uInt16 i = 0;  i < nStringCount;  ++i)
617cdf0e10cSrcweir         {
618cdf0e10cSrcweir             const String aEntry = aSuggestions[ i ];
619cdf0e10cSrcweir             InsertItem( nItemId, aEntry, 0, nPos++ );
620cdf0e10cSrcweir             SetHelpId( nItemId, HID_LINGU_REPLACE );
621cdf0e10cSrcweir             if (aSuggestionImageUrl.getLength() > 0)
622cdf0e10cSrcweir                 SetItemImage( nItemId, aImage );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir             ++nItemId;
625cdf0e10cSrcweir         }
626cdf0e10cSrcweir         InsertSeparator( nPos++ );
627cdf0e10cSrcweir     }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     OUString aIgnoreSelection( String( SW_RES( STR_IGNORE_SELECTION ) ) );
630cdf0e10cSrcweir     OUString aSpellingAndGrammar = RetrieveLabelFromCommand( C2U(".uno:SpellingAndGrammarDialog") );
631cdf0e10cSrcweir     SetItemText( MN_SPELLING_DLG, aSpellingAndGrammar );
632cdf0e10cSrcweir     sal_uInt16 nItemPos = GetItemPos( MN_IGNORE_WORD );
633cdf0e10cSrcweir     InsertItem( MN_IGNORE_SELECTION, aIgnoreSelection, 0, nItemPos );
634cdf0e10cSrcweir     SetHelpId( MN_IGNORE_SELECTION, HID_LINGU_IGNORE_SELECTION);
635cdf0e10cSrcweir 
636cdf0e10cSrcweir     EnableItem( MN_AUTOCORR, false );
637cdf0e10cSrcweir 
638cdf0e10cSrcweir     uno::Reference< linguistic2::XLanguageGuessing > xLG = SW_MOD()->GetLanguageGuesser();
639cdf0e10cSrcweir     nGuessLangWord = LANGUAGE_NONE;
640cdf0e10cSrcweir     nGuessLangPara = LANGUAGE_NONE;
641cdf0e10cSrcweir     if (xLG.is())
642cdf0e10cSrcweir     {
643cdf0e10cSrcweir //        nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), ::GetSpellChecker(), xLG, sal_False );
644cdf0e10cSrcweir         nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, sal_True );
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir     if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
647cdf0e10cSrcweir     {
648cdf0e10cSrcweir         // make sure LANGUAGE_NONE gets not used as menu entry
649cdf0e10cSrcweir         if (nGuessLangWord == LANGUAGE_NONE)
650cdf0e10cSrcweir             nGuessLangWord = nGuessLangPara;
651cdf0e10cSrcweir         if (nGuessLangPara == LANGUAGE_NONE)
652cdf0e10cSrcweir             nGuessLangPara = nGuessLangWord;
653cdf0e10cSrcweir     }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir     EnableItem( MN_IGNORE_WORD, false );
656cdf0e10cSrcweir     EnableItem( MN_ADD_TO_DIC, false );
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     //ADD NEW LANGUAGE MENU ITEM
659cdf0e10cSrcweir     ///////////////////////////////////////////////////////////////////////////
660cdf0e10cSrcweir     String aScriptTypesInUse( String::CreateFromInt32( pWrtSh->GetScriptType() ) );
661cdf0e10cSrcweir     SvtLanguageTable aLanguageTable;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     // get keyboard language
664cdf0e10cSrcweir     String aKeyboardLang;
665cdf0e10cSrcweir     LanguageType nLang = LANGUAGE_DONTKNOW;
666cdf0e10cSrcweir     SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
667cdf0e10cSrcweir     nLang = rEditWin.GetInputLanguage();
668cdf0e10cSrcweir     if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
669cdf0e10cSrcweir         aKeyboardLang = aLanguageTable.GetString( nLang );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     // get the language that is in use
672cdf0e10cSrcweir     const String aMultipleLanguages = String::CreateFromAscii("*");
673cdf0e10cSrcweir     String aCurrentLang = aMultipleLanguages;
674cdf0e10cSrcweir     nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh );
675cdf0e10cSrcweir     if (nLang != LANGUAGE_DONTKNOW)
676cdf0e10cSrcweir         aCurrentLang = aLanguageTable.GetString( nLang );
677cdf0e10cSrcweir 
678cdf0e10cSrcweir     // build sequence for status value
679cdf0e10cSrcweir     uno::Sequence< OUString > aSeq( 4 );
680cdf0e10cSrcweir     aSeq[0] = aCurrentLang;
681cdf0e10cSrcweir     aSeq[1] = aScriptTypesInUse;
682cdf0e10cSrcweir     aSeq[2] = aKeyboardLang;
683cdf0e10cSrcweir     aSeq[3] = aLanguageTable.GetString(nGuessLangWord);
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     PopupMenu *pMenu = GetPopupMenu(MN_SET_LANGUAGE_SELECTION);
686cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_SELECTION_START, aSeq, pWrtSh, aLangTable_Text );
687cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_SELECTION, true );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_SET_LANGUAGE_PARAGRAPH);
690cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_PARAGRAPH_START, aSeq, pWrtSh, aLangTable_Paragraph );
691cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_PARAGRAPH, true );
692cdf0e10cSrcweir /*
693cdf0e10cSrcweir     pMenu = GetPopupMenu(MN_SET_LANGUAGE_ALL_TEXT);
694cdf0e10cSrcweir     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_ALL_TEXT_START, aSeq, pWrtSh, aLangTable_Document );
695cdf0e10cSrcweir     EnableItem( MN_SET_LANGUAGE_ALL_TEXT, true );
696cdf0e10cSrcweir */
697cdf0e10cSrcweir     uno::Reference< frame::XFrame > xFrame = pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface();
698cdf0e10cSrcweir     Image rImg = ::GetImage( xFrame,
699cdf0e10cSrcweir             OUString::createFromAscii(".uno:SpellingAndGrammarDialog"), sal_False,
700cdf0e10cSrcweir             Application::GetSettings().GetStyleSettings().GetHighContrastMode() );
701cdf0e10cSrcweir     SetItemImage( MN_SPELLING_DLG, rImg );
702cdf0e10cSrcweir 
703cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////////////////
704cdf0e10cSrcweir 
705cdf0e10cSrcweir     RemoveDisabledEntries( sal_True, sal_True );
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir /*--------------------------------------------------------------------------
709cdf0e10cSrcweir 
710cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Execute(const Rectangle & rWordPos,Window * pWin)711cdf0e10cSrcweir sal_uInt16  SwSpellPopup::Execute( const Rectangle& rWordPos, Window* pWin )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir //    SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
714cdf0e10cSrcweir     sal_uInt16 nRet = PopupMenu::Execute(pWin, pWin->LogicToPixel(rWordPos));
715cdf0e10cSrcweir     Execute( nRet );
716cdf0e10cSrcweir     return nRet;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir /*-- 19.01.2006 08:15:48---------------------------------------------------
719cdf0e10cSrcweir 
720cdf0e10cSrcweir   -----------------------------------------------------------------------*/
Execute(sal_uInt16 nId)721cdf0e10cSrcweir void SwSpellPopup::Execute( sal_uInt16 nId )
722cdf0e10cSrcweir {
723cdf0e10cSrcweir     if (nId == USHRT_MAX)
724cdf0e10cSrcweir         return;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     if (/*bGrammarResults && */nId == MN_SHORT_COMMENT)
727cdf0e10cSrcweir         return;     // nothing to do since it is the error message (short comment)
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     if ((MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ||
730cdf0e10cSrcweir         (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END))
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir         sal_Int32 nAltIdx = (MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ?
733cdf0e10cSrcweir                 nId - MN_SUGGESTION_START : nId - MN_AUTOCORR_START;
734cdf0e10cSrcweir         DBG_ASSERT( 0 <= nAltIdx && nAltIdx < aSuggestions.getLength(), "index out of range" );
735cdf0e10cSrcweir         if (0 <= nAltIdx && nAltIdx < aSuggestions.getLength() && (bGrammarResults || xSpellAlt.is()))
736cdf0e10cSrcweir         {
737cdf0e10cSrcweir             sal_Bool bOldIns = pSh->IsInsMode();
738cdf0e10cSrcweir             pSh->SetInsMode( sal_True );
739cdf0e10cSrcweir 
740cdf0e10cSrcweir             String aTmp( aSuggestions[ nAltIdx ] );
741cdf0e10cSrcweir             String aOrig( bGrammarResults ? OUString() : xSpellAlt->getWord() );
742cdf0e10cSrcweir 
743*86e1cf34SPedro Giffuni             // if original word has a trailing . (likely the end of a sentence)
744cdf0e10cSrcweir             // and the replacement text hasn't, then add it to the replacement
745cdf0e10cSrcweir             if (aTmp.Len() && aOrig.Len() &&
746cdf0e10cSrcweir                 '.' == aOrig.GetChar( aOrig.Len() - 1) && /* !IsAlphaNumeric ??*/
747cdf0e10cSrcweir                 '.' != aTmp.GetChar( aTmp.Len() - 1))
748cdf0e10cSrcweir             {
749cdf0e10cSrcweir                 aTmp += '.';
750cdf0e10cSrcweir             }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir             // #111827#
753cdf0e10cSrcweir             SwRewriter aRewriter;
754cdf0e10cSrcweir 
755cdf0e10cSrcweir             aRewriter.AddRule(UNDO_ARG1, pSh->GetCrsrDescr());
756cdf0e10cSrcweir             aRewriter.AddRule(UNDO_ARG2, String(SW_RES(STR_YIELDS)));
757cdf0e10cSrcweir 
758cdf0e10cSrcweir             String aTmpStr( SW_RES(STR_START_QUOTE) );
759cdf0e10cSrcweir             aTmpStr += aTmp;
760cdf0e10cSrcweir             aTmpStr += String(SW_RES(STR_END_QUOTE));
761cdf0e10cSrcweir             aRewriter.AddRule(UNDO_ARG3, aTmpStr);
762cdf0e10cSrcweir 
763cdf0e10cSrcweir             pSh->StartUndo(UNDO_UI_REPLACE, &aRewriter);
764cdf0e10cSrcweir             pSh->StartAction();
765cdf0e10cSrcweir             pSh->DelLeft();
766cdf0e10cSrcweir 
767cdf0e10cSrcweir             pSh->Insert( aTmp );
768cdf0e10cSrcweir 
769cdf0e10cSrcweir             /* #102505# EndAction/EndUndo moved down since insertion
770cdf0e10cSrcweir                of temporary auto correction is now undoable two and
771cdf0e10cSrcweir                must reside in the same undo group.*/
772cdf0e10cSrcweir 
773cdf0e10cSrcweir             // nur aufnehmen, wenn es NICHT schon in der Autokorrektur vorhanden ist
774cdf0e10cSrcweir             SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get()->GetAutoCorrect();
775cdf0e10cSrcweir 
776cdf0e10cSrcweir             String aOrigWord( bGrammarResults ? OUString() : xSpellAlt->getWord() ) ;
777cdf0e10cSrcweir             String aNewWord( aSuggestions[ nAltIdx ] );
778cdf0e10cSrcweir             SvxPrepareAutoCorrect( aOrigWord, aNewWord );
779cdf0e10cSrcweir 
780cdf0e10cSrcweir             if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END)
781cdf0e10cSrcweir                 pACorr->PutText( aOrigWord, aNewWord, nCheckedLanguage );
782cdf0e10cSrcweir 
783cdf0e10cSrcweir             /* #102505# EndAction/EndUndo moved down since insertion
784cdf0e10cSrcweir                of temporary auto correction is now undoable two and
785cdf0e10cSrcweir                must reside in the same undo group.*/
786cdf0e10cSrcweir             pSh->EndAction();
787cdf0e10cSrcweir             pSh->EndUndo();
788cdf0e10cSrcweir 
789cdf0e10cSrcweir             pSh->SetInsMode( bOldIns );
790cdf0e10cSrcweir         }
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir     else if (nId == MN_SPELLING_DLG)
793cdf0e10cSrcweir     {
794cdf0e10cSrcweir         if (bGrammarResults)
795cdf0e10cSrcweir         {
796cdf0e10cSrcweir             SvtLinguConfig().SetProperty( A2OU( UPN_IS_GRAMMAR_INTERACTIVE ), uno::makeAny( sal_True ));
797cdf0e10cSrcweir         }
798cdf0e10cSrcweir         pSh->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
799cdf0e10cSrcweir         {
800cdf0e10cSrcweir             uno::Reference<linguistic2::XDictionaryList> xDictionaryList( SvxGetDictionaryList() );
801cdf0e10cSrcweir             SvxDicListChgClamp aClamp( xDictionaryList );
802cdf0e10cSrcweir             pSh->GetView().GetViewFrame()->GetDispatcher()->
803cdf0e10cSrcweir                 Execute( FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON );
804cdf0e10cSrcweir         }
805cdf0e10cSrcweir     }
806cdf0e10cSrcweir     else if (nId == MN_IGNORE_SELECTION)
807cdf0e10cSrcweir     {
808cdf0e10cSrcweir         SwPaM *pPaM = pSh->GetCrsr();
809cdf0e10cSrcweir         if (pPaM)
810cdf0e10cSrcweir             pSh->IgnoreGrammarErrorAt( *pPaM );
811cdf0e10cSrcweir     }
812cdf0e10cSrcweir     else if (nId == MN_IGNORE_WORD)
813cdf0e10cSrcweir     {
814cdf0e10cSrcweir         uno::Reference< linguistic2::XDictionary > xDictionary( SvxGetIgnoreAllList(), uno::UNO_QUERY );
815cdf0e10cSrcweir         linguistic::AddEntryToDic( xDictionary,
816cdf0e10cSrcweir                 xSpellAlt->getWord(), sal_False, aEmptyStr, LANGUAGE_NONE );
817cdf0e10cSrcweir     }
818cdf0e10cSrcweir     else if (MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END)
819cdf0e10cSrcweir     {
820cdf0e10cSrcweir             OUString aWord( xSpellAlt->getWord() );
821cdf0e10cSrcweir 
822cdf0e10cSrcweir             PopupMenu *pMenu = GetPopupMenu(MN_ADD_TO_DIC);
823cdf0e10cSrcweir             String aDicName ( pMenu->GetItemText(nId) );
824cdf0e10cSrcweir 
825cdf0e10cSrcweir             uno::Reference< linguistic2::XDictionary >      xDic;
826cdf0e10cSrcweir             uno::Reference< linguistic2::XDictionaryList >  xDicList( SvxGetDictionaryList() );
827cdf0e10cSrcweir             if (xDicList.is())
828cdf0e10cSrcweir                 xDic = xDicList->getDictionaryByName( aDicName );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir             if (xDic.is())
831cdf0e10cSrcweir             {
832cdf0e10cSrcweir                 sal_Int16 nAddRes = linguistic::AddEntryToDic( xDic, aWord, sal_False, aEmptyStr, LANGUAGE_NONE );
833cdf0e10cSrcweir                 // save modified user-dictionary if it is persistent
834cdf0e10cSrcweir                 uno::Reference< frame::XStorable >  xSavDic( xDic, uno::UNO_QUERY );
835cdf0e10cSrcweir                 if (xSavDic.is())
836cdf0e10cSrcweir                     xSavDic->store();
837cdf0e10cSrcweir 
838cdf0e10cSrcweir                 if (DIC_ERR_NONE != nAddRes
839cdf0e10cSrcweir                     && !xDic->getEntry( aWord ).is())
840cdf0e10cSrcweir                 {
841cdf0e10cSrcweir                     SvxDicError(
842cdf0e10cSrcweir                         &pSh->GetView().GetViewFrame()->GetWindow(),
843cdf0e10cSrcweir                         nAddRes );
844cdf0e10cSrcweir                 }
845cdf0e10cSrcweir             }
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir     else
848cdf0e10cSrcweir     {
849cdf0e10cSrcweir         // Set language for selection or for paragraph...
850cdf0e10cSrcweir 
851cdf0e10cSrcweir         SfxItemSet aCoreSet( pSh->GetView().GetPool(),
852cdf0e10cSrcweir                     RES_CHRATR_LANGUAGE,        RES_CHRATR_LANGUAGE,
853cdf0e10cSrcweir                     RES_CHRATR_CJK_LANGUAGE,    RES_CHRATR_CJK_LANGUAGE,
854cdf0e10cSrcweir                     RES_CHRATR_CTL_LANGUAGE,    RES_CHRATR_CTL_LANGUAGE,
855cdf0e10cSrcweir                     0 );
856cdf0e10cSrcweir         String aNewLangTxt;
857cdf0e10cSrcweir 
858cdf0e10cSrcweir         if (MN_SET_LANGUAGE_SELECTION_START <= nId && nId <= MN_SET_LANGUAGE_SELECTION_END)
859cdf0e10cSrcweir         {
860cdf0e10cSrcweir             //Set language for current selection
861cdf0e10cSrcweir             aNewLangTxt = aLangTable_Text[nId];
862cdf0e10cSrcweir             SwLangHelper::SetLanguage( *pSh, aNewLangTxt, true, aCoreSet );
863cdf0e10cSrcweir         }
864cdf0e10cSrcweir         else if (nId == MN_SET_SELECTION_NONE)
865cdf0e10cSrcweir         {
866cdf0e10cSrcweir             //Set Language_None for current selection
867cdf0e10cSrcweir             SwLangHelper::SetLanguage_None( *pSh, true, aCoreSet );
868cdf0e10cSrcweir         }
869cdf0e10cSrcweir         else if (nId == MN_SET_SELECTION_RESET)
870cdf0e10cSrcweir         {
871cdf0e10cSrcweir             //reset languages for current selection
872cdf0e10cSrcweir             SwLangHelper::ResetLanguages( *pSh, true );
873cdf0e10cSrcweir         }
874cdf0e10cSrcweir         else if (nId == MN_SET_SELECTION_MORE)
875cdf0e10cSrcweir         {
876cdf0e10cSrcweir             //Open Format/Character Dialog
877cdf0e10cSrcweir             lcl_CharDialog( *pSh, true, nId, 0, 0 );
878cdf0e10cSrcweir         }
879cdf0e10cSrcweir         else if (MN_SET_LANGUAGE_PARAGRAPH_START <= nId && nId <= MN_SET_LANGUAGE_PARAGRAPH_END)
880cdf0e10cSrcweir         {
881cdf0e10cSrcweir             //Set language for current paragraph
882cdf0e10cSrcweir             aNewLangTxt = aLangTable_Paragraph[nId];
883cdf0e10cSrcweir             pSh->Push();        // save cursor
884cdf0e10cSrcweir             SwLangHelper::SelectCurrentPara( *pSh );
885cdf0e10cSrcweir             SwLangHelper::SetLanguage( *pSh, aNewLangTxt, true, aCoreSet );
886cdf0e10cSrcweir             pSh->Pop( sal_False );  // restore cursor
887cdf0e10cSrcweir         }
888cdf0e10cSrcweir         else if (nId == MN_SET_PARA_NONE)
889cdf0e10cSrcweir         {
890cdf0e10cSrcweir             //Set Language_None for current paragraph
891cdf0e10cSrcweir             pSh->Push();        // save cursor
892cdf0e10cSrcweir             SwLangHelper::SelectCurrentPara( *pSh );
893cdf0e10cSrcweir             SwLangHelper::SetLanguage_None( *pSh, true, aCoreSet );
894cdf0e10cSrcweir             pSh->Pop( sal_False );  // restore cursor
895cdf0e10cSrcweir         }
896cdf0e10cSrcweir         else if (nId == MN_SET_PARA_RESET)
897cdf0e10cSrcweir         {
898cdf0e10cSrcweir             //reset languages for current paragraph
899cdf0e10cSrcweir             pSh->Push();        // save cursor
900cdf0e10cSrcweir             SwLangHelper::SelectCurrentPara( *pSh );
901cdf0e10cSrcweir             SwLangHelper::ResetLanguages( *pSh, true );
902cdf0e10cSrcweir             pSh->Pop( sal_False );  // restore cursor
903cdf0e10cSrcweir         }
904cdf0e10cSrcweir         else if (nId == MN_SET_PARA_MORE)
905cdf0e10cSrcweir         {
906cdf0e10cSrcweir             pSh->Push();        // save cursor
907cdf0e10cSrcweir             SwLangHelper::SelectCurrentPara( *pSh );
908cdf0e10cSrcweir             //Open Format/Character Dialog
909cdf0e10cSrcweir             lcl_CharDialog( *pSh, true, nId, 0, 0 );
910cdf0e10cSrcweir             pSh->Pop( sal_False );  // restore cursor
911cdf0e10cSrcweir         }
912cdf0e10cSrcweir #if 0
913cdf0e10cSrcweir         else if (nId == MN_SET_LANGUAGE_ALL_TEXT_START + nNumLanguageDocEntries - 1)
914cdf0e10cSrcweir         {
915cdf0e10cSrcweir             //Set Language_None as the default language
916cdf0e10cSrcweir             SwLangHelper::SetLanguage_None( *pSh, false, aCoreSet );
917cdf0e10cSrcweir         }
918cdf0e10cSrcweir         else if (nId == MN_SET_LANGUAGE_ALL_TEXT_START + nNumLanguageDocEntries)
919cdf0e10cSrcweir         {
920cdf0e10cSrcweir             // open the dialog "Tools/Options/Language Settings - Language"
921cdf0e10cSrcweir             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
922cdf0e10cSrcweir             if (pFact)
923cdf0e10cSrcweir             {
924cdf0e10cSrcweir                 VclAbstractDialog* pDlg = pFact->CreateVclDialog( pSh->GetView().GetWindow(), SID_LANGUAGE_OPTIONS );
925cdf0e10cSrcweir                 pDlg->Execute();
926cdf0e10cSrcweir                 delete pDlg;
927cdf0e10cSrcweir             }
928cdf0e10cSrcweir         }
929cdf0e10cSrcweir #endif
930cdf0e10cSrcweir     }
931cdf0e10cSrcweir 
932cdf0e10cSrcweir     pSh->EnterStdMode();
933cdf0e10cSrcweir }
934