Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "Window.hxx"
22 : #include <sfx2/dispatch.hxx>
23 : #include <sfx2/request.hxx>
24 :
25 : #include <sfx2/viewfrm.hxx>
26 : #include <svx/svxids.hrc>
27 :
28 : #include <editeng/outliner.hxx>
29 : #include <editeng/editview.hxx>
30 :
31 : #include "app.hrc"
32 : #include "helpids.h"
33 : #include "ViewShell.hxx"
34 : #include "DrawViewShell.hxx"
35 : #include "View.hxx"
36 : #include "FrameView.hxx"
37 : #include "OutlineViewShell.hxx"
38 : #include "drawdoc.hxx"
39 : #include "AccessibleDrawDocumentView.hxx"
40 : #include "WindowUpdater.hxx"
41 :
42 : namespace sd {
43 :
44 : #define SCROLL_LINE_FACT 0.05 ///< factor for line scrolling
45 : #define SCROLL_PAGE_FACT 0.5 ///< factor for page scrolling
46 : #define SCROLL_SENSITIVE 20 ///< sensitive area in pixel
47 : #define ZOOM_MULTIPLICATOR 10000 ///< multiplier to avoid rounding errors
48 : #define MIN_ZOOM 5 ///< minimal zoom factor
49 : #define MAX_ZOOM 3000 ///< maximal zoom factor
50 :
51 :
52 :
53 143 : Window::Window(::Window* pParent)
54 : : ::Window(pParent, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
55 : DropTargetHelper( this ),
56 : mpShareWin(NULL),
57 : maWinPos(0, 0), // precautionary; but the values should be set
58 : maViewOrigin(0, 0), // again from the owner of the window
59 : maViewSize(1000, 1000),
60 : maPrevSize(-1,-1),
61 : mnMinZoom(MIN_ZOOM),
62 : mnMaxZoom(MAX_ZOOM),
63 : mbMinZoomAutoCalc(false),
64 : mbCalcMinZoomByMinSide(true),
65 : mbCenterAllowed(true),
66 : mnTicks (0),
67 : mbDraggedFrom(false),
68 : mpViewShell(NULL),
69 143 : mbUseDropScroll (true)
70 : {
71 143 : SetDialogControlFlags( WINDOW_DLGCTRL_RETURN | WINDOW_DLGCTRL_WANTFOCUS );
72 :
73 143 : MapMode aMap(GetMapMode());
74 143 : aMap.SetMapUnit(MAP_100TH_MM);
75 143 : SetMapMode(aMap);
76 :
77 : // whit it, the ::WindowColor is used in the slide mode
78 143 : SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetWindowColor() ) );
79 :
80 : // adjust contrast mode initially
81 143 : bool bUseContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
82 : SetDrawMode( bUseContrast
83 : ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
84 143 : : ViewShell::OUTPUT_DRAWMODE_COLOR );
85 :
86 : // set Help ID
87 : // SetHelpId(HID_SD_WIN_DOCUMENT);
88 143 : SetUniqueId(HID_SD_WIN_DOCUMENT);
89 :
90 : // #i78183# Added after discussed with AF
91 143 : EnableRTL(sal_False);
92 143 : }
93 :
94 :
95 429 : Window::~Window (void)
96 : {
97 143 : if (mpViewShell != NULL)
98 : {
99 0 : WindowUpdater* pWindowUpdater = mpViewShell->GetWindowUpdater();
100 0 : if (pWindowUpdater != NULL)
101 0 : pWindowUpdater->UnregisterWindow (this);
102 : }
103 286 : }
104 :
105 :
106 :
107 :
108 351 : void Window::SetViewShell (ViewShell* pViewSh)
109 : {
110 351 : WindowUpdater* pWindowUpdater = NULL;
111 : // Unregister at device updater of old view shell.
112 351 : if (mpViewShell != NULL)
113 : {
114 208 : pWindowUpdater = mpViewShell->GetWindowUpdater();
115 208 : if (pWindowUpdater != NULL)
116 208 : pWindowUpdater->UnregisterWindow (this);
117 : }
118 :
119 351 : mpViewShell = pViewSh;
120 :
121 : // Register at device updater of new view shell
122 351 : if (mpViewShell != NULL)
123 : {
124 208 : pWindowUpdater = mpViewShell->GetWindowUpdater();
125 208 : if (pWindowUpdater != NULL)
126 208 : pWindowUpdater->RegisterWindow (this);
127 : }
128 351 : }
129 :
130 974 : void Window::CalcMinZoom()
131 : {
132 : // Are we entitled to change the minimal zoom factor?
133 974 : if ( mbMinZoomAutoCalc )
134 : {
135 : // Get current zoom factor.
136 0 : long nZoom = GetZoom();
137 :
138 0 : if ( mpShareWin )
139 : {
140 0 : mpShareWin->CalcMinZoom();
141 0 : mnMinZoom = mpShareWin->mnMinZoom;
142 : }
143 : else
144 : {
145 : // Get the rectangle of the output area in logical coordinates
146 : // and calculate the scaling factors that would lead to the view
147 : // area (also called application area) to completely fill the
148 : // window.
149 0 : Size aWinSize = PixelToLogic(GetOutputSizePixel());
150 0 : sal_uLong nX = (sal_uLong) ((double) aWinSize.Width()
151 0 : * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Width());
152 0 : sal_uLong nY = (sal_uLong) ((double) aWinSize.Height()
153 0 : * (double) ZOOM_MULTIPLICATOR / (double) maViewSize.Height());
154 :
155 : // Decide whether to take the larger or the smaller factor.
156 : sal_uLong nFact;
157 0 : if (mbCalcMinZoomByMinSide)
158 0 : nFact = std::min(nX, nY);
159 : else
160 0 : nFact = std::max(nX, nY);
161 :
162 : // The factor is tansfomed according to the current zoom factor.
163 0 : nFact = nFact * nZoom / ZOOM_MULTIPLICATOR;
164 0 : mnMinZoom = std::max((sal_uInt16) MIN_ZOOM, (sal_uInt16) nFact);
165 : }
166 : // If the current zoom factor is smaller than the calculated minimal
167 : // zoom factor then set the new minimal factor as the current zoom
168 : // factor.
169 0 : if ( nZoom < (long) mnMinZoom )
170 0 : SetZoomFactor(mnMinZoom);
171 : }
172 974 : }
173 :
174 :
175 :
176 :
177 0 : void Window::SetMinZoom (long int nMin)
178 : {
179 0 : mnMinZoom = (sal_uInt16) nMin;
180 0 : }
181 :
182 :
183 :
184 :
185 139 : long Window::GetMinZoom (void) const
186 : {
187 139 : return mnMinZoom;
188 : }
189 :
190 :
191 :
192 :
193 0 : void Window::SetMaxZoom (long int nMax)
194 : {
195 0 : mnMaxZoom = (sal_uInt16) nMax;
196 0 : }
197 :
198 :
199 :
200 :
201 139 : long Window::GetMaxZoom (void) const
202 : {
203 139 : return mnMaxZoom;
204 : }
205 :
206 :
207 :
208 :
209 1123 : long Window::GetZoom (void) const
210 : {
211 1123 : if( GetMapMode().GetScaleX().GetDenominator() )
212 : {
213 1123 : return GetMapMode().GetScaleX().GetNumerator() * 100L
214 1123 : / GetMapMode().GetScaleX().GetDenominator();
215 : }
216 : else
217 : {
218 0 : return 0;
219 : }
220 : }
221 :
222 :
223 :
224 :
225 :
226 522 : void Window::Resize()
227 : {
228 522 : ::Window::Resize();
229 522 : CalcMinZoom();
230 :
231 522 : if( mpViewShell && mpViewShell->GetViewFrame() )
232 522 : mpViewShell->GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER );
233 522 : }
234 :
235 :
236 1410 : void Window::PrePaint()
237 : {
238 1410 : if ( mpViewShell )
239 1410 : mpViewShell->PrePaint();
240 1410 : }
241 :
242 :
243 793 : void Window::Paint(const Rectangle& rRect)
244 : {
245 793 : if ( mpViewShell )
246 793 : mpViewShell->Paint(rRect, this);
247 793 : }
248 :
249 :
250 0 : void Window::KeyInput(const KeyEvent& rKEvt)
251 : {
252 0 : if (!(mpViewShell && mpViewShell->KeyInput(rKEvt, this)))
253 : {
254 0 : if (mpViewShell && rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
255 : {
256 0 : mpViewShell->GetViewShell()->Escape();
257 : }
258 : else
259 : {
260 0 : ::Window::KeyInput(rKEvt);
261 : }
262 : }
263 0 : }
264 :
265 :
266 0 : void Window::MouseButtonDown(const MouseEvent& rMEvt)
267 : {
268 0 : if ( mpViewShell )
269 0 : mpViewShell->MouseButtonDown(rMEvt, this);
270 0 : }
271 :
272 :
273 0 : void Window::MouseMove(const MouseEvent& rMEvt)
274 : {
275 0 : if ( mpViewShell )
276 0 : mpViewShell->MouseMove(rMEvt, this);
277 0 : }
278 :
279 :
280 0 : void Window::MouseButtonUp(const MouseEvent& rMEvt)
281 : {
282 0 : mnTicks = 0;
283 :
284 0 : if ( mpViewShell )
285 0 : mpViewShell->MouseButtonUp(rMEvt, this);
286 0 : }
287 :
288 :
289 0 : void Window::Command(const CommandEvent& rCEvt)
290 : {
291 0 : if ( mpViewShell )
292 0 : mpViewShell->Command(rCEvt, this);
293 0 : }
294 :
295 :
296 381 : long Window::Notify( NotifyEvent& rNEvt )
297 : {
298 381 : long nResult = sal_False;
299 381 : if ( mpViewShell )
300 : {
301 381 : nResult = mpViewShell->Notify(rNEvt, this);
302 : }
303 381 : if( !nResult )
304 381 : nResult = ::Window::Notify( rNEvt );
305 :
306 381 : return nResult;
307 : }
308 :
309 :
310 0 : void Window::RequestHelp(const HelpEvent& rEvt)
311 : {
312 0 : if ( mpViewShell )
313 : {
314 0 : if( !mpViewShell->RequestHelp( rEvt, this) )
315 0 : ::Window::RequestHelp( rEvt );
316 : }
317 : else
318 0 : ::Window::RequestHelp( rEvt );
319 0 : }
320 :
321 :
322 :
323 :
324 430 : Point Window::GetWinViewPos (void) const
325 : {
326 430 : return maWinPos;
327 : }
328 :
329 :
330 :
331 :
332 47 : Point Window::GetViewOrigin (void) const
333 : {
334 47 : return maViewOrigin;
335 : }
336 :
337 :
338 :
339 :
340 47 : Size Window::GetViewSize (void) const
341 : {
342 47 : return maViewSize;
343 : }
344 :
345 :
346 :
347 :
348 : /**
349 : * Set the position of the upper left corner from the visible area of the
350 : * window.
351 : */
352 298 : void Window::SetWinViewPos(const Point& rPnt)
353 : {
354 298 : maWinPos = rPnt;
355 298 : }
356 :
357 : /**
358 : * Set origin of the representation in respect to the whole working area.
359 : */
360 452 : void Window::SetViewOrigin(const Point& rPnt)
361 : {
362 452 : maViewOrigin = rPnt;
363 452 : }
364 :
365 : /**
366 : * Set size of the whole working area which can be seen with the window.
367 : */
368 452 : void Window::SetViewSize(const Size& rSize)
369 : {
370 452 : maViewSize = rSize;
371 452 : CalcMinZoom();
372 452 : }
373 :
374 :
375 :
376 :
377 221 : void Window::SetCenterAllowed (bool bIsAllowed)
378 : {
379 221 : mbCenterAllowed = bIsAllowed;
380 221 : }
381 :
382 :
383 :
384 :
385 430 : long Window::SetZoomFactor(long nZoom)
386 : {
387 : // Clip the zoom factor to the valid range marked by nMinZoom as
388 : // calculated by CalcMinZoom() and the constant MAX_ZOOM.
389 430 : if ( nZoom > MAX_ZOOM )
390 0 : nZoom = MAX_ZOOM;
391 430 : if ( nZoom < (long) mnMinZoom )
392 0 : nZoom = mnMinZoom;
393 :
394 : // Set the zoom factor at the window's map mode.
395 430 : MapMode aMap(GetMapMode());
396 430 : aMap.SetScaleX(Fraction(nZoom, 100));
397 430 : aMap.SetScaleY(Fraction(nZoom, 100));
398 430 : SetMapMode(aMap);
399 :
400 : // invalidate previous size - it was relative to the old scaling
401 430 : maPrevSize = Size(-1,-1);
402 :
403 : // Update the map mode's origin (to what effect?).
404 430 : UpdateMapOrigin();
405 :
406 : // Update the view's snapping to the new zoom factor.
407 430 : if ( mpViewShell && mpViewShell->ISA(DrawViewShell) )
408 430 : ((DrawViewShell*) mpViewShell)->GetView()->
409 860 : RecalcLogicSnapMagnetic(*this);
410 :
411 : // Return the zoom factor just in case it has been changed above to lie
412 : // inside the valid range.
413 430 : return nZoom;
414 : }
415 :
416 215 : void Window::SetZoomIntegral(long nZoom)
417 : {
418 : // Clip the zoom factor to the valid range marked by nMinZoom as
419 : // previously calculated by <member>CalcMinZoom()</member> and the
420 : // MAX_ZOOM constant.
421 215 : if ( nZoom > MAX_ZOOM )
422 0 : nZoom = MAX_ZOOM;
423 215 : if ( nZoom < (long) mnMinZoom )
424 0 : nZoom = mnMinZoom;
425 :
426 : // Calculate the window's new origin.
427 215 : Size aSize = PixelToLogic(GetOutputSizePixel());
428 215 : long nW = aSize.Width() * GetZoom() / nZoom;
429 215 : long nH = aSize.Height() * GetZoom() / nZoom;
430 215 : maWinPos.X() += (aSize.Width() - nW) / 2;
431 215 : maWinPos.Y() += (aSize.Height() - nH) / 2;
432 215 : if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
433 215 : if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
434 :
435 : // Finally update this window's map mode to the given zoom factor that
436 : // has been clipped to the valid range.
437 215 : SetZoomFactor(nZoom);
438 215 : }
439 :
440 139 : long Window::GetZoomForRect( const Rectangle& rZoomRect )
441 : {
442 139 : long nRetZoom = 100;
443 :
444 139 : if( (rZoomRect.GetWidth() != 0) && (rZoomRect.GetHeight() != 0))
445 : {
446 : // Calculate the scale factors which will lead to the given
447 : // rectangle being fully visible (when translated accordingly) as
448 : // large as possible in the output area independently in both
449 : // coordinate directions .
450 139 : sal_uLong nX(0L);
451 139 : sal_uLong nY(0L);
452 :
453 139 : const Size aWinSize( PixelToLogic(GetOutputSizePixel()) );
454 139 : if(rZoomRect.GetHeight())
455 : {
456 139 : nX = (sal_uLong) ((double) aWinSize.Height()
457 139 : * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
458 : }
459 :
460 139 : if(rZoomRect.GetWidth())
461 : {
462 139 : nY = (sal_uLong) ((double) aWinSize.Width()
463 139 : * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
464 : }
465 :
466 : // Use the smaller one of both so that the zoom rectangle will be
467 : // fully visible with respect to both coordinate directions.
468 139 : sal_uLong nFact = std::min(nX, nY);
469 :
470 : // Transform the current zoom factor so that it leads to the desired
471 : // scaling.
472 139 : nRetZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
473 :
474 : // Calculate the new origin.
475 139 : if ( nFact == 0 )
476 : {
477 : // Don't change anything if the scale factor is degenrate.
478 61 : nRetZoom = GetZoom();
479 : }
480 : else
481 : {
482 : // Clip the zoom factor to the valid range marked by nMinZoom as
483 : // previously calculated by <member>CalcMinZoom()</member> and the
484 : // MAX_ZOOM constant.
485 78 : if ( nRetZoom > MAX_ZOOM )
486 0 : nRetZoom = MAX_ZOOM;
487 78 : if ( nRetZoom < (long) mnMinZoom )
488 0 : nRetZoom = mnMinZoom;
489 : }
490 : }
491 :
492 139 : return nRetZoom;
493 : }
494 :
495 : /** Recalculate the zoom factor and translation so that the given rectangle
496 : is displayed centered and as large as possible while still being fully
497 : visible in the window.
498 : */
499 215 : long Window::SetZoomRect (const Rectangle& rZoomRect)
500 : {
501 215 : long nNewZoom = 100;
502 :
503 215 : if (rZoomRect.GetWidth() == 0 || rZoomRect.GetHeight() == 0)
504 : {
505 : // The given rectangle is degenerate. Use the default zoom factor
506 : // (above) of 100%.
507 0 : SetZoomIntegral(nNewZoom);
508 : }
509 : else
510 : {
511 215 : Point aPos = rZoomRect.TopLeft();
512 : // Transform the output area from pixel coordinates into logical
513 : // coordinates.
514 215 : Size aWinSize = PixelToLogic(GetOutputSizePixel());
515 : // Paranoia! The degenerate case of zero width or height has been
516 : // taken care of above.
517 : DBG_ASSERT(rZoomRect.GetWidth(), "ZoomRect-Width = 0!");
518 : DBG_ASSERT(rZoomRect.GetHeight(), "ZoomRect-Height = 0!");
519 :
520 : // Calculate the scale factors which will lead to the given
521 : // rectangle being fully visible (when translated accordingly) as
522 : // large as possible in the output area independently in both
523 : // coordinate directions .
524 215 : sal_uLong nX(0L);
525 215 : sal_uLong nY(0L);
526 :
527 215 : if(rZoomRect.GetHeight())
528 : {
529 215 : nX = (sal_uLong) ((double) aWinSize.Height()
530 215 : * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetHeight());
531 : }
532 :
533 215 : if(rZoomRect.GetWidth())
534 : {
535 215 : nY = (sal_uLong) ((double) aWinSize.Width()
536 215 : * (double) ZOOM_MULTIPLICATOR / (double) rZoomRect.GetWidth());
537 : }
538 :
539 : // Use the smaller one of both so that the zoom rectangle will be
540 : // fully visible with respect to both coordinate directions.
541 215 : sal_uLong nFact = std::min(nX, nY);
542 :
543 : // Transform the current zoom factor so that it leads to the desired
544 : // scaling.
545 215 : long nZoom = nFact * GetZoom() / ZOOM_MULTIPLICATOR;
546 :
547 : // Calculate the new origin.
548 215 : if ( nFact == 0 )
549 : {
550 : // Don't change anything if the scale factor is degenrate.
551 0 : nNewZoom = GetZoom();
552 : }
553 : else
554 : {
555 : // Calculate the new window position that centers the given
556 : // rectangle on the screen.
557 215 : if ( nZoom > MAX_ZOOM )
558 0 : nFact = nFact * MAX_ZOOM / nZoom;
559 :
560 215 : maWinPos = maViewOrigin + aPos;
561 :
562 215 : aWinSize.Width() = (long) ((double) aWinSize.Width() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
563 215 : maWinPos.X() += (rZoomRect.GetWidth() - aWinSize.Width()) / 2;
564 215 : aWinSize.Height() = (long) ((double) aWinSize.Height() * (double) ZOOM_MULTIPLICATOR / (double) nFact);
565 215 : maWinPos.Y() += (rZoomRect.GetHeight() - aWinSize.Height()) / 2;
566 :
567 215 : if ( maWinPos.X() < 0 ) maWinPos.X() = 0;
568 215 : if ( maWinPos.Y() < 0 ) maWinPos.Y() = 0;
569 :
570 : // Adapt the window's map mode to the new zoom factor.
571 215 : nNewZoom = SetZoomFactor(nZoom);
572 : }
573 : }
574 :
575 215 : return(nNewZoom);
576 : }
577 :
578 :
579 :
580 :
581 0 : void Window::SetMinZoomAutoCalc (bool bAuto)
582 : {
583 0 : mbMinZoomAutoCalc = bAuto;
584 0 : }
585 :
586 :
587 :
588 :
589 : /**
590 : * Calculate and set new MapMode origin.
591 : * If aWinPos.X()/Y() == -1, then we center the corresponding position (e.g. for
592 : * initialization).
593 : */
594 894 : void Window::UpdateMapOrigin(sal_Bool bInvalidate)
595 : {
596 894 : sal_Bool bChanged = sal_False;
597 894 : const Size aWinSize = PixelToLogic(GetOutputSizePixel());
598 :
599 894 : if ( mbCenterAllowed )
600 : {
601 880 : if( maPrevSize != Size(-1,-1) )
602 : {
603 : // keep view centered around current pos, when window
604 : // resizes
605 385 : maWinPos.X() -= (aWinSize.Width() - maPrevSize.Width()) / 2;
606 385 : maWinPos.Y() -= (aWinSize.Height() - maPrevSize.Height()) / 2;
607 385 : bChanged = sal_True;
608 : }
609 :
610 880 : if ( maWinPos.X() > maViewSize.Width() - aWinSize.Width() )
611 : {
612 0 : maWinPos.X() = maViewSize.Width() - aWinSize.Width();
613 0 : bChanged = sal_True;
614 : }
615 880 : if ( maWinPos.Y() > maViewSize.Height() - aWinSize.Height() )
616 : {
617 0 : maWinPos.Y() = maViewSize.Height() - aWinSize.Height();
618 0 : bChanged = sal_True;
619 : }
620 880 : if ( aWinSize.Width() > maViewSize.Width() || maWinPos.X() < 0 )
621 : {
622 83 : maWinPos.X() = maViewSize.Width() / 2 - aWinSize.Width() / 2;
623 83 : bChanged = sal_True;
624 : }
625 880 : if ( aWinSize.Height() > maViewSize.Height() || maWinPos.Y() < 0 )
626 : {
627 83 : maWinPos.Y() = maViewSize.Height() / 2 - aWinSize.Height() / 2;
628 83 : bChanged = sal_True;
629 : }
630 : }
631 :
632 894 : UpdateMapMode ();
633 :
634 894 : maPrevSize = aWinSize;
635 :
636 894 : if (bChanged && bInvalidate)
637 448 : Invalidate();
638 894 : }
639 :
640 :
641 :
642 :
643 894 : void Window::UpdateMapMode (void)
644 : {
645 894 : maWinPos -= maViewOrigin;
646 894 : Size aPix(maWinPos.X(), maWinPos.Y());
647 894 : aPix = LogicToPixel(aPix);
648 : // Size has to be a multiple of BRUSH_SIZE due to the correct depiction of
649 : // pattern
650 : // #i2237#
651 : // removed old stuff here which still forced zoom to be
652 : // %BRUSH_SIZE which is outdated now
653 :
654 894 : if (mpViewShell && mpViewShell->ISA(DrawViewShell))
655 : {
656 : // page should not "stick" to the window border
657 880 : if (aPix.Width() == 0)
658 : {
659 : // #i2237#
660 : // Since BRUSH_SIZE alignment is outdated now, i use the
661 : // former constant here directly
662 0 : aPix.Width() -= 8;
663 : }
664 880 : if (aPix.Height() == 0)
665 : {
666 : // #i2237#
667 : // Since BRUSH_SIZE alignment is outdated now, i use the
668 : // former constant here directly
669 0 : aPix.Height() -= 8;
670 : }
671 : }
672 :
673 894 : aPix = PixelToLogic(aPix);
674 894 : maWinPos.X() = aPix.Width();
675 894 : maWinPos.Y() = aPix.Height();
676 894 : Point aNewOrigin (-maWinPos.X(), -maWinPos.Y());
677 894 : maWinPos += maViewOrigin;
678 :
679 894 : MapMode aMap(GetMapMode());
680 894 : aMap.SetOrigin(aNewOrigin);
681 894 : SetMapMode(aMap);
682 894 : }
683 :
684 :
685 :
686 :
687 : /**
688 : * @returns X position of the visible area as fraction (< 1) of the whole
689 : * working area.
690 : */
691 601 : double Window::GetVisibleX()
692 : {
693 601 : return ((double) maWinPos.X() / maViewSize.Width());
694 : }
695 :
696 : /**
697 : * @returns Y position of the visible area as fraction (< 1) of the whole
698 : * working area.
699 : */
700 601 : double Window::GetVisibleY()
701 : {
702 601 : return ((double) maWinPos.Y() / maViewSize.Height());
703 : }
704 :
705 : /**
706 : * Set x and y position of the visible area as fraction (< 1) of the whole
707 : * working area. Negative values are ignored.
708 : */
709 2 : void Window::SetVisibleXY(double fX, double fY)
710 : {
711 2 : long nOldX = maWinPos.X();
712 2 : long nOldY = maWinPos.Y();
713 :
714 2 : if ( fX >= 0 )
715 2 : maWinPos.X() = (long) (fX * maViewSize.Width());
716 2 : if ( fY >= 0 )
717 0 : maWinPos.Y() = (long) (fY * maViewSize.Height());
718 2 : UpdateMapOrigin(sal_False);
719 2 : Scroll(nOldX - maWinPos.X(), nOldY - maWinPos.Y(), SCROLL_CHILDREN);
720 2 : Update();
721 2 : }
722 :
723 : /**
724 : * @returns width of the visible area in proportion to the width of the whole
725 : * working area.
726 : */
727 1344 : double Window::GetVisibleWidth()
728 : {
729 1344 : Size aWinSize = PixelToLogic(GetOutputSizePixel());
730 1344 : if ( aWinSize.Width() > maViewSize.Width() )
731 0 : aWinSize.Width() = maViewSize.Width();
732 1344 : return ((double) aWinSize.Width() / maViewSize.Width());
733 : }
734 :
735 : /**
736 : * @returns height of the visible area in proportion to the height of the whole
737 : * working area.
738 : */
739 1792 : double Window::GetVisibleHeight()
740 : {
741 1792 : Size aWinSize = PixelToLogic(GetOutputSizePixel());
742 1792 : if ( aWinSize.Height() > maViewSize.Height() )
743 0 : aWinSize.Height() = maViewSize.Height();
744 1792 : return ((double) aWinSize.Height() / maViewSize.Height());
745 : }
746 :
747 : /**
748 : * @returns width of a scroll column in proportion to the width of the whole
749 : * working area.
750 : */
751 448 : double Window::GetScrlLineWidth()
752 : {
753 448 : return (GetVisibleWidth() * SCROLL_LINE_FACT);
754 : }
755 :
756 : /**
757 : * @returns height of a scroll column in proportion to the height of the whole
758 : * working area.
759 : */
760 448 : double Window::GetScrlLineHeight()
761 : {
762 448 : return (GetVisibleHeight() * SCROLL_LINE_FACT);
763 : }
764 :
765 : /**
766 : * @returns width of a scroll page in proportion to the width of the whole
767 : * working area.
768 : */
769 448 : double Window::GetScrlPageWidth()
770 : {
771 448 : return (GetVisibleWidth() * SCROLL_PAGE_FACT);
772 : }
773 :
774 : /**
775 : * @returns height of a scroll page in proportion to the height of the whole
776 : * working area.
777 : */
778 448 : double Window::GetScrlPageHeight()
779 : {
780 448 : return (GetVisibleHeight() * SCROLL_PAGE_FACT);
781 : }
782 :
783 : /**
784 : * Deactivate window.
785 : */
786 0 : void Window::LoseFocus()
787 : {
788 0 : mnTicks = 0;
789 0 : ::Window::LoseFocus ();
790 0 : }
791 :
792 : /**
793 : * Activate window.
794 : */
795 0 : void Window::GrabFocus()
796 : {
797 0 : mnTicks = 0;
798 0 : ::Window::GrabFocus ();
799 0 : }
800 :
801 :
802 :
803 0 : void Window::DataChanged( const DataChangedEvent& rDCEvt )
804 : {
805 0 : ::Window::DataChanged( rDCEvt );
806 :
807 : /* Omit PRINTER by all documents which are not using a printer.
808 : Omit FONTS and FONTSUBSTITUTION if no text output is available or if the
809 : document does not allow text. */
810 :
811 0 : if ( (rDCEvt.GetType() == DATACHANGED_PRINTER) ||
812 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
813 0 : (rDCEvt.GetType() == DATACHANGED_FONTS) ||
814 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
815 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
816 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
817 : {
818 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
819 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
820 : {
821 : // When the screen zoom factor has changed then reset the zoom
822 : // factor of the frame to always display the whole page.
823 0 : const AllSettings* pOldSettings = rDCEvt.GetOldSettings ();
824 0 : const AllSettings& rNewSettings = GetSettings ();
825 0 : if (pOldSettings)
826 0 : if (pOldSettings->GetStyleSettings().GetScreenZoom()
827 0 : != rNewSettings.GetStyleSettings().GetScreenZoom())
828 : mpViewShell->GetViewFrame()->GetDispatcher()->
829 0 : Execute(SID_SIZE_PAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
830 :
831 : /* Rearrange or initiate Resize for scroll bars since the size of
832 : the scroll bars my have changed. Within this, inside the resize-
833 : handler, the size of the scroll bars will be asked from the
834 : Settings. */
835 0 : Resize();
836 :
837 : /* Re-set data, which are from system control or from Settings. May
838 : have to re-set more data since the resolution may also has
839 : changed. */
840 0 : if( mpViewShell )
841 : {
842 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
843 0 : SvtAccessibilityOptions aAccOptions;
844 : sal_uLong nOutputMode;
845 : sal_uInt16 nPreviewSlot;
846 :
847 0 : if( rStyleSettings.GetHighContrastMode() )
848 0 : nOutputMode = ViewShell::OUTPUT_DRAWMODE_CONTRAST;
849 : else
850 0 : nOutputMode = ViewShell::OUTPUT_DRAWMODE_COLOR;
851 :
852 0 : if( rStyleSettings.GetHighContrastMode() && aAccOptions.GetIsForPagePreviews() )
853 0 : nPreviewSlot = SID_PREVIEW_QUALITY_CONTRAST;
854 : else
855 0 : nPreviewSlot = SID_PREVIEW_QUALITY_COLOR;
856 :
857 0 : if( mpViewShell->ISA( DrawViewShell ) )
858 : {
859 0 : SetDrawMode( nOutputMode );
860 0 : mpViewShell->GetFrameView()->SetDrawMode( nOutputMode );
861 0 : Invalidate();
862 : }
863 :
864 : // Overwrite window color for OutlineView
865 0 : if( mpViewShell->ISA(OutlineViewShell ) )
866 : {
867 0 : svtools::ColorConfig aColorConfig;
868 0 : const Color aDocColor( aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor );
869 0 : SetBackground( Wallpaper( aDocColor ) );
870 : }
871 :
872 0 : SfxRequest aReq( nPreviewSlot, 0, mpViewShell->GetDocSh()->GetDoc()->GetItemPool() );
873 0 : mpViewShell->ExecReq( aReq );
874 0 : mpViewShell->Invalidate();
875 0 : mpViewShell->ArrangeGUIElements();
876 :
877 : // re-create handles to show new outfit
878 0 : if(mpViewShell->ISA(DrawViewShell))
879 : {
880 0 : mpViewShell->GetView()->AdjustMarkHdl();
881 0 : }
882 : }
883 : }
884 :
885 0 : if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
886 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
887 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
888 : {
889 : /* Virtual devices, which also depends on the resolution or the
890 : system control, should be updated. Otherwise, we should update
891 : the virtual devices at least at DATACHANGED_DISPLAY since some
892 : systems allow to change the resolution and color depth during
893 : runtime. Or the virtual devices have to be updated when the color
894 : palette has changed since a different color matching can be used
895 : when outputting. */
896 : }
897 :
898 0 : if ( rDCEvt.GetType() == DATACHANGED_FONTS )
899 : {
900 : /* If the document provides font choose boxes, we have to update
901 : them. I don't know how this looks like (also not really me, I
902 : only translated the comment ;). We may can handle it global. We
903 : have to discuss it with PB, but he is ill at the moment.
904 : Before we handle it here, discuss it with PB and me. */
905 : }
906 :
907 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
908 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) )
909 : {
910 : /* Do reformating since the fonts of the document may no longer
911 : exist, or exist now, or are replaced with others. */
912 0 : if( mpViewShell )
913 : {
914 0 : DrawDocShell* pDocSh = mpViewShell->GetDocSh();
915 0 : if( pDocSh )
916 0 : pDocSh->SetPrinter( pDocSh->GetPrinter( sal_True ) );
917 : }
918 : }
919 :
920 0 : if ( rDCEvt.GetType() == DATACHANGED_PRINTER )
921 : {
922 : /* I don't know how the handling should look like. Maybe we delete a
923 : printer and look what we have to do. Maybe I have to add
924 : something to the VCL, in case the used printer is deleted.
925 : Otherwise I may recalculate the formatting here if the current
926 : printer is destroyed. */
927 0 : if( mpViewShell )
928 : {
929 0 : DrawDocShell* pDocSh = mpViewShell->GetDocSh();
930 0 : if( pDocSh )
931 0 : pDocSh->SetPrinter( pDocSh->GetPrinter( sal_True ) );
932 : }
933 : }
934 :
935 : // Update everything
936 0 : Invalidate();
937 : }
938 0 : }
939 :
940 :
941 :
942 :
943 :
944 0 : sal_Int8 Window::AcceptDrop( const AcceptDropEvent& rEvt )
945 : {
946 0 : sal_Int8 nRet = DND_ACTION_NONE;
947 :
948 0 : if( mpViewShell && !mpViewShell->GetDocSh()->IsReadOnly() )
949 : {
950 0 : if( mpViewShell )
951 0 : nRet = mpViewShell->AcceptDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
952 :
953 0 : if (mbUseDropScroll && ! mpViewShell->ISA(OutlineViewShell))
954 0 : DropScroll( rEvt.maPosPixel );
955 : }
956 :
957 0 : return nRet;
958 : }
959 :
960 :
961 0 : sal_Int8 Window::ExecuteDrop( const ExecuteDropEvent& rEvt )
962 : {
963 0 : sal_Int8 nRet = DND_ACTION_NONE;
964 :
965 0 : if( mpViewShell )
966 : {
967 0 : nRet = mpViewShell->ExecuteDrop( rEvt, *this, this, SDRPAGE_NOTFOUND, SDRLAYER_NOTFOUND );
968 : }
969 :
970 0 : return nRet;
971 : }
972 :
973 :
974 :
975 :
976 65 : void Window::SetUseDropScroll (bool bUseDropScroll)
977 : {
978 65 : mbUseDropScroll = bUseDropScroll;
979 65 : }
980 :
981 :
982 :
983 :
984 :
985 0 : void Window::DropScroll(const Point& rMousePos)
986 : {
987 0 : short nDx = 0;
988 0 : short nDy = 0;
989 :
990 0 : Size aSize = GetOutputSizePixel();
991 :
992 0 : if (aSize.Width() > SCROLL_SENSITIVE * 3)
993 : {
994 0 : if ( rMousePos.X() < SCROLL_SENSITIVE )
995 : {
996 0 : nDx = -1;
997 : }
998 :
999 0 : if ( rMousePos.X() >= aSize.Width() - SCROLL_SENSITIVE )
1000 : {
1001 0 : nDx = 1;
1002 : }
1003 : }
1004 :
1005 0 : if (aSize.Height() > SCROLL_SENSITIVE * 3)
1006 : {
1007 0 : if ( rMousePos.Y() < SCROLL_SENSITIVE )
1008 : {
1009 0 : nDy = -1;
1010 : }
1011 :
1012 0 : if ( rMousePos.Y() >= aSize.Height() - SCROLL_SENSITIVE )
1013 : {
1014 0 : nDy = 1;
1015 : }
1016 : }
1017 :
1018 0 : if ( (nDx || nDy) && (rMousePos.X()!=0 || rMousePos.Y()!=0 ) )
1019 : {
1020 0 : if (mnTicks > 20)
1021 0 : mpViewShell->ScrollLines(nDx, nDy);
1022 : else
1023 0 : mnTicks ++;
1024 : }
1025 0 : }
1026 :
1027 :
1028 :
1029 :
1030 : ::com::sun::star::uno::Reference<
1031 : ::com::sun::star::accessibility::XAccessible>
1032 16 : Window::CreateAccessible (void)
1033 : {
1034 16 : if (mpViewShell != NULL)
1035 16 : return mpViewShell->CreateAccessibleDocumentView (this);
1036 : else
1037 : {
1038 : OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
1039 0 : return ::Window::CreateAccessible ();
1040 : }
1041 : }
1042 :
1043 0 : OUString Window::GetSurroundingText() const
1044 : {
1045 0 : if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1046 0 : return OUString();
1047 0 : else if ( mpViewShell->GetView()->IsTextEdit() )
1048 : {
1049 0 : OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1050 0 : return pOLV->GetEditView().GetSurroundingText();
1051 : }
1052 0 : return OUString();
1053 : }
1054 :
1055 0 : Selection Window::GetSurroundingTextSelection() const
1056 : {
1057 0 : if ( mpViewShell->GetShellType() == ViewShell::ST_OUTLINE )
1058 : {
1059 0 : return Selection( 0, 0 );
1060 : }
1061 0 : else if ( mpViewShell->GetView()->IsTextEdit() )
1062 : {
1063 0 : OutlinerView *pOLV = mpViewShell->GetView()->GetTextEditOutlinerView();
1064 0 : return pOLV->GetEditView().GetSurroundingTextSelection();
1065 : }
1066 : else
1067 : {
1068 0 : return Selection( 0, 0 );
1069 : }
1070 : }
1071 :
1072 33 : } // end of namespace sd
1073 :
1074 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|