1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "controller/SlideSorterController.hxx"
#include "SlideSorter.hxx"
#include "controller/SlsPageSelector.hxx"
#include "controller/SlsSelectionFunction.hxx"
#include "controller/SlsProperties.hxx"
#include "controller/SlsCurrentSlideManager.hxx"
#include "SlsListener.hxx"
#include "controller/SlsFocusManager.hxx"
#include "controller/SlsAnimator.hxx"
#include "controller/SlsClipboard.hxx"
#include "controller/SlsInsertionIndicatorHandler.hxx"
#include "controller/SlsScrollBarManager.hxx"
#include "controller/SlsSelectionManager.hxx"
#include "controller/SlsSlotManager.hxx"
#include "controller/SlsTransferableData.hxx"
#include "controller/SlsVisibleAreaManager.hxx"
#include "model/SlideSorterModel.hxx"
#include "model/SlsPageEnumerationProvider.hxx"
#include "model/SlsPageDescriptor.hxx"
#include "view/SlideSorterView.hxx"
#include "view/SlsLayouter.hxx"
#include "view/SlsFontProvider.hxx"
#include "view/SlsPageObjectLayouter.hxx"
#include "view/SlsPageObjectPainter.hxx"
#include "view/SlsTheme.hxx"
#include "view/SlsToolTip.hxx"
#include "cache/SlsPageCache.hxx"
#include "cache/SlsPageCacheManager.hxx"
#include "drawdoc.hxx"
#include "DrawViewShell.hxx"
#include "ViewShellBase.hxx"
#include "Window.hxx"
#include "FrameView.hxx"
#include "DrawDocShell.hxx"
#include "sdpage.hxx"
#include "res_bmp.hrc"
#include "sdresid.hxx"
#include "strings.hrc"
#include "app.hrc"
#include "glob.hrc"
#include "sdmod.hxx"
#include "sdxfer.hxx"
#include "ViewShellHint.hxx"
#include "AccessibleSlideSorterView.hxx"
#include "AccessibleSlideSorterObject.hxx"
#include <vcl/window.hxx>
#include <svx/svdopage.hxx>
#include <svx/svxids.hrc>
#include <svx/ruler.hxx>
#include <sfx2/zoomitem.hxx>
#include <svtools/tabbar.hxx>
#include <sfx2/request.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPages.hpp>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::sd::slidesorter::model;
using namespace ::sd::slidesorter::view;
using namespace ::sd::slidesorter::controller;
using namespace ::basegfx;
namespace sd { namespace slidesorter { namespace controller {
SlideSorterController::SlideSorterController (SlideSorter& rSlideSorter)
: mrSlideSorter(rSlideSorter),
mrModel(mrSlideSorter.GetModel()),
mrView(mrSlideSorter.GetView()),
mpPageSelector(),
mpFocusManager(),
mpSlotManager(),
mpScrollBarManager(),
mpCurrentSlideManager(),
mpSelectionManager(),
mpClipboard(),
mpInsertionIndicatorHandler(new InsertionIndicatorHandler(rSlideSorter)),
mpAnimator(new Animator(rSlideSorter)),
mpVisibleAreaManager(new VisibleAreaManager(rSlideSorter)),
mpListener(),
mnModelChangeLockCount(0),
mbIsForcedRearrangePending(false),
mbPreModelChangeDone(false),
mbPostModelChangePending(false),
maSelectionBeforeSwitch(),
mnCurrentPageBeforeSwitch(0),
mpEditModeChangeMasterPage(NULL),
maTotalWindowArea(),
mnPaintEntranceCount(0),
mbIsContextMenuOpen(false)
{
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
OSL_ASSERT(pWindow);
if (pWindow)
{
// The whole background is painted by the view and controls.
::Window* pParentWindow = pWindow->GetParent();
OSL_ASSERT(pParentWindow!=NULL);
pParentWindow->SetBackground (Wallpaper());
// Connect the view with the window that has been created by our base
// class.
pWindow->SetBackground(Wallpaper());
pWindow->SetCenterAllowed(false);
pWindow->SetMapMode(MapMode(MAP_PIXEL));
pWindow->SetViewSize(mrView.GetModelArea().GetSize());
}
}
void SlideSorterController::Init (void)
{
mpCurrentSlideManager.reset(new CurrentSlideManager(mrSlideSorter));
mpPageSelector.reset(new PageSelector(mrSlideSorter));
mpFocusManager.reset(new FocusManager(mrSlideSorter));
mpSlotManager.reset(new SlotManager(mrSlideSorter));
mpScrollBarManager.reset(new ScrollBarManager(mrSlideSorter));
mpSelectionManager.reset(new SelectionManager(mrSlideSorter));
mpClipboard.reset(new Clipboard(mrSlideSorter));
mpScrollBarManager->LateInitialization();
// Create the selection function.
SfxRequest aRequest (
SID_OBJECT_SELECT,
0,
mrModel.GetDocument()->GetItemPool());
mrSlideSorter.SetCurrentFunction(CreateSelectionFunction(aRequest));
mpListener = new Listener(mrSlideSorter);
mpPageSelector->GetCoreSelection();
GetSelectionManager()->SelectionHasChanged();
}
SlideSorterController::~SlideSorterController (void)
{
try
{
uno::Reference<lang::XComponent> xComponent (
static_cast<XWeak*>(mpListener.get()), uno::UNO_QUERY);
if (xComponent.is())
xComponent->dispose();
}
catch( uno::Exception& )
{
OSL_FAIL( "sd::SlideSorterController::~SlideSorterController(), exception caught!" );
}
// dispose should have been called by now so that nothing is to be done
// to shut down cleanly.
}
void SlideSorterController::Dispose (void)
{
mpInsertionIndicatorHandler->End(Animator::AM_Immediate);
mpClipboard.reset();
mpSelectionManager.reset();
mpAnimator->Dispose();
}
model::SharedPageDescriptor SlideSorterController::GetPageAt (
const Point& aWindowPosition)
{
sal_Int32 nHitPageIndex (mrView.GetPageIndexAtPoint(aWindowPosition));
model::SharedPageDescriptor pDescriptorAtPoint;
if (nHitPageIndex >= 0)
{
pDescriptorAtPoint = mrModel.GetPageDescriptor(nHitPageIndex);
// Depending on a property we may have to check that the mouse is no
// just over the page object but over the preview area.
if (pDescriptorAtPoint
&& mrSlideSorter.GetProperties()->IsOnlyPreviewTriggersMouseOver()
&& ! pDescriptorAtPoint->HasState(PageDescriptor::ST_Selected))
{
// Make sure that the mouse is over the preview area.
if ( ! mrView.GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
pDescriptorAtPoint,
view::PageObjectLayouter::Preview,
view::PageObjectLayouter::WindowCoordinateSystem).IsInside(aWindowPosition))
{
pDescriptorAtPoint.reset();
}
}
}
return pDescriptorAtPoint;
}
PageSelector& SlideSorterController::GetPageSelector (void)
{
OSL_ASSERT(mpPageSelector.get()!=NULL);
return *mpPageSelector.get();
}
FocusManager& SlideSorterController::GetFocusManager (void)
{
OSL_ASSERT(mpFocusManager.get()!=NULL);
return *mpFocusManager.get();
}
Clipboard& SlideSorterController::GetClipboard (void)
{
OSL_ASSERT(mpClipboard.get()!=NULL);
return *mpClipboard.get();
}
ScrollBarManager& SlideSorterController::GetScrollBarManager (void)
{
OSL_ASSERT(mpScrollBarManager.get()!=NULL);
return *mpScrollBarManager.get();
}
::boost::shared_ptr<CurrentSlideManager> SlideSorterController::GetCurrentSlideManager (void) const
{
OSL_ASSERT(mpCurrentSlideManager.get()!=NULL);
return mpCurrentSlideManager;
}
::boost::shared_ptr<SlotManager> SlideSorterController::GetSlotManager (void) const
{
OSL_ASSERT(mpSlotManager.get()!=NULL);
return mpSlotManager;
}
::boost::shared_ptr<SelectionManager> SlideSorterController::GetSelectionManager (void) const
{
OSL_ASSERT(mpSelectionManager.get()!=NULL);
return mpSelectionManager;
}
::boost::shared_ptr<InsertionIndicatorHandler>
SlideSorterController::GetInsertionIndicatorHandler (void) const
{
OSL_ASSERT(mpInsertionIndicatorHandler.get()!=NULL);
return mpInsertionIndicatorHandler;
}
void SlideSorterController::Paint (
const Rectangle& rBBox,
::Window* pWindow)
{
if (mnPaintEntranceCount == 0)
{
++mnPaintEntranceCount;
try
{
mrView.CompleteRedraw(pWindow, Region(rBBox), 0);
}
catch (const Exception&)
{
// Ignore all exceptions.
}
--mnPaintEntranceCount;
}
}
void SlideSorterController::FuTemporary (SfxRequest& rRequest)
{
mpSlotManager->FuTemporary (rRequest);
}
void SlideSorterController::FuPermanent (SfxRequest &rRequest)
{
mpSlotManager->FuPermanent (rRequest);
}
void SlideSorterController::FuSupport (SfxRequest &rRequest)
{
mpSlotManager->FuSupport (rRequest);
}
bool SlideSorterController::Command (
const CommandEvent& rEvent,
::sd::Window* pWindow)
{
bool bEventHasBeenHandled = false;
if (pWindow == NULL)
return false;
ViewShell* pViewShell = mrSlideSorter.GetViewShell();
if (pViewShell == NULL)
return false;
switch (rEvent.GetCommand())
{
case COMMAND_CONTEXTMENU:
{
SdPage* pPage = NULL;
sal_uInt16 nPopupId;
model::PageEnumeration aSelectedPages (
PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
if (aSelectedPages.HasMoreElements())
pPage = aSelectedPages.GetNextElement()->GetPage();
// Choose the popup menu depending on a) the type of the main
// view shell, b) the edit mode, and c) on whether the selection
// is empty or not.
ViewShell::ShellType eMainViewShellType (ViewShell::ST_NONE);
::boost::shared_ptr<ViewShell> pMainViewShell (
pViewShell->GetViewShellBase().GetMainViewShell());
if (pMainViewShell.get() != NULL)
eMainViewShellType = pMainViewShell->GetShellType();
switch (eMainViewShellType)
{
case ViewShell::ST_DRAW:
if (pPage != NULL)
nPopupId = RID_SLIDE_SORTER_DRAW_SEL_POPUP;
else
nPopupId = RID_SLIDE_SORTER_DRAW_NOSEL_POPUP;
break;
default:
if (mrModel.GetEditMode() == EM_PAGE)
if (pPage != NULL)
nPopupId = RID_SLIDE_SORTER_IMPRESS_SEL_POPUP;
else
nPopupId = RID_SLIDE_SORTER_IMPRESS_NOSEL_POPUP;
else
if (pPage != NULL)
nPopupId = RID_SLIDE_SORTER_MASTER_SEL_POPUP;
else
nPopupId = RID_SLIDE_SORTER_MASTER_NOSEL_POPUP;
}
::boost::scoped_ptr<InsertionIndicatorHandler::ForceShowContext> pContext;
if (pPage == NULL)
{
// When there is no selection, then we show the insertion
// indicator so that the user knows where a page insertion
// would take place.
mpInsertionIndicatorHandler->Start(false);
mpInsertionIndicatorHandler->UpdateIndicatorIcon(SD_MOD()->pTransferClip);
mpInsertionIndicatorHandler->UpdatePosition(
pWindow->PixelToLogic(rEvent.GetMousePosPixel()),
InsertionIndicatorHandler::MoveMode);
pContext.reset(new InsertionIndicatorHandler::ForceShowContext(
mpInsertionIndicatorHandler));
}
pWindow->ReleaseMouse();
Point aMenuLocation (0,0);
if (rEvent.IsMouseEvent())
{
// We have to explicitly specify the location of the menu
// when the slide sorter is placed in an undocked child
// menu. But when it is docked it does not hurt, so we
// specify the location always.
aMenuLocation = rEvent.GetMousePosPixel();
}
else
{
// The event is not a mouse event. Use the center of the
// focused page as top left position of the context menu.
model::SharedPageDescriptor pDescriptor (
GetFocusManager().GetFocusedPageDescriptor());
if (pDescriptor.get() != NULL)
{
Rectangle aBBox (
mrView.GetLayouter().GetPageObjectLayouter()->GetBoundingBox (
pDescriptor,
PageObjectLayouter::PageObject,
PageObjectLayouter::ModelCoordinateSystem));
aMenuLocation = aBBox.Center();
}
}
mbIsContextMenuOpen = true;
if (pViewShell != NULL)
{
SfxDispatcher* pDispatcher = pViewShell->GetDispatcher();
if (pDispatcher != NULL)
{
pDispatcher->ExecutePopup(
SdResId(nPopupId),
pWindow,
&aMenuLocation);
mrSlideSorter.GetView().UpdatePageUnderMouse();
::rtl::Reference<SelectionFunction> pFunction(GetCurrentSelectionFunction());
if (pFunction.is())
pFunction->ResetMouseAnchor();
}
}
mbIsContextMenuOpen = false;
if (pPage == NULL)
{
// Remember the position of the insertion indicator before
// it is hidden, so that a pending slide insertion slot call
// finds the right place to insert a new slide.
GetSelectionManager()->SetInsertionPosition(
GetInsertionIndicatorHandler()->GetInsertionPageIndex());
}
pContext.reset();
bEventHasBeenHandled = true;
}
break;
case COMMAND_WHEEL:
{
const CommandWheelData* pData = rEvent.GetWheelData();
if (pData == NULL)
return false;
if (pData->IsMod1())
{
// We do not support zooming with control+mouse wheel.
return false;
}
// Determine whether to scroll horizontally or vertically. This
// depends on the orientation of the scroll bar and the
// IsHoriz() flag of the event.
if ((mrSlideSorter.GetView().GetOrientation()==view::Layouter::HORIZONTAL)
== pData->IsHorz())
{
GetScrollBarManager().Scroll(
ScrollBarManager::Orientation_Vertical,
ScrollBarManager::Unit_Slide,
-pData->GetNotchDelta());
}
else
{
GetScrollBarManager().Scroll(
ScrollBarManager::Orientation_Horizontal,
ScrollBarManager::Unit_Slide,
-pData->GetNotchDelta());
}
mrSlideSorter.GetView().UpdatePageUnderMouse(rEvent.GetMousePosPixel());
bEventHasBeenHandled = true;
}
break;
}
return bEventHasBeenHandled;
}
void SlideSorterController::LockModelChange (void)
{
mnModelChangeLockCount += 1;
}
void SlideSorterController::UnlockModelChange (void)
{
mnModelChangeLockCount -= 1;
if (mnModelChangeLockCount==0 && mbPostModelChangePending)
{
PostModelChange();
}
}
void SlideSorterController::PreModelChange (void)
{
// Prevent PreModelChange to execute more than once per model lock.
if (mbPostModelChangePending)
return;
mbPreModelChangeDone = true;
if (mrSlideSorter.GetViewShell() != NULL)
mrSlideSorter.GetViewShell()->Broadcast(
ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_START));
GetCurrentSlideManager()->PrepareModelChange();
if (mrSlideSorter.GetContentWindow())
mrView.PreModelChange();
mbPostModelChangePending = true;
}
void SlideSorterController::PostModelChange (void)
{
mbPostModelChangePending = false;
mrModel.Resync();
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
if (pWindow)
{
GetCurrentSlideManager()->HandleModelChange();
mrView.PostModelChange ();
pWindow->SetViewOrigin (Point (0,0));
pWindow->SetViewSize (mrView.GetModelArea().GetSize());
// The visibility of the scroll bars may have to be changed. Then
// the size of the view has to change, too. Let Rearrange() handle
// that.
Rearrange(mbIsForcedRearrangePending);
}
if (mrSlideSorter.GetViewShell() != NULL)
mrSlideSorter.GetViewShell()->Broadcast(
ViewShellHint(ViewShellHint::HINT_COMPLEX_MODEL_CHANGE_END));
}
void SlideSorterController::HandleModelChange (void)
{
// Ignore this call when the document is not in a valid state, i.e. has
// not the same number of regular and notes pages.
bool bIsDocumentValid = (mrModel.GetDocument()->GetPageCount() % 2 == 1);
if (bIsDocumentValid)
{
ModelChangeLock aLock (*this);
PreModelChange();
}
}
IMPL_LINK(SlideSorterController, WindowEventHandler, VclWindowEvent*, pEvent)
{
if (pEvent != NULL)
{
::Window* pWindow = pEvent->GetWindow();
SharedSdWindow pActiveWindow (mrSlideSorter.GetContentWindow());
switch (pEvent->GetId())
{
case VCLEVENT_WINDOW_ACTIVATE:
case VCLEVENT_WINDOW_SHOW:
if (pActiveWindow && pWindow == pActiveWindow->GetParent())
mrView.RequestRepaint();
break;
case VCLEVENT_WINDOW_HIDE:
if (pActiveWindow && pWindow == pActiveWindow->GetParent())
mrView.SetPageUnderMouse(SharedPageDescriptor());
break;
case VCLEVENT_WINDOW_GETFOCUS:
if (pActiveWindow)
if (pWindow == pActiveWindow.get())
GetFocusManager().ShowFocus(false);
break;
case VCLEVENT_WINDOW_LOSEFOCUS:
if (pActiveWindow && pWindow == pActiveWindow.get())
{
GetFocusManager().HideFocus();
mrView.GetToolTip().Hide();
// Select the current slide so that it is properly
// visualized when the focus is moved to the edit view.
GetPageSelector().SelectPage(GetCurrentSlideManager()->GetCurrentSlide());
}
break;
case VCLEVENT_APPLICATION_DATACHANGED:
{
// Invalidate the preview cache.
cache::PageCacheManager::Instance()->InvalidateAllCaches();
// Update the draw mode.
sal_uLong nDrawMode (Application::GetSettings().GetStyleSettings().GetHighContrastMode()
? ViewShell::OUTPUT_DRAWMODE_CONTRAST
: ViewShell::OUTPUT_DRAWMODE_COLOR);
if (mrSlideSorter.GetViewShell() != NULL)
mrSlideSorter.GetViewShell()->GetFrameView()->SetDrawMode(nDrawMode);
if (pActiveWindow != 0)
pActiveWindow->SetDrawMode(nDrawMode);
mrView.HandleDrawModeChange();
// When the system font has changed a layout has to be done.
mrView.Resize();
FontProvider::Instance().Invalidate();
// Update theme colors.
mrSlideSorter.GetProperties()->HandleDataChangeEvent();
mrSlideSorter.GetTheme()->Update(mrSlideSorter.GetProperties());
mrView.HandleDataChangeEvent();
}
break;
default:
break;
}
}
return sal_True;
}
void SlideSorterController::GetCtrlState (SfxItemSet& rSet)
{
if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
{
// let SFx en-/disable "last version"
SfxViewFrame* pSlideViewFrame = SfxViewFrame::Current();
DBG_ASSERT(pSlideViewFrame!=NULL,
"SlideSorterController::GetCtrlState: ViewFrame not found");
if (pSlideViewFrame)
{
pSlideViewFrame->GetSlotState (SID_RELOAD, NULL, &rSet);
}
else // MI says: no MDIFrame --> disable
{
rSet.DisableItem(SID_RELOAD);
}
}
// Output quality.
if (rSet.GetItemState(SID_OUTPUT_QUALITY_COLOR)==SFX_ITEM_AVAILABLE
||rSet.GetItemState(SID_OUTPUT_QUALITY_GRAYSCALE)==SFX_ITEM_AVAILABLE
||rSet.GetItemState(SID_OUTPUT_QUALITY_BLACKWHITE)==SFX_ITEM_AVAILABLE
||rSet.GetItemState(SID_OUTPUT_QUALITY_CONTRAST)==SFX_ITEM_AVAILABLE)
{
if (mrSlideSorter.GetContentWindow())
{
sal_uLong nMode = mrSlideSorter.GetContentWindow()->GetDrawMode();
sal_uInt16 nQuality = 0;
switch (nMode)
{
case ViewShell::OUTPUT_DRAWMODE_COLOR:
nQuality = 0;
break;
case ViewShell::OUTPUT_DRAWMODE_GRAYSCALE:
nQuality = 1;
break;
case ViewShell::OUTPUT_DRAWMODE_BLACKWHITE:
nQuality = 2;
break;
case ViewShell::OUTPUT_DRAWMODE_CONTRAST:
nQuality = 3;
break;
}
rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_COLOR, nQuality==0));
rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_GRAYSCALE, nQuality==1));
rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_BLACKWHITE, nQuality==2));
rSet.Put (SfxBoolItem (SID_OUTPUT_QUALITY_CONTRAST, nQuality==3));
}
}
if (rSet.GetItemState(SID_MAIL_SCROLLBODY_PAGEDOWN) == SFX_ITEM_AVAILABLE)
{
rSet.Put (SfxBoolItem( SID_MAIL_SCROLLBODY_PAGEDOWN, true));
}
}
void SlideSorterController::GetStatusBarState (SfxItemSet& rSet)
{
mpSlotManager->GetStatusBarState (rSet);
}
void SlideSorterController::ExecCtrl (SfxRequest& rRequest)
{
mpSlotManager->ExecCtrl (rRequest);
}
void SlideSorterController::GetAttrState (SfxItemSet& rSet)
{
mpSlotManager->GetAttrState (rSet);
}
void SlideSorterController::ExecStatusBar (SfxRequest& )
{
}
void SlideSorterController::UpdateAllPages (void)
{
// Do a redraw.
mrSlideSorter.GetContentWindow()->Invalidate();
}
Rectangle SlideSorterController::Resize (const Rectangle& rAvailableSpace)
{
Rectangle aContentArea (rAvailableSpace);
if (maTotalWindowArea != rAvailableSpace)
{
maTotalWindowArea = rAvailableSpace;
aContentArea = Rearrange(true);
}
return aContentArea;
}
Rectangle SlideSorterController::Rearrange (bool bForce)
{
Rectangle aNewContentArea (maTotalWindowArea);
if (aNewContentArea.IsEmpty())
return aNewContentArea;
if (mnModelChangeLockCount>0)
{
mbIsForcedRearrangePending |= bForce;
return aNewContentArea;
}
else
mbIsForcedRearrangePending = false;
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
if (pWindow)
{
if (bForce)
mrView.UpdateOrientation();
// Place the scroll bars.
aNewContentArea = GetScrollBarManager().PlaceScrollBars(
maTotalWindowArea,
mrView.GetOrientation() != view::Layouter::VERTICAL,
mrView.GetOrientation() != view::Layouter::HORIZONTAL);
bool bSizeHasChanged (false);
// Only when bForce is not true we have to test for a size change in
// order to determine whether the window and the view have to be resized.
if ( ! bForce)
{
Rectangle aCurrentContentArea (pWindow->GetPosPixel(), pWindow->GetOutputSizePixel());
bSizeHasChanged = (aNewContentArea != aCurrentContentArea);
}
if (bForce || bSizeHasChanged)
{
// The browser window gets the remaining space.
pWindow->SetPosSizePixel (aNewContentArea.TopLeft(), aNewContentArea.GetSize());
mrView.Resize();
}
// Adapt the scroll bars to the new zoom factor of the browser
// window and the arrangement of the page objects.
GetScrollBarManager().UpdateScrollBars(false, !bForce);
// Keep the current slide in the visible area.
GetVisibleAreaManager().RequestCurrentSlideVisible();
mrView.RequestRepaint();
}
return aNewContentArea;
}
rtl::Reference<FuPoor> SlideSorterController::CreateSelectionFunction (SfxRequest& rRequest)
{
rtl::Reference<FuPoor> xFunc( SelectionFunction::Create(mrSlideSorter, rRequest) );
return xFunc;
}
::rtl::Reference<SelectionFunction> SlideSorterController::GetCurrentSelectionFunction (void)
{
rtl::Reference<FuPoor> pFunction (mrSlideSorter.GetViewShell()->GetCurrentFunction());
return ::rtl::Reference<SelectionFunction>(dynamic_cast<SelectionFunction*>(pFunction.get()));
}
void SlideSorterController::PrepareEditModeChange (void)
{
// Before we throw away the page descriptors we prepare for selecting
// descriptors in the other mode and for restoring the current
// selection when switching back to the current mode.
if (mrModel.GetEditMode() == EM_PAGE)
{
maSelectionBeforeSwitch.clear();
// Search for the first selected page and determine the master page
// used by its page object. It will be selected after the switch.
// In the same loop the current selection is stored.
PageEnumeration aSelectedPages (
PageEnumerationProvider::CreateSelectedPagesEnumeration(mrModel));
while (aSelectedPages.HasMoreElements())
{
SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
SdPage* pPage = pDescriptor->GetPage();
// Remember the master page of the first selected descriptor.
if (pPage!=NULL && mpEditModeChangeMasterPage==NULL)
mpEditModeChangeMasterPage = &static_cast<SdPage&>(
pPage->TRG_GetMasterPage());
maSelectionBeforeSwitch.push_back(pPage);
}
// Remember the current page.
if (mrSlideSorter.GetViewShell() != NULL)
mnCurrentPageBeforeSwitch = (mrSlideSorter.GetViewShell()->GetViewShellBase()
.GetMainViewShell()->GetActualPage()->GetPageNum()-1)/2;
}
}
bool SlideSorterController::ChangeEditMode (EditMode eEditMode)
{
bool bResult (false);
if (mrModel.GetEditMode() != eEditMode)
{
ModelChangeLock aLock (*this);
PreModelChange();
// Do the actual edit mode switching.
bResult = mrModel.SetEditMode(eEditMode);
if (bResult)
HandleModelChange();
}
return bResult;
}
void SlideSorterController::FinishEditModeChange (void)
{
if (mrModel.GetEditMode() == EM_MASTERPAGE)
{
mpPageSelector->DeselectAllPages();
// Search for the master page that was determined in
// PrepareEditModeChange() and make it the current page.
PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
while (aAllPages.HasMoreElements())
{
SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
if (pDescriptor->GetPage() == mpEditModeChangeMasterPage)
{
GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
mpPageSelector->SelectPage(pDescriptor);
break;
}
}
}
else
{
PageSelector::BroadcastLock aBroadcastLock (*mpPageSelector);
SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnCurrentPageBeforeSwitch));
GetCurrentSlideManager()->SwitchCurrentSlide(pDescriptor);
// Restore the selection.
mpPageSelector->DeselectAllPages();
::std::vector<SdPage*>::iterator iPage;
for (iPage=maSelectionBeforeSwitch.begin();
iPage!=maSelectionBeforeSwitch.end();
++iPage)
{
mpPageSelector->SelectPage(*iPage);
}
maSelectionBeforeSwitch.clear( );
}
mpEditModeChangeMasterPage = NULL;
}
void SlideSorterController::PageNameHasChanged (int nPageIndex, const OUString& rsOldName)
{
// Request a repaint for the page object whose name has changed.
model::SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(nPageIndex));
if (pDescriptor.get() != NULL)
mrView.RequestRepaint(pDescriptor);
// Get a pointer to the corresponding accessible object and notify
// that of the name change.
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
if ( ! pWindow)
return;
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
xAccessible (pWindow->GetAccessible(false));
if ( ! xAccessible.is())
return;
// Now comes a small hack. We assume that the accessible object is
// an instantiation of AccessibleSlideSorterView and cast it to that
// class. The cleaner alternative to this cast would be a new member
// in which we would store the last AccessibleSlideSorterView object
// created by SlideSorterViewShell::CreateAccessibleDocumentView().
// But then there is no guaranty that the accessible object obtained
// from the window really is that instance last created by
// CreateAccessibleDocumentView().
// However, the dynamic cast together with the check of the result
// being NULL should be safe enough.
::accessibility::AccessibleSlideSorterView* pAccessibleView
= dynamic_cast< ::accessibility::AccessibleSlideSorterView*>(xAccessible.get());
if (pAccessibleView == NULL)
return;
::accessibility::AccessibleSlideSorterObject* pChild
= pAccessibleView->GetAccessibleChildImplementation(nPageIndex);
if (pChild == NULL || pChild->GetPage() == NULL)
return;
OUString sOldName (rsOldName);
OUString sNewName (pChild->GetPage()->GetName());
pChild->FireAccessibleEvent(
::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED,
makeAny(sOldName),
makeAny(sNewName));
}
void SlideSorterController::SetDocumentSlides (const Reference<container::XIndexAccess>& rxSlides)
{
if (mrModel.GetDocumentSlides() != rxSlides)
{
ModelChangeLock aLock (*this);
PreModelChange();
mrModel.SetDocumentSlides(rxSlides);
}
}
::boost::shared_ptr<Animator> SlideSorterController::GetAnimator (void) const
{
return mpAnimator;
}
VisibleAreaManager& SlideSorterController::GetVisibleAreaManager (void) const
{
OSL_ASSERT(mpVisibleAreaManager);
return *mpVisibleAreaManager;
}
void SlideSorterController::CheckForMasterPageAssignment (void)
{
if (mrModel.GetPageCount()%2==0)
return;
PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
while (aAllPages.HasMoreElements())
{
SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
if (pDescriptor->UpdateMasterPage())
{
mrView.GetPreviewCache()->InvalidatePreviewBitmap (
pDescriptor->GetPage(),
true);
}
}
}
void SlideSorterController::CheckForSlideTransitionAssignment (void)
{
if (mrModel.GetPageCount()%2==0)
return;
PageEnumeration aAllPages (PageEnumerationProvider::CreateAllPagesEnumeration(mrModel));
while (aAllPages.HasMoreElements())
{
SharedPageDescriptor pDescriptor (aAllPages.GetNextElement());
if (pDescriptor->UpdateTransitionFlag())
{
mrView.GetPreviewCache()->InvalidatePreviewBitmap (
pDescriptor->GetPage(),
true);
}
}
}
//===== SlideSorterController::ModelChangeLock ================================
SlideSorterController::ModelChangeLock::ModelChangeLock (
SlideSorterController& rController)
: mpController(&rController)
{
mpController->LockModelChange();
}
SlideSorterController::ModelChangeLock::~ModelChangeLock (void)
{
Release();
}
void SlideSorterController::ModelChangeLock::Release (void)
{
if (mpController != NULL)
{
mpController->UnlockModelChange();
mpController = NULL;
}
}
} } } // end of namespace ::sd::slidesorter
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|