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