bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / sdwindow.cxx
blobc9c4bfe15b616562fe97f427a1e8e52df0810e8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "Window.hxx"
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/request.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <svx/svxids.hrc>
27 #include <editeng/outliner.hxx>
28 #include <editeng/editview.hxx>
30 #include "app.hrc"
31 #include "helpids.h"
32 #include "ViewShell.hxx"
33 #include "DrawViewShell.hxx"
34 #include "View.hxx"
35 #include "FrameView.hxx"
36 #include "OutlineViewShell.hxx"
37 #include "drawdoc.hxx"
38 #include "AccessibleDrawDocumentView.hxx"
39 #include "WindowUpdater.hxx"
41 #include <vcl/svapp.hxx>
42 #include <vcl/settings.hxx>
43 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
45 namespace sd {
47 #define SCROLL_LINE_FACT 0.05 ///< factor for line scrolling
48 #define SCROLL_PAGE_FACT 0.5 ///< factor for page scrolling
49 #define SCROLL_SENSITIVE 20 ///< sensitive area in pixel
50 #define ZOOM_MULTIPLICATOR 10000 ///< multiplier to avoid rounding errors
51 #define MIN_ZOOM 5 ///< minimal zoom factor
52 #define MAX_ZOOM 3000 ///< maximal zoom factor
54 Window::Window(vcl::Window* pParent)
55 : vcl::Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
56 DropTargetHelper( this ),
57 mpShareWin(NULL),
58 maWinPos(0, 0), // precautionary; but the values should be set
59 maViewOrigin(0, 0), // again from the owner of the window
60 maViewSize(1000, 1000),
61 maPrevSize(-1,-1),
62 mnMinZoom(MIN_ZOOM),
63 mnMaxZoom(MAX_ZOOM),
64 mbMinZoomAutoCalc(false),
65 mbCalcMinZoomByMinSide(true),
66 mbCenterAllowed(true),
67 mnTicks (0),
68 mbDraggedFrom(false),
69 mpViewShell(NULL),
70 mbUseDropScroll (true)
72 SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
74 MapMode aMap(GetMapMode());
75 aMap.SetMapUnit(MAP_100TH_MM);
76 SetMapMode(aMap);
78 // whit it, the vcl::WindowColor is used in the slide mode
79 SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
81 // adjust contrast mode initially
82 bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
83 SetDrawMode( bUseContrast
84 ? sd::OUTPUT_DRAWMODE_CONTRAST
85 : sd::OUTPUT_DRAWMODE_COLOR );
87 // set Help ID
88 // SetHelpId(HID_SD_WIN_DOCUMENT);
89 SetUniqueId(HID_SD_WIN_DOCUMENT);
91 // #i78183# Added after discussed with AF
92 EnableRTL(false);
95 Window::~Window()
97 disposeOnce();
100 void Window::dispose()
102 if (mpViewShell != NULL)
104 WindowUpdater* pWindowUpdater = mpViewShell->GetWindowUpdater();
105 if (pWindowUpdater != NULL)
106 pWindowUpdater->UnregisterWindow (this);
108 mpShareWin.clear();
109 vcl::Window::dispose();
112 void Window::SetViewShell (ViewShell* pViewSh)
114 WindowUpdater* pWindowUpdater = NULL;
115 // Unregister at device updater of old view shell.
116 if (mpViewShell != NULL)
118 pWindowUpdater = mpViewShell->GetWindowUpdater();
119 if (pWindowUpdater != NULL)
120 pWindowUpdater->UnregisterWindow (this);
123 mpViewShell = pViewSh;
125 // Register at device updater of new view shell
126 if (mpViewShell != NULL)
128 pWindowUpdater = mpViewShell->GetWindowUpdater();
129 if (pWindowUpdater != NULL)
130 pWindowUpdater->RegisterWindow (this);
134 void Window::CalcMinZoom()
136 // Are we entitled to change the minimal zoom factor?
137 if ( mbMinZoomAutoCalc )
139 // Get current zoom factor.
140 long nZoom = GetZoom();
142 if ( mpShareWin )
144 mpShareWin->CalcMinZoom();
145 mnMinZoom = mpShareWin->mnMinZoom;
147 else
149 // Get the rectangle of the output area in logical coordinates
150 // and calculate the scaling factors that would lead to the view
151 // area (also called application area) to completely fill the
152 // window.
153 Size aWinSize = PixelToLogic(GetOutputSizePixel());
154 sal_uLong nX = (sal_uLong) ((double) aWinSize.Width()
155 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Width());
156 sal_uLong nY = (sal_uLong) ((double) aWinSize.Height()
157 * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Height());
159 // Decide whether to take the larger or the smaller factor.
160 sal_uLong nFact;
161 if (mbCalcMinZoomByMinSide)
162 nFact = std::min(nX, nY);
163 else
164 nFact = std::max(nX, nY);
166 // The factor is tansfomed according to the current zoom factor.
167 nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
168 mnMinZoom = std::max((sal_uInt16) MIN_ZOOM, (sal_uInt16) nFact);
170 // If the current zoom factor is smaller than the calculated minimal
171 // zoom factor then set the new minimal factor as the current zoom
172 // factor.
173 if ( nZoom < (long) mnMinZoom )
174 SetZoomFactor(mnMinZoom);
178 void Window::SetMinZoom (long int nMin)
180 mnMinZoom = (sal_uInt16) nMin;
183 void Window::SetMaxZoom (long int nMax)
185 mnMaxZoom = (sal_uInt16) nMax;
188 long Window::GetZoom() const
190 if( GetMapMode().GetScaleX().GetDenominator() )
192 return GetMapMode().GetScaleX().GetNumerator() * 100L
193 / GetMapMode().GetScaleX().GetDenominator();
195 else
197 return 0;
201 void Window::Resize()
203 vcl::Window::Resize();
204 CalcMinZoom();
206 if( mpViewShell && mpViewShell->GetViewFrame() )
207 mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
210 void Window::PrePaint(vcl::RenderContext& /*rRenderContext*/)
212 if ( mpViewShell )
213 mpViewShell->PrePaint();
216 void Window::Paint(vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect)
218 if ( mpViewShell )
219 mpViewShell->Paint(rRect, this);
222 void Window::KeyInput(const KeyEvent& rKEvt)
224 if (getenv("SD_DEBUG") && rKEvt.GetKeyCode().GetCode() == KEY_F12 && mpViewShell)
226 mpViewShell->GetDoc()->dumpAsXml(0);
227 return;
230 if (!(mpViewShell && mpViewShell->KeyInput(rKEvt, this)))
232 if (mpViewShell && rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
234 mpViewShell->GetViewShell()->Escape();
236 else
238 vcl::Window::KeyInput(rKEvt);
243 void Window::MouseButtonDown(const MouseEvent& rMEvt)
245 if ( mpViewShell )
246 mpViewShell->MouseButtonDown(rMEvt, this);
249 void Window::MouseMove(const MouseEvent& rMEvt)
251 if ( mpViewShell )
252 mpViewShell->MouseMove(rMEvt, this);
255 void Window::MouseButtonUp(const MouseEvent& rMEvt)
257 mnTicks = 0;
259 if ( mpViewShell )
260 mpViewShell->MouseButtonUp(rMEvt, this);
263 void Window::Command(const CommandEvent& rCEvt)
265 if ( mpViewShell )
266 mpViewShell->Command(rCEvt, this);
269 bool Window::Notify( NotifyEvent& rNEvt )
271 bool nResult = false;
272 if ( mpViewShell )
274 nResult = mpViewShell->Notify(rNEvt, this);
276 if( !nResult )
277 nResult = vcl::Window::Notify( rNEvt );
279 return nResult;
282 void Window::RequestHelp(const HelpEvent& rEvt)
284 if ( mpViewShell )
286 if( !mpViewShell->RequestHelp( rEvt, this) )
287 vcl::Window::RequestHelp( rEvt );
289 else
290 vcl::Window::RequestHelp( rEvt );
294 * Set the position of the upper left corner from the visible area of the
295 * window.
297 void Window::SetWinViewPos(const Point& rPnt)
299 maWinPos = rPnt;
303 * Set origin of the representation in respect to the whole working area.
305 void Window::SetViewOrigin(const Point& rPnt)
307 maViewOrigin = rPnt;
311 * Set size of the whole working area which can be seen with the window.
313 void Window::SetViewSize(const Size& rSize)
315 maViewSize = rSize;
316 CalcMinZoom();
319 void Window::SetCenterAllowed (bool bIsAllowed)
321 mbCenterAllowed = bIsAllowed;
324 long Window::SetZoomFactor(long nZoom)
326 // Clip the zoom factor to the valid range marked by nMinZoom as
327 // calculated by CalcMinZoom() and the constant MAX_ZOOM.
328 if ( nZoom > MAX_ZOOM )
329 nZoom = MAX_ZOOM;
330 if ( nZoom < (long) mnMinZoom )
331 nZoom = mnMinZoom;
333 // Set the zoom factor at the window's map mode.
334 if (!mpViewShell || !mpViewShell->GetDoc()->isTiledRendering())
336 MapMode aMap(GetMapMode());
337 aMap.SetScaleX(Fraction(nZoom, 100));
338 aMap.SetScaleY(Fraction(nZoom, 100));
339 SetMapMode(aMap);
342 // invalidate previous size - it was relative to the old scaling
343 maPrevSize = Size(-1,-1);
345 // Update the map mode's origin (to what effect?).
346 UpdateMapOrigin();
348 // Update the view's snapping to the new zoom factor.
349 if ( mpViewShell && mpViewShell->ISA(DrawViewShell) )
350 static_cast<DrawViewShell*>(mpViewShell)->GetView()->
351 RecalcLogicSnapMagnetic(*this);
353 // Return the zoom factor just in case it has been changed above to lie
354 // inside the valid range.
355 return nZoom;
358 void Window::SetZoomIntegral(long nZoom)
360 // Clip the zoom factor to the valid range marked by nMinZoom as
361 // previously calculated by <member>CalcMinZoom()</member> and the
362 // MAX_ZOOM constant.
363 if ( nZoom > MAX_ZOOM )
364 nZoom = MAX_ZOOM;
365 if ( nZoom < (long) mnMinZoom )
366 nZoom = mnMinZoom;
368 // Calculate the window's new origin.
369 Size aSize = PixelToLogic(GetOutputSizePixel());
370 long nW = aSize.Width() * GetZoom() / nZoom;
371 long nH = aSize.Height() * GetZoom() / nZoom;
372 maWinPos.X() += (aSize.Width() - nW) / 2;
373 maWinPos.Y() += (aSize.Height() - nH) / 2;
374 if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
375 if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
377 // Finally update this window's map mode to the given zoom factor that
378 // has been clipped to the valid range.
379 SetZoomFactor(nZoom);
382 long Window::GetZoomForRect( const Rectangle& rZoomRect )
384 long nRetZoom = 100;
386 if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
388 // Calculate the scale factors which will lead to the given
389 // rectangle being fully visible (when translated accordingly) as
390 // large as possible in the output area independently in both
391 // coordinate directions .
392 sal_uLong nX(0L);
393 sal_uLong nY(0L);
395 const Size aWinSize( PixelToLogic(GetOutputSizePixel()) );
396 if(rZoomRect.GetHeight())
398 nX = (sal_uLong) ((double) aWinSize.Height()
399 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
402 if(rZoomRect.GetWidth())
404 nY = (sal_uLong) ((double) aWinSize.Width()
405 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
408 // Use the smaller one of both so that the zoom rectangle will be
409 // fully visible with respect to both coordinate directions.
410 sal_uLong nFact = std::min(nX, nY);
412 // Transform the current zoom factor so that it leads to the desired
413 // scaling.
414 nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
416 // Calculate the new origin.
417 if ( nFact == 0 )
419 // Don't change anything if the scale factor is degenrate.
420 nRetZoom = GetZoom();
422 else
424 // Clip the zoom factor to the valid range marked by nMinZoom as
425 // previously calculated by <member>CalcMinZoom()</member> and the
426 // MAX_ZOOM constant.
427 if ( nRetZoom > MAX_ZOOM )
428 nRetZoom = MAX_ZOOM;
429 if ( nRetZoom < (long) mnMinZoom )
430 nRetZoom = mnMinZoom;
434 return nRetZoom;
437 /** Recalculate the zoom factor and translation so that the given rectangle
438 is displayed centered and as large as possible while still being fully
439 visible in the window.
441 long Window::SetZoomRect (const Rectangle& rZoomRect)
443 long nNewZoom = 100;
445 if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
447 // The given rectangle is degenerate. Use the default zoom factor
448 // (above) of 100%.
449 SetZoomIntegral(nNewZoom);
451 else
453 Point aPos = rZoomRect.TopLeft();
454 // Transform the output area from pixel coordinates into logical
455 // coordinates.
456 Size aWinSize = PixelToLogic(GetOutputSizePixel());
457 // Paranoia! The degenerate case of zero width or height has been
458 // taken care of above.
459 DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Width = 0!");
460 DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Height = 0!");
462 // Calculate the scale factors which will lead to the given
463 // rectangle being fully visible (when translated accordingly) as
464 // large as possible in the output area independently in both
465 // coordinate directions .
466 sal_uLong nX(0L);
467 sal_uLong nY(0L);
469 if(rZoomRect.GetHeight())
471 nX = (sal_uLong) ((double) aWinSize.Height()
472 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
475 if(rZoomRect.GetWidth())
477 nY = (sal_uLong) ((double) aWinSize.Width()
478 * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
481 // Use the smaller one of both so that the zoom rectangle will be
482 // fully visible with respect to both coordinate directions.
483 sal_uLong nFact = std::min(nX, nY);
485 // Transform the current zoom factor so that it leads to the desired
486 // scaling.
487 long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
489 // Calculate the new origin.
490 if ( nFact == 0 )
492 // Don't change anything if the scale factor is degenrate.
493 nNewZoom = GetZoom();
495 else
497 // Calculate the new window position that centers the given
498 // rectangle on the screen.
499 if ( nZoom > MAX_ZOOM )
500 nFact = nFact * MAX_ZOOM / nZoom;
502 maWinPos = maViewOrigin + aPos;
504 aWinSize.Width() = (long) ((double) aWinSize.Width() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
505 maWinPos.X() += (rZoomRect.GetWidth() - aWinSize.Width()) / 2;
506 aWinSize.Height() = (long) ((double) aWinSize.Height() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
507 maWinPos.Y() += (rZoomRect.GetHeight() - aWinSize.Height()) / 2;
509 if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
510 if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
512 // Adapt the window's map mode to the new zoom factor.
513 nNewZoom = SetZoomFactor(nZoom);
517 return nNewZoom;
520 void Window::SetMinZoomAutoCalc (bool bAuto)
522 mbMinZoomAutoCalc = bAuto;
526 * Calculate and set new MapMode origin.
527 * If aWinPos.X()/Y() == -1, then we center the corresponding position (e.g. for
528 * initialization).
530 void Window::UpdateMapOrigin(bool bInvalidate)
532 bool bChanged = false;
533 const Size aWinSize = PixelToLogic(GetOutputSizePixel());
535 if ( mbCenterAllowed )
537 if( maPrevSize != Size(-1,-1) )
539 // keep view centered around current pos, when window
540 // resizes
541 maWinPos.X() -= (aWinSize.Width() - maPrevSize.Width()) / 2;
542 maWinPos.Y() -= (aWinSize.Height() - maPrevSize.Height()) / 2;
543 bChanged = true;
546 if ( maWinPos.X() > maViewSize.Width() - aWinSize.Width() )
548 maWinPos.X() = maViewSize.Width() - aWinSize.Width();
549 bChanged = true;
551 if ( maWinPos.Y() > maViewSize.Height() - aWinSize.Height() )
553 maWinPos.Y() = maViewSize.Height() - aWinSize.Height();
554 bChanged = true;
556 if ( aWinSize.Width() > maViewSize.Width() || maWinPos.X() < 0 )
558 maWinPos.X() = maViewSize.Width() / 2 - aWinSize.Width() / 2;
559 bChanged = true;
561 if ( aWinSize.Height() > maViewSize.Height() || maWinPos.Y() < 0 )
563 maWinPos.Y() = maViewSize.Height() / 2 - aWinSize.Height() / 2;
564 bChanged = true;
568 UpdateMapMode ();
570 maPrevSize = aWinSize;
572 // When tiled rendering, the above UpdateMapMode() call doesn't touch the map mode.
573 if (bChanged && bInvalidate && (!mpViewShell || !mpViewShell->GetDoc()->isTiledRendering()))
574 Invalidate();
577 void Window::UpdateMapMode()
579 maWinPos -= maViewOrigin;
580 Size aPix(maWinPos.X(), maWinPos.Y());
581 aPix = LogicToPixel(aPix);
582 // Size has to be a multiple of BRUSH_SIZE due to the correct depiction of
583 // pattern
584 // #i2237#
585 // removed old stuff here which still forced zoom to be
586 // %BRUSH_SIZE which is outdated now
588 if (mpViewShell && mpViewShell->ISA(DrawViewShell))
590 // page should not "stick" to the window border
591 if (aPix.Width() == 0)
593 // #i2237#
594 // Since BRUSH_SIZE alignment is outdated now, i use the
595 // former constant here directly
596 aPix.Width() -= 8;
598 if (aPix.Height() == 0)
600 // #i2237#
601 // Since BRUSH_SIZE alignment is outdated now, i use the
602 // former constant here directly
603 aPix.Height() -= 8;
607 aPix = PixelToLogic(aPix);
608 maWinPos.X() = aPix.Width();
609 maWinPos.Y() = aPix.Height();
610 Point aNewOrigin (-maWinPos.X(), -maWinPos.Y());
611 maWinPos += maViewOrigin;
613 if (!mpViewShell || !mpViewShell->GetDoc()->isTiledRendering())
615 MapMode aMap(GetMapMode());
616 aMap.SetOrigin(aNewOrigin);
617 SetMapMode(aMap);
622 * @returns X position of the visible area as fraction (< 1) of the whole
623 * working area.
625 double Window::GetVisibleX()
627 return ((double) maWinPos.X() / maViewSize.Width());
631 * @returns Y position of the visible area as fraction (< 1) of the whole
632 * working area.
634 double Window::GetVisibleY()
636 return ((double) maWinPos.Y() / maViewSize.Height());
640 * Set x and y position of the visible area as fraction (< 1) of the whole
641 * working area. Negative values are ignored.
643 void Window::SetVisibleXY(double fX, double fY)
645 long nOldX = maWinPos.X();
646 long nOldY = maWinPos.Y();
648 if ( fX >= 0 )
649 maWinPos.X() = (long) (fX * maViewSize.Width());
650 if ( fY >= 0 )
651 maWinPos.Y() = (long) (fY * maViewSize.Height());
652 UpdateMapOrigin(false);
653 Scroll(nOldX - maWinPos.X(), nOldY - maWinPos.Y(), SCROLL_CHILDREN);
654 Update();
658 * @returns width of the visible area in proportion to the width of the whole
659 * working area.
661 double Window::GetVisibleWidth()
663 Size aWinSize = PixelToLogic(GetOutputSizePixel());
664 if ( aWinSize.Width() > maViewSize.Width() )
665 aWinSize.Width() = maViewSize.Width();
666 return ((double) aWinSize.Width() / maViewSize.Width());
670 * @returns height of the visible area in proportion to the height of the whole
671 * working area.
673 double Window::GetVisibleHeight()
675 Size aWinSize = PixelToLogic(GetOutputSizePixel());
676 if ( aWinSize.Height() > maViewSize.Height() )
677 aWinSize.Height() = maViewSize.Height();
678 return ((double) aWinSize.Height() / maViewSize.Height());
682 * @returns width of a scroll column in proportion to the width of the whole
683 * working area.
685 double Window::GetScrlLineWidth()
687 return (GetVisibleWidth() * SCROLL_LINE_FACT);
691 * @returns height of a scroll column in proportion to the height of the whole
692 * working area.
694 double Window::GetScrlLineHeight()
696 return (GetVisibleHeight() * SCROLL_LINE_FACT);
700 * @returns width of a scroll page in proportion to the width of the whole
701 * working area.
703 double Window::GetScrlPageWidth()
705 return (GetVisibleWidth() * SCROLL_PAGE_FACT);
709 * @returns height of a scroll page in proportion to the height of the whole
710 * working area.
712 double Window::GetScrlPageHeight()
714 return (GetVisibleHeight() * SCROLL_PAGE_FACT);
718 * Deactivate window.
720 void Window::LoseFocus()
722 mnTicks = 0;
723 vcl::Window::LoseFocus ();
727 * Activate window.
729 void Window::GrabFocus()
731 mnTicks = 0;
732 vcl::Window::GrabFocus ();
735 void Window::DataChanged( const DataChangedEvent& rDCEvt )
737 vcl::Window::DataChanged( rDCEvt );
739 /* Omit PRINTER by all documents which are not using a printer.
740 Omit FONTS and FONTSUBSTITUTION if no text output is available or if the
741 document does not allow text. */
743 if ( (rDCEvt.GetType() == DataChangedEventType::PRINTER) ||
744 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
745 (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
746 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
747 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
748 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
750 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
751 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
753 // When the screen zoom factor has changed then reset the zoom
754 // factor of the frame to always display the whole page.
755 const AllSettings* pOldSettings = rDCEvt.GetOldSettings ();
756 const AllSettings& rNewSettings = GetSettings ();
757 if (pOldSettings && mpViewShell)
759 if (pOldSettings->GetStyleSettings().GetScreenZoom()
760 != rNewSettings.GetStyleSettings().GetScreenZoom())
762 mpViewShell->GetViewFrame()->GetDispatcher()->
763 Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
767 /* Rearrange or initiate Resize for scroll bars since the size of
768 the scroll bars my have changed. Within this, inside the resize-
769 handler, the size of the scroll bars will be asked from the
770 Settings. */
771 Resize();
773 /* Re-set data, which are from system control or from Settings. May
774 have to re-set more data since the resolution may also has
775 changed. */
776 if( mpViewShell )
778 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
779 SvtAccessibilityOptions aAccOptions;
780 DrawModeFlags nOutputMode;
781 sal_uInt16 nPreviewSlot;
783 if( rStyleSettings.GetHighContrastMode() )
784 nOutputMode = sd::OUTPUT_DRAWMODE_CONTRAST;
785 else
786 nOutputMode = sd::OUTPUT_DRAWMODE_COLOR;
788 if( rStyleSettings.GetHighContrastMode() && aAccOptions.GetIsForPagePreviews() )
789 nPreviewSlot = SID_PREVIEW_QUALITY_CONTRAST;
790 else
791 nPreviewSlot = SID_PREVIEW_QUALITY_COLOR;
793 if( mpViewShell->ISA( DrawViewShell ) )
795 SetDrawMode( nOutputMode );
796 mpViewShell->GetFrameView()->SetDrawMode( nOutputMode );
797 Invalidate();
800 // Overwrite window color for OutlineView
801 if( mpViewShell->ISA(OutlineViewShell ) )
803 svtools::ColorConfig aColorConfig;
804 const Color aDocColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
805 SetBackground( Wallpaper( aDocColor ) );
808 SfxRequest aReq( nPreviewSlot, SfxCallMode::SLOT, mpViewShell->GetDocSh()->GetDoc()->GetItemPool() );
809 mpViewShell->ExecReq( aReq );
810 mpViewShell->Invalidate();
811 mpViewShell->ArrangeGUIElements();
813 // re-create handles to show new outfit
814 if(mpViewShell->ISA(DrawViewShell))
816 mpViewShell->GetView()->AdjustMarkHdl();
821 if ( (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
822 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
823 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
825 /* Virtual devices, which also depends on the resolution or the
826 system control, should be updated. Otherwise, we should update
827 the virtual devices at least at DataChangedEventType::DISPLAY since some
828 systems allow to change the resolution and color depth during
829 runtime. Or the virtual devices have to be updated when the color
830 palette has changed since a different color matching can be used
831 when outputting. */
834 if ( rDCEvt.GetType() == DataChangedEventType::FONTS )
836 /* If the document provides font choose boxes, we have to update
837 them. I don't know how this looks like (also not really me, I
838 only translated the comment ;). We may can handle it global. We
839 have to discuss it with PB, but he is ill at the moment.
840 Before we handle it here, discuss it with PB and me. */
843 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
844 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) )
846 /* Do reformating since the fonts of the document may no longer
847 exist, or exist now, or are replaced with others. */
848 if( mpViewShell )
850 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
851 if( pDocSh )
852 pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
856 if ( rDCEvt.GetType() == DataChangedEventType::PRINTER )
858 /* I don't know how the handling should look like. Maybe we delete a
859 printer and look what we have to do. Maybe I have to add
860 something to the VCL, in case the used printer is deleted.
861 Otherwise I may recalculate the formatting here if the current
862 printer is destroyed. */
863 if( mpViewShell )
865 DrawDocShell* pDocSh = mpViewShell->GetDocSh();
866 if( pDocSh )
867 pDocSh->SetPrinter( pDocSh->GetPrinter( true ) );
871 // Update everything
872 Invalidate();
876 sal_Int8 Window::AcceptDrop( const AcceptDropEvent& rEvt )
878 sal_Int8 nRet = DND_ACTION_NONE;
880 if( mpViewShell && !mpViewShell->GetDocSh()->IsReadOnly() )
882 if( mpViewShell )
883 nRet = mpViewShell->AcceptDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
885 if (mbUseDropScroll && ! mpViewShell->ISA(OutlineViewShell))
886 DropScroll( rEvt.maPosPixel );
889 return nRet;
892 sal_Int8 Window::ExecuteDrop( const ExecuteDropEvent& rEvt )
894 sal_Int8 nRet = DND_ACTION_NONE;
896 if( mpViewShell )
898 nRet = mpViewShell->ExecuteDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
901 return nRet;
904 void Window::SetUseDropScroll (bool bUseDropScroll)
906 mbUseDropScroll = bUseDropScroll;
909 void Window::DropScroll(const Point& rMousePos)
911 short nDx = 0;
912 short nDy = 0;
914 Size aSize = GetOutputSizePixel();
916 if (aSize.Width() > SCROLL_SENSITIVE * 3)
918 if ( rMousePos.X() < SCROLL_SENSITIVE )
920 nDx = -1;
923 if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE )
925 nDx = 1;
929 if (aSize.Height() > SCROLL_SENSITIVE * 3)
931 if ( rMousePos.Y() < SCROLL_SENSITIVE )
933 nDy = -1;
936 if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE )
938 nDy = 1;
942 if ( (nDx || nDy) && (rMousePos.X()!=0 || rMousePos.Y()!=0 ) )
944 if (mnTicks > 20)
945 mpViewShell->ScrollLines(nDx, nDy);
946 else
947 mnTicks ++;
951 ::com::sun::star::uno::Reference<
952 ::com::sun::star::accessibility::XAccessible>
953 Window::CreateAccessible()
955 // If current viewshell is PresentationViewShell, just return empty because the correct ShowWin will be created later.
956 if (mpViewShell && mpViewShell->ISA(PresentationViewShell))
958 return vcl::Window::CreateAccessible ();
960 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc = GetAccessible(false);
961 if (xAcc.get())
963 return xAcc;
965 if (mpViewShell != NULL)
967 xAcc = mpViewShell->CreateAccessibleDocumentView (this);
968 SetAccessible(xAcc);
969 return xAcc;
971 else
973 OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
974 return vcl::Window::CreateAccessible ();
978 OUString Window::GetSurroundingText() const
980 if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
981 return OUString();
982 else if ( mpViewShell->GetView()->IsTextEdit() )
984 OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
985 return pOLV->GetEditView().GetSurroundingText();
987 return OUString();
990 Selection Window::GetSurroundingTextSelection() const
992 if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
994 return Selection( 0, 0 );
996 else if ( mpViewShell->GetView()->IsTextEdit() )
998 OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
999 return pOLV->GetEditView().GetSurroundingTextSelection();
1001 else
1003 return Selection( 0, 0 );
1007 void Window::LogicInvalidate(const Rectangle* pRectangle)
1009 OString sRectangle;
1010 if (!pRectangle)
1011 sRectangle = "EMPTY";
1012 else
1014 Rectangle aRectangle(*pRectangle);
1015 if (GetMapMode().GetMapUnit() == MAP_100TH_MM)
1016 aRectangle = OutputDevice::LogicToLogic(aRectangle, MAP_100TH_MM, MAP_TWIP);
1017 sRectangle = aRectangle.toString();
1019 mpViewShell->GetDoc()->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
1022 } // end of namespace sd
1024 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */