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