xref: /aoo41x/main/sd/source/ui/view/sdwindow.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "Window.hxx"
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/request.hxx>
34 
35 #include <sfx2/viewfrm.hxx>
36 #include <svx/svxids.hrc>
37 
38 #include <editeng/outliner.hxx>
39 #include <editeng/editview.hxx>
40 
41 #include "app.hrc"
42 #include "helpids.h"
43 #include "ViewShell.hxx"
44 #include "DrawViewShell.hxx"
45 #include "View.hxx"
46 #include "FrameView.hxx"
47 #include "OutlineViewShell.hxx"
48 #include "drawdoc.hxx"
49 #include "AccessibleDrawDocumentView.hxx"
50 #include "WindowUpdater.hxx"
51 
52 namespace sd {
53 
54 #define SCROLL_LINE_FACT   0.05     // Faktor fuer Zeilenscrolling
55 #define SCROLL_PAGE_FACT   0.5      // Faktor fuer Seitenscrolling
56 #define SCROLL_SENSITIVE   20       // Sensitiver Bereich (Pixel)
57 #define ZOOM_MULTIPLICATOR 10000    // Multiplikator um Rundungsfehler zu vermeiden
58 #define MIN_ZOOM	       5        // Minimaler Zoomfaktor
59 #define MAX_ZOOM	       3000	    // Maximaler Zoomfaktor
60 
61 
62 /*************************************************************************
63 |*
64 |* Konstruktor
65 |*
66 \************************************************************************/
67 
68 Window::Window(::Window* pParent)
69     : ::Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
70 	  DropTargetHelper( this ),
71       mpShareWin(NULL),
72       maWinPos(0, 0),			// vorsichtshalber; die Werte sollten aber
73       maViewOrigin(0, 0),		// vom Besitzer des Fensters neu gesetzt
74       maViewSize(1000, 1000),	// werden
75       mnMinZoom(MIN_ZOOM),
76       mnMaxZoom(MAX_ZOOM),
77 	  mbMinZoomAutoCalc(false),
78       mbCalcMinZoomByMinSide(true),
79       mbCenterAllowed(true),
80       mnTicks (0),
81       mbDraggedFrom(false),
82       mpViewShell(NULL),
83       mbUseDropScroll (true)
84 {
85 	SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
86 
87 	MapMode aMap(GetMapMode());
88 	aMap.SetMapUnit(MAP_100TH_MM);
89 	SetMapMode(aMap);
90 
91 	// Damit im Diamodus die ::WindowColor genommen wird
92 	SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
93 
94 	// adjust contrast mode initially
95 	bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
96     SetDrawMode( bUseContrast
97         ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
98         : ViewShell::OUTPUT_DRAWMODE_COLOR );
99 
100 	// Hilfe-ID setzen
101 	// SetHelpId(HID_SD_WIN_DOCUMENT);
102 	SetUniqueId(HID_SD_WIN_DOCUMENT);
103 
104 	// #i78183# Added after discussed with AF
105 	EnableRTL(sal_False);
106 }
107 
108 /*************************************************************************
109 |*
110 |* Destruktor
111 |*
112 \************************************************************************/
113 
114 Window::~Window (void)
115 {
116     if (mpViewShell != NULL)
117     {
118         WindowUpdater* pWindowUpdater = mpViewShell->GetWindowUpdater();
119         if (pWindowUpdater != NULL)
120             pWindowUpdater->UnregisterWindow (this);
121     }
122 }
123 
124 
125 
126 
127 void Window::SetViewShell (ViewShell* pViewSh)
128 {
129     WindowUpdater* pWindowUpdater = NULL;
130     // Unregister at device updater of old view shell.
131     if (mpViewShell != NULL)
132     {
133         pWindowUpdater = mpViewShell->GetWindowUpdater();
134         if (pWindowUpdater != NULL)
135             pWindowUpdater->UnregisterWindow (this);
136     }
137 
138     mpViewShell = pViewSh;
139 
140     // Register at device updater of new view shell
141     if (mpViewShell != NULL)
142     {
143         pWindowUpdater = mpViewShell->GetWindowUpdater();
144         if (pWindowUpdater != NULL)
145             pWindowUpdater->RegisterWindow (this);
146     }
147 }
148 
149 void Window::CalcMinZoom()
150 {
151     // Are we entitled to change the minimal zoom factor?
152 	if ( mbMinZoomAutoCalc )
153 	{
154         // Get current zoom factor.
155 		long nZoom = GetZoom();
156 
157 		if ( mpShareWin )
158 		{
159 			mpShareWin->CalcMinZoom();
160 			mnMinZoom = mpShareWin->mnMinZoom;
161 		}
162 		else
163 		{
164             // Get the rectangle of the output area in logical coordinates
165             // and calculate the scaling factors that would lead to the view
166             // area (also called application area) to completely fill the
167             // window.
168 			Size aWinSize = PixelToLogic(GetOutputSizePixel());
169 			sal_uLong nX = (sal_uLong) ((double) aWinSize.Width()
170                 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Width());
171 			sal_uLong nY = (sal_uLong) ((double) aWinSize.Height()
172                 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Height());
173 
174             // Decide whether to take the larger or the smaller factor.
175 			sal_uLong nFact;
176 			if (mbCalcMinZoomByMinSide)
177                 nFact = Min(nX, nY);
178 			else
179                 nFact = Max(nX, nY);
180 
181             // The factor is tansfomed according to the current zoom factor.
182 			nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
183 			mnMinZoom = Max((sal_uInt16) MIN_ZOOM, (sal_uInt16) nFact);
184 		}
185         // If the current zoom factor is smaller than the calculated minimal
186         // zoom factor then set the new minimal factor as the current zoom
187         // factor.
188 		if ( nZoom < (long) mnMinZoom )
189 			SetZoomFactor(mnMinZoom);
190 	}
191 }
192 
193 
194 
195 
196 void Window::SetMinZoom (long int nMin)
197 {
198     mnMinZoom = (sal_uInt16) nMin;
199 }
200 
201 
202 
203 
204 long Window::GetMinZoom (void) const
205 {
206     return mnMinZoom;
207 }
208 
209 
210 
211 
212 void Window::SetMaxZoom (long int nMax)
213 {
214     mnMaxZoom = (sal_uInt16) nMax;
215 }
216 
217 
218 
219 
220 long Window::GetMaxZoom (void) const
221 {
222     return mnMaxZoom;
223 }
224 
225 
226 
227 
228 long Window::GetZoom (void) const
229 {
230 	if( GetMapMode().GetScaleX().GetDenominator() )
231 	{
232 		return GetMapMode().GetScaleX().GetNumerator() * 100L
233 			/ GetMapMode().GetScaleX().GetDenominator();
234 	}
235 	else
236 	{
237 		return 0;
238 	}
239 }
240 
241 
242 
243 
244 /*************************************************************************
245 |*
246 |* Resize event
247 |*
248 \************************************************************************/
249 
250 void Window::Resize()
251 {
252 	::Window::Resize();
253 	CalcMinZoom();
254 
255     if( mpViewShell && mpViewShell->GetViewFrame() )
256         mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
257 }
258 
259 /*************************************************************************
260 |*
261 |* PrePaint event
262 |*
263 \************************************************************************/
264 
265 void Window::PrePaint()
266 {
267 	if ( mpViewShell )
268 		mpViewShell->PrePaint();
269 }
270 
271 /*************************************************************************
272 |*
273 |* Paint event
274 |*
275 \************************************************************************/
276 
277 void Window::Paint(const Rectangle& rRect)
278 {
279 	if ( mpViewShell )
280 		mpViewShell->Paint(rRect, this);
281 }
282 
283 /*************************************************************************
284 |*
285 |* Keyboard event
286 |*
287 \************************************************************************/
288 
289 void Window::KeyInput(const KeyEvent& rKEvt)
290 {
291 	if (!(mpViewShell && mpViewShell->KeyInput(rKEvt, this)))
292 	{
293 		if (mpViewShell && rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
294 		{
295             mpViewShell->GetViewShell()->Escape();
296 		}
297 		else
298 		{
299 			::Window::KeyInput(rKEvt);
300 		}
301 	}
302 }
303 
304 /*************************************************************************
305 |*
306 |* MouseButtonDown event
307 |*
308 \************************************************************************/
309 
310 void Window::MouseButtonDown(const MouseEvent& rMEvt)
311 {
312 	if ( mpViewShell )
313 		mpViewShell->MouseButtonDown(rMEvt, this);
314 }
315 
316 /*************************************************************************
317 |*
318 |* MouseMove event
319 |*
320 \************************************************************************/
321 
322 void Window::MouseMove(const MouseEvent& rMEvt)
323 {
324 	if ( mpViewShell )
325 		mpViewShell->MouseMove(rMEvt, this);
326 }
327 
328 /*************************************************************************
329 |*
330 |* MouseButtonUp event
331 |*
332 \************************************************************************/
333 
334 void Window::MouseButtonUp(const MouseEvent& rMEvt)
335 {
336 	mnTicks = 0;
337 
338 	if ( mpViewShell )
339 		mpViewShell->MouseButtonUp(rMEvt, this);
340 }
341 
342 /*************************************************************************
343 |*
344 |* Command event
345 |*
346 \************************************************************************/
347 
348 void Window::Command(const CommandEvent& rCEvt)
349 {
350 	if ( mpViewShell )
351 		mpViewShell->Command(rCEvt, this);
352 }
353 
354 long Window::Notify( NotifyEvent& rNEvt )
355 {
356     long nResult = sal_False;
357     if ( mpViewShell )
358     {
359         nResult = mpViewShell->Notify(rNEvt, this);
360     }
361     if( !nResult )
362         nResult = ::Window::Notify( rNEvt );
363 
364     return nResult;
365 }
366 
367 
368 /*************************************************************************
369 |*
370 |* RequestHelp event
371 |*
372 \************************************************************************/
373 
374 void Window::RequestHelp(const HelpEvent& rEvt)
375 {
376 	if ( mpViewShell )
377 	{
378 		if( !mpViewShell->RequestHelp( rEvt, this) )
379 			::Window::RequestHelp( rEvt );
380 	}
381 	else
382 		::Window::RequestHelp( rEvt );
383 }
384 
385 
386 
387 
388 Point Window::GetWinViewPos (void) const
389 {
390     return maWinPos;
391 }
392 
393 
394 
395 
396 Point Window::GetViewOrigin (void) const
397 {
398     return maViewOrigin;
399 }
400 
401 
402 
403 
404 Size Window::GetViewSize (void) const
405 {
406     return maViewSize;
407 }
408 
409 
410 
411 
412 /*************************************************************************
413 |*
414 |* Position der linken oberen Ecke des im Fenster sichtbaren Bereichs
415 |* setzen
416 |*
417 \************************************************************************/
418 
419 void Window::SetWinViewPos(const Point& rPnt)
420 {
421 	maWinPos = rPnt;
422 }
423 
424 /*************************************************************************
425 |*
426 |* Ursprung der Darstellung in Bezug zur gesamten Arbeitsflaeche setzen
427 |*
428 \************************************************************************/
429 
430 void Window::SetViewOrigin(const Point& rPnt)
431 {
432 	maViewOrigin = rPnt;
433 }
434 
435 /*************************************************************************
436 |*
437 |* Groesse der gesamten Arbeitsflaeche, die mit dem Fenster betrachtet
438 |* werden kann, setzen
439 |*
440 \************************************************************************/
441 
442 void Window::SetViewSize(const Size& rSize)
443 {
444 	maViewSize = rSize;
445 	CalcMinZoom();
446 }
447 
448 
449 
450 
451 void Window::SetCenterAllowed (bool bIsAllowed)
452 {
453     mbCenterAllowed = bIsAllowed;
454 }
455 
456 
457 
458 
459 long Window::SetZoomFactor(long nZoom)
460 {
461     // Clip the zoom factor to the valid range marked by nMinZoom as
462     // calculated by CalcMinZoom() and the constant MAX_ZOOM.
463 	if ( nZoom > MAX_ZOOM )
464         nZoom = MAX_ZOOM;
465 	if ( nZoom < (long) mnMinZoom )
466         nZoom = mnMinZoom;
467 
468     // Set the zoom factor at the window's map mode.
469 	MapMode aMap(GetMapMode());
470 	aMap.SetScaleX(Fraction(nZoom, 100));
471 	aMap.SetScaleY(Fraction(nZoom, 100));
472 	SetMapMode(aMap);
473 
474     // Update the map mode's origin (to what effect?).
475 	UpdateMapOrigin();
476 
477     // Update the view's snapping to the the new zoom factor.
478 	if ( mpViewShell && mpViewShell->ISA(DrawViewShell) )
479 		((DrawViewShell*) mpViewShell)->GetView()->
480 										RecalcLogicSnapMagnetic(*this);
481 
482     // Return the zoom factor just in case it has been changed above to lie
483     // inside the valid range.
484 	return nZoom;
485 }
486 
487 void Window::SetZoomIntegral(long nZoom)
488 {
489     // Clip the zoom factor to the valid range marked by nMinZoom as
490     // previously calculated by <member>CalcMinZoom()</member> and the
491     // MAX_ZOOM constant.
492 	if ( nZoom > MAX_ZOOM )
493         nZoom = MAX_ZOOM;
494 	if ( nZoom < (long) mnMinZoom )
495         nZoom = mnMinZoom;
496 
497     // Calculate the window's new origin.
498 	Size aSize = PixelToLogic(GetOutputSizePixel());
499 	long nW = aSize.Width()  * GetZoom() / nZoom;
500 	long nH = aSize.Height() * GetZoom() / nZoom;
501 	maWinPos.X() += (aSize.Width()  - nW) / 2;
502 	maWinPos.Y() += (aSize.Height() - nH) / 2;
503 	if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
504 	if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
505 
506     // Finally update this window's map mode to the given zoom factor that
507     // has been clipped to the valid range.
508 	SetZoomFactor(nZoom);
509 }
510 
511 long Window::GetZoomForRect( const Rectangle& rZoomRect )
512 {
513 	long nRetZoom = 100;
514 
515     if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
516     {
517         // Calculate the scale factors which will lead to the given
518         // rectangle being fully visible (when translated accordingly) as
519         // large as possible in the output area independently in both
520         // coordinate directions .
521 		sal_uLong nX(0L);
522 		sal_uLong nY(0L);
523 
524         const Size aWinSize( PixelToLogic(GetOutputSizePixel()) );
525 		if(rZoomRect.GetHeight())
526 		{
527 			nX = (sal_uLong) ((double) aWinSize.Height()
528 			   * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
529 		}
530 
531 		if(rZoomRect.GetWidth())
532 		{
533 			nY = (sal_uLong) ((double) aWinSize.Width()
534 				* (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
535 		}
536 
537         // Use the smaller one of both so that the zoom rectangle will be
538         // fully visible with respect to both coordinate directions.
539 		sal_uLong nFact = Min(nX, nY);
540 
541         // Transform the current zoom factor so that it leads to the desired
542         // scaling.
543 		nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
544 
545         // Calculate the new origin.
546 		if ( nFact == 0 )
547 		{
548             // Don't change anything if the scale factor is degenrate.
549 			nRetZoom = GetZoom();
550 		}
551 		else
552 		{
553             // Clip the zoom factor to the valid range marked by nMinZoom as
554             // previously calculated by <member>CalcMinZoom()</member> and the
555             // MAX_ZOOM constant.
556 	        if ( nRetZoom > MAX_ZOOM )
557                 nRetZoom = MAX_ZOOM;
558 	        if ( nRetZoom < (long) mnMinZoom )
559                 nRetZoom = mnMinZoom;
560        }
561     }
562 
563     return nRetZoom;
564 }
565 
566 /** Recalculate the zoom factor and translation so that the given rectangle
567     is displayed centered and as large as possible while still being fully
568     visible in the window.
569 */
570 long Window::SetZoomRect (const Rectangle& rZoomRect)
571 {
572 	long nNewZoom = 100;
573 
574 	if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
575 	{
576         // The given rectangle is degenerate.  Use the default zoom factor
577         // (above) of 100%.
578 		SetZoomIntegral(nNewZoom);
579 	}
580 	else
581 	{
582 		Point aPos = rZoomRect.TopLeft();
583         // Transform the output area from pixel coordinates into logical
584         // coordinates.
585 		Size aWinSize = PixelToLogic(GetOutputSizePixel());
586         // Paranoia!  The degenerate case of zero width or height has been
587         // taken care of above.
588 		DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Breite = 0!");
589 		DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Hoehe = 0!");
590 
591         // Calculate the scale factors which will lead to the given
592         // rectangle being fully visible (when translated accordingly) as
593         // large as possible in the output area independently in both
594         // coordinate directions .
595 		sal_uLong nX(0L);
596 		sal_uLong nY(0L);
597 
598 		if(rZoomRect.GetHeight())
599 		{
600 			nX = (sal_uLong) ((double) aWinSize.Height()
601 			   * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
602 		}
603 
604 		if(rZoomRect.GetWidth())
605 		{
606 			nY = (sal_uLong) ((double) aWinSize.Width()
607 				* (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
608 		}
609 
610         // Use the smaller one of both so that the zoom rectangle will be
611         // fully visible with respect to both coordinate directions.
612 		sal_uLong nFact = Min(nX, nY);
613 
614         // Transform the current zoom factor so that it leads to the desired
615         // scaling.
616 		long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
617 
618         // Calculate the new origin.
619 		if ( nFact == 0 )
620 		{
621             // Don't change anything if the scale factor is degenrate.
622 			nNewZoom = GetZoom();
623 		}
624 		else
625 		{
626             // Calculate the new window position that centers the given
627             // rectangle on the screen.
628 			if ( nZoom > MAX_ZOOM )
629 				nFact = nFact * MAX_ZOOM / nZoom;
630 
631 			maWinPos = maViewOrigin + aPos;
632 
633 			aWinSize.Width() = (long) ((double) aWinSize.Width() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
634 			maWinPos.X() += (rZoomRect.GetWidth() - aWinSize.Width()) / 2;
635 			aWinSize.Height() = (long) ((double) aWinSize.Height() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
636 			maWinPos.Y() += (rZoomRect.GetHeight() - aWinSize.Height()) / 2;
637 
638 			if ( maWinPos.X() < 0 )	maWinPos.X() = 0;
639 			if ( maWinPos.Y() < 0 )	maWinPos.Y() = 0;
640 
641             // Adapt the window's map mode to the new zoom factor.
642 			nNewZoom = SetZoomFactor(nZoom);
643 		}
644 	}
645 
646 	return(nNewZoom);
647 }
648 
649 
650 
651 
652 void Window::SetMinZoomAutoCalc (bool bAuto)
653 {
654     mbMinZoomAutoCalc = bAuto;
655 }
656 
657 
658 
659 
660 /*************************************************************************
661 |*
662 |* Neuen MapMode-Origin berechnen und setzen; wenn aWinPos.X()/Y()
663 |* gleich -1 ist, wird die entsprechende Position zentriert
664 |* (z.B. fuer Initialisierung)
665 |*
666 \************************************************************************/
667 
668 void Window::UpdateMapOrigin(sal_Bool bInvalidate)
669 {
670 	sal_Bool	bChanged = sal_False;
671 	Size	aWinSize = PixelToLogic(GetOutputSizePixel());
672 
673 	if ( mbCenterAllowed )
674 	{
675 		if ( maWinPos.X() > maViewSize.Width() - aWinSize.Width() )
676 		{
677 			maWinPos.X() = maViewSize.Width() - aWinSize.Width();
678 			bChanged = sal_True;
679 		}
680 		if ( maWinPos.Y() > maViewSize.Height() - aWinSize.Height() )
681 		{
682 			maWinPos.Y() = maViewSize.Height() - aWinSize.Height();
683 			bChanged = sal_True;
684 		}
685 		if ( aWinSize.Width() > maViewSize.Width() || maWinPos.X() < 0 )
686 		{
687 			maWinPos.X() = maViewSize.Width()  / 2 - aWinSize.Width()  / 2;
688 			bChanged = sal_True;
689 		}
690 		if ( aWinSize.Height() > maViewSize.Height() || maWinPos.Y() < 0 )
691 		{
692 			maWinPos.Y() = maViewSize.Height() / 2 - aWinSize.Height() / 2;
693 			bChanged = sal_True;
694 		}
695     }
696 
697     UpdateMapMode ();
698 
699     if (bChanged && bInvalidate)
700         Invalidate();
701 }
702 
703 
704 
705 
706 void Window::UpdateMapMode (void)
707 {
708 	Size aWinSize = PixelToLogic(GetOutputSizePixel());
709     maWinPos -= maViewOrigin;
710     Size aPix(maWinPos.X(), maWinPos.Y());
711     aPix = LogicToPixel(aPix);
712     // Groesse muss vielfaches von BRUSH_SIZE sein, damit Muster
713     // richtig dargestellt werden
714     // #i2237#
715     // removed old stuff here which still forced zoom to be
716     // %BRUSH_SIZE which is outdated now
717 
718     if (mpViewShell && mpViewShell->ISA(DrawViewShell))
719     {
720         Size aViewSizePixel = LogicToPixel(maViewSize);
721         Size aWinSizePixel = LogicToPixel(aWinSize);
722 
723         // Seite soll nicht am Fensterrand "kleben"
724         if (aPix.Width() == 0)
725         {
726             // #i2237#
727             // Since BRUSH_SIZE alignment is outdated now, i use the
728             // former constant here directly
729             aPix.Width() -= 8;
730         }
731         if (aPix.Height() == 0)
732         {
733             // #i2237#
734             // Since BRUSH_SIZE alignment is outdated now, i use the
735             // former constant here directly
736             aPix.Height() -= 8;
737         }
738     }
739 
740     aPix = PixelToLogic(aPix);
741     maWinPos.X() = aPix.Width();
742     maWinPos.Y() = aPix.Height();
743 	Point aNewOrigin (-maWinPos.X(), -maWinPos.Y());
744     maWinPos += maViewOrigin;
745 
746 	MapMode aMap(GetMapMode());
747     aMap.SetOrigin(aNewOrigin);
748     SetMapMode(aMap);
749 }
750 
751 
752 
753 
754 /*************************************************************************
755 |*
756 |* X-Position des sichtbaren Bereichs als Bruchteil (< 1)
757 |* der gesamten Arbeitsbereichbreite zuruegeben
758 |*
759 \************************************************************************/
760 
761 double Window::GetVisibleX()
762 {
763 	return ((double) maWinPos.X() / maViewSize.Width());
764 }
765 
766 /*************************************************************************
767 |*
768 |* Y-Position des sichtbaren Bereichs als Bruchteil (< 1)
769 |* der gesamten Arbeitsbereichhoehe zuruegeben
770 |*
771 \************************************************************************/
772 
773 double Window::GetVisibleY()
774 {
775 	return ((double) maWinPos.Y() / maViewSize.Height());
776 }
777 
778 /*************************************************************************
779 |*
780 |* X- und Y-Position des sichtbaren Bereichs als Bruchteile (< 1)
781 |* der gesamten Arbeitsbereichgroesse setzen
782 |* negative Werte werden ignoriert
783 |*
784 \************************************************************************/
785 
786 void Window::SetVisibleXY(double fX, double fY)
787 {
788 	long nOldX = maWinPos.X();
789 	long nOldY = maWinPos.Y();
790 
791 	if ( fX >= 0 )
792 		maWinPos.X() = (long) (fX * maViewSize.Width());
793 	if ( fY >= 0 )
794 		maWinPos.Y() = (long) (fY * maViewSize.Height());
795 	UpdateMapOrigin(sal_False);
796     //	Size sz(nOldX - aWinPos.X(), nOldY - aWinPos.Y());
797     //	sz = LogicToPixel(sz);
798 	Scroll(nOldX - maWinPos.X(), nOldY - maWinPos.Y(), SCROLL_CHILDREN);
799 	Update();
800 }
801 
802 /*************************************************************************
803 |*
804 |* Breite des sichtbaren Bereichs im Verhaeltnis zur
805 |* gesamten Arbeitsbereichbreite zuruegeben
806 |*
807 \************************************************************************/
808 
809 double Window::GetVisibleWidth()
810 {
811 	Size aWinSize = PixelToLogic(GetOutputSizePixel());
812 	if ( aWinSize.Width() > maViewSize.Width() )
813 		aWinSize.Width() = maViewSize.Width();
814 	return ((double) aWinSize.Width() / maViewSize.Width());
815 }
816 
817 /*************************************************************************
818 |*
819 |* Hoehe des sichtbaren Bereichs im Verhaeltnis zur
820 |* gesamten Arbeitsbereichhoehe zuruegeben
821 |*
822 \************************************************************************/
823 
824 double Window::GetVisibleHeight()
825 {
826 	Size aWinSize = PixelToLogic(GetOutputSizePixel());
827 	if ( aWinSize.Height() > maViewSize.Height() )
828 		aWinSize.Height() = maViewSize.Height();
829 	return ((double) aWinSize.Height() / maViewSize.Height());
830 }
831 
832 /*************************************************************************
833 |*
834 |* Breite einer Scrollspalte im Verhaeltnis zur gesamten
835 |* Arbeitsbereichbreite zuruegeben
836 |*
837 \************************************************************************/
838 
839 double Window::GetScrlLineWidth()
840 {
841 	return (GetVisibleWidth() * SCROLL_LINE_FACT);
842 }
843 
844 /*************************************************************************
845 |*
846 |* Breite einer Scrollspalte im Verhaeltnis zur gesamten
847 |* Arbeitsbereichhoehe zuruegeben
848 |*
849 \************************************************************************/
850 
851 double Window::GetScrlLineHeight()
852 {
853 	return (GetVisibleHeight() * SCROLL_LINE_FACT);
854 }
855 
856 /*************************************************************************
857 |*
858 |* Breite einer Scrollpage im Verhaeltnis zur gesamten
859 |* Arbeitsbereichbreite zuruegeben
860 |*
861 \************************************************************************/
862 
863 double Window::GetScrlPageWidth()
864 {
865 	return (GetVisibleWidth() * SCROLL_PAGE_FACT);
866 }
867 
868 /*************************************************************************
869 |*
870 |* Breite einer Scrollpage im Verhaeltnis zur gesamten
871 |* Arbeitsbereichhoehe zuruegeben
872 |*
873 \************************************************************************/
874 
875 double Window::GetScrlPageHeight()
876 {
877 	return (GetVisibleHeight() * SCROLL_PAGE_FACT);
878 }
879 
880 /*************************************************************************
881 |*
882 |* Fenster deaktivieren
883 |*
884 \************************************************************************/
885 
886 void Window::LoseFocus()
887 {
888 	mnTicks = 0;
889     ::Window::LoseFocus ();
890 }
891 
892 /*************************************************************************
893 |*
894 |* Fenster aktivieren
895 |*
896 \************************************************************************/
897 
898 void Window::GrabFocus()
899 {
900 	mnTicks		 = 0;
901     ::Window::GrabFocus ();
902 }
903 
904 
905 /*************************************************************************
906 |*
907 |* DataChanged
908 |*
909 \************************************************************************/
910 
911 void Window::DataChanged( const DataChangedEvent& rDCEvt )
912 {
913 	::Window::DataChanged( rDCEvt );
914 
915 	// PRINTER bei allen Dokumenten weglassen, die keinen Printer benutzen.
916 	// FONTS und FONTSUBSTITUTION weglassen, wenn keine Textausgaben
917 	// vorhanden sind, bzw. wenn das Dokument keinen Text zulaesst.
918 
919 	if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
920 		 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
921 		 (rDCEvt.GetType() == DATACHANGED_FONTS) ||
922 		 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
923 		 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
924 		  (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
925 	{
926 		if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
927 			 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
928 		{
929             // When the screen zoom factor has changed then reset the zoom
930             // factor of the frame to allways display the whole page.
931             const AllSettings* pOldSettings = rDCEvt.GetOldSettings ();
932             const AllSettings& rNewSettings = GetSettings ();
933             if (pOldSettings)
934                 if (pOldSettings->GetStyleSettings().GetScreenZoom()
935                     != rNewSettings.GetStyleSettings().GetScreenZoom())
936                     mpViewShell->GetViewFrame()->GetDispatcher()->
937                         Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
938 
939 			// ScrollBars neu anordnen bzw. Resize ausloesen, da sich
940 			// ScrollBar-Groesse geaendert haben kann. Dazu muss dann im
941 			// Resize-Handler aber auch die Groesse der ScrollBars aus
942 			// den Settings abgefragt werden.
943 			Resize();
944 
945 			// Daten neu Setzen, die aus den Systemeinstellungen bzw. aus
946 			// den Settings uebernommen werden. Evtl. weitere Daten neu
947 			// berechnen, da sich auch die Aufloesung hierdurch geaendert
948 			// haben kann.
949             if( mpViewShell )
950             {
951 				const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
952 				SvtAccessibilityOptions aAccOptions;
953 		        sal_uLong                   nOutputMode;
954 			    sal_uInt16                  nPreviewSlot;
955 
956 				if( rStyleSettings.GetHighContrastMode() )
957 					nOutputMode = ViewShell::OUTPUT_DRAWMODE_CONTRAST;
958 				else
959 					nOutputMode = ViewShell::OUTPUT_DRAWMODE_COLOR;
960 
961 				if( rStyleSettings.GetHighContrastMode() && aAccOptions.GetIsForPagePreviews() )
962 					nPreviewSlot = SID_PREVIEW_QUALITY_CONTRAST;
963 				else
964 					nPreviewSlot = SID_PREVIEW_QUALITY_COLOR;
965 
966                 if( mpViewShell->ISA( DrawViewShell ) )
967                 {
968 			        SetDrawMode( nOutputMode );
969                     mpViewShell->GetFrameView()->SetDrawMode( nOutputMode );
970 // #110094#-7
971 //			        mpViewShell->GetView()->ReleaseMasterPagePaintCache();
972 			        Invalidate();
973                 }
974 
975                 // #103100# Overwrite window color for OutlineView
976                 if( mpViewShell->ISA(OutlineViewShell ) )
977                 {
978                     svtools::ColorConfig aColorConfig;
979                     const Color aDocColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
980 					SetBackground( Wallpaper( aDocColor ) );
981                 }
982 
983                 SfxRequest aReq( nPreviewSlot, 0, mpViewShell->GetDocSh()->GetDoc()->GetItemPool() );
984                 mpViewShell->ExecReq( aReq );
985 				mpViewShell->Invalidate();
986                 mpViewShell->ArrangeGUIElements();
987 
988 				// #101928# re-create handles to show new outfit
989 				if(mpViewShell->ISA(DrawViewShell))
990 				{
991 					mpViewShell->GetView()->AdjustMarkHdl();
992 				}
993             }
994         }
995 
996 		if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
997 			 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
998 			  (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
999 		{
1000 			// Virtuelle Device die auch von der Aufloesung oder von
1001 			// Systemeinstellungen abhaengen, sollten geupdatet werden.
1002 			// Ansonsten sollte zumindest bei DATACHANGED_DISPLAY
1003 			// die virtuellen Devices geupdatet werden, da es einige
1004 			// Systeme erlauben die Aufloesung und Farbtiefe waehrend
1005 			// der Laufzeit zu aendern oder eben bei Palettenaenderungen
1006 			// die virtuellen Device geupdatet werden muessen, da bei
1007 			// Ausgaben ein anderes Farbmatching stattfinden kann.
1008 		}
1009 
1010 		if ( rDCEvt.GetType() == DATACHANGED_FONTS )
1011 		{
1012 			// Wenn das Dokument Font-AuswahlBoxen anbietet, muessen
1013 			// diese geupdatet werden. Wie dies genau aussehen muss,
1014 			// weiss ich leider auch nicht. Aber evtl. kann man das
1015 			// ja global handeln. Dies muessten wir evtl. mal
1016 			// mit PB absprechen, aber der ist derzeit leider Krank.
1017 			// Also bevor dies hier gehandelt wird, vorher mit
1018 			// PB und mir absprechen.
1019 		}
1020 
1021 		if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1022 			 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) )
1023 		{
1024 			// Formatierung neu durchfuehren, da Fonts die im Dokument
1025 			// vorkommen, nicht mehr vorhanden sein muessen oder
1026 			// jetzt vorhanden sind oder durch andere ersetzt wurden
1027 			// sind.
1028 			if( mpViewShell )
1029 			{
1030 				DrawDocShell* pDocSh = mpViewShell->GetDocSh();
1031 				if( pDocSh )
1032 					pDocSh->SetPrinter( pDocSh->GetPrinter( sal_True ) );
1033 			}
1034 		}
1035 
1036 		if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
1037 		{
1038 			// Wie hier die Behandlung aussehen soll, weiss ich leider
1039 			// selbst noch nicht. Evtl. mal einen Printer loeschen und
1040 			// schauen was gemacht werden muss. Evtl. muesste ich in
1041 			// VCL dafuer noch etwas einbauen, wenn der benutze Printer
1042 			// geloescht wird. Ansonsten wuerde ich hier evtl. die
1043 			// Formatierung neu berechnen, wenn der aktuelle Drucker
1044 			// zerstoert wurde.
1045 			if( mpViewShell )
1046 			{
1047 				DrawDocShell* pDocSh = mpViewShell->GetDocSh();
1048 				if( pDocSh )
1049 					pDocSh->SetPrinter( pDocSh->GetPrinter( sal_True ) );
1050 			}
1051 		}
1052 
1053 		// Alles neu ausgeben
1054 		Invalidate();
1055 	}
1056 }
1057 
1058 
1059 
1060 
1061 /*************************************************************************
1062 |*
1063 |* DropTargetHelper::AcceptDrop
1064 |*
1065 \************************************************************************/
1066 
1067 sal_Int8 Window::AcceptDrop( const AcceptDropEvent& rEvt )
1068 {
1069 	sal_Int8 nRet = DND_ACTION_NONE;
1070 
1071 	if( mpViewShell && !mpViewShell->GetDocSh()->IsReadOnly() )
1072 	{
1073 		if( mpViewShell )
1074 			nRet = mpViewShell->AcceptDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
1075 
1076 		if (mbUseDropScroll && ! mpViewShell->ISA(OutlineViewShell))
1077 			DropScroll( rEvt.maPosPixel );
1078 	}
1079 
1080 	return nRet;
1081 }
1082 
1083 /*************************************************************************
1084 |*
1085 |* DropTargetHelper::ExecuteDrop
1086 |*
1087 \************************************************************************/
1088 
1089 sal_Int8 Window::ExecuteDrop( const ExecuteDropEvent& rEvt )
1090 {
1091 	sal_Int8 nRet = DND_ACTION_NONE;
1092 
1093 	if( mpViewShell )
1094 	{
1095 		nRet = mpViewShell->ExecuteDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
1096 	}
1097 
1098 	return nRet;
1099 }
1100 
1101 
1102 
1103 
1104 void Window::SetUseDropScroll (bool bUseDropScroll)
1105 {
1106     mbUseDropScroll = bUseDropScroll;
1107 }
1108 
1109 
1110 
1111 
1112 /*************************************************************************
1113 |*
1114 |* Scrolling bei AcceptDrop-Events
1115 |*
1116 \************************************************************************/
1117 
1118 void Window::DropScroll(const Point& rMousePos)
1119 {
1120 	short nDx = 0;
1121 	short nDy = 0;
1122 
1123 	Size aSize = GetOutputSizePixel();
1124 
1125 	if (aSize.Width() > SCROLL_SENSITIVE * 3)
1126 	{
1127 		if ( rMousePos.X() < SCROLL_SENSITIVE )
1128 		{
1129 			nDx = -1;
1130 		}
1131 
1132 		if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE )
1133 		{
1134 			nDx = 1;
1135 		}
1136 	}
1137 
1138 	if (aSize.Height() > SCROLL_SENSITIVE * 3)
1139 	{
1140 		if ( rMousePos.Y() < SCROLL_SENSITIVE )
1141 		{
1142 			nDy = -1;
1143 		}
1144 
1145 		if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE )
1146 		{
1147 			nDy = 1;
1148 		}
1149 	}
1150 
1151 	if ( (nDx || nDy) && (rMousePos.X()!=0 || rMousePos.Y()!=0 ) )
1152 	{
1153         if (mnTicks > 20)
1154             mpViewShell->ScrollLines(nDx, nDy);
1155 		else
1156             mnTicks ++;
1157 	}
1158 }
1159 
1160 
1161 
1162 
1163 ::com::sun::star::uno::Reference<
1164     ::com::sun::star::accessibility::XAccessible>
1165     Window::CreateAccessible (void)
1166 {
1167     if (mpViewShell != NULL)
1168         return mpViewShell->CreateAccessibleDocumentView (this);
1169     else
1170     {
1171         OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
1172         return ::Window::CreateAccessible ();
1173     }
1174 }
1175 
1176 XubString Window::GetSurroundingText() const
1177 {
1178     if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1179     {
1180     	return XubString();
1181     }
1182     else if ( mpViewShell->GetView()->IsTextEdit() )
1183     {
1184 	    OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1185 	    return pOLV->GetEditView().GetSurroundingText();
1186     }
1187     else
1188     {
1189     	return XubString();
1190     }
1191 }
1192 
1193 Selection Window::GetSurroundingTextSelection() const
1194 {
1195     if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1196     {
1197 	    return Selection( 0, 0 );
1198     }
1199     else if ( mpViewShell->GetView()->IsTextEdit() )
1200     {
1201 	    OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1202 	    return pOLV->GetEditView().GetSurroundingTextSelection();
1203     }
1204     else
1205     {
1206         return Selection( 0, 0 );
1207     }
1208 }
1209 
1210 } // end of namespace sd
1211