xref: /aoo4110/main/sw/source/ui/docvw/edtwin.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <tools/list.hxx>
29 #include <swtypes.hxx>
30 #include <hintids.hxx>
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <com/sun/star/i18n/XBreakIterator.hpp>
34 #include <com/sun/star/i18n/ScriptType.hpp>
35 #include <com/sun/star/i18n/InputSequenceCheckMode.hpp>
36 
37 #include <com/sun/star/i18n/UnicodeScript.hpp>
38 
39 #include <vcl/help.hxx>
40 #include <vcl/graph.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <vcl/cmdevt.h>
43 #include <sot/storage.hxx>
44 #include <svl/macitem.hxx>
45 #include <unotools/securityoptions.hxx>
46 #include <basic/sbxvar.hxx>
47 #include <svl/ctloptions.hxx>
48 #include <basic/sbx.hxx>
49 #include <svl/eitem.hxx>
50 #include <svl/stritem.hxx>
51 #include <sfx2/ipclient.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/request.hxx>
54 #include <sfx2/bindings.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <svl/ptitem.hxx>
57 #include <editeng/sizeitem.hxx>
58 #include <editeng/langitem.hxx>
59 #include <svx/htmlmode.hxx>
60 #include <svx/svdview.hxx>
61 #include <svx/svdhdl.hxx>
62 #include <svx/svdoutl.hxx>
63 #include <editeng/editeng.hxx>
64 #include <editeng/svxacorr.hxx>
65 #include <editeng/scripttypeitem.hxx>
66 #include <editeng/flditem.hxx>
67 #include <editeng/colritem.hxx>
68 #include <editeng/brshitem.hxx>
69 #include <editeng/wghtitem.hxx>
70 #include <editeng/udlnitem.hxx>
71 #include <editeng/postitem.hxx>
72 #include <editeng/protitem.hxx>
73 #include <unotools/charclass.hxx>
74 
75 #include <editeng/acorrcfg.hxx>
76 #include <SwSmartTagMgr.hxx>
77 #include <edtwin.hxx>
78 #include <view.hxx>
79 #include <wrtsh.hxx>
80 #include <IDocumentSettingAccess.hxx>
81 #include <fldbas.hxx>
82 #include <swmodule.hxx>
83 #include <docsh.hxx>
84 #include <viewopt.hxx>
85 #include <drawbase.hxx>
86 #include <dselect.hxx>
87 #include <textsh.hxx>
88 #include <shdwcrsr.hxx>
89 #include <txatbase.hxx>
90 #include <fmtanchr.hxx>
91 #include <fmtornt.hxx>
92 #include <fmtfsize.hxx>
93 #include <fmtclds.hxx>
94 #include <frmfmt.hxx>
95 #include <modcfg.hxx>
96 #include <fmtcol.hxx>
97 #include <wview.hxx>
98 #include <listsh.hxx>
99 #include <gloslst.hxx>
100 #include <inputwin.hxx>
101 #include <gloshdl.hxx>
102 #include <swundo.hxx>
103 #include <drwtxtsh.hxx>
104 #include <fchrfmt.hxx>
105 #include <fmturl.hxx>
106 #include <romenu.hxx>
107 #include <initui.hxx>
108 #include <frmatr.hxx>
109 #include <extinput.hxx>
110 #include <acmplwrd.hxx>
111 #include <swcalwrp.hxx>
112 #include <swdtflvr.hxx>
113 #include <wdocsh.hxx>
114 #include <crsskip.hxx>
115 #include <breakit.hxx>
116 #include <checkit.hxx>
117 
118 #include <helpid.h>
119 #include <cmdid.h>
120 #include <docvw.hrc>
121 #include <uitool.hxx>
122 #include <fmtfollowtextflow.hxx>
123 #include <toolkit/helper/vclunohelper.hxx>
124 #include <charfmt.hxx>
125 #include <numrule.hxx>
126 #include <pagedesc.hxx>
127 #include <svtools/ruler.hxx>
128 #include "formatclipboard.hxx"
129 #include <vos/mutex.hxx>
130 #include <vcl/svapp.hxx>
131 
132 #include <IMark.hxx>
133 #include <doc.hxx>
134 #include <xmloff/odffields.hxx>
135 
136 #include <PostItMgr.hxx>
137 
138 using namespace sw::mark;
139 using namespace ::com::sun::star;
140 
141 /*--------------------------------------------------------------------
142     Beschreibung:   Globals
143  --------------------------------------------------------------------*/
144 
145 static bool bInputLanguageSwitched = false;
146 extern sal_Bool bNoInterrupt;       // in mainwn.cxx
147 
148 //Normalerweise wird im MouseButtonUp eine Selektion aufgehoben wenn die
149 //Selektion nicht gerade aufgezogen wird. Leider wird im MouseButtonDown
150 //bei doppel-/dreifach-Klick Selektiert, diese Selektion wird in dem Handler
151 //komplett abgeschlossen und kann deshalb im Up nicht mehr unterschieden
152 //werden. Um dies Aufzuloese wird bHoldSelection im Down gesetzt und im
153 //Up ausgewertet.
154 static sal_Bool bHoldSelection      = sal_False;
155 
156 sal_Bool bFrmDrag                   = sal_False;
157 sal_Bool bValidCrsrPos              = sal_False;
158 sal_Bool bModePushed                = sal_False;
159 sal_Bool bDDTimerStarted            = sal_False;
160 sal_Bool bFlushCharBuffer           = sal_False;
161 sal_Bool SwEditWin::bReplaceQuote   = sal_False;
162 sal_Bool bDDINetAttr                = sal_False;
163 SdrHdlKind eSdrMoveHdl          = HDL_USER;
164 
165 QuickHelpData* SwEditWin::pQuickHlpData = 0;
166 
167 long    SwEditWin::nDDStartPosY = 0;
168 long    SwEditWin::nDDStartPosX = 0;
169 Color   SwEditWin::aTextBackColor(COL_YELLOW);
170 Color   SwEditWin::aTextColor(COL_RED);
171 sal_Bool    SwEditWin::bTransparentBackColor = sal_False; // Hintergrund nicht transparent
172 
173 
174 extern sal_Bool     bExecuteDrag;
175 
176 SfxShell* lcl_GetShellFromDispatcher( SwView& rView, TypeId nType );
177 
178 DBG_NAME(edithdl)
179 
180 class SwAnchorMarker
181 {
182     SdrHdl* pHdl;
183     Point aHdlPos;
184     Point aLastPos;
185     bool bTopRightHandle;
186 public:
SwAnchorMarker(SdrHdl * pH)187     SwAnchorMarker( SdrHdl* pH )
188         : pHdl( pH )
189         , aHdlPos( pH->GetPos() )
190         , aLastPos( pH->GetPos() )
191         , bTopRightHandle( pH->GetKind() == HDL_ANCHOR_TR )
192     {}
GetLastPos() const193     const Point& GetLastPos() const { return aLastPos; }
SetLastPos(const Point & rNew)194     void SetLastPos( const Point& rNew ) { aLastPos = rNew; }
SetPos(const Point & rNew)195     void SetPos( const Point& rNew ) { pHdl->SetPos( rNew ); }
GetPos()196     const Point& GetPos() { return pHdl->GetPos(); }
GetHdlPos()197     const Point& GetHdlPos() { return aHdlPos; }
GetHdl() const198     SdrHdl* GetHdl() const { return pHdl; }
ChgHdl(SdrHdl * pNew)199     void ChgHdl( SdrHdl* pNew )
200     {
201         pHdl = pNew;
202         if ( pHdl )
203         {
204             bTopRightHandle = (pHdl->GetKind() == HDL_ANCHOR_TR);
205         }
206     }
GetPosForHitTest(const OutputDevice & rOut)207     const Point GetPosForHitTest( const OutputDevice& rOut )
208     {
209         Point aHitTestPos( GetPos() );
210         aHitTestPos = rOut.LogicToPixel( aHitTestPos );
211         if ( bTopRightHandle )
212         {
213             aHitTestPos += Point( -1, 1 );
214         }
215         else
216         {
217             aHitTestPos += Point( 1, 1 );
218         }
219         aHitTestPos = rOut.PixelToLogic( aHitTestPos );
220 
221         return aHitTestPos;
222     }
223 };
224 
225 struct QuickHelpData
226 {
227     SvStringsISortDtor aArr;
228     sal_uInt16* pAttrs;
229     CommandExtTextInputData* pCETID;
230     sal_uLong nTipId;
231     sal_uInt16 nLen, nCurArrPos;
232     sal_Bool bClear : 1, bChkInsBlank : 1, bIsTip : 1, bIsAutoText : 1;
233 
QuickHelpDataQuickHelpData234     QuickHelpData() : pAttrs( 0 ), pCETID( 0 )  { ClearCntnt(); }
235 
236     void Move( QuickHelpData& rCpy );
237     void ClearCntnt();
238     void Start( SwWrtShell& rSh, sal_uInt16 nWrdLen );
239     void Stop( SwWrtShell& rSh );
240 
HasCntntQuickHelpData241     sal_Bool HasCntnt() const       { return aArr.Count() && 0 != nLen; }
242 
IncQuickHelpData243     void Inc( sal_Bool bEndLess )
244         {
245             if( ++nCurArrPos >= aArr.Count() )
246                 nCurArrPos = (bEndLess && !bIsAutoText )? 0 : nCurArrPos-1;
247         }
DecQuickHelpData248     void Dec( sal_Bool bEndLess )
249         {
250             if( 0 == nCurArrPos-- )
251                 nCurArrPos = (bEndLess && !bIsAutoText ) ? aArr.Count()-1 : 0;
252         }
253     void FillStrArr( SwWrtShell& rSh, const String& rWord );
254 };
255 
256 
257 /*--------------------------------------------------------------------
258     Beschreibung:   Minimale Bewegung Zittern vermeiden
259  --------------------------------------------------------------------*/
260 
261 #define HIT_PIX  2 /* Hit-Toleranz in Pixel */
262 #define MIN_MOVE 4
263 
IsMinMove(const Point & rStartPos,const Point & rLPt)264 inline sal_Bool IsMinMove(const Point &rStartPos, const Point &rLPt)
265 {
266     return Abs(rStartPos.X() - rLPt.X()) > MIN_MOVE ||
267            Abs(rStartPos.Y() - rLPt.Y()) > MIN_MOVE;
268 }
269 
270 /*--------------------------------------------------------------------
271     JP 30.07.98: fuer MouseButtonDown - feststellen, ob ein DrawObject
272                 und KEIN SwgFrame getroffen wurde! Shift/Ctrl sollen
273                 nur bei DrawObjecte zum Selektieren fuehren, bei SwgFlys
274                 ggfs zum ausloesen von Hyperlinks (DownLoad/NewWindow!)
275  --------------------------------------------------------------------*/
IsDrawObjSelectable(const SwWrtShell & rSh,const Point & rPt)276 inline sal_Bool IsDrawObjSelectable( const SwWrtShell& rSh, const Point& rPt )
277 {
278     sal_Bool bRet = sal_True;
279     SdrObject* pObj;
280     switch( rSh.GetObjCntType( rPt, pObj ))
281     {
282     case OBJCNT_NONE:
283     case OBJCNT_FLY:
284     case OBJCNT_GRF:
285     case OBJCNT_OLE:
286         bRet = sal_False;
287         break;
288     default:; //prevent warning
289     }
290     return bRet;
291 }
292 
293 /*--------------------------------------------------------------------
294     Beschreibung:   Pointer umschalten
295  --------------------------------------------------------------------*/
296 
297 
UpdatePointer(const Point & rLPt,sal_uInt16 nModifier)298 void SwEditWin::UpdatePointer(const Point &rLPt, sal_uInt16 nModifier )
299 {
300     SwWrtShell &rSh = rView.GetWrtShell();
301     if( pApplyTempl )
302     {
303         PointerStyle eStyle = POINTER_FILL;
304         if ( rSh.IsOverReadOnlyPos( rLPt ) )
305         {
306             if( pUserMarker )
307             {
308                 delete pUserMarker;
309                 pUserMarker = 0L;
310             }
311             eStyle = POINTER_NOTALLOWED;
312         }
313         else
314         {
315             SwRect aRect;
316             SwRect* pRect = &aRect;
317             const SwFrmFmt* pFmt = 0;
318 
319             bool bFrameIsValidTarget = false;
320             if( pApplyTempl->pFormatClipboard )
321                 bFrameIsValidTarget = pApplyTempl->pFormatClipboard->HasContentForThisType( nsSelectionType::SEL_FRM );
322             else if( !pApplyTempl->nColor )
323                 bFrameIsValidTarget = ( pApplyTempl->eType == SFX_STYLE_FAMILY_FRAME );
324 
325             if( bFrameIsValidTarget &&
326                         0 !=(pFmt = rSh.GetFmtFromObj( rLPt, &pRect )) &&
327                         PTR_CAST(SwFlyFrmFmt, pFmt))
328             {
329                 //Highlight fuer Rahmen anwerfen
330                 Rectangle aTmp( pRect->SVRect() );
331 
332                 if ( !pUserMarker )
333                 {
334                     pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), aTmp );
335                 }
336             }
337             else if(pUserMarker)
338             {
339                 delete pUserMarker;
340                 pUserMarker = 0L;
341             }
342 
343             rSh.SwCrsrShell::SetVisCrsr( rLPt );
344         }
345         SetPointer( eStyle );
346         return;
347     }
348 
349     if( !rSh.VisArea().Width() )
350         return;
351 
352     SET_CURR_SHELL(&rSh);
353 
354     if ( IsChainMode() )
355     {
356         SwRect aRect;
357         int nChainable = rSh.Chainable( aRect, *rSh.GetFlyFrmFmt(), rLPt );
358         PointerStyle eStyle = nChainable
359                 ? POINTER_CHAIN_NOTALLOWED : POINTER_CHAIN;
360         if ( !nChainable )
361         {
362             Rectangle aTmp( aRect.SVRect() );
363 
364             if ( !pUserMarker )
365             {
366                 pUserMarker = new SdrDropMarkerOverlay( *rSh.GetDrawView(), aTmp );
367             }
368         }
369         else
370         {
371             delete pUserMarker;
372             pUserMarker = 0L;
373         }
374 
375         rView.GetViewFrame()->ShowStatusText(
376                                         SW_RESSTR(STR_CHAIN_OK+nChainable));
377         SetPointer( eStyle );
378         return;
379     }
380 
381     // Removed ExecHyperlink option.
382     //sal_Bool bExecHyperlinks = rSh.GetViewOptions()->IsExecHyperlinks() ^
383     //                     (nModifier == KEY_MOD2 ? sal_True : sal_False);
384     sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
385     if ( !bExecHyperlinks )
386     {
387         SvtSecurityOptions aSecOpts;
388         const sal_Bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
389         if ( (  bSecureOption && nModifier == KEY_MOD1 ) ||
390              ( !bSecureOption && nModifier != KEY_MOD1 ) )
391             bExecHyperlinks = sal_True;
392     }
393 
394     const sal_Bool bExecSmarttags  = nModifier == KEY_MOD1;
395 
396     SdrView *pSdrView = rSh.GetDrawView();
397     sal_Bool bPrefSdrPointer = sal_False;
398     sal_Bool bHitHandle = sal_False;
399     sal_Bool bCntAtPos = sal_False;
400     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
401                           rSh.IsCrsrReadonly();
402     aActHitType = SDRHIT_NONE;
403     PointerStyle eStyle = POINTER_TEXT;
404     if ( !pSdrView )
405         bCntAtPos = sal_True;
406     else if ( sal_True == (bHitHandle = pSdrView->PickHandle( rLPt ) != 0) )
407     {
408         aActHitType = SDRHIT_OBJECT;
409         bPrefSdrPointer = sal_True;
410     }
411     else
412     {
413         const sal_Bool bNotInSelObj = !rSh.IsInsideSelectedObj( rLPt );
414         if ( rView.GetDrawFuncPtr() && !bInsDraw && bNotInSelObj )
415         {
416             aActHitType = SDRHIT_OBJECT;
417             if (IsObjectSelect())
418                 eStyle = POINTER_ARROW;
419             else
420                 bPrefSdrPointer = sal_True;
421         }
422         else
423         {
424             SdrObject* pObj; SdrPageView* pPV;
425             pSdrView->SetHitTolerancePixel( HIT_PIX );
426             if ( bNotInSelObj && bExecHyperlinks &&
427                  pSdrView->PickObj( rLPt, pSdrView->getHitTolLog(), pObj, pPV, SDRSEARCH_PICKMACRO ))
428             {
429                 SdrObjMacroHitRec aTmp;
430                 aTmp.aPos = rLPt;
431                 aTmp.pPageView = pPV;
432                 SetPointer( pObj->GetMacroPointer( aTmp ) );
433                 return;
434             }
435             else
436             {
437                 // dvo: IsObjSelectable() eventually calls SdrView::PickObj, so
438                 // apparently this is used to determine whether this is a
439                 // drawling layer object or not.
440                 if ( rSh.IsObjSelectable( rLPt ) )
441                 {
442                     if (pSdrView->IsTextEdit())
443                     {
444                         aActHitType = SDRHIT_NONE;
445                         bPrefSdrPointer = sal_True;
446                     }
447                     else
448                     {
449                         SdrViewEvent aVEvt;
450                         SdrHitKind eHit = pSdrView->PickAnything(rLPt, aVEvt);
451 
452                         if (eHit == SDRHIT_URLFIELD && bExecHyperlinks)
453                         {
454                             aActHitType = SDRHIT_OBJECT;
455                             bPrefSdrPointer = sal_True;
456                         }
457                         else
458                         {
459                             // if we're over a selected object, we show an
460                             // ARROW by default. We only show a MOVE if 1) the
461                             // object is selected, and 2) it may be moved
462                             // (i.e., position is not protected).
463                             bool bMovable =
464                                 (!bNotInSelObj) &&
465                                 (rSh.IsObjSelected() || rSh.IsFrmSelected()) &&
466                                 (!rSh.IsSelObjProtected(FLYPROTECT_POS));
467 
468                             eStyle = bMovable ? POINTER_MOVE : POINTER_ARROW;
469                             aActHitType = SDRHIT_OBJECT;
470                         }
471                     }
472                 }
473                 else
474                 {
475                     if ( rSh.IsFrmSelected() && !bNotInSelObj )
476                     {
477                         // dvo: this branch appears to be dead and should be
478                         // removed in a future version. Reason: The condition
479                         // !bNotInSelObj means that this branch will only be
480                         // executed in the cursor points inside a selected
481                         // object. However, if this is the case, the previous
482                         // if( rSh.IsObjSelectable(rLPt) ) must always be true:
483                         // rLPt is inside a selected object, then obviously
484                         // rLPt is over a selectable object.
485                         if (rSh.IsSelObjProtected(FLYPROTECT_SIZE))
486                             eStyle = POINTER_NOTALLOWED;
487                         else
488                             eStyle = POINTER_MOVE;
489                         aActHitType = SDRHIT_OBJECT;
490                     }
491                     else
492                     {
493                         if ( rView.GetDrawFuncPtr() )
494                             bPrefSdrPointer = sal_True;
495                         else
496                             bCntAtPos = sal_True;
497                     }
498                 }
499             }
500         }
501     }
502     if ( bPrefSdrPointer )
503     {
504         if (bIsDocReadOnly || (rSh.IsObjSelected() && rSh.IsSelObjProtected(FLYPROTECT_CONTENT)))
505             SetPointer( POINTER_NOTALLOWED );
506         else
507         {
508             if (rView.GetDrawFuncPtr() && rView.GetDrawFuncPtr()->IsInsertForm() && !bHitHandle)
509                 SetPointer( POINTER_DRAW_RECT );
510             else
511                 SetPointer( pSdrView->GetPreferedPointer( rLPt, rSh.GetOut() ) );
512         }
513     }
514     else
515     {
516         if( !rSh.IsPageAtPos( rLPt ) || pAnchorMarker )
517             eStyle = POINTER_ARROW;
518         else
519         {
520             if( bCntAtPos )
521             {
522                 SwContentAtPos aSwContentAtPos(
523                     SwContentAtPos::SW_CLICKFIELD|
524                     SwContentAtPos::SW_INETATTR|
525                     SwContentAtPos::SW_FTN |
526                     SwContentAtPos::SW_SMARTTAG );
527                 if( rSh.GetContentAtPos( rLPt, aSwContentAtPos) )
528                 {
529                     const bool bClickToFollow = SwContentAtPos::SW_INETATTR == aSwContentAtPos.eCntntAtPos ||
530                                                 SwContentAtPos::SW_SMARTTAG == aSwContentAtPos.eCntntAtPos;
531 
532                      if( !bClickToFollow ||
533                          (SwContentAtPos::SW_INETATTR == aSwContentAtPos.eCntntAtPos && bExecHyperlinks) ||
534                          (SwContentAtPos::SW_SMARTTAG == aSwContentAtPos.eCntntAtPos && bExecSmarttags) )
535                         eStyle = POINTER_REFHAND;
536                 }
537             }
538         }
539 
540         // which kind of text pointer have we to show - horz / vert - ?
541         if( POINTER_TEXT == eStyle && rSh.IsInVerticalText( &rLPt ))
542             eStyle = POINTER_TEXT_VERTICAL;
543 
544         SetPointer( eStyle );
545     }
546 }
547 
548 /*--------------------------------------------------------------------
549     Beschreibung: Timer fuer Selektion vergroessern
550  --------------------------------------------------------------------*/
551 
552 
IMPL_LINK(SwEditWin,TimerHandler,Timer *,EMPTYARG)553 IMPL_LINK( SwEditWin, TimerHandler, Timer *, EMPTYARG )
554 {
555     DBG_PROFSTART(edithdl);
556 
557     SwWrtShell &rSh = rView.GetWrtShell();
558     Point aModPt( aMovePos );
559     const SwRect aOldVis( rSh.VisArea() );
560     sal_Bool bDone = sal_False;
561 
562     if ( !rSh.VisArea().IsInside( aModPt ) )
563     {
564         if ( bInsDraw )
565         {
566             const int nMaxScroll = 40;
567             rView.Scroll( Rectangle(aModPt,Size(1,1)), nMaxScroll, nMaxScroll);
568             bDone = sal_True;
569         }
570         else if ( bFrmDrag )
571         {
572             (rSh.*rSh.fnDrag)(&aModPt,sal_False);
573             bDone = sal_True;
574         }
575         if ( !bDone )
576             aModPt = rSh.GetCntntPos( aModPt,aModPt.Y() > rSh.VisArea().Bottom() );
577     }
578     if ( !bDone && !(bFrmDrag || bInsDraw) )
579     {
580         if ( pRowColumnSelectionStart )
581         {
582             Point aPos( aModPt );
583             rSh.SelectTableRowCol( *pRowColumnSelectionStart, &aPos, bIsRowDrag );
584         }
585         else
586             (rSh.*rSh.fnSetCrsr)( &aModPt, sal_False );
587 
588         //fix(24138): Es kann sein, dass der "Sprung" ueber eine Tabelle so
589         //nicht geschafft wird. Deshalb wir hier eben per Up/Down ueber die
590         //Tabelle gesprungen.
591         const SwRect& rVisArea = rSh.VisArea();
592         if( aOldVis == rVisArea && !rSh.IsStartOfDoc() && !rSh.IsEndOfDoc() )
593         {
594             //JP 11.10.2001 Bug 72294 - take the center point of VisArea to
595             //              decide in which direction the user want.
596             if( aModPt.Y() < ( rVisArea.Top() + rVisArea.Height() / 2 ) )
597                 rSh.Up( sal_True, 1 );
598             else
599                 rSh.Down( sal_True, 1 );
600         }
601     }
602 
603     aMovePos += rSh.VisArea().Pos() - aOldVis.Pos();
604     JustifyAreaTimer();
605     DBG_PROFSTOP(edithdl);
606     return 0;
607 }
608 
609 /*--------------------------------------------------------------------
610     Beschreibung:
611  --------------------------------------------------------------------*/
612 
613 
JustifyAreaTimer()614 void SwEditWin::JustifyAreaTimer()
615 {
616     const Rectangle &rVisArea = GetView().GetVisArea();
617 #ifdef UNX
618     const long coMinLen = 100;
619 #else
620     const long coMinLen = 50;
621 #endif
622     long nTimeout = 800,
623          nDiff = Max(
624          Max( aMovePos.Y() - rVisArea.Bottom(), rVisArea.Top() - aMovePos.Y() ),
625          Max( aMovePos.X() - rVisArea.Right(),  rVisArea.Left() - aMovePos.X()));
626     aTimer.SetTimeout( Max( coMinLen, nTimeout - nDiff) );
627 }
628 
LeaveArea(const Point & rPos)629 void SwEditWin::LeaveArea(const Point &rPos)
630 {
631     aMovePos = rPos;
632     JustifyAreaTimer();
633     if( !aTimer.IsActive() )
634         aTimer.Start();
635     if( pShadCrsr )
636         delete pShadCrsr, pShadCrsr = 0;
637 }
638 
EnterArea()639 inline void SwEditWin::EnterArea()
640 {
641     aTimer.Stop();
642 }
643 
644 /*------------------------------------------------------------------------
645  Beschreibung:  Modus fuer Rahmen einfuegen
646 ------------------------------------------------------------------------*/
647 
648 
InsFrm(sal_uInt16 nCols)649 void SwEditWin::InsFrm(sal_uInt16 nCols)
650 {
651     StdDrawMode( OBJ_NONE, sal_False );
652     bInsFrm = sal_True;
653     nInsFrmColCount = nCols;
654 }
655 
656 
657 
StdDrawMode(SdrObjKind eSdrObjectKind,sal_Bool bObjSelect)658 void SwEditWin::StdDrawMode( SdrObjKind eSdrObjectKind, sal_Bool bObjSelect )
659 {
660     SetSdrDrawMode( eSdrObjectKind );
661 
662     if (bObjSelect)
663         rView.SetDrawFuncPtr(new DrawSelection( &rView.GetWrtShell(), this, &rView ));
664     else
665         rView.SetDrawFuncPtr(new SwDrawBase( &rView.GetWrtShell(), this, &rView ));
666 
667     rView.SetSelDrawSlot();
668     SetSdrDrawMode( eSdrObjectKind );
669     if (bObjSelect)
670         rView.GetDrawFuncPtr()->Activate( SID_OBJECT_SELECT );
671     else
672         rView.GetDrawFuncPtr()->Activate( sal::static_int_cast< sal_uInt16 >(eSdrObjectKind) );     // don't know if this is useful at all; but it keeps functionality as it was...
673     bInsFrm = sal_False;
674     nInsFrmColCount = 1;
675 }
676 
677 
678 
StopInsFrm()679 void SwEditWin::StopInsFrm()
680 {
681     if (rView.GetDrawFuncPtr())
682     {
683         rView.GetDrawFuncPtr()->Deactivate();
684         rView.SetDrawFuncPtr(NULL);
685     }
686     rView.LeaveDrawCreate();    // Konstruktionsmode verlassen
687     bInsFrm = sal_False;
688     nInsFrmColCount = 1;
689 }
690 
691 /*--------------------------------------------------------------------
692  --------------------------------------------------------------------*/
693 
694 
IsInputSequenceCheckingRequired(const String & rText,const SwPaM & rCrsr) const695 sal_Bool SwEditWin::IsInputSequenceCheckingRequired( const String &rText, const SwPaM& rCrsr ) const
696 {
697     const SvtCTLOptions& rCTLOptions = SW_MOD()->GetCTLOptions();
698     if ( !rCTLOptions.IsCTLFontEnabled() ||
699          !rCTLOptions.IsCTLSequenceChecking() )
700          return sal_False;
701 
702     const xub_StrLen nFirstPos = rCrsr.Start()->nContent.GetIndex();
703     if ( 0 == nFirstPos ) /* first char needs not to be checked */
704         return sal_False;
705 
706     SwBreakIt *pBreakIter = SwBreakIt::Get();
707     uno::Reference < i18n::XBreakIterator > xBI = pBreakIter->GetBreakIter();
708     long nCTLScriptPos = -1;
709 
710     if (xBI.is())
711     {
712         if (xBI->getScriptType( rText, 0 ) == i18n::ScriptType::COMPLEX)
713             nCTLScriptPos = 0;
714         else
715             nCTLScriptPos = xBI->nextScript( rText, 0, i18n::ScriptType::COMPLEX );
716     }
717 
718     return (0 <= nCTLScriptPos && nCTLScriptPos <= rText.Len());
719 }
720 
721 
722 /*--------------------------------------------------------------------
723      Beschreibung:  Der Character Buffer wird in das Dokument eingefuegt
724  --------------------------------------------------------------------*/
725 
726 
FlushInBuffer()727 void SwEditWin::FlushInBuffer()
728 {
729     if ( aInBuffer.Len() )
730     {
731         SwWrtShell& rSh = rView.GetWrtShell();
732 
733         // generate new sequence input checker if not already done
734         if ( !pCheckIt )
735             pCheckIt = new SwCheckIt;
736 
737         uno::Reference < i18n::XExtendedInputSequenceChecker > xISC = pCheckIt->xCheck;
738         if ( xISC.is() && IsInputSequenceCheckingRequired( aInBuffer, *rSh.GetCrsr() ) )
739         {
740             //
741             // apply (Thai) input sequence checking/correction
742             //
743 
744             rSh.Push(); // push current cursor to stack
745 
746             // get text from the beginning (i.e left side) of current selection
747             // to the start of the paragraph
748             rSh.NormalizePam();     // make point be the first (left) one
749             if (!rSh.GetCrsr()->HasMark())
750                 rSh.GetCrsr()->SetMark();
751             rSh.GetCrsr()->GetMark()->nContent = 0;
752             String aLeftText( rSh.GetCrsr()->GetTxt() );
753 
754             SvtCTLOptions& rCTLOptions = SW_MOD()->GetCTLOptions();
755 
756             xub_StrLen nExpandSelection = 0;
757             if (aLeftText.Len() > 0)
758             {
759                 sal_Unicode cChar = '\0';
760 
761                 xub_StrLen nTmpPos = aLeftText.Len();
762                 sal_Int16 nCheckMode = rCTLOptions.IsCTLSequenceCheckingRestricted() ?
763                         i18n::InputSequenceCheckMode::STRICT : i18n::InputSequenceCheckMode::BASIC;
764 
765                 rtl::OUString aOldText( aLeftText );
766                 rtl::OUString aNewText( aOldText );
767                 if (rCTLOptions.IsCTLSequenceCheckingTypeAndReplace())
768                 {
769                     for (xub_StrLen k = 0;  k < aInBuffer.Len();  ++k)
770                     {
771                         cChar = aInBuffer.GetChar(k);
772                         const xub_StrLen nPrevPos = static_cast<xub_StrLen>(xISC->correctInputSequence( aNewText, nTmpPos - 1, cChar, nCheckMode ));
773 
774                         // valid sequence or sequence could be corrected:
775                         if (nPrevPos != aNewText.getLength())
776                             nTmpPos = nPrevPos + 1;
777                     }
778 
779                     // find position of first character that has changed
780                     sal_Int32 nOldLen = aOldText.getLength();
781                     sal_Int32 nNewLen = aNewText.getLength();
782                     const sal_Unicode *pOldTxt = aOldText.getStr();
783                     const sal_Unicode *pNewTxt = aNewText.getStr();
784                     sal_Int32 nChgPos = 0;
785                     while ( nChgPos < nOldLen && nChgPos < nNewLen &&
786                             pOldTxt[nChgPos] == pNewTxt[nChgPos] )
787                         ++nChgPos;
788 
789                     xub_StrLen nChgLen = static_cast< xub_StrLen >(nNewLen - nChgPos);
790                     String aChgText( aNewText.copy( static_cast< xub_StrLen >(nChgPos), nChgLen ) );
791 
792                     if (aChgText.Len())
793                     {
794                         aInBuffer = aChgText;
795                         nExpandSelection = aLeftText.Len() - static_cast< xub_StrLen >(nChgPos);
796                     }
797                     else
798                         aInBuffer.Erase();
799                 }
800                 else
801                 {
802                     for (xub_StrLen k = 0;  k < aInBuffer.Len();  ++k)
803                     {
804                         cChar = aInBuffer.GetChar(k);
805                         if (xISC->checkInputSequence( aNewText, nTmpPos - 1, cChar, nCheckMode ))
806                         {
807                             // character can be inserted:
808                             aNewText += rtl::OUString( (sal_Unicode) cChar );
809                             ++nTmpPos;
810                         }
811                     }
812                     aInBuffer = aNewText.copy( aOldText.getLength() );  // copy new text to be inserted to buffer
813                 }
814             }
815 
816             // at this point now we will insert the buffer text 'normally' some lines below...
817 
818             rSh.Pop( sal_False );  // pop old cursor from stack
819 
820             if (!aInBuffer.Len())
821                 return;
822 
823             // if text prior to the original selection needs to be changed
824             // as well, we now expand the selection accordingly.
825             SwPaM &rCrsr = *rSh.GetCrsr();
826             xub_StrLen nCrsrStartPos = rCrsr.Start()->nContent.GetIndex();
827             DBG_ASSERT( nCrsrStartPos >= nExpandSelection, "cannot expand selection as specified!!" );
828             if (nExpandSelection && nCrsrStartPos >= nExpandSelection)
829             {
830                 if (!rCrsr.HasMark())
831                     rCrsr.SetMark();
832                 rCrsr.Start()->nContent -= nExpandSelection;
833             }
834         }
835 
836         uno::Reference< frame::XDispatchRecorder > xRecorder =
837                 rView.GetViewFrame()->GetBindings().GetRecorder();
838         if ( xRecorder.is() )
839         {
840             //Shell ermitteln
841             SfxShell *pSfxShell = lcl_GetShellFromDispatcher( rView, TYPE(SwTextShell) );
842             // Request generieren und recorden
843             if (pSfxShell)
844             {
845                 SfxRequest aReq( rView.GetViewFrame(), FN_INSERT_STRING );
846                 aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, aInBuffer ) );
847                 aReq.Done();
848             }
849         }
850         //#21019# apply CTL and CJK language to the text input
851         sal_Bool bLang = true;
852         if(eBufferLanguage != LANGUAGE_DONTKNOW)
853         {
854             sal_uInt16 nWhich = 0;
855             switch( GetI18NScriptTypeOfLanguage( eBufferLanguage ))
856             {
857                 case  i18n::ScriptType::ASIAN:     nWhich = RES_CHRATR_CJK_LANGUAGE; break;
858                 case  i18n::ScriptType::COMPLEX:   nWhich = RES_CHRATR_CTL_LANGUAGE; break;
859                 case  i18n::ScriptType::LATIN:     nWhich = RES_CHRATR_LANGUAGE; break;
860                 default: bLang = sal_False;
861             }
862             if(bLang)
863             {
864                 SfxItemSet aLangSet(rView.GetPool(), nWhich, nWhich);
865                 rSh.GetCurAttr(aLangSet);
866                 if(SFX_ITEM_DEFAULT <= aLangSet.GetItemState(nWhich, sal_True))
867                 {
868                     LanguageType eLang = static_cast<const SvxLanguageItem&>(aLangSet.Get(nWhich)).GetLanguage();
869                     if ( eLang == eBufferLanguage )
870                         // current language attribute equal to language reported from system
871                         bLang = sal_False;
872                     else if ( !bInputLanguageSwitched && RES_CHRATR_LANGUAGE == nWhich /* && (eLang&LANGUAGE_MASK_PRIMARY) == LANGUAGE_ENGLISH */ )
873                     {
874                         // special case: switching between two "LATIN" languages
875                         // In case the current keyboard setting might be suitable for both languages we can't safely assume that the user
876                         // wants to use the language reported from the system, except if we knew that it was explicitly switched (thus the check for "bInputLangeSwitched").
877                         // The language reported by the system could be just the system default language that the user is not even aware of,
878                         // because no language selection tool is installed at all. In this case the OOo language should get preference as
879                         // it might have been selected by the user explicitly.
880                         // Usually this case happens if the OOo language is different to the system language but the system keyboard is still suitable
881                         // for the OOo language (e.g. writing English texts with a German keyboard).
882                         // For non-latin keyboards overwriting the attribute is still valid. We do this for kyrillic and greek ATM.
883                         // In future versions of OOo this should be replaced by a configuration switch that allows to give the preference to
884                         // the OOo setting or the system setting explicitly and/or a better handling of the script type.
885                         sal_Int16 nScript = GetAppCharClass().getScript( aInBuffer, 0 );
886                         i18n::UnicodeScript eType = (i18n::UnicodeScript) nScript;
887 
888                         bool bSystemIsNonLatin = false, bOOoLangIsNonLatin = false;
889                         switch ( eType )
890                         {
891                             case i18n::UnicodeScript_kGreek:
892                             case i18n::UnicodeScript_kCyrillic:
893                                 // in case other UnicodeScripts require special keyboards they can be added here
894                                 bSystemIsNonLatin = true;
895                                 break;
896                             default:
897                                 break;
898                         }
899 
900                         switch ( eLang )
901                         {
902                             case LANGUAGE_AZERI_CYRILLIC:
903                             case LANGUAGE_BOSNIAN_CYRILLIC_BOSNIA_HERZEGOVINA:
904                             case LANGUAGE_BULGARIAN:
905                             case LANGUAGE_GREEK:
906                             case LANGUAGE_RUSSIAN:
907                             case LANGUAGE_RUSSIAN_MOLDOVA:
908                             case LANGUAGE_SERBIAN_CYRILLIC:
909                             case LANGUAGE_SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA:
910                             case LANGUAGE_UZBEK_CYRILLIC:
911                             case LANGUAGE_UKRAINIAN:
912                             case LANGUAGE_BELARUSIAN:
913                                 bOOoLangIsNonLatin = true;
914                                 break;
915                             default:
916                                 break;
917                         }
918 
919                         bLang = (bSystemIsNonLatin != bOOoLangIsNonLatin);
920                     }
921                 }
922                 if(bLang)
923                 {
924                     SvxLanguageItem aLangItem( eBufferLanguage, nWhich );
925                     rSh.SetAttrItem( aLangItem );
926                 }
927             }
928         }
929 
930         rSh.Insert( aInBuffer );
931         eBufferLanguage = LANGUAGE_DONTKNOW;
932         aInBuffer.Erase();
933         bFlushCharBuffer = sal_False;
934     }
935 }
936 
937 #define MOVE_LEFT_SMALL     0
938 #define MOVE_UP_SMALL       1
939 #define MOVE_RIGHT_BIG      2
940 #define MOVE_DOWN_BIG       3
941 #define MOVE_LEFT_BIG       4
942 #define MOVE_UP_BIG         5
943 #define MOVE_RIGHT_SMALL    6
944 #define MOVE_DOWN_SMALL     7
945 
946 // #121236# Support for shift key in writer
947 #define MOVE_LEFT_HUGE      8
948 #define MOVE_UP_HUGE        9
949 #define MOVE_RIGHT_HUGE     10
950 #define MOVE_DOWN_HUGE      11
951 
ChangeFly(sal_uInt8 nDir,sal_Bool bWeb)952 void SwEditWin::ChangeFly( sal_uInt8 nDir, sal_Bool bWeb )
953 {
954     SwWrtShell &rSh = rView.GetWrtShell();
955     SwRect aTmp = rSh.GetFlyRect();
956     if( aTmp.HasArea() &&
957         !rSh.IsSelObjProtected( FLYPROTECT_POS ) )
958     {
959         SfxItemSet aSet(rSh.GetAttrPool(),
960                         RES_FRM_SIZE, RES_FRM_SIZE,
961                         RES_VERT_ORIENT, RES_ANCHOR,
962                         RES_COL, RES_COL,
963                         RES_PROTECT, RES_PROTECT,
964                         RES_FOLLOW_TEXT_FLOW, RES_FOLLOW_TEXT_FLOW, 0);
965         rSh.GetFlyFrmAttr( aSet );
966         RndStdIds eAnchorId = ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetAnchorId();
967         Size aSnap;
968         bool bHuge(MOVE_LEFT_HUGE == nDir ||
969             MOVE_UP_HUGE == nDir ||
970             MOVE_RIGHT_HUGE == nDir ||
971             MOVE_DOWN_HUGE == nDir);
972 
973         if(MOVE_LEFT_SMALL == nDir ||
974             MOVE_UP_SMALL == nDir ||
975             MOVE_RIGHT_SMALL == nDir ||
976             MOVE_DOWN_SMALL == nDir )
977         {
978             aSnap = PixelToLogic(Size(1,1));
979         }
980         else
981         {
982             aSnap = rSh.GetViewOptions()->GetSnapSize();
983             short nDiv = rSh.GetViewOptions()->GetDivisionX();
984             if ( nDiv > 0 )
985                 aSnap.Width() = Max( (sal_uLong)1, (sal_uLong)aSnap.Width() / nDiv );
986             nDiv = rSh.GetViewOptions()->GetDivisionY();
987             if ( nDiv > 0 )
988                 aSnap.Height() = Max( (sal_uLong)1, (sal_uLong)aSnap.Height() / nDiv );
989         }
990 
991         if(bHuge)
992         {
993             // #121236# 567twips == 1cm, but just take three times the normal snap
994             aSnap = Size(aSnap.Width() * 3, aSnap.Height() * 3);
995         }
996 
997         SwRect aBoundRect;
998         Point aRefPoint;
999         {
1000             SwFmtVertOrient aVert( (SwFmtVertOrient&)aSet.Get(RES_VERT_ORIENT) );
1001             const bool bFollowTextFlow =
1002                     static_cast<const SwFmtFollowTextFlow&>(aSet.Get(RES_FOLLOW_TEXT_FLOW)).GetValue();
1003             const SwPosition* pToCharCntntPos = ((SwFmtAnchor&)aSet.Get(RES_ANCHOR)).GetCntntAnchor();
1004             rSh.CalcBoundRect( aBoundRect, eAnchorId,
1005                                text::RelOrientation::FRAME, aVert.GetRelationOrient(),
1006                                pToCharCntntPos, bFollowTextFlow,
1007                                false, &aRefPoint );
1008         }
1009         long nLeft = Min( aTmp.Left() - aBoundRect.Left(), aSnap.Width() );
1010         long nRight = Min( aBoundRect.Right() - aTmp.Right(), aSnap.Width() );
1011         long nUp = Min( aTmp.Top() - aBoundRect.Top(), aSnap.Height() );
1012         long nDown = Min( aBoundRect.Bottom() - aTmp.Bottom(), aSnap.Height() );
1013 
1014         switch ( nDir )
1015         {
1016             case MOVE_LEFT_BIG:
1017             case MOVE_LEFT_HUGE:
1018             case MOVE_LEFT_SMALL: aTmp.Left( aTmp.Left() - nLeft );
1019                 break;
1020 
1021             case MOVE_UP_BIG:
1022             case MOVE_UP_HUGE:
1023             case MOVE_UP_SMALL: aTmp.Top( aTmp.Top() - nUp );
1024                 break;
1025 
1026             case MOVE_RIGHT_SMALL:
1027                 if( aTmp.Width() < aSnap.Width() + MINFLY )
1028                     break;
1029                 nRight = aSnap.Width(); // kein break
1030             case MOVE_RIGHT_HUGE:
1031             case MOVE_RIGHT_BIG: aTmp.Left( aTmp.Left() + nRight );
1032                 break;
1033 
1034             case MOVE_DOWN_SMALL:
1035                 if( aTmp.Height() < aSnap.Height() + MINFLY )
1036                     break;
1037                 nDown = aSnap.Height(); // kein break
1038             case MOVE_DOWN_HUGE:
1039             case MOVE_DOWN_BIG: aTmp.Top( aTmp.Top() + nDown );
1040                 break;
1041 
1042             default: ASSERT( sal_True, "ChangeFly: Unknown direction." );
1043         }
1044         sal_Bool bSet = sal_False;
1045         if ((FLY_AS_CHAR == eAnchorId) && ( nDir % 2 ))
1046         {
1047             long aDiff = aTmp.Top() - aRefPoint.Y();
1048             if( aDiff > 0 )
1049                 aDiff = 0;
1050             else if ( aDiff < -aTmp.Height() )
1051                 aDiff = -aTmp.Height();
1052             SwFmtVertOrient aVert( (SwFmtVertOrient&)aSet.Get(RES_VERT_ORIENT) );
1053             sal_Int16 eNew;
1054             if( bWeb )
1055             {
1056                 eNew = aVert.GetVertOrient();
1057                 sal_Bool bDown = 0 != ( nDir & 0x02 );
1058                 switch( eNew )
1059                 {
1060                     case text::VertOrientation::CHAR_TOP:
1061                         if( bDown ) eNew = text::VertOrientation::CENTER;
1062                     break;
1063                     case text::VertOrientation::CENTER:
1064                         eNew = bDown ? text::VertOrientation::TOP : text::VertOrientation::CHAR_TOP;
1065                     break;
1066                     case text::VertOrientation::TOP:
1067                         if( !bDown ) eNew = text::VertOrientation::CENTER;
1068                     break;
1069                     case text::VertOrientation::LINE_TOP:
1070                         if( bDown ) eNew = text::VertOrientation::LINE_CENTER;
1071                     break;
1072                     case text::VertOrientation::LINE_CENTER:
1073                         eNew = bDown ? text::VertOrientation::LINE_BOTTOM : text::VertOrientation::LINE_TOP;
1074                     break;
1075                     case text::VertOrientation::LINE_BOTTOM:
1076                         if( !bDown ) eNew = text::VertOrientation::LINE_CENTER;
1077                     break;
1078                     default:; //prevent warning
1079                 }
1080             }
1081             else
1082             {
1083                 aVert.SetPos( aDiff );
1084                 eNew = text::VertOrientation::NONE;
1085             }
1086             aVert.SetVertOrient( eNew );
1087             aSet.Put( aVert );
1088             bSet = sal_True;
1089         }
1090         if (bWeb && (FLY_AT_PARA == eAnchorId)
1091             && ( nDir==MOVE_LEFT_SMALL || nDir==MOVE_RIGHT_BIG ))
1092         {
1093             SwFmtHoriOrient aHori( (SwFmtHoriOrient&)aSet.Get(RES_HORI_ORIENT) );
1094             sal_Int16 eNew;
1095             eNew = aHori.GetHoriOrient();
1096             switch( eNew )
1097             {
1098                 case text::HoriOrientation::RIGHT:
1099                     if( nDir==MOVE_LEFT_SMALL )
1100                         eNew = text::HoriOrientation::LEFT;
1101                 break;
1102                 case text::HoriOrientation::LEFT:
1103                     if( nDir==MOVE_RIGHT_BIG )
1104                         eNew = text::HoriOrientation::RIGHT;
1105                 break;
1106                 default:; //prevent warning
1107             }
1108             if( eNew != aHori.GetHoriOrient() )
1109             {
1110                 aHori.SetHoriOrient( eNew );
1111                 aSet.Put( aHori );
1112                 bSet = sal_True;
1113             }
1114         }
1115         rSh.StartAllAction();
1116         if( bSet )
1117             rSh.SetFlyFrmAttr( aSet );
1118         sal_Bool bSetPos = (FLY_AS_CHAR != eAnchorId);
1119         if(bSetPos && bWeb)
1120         {
1121             if (FLY_AT_PAGE != eAnchorId)
1122             {
1123                 bSetPos = sal_False;
1124             }
1125             else
1126             {
1127                 bSetPos = (::GetHtmlMode(rView.GetDocShell()) & HTMLMODE_SOME_ABS_POS) ?
1128                     sal_True : sal_False;
1129             }
1130         }
1131         if( bSetPos )
1132             rSh.SetFlyPos( aTmp.Pos() );
1133         rSh.EndAllAction();
1134     }
1135 }
1136 /* -----------------------------23.05.2002 11:35------------------------------
1137 
1138  ---------------------------------------------------------------------------*/
ChangeDrawing(sal_uInt8 nDir)1139 void SwEditWin::ChangeDrawing( sal_uInt8 nDir )
1140 {
1141     SwWrtShell &rSh = rView.GetWrtShell();
1142     rSh.StartUndo();
1143 
1144     long nX = 0;
1145     long nY = 0;
1146     const sal_Bool bOnePixel(
1147         MOVE_LEFT_SMALL == nDir ||
1148         MOVE_UP_SMALL == nDir ||
1149         MOVE_RIGHT_SMALL == nDir ||
1150         MOVE_DOWN_SMALL == nDir);
1151     const sal_Bool bHuge(
1152         MOVE_LEFT_HUGE == nDir ||
1153         MOVE_UP_HUGE == nDir ||
1154         MOVE_RIGHT_HUGE == nDir ||
1155         MOVE_DOWN_HUGE == nDir);
1156     sal_uInt16 nAnchorDir = SW_MOVE_UP;
1157     switch(nDir)
1158     {
1159         case MOVE_LEFT_SMALL:
1160         case MOVE_LEFT_HUGE:
1161         case MOVE_LEFT_BIG:
1162             nX = -1;
1163             nAnchorDir = SW_MOVE_LEFT;
1164         break;
1165         case MOVE_UP_SMALL:
1166         case MOVE_UP_HUGE:
1167         case MOVE_UP_BIG:
1168             nY = -1;
1169         break;
1170         case MOVE_RIGHT_SMALL:
1171         case MOVE_RIGHT_HUGE:
1172         case MOVE_RIGHT_BIG:
1173             nX = +1;
1174             nAnchorDir = SW_MOVE_RIGHT;
1175         break;
1176         case MOVE_DOWN_SMALL:
1177         case MOVE_DOWN_HUGE:
1178         case MOVE_DOWN_BIG:
1179             nY = +1;
1180             nAnchorDir = SW_MOVE_DOWN;
1181         break;
1182     }
1183 
1184     if(0 != nX || 0 != nY)
1185     {
1186         sal_uInt8 nProtect = rSh.IsSelObjProtected( FLYPROTECT_POS|FLYPROTECT_SIZE );
1187         Size aSnap( rSh.GetViewOptions()->GetSnapSize() );
1188         short nDiv = rSh.GetViewOptions()->GetDivisionX();
1189         if ( nDiv > 0 )
1190             aSnap.Width() = Max( (sal_uLong)1, (sal_uLong)aSnap.Width() / nDiv );
1191         nDiv = rSh.GetViewOptions()->GetDivisionY();
1192         if ( nDiv > 0 )
1193             aSnap.Height() = Max( (sal_uLong)1, (sal_uLong)aSnap.Height() / nDiv );
1194 
1195         if(bOnePixel)
1196         {
1197             aSnap = PixelToLogic(Size(1,1));
1198         }
1199         else if(bHuge)
1200         {
1201             // #121236# 567twips == 1cm, but just take three times the normal snap
1202             aSnap = Size(aSnap.Width() * 3, aSnap.Height() * 3);
1203         }
1204 
1205         nX *= aSnap.Width();
1206         nY *= aSnap.Height();
1207 
1208         SdrView *pSdrView = rSh.GetDrawView();
1209         const SdrHdlList& rHdlList = pSdrView->GetHdlList();
1210         SdrHdl* pHdl = rHdlList.GetFocusHdl();
1211         rSh.StartAllAction();
1212         if(0L == pHdl)
1213         {
1214             // now move the selected draw objects
1215             // if the object's position is not protected
1216             if(0 == (nProtect&FLYPROTECT_POS))
1217             {
1218                 sal_Bool bDummy1, bDummy2;
1219                 const bool bVertAnchor = rSh.IsFrmVertical( sal_True, bDummy1, bDummy2 );
1220                 const bool bHoriMove = !bVertAnchor == !( nDir % 2 );
1221                 const bool bMoveAllowed =
1222                     !bHoriMove || (rSh.GetAnchorId() != FLY_AS_CHAR);
1223                 if ( bMoveAllowed )
1224                 {
1225                     pSdrView->MoveAllMarked(Size(nX, nY));
1226                     rSh.SetModified();
1227                 }
1228             }
1229         }
1230         else
1231         {
1232             // move handle with index nHandleIndex
1233             if(pHdl && (nX || nY))
1234             {
1235                 if( HDL_ANCHOR == pHdl->GetKind() ||
1236                     HDL_ANCHOR_TR == pHdl->GetKind() )
1237                 {
1238                     // anchor move cannot be allowed when position is protected
1239                     if(0 == (nProtect&FLYPROTECT_POS))
1240                         rSh.MoveAnchor( nAnchorDir );
1241                 }
1242                 //now resize if size is protected
1243                 else if(0 == (nProtect&FLYPROTECT_SIZE))
1244                 {
1245                     // now move the Handle (nX, nY)
1246                     Point aStartPoint(pHdl->GetPos());
1247                     Point aEndPoint(pHdl->GetPos() + Point(nX, nY));
1248                     const SdrDragStat& rDragStat = pSdrView->GetDragStat();
1249 
1250                     // start dragging
1251                     pSdrView->BegDragObj(aStartPoint, 0, pHdl, 0);
1252 
1253                     if(pSdrView->IsDragObj())
1254                     {
1255                         sal_Bool bWasNoSnap = static_cast< sal_Bool >(rDragStat.IsNoSnap());
1256                         sal_Bool bWasSnapEnabled = pSdrView->IsSnapEnabled();
1257 
1258                         // switch snapping off
1259                         if(!bWasNoSnap)
1260                             ((SdrDragStat&)rDragStat).SetNoSnap(sal_True);
1261                         if(bWasSnapEnabled)
1262                             pSdrView->SetSnapEnabled(sal_False);
1263 
1264                         pSdrView->MovAction(aEndPoint);
1265                         pSdrView->EndDragObj();
1266                         rSh.SetModified();
1267 
1268                         // restore snap
1269                         if(!bWasNoSnap)
1270                             ((SdrDragStat&)rDragStat).SetNoSnap(bWasNoSnap);
1271                         if(bWasSnapEnabled)
1272                             pSdrView->SetSnapEnabled(bWasSnapEnabled);
1273                     }
1274                 }
1275             }
1276         }
1277         rSh.EndAllAction();
1278     }
1279 
1280     rSh.EndUndo();
1281 }
1282 
1283 /*--------------------------------------------------------------------
1284     Beschreibung:   KeyEvents
1285  --------------------------------------------------------------------*/
1286 
1287 
1288 
KeyInput(const KeyEvent & rKEvt)1289 void SwEditWin::KeyInput(const KeyEvent &rKEvt)
1290 {
1291     if( rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE &&
1292         pApplyTempl && pApplyTempl->pFormatClipboard )
1293     {
1294         pApplyTempl->pFormatClipboard->Erase();
1295         SetApplyTemplate(SwApplyTemplate());
1296         rView.GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
1297     }
1298 
1299     SfxObjectShell *pObjSh = (SfxObjectShell*)rView.GetViewFrame()->GetObjectShell();
1300     if ( bLockInput || (pObjSh && pObjSh->GetProgress()) )
1301         // Wenn die Rechenleiste aktiv ist oder
1302         // auf dem Document ein Progress laeuft wird keine
1303         // Bestellungen angenommen.
1304         return;
1305 
1306     if( pShadCrsr )
1307         delete pShadCrsr, pShadCrsr = 0;
1308     aKeyInputFlushTimer.Stop();
1309 
1310     SwWrtShell &rSh = rView.GetWrtShell();
1311     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
1312                           rSh.IsCrsrReadonly();
1313 
1314     //if the language changes the buffer must be flushed
1315     LanguageType eNewLanguage = GetInputLanguage();
1316     if(!bIsDocReadOnly && eBufferLanguage != eNewLanguage && aInBuffer.Len())
1317     {
1318         FlushInBuffer();
1319     }
1320     eBufferLanguage = eNewLanguage;
1321 
1322     QuickHelpData aTmpQHD;
1323     if( pQuickHlpData->bClear )
1324     {
1325         aTmpQHD.Move( *pQuickHlpData );
1326         pQuickHlpData->Stop( rSh );
1327     }
1328 
1329     // OS:auch die DrawView braucht noch ein readonly-Flag
1330     if ( !bIsDocReadOnly && rSh.GetDrawView() && rSh.GetDrawView()->KeyInput( rKEvt, this ) )
1331     {
1332         rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll( sal_False );
1333         rSh.SetModified();
1334         return; // Event von der SdrView ausgewertet
1335     }
1336 
1337     if ( rView.GetDrawFuncPtr() && bInsFrm )
1338     {
1339         StopInsFrm();
1340         rSh.Edit();
1341     }
1342 
1343     sal_Bool bFlushBuffer = sal_False;
1344     sal_Bool bNormalChar = sal_False;
1345     sal_Bool bChkInsBlank = pQuickHlpData->bChkInsBlank;
1346     pQuickHlpData->bChkInsBlank = sal_False;
1347 
1348     KeyEvent aKeyEvent( rKEvt );
1349     // look for vertical mappings
1350     if( !bIsDocReadOnly && !rSh.IsSelFrmMode() && !rSh.IsObjSelected() )
1351     {
1352         //JP 21.2.2002: must changed from switch to if, because the Linux
1353         // compiler has problem with the code. Has to remove if the new general
1354         // handler exist.
1355         sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
1356 
1357         if( KEY_UP == nKey || KEY_DOWN == nKey ||
1358             KEY_LEFT == nKey || KEY_RIGHT == nKey )
1359         {
1360             // In general, we want to map the direction keys if we are inside
1361             // some vertical formatted text.
1362             // 1. Exception: For a table cursor in a horizontal table, the
1363             //               directions should never be mapped.
1364             // 2. Exception: For a table cursor in a vertical table, the
1365             //               directions should always be mapped.
1366             const bool bVertText = rSh.IsInVerticalText();
1367             const bool bTblCrsr = rSh.GetTableCrsr();
1368             const bool bVertTable = rSh.IsTableVertical();
1369             if( ( bVertText && ( !bTblCrsr || bVertTable ) ) ||
1370                 ( bTblCrsr && bVertTable ) )
1371             {
1372                 // Attempt to integrate cursor travelling for mongolian layout does not work.
1373                 // Thus, back to previous mapping of cursor keys to direction keys.
1374                 if( KEY_UP == nKey ) nKey = KEY_LEFT;
1375                 else if( KEY_DOWN == nKey ) nKey = KEY_RIGHT;
1376                 else if( KEY_LEFT == nKey ) nKey = KEY_DOWN;
1377                 else if( KEY_RIGHT == nKey ) nKey = KEY_UP;
1378             }
1379 
1380             if ( rSh.IsInRightToLeftText() )
1381             {
1382                 if( KEY_LEFT == nKey ) nKey = KEY_RIGHT;
1383                 else if( KEY_RIGHT == nKey ) nKey = KEY_LEFT;
1384             }
1385 
1386             aKeyEvent = KeyEvent( rKEvt.GetCharCode(),
1387                                   KeyCode( nKey, rKEvt.GetKeyCode().GetModifier() ),
1388                                   rKEvt.GetRepeat() );
1389         }
1390     }
1391 
1392     const KeyCode& rKeyCode = aKeyEvent.GetKeyCode();
1393     sal_Unicode aCh = aKeyEvent.GetCharCode();
1394 
1395     // enable switching to notes ankor with Ctrl - Alt - Page Up/Down
1396     // pressing this inside a note will switch to next/previous note
1397     if ((rKeyCode.IsMod1() && rKeyCode.IsMod2()) && ((rKeyCode.GetCode() == KEY_PAGEUP) || (rKeyCode.GetCode() == KEY_PAGEDOWN)))
1398     {
1399         const bool bNext = rKeyCode.GetCode()==KEY_PAGEDOWN ? true : false;
1400         const SwFieldType* pFldType = rSh.GetFldType( 0, RES_POSTITFLD );
1401         rSh.MoveFldType( pFldType, bNext );
1402         return;
1403     }
1404 
1405     const SwFrmFmt* pFlyFmt = rSh.GetFlyFrmFmt();
1406     if( pFlyFmt )
1407     {
1408         sal_uInt16 nEvent;
1409 
1410         if( 32 <= aCh &&
1411             0 == (( KEY_MOD1 | KEY_MOD2 ) & rKeyCode.GetModifier() ))
1412             nEvent = SW_EVENT_FRM_KEYINPUT_ALPHA;
1413         else
1414             nEvent = SW_EVENT_FRM_KEYINPUT_NOALPHA;
1415 
1416         const SvxMacro* pMacro = pFlyFmt->GetMacro().GetMacroTable().Get( nEvent );
1417         if( pMacro )
1418         {
1419             String sRet;
1420             SbxArrayRef xArgs = new SbxArray;
1421             SbxVariableRef xVar = new SbxVariable;
1422             xVar->PutString( pFlyFmt->GetName() );
1423             xArgs->Put( &xVar, 1 );
1424 
1425             xVar = new SbxVariable;
1426             if( SW_EVENT_FRM_KEYINPUT_ALPHA == nEvent )
1427                 xVar->PutChar( aCh );
1428             else
1429                 xVar->PutUShort( rKeyCode.GetModifier() | rKeyCode.GetCode() );
1430             xArgs->Put( &xVar, 2 );
1431 
1432             rSh.ExecMacro( *pMacro, &sRet, &xArgs );
1433             if( sRet.Len() && 0 != sRet.ToInt32() )
1434                 return ;
1435         }
1436     }
1437     int nLclSelectionType;
1438     //A is converted to 1
1439     if( rKeyCode.GetFullCode() == (KEY_A | KEY_MOD1 |KEY_SHIFT)
1440         && rSh.HasDrawView() &&
1441         (0 != (nLclSelectionType = rSh.GetSelectionType()) &&
1442         ((nLclSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_GRF)) ||
1443         ((nLclSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM)) &&
1444                 rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1))))
1445     {
1446         SdrHdlList& rHdlList = (SdrHdlList&)rSh.GetDrawView()->GetHdlList();
1447         SdrHdl* pAnchor = rHdlList.GetHdl(HDL_ANCHOR);
1448         if ( ! pAnchor )
1449             pAnchor = rHdlList.GetHdl(HDL_ANCHOR_TR);
1450         if(pAnchor)
1451             rHdlList.SetFocusHdl(pAnchor);
1452         return;
1453     }
1454 
1455     SvxAutoCorrCfg* pACfg = 0;
1456     SvxAutoCorrect* pACorr = 0;
1457 
1458     uno::Reference< frame::XDispatchRecorder > xRecorder =
1459             rView.GetViewFrame()->GetBindings().GetRecorder();
1460     if ( !xRecorder.is() )
1461     {
1462         pACfg = SvxAutoCorrCfg::Get();
1463         pACorr = pACfg->GetAutoCorrect();
1464     }
1465 
1466     SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
1467 
1468     TblChgWidthHeightType eTblChgMode = nsTblChgWidthHeightType::WH_COL_LEFT;    // initialization just for warning-free code
1469     sal_uInt16 nTblChgSize = 0;
1470     sal_Bool bStopKeyInputTimer = sal_True;
1471     String sFmlEntry;
1472 
1473     enum SW_KeyState { KS_Start,
1474                        KS_CheckKey, KS_InsChar, KS_InsTab,
1475                        KS_NoNum, KS_NumOff, KS_NumOrNoNum, KS_NumDown, KS_NumUp,
1476                        // -> #i23725#
1477                        KS_NumIndentInc, KS_NumIndentDec,
1478                        // <- #i23725#
1479 
1480                        KS_OutlineLvOff,
1481                        KS_NextCell, KS_PrevCell, KS_OutlineUp, KS_OutlineDown,
1482                        KS_GlossaryExpand, KS_NextPrevGlossary,
1483                        KS_AutoFmtByInput,
1484                        KS_NextObject, KS_PrevObject,
1485                        KS_KeyToView,
1486                        KS_LaunchOLEObject, KS_GoIntoFly, KS_GoIntoDrawing,
1487                        KS_EnterDrawHandleMode,
1488                        KS_CheckDocReadOnlyKeys,
1489                        KS_CheckAutoCorrect, KS_EditFormula,
1490                        KS_ColLeftBig, KS_ColRightBig,
1491                        KS_ColLeftSmall, KS_ColRightSmall,
1492                        KS_ColTopBig, KS_ColBottomBig,
1493                        KS_ColTopSmall, KS_ColBottomSmall,
1494                        KS_CellLeftBig, KS_CellRightBig,
1495                        KS_CellLeftSmall, KS_CellRightSmall,
1496                        KS_CellTopBig, KS_CellBottomBig,
1497                        KS_CellTopSmall, KS_CellBottomSmall,
1498 
1499                        KS_InsDel_ColLeftBig, KS_InsDel_ColRightBig,
1500                        KS_InsDel_ColLeftSmall, KS_InsDel_ColRightSmall,
1501                        KS_InsDel_ColTopBig, KS_InsDel_ColBottomBig,
1502                        KS_InsDel_ColTopSmall, KS_InsDel_ColBottomSmall,
1503                        KS_InsDel_CellLeftBig, KS_InsDel_CellRightBig,
1504                        KS_InsDel_CellLeftSmall, KS_InsDel_CellRightSmall,
1505                        KS_InsDel_CellTopBig, KS_InsDel_CellBottomBig,
1506                        KS_InsDel_CellTopSmall, KS_InsDel_CellBottomSmall,
1507                        KS_TblColCellInsDel,
1508 
1509                        KS_Fly_Change, KS_Draw_Change,
1510                        KS_SpecialInsert,
1511                        KS_EnterCharCell,
1512                        KS_GotoNextFieldMark,
1513                        KS_GotoPrevFieldMark,
1514                        KS_Ende };
1515 
1516 
1517 
1518     SW_KeyState eKeyState = bIsDocReadOnly ? KS_CheckDocReadOnlyKeys : KS_CheckKey;
1519     SW_KeyState eNextKeyState = KS_Ende;
1520     sal_uInt8 nDir = 0;
1521 
1522     if (nKS_NUMDOWN_Count > 0)
1523         nKS_NUMDOWN_Count--;
1524 
1525     if (nKS_NUMINDENTINC_Count > 0)
1526         nKS_NUMINDENTINC_Count--;
1527 
1528     while( KS_Ende != eKeyState )
1529     {
1530         SW_KeyState eFlyState = KS_KeyToView;
1531 
1532         switch( eKeyState )
1533         {
1534         case KS_CheckKey:
1535             eKeyState = KS_KeyToView;       // default weiter zur View
1536 
1537 #ifdef DBG_UTIL
1538 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1539             // JP 19.01.99: zum Umschalten des Cursor Verhaltens in ReadOnly
1540             //              Bereichen
1541             if( 0x7210 == rKeyCode.GetFullCode() )
1542                 rSh.SetReadOnlyAvailable( !rSh.IsReadOnlyAvailable() );
1543             else
1544 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1545 #endif
1546 
1547             if( !rKeyCode.IsMod2() && '=' == aCh &&
1548                 !rSh.IsTableMode() && rSh.GetTableFmt() &&
1549                 rSh.IsSttPara() /*&& rSh.IsEndPara()*/ &&
1550                 !rSh.HasReadonlySel() )
1551             {
1552                 // in der Tabelle am Anfang der Zelle ein '=' ->
1553                 //  EditZeile aufrufen (F2-Funktionalitaet)
1554                 rSh.Push();
1555                 if( !rSh.MoveSection( fnSectionCurr, fnSectionStart) &&
1556                     !rSh.IsTableBoxTextFormat() )
1557                 {
1558                     // steht also am Anfang der Box
1559                     eKeyState = KS_EditFormula;
1560                     if( rSh.HasMark() )
1561                         rSh.SwapPam();
1562                     else
1563                         rSh.SttSelect();
1564                     rSh.MoveSection( fnSectionCurr, fnSectionEnd );
1565                     rSh.Pop( sal_True );
1566                     rSh.EndSelect();
1567                     sFmlEntry = '=';
1568                 }
1569                 else
1570                     rSh.Pop( sal_False );
1571             }
1572             else
1573             {
1574                 if( pACorr && aTmpQHD.HasCntnt() && !rSh.HasSelection() &&
1575                     !rSh.HasReadonlySel() && !aTmpQHD.bIsAutoText &&
1576                     pACorr->GetSwFlags().nAutoCmpltExpandKey ==
1577                     (rKeyCode.GetModifier() | rKeyCode.GetCode()) )
1578                 {
1579                     eKeyState = KS_GlossaryExpand;
1580                     break;
1581                 }
1582 
1583                 switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
1584                 {
1585                 case KEY_RIGHT | KEY_MOD2:
1586                     eKeyState = KS_ColRightBig;
1587                     eFlyState = KS_Fly_Change;
1588                     nDir = MOVE_RIGHT_SMALL;
1589                     goto KEYINPUT_CHECKTABLE;
1590 
1591                 case KEY_LEFT | KEY_MOD2:
1592                     eKeyState = KS_ColRightSmall;
1593                     eFlyState = KS_Fly_Change;
1594                     nDir = MOVE_LEFT_SMALL;
1595                     goto KEYINPUT_CHECKTABLE;
1596 
1597                 case KEY_RIGHT | KEY_MOD2 | KEY_SHIFT:
1598                     eKeyState = KS_ColLeftSmall;
1599                     goto KEYINPUT_CHECKTABLE;
1600 
1601                 case KEY_LEFT | KEY_MOD2 | KEY_SHIFT:
1602                     eKeyState = KS_ColLeftBig;
1603                     goto KEYINPUT_CHECKTABLE;
1604 
1605                 case KEY_RIGHT | KEY_MOD2 | KEY_MOD1:
1606                     eKeyState = KS_CellRightBig;
1607                     goto KEYINPUT_CHECKTABLE;
1608 
1609                 case KEY_LEFT | KEY_MOD2 | KEY_MOD1:
1610                     eKeyState = KS_CellRightSmall;
1611                     goto KEYINPUT_CHECKTABLE;
1612 
1613                 case KEY_RIGHT | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
1614                     eKeyState = KS_CellLeftSmall;
1615                     goto KEYINPUT_CHECKTABLE;
1616 
1617                 case KEY_LEFT | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
1618                     eKeyState = KS_CellLeftBig;
1619                     goto KEYINPUT_CHECKTABLE;
1620 
1621                 case KEY_UP | KEY_MOD2:
1622                     eKeyState = KS_ColBottomSmall;
1623                     eFlyState = KS_Fly_Change;
1624                     nDir = MOVE_UP_SMALL;
1625                     goto KEYINPUT_CHECKTABLE;
1626 
1627                 case KEY_DOWN | KEY_MOD2:
1628                     eKeyState = KS_ColBottomBig;
1629                     eFlyState = KS_Fly_Change;
1630                     nDir = MOVE_DOWN_SMALL;
1631                     goto KEYINPUT_CHECKTABLE;
1632 
1633                 case KEY_UP | KEY_MOD2 | KEY_MOD1:
1634                     eKeyState = KS_CellBottomSmall;
1635                     goto KEYINPUT_CHECKTABLE;
1636 
1637                 case KEY_DOWN | KEY_MOD2 | KEY_MOD1:
1638                     eKeyState = KS_CellBottomBig;
1639                     goto KEYINPUT_CHECKTABLE;
1640 
1641                 case KEY_UP | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
1642                     eKeyState = KS_CellTopBig;
1643                     goto KEYINPUT_CHECKTABLE;
1644 
1645                 case KEY_DOWN | KEY_MOD2 | KEY_SHIFT | KEY_MOD1:
1646                     eKeyState = KS_CellTopSmall;
1647                     goto KEYINPUT_CHECKTABLE;
1648 
1649 KEYINPUT_CHECKTABLE:
1650                     if( rSh.IsTableMode() || !rSh.GetTableFmt() )
1651                     {
1652                         if(KS_KeyToView != eFlyState)
1653                         {
1654                             if(!pFlyFmt && KS_KeyToView != eFlyState &&
1655                                 (rSh.GetSelectionType() & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM))  &&
1656                                     rSh.GetDrawView()->AreObjectsMarked())
1657                                 eKeyState = KS_Draw_Change;
1658                         }
1659 
1660                         if( pFlyFmt )
1661                             eKeyState = eFlyState;
1662                         else if( KS_Draw_Change != eKeyState)
1663                             eKeyState = KS_EnterCharCell;
1664                     }
1665                     break;
1666 
1667                 // huge object move
1668                 case KEY_RIGHT | KEY_SHIFT:
1669                 case KEY_LEFT | KEY_SHIFT:
1670                 case KEY_UP | KEY_SHIFT:
1671                 case KEY_DOWN | KEY_SHIFT:
1672                 {
1673                     const int nSelectionType = rSh.GetSelectionType();
1674                     if ( ( pFlyFmt
1675                            && ( nSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF) ) )
1676                          || ( ( nSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM) )
1677                               && rSh.GetDrawView()->AreObjectsMarked() ) )
1678                     {
1679                         eKeyState = pFlyFmt ? KS_Fly_Change : KS_Draw_Change;
1680                         switch ( rKeyCode.GetCode() )
1681                         {
1682                             case KEY_RIGHT: nDir = MOVE_RIGHT_HUGE; break;
1683                             case KEY_LEFT: nDir = MOVE_LEFT_HUGE; break;
1684                             case KEY_UP: nDir = MOVE_UP_HUGE; break;
1685                             case KEY_DOWN: nDir = MOVE_DOWN_HUGE; break;
1686                         }
1687                     }
1688                     break;
1689                 }
1690 
1691 //-------
1692 // Insert/Delete
1693                 case KEY_LEFT:
1694                 case KEY_LEFT | KEY_MOD1:
1695                 {
1696                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
1697                     if(!bMod1)
1698                     {
1699                         eFlyState = KS_Fly_Change;
1700                         nDir = MOVE_LEFT_BIG;
1701                     }
1702                     eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL |
1703                             ( bMod1
1704                                 ? nsTblChgWidthHeightType::WH_CELL_LEFT
1705                                 : nsTblChgWidthHeightType::WH_COL_LEFT );
1706                     nTblChgSize = pModOpt->GetTblVInsert();
1707                 }
1708                     goto KEYINPUT_CHECKTABLE_INSDEL;
1709                 case KEY_RIGHT | KEY_MOD1:
1710                 {
1711                     eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL | nsTblChgWidthHeightType::WH_CELL_RIGHT;
1712                     nTblChgSize = pModOpt->GetTblVInsert();
1713                 }
1714                     goto KEYINPUT_CHECKTABLE_INSDEL;
1715                 case KEY_UP:
1716                 case KEY_UP | KEY_MOD1:
1717                 {
1718                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
1719                     if(!bMod1)
1720                     {
1721                         eFlyState = KS_Fly_Change;
1722                         nDir = MOVE_UP_BIG;
1723                     }
1724                     eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL |
1725                             ( bMod1
1726                                 ? nsTblChgWidthHeightType::WH_CELL_TOP
1727                                 : nsTblChgWidthHeightType::WH_ROW_TOP );
1728                     nTblChgSize = pModOpt->GetTblHInsert();
1729                 }
1730                     goto KEYINPUT_CHECKTABLE_INSDEL;
1731                 case KEY_DOWN:
1732                 case KEY_DOWN | KEY_MOD1:
1733                 {
1734                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
1735                     if(!bMod1)
1736                     {
1737                         eFlyState = KS_Fly_Change;
1738                         nDir = MOVE_DOWN_BIG;
1739                     }
1740                     eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL |
1741                             ( bMod1
1742                                 ? nsTblChgWidthHeightType::WH_CELL_BOTTOM
1743                                 : nsTblChgWidthHeightType::WH_ROW_BOTTOM );
1744                     nTblChgSize = pModOpt->GetTblHInsert();
1745                 }
1746                     goto KEYINPUT_CHECKTABLE_INSDEL;
1747 
1748 KEYINPUT_CHECKTABLE_INSDEL:
1749                     if( rSh.IsTableMode() || !rSh.GetTableFmt() ||
1750                         !bTblInsDelMode ||
1751                         sal_False /* Tabelle geschuetzt */
1752                             )
1753                     {
1754                         const int nSelectionType = rSh.GetSelectionType();
1755 
1756                         eKeyState = KS_KeyToView;
1757                         if(KS_KeyToView != eFlyState)
1758                         {
1759                             if((nSelectionType & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM))  &&
1760                                     rSh.GetDrawView()->AreObjectsMarked())
1761                                 eKeyState = KS_Draw_Change;
1762                             else if(nSelectionType & (nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF))
1763                                 eKeyState = KS_Fly_Change;
1764                         }
1765                     }
1766                     else
1767                     {
1768                         if( !bTblIsInsMode )
1769                             eTblChgMode = eTblChgMode | nsTblChgWidthHeightType::WH_FLAG_BIGGER;
1770                         eKeyState = KS_TblColCellInsDel;
1771                     }
1772                     break;
1773 
1774                 case KEY_DELETE:
1775                     if (rSh.IsInFrontOfLabel() &&
1776                         rSh.NumOrNoNum(sal_False))
1777                         eKeyState = KS_NumOrNoNum;
1778                     break;
1779 
1780                 case KEY_DELETE | KEY_MOD2:
1781                     if( !rSh.IsTableMode() && rSh.GetTableFmt() )
1782                     {
1783                         eKeyState = KS_Ende;
1784                         bTblInsDelMode = sal_True;
1785                         bTblIsInsMode = sal_False;
1786                         bTblIsColMode = sal_True;
1787                         aKeyInputTimer.Start();
1788                         bStopKeyInputTimer = sal_False;
1789                     }
1790                     break;
1791                 case KEY_INSERT | KEY_MOD2:
1792                     if( !rSh.IsTableMode() && rSh.GetTableFmt() )
1793                     {
1794                         eKeyState = KS_Ende;
1795                         bTblInsDelMode = sal_True;
1796                         bTblIsInsMode = sal_True;
1797                         bTblIsColMode = sal_True;
1798                         aKeyInputTimer.Start();
1799                         bStopKeyInputTimer = sal_False;
1800                     }
1801                     break;
1802 
1803                 case KEY_RETURN:                // Return
1804                     if ( !rSh.HasReadonlySel()
1805                          && !rSh.CrsrInsideInputFld() )
1806                     {
1807                         const int nSelectionType = rSh.GetSelectionType();
1808                         if(nSelectionType & nsSelectionType::SEL_OLE)
1809                             eKeyState = KS_LaunchOLEObject;
1810                         else if(nSelectionType & nsSelectionType::SEL_FRM)
1811                             eKeyState = KS_GoIntoFly;
1812                         else if((nSelectionType & nsSelectionType::SEL_DRW) &&
1813                                 0 == (nSelectionType & nsSelectionType::SEL_DRW_TXT) &&
1814                                 rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1)
1815                             eKeyState = KS_GoIntoDrawing;
1816                         else if( aTmpQHD.HasCntnt() && !rSh.HasSelection() &&
1817                             aTmpQHD.bIsAutoText )
1818                             eKeyState = KS_GlossaryExpand;
1819 
1820                         //RETURN und leerer Absatz in Numerierung -> Num. beenden
1821                         else if( !aInBuffer.Len() &&
1822                                  rSh.GetCurNumRule() &&
1823                                  !rSh.GetCurNumRule()->IsOutlineRule() &&
1824                                  !rSh.HasSelection() &&
1825                                 rSh.IsSttPara() && rSh.IsEndPara() )
1826                             eKeyState = KS_NumOff, eNextKeyState = KS_OutlineLvOff;
1827 
1828                         //RETURN fuer neuen Absatz mit AutoFormatierung
1829                         else if( pACfg && pACfg->IsAutoFmtByInput() &&
1830                                 !(nSelectionType & (nsSelectionType::SEL_GRF |
1831                                     nsSelectionType::SEL_OLE | nsSelectionType::SEL_FRM |
1832                                     nsSelectionType::SEL_TBL_CELLS | nsSelectionType::SEL_DRW |
1833                                     nsSelectionType::SEL_DRW_TXT)) )
1834                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_AutoFmtByInput;
1835                         else
1836                             eNextKeyState = eKeyState, eKeyState = KS_CheckAutoCorrect;
1837                     }
1838                     break;
1839 
1840                 case KEY_RETURN | KEY_MOD2:     // ALT-Return
1841                     if ( !rSh.HasReadonlySel()
1842                          && !rSh.IsSttPara()
1843                          && rSh.GetCurNumRule()
1844                          && !rSh.CrsrInsideInputFld() )
1845                     {
1846                         eKeyState = KS_NoNum;
1847                     }
1848                     else if( rSh.CanSpecialInsert() )
1849                         eKeyState = KS_SpecialInsert;
1850                     break;
1851 
1852                 case KEY_BACKSPACE:
1853                 case KEY_BACKSPACE | KEY_SHIFT:
1854                     if ( !rSh.HasReadonlySel()
1855                          && !rSh.CrsrInsideInputFld() )
1856                     {
1857                         sal_Bool bDone = sal_False;
1858                         // Remove the paragraph indent, if the cursor is at the
1859                         // beginning of a paragraph, there is no selection
1860                         // and no numbering rule found at the current paragraph
1861                         // Also try to remove indent, if current paragraph
1862                         // has numbering rule, but isn't counted and only
1863                         // key <backspace> is hit.
1864                         const bool bOnlyBackspaceKey( KEY_BACKSPACE == rKeyCode.GetFullCode() );
1865                         if ( rSh.IsSttPara()
1866                              && !rSh.HasSelection()
1867                              && ( rSh.GetCurNumRule() == NULL
1868                                   || ( rSh.IsNoNum() && bOnlyBackspaceKey ) ) )
1869                         {
1870                             bDone = rSh.TryRemoveIndent();
1871                         }
1872 
1873                         if (bDone)
1874                             eKeyState = KS_Ende;
1875                         else
1876                         {
1877                             if ( rSh.IsSttPara() && !rSh.IsNoNum() )
1878                             {
1879                                 if (nKS_NUMDOWN_Count > 0
1880                                     && rSh.GetNumLevel() > 0)
1881                                 {
1882                                     eKeyState = KS_NumUp;
1883                                     nKS_NUMDOWN_Count = 2;
1884                                     bDone = sal_True;
1885                                 }
1886                                 else if (nKS_NUMINDENTINC_Count > 0)
1887                                 {
1888                                     eKeyState = KS_NumIndentDec;
1889                                     nKS_NUMINDENTINC_Count = 2;
1890                                     bDone = sal_True;
1891                                 }
1892                             }
1893                             // If the cursor is in an empty paragraph, which has
1894                             // a numbering, but not the outline numbering, and
1895                             // there is no selection, the numbering has to be
1896                             // deleted on key <Backspace>.
1897                             // Otherwise method <SwEditShell::NumOrNoNum(..)>
1898                             // should only change the <IsCounted()> state of
1899                             // the current paragraph depending of the key.
1900                             // On <backspace> it is set to <false>,
1901                             // on <shift-backspace> it is set to <true>.
1902                             // Thus, assure that method <SwEditShell::NumOrNum(..)>
1903                             // is only called for the intended purpose.
1904                             if ( !bDone && rSh.IsSttPara() )
1905                             {
1906                                 bool bCallNumOrNoNum( false );
1907                                 if ( bOnlyBackspaceKey && !rSh.IsNoNum() )
1908                                 {
1909                                     bCallNumOrNoNum = true;
1910                                 }
1911                                 else if ( !bOnlyBackspaceKey && rSh.IsNoNum() )
1912                                 {
1913                                     bCallNumOrNoNum = true;
1914                                 }
1915                                 else if ( bOnlyBackspaceKey
1916                                           && rSh.IsSttPara()
1917                                           && rSh.IsEndPara()
1918                                           && !rSh.HasSelection() )
1919                                 {
1920                                     const SwNumRule* pCurrNumRule( rSh.GetCurNumRule() );
1921                                     if ( pCurrNumRule != NULL
1922                                          && pCurrNumRule != rSh.GetOutlineNumRule() )
1923                                     {
1924                                         bCallNumOrNoNum = true;
1925                                     }
1926                                 }
1927                                 if ( bCallNumOrNoNum
1928                                      && rSh.NumOrNoNum( !bOnlyBackspaceKey, sal_True ) )
1929                                 {
1930                                     eKeyState = KS_NumOrNoNum;
1931                                 }
1932                             }
1933                         }
1934                     }
1935                     break;
1936 
1937                 case KEY_RIGHT:
1938                     {
1939                         eFlyState = KS_Fly_Change;
1940                         nDir = MOVE_RIGHT_BIG;
1941                         eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL | nsTblChgWidthHeightType::WH_COL_RIGHT;
1942                         nTblChgSize = pModOpt->GetTblVInsert();
1943                         goto KEYINPUT_CHECKTABLE_INSDEL;
1944                     }
1945                 case KEY_TAB:
1946                 {
1947 
1948 #ifdef SW_CRSR_TIMER
1949                     sal_Bool bOld = rSh.ChgCrsrTimerFlag( sal_False );
1950 #endif
1951                     if (rSh.IsFormProtected() || rSh.GetCurrentFieldmark() || rSh.GetChar(sal_False)==CH_TXT_ATR_FORMELEMENT)
1952                     {
1953                         eKeyState=KS_GotoNextFieldMark;
1954                     }
1955                     else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputFld() )
1956                     {
1957                         GetView().GetViewFrame()->GetDispatcher()->Execute( FN_GOTO_NEXT_INPUTFLD );
1958                         eKeyState = KS_Ende;
1959                     }
1960                     else if( rSh.GetCurNumRule()
1961                              && rSh.IsSttOfPara()
1962                              && !rSh.HasReadonlySel() )
1963                     {
1964                         if ( rSh.IsFirstOfNumRule() &&
1965                              numfunc::ChangeIndentOnTabAtFirstPosOfFirstListItem() )
1966                             eKeyState = KS_NumIndentInc;
1967                         else
1968                             eKeyState = KS_NumDown;
1969                     }
1970                     else if ( rSh.GetTableFmt() )
1971                     {
1972                         if( rSh.HasSelection() || rSh.HasReadonlySel() )
1973                             eKeyState = KS_NextCell;
1974                         else
1975                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_NextCell;
1976                     }
1977                     else if ( rSh.GetSelectionType() &
1978                                 (nsSelectionType::SEL_GRF |
1979                                     nsSelectionType::SEL_FRM |
1980                                     nsSelectionType::SEL_OLE |
1981                                     nsSelectionType::SEL_DRW |
1982                                     nsSelectionType::SEL_DRW_FORM))
1983 
1984                             eKeyState = KS_NextObject;
1985                     else
1986                     {
1987                         eKeyState = KS_InsTab;
1988                         if( rSh.IsSttOfPara() && !rSh.HasReadonlySel() )
1989                         {
1990                             SwTxtFmtColl* pColl = rSh.GetCurTxtFmtColl();
1991                             if( pColl &&
1992                                 //0 <= pColl->GetOutlineLevel() && #i24560#
1993                                 //MAXLEVEL - 1 > pColl->GetOutlineLevel() )//#outline level,zhaojianwei
1994                                 pColl->IsAssignedToListLevelOfOutlineStyle()
1995                                 && MAXLEVEL-1 > pColl->GetAssignedOutlineStyleLevel() )//<-end,zhaojianwei
1996                                 eKeyState = KS_OutlineDown;
1997                         }
1998                     }
1999 #ifdef SW_CRSR_TIMER
2000                     rSh.ChgCrsrTimerFlag( bOld );
2001 #endif
2002                 }
2003                 break;
2004                 case KEY_TAB | KEY_SHIFT:
2005                 {
2006 #ifdef SW_CRSR_TIMER
2007                     sal_Bool bOld = rSh.ChgCrsrTimerFlag( sal_False );
2008                     sal_Bool bOld = rSh.ChgCrsrTimerFlag( sal_False );
2009 #endif
2010                     if (rSh.IsFormProtected() || rSh.GetCurrentFieldmark()|| rSh.GetChar(sal_False)==CH_TXT_ATR_FORMELEMENT)
2011                     {
2012                         eKeyState=KS_GotoPrevFieldMark;
2013                     }
2014                     else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputFld() )
2015                     {
2016                         GetView().GetViewFrame()->GetDispatcher()->Execute( FN_GOTO_PREV_INPUTFLD );
2017                         eKeyState = KS_Ende;
2018                     }
2019                     else if( rSh.GetCurNumRule()
2020                              && rSh.IsSttOfPara()
2021                              && !rSh.HasReadonlySel() )
2022                     {
2023                         if ( rSh.IsFirstOfNumRule() &&
2024                              numfunc::ChangeIndentOnTabAtFirstPosOfFirstListItem() )
2025                             eKeyState = KS_NumIndentDec;
2026                         else
2027                             eKeyState = KS_NumUp;
2028                     }
2029                     else if ( rSh.GetTableFmt() )
2030                     {
2031                         if( rSh.HasSelection() || rSh.HasReadonlySel() )
2032                             eKeyState = KS_PrevCell;
2033                         else
2034                             eKeyState = KS_CheckAutoCorrect, eNextKeyState = KS_PrevCell;
2035                     }
2036                     else if ( rSh.GetSelectionType() &
2037                                 (nsSelectionType::SEL_GRF |
2038                                     nsSelectionType::SEL_FRM |
2039                                     nsSelectionType::SEL_OLE |
2040                                     nsSelectionType::SEL_DRW |
2041                                     nsSelectionType::SEL_DRW_FORM))
2042 
2043                             eKeyState = KS_PrevObject;
2044                     else
2045                     {
2046                         eKeyState = KS_Ende;
2047                         if( rSh.IsSttOfPara() && !rSh.HasReadonlySel() )
2048                         {
2049                             SwTxtFmtColl* pColl = rSh.GetCurTxtFmtColl();
2050                             //if( pColl && 0 < pColl->GetOutlineLevel() &&  //#outline level,zhaojianwei
2051                             //  MAXLEVEL - 1 >= pColl->GetOutlineLevel() )
2052                             if( pColl &&
2053                                 pColl->IsAssignedToListLevelOfOutlineStyle() &&
2054                                 0 < pColl->GetAssignedOutlineStyleLevel())
2055                                 eKeyState = KS_OutlineUp;
2056                         }
2057                     }
2058 #ifdef SW_CRSR_TIMER
2059                     rSh.ChgCrsrTimerFlag( bOld );
2060 #endif
2061                 }
2062                 break;
2063                 case KEY_TAB | KEY_MOD1:
2064                 case KEY_TAB | KEY_MOD2:
2065                     if( !rSh.HasReadonlySel() )
2066                     {
2067                         if( aTmpQHD.HasCntnt() && !rSh.HasSelection() )
2068                         {
2069                             // zum naechsten Tip
2070                             aTmpQHD.Inc( pACorr && pACorr->GetSwFlags().
2071                                                    bAutoCmpltEndless );
2072                             eKeyState = KS_NextPrevGlossary;
2073                         }
2074                         else if( rSh.GetTableFmt() )
2075                             eKeyState = KS_InsTab;
2076                         else if((rSh.GetSelectionType() &
2077                                     (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM|
2078                                         nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF))  &&
2079                                 rSh.GetDrawView()->AreObjectsMarked())
2080                             eKeyState = KS_EnterDrawHandleMode;
2081                         else
2082                         {
2083                             eKeyState = KS_InsTab;
2084                         }
2085                     }
2086                     break;
2087 
2088                     case KEY_TAB | KEY_MOD1 | KEY_SHIFT:
2089                         if( aTmpQHD.HasCntnt() && !rSh.HasSelection() &&
2090                             !rSh.HasReadonlySel() )
2091                         {
2092                             // zum vorherigen Tip
2093                             aTmpQHD.Dec( pACorr && pACorr->GetSwFlags().
2094                                                         bAutoCmpltEndless );
2095                             eKeyState = KS_NextPrevGlossary;
2096                         }
2097                         else if((rSh.GetSelectionType() & (nsSelectionType::SEL_DRW|nsSelectionType::SEL_DRW_FORM|
2098                                         nsSelectionType::SEL_FRM|nsSelectionType::SEL_OLE|nsSelectionType::SEL_GRF)) &&
2099                                 rSh.GetDrawView()->AreObjectsMarked())
2100                             eKeyState = KS_EnterDrawHandleMode;
2101                     break;
2102                     case KEY_F2 :
2103                     if( !rSh.HasReadonlySel() )
2104                     {
2105                         const int nSelectionType = rSh.GetSelectionType();
2106                         if(nSelectionType & nsSelectionType::SEL_FRM)
2107                             eKeyState = KS_GoIntoFly;
2108                         else if((nSelectionType & nsSelectionType::SEL_DRW))
2109                             eKeyState = KS_GoIntoDrawing;
2110                     }
2111                     break;
2112                 }
2113             }
2114             break;
2115         case KS_CheckDocReadOnlyKeys:
2116             {
2117                 eKeyState = KS_KeyToView;
2118                 switch( rKeyCode.GetModifier() | rKeyCode.GetCode() )
2119                 {
2120                     case KEY_TAB:
2121                     case KEY_TAB | KEY_SHIFT:
2122                         bNormalChar = sal_False;
2123                         eKeyState = KS_Ende;
2124                         if ( rSh.GetSelectionType() &
2125                                 (nsSelectionType::SEL_GRF |
2126                                     nsSelectionType::SEL_FRM |
2127                                     nsSelectionType::SEL_OLE |
2128                                     nsSelectionType::SEL_DRW |
2129                                     nsSelectionType::SEL_DRW_FORM))
2130 
2131                         {
2132                             eKeyState = rKeyCode.GetModifier() & KEY_SHIFT ?
2133                                                 KS_PrevObject : KS_NextObject;
2134                         }
2135                         else if ( !rSh.IsMultiSelection() && rSh.CrsrInsideInputFld() )
2136                         {
2137                             GetView().GetViewFrame()->GetDispatcher()->Execute(
2138                                 KEY_SHIFT != rKeyCode.GetModifier() ? FN_GOTO_NEXT_INPUTFLD : FN_GOTO_PREV_INPUTFLD );
2139                         }
2140                         else
2141                         {
2142                             rSh.SelectNextPrevHyperlink( KEY_SHIFT != rKeyCode.GetModifier() );
2143                         }
2144                     break;
2145                     case KEY_RETURN:
2146                     {
2147                         const int nSelectionType = rSh.GetSelectionType();
2148                         if(nSelectionType & nsSelectionType::SEL_FRM)
2149                             eKeyState = KS_GoIntoFly;
2150                         else
2151                         {
2152                             SfxItemSet aSet(rSh.GetAttrPool(), RES_TXTATR_INETFMT, RES_TXTATR_INETFMT);
2153                             rSh.GetCurAttr(aSet);
2154                             if(SFX_ITEM_SET == aSet.GetItemState(RES_TXTATR_INETFMT, sal_False))
2155                             {
2156                                 const SfxPoolItem& rItem = aSet.Get(RES_TXTATR_INETFMT, sal_True);
2157                                 bNormalChar = sal_False;
2158                                 eKeyState = KS_Ende;
2159                                 rSh.ClickToINetAttr((const SwFmtINetFmt&)rItem, URLLOAD_NOFILTER);
2160                             }
2161                         }
2162                     }
2163                     break;
2164                 }
2165             }
2166             break;
2167 
2168         case KS_EnterCharCell:
2169             {
2170                 eKeyState = KS_KeyToView;
2171                 switch ( rKeyCode.GetModifier() | rKeyCode.GetCode() )
2172                 {
2173                     case KEY_RIGHT | KEY_MOD2:
2174                         rSh.Right( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
2175                         eKeyState = KS_Ende;
2176                         FlushInBuffer();
2177                         break;
2178                     case KEY_LEFT | KEY_MOD2:
2179                         rSh.Left( CRSR_SKIP_CHARS, sal_False, 1, sal_False );
2180                         eKeyState = KS_Ende;
2181                         FlushInBuffer();
2182                         break;
2183                 }
2184             }
2185             break;
2186 
2187         case KS_KeyToView:
2188             {
2189                 eKeyState = KS_Ende;
2190                 bNormalChar =
2191                     !rKeyCode.IsMod2() &&
2192                     rKeyCode.GetModifier() != (KEY_MOD1) &&
2193                     rKeyCode.GetModifier() != (KEY_MOD1|KEY_SHIFT) &&
2194                                 SW_ISPRINTABLE( aCh );
2195 
2196                 if (bNormalChar && rSh.IsInFrontOfLabel())
2197                 {
2198                     rSh.NumOrNoNum(sal_False);
2199                 }
2200 
2201                 if( aInBuffer.Len() && ( !bNormalChar || bIsDocReadOnly ))
2202                     FlushInBuffer();
2203 
2204                 if( rView.KeyInput( aKeyEvent ) )
2205                     bFlushBuffer = sal_True, bNormalChar = sal_False;
2206                 else
2207                 {
2208 // OS 22.09.95: Da der Sfx Acceleratoren nur aufruft, wenn sie beim letzten
2209 //              Statusupdate enabled wurden, muss copy ggf. von uns
2210 //              'gewaltsam' gerufen werden.
2211                     if( rKeyCode.GetFunction() == KEYFUNC_COPY )
2212                         GetView().GetViewFrame()->GetBindings().Execute(SID_COPY);
2213 
2214 
2215                     if( !bIsDocReadOnly && bNormalChar )
2216                     {
2217                         const int nSelectionType = rSh.GetSelectionType();
2218                         if((nSelectionType & nsSelectionType::SEL_DRW) &&
2219                             0 == (nSelectionType & nsSelectionType::SEL_DRW_TXT) &&
2220                             rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1)
2221                         {
2222                             SdrObject* pObj = rSh.GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
2223                             if(pObj)
2224                             {
2225                                 EnterDrawTextMode(pObj->GetLogicRect().Center());
2226                                 if ( rView.GetCurShell()->ISA(SwDrawTextShell) )
2227                                     ((SwDrawTextShell*)rView.GetCurShell())->Init();
2228                                 rSh.GetDrawView()->KeyInput( rKEvt, this );
2229                             }
2230                         }
2231                         else if(nSelectionType & nsSelectionType::SEL_FRM)
2232                         {
2233                             rSh.UnSelectFrm();
2234                             rSh.LeaveSelFrmMode();
2235                             rView.AttrChangedNotify(&rSh);
2236                             rSh.MoveSection( fnSectionCurr, fnSectionEnd );
2237                         }
2238                         eKeyState = KS_InsChar;
2239                     }
2240                     else
2241                     {
2242                         bNormalChar = sal_False;
2243                         Window::KeyInput( aKeyEvent );
2244                     }
2245                 }
2246             }
2247             break;
2248         case KS_LaunchOLEObject:
2249             rSh.LaunchOLEObj();
2250             eKeyState = KS_Ende;
2251         break;
2252         case KS_GoIntoFly :
2253             rSh.UnSelectFrm();
2254             rSh.LeaveSelFrmMode();
2255             rView.AttrChangedNotify(&rSh);
2256             rSh.MoveSection( fnSectionCurr, fnSectionEnd );
2257             eKeyState = KS_Ende;
2258         break;
2259         case KS_GoIntoDrawing :
2260         {
2261             SdrObject* pObj = rSh.GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
2262             if(pObj)
2263             {
2264                 EnterDrawTextMode(pObj->GetLogicRect().Center());
2265                 if ( rView.GetCurShell()->ISA(SwDrawTextShell) )
2266                     ((SwDrawTextShell*)rView.GetCurShell())->Init();
2267             }
2268             eKeyState = KS_Ende;
2269         }
2270         break;
2271         case KS_EnterDrawHandleMode:
2272         {
2273             const SdrHdlList& rHdlList = rSh.GetDrawView()->GetHdlList();
2274             sal_Bool bForward(!aKeyEvent.GetKeyCode().IsShift());
2275 
2276             ((SdrHdlList&)rHdlList).TravelFocusHdl(bForward);
2277             eKeyState = KS_Ende;
2278         }
2279         break;
2280         case KS_InsTab:
2281             if( rView.ISA( SwWebView ))     //Kein Tabulator fuer Web!
2282             {
2283                 Window::KeyInput( aKeyEvent );
2284                 eKeyState = KS_Ende;
2285                 break;
2286             }
2287             aCh = '\t';
2288             // kein break!
2289         case KS_InsChar:
2290             if (rSh.GetChar(sal_False)==CH_TXT_ATR_FORMELEMENT)
2291             {
2292                 ::sw::mark::ICheckboxFieldmark* pFieldmark =
2293                     dynamic_cast< ::sw::mark::ICheckboxFieldmark* >
2294                         (rSh.GetCurrentFieldmark());
2295                 OSL_ENSURE(pFieldmark,
2296                     "Where is my FieldMark??");
2297                 if(pFieldmark)
2298                 {
2299                     pFieldmark->SetChecked(!pFieldmark->IsChecked());
2300                     OSL_ENSURE(pFieldmark->IsExpanded(),
2301                         "where is the otherpos?");
2302                     if (pFieldmark->IsExpanded())
2303                     {
2304                         rSh.CalcLayout();
2305                     }
2306                 }
2307                 eKeyState = KS_Ende;
2308             }
2309             else if ( !rSh.HasReadonlySel()
2310                       || rSh.CrsrInsideInputFld() )
2311             {
2312                 const sal_Bool bIsNormalChar =
2313                     GetAppCharClass().isLetterNumeric( String( aCh ), 0 );
2314                 if( bChkInsBlank && bIsNormalChar &&
2315                     (aInBuffer.Len() || !rSh.IsSttPara() || !rSh.IsEndPara() ))
2316                 {
2317                     // vor dem Zeichen noch ein Blank einfuegen. Dieses
2318                     // kommt zwischen den Expandierten Text und dem neuen
2319                     // "nicht Worttrenner".
2320                     aInBuffer.Expand( aInBuffer.Len() + 1, ' ' );
2321                 }
2322 
2323                 const sal_Bool bIsAutoCorrectChar =  SvxAutoCorrect::IsAutoCorrectChar( aCh );
2324                 const sal_Bool bRunNext = pACorr != NULL && pACorr->HasRunNext();
2325                 if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
2326                         pACfg->IsAutoFmtByInput() &&
2327                     (( pACorr->IsAutoCorrFlag( ChgWeightUnderl ) &&
2328                         ( '*' == aCh || '_' == aCh ) ) ||
2329                      ( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
2330                      ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
2331                 {
2332                     FlushInBuffer();
2333                     rSh.AutoCorrect( *pACorr, aCh );
2334                     if( '\"' != aCh && '\'' != aCh )        // nur bei "*_" rufen!
2335                         rSh.UpdateAttr();
2336                 }
2337                 else if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
2338                         pACfg->IsAutoFmtByInput() &&
2339                     pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
2340                                             ChgOrdinalNumber | AddNonBrkSpace |
2341                                             ChgToEnEmDash | SetINetAttr |
2342                                             Autocorrect ) &&
2343                     '\"' != aCh && '\'' != aCh && '*' != aCh && '_' != aCh
2344                     )
2345                 {
2346                     FlushInBuffer();
2347                     rSh.AutoCorrect( *pACorr, aCh );
2348                 }
2349                 else
2350                 {
2351                     aInBuffer.Expand( aInBuffer.Len() + aKeyEvent.GetRepeat() + 1,aCh );
2352                     bFlushCharBuffer = Application::AnyInput( INPUT_KEYBOARD );
2353                     bFlushBuffer = !bFlushCharBuffer;
2354                     if( bFlushCharBuffer )
2355                         aKeyInputFlushTimer.Start();
2356                 }
2357                 eKeyState = KS_Ende;
2358             }
2359             else
2360             {
2361                 InfoBox( this, SW_RES( MSG_READONLY_CONTENT )).Execute();
2362                 eKeyState = KS_Ende;
2363             }
2364         break;
2365 
2366         case KS_CheckAutoCorrect:
2367         {
2368             if( pACorr && pACfg->IsAutoFmtByInput() &&
2369                 pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
2370                                         ChgOrdinalNumber |
2371                                         ChgToEnEmDash | SetINetAttr |
2372                                         Autocorrect ) &&
2373                 !rSh.HasReadonlySel() )
2374             {
2375                 FlushInBuffer();
2376                 rSh.AutoCorrect( *pACorr, static_cast< sal_Unicode >('\0') );
2377             }
2378             eKeyState = eNextKeyState;
2379         }
2380         break;
2381 
2382         default:
2383         {
2384             sal_uInt16 nSlotId = 0;
2385             FlushInBuffer();
2386             switch( eKeyState )
2387             {
2388             case KS_SpecialInsert:
2389                 rSh.DoSpecialInsert();
2390                 break;
2391 
2392             case KS_NoNum:
2393                 rSh.NoNum();
2394                 break;
2395 
2396             case KS_NumOff:
2397                 // Shellwechsel - also vorher aufzeichnen
2398                 rSh.DelNumRules();
2399                 eKeyState = eNextKeyState;
2400                 break;
2401             case KS_OutlineLvOff: // delete autofmt outlinelevel later
2402                 break;
2403 
2404             case KS_NumDown:
2405                 rSh.NumUpDown( sal_True );
2406                 nKS_NUMDOWN_Count = 2; // #i23725#
2407                 break;
2408             case KS_NumUp:
2409                 rSh.NumUpDown( sal_False );
2410                 break;
2411 
2412             case KS_NumIndentInc:
2413                 rSh.ChangeIndentOfAllListLevels(360);
2414                 nKS_NUMINDENTINC_Count = 2;
2415                 break;
2416 
2417             case KS_GotoNextFieldMark:
2418                 {
2419                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkAfter();
2420                     if(pFieldmark) rSh.GotoFieldmark(pFieldmark);
2421                 }
2422                 break;
2423 
2424             case KS_GotoPrevFieldMark:
2425                 {
2426                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkBefore();
2427                     if(pFieldmark) rSh.GotoFieldmark(pFieldmark);
2428                 }
2429                 break;
2430 
2431             case KS_NumIndentDec:
2432                 rSh.ChangeIndentOfAllListLevels(-360);
2433                 // <--
2434                 break;
2435 
2436             case KS_OutlineDown:
2437                 rSh.OutlineUpDown( 1 );
2438                 break;
2439             case KS_OutlineUp:
2440                 rSh.OutlineUpDown( -1 );
2441                 break;
2442 
2443             case KS_NextCell:
2444                 //In Tabelle immer 'flushen'
2445                 rSh.GoNextCell();
2446                 nSlotId = FN_GOTO_NEXT_CELL;
2447                 break;
2448             case KS_PrevCell:
2449                 rSh.GoPrevCell();
2450                 nSlotId = FN_GOTO_PREV_CELL;
2451                 break;
2452             case KS_AutoFmtByInput:
2453                 rSh.SplitNode( sal_True );
2454                 break;
2455 
2456             case KS_NextObject:
2457             case KS_PrevObject:
2458                 if(rSh.GotoObj( KS_NextObject == eKeyState, GOTOOBJ_GOTO_ANY))
2459                 {
2460                     if( rSh.IsFrmSelected() &&
2461                         rView.GetDrawFuncPtr() )
2462                     {
2463                         rView.GetDrawFuncPtr()->Deactivate();
2464                         rView.SetDrawFuncPtr(NULL);
2465                         rView.LeaveDrawCreate();
2466                         rView.AttrChangedNotify( &rSh );
2467                     }
2468                     rSh.HideCrsr();
2469                     rSh.EnterSelFrmMode();
2470                 }
2471             break;
2472             case KS_GlossaryExpand:
2473             {
2474                 // ersetze das Wort oder Kuerzel durch den den Textbaustein
2475                 rSh.StartUndo( UNDO_START );
2476 
2477                 String sFnd( *aTmpQHD.aArr[ aTmpQHD.nCurArrPos ] );
2478                 if( aTmpQHD.bIsAutoText )
2479                 {
2480                     SwGlossaryList* pList = ::GetGlossaryList();
2481                     String sShrtNm;
2482                     String sGroup;
2483                     if(pList->GetShortName( sFnd, sShrtNm, sGroup))
2484                     {
2485                         rSh.SttSelect();
2486                         rSh.ExtendSelection( sal_False, aTmpQHD.nLen );
2487                         SwGlossaryHdl* pGlosHdl = GetView().GetGlosHdl();
2488                         pGlosHdl->SetCurGroup(sGroup, sal_True);
2489                         pGlosHdl->InsertGlossary( sShrtNm);
2490                         pQuickHlpData->bChkInsBlank = sal_True;
2491                     }
2492                 }
2493                 else
2494                 {
2495                     rSh.Insert( sFnd.Erase( 0, aTmpQHD.nLen ));
2496                     pQuickHlpData->bChkInsBlank = !pACorr ||
2497                             pACorr->GetSwFlags().bAutoCmpltAppendBlanc;
2498                 }
2499                 rSh.EndUndo( UNDO_END );
2500             }
2501             break;
2502 
2503             case KS_NextPrevGlossary:
2504                 pQuickHlpData->Move( aTmpQHD );
2505                 pQuickHlpData->Start( rSh, USHRT_MAX );
2506                 break;
2507 
2508             case KS_EditFormula:
2509             {
2510                 const sal_uInt16 nId = SwInputChild::GetChildWindowId();
2511 
2512                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
2513                 pVFrame->ToggleChildWindow( nId );
2514                 SwInputChild* pChildWin = (SwInputChild*)pVFrame->
2515                                                     GetChildWindow( nId );
2516                 if( pChildWin )
2517                     pChildWin->SetFormula( sFmlEntry );
2518             }
2519             break;
2520 
2521             case KS_ColLeftBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );   break;
2522             case KS_ColRightBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );  break;
2523             case KS_ColLeftSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTblHMove() );   break;
2524             case KS_ColRightSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTblHMove() );  break;
2525             case KS_ColBottomBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_ROW_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() ); break;
2526             case KS_ColBottomSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTblVMove() ); break;
2527             case KS_CellLeftBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );  break;
2528             case KS_CellRightBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() ); break;
2529             case KS_CellLeftSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTblHMove() );  break;
2530             case KS_CellRightSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTblHMove() ); break;
2531             case KS_CellTopBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() );   break;
2532             case KS_CellBottomBig:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() );    break;
2533             case KS_CellTopSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTblVMove() );   break;
2534             case KS_CellBottomSmall:    rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTblVMove() );    break;
2535 
2536 //---------------
2537             case KS_InsDel_ColLeftBig:          rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() ); break;
2538             case KS_InsDel_ColRightBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );    break;
2539             case KS_InsDel_ColLeftSmall:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTblHInsert() ); break;
2540             case KS_InsDel_ColRightSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTblHInsert() );    break;
2541             case KS_InsDel_ColTopBig:           rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );  break;
2542             case KS_InsDel_ColBottomBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );   break;
2543             case KS_InsDel_ColTopSmall:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_TOP, pModOpt->GetTblVInsert() );  break;
2544             case KS_InsDel_ColBottomSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTblVInsert() );   break;
2545             case KS_InsDel_CellLeftBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );    break;
2546             case KS_InsDel_CellRightBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );   break;
2547             case KS_InsDel_CellLeftSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTblHInsert() );    break;
2548             case KS_InsDel_CellRightSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTblHInsert() );   break;
2549             case KS_InsDel_CellTopBig:          rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() ); break;
2550             case KS_InsDel_CellBottomBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );  break;
2551             case KS_InsDel_CellTopSmall:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTblVInsert() ); break;
2552             case KS_InsDel_CellBottomSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTblVInsert() );  break;
2553 //---------------
2554             case KS_TblColCellInsDel:
2555                 rSh.SetColRowWidthHeight( eTblChgMode, nTblChgSize );
2556                 break;
2557             case KS_Fly_Change:
2558             {
2559                 SdrView *pSdrView = rSh.GetDrawView();
2560                 const SdrHdlList& rHdlList = pSdrView->GetHdlList();
2561                 if(rHdlList.GetFocusHdl())
2562                     ChangeDrawing( nDir );
2563                 else
2564                     ChangeFly( nDir, rView.ISA( SwWebView ) );
2565             }
2566             break;
2567             case KS_Draw_Change :
2568                 ChangeDrawing( nDir );
2569                 break;
2570             default:; //prevent warning
2571             }
2572             if( nSlotId && rView.GetViewFrame()->GetBindings().GetRecorder().is() )
2573             {
2574                 SfxRequest aReq(rView.GetViewFrame(), nSlotId );
2575                 aReq.Done();
2576             }
2577             eKeyState = KS_Ende;
2578         }
2579         }
2580     }
2581 
2582     if( bStopKeyInputTimer )
2583     {
2584         aKeyInputTimer.Stop();
2585         bTblInsDelMode = sal_False;
2586     }
2587 
2588     // falls die gepufferten Zeichen eingefuegt werden sollen
2589     if( bFlushBuffer && aInBuffer.Len() )
2590     {
2591         //OS 16.02.96 11.04: bFlushCharBuffer wurde hier nicht zurueckgesetzt
2592         // warum nicht?
2593         sal_Bool bSave = bFlushCharBuffer;
2594         FlushInBuffer();
2595         bFlushCharBuffer = bSave;
2596 
2597         // evt. Tip-Hilfe anzeigen
2598         String sWord;
2599         if( bNormalChar && pACfg && pACorr &&
2600             ( pACfg->IsAutoTextTip() ||
2601               pACorr->GetSwFlags().bAutoCompleteWords ) &&
2602             rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
2603         {
2604             ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr);
2605         }
2606     }
2607 }
2608 
2609 /*--------------------------------------------------------------------
2610      Beschreibung:  MouseEvents
2611  --------------------------------------------------------------------*/
2612 
2613 
RstMBDownFlags()2614 void SwEditWin::RstMBDownFlags()
2615 {
2616     //Nicht auf allen Systemen kommt vor dem modalen
2617     //Dialog noch ein MouseButton Up (wie unter WINDOWS).
2618     //Daher hier die Stati zuruecksetzen und die Maus
2619     //fuer den Dialog freigeben.
2620     bMBPressed = bNoInterrupt = sal_False;
2621     EnterArea();
2622     ReleaseMouse();
2623 }
2624 
2625 
2626 
MouseButtonDown(const MouseEvent & _rMEvt)2627 void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
2628 {
2629     SwWrtShell &rSh = rView.GetWrtShell();
2630 
2631     // We have to check if a context menu is shown and we have an UI
2632     // active inplace client. In that case we have to ignore the mouse
2633     // button down event. Otherwise we would crash (context menu has been
2634     // opened by inplace client and we would deactivate the inplace client,
2635     // the contex menu is closed by VCL asynchronously which in the end
2636     // would work on deleted objects or the context menu has no parent anymore)
2637     // See #126086# and #128122#
2638     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
2639     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
2640 
2641     if ( bIsOleActive && PopupMenu::IsInExecute() )
2642         return;
2643 
2644     MouseEvent rMEvt(_rMEvt);
2645 
2646     if (rView.GetPostItMgr()->IsHit(rMEvt.GetPosPixel()))
2647         return;
2648 
2649     rView.GetPostItMgr()->SetActiveSidebarWin(0);
2650 
2651     GrabFocus();
2652 
2653     //ignore key modifiers for format paintbrush
2654     {
2655         sal_Bool bExecFormatPaintbrush = pApplyTempl && pApplyTempl->pFormatClipboard
2656                                 &&  pApplyTempl->pFormatClipboard->HasContent();
2657         if( bExecFormatPaintbrush )
2658             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
2659                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
2660     }
2661 
2662     bWasShdwCrsr = 0 != pShadCrsr;
2663     if( bWasShdwCrsr )
2664         delete pShadCrsr, pShadCrsr = 0;
2665 
2666     const Point aDocPos( PixelToLogic( rMEvt.GetPosPixel() ) );
2667 
2668     if ( IsChainMode() )
2669     {
2670         SetChainMode( sal_False );
2671         SwRect aDummy;
2672         SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)rSh.GetFlyFrmFmt();
2673         if ( !rSh.Chainable( aDummy, *pFmt, aDocPos ) )
2674             rSh.Chain( *pFmt, aDocPos );
2675         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2676         return;
2677     }
2678 
2679     //Nach GrabFocus sollte eine Shell gepusht sein. Das muss eigentlich
2680     //klappen aber in der Praxis ...
2681     lcl_SelectShellForDrop( rView );
2682 
2683     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly();
2684     sal_Bool bCallBase = sal_True;
2685 
2686     if( pQuickHlpData->bClear )
2687         pQuickHlpData->Stop( rSh );
2688     pQuickHlpData->bChkInsBlank = sal_False;
2689 
2690     if( rSh.FinishOLEObj() )
2691         return; //InPlace beenden und der Klick zaehlt nicht mehr
2692 
2693     SET_CURR_SHELL( &rSh );
2694 
2695     SdrView *pSdrView = rSh.GetDrawView();
2696     if ( pSdrView )
2697     {
2698         if (pSdrView->MouseButtonDown( rMEvt, this ) )
2699         {
2700             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
2701             return; // Event von der SdrView ausgewertet
2702         }
2703     }
2704 
2705 
2706     bIsInMove = sal_False;
2707     aStartPos = rMEvt.GetPosPixel();
2708     aRszMvHdlPt.X() = 0, aRszMvHdlPt.Y() = 0;
2709 
2710     sal_uInt8 nMouseTabCol = 0;
2711     const sal_Bool bTmp = !rSh.IsDrawCreate() && !pApplyTempl && !rSh.IsInSelect() &&
2712          rMEvt.GetClicks() == 1 && MOUSE_LEFT == rMEvt.GetButtons();
2713     if (  bTmp &&
2714          0 != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPos ) ) &&
2715          !rSh.IsObjSelectable( aDocPos ) )
2716     {
2717         // Enhanced table selection
2718         if ( SW_TABSEL_HORI <= nMouseTabCol && SW_TABCOLSEL_VERT >= nMouseTabCol )
2719         {
2720             rSh.EnterStdMode();
2721             rSh.SelectTableRowCol( aDocPos );
2722             if( SW_TABSEL_HORI  != nMouseTabCol && SW_TABSEL_HORI_RTL  != nMouseTabCol)
2723             {
2724                 pRowColumnSelectionStart = new Point( aDocPos );
2725                 bIsRowDrag = SW_TABROWSEL_HORI == nMouseTabCol||
2726                             SW_TABROWSEL_HORI_RTL == nMouseTabCol ||
2727                             SW_TABCOLSEL_VERT == nMouseTabCol;
2728                 bMBPressed = sal_True;
2729                 CaptureMouse();
2730             }
2731             return;
2732         }
2733 
2734         if ( !rSh.IsTableMode() )
2735         {
2736             //Zuppeln von Tabellenspalten aus dem Dokument heraus.
2737             if(SW_TABCOL_VERT == nMouseTabCol || SW_TABCOL_HORI == nMouseTabCol)
2738                 rView.SetTabColFromDoc( sal_True );
2739             else
2740                 rView.SetTabRowFromDoc( sal_True );
2741 
2742             rView.SetTabColFromDocPos( aDocPos );
2743             rView.InvalidateRulerPos();
2744             SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
2745             rBind.Update();
2746             if ( RulerColumnDrag( rMEvt,
2747                     (SW_TABCOL_VERT == nMouseTabCol || SW_TABROW_HORI == nMouseTabCol)) )
2748             {
2749                 rView.SetTabColFromDoc( sal_False );
2750                 rView.SetTabRowFromDoc( sal_False );
2751                 rView.InvalidateRulerPos();
2752                 rBind.Update();
2753                 bCallBase = sal_False;
2754             }
2755             else
2756             {
2757                 return;
2758             }
2759         }
2760     }
2761     else if (bTmp &&
2762              rSh.IsNumLabel(aDocPos))
2763     {
2764         SwTxtNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPos );
2765         rView.SetNumRuleNodeFromDoc( pNodeAtPos );
2766         rView.InvalidateRulerPos();
2767         SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
2768         rBind.Update();
2769 
2770         if ( RulerMarginDrag( rMEvt,
2771                         rSh.IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPos ) ) )
2772         {
2773             rView.SetNumRuleNodeFromDoc( NULL );
2774             rView.InvalidateRulerPos();
2775             rBind.Update();
2776             bCallBase = sal_False;
2777         }
2778         else
2779         {
2780             // Make sure the pointer is set to 0, otherwise it may point to
2781             // nowhere after deleting the corresponding text node.
2782             rView.SetNumRuleNodeFromDoc( NULL );
2783             return;
2784         }
2785     }
2786 
2787     if ( rSh.IsInSelect() )
2788         rSh.EndSelect();
2789 
2790     //Abfrage auf LEFT, da sonst auch bei einem Click mit der rechten Taste
2791     //beispielsweise die Selektion aufgehoben wird.
2792     if ( MOUSE_LEFT == rMEvt.GetButtons() )
2793     {
2794         sal_Bool bOnlyText = sal_False;
2795         bMBPressed = bNoInterrupt = sal_True;
2796         nKS_NUMDOWN_Count = 0; // #i23725#
2797 
2798         CaptureMouse();
2799 
2800         //ggf. Cursorpositionen zuruecksetzen
2801         rSh.ResetCursorStack();
2802 
2803         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
2804         {
2805             case MOUSE_LEFT:
2806             case MOUSE_LEFT + KEY_SHIFT:
2807             case MOUSE_LEFT + KEY_MOD2:
2808                 if( rSh.IsObjSelected() )
2809                 {
2810                     SdrHdl* pHdl;
2811                     if( !bIsDocReadOnly &&
2812                         !pAnchorMarker &&
2813                         0 != ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
2814                             ( pHdl->GetKind() == HDL_ANCHOR ||
2815                               pHdl->GetKind() == HDL_ANCHOR_TR ) )
2816                     {
2817                         // Set selected during drag
2818                         pHdl->SetSelected(true);
2819                         pAnchorMarker = new SwAnchorMarker( pHdl );
2820                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2821                         return;
2822                     }
2823                 }
2824                 if ( EnterDrawMode( rMEvt, aDocPos ) )
2825                 {
2826                     bNoInterrupt = sal_False;
2827                     return;
2828                 }
2829                 else  if ( rView.GetDrawFuncPtr() && bInsFrm )
2830                 {
2831                     StopInsFrm();
2832                     rSh.Edit();
2833                 }
2834 
2835                 // Ohne SHIFT, da sonst Toggle bei Selektion nicht funktioniert
2836                 if (rMEvt.GetClicks() == 1)
2837                 {
2838                     if ( rSh.IsSelFrmMode())
2839                     {
2840                         SdrHdl* pHdl = rSh.GetDrawView()->PickHandle(aDocPos);
2841                         sal_Bool bHitHandle = pHdl && pHdl->GetKind() != HDL_ANCHOR &&
2842                                                   pHdl->GetKind() != HDL_ANCHOR_TR;
2843 
2844                         if ((rSh.IsInsideSelectedObj(aDocPos) || bHitHandle) &&
2845                             !(rMEvt.GetModifier() == KEY_SHIFT && !bHitHandle))
2846                         {
2847                             rSh.EnterSelFrmMode( &aDocPos );
2848                             if ( !pApplyTempl )
2849                             {
2850                                 //nur, wenn keine Position zum Sizen getroffen ist.
2851                                 if (!bHitHandle)
2852                                 {
2853                                     StartDDTimer();
2854                                     SwEditWin::nDDStartPosY = aDocPos.Y();
2855                                     SwEditWin::nDDStartPosX = aDocPos.X();
2856                                 }
2857                                 bFrmDrag = sal_True;
2858                             }
2859                             bNoInterrupt = sal_False;
2860                             return;
2861                         }
2862                     }
2863                 }
2864         }
2865 
2866         sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
2867         if ( !bExecHyperlinks )
2868         {
2869             SvtSecurityOptions aSecOpts;
2870             const sal_Bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
2871             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
2872                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
2873                 bExecHyperlinks = sal_True;
2874         }
2875 
2876         // Enhanced selection
2877         sal_uInt8 nNumberOfClicks = static_cast< sal_uInt8 >(rMEvt.GetClicks() % 4);
2878         if ( 0 == nNumberOfClicks && 0 < rMEvt.GetClicks() )
2879             nNumberOfClicks = 4;
2880 
2881         sal_Bool bExecDrawTextLink = sal_False;
2882 
2883         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
2884         {
2885             case MOUSE_LEFT:
2886             case MOUSE_LEFT + KEY_MOD1:
2887             case MOUSE_LEFT + KEY_MOD2:
2888                 switch ( nNumberOfClicks )
2889                 {
2890                     case 1:
2891                     {
2892                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2893                         SwEditWin::nDDStartPosY = aDocPos.Y();
2894                         SwEditWin::nDDStartPosX = aDocPos.X();
2895 
2896                         // URL in DrawText-Objekt getroffen?
2897                         if (bExecHyperlinks && pSdrView)
2898                         {
2899                             SdrViewEvent aVEvt;
2900                             pSdrView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
2901 
2902                             if (aVEvt.eEvent == SDREVENT_EXECUTEURL)
2903                                 bExecDrawTextLink = sal_True;
2904                         }
2905 
2906                         //Rahmen nur zu selektieren versuchen, wenn
2907                         //der Pointer bereits entsprechend geschaltet wurde
2908                         if ( aActHitType != SDRHIT_NONE && !rSh.IsSelFrmMode() &&
2909                             !GetView().GetViewFrame()->GetDispatcher()->IsLocked() &&
2910                             !bExecDrawTextLink)
2911                         {
2912                             // Test if there is a draw object at that position and if it should be selected.
2913                             sal_Bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
2914 
2915                             if(bShould)
2916                             {
2917                                 rView.NoRotate();
2918                                 rSh.HideCrsr();
2919 
2920                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
2921                                 rSh.LockView( sal_True );
2922                                 sal_Bool bSelObj = rSh.SelectObj( aDocPos,
2923                                                rMEvt.IsMod1() ? SW_ENTER_GROUP : 0);
2924                                 if( bUnLockView )
2925                                     rSh.LockView( sal_False );
2926 
2927                                 if( bSelObj )
2928                                 {
2929                                     // falls im Macro der Rahmen deselektiert
2930                                     // wurde, muss nur noch der Cursor
2931                                     // wieder angezeigt werden.
2932                                     if( FRMTYPE_NONE == rSh.GetSelFrmType() )
2933                                         rSh.ShowCrsr();
2934                                     else
2935                                     {
2936                                         if (rSh.IsFrmSelected() && rView.GetDrawFuncPtr())
2937                                         {
2938                                             rView.GetDrawFuncPtr()->Deactivate();
2939                                             rView.SetDrawFuncPtr(NULL);
2940                                             rView.LeaveDrawCreate();
2941                                             rView.AttrChangedNotify( &rSh );
2942                                         }
2943 
2944                                         rSh.EnterSelFrmMode( &aDocPos );
2945                                         bFrmDrag = sal_True;
2946                                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2947                                     }
2948                                     return;
2949                                 }
2950                                 else
2951                                     bOnlyText = static_cast< sal_Bool >(rSh.IsObjSelectable( aDocPos ));
2952 
2953                                 if (!rView.GetDrawFuncPtr())
2954                                     rSh.ShowCrsr();
2955                             }
2956                             else
2957                                 bOnlyText = KEY_MOD1 != rMEvt.GetModifier();
2958                         }
2959                         else if ( rSh.IsSelFrmMode() &&
2960                                   (aActHitType == SDRHIT_NONE ||
2961                                    !rSh.IsInsideSelectedObj( aDocPos )))
2962                         {
2963                             rView.NoRotate();
2964                             SdrHdl *pHdl;
2965                             if( !bIsDocReadOnly && !pAnchorMarker && 0 !=
2966                                 ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
2967                                     ( pHdl->GetKind() == HDL_ANCHOR ||
2968                                       pHdl->GetKind() == HDL_ANCHOR_TR ) )
2969                             {
2970                                 pAnchorMarker = new SwAnchorMarker( pHdl );
2971                                 UpdatePointer( aDocPos, rMEvt.GetModifier() );
2972                                 return;
2973                             }
2974                             else
2975                             {
2976                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
2977                                 rSh.LockView( sal_True );
2978                                 sal_uInt8 nFlag = rMEvt.IsShift() ? SW_ADD_SELECT :0;
2979                                 if( rMEvt.IsMod1() )
2980                                     nFlag = nFlag | SW_ENTER_GROUP;
2981 
2982                                 if ( rSh.IsSelFrmMode() )
2983                                 {
2984                                     rSh.UnSelectFrm();
2985                                     rSh.LeaveSelFrmMode();
2986                                     rView.AttrChangedNotify(&rSh);
2987                                 }
2988 
2989                                 sal_Bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
2990                                 if( bUnLockView )
2991                                     rSh.LockView( sal_False );
2992 
2993                                 if( !bSelObj )
2994                                 {
2995                                     // Cursor hier umsetzen, damit er nicht zuerst
2996                                     // im Rahmen gezeichnet wird; ShowCrsr() geschieht
2997                                     // in LeaveSelFrmMode()
2998                                     bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
2999                                     rSh.LeaveSelFrmMode();
3000                                     rView.AttrChangedNotify( &rSh );
3001                                     bCallBase = sal_False;
3002                                 }
3003                                 else
3004                                 {
3005                                     rSh.HideCrsr();
3006                                     rSh.EnterSelFrmMode( &aDocPos );
3007                                     rSh.SelFlyGrabCrsr();
3008                                     rSh.MakeSelVisible();
3009                                     bFrmDrag = sal_True;
3010                                     if( rSh.IsFrmSelected() &&
3011                                         rView.GetDrawFuncPtr() )
3012                                     {
3013                                         rView.GetDrawFuncPtr()->Deactivate();
3014                                         rView.SetDrawFuncPtr(NULL);
3015                                         rView.LeaveDrawCreate();
3016                                         rView.AttrChangedNotify( &rSh );
3017                                     }
3018                                     UpdatePointer( aDocPos, rMEvt.GetModifier() );
3019                                     return;
3020                                 }
3021                             }
3022                         }
3023 
3024                         break;
3025                     }
3026                     case 2:
3027                     {
3028                         bFrmDrag = sal_False;
3029                         if ( !bIsDocReadOnly && rSh.IsInsideSelectedObj(aDocPos) &&
3030                              0 == rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) )
3031 
3032 /* SJ: 01.03.2005: this is no good, on the one hand GetSelectionType is used as flag field (take a look into the GetSelectionType method)
3033    on the other hand the return value is used in a switch without proper masking (very nice), this must lead to trouble
3034 */
3035                         switch ( rSh.GetSelectionType() &~ ( nsSelectionType::SEL_FONTWORK | nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE ) )
3036                         {
3037                             case nsSelectionType::SEL_GRF:
3038                                 RstMBDownFlags();
3039                                 GetView().GetViewFrame()->GetBindings().Execute(
3040                                     FN_FORMAT_GRAFIC_DLG, 0, 0,
3041                                     SFX_CALLMODE_RECORD|SFX_CALLMODE_SLOT);
3042                                 return;
3043 
3044                                 // Doppelklick auf OLE-Objekt --> OLE-InPlace
3045                             case nsSelectionType::SEL_OLE:
3046                                 if (!rSh.IsSelObjProtected(FLYPROTECT_CONTENT))
3047                                 {
3048                                     RstMBDownFlags();
3049                                     rSh.LaunchOLEObj();
3050                                 }
3051                                 return;
3052 
3053                             case nsSelectionType::SEL_FRM:
3054                                 RstMBDownFlags();
3055                                 GetView().GetViewFrame()->GetBindings().Execute(
3056                                     FN_FORMAT_FRAME_DLG, 0, 0, SFX_CALLMODE_RECORD|SFX_CALLMODE_SLOT);
3057                                 return;
3058 
3059                             case nsSelectionType::SEL_DRW:
3060                                 RstMBDownFlags();
3061                                 EnterDrawTextMode(aDocPos);
3062                                 if ( rView.GetCurShell()->ISA(SwDrawTextShell) )
3063                                     ((SwDrawTextShell*)rView.GetCurShell())->Init();
3064                                 return;
3065                         }
3066 
3067                         //falls die Cursorposition korrigiert wurde oder
3068                         // ein Fly im ReadOnlyModus selektiert ist,
3069                         //keine Wortselektion.
3070                         if ( !bValidCrsrPos ||
3071                             (rSh.IsFrmSelected() && rSh.IsFrmSelected() ))
3072                             return;
3073 
3074                         SwField *pFld;
3075                         sal_Bool bFtn = sal_False;
3076 
3077                         if( !bIsDocReadOnly &&
3078                             ( 0 != ( pFld = rSh.GetCurFld() ) ||
3079                               0 != ( bFtn = rSh.GetCurFtn() )) )
3080                         {
3081                             RstMBDownFlags();
3082                             if( bFtn )
3083                                 GetView().GetViewFrame()->GetBindings().Execute( FN_EDIT_FOOTNOTE );
3084                             else
3085                             {
3086                                 sal_uInt16 nTypeId = pFld->GetTypeId();
3087                                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
3088                                 switch( nTypeId )
3089                                 {
3090                                 case TYP_POSTITFLD:
3091                                 case TYP_SCRIPTFLD:
3092                                 {
3093                                     //falls es ein Readonly-Bereich ist, dann muss der Status
3094                                     //enabled werden
3095                                     sal_uInt16 nSlot = TYP_POSTITFLD == nTypeId ? FN_POSTIT : FN_JAVAEDIT;
3096                                     SfxBoolItem aItem(nSlot, sal_True);
3097                                     pVFrame->GetBindings().SetState(aItem);
3098                                     pVFrame->GetBindings().Execute(nSlot);
3099                                     break;
3100                                 }
3101                                 case TYP_AUTHORITY :
3102                                     pVFrame->GetBindings().Execute(FN_EDIT_AUTH_ENTRY_DLG);
3103                                 break;
3104                                 default:
3105                                     pVFrame->GetBindings().Execute(FN_EDIT_FIELD);
3106                                 }
3107                             }
3108                             return;
3109                         }
3110                         //im Extended Mode hat Doppel- und
3111                         //Dreifachklick keine Auswirkungen.
3112                         if ( rSh.IsExtMode() || rSh.IsBlockMode() )
3113                             return;
3114 
3115                         //Wort selektieren, gfs. Additional Mode
3116                         if ( KEY_MOD1 == rMEvt.GetModifier() && !rSh.IsAddMode() )
3117                         {
3118                             rSh.EnterAddMode();
3119                             rSh.SelWrd( &aDocPos );
3120                             rSh.LeaveAddMode();
3121                         }
3122                         else
3123                             rSh.SelWrd( &aDocPos );
3124                         bHoldSelection = sal_True;
3125                         return;
3126                     }
3127                     case 3:
3128                     case 4:
3129                     {
3130                         bFrmDrag = sal_False;
3131                         //im Extended Mode hat Doppel- und
3132                         //Dreifachklick keine Auswirkungen.
3133                         if ( rSh.IsExtMode() )
3134                             return;
3135 
3136                         //falls die Cursorposition korrigiert wurde oder
3137                         // ein Fly im ReadOnlyModus selektiert ist,
3138                         //keine Wortselektion.
3139                         if ( !bValidCrsrPos || rSh.IsFrmSelected() )
3140                             return;
3141 
3142                         //Zeile selektieren, gfs. Additional Mode
3143                         const bool bMod = KEY_MOD1 == rMEvt.GetModifier() &&
3144                                          !rSh.IsAddMode();
3145 
3146                         if ( bMod )
3147                             rSh.EnterAddMode();
3148 
3149                         // Enhanced selection
3150                         if ( 3 == nNumberOfClicks )
3151                             rSh.SelSentence( &aDocPos );
3152                         else
3153                             rSh.SelPara( &aDocPos );
3154 
3155                         if ( bMod )
3156                             rSh.LeaveAddMode();
3157 
3158                         bHoldSelection = sal_True;
3159                         return;
3160                     }
3161 
3162                     default:
3163                         return;
3164                 }
3165                 /* no break */
3166             case MOUSE_LEFT + KEY_SHIFT:
3167             case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
3168             {
3169                 sal_Bool bLockView = bWasShdwCrsr;
3170 
3171                 switch ( rMEvt.GetModifier() )
3172                 {
3173                     case KEY_MOD1 + KEY_SHIFT:
3174                     {
3175                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3176                         {
3177                             rView.NoRotate();
3178                             rSh.HideCrsr();
3179                             if ( rSh.IsSelFrmMode() )
3180                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP);
3181                             else
3182                             {   if ( rSh.SelectObj( aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP ) )
3183                                 {
3184                                     rSh.EnterSelFrmMode( &aDocPos );
3185                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3186                                     SwEditWin::nDDStartPosX = aDocPos.X();
3187                                     bFrmDrag = sal_True;
3188                                     return;
3189                                 }
3190                             }
3191                         }
3192                         else if( rSh.IsSelFrmMode() &&
3193                                  rSh.GetDrawView()->PickHandle( aDocPos ))
3194                         {
3195                             bFrmDrag = sal_True;
3196                             bNoInterrupt = sal_False;
3197                             return;
3198                         }
3199                     }
3200                     break;
3201                     case KEY_MOD1:
3202                     if ( !bExecDrawTextLink )
3203                     {
3204                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3205                         {
3206                             rView.NoRotate();
3207                             rSh.HideCrsr();
3208                             if ( rSh.IsSelFrmMode() )
3209                                 rSh.SelectObj(aDocPos, SW_ENTER_GROUP);
3210                             else
3211                             {   if ( rSh.SelectObj( aDocPos, SW_ENTER_GROUP ) )
3212                                 {
3213                                     rSh.EnterSelFrmMode( &aDocPos );
3214                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3215                                     SwEditWin::nDDStartPosX = aDocPos.X();
3216                                     bFrmDrag = sal_True;
3217                                     return;
3218                                 }
3219                             }
3220                         }
3221                         else if( rSh.IsSelFrmMode() &&
3222                                  rSh.GetDrawView()->PickHandle( aDocPos ))
3223                         {
3224                             bFrmDrag = sal_True;
3225                             bNoInterrupt = sal_False;
3226                             return;
3227                         }
3228                         else
3229                         {
3230                             if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
3231                             {
3232                                 rSh.PushMode();
3233                                 bModePushed = sal_True;
3234 
3235                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
3236                                 rSh.LockView( sal_True );
3237                                 rSh.EnterAddMode();
3238                                 if( bUnLockView )
3239                                     rSh.LockView( sal_False );
3240                             }
3241                             bCallBase = sal_False;
3242                         }
3243                     }
3244                     break;
3245                     case KEY_MOD2:
3246                     {
3247                         if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
3248                         {
3249                             rSh.PushMode();
3250                             bModePushed = sal_True;
3251                             sal_Bool bUnLockView = !rSh.IsViewLocked();
3252                             rSh.LockView( sal_True );
3253                             rSh.EnterBlockMode();
3254                             if( bUnLockView )
3255                                 rSh.LockView( sal_False );
3256                         }
3257                         bCallBase = sal_False;
3258                     }
3259                     break;
3260                     case KEY_SHIFT:
3261                     {
3262                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3263                         {
3264                             rView.NoRotate();
3265                             rSh.HideCrsr();
3266                             if ( rSh.IsSelFrmMode() )
3267                             {
3268                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT);
3269 
3270                                 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
3271                                 if (rMarkList.GetMark(0) == NULL)
3272                                 {
3273                                     rSh.LeaveSelFrmMode();
3274                                     rView.AttrChangedNotify(&rSh);
3275                                     bFrmDrag = sal_False;
3276                                 }
3277                             }
3278                             else
3279                             {   if ( rSh.SelectObj( aDocPos ) )
3280                                 {
3281                                     rSh.EnterSelFrmMode( &aDocPos );
3282                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3283                                     SwEditWin::nDDStartPosX = aDocPos.X();
3284                                     bFrmDrag = sal_True;
3285                                     return;
3286                                 }
3287                             }
3288                         }
3289                         else
3290                         {
3291                             if ( rSh.IsSelFrmMode() &&
3292                                  rSh.IsInsideSelectedObj( aDocPos ) )
3293                             {
3294                                 rSh.EnterSelFrmMode( &aDocPos );
3295                                 SwEditWin::nDDStartPosY = aDocPos.Y();
3296                                 SwEditWin::nDDStartPosX = aDocPos.X();
3297                                 bFrmDrag = sal_True;
3298                                 return;
3299                             }
3300                             if ( rSh.IsSelFrmMode() )
3301                             {
3302                                 rSh.UnSelectFrm();
3303                                 rSh.LeaveSelFrmMode();
3304                                 rView.AttrChangedNotify(&rSh);
3305                                 bFrmDrag = sal_False;
3306                             }
3307                             if ( !rSh.IsExtMode() )
3308                             {
3309                                 // keine Selection anfangen, wenn in ein URL-
3310                                 // Feld oder eine -Grafik geklickt wird
3311                                 sal_Bool bSttSelect = rSh.HasSelection() ||
3312                                                 Pointer(POINTER_REFHAND) != GetPointer();
3313 
3314                                 if( !bSttSelect )
3315                                 {
3316                                     bSttSelect = sal_True;
3317                                     if( bExecHyperlinks )
3318                                     {
3319                                         SwContentAtPos aCntntAtPos(
3320                                             SwContentAtPos::SW_FTN |
3321                                             SwContentAtPos::SW_INETATTR );
3322 
3323                                         if( rSh.GetContentAtPos( aDocPos, aCntntAtPos ) )
3324                                         {
3325                                             if( !rSh.IsViewLocked() &&
3326                                                 !rSh.IsReadOnlyAvailable() &&
3327                                                 aCntntAtPos.IsInProtectSect() )
3328                                                     bLockView = sal_True;
3329 
3330                                             bSttSelect = sal_False;
3331                                         }
3332                                         else if( rSh.IsURLGrfAtPos( aDocPos ))
3333                                             bSttSelect = sal_False;
3334                                     }
3335                                 }
3336 
3337                                 if( bSttSelect )
3338                                     rSh.SttSelect();
3339                             }
3340                         }
3341                         bCallBase = sal_False;
3342                         break;
3343                     }
3344                     default:
3345                         if( !rSh.IsViewLocked() )
3346                         {
3347                             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_CLICKFIELD |
3348                                                         SwContentAtPos::SW_INETATTR );
3349                             if( rSh.GetContentAtPos( aDocPos, aCntntAtPos, sal_False ) &&
3350                                 !rSh.IsReadOnlyAvailable() &&
3351                                 aCntntAtPos.IsInProtectSect() )
3352                                 bLockView = sal_True;
3353                         }
3354                 }
3355 
3356                 if ( rSh.IsGCAttr() )
3357                 {
3358                     rSh.GCAttr();
3359                     rSh.ClearGCAttr();
3360                 }
3361 
3362                 sal_Bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = sal_False;
3363                 if( !bOverSelect )
3364                     bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
3365 
3366                 if ( !bOverSelect )
3367                 {
3368                     const sal_Bool bTmpNoInterrupt = bNoInterrupt;
3369                     bNoInterrupt = sal_False;
3370 
3371                     if( !rSh.IsViewLocked() && bLockView )
3372                         rSh.LockView( sal_True );
3373                     else
3374                         bLockView = sal_False;
3375 
3376                     int nTmpSetCrsr = 0;
3377 
3378                     {   // nur temp. Move-Kontext aufspannen, da sonst die
3379                         // Abfrage auf die Inhaltsform nicht funktioniert!!!
3380                         MV_KONTEXT( &rSh );
3381                         nTmpSetCrsr = (rSh.*rSh.fnSetCrsr)(&aDocPos,bOnlyText);
3382                         bValidCrsrPos = !(CRSR_POSCHG & nTmpSetCrsr);
3383                         bCallBase = sal_False;
3384                     }
3385 
3386                     //#i42732# - notify the edit window that from now on we do not use the input language
3387                     if ( !(CRSR_POSOLD & nTmpSetCrsr) )
3388                         SetUseInputLanguage( sal_False );
3389 
3390                     if( bLockView )
3391                         rSh.LockView( sal_False );
3392 
3393                     bNoInterrupt = bTmpNoInterrupt;
3394                 }
3395                 if ( !bOverURLGrf && !bOnlyText )
3396                 {
3397                     const int nSelType = rSh.GetSelectionType();
3398                     // Check in general, if an object is selectable at given position.
3399                     // Thus, also text fly frames in background become selectable via Ctrl-Click.
3400                     if ( ( nSelType & nsSelectionType::SEL_OLE )
3401                          || ( nSelType & nsSelectionType::SEL_GRF )
3402                          || rSh.IsObjSelectable( aDocPos ) )
3403                     {
3404                         MV_KONTEXT( &rSh );
3405                         if( !rSh.IsFrmSelected() )
3406                             rSh.GotoNextFly();
3407                         rSh.EnterSelFrmMode();
3408                         bCallBase = sal_False;
3409                     }
3410                 }
3411                 break;
3412             }
3413         }
3414     }
3415     if (bCallBase)
3416         Window::MouseButtonDown(rMEvt);
3417 }
3418 
3419 /*--------------------------------------------------------------------
3420     Beschreibung:   MouseMove
3421  --------------------------------------------------------------------*/
3422 
3423 
MouseMove(const MouseEvent & _rMEvt)3424 void SwEditWin::MouseMove(const MouseEvent& _rMEvt)
3425 {
3426     MouseEvent rMEvt(_rMEvt);
3427 
3428     //ignore key modifiers for format paintbrush
3429     {
3430         sal_Bool bExecFormatPaintbrush = pApplyTempl && pApplyTempl->pFormatClipboard
3431                                 &&  pApplyTempl->pFormatClipboard->HasContent();
3432         if( bExecFormatPaintbrush )
3433             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
3434                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
3435     }
3436 
3437     // solange eine Action laeuft sollte das MouseMove abgeklemmt sein
3438     // Ansonsten gibt es den Bug 40102
3439     SwWrtShell &rSh = rView.GetWrtShell();
3440     if( rSh.ActionPend() )
3441         return ;
3442 
3443     if( pShadCrsr && 0 != (rMEvt.GetModifier() + rMEvt.GetButtons() ) )
3444         delete pShadCrsr, pShadCrsr = 0;
3445 
3446     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly();
3447 
3448     SET_CURR_SHELL( &rSh );
3449 
3450     //aPixPt == Point in Pixel, rel. zu ChildWin
3451     //aDocPt == Point in Twips, Dokumentkoordinaten
3452     const Point aPixPt( rMEvt.GetPosPixel() );
3453     const Point aDocPt( PixelToLogic( aPixPt ) );
3454 
3455     if ( IsChainMode() )
3456     {
3457         UpdatePointer( aDocPt, rMEvt.GetModifier() );
3458         if ( rMEvt.IsLeaveWindow() )
3459             rView.GetViewFrame()->HideStatusText();
3460         return;
3461     }
3462 
3463     SdrView *pSdrView = rSh.GetDrawView();
3464 
3465     const SwCallMouseEvent aLastCallEvent( aSaveCallEvent );
3466     aSaveCallEvent.Clear();
3467 
3468     if ( !bIsDocReadOnly && pSdrView && pSdrView->MouseMove(rMEvt,this) )
3469     {
3470         SetPointer( POINTER_TEXT );
3471         return; // Event von der SdrView ausgewertet
3472     }
3473 
3474     const Point aOldPt( rSh.VisArea().Pos() );
3475     const sal_Bool bInsWin = rSh.VisArea().IsInside( aDocPt );
3476 
3477     if( pShadCrsr && !bInsWin )
3478         delete pShadCrsr, pShadCrsr = 0;
3479 
3480     if( bInsWin && pRowColumnSelectionStart )
3481     {
3482         EnterArea();
3483         Point aPos( aDocPt );
3484         if( rSh.SelectTableRowCol( *pRowColumnSelectionStart, &aPos, bIsRowDrag ))
3485             return;
3486     }
3487 
3488     // Position ist noetig fuer OS/2, da dort nach einem MB-Down
3489     // offensichtlich sofort ein MB-Move gerufen wird.
3490     if( bDDTimerStarted )
3491     {
3492         Point aDD( SwEditWin::nDDStartPosX, SwEditWin::nDDStartPosY );
3493         aDD = LogicToPixel( aDD );
3494         Rectangle aRect( aDD.X()-3, aDD.Y()-3, aDD.X()+3, aDD.Y()+3 );
3495         if ( !aRect.IsInside( aPixPt ) )    // MA 23. May. 95: Tatterschutz.
3496             StopDDTimer( &rSh, aDocPt );
3497     }
3498 
3499     if(rView.GetDrawFuncPtr())
3500     {
3501         if( bInsDraw  )
3502         {
3503             rView.GetDrawFuncPtr()->MouseMove( rMEvt );
3504             if ( !bInsWin )
3505             {
3506                 Point aTmp( aDocPt );
3507                 aTmp += rSh.VisArea().Pos() - aOldPt;
3508                 LeaveArea( aTmp );
3509             }
3510             else
3511                 EnterArea();
3512             return;
3513         }
3514         else if(!rSh.IsFrmSelected() && !rSh.IsObjSelected())
3515         {
3516             SfxBindings &rBnd = rSh.GetView().GetViewFrame()->GetBindings();
3517             Point aRelPos = rSh.GetRelativePagePosition(aDocPt);
3518             if(aRelPos.X() >= 0)
3519             {
3520                 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &GetView()));
3521                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
3522                 const SfxPointItem aTmp1( SID_ATTR_POSITION, aRelPos );
3523                 rBnd.SetState( aTmp1 );
3524             }
3525             else
3526             {
3527                 rBnd.Invalidate(SID_ATTR_POSITION);
3528             }
3529             rBnd.Invalidate(SID_ATTR_SIZE);
3530             const SfxStringItem aCell( SID_TABLE_CELL, aEmptyStr );
3531             rBnd.SetState( aCell );
3532         }
3533     }
3534 
3535     sal_uInt8 nMouseTabCol;
3536     if( !bIsDocReadOnly && bInsWin && !pApplyTempl && !rSh.IsInSelect() )
3537     {
3538         if ( SW_TABCOL_NONE != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPt ) ) &&
3539              !rSh.IsObjSelectable( aDocPt ) )
3540         {
3541             sal_uInt16 nPointer = USHRT_MAX;
3542             bool bChkTblSel = false;
3543 
3544             switch ( nMouseTabCol )
3545             {
3546                 case SW_TABCOL_VERT :
3547                 case SW_TABROW_HORI :
3548                     nPointer = POINTER_VSIZEBAR;
3549                     bChkTblSel = true;
3550                     break;
3551                 case SW_TABROW_VERT :
3552                 case SW_TABCOL_HORI :
3553                     nPointer = POINTER_HSIZEBAR;
3554                     bChkTblSel = true;
3555                     break;
3556                 // Enhanced table selection
3557                 case SW_TABSEL_HORI :
3558                     nPointer = POINTER_TAB_SELECT_SE;
3559                     break;
3560                 case SW_TABSEL_HORI_RTL :
3561                 case SW_TABSEL_VERT :
3562                     nPointer = POINTER_TAB_SELECT_SW;
3563                     break;
3564                 case SW_TABCOLSEL_HORI :
3565                 case SW_TABROWSEL_VERT :
3566                     nPointer = POINTER_TAB_SELECT_S;
3567                     break;
3568                 case SW_TABROWSEL_HORI :
3569                     nPointer = POINTER_TAB_SELECT_E;
3570                     break;
3571                 case SW_TABROWSEL_HORI_RTL :
3572                 case SW_TABCOLSEL_VERT :
3573                     nPointer = POINTER_TAB_SELECT_W;
3574                     break;
3575             }
3576 
3577             if ( USHRT_MAX != nPointer &&
3578                 // Enhanced table selection is explicitely allowed in table mode
3579                 ( !bChkTblSel || !rSh.IsTableMode() ) )
3580             {
3581                 SetPointer( nPointer );
3582             }
3583 
3584             return;
3585         }
3586         else if (rSh.IsNumLabel(aDocPt, RULER_MOUSE_MARGINWIDTH))
3587         {
3588             SwTxtNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPt );
3589             const sal_uInt16 nPointer =
3590                     rSh.IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPt )
3591                     ? POINTER_VSIZEBAR
3592                     : POINTER_HSIZEBAR;
3593             SetPointer( nPointer );
3594 
3595             return;
3596         }
3597     }
3598 
3599     sal_Bool bDelShadCrsr = sal_True;
3600 
3601     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
3602     {
3603         case MOUSE_LEFT:
3604             if( pAnchorMarker )
3605             {
3606                 // Now we need to refresh the SdrHdl pointer of pAnchorMarker.
3607                 // This looks a little bit tricky, but it solves the following
3608                 // problem: the pAnchorMarker contains a pointer to an SdrHdl,
3609                 // if the FindAnchorPos-call cause a scrolling of the visible
3610                 // area, it's possible that the SdrHdl will be destroyed and a
3611                 // new one will initialized at the original position(GetHdlPos).
3612                 // So the pAnchorMarker has to find the right SdrHdl, if it's
3613                 // the old one, it will find it with position aOld, if this one
3614                 // is destroyed, it will find a new one at position GetHdlPos().
3615                 const Point aOld = pAnchorMarker->GetPosForHitTest( *(rSh.GetOut()) );
3616                 Point aNew = rSh.FindAnchorPos( aDocPt );
3617                 SdrHdl* pHdl;
3618                 if( (0!=( pHdl = pSdrView->PickHandle( aOld ) )||
3619                     0 !=(pHdl = pSdrView->PickHandle( pAnchorMarker->GetHdlPos()) ) ) &&
3620                         ( pHdl->GetKind() == HDL_ANCHOR ||
3621                           pHdl->GetKind() == HDL_ANCHOR_TR ) )
3622                 {
3623                     pAnchorMarker->ChgHdl( pHdl );
3624                     if( aNew.X() || aNew.Y() )
3625                     {
3626                         pAnchorMarker->SetPos( aNew );
3627                         pAnchorMarker->SetLastPos( aDocPt );
3628                     }
3629                 }
3630                 else
3631                 {
3632                     delete pAnchorMarker;
3633                     pAnchorMarker = NULL;
3634                 }
3635             }
3636             if ( bInsDraw )
3637             {
3638                 if ( !bMBPressed )
3639                     break;
3640                 if ( bIsInMove || IsMinMove( aStartPos, aPixPt ) )
3641                 {
3642                     if ( !bInsWin )
3643                         LeaveArea( aDocPt );
3644                     else
3645                         EnterArea();
3646                     if ( rView.GetDrawFuncPtr() )
3647                     {
3648                         pSdrView->SetOrtho(sal_False);
3649                         rView.GetDrawFuncPtr()->MouseMove( rMEvt );
3650                     }
3651                     bIsInMove = sal_True;
3652                 }
3653                 return;
3654             }
3655         case MOUSE_LEFT + KEY_SHIFT:
3656         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
3657             if ( !bMBPressed )
3658                 break;
3659         case MOUSE_LEFT + KEY_MOD1:
3660             if ( bFrmDrag && rSh.IsSelFrmMode() )
3661             {
3662                 if( !bMBPressed )
3663                     break;
3664 
3665                 if ( bIsInMove || IsMinMove( aStartPos, aPixPt ) )
3666                 {
3667                     // Event-Verarbeitung fuers Resizen
3668                     if( pSdrView->AreObjectsMarked() )
3669                     {
3670                         const SwFrmFmt* pFlyFmt;
3671                         const SvxMacro* pMacro;
3672 
3673                         const Point aSttPt( PixelToLogic( aStartPos ) );
3674 
3675                         // geht es los?
3676                         if( HDL_USER == eSdrMoveHdl )
3677                         {
3678                             SdrHdl* pHdl = pSdrView->PickHandle( aSttPt );
3679                             eSdrMoveHdl = pHdl ? pHdl->GetKind() : HDL_MOVE;
3680                         }
3681 
3682                         sal_uInt16 nEvent = HDL_MOVE == eSdrMoveHdl
3683                                             ? SW_EVENT_FRM_MOVE
3684                                             : SW_EVENT_FRM_RESIZE;
3685 
3686                         if( 0 != ( pFlyFmt = rSh.GetFlyFrmFmt() ) &&
3687                             0 != ( pMacro = pFlyFmt->GetMacro().GetMacroTable().
3688                             Get( nEvent )) &&
3689                             aRszMvHdlPt != aDocPt )
3690                         {
3691                             aRszMvHdlPt = aDocPt;
3692                             sal_uInt16 nPos = 0;
3693                             String sRet;
3694                             SbxArrayRef xArgs = new SbxArray;
3695                             SbxVariableRef xVar = new SbxVariable;
3696                             xVar->PutString( pFlyFmt->GetName() );
3697                             xArgs->Put( &xVar, ++nPos );
3698 
3699                             if( SW_EVENT_FRM_RESIZE == nEvent )
3700                             {
3701                                 xVar = new SbxVariable;
3702                                 xVar->PutUShort( static_cast< sal_uInt16 >(eSdrMoveHdl) );
3703                                 xArgs->Put( &xVar, ++nPos );
3704                             }
3705 
3706                             xVar = new SbxVariable;
3707                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
3708                             xArgs->Put( &xVar, ++nPos );
3709                             xVar = new SbxVariable;
3710                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
3711                             xArgs->Put( &xVar, ++nPos );
3712 
3713                             ReleaseMouse();
3714 
3715                             rSh.ExecMacro( *pMacro, &sRet, &xArgs );
3716 
3717                             CaptureMouse();
3718 
3719                             if( sRet.Len() && 0 != sRet.ToInt32() )
3720                                 return ;
3721                         }
3722                     }
3723                     // Event-Verarbeitung fuers Resizen
3724 
3725                     if( bIsDocReadOnly )
3726                         break;
3727 
3728                     if ( rMEvt.IsShift() )
3729                     {
3730                         pSdrView->SetOrtho(sal_True);
3731                         pSdrView->SetAngleSnapEnabled(sal_True);
3732                     }
3733                     else
3734                     {
3735                         pSdrView->SetOrtho(sal_False);
3736                         pSdrView->SetAngleSnapEnabled(sal_False);
3737                     }
3738 
3739                     (rSh.*rSh.fnDrag)( &aDocPt, rMEvt.IsShift() );
3740                     bIsInMove = sal_True;
3741                 }
3742                 else if( bIsDocReadOnly )
3743                     break;
3744 
3745                 if ( !bInsWin )
3746                 {
3747                     Point aTmp( aDocPt );
3748                     aTmp += rSh.VisArea().Pos() - aOldPt;
3749                     LeaveArea( aTmp );
3750                 }
3751                 else if(bIsInMove)
3752                     EnterArea();
3753                 return;
3754             }
3755             if ( !rSh.IsSelFrmMode() && !bDDINetAttr &&
3756                 (IsMinMove( aStartPos,aPixPt ) || bIsInMove) &&
3757                 (rSh.IsInSelect() || !rSh.ChgCurrPam( aDocPt )) )
3758             {
3759                 if ( pSdrView )
3760                 {
3761                     if ( rMEvt.IsShift() )
3762                         pSdrView->SetOrtho(sal_True);
3763                     else
3764                         pSdrView->SetOrtho(sal_False);
3765                 }
3766                 if ( !bInsWin )
3767                 {
3768                     Point aTmp( aDocPt );
3769                     aTmp += rSh.VisArea().Pos() - aOldPt;
3770                     LeaveArea( aTmp );
3771                 }
3772                 else
3773                 {
3774                     //JP 24.09.98: Fix fuer die Bugs 55592 / 55931
3775                     //JP 23.04.99: Fix fuer den Bugs 65289
3776                     //JP 06.07.99: Fix fuer den Bugs 67360
3777                     if( !rMEvt.IsSynthetic() &&
3778                             !(( MOUSE_LEFT + KEY_MOD1 ==
3779                             rMEvt.GetModifier() + rMEvt.GetButtons() ) &&
3780                             rSh.Is_FnDragEQBeginDrag() && !rSh.IsAddMode() ))
3781                     {
3782                         (rSh.*rSh.fnDrag)( &aDocPt,sal_False );
3783 
3784                         bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPt,sal_False));
3785                         EnterArea();
3786                     }
3787                 }
3788             }
3789             bDDINetAttr = sal_False;
3790             break;
3791         case 0:
3792         {
3793             if ( pApplyTempl )
3794                         {
3795                 UpdatePointer(aDocPt, 0); // evtl. muss hier ein Rahmen markiert werden
3796                                 break;
3797                         }
3798             //#i6193#, change ui if mouse is over SwPostItField
3799             // TODO: do the same thing for redlines SW_REDLINE
3800             SwRect aFldRect;
3801             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_FIELD);
3802             if( rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_False, &aFldRect ) )
3803             {
3804                 const SwField* pFld = aCntntAtPos.aFnd.pFld;
3805                 if (pFld->Which()== RES_POSTITFLD)
3806                 {
3807                     rView.GetPostItMgr()->SetShadowState(reinterpret_cast<const SwPostItField*>(pFld),false);
3808                 }
3809                 else
3810                     rView.GetPostItMgr()->SetShadowState(0,false);
3811             }
3812             else
3813                 rView.GetPostItMgr()->SetShadowState(0,false);
3814                 // no break;
3815         }
3816         case KEY_SHIFT:
3817         case KEY_MOD2:
3818         case KEY_MOD1:
3819             if ( !bInsDraw )
3820             {
3821                 sal_Bool bTstShdwCrsr = sal_True;
3822 
3823                 UpdatePointer( aDocPt, rMEvt.GetModifier() );
3824 
3825                 const SwFrmFmt* pFmt = 0;
3826                 const SwFmtINetFmt* pINet = 0;
3827                 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
3828                 if( rSh.GetContentAtPos( aDocPt, aCntntAtPos ) )
3829                     pINet = (SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
3830 
3831                 const void* pTmp = pINet;
3832 
3833                 if( pINet ||
3834                     0 != ( pTmp = pFmt = rSh.GetFmtFromAnyObj( aDocPt )))
3835                 {
3836                     bTstShdwCrsr = sal_False;
3837                     if( pTmp == pINet )
3838                         aSaveCallEvent.Set( pINet );
3839                     else
3840                     {
3841                         IMapObject* pIMapObj = pFmt->GetIMapObject( aDocPt );
3842                         if( pIMapObj )
3843                             aSaveCallEvent.Set( pFmt, pIMapObj );
3844                         else
3845                             aSaveCallEvent.Set( EVENT_OBJECT_URLITEM, pFmt );
3846                     }
3847 
3848                     // sollte wir ueber einem InternetFeld mit einem
3849                     // gebundenen Macro stehen?
3850                     if( aSaveCallEvent != aLastCallEvent )
3851                     {
3852                         if( aLastCallEvent.HasEvent() )
3853                             rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
3854                                             aLastCallEvent, sal_True );
3855                         // 0 besagt, das das Object gar keine Tabelle hat
3856                         if( !rSh.CallEvent( SFX_EVENT_MOUSEOVER_OBJECT,
3857                                         aSaveCallEvent ))
3858                             aSaveCallEvent.Clear();
3859                     }
3860                 }
3861                 else if( aLastCallEvent.HasEvent() )
3862                 {
3863                     // Cursor stand auf einem Object
3864                     rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
3865                                     aLastCallEvent, sal_True );
3866                 }
3867 
3868                 if( bTstShdwCrsr && bInsWin && !bIsDocReadOnly &&
3869                     !bInsFrm &&
3870                     !rSh.GetViewOptions()->getBrowseMode() &&
3871                     rSh.GetViewOptions()->IsShadowCursor() &&
3872                     !(rMEvt.GetModifier() + rMEvt.GetButtons()) &&
3873                     !rSh.HasSelection() && !GetConnectMetaFile() )
3874                 {
3875                     SwRect aRect;
3876                     sal_Int16 eOrient;
3877                     SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
3878                     if( rSh.GetShadowCrsrPos( aDocPt, eMode, aRect, eOrient ))
3879                     {
3880                         if( !pShadCrsr )
3881                             pShadCrsr = new SwShadowCursor( *this,
3882                                 SwViewOption::GetDirectCursorColor() );
3883                         if( text::HoriOrientation::RIGHT != eOrient && text::HoriOrientation::CENTER != eOrient )
3884                             eOrient = text::HoriOrientation::LEFT;
3885                         pShadCrsr->SetPos( aRect.Pos(), aRect.Height(), static_cast< sal_uInt16 >(eOrient) );
3886                         bDelShadCrsr = sal_False;
3887                     }
3888                 }
3889             }
3890             break;
3891         case MOUSE_LEFT + KEY_MOD2:
3892             if( rSh.IsBlockMode() && !rMEvt.IsSynthetic() )
3893             {
3894                 (rSh.*rSh.fnDrag)( &aDocPt,sal_False );
3895                 bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPt,sal_False));
3896                 EnterArea();
3897             }
3898         break;
3899     }
3900 
3901     if( bDelShadCrsr && pShadCrsr )
3902         delete pShadCrsr, pShadCrsr = 0;
3903     bWasShdwCrsr = sal_False;
3904 }
3905 
3906 /*--------------------------------------------------------------------
3907     Beschreibung:   Button Up
3908  --------------------------------------------------------------------*/
3909 
3910 
MouseButtonUp(const MouseEvent & rMEvt)3911 void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
3912 {
3913     sal_Bool bCallBase = sal_True;
3914 
3915     sal_Bool bCallShadowCrsr = bWasShdwCrsr;
3916     bWasShdwCrsr = sal_False;
3917     if( pShadCrsr )
3918         delete pShadCrsr, pShadCrsr = 0;
3919 
3920     if( pRowColumnSelectionStart )
3921         DELETEZ( pRowColumnSelectionStart );
3922 
3923     SdrHdlKind eOldSdrMoveHdl = eSdrMoveHdl;
3924     eSdrMoveHdl = HDL_USER;     // fuer die MoveEvents - wieder zuruecksetzen
3925 
3926     // sicherheitshalber zuruecksetzen Bug 27900
3927     rView.SetTabColFromDoc( sal_False );
3928     rView.SetNumRuleNodeFromDoc(NULL);
3929 
3930     SwWrtShell &rSh = rView.GetWrtShell();
3931     SET_CURR_SHELL( &rSh );
3932     SdrView *pSdrView = rSh.GetDrawView();
3933     if ( pSdrView )
3934     {
3935         pSdrView->SetOrtho(sal_False);
3936 
3937         if ( pSdrView->MouseButtonUp( rMEvt,this ) )
3938         {
3939             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
3940             return; // Event von der SdrView ausgewertet
3941         }
3942     }
3943     //MouseButtonUp nur bearbeiten, wenn auch das Down an dieses Fenster ging.
3944     if ( !bMBPressed )
3945     {
3946         return;
3947     }
3948 
3949     Point aDocPt( PixelToLogic( rMEvt.GetPosPixel() ) );
3950 
3951     if ( bDDTimerStarted )
3952     {
3953         StopDDTimer( &rSh, aDocPt );
3954         bMBPressed = sal_False;
3955         if ( rSh.IsSelFrmMode() )
3956         {
3957             (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
3958             bFrmDrag = sal_False;
3959         }
3960         bNoInterrupt = sal_False;
3961         ReleaseMouse();
3962         return;
3963     }
3964 
3965     if( pAnchorMarker )
3966     {
3967         if(pAnchorMarker->GetHdl())
3968         {
3969             // delete selected after drag
3970             pAnchorMarker->GetHdl()->SetSelected(false);
3971         }
3972 
3973         Point aPnt( pAnchorMarker->GetLastPos() );
3974         DELETEZ( pAnchorMarker );
3975         if( aPnt.X() || aPnt.Y() )
3976             rSh.FindAnchorPos( aPnt, sal_True );
3977     }
3978     if ( bInsDraw && rView.GetDrawFuncPtr() )
3979     {
3980         if ( rView.GetDrawFuncPtr()->MouseButtonUp( rMEvt ) )
3981         {
3982             if (rView.GetDrawFuncPtr()) // Koennte im MouseButtonUp zerstoert worden sein
3983             {
3984                 rView.GetDrawFuncPtr()->Deactivate();
3985 
3986                 if (!rView.IsDrawMode())
3987                 {
3988                     rView.SetDrawFuncPtr(NULL);
3989                     SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
3990                     rBind.Invalidate( SID_ATTR_SIZE );
3991                     rBind.Invalidate( SID_TABLE_CELL );
3992                 }
3993             }
3994 
3995             if ( rSh.IsObjSelected() )
3996             {
3997                 rSh.EnterSelFrmMode();
3998                 if (!rView.GetDrawFuncPtr())
3999                     StdDrawMode( OBJ_NONE, sal_True );
4000             }
4001             else if ( rSh.IsFrmSelected() )
4002             {
4003                 rSh.EnterSelFrmMode();
4004                 StopInsFrm();
4005             }
4006             else
4007             {
4008                 const Point aDocPos( PixelToLogic( aStartPos ) );
4009                 bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
4010                 rSh.Edit();
4011             }
4012 
4013             rView.AttrChangedNotify( &rSh );
4014         }
4015         else if (rMEvt.GetButtons() == MOUSE_RIGHT && rSh.IsDrawCreate())
4016             rView.GetDrawFuncPtr()->BreakCreate();   // Zeichnen abbrechen
4017 
4018         bNoInterrupt = sal_False;
4019         ReleaseMouse();
4020         return;
4021     }
4022     sal_Bool bPopMode = sal_False;
4023     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
4024     {
4025         case MOUSE_LEFT:
4026             if ( bInsDraw && rSh.IsDrawCreate() )
4027             {
4028                 if ( rView.GetDrawFuncPtr() && rView.GetDrawFuncPtr()->MouseButtonUp(rMEvt) == sal_True )
4029                 {
4030                     rView.GetDrawFuncPtr()->Deactivate();
4031                     rView.AttrChangedNotify( &rSh );
4032                     if ( rSh.IsObjSelected() )
4033                         rSh.EnterSelFrmMode();
4034                     if ( rView.GetDrawFuncPtr() && bInsFrm )
4035                         StopInsFrm();
4036                 }
4037                 bCallBase = sal_False;
4038                 break;
4039             }
4040         case MOUSE_LEFT + KEY_MOD1:
4041         case MOUSE_LEFT + KEY_MOD2:
4042         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
4043             if ( bFrmDrag && rSh.IsSelFrmMode() )
4044             {
4045                 if ( rMEvt.IsMod1() ) //Kopieren und nicht moven.
4046                 {
4047                     //Drag abbrechen, statt dessen internes Copy verwenden
4048                     Rectangle aRect;
4049                     rSh.GetDrawView()->TakeActionRect( aRect );
4050                     if (!aRect.IsEmpty())
4051                     {
4052                         rSh.BreakDrag();
4053                         Point aEndPt, aSttPt;
4054                         if ( rSh.GetSelFrmType() & FRMTYPE_FLY_ATCNT )
4055                         {
4056                             aEndPt = aRect.TopLeft();
4057                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().TopLeft();
4058                         }
4059                         else
4060                         {
4061                             aEndPt = aRect.Center();
4062                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().Center();
4063                         }
4064                         if ( aSttPt != aEndPt )
4065                         {
4066                             rSh.StartUndo( UNDO_UI_DRAG_AND_COPY );
4067                             rSh.Copy(&rSh, aSttPt, aEndPt, sal_False);
4068                             rSh.EndUndo( UNDO_UI_DRAG_AND_COPY );
4069                         }
4070                     }
4071                     else
4072                         (rSh.*rSh.fnEndDrag)( &aDocPt,sal_False );
4073                 }
4074                 else
4075                 {
4076                     {
4077                         const SwFrmFmt* pFlyFmt;
4078                         const SvxMacro* pMacro;
4079 
4080                         sal_uInt16 nEvent = HDL_MOVE == eOldSdrMoveHdl
4081                                             ? SW_EVENT_FRM_MOVE
4082                                             : SW_EVENT_FRM_RESIZE;
4083 
4084                         if( 0 != ( pFlyFmt = rSh.GetFlyFrmFmt() ) &&
4085                             0 != ( pMacro = pFlyFmt->GetMacro().GetMacroTable().
4086                             Get( nEvent )) )
4087                         {
4088                             const Point aSttPt( PixelToLogic( aStartPos ) );
4089                             aRszMvHdlPt = aDocPt;
4090                             sal_uInt16 nPos = 0;
4091                             SbxArrayRef xArgs = new SbxArray;
4092                             SbxVariableRef xVar = new SbxVariable;
4093                             xVar->PutString( pFlyFmt->GetName() );
4094                             xArgs->Put( &xVar, ++nPos );
4095 
4096                             if( SW_EVENT_FRM_RESIZE == nEvent )
4097                             {
4098                                 xVar = new SbxVariable;
4099                                 xVar->PutUShort( static_cast< sal_uInt16 >(eOldSdrMoveHdl) );
4100                                 xArgs->Put( &xVar, ++nPos );
4101                             }
4102 
4103                             xVar = new SbxVariable;
4104                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
4105                             xArgs->Put( &xVar, ++nPos );
4106                             xVar = new SbxVariable;
4107                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
4108                             xArgs->Put( &xVar, ++nPos );
4109 
4110                             xVar = new SbxVariable;
4111                             xVar->PutUShort( 1 );
4112                             xArgs->Put( &xVar, ++nPos );
4113 
4114                             ReleaseMouse();
4115 
4116                             rSh.ExecMacro( *pMacro, 0, &xArgs );
4117 
4118                             CaptureMouse();
4119                         }
4120                     }
4121                     (rSh.*rSh.fnEndDrag)( &aDocPt,sal_False );
4122                 }
4123                 bFrmDrag = sal_False;
4124                 bCallBase = sal_False;
4125                 break;
4126             }
4127             bPopMode = sal_True;
4128             // no break
4129         case MOUSE_LEFT + KEY_SHIFT:
4130             if (rSh.IsSelFrmMode())
4131             {
4132 
4133                 (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4134                 bFrmDrag = sal_False;
4135                 bCallBase = sal_False;
4136                 break;
4137             }
4138 
4139             if( bHoldSelection )
4140             {
4141                 //JP 27.04.99: Bug 65389 - das EndDrag sollte auf jedenfall
4142                 //              gerufen werden.
4143                 bHoldSelection = sal_False;
4144                 (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4145             }
4146             else
4147             {
4148                 if ( !rSh.IsInSelect() && rSh.ChgCurrPam( aDocPt ) )
4149                 {
4150                     const sal_Bool bTmpNoInterrupt = bNoInterrupt;
4151                     bNoInterrupt = sal_False;
4152                     {   // nur temp. Move-Kontext aufspannen, da sonst die
4153                         // Abfrage auf die Inhaltsform nicht funktioniert!!!
4154                         MV_KONTEXT( &rSh );
4155                         const Point aDocPos( PixelToLogic( aStartPos ) );
4156                         bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
4157                     }
4158                     bNoInterrupt = bTmpNoInterrupt;
4159 
4160                 }
4161                 else
4162                 {
4163                     sal_Bool bInSel = rSh.IsInSelect();
4164                     (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4165 
4166                     // Internetfield? --> Link-Callen (DocLaden!!)
4167 //JP 18.10.96: Bug 32437 -
4168 //                  if( !rSh.HasSelection() )
4169                     if( !bInSel )
4170                     {
4171                         sal_uInt16 nFilter = URLLOAD_NOFILTER;
4172                         if( KEY_MOD1 == rMEvt.GetModifier() )
4173                             nFilter |= URLLOAD_NEWVIEW;
4174 
4175                         sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
4176                         if ( !bExecHyperlinks )
4177                         {
4178                             SvtSecurityOptions aSecOpts;
4179                             const sal_Bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
4180                             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
4181                                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
4182                                 bExecHyperlinks = sal_True;
4183                         }
4184 
4185                         const sal_Bool bExecSmarttags = rMEvt.GetModifier() == KEY_MOD1;
4186 
4187                         if(pApplyTempl)
4188                             bExecHyperlinks = sal_False;
4189 
4190                         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_CLICKFIELD |
4191                                                     SwContentAtPos::SW_INETATTR |
4192                                                     SwContentAtPos::SW_SMARTTAG  | SwContentAtPos::SW_FORMCTRL);
4193 
4194                         if( rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_True ) )
4195                         {
4196                             sal_Bool bViewLocked = rSh.IsViewLocked();
4197                             if( !bViewLocked && !rSh.IsReadOnlyAvailable() &&
4198                                 aCntntAtPos.IsInProtectSect() )
4199                                 rSh.LockView( sal_True );
4200 
4201                             ReleaseMouse();
4202 
4203                             if( SwContentAtPos::SW_FIELD == aCntntAtPos.eCntntAtPos )
4204                             {
4205                                 if ( aCntntAtPos.pFndTxtAttr != NULL
4206                                      && aCntntAtPos.pFndTxtAttr->Which() == RES_TXTATR_INPUTFIELD )
4207                                 {
4208                                     // select content of Input Field, but exclude CH_TXT_ATR_INPUTFIELDSTART
4209                                     // and CH_TXT_ATR_INPUTFIELDEND
4210                                     rSh.SttSelect();
4211                                     rSh.SelectTxt( *(aCntntAtPos.pFndTxtAttr->GetStart()) + 1,
4212                                                    *(aCntntAtPos.pFndTxtAttr->End()) - 1 );
4213                                 }
4214                                 else
4215                                 {
4216                                     rSh.ClickToField( *aCntntAtPos.aFnd.pFld );
4217                                 }
4218                             }
4219                             else if ( SwContentAtPos::SW_SMARTTAG == aCntntAtPos.eCntntAtPos )
4220                             {
4221                                     // execute smarttag menu
4222                                     if ( bExecSmarttags && SwSmartTagMgr::Get().IsSmartTagsEnabled() )
4223                                         rView.ExecSmartTagPopup( aDocPt );
4224                             }
4225                             else if ( SwContentAtPos::SW_FORMCTRL == aCntntAtPos.eCntntAtPos )
4226                             {
4227                                 ASSERT( aCntntAtPos.aFnd.pFldmark != NULL, "where is my field ptr???");
4228                                 if ( aCntntAtPos.aFnd.pFldmark != NULL)
4229                                 {
4230                                     IFieldmark *fieldBM = const_cast< IFieldmark* > ( aCntntAtPos.aFnd.pFldmark );
4231                                     if (fieldBM->GetFieldname( ).equalsAscii( ODF_FORMCHECKBOX ) )
4232                                     {
4233                                         ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(fieldBM);
4234                                         pCheckboxFm->SetChecked(!pCheckboxFm->IsChecked());
4235                                         pCheckboxFm->Invalidate();
4236                                         rSh.InvalidateWindows( rView.GetVisArea() );
4237                                     } else if (fieldBM->GetFieldname().equalsAscii( ODF_FORMDROPDOWN) ) {
4238                                         rView.ExecFieldPopup( aDocPt, fieldBM );
4239                                         fieldBM->Invalidate();
4240                                         rSh.InvalidateWindows( rView.GetVisArea() );
4241                                     } else {
4242                                         // unknown type..
4243                                     }
4244                                 }
4245                             }
4246                             else // if ( SwContentAtPos::SW_INETATTR == aCntntAtPos.eCntntAtPos )
4247                             {
4248                                 if ( bExecHyperlinks )
4249                                     rSh.ClickToINetAttr( *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr, nFilter );
4250                             }
4251 
4252                             rSh.LockView( bViewLocked );
4253                             bCallShadowCrsr = sal_False;
4254                         }
4255                         else
4256                         {
4257                             aCntntAtPos = SwContentAtPos( SwContentAtPos::SW_FTN );
4258                             if( !rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_True ) && bExecHyperlinks )
4259                             {
4260                                 SdrViewEvent aVEvt;
4261 
4262                                 if (pSdrView)
4263                                     pSdrView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
4264 
4265                                 if (pSdrView && aVEvt.eEvent == SDREVENT_EXECUTEURL)
4266                                 {
4267                                     // URL-Feld getroffen
4268                                     const SvxURLField *pField = aVEvt.pURLField;
4269                                     if (pField)
4270                                     {
4271                                         String sURL(pField->GetURL());
4272                                         String sTarget(pField->GetTargetFrame());
4273                                         ::LoadURL( sURL, &rSh, nFilter, &sTarget);
4274                                     }
4275                                     bCallShadowCrsr = sal_False;
4276                                 }
4277                                 else
4278                                 {
4279                                     // Grafik getroffen
4280                                     ReleaseMouse();
4281                                     if( rSh.ClickToINetGrf( aDocPt, nFilter ))
4282                                         bCallShadowCrsr = sal_False;
4283                                 }
4284                             }
4285                         }
4286 
4287                         if( bCallShadowCrsr &&
4288                             rSh.GetViewOptions()->IsShadowCursor() &&
4289                             MOUSE_LEFT == (rMEvt.GetModifier() + rMEvt.GetButtons()) &&
4290                             !rSh.HasSelection() &&
4291                             !GetConnectMetaFile() &&
4292                             rSh.VisArea().IsInside( aDocPt ))
4293                         {
4294                             SwUndoId nLastUndoId(UNDO_EMPTY);
4295                             if (rSh.GetLastUndoInfo(0, & nLastUndoId))
4296                             {
4297                                 if (UNDO_INS_FROM_SHADOWCRSR == nLastUndoId)
4298                                 {
4299                                     rSh.Undo();
4300                                 }
4301                             }
4302                             SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
4303                             rSh.SetShadowCrsrPos( aDocPt, eMode );
4304                         }
4305                     }
4306                 }
4307                 bCallBase = sal_False;
4308 
4309             }
4310 
4311             // gfs. im Down gepushten Mode wieder zuruecksetzen
4312             if ( bPopMode && bModePushed )
4313             {
4314                 rSh.PopMode();
4315                 bModePushed = sal_False;
4316                 bCallBase = sal_False;
4317             }
4318             break;
4319 
4320         default:
4321             ReleaseMouse();
4322             return;
4323     }
4324 
4325     if( pApplyTempl )
4326     {
4327         int eSelection = rSh.GetSelectionType();
4328         SwFormatClipboard* pFormatClipboard = pApplyTempl->pFormatClipboard;
4329         if( pFormatClipboard )//apply format paintbrush
4330         {
4331             //get some parameters
4332             SwWrtShell& rWrtShell = rView.GetWrtShell();
4333             SfxStyleSheetBasePool* pPool=0;
4334             bool bNoCharacterFormats = false;
4335             bool bNoParagraphFormats = false;
4336             {
4337                 SwDocShell* pDocSh = rView.GetDocShell();
4338                 if(pDocSh)
4339                     pPool = pDocSh->GetStyleSheetPool();
4340                 if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
4341                     bNoCharacterFormats = true;
4342                 else if( rMEvt.GetModifier() & KEY_MOD1 )
4343                     bNoParagraphFormats = true;
4344             }
4345             //execute paste
4346             pFormatClipboard->Paste( rWrtShell, pPool, bNoCharacterFormats, bNoParagraphFormats );
4347 
4348             //if the clipboard is empty after paste remove the ApplyTemplate
4349             if(!pFormatClipboard->HasContent())
4350                 SetApplyTemplate(SwApplyTemplate());
4351         }
4352         else if( pApplyTempl->nColor )
4353         {
4354             sal_uInt16 nId = 0;
4355             switch( pApplyTempl->nColor )
4356             {
4357                 case SID_ATTR_CHAR_COLOR_EXT:
4358                     nId = RES_CHRATR_COLOR;
4359                 break;
4360                 case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
4361                     nId = RES_CHRATR_BACKGROUND;
4362                 break;
4363             }
4364             if( nId && (nsSelectionType::SEL_TXT|nsSelectionType::SEL_TBL) & eSelection)
4365             {
4366                 if( rSh.IsSelection() && !rSh.HasReadonlySel() )
4367                 {
4368                     if(nId == RES_CHRATR_BACKGROUND)
4369                     {
4370                         Color aColor( COL_TRANSPARENT  );
4371                         if( !SwEditWin::bTransparentBackColor )
4372                             aColor = SwEditWin::aTextBackColor;
4373                         rSh.SetAttrItem( SvxBrushItem( aColor, nId ) );
4374                     }
4375                     else
4376                         rSh.SetAttrItem( SvxColorItem(SwEditWin::aTextColor, nId) );
4377                     rSh.UnSetVisCrsr();
4378                     rSh.EnterStdMode();
4379                     rSh.SetVisCrsr(aDocPt);
4380 
4381                     pApplyTempl->bUndo = sal_True;
4382                     bCallBase = sal_False;
4383                     aTemplateTimer.Stop();
4384                 }
4385                 else if(rMEvt.GetClicks() == 1)
4386                 {
4387                     // keine Selektion -> also Giesskanne abschalten
4388                     aTemplateTimer.Start();
4389                 }
4390             }
4391         }
4392         else
4393         {
4394             String aStyleName;
4395             switch ( pApplyTempl->eType )
4396             {
4397                 case SFX_STYLE_FAMILY_PARA:
4398                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
4399                          & eSelection ) && !rSh.HasReadonlySel() )
4400                     {
4401                         rSh.SetTxtFmtColl( pApplyTempl->aColl.pTxtColl );
4402                         pApplyTempl->bUndo = sal_True;
4403                         bCallBase = sal_False;
4404                         if ( pApplyTempl->aColl.pTxtColl )
4405                             aStyleName = pApplyTempl->aColl.pTxtColl->GetName();
4406                     }
4407                     break;
4408                 case SFX_STYLE_FAMILY_CHAR:
4409                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
4410                          & eSelection ) && !rSh.HasReadonlySel() )
4411                     {
4412                         rSh.SetAttrItem( SwFmtCharFmt(pApplyTempl->aColl.pCharFmt) );
4413                         rSh.UnSetVisCrsr();
4414                         rSh.EnterStdMode();
4415                         rSh.SetVisCrsr(aDocPt);
4416                         pApplyTempl->bUndo = sal_True;
4417                         bCallBase = sal_False;
4418                         if ( pApplyTempl->aColl.pCharFmt )
4419                             aStyleName = pApplyTempl->aColl.pCharFmt->GetName();
4420                     }
4421                     break;
4422                 case SFX_STYLE_FAMILY_FRAME :
4423                 {
4424                     const SwFrmFmt* pFmt = rSh.GetFmtFromObj( aDocPt );
4425                     if(PTR_CAST(SwFlyFrmFmt, pFmt))
4426                     {
4427                         rSh.SetFrmFmt( pApplyTempl->aColl.pFrmFmt, sal_False, &aDocPt );
4428                         pApplyTempl->bUndo = sal_True;
4429                         bCallBase = sal_False;
4430                         if( pApplyTempl->aColl.pFrmFmt )
4431                             aStyleName = pApplyTempl->aColl.pFrmFmt->GetName();
4432                     }
4433                     break;
4434                 }
4435                 case SFX_STYLE_FAMILY_PAGE:
4436                             // Kein Undo bei Seitenvorlagen
4437                     rSh.ChgCurPageDesc( *pApplyTempl->aColl.pPageDesc );
4438                     if ( pApplyTempl->aColl.pPageDesc )
4439                         aStyleName = pApplyTempl->aColl.pPageDesc->GetName();
4440                     bCallBase = sal_False;
4441                     break;
4442                 case SFX_STYLE_FAMILY_PSEUDO:
4443                     if( !rSh.HasReadonlySel() )
4444                     {
4445                         rSh.SetCurNumRule( *pApplyTempl->aColl.pNumRule,
4446                                            false,
4447                                            pApplyTempl->aColl.pNumRule->GetDefaultListId() );
4448                         bCallBase = sal_False;
4449                         pApplyTempl->bUndo = sal_True;
4450                         if( pApplyTempl->aColl.pNumRule )
4451                             aStyleName = pApplyTempl->aColl.pNumRule->GetName();
4452                     }
4453                     break;
4454             }
4455 
4456             uno::Reference< frame::XDispatchRecorder > xRecorder =
4457                     rView.GetViewFrame()->GetBindings().GetRecorder();
4458             if ( aStyleName.Len() && xRecorder.is() )
4459             {
4460                 SfxShell *pSfxShell = lcl_GetShellFromDispatcher( rView, TYPE(SwTextShell) );
4461                 if ( pSfxShell )
4462                 {
4463                     SfxRequest aReq( rView.GetViewFrame(), SID_STYLE_APPLY );
4464                     aReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aStyleName ) );
4465                     aReq.AppendItem( SfxUInt16Item( SID_STYLE_FAMILY, (sal_uInt16) pApplyTempl->eType ) );
4466                     aReq.Done();
4467                 }
4468             }
4469         }
4470 
4471     }
4472     ReleaseMouse();
4473     // Hier kommen nur verarbeitete MouseEvents an; nur bei diesen duerfen
4474     // die Modi zurueckgesetzt werden.
4475     bMBPressed = sal_False;
4476 
4477     //sicherheitshalber aufrufen, da jetzt das Selektieren bestimmt zu Ende ist.
4478     //Andernfalls koennte der Timeout des Timers Kummer machen.
4479     EnterArea();
4480     bNoInterrupt = sal_False;
4481 
4482     if (bCallBase)
4483         Window::MouseButtonUp(rMEvt);
4484 }
4485 
4486 
4487 /*--------------------------------------------------------------------
4488     Beschreibung:   Vorlage anwenden
4489  --------------------------------------------------------------------*/
4490 
4491 
SetApplyTemplate(const SwApplyTemplate & rTempl)4492 void SwEditWin::SetApplyTemplate(const SwApplyTemplate &rTempl)
4493 {
4494     static sal_Bool bIdle = sal_False;
4495     DELETEZ(pApplyTempl);
4496     SwWrtShell &rSh = rView.GetWrtShell();
4497 
4498     if(rTempl.pFormatClipboard)
4499     {
4500         pApplyTempl = new SwApplyTemplate( rTempl );
4501               SetPointer( POINTER_FILL );//@todo #i20119# maybe better a new brush pointer here in future
4502               rSh.NoEdit( sal_False );
4503               bIdle = rSh.GetViewOptions()->IsIdle();
4504               ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4505     }
4506     else if(rTempl.nColor)
4507     {
4508         pApplyTempl = new SwApplyTemplate( rTempl );
4509         SetPointer( POINTER_FILL );
4510         rSh.NoEdit( sal_False );
4511         bIdle = rSh.GetViewOptions()->IsIdle();
4512         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4513     }
4514     else if( rTempl.eType )
4515     {
4516         pApplyTempl = new SwApplyTemplate( rTempl );
4517         SetPointer( POINTER_FILL  );
4518         rSh.NoEdit( sal_False );
4519         bIdle = rSh.GetViewOptions()->IsIdle();
4520         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4521     }
4522     else
4523     {
4524         SetPointer( POINTER_TEXT );
4525         rSh.UnSetVisCrsr();
4526 
4527         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( bIdle );
4528         if ( !rSh.IsSelFrmMode() )
4529             rSh.Edit();
4530     }
4531 
4532     static sal_uInt16 __READONLY_DATA aInva[] =
4533     {
4534         SID_STYLE_WATERCAN,
4535         SID_ATTR_CHAR_COLOR_EXT,
4536         SID_ATTR_CHAR_COLOR_BACKGROUND_EXT,
4537         0
4538     };
4539     rView.GetViewFrame()->GetBindings().Invalidate(aInva);
4540 }
4541 
4542 /*--------------------------------------------------------------------
4543     Beschreibung:   ctor
4544  --------------------------------------------------------------------*/
4545 
4546 
SwEditWin(Window * pParent,SwView & rMyView)4547 SwEditWin::SwEditWin(Window *pParent, SwView &rMyView):
4548     Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
4549     DropTargetHelper( this ),
4550     DragSourceHelper( this ),
4551 
4552     eBufferLanguage(LANGUAGE_DONTKNOW),
4553     pApplyTempl(0),
4554     pAnchorMarker( 0 ),
4555     pUserMarker( 0 ),
4556     pUserMarkerObj( 0 ),
4557     pShadCrsr( 0 ),
4558     pRowColumnSelectionStart( 0 ),
4559 
4560     rView( rMyView ),
4561 
4562     aActHitType(SDRHIT_NONE),
4563     m_nDropFormat( 0 ),
4564     m_nDropAction( 0 ),
4565     m_nDropDestination( 0 ),
4566 
4567     nInsFrmColCount( 1 ),
4568     eDrawMode(OBJ_NONE),
4569 
4570     bLockInput(sal_False),
4571     bObjectSelect( sal_False ),
4572     nKS_NUMDOWN_Count(0),
4573     nKS_NUMINDENTINC_Count(0)
4574 {
4575     SetHelpId(HID_EDIT_WIN);
4576     EnableChildTransparentMode();
4577     SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
4578 
4579     bLinkRemoved = bMBPressed = bInsDraw = bInsFrm =
4580     bIsInDrag = bOldIdle = bOldIdleSet = bChainMode = bWasShdwCrsr = sal_False;
4581     //#i42732# initially use the input language
4582     bUseInputLanguage = sal_True;
4583 
4584     SetMapMode(MapMode(MAP_TWIP));
4585 
4586     SetPointer( POINTER_TEXT );
4587     aTimer.SetTimeoutHdl(LINK(this, SwEditWin, TimerHandler));
4588 
4589     bTblInsDelMode = sal_False;
4590     aKeyInputTimer.SetTimeout( 3000 );
4591     aKeyInputTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputTimerHandler));
4592 
4593     aKeyInputFlushTimer.SetTimeout( 200 );
4594     aKeyInputFlushTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputFlushHandler));
4595 
4596     // TemplatePointer fuer Farben soll nach Einfachclick
4597     // ohne Selektion zurueckgesetzt werden
4598     aTemplateTimer.SetTimeout(400);
4599     aTemplateTimer.SetTimeoutHdl(LINK(this, SwEditWin, TemplateTimerHdl));
4600 
4601     //JP 16.12.98: temporaere Loesung!!! Sollte bei jeder Cursorbewegung
4602     //          den Font von der akt. einfuege Position setzen!
4603     if( !rMyView.GetDocShell()->IsReadOnly() )
4604     {
4605         Font aFont;
4606         SetInputContext( InputContext( aFont, INPUTCONTEXT_TEXT |
4607                                             INPUTCONTEXT_EXTTEXTINPUT ) );
4608     }
4609 }
4610 
4611 
4612 
~SwEditWin()4613 SwEditWin::~SwEditWin()
4614 {
4615     aKeyInputTimer.Stop();
4616     delete pShadCrsr;
4617     delete pRowColumnSelectionStart;
4618     if( pQuickHlpData->bClear && rView.GetWrtShellPtr() )
4619         pQuickHlpData->Stop( rView.GetWrtShell() );
4620     bExecuteDrag = sal_False;
4621     delete pApplyTempl;
4622     rView.SetDrawFuncPtr(NULL);
4623 
4624     if(pUserMarker)
4625     {
4626         delete pUserMarker;
4627     }
4628 
4629     delete pAnchorMarker;
4630 }
4631 
4632 
4633 /******************************************************************************
4634  *  Beschreibung: DrawTextEditMode einschalten
4635  ******************************************************************************/
4636 
4637 
EnterDrawTextMode(const Point & aDocPos)4638 void SwEditWin::EnterDrawTextMode( const Point& aDocPos )
4639 {
4640     if ( rView.EnterDrawTextMode(aDocPos) == sal_True )
4641     {
4642         if (rView.GetDrawFuncPtr())
4643         {
4644             rView.GetDrawFuncPtr()->Deactivate();
4645             rView.SetDrawFuncPtr(NULL);
4646             rView.LeaveDrawCreate();
4647         }
4648         rView.NoRotate();
4649         rView.AttrChangedNotify( &rView.GetWrtShell() );
4650     }
4651 }
4652 
4653 /******************************************************************************
4654  *  Beschreibung: DrawMode einschalten
4655  ******************************************************************************/
4656 
4657 
4658 
EnterDrawMode(const MouseEvent & rMEvt,const Point & aDocPos)4659 sal_Bool SwEditWin::EnterDrawMode(const MouseEvent& rMEvt, const Point& aDocPos)
4660 {
4661     SwWrtShell &rSh = rView.GetWrtShell();
4662     SdrView *pSdrView = rSh.GetDrawView();
4663 
4664     if ( rView.GetDrawFuncPtr() )
4665     {
4666         if (rSh.IsDrawCreate())
4667             return sal_True;
4668 
4669         sal_Bool bRet = rView.GetDrawFuncPtr()->MouseButtonDown( rMEvt );
4670         rView.AttrChangedNotify( &rSh );
4671         return bRet;
4672     }
4673 
4674     if ( pSdrView && pSdrView->IsTextEdit() )
4675     {
4676         sal_Bool bUnLockView = !rSh.IsViewLocked();
4677         rSh.LockView( sal_True );
4678 
4679         rSh.EndTextEdit(); // Danebengeklickt, Ende mit Edit
4680         rSh.SelectObj( aDocPos );
4681         if ( !rSh.IsObjSelected() && !rSh.IsFrmSelected() )
4682             rSh.LeaveSelFrmMode();
4683         else
4684         {
4685             SwEditWin::nDDStartPosY = aDocPos.Y();
4686             SwEditWin::nDDStartPosX = aDocPos.X();
4687             bFrmDrag = sal_True;
4688         }
4689         if( bUnLockView )
4690             rSh.LockView( sal_False );
4691         rView.AttrChangedNotify( &rSh );
4692         return sal_True;
4693     }
4694     return sal_False;
4695 }
4696 
4697 /******************************************************************************
4698  *  Beschreibung:
4699  ******************************************************************************/
4700 
4701 
4702 
IsDrawSelMode()4703 sal_Bool SwEditWin::IsDrawSelMode()
4704 {
4705     return IsObjectSelect();
4706 }
4707 
4708 /******************************************************************************
4709  *  Beschreibung:
4710  ******************************************************************************/
4711 
4712 
GetFocus()4713 void SwEditWin::GetFocus()
4714 {
4715     if ( rView.GetPostItMgr()->HasActiveSidebarWin() )
4716     {
4717         rView.GetPostItMgr()->GrabFocusOnActiveSidebarWin();
4718     }
4719 	else
4720 	{
4721 		rView.GotFocus();
4722 		Window::GetFocus();
4723 		rView.GetWrtShell().InvalidateAccessibleFocus();
4724 	}
4725 }
4726 
4727 /******************************************************************************
4728  *  Beschreibung:
4729  ******************************************************************************/
4730 
4731 
4732 
LoseFocus()4733 void SwEditWin::LoseFocus()
4734 {
4735     rView.GetWrtShell().InvalidateAccessibleFocus();
4736     Window::LoseFocus();
4737     if( pQuickHlpData->bClear )
4738         pQuickHlpData->Stop( rView.GetWrtShell() );
4739     rView.LostFocus();
4740 }
4741 
4742 /******************************************************************************
4743  *  Beschreibung:
4744  ******************************************************************************/
4745 
4746 
4747 
Command(const CommandEvent & rCEvt)4748 void SwEditWin::Command( const CommandEvent& rCEvt )
4749 {
4750     SwWrtShell &rSh = rView.GetWrtShell();
4751 
4752 	if ( !rView.GetViewFrame() )
4753 	{
4754 		//Wenn der ViewFrame in Kuerze stirbt kein Popup mehr!
4755 		Window::Command(rCEvt);
4756 		return;
4757 	}
4758 
4759     // The command event is send to the window after a possible context
4760     // menu from an inplace client has been closed. Now we have the chance
4761     // to deactivate the inplace client without any problem regarding parent
4762     // windows and code on the stack.
4763     // For more information, see #126086# and #128122#
4764     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
4765     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
4766     if ( bIsOleActive && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ))
4767     {
4768         rSh.FinishOLEObj();
4769         return;
4770     }
4771 
4772     sal_Bool bCallBase      = sal_True;
4773 
4774     switch ( rCEvt.GetCommand() )
4775     {
4776         case COMMAND_CONTEXTMENU:
4777         {
4778             const sal_uInt16 nId = SwInputChild::GetChildWindowId();
4779             SwInputChild* pChildWin = (SwInputChild*)GetView().GetViewFrame()->
4780                                                 GetChildWindow( nId );
4781 
4782             if (rView.GetPostItMgr()->IsHit(rCEvt.GetMousePosPixel()))
4783                 return;
4784 
4785             if((!pChildWin || pChildWin->GetView() != &rView) &&
4786                 !rSh.IsDrawCreate() && !IsDrawAction())
4787             {
4788                 SET_CURR_SHELL( &rSh );
4789                 if (!pApplyTempl)
4790                 {
4791                     if (bNoInterrupt == sal_True)
4792                     {
4793                         ReleaseMouse();
4794                         bNoInterrupt = sal_False;
4795                         bMBPressed = sal_False;
4796                     }
4797                     Point aDocPos( PixelToLogic( rCEvt.GetMousePosPixel() ) );
4798                     if ( !rCEvt.IsMouseEvent() )
4799                         aDocPos = rSh.GetCharRect().Center();
4800                     else
4801                     {
4802                         SelectMenuPosition(rSh, rCEvt.GetMousePosPixel());
4803                         rView.StopShellTimer();
4804 
4805                     }
4806                     const Point aPixPos = LogicToPixel( aDocPos );
4807 
4808                     if ( rView.GetDocShell()->IsReadOnly() )
4809                     {
4810                         SwReadOnlyPopup* pROPopup = new SwReadOnlyPopup( aDocPos, rView );
4811 
4812                         ui::ContextMenuExecuteEvent aEvent;
4813                         aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
4814                         aEvent.ExecutePosition.X = aPixPos.X();
4815                         aEvent.ExecutePosition.Y = aPixPos.Y();
4816                         Menu* pMenu = 0;
4817                         ::rtl::OUString sMenuName =
4818                             ::rtl::OUString::createFromAscii( "private:resource/ReadonlyContextMenu");
4819                         if( GetView().TryContextMenuInterception( *pROPopup, sMenuName, pMenu, aEvent ) )
4820                         {
4821                             if ( pMenu )
4822                             {
4823                                 sal_uInt16 nExecId = ((PopupMenu*)pMenu)->Execute(this, aPixPos);
4824                                 if( !::ExecuteMenuCommand( *static_cast<PopupMenu*>(pMenu), *rView.GetViewFrame(), nExecId ))
4825                                     pROPopup->Execute(this, nExecId);
4826                             }
4827                             else
4828                                 pROPopup->Execute(this, aPixPos);
4829                         }
4830                         delete pROPopup;
4831                     }
4832                     else if ( !rView.ExecSpellPopup( aDocPos ) )
4833                         GetView().GetViewFrame()->GetDispatcher()->ExecutePopup( 0, this, &aPixPos);
4834                 }
4835                 else if (pApplyTempl->bUndo)
4836                     rSh.Do(SwWrtShell::UNDO);
4837                 bCallBase = sal_False;
4838             }
4839         }
4840         break;
4841 
4842         case COMMAND_WHEEL:
4843         case COMMAND_STARTAUTOSCROLL:
4844         case COMMAND_AUTOSCROLL:
4845             if( pShadCrsr )
4846                 delete pShadCrsr, pShadCrsr = 0;
4847             bCallBase = !rView.HandleWheelCommands( rCEvt );
4848             break;
4849 
4850         case COMMAND_VOICE:
4851             {
4852                 //ggf. an Outliner weiterleiten
4853                 if ( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4854                 {
4855                     bCallBase = sal_False;
4856                     rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4857                     break;
4858                 }
4859 
4860                 const CommandVoiceData *pCData = rCEvt.GetVoiceData();
4861                 if ( VOICECOMMANDTYPE_CONTROL == pCData->GetType() )
4862                     break;
4863 
4864 
4865                 sal_uInt16 nSlotId = 0;
4866                 SfxPoolItem *pItem = 0;
4867 
4868                 switch ( pCData->GetCommand() )
4869                 {
4870                     case DICTATIONCOMMAND_NEWPARAGRAPH: nSlotId = FN_INSERT_BREAK; break;
4871                     case DICTATIONCOMMAND_NEWLINE:      nSlotId = FN_INSERT_LINEBREAK; break;
4872                     case DICTATIONCOMMAND_LEFT:         nSlotId = FN_PREV_WORD; break;
4873                     case DICTATIONCOMMAND_RIGHT:        nSlotId = FN_NEXT_WORD; break;
4874                     case DICTATIONCOMMAND_UP:           nSlotId = FN_LINE_UP; break;
4875                     case DICTATIONCOMMAND_DOWN:         nSlotId = FN_LINE_DOWN; break;
4876                     case DICTATIONCOMMAND_UNDO:         nSlotId = SID_UNDO; break;
4877                     case DICTATIONCOMMAND_REPEAT:       nSlotId = SID_REPEAT; break;
4878                     case DICTATIONCOMMAND_DEL:          nSlotId = FN_DELETE_BACK_WORD; break;
4879 
4880                     case DICTATIONCOMMAND_BOLD_ON:      nSlotId = SID_ATTR_CHAR_WEIGHT;
4881                                                         pItem = new SvxWeightItem( WEIGHT_BOLD, RES_CHRATR_WEIGHT );
4882                                                         break;
4883                     case DICTATIONCOMMAND_BOLD_OFF:     nSlotId = SID_ATTR_CHAR_WEIGHT;
4884                                                         pItem = new SvxWeightItem( WEIGHT_NORMAL, RES_CHRATR_WEIGHT );
4885                                                         break;
4886                     case DICTATIONCOMMAND_UNDERLINE_ON: nSlotId = SID_ATTR_CHAR_UNDERLINE;
4887                                                         pItem = new SvxUnderlineItem( UNDERLINE_SINGLE, RES_CHRATR_WEIGHT );
4888                                                         break;
4889                     case DICTATIONCOMMAND_UNDERLINE_OFF:nSlotId = SID_ATTR_CHAR_UNDERLINE;
4890                                                         pItem = new SvxUnderlineItem( UNDERLINE_NONE, RES_CHRATR_UNDERLINE );
4891                                                         break;
4892                     case DICTATIONCOMMAND_ITALIC_ON:    nSlotId = SID_ATTR_CHAR_POSTURE;
4893                                                         pItem = new SvxPostureItem( ITALIC_NORMAL, RES_CHRATR_POSTURE );
4894                                                         break;
4895                     case DICTATIONCOMMAND_ITALIC_OFF:   nSlotId = SID_ATTR_CHAR_POSTURE;
4896                                                         pItem = new SvxPostureItem( ITALIC_NONE, RES_CHRATR_POSTURE );
4897                                                         break;
4898                     case DICTATIONCOMMAND_NUMBERING_ON:
4899                                     if ( !rSh.GetCurNumRule() )
4900                                         nSlotId = FN_NUM_NUMBERING_ON;
4901                                     break;
4902                     case DICTATIONCOMMAND_NUMBERING_OFF:
4903                                     if ( rSh.GetCurNumRule() )
4904                                        nSlotId = FN_NUM_NUMBERING_ON;
4905                                     break;
4906                     case DICTATIONCOMMAND_TAB:
4907                                     {
4908                                        rSh.Insert( '\t' );
4909                                     }
4910                                     break;
4911                     case DICTATIONCOMMAND_UNKNOWN:
4912                                     {
4913                                         rView.GetWrtShell().Insert( pCData->GetText() );
4914                                     }
4915                                     break;
4916 
4917 #ifdef DBG_UTIL
4918                     default:
4919                         ASSERT( !this, "unknown speech command." );
4920 #endif
4921                 }
4922                 if ( nSlotId )
4923                 {
4924                     bCallBase = sal_False;
4925                     if ( pItem )
4926                     {
4927                         const SfxPoolItem* aArgs[2];
4928                         aArgs[0] = pItem;
4929                         aArgs[1] = 0;
4930                         GetView().GetViewFrame()->GetBindings().Execute(
4931                                     nSlotId, aArgs, 0, SFX_CALLMODE_STANDARD );
4932                         delete pItem;
4933                     }
4934                     else
4935                         GetView().GetViewFrame()->GetBindings().Execute( nSlotId );
4936                 }
4937             }
4938             break;
4939 
4940     case COMMAND_STARTEXTTEXTINPUT:
4941     {
4942         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
4943                               rSh.IsCrsrReadonly();
4944         if(!bIsDocReadOnly)
4945         {
4946             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4947             {
4948                 bCallBase = sal_False;
4949                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4950             }
4951             else
4952             {
4953                 if( rSh.HasSelection() )
4954                     rSh.DelRight();
4955 
4956                 bCallBase = sal_False;
4957                 LanguageType eInputLanguage = GetInputLanguage();
4958                 rSh.CreateExtTextInput(eInputLanguage);
4959             }
4960         }
4961         break;
4962     }
4963     case COMMAND_ENDEXTTEXTINPUT:
4964     {
4965         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
4966                               rSh.IsCrsrReadonly();
4967         if(!bIsDocReadOnly)
4968         {
4969             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4970             {
4971                 bCallBase = sal_False;
4972                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4973             }
4974             else
4975             {
4976                 bCallBase = sal_False;
4977                 String sRecord = rSh.DeleteExtTextInput();
4978                 uno::Reference< frame::XDispatchRecorder > xRecorder =
4979                         rView.GetViewFrame()->GetBindings().GetRecorder();
4980 
4981                 if ( sRecord.Len() )
4982                 {
4983                     // #102812# convert quotes in IME text
4984                     // works on the last input character, this is escpecially in Korean text often done
4985                     // quotes that are inside of the string are not replaced!
4986                     const sal_Unicode aCh = sRecord.GetChar(sRecord.Len() - 1);
4987                     SvxAutoCorrCfg* pACfg = SvxAutoCorrCfg::Get();
4988                     SvxAutoCorrect* pACorr = pACfg->GetAutoCorrect();
4989                     if(pACorr &&
4990                         (( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
4991                         ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
4992                     {
4993                         rSh.DelLeft();
4994                         rSh.AutoCorrect( *pACorr, aCh );
4995                     }
4996 
4997                     if ( xRecorder.is() )
4998                     {
4999                         //Shell ermitteln
5000                         SfxShell *pSfxShell = lcl_GetShellFromDispatcher( rView, TYPE(SwTextShell) );
5001                         // Request generieren und recorden
5002                         if (pSfxShell)
5003                         {
5004                             SfxRequest aReq( rView.GetViewFrame(), FN_INSERT_STRING );
5005                             aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sRecord ) );
5006                             aReq.Done();
5007                         }
5008                     }
5009                 }
5010             }
5011         }
5012     }
5013     break;
5014     case COMMAND_EXTTEXTINPUT:
5015     {
5016         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
5017                               rSh.IsCrsrReadonly();
5018         if(!bIsDocReadOnly)
5019         {
5020             QuickHelpData aTmpQHD;
5021             if( pQuickHlpData->bClear )
5022             {
5023                 aTmpQHD.Move( *pQuickHlpData );
5024                 pQuickHlpData->Stop( rSh );
5025             }
5026             String sWord;
5027             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
5028             {
5029                 bCallBase = sal_False;
5030                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
5031             }
5032             else
5033             {
5034                 const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData();
5035                 if( pData )
5036                 {
5037                     sWord = pData->GetText();
5038                     bCallBase = sal_False;
5039                     rSh.SetExtTextInputData( *pData );
5040                 }
5041             }
5042                 uno::Reference< frame::XDispatchRecorder > xRecorder =
5043                         rView.GetViewFrame()->GetBindings().GetRecorder();
5044                 if(!xRecorder.is())
5045                 {
5046                     SvxAutoCorrCfg* pACfg = SvxAutoCorrCfg::Get();
5047                     SvxAutoCorrect* pACorr = pACfg->GetAutoCorrect();
5048                     if( pACfg && pACorr &&
5049                         ( pACfg->IsAutoTextTip() ||
5050                           pACorr->GetSwFlags().bAutoCompleteWords ) &&
5051                         rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
5052                     {
5053                         ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr, sal_True);
5054                     }
5055                 }
5056         }
5057     }
5058     break;
5059     case COMMAND_CURSORPOS:
5060         // will be handled by the base class
5061         break;
5062 
5063     case COMMAND_PASTESELECTION:
5064         if( !rView.GetDocShell()->IsReadOnly() )
5065         {
5066             TransferableDataHelper aDataHelper(
5067                         TransferableDataHelper::CreateFromSelection( this ));
5068             if( !aDataHelper.GetXTransferable().is() )
5069                 break;
5070 
5071             sal_uLong nDropFormat;
5072             sal_uInt16 nEventAction, nDropAction, nDropDestination;
5073             nDropDestination = GetDropDestination( rCEvt.GetMousePosPixel() );
5074             if( !nDropDestination )
5075                 break;
5076 
5077             nDropAction = SotExchange::GetExchangeAction(
5078                                 aDataHelper.GetDataFlavorExVector(),
5079                                 nDropDestination, EXCHG_IN_ACTION_COPY,
5080                                 EXCHG_IN_ACTION_COPY, nDropFormat,
5081                                 nEventAction );
5082             if( EXCHG_INOUT_ACTION_NONE != nDropAction )
5083             {
5084                 const Point aDocPt( PixelToLogic( rCEvt.GetMousePosPixel() ) );
5085                 SwTransferable::PasteData( aDataHelper, rSh, nDropAction,
5086                                     nDropFormat, nDropDestination, sal_False,
5087                                     sal_False, &aDocPt, EXCHG_IN_ACTION_COPY,
5088                                     sal_True );
5089             }
5090         }
5091         break;
5092         case COMMAND_MODKEYCHANGE :
5093         {
5094             const CommandModKeyData* pCommandData = (const CommandModKeyData*)rCEvt.GetData();
5095             if(pCommandData->IsMod1() && !pCommandData->IsMod2())
5096             {
5097                 sal_uInt16 nSlot = 0;
5098                 if(pCommandData->IsLeftShift() && !pCommandData->IsRightShift())
5099                     nSlot = SID_ATTR_PARA_LEFT_TO_RIGHT;
5100                 else if(!pCommandData->IsLeftShift() && pCommandData->IsRightShift())
5101                     nSlot = SID_ATTR_PARA_RIGHT_TO_LEFT;
5102                 if(nSlot && SW_MOD()->GetCTLOptions().IsCTLFontEnabled())
5103                     GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
5104             }
5105         }
5106         break;
5107         case COMMAND_HANGUL_HANJA_CONVERSION :
5108             GetView().GetViewFrame()->GetDispatcher()->Execute(SID_HANGUL_HANJA_CONVERSION);
5109         break;
5110         case COMMAND_INPUTLANGUAGECHANGE :
5111             //#i42732# update state of fontname if input language changes
5112             bInputLanguageSwitched = true;
5113             SetUseInputLanguage( sal_True );
5114         break;
5115         case COMMAND_SELECTIONCHANGE:
5116         {
5117             const CommandSelectionChangeData *pData = rCEvt.GetSelectionChangeData();
5118             rSh.SttCrsrMove();
5119             rSh.GoStartSentence();
5120             rSh.GetCrsr()->GetPoint()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetStart());
5121             rSh.SetMark();
5122             rSh.GetCrsr()->GetMark()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetEnd() - pData->GetStart());
5123             rSh.EndCrsrMove( sal_True );
5124         }
5125         break;
5126         case COMMAND_PREPARERECONVERSION:
5127         if( rSh.HasSelection() )
5128         {
5129             SwPaM *pCrsr = (SwPaM*)rSh.GetCrsr();
5130 
5131             if( rSh.IsMultiSelection() )
5132             {
5133                 if( pCrsr && !pCrsr->HasMark() &&
5134                 pCrsr->GetPoint() == pCrsr->GetMark() )
5135                 {
5136                 rSh.GoPrevCrsr();
5137                 pCrsr = (SwPaM*)rSh.GetCrsr();
5138                 }
5139 
5140                 // Cancel all selections other than the last selected one.
5141                 while( rSh.GetCrsr()->GetNext() != rSh.GetCrsr() )
5142                 delete rSh.GetCrsr()->GetNext();
5143             }
5144 
5145             if( pCrsr )
5146             {
5147                 sal_uLong nPosNodeIdx = pCrsr->GetPoint()->nNode.GetIndex();
5148                 xub_StrLen nPosIdx = pCrsr->GetPoint()->nContent.GetIndex();
5149                 sal_uLong nMarkNodeIdx = pCrsr->GetMark()->nNode.GetIndex();
5150                 xub_StrLen nMarkIdx = pCrsr->GetMark()->nContent.GetIndex();
5151 
5152                 if( !rSh.GetCrsr()->HasMark() )
5153                 rSh.GetCrsr()->SetMark();
5154 
5155                 rSh.SttCrsrMove();
5156 
5157                 if( nPosNodeIdx < nMarkNodeIdx )
5158                 {
5159                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
5160                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
5161                 rSh.GetCrsr()->GetMark()->nNode = nPosNodeIdx;
5162                 rSh.GetCrsr()->GetMark()->nContent =
5163                     rSh.GetCrsr()->GetCntntNode( sal_True )->Len();
5164                 }
5165                 else if( nPosNodeIdx == nMarkNodeIdx )
5166                 {
5167                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
5168                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
5169                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
5170                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
5171                 }
5172                 else
5173                 {
5174                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
5175                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
5176                 rSh.GetCrsr()->GetPoint()->nNode = nMarkNodeIdx;
5177                 rSh.GetCrsr()->GetPoint()->nContent =
5178                     rSh.GetCrsr()->GetCntntNode( sal_False )->Len();
5179                 }
5180 
5181                 rSh.EndCrsrMove( sal_True );
5182             }
5183         }
5184         break;
5185 #ifdef DBG_UTIL
5186         default:
5187             ASSERT( !this, "unknown command." );
5188 #endif
5189     }
5190     if (bCallBase)
5191         Window::Command(rCEvt);
5192 }
5193 
5194 /* -----------------25.08.2003 10:12-----------------
5195     #i18686#: select the object/cursor at the mouse
5196     position of the context menu request
5197  --------------------------------------------------*/
SelectMenuPosition(SwWrtShell & rSh,const Point & rMousePos)5198 sal_Bool SwEditWin::SelectMenuPosition(SwWrtShell& rSh, const Point& rMousePos )
5199 {
5200     sal_Bool bRet = sal_False;
5201     const Point aDocPos( PixelToLogic( rMousePos ) );
5202     const bool bIsInsideSelectedObj( rSh.IsInsideSelectedObj( aDocPos ) );
5203     //create a synthetic mouse event out of the coordinates
5204     MouseEvent aMEvt(rMousePos);
5205     SdrView *pSdrView = rSh.GetDrawView();
5206     if ( pSdrView )
5207     {
5208         // no close of insert_draw and reset of draw mode,
5209         // if context menu position is inside a selected object.
5210         if ( !bIsInsideSelectedObj && rView.GetDrawFuncPtr() )
5211         {
5212 
5213             rView.GetDrawFuncPtr()->Deactivate();
5214             rView.SetDrawFuncPtr(NULL);
5215             rView.LeaveDrawCreate();
5216             SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
5217             rBind.Invalidate( SID_ATTR_SIZE );
5218             rBind.Invalidate( SID_TABLE_CELL );
5219         }
5220 
5221         // if draw text is active and there's a text selection
5222         // at the mouse position then do nothing
5223         if(rSh.GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
5224         {
5225             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
5226             ESelection aSelection = pOLV->GetSelection();
5227             if(!aSelection.IsZero())
5228             {
5229                 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
5230                 sal_Bool bVertical = pOutliner->IsVertical();
5231                 const EditEngine& rEditEng = pOutliner->GetEditEngine();
5232                 Point aEEPos(aDocPos);
5233                 const Rectangle& rOutputArea = pOLV->GetOutputArea();
5234                 // regard vertical mode
5235                 if(bVertical)
5236                 {
5237                     aEEPos -= rOutputArea.TopRight();
5238                     //invert the horizontal direction and exchange X and Y
5239                     long nTemp = -aEEPos.X();
5240                     aEEPos.X() = aEEPos.Y();
5241                     aEEPos.Y() = nTemp;
5242                 }
5243                 else
5244                     aEEPos -= rOutputArea.TopLeft();
5245 
5246                 EPosition aDocPosition = rEditEng.FindDocPosition(aEEPos);
5247                 ESelection aCompare(aDocPosition.nPara, aDocPosition.nIndex);
5248                 // make it a forward selection - otherwise the IsLess/IsGreater do not work :-(
5249                 aSelection.Adjust();
5250                 if(!aCompare.IsLess(aSelection)  && !aCompare.IsGreater(aSelection))
5251                 {
5252                     return sal_False;
5253                 }
5254             }
5255 
5256         }
5257 
5258         if (pSdrView->MouseButtonDown( aMEvt, this ) )
5259         {
5260             pSdrView->MouseButtonUp( aMEvt, this );
5261             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
5262             return sal_True;
5263         }
5264     }
5265     rSh.ResetCursorStack();
5266 
5267     if ( EnterDrawMode( aMEvt, aDocPos ) )
5268     {
5269         return sal_True;
5270     }
5271     if ( rView.GetDrawFuncPtr() && bInsFrm )
5272     {
5273         StopInsFrm();
5274         rSh.Edit();
5275     }
5276 
5277     UpdatePointer( aDocPos, 0 );
5278 
5279     if( !rSh.IsSelFrmMode() &&
5280         !GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
5281     {
5282         // #107513#
5283         // Test if there is a draw object at that position and if it should be selected.
5284         sal_Bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
5285 
5286         if(bShould)
5287         {
5288             rView.NoRotate();
5289             rSh.HideCrsr();
5290 
5291             sal_Bool bUnLockView = !rSh.IsViewLocked();
5292             rSh.LockView( sal_True );
5293             sal_Bool bSelObj = rSh.SelectObj( aDocPos, 0);
5294             if( bUnLockView )
5295                 rSh.LockView( sal_False );
5296 
5297             if( bSelObj )
5298             {
5299                 bRet = sal_True;
5300                 // falls im Macro der Rahmen deselektiert
5301                 // wurde, muss nur noch der Cursor
5302                 // wieder angezeigt werden.
5303                 if( FRMTYPE_NONE == rSh.GetSelFrmType() )
5304                     rSh.ShowCrsr();
5305                 else
5306                 {
5307                     if (rSh.IsFrmSelected() && rView.GetDrawFuncPtr())
5308                     {
5309                         rView.GetDrawFuncPtr()->Deactivate();
5310                         rView.SetDrawFuncPtr(NULL);
5311                         rView.LeaveDrawCreate();
5312                         rView.AttrChangedNotify( &rSh );
5313                     }
5314 
5315                     rSh.EnterSelFrmMode( &aDocPos );
5316                     bFrmDrag = sal_True;
5317                     UpdatePointer( aDocPos, 0 );
5318                     return bRet;
5319                 }
5320             }
5321 
5322             if (!rView.GetDrawFuncPtr())
5323                 rSh.ShowCrsr();
5324         }
5325     }
5326     else if ( rSh.IsSelFrmMode() &&
5327               (aActHitType == SDRHIT_NONE ||
5328                !bIsInsideSelectedObj))
5329     {
5330         rView.NoRotate();
5331         sal_Bool bUnLockView = !rSh.IsViewLocked();
5332         rSh.LockView( sal_True );
5333         sal_uInt8 nFlag = 0;
5334 
5335         if ( rSh.IsSelFrmMode() )
5336         {
5337             rSh.UnSelectFrm();
5338             rSh.LeaveSelFrmMode();
5339             rView.AttrChangedNotify(&rSh);
5340             bRet = sal_True;
5341         }
5342 
5343         sal_Bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
5344         if( bUnLockView )
5345             rSh.LockView( sal_False );
5346 
5347         if( !bSelObj )
5348         {
5349             // Cursor hier umsetzen, damit er nicht zuerst
5350             // im Rahmen gezeichnet wird; ShowCrsr() geschieht
5351             // in LeaveSelFrmMode()
5352             bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
5353             rSh.LeaveSelFrmMode();
5354             rView.LeaveDrawCreate();
5355             rView.AttrChangedNotify( &rSh );
5356             bRet = sal_True;
5357         }
5358         else
5359         {
5360             rSh.HideCrsr();
5361             rSh.EnterSelFrmMode( &aDocPos );
5362             rSh.SelFlyGrabCrsr();
5363             rSh.MakeSelVisible();
5364             bFrmDrag = sal_True;
5365             if( rSh.IsFrmSelected() &&
5366                 rView.GetDrawFuncPtr() )
5367             {
5368                 rView.GetDrawFuncPtr()->Deactivate();
5369                 rView.SetDrawFuncPtr(NULL);
5370                 rView.LeaveDrawCreate();
5371                 rView.AttrChangedNotify( &rSh );
5372             }
5373             UpdatePointer( aDocPos, 0 );
5374             bRet = sal_True;
5375         }
5376     }
5377     else if ( rSh.IsSelFrmMode() && bIsInsideSelectedObj )
5378     {
5379         // ## object at the mouse cursor is already selected - do nothing
5380         return sal_False;
5381     }
5382 
5383     if ( rSh.IsGCAttr() )
5384     {
5385         rSh.GCAttr();
5386         rSh.ClearGCAttr();
5387     }
5388 
5389     sal_Bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = sal_False;
5390     if( !bOverSelect )
5391         bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
5392 
5393     if ( !bOverSelect )
5394     {
5395         {   // nur temp. Move-Kontext aufspannen, da sonst die
5396             // Abfrage auf die Inhaltsform nicht funktioniert!!!
5397             MV_KONTEXT( &rSh );
5398             (rSh.*rSh.fnSetCrsr)(&aDocPos, sal_False);
5399             bRet = sal_True;
5400         }
5401     }
5402     if( !bOverURLGrf )
5403     {
5404         const int nSelType = rSh.GetSelectionType();
5405         if( nSelType == nsSelectionType::SEL_OLE ||
5406             nSelType == nsSelectionType::SEL_GRF )
5407         {
5408             MV_KONTEXT( &rSh );
5409             if( !rSh.IsFrmSelected() )
5410                 rSh.GotoNextFly();
5411             rSh.EnterSelFrmMode();
5412             bRet = sal_True;
5413         }
5414     }
5415     return bRet;
5416 }
5417 
lcl_GetShellFromDispatcher(SwView & rView,TypeId nType)5418 SfxShell* lcl_GetShellFromDispatcher( SwView& rView, TypeId nType )
5419 {
5420     //Shell ermitteln
5421     SfxShell* pShell;
5422     SfxDispatcher* pDispatcher = rView.GetViewFrame()->GetDispatcher();
5423     for(sal_uInt16  i = 0; sal_True; ++i )
5424     {
5425         pShell = pDispatcher->GetShell( i );
5426         if( !pShell || pShell->IsA( nType ) )
5427             break;
5428     }
5429     return pShell;
5430 }
5431 
5432 
5433 
ClearTip()5434 void SwEditWin::ClearTip()
5435 {
5436 }
5437 
IMPL_LINK(SwEditWin,KeyInputFlushHandler,Timer *,EMPTYARG)5438 IMPL_LINK( SwEditWin, KeyInputFlushHandler, Timer *, EMPTYARG )
5439 {
5440     FlushInBuffer();
5441     return 0;
5442 }
5443 
5444 
IMPL_LINK(SwEditWin,KeyInputTimerHandler,Timer *,EMPTYARG)5445 IMPL_LINK( SwEditWin, KeyInputTimerHandler, Timer *, EMPTYARG )
5446 {
5447     bTblInsDelMode = sal_False;
5448     return 0;
5449 }
5450 
_InitStaticData()5451 void SwEditWin::_InitStaticData()
5452 {
5453     pQuickHlpData = new QuickHelpData();
5454 }
5455 
_FinitStaticData()5456 void SwEditWin::_FinitStaticData()
5457 {
5458     delete pQuickHlpData;
5459 }
5460 /* -----------------23.01.2003 12:15-----------------
5461  * #i3370# remove quick help to prevent saving
5462  * of autocorrection suggestions
5463  * --------------------------------------------------*/
StopQuickHelp()5464 void SwEditWin::StopQuickHelp()
5465 {
5466     if( HasFocus() && pQuickHlpData && pQuickHlpData->bClear  )
5467         pQuickHlpData->Stop( rView.GetWrtShell() );
5468 }
5469 
5470 /*-----------------23.02.97 18:39-------------------
5471 
5472 --------------------------------------------------*/
5473 
5474 
IMPL_LINK(SwEditWin,TemplateTimerHdl,Timer *,EMPTYARG)5475 IMPL_LINK(SwEditWin, TemplateTimerHdl, Timer*, EMPTYARG)
5476 {
5477     SetApplyTemplate(SwApplyTemplate());
5478     return 0;
5479 }
5480 
5481 
SetChainMode(sal_Bool bOn)5482 void SwEditWin::SetChainMode( sal_Bool bOn )
5483 {
5484     if ( !bChainMode )
5485         StopInsFrm();
5486 
5487     if ( pUserMarker )
5488     {
5489         delete pUserMarker;
5490         pUserMarker = 0L;
5491     }
5492 
5493     bChainMode = bOn;
5494     if ( !bChainMode )
5495         rView.GetViewFrame()->HideStatusText();
5496 
5497     static sal_uInt16 __READONLY_DATA aInva[] =
5498     {
5499         FN_FRAME_CHAIN, FN_FRAME_UNCHAIN, 0
5500     };
5501     rView.GetViewFrame()->GetBindings().Invalidate(aInva);
5502 }
5503 
CreateAccessible()5504 uno::Reference< ::com::sun::star::accessibility::XAccessible > SwEditWin::CreateAccessible()
5505 {
5506     vos::OGuard aGuard(Application::GetSolarMutex());   // this should have
5507                                                         // happend already!!!
5508     SwWrtShell *pSh = rView.GetWrtShellPtr();
5509     ASSERT( pSh, "no writer shell, no accessible object" );
5510     uno::Reference<
5511         ::com::sun::star::accessibility::XAccessible > xAcc;
5512     if( pSh )
5513         xAcc = pSh->CreateAccessible();
5514 
5515     return xAcc;
5516 }
5517 
5518 //-------------------------------------------------------------
5519 
Move(QuickHelpData & rCpy)5520 void QuickHelpData::Move( QuickHelpData& rCpy )
5521 {
5522     // Pointer verschieben
5523     aArr.Insert( &rCpy.aArr );
5524     rCpy.aArr.Remove( (sal_uInt16)0, rCpy.aArr.Count() );
5525 //  nTipId = rCpy.nTipId;
5526     bClear = rCpy.bClear;
5527     nLen = rCpy.nLen;
5528     nCurArrPos = rCpy.nCurArrPos;
5529     bChkInsBlank = rCpy.bChkInsBlank;
5530     bIsTip = rCpy.bIsTip;
5531     bIsAutoText = rCpy.bIsAutoText;
5532 
5533     if( pCETID ) delete pCETID;
5534     pCETID = rCpy.pCETID;
5535     rCpy.pCETID = 0;
5536 
5537     if( pAttrs )
5538         delete[] pAttrs;
5539     pAttrs = rCpy.pAttrs;
5540     rCpy.pAttrs = 0;
5541 }
5542 
ClearCntnt()5543 void QuickHelpData::ClearCntnt()
5544 {
5545     nLen = nCurArrPos = 0;
5546     bClear = bChkInsBlank = sal_False;
5547     nTipId = 0;
5548     aArr.DeleteAndDestroy( 0 , aArr.Count() );
5549     bIsTip = sal_True;
5550     bIsAutoText = sal_True;
5551     delete pCETID, pCETID = 0;
5552     delete[] pAttrs, pAttrs = 0;
5553 }
5554 
5555 
Start(SwWrtShell & rSh,sal_uInt16 nWrdLen)5556 void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
5557 {
5558     if( pCETID ) delete pCETID, pCETID = 0;
5559     if( pAttrs ) delete[] pAttrs, pAttrs = 0;
5560 
5561     if( USHRT_MAX != nWrdLen )
5562     {
5563         nLen = nWrdLen;
5564         nCurArrPos = 0;
5565     }
5566     bClear = sal_True;
5567 
5568     Window& rWin = rSh.GetView().GetEditWin();
5569     if( bIsTip )
5570     {
5571         Point aPt( rWin.OutputToScreenPixel( rWin.LogicToPixel(
5572                     rSh.GetCharRect().Pos() )));
5573         aPt.Y() -= 3;
5574         nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )),
5575                         *aArr[ nCurArrPos ],
5576                         QUICKHELP_LEFT | QUICKHELP_BOTTOM );
5577     }
5578     else
5579     {
5580         String sStr( *aArr[ nCurArrPos ] );
5581         sStr.Erase( 0, nLen );
5582         sal_uInt16 nL = sStr.Len();
5583         pAttrs = new sal_uInt16[ nL ];
5584         for( sal_uInt16 n = nL; n;  )
5585             *(pAttrs + --n ) = EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE |
5586                                 EXTTEXTINPUT_ATTR_HIGHLIGHT;
5587         pCETID = new CommandExtTextInputData( sStr, pAttrs, nL,
5588                                                 0, 0, 0, sal_False );
5589         rSh.CreateExtTextInput(rWin.GetInputLanguage());
5590         rSh.SetExtTextInputData( *pCETID );
5591     }
5592 }
5593 
Stop(SwWrtShell & rSh)5594 void QuickHelpData::Stop( SwWrtShell& rSh )
5595 {
5596     if( !bIsTip )
5597         rSh.DeleteExtTextInput( 0, sal_False );
5598     else if( nTipId )
5599         Help::HideTip( nTipId );
5600     ClearCntnt();
5601 }
5602 
FillStrArr(SwWrtShell & rSh,const String & rWord)5603 void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
5604 {
5605     // #i22961# get the letter-case context
5606     const CharClass& rCharClass = GetAppCharClass();
5607     const String aLWord = rCharClass.toLower( rWord, 0, rWord.Len() );
5608     const bool bIsUpper = (rWord == rCharClass.toUpper( rWord, 0, rWord.Len() ) );
5609     const bool bIsLower = (rWord == aLWord);
5610 
5611     // add all matching month/day names from the calendar
5612     salhelper::SingletonRef<SwCalendarWrapper>* pCalendar = s_getCalendarWrapper();
5613     (*pCalendar)->LoadDefaultCalendar( rSh.GetCurLang() );
5614 
5615     {
5616         uno::Sequence< i18n::CalendarItem > aNames(
5617                                             (*pCalendar)->getMonths() );
5618         for( int n = 0; n < 2; ++n )
5619         {
5620             for( long nPos = 0, nEnd = aNames.getLength(); nPos < nEnd; ++nPos )
5621             {
5622                 const String& rS = aNames[ nPos ].FullName;
5623                 if( rS.Len() <= rWord.Len() + 1 )
5624                     continue;
5625                 const String aLName = rCharClass.toLower( rS, 0, rWord.Len() );
5626                 if( aLName != aLWord )
5627                     continue;
5628                 // #i22961# provide case-sensitive autocompletion suggestions
5629                 String* pNew = new String( (bIsUpper==bIsLower) ? rS : (bIsUpper ? rCharClass.toUpper(rS,0,rS.Len()) : rCharClass.toLower(rS,0,rS.Len())) );
5630                 if( !aArr.Insert( pNew ) )
5631                     delete pNew;
5632             }
5633             if( !n )                    // get data for the second loop
5634                 aNames = (*pCalendar)->getDays();
5635         }
5636     }
5637 
5638     // and then add all words from the AutoCompleteWord-List
5639     const SwAutoCompleteWord& rACLst = rSh.GetAutoCompleteWords();
5640     sal_uInt16 nStt, nEnd;
5641     if( rACLst.GetRange( rWord, nStt, nEnd ) )
5642     {
5643         for(; nStt < nEnd; ++nStt )
5644         {
5645             const String& rS = rACLst[ nStt ];
5646             if( rS.Len() <= rWord.Len() )
5647                 continue;
5648             // #i22961# provide case-sensitive autocompletion suggestions
5649             String* pNew = new String( (bIsUpper==bIsLower) ? rS : (bIsUpper ? rCharClass.toUpper(rS,0,rS.Len()) : rCharClass.toLower(rS,0,rS.Len())) );
5650             if( !aArr.Insert( pNew ) )
5651                 delete pNew;
5652         }
5653     }
5654 }
5655 
ShowAutoTextCorrectQuickHelp(const String & rWord,SvxAutoCorrCfg * pACfg,SvxAutoCorrect * pACorr,sal_Bool bFromIME)5656 void SwEditWin::ShowAutoTextCorrectQuickHelp(
5657         const String& rWord, SvxAutoCorrCfg* pACfg, SvxAutoCorrect* pACorr,
5658         sal_Bool bFromIME )
5659 {
5660     SwWrtShell& rSh = rView.GetWrtShell();
5661     pQuickHlpData->ClearCntnt();
5662     if( pACfg->IsAutoTextTip() )
5663     {
5664         SwGlossaryList* pList = ::GetGlossaryList();
5665         pList->HasLongName( rWord, &pQuickHlpData->aArr );
5666     }
5667 
5668     if( pQuickHlpData->aArr.Count() )
5669     {
5670         pQuickHlpData->bIsTip = sal_True;
5671         pQuickHlpData->bIsAutoText = sal_True;
5672     }
5673     else if( pACorr->GetSwFlags().bAutoCompleteWords )
5674     {
5675         pQuickHlpData->bIsAutoText = sal_False;
5676         pQuickHlpData->bIsTip = bFromIME ||
5677                     !pACorr ||
5678                     pACorr->GetSwFlags().bAutoCmpltShowAsTip;
5679 
5680         pQuickHlpData->FillStrArr( rSh, rWord );
5681     }
5682 
5683     if( pQuickHlpData->aArr.Count() )
5684         pQuickHlpData->Start( rSh, rWord.Len() );
5685 }
5686 
5687 /* -----------------29.03.2006 11:01-----------------
5688  *
5689  * --------------------------------------------------*/
5690 
SetUseInputLanguage(sal_Bool bNew)5691 void SwEditWin::SetUseInputLanguage( sal_Bool bNew )
5692 {
5693     if ( bNew || bUseInputLanguage )
5694     {
5695         SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
5696         rBind.Invalidate( SID_ATTR_CHAR_FONT );
5697         rBind.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
5698     }
5699     bUseInputLanguage = bNew;
5700 }
5701 
5702 /*-- 13.11.2008 10:18:17---------------------------------------------------
5703 
5704   -----------------------------------------------------------------------*/
GetSurroundingText() const5705 XubString SwEditWin::GetSurroundingText() const
5706 {
5707     String sReturn;
5708     SwWrtShell& rSh = rView.GetWrtShell();
5709     if( rSh.HasSelection() && !rSh.IsMultiSelection() && rSh.IsSelOnePara() )
5710         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5711     else if( !rSh.HasSelection() )
5712     {
5713         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
5714         xub_StrLen nPos = pPos->nContent.GetIndex();
5715 
5716         // get the sentence around the cursor
5717         rSh.HideCrsr();
5718         rSh.GoStartSentence();
5719         rSh.SetMark();
5720         rSh.GoEndSentence();
5721         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5722 
5723         pPos->nContent = nPos;
5724         rSh.ClearMark();
5725         rSh.HideCrsr();
5726     }
5727 
5728     return sReturn;
5729 }
5730 /*-- 13.11.2008 10:18:17---------------------------------------------------
5731 
5732   -----------------------------------------------------------------------*/
GetSurroundingTextSelection() const5733 Selection SwEditWin::GetSurroundingTextSelection() const
5734 {
5735     SwWrtShell& rSh = rView.GetWrtShell();
5736     if( rSh.HasSelection() )
5737     {
5738         String sReturn;
5739         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5740         return Selection( 0, sReturn.Len() );
5741     }
5742     else
5743     {
5744         // Return the position of the visible cursor in the sentence
5745         // around the visible cursor.
5746         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
5747         xub_StrLen nPos = pPos->nContent.GetIndex();
5748 
5749         rSh.HideCrsr();
5750         rSh.GoStartSentence();
5751         xub_StrLen nStartPos = rSh.GetCrsr()->GetPoint()->nContent.GetIndex();
5752 
5753         pPos->nContent = nPos;
5754         rSh.ClearMark();
5755         rSh.ShowCrsr();
5756 
5757         return Selection( nPos - nStartPos, nPos - nStartPos );
5758     }
5759 }
5760 // MT: Removed Windows::SwitchView() introduced with IA2 CWS.
5761 // There are other notifications for this when the active view has chnaged, so please update the code to use that event mechanism
SwitchView()5762 void SwEditWin::SwitchView()
5763 {
5764 #ifdef ACCESSIBLE_LAYOUT
5765 	if (!Application::IsAccessibilityEnabled())
5766 	{
5767 		return ;
5768 	}
5769 	rView.GetWrtShell().InvalidateAccessibleFocus();
5770 #endif
5771 }
5772