xref: /aoo41x/main/sw/source/ui/docvw/edtwin.cxx (revision 597675b0)
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                     OSL_ENSURE(pFieldmark->IsExpanded(),
2280                         "where is the otherpos?");
2281                     if (pFieldmark->IsExpanded())
2282                     {
2283                         rSh.CalcLayout();
2284                     }
2285                 }
2286                 eKeyState = KS_Ende;
2287             }
2288             else if(!rSh.HasReadonlySel())
2289             {
2290                 sal_Bool bIsNormalChar = GetAppCharClass().isLetterNumeric(
2291                                                             String( aCh ), 0 );
2292                 if( bChkInsBlank && bIsNormalChar &&
2293                     (aInBuffer.Len() || !rSh.IsSttPara() || !rSh.IsEndPara() ))
2294                 {
2295                     // vor dem Zeichen noch ein Blank einfuegen. Dieses
2296                     // kommt zwischen den Expandierten Text und dem neuen
2297                     // "nicht Worttrenner".
2298                     aInBuffer.Expand( aInBuffer.Len() + 1, ' ' );
2299                 }
2300 
2301 
2302                 sal_Bool bIsAutoCorrectChar =  SvxAutoCorrect::IsAutoCorrectChar( aCh );
2303                 sal_Bool bRunNext = pACorr && pACorr->HasRunNext();
2304                 if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
2305                         pACfg->IsAutoFmtByInput() &&
2306                     (( pACorr->IsAutoCorrFlag( ChgWeightUnderl ) &&
2307                         ( '*' == aCh || '_' == aCh ) ) ||
2308                      ( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
2309                      ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
2310                 {
2311                     FlushInBuffer();
2312                     rSh.AutoCorrect( *pACorr, aCh );
2313                     if( '\"' != aCh && '\'' != aCh )        // nur bei "*_" rufen!
2314                         rSh.UpdateAttr();
2315                 }
2316                 else if( !aKeyEvent.GetRepeat() && pACorr && ( bIsAutoCorrectChar || bRunNext ) &&
2317                         pACfg->IsAutoFmtByInput() &&
2318                     pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
2319                                             ChgOrdinalNumber | AddNonBrkSpace |
2320                                             ChgToEnEmDash | SetINetAttr |
2321                                             Autocorrect ) &&
2322                     '\"' != aCh && '\'' != aCh && '*' != aCh && '_' != aCh
2323                     )
2324                 {
2325                     FlushInBuffer();
2326                     rSh.AutoCorrect( *pACorr, aCh );
2327                 }
2328                 else
2329                 {
2330                     aInBuffer.Expand( aInBuffer.Len() + aKeyEvent.GetRepeat() + 1,aCh );
2331                     bFlushCharBuffer = Application::AnyInput( INPUT_KEYBOARD );
2332                     bFlushBuffer = !bFlushCharBuffer;
2333                     if( bFlushCharBuffer )
2334                         aKeyInputFlushTimer.Start();
2335                 }
2336                 eKeyState = KS_Ende;
2337             }
2338             else
2339             {
2340                 InfoBox( this, SW_RES( MSG_READONLY_CONTENT )).Execute();
2341                 eKeyState = KS_Ende;
2342             }
2343         break;
2344 
2345         case KS_CheckAutoCorrect:
2346         {
2347             if( pACorr && pACfg->IsAutoFmtByInput() &&
2348                 pACorr->IsAutoCorrFlag( CptlSttSntnc | CptlSttWrd |
2349                                         ChgOrdinalNumber |
2350                                         ChgToEnEmDash | SetINetAttr |
2351                                         Autocorrect ) &&
2352                 !rSh.HasReadonlySel() )
2353             {
2354                 FlushInBuffer();
2355                 rSh.AutoCorrect( *pACorr, static_cast< sal_Unicode >('\0') );
2356             }
2357             eKeyState = eNextKeyState;
2358         }
2359         break;
2360 
2361         default:
2362         {
2363             sal_uInt16 nSlotId = 0;
2364             FlushInBuffer();
2365             switch( eKeyState )
2366             {
2367             case KS_SpecialInsert:
2368                 rSh.DoSpecialInsert();
2369                 break;
2370 
2371             case KS_NoNum:
2372                 rSh.NoNum();
2373                 break;
2374 
2375             case KS_NumOff:
2376                 // Shellwechsel - also vorher aufzeichnen
2377                 rSh.DelNumRules();
2378                 eKeyState = eNextKeyState;
2379                 break;
2380             case KS_OutlineLvOff: // delete autofmt outlinelevel later
2381                 break;
2382 
2383             case KS_NumDown:
2384                 rSh.NumUpDown( sal_True );
2385                 nKS_NUMDOWN_Count = 2; // #i23725#
2386                 break;
2387             case KS_NumUp:
2388                 rSh.NumUpDown( sal_False );
2389                 break;
2390 
2391             case KS_NumIndentInc:
2392                 rSh.ChangeIndentOfAllListLevels(360);
2393                 nKS_NUMINDENTINC_Count = 2;
2394                 break;
2395 
2396             case KS_GotoNextFieldMark:
2397                 {
2398                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkAfter();
2399                     if(pFieldmark) rSh.GotoFieldmark(pFieldmark);
2400                 }
2401                 break;
2402 
2403             case KS_GotoPrevFieldMark:
2404                 {
2405                     ::sw::mark::IFieldmark const * const pFieldmark = rSh.GetFieldmarkBefore();
2406                     if(pFieldmark) rSh.GotoFieldmark(pFieldmark);
2407                 }
2408                 break;
2409 
2410             case KS_NumIndentDec:
2411                 rSh.ChangeIndentOfAllListLevels(-360);
2412                 // <--
2413                 break;
2414 
2415             case KS_OutlineDown:
2416                 rSh.OutlineUpDown( 1 );
2417                 break;
2418             case KS_OutlineUp:
2419                 rSh.OutlineUpDown( -1 );
2420                 break;
2421 
2422             case KS_NextCell:
2423                 //In Tabelle immer 'flushen'
2424                 rSh.GoNextCell();
2425                 nSlotId = FN_GOTO_NEXT_CELL;
2426                 break;
2427             case KS_PrevCell:
2428                 rSh.GoPrevCell();
2429                 nSlotId = FN_GOTO_PREV_CELL;
2430                 break;
2431             case KS_AutoFmtByInput:
2432                 rSh.SplitNode( sal_True );
2433                 break;
2434 
2435             case KS_NextObject:
2436             case KS_PrevObject:
2437                 if(rSh.GotoObj( KS_NextObject == eKeyState, GOTOOBJ_GOTO_ANY))
2438                 {
2439                     if( rSh.IsFrmSelected() &&
2440                         rView.GetDrawFuncPtr() )
2441                     {
2442                         rView.GetDrawFuncPtr()->Deactivate();
2443                         rView.SetDrawFuncPtr(NULL);
2444                         rView.LeaveDrawCreate();
2445                         rView.AttrChangedNotify( &rSh );
2446                     }
2447                     rSh.HideCrsr();
2448                     rSh.EnterSelFrmMode();
2449                 }
2450             break;
2451             case KS_GlossaryExpand:
2452             {
2453                 // ersetze das Wort oder Kuerzel durch den den Textbaustein
2454                 rSh.StartUndo( UNDO_START );
2455 
2456                 String sFnd( *aTmpQHD.aArr[ aTmpQHD.nCurArrPos ] );
2457                 if( aTmpQHD.bIsAutoText )
2458                 {
2459                     SwGlossaryList* pList = ::GetGlossaryList();
2460                     String sShrtNm;
2461                     String sGroup;
2462                     if(pList->GetShortName( sFnd, sShrtNm, sGroup))
2463                     {
2464                         rSh.SttSelect();
2465                         rSh.ExtendSelection( sal_False, aTmpQHD.nLen );
2466                         SwGlossaryHdl* pGlosHdl = GetView().GetGlosHdl();
2467                         pGlosHdl->SetCurGroup(sGroup, sal_True);
2468                         pGlosHdl->InsertGlossary( sShrtNm);
2469                         pQuickHlpData->bChkInsBlank = sal_True;
2470                     }
2471                 }
2472                 else
2473                 {
2474                     rSh.Insert( sFnd.Erase( 0, aTmpQHD.nLen ));
2475                     pQuickHlpData->bChkInsBlank = !pACorr ||
2476                             pACorr->GetSwFlags().bAutoCmpltAppendBlanc;
2477                 }
2478                 rSh.EndUndo( UNDO_END );
2479             }
2480             break;
2481 
2482             case KS_NextPrevGlossary:
2483                 pQuickHlpData->Move( aTmpQHD );
2484                 pQuickHlpData->Start( rSh, USHRT_MAX );
2485                 break;
2486 
2487             case KS_EditFormula:
2488             {
2489                 const sal_uInt16 nId = SwInputChild::GetChildWindowId();
2490 
2491                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
2492                 pVFrame->ToggleChildWindow( nId );
2493                 SwInputChild* pChildWin = (SwInputChild*)pVFrame->
2494                                                     GetChildWindow( nId );
2495                 if( pChildWin )
2496                     pChildWin->SetFormula( sFmlEntry );
2497             }
2498             break;
2499 
2500             case KS_ColLeftBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );   break;
2501             case KS_ColRightBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );  break;
2502             case KS_ColLeftSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTblHMove() );   break;
2503             case KS_ColRightSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTblHMove() );  break;
2504             case KS_ColBottomBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_ROW_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() ); break;
2505             case KS_ColBottomSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTblVMove() ); break;
2506             case KS_CellLeftBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() );  break;
2507             case KS_CellRightBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHMove() ); break;
2508             case KS_CellLeftSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTblHMove() );  break;
2509             case KS_CellRightSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTblHMove() ); break;
2510             case KS_CellTopBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() );   break;
2511             case KS_CellBottomBig:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVMove() );    break;
2512             case KS_CellTopSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTblVMove() );   break;
2513             case KS_CellBottomSmall:    rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTblVMove() );    break;
2514 
2515 //---------------
2516             case KS_InsDel_ColLeftBig:          rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() ); break;
2517             case KS_InsDel_ColRightBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );    break;
2518             case KS_InsDel_ColLeftSmall:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_LEFT, pModOpt->GetTblHInsert() ); break;
2519             case KS_InsDel_ColRightSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_COL_RIGHT, pModOpt->GetTblHInsert() );    break;
2520             case KS_InsDel_ColTopBig:           rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );  break;
2521             case KS_InsDel_ColBottomBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );   break;
2522             case KS_InsDel_ColTopSmall:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_TOP, pModOpt->GetTblVInsert() );  break;
2523             case KS_InsDel_ColBottomSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_ROW_BOTTOM, pModOpt->GetTblVInsert() );   break;
2524             case KS_InsDel_CellLeftBig:         rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_LEFT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );    break;
2525             case KS_InsDel_CellRightBig:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_RIGHT|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblHInsert() );   break;
2526             case KS_InsDel_CellLeftSmall:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_LEFT, pModOpt->GetTblHInsert() );    break;
2527             case KS_InsDel_CellRightSmall:      rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_RIGHT, pModOpt->GetTblHInsert() );   break;
2528             case KS_InsDel_CellTopBig:          rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_TOP|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() ); break;
2529             case KS_InsDel_CellBottomBig:       rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_BOTTOM|nsTblChgWidthHeightType::WH_FLAG_BIGGER, pModOpt->GetTblVInsert() );  break;
2530             case KS_InsDel_CellTopSmall:        rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_TOP, pModOpt->GetTblVInsert() ); break;
2531             case KS_InsDel_CellBottomSmall:     rSh.SetColRowWidthHeight( nsTblChgWidthHeightType::WH_FLAG_INSDEL|nsTblChgWidthHeightType::WH_CELL_BOTTOM, pModOpt->GetTblVInsert() );  break;
2532 //---------------
2533             case KS_TblColCellInsDel:
2534                 rSh.SetColRowWidthHeight( eTblChgMode, nTblChgSize );
2535                 break;
2536             case KS_Fly_Change:
2537             {
2538                 SdrView *pSdrView = rSh.GetDrawView();
2539                 const SdrHdlList& rHdlList = pSdrView->GetHdlList();
2540                 if(rHdlList.GetFocusHdl())
2541                     ChangeDrawing( nDir );
2542                 else
2543                     ChangeFly( nDir, rView.ISA( SwWebView ) );
2544             }
2545             break;
2546             case KS_Draw_Change :
2547                 ChangeDrawing( nDir );
2548                 break;
2549             default:; //prevent warning
2550             }
2551             if( nSlotId && rView.GetViewFrame()->GetBindings().GetRecorder().is() )
2552             {
2553                 SfxRequest aReq(rView.GetViewFrame(), nSlotId );
2554                 aReq.Done();
2555             }
2556             eKeyState = KS_Ende;
2557         }
2558         }
2559     }
2560 
2561     if( bStopKeyInputTimer )
2562     {
2563         aKeyInputTimer.Stop();
2564         bTblInsDelMode = sal_False;
2565     }
2566 
2567     // falls die gepufferten Zeichen eingefuegt werden sollen
2568     if( bFlushBuffer && aInBuffer.Len() )
2569     {
2570         //OS 16.02.96 11.04: bFlushCharBuffer wurde hier nicht zurueckgesetzt
2571         // warum nicht?
2572         sal_Bool bSave = bFlushCharBuffer;
2573         FlushInBuffer();
2574         bFlushCharBuffer = bSave;
2575 
2576         // evt. Tip-Hilfe anzeigen
2577         String sWord;
2578         if( bNormalChar && pACfg && pACorr &&
2579             ( pACfg->IsAutoTextTip() ||
2580               pACorr->GetSwFlags().bAutoCompleteWords ) &&
2581             rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
2582         {
2583             ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr);
2584         }
2585     }
2586 }
2587 
2588 /*--------------------------------------------------------------------
2589      Beschreibung:  MouseEvents
2590  --------------------------------------------------------------------*/
2591 
2592 
2593 void SwEditWin::RstMBDownFlags()
2594 {
2595     //Nicht auf allen Systemen kommt vor dem modalen
2596     //Dialog noch ein MouseButton Up (wie unter WINDOWS).
2597     //Daher hier die Stati zuruecksetzen und die Maus
2598     //fuer den Dialog freigeben.
2599     bMBPressed = bNoInterrupt = sal_False;
2600     EnterArea();
2601     ReleaseMouse();
2602 }
2603 
2604 
2605 
2606 void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
2607 {
2608     SwWrtShell &rSh = rView.GetWrtShell();
2609 
2610     // We have to check if a context menu is shown and we have an UI
2611     // active inplace client. In that case we have to ignore the mouse
2612     // button down event. Otherwise we would crash (context menu has been
2613     // opened by inplace client and we would deactivate the inplace client,
2614     // the contex menu is closed by VCL asynchronously which in the end
2615     // would work on deleted objects or the context menu has no parent anymore)
2616     // See #126086# and #128122#
2617     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
2618     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
2619 
2620     if ( bIsOleActive && PopupMenu::IsInExecute() )
2621         return;
2622 
2623     MouseEvent rMEvt(_rMEvt);
2624 
2625     if (rView.GetPostItMgr()->IsHit(rMEvt.GetPosPixel()))
2626         return;
2627 
2628     rView.GetPostItMgr()->SetActiveSidebarWin(0);
2629 
2630     GrabFocus();
2631 
2632     //ignore key modifiers for format paintbrush
2633     {
2634         sal_Bool bExecFormatPaintbrush = pApplyTempl && pApplyTempl->pFormatClipboard
2635                                 &&  pApplyTempl->pFormatClipboard->HasContent();
2636         if( bExecFormatPaintbrush )
2637             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
2638                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
2639     }
2640 
2641     bWasShdwCrsr = 0 != pShadCrsr;
2642     if( bWasShdwCrsr )
2643         delete pShadCrsr, pShadCrsr = 0;
2644 
2645     const Point aDocPos( PixelToLogic( rMEvt.GetPosPixel() ) );
2646 
2647     if ( IsChainMode() )
2648     {
2649         SetChainMode( sal_False );
2650         SwRect aDummy;
2651         SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)rSh.GetFlyFrmFmt();
2652         if ( !rSh.Chainable( aDummy, *pFmt, aDocPos ) )
2653             rSh.Chain( *pFmt, aDocPos );
2654         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2655         return;
2656     }
2657 
2658     //Nach GrabFocus sollte eine Shell gepusht sein. Das muss eigentlich
2659     //klappen aber in der Praxis ...
2660     lcl_SelectShellForDrop( rView );
2661 
2662     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly();
2663     sal_Bool bCallBase = sal_True;
2664 
2665     if( pQuickHlpData->bClear )
2666         pQuickHlpData->Stop( rSh );
2667     pQuickHlpData->bChkInsBlank = sal_False;
2668 
2669     if( rSh.FinishOLEObj() )
2670         return; //InPlace beenden und der Klick zaehlt nicht mehr
2671 
2672     SET_CURR_SHELL( &rSh );
2673 
2674     SdrView *pSdrView = rSh.GetDrawView();
2675     if ( pSdrView )
2676     {
2677         if (pSdrView->MouseButtonDown( rMEvt, this ) )
2678         {
2679             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
2680             return; // Event von der SdrView ausgewertet
2681         }
2682     }
2683 
2684 
2685     bIsInMove = sal_False;
2686     aStartPos = rMEvt.GetPosPixel();
2687     aRszMvHdlPt.X() = 0, aRszMvHdlPt.Y() = 0;
2688 
2689     sal_uInt8 nMouseTabCol = 0;
2690     const sal_Bool bTmp = !rSh.IsDrawCreate() && !pApplyTempl && !rSh.IsInSelect() &&
2691          rMEvt.GetClicks() == 1 && MOUSE_LEFT == rMEvt.GetButtons();
2692     if (  bTmp &&
2693          0 != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPos ) ) &&
2694          !rSh.IsObjSelectable( aDocPos ) )
2695     {
2696         // Enhanced table selection
2697         if ( SW_TABSEL_HORI <= nMouseTabCol && SW_TABCOLSEL_VERT >= nMouseTabCol )
2698         {
2699             rSh.EnterStdMode();
2700             rSh.SelectTableRowCol( aDocPos );
2701             if( SW_TABSEL_HORI  != nMouseTabCol && SW_TABSEL_HORI_RTL  != nMouseTabCol)
2702             {
2703                 pRowColumnSelectionStart = new Point( aDocPos );
2704                 bIsRowDrag = SW_TABROWSEL_HORI == nMouseTabCol||
2705                             SW_TABROWSEL_HORI_RTL == nMouseTabCol ||
2706                             SW_TABCOLSEL_VERT == nMouseTabCol;
2707                 bMBPressed = sal_True;
2708                 CaptureMouse();
2709             }
2710             return;
2711         }
2712 
2713         if ( !rSh.IsTableMode() )
2714         {
2715             //Zuppeln von Tabellenspalten aus dem Dokument heraus.
2716             if(SW_TABCOL_VERT == nMouseTabCol || SW_TABCOL_HORI == nMouseTabCol)
2717                 rView.SetTabColFromDoc( sal_True );
2718             else
2719                 rView.SetTabRowFromDoc( sal_True );
2720 
2721             rView.SetTabColFromDocPos( aDocPos );
2722             rView.InvalidateRulerPos();
2723             SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
2724             rBind.Update();
2725             if ( RulerColumnDrag( rMEvt,
2726                     (SW_TABCOL_VERT == nMouseTabCol || SW_TABROW_HORI == nMouseTabCol)) )
2727             {
2728                 rView.SetTabColFromDoc( sal_False );
2729                 rView.SetTabRowFromDoc( sal_False );
2730                 rView.InvalidateRulerPos();
2731                 rBind.Update();
2732                 bCallBase = sal_False;
2733             }
2734             else
2735             {
2736                 return;
2737             }
2738         }
2739     }
2740     else if (bTmp &&
2741              rSh.IsNumLabel(aDocPos))
2742     {
2743         SwTxtNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPos );
2744         rView.SetNumRuleNodeFromDoc( pNodeAtPos );
2745         rView.InvalidateRulerPos();
2746         SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
2747         rBind.Update();
2748 
2749         if ( RulerMarginDrag( rMEvt,
2750                         rSh.IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPos ) ) )
2751         {
2752             rView.SetNumRuleNodeFromDoc( NULL );
2753             rView.InvalidateRulerPos();
2754             rBind.Update();
2755             bCallBase = sal_False;
2756         }
2757         else
2758         {
2759             // Make sure the pointer is set to 0, otherwise it may point to
2760             // nowhere after deleting the corresponding text node.
2761             rView.SetNumRuleNodeFromDoc( NULL );
2762             return;
2763         }
2764     }
2765 
2766     //Man kann sich in einem Selektionszustand befinden, wenn zuletzt
2767     //mit dem Keyboard selektiert wurde, aber noch kein CURSOR_KEY
2768     //anschliessend bewegt worden ist. In diesem Fall muss die vorher-
2769     //gehende Selektion zuerst beendet werden.
2770     //MA 07. Oct. 95: Und zwar nicht nur bei Linker Maustaste sondern immer.
2771     //siehe auch Bug: 19263
2772     if ( rSh.IsInSelect() )
2773         rSh.EndSelect();
2774 
2775     //Abfrage auf LEFT, da sonst auch bei einem Click mit der rechten Taste
2776     //beispielsweise die Selektion aufgehoben wird.
2777     if ( MOUSE_LEFT == rMEvt.GetButtons() )
2778     {
2779         sal_Bool bOnlyText = sal_False;
2780         bMBPressed = bNoInterrupt = sal_True;
2781         nKS_NUMDOWN_Count = 0; // #i23725#
2782 
2783         CaptureMouse();
2784 
2785         //ggf. Cursorpositionen zuruecksetzen
2786         rSh.ResetCursorStack();
2787 
2788         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
2789         {
2790             case MOUSE_LEFT:
2791             case MOUSE_LEFT + KEY_SHIFT:
2792             case MOUSE_LEFT + KEY_MOD2:
2793                 if( rSh.IsObjSelected() )
2794                 {
2795                     SdrHdl* pHdl;
2796                     if( !bIsDocReadOnly &&
2797                         !pAnchorMarker &&
2798                         0 != ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
2799                             ( pHdl->GetKind() == HDL_ANCHOR ||
2800                               pHdl->GetKind() == HDL_ANCHOR_TR ) )
2801                     {
2802                         // Set selected during drag
2803                         pHdl->SetSelected(true);
2804                         pAnchorMarker = new SwAnchorMarker( pHdl );
2805                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2806                         return;
2807                     }
2808                 }
2809                 if ( EnterDrawMode( rMEvt, aDocPos ) )
2810                 {
2811                     bNoInterrupt = sal_False;
2812                     return;
2813                 }
2814                 else  if ( rView.GetDrawFuncPtr() && bInsFrm )
2815                 {
2816                     StopInsFrm();
2817                     rSh.Edit();
2818                 }
2819 
2820                 // Ohne SHIFT, da sonst Toggle bei Selektion nicht funktioniert
2821                 if (rMEvt.GetClicks() == 1)
2822                 {
2823                     if ( rSh.IsSelFrmMode())
2824                     {
2825                         SdrHdl* pHdl = rSh.GetDrawView()->PickHandle(aDocPos);
2826                         sal_Bool bHitHandle = pHdl && pHdl->GetKind() != HDL_ANCHOR &&
2827                                                   pHdl->GetKind() != HDL_ANCHOR_TR;
2828 
2829                         if ((rSh.IsInsideSelectedObj(aDocPos) || bHitHandle) &&
2830                             !(rMEvt.GetModifier() == KEY_SHIFT && !bHitHandle))
2831                         {
2832                             rSh.EnterSelFrmMode( &aDocPos );
2833                             if ( !pApplyTempl )
2834                             {
2835                                 //nur, wenn keine Position zum Sizen getroffen ist.
2836                                 if (!bHitHandle)
2837                                 {
2838                                     StartDDTimer();
2839                                     SwEditWin::nDDStartPosY = aDocPos.Y();
2840                                     SwEditWin::nDDStartPosX = aDocPos.X();
2841                                 }
2842                                 bFrmDrag = sal_True;
2843                             }
2844                             bNoInterrupt = sal_False;
2845                             return;
2846                         }
2847                     }
2848                 }
2849         }
2850 
2851         sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
2852         if ( !bExecHyperlinks )
2853         {
2854             SvtSecurityOptions aSecOpts;
2855             const sal_Bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
2856             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
2857                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
2858                 bExecHyperlinks = sal_True;
2859         }
2860 
2861         // Enhanced selection
2862         sal_uInt8 nNumberOfClicks = static_cast< sal_uInt8 >(rMEvt.GetClicks() % 4);
2863         if ( 0 == nNumberOfClicks && 0 < rMEvt.GetClicks() )
2864             nNumberOfClicks = 4;
2865 
2866         sal_Bool bExecDrawTextLink = sal_False;
2867 
2868         switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
2869         {
2870             case MOUSE_LEFT:
2871             case MOUSE_LEFT + KEY_MOD1:
2872             case MOUSE_LEFT + KEY_MOD2:
2873                 switch ( nNumberOfClicks )
2874                 {
2875                     case 1:
2876                     {
2877                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2878                         SwEditWin::nDDStartPosY = aDocPos.Y();
2879                         SwEditWin::nDDStartPosX = aDocPos.X();
2880 
2881                         // URL in DrawText-Objekt getroffen?
2882                         if (bExecHyperlinks && pSdrView)
2883                         {
2884                             SdrViewEvent aVEvt;
2885                             pSdrView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
2886 
2887                             if (aVEvt.eEvent == SDREVENT_EXECUTEURL)
2888                                 bExecDrawTextLink = sal_True;
2889                         }
2890 
2891                         //Rahmen nur zu selektieren versuchen, wenn
2892                         //der Pointer bereits entsprechend geschaltet wurde
2893                         if ( aActHitType != SDRHIT_NONE && !rSh.IsSelFrmMode() &&
2894                             !GetView().GetViewFrame()->GetDispatcher()->IsLocked() &&
2895                             !bExecDrawTextLink)
2896                         {
2897                             // Test if there is a draw object at that position and if it should be selected.
2898                             sal_Bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
2899 
2900                             if(bShould)
2901                             {
2902                                 rView.NoRotate();
2903                                 rSh.HideCrsr();
2904 
2905                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
2906                                 rSh.LockView( sal_True );
2907                                 sal_Bool bSelObj = rSh.SelectObj( aDocPos,
2908                                                rMEvt.IsMod1() ? SW_ENTER_GROUP : 0);
2909                                 if( bUnLockView )
2910                                     rSh.LockView( sal_False );
2911 
2912                                 if( bSelObj )
2913                                 {
2914                                     // falls im Macro der Rahmen deselektiert
2915                                     // wurde, muss nur noch der Cursor
2916                                     // wieder angezeigt werden.
2917                                     if( FRMTYPE_NONE == rSh.GetSelFrmType() )
2918                                         rSh.ShowCrsr();
2919                                     else
2920                                     {
2921                                         if (rSh.IsFrmSelected() && rView.GetDrawFuncPtr())
2922                                         {
2923                                             rView.GetDrawFuncPtr()->Deactivate();
2924                                             rView.SetDrawFuncPtr(NULL);
2925                                             rView.LeaveDrawCreate();
2926                                             rView.AttrChangedNotify( &rSh );
2927                                         }
2928 
2929                                         rSh.EnterSelFrmMode( &aDocPos );
2930                                         bFrmDrag = sal_True;
2931                                         UpdatePointer( aDocPos, rMEvt.GetModifier() );
2932                                     }
2933                                     return;
2934                                 }
2935                                 else
2936                                     bOnlyText = static_cast< sal_Bool >(rSh.IsObjSelectable( aDocPos ));
2937 
2938                                 if (!rView.GetDrawFuncPtr())
2939                                     rSh.ShowCrsr();
2940                             }
2941                             else
2942                                 bOnlyText = KEY_MOD1 != rMEvt.GetModifier();
2943                         }
2944                         else if ( rSh.IsSelFrmMode() &&
2945                                   (aActHitType == SDRHIT_NONE ||
2946                                    !rSh.IsInsideSelectedObj( aDocPos )))
2947                         {
2948                             rView.NoRotate();
2949                             SdrHdl *pHdl;
2950                             if( !bIsDocReadOnly && !pAnchorMarker && 0 !=
2951                                 ( pHdl = pSdrView->PickHandle(aDocPos) ) &&
2952                                     ( pHdl->GetKind() == HDL_ANCHOR ||
2953                                       pHdl->GetKind() == HDL_ANCHOR_TR ) )
2954                             {
2955                                 pAnchorMarker = new SwAnchorMarker( pHdl );
2956                                 UpdatePointer( aDocPos, rMEvt.GetModifier() );
2957                                 return;
2958                             }
2959                             else
2960                             {
2961                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
2962                                 rSh.LockView( sal_True );
2963                                 sal_uInt8 nFlag = rMEvt.IsShift() ? SW_ADD_SELECT :0;
2964                                 if( rMEvt.IsMod1() )
2965                                     nFlag = nFlag | SW_ENTER_GROUP;
2966 
2967                                 if ( rSh.IsSelFrmMode() )
2968                                 {
2969                                     rSh.UnSelectFrm();
2970                                     rSh.LeaveSelFrmMode();
2971                                     rView.AttrChangedNotify(&rSh);
2972                                 }
2973 
2974                                 sal_Bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
2975                                 if( bUnLockView )
2976                                     rSh.LockView( sal_False );
2977 
2978                                 if( !bSelObj )
2979                                 {
2980                                     // Cursor hier umsetzen, damit er nicht zuerst
2981                                     // im Rahmen gezeichnet wird; ShowCrsr() geschieht
2982                                     // in LeaveSelFrmMode()
2983                                     bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
2984                                     rSh.LeaveSelFrmMode();
2985                                     rView.AttrChangedNotify( &rSh );
2986                                     bCallBase = sal_False;
2987                                 }
2988                                 else
2989                                 {
2990                                     rSh.HideCrsr();
2991                                     rSh.EnterSelFrmMode( &aDocPos );
2992                                     rSh.SelFlyGrabCrsr();
2993                                     rSh.MakeSelVisible();
2994                                     bFrmDrag = sal_True;
2995                                     if( rSh.IsFrmSelected() &&
2996                                         rView.GetDrawFuncPtr() )
2997                                     {
2998                                         rView.GetDrawFuncPtr()->Deactivate();
2999                                         rView.SetDrawFuncPtr(NULL);
3000                                         rView.LeaveDrawCreate();
3001                                         rView.AttrChangedNotify( &rSh );
3002                                     }
3003                                     UpdatePointer( aDocPos, rMEvt.GetModifier() );
3004                                     return;
3005                                 }
3006                             }
3007                         }
3008 
3009                         break;
3010                     }
3011                     case 2:
3012                     {
3013                         bFrmDrag = sal_False;
3014                         if ( !bIsDocReadOnly && rSh.IsInsideSelectedObj(aDocPos) &&
3015                              0 == rSh.IsSelObjProtected( FLYPROTECT_CONTENT|FLYPROTECT_PARENT ) )
3016 
3017 /* 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)
3018    on the other hand the return value is used in a switch without proper masking (very nice), this must lead to trouble
3019 */
3020                         switch ( rSh.GetSelectionType() &~ ( nsSelectionType::SEL_FONTWORK | nsSelectionType::SEL_EXTRUDED_CUSTOMSHAPE ) )
3021                         {
3022                             case nsSelectionType::SEL_GRF:
3023                                 RstMBDownFlags();
3024                                 GetView().GetViewFrame()->GetBindings().Execute(
3025                                     FN_FORMAT_GRAFIC_DLG, 0, 0,
3026                                     SFX_CALLMODE_RECORD|SFX_CALLMODE_SLOT);
3027                                 return;
3028 
3029                                 // Doppelklick auf OLE-Objekt --> OLE-InPlace
3030                             case nsSelectionType::SEL_OLE:
3031                                 if (!rSh.IsSelObjProtected(FLYPROTECT_CONTENT))
3032                                 {
3033                                     RstMBDownFlags();
3034                                     rSh.LaunchOLEObj();
3035                                 }
3036                                 return;
3037 
3038                             case nsSelectionType::SEL_FRM:
3039                                 RstMBDownFlags();
3040                                 GetView().GetViewFrame()->GetBindings().Execute(
3041                                     FN_FORMAT_FRAME_DLG, 0, 0, SFX_CALLMODE_RECORD|SFX_CALLMODE_SLOT);
3042                                 return;
3043 
3044                             case nsSelectionType::SEL_DRW:
3045                                 RstMBDownFlags();
3046                                 EnterDrawTextMode(aDocPos);
3047                                 if ( rView.GetCurShell()->ISA(SwDrawTextShell) )
3048                                     ((SwDrawTextShell*)rView.GetCurShell())->Init();
3049                                 return;
3050                         }
3051 
3052                         //falls die Cursorposition korrigiert wurde oder
3053                         // ein Fly im ReadOnlyModus selektiert ist,
3054                         //keine Wortselektion.
3055                         if ( !bValidCrsrPos ||
3056                             (rSh.IsFrmSelected() && rSh.IsFrmSelected() ))
3057                             return;
3058 
3059                         SwField *pFld;
3060                         sal_Bool bFtn = sal_False;
3061 
3062                         if( !bIsDocReadOnly &&
3063                             ( 0 != ( pFld = rSh.GetCurFld() ) ||
3064                               0 != ( bFtn = rSh.GetCurFtn() )) )
3065                         {
3066                             RstMBDownFlags();
3067                             if( bFtn )
3068                                 GetView().GetViewFrame()->GetBindings().Execute( FN_EDIT_FOOTNOTE );
3069                             else
3070                             {
3071                                 sal_uInt16 nTypeId = pFld->GetTypeId();
3072                                 SfxViewFrame* pVFrame = GetView().GetViewFrame();
3073                                 switch( nTypeId )
3074                                 {
3075                                 case TYP_POSTITFLD:
3076                                 case TYP_SCRIPTFLD:
3077                                 {
3078                                     //falls es ein Readonly-Bereich ist, dann muss der Status
3079                                     //enabled werden
3080                                     sal_uInt16 nSlot = TYP_POSTITFLD == nTypeId ? FN_POSTIT : FN_JAVAEDIT;
3081                                     SfxBoolItem aItem(nSlot, sal_True);
3082                                     pVFrame->GetBindings().SetState(aItem);
3083                                     pVFrame->GetBindings().Execute(nSlot);
3084                                     break;
3085                                 }
3086                                 case TYP_AUTHORITY :
3087                                     pVFrame->GetBindings().Execute(FN_EDIT_AUTH_ENTRY_DLG);
3088                                 break;
3089                                 default:
3090                                     pVFrame->GetBindings().Execute(FN_EDIT_FIELD);
3091                                 }
3092                             }
3093                             return;
3094                         }
3095                         //im Extended Mode hat Doppel- und
3096                         //Dreifachklick keine Auswirkungen.
3097                         if ( rSh.IsExtMode() || rSh.IsBlockMode() )
3098                             return;
3099 
3100                         //Wort selektieren, gfs. Additional Mode
3101                         if ( KEY_MOD1 == rMEvt.GetModifier() && !rSh.IsAddMode() )
3102                         {
3103                             rSh.EnterAddMode();
3104                             rSh.SelWrd( &aDocPos );
3105                             rSh.LeaveAddMode();
3106                         }
3107                         else
3108                             rSh.SelWrd( &aDocPos );
3109                         bHoldSelection = sal_True;
3110                         return;
3111                     }
3112                     case 3:
3113                     case 4:
3114                     {
3115                         bFrmDrag = sal_False;
3116                         //im Extended Mode hat Doppel- und
3117                         //Dreifachklick keine Auswirkungen.
3118                         if ( rSh.IsExtMode() )
3119                             return;
3120 
3121                         //falls die Cursorposition korrigiert wurde oder
3122                         // ein Fly im ReadOnlyModus selektiert ist,
3123                         //keine Wortselektion.
3124                         if ( !bValidCrsrPos || rSh.IsFrmSelected() )
3125                             return;
3126 
3127                         //Zeile selektieren, gfs. Additional Mode
3128                         const bool bMod = KEY_MOD1 == rMEvt.GetModifier() &&
3129                                          !rSh.IsAddMode();
3130 
3131                         if ( bMod )
3132                             rSh.EnterAddMode();
3133 
3134                         // Enhanced selection
3135                         if ( 3 == nNumberOfClicks )
3136                             rSh.SelSentence( &aDocPos );
3137                         else
3138                             rSh.SelPara( &aDocPos );
3139 
3140                         if ( bMod )
3141                             rSh.LeaveAddMode();
3142 
3143                         bHoldSelection = sal_True;
3144                         return;
3145                     }
3146 
3147                     default:
3148                         return;
3149                 }
3150                 /* no break */
3151             case MOUSE_LEFT + KEY_SHIFT:
3152             case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
3153             {
3154                 sal_Bool bLockView = bWasShdwCrsr;
3155 
3156                 switch ( rMEvt.GetModifier() )
3157                 {
3158                     case KEY_MOD1 + KEY_SHIFT:
3159                     {
3160                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3161                         {
3162                             rView.NoRotate();
3163                             rSh.HideCrsr();
3164                             if ( rSh.IsSelFrmMode() )
3165                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP);
3166                             else
3167                             {   if ( rSh.SelectObj( aDocPos, SW_ADD_SELECT | SW_ENTER_GROUP ) )
3168                                 {
3169                                     rSh.EnterSelFrmMode( &aDocPos );
3170                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3171                                     SwEditWin::nDDStartPosX = aDocPos.X();
3172                                     bFrmDrag = sal_True;
3173                                     return;
3174                                 }
3175                             }
3176                         }
3177                         else if( rSh.IsSelFrmMode() &&
3178                                  rSh.GetDrawView()->PickHandle( aDocPos ))
3179                         {
3180                             bFrmDrag = sal_True;
3181                             bNoInterrupt = sal_False;
3182                             return;
3183                         }
3184                     }
3185                     break;
3186                     case KEY_MOD1:
3187                     if ( !bExecDrawTextLink )
3188                     {
3189                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3190                         {
3191                             rView.NoRotate();
3192                             rSh.HideCrsr();
3193                             if ( rSh.IsSelFrmMode() )
3194                                 rSh.SelectObj(aDocPos, SW_ENTER_GROUP);
3195                             else
3196                             {   if ( rSh.SelectObj( aDocPos, SW_ENTER_GROUP ) )
3197                                 {
3198                                     rSh.EnterSelFrmMode( &aDocPos );
3199                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3200                                     SwEditWin::nDDStartPosX = aDocPos.X();
3201                                     bFrmDrag = sal_True;
3202                                     return;
3203                                 }
3204                             }
3205                         }
3206                         else if( rSh.IsSelFrmMode() &&
3207                                  rSh.GetDrawView()->PickHandle( aDocPos ))
3208                         {
3209                             bFrmDrag = sal_True;
3210                             bNoInterrupt = sal_False;
3211                             return;
3212                         }
3213                         else
3214                         {
3215                             if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
3216                             {
3217                                 rSh.PushMode();
3218                                 bModePushed = sal_True;
3219 
3220                                 sal_Bool bUnLockView = !rSh.IsViewLocked();
3221                                 rSh.LockView( sal_True );
3222                                 rSh.EnterAddMode();
3223                                 if( bUnLockView )
3224                                     rSh.LockView( sal_False );
3225                             }
3226                             bCallBase = sal_False;
3227                         }
3228                     }
3229                     break;
3230                     case KEY_MOD2:
3231                     {
3232                         if ( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
3233                         {
3234                             rSh.PushMode();
3235                             bModePushed = sal_True;
3236                             sal_Bool bUnLockView = !rSh.IsViewLocked();
3237                             rSh.LockView( sal_True );
3238                             rSh.EnterBlockMode();
3239                             if( bUnLockView )
3240                                 rSh.LockView( sal_False );
3241                         }
3242                         bCallBase = sal_False;
3243                     }
3244                     break;
3245                     case KEY_SHIFT:
3246                     {
3247                         if ( !bInsDraw && IsDrawObjSelectable( rSh, aDocPos ) )
3248                         {
3249                             rView.NoRotate();
3250                             rSh.HideCrsr();
3251                             if ( rSh.IsSelFrmMode() )
3252                             {
3253                                 rSh.SelectObj(aDocPos, SW_ADD_SELECT);
3254 
3255                                 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
3256                                 if (rMarkList.GetMark(0) == NULL)
3257                                 {
3258                                     rSh.LeaveSelFrmMode();
3259                                     rView.AttrChangedNotify(&rSh);
3260                                     bFrmDrag = sal_False;
3261                                 }
3262                             }
3263                             else
3264                             {   if ( rSh.SelectObj( aDocPos ) )
3265                                 {
3266                                     rSh.EnterSelFrmMode( &aDocPos );
3267                                     SwEditWin::nDDStartPosY = aDocPos.Y();
3268                                     SwEditWin::nDDStartPosX = aDocPos.X();
3269                                     bFrmDrag = sal_True;
3270                                     return;
3271                                 }
3272                             }
3273                         }
3274                         else
3275                         {
3276                             if ( rSh.IsSelFrmMode() &&
3277                                  rSh.IsInsideSelectedObj( aDocPos ) )
3278                             {
3279                                 rSh.EnterSelFrmMode( &aDocPos );
3280                                 SwEditWin::nDDStartPosY = aDocPos.Y();
3281                                 SwEditWin::nDDStartPosX = aDocPos.X();
3282                                 bFrmDrag = sal_True;
3283                                 return;
3284                             }
3285                             if ( rSh.IsSelFrmMode() )
3286                             {
3287                                 rSh.UnSelectFrm();
3288                                 rSh.LeaveSelFrmMode();
3289                                 rView.AttrChangedNotify(&rSh);
3290                                 bFrmDrag = sal_False;
3291                             }
3292                             if ( !rSh.IsExtMode() )
3293                             {
3294                                 // keine Selection anfangen, wenn in ein URL-
3295                                 // Feld oder eine -Grafik geklickt wird
3296                                 sal_Bool bSttSelect = rSh.HasSelection() ||
3297                                                 Pointer(POINTER_REFHAND) != GetPointer();
3298 
3299                                 if( !bSttSelect )
3300                                 {
3301                                     bSttSelect = sal_True;
3302                                     if( bExecHyperlinks )
3303                                     {
3304                                         SwContentAtPos aCntntAtPos(
3305                                             SwContentAtPos::SW_FTN |
3306                                             SwContentAtPos::SW_INETATTR );
3307 
3308                                         if( rSh.GetContentAtPos( aDocPos, aCntntAtPos ) )
3309                                         {
3310                                             if( !rSh.IsViewLocked() &&
3311                                                 !rSh.IsReadOnlyAvailable() &&
3312                                                 aCntntAtPos.IsInProtectSect() )
3313                                                     bLockView = sal_True;
3314 
3315                                             bSttSelect = sal_False;
3316                                         }
3317                                         else if( rSh.IsURLGrfAtPos( aDocPos ))
3318                                             bSttSelect = sal_False;
3319                                     }
3320                                 }
3321 
3322                                 if( bSttSelect )
3323                                     rSh.SttSelect();
3324                             }
3325                         }
3326                         bCallBase = sal_False;
3327                         break;
3328                     }
3329                     default:
3330                         if( !rSh.IsViewLocked() )
3331                         {
3332                             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_CLICKFIELD |
3333                                                         SwContentAtPos::SW_INETATTR );
3334                             if( rSh.GetContentAtPos( aDocPos, aCntntAtPos, sal_False ) &&
3335                                 !rSh.IsReadOnlyAvailable() &&
3336                                 aCntntAtPos.IsInProtectSect() )
3337                                 bLockView = sal_True;
3338                         }
3339                 }
3340 
3341                 if ( rSh.IsGCAttr() )
3342                 {
3343                     rSh.GCAttr();
3344                     rSh.ClearGCAttr();
3345                 }
3346 
3347                 sal_Bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = sal_False;
3348                 if( !bOverSelect )
3349                     bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
3350 
3351                 if ( !bOverSelect )
3352                 {
3353                     const sal_Bool bTmpNoInterrupt = bNoInterrupt;
3354                     bNoInterrupt = sal_False;
3355 
3356                     if( !rSh.IsViewLocked() && bLockView )
3357                         rSh.LockView( sal_True );
3358                     else
3359                         bLockView = sal_False;
3360 
3361                     int nTmpSetCrsr = 0;
3362 
3363                     {   // nur temp. Move-Kontext aufspannen, da sonst die
3364                         // Abfrage auf die Inhaltsform nicht funktioniert!!!
3365                         MV_KONTEXT( &rSh );
3366                         nTmpSetCrsr = (rSh.*rSh.fnSetCrsr)(&aDocPos,bOnlyText);
3367                         bValidCrsrPos = !(CRSR_POSCHG & nTmpSetCrsr);
3368                         bCallBase = sal_False;
3369                     }
3370 
3371                     //#i42732# - notify the edit window that from now on we do not use the input language
3372                     if ( !(CRSR_POSOLD & nTmpSetCrsr) )
3373                         SetUseInputLanguage( sal_False );
3374 
3375                     if( bLockView )
3376                         rSh.LockView( sal_False );
3377 
3378                     bNoInterrupt = bTmpNoInterrupt;
3379                 }
3380                 if ( !bOverURLGrf && !bOnlyText )
3381                 {
3382                     const int nSelType = rSh.GetSelectionType();
3383                     // Check in general, if an object is selectable at given position.
3384                     // Thus, also text fly frames in background become selectable via Ctrl-Click.
3385                     if ( nSelType & nsSelectionType::SEL_OLE ||
3386                          nSelType & nsSelectionType::SEL_GRF ||
3387                          rSh.IsObjSelectable( aDocPos ) )
3388                     {
3389                         MV_KONTEXT( &rSh );
3390                         if( !rSh.IsFrmSelected() )
3391                             rSh.GotoNextFly();
3392                         rSh.EnterSelFrmMode();
3393                         bCallBase = sal_False;
3394                     }
3395                 }
3396                 break;
3397             }
3398         }
3399     }
3400     if (bCallBase)
3401         Window::MouseButtonDown(rMEvt);
3402 }
3403 
3404 /*--------------------------------------------------------------------
3405     Beschreibung:   MouseMove
3406  --------------------------------------------------------------------*/
3407 
3408 
3409 void SwEditWin::MouseMove(const MouseEvent& _rMEvt)
3410 {
3411     MouseEvent rMEvt(_rMEvt);
3412 
3413     //ignore key modifiers for format paintbrush
3414     {
3415         sal_Bool bExecFormatPaintbrush = pApplyTempl && pApplyTempl->pFormatClipboard
3416                                 &&  pApplyTempl->pFormatClipboard->HasContent();
3417         if( bExecFormatPaintbrush )
3418             rMEvt = MouseEvent( _rMEvt.GetPosPixel(), _rMEvt.GetClicks(),
3419                                     _rMEvt.GetMode(), _rMEvt.GetButtons() );
3420     }
3421 
3422     // solange eine Action laeuft sollte das MouseMove abgeklemmt sein
3423     // Ansonsten gibt es den Bug 40102
3424     SwWrtShell &rSh = rView.GetWrtShell();
3425     if( rSh.ActionPend() )
3426         return ;
3427 
3428     if( pShadCrsr && 0 != (rMEvt.GetModifier() + rMEvt.GetButtons() ) )
3429         delete pShadCrsr, pShadCrsr = 0;
3430 
3431     sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly();
3432 
3433     SET_CURR_SHELL( &rSh );
3434 
3435     //aPixPt == Point in Pixel, rel. zu ChildWin
3436     //aDocPt == Point in Twips, Dokumentkoordinaten
3437     const Point aPixPt( rMEvt.GetPosPixel() );
3438     const Point aDocPt( PixelToLogic( aPixPt ) );
3439 
3440     if ( IsChainMode() )
3441     {
3442         UpdatePointer( aDocPt, rMEvt.GetModifier() );
3443         if ( rMEvt.IsLeaveWindow() )
3444             rView.GetViewFrame()->HideStatusText();
3445         return;
3446     }
3447 
3448     SdrView *pSdrView = rSh.GetDrawView();
3449 
3450     const SwCallMouseEvent aLastCallEvent( aSaveCallEvent );
3451     aSaveCallEvent.Clear();
3452 
3453     if ( !bIsDocReadOnly && pSdrView && pSdrView->MouseMove(rMEvt,this) )
3454     {
3455         SetPointer( POINTER_TEXT );
3456         return; // Event von der SdrView ausgewertet
3457     }
3458 
3459     const Point aOldPt( rSh.VisArea().Pos() );
3460     const sal_Bool bInsWin = rSh.VisArea().IsInside( aDocPt );
3461 
3462     if( pShadCrsr && !bInsWin )
3463         delete pShadCrsr, pShadCrsr = 0;
3464 
3465     if( bInsWin && pRowColumnSelectionStart )
3466     {
3467         EnterArea();
3468         Point aPos( aDocPt );
3469         if( rSh.SelectTableRowCol( *pRowColumnSelectionStart, &aPos, bIsRowDrag ))
3470             return;
3471     }
3472 
3473     // Position ist noetig fuer OS/2, da dort nach einem MB-Down
3474     // offensichtlich sofort ein MB-Move gerufen wird.
3475     if( bDDTimerStarted )
3476     {
3477         Point aDD( SwEditWin::nDDStartPosX, SwEditWin::nDDStartPosY );
3478         aDD = LogicToPixel( aDD );
3479         Rectangle aRect( aDD.X()-3, aDD.Y()-3, aDD.X()+3, aDD.Y()+3 );
3480         if ( !aRect.IsInside( aPixPt ) )    // MA 23. May. 95: Tatterschutz.
3481             StopDDTimer( &rSh, aDocPt );
3482     }
3483 
3484     if(rView.GetDrawFuncPtr())
3485     {
3486         if( bInsDraw  )
3487         {
3488             rView.GetDrawFuncPtr()->MouseMove( rMEvt );
3489             if ( !bInsWin )
3490             {
3491                 Point aTmp( aDocPt );
3492                 aTmp += rSh.VisArea().Pos() - aOldPt;
3493                 LeaveArea( aTmp );
3494             }
3495             else
3496                 EnterArea();
3497             return;
3498         }
3499         else if(!rSh.IsFrmSelected() && !rSh.IsObjSelected())
3500         {
3501             SfxBindings &rBnd = rSh.GetView().GetViewFrame()->GetBindings();
3502             Point aRelPos = rSh.GetRelativePagePosition(aDocPt);
3503             if(aRelPos.X() >= 0)
3504             {
3505                 FieldUnit eMetric = ::GetDfltMetric(0 != PTR_CAST(SwWebView, &GetView()));
3506                 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
3507                 const SfxPointItem aTmp1( SID_ATTR_POSITION, aRelPos );
3508                 rBnd.SetState( aTmp1 );
3509             }
3510             else
3511             {
3512                 rBnd.Invalidate(SID_ATTR_POSITION);
3513             }
3514             rBnd.Invalidate(SID_ATTR_SIZE);
3515             const SfxStringItem aCell( SID_TABLE_CELL, aEmptyStr );
3516             rBnd.SetState( aCell );
3517         }
3518     }
3519 
3520     sal_uInt8 nMouseTabCol;
3521     if( !bIsDocReadOnly && bInsWin && !pApplyTempl && !rSh.IsInSelect() )
3522     {
3523         if ( SW_TABCOL_NONE != (nMouseTabCol = rSh.WhichMouseTabCol( aDocPt ) ) &&
3524              !rSh.IsObjSelectable( aDocPt ) )
3525         {
3526             sal_uInt16 nPointer = USHRT_MAX;
3527             bool bChkTblSel = false;
3528 
3529             switch ( nMouseTabCol )
3530             {
3531                 case SW_TABCOL_VERT :
3532                 case SW_TABROW_HORI :
3533                     nPointer = POINTER_VSIZEBAR;
3534                     bChkTblSel = true;
3535                     break;
3536                 case SW_TABROW_VERT :
3537                 case SW_TABCOL_HORI :
3538                     nPointer = POINTER_HSIZEBAR;
3539                     bChkTblSel = true;
3540                     break;
3541                 // Enhanced table selection
3542                 case SW_TABSEL_HORI :
3543                     nPointer = POINTER_TAB_SELECT_SE;
3544                     break;
3545                 case SW_TABSEL_HORI_RTL :
3546                 case SW_TABSEL_VERT :
3547                     nPointer = POINTER_TAB_SELECT_SW;
3548                     break;
3549                 case SW_TABCOLSEL_HORI :
3550                 case SW_TABROWSEL_VERT :
3551                     nPointer = POINTER_TAB_SELECT_S;
3552                     break;
3553                 case SW_TABROWSEL_HORI :
3554                     nPointer = POINTER_TAB_SELECT_E;
3555                     break;
3556                 case SW_TABROWSEL_HORI_RTL :
3557                 case SW_TABCOLSEL_VERT :
3558                     nPointer = POINTER_TAB_SELECT_W;
3559                     break;
3560             }
3561 
3562             if ( USHRT_MAX != nPointer &&
3563                 // Enhanced table selection is explicitely allowed in table mode
3564                 ( !bChkTblSel || !rSh.IsTableMode() ) )
3565             {
3566                 SetPointer( nPointer );
3567             }
3568 
3569             return;
3570         }
3571         else if (rSh.IsNumLabel(aDocPt, RULER_MOUSE_MARGINWIDTH))
3572         {
3573             SwTxtNode* pNodeAtPos = rSh.GetNumRuleNodeAtPos( aDocPt );
3574             const sal_uInt16 nPointer =
3575                     rSh.IsVerticalModeAtNdAndPos( *pNodeAtPos, aDocPt )
3576                     ? POINTER_VSIZEBAR
3577                     : POINTER_HSIZEBAR;
3578             SetPointer( nPointer );
3579 
3580             return;
3581         }
3582     }
3583 
3584     sal_Bool bDelShadCrsr = sal_True;
3585 
3586     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
3587     {
3588         case MOUSE_LEFT:
3589             if( pAnchorMarker )
3590             {
3591                 // Now we need to refresh the SdrHdl pointer of pAnchorMarker.
3592                 // This looks a little bit tricky, but it solves the following
3593                 // problem: the pAnchorMarker contains a pointer to an SdrHdl,
3594                 // if the FindAnchorPos-call cause a scrolling of the visible
3595                 // area, it's possible that the SdrHdl will be destroyed and a
3596                 // new one will initialized at the original position(GetHdlPos).
3597                 // So the pAnchorMarker has to find the right SdrHdl, if it's
3598                 // the old one, it will find it with position aOld, if this one
3599                 // is destroyed, it will find a new one at position GetHdlPos().
3600                 const Point aOld = pAnchorMarker->GetPosForHitTest( *(rSh.GetOut()) );
3601                 Point aNew = rSh.FindAnchorPos( aDocPt );
3602                 SdrHdl* pHdl;
3603                 if( (0!=( pHdl = pSdrView->PickHandle( aOld ) )||
3604                     0 !=(pHdl = pSdrView->PickHandle( pAnchorMarker->GetHdlPos()) ) ) &&
3605                         ( pHdl->GetKind() == HDL_ANCHOR ||
3606                           pHdl->GetKind() == HDL_ANCHOR_TR ) )
3607                 {
3608                     pAnchorMarker->ChgHdl( pHdl );
3609                     if( aNew.X() || aNew.Y() )
3610                     {
3611                         pAnchorMarker->SetPos( aNew );
3612                         pAnchorMarker->SetLastPos( aDocPt );
3613                     }
3614                 }
3615                 else
3616                 {
3617                     delete pAnchorMarker;
3618                     pAnchorMarker = NULL;
3619                 }
3620             }
3621             if ( bInsDraw )
3622             {
3623                 if ( !bMBPressed )
3624                     break;
3625                 if ( bIsInMove || IsMinMove( aStartPos, aPixPt ) )
3626                 {
3627                     if ( !bInsWin )
3628                         LeaveArea( aDocPt );
3629                     else
3630                         EnterArea();
3631                     if ( rView.GetDrawFuncPtr() )
3632                     {
3633                         pSdrView->SetOrtho(sal_False);
3634                         rView.GetDrawFuncPtr()->MouseMove( rMEvt );
3635                     }
3636                     bIsInMove = sal_True;
3637                 }
3638                 return;
3639             }
3640         case MOUSE_LEFT + KEY_SHIFT:
3641         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
3642             if ( !bMBPressed )
3643                 break;
3644         case MOUSE_LEFT + KEY_MOD1:
3645             if ( bFrmDrag && rSh.IsSelFrmMode() )
3646             {
3647                 if( !bMBPressed )
3648                     break;
3649 
3650                 if ( bIsInMove || IsMinMove( aStartPos, aPixPt ) )
3651                 {
3652                     // Event-Verarbeitung fuers Resizen
3653                     if( pSdrView->AreObjectsMarked() )
3654                     {
3655                         const SwFrmFmt* pFlyFmt;
3656                         const SvxMacro* pMacro;
3657 
3658                         const Point aSttPt( PixelToLogic( aStartPos ) );
3659 
3660                         // geht es los?
3661                         if( HDL_USER == eSdrMoveHdl )
3662                         {
3663                             SdrHdl* pHdl = pSdrView->PickHandle( aSttPt );
3664                             eSdrMoveHdl = pHdl ? pHdl->GetKind() : HDL_MOVE;
3665                         }
3666 
3667                         sal_uInt16 nEvent = HDL_MOVE == eSdrMoveHdl
3668                                             ? SW_EVENT_FRM_MOVE
3669                                             : SW_EVENT_FRM_RESIZE;
3670 
3671                         if( 0 != ( pFlyFmt = rSh.GetFlyFrmFmt() ) &&
3672                             0 != ( pMacro = pFlyFmt->GetMacro().GetMacroTable().
3673                             Get( nEvent )) &&
3674                             aRszMvHdlPt != aDocPt )
3675                         {
3676                             aRszMvHdlPt = aDocPt;
3677                             sal_uInt16 nPos = 0;
3678                             String sRet;
3679                             SbxArrayRef xArgs = new SbxArray;
3680                             SbxVariableRef xVar = new SbxVariable;
3681                             xVar->PutString( pFlyFmt->GetName() );
3682                             xArgs->Put( &xVar, ++nPos );
3683 
3684                             if( SW_EVENT_FRM_RESIZE == nEvent )
3685                             {
3686                                 xVar = new SbxVariable;
3687                                 xVar->PutUShort( static_cast< sal_uInt16 >(eSdrMoveHdl) );
3688                                 xArgs->Put( &xVar, ++nPos );
3689                             }
3690 
3691                             xVar = new SbxVariable;
3692                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
3693                             xArgs->Put( &xVar, ++nPos );
3694                             xVar = new SbxVariable;
3695                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
3696                             xArgs->Put( &xVar, ++nPos );
3697 
3698                             ReleaseMouse();
3699 
3700                             rSh.ExecMacro( *pMacro, &sRet, &xArgs );
3701 
3702                             CaptureMouse();
3703 
3704                             if( sRet.Len() && 0 != sRet.ToInt32() )
3705                                 return ;
3706                         }
3707                     }
3708                     // Event-Verarbeitung fuers Resizen
3709 
3710                     if( bIsDocReadOnly )
3711                         break;
3712 
3713                     if ( rMEvt.IsShift() )
3714                     {
3715                         pSdrView->SetOrtho(sal_True);
3716                         pSdrView->SetAngleSnapEnabled(sal_True);
3717                     }
3718                     else
3719                     {
3720                         pSdrView->SetOrtho(sal_False);
3721                         pSdrView->SetAngleSnapEnabled(sal_False);
3722                     }
3723 
3724                     (rSh.*rSh.fnDrag)( &aDocPt, rMEvt.IsShift() );
3725                     bIsInMove = sal_True;
3726                 }
3727                 else if( bIsDocReadOnly )
3728                     break;
3729 
3730                 if ( !bInsWin )
3731                 {
3732                     Point aTmp( aDocPt );
3733                     aTmp += rSh.VisArea().Pos() - aOldPt;
3734                     LeaveArea( aTmp );
3735                 }
3736                 else if(bIsInMove)
3737                     EnterArea();
3738                 return;
3739             }
3740             if ( !rSh.IsSelFrmMode() && !bDDINetAttr &&
3741                 (IsMinMove( aStartPos,aPixPt ) || bIsInMove) &&
3742                 (rSh.IsInSelect() || !rSh.ChgCurrPam( aDocPt )) )
3743             {
3744                 if ( pSdrView )
3745                 {
3746                     if ( rMEvt.IsShift() )
3747                         pSdrView->SetOrtho(sal_True);
3748                     else
3749                         pSdrView->SetOrtho(sal_False);
3750                 }
3751                 if ( !bInsWin )
3752                 {
3753                     Point aTmp( aDocPt );
3754                     aTmp += rSh.VisArea().Pos() - aOldPt;
3755                     LeaveArea( aTmp );
3756                 }
3757                 else
3758                 {
3759                     //JP 24.09.98: Fix fuer die Bugs 55592 / 55931
3760                     //JP 23.04.99: Fix fuer den Bugs 65289
3761                     //JP 06.07.99: Fix fuer den Bugs 67360
3762                     if( !rMEvt.IsSynthetic() &&
3763                             !(( MOUSE_LEFT + KEY_MOD1 ==
3764                             rMEvt.GetModifier() + rMEvt.GetButtons() ) &&
3765                             rSh.Is_FnDragEQBeginDrag() && !rSh.IsAddMode() ))
3766                     {
3767                         (rSh.*rSh.fnDrag)( &aDocPt,sal_False );
3768 
3769                         bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPt,sal_False));
3770                         EnterArea();
3771                     }
3772                 }
3773             }
3774             bDDINetAttr = sal_False;
3775             break;
3776         case 0:
3777         {
3778             if ( pApplyTempl )
3779                         {
3780                 UpdatePointer(aDocPt, 0); // evtl. muss hier ein Rahmen markiert werden
3781                                 break;
3782                         }
3783             //#i6193#, change ui if mouse is over SwPostItField
3784             // TODO: do the same thing for redlines SW_REDLINE
3785             SwRect aFldRect;
3786             SwContentAtPos aCntntAtPos( SwContentAtPos::SW_FIELD);
3787             if( rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_False, &aFldRect ) )
3788             {
3789                 const SwField* pFld = aCntntAtPos.aFnd.pFld;
3790                 if (pFld->Which()== RES_POSTITFLD)
3791                 {
3792                     rView.GetPostItMgr()->SetShadowState(reinterpret_cast<const SwPostItField*>(pFld),false);
3793                 }
3794                 else
3795                     rView.GetPostItMgr()->SetShadowState(0,false);
3796             }
3797             else
3798                 rView.GetPostItMgr()->SetShadowState(0,false);
3799                 // no break;
3800         }
3801         case KEY_SHIFT:
3802         case KEY_MOD2:
3803         case KEY_MOD1:
3804             if ( !bInsDraw )
3805             {
3806                 sal_Bool bTstShdwCrsr = sal_True;
3807 
3808                 UpdatePointer( aDocPt, rMEvt.GetModifier() );
3809 
3810                 const SwFrmFmt* pFmt = 0;
3811                 const SwFmtINetFmt* pINet = 0;
3812                 SwContentAtPos aCntntAtPos( SwContentAtPos::SW_INETATTR );
3813                 if( rSh.GetContentAtPos( aDocPt, aCntntAtPos ) )
3814                     pINet = (SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr;
3815 
3816                 const void* pTmp = pINet;
3817 
3818                 if( pINet ||
3819                     0 != ( pTmp = pFmt = rSh.GetFmtFromAnyObj( aDocPt )))
3820                 {
3821                     bTstShdwCrsr = sal_False;
3822                     if( pTmp == pINet )
3823                         aSaveCallEvent.Set( pINet );
3824                     else
3825                     {
3826                         IMapObject* pIMapObj = pFmt->GetIMapObject( aDocPt );
3827                         if( pIMapObj )
3828                             aSaveCallEvent.Set( pFmt, pIMapObj );
3829                         else
3830                             aSaveCallEvent.Set( EVENT_OBJECT_URLITEM, pFmt );
3831                     }
3832 
3833                     // sollte wir ueber einem InternetFeld mit einem
3834                     // gebundenen Macro stehen?
3835                     if( aSaveCallEvent != aLastCallEvent )
3836                     {
3837                         if( aLastCallEvent.HasEvent() )
3838                             rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
3839                                             aLastCallEvent, sal_True );
3840                         // 0 besagt, das das Object gar keine Tabelle hat
3841                         if( !rSh.CallEvent( SFX_EVENT_MOUSEOVER_OBJECT,
3842                                         aSaveCallEvent ))
3843                             aSaveCallEvent.Clear();
3844                     }
3845                 }
3846                 else if( aLastCallEvent.HasEvent() )
3847                 {
3848                     // Cursor stand auf einem Object
3849                     rSh.CallEvent( SFX_EVENT_MOUSEOUT_OBJECT,
3850                                     aLastCallEvent, sal_True );
3851                 }
3852 
3853                 if( bTstShdwCrsr && bInsWin && !bIsDocReadOnly &&
3854                     !bInsFrm &&
3855                     !rSh.GetViewOptions()->getBrowseMode() &&
3856                     rSh.GetViewOptions()->IsShadowCursor() &&
3857                     !(rMEvt.GetModifier() + rMEvt.GetButtons()) &&
3858                     !rSh.HasSelection() && !GetConnectMetaFile() )
3859                 {
3860                     SwRect aRect;
3861                     sal_Int16 eOrient;
3862                     SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
3863                     if( rSh.GetShadowCrsrPos( aDocPt, eMode, aRect, eOrient ))
3864                     {
3865                         if( !pShadCrsr )
3866                             pShadCrsr = new SwShadowCursor( *this,
3867                                 SwViewOption::GetDirectCursorColor() );
3868                         if( text::HoriOrientation::RIGHT != eOrient && text::HoriOrientation::CENTER != eOrient )
3869                             eOrient = text::HoriOrientation::LEFT;
3870                         pShadCrsr->SetPos( aRect.Pos(), aRect.Height(), static_cast< sal_uInt16 >(eOrient) );
3871                         bDelShadCrsr = sal_False;
3872                     }
3873                 }
3874             }
3875             break;
3876         case MOUSE_LEFT + KEY_MOD2:
3877             if( rSh.IsBlockMode() && !rMEvt.IsSynthetic() )
3878             {
3879                 (rSh.*rSh.fnDrag)( &aDocPt,sal_False );
3880                 bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPt,sal_False));
3881                 EnterArea();
3882             }
3883         break;
3884     }
3885 
3886     if( bDelShadCrsr && pShadCrsr )
3887         delete pShadCrsr, pShadCrsr = 0;
3888     bWasShdwCrsr = sal_False;
3889 }
3890 
3891 /*--------------------------------------------------------------------
3892     Beschreibung:   Button Up
3893  --------------------------------------------------------------------*/
3894 
3895 
3896 void SwEditWin::MouseButtonUp(const MouseEvent& rMEvt)
3897 {
3898     sal_Bool bCallBase = sal_True;
3899 
3900     sal_Bool bCallShadowCrsr = bWasShdwCrsr;
3901     bWasShdwCrsr = sal_False;
3902     if( pShadCrsr )
3903         delete pShadCrsr, pShadCrsr = 0;
3904 
3905     if( pRowColumnSelectionStart )
3906         DELETEZ( pRowColumnSelectionStart );
3907 
3908     SdrHdlKind eOldSdrMoveHdl = eSdrMoveHdl;
3909     eSdrMoveHdl = HDL_USER;     // fuer die MoveEvents - wieder zuruecksetzen
3910 
3911     // sicherheitshalber zuruecksetzen Bug 27900
3912     rView.SetTabColFromDoc( sal_False );
3913     rView.SetNumRuleNodeFromDoc(NULL);
3914 
3915     SwWrtShell &rSh = rView.GetWrtShell();
3916     SET_CURR_SHELL( &rSh );
3917     SdrView *pSdrView = rSh.GetDrawView();
3918     if ( pSdrView )
3919     {
3920         pSdrView->SetOrtho(sal_False);
3921 
3922         if ( pSdrView->MouseButtonUp( rMEvt,this ) )
3923         {
3924             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
3925             return; // Event von der SdrView ausgewertet
3926         }
3927     }
3928     //MouseButtonUp nur bearbeiten, wenn auch das Down an dieses Fenster ging.
3929     if ( !bMBPressed )
3930     {
3931         return;
3932     }
3933 
3934     Point aDocPt( PixelToLogic( rMEvt.GetPosPixel() ) );
3935 
3936     if ( bDDTimerStarted )
3937     {
3938         StopDDTimer( &rSh, aDocPt );
3939         bMBPressed = sal_False;
3940         if ( rSh.IsSelFrmMode() )
3941         {
3942             (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
3943             bFrmDrag = sal_False;
3944         }
3945         bNoInterrupt = sal_False;
3946         ReleaseMouse();
3947         return;
3948     }
3949 
3950     if( pAnchorMarker )
3951     {
3952         if(pAnchorMarker->GetHdl())
3953         {
3954             // delete selected after drag
3955             pAnchorMarker->GetHdl()->SetSelected(false);
3956         }
3957 
3958         Point aPnt( pAnchorMarker->GetLastPos() );
3959         DELETEZ( pAnchorMarker );
3960         if( aPnt.X() || aPnt.Y() )
3961             rSh.FindAnchorPos( aPnt, sal_True );
3962     }
3963     if ( bInsDraw && rView.GetDrawFuncPtr() )
3964     {
3965         if ( rView.GetDrawFuncPtr()->MouseButtonUp( rMEvt ) )
3966         {
3967             if (rView.GetDrawFuncPtr()) // Koennte im MouseButtonUp zerstoert worden sein
3968             {
3969                 rView.GetDrawFuncPtr()->Deactivate();
3970 
3971                 if (!rView.IsDrawMode())
3972                 {
3973                     rView.SetDrawFuncPtr(NULL);
3974                     SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
3975                     rBind.Invalidate( SID_ATTR_SIZE );
3976                     rBind.Invalidate( SID_TABLE_CELL );
3977                 }
3978             }
3979 
3980             if ( rSh.IsObjSelected() )
3981             {
3982                 rSh.EnterSelFrmMode();
3983                 if (!rView.GetDrawFuncPtr())
3984                     StdDrawMode( OBJ_NONE, sal_True );
3985             }
3986             else if ( rSh.IsFrmSelected() )
3987             {
3988                 rSh.EnterSelFrmMode();
3989                 StopInsFrm();
3990             }
3991             else
3992             {
3993                 const Point aDocPos( PixelToLogic( aStartPos ) );
3994                 bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
3995                 rSh.Edit();
3996             }
3997 
3998             rView.AttrChangedNotify( &rSh );
3999         }
4000         else if (rMEvt.GetButtons() == MOUSE_RIGHT && rSh.IsDrawCreate())
4001             rView.GetDrawFuncPtr()->BreakCreate();   // Zeichnen abbrechen
4002 
4003         bNoInterrupt = sal_False;
4004         ReleaseMouse();
4005         return;
4006     }
4007     sal_Bool bPopMode = sal_False;
4008     switch ( rMEvt.GetModifier() + rMEvt.GetButtons() )
4009     {
4010         case MOUSE_LEFT:
4011             if ( bInsDraw && rSh.IsDrawCreate() )
4012             {
4013                 if ( rView.GetDrawFuncPtr() && rView.GetDrawFuncPtr()->MouseButtonUp(rMEvt) == sal_True )
4014                 {
4015                     rView.GetDrawFuncPtr()->Deactivate();
4016                     rView.AttrChangedNotify( &rSh );
4017                     if ( rSh.IsObjSelected() )
4018                         rSh.EnterSelFrmMode();
4019                     if ( rView.GetDrawFuncPtr() && bInsFrm )
4020                         StopInsFrm();
4021                 }
4022                 bCallBase = sal_False;
4023                 break;
4024             }
4025         case MOUSE_LEFT + KEY_MOD1:
4026         case MOUSE_LEFT + KEY_MOD2:
4027         case MOUSE_LEFT + KEY_SHIFT + KEY_MOD1:
4028             if ( bFrmDrag && rSh.IsSelFrmMode() )
4029             {
4030                 if ( rMEvt.IsMod1() ) //Kopieren und nicht moven.
4031                 {
4032                     //Drag abbrechen, statt dessen internes Copy verwenden
4033                     Rectangle aRect;
4034                     rSh.GetDrawView()->TakeActionRect( aRect );
4035                     if (!aRect.IsEmpty())
4036                     {
4037                         rSh.BreakDrag();
4038                         Point aEndPt, aSttPt;
4039                         if ( rSh.GetSelFrmType() & FRMTYPE_FLY_ATCNT )
4040                         {
4041                             aEndPt = aRect.TopLeft();
4042                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().TopLeft();
4043                         }
4044                         else
4045                         {
4046                             aEndPt = aRect.Center();
4047                             aSttPt = rSh.GetDrawView()->GetAllMarkedRect().Center();
4048                         }
4049                         if ( aSttPt != aEndPt )
4050                         {
4051                             rSh.StartUndo( UNDO_UI_DRAG_AND_COPY );
4052                             rSh.Copy(&rSh, aSttPt, aEndPt, sal_False);
4053                             rSh.EndUndo( UNDO_UI_DRAG_AND_COPY );
4054                         }
4055                     }
4056                     else
4057                         (rSh.*rSh.fnEndDrag)( &aDocPt,sal_False );
4058                 }
4059                 else
4060                 {
4061                     {
4062                         const SwFrmFmt* pFlyFmt;
4063                         const SvxMacro* pMacro;
4064 
4065                         sal_uInt16 nEvent = HDL_MOVE == eOldSdrMoveHdl
4066                                             ? SW_EVENT_FRM_MOVE
4067                                             : SW_EVENT_FRM_RESIZE;
4068 
4069                         if( 0 != ( pFlyFmt = rSh.GetFlyFrmFmt() ) &&
4070                             0 != ( pMacro = pFlyFmt->GetMacro().GetMacroTable().
4071                             Get( nEvent )) )
4072                         {
4073                             const Point aSttPt( PixelToLogic( aStartPos ) );
4074                             aRszMvHdlPt = aDocPt;
4075                             sal_uInt16 nPos = 0;
4076                             SbxArrayRef xArgs = new SbxArray;
4077                             SbxVariableRef xVar = new SbxVariable;
4078                             xVar->PutString( pFlyFmt->GetName() );
4079                             xArgs->Put( &xVar, ++nPos );
4080 
4081                             if( SW_EVENT_FRM_RESIZE == nEvent )
4082                             {
4083                                 xVar = new SbxVariable;
4084                                 xVar->PutUShort( static_cast< sal_uInt16 >(eOldSdrMoveHdl) );
4085                                 xArgs->Put( &xVar, ++nPos );
4086                             }
4087 
4088                             xVar = new SbxVariable;
4089                             xVar->PutLong( aDocPt.X() - aSttPt.X() );
4090                             xArgs->Put( &xVar, ++nPos );
4091                             xVar = new SbxVariable;
4092                             xVar->PutLong( aDocPt.Y() - aSttPt.Y() );
4093                             xArgs->Put( &xVar, ++nPos );
4094 
4095                             xVar = new SbxVariable;
4096                             xVar->PutUShort( 1 );
4097                             xArgs->Put( &xVar, ++nPos );
4098 
4099                             ReleaseMouse();
4100 
4101                             rSh.ExecMacro( *pMacro, 0, &xArgs );
4102 
4103                             CaptureMouse();
4104                         }
4105                     }
4106                     (rSh.*rSh.fnEndDrag)( &aDocPt,sal_False );
4107                 }
4108                 bFrmDrag = sal_False;
4109                 bCallBase = sal_False;
4110                 break;
4111             }
4112             bPopMode = sal_True;
4113             // no break
4114         case MOUSE_LEFT + KEY_SHIFT:
4115             if (rSh.IsSelFrmMode())
4116             {
4117 
4118                 (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4119                 bFrmDrag = sal_False;
4120                 bCallBase = sal_False;
4121                 break;
4122             }
4123 
4124             if( bHoldSelection )
4125             {
4126                 //JP 27.04.99: Bug 65389 - das EndDrag sollte auf jedenfall
4127                 //              gerufen werden.
4128                 bHoldSelection = sal_False;
4129                 (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4130             }
4131             else
4132             {
4133                 if ( !rSh.IsInSelect() && rSh.ChgCurrPam( aDocPt ) )
4134                 {
4135                     const sal_Bool bTmpNoInterrupt = bNoInterrupt;
4136                     bNoInterrupt = sal_False;
4137                     {   // nur temp. Move-Kontext aufspannen, da sonst die
4138                         // Abfrage auf die Inhaltsform nicht funktioniert!!!
4139                         MV_KONTEXT( &rSh );
4140                         const Point aDocPos( PixelToLogic( aStartPos ) );
4141                         bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
4142                     }
4143                     bNoInterrupt = bTmpNoInterrupt;
4144 
4145                 }
4146                 else
4147                 {
4148                     sal_Bool bInSel = rSh.IsInSelect();
4149                     (rSh.*rSh.fnEndDrag)( &aDocPt, sal_False );
4150 
4151                     // Internetfield? --> Link-Callen (DocLaden!!)
4152 //JP 18.10.96: Bug 32437 -
4153 //                  if( !rSh.HasSelection() )
4154                     if( !bInSel )
4155                     {
4156                         sal_uInt16 nFilter = URLLOAD_NOFILTER;
4157                         if( KEY_MOD1 == rMEvt.GetModifier() )
4158                             nFilter |= URLLOAD_NEWVIEW;
4159 
4160                         sal_Bool bExecHyperlinks = rView.GetDocShell()->IsReadOnly();
4161                         if ( !bExecHyperlinks )
4162                         {
4163                             SvtSecurityOptions aSecOpts;
4164                             const sal_Bool bSecureOption = aSecOpts.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
4165                             if ( (  bSecureOption && rMEvt.GetModifier() == KEY_MOD1 ) ||
4166                                  ( !bSecureOption && rMEvt.GetModifier() != KEY_MOD1 ) )
4167                                 bExecHyperlinks = sal_True;
4168                         }
4169 
4170                         const sal_Bool bExecSmarttags = rMEvt.GetModifier() == KEY_MOD1;
4171 
4172                         if(pApplyTempl)
4173                             bExecHyperlinks = sal_False;
4174 
4175                         SwContentAtPos aCntntAtPos( SwContentAtPos::SW_CLICKFIELD |
4176                                                     SwContentAtPos::SW_INETATTR |
4177                                                     SwContentAtPos::SW_SMARTTAG  | SwContentAtPos::SW_FORMCTRL);
4178 
4179                         if( rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_True ) )
4180                         {
4181                             sal_Bool bViewLocked = rSh.IsViewLocked();
4182                             if( !bViewLocked && !rSh.IsReadOnlyAvailable() &&
4183                                 aCntntAtPos.IsInProtectSect() )
4184                                 rSh.LockView( sal_True );
4185 
4186                             ReleaseMouse();
4187 
4188                             if( SwContentAtPos::SW_FIELD == aCntntAtPos.eCntntAtPos )
4189                             {
4190                                 rSh.ClickToField( *aCntntAtPos.aFnd.pFld );
4191                             }
4192                             else if ( SwContentAtPos::SW_SMARTTAG == aCntntAtPos.eCntntAtPos )
4193                             {
4194                                     // execute smarttag menu
4195                                     if ( bExecSmarttags && SwSmartTagMgr::Get().IsSmartTagsEnabled() )
4196                                         rView.ExecSmartTagPopup( aDocPt );
4197                             }
4198                             else if ( SwContentAtPos::SW_FORMCTRL == aCntntAtPos.eCntntAtPos )
4199                             {
4200                                 ASSERT( aCntntAtPos.aFnd.pFldmark != NULL, "where is my field ptr???");
4201                                 if ( aCntntAtPos.aFnd.pFldmark != NULL)
4202                                 {
4203                                     IFieldmark *fieldBM = const_cast< IFieldmark* > ( aCntntAtPos.aFnd.pFldmark );
4204                                     if (fieldBM->GetFieldname( ).equalsAscii( ODF_FORMCHECKBOX ) )
4205                                     {
4206                                         ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(fieldBM);
4207                                         pCheckboxFm->SetChecked(!pCheckboxFm->IsChecked());
4208                                         pCheckboxFm->Invalidate();
4209                                         rSh.InvalidateWindows( rView.GetVisArea() );
4210                                     } else if (fieldBM->GetFieldname().equalsAscii( ODF_FORMDROPDOWN) ) {
4211                                         rView.ExecFieldPopup( aDocPt, fieldBM );
4212                                         fieldBM->Invalidate();
4213                                         rSh.InvalidateWindows( rView.GetVisArea() );
4214                                     } else {
4215                                         // unknown type..
4216                                     }
4217                                 }
4218                             }
4219                             else // if ( SwContentAtPos::SW_INETATTR == aCntntAtPos.eCntntAtPos )
4220                             {
4221                                 if ( bExecHyperlinks )
4222                                     rSh.ClickToINetAttr( *(SwFmtINetFmt*)aCntntAtPos.aFnd.pAttr, nFilter );
4223                             }
4224 
4225                             rSh.LockView( bViewLocked );
4226                             bCallShadowCrsr = sal_False;
4227                         }
4228                         else
4229                         {
4230                             aCntntAtPos = SwContentAtPos( SwContentAtPos::SW_FTN );
4231                             if( !rSh.GetContentAtPos( aDocPt, aCntntAtPos, sal_True ) && bExecHyperlinks )
4232                             {
4233                                 SdrViewEvent aVEvt;
4234 
4235                                 if (pSdrView)
4236                                     pSdrView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
4237 
4238                                 if (pSdrView && aVEvt.eEvent == SDREVENT_EXECUTEURL)
4239                                 {
4240                                     // URL-Feld getroffen
4241                                     const SvxURLField *pField = aVEvt.pURLField;
4242                                     if (pField)
4243                                     {
4244                                         String sURL(pField->GetURL());
4245                                         String sTarget(pField->GetTargetFrame());
4246                                         ::LoadURL( sURL, &rSh, nFilter, &sTarget);
4247                                     }
4248                                     bCallShadowCrsr = sal_False;
4249                                 }
4250                                 else
4251                                 {
4252                                     // Grafik getroffen
4253                                     ReleaseMouse();
4254                                     if( rSh.ClickToINetGrf( aDocPt, nFilter ))
4255                                         bCallShadowCrsr = sal_False;
4256                                 }
4257                             }
4258                         }
4259 
4260                         if( bCallShadowCrsr &&
4261                             rSh.GetViewOptions()->IsShadowCursor() &&
4262                             MOUSE_LEFT == (rMEvt.GetModifier() + rMEvt.GetButtons()) &&
4263                             !rSh.HasSelection() &&
4264                             !GetConnectMetaFile() &&
4265                             rSh.VisArea().IsInside( aDocPt ))
4266                         {
4267                             SwUndoId nLastUndoId(UNDO_EMPTY);
4268                             if (rSh.GetLastUndoInfo(0, & nLastUndoId))
4269                             {
4270                                 if (UNDO_INS_FROM_SHADOWCRSR == nLastUndoId)
4271                                 {
4272                                     rSh.Undo();
4273                                 }
4274                             }
4275                             SwFillMode eMode = (SwFillMode)rSh.GetViewOptions()->GetShdwCrsrFillMode();
4276                             rSh.SetShadowCrsrPos( aDocPt, eMode );
4277                         }
4278                     }
4279                 }
4280                 bCallBase = sal_False;
4281 
4282             }
4283 
4284             // gfs. im Down gepushten Mode wieder zuruecksetzen
4285             if ( bPopMode && bModePushed )
4286             {
4287                 rSh.PopMode();
4288                 bModePushed = sal_False;
4289                 bCallBase = sal_False;
4290             }
4291             break;
4292 
4293         default:
4294             ReleaseMouse();
4295             return;
4296     }
4297 
4298     if( pApplyTempl )
4299     {
4300         int eSelection = rSh.GetSelectionType();
4301         SwFormatClipboard* pFormatClipboard = pApplyTempl->pFormatClipboard;
4302         if( pFormatClipboard )//apply format paintbrush
4303         {
4304             //get some parameters
4305             SwWrtShell& rWrtShell = rView.GetWrtShell();
4306             SfxStyleSheetBasePool* pPool=0;
4307             bool bNoCharacterFormats = false;
4308             bool bNoParagraphFormats = false;
4309             {
4310                 SwDocShell* pDocSh = rView.GetDocShell();
4311                 if(pDocSh)
4312                     pPool = pDocSh->GetStyleSheetPool();
4313                 if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
4314                     bNoCharacterFormats = true;
4315                 else if( rMEvt.GetModifier() & KEY_MOD1 )
4316                     bNoParagraphFormats = true;
4317             }
4318             //execute paste
4319             pFormatClipboard->Paste( rWrtShell, pPool, bNoCharacterFormats, bNoParagraphFormats );
4320 
4321             //if the clipboard is empty after paste remove the ApplyTemplate
4322             if(!pFormatClipboard->HasContent())
4323                 SetApplyTemplate(SwApplyTemplate());
4324         }
4325         else if( pApplyTempl->nColor )
4326         {
4327             sal_uInt16 nId = 0;
4328             switch( pApplyTempl->nColor )
4329             {
4330                 case SID_ATTR_CHAR_COLOR_EXT:
4331                     nId = RES_CHRATR_COLOR;
4332                 break;
4333                 case SID_ATTR_CHAR_COLOR_BACKGROUND_EXT:
4334                     nId = RES_CHRATR_BACKGROUND;
4335                 break;
4336             }
4337             if( nId && (nsSelectionType::SEL_TXT|nsSelectionType::SEL_TBL) & eSelection)
4338             {
4339                 if( rSh.IsSelection() && !rSh.HasReadonlySel() )
4340                 {
4341                     if(nId == RES_CHRATR_BACKGROUND)
4342                     {
4343                         Color aColor( COL_TRANSPARENT  );
4344                         if( !SwEditWin::bTransparentBackColor )
4345                             aColor = SwEditWin::aTextBackColor;
4346                         rSh.SetAttr( SvxBrushItem( aColor, nId ) );
4347                     }
4348                     else
4349                         rSh.SetAttr( SvxColorItem(SwEditWin::aTextColor, nId) );
4350                     rSh.UnSetVisCrsr();
4351                     rSh.EnterStdMode();
4352                     rSh.SetVisCrsr(aDocPt);
4353 
4354                     pApplyTempl->bUndo = sal_True;
4355                     bCallBase = sal_False;
4356                     aTemplateTimer.Stop();
4357                 }
4358                 else if(rMEvt.GetClicks() == 1)
4359                 {
4360                     // keine Selektion -> also Giesskanne abschalten
4361                     aTemplateTimer.Start();
4362                 }
4363             }
4364         }
4365         else
4366         {
4367             String aStyleName;
4368             switch ( pApplyTempl->eType )
4369             {
4370                 case SFX_STYLE_FAMILY_PARA:
4371                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
4372                          & eSelection ) && !rSh.HasReadonlySel() )
4373                     {
4374                         rSh.SetTxtFmtColl( pApplyTempl->aColl.pTxtColl );
4375                         pApplyTempl->bUndo = sal_True;
4376                         bCallBase = sal_False;
4377                         if ( pApplyTempl->aColl.pTxtColl )
4378                             aStyleName = pApplyTempl->aColl.pTxtColl->GetName();
4379                     }
4380                     break;
4381                 case SFX_STYLE_FAMILY_CHAR:
4382                     if( (( nsSelectionType::SEL_TXT | nsSelectionType::SEL_TBL )
4383                          & eSelection ) && !rSh.HasReadonlySel() )
4384                     {
4385                         rSh.SetAttr( SwFmtCharFmt(pApplyTempl->aColl.pCharFmt) );
4386                         rSh.UnSetVisCrsr();
4387                         rSh.EnterStdMode();
4388                         rSh.SetVisCrsr(aDocPt);
4389                         pApplyTempl->bUndo = sal_True;
4390                         bCallBase = sal_False;
4391                         if ( pApplyTempl->aColl.pCharFmt )
4392                             aStyleName = pApplyTempl->aColl.pCharFmt->GetName();
4393                     }
4394                     break;
4395                 case SFX_STYLE_FAMILY_FRAME :
4396                 {
4397                     const SwFrmFmt* pFmt = rSh.GetFmtFromObj( aDocPt );
4398                     if(PTR_CAST(SwFlyFrmFmt, pFmt))
4399                     {
4400                         rSh.SetFrmFmt( pApplyTempl->aColl.pFrmFmt, sal_False, &aDocPt );
4401                         pApplyTempl->bUndo = sal_True;
4402                         bCallBase = sal_False;
4403                         if( pApplyTempl->aColl.pFrmFmt )
4404                             aStyleName = pApplyTempl->aColl.pFrmFmt->GetName();
4405                     }
4406                     break;
4407                 }
4408                 case SFX_STYLE_FAMILY_PAGE:
4409                             // Kein Undo bei Seitenvorlagen
4410                     rSh.ChgCurPageDesc( *pApplyTempl->aColl.pPageDesc );
4411                     if ( pApplyTempl->aColl.pPageDesc )
4412                         aStyleName = pApplyTempl->aColl.pPageDesc->GetName();
4413                     bCallBase = sal_False;
4414                     break;
4415                 case SFX_STYLE_FAMILY_PSEUDO:
4416                     if( !rSh.HasReadonlySel() )
4417                     {
4418                         rSh.SetCurNumRule( *pApplyTempl->aColl.pNumRule,
4419                                            false,
4420                                            pApplyTempl->aColl.pNumRule->GetDefaultListId() );
4421                         bCallBase = sal_False;
4422                         pApplyTempl->bUndo = sal_True;
4423                         if( pApplyTempl->aColl.pNumRule )
4424                             aStyleName = pApplyTempl->aColl.pNumRule->GetName();
4425                     }
4426                     break;
4427             }
4428 
4429             uno::Reference< frame::XDispatchRecorder > xRecorder =
4430                     rView.GetViewFrame()->GetBindings().GetRecorder();
4431             if ( aStyleName.Len() && xRecorder.is() )
4432             {
4433                 SfxShell *pSfxShell = lcl_GetShellFromDispatcher( rView, TYPE(SwTextShell) );
4434                 if ( pSfxShell )
4435                 {
4436                     SfxRequest aReq( rView.GetViewFrame(), SID_STYLE_APPLY );
4437                     aReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aStyleName ) );
4438                     aReq.AppendItem( SfxUInt16Item( SID_STYLE_FAMILY, (sal_uInt16) pApplyTempl->eType ) );
4439                     aReq.Done();
4440                 }
4441             }
4442         }
4443 
4444     }
4445     ReleaseMouse();
4446     // Hier kommen nur verarbeitete MouseEvents an; nur bei diesen duerfen
4447     // die Modi zurueckgesetzt werden.
4448     bMBPressed = sal_False;
4449 
4450     //sicherheitshalber aufrufen, da jetzt das Selektieren bestimmt zu Ende ist.
4451     //Andernfalls koennte der Timeout des Timers Kummer machen.
4452     EnterArea();
4453     bNoInterrupt = sal_False;
4454 
4455     if (bCallBase)
4456         Window::MouseButtonUp(rMEvt);
4457 }
4458 
4459 
4460 /*--------------------------------------------------------------------
4461     Beschreibung:   Vorlage anwenden
4462  --------------------------------------------------------------------*/
4463 
4464 
4465 void SwEditWin::SetApplyTemplate(const SwApplyTemplate &rTempl)
4466 {
4467     static sal_Bool bIdle = sal_False;
4468     DELETEZ(pApplyTempl);
4469     SwWrtShell &rSh = rView.GetWrtShell();
4470 
4471     if(rTempl.pFormatClipboard)
4472     {
4473         pApplyTempl = new SwApplyTemplate( rTempl );
4474               SetPointer( POINTER_FILL );//@todo #i20119# maybe better a new brush pointer here in future
4475               rSh.NoEdit( sal_False );
4476               bIdle = rSh.GetViewOptions()->IsIdle();
4477               ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4478     }
4479     else if(rTempl.nColor)
4480     {
4481         pApplyTempl = new SwApplyTemplate( rTempl );
4482         SetPointer( POINTER_FILL );
4483         rSh.NoEdit( sal_False );
4484         bIdle = rSh.GetViewOptions()->IsIdle();
4485         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4486     }
4487     else if( rTempl.eType )
4488     {
4489         pApplyTempl = new SwApplyTemplate( rTempl );
4490         SetPointer( POINTER_FILL  );
4491         rSh.NoEdit( sal_False );
4492         bIdle = rSh.GetViewOptions()->IsIdle();
4493         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( sal_False );
4494     }
4495     else
4496     {
4497         SetPointer( POINTER_TEXT );
4498         rSh.UnSetVisCrsr();
4499 
4500         ((SwViewOption *)rSh.GetViewOptions())->SetIdle( bIdle );
4501         if ( !rSh.IsSelFrmMode() )
4502             rSh.Edit();
4503     }
4504 
4505     static sal_uInt16 __READONLY_DATA aInva[] =
4506     {
4507         SID_STYLE_WATERCAN,
4508         SID_ATTR_CHAR_COLOR_EXT,
4509         SID_ATTR_CHAR_COLOR_BACKGROUND_EXT,
4510         0
4511     };
4512     rView.GetViewFrame()->GetBindings().Invalidate(aInva);
4513 }
4514 
4515 /*--------------------------------------------------------------------
4516     Beschreibung:   ctor
4517  --------------------------------------------------------------------*/
4518 
4519 
4520 SwEditWin::SwEditWin(Window *pParent, SwView &rMyView):
4521     Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
4522     DropTargetHelper( this ),
4523     DragSourceHelper( this ),
4524 
4525     eBufferLanguage(LANGUAGE_DONTKNOW),
4526     pApplyTempl(0),
4527     pAnchorMarker( 0 ),
4528     pUserMarker( 0 ),
4529     pUserMarkerObj( 0 ),
4530     pShadCrsr( 0 ),
4531     pRowColumnSelectionStart( 0 ),
4532 
4533     rView( rMyView ),
4534 
4535     aActHitType(SDRHIT_NONE),
4536     m_nDropFormat( 0 ),
4537     m_nDropAction( 0 ),
4538     m_nDropDestination( 0 ),
4539 
4540     nInsFrmColCount( 1 ),
4541     eDrawMode(OBJ_NONE),
4542 
4543     bLockInput(sal_False),
4544     bObjectSelect( sal_False ),
4545     nKS_NUMDOWN_Count(0),
4546     nKS_NUMINDENTINC_Count(0)
4547 {
4548     SetHelpId(HID_EDIT_WIN);
4549     EnableChildTransparentMode();
4550     SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
4551 
4552     bLinkRemoved = bMBPressed = bInsDraw = bInsFrm =
4553     bIsInDrag = bOldIdle = bOldIdleSet = bChainMode = bWasShdwCrsr = sal_False;
4554     //#i42732# initially use the input language
4555     bUseInputLanguage = sal_True;
4556 
4557     SetMapMode(MapMode(MAP_TWIP));
4558 
4559     SetPointer( POINTER_TEXT );
4560     aTimer.SetTimeoutHdl(LINK(this, SwEditWin, TimerHandler));
4561 
4562     bTblInsDelMode = sal_False;
4563     aKeyInputTimer.SetTimeout( 3000 );
4564     aKeyInputTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputTimerHandler));
4565 
4566     aKeyInputFlushTimer.SetTimeout( 200 );
4567     aKeyInputFlushTimer.SetTimeoutHdl(LINK(this, SwEditWin, KeyInputFlushHandler));
4568 
4569     // TemplatePointer fuer Farben soll nach Einfachclick
4570     // ohne Selektion zurueckgesetzt werden
4571     aTemplateTimer.SetTimeout(400);
4572     aTemplateTimer.SetTimeoutHdl(LINK(this, SwEditWin, TemplateTimerHdl));
4573 
4574     //JP 16.12.98: temporaere Loesung!!! Sollte bei jeder Cursorbewegung
4575     //          den Font von der akt. einfuege Position setzen!
4576     if( !rMyView.GetDocShell()->IsReadOnly() )
4577     {
4578         Font aFont;
4579         SetInputContext( InputContext( aFont, INPUTCONTEXT_TEXT |
4580                                             INPUTCONTEXT_EXTTEXTINPUT ) );
4581     }
4582 }
4583 
4584 
4585 
4586 SwEditWin::~SwEditWin()
4587 {
4588     aKeyInputTimer.Stop();
4589     delete pShadCrsr;
4590     delete pRowColumnSelectionStart;
4591     if( pQuickHlpData->bClear && rView.GetWrtShellPtr() )
4592         pQuickHlpData->Stop( rView.GetWrtShell() );
4593     bExecuteDrag = sal_False;
4594     delete pApplyTempl;
4595     rView.SetDrawFuncPtr(NULL);
4596 
4597     if(pUserMarker)
4598     {
4599         delete pUserMarker;
4600     }
4601 
4602     delete pAnchorMarker;
4603 }
4604 
4605 
4606 /******************************************************************************
4607  *  Beschreibung: DrawTextEditMode einschalten
4608  ******************************************************************************/
4609 
4610 
4611 void SwEditWin::EnterDrawTextMode( const Point& aDocPos )
4612 {
4613     if ( rView.EnterDrawTextMode(aDocPos) == sal_True )
4614     {
4615         if (rView.GetDrawFuncPtr())
4616         {
4617             rView.GetDrawFuncPtr()->Deactivate();
4618             rView.SetDrawFuncPtr(NULL);
4619             rView.LeaveDrawCreate();
4620         }
4621         rView.NoRotate();
4622         rView.AttrChangedNotify( &rView.GetWrtShell() );
4623     }
4624 }
4625 
4626 /******************************************************************************
4627  *  Beschreibung: DrawMode einschalten
4628  ******************************************************************************/
4629 
4630 
4631 
4632 sal_Bool SwEditWin::EnterDrawMode(const MouseEvent& rMEvt, const Point& aDocPos)
4633 {
4634     SwWrtShell &rSh = rView.GetWrtShell();
4635     SdrView *pSdrView = rSh.GetDrawView();
4636 
4637     if ( rView.GetDrawFuncPtr() )
4638     {
4639         if (rSh.IsDrawCreate())
4640             return sal_True;
4641 
4642         sal_Bool bRet = rView.GetDrawFuncPtr()->MouseButtonDown( rMEvt );
4643         rView.AttrChangedNotify( &rSh );
4644         return bRet;
4645     }
4646 
4647     if ( pSdrView && pSdrView->IsTextEdit() )
4648     {
4649         sal_Bool bUnLockView = !rSh.IsViewLocked();
4650         rSh.LockView( sal_True );
4651 
4652         rSh.EndTextEdit(); // Danebengeklickt, Ende mit Edit
4653         rSh.SelectObj( aDocPos );
4654         if ( !rSh.IsObjSelected() && !rSh.IsFrmSelected() )
4655             rSh.LeaveSelFrmMode();
4656         else
4657         {
4658             SwEditWin::nDDStartPosY = aDocPos.Y();
4659             SwEditWin::nDDStartPosX = aDocPos.X();
4660             bFrmDrag = sal_True;
4661         }
4662         if( bUnLockView )
4663             rSh.LockView( sal_False );
4664         rView.AttrChangedNotify( &rSh );
4665         return sal_True;
4666     }
4667     return sal_False;
4668 }
4669 
4670 /******************************************************************************
4671  *  Beschreibung:
4672  ******************************************************************************/
4673 
4674 
4675 
4676 sal_Bool SwEditWin::IsDrawSelMode()
4677 {
4678     return IsObjectSelect();
4679 }
4680 
4681 /******************************************************************************
4682  *  Beschreibung:
4683  ******************************************************************************/
4684 
4685 
4686 void SwEditWin::GetFocus()
4687 {
4688     if ( rView.GetPostItMgr()->HasActiveSidebarWin() )
4689     {
4690         rView.GetPostItMgr()->GrabFocusOnActiveSidebarWin();
4691     }
4692 	else
4693 	{
4694 		rView.GotFocus();
4695 		Window::GetFocus();
4696 		rView.GetWrtShell().InvalidateAccessibleFocus();
4697 	}
4698 }
4699 
4700 /******************************************************************************
4701  *  Beschreibung:
4702  ******************************************************************************/
4703 
4704 
4705 
4706 void SwEditWin::LoseFocus()
4707 {
4708     rView.GetWrtShell().InvalidateAccessibleFocus();
4709     Window::LoseFocus();
4710     if( pQuickHlpData->bClear )
4711         pQuickHlpData->Stop( rView.GetWrtShell() );
4712     rView.LostFocus();
4713 }
4714 
4715 /******************************************************************************
4716  *  Beschreibung:
4717  ******************************************************************************/
4718 
4719 
4720 
4721 void SwEditWin::Command( const CommandEvent& rCEvt )
4722 {
4723     SwWrtShell &rSh = rView.GetWrtShell();
4724 
4725 	if ( !rView.GetViewFrame() )
4726 	{
4727 		//Wenn der ViewFrame in Kuerze stirbt kein Popup mehr!
4728 		Window::Command(rCEvt);
4729 		return;
4730 	}
4731 
4732     // The command event is send to the window after a possible context
4733     // menu from an inplace client has been closed. Now we have the chance
4734     // to deactivate the inplace client without any problem regarding parent
4735     // windows and code on the stack.
4736     // For more information, see #126086# and #128122#
4737     SfxInPlaceClient* pIPClient = rSh.GetSfxViewShell()->GetIPClient();
4738     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
4739     if ( bIsOleActive && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ))
4740     {
4741         rSh.FinishOLEObj();
4742         return;
4743     }
4744 
4745     sal_Bool bCallBase      = sal_True;
4746 
4747     switch ( rCEvt.GetCommand() )
4748     {
4749         case COMMAND_CONTEXTMENU:
4750         {
4751             const sal_uInt16 nId = SwInputChild::GetChildWindowId();
4752             SwInputChild* pChildWin = (SwInputChild*)GetView().GetViewFrame()->
4753                                                 GetChildWindow( nId );
4754 
4755             if (rView.GetPostItMgr()->IsHit(rCEvt.GetMousePosPixel()))
4756                 return;
4757 
4758             if((!pChildWin || pChildWin->GetView() != &rView) &&
4759                 !rSh.IsDrawCreate() && !IsDrawAction())
4760             {
4761                 SET_CURR_SHELL( &rSh );
4762                 if (!pApplyTempl)
4763                 {
4764                     if (bNoInterrupt == sal_True)
4765                     {
4766                         ReleaseMouse();
4767                         bNoInterrupt = sal_False;
4768                         bMBPressed = sal_False;
4769                     }
4770                     Point aDocPos( PixelToLogic( rCEvt.GetMousePosPixel() ) );
4771                     if ( !rCEvt.IsMouseEvent() )
4772                         aDocPos = rSh.GetCharRect().Center();
4773                     else
4774                     {
4775                         SelectMenuPosition(rSh, rCEvt.GetMousePosPixel());
4776                         rView.StopShellTimer();
4777 
4778                     }
4779                     const Point aPixPos = LogicToPixel( aDocPos );
4780 
4781                     if ( rView.GetDocShell()->IsReadOnly() )
4782                     {
4783                         SwReadOnlyPopup* pROPopup = new SwReadOnlyPopup( aDocPos, rView );
4784 
4785                         ui::ContextMenuExecuteEvent aEvent;
4786                         aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
4787                         aEvent.ExecutePosition.X = aPixPos.X();
4788                         aEvent.ExecutePosition.Y = aPixPos.Y();
4789                         Menu* pMenu = 0;
4790                         ::rtl::OUString sMenuName =
4791                             ::rtl::OUString::createFromAscii( "private:resource/ReadonlyContextMenu");
4792                         if( GetView().TryContextMenuInterception( *pROPopup, sMenuName, pMenu, aEvent ) )
4793                         {
4794                             if ( pMenu )
4795                             {
4796                                 sal_uInt16 nExecId = ((PopupMenu*)pMenu)->Execute(this, aPixPos);
4797                                 if( !::ExecuteMenuCommand( *static_cast<PopupMenu*>(pMenu), *rView.GetViewFrame(), nExecId ))
4798                                     pROPopup->Execute(this, nExecId);
4799                             }
4800                             else
4801                                 pROPopup->Execute(this, aPixPos);
4802                         }
4803                         delete pROPopup;
4804                     }
4805                     else if ( !rView.ExecSpellPopup( aDocPos ) )
4806                         GetView().GetViewFrame()->GetDispatcher()->ExecutePopup( 0, this, &aPixPos);
4807                 }
4808                 else if (pApplyTempl->bUndo)
4809                     rSh.Do(SwWrtShell::UNDO);
4810                 bCallBase = sal_False;
4811             }
4812         }
4813         break;
4814 
4815         case COMMAND_WHEEL:
4816         case COMMAND_STARTAUTOSCROLL:
4817         case COMMAND_AUTOSCROLL:
4818             if( pShadCrsr )
4819                 delete pShadCrsr, pShadCrsr = 0;
4820             bCallBase = !rView.HandleWheelCommands( rCEvt );
4821             break;
4822 
4823         case COMMAND_VOICE:
4824             {
4825                 //ggf. an Outliner weiterleiten
4826                 if ( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4827                 {
4828                     bCallBase = sal_False;
4829                     rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4830                     break;
4831                 }
4832 
4833                 const CommandVoiceData *pCData = rCEvt.GetVoiceData();
4834                 if ( VOICECOMMANDTYPE_CONTROL == pCData->GetType() )
4835                     break;
4836 
4837 
4838                 sal_uInt16 nSlotId = 0;
4839                 SfxPoolItem *pItem = 0;
4840 
4841                 switch ( pCData->GetCommand() )
4842                 {
4843                     case DICTATIONCOMMAND_NEWPARAGRAPH: nSlotId = FN_INSERT_BREAK; break;
4844                     case DICTATIONCOMMAND_NEWLINE:      nSlotId = FN_INSERT_LINEBREAK; break;
4845                     case DICTATIONCOMMAND_LEFT:         nSlotId = FN_PREV_WORD; break;
4846                     case DICTATIONCOMMAND_RIGHT:        nSlotId = FN_NEXT_WORD; break;
4847                     case DICTATIONCOMMAND_UP:           nSlotId = FN_LINE_UP; break;
4848                     case DICTATIONCOMMAND_DOWN:         nSlotId = FN_LINE_DOWN; break;
4849                     case DICTATIONCOMMAND_UNDO:         nSlotId = SID_UNDO; break;
4850                     case DICTATIONCOMMAND_REPEAT:       nSlotId = SID_REPEAT; break;
4851                     case DICTATIONCOMMAND_DEL:          nSlotId = FN_DELETE_BACK_WORD; break;
4852 
4853                     case DICTATIONCOMMAND_BOLD_ON:      nSlotId = SID_ATTR_CHAR_WEIGHT;
4854                                                         pItem = new SvxWeightItem( WEIGHT_BOLD, RES_CHRATR_WEIGHT );
4855                                                         break;
4856                     case DICTATIONCOMMAND_BOLD_OFF:     nSlotId = SID_ATTR_CHAR_WEIGHT;
4857                                                         pItem = new SvxWeightItem( WEIGHT_NORMAL, RES_CHRATR_WEIGHT );
4858                                                         break;
4859                     case DICTATIONCOMMAND_UNDERLINE_ON: nSlotId = SID_ATTR_CHAR_UNDERLINE;
4860                                                         pItem = new SvxUnderlineItem( UNDERLINE_SINGLE, RES_CHRATR_WEIGHT );
4861                                                         break;
4862                     case DICTATIONCOMMAND_UNDERLINE_OFF:nSlotId = SID_ATTR_CHAR_UNDERLINE;
4863                                                         pItem = new SvxUnderlineItem( UNDERLINE_NONE, RES_CHRATR_UNDERLINE );
4864                                                         break;
4865                     case DICTATIONCOMMAND_ITALIC_ON:    nSlotId = SID_ATTR_CHAR_POSTURE;
4866                                                         pItem = new SvxPostureItem( ITALIC_NORMAL, RES_CHRATR_POSTURE );
4867                                                         break;
4868                     case DICTATIONCOMMAND_ITALIC_OFF:   nSlotId = SID_ATTR_CHAR_POSTURE;
4869                                                         pItem = new SvxPostureItem( ITALIC_NONE, RES_CHRATR_POSTURE );
4870                                                         break;
4871                     case DICTATIONCOMMAND_NUMBERING_ON:
4872                                     if ( !rSh.GetCurNumRule() )
4873                                         nSlotId = FN_NUM_NUMBERING_ON;
4874                                     break;
4875                     case DICTATIONCOMMAND_NUMBERING_OFF:
4876                                     if ( rSh.GetCurNumRule() )
4877                                        nSlotId = FN_NUM_NUMBERING_ON;
4878                                     break;
4879                     case DICTATIONCOMMAND_TAB:
4880                                     {
4881                                        rSh.Insert( '\t' );
4882                                     }
4883                                     break;
4884                     case DICTATIONCOMMAND_UNKNOWN:
4885                                     {
4886                                         rView.GetWrtShell().Insert( pCData->GetText() );
4887                                     }
4888                                     break;
4889 
4890 #ifdef DBG_UTIL
4891                     default:
4892                         ASSERT( !this, "unknown speech command." );
4893 #endif
4894                 }
4895                 if ( nSlotId )
4896                 {
4897                     bCallBase = sal_False;
4898                     if ( pItem )
4899                     {
4900                         const SfxPoolItem* aArgs[2];
4901                         aArgs[0] = pItem;
4902                         aArgs[1] = 0;
4903                         GetView().GetViewFrame()->GetBindings().Execute(
4904                                     nSlotId, aArgs, 0, SFX_CALLMODE_STANDARD );
4905                         delete pItem;
4906                     }
4907                     else
4908                         GetView().GetViewFrame()->GetBindings().Execute( nSlotId );
4909                 }
4910             }
4911             break;
4912 
4913     case COMMAND_STARTEXTTEXTINPUT:
4914     {
4915         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
4916                               rSh.IsCrsrReadonly();
4917         if(!bIsDocReadOnly)
4918         {
4919             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4920             {
4921                 bCallBase = sal_False;
4922                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4923             }
4924             else
4925             {
4926                 if( rSh.HasSelection() )
4927                     rSh.DelRight();
4928 
4929                 bCallBase = sal_False;
4930                 LanguageType eInputLanguage = GetInputLanguage();
4931                 rSh.CreateExtTextInput(eInputLanguage);
4932             }
4933         }
4934         break;
4935     }
4936     case COMMAND_ENDEXTTEXTINPUT:
4937     {
4938         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
4939                               rSh.IsCrsrReadonly();
4940         if(!bIsDocReadOnly)
4941         {
4942             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
4943             {
4944                 bCallBase = sal_False;
4945                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
4946             }
4947             else
4948             {
4949                 bCallBase = sal_False;
4950                 String sRecord = rSh.DeleteExtTextInput();
4951                 uno::Reference< frame::XDispatchRecorder > xRecorder =
4952                         rView.GetViewFrame()->GetBindings().GetRecorder();
4953 
4954                 if ( sRecord.Len() )
4955                 {
4956                     // #102812# convert quotes in IME text
4957                     // works on the last input character, this is escpecially in Korean text often done
4958                     // quotes that are inside of the string are not replaced!
4959                     const sal_Unicode aCh = sRecord.GetChar(sRecord.Len() - 1);
4960                     SvxAutoCorrCfg* pACfg = SvxAutoCorrCfg::Get();
4961                     SvxAutoCorrect* pACorr = pACfg->GetAutoCorrect();
4962                     if(pACorr &&
4963                         (( pACorr->IsAutoCorrFlag( ChgQuotes ) && ('\"' == aCh ))||
4964                         ( pACorr->IsAutoCorrFlag( ChgSglQuotes ) && ( '\'' == aCh))))
4965                     {
4966                         rSh.DelLeft();
4967                         rSh.AutoCorrect( *pACorr, aCh );
4968                     }
4969 
4970                     if ( xRecorder.is() )
4971                     {
4972                         //Shell ermitteln
4973                         SfxShell *pSfxShell = lcl_GetShellFromDispatcher( rView, TYPE(SwTextShell) );
4974                         // Request generieren und recorden
4975                         if (pSfxShell)
4976                         {
4977                             SfxRequest aReq( rView.GetViewFrame(), FN_INSERT_STRING );
4978                             aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sRecord ) );
4979                             aReq.Done();
4980                         }
4981                     }
4982                 }
4983             }
4984         }
4985     }
4986     break;
4987     case COMMAND_EXTTEXTINPUT:
4988     {
4989         sal_Bool bIsDocReadOnly = rView.GetDocShell()->IsReadOnly() &&
4990                               rSh.IsCrsrReadonly();
4991         if(!bIsDocReadOnly)
4992         {
4993             QuickHelpData aTmpQHD;
4994             if( pQuickHlpData->bClear )
4995             {
4996                 aTmpQHD.Move( *pQuickHlpData );
4997                 pQuickHlpData->Stop( rSh );
4998             }
4999             String sWord;
5000             if( rSh.HasDrawView() && rSh.GetDrawView()->IsTextEdit() )
5001             {
5002                 bCallBase = sal_False;
5003                 rSh.GetDrawView()->GetTextEditOutlinerView()->Command( rCEvt );
5004             }
5005             else
5006             {
5007                 const CommandExtTextInputData* pData = rCEvt.GetExtTextInputData();
5008                 if( pData )
5009                 {
5010                     sWord = pData->GetText();
5011                     bCallBase = sal_False;
5012                     rSh.SetExtTextInputData( *pData );
5013                 }
5014             }
5015                 uno::Reference< frame::XDispatchRecorder > xRecorder =
5016                         rView.GetViewFrame()->GetBindings().GetRecorder();
5017                 if(!xRecorder.is())
5018                 {
5019                     SvxAutoCorrCfg* pACfg = SvxAutoCorrCfg::Get();
5020                     SvxAutoCorrect* pACorr = pACfg->GetAutoCorrect();
5021                     if( pACfg && pACorr &&
5022                         ( pACfg->IsAutoTextTip() ||
5023                           pACorr->GetSwFlags().bAutoCompleteWords ) &&
5024                         rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
5025                     {
5026                         ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr, sal_True);
5027                     }
5028                 }
5029         }
5030     }
5031     break;
5032     case COMMAND_CURSORPOS:
5033         // will be handled by the base class
5034         break;
5035 
5036     case COMMAND_PASTESELECTION:
5037         if( !rView.GetDocShell()->IsReadOnly() )
5038         {
5039             TransferableDataHelper aDataHelper(
5040                         TransferableDataHelper::CreateFromSelection( this ));
5041             if( !aDataHelper.GetXTransferable().is() )
5042                 break;
5043 
5044             sal_uLong nDropFormat;
5045             sal_uInt16 nEventAction, nDropAction, nDropDestination;
5046             nDropDestination = GetDropDestination( rCEvt.GetMousePosPixel() );
5047             if( !nDropDestination )
5048                 break;
5049 
5050             nDropAction = SotExchange::GetExchangeAction(
5051                                 aDataHelper.GetDataFlavorExVector(),
5052                                 nDropDestination, EXCHG_IN_ACTION_COPY,
5053                                 EXCHG_IN_ACTION_COPY, nDropFormat,
5054                                 nEventAction );
5055             if( EXCHG_INOUT_ACTION_NONE != nDropAction )
5056             {
5057                 const Point aDocPt( PixelToLogic( rCEvt.GetMousePosPixel() ) );
5058                 SwTransferable::PasteData( aDataHelper, rSh, nDropAction,
5059                                     nDropFormat, nDropDestination, sal_False,
5060                                     sal_False, &aDocPt, EXCHG_IN_ACTION_COPY,
5061                                     sal_True );
5062             }
5063         }
5064         break;
5065         case COMMAND_MODKEYCHANGE :
5066         {
5067             const CommandModKeyData* pCommandData = (const CommandModKeyData*)rCEvt.GetData();
5068             if(pCommandData->IsMod1() && !pCommandData->IsMod2())
5069             {
5070                 sal_uInt16 nSlot = 0;
5071                 if(pCommandData->IsLeftShift() && !pCommandData->IsRightShift())
5072                     nSlot = SID_ATTR_PARA_LEFT_TO_RIGHT;
5073                 else if(!pCommandData->IsLeftShift() && pCommandData->IsRightShift())
5074                     nSlot = SID_ATTR_PARA_RIGHT_TO_LEFT;
5075                 if(nSlot && SW_MOD()->GetCTLOptions().IsCTLFontEnabled())
5076                     GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
5077             }
5078         }
5079         break;
5080         case COMMAND_HANGUL_HANJA_CONVERSION :
5081             GetView().GetViewFrame()->GetDispatcher()->Execute(SID_HANGUL_HANJA_CONVERSION);
5082         break;
5083         case COMMAND_INPUTLANGUAGECHANGE :
5084             //#i42732# update state of fontname if input language changes
5085             bInputLanguageSwitched = true;
5086             SetUseInputLanguage( sal_True );
5087         break;
5088         case COMMAND_SELECTIONCHANGE:
5089         {
5090             const CommandSelectionChangeData *pData = rCEvt.GetSelectionChangeData();
5091             rSh.SttCrsrMove();
5092             rSh.GoStartSentence();
5093             rSh.GetCrsr()->GetPoint()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetStart());
5094             rSh.SetMark();
5095             rSh.GetCrsr()->GetMark()->nContent += sal::static_int_cast<sal_uInt16, sal_uLong>(pData->GetEnd() - pData->GetStart());
5096             rSh.EndCrsrMove( sal_True );
5097         }
5098         break;
5099         case COMMAND_PREPARERECONVERSION:
5100         if( rSh.HasSelection() )
5101         {
5102             SwPaM *pCrsr = (SwPaM*)rSh.GetCrsr();
5103 
5104             if( rSh.IsMultiSelection() )
5105             {
5106                 if( pCrsr && !pCrsr->HasMark() &&
5107                 pCrsr->GetPoint() == pCrsr->GetMark() )
5108                 {
5109                 rSh.GoPrevCrsr();
5110                 pCrsr = (SwPaM*)rSh.GetCrsr();
5111                 }
5112 
5113                 // Cancel all selections other than the last selected one.
5114                 while( rSh.GetCrsr()->GetNext() != rSh.GetCrsr() )
5115                 delete rSh.GetCrsr()->GetNext();
5116             }
5117 
5118             if( pCrsr )
5119             {
5120                 sal_uLong nPosNodeIdx = pCrsr->GetPoint()->nNode.GetIndex();
5121                 xub_StrLen nPosIdx = pCrsr->GetPoint()->nContent.GetIndex();
5122                 sal_uLong nMarkNodeIdx = pCrsr->GetMark()->nNode.GetIndex();
5123                 xub_StrLen nMarkIdx = pCrsr->GetMark()->nContent.GetIndex();
5124 
5125                 if( !rSh.GetCrsr()->HasMark() )
5126                 rSh.GetCrsr()->SetMark();
5127 
5128                 rSh.SttCrsrMove();
5129 
5130                 if( nPosNodeIdx < nMarkNodeIdx )
5131                 {
5132                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
5133                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
5134                 rSh.GetCrsr()->GetMark()->nNode = nPosNodeIdx;
5135                 rSh.GetCrsr()->GetMark()->nContent =
5136                     rSh.GetCrsr()->GetCntntNode( sal_True )->Len();
5137                 }
5138                 else if( nPosNodeIdx == nMarkNodeIdx )
5139                 {
5140                 rSh.GetCrsr()->GetPoint()->nNode = nPosNodeIdx;
5141                 rSh.GetCrsr()->GetPoint()->nContent = nPosIdx;
5142                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
5143                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
5144                 }
5145                 else
5146                 {
5147                 rSh.GetCrsr()->GetMark()->nNode = nMarkNodeIdx;
5148                 rSh.GetCrsr()->GetMark()->nContent = nMarkIdx;
5149                 rSh.GetCrsr()->GetPoint()->nNode = nMarkNodeIdx;
5150                 rSh.GetCrsr()->GetPoint()->nContent =
5151                     rSh.GetCrsr()->GetCntntNode( sal_False )->Len();
5152                 }
5153 
5154                 rSh.EndCrsrMove( sal_True );
5155             }
5156         }
5157         break;
5158 #ifdef DBG_UTIL
5159         default:
5160             ASSERT( !this, "unknown command." );
5161 #endif
5162     }
5163     if (bCallBase)
5164         Window::Command(rCEvt);
5165 }
5166 
5167 /* -----------------25.08.2003 10:12-----------------
5168     #i18686#: select the object/cursor at the mouse
5169     position of the context menu request
5170  --------------------------------------------------*/
5171 sal_Bool SwEditWin::SelectMenuPosition(SwWrtShell& rSh, const Point& rMousePos )
5172 {
5173     sal_Bool bRet = sal_False;
5174     const Point aDocPos( PixelToLogic( rMousePos ) );
5175     const bool bIsInsideSelectedObj( rSh.IsInsideSelectedObj( aDocPos ) );
5176     //create a synthetic mouse event out of the coordinates
5177     MouseEvent aMEvt(rMousePos);
5178     SdrView *pSdrView = rSh.GetDrawView();
5179     if ( pSdrView )
5180     {
5181         // no close of insert_draw and reset of draw mode,
5182         // if context menu position is inside a selected object.
5183         if ( !bIsInsideSelectedObj && rView.GetDrawFuncPtr() )
5184         {
5185 
5186             rView.GetDrawFuncPtr()->Deactivate();
5187             rView.SetDrawFuncPtr(NULL);
5188             rView.LeaveDrawCreate();
5189             SfxBindings& rBind = rView.GetViewFrame()->GetBindings();
5190             rBind.Invalidate( SID_ATTR_SIZE );
5191             rBind.Invalidate( SID_TABLE_CELL );
5192         }
5193 
5194         // if draw text is active and there's a text selection
5195         // at the mouse position then do nothing
5196         if(rSh.GetSelectionType() & nsSelectionType::SEL_DRW_TXT)
5197         {
5198             OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
5199             ESelection aSelection = pOLV->GetSelection();
5200             if(!aSelection.IsZero())
5201             {
5202                 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
5203                 sal_Bool bVertical = pOutliner->IsVertical();
5204                 const EditEngine& rEditEng = pOutliner->GetEditEngine();
5205                 Point aEEPos(aDocPos);
5206                 const Rectangle& rOutputArea = pOLV->GetOutputArea();
5207                 // regard vertical mode
5208                 if(bVertical)
5209                 {
5210                     aEEPos -= rOutputArea.TopRight();
5211                     //invert the horizontal direction and exchange X and Y
5212                     long nTemp = -aEEPos.X();
5213                     aEEPos.X() = aEEPos.Y();
5214                     aEEPos.Y() = nTemp;
5215                 }
5216                 else
5217                     aEEPos -= rOutputArea.TopLeft();
5218 
5219                 EPosition aDocPosition = rEditEng.FindDocPosition(aEEPos);
5220                 ESelection aCompare(aDocPosition.nPara, aDocPosition.nIndex);
5221                 // make it a forward selection - otherwise the IsLess/IsGreater do not work :-(
5222                 aSelection.Adjust();
5223                 if(!aCompare.IsLess(aSelection)  && !aCompare.IsGreater(aSelection))
5224                 {
5225                     return sal_False;
5226                 }
5227             }
5228 
5229         }
5230 
5231         if (pSdrView->MouseButtonDown( aMEvt, this ) )
5232         {
5233             pSdrView->MouseButtonUp( aMEvt, this );
5234             rSh.GetView().GetViewFrame()->GetBindings().InvalidateAll(sal_False);
5235             return sal_True;
5236         }
5237     }
5238     rSh.ResetCursorStack();
5239 
5240     if ( EnterDrawMode( aMEvt, aDocPos ) )
5241     {
5242         return sal_True;
5243     }
5244     if ( rView.GetDrawFuncPtr() && bInsFrm )
5245     {
5246         StopInsFrm();
5247         rSh.Edit();
5248     }
5249 
5250     UpdatePointer( aDocPos, 0 );
5251 
5252     if( !rSh.IsSelFrmMode() &&
5253         !GetView().GetViewFrame()->GetDispatcher()->IsLocked() )
5254     {
5255         // #107513#
5256         // Test if there is a draw object at that position and if it should be selected.
5257         sal_Bool bShould = rSh.ShouldObjectBeSelected(aDocPos);
5258 
5259         if(bShould)
5260         {
5261             rView.NoRotate();
5262             rSh.HideCrsr();
5263 
5264             sal_Bool bUnLockView = !rSh.IsViewLocked();
5265             rSh.LockView( sal_True );
5266             sal_Bool bSelObj = rSh.SelectObj( aDocPos, 0);
5267             if( bUnLockView )
5268                 rSh.LockView( sal_False );
5269 
5270             if( bSelObj )
5271             {
5272                 bRet = sal_True;
5273                 // falls im Macro der Rahmen deselektiert
5274                 // wurde, muss nur noch der Cursor
5275                 // wieder angezeigt werden.
5276                 if( FRMTYPE_NONE == rSh.GetSelFrmType() )
5277                     rSh.ShowCrsr();
5278                 else
5279                 {
5280                     if (rSh.IsFrmSelected() && rView.GetDrawFuncPtr())
5281                     {
5282                         rView.GetDrawFuncPtr()->Deactivate();
5283                         rView.SetDrawFuncPtr(NULL);
5284                         rView.LeaveDrawCreate();
5285                         rView.AttrChangedNotify( &rSh );
5286                     }
5287 
5288                     rSh.EnterSelFrmMode( &aDocPos );
5289                     bFrmDrag = sal_True;
5290                     UpdatePointer( aDocPos, 0 );
5291                     return bRet;
5292                 }
5293             }
5294 
5295             if (!rView.GetDrawFuncPtr())
5296                 rSh.ShowCrsr();
5297         }
5298     }
5299     else if ( rSh.IsSelFrmMode() &&
5300               (aActHitType == SDRHIT_NONE ||
5301                !bIsInsideSelectedObj))
5302     {
5303         rView.NoRotate();
5304         sal_Bool bUnLockView = !rSh.IsViewLocked();
5305         rSh.LockView( sal_True );
5306         sal_uInt8 nFlag = 0;
5307 
5308         if ( rSh.IsSelFrmMode() )
5309         {
5310             rSh.UnSelectFrm();
5311             rSh.LeaveSelFrmMode();
5312             rView.AttrChangedNotify(&rSh);
5313             bRet = sal_True;
5314         }
5315 
5316         sal_Bool bSelObj = rSh.SelectObj( aDocPos, nFlag );
5317         if( bUnLockView )
5318             rSh.LockView( sal_False );
5319 
5320         if( !bSelObj )
5321         {
5322             // Cursor hier umsetzen, damit er nicht zuerst
5323             // im Rahmen gezeichnet wird; ShowCrsr() geschieht
5324             // in LeaveSelFrmMode()
5325             bValidCrsrPos = !(CRSR_POSCHG & (rSh.*rSh.fnSetCrsr)(&aDocPos,sal_False));
5326             rSh.LeaveSelFrmMode();
5327             rView.LeaveDrawCreate();
5328             rView.AttrChangedNotify( &rSh );
5329             bRet = sal_True;
5330         }
5331         else
5332         {
5333             rSh.HideCrsr();
5334             rSh.EnterSelFrmMode( &aDocPos );
5335             rSh.SelFlyGrabCrsr();
5336             rSh.MakeSelVisible();
5337             bFrmDrag = sal_True;
5338             if( rSh.IsFrmSelected() &&
5339                 rView.GetDrawFuncPtr() )
5340             {
5341                 rView.GetDrawFuncPtr()->Deactivate();
5342                 rView.SetDrawFuncPtr(NULL);
5343                 rView.LeaveDrawCreate();
5344                 rView.AttrChangedNotify( &rSh );
5345             }
5346             UpdatePointer( aDocPos, 0 );
5347             bRet = sal_True;
5348         }
5349     }
5350     else if ( rSh.IsSelFrmMode() && bIsInsideSelectedObj )
5351     {
5352         // ## object at the mouse cursor is already selected - do nothing
5353         return sal_False;
5354     }
5355 
5356     if ( rSh.IsGCAttr() )
5357     {
5358         rSh.GCAttr();
5359         rSh.ClearGCAttr();
5360     }
5361 
5362     sal_Bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = sal_False;
5363     if( !bOverSelect )
5364         bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );
5365 
5366     if ( !bOverSelect )
5367     {
5368         {   // nur temp. Move-Kontext aufspannen, da sonst die
5369             // Abfrage auf die Inhaltsform nicht funktioniert!!!
5370             MV_KONTEXT( &rSh );
5371             (rSh.*rSh.fnSetCrsr)(&aDocPos, sal_False);
5372             bRet = sal_True;
5373         }
5374     }
5375     if( !bOverURLGrf )
5376     {
5377         const int nSelType = rSh.GetSelectionType();
5378         if( nSelType == nsSelectionType::SEL_OLE ||
5379             nSelType == nsSelectionType::SEL_GRF )
5380         {
5381             MV_KONTEXT( &rSh );
5382             if( !rSh.IsFrmSelected() )
5383                 rSh.GotoNextFly();
5384             rSh.EnterSelFrmMode();
5385             bRet = sal_True;
5386         }
5387     }
5388     return bRet;
5389 }
5390 
5391 SfxShell* lcl_GetShellFromDispatcher( SwView& rView, TypeId nType )
5392 {
5393     //Shell ermitteln
5394     SfxShell* pShell;
5395     SfxDispatcher* pDispatcher = rView.GetViewFrame()->GetDispatcher();
5396     for(sal_uInt16  i = 0; sal_True; ++i )
5397     {
5398         pShell = pDispatcher->GetShell( i );
5399         if( !pShell || pShell->IsA( nType ) )
5400             break;
5401     }
5402     return pShell;
5403 }
5404 
5405 
5406 
5407 void SwEditWin::ClearTip()
5408 {
5409 }
5410 
5411 IMPL_LINK( SwEditWin, KeyInputFlushHandler, Timer *, EMPTYARG )
5412 {
5413     FlushInBuffer();
5414     return 0;
5415 }
5416 
5417 
5418 IMPL_LINK( SwEditWin, KeyInputTimerHandler, Timer *, EMPTYARG )
5419 {
5420     bTblInsDelMode = sal_False;
5421     return 0;
5422 }
5423 
5424 void SwEditWin::_InitStaticData()
5425 {
5426     pQuickHlpData = new QuickHelpData();
5427 }
5428 
5429 void SwEditWin::_FinitStaticData()
5430 {
5431     delete pQuickHlpData;
5432 }
5433 /* -----------------23.01.2003 12:15-----------------
5434  * #i3370# remove quick help to prevent saving
5435  * of autocorrection suggestions
5436  * --------------------------------------------------*/
5437 void SwEditWin::StopQuickHelp()
5438 {
5439     if( HasFocus() && pQuickHlpData && pQuickHlpData->bClear  )
5440         pQuickHlpData->Stop( rView.GetWrtShell() );
5441 }
5442 
5443 /*-----------------23.02.97 18:39-------------------
5444 
5445 --------------------------------------------------*/
5446 
5447 
5448 IMPL_LINK(SwEditWin, TemplateTimerHdl, Timer*, EMPTYARG)
5449 {
5450     SetApplyTemplate(SwApplyTemplate());
5451     return 0;
5452 }
5453 
5454 
5455 void SwEditWin::SetChainMode( sal_Bool bOn )
5456 {
5457     if ( !bChainMode )
5458         StopInsFrm();
5459 
5460     if ( pUserMarker )
5461     {
5462         delete pUserMarker;
5463         pUserMarker = 0L;
5464     }
5465 
5466     bChainMode = bOn;
5467     if ( !bChainMode )
5468         rView.GetViewFrame()->HideStatusText();
5469 
5470     static sal_uInt16 __READONLY_DATA aInva[] =
5471     {
5472         FN_FRAME_CHAIN, FN_FRAME_UNCHAIN, 0
5473     };
5474     rView.GetViewFrame()->GetBindings().Invalidate(aInva);
5475 }
5476 
5477 uno::Reference< ::com::sun::star::accessibility::XAccessible > SwEditWin::CreateAccessible()
5478 {
5479     vos::OGuard aGuard(Application::GetSolarMutex());   // this should have
5480                                                         // happend already!!!
5481     SwWrtShell *pSh = rView.GetWrtShellPtr();
5482     ASSERT( pSh, "no writer shell, no accessible object" );
5483     uno::Reference<
5484         ::com::sun::star::accessibility::XAccessible > xAcc;
5485     if( pSh )
5486         xAcc = pSh->CreateAccessible();
5487 
5488     return xAcc;
5489 }
5490 
5491 //-------------------------------------------------------------
5492 
5493 void QuickHelpData::Move( QuickHelpData& rCpy )
5494 {
5495     // Pointer verschieben
5496     aArr.Insert( &rCpy.aArr );
5497     rCpy.aArr.Remove( (sal_uInt16)0, rCpy.aArr.Count() );
5498 //  nTipId = rCpy.nTipId;
5499     bClear = rCpy.bClear;
5500     nLen = rCpy.nLen;
5501     nCurArrPos = rCpy.nCurArrPos;
5502     bChkInsBlank = rCpy.bChkInsBlank;
5503     bIsTip = rCpy.bIsTip;
5504     bIsAutoText = rCpy.bIsAutoText;
5505 
5506     if( pCETID ) delete pCETID;
5507     pCETID = rCpy.pCETID;
5508     rCpy.pCETID = 0;
5509 
5510     if( pAttrs )
5511         delete[] pAttrs;
5512     pAttrs = rCpy.pAttrs;
5513     rCpy.pAttrs = 0;
5514 }
5515 
5516 void QuickHelpData::ClearCntnt()
5517 {
5518     nLen = nCurArrPos = 0;
5519     bClear = bChkInsBlank = sal_False;
5520     nTipId = 0;
5521     aArr.DeleteAndDestroy( 0 , aArr.Count() );
5522     bIsTip = sal_True;
5523     bIsAutoText = sal_True;
5524     delete pCETID, pCETID = 0;
5525     delete[] pAttrs, pAttrs = 0;
5526 }
5527 
5528 
5529 void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
5530 {
5531     if( pCETID ) delete pCETID, pCETID = 0;
5532     if( pAttrs ) delete[] pAttrs, pAttrs = 0;
5533 
5534     if( USHRT_MAX != nWrdLen )
5535     {
5536         nLen = nWrdLen;
5537         nCurArrPos = 0;
5538     }
5539     bClear = sal_True;
5540 
5541     Window& rWin = rSh.GetView().GetEditWin();
5542     if( bIsTip )
5543     {
5544         Point aPt( rWin.OutputToScreenPixel( rWin.LogicToPixel(
5545                     rSh.GetCharRect().Pos() )));
5546         aPt.Y() -= 3;
5547         nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )),
5548                         *aArr[ nCurArrPos ],
5549                         QUICKHELP_LEFT | QUICKHELP_BOTTOM );
5550     }
5551     else
5552     {
5553         String sStr( *aArr[ nCurArrPos ] );
5554         sStr.Erase( 0, nLen );
5555         sal_uInt16 nL = sStr.Len();
5556         pAttrs = new sal_uInt16[ nL ];
5557         for( sal_uInt16 n = nL; n;  )
5558             *(pAttrs + --n ) = EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE |
5559                                 EXTTEXTINPUT_ATTR_HIGHLIGHT;
5560         pCETID = new CommandExtTextInputData( sStr, pAttrs, nL,
5561                                                 0, 0, 0, sal_False );
5562         rSh.CreateExtTextInput(rWin.GetInputLanguage());
5563         rSh.SetExtTextInputData( *pCETID );
5564     }
5565 }
5566 
5567 void QuickHelpData::Stop( SwWrtShell& rSh )
5568 {
5569     if( !bIsTip )
5570         rSh.DeleteExtTextInput( 0, sal_False );
5571     else if( nTipId )
5572         Help::HideTip( nTipId );
5573     ClearCntnt();
5574 }
5575 
5576 void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
5577 {
5578     // #i22961# get the letter-case context
5579     const CharClass& rCharClass = GetAppCharClass();
5580     const String aLWord = rCharClass.toLower( rWord, 0, rWord.Len() );
5581     const bool bIsUpper = (rWord == rCharClass.toUpper( rWord, 0, rWord.Len() ) );
5582     const bool bIsLower = (rWord == aLWord);
5583 
5584     // add all matching month/day names from the calendar
5585     salhelper::SingletonRef<SwCalendarWrapper>* pCalendar = s_getCalendarWrapper();
5586     (*pCalendar)->LoadDefaultCalendar( rSh.GetCurLang() );
5587 
5588     {
5589         uno::Sequence< i18n::CalendarItem > aNames(
5590                                             (*pCalendar)->getMonths() );
5591         for( int n = 0; n < 2; ++n )
5592         {
5593             for( long nPos = 0, nEnd = aNames.getLength(); nPos < nEnd; ++nPos )
5594             {
5595                 const String& rS = aNames[ nPos ].FullName;
5596                 if( rS.Len() <= rWord.Len() + 1 )
5597                     continue;
5598                 const String aLName = rCharClass.toLower( rS, 0, rWord.Len() );
5599                 if( aLName != aLWord )
5600                     continue;
5601                 // #i22961# provide case-sensitive autocompletion suggestions
5602                 String* pNew = new String( (bIsUpper==bIsLower) ? rS : (bIsUpper ? rCharClass.toUpper(rS,0,rS.Len()) : rCharClass.toLower(rS,0,rS.Len())) );
5603                 if( !aArr.Insert( pNew ) )
5604                     delete pNew;
5605             }
5606             if( !n )                    // get data for the second loop
5607                 aNames = (*pCalendar)->getDays();
5608         }
5609     }
5610 
5611     // and then add all words from the AutoCompleteWord-List
5612     const SwAutoCompleteWord& rACLst = rSh.GetAutoCompleteWords();
5613     sal_uInt16 nStt, nEnd;
5614     if( rACLst.GetRange( rWord, nStt, nEnd ) )
5615     {
5616         for(; nStt < nEnd; ++nStt )
5617         {
5618             const String& rS = rACLst[ nStt ];
5619             if( rS.Len() <= rWord.Len() )
5620                 continue;
5621             // #i22961# provide case-sensitive autocompletion suggestions
5622             String* pNew = new String( (bIsUpper==bIsLower) ? rS : (bIsUpper ? rCharClass.toUpper(rS,0,rS.Len()) : rCharClass.toLower(rS,0,rS.Len())) );
5623             if( !aArr.Insert( pNew ) )
5624                 delete pNew;
5625         }
5626     }
5627 }
5628 
5629 void SwEditWin::ShowAutoTextCorrectQuickHelp(
5630         const String& rWord, SvxAutoCorrCfg* pACfg, SvxAutoCorrect* pACorr,
5631         sal_Bool bFromIME )
5632 {
5633     SwWrtShell& rSh = rView.GetWrtShell();
5634     pQuickHlpData->ClearCntnt();
5635     if( pACfg->IsAutoTextTip() )
5636     {
5637         SwGlossaryList* pList = ::GetGlossaryList();
5638         pList->HasLongName( rWord, &pQuickHlpData->aArr );
5639     }
5640 
5641     if( pQuickHlpData->aArr.Count() )
5642     {
5643         pQuickHlpData->bIsTip = sal_True;
5644         pQuickHlpData->bIsAutoText = sal_True;
5645     }
5646     else if( pACorr->GetSwFlags().bAutoCompleteWords )
5647     {
5648         pQuickHlpData->bIsAutoText = sal_False;
5649         pQuickHlpData->bIsTip = bFromIME ||
5650                     !pACorr ||
5651                     pACorr->GetSwFlags().bAutoCmpltShowAsTip;
5652 
5653         pQuickHlpData->FillStrArr( rSh, rWord );
5654     }
5655 
5656     if( pQuickHlpData->aArr.Count() )
5657         pQuickHlpData->Start( rSh, rWord.Len() );
5658 }
5659 
5660 /* -----------------29.03.2006 11:01-----------------
5661  *
5662  * --------------------------------------------------*/
5663 
5664 void SwEditWin::SetUseInputLanguage( sal_Bool bNew )
5665 {
5666     if ( bNew || bUseInputLanguage )
5667     {
5668         SfxBindings& rBind = GetView().GetViewFrame()->GetBindings();
5669         rBind.Invalidate( SID_ATTR_CHAR_FONT );
5670         rBind.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
5671     }
5672     bUseInputLanguage = bNew;
5673 }
5674 
5675 /*-- 13.11.2008 10:18:17---------------------------------------------------
5676 
5677   -----------------------------------------------------------------------*/
5678 XubString SwEditWin::GetSurroundingText() const
5679 {
5680     String sReturn;
5681     SwWrtShell& rSh = rView.GetWrtShell();
5682     if( rSh.HasSelection() && !rSh.IsMultiSelection() && rSh.IsSelOnePara() )
5683         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5684     else if( !rSh.HasSelection() )
5685     {
5686         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
5687         xub_StrLen nPos = pPos->nContent.GetIndex();
5688 
5689         // get the sentence around the cursor
5690         rSh.HideCrsr();
5691         rSh.GoStartSentence();
5692         rSh.SetMark();
5693         rSh.GoEndSentence();
5694         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5695 
5696         pPos->nContent = nPos;
5697         rSh.ClearMark();
5698         rSh.HideCrsr();
5699     }
5700 
5701     return sReturn;
5702 }
5703 /*-- 13.11.2008 10:18:17---------------------------------------------------
5704 
5705   -----------------------------------------------------------------------*/
5706 Selection SwEditWin::GetSurroundingTextSelection() const
5707 {
5708     SwWrtShell& rSh = rView.GetWrtShell();
5709     if( rSh.HasSelection() )
5710     {
5711         String sReturn;
5712         rSh.GetSelectedText( sReturn, GETSELTXT_PARABRK_TO_ONLYCR  );
5713         return Selection( 0, sReturn.Len() );
5714     }
5715     else
5716     {
5717         // Return the position of the visible cursor in the sentence
5718         // around the visible cursor.
5719         SwPosition *pPos = rSh.GetCrsr()->GetPoint();
5720         xub_StrLen nPos = pPos->nContent.GetIndex();
5721 
5722         rSh.HideCrsr();
5723         rSh.GoStartSentence();
5724         xub_StrLen nStartPos = rSh.GetCrsr()->GetPoint()->nContent.GetIndex();
5725 
5726         pPos->nContent = nPos;
5727         rSh.ClearMark();
5728         rSh.ShowCrsr();
5729 
5730         return Selection( nPos - nStartPos, nPos - nStartPos );
5731     }
5732 }
5733