update dev300-m58
[ooovba.git] / sd / source / ui / view / sdwindow.cxx
blob03a178277d08b75318b84cc5853edc6f512ecf29
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdwindow.cxx,v $
10 * $Revision: 1.38.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "Window.hxx"
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/request.hxx>
38 #include <sfx2/viewfrm.hxx>
40 #include <svx/outliner.hxx>
42 #include <svx/editview.hxx>
44 #include "app.hrc"
45 #include "helpids.h"
46 #include "ViewShell.hxx"
47 #include "DrawViewShell.hxx"
48 #include "View.hxx"
49 #include "FrameView.hxx"
50 #include "OutlineViewShell.hxx"
51 #include "drawdoc.hxx"
52 #ifndef SD_ACCESSIBILITY_ACCESSIBLE_DRAW_DOCUMENT_VIEW_HXX
53 #include "AccessibleDrawDocumentView.hxx"
54 #endif
55 #ifndef SD_WINDOW_UPDATER_HXX
56 #include "WindowUpdater.hxx"
57 #endif
59 namespace sd {
61 #define SCROLL_LINE_FACT 0.05 // Faktor fuer Zeilenscrolling
62 #define SCROLL_PAGE_FACT 0.5 // Faktor fuer Seitenscrolling
63 #define SCROLL_SENSITIVE 20 // Sensitiver Bereich (Pixel)
64 #define ZOOM_MULTIPLICATOR 10000 // Multiplikator um Rundungsfehler zu vermeiden
65 #define MIN_ZOOM 5 // Minimaler Zoomfaktor
66 #define MAX_ZOOM 3000 // Maximaler Zoomfaktor
69 /*************************************************************************
71 |* Konstruktor
73 \************************************************************************/
75 Window::Window(::Window* pParent)
76 : ::Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
77 DropTargetHelper( this ),
78 mpShareWin(NULL),
79 maWinPos(0, 0), // vorsichtshalber; die Werte sollten aber
80 maViewOrigin(0, 0), // vom Besitzer des Fensters neu gesetzt
81 maViewSize(1000, 1000), // werden
82 maPrevSize(-1,-1),
83 mnMinZoom(MIN_ZOOM),
84 mnMaxZoom(MAX_ZOOM),
85 mbMinZoomAutoCalc(false),
86 mbCalcMinZoomByMinSide(true),
87 mbCenterAllowed(true),
88 mnTicks (0),
89 mbDraggedFrom(false),
90 mpViewShell(NULL),
91 mbUseDropScroll (true)
93 SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
95 MapMode aMap(GetMapMode());
96 aMap.SetMapUnit(MAP_100TH_MM);
97 SetMapMode(aMap);
99 // Damit im Diamodus die ::WindowColor genommen wird
100 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
102 // adjust contrast mode initially
103 bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
104 SetDrawMode( bUseContrast
105 ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
106 : ViewShell::OUTPUT_DRAWMODE_COLOR );
108 // Hilfe-ID setzen
109 // SetHelpId(HID_SD_WIN_DOCUMENT);
110 SetUniqueId(HID_SD_WIN_DOCUMENT);
112 // #i78183# Added after discussed with AF
113 EnableRTL(FALSE);
116 /*************************************************************************
118 |* Destruktor
120 \************************************************************************/
122 Window::~Window (void)
124 if (mpViewShell != NULL)
126 WindowUpdater* pWindowUpdater = mpViewShell->GetWindowUpdater();
127 if (pWindowUpdater != NULL)
128 pWindowUpdater->UnregisterWindow (this);
135 void Window::SetViewShell (ViewShell* pViewSh)
137 WindowUpdater* pWindowUpdater = NULL;
138 // Unregister at device updater of old view shell.
139 if (mpViewShell != NULL)
141 pWindowUpdater = mpViewShell->GetWindowUpdater();
142 if (pWindowUpdater != NULL)
143 pWindowUpdater->UnregisterWindow (this);
146 mpViewShell = pViewSh;
148 // Register at device updater of new view shell
149 if (mpViewShell != NULL)
151 pWindowUpdater = mpViewShell->GetWindowUpdater();
152 if (pWindowUpdater != NULL)
153 pWindowUpdater->RegisterWindow (this);
160 /*************************************************************************
162 |* Die Haelfte des Sichtbaren Bereich eines anderen Fensters darstellen
164 \************************************************************************/
166 void Window::ShareViewArea(Window* pOtherWin)
168 mpShareWin = pOtherWin;
169 maViewOrigin = pOtherWin->maViewOrigin;
170 maViewSize = pOtherWin->maViewSize;
171 mnMinZoom = pOtherWin->mnMinZoom;
172 mnMaxZoom = pOtherWin->mnMaxZoom;
173 mbCenterAllowed = pOtherWin->mbCenterAllowed;
175 long nZoom = pOtherWin->GetZoom();
176 MapMode aMap(GetMapMode());
177 aMap.SetScaleX(Fraction(nZoom, 100));
178 aMap.SetScaleY(Fraction(nZoom, 100));
179 aMap.SetOrigin(pOtherWin->GetMapMode().GetOrigin());
180 SetMapMode(aMap);
186 void Window::CalcMinZoom()
188 // Are we entitled to change the minimal zoom factor?
189 if ( mbMinZoomAutoCalc )
191 // Get current zoom factor.
192 long nZoom = GetZoom();
194 if ( mpShareWin )
196 mpShareWin->CalcMinZoom();
197 mnMinZoom = mpShareWin->mnMinZoom;
199 else
201 // Get the rectangle of the output area in logical coordinates
202 // and calculate the scaling factors that would lead to the view
203 // area (also called application area) to completely fill the
204 // window.
205 Size aWinSize = PixelToLogic(GetOutputSizePixel());
206 ULONG nX = (ULONG) ((double) aWinSize.Width()
207 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Width());
208 ULONG nY = (ULONG) ((double) aWinSize.Height()
209 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Height());
211 // Decide whether to take the larger or the smaller factor.
212 ULONG nFact;
213 if (mbCalcMinZoomByMinSide)
214 nFact = Min(nX, nY);
215 else
216 nFact = Max(nX, nY);
218 // The factor is tansfomed according to the current zoom factor.
219 nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
220 mnMinZoom = Max((USHORT) MIN_ZOOM, (USHORT) nFact);
222 // If the current zoom factor is smaller than the calculated minimal
223 // zoom factor then set the new minimal factor as the current zoom
224 // factor.
225 if ( nZoom < (long) mnMinZoom )
226 SetZoomFactor(mnMinZoom);
233 void Window::SetMinZoom (long int nMin)
235 mnMinZoom = (USHORT) nMin;
241 long Window::GetMinZoom (void) const
243 return mnMinZoom;
249 void Window::SetMaxZoom (long int nMax)
251 mnMaxZoom = (USHORT) nMax;
257 long Window::GetMaxZoom (void) const
259 return mnMaxZoom;
265 long Window::GetZoom (void) const
267 if( GetMapMode().GetScaleX().GetDenominator() )
269 return GetMapMode().GetScaleX().GetNumerator() * 100L
270 / GetMapMode().GetScaleX().GetDenominator();
272 else
274 return 0;
281 /*************************************************************************
283 |* Resize event
285 \************************************************************************/
287 void Window::Resize()
289 ::Window::Resize();
290 CalcMinZoom();
292 if( mpViewShell && mpViewShell->GetViewFrame() )
293 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
296 /*************************************************************************
298 |* PrePaint event
300 \************************************************************************/
302 void Window::PrePaint()
304 if ( mpViewShell )
305 mpViewShell->PrePaint();
308 /*************************************************************************
310 |* Paint event
312 \************************************************************************/
314 void Window::Paint(const Rectangle& rRect)
316 if ( mpViewShell )
317 mpViewShell->Paint(rRect, this);
320 /*************************************************************************
322 |* Keyboard event
324 \************************************************************************/
326 void Window::KeyInput(const KeyEvent& rKEvt)
328 if (!(mpViewShell && mpViewShell->KeyInput(rKEvt, this)))
330 if (mpViewShell && rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
332 mpViewShell->GetViewShell()->Escape();
334 else
336 ::Window::KeyInput(rKEvt);
341 /*************************************************************************
343 |* MouseButtonDown event
345 \************************************************************************/
347 void Window::MouseButtonDown(const MouseEvent& rMEvt)
349 if ( mpViewShell )
350 mpViewShell->MouseButtonDown(rMEvt, this);
353 /*************************************************************************
355 |* MouseMove event
357 \************************************************************************/
359 void Window::MouseMove(const MouseEvent& rMEvt)
361 if ( mpViewShell )
362 mpViewShell->MouseMove(rMEvt, this);
365 /*************************************************************************
367 |* MouseButtonUp event
369 \************************************************************************/
371 void Window::MouseButtonUp(const MouseEvent& rMEvt)
373 mnTicks = 0;
375 if ( mpViewShell )
376 mpViewShell->MouseButtonUp(rMEvt, this);
379 /*************************************************************************
381 |* Command event
383 \************************************************************************/
385 void Window::Command(const CommandEvent& rCEvt)
387 if ( mpViewShell )
388 mpViewShell->Command(rCEvt, this);
391 long Window::Notify( NotifyEvent& rNEvt )
393 long nResult = FALSE;
394 if ( mpViewShell )
396 nResult = mpViewShell->Notify(rNEvt, this);
398 if( !nResult )
399 ::Window::Notify( rNEvt );
401 return nResult;
405 /*************************************************************************
407 |* RequestHelp event
409 \************************************************************************/
411 void Window::RequestHelp(const HelpEvent& rEvt)
413 if ( mpViewShell )
415 if( !mpViewShell->RequestHelp( rEvt, this) )
416 ::Window::RequestHelp( rEvt );
418 else
419 ::Window::RequestHelp( rEvt );
425 Point Window::GetWinViewPos (void) const
427 return maWinPos;
433 Point Window::GetViewOrigin (void) const
435 return maViewOrigin;
441 Size Window::GetViewSize (void) const
443 return maViewSize;
449 /*************************************************************************
451 |* Position der linken oberen Ecke des im Fenster sichtbaren Bereichs
452 |* setzen
454 \************************************************************************/
456 void Window::SetWinViewPos(const Point& rPnt)
458 maWinPos = rPnt;
461 /*************************************************************************
463 |* Ursprung der Darstellung in Bezug zur gesamten Arbeitsflaeche setzen
465 \************************************************************************/
467 void Window::SetViewOrigin(const Point& rPnt)
469 maViewOrigin = rPnt;
472 /*************************************************************************
474 |* Groesse der gesamten Arbeitsflaeche, die mit dem Fenster betrachtet
475 |* werden kann, setzen
477 \************************************************************************/
479 void Window::SetViewSize(const Size& rSize)
481 maViewSize = rSize;
482 CalcMinZoom();
488 void Window::SetCenterAllowed (bool bIsAllowed)
490 mbCenterAllowed = bIsAllowed;
496 long Window::SetZoomFactor(long nZoom)
498 // Clip the zoom factor to the valid range marked by nMinZoom as
499 // calculated by CalcMinZoom() and the constant MAX_ZOOM.
500 if ( nZoom > MAX_ZOOM )
501 nZoom = MAX_ZOOM;
502 if ( nZoom < (long) mnMinZoom )
503 nZoom = mnMinZoom;
505 // Set the zoom factor at the window's map mode.
506 MapMode aMap(GetMapMode());
507 aMap.SetScaleX(Fraction(nZoom, 100));
508 aMap.SetScaleY(Fraction(nZoom, 100));
509 SetMapMode(aMap);
511 // invalidate previous size - it was relative to the old scaling
512 maPrevSize = Size(-1,-1);
514 // Update the map mode's origin (to what effect?).
515 UpdateMapOrigin();
517 // Update the view's snapping to the the new zoom factor.
518 if ( mpViewShell && mpViewShell->ISA(DrawViewShell) )
519 ((DrawViewShell*) mpViewShell)->GetView()->
520 RecalcLogicSnapMagnetic(*this);
522 // Return the zoom factor just in case it has been changed above to lie
523 // inside the valid range.
524 return nZoom;
527 void Window::SetZoomIntegral(long nZoom)
529 // Clip the zoom factor to the valid range marked by nMinZoom as
530 // previously calculated by <member>CalcMinZoom()</member> and the
531 // MAX_ZOOM constant.
532 if ( nZoom > MAX_ZOOM )
533 nZoom = MAX_ZOOM;
534 if ( nZoom < (long) mnMinZoom )
535 nZoom = mnMinZoom;
537 // Calculate the window's new origin.
538 Size aSize = PixelToLogic(GetOutputSizePixel());
539 long nW = aSize.Width() * GetZoom() / nZoom;
540 long nH = aSize.Height() * GetZoom() / nZoom;
541 maWinPos.X() += (aSize.Width() - nW) / 2;
542 maWinPos.Y() += (aSize.Height() - nH) / 2;
543 if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
544 if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
546 // Finally update this window's map mode to the given zoom factor that
547 // has been clipped to the valid range.
548 SetZoomFactor(nZoom);
551 long Window::GetZoomForRect( const Rectangle& rZoomRect )
553 long nRetZoom = 100;
555 if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
557 // Calculate the scale factors which will lead to the given
558 // rectangle being fully visible (when translated accordingly) as
559 // large as possible in the output area independently in both
560 // coordinate directions .
561 ULONG nX(0L);
562 ULONG nY(0L);
564 const Size aWinSize( PixelToLogic(GetOutputSizePixel()) );
565 if(rZoomRect.GetHeight())
567 nX = (ULONG) ((double) aWinSize.Height()
568 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
571 if(rZoomRect.GetWidth())
573 nY = (ULONG) ((double) aWinSize.Width()
574 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
577 // Use the smaller one of both so that the zoom rectangle will be
578 // fully visible with respect to both coordinate directions.
579 ULONG nFact = Min(nX, nY);
581 // Transform the current zoom factor so that it leads to the desired
582 // scaling.
583 nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
585 // Calculate the new origin.
586 if ( nFact == 0 )
588 // Don't change anything if the scale factor is degenrate.
589 nRetZoom = GetZoom();
591 else
593 // Clip the zoom factor to the valid range marked by nMinZoom as
594 // previously calculated by <member>CalcMinZoom()</member> and the
595 // MAX_ZOOM constant.
596 if ( nRetZoom > MAX_ZOOM )
597 nRetZoom = MAX_ZOOM;
598 if ( nRetZoom < (long) mnMinZoom )
599 nRetZoom = mnMinZoom;
603 return nRetZoom;
606 /** Recalculate the zoom factor and translation so that the given rectangle
607 is displayed centered and as large as possible while still being fully
608 visible in the window.
610 long Window::SetZoomRect (const Rectangle& rZoomRect)
612 long nNewZoom = 100;
614 if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
616 // The given rectangle is degenerate. Use the default zoom factor
617 // (above) of 100%.
618 SetZoomIntegral(nNewZoom);
620 else
622 Point aPos = rZoomRect.TopLeft();
623 // Transform the output area from pixel coordinates into logical
624 // coordinates.
625 Size aWinSize = PixelToLogic(GetOutputSizePixel());
626 // Paranoia! The degenerate case of zero width or height has been
627 // taken care of above.
628 DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Breite = 0!");
629 DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Hoehe = 0!");
631 // Calculate the scale factors which will lead to the given
632 // rectangle being fully visible (when translated accordingly) as
633 // large as possible in the output area independently in both
634 // coordinate directions .
635 ULONG nX(0L);
636 ULONG nY(0L);
638 if(rZoomRect.GetHeight())
640 nX = (ULONG) ((double) aWinSize.Height()
641 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
644 if(rZoomRect.GetWidth())
646 nY = (ULONG) ((double) aWinSize.Width()
647 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
650 // Use the smaller one of both so that the zoom rectangle will be
651 // fully visible with respect to both coordinate directions.
652 ULONG nFact = Min(nX, nY);
654 // Transform the current zoom factor so that it leads to the desired
655 // scaling.
656 long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
658 // Calculate the new origin.
659 if ( nFact == 0 )
661 // Don't change anything if the scale factor is degenrate.
662 nNewZoom = GetZoom();
664 else
666 // Calculate the new window position that centers the given
667 // rectangle on the screen.
668 if ( nZoom > MAX_ZOOM )
669 nFact = nFact * MAX_ZOOM / nZoom;
671 maWinPos = maViewOrigin + aPos;
673 aWinSize.Width() = (long) ((double) aWinSize.Width() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
674 maWinPos.X() += (rZoomRect.GetWidth() - aWinSize.Width()) / 2;
675 aWinSize.Height() = (long) ((double) aWinSize.Height() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
676 maWinPos.Y() += (rZoomRect.GetHeight() - aWinSize.Height()) / 2;
678 if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
679 if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
681 // Adapt the window's map mode to the new zoom factor.
682 nNewZoom = SetZoomFactor(nZoom);
686 return(nNewZoom);
692 void Window::SetMinZoomAutoCalc (bool bAuto)
694 mbMinZoomAutoCalc = bAuto;
700 /*************************************************************************
702 |* Neuen MapMode-Origin berechnen und setzen; wenn aWinPos.X()/Y()
703 |* gleich -1 ist, wird die entsprechende Position zentriert
704 |* (z.B. fuer Initialisierung)
706 \************************************************************************/
708 void Window::UpdateMapOrigin(BOOL bInvalidate)
710 BOOL bChanged = FALSE;
711 const Size aWinSize = PixelToLogic(GetOutputSizePixel());
713 if ( mbCenterAllowed )
715 if( maPrevSize != Size(-1,-1) )
717 // keep view centered around current pos, when window
718 // resizes
719 maWinPos.X() -= (aWinSize.Width() - maPrevSize.Width()) / 2;
720 maWinPos.Y() -= (aWinSize.Height() - maPrevSize.Height()) / 2;
721 bChanged = TRUE;
724 if ( maWinPos.X() > maViewSize.Width() - aWinSize.Width() )
726 maWinPos.X() = maViewSize.Width() - aWinSize.Width();
727 bChanged = TRUE;
729 if ( maWinPos.Y() > maViewSize.Height() - aWinSize.Height() )
731 maWinPos.Y() = maViewSize.Height() - aWinSize.Height();
732 bChanged = TRUE;
734 if ( aWinSize.Width() > maViewSize.Width() || maWinPos.X() < 0 )
736 maWinPos.X() = maViewSize.Width() / 2 - aWinSize.Width() / 2;
737 bChanged = TRUE;
739 if ( aWinSize.Height() > maViewSize.Height() || maWinPos.Y() < 0 )
741 maWinPos.Y() = maViewSize.Height() / 2 - aWinSize.Height() / 2;
742 bChanged = TRUE;
746 UpdateMapMode ();
748 maPrevSize = aWinSize;
750 if (bChanged && bInvalidate)
751 Invalidate();
757 void Window::UpdateMapMode (void)
759 Size aWinSize = PixelToLogic(GetOutputSizePixel());
760 maWinPos -= maViewOrigin;
761 Size aPix(maWinPos.X(), maWinPos.Y());
762 aPix = LogicToPixel(aPix);
763 // Groesse muss vielfaches von BRUSH_SIZE sein, damit Muster
764 // richtig dargestellt werden
765 // #i2237#
766 // removed old stuff here which still forced zoom to be
767 // %BRUSH_SIZE which is outdated now
769 if (mpViewShell && mpViewShell->ISA(DrawViewShell))
771 Size aViewSizePixel = LogicToPixel(maViewSize);
772 Size aWinSizePixel = LogicToPixel(aWinSize);
774 // Seite soll nicht am Fensterrand "kleben"
775 if (aPix.Width() == 0)
777 // #i2237#
778 // Since BRUSH_SIZE alignment is outdated now, i use the
779 // former constant here directly
780 aPix.Width() -= 8;
782 if (aPix.Height() == 0)
784 // #i2237#
785 // Since BRUSH_SIZE alignment is outdated now, i use the
786 // former constant here directly
787 aPix.Height() -= 8;
791 aPix = PixelToLogic(aPix);
792 maWinPos.X() = aPix.Width();
793 maWinPos.Y() = aPix.Height();
794 Point aNewOrigin (-maWinPos.X(), -maWinPos.Y());
795 maWinPos += maViewOrigin;
797 MapMode aMap(GetMapMode());
798 aMap.SetOrigin(aNewOrigin);
799 SetMapMode(aMap);
805 /*************************************************************************
807 |* X-Position des sichtbaren Bereichs als Bruchteil (< 1)
808 |* der gesamten Arbeitsbereichbreite zuruegeben
810 \************************************************************************/
812 double Window::GetVisibleX()
814 return ((double) maWinPos.X() / maViewSize.Width());
817 /*************************************************************************
819 |* Y-Position des sichtbaren Bereichs als Bruchteil (< 1)
820 |* der gesamten Arbeitsbereichhoehe zuruegeben
822 \************************************************************************/
824 double Window::GetVisibleY()
826 return ((double) maWinPos.Y() / maViewSize.Height());
829 /*************************************************************************
831 |* X- und Y-Position des sichtbaren Bereichs als Bruchteile (< 1)
832 |* der gesamten Arbeitsbereichgroesse setzen
833 |* negative Werte werden ignoriert
835 \************************************************************************/
837 void Window::SetVisibleXY(double fX, double fY)
839 long nOldX = maWinPos.X();
840 long nOldY = maWinPos.Y();
842 if ( fX >= 0 )
843 maWinPos.X() = (long) (fX * maViewSize.Width());
844 if ( fY >= 0 )
845 maWinPos.Y() = (long) (fY * maViewSize.Height());
846 UpdateMapOrigin(FALSE);
847 // Size sz(nOldX - aWinPos.X(), nOldY - aWinPos.Y());
848 // sz = LogicToPixel(sz);
849 Scroll(nOldX - maWinPos.X(), nOldY - maWinPos.Y(), SCROLL_CHILDREN);
850 Update();
853 /*************************************************************************
855 |* Breite des sichtbaren Bereichs im Verhaeltnis zur
856 |* gesamten Arbeitsbereichbreite zuruegeben
858 \************************************************************************/
860 double Window::GetVisibleWidth()
862 Size aWinSize = PixelToLogic(GetOutputSizePixel());
863 if ( aWinSize.Width() > maViewSize.Width() )
864 aWinSize.Width() = maViewSize.Width();
865 return ((double) aWinSize.Width() / maViewSize.Width());
868 /*************************************************************************
870 |* Hoehe des sichtbaren Bereichs im Verhaeltnis zur
871 |* gesamten Arbeitsbereichhoehe zuruegeben
873 \************************************************************************/
875 double Window::GetVisibleHeight()
877 Size aWinSize = PixelToLogic(GetOutputSizePixel());
878 if ( aWinSize.Height() > maViewSize.Height() )
879 aWinSize.Height() = maViewSize.Height();
880 return ((double) aWinSize.Height() / maViewSize.Height());
883 /*************************************************************************
885 |* Breite einer Scrollspalte im Verhaeltnis zur gesamten
886 |* Arbeitsbereichbreite zuruegeben
888 \************************************************************************/
890 double Window::GetScrlLineWidth()
892 return (GetVisibleWidth() * SCROLL_LINE_FACT);
895 /*************************************************************************
897 |* Breite einer Scrollspalte im Verhaeltnis zur gesamten
898 |* Arbeitsbereichhoehe zuruegeben
900 \************************************************************************/
902 double Window::GetScrlLineHeight()
904 return (GetVisibleHeight() * SCROLL_LINE_FACT);
907 /*************************************************************************
909 |* Breite einer Scrollpage im Verhaeltnis zur gesamten
910 |* Arbeitsbereichbreite zuruegeben
912 \************************************************************************/
914 double Window::GetScrlPageWidth()
916 return (GetVisibleWidth() * SCROLL_PAGE_FACT);
919 /*************************************************************************
921 |* Breite einer Scrollpage im Verhaeltnis zur gesamten
922 |* Arbeitsbereichhoehe zuruegeben
924 \************************************************************************/
926 double Window::GetScrlPageHeight()
928 return (GetVisibleHeight() * SCROLL_PAGE_FACT);
931 /*************************************************************************
933 |* Fenster deaktivieren
935 \************************************************************************/
937 void Window::LoseFocus()
939 mnTicks = 0;
940 ::Window::LoseFocus ();
943 /*************************************************************************
945 |* Fenster aktivieren
947 \************************************************************************/
949 void Window::GrabFocus()
951 mnTicks = 0;
952 ::Window::GrabFocus ();
956 /*************************************************************************
958 |* DataChanged
960 \************************************************************************/
962 void Window::DataChanged( const DataChangedEvent& rDCEvt )
964 ::Window::DataChanged( rDCEvt );
966 // PRINTER bei allen Dokumenten weglassen, die keinen Printer benutzen.
967 // FONTS und FONTSUBSTITUTION weglassen, wenn keine Textausgaben
968 // vorhanden sind, bzw. wenn das Dokument keinen Text zulaesst.
970 if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
971 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
972 (rDCEvt.GetType() == DATACHANGED_FONTS) ||
973 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
974 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
975 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
977 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
978 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
980 // When the screen zoom factor has changed then reset the zoom
981 // factor of the frame to allways display the whole page.
982 const AllSettings* pOldSettings = rDCEvt.GetOldSettings ();
983 const AllSettings& rNewSettings = GetSettings ();
984 if (pOldSettings)
985 if (pOldSettings->GetStyleSettings().GetScreenZoom()
986 != rNewSettings.GetStyleSettings().GetScreenZoom())
987 mpViewShell->GetViewFrame()->GetDispatcher()->
988 Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
990 // ScrollBars neu anordnen bzw. Resize ausloesen, da sich
991 // ScrollBar-Groesse geaendert haben kann. Dazu muss dann im
992 // Resize-Handler aber auch die Groesse der ScrollBars aus
993 // den Settings abgefragt werden.
994 Resize();
996 // Daten neu Setzen, die aus den Systemeinstellungen bzw. aus
997 // den Settings uebernommen werden. Evtl. weitere Daten neu
998 // berechnen, da sich auch die Aufloesung hierdurch geaendert
999 // haben kann.
1000 if( mpViewShell )
1002 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1003 SvtAccessibilityOptions aAccOptions;
1004 ULONG nOutputMode;
1005 USHORT nPreviewSlot;
1007 if( rStyleSettings.GetHighContrastMode() )
1008 nOutputMode = ViewShell::OUTPUT_DRAWMODE_CONTRAST;
1009 else
1010 nOutputMode = ViewShell::OUTPUT_DRAWMODE_COLOR;
1012 if( rStyleSettings.GetHighContrastMode() && aAccOptions.GetIsForPagePreviews() )
1013 nPreviewSlot = SID_PREVIEW_QUALITY_CONTRAST;
1014 else
1015 nPreviewSlot = SID_PREVIEW_QUALITY_COLOR;
1017 if( mpViewShell->ISA( DrawViewShell ) )
1019 SetDrawMode( nOutputMode );
1020 mpViewShell->GetFrameView()->SetDrawMode( nOutputMode );
1021 // #110094#-7
1022 // mpViewShell->GetView()->ReleaseMasterPagePaintCache();
1023 Invalidate();
1026 // #103100# Overwrite window color for OutlineView
1027 if( mpViewShell->ISA(OutlineViewShell ) )
1029 svtools::ColorConfig aColorConfig;
1030 const Color aDocColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
1031 SetBackground( Wallpaper( aDocColor ) );
1034 SfxRequest aReq( nPreviewSlot, 0, mpViewShell->GetDocSh()->GetDoc()->GetItemPool() );
1035 mpViewShell->ExecReq( aReq );
1036 mpViewShell->Invalidate();
1037 mpViewShell->ArrangeGUIElements();
1039 // #101928# re-create handles to show new outfit
1040 if(mpViewShell->ISA(DrawViewShell))
1042 mpViewShell->GetView()->AdjustMarkHdl();
1047 if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1048 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1049 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1051 // Virtuelle Device die auch von der Aufloesung oder von
1052 // Systemeinstellungen abhaengen, sollten geupdatet werden.
1053 // Ansonsten sollte zumindest bei DATACHANGED_DISPLAY
1054 // die virtuellen Devices geupdatet werden, da es einige
1055 // Systeme erlauben die Aufloesung und Farbtiefe waehrend
1056 // der Laufzeit zu aendern oder eben bei Palettenaenderungen
1057 // die virtuellen Device geupdatet werden muessen, da bei
1058 // Ausgaben ein anderes Farbmatching stattfinden kann.
1061 if ( rDCEvt.GetType() == DATACHANGED_FONTS )
1063 // Wenn das Dokument Font-AuswahlBoxen anbietet, muessen
1064 // diese geupdatet werden. Wie dies genau aussehen muss,
1065 // weiss ich leider auch nicht. Aber evtl. kann man das
1066 // ja global handeln. Dies muessten wir evtl. mal
1067 // mit PB absprechen, aber der ist derzeit leider Krank.
1068 // Also bevor dies hier gehandelt wird, vorher mit
1069 // PB und mir absprechen.
1072 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1073 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) )
1075 // Formatierung neu durchfuehren, da Fonts die im Dokument
1076 // vorkommen, nicht mehr vorhanden sein muessen oder
1077 // jetzt vorhanden sind oder durch andere ersetzt wurden
1078 // sind.
1079 if( mpViewShell )
1081 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
1082 if( pDocSh )
1083 pDocSh->SetPrinter( pDocSh->GetPrinter( TRUE ) );
1087 if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
1089 // Wie hier die Behandlung aussehen soll, weiss ich leider
1090 // selbst noch nicht. Evtl. mal einen Printer loeschen und
1091 // schauen was gemacht werden muss. Evtl. muesste ich in
1092 // VCL dafuer noch etwas einbauen, wenn der benutze Printer
1093 // geloescht wird. Ansonsten wuerde ich hier evtl. die
1094 // Formatierung neu berechnen, wenn der aktuelle Drucker
1095 // zerstoert wurde.
1096 if( mpViewShell )
1098 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
1099 if( pDocSh )
1100 pDocSh->SetPrinter( pDocSh->GetPrinter( TRUE ) );
1104 // Alles neu ausgeben
1105 Invalidate();
1112 /*************************************************************************
1114 |* DropTargetHelper::AcceptDrop
1116 \************************************************************************/
1118 sal_Int8 Window::AcceptDrop( const AcceptDropEvent& rEvt )
1120 sal_Int8 nRet = DND_ACTION_NONE;
1122 if( mpViewShell && !mpViewShell->GetDocSh()->IsReadOnly() )
1124 if( mpViewShell )
1125 nRet = mpViewShell->AcceptDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
1127 if (mbUseDropScroll && ! mpViewShell->ISA(OutlineViewShell))
1128 DropScroll( rEvt.maPosPixel );
1131 return nRet;
1134 /*************************************************************************
1136 |* DropTargetHelper::ExecuteDrop
1138 \************************************************************************/
1140 sal_Int8 Window::ExecuteDrop( const ExecuteDropEvent& rEvt )
1142 sal_Int8 nRet = DND_ACTION_NONE;
1144 if( mpViewShell )
1146 nRet = mpViewShell->ExecuteDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
1149 return nRet;
1155 void Window::SetUseDropScroll (bool bUseDropScroll)
1157 mbUseDropScroll = bUseDropScroll;
1163 /*************************************************************************
1165 |* Scrolling bei AcceptDrop-Events
1167 \************************************************************************/
1169 void Window::DropScroll(const Point& rMousePos)
1171 short nDx = 0;
1172 short nDy = 0;
1174 Size aSize = GetOutputSizePixel();
1176 if (aSize.Width() > SCROLL_SENSITIVE * 3)
1178 if ( rMousePos.X() < SCROLL_SENSITIVE )
1180 nDx = -1;
1183 if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE )
1185 nDx = 1;
1189 if (aSize.Height() > SCROLL_SENSITIVE * 3)
1191 if ( rMousePos.Y() < SCROLL_SENSITIVE )
1193 nDy = -1;
1196 if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE )
1198 nDy = 1;
1202 if ( (nDx || nDy) && (rMousePos.X()!=0 || rMousePos.Y()!=0 ) )
1204 if (mnTicks > 20)
1205 mpViewShell->ScrollLines(nDx, nDy);
1206 else
1207 mnTicks ++;
1214 ::com::sun::star::uno::Reference<
1215 ::com::sun::star::accessibility::XAccessible>
1216 Window::CreateAccessible (void)
1218 if (mpViewShell != NULL)
1219 return mpViewShell->CreateAccessibleDocumentView (this);
1220 else
1222 OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
1223 return ::Window::CreateAccessible ();
1227 XubString Window::GetSurroundingText() const
1229 if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1231 return XubString();
1233 else if ( mpViewShell->GetView()->IsTextEdit() )
1235 OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1236 return pOLV->GetEditView().GetSurroundingText();
1238 else
1240 return XubString();
1244 Selection Window::GetSurroundingTextSelection() const
1246 if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1248 return Selection( 0, 0 );
1250 else if ( mpViewShell->GetView()->IsTextEdit() )
1252 OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1253 return pOLV->GetEditView().GetSurroundingTextSelection();
1255 else
1257 return Selection( 0, 0 );
1261 } // end of namespace sd