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