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