xref: /trunk/main/sd/source/ui/view/drviews4.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_sd.hxx"
30 
31 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
32 
33 #include "DrawViewShell.hxx"
34 #include <vcl/msgbox.hxx>
35 #include <svl/urlbmk.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/svdundo.hxx>
38 #include <svx/fmglob.hxx>
39 #include <editeng/eeitem.hxx>
40 #ifndef _FLDITEM_HXX
41 #include <editeng/flditem.hxx>
42 #endif
43 #ifndef _SVXIDS_HRC
44 #include <svx/svxids.hrc>
45 #endif
46 #include <svx/ruler.hxx>
47 #ifndef _GLOBL3D_HXX
48 #include <svx/globl3d.hxx>
49 #endif
50 #include <editeng/outliner.hxx>
51 #ifndef _SFX_CLIENTSH_HXX
52 #include <sfx2/ipclient.hxx>
53 #endif
54 #include <sfx2/request.hxx>
55 #include <sfx2/dispatch.hxx>
56 #include <svx/svdopath.hxx>
57 #include <sfx2/viewfrm.hxx>
58 #include <editeng/editview.hxx>
59 #include <vcl/cursor.hxx>
60 
61 
62 #include "app.hrc"
63 #include "glob.hrc"
64 #include "strings.hrc"
65 #include "res_bmp.hrc"
66 #include "DrawDocShell.hxx"
67 #include "drawdoc.hxx"
68 #include "Window.hxx"
69 #include "fupoor.hxx"
70 #include "fusnapln.hxx"
71 #include "app.hxx"
72 #include "Ruler.hxx"
73 #include "sdresid.hxx"
74 #include "GraphicViewShell.hxx"
75 #include "sdpage.hxx"
76 #include "slideshow.hxx"
77 #include "anminfo.hxx"
78 #include "sdpopup.hxx"
79 #include "drawview.hxx"
80 #include <svx/bmpmask.hxx>
81 #include "LayerTabBar.hxx"
82 
83 // #97016# IV
84 #include <svx/svditer.hxx>
85 
86 namespace sd {
87 
88 #define PIPETTE_RANGE 0
89 
90 #ifdef _MSC_VER
91 #pragma optimize ( "", off )
92 #endif
93 
94 using namespace ::com::sun::star::uno;
95 using namespace ::com::sun::star::drawing;
96 
97 /*************************************************************************
98 |*
99 |* aktuelle Seite loeschen
100 |*
101 \************************************************************************/
102 
103 void DrawViewShell::DeleteActualPage()
104 {
105     sal_uInt16          nPage = maTabControl.GetCurPageId() - 1;
106 
107     mpDrawView->SdrEndTextEdit();
108 
109     try
110     {
111         Reference<XDrawPagesSupplier> xDrawPagesSupplier( GetDoc()->getUnoModel(), UNO_QUERY_THROW );
112         Reference<XDrawPages> xPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
113         Reference< XDrawPage > xPage( xPages->getByIndex( nPage ), UNO_QUERY_THROW );
114         xPages->remove( xPage );
115     }
116     catch( Exception& )
117     {
118         DBG_ERROR("SelectionManager::DeleteSelectedMasterPages(), exception caught!");
119     }
120 }
121 
122 /*************************************************************************
123 |*
124 |* aktuelle Ebene loeschen
125 |*
126 \************************************************************************/
127 
128 void DrawViewShell::DeleteActualLayer()
129 {
130     SdrLayerAdmin& rAdmin = GetDoc()->GetLayerAdmin();
131     const String&  rName  = GetLayerTabControl()->GetPageText(GetLayerTabControl()->GetCurPageId());
132     String         aString(SdResId(STR_ASK_DELETE_LAYER));
133 
134     // Platzhalter ersetzen
135     sal_uInt16 nPos = aString.Search(sal_Unicode('$'));
136     aString.Erase(nPos, 1);
137     aString.Insert(rName, nPos);
138 
139     if (QueryBox(GetActiveWindow(), WB_YES_NO, aString).Execute() == RET_YES)
140     {
141         const SdrLayer* pLayer = rAdmin.GetLayer(rName, sal_False);
142         mpDrawView->DeleteLayer( pLayer->GetName() );
143 
144         // damit TabBar und Window neu gezeichnet werden;
145         // sollte spaeter wie beim Aendern der Layerfolge durch einen
146         // Hint von Joe angestossen werden
147         // ( View::Notify() --> ViewShell::ResetActualLayer() )
148 
149         mbIsLayerModeActive = false;    // damit ChangeEditMode() ueberhaupt was tut
150         ChangeEditMode(GetEditMode(), true);
151     }
152 }
153 
154 
155 /*************************************************************************
156 |*
157 |* Keyboard event
158 |*
159 \************************************************************************/
160 
161 sal_Bool DrawViewShell::KeyInput (const KeyEvent& rKEvt, ::sd::Window* pWin)
162 {
163     sal_Bool bRet = sal_False;
164 
165     if ( !IsInputLocked() || ( rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE ) )
166     {
167         // #97016# IV
168         if(KEY_RETURN == rKEvt.GetKeyCode().GetCode()
169             && rKEvt.GetKeyCode().IsMod1()
170             && GetView()->IsTextEdit())
171         {
172             // this should be used for cursor travelling.
173             SdPage* pActualPage = GetActualPage();
174             const SdrMarkList& rMarkList = GetView()->GetMarkedObjectList();
175             SdrTextObj* pCandidate = 0L;
176 
177             if(pActualPage && 1 == rMarkList.GetMarkCount())
178             {
179                 SdrMark* pMark = rMarkList.GetMark(0);
180 
181                 // remember which object was the text in edit mode
182                 SdrObject* pOldObj = pMark->GetMarkedSdrObj();
183 
184                 // end text edit now
185                 GetView()->SdrEndTextEdit();
186 
187                 // look for a new candidate, a successor of pOldObj
188                 SdrObjListIter aIter(*pActualPage, IM_DEEPNOGROUPS);
189                 sal_Bool bDidVisitOldObject(sal_False);
190 
191                 while(aIter.IsMore() && !pCandidate)
192                 {
193                     SdrObject* pObj = aIter.Next();
194 
195                     if(pObj && pObj->ISA(SdrTextObj))
196                     {
197                         sal_uInt32 nInv(pObj->GetObjInventor());
198                         sal_uInt16 nKnd(pObj->GetObjIdentifier());
199 
200                         if(SdrInventor == nInv &&
201                             (OBJ_TITLETEXT == nKnd || OBJ_OUTLINETEXT == nKnd || OBJ_TEXT == nKnd)
202                             && bDidVisitOldObject)
203                         {
204                             pCandidate = (SdrTextObj*)pObj;
205                         }
206 
207                         if(pObj == pOldObj)
208                         {
209                             bDidVisitOldObject = sal_True;
210                         }
211                     }
212                 }
213             }
214 
215             if(pCandidate)
216             {
217                 // set the new candidate to text edit mode
218                 GetView()->UnMarkAll();
219                 GetView()->MarkObj(pCandidate, GetView()->GetSdrPageView());
220 
221                 GetViewFrame()->GetDispatcher()->Execute(
222                     SID_ATTR_CHAR, SFX_CALLMODE_ASYNCHRON);
223             }
224             else
225             {
226                 // insert a new page with the same page layout
227                 GetViewFrame()->GetDispatcher()->Execute(
228                     SID_INSERTPAGE_QUICK, SFX_CALLMODE_ASYNCHRON);
229             }
230         }
231         else
232         {
233             bRet = ViewShell::KeyInput(rKEvt, pWin);
234         }
235     }
236 
237     return bRet;
238 }
239 
240 /*************************************************************************
241 |*
242 |* Vom Lineal ausgehenden Drag (Hilflinien, Ursprung) beginnen
243 |*
244 \************************************************************************/
245 
246 void DrawViewShell::StartRulerDrag (
247     const Ruler& rRuler,
248     const MouseEvent& rMEvt)
249 {
250     GetActiveWindow()->CaptureMouse();
251 
252     Point aWPos = GetActiveWindow()->PixelToLogic(GetActiveWindow()->GetPointerPosPixel());
253 
254     if ( rRuler.GetExtraRect().IsInside(rMEvt.GetPosPixel()) )
255     {
256         mpDrawView->BegSetPageOrg(aWPos);
257         mbIsRulerDrag = sal_True;
258     }
259     else
260     {
261         // #i34536# if no guide-lines are visible yet, that show them
262         if( ! mpDrawView->IsHlplVisible())
263             mpDrawView->SetHlplVisible( sal_True );
264 
265         SdrHelpLineKind eKind;
266 
267         if ( rMEvt.IsMod1() )
268             eKind = SDRHELPLINE_POINT;
269         else if ( rRuler.IsHorizontal() )
270             eKind = SDRHELPLINE_HORIZONTAL;
271         else
272             eKind = SDRHELPLINE_VERTICAL;
273 
274         mpDrawView->BegDragHelpLine(aWPos, eKind);
275         mbIsRulerDrag = sal_True;
276     }
277 }
278 
279 /*************************************************************************
280 |*
281 |* MouseButtonDown event
282 |*
283 \************************************************************************/
284 
285 void DrawViewShell::MouseButtonDown(const MouseEvent& rMEvt,
286     ::sd::Window* pWin)
287 {
288     // We have to check if a context menu is shown and we have an UI
289     // active inplace client. In that case we have to ignore the mouse
290     // button down event. Otherwise we would crash (context menu has been
291     // opened by inplace client and we would deactivate the inplace client,
292     // the contex menu is closed by VCL asynchronously which in the end
293     // would work on deleted objects or the context menu has no parent anymore)
294     // See #126086# and #128122#
295     SfxInPlaceClient* pIPClient = GetViewShell()->GetIPClient();
296     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
297 
298     if ( bIsOleActive && PopupMenu::IsInExecute() )
299         return;
300 
301     if ( !IsInputLocked() )
302     {
303         ViewShell::MouseButtonDown(rMEvt, pWin);
304 
305         if ( mbPipette )
306             ( (SvxBmpMask*) GetViewFrame()->GetChildWindow( SvxBmpMaskChildWindow::GetChildWindowId() )->GetWindow() )->PipetteClicked();
307     }
308 }
309 
310 /*************************************************************************
311 |*
312 |* MouseMove event
313 |*
314 \************************************************************************/
315 
316 
317 void DrawViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin)
318 {
319     if ( !IsInputLocked() )
320     {
321         if ( mpDrawView->IsAction() )
322         {
323             Rectangle aOutputArea(Point(0,0), GetActiveWindow()->GetOutputSizePixel());
324 
325             if ( !aOutputArea.IsInside(rMEvt.GetPosPixel()) )
326             {
327                 sal_Bool bInsideOtherWindow = sal_False;
328 
329                 if (mpContentWindow.get() != NULL)
330                 {
331                     aOutputArea = Rectangle(Point(0,0),
332                         mpContentWindow->GetOutputSizePixel());
333 
334                     Point aPos = mpContentWindow->GetPointerPosPixel();
335                     if ( aOutputArea.IsInside(aPos) )
336                         bInsideOtherWindow = sal_True;
337                 }
338 
339                 if (! GetActiveWindow()->HasFocus ())
340                 {
341                     GetActiveWindow()->ReleaseMouse ();
342                     mpDrawView->BrkAction ();
343                     return;
344                 }
345                 else if ( bInsideOtherWindow )
346                 {
347                     GetActiveWindow()->ReleaseMouse();
348                     pWin->CaptureMouse ();
349                 }
350             }
351             else if ( pWin != GetActiveWindow() )
352                  pWin->CaptureMouse();
353         }
354 
355         // #109585#
356         // Since the next MouseMove may execute a IsSolidDraggingNow() in
357         // SdrCreateView::MovCreateObj and there the ApplicationBackgroundColor
358         // is needed it is necessary to set it here.
359         if(mpDrawView!=NULL && GetDoc()!=NULL)
360         {
361             svtools::ColorConfig aColorConfig;
362             Color aFillColor;
363 
364             if(DOCUMENT_TYPE_IMPRESS == GetDoc()->GetDocumentType())
365             {
366                 aFillColor = Color( aColorConfig.GetColorValue( svtools::APPBACKGROUND ).nColor );
367             }
368             else
369             {
370                 aFillColor = Color( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
371             }
372 
373             mpDrawView->SetApplicationBackgroundColor(aFillColor);
374         }
375 
376         ViewShell::MouseMove(rMEvt, pWin);
377 
378         if( !mbMousePosFreezed )
379             maMousePos = rMEvt.GetPosPixel();
380 
381         Rectangle aRect;
382 
383         if ( mbIsRulerDrag )
384         {
385             Point aLogPos = GetActiveWindow()->PixelToLogic(maMousePos);
386             mpDrawView->MovAction(aLogPos);
387         }
388 
389         if ( mpDrawView->IsAction() )
390         {
391             mpDrawView->TakeActionRect(aRect);
392             aRect = GetActiveWindow()->LogicToPixel(aRect);
393         }
394         else
395         {
396             aRect = Rectangle(maMousePos, maMousePos);
397         }
398 
399         ShowMousePosInfo(aRect, pWin);
400 
401         if ( mbPipette && GetViewFrame()->HasChildWindow( SvxBmpMaskChildWindow::GetChildWindowId() ) )
402         {
403             const long      nStartX = maMousePos.X() - PIPETTE_RANGE;
404             const long      nEndX = maMousePos.X() + PIPETTE_RANGE;
405             const long      nStartY = maMousePos.Y() - PIPETTE_RANGE;
406             const long      nEndY = maMousePos.Y() + PIPETTE_RANGE;
407             long            nRed = 0;
408             long            nGreen = 0;
409             long            nBlue = 0;
410             const double    fDiv = ( ( PIPETTE_RANGE << 1 ) + 1 ) * ( ( PIPETTE_RANGE << 1 ) + 1 );
411 
412             for ( long nY = nStartY; nY <= nEndY; nY++ )
413             {
414                 for( long nX = nStartX; nX <= nEndX; nX++ )
415                 {
416                     const Color aCol( pWin->GetPixel( pWin->PixelToLogic( Point( nX, nY ) ) ) );
417 
418                     nRed += aCol.GetRed();
419                     nGreen += aCol.GetGreen();
420                     nBlue += aCol.GetBlue();
421                 }
422             }
423 
424             ( (SvxBmpMask*) GetViewFrame()->GetChildWindow( SvxBmpMaskChildWindow::GetChildWindowId() )->GetWindow() )->
425                 SetColor( Color( (sal_uInt8) ( nRed / fDiv + .5 ),
426                                  (sal_uInt8) ( nGreen / fDiv + .5 ),
427                                  (sal_uInt8) ( nBlue / fDiv + .5 ) ) );
428         }
429     }
430 }
431 
432 
433 /*************************************************************************
434 |*
435 |* MouseButtonUp event
436 |*
437 \************************************************************************/
438 
439 void DrawViewShell::MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin)
440 {
441     if ( !IsInputLocked() )
442     {
443         FASTBOOL bIsSetPageOrg = mpDrawView->IsSetPageOrg();
444 
445         if (mbIsRulerDrag)
446         {
447             Rectangle aOutputArea(Point(0,0), GetActiveWindow()->GetOutputSizePixel());
448 
449             if (aOutputArea.IsInside(rMEvt.GetPosPixel()))
450             {
451                 mpDrawView->EndAction();
452 
453                 if (bIsSetPageOrg)
454                     GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
455             }
456             else if (rMEvt.IsLeft() && bIsSetPageOrg)
457             {
458                 mpDrawView->BrkAction();
459                 SdPage* pPage = (SdPage*) mpDrawView->GetSdrPageView()->GetPage();
460                 Point aOrg(pPage->GetLftBorder(), pPage->GetUppBorder());
461                 mpDrawView->GetSdrPageView()->SetPageOrigin(aOrg);
462                 GetViewFrame()->GetBindings().Invalidate(SID_RULER_NULL_OFFSET);
463             }
464             else
465             {
466                 mpDrawView->BrkAction();
467             }
468 
469             GetActiveWindow()->ReleaseMouse();
470             mbIsRulerDrag = sal_False;
471         }
472         else
473             ViewShell::MouseButtonUp(rMEvt, pWin);
474     }
475 }
476 
477 /*************************************************************************
478 |*
479 |* Command event
480 |*
481 \************************************************************************/
482 
483 void DrawViewShell::Command(const CommandEvent& rCEvt, ::sd::Window* pWin)
484 {
485     // The command event is send to the window after a possible context
486     // menu from an inplace client is closed. Now we have the chance to
487     // deactivate the inplace client without any problem regarding parent
488     // windows and code on the stack.
489     // For more information, see #126086# and #128122#
490     SfxInPlaceClient* pIPClient = GetViewShell()->GetIPClient();
491     sal_Bool bIsOleActive = ( pIPClient && pIPClient->IsObjectInPlaceActive() );
492     if ( bIsOleActive && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ))
493     {
494         // Deactivate OLE object
495         mpDrawView->UnmarkAll();
496         SelectionHasChanged();
497         return;
498     }
499 
500     if ( !IsInputLocked() )
501     {
502         if( GetView() &&GetView()->getSmartTags().Command(rCEvt) )
503             return;
504 
505         const bool bNativeShow (SlideShow::IsRunning(GetViewShellBase()));
506 
507         if( rCEvt.GetCommand() == COMMAND_PASTESELECTION && !bNativeShow )
508         {
509             TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSelection( GetActiveWindow() ) );
510 
511             if( aDataHelper.GetTransferable().is() )
512             {
513                 Point       aPos;
514                 sal_Int8    nDnDAction = DND_ACTION_COPY;
515 
516                 if( GetActiveWindow() )
517                     aPos = GetActiveWindow()->PixelToLogic( rCEvt.GetMousePosPixel() );
518 
519                 if( !mpDrawView->InsertData( aDataHelper, aPos, nDnDAction, sal_False ) )
520                 {
521                     INetBookmark    aINetBookmark( aEmptyStr, aEmptyStr );
522 
523                     if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
524                           aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
525                         ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
526                           aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
527                         ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
528                           aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
529                     {
530                         InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
531                     }
532                 }
533             }
534         }
535         else if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && !bNativeShow &&
536                  pWin != NULL && !mpDrawView->IsAction() && !SD_MOD()->GetWaterCan() )
537         {
538             sal_uInt16 nSdResId = 0;          // ResourceID fuer Popup-Menue
539             sal_Bool bGraphicShell = this->ISA(GraphicViewShell);
540 
541             // Ist ein Fangobjekt unter dem Mauszeiger?
542             SdrPageView* pPV;
543             Point   aMPos = pWin->PixelToLogic( maMousePos );
544             sal_uInt16  nHitLog = (sal_uInt16) GetActiveWindow()->PixelToLogic(
545                 Size(FuPoor::HITPIX, 0 ) ).Width();
546             sal_uInt16  nHelpLine;
547             // fuer Klebepunkt
548             SdrObject*  pObj = NULL;
549             sal_uInt16      nPickId = 0;
550             // fuer Feldbefehl
551             OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView();
552             const SvxFieldItem* pFldItem = NULL;
553             if( pOLV )
554                 pFldItem = pOLV->GetFieldAtSelection();
555                 //pFldItem = pOLV->GetFieldUnderMousePointer();
556 
557             // Hilfslinie
558             if ( mpDrawView->PickHelpLine( aMPos, nHitLog, *GetActiveWindow(), nHelpLine, pPV) )
559             {
560                 nSdResId = RID_DRAW_SNAPOBJECT_POPUP;
561                 ShowSnapLineContextMenu(*pPV, nHelpLine, rCEvt.GetMousePosPixel());
562                 return;
563             }
564             // Klebepunkt unter dem Mauszeiger markiert?
565             else if( mpDrawView->PickGluePoint( aMPos, pObj, nPickId, pPV ) &&
566                      mpDrawView->IsGluePointMarked( pObj, nPickId ) )
567             {
568                 nSdResId = RID_DRAW_GLUEPOINT_POPUP;
569             }
570             // Feldbefehl ?
571             else if( pFldItem && (pFldItem->GetField()->ISA( SvxDateField ) ||
572                                  pFldItem->GetField()->ISA( SvxExtTimeField ) ||
573                                  pFldItem->GetField()->ISA( SvxExtFileField ) ||
574                                  pFldItem->GetField()->ISA( SvxAuthorField ) ) )
575             {
576                 LanguageType eLanguage( LANGUAGE_SYSTEM );
577 
578                 // #101743# Format popup with outliner language, if possible
579                 if( pOLV->GetOutliner() )
580                 {
581                     ESelection aSelection( pOLV->GetSelection() );
582                     eLanguage = pOLV->GetOutliner()->GetLanguage( aSelection.nStartPara, aSelection.nStartPos );
583                 }
584 
585                 SdFieldPopup aFieldPopup( pFldItem->GetField(), eLanguage );
586 
587                 if ( rCEvt.IsMouseEvent() )
588                     aMPos = rCEvt.GetMousePosPixel();
589                 else
590                     aMPos = Point( 20, 20 );
591                 aFieldPopup.Execute( pWin, aMPos );
592 
593                 SvxFieldData* pField = aFieldPopup.GetField();
594                 if( pField )
595                 {
596                     SvxFieldItem aFieldItem( *pField, EE_FEATURE_FIELD );
597                     //pOLV->DeleteSelected(); <-- fehlt leider !
598                     // Feld selektieren, so dass es beim Insert geloescht wird
599                     ESelection aSel = pOLV->GetSelection();
600                     sal_Bool bSel = sal_True;
601                     if( aSel.nStartPos == aSel.nEndPos )
602                     {
603                         bSel = sal_False;
604                         aSel.nEndPos++;
605                     }
606                     pOLV->SetSelection( aSel );
607 
608                     pOLV->InsertField( aFieldItem );
609 
610                     // Selektion wird wieder in den Ursprungszustand gebracht
611                     if( !bSel )
612                         aSel.nEndPos--;
613                     pOLV->SetSelection( aSel );
614 
615                     delete pField;
616                 }
617             }
618             else
619             {
620                 // ist etwas selektiert?
621                 if (mpDrawView->AreObjectsMarked() &&
622                     mpDrawView->GetMarkedObjectList().GetMarkCount() == 1 )
623                 {
624                     pObj = mpDrawView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
625                     if( HasCurrentFunction(SID_BEZIER_EDIT) && (dynamic_cast< SdrPathObj * >( pObj ) != 0 ) )
626                     {
627                         nSdResId = RID_BEZIER_POPUP;
628                     }
629                     else
630                     {
631                         if( mpDrawView->GetTextEditObject() )
632                         {
633                             OutlinerView* pOutlinerView = mpDrawView->GetTextEditOutlinerView();
634                             Point aPos(rCEvt.GetMousePosPixel());
635 
636                             if ( pOutlinerView )
637                             {
638                                 if( (  rCEvt.IsMouseEvent() && pOutlinerView->IsWrongSpelledWordAtPos(aPos) ) ||
639                                     ( !rCEvt.IsMouseEvent() && pOutlinerView->IsCursorAtWrongSpelledWord() ) )
640                                 {
641                                     // #91457# Popup for Online-Spelling now handled by DrawDocShell
642                                     // Link aLink = LINK(GetDoc(), SdDrawDocument, OnlineSpellCallback);
643                                     Link aLink = LINK(GetDocSh(), DrawDocShell, OnlineSpellCallback);
644 
645                                     if( !rCEvt.IsMouseEvent() )
646                                     {
647                                         aPos = GetActiveWindow()->LogicToPixel( pOutlinerView->GetEditView().GetCursor()->GetPos() );
648                                     }
649                                     // While showing the spell context menu
650                                     // we lock the input so that another
651                                     // context menu can not be opened during
652                                     // that time (crash #i43235#).  In order
653                                     // to not lock the UI completely we
654                                     // first release the mouse.
655                                     GetActiveWindow()->ReleaseMouse();
656                                     LockInput();
657                                     pOutlinerView->ExecuteSpellPopup(aPos, &aLink);
658                                     UnlockInput();
659                                 }
660                                 else
661                                 {
662                                     if( (pObj->GetObjInventor() == SdrInventor) && (pObj->GetObjIdentifier() == OBJ_TABLE) )
663                                     {
664                                         nSdResId = RID_DRAW_TABLEOBJ_INSIDE_POPUP;
665                                     }
666                                     else
667                                     {
668                                         nSdResId = RID_DRAW_TEXTOBJ_INSIDE_POPUP;
669                                     }
670                                 }
671                             }
672                         }
673                         else
674                         {
675                             sal_uInt32 nInv = pObj->GetObjInventor();
676                             sal_uInt16 nId = pObj->GetObjIdentifier();
677 
678                             if (nInv == SdrInventor)
679                             {
680                                 switch ( nId )
681                                 {
682                                     case OBJ_CAPTION:
683                                     case OBJ_TITLETEXT:
684                                     case OBJ_OUTLINETEXT:
685                                     case OBJ_TEXT:
686                                         nSdResId = bGraphicShell ? RID_GRAPHIC_TEXTOBJ_POPUP :
687                                                                     RID_DRAW_TEXTOBJ_POPUP;
688                                         break;
689 
690                                     case OBJ_PATHLINE:
691                                     case OBJ_PLIN:
692                                         nSdResId = bGraphicShell ? RID_GRAPHIC_POLYLINEOBJ_POPUP :
693                                                                     RID_DRAW_POLYLINEOBJ_POPUP;
694                                         break;
695 
696                                     case OBJ_FREELINE:
697                                     case OBJ_EDGE:      // Connector
698                                         nSdResId = bGraphicShell ? RID_GRAPHIC_EDGEOBJ_POPUP :
699                                                                     RID_DRAW_EDGEOBJ_POPUP;
700                                         break;
701 
702                                     case OBJ_LINE:
703                                         nSdResId = bGraphicShell ? RID_GRAPHIC_LINEOBJ_POPUP :
704                                                                     RID_DRAW_LINEOBJ_POPUP;
705                                         break;
706 
707                                     case OBJ_MEASURE:
708                                         nSdResId = bGraphicShell ? RID_GRAPHIC_MEASUREOBJ_POPUP :
709                                                                     RID_DRAW_MEASUREOBJ_POPUP;
710                                         break;
711 
712                                     case OBJ_RECT:
713                                     case OBJ_CIRC:
714                                     case OBJ_FREEFILL:
715                                     case OBJ_PATHFILL:
716                                     case OBJ_POLY:
717                                     case OBJ_SECT:
718                                     case OBJ_CARC:
719                                     case OBJ_CCUT:
720                                         nSdResId = bGraphicShell ? RID_GRAPHIC_GEOMOBJ_POPUP :
721                                                                     RID_DRAW_GEOMOBJ_POPUP;
722                                         break;
723 
724                                     case OBJ_CUSTOMSHAPE:
725                                         nSdResId = bGraphicShell ? RID_GRAPHIC_CUSTOMSHAPE_POPUP :
726                                                                     RID_DRAW_CUSTOMSHAPE_POPUP;
727                                         break;
728 
729                                     case OBJ_GRUP:
730                                         nSdResId = bGraphicShell ? RID_GRAPHIC_GROUPOBJ_POPUP :
731                                                                     RID_DRAW_GROUPOBJ_POPUP;
732                                         break;
733 
734                                     case OBJ_GRAF:
735                                         nSdResId = bGraphicShell ? RID_GRAPHIC_GRAPHIC_POPUP :
736                                                                     RID_DRAW_GRAPHIC_POPUP;
737                                         break;
738 
739                                     case OBJ_OLE2:
740                                         nSdResId = bGraphicShell ? RID_GRAPHIC_OLE2_POPUP :
741                                                                     RID_DRAW_OLE2_POPUP;
742                                         break;
743                                     case OBJ_MEDIA:
744                                         nSdResId = bGraphicShell ? RID_GRAPHIC_MEDIA_POPUP :
745                                                                     RID_DRAW_MEDIA_POPUP;
746                                         break;
747                                     case OBJ_TABLE:
748                                         nSdResId = bGraphicShell ? RID_GRAPHIC_TABLE_POPUP :
749                                                                     RID_DRAW_TABLE_POPUP;
750                                         break;
751                                 }
752                             }
753                             else if( nInv == E3dInventor /*&& nId == E3D_POLYSCENE_ID*/)
754                             {
755                                 if( nId == E3D_POLYSCENE_ID || nId == E3D_SCENE_ID )
756                                 {
757                                     if( !mpDrawView->IsGroupEntered() )
758                                         nSdResId = bGraphicShell ? RID_GRAPHIC_3DSCENE_POPUP :
759                                                                 RID_DRAW_3DSCENE_POPUP;
760                                     else
761                                         nSdResId = bGraphicShell ? RID_GRAPHIC_3DSCENE2_POPUP :
762                                                                 RID_DRAW_3DSCENE2_POPUP;
763                                 }
764                                 else
765                                     nSdResId = bGraphicShell ? RID_GRAPHIC_3DOBJ_POPUP :
766                                                                 RID_DRAW_3DOBJ_POPUP;
767                             }
768                             else if( nInv == FmFormInventor )
769                             {
770                                 nSdResId = RID_FORM_CONTROL_POPUP;
771                             }
772                         }
773                     }
774                 }
775 
776                 // Mehrfachselektion
777                 else if (mpDrawView->AreObjectsMarked() &&
778                     mpDrawView->GetMarkedObjectList().GetMarkCount() > 1 )
779                 {
780                     nSdResId = bGraphicShell ? RID_GRAPHIC_MULTISELECTION_POPUP :
781                                                 RID_DRAW_MULTISELECTION_POPUP;
782                 }
783 
784                 // nichts selektiert
785                 else
786                 {
787                     nSdResId = bGraphicShell ? RID_GRAPHIC_NOSEL_POPUP :
788                                                 RID_DRAW_NOSEL_POPUP;
789                 }
790             }
791             // Popup-Menue anzeigen
792             if (nSdResId)
793             {
794                 GetActiveWindow()->ReleaseMouse();
795 
796                 if(rCEvt.IsMouseEvent())
797                     GetViewFrame()->GetDispatcher()->ExecutePopup(SdResId(nSdResId));
798                 else
799                 {
800                     //#106326# don't open contextmenu at mouse position if not opened via mouse
801 
802                     //middle of the window if nothing is marked
803                     Point aMenuPos(GetActiveWindow()->GetSizePixel().Width()/2
804                             ,GetActiveWindow()->GetSizePixel().Height()/2);
805 
806                     //middle of the bounding rect if something is marked
807                     if( mpDrawView->AreObjectsMarked() && mpDrawView->GetMarkedObjectList().GetMarkCount() >= 1 )
808                     {
809                         Rectangle aMarkRect;
810                         mpDrawView->GetMarkedObjectList().TakeBoundRect(NULL,aMarkRect);
811                         aMenuPos = GetActiveWindow()->LogicToPixel( aMarkRect.Center() );
812 
813                         //move the point into the visible window area
814                         if( aMenuPos.X() < 0 )
815                             aMenuPos.X() = 0;
816                         if( aMenuPos.Y() < 0 )
817                             aMenuPos.Y() = 0;
818                         if( aMenuPos.X() > GetActiveWindow()->GetSizePixel().Width() )
819                             aMenuPos.X() = GetActiveWindow()->GetSizePixel().Width();
820                         if( aMenuPos.Y() > GetActiveWindow()->GetSizePixel().Height() )
821                             aMenuPos.Y() = GetActiveWindow()->GetSizePixel().Height();
822                     }
823 
824                     //open context menu at that point
825                     GetViewFrame()->GetDispatcher()->ExecutePopup(SdResId(nSdResId),GetActiveWindow(),&aMenuPos);
826                 }
827                 mbMousePosFreezed = sal_False;
828             }
829         }
830         else
831         {
832             ViewShell::Command(rCEvt, pWin);
833         }
834     }
835 }
836 
837 /*************************************************************************
838 |*
839 |* Linealmarkierungen anzeigen
840 |*
841 \************************************************************************/
842 
843 void DrawViewShell::ShowMousePosInfo(const Rectangle& rRect,
844     ::sd::Window* pWin)
845 {
846     if (mbHasRulers && pWin )
847     {
848         RulerLine   pHLines[2];
849         RulerLine   pVLines[2];
850         long        nHOffs = 0L;
851         long        nVOffs = 0L;
852         sal_uInt16      nCnt;
853 
854         if (mpHorizontalRuler.get() != NULL)
855             mpHorizontalRuler->SetLines();
856 
857         if (mpVerticalRuler.get() != NULL)
858             mpVerticalRuler->SetLines();
859 
860         if (mpHorizontalRuler.get() != NULL)
861         {
862             nHOffs = mpHorizontalRuler->GetNullOffset() +
863                      mpHorizontalRuler->GetPageOffset();
864         }
865 
866         if (mpVerticalRuler.get() != NULL)
867         {
868             nVOffs = mpVerticalRuler->GetNullOffset() +
869                      mpVerticalRuler->GetPageOffset();
870         }
871 
872         nCnt = 1;
873         pHLines[0].nPos = rRect.Left() - nHOffs;
874         pVLines[0].nPos = rRect.Top()  - nVOffs;
875         pHLines[0].nStyle = 0;
876         pVLines[0].nStyle = 0;
877 
878         if ( rRect.Right() != rRect.Left() || rRect.Bottom() != rRect.Top() )
879         {
880             pHLines[1].nPos = rRect.Right()  - nHOffs;
881             pVLines[1].nPos = rRect.Bottom() - nVOffs;
882             pHLines[1].nStyle = 0;
883             pVLines[1].nStyle = 0;
884             nCnt++;
885         }
886 
887         if (mpHorizontalRuler.get() != NULL)
888             mpHorizontalRuler->SetLines(nCnt, pHLines);
889         if (mpVerticalRuler.get() != NULL)
890             mpVerticalRuler->SetLines(nCnt, pVLines);
891     }
892 
893     // StatusBar Koordinatenanzeige
894     OSL_ASSERT (GetViewShell()!=NULL);
895     if ( !GetViewShell()->GetUIActiveClient() )
896     {
897         SfxItemSet aSet(GetPool(), SID_CONTEXT, SID_CONTEXT,
898                                    SID_ATTR_POSITION, SID_ATTR_POSITION,
899                                    SID_ATTR_SIZE, SID_ATTR_SIZE,
900                                    0L);
901 
902 //        GetStatusBarState(aSet);  nicht performant bei gedrueckter Modifiertaste!!
903 
904         aSet.Put( SfxStringItem( SID_CONTEXT, mpDrawView->GetStatusText() ) );
905 
906         SfxBindings& rBindings = GetViewFrame()->GetBindings();
907         rBindings.SetState(aSet);
908         rBindings.Invalidate(SID_CONTEXT);
909         rBindings.Invalidate(SID_ATTR_POSITION);
910         rBindings.Invalidate(SID_ATTR_SIZE);
911     }
912 }
913 
914 /*************************************************************************
915 |*
916 |*
917 |*
918 \************************************************************************/
919 
920 void DrawViewShell::LockInput()
921 {
922     mnLockCount++;
923 }
924 
925 /*************************************************************************
926 |*
927 |*
928 |*
929 \************************************************************************/
930 
931 void DrawViewShell::UnlockInput()
932 {
933     DBG_ASSERT( mnLockCount, "Input for this shell is not locked!" );
934     if ( mnLockCount )
935         mnLockCount--;
936 }
937 
938 
939 
940 
941 void DrawViewShell::ShowSnapLineContextMenu (
942     SdrPageView& rPageView,
943     const sal_uInt16 nSnapLineIndex,
944     const Point& rMouseLocation)
945 {
946     const SdrHelpLine& rHelpLine (rPageView.GetHelpLines()[nSnapLineIndex]);
947     ::boost::scoped_ptr<PopupMenu> pMenu (new PopupMenu ());
948 
949     if (rHelpLine.GetKind() == SDRHELPLINE_POINT)
950     {
951         pMenu->InsertItem(
952             SID_SET_SNAPITEM,
953             String(SdResId(STR_POPUP_EDIT_SNAPPOINT)));
954         pMenu->InsertSeparator();
955         pMenu->InsertItem(
956             SID_DELETE_SNAPITEM,
957             String(SdResId(STR_POPUP_DELETE_SNAPPOINT)));
958     }
959     else
960     {
961         pMenu->InsertItem(
962             SID_SET_SNAPITEM,
963             String(SdResId(STR_POPUP_EDIT_SNAPLINE)));
964         pMenu->InsertSeparator();
965         pMenu->InsertItem(
966             SID_DELETE_SNAPITEM,
967             String(SdResId(STR_POPUP_DELETE_SNAPLINE)));
968     }
969 
970     pMenu->RemoveDisabledEntries(sal_False, sal_False);
971 
972     const sal_uInt16 nResult = pMenu->Execute(
973         GetActiveWindow(),
974         Rectangle(rMouseLocation, Size(10,10)),
975         POPUPMENU_EXECUTE_DOWN);
976     switch (nResult)
977     {
978         case SID_SET_SNAPITEM:
979         {
980             SfxUInt32Item aHelpLineItem (ID_VAL_INDEX, nSnapLineIndex);
981             const SfxPoolItem* aArguments[] = {&aHelpLineItem, NULL};
982             GetViewFrame()->GetDispatcher()->Execute(
983                 SID_SET_SNAPITEM,
984                 SFX_CALLMODE_SLOT,
985                 aArguments);
986         }
987         break;
988 
989         case SID_DELETE_SNAPITEM:
990         {
991             rPageView.DeleteHelpLine(nSnapLineIndex);
992         }
993         break;
994 
995         default:
996             break;
997     }
998 }
999 
1000 
1001 
1002 
1003 #ifdef _MSC_VER
1004 #pragma optimize ( "", on )
1005 #endif
1006 
1007 } // end of namespace sd
1008