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