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