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