xref: /aoo41x/main/sw/source/ui/uiview/viewling.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <hintids.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifndef _SVSTDARR_HXX
35*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
36*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/linguistic2/XThesaurus.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/linguistic2/ProofreadingResult.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hpp>
42*cdf0e10cSrcweir #include <linguistic/lngprops.hxx>
43*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
45*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
47*cdf0e10cSrcweir #include <svl/stritem.hxx>
48*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
49*cdf0e10cSrcweir #include <sfx2/request.hxx>
50*cdf0e10cSrcweir #include <svx/dlgutil.hxx>
51*cdf0e10cSrcweir #include <svx/dialmgr.hxx>
52*cdf0e10cSrcweir #include <editeng/langitem.hxx>
53*cdf0e10cSrcweir #include <svx/svxerr.hxx>
54*cdf0e10cSrcweir #include <editeng/unolingu.hxx>
55*cdf0e10cSrcweir #include <svx/svxdlg.hxx>
56*cdf0e10cSrcweir #include <editeng/SpellPortions.hxx>
57*cdf0e10cSrcweir #include <swmodule.hxx>
58*cdf0e10cSrcweir #include <swwait.hxx>
59*cdf0e10cSrcweir #include <initui.hxx>				// fuer SpellPointer
60*cdf0e10cSrcweir #include <uitool.hxx>
61*cdf0e10cSrcweir #include <view.hxx>
62*cdf0e10cSrcweir #include <wrtsh.hxx>
63*cdf0e10cSrcweir #include <basesh.hxx>
64*cdf0e10cSrcweir #include <docsh.hxx>				// CheckSpellChanges
65*cdf0e10cSrcweir #include <viewopt.hxx>				// Viewoptions
66*cdf0e10cSrcweir #include <swundo.hxx>               // fuer Undo-Ids
67*cdf0e10cSrcweir #include <hyp.hxx>                  // Trennung
68*cdf0e10cSrcweir #include <olmenu.hxx>				// PopupMenu fuer OnlineSpelling
69*cdf0e10cSrcweir #include <pam.hxx>					// Spelling: Multiselektion
70*cdf0e10cSrcweir #include <edtwin.hxx>
71*cdf0e10cSrcweir #include <crsskip.hxx>
72*cdf0e10cSrcweir #include <ndtxt.hxx>
73*cdf0e10cSrcweir #include <vcl/lstbox.hxx>
74*cdf0e10cSrcweir #include <cmdid.h>
75*cdf0e10cSrcweir #include <globals.hrc>
76*cdf0e10cSrcweir #include <comcore.hrc>				// STR_MULT_INTERACT_SPELL_WARN
77*cdf0e10cSrcweir #include <view.hrc>
78*cdf0e10cSrcweir #include <hhcwrp.hxx>
79*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
82*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
83*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
84*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
85*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
86*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
87*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
88*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir #include <unotools/processfactory.hxx>
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir #include <vcl/svapp.hxx>
93*cdf0e10cSrcweir #include <rtl/ustring.hxx>
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
96*cdf0e10cSrcweir #include "stmenu.hxx"              // PopupMenu for smarttags
97*cdf0e10cSrcweir #include <svx/dialogs.hrc>
98*cdf0e10cSrcweir #include <svtools/langtab.hxx>
99*cdf0e10cSrcweir #include <unomid.h>
100*cdf0e10cSrcweir #include <IMark.hxx>
101*cdf0e10cSrcweir #include <xmloff/odffields.hxx>
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir #include <memory>
104*cdf0e10cSrcweir #include <editeng/editerr.hxx>
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir using namespace sw::mark;
107*cdf0e10cSrcweir using ::rtl::OUString;
108*cdf0e10cSrcweir using namespace ::com::sun::star;
109*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
110*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
111*cdf0e10cSrcweir using namespace ::com::sun::star::linguistic2;
112*cdf0e10cSrcweir using namespace ::com::sun::star::smarttags;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir /*--------------------------------------------------------------------
115*cdf0e10cSrcweir 	Beschreibung:	Lingu-Dispatcher
116*cdf0e10cSrcweir  --------------------------------------------------------------------*/
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir void SwView::ExecLingu(SfxRequest &rReq)
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir 	switch(rReq.GetSlot())
122*cdf0e10cSrcweir 	{
123*cdf0e10cSrcweir         case SID_THESAURUS:
124*cdf0e10cSrcweir 			StartThesaurus();
125*cdf0e10cSrcweir             rReq.Ignore();
126*cdf0e10cSrcweir 			break;
127*cdf0e10cSrcweir         case SID_HANGUL_HANJA_CONVERSION:
128*cdf0e10cSrcweir             StartTextConversion( LANGUAGE_KOREAN, LANGUAGE_KOREAN, NULL,
129*cdf0e10cSrcweir                     i18n::TextConversionOption::CHARACTER_BY_CHARACTER, sal_True );
130*cdf0e10cSrcweir             break;
131*cdf0e10cSrcweir         case SID_CHINESE_CONVERSION:
132*cdf0e10cSrcweir         {
133*cdf0e10cSrcweir             //open ChineseTranslationDialog
134*cdf0e10cSrcweir             Reference< XComponentContext > xContext(
135*cdf0e10cSrcweir                 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
136*cdf0e10cSrcweir             if(xContext.is())
137*cdf0e10cSrcweir             {
138*cdf0e10cSrcweir                 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
139*cdf0e10cSrcweir                 if(xMCF.is())
140*cdf0e10cSrcweir                 {
141*cdf0e10cSrcweir 			        Reference< ui::dialogs::XExecutableDialog > xDialog(
142*cdf0e10cSrcweir                             xMCF->createInstanceWithContext(
143*cdf0e10cSrcweir                                 rtl::OUString::createFromAscii("com.sun.star.linguistic2.ChineseTranslationDialog")
144*cdf0e10cSrcweir                                 , xContext), UNO_QUERY);
145*cdf0e10cSrcweir                     Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
146*cdf0e10cSrcweir                     if( xInit.is() )
147*cdf0e10cSrcweir 			        {
148*cdf0e10cSrcweir                         //	initialize dialog
149*cdf0e10cSrcweir                         Reference< awt::XWindow > xDialogParentWindow(0);
150*cdf0e10cSrcweir 					    Sequence<Any> aSeq(1);
151*cdf0e10cSrcweir 					    Any* pArray = aSeq.getArray();
152*cdf0e10cSrcweir                         PropertyValue aParam;
153*cdf0e10cSrcweir                         aParam.Name = rtl::OUString::createFromAscii("ParentWindow");
154*cdf0e10cSrcweir                         aParam.Value <<= makeAny(xDialogParentWindow);
155*cdf0e10cSrcweir 					    pArray[0] <<= makeAny(aParam);
156*cdf0e10cSrcweir                         xInit->initialize( aSeq );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir                         //execute dialog
159*cdf0e10cSrcweir 				        sal_Int16 nDialogRet = xDialog->execute();
160*cdf0e10cSrcweir                         if( RET_OK == nDialogRet )
161*cdf0e10cSrcweir                         {
162*cdf0e10cSrcweir                             //get some parameters from the dialog
163*cdf0e10cSrcweir                             sal_Bool bToSimplified = sal_True;
164*cdf0e10cSrcweir                             sal_Bool bUseVariants = sal_True;
165*cdf0e10cSrcweir                             sal_Bool bCommonTerms = sal_True;
166*cdf0e10cSrcweir                             Reference< beans::XPropertySet >  xProp( xDialog, UNO_QUERY );
167*cdf0e10cSrcweir                             if( xProp.is() )
168*cdf0e10cSrcweir                             {
169*cdf0e10cSrcweir                                 try
170*cdf0e10cSrcweir                                 {
171*cdf0e10cSrcweir                                     xProp->getPropertyValue( C2U("IsDirectionToSimplified") ) >>= bToSimplified;
172*cdf0e10cSrcweir                                     xProp->getPropertyValue( C2U("IsUseCharacterVariants") ) >>= bUseVariants;
173*cdf0e10cSrcweir                                     xProp->getPropertyValue( C2U("IsTranslateCommonTerms") ) >>= bCommonTerms;
174*cdf0e10cSrcweir                                 }
175*cdf0e10cSrcweir                                 catch( Exception& )
176*cdf0e10cSrcweir                                 {
177*cdf0e10cSrcweir                                 }
178*cdf0e10cSrcweir                             }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir                             //execute translation
181*cdf0e10cSrcweir                             sal_Int16 nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
182*cdf0e10cSrcweir                             sal_Int16 nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
183*cdf0e10cSrcweir                             sal_Int32 nOptions    = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
184*cdf0e10cSrcweir                             if( !bCommonTerms )
185*cdf0e10cSrcweir                                 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir                             Font aTargetFont = GetEditWin().GetDefaultFont( DEFAULTFONT_CJK_TEXT,
188*cdf0e10cSrcweir                                                     nTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 							// disallow formatting, updating the view, ... while
191*cdf0e10cSrcweir 							// converting the document. (saves time)
192*cdf0e10cSrcweir 							// Also remember the current view and cursor position for later
193*cdf0e10cSrcweir 							pWrtShell->StartAction();
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 							// remember cursor position data for later restoration of the cursor
196*cdf0e10cSrcweir 							const SwPosition *pPoint = pWrtShell->GetCrsr()->GetPoint();
197*cdf0e10cSrcweir 							sal_Bool bRestoreCursor = pPoint->nNode.GetNode().IsTxtNode();
198*cdf0e10cSrcweir 							const SwNodeIndex aPointNodeIndex( pPoint->nNode );
199*cdf0e10cSrcweir 							xub_StrLen nPointIndex = pPoint->nContent.GetIndex();;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 							// since this conversion is not interactive the whole converted
202*cdf0e10cSrcweir 							// document should be undone in a single undo step.
203*cdf0e10cSrcweir 					        pWrtShell->StartUndo( UNDO_OVERWRITE );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 							StartTextConversion( nSourceLang, nTargetLang, &aTargetFont, nOptions, sal_False );
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 							pWrtShell->EndUndo( UNDO_OVERWRITE );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 							if (bRestoreCursor)
210*cdf0e10cSrcweir 							{
211*cdf0e10cSrcweir 								SwTxtNode *pTxtNode = aPointNodeIndex.GetNode().GetTxtNode();
212*cdf0e10cSrcweir 								// check for unexpected error case
213*cdf0e10cSrcweir 								DBG_ASSERT( pTxtNode && pTxtNode->GetTxt().Len() >= nPointIndex,
214*cdf0e10cSrcweir 									"text missing: corrupted node?" );
215*cdf0e10cSrcweir 								if (!pTxtNode || pTxtNode->GetTxt().Len() < nPointIndex)
216*cdf0e10cSrcweir 									nPointIndex = 0;
217*cdf0e10cSrcweir 								// restore cursor to its original position
218*cdf0e10cSrcweir 								pWrtShell->GetCrsr()->GetPoint()->nContent.Assign( pTxtNode, nPointIndex );
219*cdf0e10cSrcweir 							}
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 							// enable all, restore view and cursor position
222*cdf0e10cSrcweir 							pWrtShell->EndAction();
223*cdf0e10cSrcweir                         }
224*cdf0e10cSrcweir                     }
225*cdf0e10cSrcweir                     Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
226*cdf0e10cSrcweir                     if( xComponent.is() )
227*cdf0e10cSrcweir                         xComponent->dispose();
228*cdf0e10cSrcweir 			    }
229*cdf0e10cSrcweir             }
230*cdf0e10cSrcweir             break;
231*cdf0e10cSrcweir         }
232*cdf0e10cSrcweir         case FN_HYPHENATE_OPT_DLG:
233*cdf0e10cSrcweir 			HyphenateDocument();
234*cdf0e10cSrcweir 			break;
235*cdf0e10cSrcweir 		default:
236*cdf0e10cSrcweir 			ASSERT(!this, falscher Dispatcher);
237*cdf0e10cSrcweir 			return;
238*cdf0e10cSrcweir 	}
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir /*--------------------------------------------------------------------
242*cdf0e10cSrcweir     Description: start language specific text conversion
243*cdf0e10cSrcweir  --------------------------------------------------------------------*/
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir void SwView::StartTextConversion(
246*cdf0e10cSrcweir         LanguageType nSourceLang,
247*cdf0e10cSrcweir         LanguageType nTargetLang,
248*cdf0e10cSrcweir         const Font *pTargetFont,
249*cdf0e10cSrcweir         sal_Int32 nOptions,
250*cdf0e10cSrcweir         sal_Bool bIsInteractive )
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir     // do not do text conversion if it is active elsewhere
253*cdf0e10cSrcweir     if (GetWrtShell().HasConvIter())
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         return;
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     SpellKontext(sal_True);
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
261*cdf0e10cSrcweir     const sal_Bool bOldIdle = pVOpt->IsIdle();
262*cdf0e10cSrcweir     pVOpt->SetIdle( sal_False );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     sal_Bool bOldIns = pWrtShell->IsInsMode();
265*cdf0e10cSrcweir     pWrtShell->SetInsMode( sal_True );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     sal_Bool bSelection = ((SwCrsrShell*)pWrtShell)->HasSelection() ||
268*cdf0e10cSrcweir         pWrtShell->GetCrsr() != pWrtShell->GetCrsr()->GetNext();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     sal_Bool    bStart = bSelection || pWrtShell->IsStartOfDoc();
271*cdf0e10cSrcweir     sal_Bool    bOther = !bSelection && !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY);
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir         const uno::Reference< lang::XMultiServiceFactory > xMgr(
275*cdf0e10cSrcweir                     comphelper::getProcessServiceFactory() );
276*cdf0e10cSrcweir         SwHHCWrapper aWrap( this, xMgr, nSourceLang, nTargetLang, pTargetFont,
277*cdf0e10cSrcweir                             nOptions, bIsInteractive,
278*cdf0e10cSrcweir                             bStart, bOther, bSelection );
279*cdf0e10cSrcweir         aWrap.Convert();
280*cdf0e10cSrcweir     }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     pWrtShell->SetInsMode( bOldIns );
283*cdf0e10cSrcweir     pVOpt->SetIdle( bOldIdle );
284*cdf0e10cSrcweir     SpellKontext(sal_False);
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir /*--------------------------------------------------------------------
288*cdf0e10cSrcweir      spellcheck and text conversion related stuff
289*cdf0e10cSrcweir  --------------------------------------------------------------------*/
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir void SwView::SpellStart( SvxSpellArea eWhich,
292*cdf0e10cSrcweir         sal_Bool bStartDone, sal_Bool bEndDone,
293*cdf0e10cSrcweir         SwConversionArgs *pConvArgs )
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir 	Reference< beans::XPropertySet >  xProp( ::GetLinguPropertySet() );
296*cdf0e10cSrcweir     sal_Bool bIsWrapReverse = (!pConvArgs && xProp.is()) ?
297*cdf0e10cSrcweir 			*(sal_Bool*)xProp->getPropertyValue( C2U(UPN_IS_WRAP_REVERSE) ).getValue() : sal_False;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	SwDocPositions eStart = DOCPOS_START;
300*cdf0e10cSrcweir 	SwDocPositions eEnde  = DOCPOS_END;
301*cdf0e10cSrcweir 	SwDocPositions eCurr  = DOCPOS_CURR;
302*cdf0e10cSrcweir 	switch ( eWhich )
303*cdf0e10cSrcweir 	{
304*cdf0e10cSrcweir 		case SVX_SPELL_BODY:
305*cdf0e10cSrcweir 			if( bIsWrapReverse )
306*cdf0e10cSrcweir 				eCurr = DOCPOS_END;
307*cdf0e10cSrcweir 			else
308*cdf0e10cSrcweir 				eCurr = DOCPOS_START;
309*cdf0e10cSrcweir 			break;
310*cdf0e10cSrcweir 		case SVX_SPELL_BODY_END:
311*cdf0e10cSrcweir 			if( bIsWrapReverse )
312*cdf0e10cSrcweir 			{
313*cdf0e10cSrcweir 				if( bStartDone )
314*cdf0e10cSrcweir 					eStart = DOCPOS_CURR;
315*cdf0e10cSrcweir 				eCurr = DOCPOS_END;
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 			else if( bStartDone )
318*cdf0e10cSrcweir 				eCurr = DOCPOS_START;
319*cdf0e10cSrcweir 			break;
320*cdf0e10cSrcweir 		case SVX_SPELL_BODY_START:
321*cdf0e10cSrcweir 			if( !bIsWrapReverse )
322*cdf0e10cSrcweir 			{
323*cdf0e10cSrcweir 				if( bEndDone )
324*cdf0e10cSrcweir 					eEnde = DOCPOS_CURR;
325*cdf0e10cSrcweir 				eCurr = DOCPOS_START;
326*cdf0e10cSrcweir 			}
327*cdf0e10cSrcweir 			else if( bEndDone )
328*cdf0e10cSrcweir 				eCurr = DOCPOS_END;
329*cdf0e10cSrcweir 			break;
330*cdf0e10cSrcweir 		case SVX_SPELL_OTHER:
331*cdf0e10cSrcweir 			if( bIsWrapReverse )
332*cdf0e10cSrcweir 			{
333*cdf0e10cSrcweir 				eStart = DOCPOS_OTHERSTART;
334*cdf0e10cSrcweir 				eEnde  = DOCPOS_OTHEREND;
335*cdf0e10cSrcweir 				eCurr = DOCPOS_OTHEREND;
336*cdf0e10cSrcweir 			}
337*cdf0e10cSrcweir 			else
338*cdf0e10cSrcweir 			{
339*cdf0e10cSrcweir 				eStart = DOCPOS_OTHERSTART;
340*cdf0e10cSrcweir 				eEnde  = DOCPOS_OTHEREND;
341*cdf0e10cSrcweir 				eCurr = DOCPOS_OTHERSTART;
342*cdf0e10cSrcweir 			}
343*cdf0e10cSrcweir 			break;
344*cdf0e10cSrcweir 		default:
345*cdf0e10cSrcweir 			ASSERT( !this, "SpellStart with unknown Area" );
346*cdf0e10cSrcweir 	}
347*cdf0e10cSrcweir     pWrtShell->SpellStart( eStart, eEnde, eCurr, pConvArgs );
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir /*--------------------------------------------------------------------
351*cdf0e10cSrcweir 	Beschreibung: Fehlermeldung beim Spelling
352*cdf0e10cSrcweir  --------------------------------------------------------------------*/
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir // Der uebergebene Pointer nLang ist selbst der Wert
356*cdf0e10cSrcweir IMPL_LINK( SwView, SpellError, LanguageType *, pLang )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
359*cdf0e10cSrcweir 	sal_Bool bFocus = GetEditWin().HasFocus();
360*cdf0e10cSrcweir #endif
361*cdf0e10cSrcweir 	sal_uInt16 nPend = 0;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	if ( pWrtShell->ActionPend() )
364*cdf0e10cSrcweir 	{
365*cdf0e10cSrcweir 		pWrtShell->Push();
366*cdf0e10cSrcweir 		pWrtShell->ClearMark();
367*cdf0e10cSrcweir 		do
368*cdf0e10cSrcweir 		{
369*cdf0e10cSrcweir 			pWrtShell->EndAction();
370*cdf0e10cSrcweir 			++nPend;
371*cdf0e10cSrcweir 		}
372*cdf0e10cSrcweir 		while( pWrtShell->ActionPend() );
373*cdf0e10cSrcweir 	}
374*cdf0e10cSrcweir 	LanguageType eLang = pLang ? *pLang : LANGUAGE_NONE;
375*cdf0e10cSrcweir 	String aErr(SvtLanguageTable::GetLanguageString( eLang ) );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	SwEditWin &rEditWin = GetEditWin();
378*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
379*cdf0e10cSrcweir 	bFocus = rEditWin.HasFocus();
380*cdf0e10cSrcweir #endif
381*cdf0e10cSrcweir 	sal_uInt16 nWaitCnt = 0;
382*cdf0e10cSrcweir 	while( rEditWin.IsWait() )
383*cdf0e10cSrcweir 	{
384*cdf0e10cSrcweir 		rEditWin.LeaveWait();
385*cdf0e10cSrcweir 		++nWaitCnt;
386*cdf0e10cSrcweir 	}
387*cdf0e10cSrcweir 	if ( LANGUAGE_NONE == eLang )
388*cdf0e10cSrcweir 		ErrorHandler::HandleError( ERRCODE_SVX_LINGU_NOLANGUAGE );
389*cdf0e10cSrcweir 	else
390*cdf0e10cSrcweir 		ErrorHandler::HandleError( *new StringErrorInfo( ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aErr ) );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	while( nWaitCnt )
393*cdf0e10cSrcweir 	{
394*cdf0e10cSrcweir 		rEditWin.EnterWait();
395*cdf0e10cSrcweir 		--nWaitCnt;
396*cdf0e10cSrcweir 	}
397*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
398*cdf0e10cSrcweir 	bFocus = GetEditWin().HasFocus();
399*cdf0e10cSrcweir #endif
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	if ( nPend )
402*cdf0e10cSrcweir 	{
403*cdf0e10cSrcweir 		while( nPend-- )
404*cdf0e10cSrcweir 			pWrtShell->StartAction();
405*cdf0e10cSrcweir 		pWrtShell->Combine();
406*cdf0e10cSrcweir 	}
407*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
408*cdf0e10cSrcweir 	if( !bFocus )
409*cdf0e10cSrcweir 		GetEditWin().GrabFocus();
410*cdf0e10cSrcweir #endif
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	return 0;
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir /*--------------------------------------------------------------------
416*cdf0e10cSrcweir 	 Beschreibung: Spelling beenden und Cursor wiederherstellen
417*cdf0e10cSrcweir  --------------------------------------------------------------------*/
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void SwView::SpellEnd( SwConversionArgs *pConvArgs )
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir     pWrtShell->SpellEnd( pConvArgs );
423*cdf0e10cSrcweir 	if( pWrtShell->IsExtMode() )
424*cdf0e10cSrcweir 		pWrtShell->SetMark();
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir void SwView::HyphStart( SvxSpellArea eWhich )
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir 	switch ( eWhich )
431*cdf0e10cSrcweir 	{
432*cdf0e10cSrcweir 		case SVX_SPELL_BODY:
433*cdf0e10cSrcweir 			pWrtShell->HyphStart( DOCPOS_START, DOCPOS_END );
434*cdf0e10cSrcweir 			break;
435*cdf0e10cSrcweir 		case SVX_SPELL_BODY_END:
436*cdf0e10cSrcweir 			pWrtShell->HyphStart( DOCPOS_CURR, DOCPOS_END );
437*cdf0e10cSrcweir 			break;
438*cdf0e10cSrcweir 		case SVX_SPELL_BODY_START:
439*cdf0e10cSrcweir 			pWrtShell->HyphStart( DOCPOS_START, DOCPOS_CURR );
440*cdf0e10cSrcweir 			break;
441*cdf0e10cSrcweir 		case SVX_SPELL_OTHER:
442*cdf0e10cSrcweir 			pWrtShell->HyphStart( DOCPOS_OTHERSTART, DOCPOS_OTHEREND );
443*cdf0e10cSrcweir 			break;
444*cdf0e10cSrcweir 		default:
445*cdf0e10cSrcweir 			ASSERT( !this, "HyphStart with unknown Area" );
446*cdf0e10cSrcweir 	}
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir /*--------------------------------------------------------------------
450*cdf0e10cSrcweir 	 Beschreibung: Interaktive Trennung
451*cdf0e10cSrcweir  --------------------------------------------------------------------*/
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir void SwView::HyphenateDocument()
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir 	// do not hyphenate if interactive hyphenationg is active elsewhere
457*cdf0e10cSrcweir 	if (GetWrtShell().HasHyphIter())
458*cdf0e10cSrcweir 	{
459*cdf0e10cSrcweir 		MessBox( 0, WB_OK, String( SW_RES( STR_HYPH_TITLE ) ),
460*cdf0e10cSrcweir 				String( SW_RES( STR_MULT_INTERACT_HYPH_WARN ) ) ).Execute();
461*cdf0e10cSrcweir 		return;
462*cdf0e10cSrcweir 	}
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 	SfxErrorContext aContext( ERRCTX_SVX_LINGU_HYPHENATION, aEmptyStr, pEditWin,
465*cdf0e10cSrcweir 		 RID_SVXERRCTX, &DIALOG_MGR() );
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	Reference< XHyphenator >  xHyph( ::GetHyphenator() );
468*cdf0e10cSrcweir 	if (!xHyph.is())
469*cdf0e10cSrcweir 	{
470*cdf0e10cSrcweir 		ErrorHandler::HandleError( ERRCODE_SVX_LINGU_LINGUNOTEXISTS );
471*cdf0e10cSrcweir 		return;
472*cdf0e10cSrcweir 	}
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 	if (pWrtShell->GetSelectionType() & (nsSelectionType::SEL_DRW_TXT|nsSelectionType::SEL_DRW))
475*cdf0e10cSrcweir 	{
476*cdf0e10cSrcweir 		// Silbentrennung in einem Draw-Objekt
477*cdf0e10cSrcweir 		HyphenateDrawText();
478*cdf0e10cSrcweir 	}
479*cdf0e10cSrcweir 	else
480*cdf0e10cSrcweir 	{
481*cdf0e10cSrcweir 		SwViewOption* pVOpt = (SwViewOption*)pWrtShell->GetViewOptions();
482*cdf0e10cSrcweir 		sal_Bool bOldIdle = pVOpt->IsIdle();
483*cdf0e10cSrcweir 		pVOpt->SetIdle( sal_False );
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 		Reference< beans::XPropertySet >  xProp( ::GetLinguPropertySet() );
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir 		pWrtShell->StartUndo(UNDO_INSATTR);       	// spaeter gueltig
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 		sal_Bool bHyphSpecial = xProp.is() ?
491*cdf0e10cSrcweir 				*(sal_Bool*)xProp->getPropertyValue( C2U(UPN_IS_HYPH_SPECIAL) ).getValue() : sal_False;
492*cdf0e10cSrcweir 		sal_Bool bSelection = ((SwCrsrShell*)pWrtShell)->HasSelection() ||
493*cdf0e10cSrcweir 			pWrtShell->GetCrsr() != pWrtShell->GetCrsr()->GetNext();
494*cdf0e10cSrcweir 		sal_Bool bOther = pWrtShell->HasOtherCnt() && bHyphSpecial && !bSelection;
495*cdf0e10cSrcweir 		sal_Bool bStart = bSelection || ( !bOther && pWrtShell->IsStartOfDoc() );
496*cdf0e10cSrcweir 		sal_Bool bStop = sal_False;
497*cdf0e10cSrcweir 		if( !bOther && !(pWrtShell->GetFrmType(0,sal_True) & FRMTYPE_BODY) && !bSelection )
498*cdf0e10cSrcweir 		// kein Sonderbereich eingeschaltet
499*cdf0e10cSrcweir 		{
500*cdf0e10cSrcweir 			// Ich will auch in Sonderbereichen trennen
501*cdf0e10cSrcweir 			QueryBox aBox( &GetEditWin(), SW_RES( DLG_SPECIAL_FORCED ) );
502*cdf0e10cSrcweir 			if( aBox.Execute() == RET_YES )
503*cdf0e10cSrcweir 			{
504*cdf0e10cSrcweir 				bOther = sal_True;
505*cdf0e10cSrcweir 				if (xProp.is())
506*cdf0e10cSrcweir 				{
507*cdf0e10cSrcweir 					sal_Bool bTrue = sal_True;
508*cdf0e10cSrcweir 					Any aTmp(&bTrue, ::getBooleanCppuType());
509*cdf0e10cSrcweir 					xProp->setPropertyValue( C2U(UPN_IS_HYPH_SPECIAL), aTmp );
510*cdf0e10cSrcweir 				}
511*cdf0e10cSrcweir 			}
512*cdf0e10cSrcweir 			else
513*cdf0e10cSrcweir 				bStop = sal_True; // Nein Es wird nicht getrennt
514*cdf0e10cSrcweir 		}
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 		if( !bStop )
517*cdf0e10cSrcweir 		{
518*cdf0e10cSrcweir 			SwHyphWrapper aWrap( this, xHyph, bStart, bOther, bSelection );
519*cdf0e10cSrcweir 			aWrap.SpellDocument();
520*cdf0e10cSrcweir 			pWrtShell->EndUndo(UNDO_INSATTR);
521*cdf0e10cSrcweir 		}
522*cdf0e10cSrcweir 		pVOpt->SetIdle( bOldIdle );
523*cdf0e10cSrcweir 	}
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir /*--------------------------------------------------------------------
527*cdf0e10cSrcweir  --------------------------------------------------------------------*/
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir bool SwView::IsValidSelectionForThesaurus() const
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     // must not be a multi-selection, and if it is a selection it needs
532*cdf0e10cSrcweir     // to be within a single paragraph
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     const bool bMultiSel = pWrtShell->GetCrsr() != pWrtShell->GetCrsr()->GetNext();
535*cdf0e10cSrcweir     const sal_Bool bSelection = ((SwCrsrShell*)pWrtShell)->HasSelection();
536*cdf0e10cSrcweir     return !bMultiSel && (!bSelection || pWrtShell->IsSelOnePara() );
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir String SwView::GetThesaurusLookUpText( bool bSelection ) const
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir     return bSelection ? pWrtShell->GetSelTxt() : pWrtShell->GetCurWord();
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir void SwView::InsertThesaurusSynonym( const String &rSynonmText, const String &rLookUpText, bool bSelection )
547*cdf0e10cSrcweir {
548*cdf0e10cSrcweir     sal_Bool bOldIns = pWrtShell->IsInsMode();
549*cdf0e10cSrcweir     pWrtShell->SetInsMode( sal_True );
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir     pWrtShell->StartAllAction();
552*cdf0e10cSrcweir     pWrtShell->StartUndo(UNDO_DELETE);
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir     if( !bSelection )
555*cdf0e10cSrcweir     {
556*cdf0e10cSrcweir         if(pWrtShell->IsEndWrd())
557*cdf0e10cSrcweir             pWrtShell->Left(CRSR_SKIP_CELLS, sal_False, 1, sal_False );
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir         pWrtShell->SelWrd();
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir         // make sure the selection build later from the
562*cdf0e10cSrcweir         // data below does not include footnotes and other
563*cdf0e10cSrcweir         // "in word" character to the left and right in order
564*cdf0e10cSrcweir         // to preserve those. Therefore count those "in words"
565*cdf0e10cSrcweir         // in order to modify the selection accordingly.
566*cdf0e10cSrcweir         const sal_Unicode* pChar = rLookUpText.GetBuffer();
567*cdf0e10cSrcweir         xub_StrLen nLeft = 0;
568*cdf0e10cSrcweir         while (pChar && *pChar++ == CH_TXTATR_INWORD)
569*cdf0e10cSrcweir             ++nLeft;
570*cdf0e10cSrcweir         pChar = rLookUpText.Len() ? rLookUpText.GetBuffer() + rLookUpText.Len() - 1 : 0;
571*cdf0e10cSrcweir         xub_StrLen nRight = 0;
572*cdf0e10cSrcweir         while (pChar && *pChar-- == CH_TXTATR_INWORD)
573*cdf0e10cSrcweir             ++nRight;
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir         // adjust existing selection
576*cdf0e10cSrcweir         SwPaM *pCrsr = pWrtShell->GetCrsr();
577*cdf0e10cSrcweir         pCrsr->GetPoint()->nContent/*.nIndex*/ -= nRight;
578*cdf0e10cSrcweir         pCrsr->GetMark()->nContent/*.nIndex*/ += nLeft;
579*cdf0e10cSrcweir     }
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     pWrtShell->Insert( rSynonmText );
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir     pWrtShell->EndUndo(UNDO_DELETE);
584*cdf0e10cSrcweir     pWrtShell->EndAllAction();
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir     pWrtShell->SetInsMode( bOldIns );
587*cdf0e10cSrcweir }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir /*--------------------------------------------------------------------
591*cdf0e10cSrcweir 	Beschreibung:	Thesaurus starten
592*cdf0e10cSrcweir  --------------------------------------------------------------------*/
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir void SwView::StartThesaurus()
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir     if (!IsValidSelectionForThesaurus())
598*cdf0e10cSrcweir         return;
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 	SfxErrorContext aContext( ERRCTX_SVX_LINGU_THESAURUS, aEmptyStr, pEditWin,
601*cdf0e10cSrcweir 		 RID_SVXERRCTX, &DIALOG_MGR() );
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 	// Sprache rausholen
604*cdf0e10cSrcweir 	//
605*cdf0e10cSrcweir 	LanguageType eLang = pWrtShell->GetCurLang();
606*cdf0e10cSrcweir 	if( LANGUAGE_SYSTEM == eLang )
607*cdf0e10cSrcweir        eLang = GetAppLanguage();
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 	if( eLang == LANGUAGE_DONTKNOW || eLang == LANGUAGE_NONE )
610*cdf0e10cSrcweir 	{
611*cdf0e10cSrcweir 		LanguageType nLanguage = LANGUAGE_NONE;
612*cdf0e10cSrcweir 		SpellError( &nLanguage );
613*cdf0e10cSrcweir 		return;
614*cdf0e10cSrcweir 	}
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 	SwViewOption* pVOpt = (SwViewOption*)pWrtShell->GetViewOptions();
617*cdf0e10cSrcweir 	sal_Bool bOldIdle = pVOpt->IsIdle();
618*cdf0e10cSrcweir 	pVOpt->SetIdle( sal_False );
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	// get initial LookUp text
621*cdf0e10cSrcweir     const sal_Bool bSelection = ((SwCrsrShell*)pWrtShell)->HasSelection();
622*cdf0e10cSrcweir     String aTmp = GetThesaurusLookUpText( bSelection );
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 	Reference< XThesaurus >  xThes( ::GetThesaurus() );
625*cdf0e10cSrcweir 	AbstractThesaurusDialog *pDlg = NULL;
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 	if ( !xThes.is() || !xThes->hasLocale( SvxCreateLocale( eLang ) ) )
628*cdf0e10cSrcweir 		SpellError( &eLang );
629*cdf0e10cSrcweir 	else
630*cdf0e10cSrcweir 	{
631*cdf0e10cSrcweir 		// create dialog
632*cdf0e10cSrcweir 		{	//Scope for SwWait-Object
633*cdf0e10cSrcweir 			SwWait aWait( *GetDocShell(), sal_True );
634*cdf0e10cSrcweir 			// load library with dialog only on demand ...
635*cdf0e10cSrcweir 			SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
636*cdf0e10cSrcweir 			pDlg = pFact->CreateThesaurusDialog( &GetEditWin(), xThes, aTmp, eLang );
637*cdf0e10cSrcweir 		}
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir 		if ( pDlg->Execute()== RET_OK )
640*cdf0e10cSrcweir             InsertThesaurusSynonym( pDlg->GetWord(), aTmp, bSelection );
641*cdf0e10cSrcweir 	}
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir 	delete pDlg;
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 	pVOpt->SetIdle( bOldIdle );
646*cdf0e10cSrcweir }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir /*--------------------------------------------------------------------
649*cdf0e10cSrcweir 	Beschreibung:	Online-Vorschlaege anbieten
650*cdf0e10cSrcweir  *--------------------------------------------------------------------*/
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir //!! Start of extra code for context menu modifying extensions
653*cdf0e10cSrcweir struct ExecuteInfo
654*cdf0e10cSrcweir {
655*cdf0e10cSrcweir     uno::Reference< frame::XDispatch >  xDispatch;
656*cdf0e10cSrcweir     util::URL                           aTargetURL;
657*cdf0e10cSrcweir     uno::Sequence< PropertyValue >      aArgs;
658*cdf0e10cSrcweir };
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir class AsyncExecute
661*cdf0e10cSrcweir {
662*cdf0e10cSrcweir public:
663*cdf0e10cSrcweir     DECL_STATIC_LINK( AsyncExecute, ExecuteHdl_Impl, ExecuteInfo* );
664*cdf0e10cSrcweir };
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( AsyncExecute, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir     const sal_uInt32 nRef = Application::ReleaseSolarMutex();
669*cdf0e10cSrcweir     try
670*cdf0e10cSrcweir     {
671*cdf0e10cSrcweir         // Asynchronous execution as this can lead to our own destruction!
672*cdf0e10cSrcweir         // Framework can recycle our current frame and the layout manager disposes all user interface
673*cdf0e10cSrcweir         // elements if a component gets detached from its frame!
674*cdf0e10cSrcweir         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
675*cdf0e10cSrcweir     }
676*cdf0e10cSrcweir     catch ( Exception& )
677*cdf0e10cSrcweir     {
678*cdf0e10cSrcweir     }
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir     Application::AcquireSolarMutex( nRef );
681*cdf0e10cSrcweir     delete pExecuteInfo;
682*cdf0e10cSrcweir     return 0;
683*cdf0e10cSrcweir }
684*cdf0e10cSrcweir //!! End of extra code for context menu modifying extensions
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir sal_Bool SwView::ExecSpellPopup(const Point& rPt)
687*cdf0e10cSrcweir {
688*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
689*cdf0e10cSrcweir 	const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
690*cdf0e10cSrcweir 	if( pVOpt->IsOnlineSpell() &&
691*cdf0e10cSrcweir 		!pWrtShell->IsSelection())
692*cdf0e10cSrcweir 	{
693*cdf0e10cSrcweir 		if (pWrtShell->GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
694*cdf0e10cSrcweir 			bRet = ExecDrwTxtSpellPopup(rPt);
695*cdf0e10cSrcweir 		else if (!pWrtShell->IsSelFrmMode())
696*cdf0e10cSrcweir 		{
697*cdf0e10cSrcweir 			const sal_Bool bOldViewLock = pWrtShell->IsViewLocked();
698*cdf0e10cSrcweir 			pWrtShell->LockView( sal_True );
699*cdf0e10cSrcweir 			pWrtShell->Push();
700*cdf0e10cSrcweir             SwRect aToFill;
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir             // decide which variant of the context menu to use...
703*cdf0e10cSrcweir             // if neither spell checking nor grammar checking provides suggestions use the
704*cdf0e10cSrcweir             // default context menu.
705*cdf0e10cSrcweir             bool bUseGrammarContext = false;
706*cdf0e10cSrcweir             Reference< XSpellAlternatives >  xAlt( pWrtShell->GetCorrection(&rPt, aToFill) );
707*cdf0e10cSrcweir             /*linguistic2::*/ProofreadingResult aGrammarCheckRes;
708*cdf0e10cSrcweir             sal_Int32 nErrorPosInText = -1;
709*cdf0e10cSrcweir             sal_Int32 nErrorInResult = -1;
710*cdf0e10cSrcweir             uno::Sequence< rtl::OUString > aSuggestions;
711*cdf0e10cSrcweir             bool bCorrectionRes = false;
712*cdf0e10cSrcweir             if (!xAlt.is() || xAlt->getAlternatives().getLength() == 0)
713*cdf0e10cSrcweir             {
714*cdf0e10cSrcweir                 bCorrectionRes = pWrtShell->GetGrammarCorrection( aGrammarCheckRes, nErrorPosInText, nErrorInResult, aSuggestions, &rPt, aToFill );
715*cdf0e10cSrcweir 				::rtl::OUString aMessageText;
716*cdf0e10cSrcweir 				if (nErrorInResult >= 0)
717*cdf0e10cSrcweir 					aMessageText = aGrammarCheckRes.aErrors[ nErrorInResult ].aShortComment;
718*cdf0e10cSrcweir 				// we like to use the grammar checking context menu if we either get
719*cdf0e10cSrcweir 				// some suggestions or at least a comment about the error found...
720*cdf0e10cSrcweir                 bUseGrammarContext = bCorrectionRes &&
721*cdf0e10cSrcweir 						(aSuggestions.getLength() > 0 || aMessageText.getLength() > 0);
722*cdf0e10cSrcweir             }
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir             // open respective context menu for spell check or grammar errors with correction suggestions...
725*cdf0e10cSrcweir             if ((!bUseGrammarContext && xAlt.is()) ||
726*cdf0e10cSrcweir                 (bUseGrammarContext && bCorrectionRes && aGrammarCheckRes.aErrors.getLength() > 0))
727*cdf0e10cSrcweir 			{
728*cdf0e10cSrcweir 				// get paragraph text
729*cdf0e10cSrcweir 				String aParaText;
730*cdf0e10cSrcweir                 SwPosition aPoint( *pWrtShell->GetCrsr()->GetPoint() );
731*cdf0e10cSrcweir 				const SwTxtNode *pNode = dynamic_cast< const SwTxtNode * >(
732*cdf0e10cSrcweir                                             &aPoint.nNode.GetNode() );
733*cdf0e10cSrcweir 				if (pNode)
734*cdf0e10cSrcweir 					aParaText = pNode->GetTxt();	// this may include hidden text but that should be Ok
735*cdf0e10cSrcweir                 else
736*cdf0e10cSrcweir                 {
737*cdf0e10cSrcweir 					DBG_ERROR( "text node expected but not found" );
738*cdf0e10cSrcweir                 }
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 				bRet = sal_True;
741*cdf0e10cSrcweir 				pWrtShell->SttSelect();
742*cdf0e10cSrcweir                 std::auto_ptr< SwSpellPopup > pPopup;
743*cdf0e10cSrcweir                 if (bUseGrammarContext)
744*cdf0e10cSrcweir                 {
745*cdf0e10cSrcweir                     sal_Int32 nPos = aPoint.nContent.GetIndex();
746*cdf0e10cSrcweir 					(void) nPos;
747*cdf0e10cSrcweir                     pPopup = std::auto_ptr< SwSpellPopup >(new SwSpellPopup( pWrtShell, aGrammarCheckRes, nErrorInResult, aSuggestions, aParaText ));
748*cdf0e10cSrcweir                 }
749*cdf0e10cSrcweir                 else
750*cdf0e10cSrcweir                     pPopup = std::auto_ptr< SwSpellPopup >(new SwSpellPopup( pWrtShell, xAlt, aParaText ));
751*cdf0e10cSrcweir                 ui::ContextMenuExecuteEvent aEvent;
752*cdf0e10cSrcweir                 const Point aPixPos = GetEditWin().LogicToPixel( rPt );
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir                 aEvent.SourceWindow = VCLUnoHelper::GetInterface( pEditWin );
755*cdf0e10cSrcweir                 aEvent.ExecutePosition.X = aPixPos.X();
756*cdf0e10cSrcweir                 aEvent.ExecutePosition.Y = aPixPos.Y();
757*cdf0e10cSrcweir                 Menu* pMenu = 0;
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir                 ::rtl::OUString sMenuName = ::rtl::OUString::createFromAscii(
760*cdf0e10cSrcweir                     bUseGrammarContext ? "private:resource/GrammarContextMenu" : "private:resource/SpellContextMenu");
761*cdf0e10cSrcweir                 if(TryContextMenuInterception( *pPopup, sMenuName, pMenu, aEvent ))
762*cdf0e10cSrcweir                 {
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir                     //! happy hacking for context menu modifying extensions of this
765*cdf0e10cSrcweir                     //! 'custom made' menu... *sigh* (code copied from sfx2 and framework)
766*cdf0e10cSrcweir                     if ( pMenu )
767*cdf0e10cSrcweir                     {
768*cdf0e10cSrcweir                         OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
769*cdf0e10cSrcweir                         sal_uInt16 nId = ((PopupMenu*)pMenu)->Execute(pEditWin, aPixPos);
770*cdf0e10cSrcweir                         OUString aCommand = ((PopupMenu*)pMenu)->GetItemCommand(nId);
771*cdf0e10cSrcweir                         if (aCommand.getLength() == 0 )
772*cdf0e10cSrcweir                         {
773*cdf0e10cSrcweir                             if(!ExecuteMenuCommand( *dynamic_cast<PopupMenu*>(pMenu), *GetViewFrame(), nId ))
774*cdf0e10cSrcweir                                 pPopup->Execute(nId);
775*cdf0e10cSrcweir                         }
776*cdf0e10cSrcweir                         else
777*cdf0e10cSrcweir                         {
778*cdf0e10cSrcweir                             SfxViewFrame *pSfxViewFrame = GetViewFrame();
779*cdf0e10cSrcweir                             uno::Reference< frame::XFrame > xFrame;
780*cdf0e10cSrcweir                             if ( pSfxViewFrame )
781*cdf0e10cSrcweir                                 xFrame = pSfxViewFrame->GetFrame().GetFrameInterface();
782*cdf0e10cSrcweir                             com::sun::star::util::URL aURL;
783*cdf0e10cSrcweir                             uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
784*cdf0e10cSrcweir                             uno::Reference< lang::XMultiServiceFactory > xMgr( utl::getProcessServiceFactory(), uno::UNO_QUERY );
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir                             try
787*cdf0e10cSrcweir                             {
788*cdf0e10cSrcweir                                 uno::Reference< frame::XDispatch > xDispatch;
789*cdf0e10cSrcweir                                 uno::Reference< util::XURLTransformer > xURLTransformer;
790*cdf0e10cSrcweir                                 if (xMgr.is())
791*cdf0e10cSrcweir                                 {
792*cdf0e10cSrcweir                                     xURLTransformer = uno::Reference< util::XURLTransformer >( xMgr->createInstance(
793*cdf0e10cSrcweir                                             C2U("com.sun.star.util.URLTransformer")), UNO_QUERY);
794*cdf0e10cSrcweir                                 }
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir                                 aURL.Complete = aCommand;
797*cdf0e10cSrcweir                                 xURLTransformer->parseStrict(aURL);
798*cdf0e10cSrcweir                                 uno::Sequence< beans::PropertyValue > aArgs;
799*cdf0e10cSrcweir                                 xDispatch = xDispatchProvider->queryDispatch( aURL, rtl::OUString(), 0 );
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir                                 if (xDispatch.is())
803*cdf0e10cSrcweir                                 {
804*cdf0e10cSrcweir                                     // Execute dispatch asynchronously
805*cdf0e10cSrcweir                                     ExecuteInfo* pExecuteInfo   = new ExecuteInfo;
806*cdf0e10cSrcweir                                     pExecuteInfo->xDispatch     = xDispatch;
807*cdf0e10cSrcweir                                     pExecuteInfo->aTargetURL    = aURL;
808*cdf0e10cSrcweir                                     pExecuteInfo->aArgs         = aArgs;
809*cdf0e10cSrcweir                                     Application::PostUserEvent( STATIC_LINK(0, AsyncExecute , ExecuteHdl_Impl), pExecuteInfo );
810*cdf0e10cSrcweir                                 }
811*cdf0e10cSrcweir                             }
812*cdf0e10cSrcweir                             catch (Exception &)
813*cdf0e10cSrcweir                             {
814*cdf0e10cSrcweir                             }
815*cdf0e10cSrcweir                         }
816*cdf0e10cSrcweir                     }
817*cdf0e10cSrcweir                     else
818*cdf0e10cSrcweir                     {
819*cdf0e10cSrcweir                         pPopup->Execute( aToFill.SVRect(), pEditWin );
820*cdf0e10cSrcweir                     }
821*cdf0e10cSrcweir                 }
822*cdf0e10cSrcweir 			}
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir 			pWrtShell->Pop( sal_False );
825*cdf0e10cSrcweir 			pWrtShell->LockView( bOldViewLock );
826*cdf0e10cSrcweir 		}
827*cdf0e10cSrcweir 	}
828*cdf0e10cSrcweir 	return bRet;
829*cdf0e10cSrcweir }
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir /** Function: ExecSmartTagPopup
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir    This function shows the popup menu for smarttag
834*cdf0e10cSrcweir    actions.
835*cdf0e10cSrcweir */
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir sal_Bool SwView::ExecSmartTagPopup( const Point& rPt )
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
840*cdf0e10cSrcweir     const sal_Bool bOldViewLock = pWrtShell->IsViewLocked();
841*cdf0e10cSrcweir     pWrtShell->LockView( sal_True );
842*cdf0e10cSrcweir     pWrtShell->Push();
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     // get word that was clicked on
846*cdf0e10cSrcweir     // This data structure maps a smart tag type string to the property bag
847*cdf0e10cSrcweir     SwRect aToFill;
848*cdf0e10cSrcweir     Sequence< rtl::OUString > aSmartTagTypes;
849*cdf0e10cSrcweir     Sequence< Reference< container::XStringKeyMap > > aStringKeyMaps;
850*cdf0e10cSrcweir     Reference<text::XTextRange> xRange;
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir     pWrtShell->GetSmartTagTerm( rPt, aToFill, aSmartTagTypes, aStringKeyMaps, xRange);
853*cdf0e10cSrcweir     if ( xRange.is() && aSmartTagTypes.getLength() )
854*cdf0e10cSrcweir     {
855*cdf0e10cSrcweir         bRet = sal_True;
856*cdf0e10cSrcweir         pWrtShell->SttSelect();
857*cdf0e10cSrcweir         SwSmartTagPopup aPopup( this, aSmartTagTypes, aStringKeyMaps, xRange );
858*cdf0e10cSrcweir         aPopup.Execute( aToFill.SVRect(), pEditWin );
859*cdf0e10cSrcweir     }
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir     pWrtShell->Pop( sal_False );
862*cdf0e10cSrcweir     pWrtShell->LockView( bOldViewLock );
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     return bRet;
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir class SwFieldPopup : public PopupMenu
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir public:
872*cdf0e10cSrcweir     SwFieldPopup()  {
873*cdf0e10cSrcweir 	InsertItem(1, ::rtl::OUString::createFromAscii("Hello"));
874*cdf0e10cSrcweir     }
875*cdf0e10cSrcweir };
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir class SwFieldListBox : public ListBox
878*cdf0e10cSrcweir {
879*cdf0e10cSrcweir public:
880*cdf0e10cSrcweir     SwFieldListBox(Window* pParent) : ListBox(pParent /*, WB_DROPDOWN*/) {
881*cdf0e10cSrcweir     }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir     void *GetImplWin() {
884*cdf0e10cSrcweir 	return NULL; //FIXME!!!
885*cdf0e10cSrcweir //	return mpImplWin;
886*cdf0e10cSrcweir     }
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir protected:
889*cdf0e10cSrcweir     virtual void LoseFocus() {
890*cdf0e10cSrcweir //	printf("ListBox: lose focus!!\n");
891*cdf0e10cSrcweir 	ListBox::LoseFocus();
892*cdf0e10cSrcweir     }
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir     virtual void Select() {
895*cdf0e10cSrcweir //	printf("SELECT!!! IsTravelSelect=%i\n", IsTravelSelect());
896*cdf0e10cSrcweir 	ListBox::Select();
897*cdf0e10cSrcweir     }
898*cdf0e10cSrcweir };
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir class SwFieldDialog : public Dialog
901*cdf0e10cSrcweir {
902*cdf0e10cSrcweir private:
903*cdf0e10cSrcweir     SwFieldListBox aListBox;
904*cdf0e10cSrcweir     Edit aText;
905*cdf0e10cSrcweir     int selection;
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir     DECL_LINK( MyListBoxHandler, ListBox * );
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir public:
910*cdf0e10cSrcweir     SwFieldDialog(Window* parent, IFieldmark *fieldBM) : Dialog(parent, WB_BORDER | WB_SYSTEMWINDOW | WB_NOSHADOW ), aListBox(this), aText(this, WB_RIGHT | WB_READONLY), selection(-1) {
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir 	assert(fieldBM!=NULL);
913*cdf0e10cSrcweir 	if (fieldBM!=NULL) {
914*cdf0e10cSrcweir         const IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
915*cdf0e10cSrcweir         IFieldmark::parameter_map_t::const_iterator pListEntries = pParameters->find(::rtl::OUString::createFromAscii(ODF_FORMDROPDOWN_LISTENTRY));
916*cdf0e10cSrcweir         if(pListEntries != pParameters->end())
917*cdf0e10cSrcweir         {
918*cdf0e10cSrcweir             Sequence< ::rtl::OUString> vListEntries;
919*cdf0e10cSrcweir             pListEntries->second >>= vListEntries;
920*cdf0e10cSrcweir             for( ::rtl::OUString* pCurrent = vListEntries.getArray();
921*cdf0e10cSrcweir                 pCurrent != vListEntries.getArray() + vListEntries.getLength();
922*cdf0e10cSrcweir                 ++pCurrent)
923*cdf0e10cSrcweir             {
924*cdf0e10cSrcweir                 aListBox.InsertEntry(*pCurrent);
925*cdf0e10cSrcweir 		    }
926*cdf0e10cSrcweir 	    }
927*cdf0e10cSrcweir 	}
928*cdf0e10cSrcweir 	Size lbSize=aListBox.GetOptimalSize(WINDOWSIZE_PREFERRED);
929*cdf0e10cSrcweir 	lbSize.Width()+=50;
930*cdf0e10cSrcweir 	lbSize.Height()+=20;
931*cdf0e10cSrcweir 	aListBox.SetSizePixel(lbSize);
932*cdf0e10cSrcweir 	aListBox.SetSelectHdl( LINK( this, SwFieldDialog, MyListBoxHandler ) );
933*cdf0e10cSrcweir 	aListBox.Show();
934*cdf0e10cSrcweir 	aText.SetText(rtl::OUString::createFromAscii("Cancel"));
935*cdf0e10cSrcweir 	Size tSize=aText.GetOptimalSize(WINDOWSIZE_PREFERRED);
936*cdf0e10cSrcweir 	aText.SetSizePixel(Size(lbSize.Width(), tSize.Height()));
937*cdf0e10cSrcweir 	aText.SetPosPixel(Point(0, lbSize.Height()));
938*cdf0e10cSrcweir 	aText.Show();
939*cdf0e10cSrcweir 	SetSizePixel(Size(lbSize.Width(), lbSize.Height()+tSize.Height()));
940*cdf0e10cSrcweir //	SetSizePixel(Size(200, 200));
941*cdf0e10cSrcweir     }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir     int getSelection() {
944*cdf0e10cSrcweir 	return selection;
945*cdf0e10cSrcweir     }
946*cdf0e10cSrcweir protected:
947*cdf0e10cSrcweir     /*
948*cdf0e10cSrcweir     virtual void LoseFocus() {
949*cdf0e10cSrcweir 	printf("lose focus!!\n");
950*cdf0e10cSrcweir 	Dialog::LoseFocus();
951*cdf0e10cSrcweir 	printf("close:\n");
952*cdf0e10cSrcweir 	EndDialog(8);
953*cdf0e10cSrcweir     }
954*cdf0e10cSrcweir     */
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir     virtual long PreNotify( NotifyEvent& rNEvt ) {
957*cdf0e10cSrcweir 	if (rNEvt.GetType() == EVENT_LOSEFOCUS && aListBox.GetImplWin()==rNEvt.GetWindow()) {
958*cdf0e10cSrcweir 	    EndDialog(8);
959*cdf0e10cSrcweir 	    return 1;
960*cdf0e10cSrcweir 	}
961*cdf0e10cSrcweir 	if (rNEvt.GetType() == EVENT_KEYINPUT) {
962*cdf0e10cSrcweir //	    printf("PreNotify::KEYINPUT\n");
963*cdf0e10cSrcweir 	}
964*cdf0e10cSrcweir 	return Dialog::PreNotify(rNEvt);
965*cdf0e10cSrcweir     }
966*cdf0e10cSrcweir };
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir IMPL_LINK( SwFieldDialog, MyListBoxHandler, ListBox *, pBox )
969*cdf0e10cSrcweir {
970*cdf0e10cSrcweir //    printf("### DROP DOWN SELECT... IsTravelSelect=%i\n", pBox->IsTravelSelect());
971*cdf0e10cSrcweir     if (pBox->IsTravelSelect()) {
972*cdf0e10cSrcweir 	return 0;
973*cdf0e10cSrcweir     } else {
974*cdf0e10cSrcweir 	this->selection=pBox->GetSelectEntryPos();
975*cdf0e10cSrcweir 	EndDialog(9); //@TODO have meaningfull returns...
976*cdf0e10cSrcweir 	return 1;
977*cdf0e10cSrcweir     }
978*cdf0e10cSrcweir }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir sal_Bool SwView::ExecFieldPopup( const Point& rPt, IFieldmark *fieldBM )
982*cdf0e10cSrcweir {
983*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
984*cdf0e10cSrcweir     const sal_Bool bOldViewLock = pWrtShell->IsViewLocked();
985*cdf0e10cSrcweir     pWrtShell->LockView( sal_True );
986*cdf0e10cSrcweir     pWrtShell->Push();
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir 	bRet=sal_True;
989*cdf0e10cSrcweir 	const Point aPixPos = GetEditWin().LogicToPixel( rPt );
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir 	SwFieldDialog aFldDlg(pEditWin, fieldBM);
992*cdf0e10cSrcweir 	aFldDlg.SetPosPixel(pEditWin->OutputToScreenPixel(aPixPos));
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 	/*short ret=*/aFldDlg.Execute();
995*cdf0e10cSrcweir 	sal_Int32 selection=aFldDlg.getSelection();
996*cdf0e10cSrcweir 	if (selection>=0) {
997*cdf0e10cSrcweir         (*fieldBM->GetParameters())[::rtl::OUString::createFromAscii(ODF_FORMDROPDOWN_RESULT)] = makeAny(selection);
998*cdf0e10cSrcweir 	}
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir     pWrtShell->Pop( sal_False );
1001*cdf0e10cSrcweir     pWrtShell->LockView( bOldViewLock );
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     return bRet;
1004*cdf0e10cSrcweir }
1005*cdf0e10cSrcweir 
1006