xref: /aoo41x/main/svx/source/dialog/graphctl.cxx (revision f6e50924)
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_svx.hxx"
26 #include <svl/itempool.hxx>
27 #include <vcl/dialog.hxx>
28 #include <vcl/wrkwin.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <rtl/math.hxx>
31 #include <unotools/localedatawrapper.hxx>
32 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
33 #include <comphelper/processfactory.hxx>
34 #endif
35 #include <vcl/svapp.hxx>
36 #include <osl/mutex.hxx>
37 
38 #include <svx/graphctl.hxx>
39 #include "GraphCtlAccessibleContext.hxx"
40 #include "svx/xoutbmp.hxx"
41 #include <svx/svxids.hrc>
42 #include <svx/svdpage.hxx>
43 
44 // #i72889#
45 #include "svx/sdrpaintwindow.hxx"
46 
47 /*************************************************************************
48 |*
49 |*
50 |*
51 \************************************************************************/
52 
Changed(const SdrObject & rObj,SdrUserCallType eType,const Rectangle &)53 void GraphCtrlUserCall::Changed( const SdrObject& rObj, SdrUserCallType eType, const Rectangle& /*rOldBoundRect*/ )
54 {
55 	switch( eType )
56 	{
57 		case( SDRUSERCALL_MOVEONLY ):
58 		case( SDRUSERCALL_RESIZE ):
59 			rWin.SdrObjChanged( rObj );
60 		break;
61 
62 		case( SDRUSERCALL_INSERTED ):
63 			rWin.SdrObjCreated( rObj );
64 		break;
65 
66 		default:
67 		break;
68 	}
69 }
70 
71 
72 /*************************************************************************
73 |*
74 |*
75 |*
76 \************************************************************************/
77 
GraphCtrl(Window * pParent,const WinBits nWinBits)78 GraphCtrl::GraphCtrl( Window* pParent, const WinBits nWinBits ) :
79 			Control			( pParent, nWinBits ),
80 			aMap100			( MAP_100TH_MM ),
81             eObjKind        ( OBJ_NONE ),
82 			nPolyEdit		( 0 ),
83 			bEditMode		( sal_False ),
84 			bSdrMode		( sal_False ),
85             mpAccContext    ( NULL ),
86             pModel          ( NULL ),
87             pView           ( NULL )
88 {
89 	pUserCall = new GraphCtrlUserCall( *this );
90 	aUpdateTimer.SetTimeout( 200 );
91 	aUpdateTimer.SetTimeoutHdl( LINK( this, GraphCtrl, UpdateHdl ) );
92 	aUpdateTimer.Start();
93 
94 	SetWinStyle( nWinBits );
95 
96 	EnableRTL( sal_False );
97 }
98 
99 
100 /*************************************************************************
101 |*
102 |*
103 |*
104 \************************************************************************/
105 
GraphCtrl(Window * pParent,const ResId & rResId)106 GraphCtrl::GraphCtrl( Window* pParent, const ResId& rResId ) :
107 			Control			( pParent, rResId ),
108 			aMap100			( MAP_100TH_MM ),
109             nWinStyle       ( 0 ),
110             eObjKind        ( OBJ_NONE ),
111 			nPolyEdit		( 0 ),
112             bEditMode       ( sal_False ),
113             bSdrMode        ( sal_False ),
114             bAnim           ( sal_False ),
115             mpAccContext    ( NULL ),
116             pModel          ( NULL ),
117             pView           ( NULL )
118 {
119 	pUserCall = new GraphCtrlUserCall( *this );
120 	aUpdateTimer.SetTimeout( 500 );
121 	aUpdateTimer.SetTimeoutHdl( LINK( this, GraphCtrl, UpdateHdl ) );
122 	aUpdateTimer.Start();
123 	EnableRTL( sal_False );
124 }
125 
126 
127 /*************************************************************************
128 |*
129 |*
130 |*
131 \************************************************************************/
132 
~GraphCtrl()133 GraphCtrl::~GraphCtrl()
134 {
135 	if( mpAccContext )
136 	{
137 		mpAccContext->disposing();
138 		mpAccContext->release();
139 	}
140 	delete pView;
141 	delete pModel;
142 	delete pUserCall;
143 }
144 
145 
146 /*************************************************************************
147 |*
148 |*
149 |*
150 \************************************************************************/
151 
SetWinStyle(WinBits nWinBits)152 void GraphCtrl::SetWinStyle( WinBits nWinBits )
153 {
154 	nWinStyle = nWinBits;
155 	bAnim = ( nWinStyle & WB_ANIMATION ) == WB_ANIMATION;
156 	bSdrMode = ( nWinStyle & WB_SDRMODE ) == WB_SDRMODE;
157 
158 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
159 	SetBackground( Wallpaper( rStyleSettings.GetWindowColor() ) );
160 	SetMapMode( aMap100 );
161 
162 	delete pView;
163 	pView = NULL;
164 
165 	delete pModel;
166 	pModel = NULL;
167 
168 	if ( bSdrMode )
169 		InitSdrModel();
170 }
171 
172 
173 /*************************************************************************
174 |*
175 |*
176 |*
177 \************************************************************************/
178 
InitSdrModel()179 void GraphCtrl::InitSdrModel()
180 {
181 	::vos::OGuard aGuard (Application::GetSolarMutex());
182 
183 	SdrPage* pPage;
184 
185 	// alten Kram zerstoeren
186 	delete pView;
187 	delete pModel;
188 
189 	// Model anlegen
190 	pModel = new SdrModel;
191 	pModel->GetItemPool().FreezeIdRanges();
192 	pModel->SetScaleUnit( aMap100.GetMapUnit() );
193 	pModel->SetScaleFraction( Fraction( 1, 1 ) );
194 	pModel->SetDefaultFontHeight( 500 );
195 
196 	pPage = new SdrPage( *pModel );
197 
198 	pPage->SetSize( aGraphSize );
199 	pPage->SetBorder( 0, 0, 0, 0 );
200 	pModel->InsertPage( pPage );
201 	pModel->SetChanged( sal_False );
202 
203 	// View anlegen
204 	pView = new GraphCtrlView( pModel, this );
205 	pView->SetWorkArea( Rectangle( Point(), aGraphSize ) );
206 	pView->EnableExtendedMouseEventDispatcher( sal_True );
207 	pView->ShowSdrPage(pView->GetModel()->GetPage(0));
208 //	pView->ShowSdrPage(pView->GetModel()->GetPage(0));
209 	pView->SetFrameDragSingles( sal_True );
210 	pView->SetMarkedPointsSmooth( SDRPATHSMOOTH_SYMMETRIC );
211 	pView->SetEditMode( sal_True );
212 
213 	// #i72889# set neeeded flags
214 	pView->SetPagePaintingAllowed(false);
215 	pView->SetBufferedOutputAllowed(true);
216 	pView->SetBufferedOverlayAllowed(true);
217 
218     // Tell the accessibility object about the changes.
219     if (mpAccContext != NULL)
220         mpAccContext->setModelAndView (pModel, pView);
221 }
222 
223 
224 /*************************************************************************
225 |*
226 |*
227 |*
228 \************************************************************************/
229 
SetGraphic(const Graphic & rGraphic,sal_Bool bNewModel)230 void GraphCtrl::SetGraphic( const Graphic& rGraphic, sal_Bool bNewModel )
231 {
232 	// Bitmaps dithern wir ggf. fuer die Anzeige
233 	if ( !bAnim && ( rGraphic.GetType() == GRAPHIC_BITMAP )  )
234 	{
235 		if ( rGraphic.IsTransparent() )
236 		{
237 			Bitmap	aBmp( rGraphic.GetBitmap() );
238 
239 			DitherBitmap( aBmp );
240 			aGraphic = Graphic( BitmapEx( aBmp, rGraphic.GetBitmapEx().GetMask() ) );
241 		}
242 		else
243 		{
244 			Bitmap aBmp( rGraphic.GetBitmap() );
245 			DitherBitmap( aBmp );
246 			aGraphic = aBmp;
247 		}
248 	}
249 	else
250 		aGraphic = rGraphic;
251 
252 	if ( aGraphic.GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
253 		aGraphSize = Application::GetDefaultDevice()->PixelToLogic( aGraphic.GetPrefSize(), aMap100 );
254 	else
255 		aGraphSize = OutputDevice::LogicToLogic( aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(), aMap100 );
256 
257 	if ( bSdrMode && bNewModel )
258 		InitSdrModel();
259 
260 	if ( aGraphSizeLink.IsSet() )
261 		aGraphSizeLink.Call( this );
262 
263 	Resize();
264 	Invalidate();
265 }
266 
267 
268 /*************************************************************************
269 |*
270 |*
271 |*
272 \************************************************************************/
273 
Resize()274 void GraphCtrl::Resize()
275 {
276 	Control::Resize();
277 
278 	if ( aGraphSize.Width() && aGraphSize.Height() )
279 	{
280 		MapMode			aDisplayMap( aMap100 );
281 		Point           aNewPos;
282 		Size			aNewSize;
283 		const Size		aWinSize = PixelToLogic( GetOutputSizePixel(), aDisplayMap );
284 		const long		nWidth = aWinSize.Width();
285 		const long		nHeight = aWinSize.Height();
286 		double          fGrfWH = (double) aGraphSize.Width() / aGraphSize.Height();
287 		double          fWinWH = (double) nWidth / nHeight;
288 
289 		// Bitmap an Thumbgroesse anpassen
290 		if ( fGrfWH < fWinWH)
291 		{
292 			aNewSize.Width() = (long) ( (double) nHeight * fGrfWH );
293 			aNewSize.Height()= nHeight;
294 		}
295 		else
296 		{
297 			aNewSize.Width() = nWidth;
298 			aNewSize.Height()= (long) ( (double) nWidth / fGrfWH );
299 		}
300 
301 		aNewPos.X() = ( nWidth - aNewSize.Width() )  >> 1;
302 		aNewPos.Y() = ( nHeight - aNewSize.Height() ) >> 1;
303 
304 		// MapMode fuer Engine umsetzen
305 		aDisplayMap.SetScaleX( Fraction( aNewSize.Width(), aGraphSize.Width() ) );
306 		aDisplayMap.SetScaleY( Fraction( aNewSize.Height(), aGraphSize.Height() ) );
307 
308 		aDisplayMap.SetOrigin( LogicToLogic( aNewPos, aMap100, aDisplayMap ) );
309 		SetMapMode( aDisplayMap );
310 	}
311 
312 	Invalidate();
313 }
314 
315 
316 /*************************************************************************
317 |*
318 |*
319 |*
320 \************************************************************************/
321 
Paint(const Rectangle & rRect)322 void GraphCtrl::Paint( const Rectangle& rRect )
323 {
324 	// #i72889# used splitted repaint to be able to paint an own background
325 	// even to the buffered view
326 	const bool bGraphicValid(GRAPHIC_NONE != aGraphic.GetType());
327 
328 	if(bSdrMode)
329 	{
330 		SdrPaintWindow* pPaintWindow = pView->BeginCompleteRedraw(this);
331 
332 		if(bGraphicValid)
333 		{
334 			OutputDevice& rTarget = pPaintWindow->GetTargetOutputDevice();
335 
336 			rTarget.SetBackground(GetBackground());
337 			rTarget.Erase();
338 
339 			aGraphic.Draw(&rTarget, Point(), aGraphSize);
340 		}
341 
342 		const Region aRepaintRegion(rRect);
343 		pView->DoCompleteRedraw(*pPaintWindow, aRepaintRegion);
344 		pView->EndCompleteRedraw(*pPaintWindow, true);
345 	}
346 	else
347 	{
348 		// #i73381# in non-SdrMode, paint to local directly
349 		if(bGraphicValid)
350 		{
351 			aGraphic.Draw(this, Point(), aGraphSize);
352 		}
353 	}
354 }
355 
356 
357 /*************************************************************************
358 |*
359 |*
360 |*
361 \************************************************************************/
362 
SdrObjChanged(const SdrObject &)363 void GraphCtrl::SdrObjChanged( const SdrObject&  )
364 {
365 }
366 
367 
368 /*************************************************************************
369 |*
370 |*
371 |*
372 \************************************************************************/
373 
SdrObjCreated(const SdrObject &)374 void GraphCtrl::SdrObjCreated( const SdrObject& )
375 {
376 }
377 
378 
379 /*************************************************************************
380 |*
381 |*
382 |*
383 \************************************************************************/
384 
MarkListHasChanged()385 void GraphCtrl::MarkListHasChanged()
386 {
387 	if ( aMarkObjLink.IsSet() )
388 		aMarkObjLink.Call( this );
389 }
390 
391 
392 /*************************************************************************
393 |*
394 |*
395 |*
396 \************************************************************************/
397 
KeyInput(const KeyEvent & rKEvt)398 void GraphCtrl::KeyInput( const KeyEvent& rKEvt )
399 {
400 	KeyCode aCode( rKEvt.GetKeyCode() );
401 	sal_Bool	bProc = sal_False;
402 
403 	switch ( aCode.GetCode() )
404 	{
405 		case KEY_DELETE:
406 		case KEY_BACKSPACE:
407 		{
408 			if ( bSdrMode )
409 			{
410 				pView->DeleteMarked();
411 				bProc = sal_True;
412 				if( !pView->AreObjectsMarked() )
413 					((Dialog*)GetParent())->GrabFocusToFirstControl();
414 			}
415 		}
416 		break;
417 
418 		case KEY_ESCAPE:
419 		{
420 			if ( bSdrMode )
421 			{
422 				if ( pView->IsAction() )
423 				{
424 					pView->BrkAction();
425 				}
426 				else if ( pView->AreObjectsMarked() )
427 				{
428 					const SdrHdlList& rHdlList = pView->GetHdlList();
429 					SdrHdl* pHdl = rHdlList.GetFocusHdl();
430 
431 					if(pHdl)
432 					{
433 						((SdrHdlList&)rHdlList).ResetFocusHdl();
434 					}
435 					else
436 					{
437 						((Dialog*)GetParent())->GrabFocusToFirstControl();
438 					}
439 				}
440 				else
441 				{
442 					((Dialog*)GetParent())->GrabFocusToFirstControl();
443 				}
444 				bProc = sal_True;
445 			}
446 		}
447 		break;
448 
449 		case KEY_F11:
450 		case KEY_TAB:
451 		{
452 			if( bSdrMode )
453 			{
454 				if( !aCode.IsMod1() && !aCode.IsMod2() )
455 				{
456 					bool bForward = !aCode.IsShift();
457 					// select next object
458 					if ( ! pView->MarkNextObj( bForward ))
459                     {
460                         // At first or last object.  Cycle to the other end
461                         // of the list.
462                         pView->UnmarkAllObj();
463                         pView->MarkNextObj (bForward);
464                     }
465 					bProc = sal_True;
466 				}
467 				else if(aCode.IsMod1())
468 				{
469 					// select next handle
470 					const SdrHdlList& rHdlList = pView->GetHdlList();
471 					sal_Bool bForward(!aCode.IsShift());
472 
473 					((SdrHdlList&)rHdlList).TravelFocusHdl(bForward);
474 
475 					bProc = true;
476 				}
477 			}
478 		}
479 		break;
480 
481 		case KEY_END:
482 		{
483 
484 			if ( aCode.IsMod1() )
485 			{
486 				// #97016# mark last object
487 				pView->UnmarkAllObj();
488 				pView->MarkNextObj(sal_False);
489 
490 				bProc = true;
491 			}
492 		}
493 		break;
494 
495 		case KEY_HOME:
496 		{
497 			if ( aCode.IsMod1() )
498 			{
499 				pView->UnmarkAllObj();
500 				pView->MarkNextObj(sal_True);
501 
502 				bProc = true;
503 			}
504 		}
505 		break;
506 
507 		case KEY_UP:
508 		case KEY_DOWN:
509 		case KEY_LEFT:
510 		case KEY_RIGHT:
511 		{
512 			long nX = 0;
513 			long nY = 0;
514 
515 			if (aCode.GetCode() == KEY_UP)
516 			{
517 				// Scroll nach oben
518 				nX = 0;
519 				nY =-1;
520 			}
521 			else if (aCode.GetCode() == KEY_DOWN)
522 			{
523 				// Scroll nach unten
524 				nX = 0;
525 				nY = 1;
526 			}
527 			else if (aCode.GetCode() == KEY_LEFT)
528 			{
529 				// Scroll nach links
530 				nX =-1;
531 				nY = 0;
532 			}
533 			else if (aCode.GetCode() == KEY_RIGHT)
534 			{
535 				// Scroll nach rechts
536 				nX = 1;
537 				nY = 0;
538 			}
539 
540 			if (pView->AreObjectsMarked() && !aCode.IsMod1() )
541 			{
542 				if(aCode.IsMod2())
543 				{
544 					// #97016# move in 1 pixel distance
545 					Size aLogicSizeOnePixel = PixelToLogic(Size(1,1));
546 					nX *= aLogicSizeOnePixel.Width();
547 					nY *= aLogicSizeOnePixel.Height();
548 				}
549 				else
550 				{
551 					// old, fixed move distance
552 					nX *= 100;
553 					nY *= 100;
554 				}
555 
556 				// #97016# II
557 				const SdrHdlList& rHdlList = pView->GetHdlList();
558 				SdrHdl* pHdl = rHdlList.GetFocusHdl();
559 
560 				if(0L == pHdl)
561 				{
562 					// #90129# restrict movement to WorkArea
563 					const Rectangle& rWorkArea = pView->GetWorkArea();
564 
565 					if(!rWorkArea.IsEmpty())
566 					{
567 						Rectangle aMarkRect(pView->GetMarkedObjRect());
568 						aMarkRect.Move(nX, nY);
569 
570 						if(!aMarkRect.IsInside(rWorkArea))
571 						{
572 							if(aMarkRect.Left() < rWorkArea.Left())
573 							{
574 								nX += rWorkArea.Left() - aMarkRect.Left();
575 							}
576 
577 							if(aMarkRect.Right() > rWorkArea.Right())
578 							{
579 								nX -= aMarkRect.Right() - rWorkArea.Right();
580 							}
581 
582 							if(aMarkRect.Top() < rWorkArea.Top())
583 							{
584 								nY += rWorkArea.Top() - aMarkRect.Top();
585 							}
586 
587 							if(aMarkRect.Bottom() > rWorkArea.Bottom())
588 							{
589 								nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
590 							}
591 						}
592 					}
593 
594 					// no handle selected
595 					if(0 != nX || 0 != nY)
596 					{
597 						pView->MoveAllMarked(Size(nX, nY));
598 					}
599 				}
600 				else
601 				{
602 					// move handle with index nHandleIndex
603 					if(pHdl && (nX || nY))
604 					{
605 						// now move the Handle (nX, nY)
606 						Point aStartPoint(pHdl->GetPos());
607 						Point aEndPoint(pHdl->GetPos() + Point(nX, nY));
608 						const SdrDragStat& rDragStat = pView->GetDragStat();
609 
610 						// start dragging
611 						pView->BegDragObj(aStartPoint, 0, pHdl, 0);
612 
613 					    if(pView->IsDragObj())
614 						{
615 							FASTBOOL bWasNoSnap = rDragStat.IsNoSnap();
616 							sal_Bool bWasSnapEnabled = pView->IsSnapEnabled();
617 
618 							// switch snapping off
619 							if(!bWasNoSnap)
620 								((SdrDragStat&)rDragStat).SetNoSnap(sal_True);
621 							if(bWasSnapEnabled)
622 								pView->SetSnapEnabled(sal_False);
623 
624 							pView->MovAction(aEndPoint);
625 							pView->EndDragObj();
626 
627 							// restore snap
628 							if(!bWasNoSnap)
629 								((SdrDragStat&)rDragStat).SetNoSnap(bWasNoSnap);
630 							if(bWasSnapEnabled)
631 								pView->SetSnapEnabled(bWasSnapEnabled);
632 						}
633 					}
634 				}
635 
636 				bProc = true;
637 			}
638 		}
639 		break;
640 
641 		case KEY_SPACE:
642 		{
643 			const SdrHdlList& rHdlList = pView->GetHdlList();
644 			SdrHdl* pHdl = rHdlList.GetFocusHdl();
645 
646 			if(pHdl)
647 			{
648 				if(pHdl->GetKind() == HDL_POLY)
649 				{
650 					// rescue ID of point with focus
651 					sal_uInt32 nPol(pHdl->GetPolyNum());
652 					sal_uInt32 nPnt(pHdl->GetPointNum());
653 
654 					if(pView->IsPointMarked(*pHdl))
655 					{
656 						if(rKEvt.GetKeyCode().IsShift())
657 						{
658 							pView->UnmarkPoint(*pHdl);
659 						}
660 					}
661 					else
662 					{
663 						if(!rKEvt.GetKeyCode().IsShift())
664 						{
665 							pView->UnmarkAllPoints();
666 						}
667 
668 						pView->MarkPoint(*pHdl);
669 					}
670 
671 					if(0L == rHdlList.GetFocusHdl())
672 					{
673 						// restore point with focus
674 						SdrHdl* pNewOne = 0L;
675 
676 						for(sal_uInt32 a(0); !pNewOne && a < rHdlList.GetHdlCount(); a++)
677 						{
678 							SdrHdl* pAct = rHdlList.GetHdl(a);
679 
680 							if(pAct
681 								&& pAct->GetKind() == HDL_POLY
682 								&& pAct->GetPolyNum() == nPol
683 								&& pAct->GetPointNum() == nPnt)
684 							{
685 								pNewOne = pAct;
686 							}
687 						}
688 
689 						if(pNewOne)
690 						{
691 							((SdrHdlList&)rHdlList).SetFocusHdl(pNewOne);
692 						}
693 					}
694 
695 					bProc = sal_True;
696 				}
697 			}
698 		}
699 		break;
700 
701 		default:
702 		break;
703 	}
704 
705 	if ( !bProc )
706 		Control::KeyInput( rKEvt );
707 	else
708 		ReleaseMouse();
709 }
710 
711 
712 /*************************************************************************
713 |*
714 |*
715 |*
716 \************************************************************************/
717 
MouseButtonDown(const MouseEvent & rMEvt)718 void GraphCtrl::MouseButtonDown( const MouseEvent& rMEvt )
719 {
720 	if ( bSdrMode && ( rMEvt.GetClicks() < 2 ) )
721 	{
722 		const Point aLogPt( PixelToLogic( rMEvt.GetPosPixel() ) );
723 
724 		if ( !Rectangle( Point(), aGraphSize ).IsInside( aLogPt ) && !pView->IsEditMode() )
725 			Control::MouseButtonDown( rMEvt );
726 		else
727 		{
728 			// Focus anziehen fuer Key-Inputs
729 			GrabFocus();
730 
731 			if ( nPolyEdit )
732 			{
733 				SdrViewEvent	aVEvt;
734 				SdrHitKind		eHit = pView->PickAnything( rMEvt, SDRMOUSEBUTTONDOWN, aVEvt );
735 
736 				if ( nPolyEdit == SID_BEZIER_INSERT && eHit == SDRHIT_MARKEDOBJECT )
737 					pView->BegInsObjPoint( aLogPt, rMEvt.IsMod1());
738 				else
739 					pView->MouseButtonDown( rMEvt, this );
740 			}
741 			else
742 				pView->MouseButtonDown( rMEvt, this );
743 		}
744 
745 		SdrObject* pCreateObj = pView->GetCreateObj();
746 
747 		// Wir wollen das Inserten mitbekommen
748 		if ( pCreateObj && !pCreateObj->GetUserCall() )
749 			pCreateObj->SetUserCall( pUserCall );
750 
751 		SetPointer( pView->GetPreferedPointer( aLogPt, this ) );
752 	}
753 	else
754 		Control::MouseButtonDown( rMEvt );
755 }
756 
757 
758 /*************************************************************************
759 |*
760 |*
761 |*
762 \************************************************************************/
763 
MouseMove(const MouseEvent & rMEvt)764 void GraphCtrl::MouseMove(const MouseEvent& rMEvt)
765 {
766 	const Point	aLogPos( PixelToLogic( rMEvt.GetPosPixel() ) );
767 
768 	if ( bSdrMode )
769 	{
770 		pView->MouseMove( rMEvt, this );
771 
772 		if( ( SID_BEZIER_INSERT == nPolyEdit ) &&
773 			!pView->PickHandle( aLogPos ) &&
774 			!pView->IsInsObjPoint() )
775 		{
776 			SetPointer( POINTER_CROSS );
777 		}
778 		else
779 			SetPointer( pView->GetPreferedPointer( aLogPos, this ) );
780 	}
781 	else
782 		Control::MouseButtonUp( rMEvt );
783 
784 	if ( aMousePosLink.IsSet() )
785 	{
786 		if ( Rectangle( Point(), aGraphSize ).IsInside( aLogPos ) )
787 			aMousePos = aLogPos;
788 		else
789 			aMousePos = Point();
790 
791 		aMousePosLink.Call( this );
792 	}
793 }
794 
795 
796 /*************************************************************************
797 |*
798 |*
799 |*
800 \************************************************************************/
801 
MouseButtonUp(const MouseEvent & rMEvt)802 void GraphCtrl::MouseButtonUp(const MouseEvent& rMEvt)
803 {
804 	if ( bSdrMode )
805 	{
806 		if ( pView->IsInsObjPoint() )
807 			pView->EndInsObjPoint( SDRCREATE_FORCEEND );
808 		else
809 			pView->MouseButtonUp( rMEvt, this );
810 
811 		ReleaseMouse();
812 		SetPointer( pView->GetPreferedPointer( PixelToLogic( rMEvt.GetPosPixel() ), this ) );
813 	}
814 	else
815 		Control::MouseButtonUp( rMEvt );
816 }
817 
818 
819 /*************************************************************************
820 |*
821 |*
822 |*
823 \************************************************************************/
824 
GetSelectedSdrObject() const825 SdrObject* GraphCtrl::GetSelectedSdrObject() const
826 {
827 	SdrObject* pSdrObj = NULL;
828 
829 	if ( bSdrMode )
830 	{
831 		const SdrMarkList&	rMarkList = pView->GetMarkedObjectList();
832 
833 		if ( rMarkList.GetMarkCount() == 1 )
834 			pSdrObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
835 	}
836 
837 	return pSdrObj;
838 }
839 
840 
841 /*************************************************************************
842 |*
843 |*
844 |*
845 \************************************************************************/
846 
SetEditMode(const sal_Bool _bEditMode)847 void GraphCtrl::SetEditMode( const sal_Bool _bEditMode )
848 {
849 	if ( bSdrMode )
850 	{
851         bEditMode = _bEditMode;
852 		pView->SetEditMode( bEditMode );
853         eObjKind = OBJ_NONE;
854 		pView->SetCurrentObj( sal::static_int_cast< sal_uInt16 >( eObjKind ) );
855 	}
856 	else
857 		bEditMode = sal_False;
858 }
859 
860 
861 /*************************************************************************
862 |*
863 |*
864 |*
865 \************************************************************************/
866 
SetPolyEditMode(const sal_uInt16 _nPolyEdit)867 void GraphCtrl::SetPolyEditMode( const sal_uInt16 _nPolyEdit )
868 {
869 	if ( bSdrMode && ( _nPolyEdit != nPolyEdit ) )
870 	{
871 		nPolyEdit = _nPolyEdit;
872 		pView->SetFrameDragSingles( nPolyEdit == 0 );
873 	}
874 	else
875 		nPolyEdit = 0;
876 }
877 
878 
879 /*************************************************************************
880 |*
881 |*
882 |*
883 \************************************************************************/
884 
SetObjKind(const SdrObjKind _eObjKind)885 void GraphCtrl::SetObjKind( const SdrObjKind _eObjKind )
886 {
887 	if ( bSdrMode )
888 	{
889         bEditMode = sal_False;
890 		pView->SetEditMode( bEditMode );
891         eObjKind = _eObjKind;
892 		pView->SetCurrentObj( sal::static_int_cast< sal_uInt16 >( eObjKind ) );
893 	}
894 	else
895 		eObjKind = OBJ_NONE;
896 }
897 
898 
899 /*************************************************************************
900 |*
901 |*
902 |*
903 \************************************************************************/
904 
GetStringFromDouble(const double & rDouble)905 String GraphCtrl::GetStringFromDouble( const double& rDouble )
906 {
907     sal_Unicode cSep =
908         SvtSysLocale().GetLocaleData().getNumDecimalSep().GetChar(0);
909     String aStr( ::rtl::math::doubleToUString( rDouble,
910                 rtl_math_StringFormat_F, 2, cSep ));
911     return aStr;
912 }
913 
914 
915 /*************************************************************************
916 www|*
917 |*
918 |*
919 \************************************************************************/
920 
IMPL_LINK(GraphCtrl,UpdateHdl,Timer *,pTimer)921 IMPL_LINK( GraphCtrl, UpdateHdl, Timer*, pTimer )
922 {
923 	if ( aUpdateLink.IsSet() )
924 		aUpdateLink.Call( this );
925 
926 	pTimer->Start();
927 
928 	return 0L;
929 }
930 
931 
CreateAccessible()932 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > GraphCtrl::CreateAccessible()
933 {
934 	if( mpAccContext == NULL )
935 	{
936 		Window* pParent = GetParent();
937 
938 		DBG_ASSERT( pParent, "-GraphCtrl::CreateAccessible(): No Parent!" );
939 
940 		if( pParent )
941 		{
942 			::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccParent( pParent->GetAccessible() );
943 
944             // #103856# Disable accessibility if no model/view data available
945 			if( pView &&
946                 pModel &&
947                 xAccParent.is() )
948 			{
949 				mpAccContext = new SvxGraphCtrlAccessibleContext( xAccParent, *this );
950 				mpAccContext->acquire();
951 			}
952 		}
953 	}
954 
955 	return mpAccContext;
956 }
957