xref: /trunk/main/sw/source/ui/uiview/viewdraw.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include "hintids.hxx"
33 #include <svl/aeitem.hxx>
34 #include <svl/itempool.hxx>
35 #include <svx/svdobj.hxx>
36 #include <svx/svdview.hxx>
37 #include <svx/svdpage.hxx>
38 #include <editeng/editview.hxx>
39 #include <editeng/editeng.hxx>
40 #include <editeng/outliner.hxx>
41 #include <svx/fmview.hxx>
42 #include <svx/dataaccessdescriptor.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <doc.hxx>
45 #include <editeng/langitem.hxx>
46 #include <linguistic/lngprops.hxx>
47 #include <editeng/unolingu.hxx>
48 #include <svx/fontworkbar.hxx>
49 #include <svx/fontworkgallery.hxx>
50 #include <editeng/eeitem.hxx>
51 #include <svx/svdogrp.hxx>
52 #include <svx/svdetc.hxx>
53 #include <editeng/editstat.hxx>
54 #include <sfx2/request.hxx>
55 #include <sfx2/bindings.hxx>
56 #include <sfx2/printer.hxx>
57 #include <svx/fmglob.hxx>
58 #include <sfx2/dispatch.hxx>
59 #include <svx/svdoutl.hxx>
60 
61 #include "view.hxx"
62 #include "wrtsh.hxx"
63 #include "viewopt.hxx"
64 #include "cmdid.h"
65 #include "drawsh.hxx"
66 #include "drwbassh.hxx"
67 #include "beziersh.hxx"
68 #include "conrect.hxx"
69 #include "conpoly.hxx"
70 #include "conarc.hxx"
71 #include "conform.hxx"
72 #include "concustomshape.hxx"
73 #include "dselect.hxx"
74 #include "edtwin.hxx"
75 
76 // #108784#
77 #include <dcontact.hxx>
78 
79 // #108784#
80 #include <svx/svdpagv.hxx>
81 #include <svx/extrusionbar.hxx>
82 #include <vcl/svapp.hxx>
83 
84 using namespace ::com::sun::star;
85 /*--------------------------------------------------------------------
86     Beschreibung:   Drawing-Ids ausfuehren
87  --------------------------------------------------------------------*/
88 
89 void SwView::ExecDraw(SfxRequest& rReq)
90 {
91     const SfxItemSet *pArgs = rReq.GetArgs();
92     const SfxPoolItem* pItem;
93     const SfxAllEnumItem* pEItem = 0;
94     const SfxStringItem* pStringItem = 0;
95     SdrView *pSdrView = pWrtShell->GetDrawView();
96     sal_Bool bDeselect = sal_False;
97 
98     sal_uInt16 nSlotId = rReq.GetSlot();
99     if(pArgs && SFX_ITEM_SET == pArgs->GetItemState(GetPool().GetWhich(nSlotId), sal_False, &pItem))
100     {
101         pEItem = dynamic_cast< const SfxAllEnumItem*>(pItem);
102         pStringItem = dynamic_cast< const SfxStringItem*>(pItem);
103     }
104 
105     if (SID_INSERT_DRAW == nSlotId && pEItem)
106         switch ( pEItem->GetValue() )
107         {
108             case SVX_SNAP_DRAW_SELECT:              nSlotId = SID_OBJECT_SELECT;            break;
109             case SVX_SNAP_DRAW_LINE:                nSlotId = SID_DRAW_LINE;                break;
110             case SVX_SNAP_DRAW_RECT:                nSlotId = SID_DRAW_RECT;                break;
111             case SVX_SNAP_DRAW_ELLIPSE:             nSlotId = SID_DRAW_ELLIPSE;             break;
112             case SVX_SNAP_DRAW_POLYGON_NOFILL:      nSlotId = SID_DRAW_POLYGON_NOFILL;      break;
113             case SVX_SNAP_DRAW_BEZIER_NOFILL:       nSlotId = SID_DRAW_BEZIER_NOFILL;       break;
114             case SVX_SNAP_DRAW_FREELINE_NOFILL:     nSlotId = SID_DRAW_FREELINE_NOFILL;     break;
115             case SVX_SNAP_DRAW_ARC:                 nSlotId = SID_DRAW_ARC;                 break;
116             case SVX_SNAP_DRAW_PIE:                 nSlotId = SID_DRAW_PIE;                 break;
117             case SVX_SNAP_DRAW_CIRCLECUT:           nSlotId = SID_DRAW_CIRCLECUT;           break;
118             case SVX_SNAP_DRAW_TEXT:                nSlotId = SID_DRAW_TEXT;                break;
119             case SVX_SNAP_DRAW_TEXT_VERTICAL:       nSlotId = SID_DRAW_TEXT_VERTICAL;       break;
120             case SVX_SNAP_DRAW_TEXT_MARQUEE:        nSlotId = SID_DRAW_TEXT_MARQUEE;        break;
121             case SVX_SNAP_DRAW_CAPTION:             nSlotId = SID_DRAW_CAPTION;             break;
122             case SVX_SNAP_DRAW_CAPTION_VERTICAL:    nSlotId = SID_DRAW_CAPTION_VERTICAL;    break;
123         }
124 
125     if (nSlotId == SID_OBJECT_SELECT && nFormSfxId == nSlotId)
126     {
127         bDeselect = sal_True;
128     }
129     else if (nSlotId == SID_FM_CREATE_CONTROL)
130     {
131         SFX_REQUEST_ARG( rReq, pIdentifierItem, SfxUInt16Item, SID_FM_CONTROL_IDENTIFIER, sal_False );
132         if( pIdentifierItem )
133         {
134             sal_uInt16 nNewId = pIdentifierItem->GetValue();
135             if (nNewId == nFormSfxId)
136             {
137                 bDeselect = sal_True;
138                 GetViewFrame()->GetDispatcher()->Execute(SID_FM_LEAVE_CREATE);  // Button soll rauspoppen
139             }
140         }
141     }
142     else if( nSlotId == SID_FM_CREATE_FIELDCONTROL)
143     {
144         FmFormView* pFormView = PTR_CAST( FmFormView, pSdrView );
145         if ( pFormView )
146         {
147             SFX_REQUEST_ARG( rReq, pDescriptorItem, SfxUnoAnyItem, SID_FM_DATACCESS_DESCRIPTOR, sal_False );
148             DBG_ASSERT( pDescriptorItem, "SwView::ExecDraw(SID_FM_CREATE_FIELDCONTROL): invalid request args!" );
149             if( pDescriptorItem )
150             {
151                 ::svx::ODataAccessDescriptor aDescriptor( pDescriptorItem->GetValue() );
152                 SdrObject* pObj = pFormView->CreateFieldControl( aDescriptor );
153 
154                 if ( pObj )
155                 {
156                     Size aDocSize(pWrtShell->GetDocSize());
157                     const SwRect& rVisArea = pWrtShell->VisArea();
158                     Point aStartPos = rVisArea.Center();
159                     if(rVisArea.Width() > aDocSize.Width())
160                         aStartPos.X() = aDocSize.Width() / 2 + rVisArea.Left();
161                     if(rVisArea.Height() > aDocSize.Height())
162                         aStartPos.Y() = aDocSize.Height() / 2 + rVisArea.Top();
163 
164                     //determine the size of the object
165                     if(pObj->IsGroupObject())
166                     {
167                         const Rectangle& rBoundRect = ((SdrObjGroup*)pObj)->GetCurrentBoundRect();
168                         aStartPos.X() -= rBoundRect.GetWidth()/2;
169                         aStartPos.Y() -= rBoundRect.GetHeight()/2;
170                     }
171 
172                     // TODO: unmark all other
173                     pWrtShell->EnterStdMode();
174                     pWrtShell->SwFEShell::InsertDrawObj( *pObj, aStartPos );
175                 }
176             }
177         }
178     }
179     else if ( nSlotId == SID_FONTWORK_GALLERY_FLOATER )
180     {
181         Window*  pWin = &( pWrtShell->GetView().GetViewFrame()->GetWindow() );
182 
183         if ( pWin )
184             pWin->EnterWait();
185 
186         if( !pWrtShell->HasDrawView() )
187             pWrtShell->MakeDrawView();
188 
189         pSdrView = pWrtShell->GetDrawView();
190         if ( pSdrView )
191         {
192             SdrObject* pObj = NULL;
193             svx::FontWorkGalleryDialog aDlg( pSdrView, pWin, nSlotId );
194             aDlg.SetSdrObjectRef( &pObj, pSdrView->GetModel() );
195             aDlg.Execute();
196             if ( pObj )
197             {
198                 Size            aDocSize( pWrtShell->GetDocSize() );
199                 const SwRect&   rVisArea = pWrtShell->VisArea();
200                 Point           aPos( rVisArea.Center() );
201                 Size            aSize;
202                 Size            aPrefSize( pObj->GetSnapRect().GetSize() );
203 
204                 if( rVisArea.Width() > aDocSize.Width())
205                     aPos.X() = aDocSize.Width() / 2 + rVisArea.Left();
206 
207                 if(rVisArea.Height() > aDocSize.Height())
208                     aPos.Y() = aDocSize.Height() / 2 + rVisArea.Top();
209 
210                 if( aPrefSize.Width() && aPrefSize.Height() )
211                 {
212                     if( pWin )
213                         aSize = pWin->PixelToLogic( aPrefSize, MAP_TWIP );
214                     else
215                         aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_TWIP );
216                 }
217                 else
218                     aSize = Size( 2835, 2835 );
219 
220                 pWrtShell->EnterStdMode();
221                 pWrtShell->SwFEShell::InsertDrawObj( *pObj, aPos );
222                 rReq.Ignore ();
223             }
224         }
225         if( pWin )
226             pWin->LeaveWait();
227     }
228 
229     if( nSlotId == SID_DRAW_CS_ID )
230     {
231         //deselect if same custom shape is selected again
232         SwDrawBase* pFuncPtr = GetDrawFuncPtr();
233         if( pFuncPtr && pFuncPtr->GetSlotId() == SID_DRAW_CS_ID )
234         {
235             ConstCustomShape* pConstCustomShape = (ConstCustomShape*)(pFuncPtr);
236             rtl::OUString aNew = ConstCustomShape::GetShapeTypeFromRequest( rReq );
237             rtl::OUString aOld = pConstCustomShape->GetShapeType();
238             if( aNew == aOld )
239             {
240                 bDeselect = true;
241             }
242         }
243     }
244 
245     //deselect if same shape is selected again (but different custom shapes do have same slot id)
246     if ( bDeselect || (nSlotId == nDrawSfxId &&
247             (!pStringItem || (pStringItem->GetValue() == sDrawCustom))
248                 && (nSlotId != SID_DRAW_CS_ID) ) )
249     {
250         if (GetDrawFuncPtr())
251         {
252             GetDrawFuncPtr()->Deactivate();
253             SetDrawFuncPtr(NULL);
254         }
255 
256         if (pWrtShell->IsObjSelected() && !pWrtShell->IsSelFrmMode())
257             pWrtShell->EnterSelFrmMode(NULL);
258         LeaveDrawCreate();
259 
260         GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW);
261 
262         AttrChangedNotify(pWrtShell);
263         return;
264     }
265 
266     LeaveDrawCreate();
267 
268     if (pWrtShell->IsFrmSelected())
269         pWrtShell->EnterStdMode();  // wegen Bug #45639
270 
271     SwDrawBase* pFuncPtr = NULL;
272 
273     switch (nSlotId)
274     {
275         case SID_OBJECT_SELECT:
276         case SID_DRAW_SELECT:
277             pFuncPtr = new DrawSelection(pWrtShell, pEditWin, this);
278             nDrawSfxId = nFormSfxId = SID_OBJECT_SELECT;
279             sDrawCustom.Erase();
280             break;
281 
282         case SID_DRAW_LINE:
283         case SID_DRAW_RECT:
284         case SID_DRAW_ELLIPSE:
285         case SID_DRAW_TEXT:
286         case SID_DRAW_TEXT_VERTICAL:
287         case SID_DRAW_TEXT_MARQUEE:
288         case SID_DRAW_CAPTION:
289         case SID_DRAW_CAPTION_VERTICAL:
290             pFuncPtr = new ConstRectangle(pWrtShell, pEditWin, this);
291             nDrawSfxId = nSlotId;
292             sDrawCustom.Erase();
293             break;
294 
295         case SID_DRAW_POLYGON_NOFILL:
296         case SID_DRAW_BEZIER_NOFILL:
297         case SID_DRAW_FREELINE_NOFILL:
298             pFuncPtr = new ConstPolygon(pWrtShell, pEditWin, this);
299             nDrawSfxId = nSlotId;
300             sDrawCustom.Erase();
301             break;
302 
303         case SID_DRAW_ARC:
304         case SID_DRAW_PIE:
305         case SID_DRAW_CIRCLECUT:
306             pFuncPtr = new ConstArc(pWrtShell, pEditWin, this);
307             nDrawSfxId = nSlotId;
308             sDrawCustom.Erase();
309             break;
310 
311         case SID_FM_CREATE_CONTROL:
312         {
313             SFX_REQUEST_ARG( rReq, pIdentifierItem, SfxUInt16Item, SID_FM_CONTROL_IDENTIFIER, sal_False );
314             if( pIdentifierItem )
315                 nSlotId = pIdentifierItem->GetValue();
316             pFuncPtr = new ConstFormControl(pWrtShell, pEditWin, this);
317             nFormSfxId = nSlotId;
318         }
319         break;
320 
321         case SID_DRAWTBX_CS_BASIC :
322         case SID_DRAWTBX_CS_SYMBOL :
323         case SID_DRAWTBX_CS_ARROW :
324         case SID_DRAWTBX_CS_FLOWCHART :
325         case SID_DRAWTBX_CS_CALLOUT :
326         case SID_DRAWTBX_CS_STAR :
327         case SID_DRAW_CS_ID :
328         {
329             pFuncPtr = new ConstCustomShape(pWrtShell, pEditWin, this, rReq );
330             nDrawSfxId = nSlotId;
331             if ( nSlotId != SID_DRAW_CS_ID )
332             {
333                 if ( pStringItem )
334                 {
335                     sDrawCustom = pStringItem->GetValue();
336                     aCurrShapeEnumCommand[ nSlotId - SID_DRAWTBX_CS_BASIC ] = sDrawCustom;
337                     SfxBindings& rBind = GetViewFrame()->GetBindings();
338                     rBind.Invalidate( nSlotId );
339                     rBind.Update( nSlotId );
340                 }
341             }
342         }
343         break;
344 
345         default:
346             break;
347     }
348 
349     static sal_uInt16 __READONLY_DATA aInval[] =
350     {
351         // Slot-Ids muessen beim Aufruf von Invalidate sortiert sein!
352         SID_ATTRIBUTES_AREA,
353         SID_INSERT_DRAW,
354         0
355     };
356     GetViewFrame()->GetBindings().Invalidate(aInval);
357 
358     sal_Bool bEndTextEdit = sal_True;
359     if (pFuncPtr)
360     {
361         if (GetDrawFuncPtr())
362         {
363             GetDrawFuncPtr()->Deactivate();
364             SetDrawFuncPtr(NULL);
365         }
366 
367         SetDrawFuncPtr(pFuncPtr);
368         AttrChangedNotify(pWrtShell);
369 
370         pFuncPtr->Activate(nSlotId);
371         NoRotate();
372         if(rReq.GetModifier() == KEY_MOD1)
373         {
374             if(SID_OBJECT_SELECT == nDrawSfxId )
375             {
376                 pWrtShell->GotoObj(sal_True);
377             }
378             else
379             {
380                 pFuncPtr->CreateDefaultObject();
381                 pFuncPtr->Deactivate();
382                 SetDrawFuncPtr(NULL);
383                 LeaveDrawCreate();
384                 pWrtShell->EnterStdMode();
385                 SdrView *pTmpSdrView = pWrtShell->GetDrawView();
386                 const SdrMarkList& rMarkList = pTmpSdrView->GetMarkedObjectList();
387                 if(rMarkList.GetMarkCount() == 1 &&
388                         (SID_DRAW_TEXT == nSlotId || SID_DRAW_TEXT_VERTICAL == nSlotId ||
389                             SID_DRAW_TEXT_MARQUEE == nSlotId ))
390                 {
391                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
392                     BeginTextEdit(pObj);
393                     bEndTextEdit = sal_False;
394                 }
395             }
396         }
397     }
398     else
399     {
400         if (pWrtShell->IsObjSelected() && !pWrtShell->IsSelFrmMode())
401             pWrtShell->EnterSelFrmMode(NULL);
402     }
403 
404     if(bEndTextEdit && pSdrView && pSdrView->IsTextEdit())
405         pSdrView->SdrEndTextEdit( sal_True );
406 
407     AttrChangedNotify(pWrtShell);
408 }
409 
410 /*--------------------------------------------------------------------
411     Beschreibung:   Drawing beenden
412  --------------------------------------------------------------------*/
413 
414 
415 
416 void SwView::ExitDraw()
417 {
418     NoRotate();
419 
420     if(pShell)
421     {
422         //#126062 # the shell may be invalid at close/reload/SwitchToViewShell
423         SfxDispatcher* pDispatch = GetViewFrame()->GetDispatcher();
424         sal_uInt16 nIdx = 0;
425         SfxShell* pTest = 0;
426         do
427         {
428             pTest = pDispatch->GetShell(nIdx++);
429         }
430         while( pTest && pTest != this && pTest != pShell);
431         if(pTest == pShell &&
432             // don't call LeaveSelFrmMode() etc. for the below,
433             // because objects may still be selected:
434             !pShell->ISA(SwDrawBaseShell) &&
435             !pShell->ISA(SwBezierShell) &&
436             !pShell->ISA(svx::ExtrusionBar) &&
437             !pShell->ISA(svx::FontworkBar))
438         {
439             SdrView *pSdrView = pWrtShell->GetDrawView();
440 
441             if (pSdrView && pSdrView->IsGroupEntered())
442             {
443                 pSdrView->LeaveOneGroup();
444                 pSdrView->UnmarkAll();
445                 GetViewFrame()->GetBindings().Invalidate(SID_ENTER_GROUP);
446             }
447 
448             if (GetDrawFuncPtr())
449             {
450                 if (pWrtShell->IsSelFrmMode())
451                     pWrtShell->LeaveSelFrmMode();
452                 GetDrawFuncPtr()->Deactivate();
453 
454                 SetDrawFuncPtr(NULL);
455                 LeaveDrawCreate();
456 
457                 GetViewFrame()->GetBindings().Invalidate(SID_INSERT_DRAW);
458             }
459             GetEditWin().SetPointer(Pointer(POINTER_TEXT));
460         }
461     }
462 }
463 
464 /*--------------------------------------------------------------------
465     Beschreibung:   Rotate-Mode abschalten
466  --------------------------------------------------------------------*/
467 
468 
469 
470 void SwView::NoRotate()
471 {
472     if (IsDrawRotate())
473     {
474         pWrtShell->SetDragMode(SDRDRAG_MOVE);
475         FlipDrawRotate();
476 
477         const SfxBoolItem aTmp( SID_OBJECT_ROTATE, sal_False );
478         GetViewFrame()->GetBindings().SetState( aTmp );
479     }
480 }
481 
482 /******************************************************************************
483  *  Beschreibung: DrawTextEditMode einschalten
484  ******************************************************************************/
485 
486 sal_Bool SwView::EnterDrawTextMode(const Point& aDocPos)
487 {
488     SdrObject* pObj;
489     SdrPageView* pPV;
490     SwWrtShell *pSh = &GetWrtShell();
491     SdrView *pSdrView = pSh->GetDrawView();
492     ASSERT( pSdrView, "EnterDrawTextMode without DrawView?" );
493 
494     sal_Bool bReturn = sal_False;
495 
496     sal_uInt16 nOld = pSdrView->GetHitTolerancePixel();
497     pSdrView->SetHitTolerancePixel( 2 );
498 
499     if( pSdrView->IsMarkedHit( aDocPos ) &&
500         !pSdrView->PickHandle( aDocPos ) && IsTextTool() &&
501         pSdrView->PickObj( aDocPos, pSdrView->getHitTolLog(), pObj, pPV, SDRSEARCH_PICKTEXTEDIT ) &&
502 
503         // #108784#
504         // To allow SwDrawVirtObj text objects to be activated, allow their type, too.
505         //pObj->ISA( SdrTextObj ) &&
506         ( pObj->ISA( SdrTextObj ) ||
507           ( pObj->ISA(SwDrawVirtObj) &&
508             ((SwDrawVirtObj*)pObj)->GetReferencedObj().ISA(SdrTextObj) ) ) &&
509 
510         !pWrtShell->IsSelObjProtected(FLYPROTECT_CONTENT))
511     {
512         bReturn = BeginTextEdit( pObj, pPV, pEditWin, sal_False );
513     }
514 
515     pSdrView->SetHitTolerancePixel( nOld );
516 
517     return bReturn;
518 }
519 
520 /******************************************************************************
521  *  Beschreibung: DrawTextEditMode einschalten
522  ******************************************************************************/
523 sal_Bool SwView::BeginTextEdit(SdrObject* pObj, SdrPageView* pPV, Window* pWin,
524         bool bIsNewObj, bool bSetSelectionToStart)
525 {
526     SwWrtShell *pSh = &GetWrtShell();
527     SdrView *pSdrView = pSh->GetDrawView();
528     SdrOutliner* pOutliner = ::SdrMakeOutliner(OUTLINERMODE_TEXTOBJECT, pSdrView->GetModel());
529     uno::Reference< linguistic2::XSpellChecker1 >  xSpell( ::GetSpellChecker() );
530     if (pOutliner)
531     {
532         pOutliner->SetRefDevice(pSh->getIDocumentDeviceAccess()->getReferenceDevice(false));
533         pOutliner->SetSpeller(xSpell);
534         uno::Reference<linguistic2::XHyphenator> xHyphenator( ::GetHyphenator() );
535         pOutliner->SetHyphenator( xHyphenator );
536         pSh->SetCalcFieldValueHdl(pOutliner);
537 
538         sal_uInt32 nCntrl = pOutliner->GetControlWord();
539         nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
540         nCntrl |= EE_CNTRL_URLSFXEXECUTE;
541 
542         const SwViewOption *pOpt = pSh->GetViewOptions();
543 
544         if (SwViewOption::IsFieldShadings())
545             nCntrl |= EE_CNTRL_MARKFIELDS;
546         else
547             nCntrl &= ~EE_CNTRL_MARKFIELDS;
548 
549         if (pOpt->IsOnlineSpell())
550             nCntrl |= EE_CNTRL_ONLINESPELLING;
551         else
552             nCntrl &= ~EE_CNTRL_ONLINESPELLING;
553 
554         pOutliner->SetControlWord(nCntrl);
555         const SfxPoolItem& rItem = pSh->GetDoc()->GetDefault(RES_CHRATR_LANGUAGE);
556         pOutliner->SetDefaultLanguage(((const SvxLanguageItem&)rItem).GetLanguage());
557 
558         if( bIsNewObj )
559             pOutliner->SetVertical( SID_DRAW_TEXT_VERTICAL == nDrawSfxId ||
560                                     SID_DRAW_CAPTION_VERTICAL == nDrawSfxId );
561         // #i7672#
562         // No longer necessary, see text below
563         // Color aBackground(pSh->GetShapeBackgrd());
564         // pOutliner->SetBackgroundColor(aBackground);
565 
566         // OD 09.12.2002 #103045# - set default horizontal text direction at outliner
567         EEHorizontalTextDirection aDefHoriTextDir =
568             pSh->IsShapeDefaultHoriTextDirR2L() ? EE_HTEXTDIR_R2L : EE_HTEXTDIR_L2R;
569         pOutliner->SetDefaultHorizontalTextDirection( aDefHoriTextDir );
570     }
571 
572     // #108784#
573     // To allow editing the referenced object from a SwDrawVirtObj here
574     // the original needs to be fetched evenually. This ATM activates the
575     // text edit mode for the original object.
576     SdrObject* pToBeActivated = pObj;
577 
578     // #108784#
579     // Always the original object is edited. To allow the TextEdit to happen
580     // where the VirtObj is positioned, on demand a occurring offset is set at
581     // the TextEdit object. That offset is used for creating and managing the
582     // OutlinerView.
583     Point aNewTextEditOffset(0, 0);
584 
585     if(pObj->ISA(SwDrawVirtObj))
586     {
587         SwDrawVirtObj* pVirtObj = (SwDrawVirtObj*)pObj;
588         pToBeActivated = &((SdrObject&)pVirtObj->GetReferencedObj());
589         aNewTextEditOffset = pVirtObj->GetOffset();
590     }
591 
592     // set in each case, thus it will be correct for all objects
593     ((SdrTextObj*)pToBeActivated)->SetTextEditOffset(aNewTextEditOffset);
594 
595     sal_Bool bRet(pSdrView->SdrBeginTextEdit( pToBeActivated, pPV, pWin, sal_True, pOutliner, 0, sal_False, sal_False, sal_False ));
596 
597     // #i7672#
598     // Since SdrBeginTextEdit actually creates the OutlinerView and thus also
599     // sets the background color, an own background color needs to be set
600     // after TextEditing was started. This is now done here.
601     if(bRet)
602     {
603         OutlinerView* pView = pSdrView->GetTextEditOutlinerView();
604 
605         if(pView)
606         {
607             Color aBackground(pSh->GetShapeBackgrd());
608             pView->SetBackgroundColor(aBackground);
609         }
610 
611         // editing should start at the end of text, spell checking at the beginning ...
612         ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
613         if (bSetSelectionToStart)
614             aNewSelection = ESelection();
615         pView->SetSelection(aNewSelection);
616     }
617 
618     return bRet;
619 }
620 
621 /******************************************************************************
622  *  Beschreibung: Ist ein DrawTextObjekt selektiert?
623  ******************************************************************************/
624 
625 
626 
627 sal_Bool SwView::IsTextTool() const
628 {
629     sal_uInt16 nId;
630     sal_uInt32 nInvent;
631     SdrView *pSdrView = GetWrtShell().GetDrawView();
632     ASSERT( pSdrView, "IsTextTool without DrawView?" );
633 
634     if (pSdrView->IsCreateMode())
635         pSdrView->SetCreateMode(sal_False);
636 
637     pSdrView->TakeCurrentObj(nId,nInvent);
638     return (nInvent==SdrInventor);
639 }
640 
641 /*--------------------------------------------------------------------
642     Beschreibung:
643  --------------------------------------------------------------------*/
644 
645 
646 
647 SdrView* SwView::GetDrawView() const
648 {
649     return GetWrtShell().GetDrawView();
650 }
651 
652 /*--------------------------------------------------------------------
653     Beschreibung:
654  --------------------------------------------------------------------*/
655 
656 
657 
658 sal_Bool SwView::IsBezierEditMode()
659 {
660     return (!IsDrawSelMode() && GetWrtShell().GetDrawView()->HasMarkablePoints());
661 }
662 
663 /*--------------------------------------------------------------------
664     Beschreibung:
665  --------------------------------------------------------------------*/
666 
667 sal_Bool SwView::IsFormMode() const
668 {
669     if (GetDrawFuncPtr() && GetDrawFuncPtr()->IsCreateObj())
670     {
671         return (GetDrawFuncPtr()->IsInsertForm());
672     }
673 
674     return AreOnlyFormsSelected();
675 }
676 
677 /*--------------------------------------------------------------------
678     Beschreibung:
679  --------------------------------------------------------------------*/
680 
681 
682 
683 void SwView::SetDrawFuncPtr(SwDrawBase* pFuncPtr)
684 {
685     if (pDrawActual)
686         delete pDrawActual;
687     pDrawActual = pFuncPtr;
688 }
689 
690 /*--------------------------------------------------------------------
691     Beschreibung:
692  --------------------------------------------------------------------*/
693 
694 void SwView::SetSelDrawSlot()
695 {
696     nDrawSfxId = SID_OBJECT_SELECT;
697     sDrawCustom.Erase();
698 }
699 
700 /*--------------------------------------------------------------------
701     Beschreibung:
702  --------------------------------------------------------------------*/
703 
704 sal_Bool SwView::AreOnlyFormsSelected() const
705 {
706     if ( GetWrtShell().IsFrmSelected() )
707         return sal_False;
708 
709     sal_Bool bForm = sal_True;
710 
711     SdrView* pSdrView = GetWrtShell().GetDrawView();
712 
713     const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
714     sal_uInt32 nCount = rMarkList.GetMarkCount();
715 
716     if (nCount)
717     {
718         for (sal_uInt32 i = 0; i < nCount; i++)
719         {
720             // Sind ausser Controls noch normale Draw-Objekte selektiert?
721             SdrObject *pSdrObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
722 
723             if (!HasOnlyObj(pSdrObj, FmFormInventor))
724             {
725                 bForm = sal_False;
726                 break;
727             }
728         }
729     }
730     else
731         bForm = sal_False;
732 
733     return bForm;
734 }
735 
736 /*--------------------------------------------------------------------
737     Beschreibung:
738  --------------------------------------------------------------------*/
739 
740 sal_Bool SwView::HasDrwObj(SdrObject *pSdrObj) const
741 {
742     sal_Bool bRet = sal_False;
743 
744     if (pSdrObj->IsGroupObject())
745     {
746         SdrObjList* pList = pSdrObj->GetSubList();
747         sal_uInt32 nCnt = pList->GetObjCount();
748 
749         for (sal_uInt32 i = 0; i < nCnt; i++)
750             if ((bRet = HasDrwObj(pList->GetObj(i))) == sal_True)
751                 break;
752     }
753     else if (SdrInventor == pSdrObj->GetObjInventor() || pSdrObj->Is3DObj())
754         return sal_True;
755 
756     return bRet;
757 }
758 
759 /*--------------------------------------------------------------------
760     Beschreibung:
761  --------------------------------------------------------------------*/
762 
763 sal_Bool SwView::HasOnlyObj(SdrObject *pSdrObj, sal_uInt32 eObjInventor) const
764 {
765     sal_Bool bRet = sal_False;
766 
767     if (pSdrObj->IsGroupObject())
768     {
769         SdrObjList* pList = pSdrObj->GetSubList();
770         sal_uInt32 nCnt = pList->GetObjCount();
771 
772         for (sal_uInt32 i = 0; i < nCnt; i++)
773             if ((bRet = HasOnlyObj(pList->GetObj(i), eObjInventor)) == sal_False)
774                 break;
775     }
776     else if (eObjInventor == pSdrObj->GetObjInventor())
777         return sal_True;
778 
779     return bRet;
780 }
781 
782 
783 //#i87414# mod
784 IMPL_LINK(SwView, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
785 {
786     if (pInfo->nCommand == SPELLCMD_STARTSPELLDLG)
787         GetViewFrame()->GetDispatcher()->Execute( FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON);
788     return 0;
789 }
790 
791 /*--------------------------------------------------------------------
792     Beschreibung:
793  --------------------------------------------------------------------*/
794 sal_Bool SwView::ExecDrwTxtSpellPopup(const Point& rPt)
795 {
796     sal_Bool bRet = sal_False;
797     SdrView *pSdrView = pWrtShell->GetDrawView();
798     OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
799     Point aPos( GetEditWin().LogicToPixel( rPt ) );
800 
801     if (pOLV->IsWrongSpelledWordAtPos( aPos ))
802     {
803         bRet = sal_True;
804         Link aLink = LINK(this, SwView, OnlineSpellCallback);
805         pOLV->ExecuteSpellPopup( aPos,&aLink );
806     }
807     return bRet;
808 }
809 
810 /*--------------------------------------------------------------------
811     Beschreibung:
812  --------------------------------------------------------------------*/
813 
814 
815 
816 sal_Bool SwView::IsDrawTextHyphenate()
817 {
818     SdrView *pSdrView = pWrtShell->GetDrawView();
819     sal_Bool bHyphenate = sal_False;
820 
821     SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool(),
822                             EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
823     if( pSdrView->GetAttributes( aNewAttr ) &&
824         aNewAttr.GetItemState( EE_PARA_HYPHENATE ) >= SFX_ITEM_AVAILABLE )
825         bHyphenate = ((const SfxBoolItem&)aNewAttr.Get( EE_PARA_HYPHENATE )).
826                         GetValue();
827 
828     return bHyphenate;
829 }
830 
831 /*--------------------------------------------------------------------
832     Beschreibung:
833  --------------------------------------------------------------------*/
834 
835 
836 
837 void SwView::HyphenateDrawText()
838 {
839     SdrView *pSdrView = pWrtShell->GetDrawView();
840     sal_Bool bHyphenate = IsDrawTextHyphenate();
841 
842     SfxItemSet aSet( GetPool(), EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
843     aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, !bHyphenate ) );
844     pSdrView->SetAttributes( aSet );
845     GetViewFrame()->GetBindings().Invalidate(FN_HYPHENATE_OPT_DLG);
846 }
847 
848 
849 
850