LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - LayoutMenu.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 162 317 51.1 %
Date: 2015-06-13 12:38:46 Functions: 22 36 61.1 %
Legend: Lines: hit not hit

          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             : #include "LayoutMenu.hxx"
      21             : 
      22             : #include "app.hrc"
      23             : #include "drawdoc.hxx"
      24             : #include "framework/FrameworkHelper.hxx"
      25             : #include "glob.hrc"
      26             : #include "glob.hxx"
      27             : #include "helpids.h"
      28             : #include "pres.hxx"
      29             : #include "res_bmp.hrc"
      30             : #include "sdpage.hxx"
      31             : #include "sdresid.hxx"
      32             : #include "strings.hrc"
      33             : #include "tools/SlotStateListener.hxx"
      34             : #include "DrawController.hxx"
      35             : #include "DrawDocShell.hxx"
      36             : #include "DrawViewShell.hxx"
      37             : #include "EventMultiplexer.hxx"
      38             : #include "SlideSorterViewShell.hxx"
      39             : #include "ViewShellBase.hxx"
      40             : #include <sfx2/sidebar/Theme.hxx>
      41             : 
      42             : #include <comphelper/processfactory.hxx>
      43             : #include <sfx2/app.hxx>
      44             : #include <sfx2/dispatch.hxx>
      45             : #include <sfx2/objface.hxx>
      46             : #include <sfx2/request.hxx>
      47             : #include <sfx2/viewfrm.hxx>
      48             : #include <svl/languageoptions.hxx>
      49             : #include <vcl/image.hxx>
      50             : #include <vcl/floatwin.hxx>
      51             : 
      52             : #include <com/sun/star/frame/XController.hpp>
      53             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      54             : #include <com/sun/star/drawing/framework/XView.hpp>
      55             : #include <com/sun/star/drawing/framework/ResourceId.hpp>
      56             : 
      57             : #include <vector>
      58             : 
      59             : using namespace ::com::sun::star;
      60             : using namespace ::com::sun::star::text;
      61             : using namespace ::com::sun::star::uno;
      62             : using namespace ::com::sun::star::drawing::framework;
      63             : using namespace ::sd::slidesorter;
      64             : using ::sd::framework::FrameworkHelper;
      65             : 
      66             : namespace sd { namespace sidebar {
      67             : 
      68             : struct snewfoil_value_info
      69             : {
      70             :     sal_uInt16 mnBmpResId;
      71             :     sal_uInt16 mnStrResId;
      72             :     WritingMode meWritingMode;
      73             :     AutoLayout maAutoLayout;
      74             : };
      75             : 
      76             : static const snewfoil_value_info notes[] =
      77             : {
      78             :     {BMP_FOILN_01, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
      79             :      AUTOLAYOUT_NOTES},
      80             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
      81             : };
      82             : 
      83             : static const snewfoil_value_info handout[] =
      84             : {
      85             :     {BMP_FOILH_01, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
      86             :      AUTOLAYOUT_HANDOUT1},
      87             :     {BMP_FOILH_02, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
      88             :      AUTOLAYOUT_HANDOUT2},
      89             :     {BMP_FOILH_03, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
      90             :      AUTOLAYOUT_HANDOUT3},
      91             :     {BMP_FOILH_04, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
      92             :      AUTOLAYOUT_HANDOUT4},
      93             :     {BMP_FOILH_06, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
      94             :      AUTOLAYOUT_HANDOUT6},
      95             :     {BMP_FOILH_09, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
      96             :      AUTOLAYOUT_HANDOUT9},
      97             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
      98             : };
      99             : 
     100             : static const snewfoil_value_info standard[] =
     101             : {
     102             :     {BMP_LAYOUT_EMPTY, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB,        AUTOLAYOUT_NONE},
     103             :     {BMP_LAYOUT_HEAD03, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB,       AUTOLAYOUT_TITLE},
     104             :     {BMP_LAYOUT_HEAD02, STR_AUTOLAYOUT_CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_ENUM},
     105             :     {BMP_LAYOUT_HEAD02A, STR_AUTOLAYOUT_2CONTENT, WritingMode_LR_TB,       AUTOLAYOUT_2TEXT},
     106             :     {BMP_LAYOUT_HEAD01, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB,  AUTOLAYOUT_ONLY_TITLE},
     107             :     {BMP_LAYOUT_TEXTONLY, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB,   AUTOLAYOUT_ONLY_TEXT},
     108             :     {BMP_LAYOUT_HEAD03B, STR_AUTOLAYOUT_2CONTENT_CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_2OBJTEXT},
     109             :     {BMP_LAYOUT_HEAD03C, STR_AUTOLAYOUT_CONTENT_2CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_TEXT2OBJ},
     110             :     {BMP_LAYOUT_HEAD03A, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT},
     111             :     {BMP_LAYOUT_HEAD02B, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT},
     112             :     {BMP_LAYOUT_HEAD04, STR_AUTOLAYOUT_4CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_4OBJ},
     113             :     {BMP_LAYOUT_HEAD06, STR_AUTOLAYOUT_6CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_6CLIPART},
     114             : 
     115             :     // vertical
     116             :     {BMP_LAYOUT_VERTICAL02, STR_AL_VERT_TITLE_TEXT_CHART, WritingMode_TB_RL,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
     117             :     {BMP_LAYOUT_VERTICAL01, STR_AL_VERT_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
     118             :     {BMP_LAYOUT_HEAD02, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
     119             :     {BMP_LAYOUT_HEAD02A, STR_AL_TITLE_VERT_OUTLINE_CLIPART,   WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
     120             :     {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
     121             : };
     122             : 
     123          10 : LayoutMenu::LayoutMenu (
     124             :     vcl::Window* pParent,
     125             :     ViewShellBase& rViewShellBase,
     126             :     const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
     127             :     : ValueSet (pParent, WB_ITEMBORDER),
     128             :       DragSourceHelper(this),
     129             :       DropTargetHelper(this),
     130             :       mrBase(rViewShellBase),
     131             :       mbUseOwnScrollBar(false),
     132             :       mnPreferredColumnCount(3),
     133             :       mxListener(NULL),
     134             :       mbSelectionUpdatePending(true),
     135             :       mbIsMainViewChangePending(false),
     136             :       mxSidebar(rxSidebar),
     137          10 :       mbIsDisposed(false)
     138             : {
     139          10 :     implConstruct( *mrBase.GetDocument()->GetDocSh() );
     140             :     SAL_INFO("sd.ui", "created LayoutMenu at " << this);
     141             : 
     142          10 :     SetStyle(GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_TABSTOP);
     143             : 
     144          10 :     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
     145          10 :     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
     146             : 
     147             : #ifdef DEBUG
     148             :     SetText(OUString("sd:LayoutMenu"));
     149             : #endif
     150          10 : }
     151             : 
     152          10 : void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell )
     153             : {
     154             :     OSL_ENSURE( mrBase.GetDocument()->GetDocSh() == &rDocumentShell,
     155             :         "LayoutMenu::implConstruct: hmm?" );
     156             :     // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
     157             :     (void) rDocumentShell;
     158             : 
     159             :     SetStyle (
     160          10 :         ( GetStyle()  & ~(WB_ITEMBORDER) )
     161             :         | WB_TABSTOP
     162             :         | WB_MENUSTYLEVALUESET
     163             :         | WB_NO_DIRECTSELECT
     164          10 :         );
     165          10 :     if (mbUseOwnScrollBar)
     166           0 :         SetStyle (GetStyle() | WB_VSCROLL);
     167          10 :     SetExtraSpacing(2);
     168          10 :     SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
     169          10 :     InvalidateContent();
     170             : 
     171          10 :     Link<> aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
     172             :     mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
     173             :         ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
     174             :         | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
     175             :         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
     176             :         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
     177             :         | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
     178             :         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
     179          10 :         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
     180             : 
     181          10 :     Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS);
     182          10 :     SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
     183             : 
     184          10 :     Link<> aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
     185          30 :     mxListener = new ::sd::tools::SlotStateListener(
     186             :         aStateChangeLink,
     187          20 :         Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
     188          20 :         ".uno:VerticalTextState");
     189             : 
     190          10 :     SetSizePixel(GetParent()->GetSizePixel());
     191          10 :     Link<> aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
     192          10 :     GetParent()->AddEventListener(aWindowEventHandlerLink);
     193          10 : }
     194             : 
     195          30 : LayoutMenu::~LayoutMenu()
     196             : {
     197          10 :     disposeOnce();
     198          20 : }
     199             : 
     200          10 : void LayoutMenu::dispose()
     201             : {
     202             :     SAL_INFO("sd.ui", "destroying LayoutMenu at " << this);
     203          10 :     Dispose();
     204          10 :     ValueSet::dispose();
     205          10 : }
     206             : 
     207          10 : void LayoutMenu::Dispose()
     208             : {
     209          10 :     if (mbIsDisposed)
     210          10 :         return;
     211             : 
     212             :     SAL_INFO("sd.ui", "disposing LayoutMenu at " << this);
     213             : 
     214          10 :     mbIsDisposed = true;
     215             : 
     216          10 :     Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
     217          10 :     if (xComponent.is())
     218          10 :         xComponent->dispose();
     219             : 
     220          10 :     Clear();
     221          10 :     Link<> aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
     222          10 :     mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
     223             : 
     224          10 :     Link<> aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
     225          10 :     GetParent()->RemoveEventListener(aWindowEventHandlerLink);
     226             : }
     227             : 
     228           0 : AutoLayout LayoutMenu::GetSelectedAutoLayout()
     229             : {
     230           0 :     AutoLayout aResult = AUTOLAYOUT_NONE;
     231             : 
     232           0 :     if ( ! IsNoSelection() && GetSelectItemId()!=0)
     233             :     {
     234           0 :         AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
     235           0 :         if (pLayout != NULL)
     236           0 :             aResult = *pLayout;
     237             :     }
     238             : 
     239           0 :     return aResult;
     240             : }
     241             : 
     242          64 : ui::LayoutSize LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth)
     243             : {
     244          64 :     sal_Int32 nPreferredHeight = 200;
     245          64 :     if ( ! mbUseOwnScrollBar && GetItemCount()>0)
     246             :     {
     247          64 :         Image aImage = GetItemImage(GetItemId(0));
     248          64 :         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
     249          64 :         if (nWidth>0 && aItemSize.Width()>0)
     250             :         {
     251          64 :             aItemSize.Width() += 8;
     252          64 :             aItemSize.Height() += 8;
     253          64 :             int nColumnCount = nWidth / aItemSize.Width();
     254          64 :             if (nColumnCount <= 0)
     255           0 :                 nColumnCount = 1;
     256          64 :             else if (nColumnCount > 4)
     257           0 :                 nColumnCount = 4;
     258          64 :             int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
     259          64 :             nPreferredHeight = nRowCount * aItemSize.Height();
     260          64 :         }
     261             :     }
     262          64 :     return ui::LayoutSize(nPreferredHeight,nPreferredHeight,nPreferredHeight);
     263             : }
     264             : 
     265          24 : void LayoutMenu::Paint (vcl::RenderContext& rRenderContext, const Rectangle& rRect)
     266             : {
     267          24 :     if (mbSelectionUpdatePending)
     268             :     {
     269          12 :         mbSelectionUpdatePending = false;
     270          12 :         UpdateSelection();
     271             :     }
     272          24 :     ValueSet::Paint(rRenderContext, rRect);
     273          24 : }
     274             : 
     275          20 : void LayoutMenu::Resize()
     276             : {
     277          20 :     Size aWindowSize = GetOutputSizePixel();
     278          20 :     if (IsVisible() && aWindowSize.Width() > 0)
     279             :     {
     280             :         // Calculate the number of rows and columns.
     281          10 :         if (GetItemCount() > 0)
     282             :         {
     283          10 :             Image aImage = GetItemImage(GetItemId(0));
     284             :             Size aItemSize = CalcItemSizePixel (
     285          10 :                 aImage.GetSizePixel());
     286          10 :             aItemSize.Width() += 8;
     287          10 :             aItemSize.Height() += 8;
     288          10 :             int nColumnCount = aWindowSize.Width() / aItemSize.Width();
     289          10 :             if (nColumnCount < 1)
     290           0 :                 nColumnCount = 1;
     291          10 :             else if (nColumnCount > 4)
     292           0 :                 nColumnCount = 4;
     293             : 
     294          10 :             int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
     295             : 
     296          10 :             SetColCount ((sal_uInt16)nColumnCount);
     297          10 :             SetLineCount ((sal_uInt16)nRowCount);
     298             :         }
     299             :     }
     300             : 
     301          20 :     ValueSet::Resize ();
     302          20 : }
     303             : 
     304           0 : void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
     305             : {
     306             :     // As a preparation for the context menu the item under the mouse is
     307             :     // selected.
     308           0 :     if (rEvent.IsRight())
     309             :     {
     310           0 :         ReleaseMouse();
     311           0 :         sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel());
     312           0 :         if (nIndex > 0)
     313           0 :             SelectItem(nIndex);
     314             :     }
     315             : 
     316           0 :     ValueSet::MouseButtonDown (rEvent);
     317           0 : }
     318             : 
     319           0 : void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
     320             : {
     321           0 :     ViewShell* pViewShell = mrBase.GetMainViewShell().get();
     322           0 :     if (pViewShell == NULL)
     323           0 :         return;
     324             : 
     325           0 :     SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
     326           0 :     if (pViewFrame == NULL)
     327           0 :         return;
     328             : 
     329           0 :     SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
     330           0 :     if (pDispatcher == NULL)
     331           0 :         return;
     332             : 
     333             :     // Call SID_INSERTPAGE with the right arguments.  This is because
     334             :     // the popup menu can not call this slot with arguments directly.
     335           0 :     SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
     336           0 :     if (aRequest.GetArgs() != NULL)
     337             :     {
     338             :         pDispatcher->Execute(
     339             :             SID_INSERTPAGE,
     340             :             SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
     341           0 :             *aRequest.GetArgs());
     342             :     }
     343           0 :     UpdateSelection();
     344             : }
     345             : 
     346          22 : void LayoutMenu::InvalidateContent()
     347             : {
     348             :     // Throw away the current set and fill the menu anew according to the
     349             :     // current settings (this includes the support for vertical writing.)
     350          22 :     Fill();
     351             : 
     352          22 :     if (mxSidebar.is())
     353          22 :         mxSidebar->requestLayout();
     354          22 : }
     355             : 
     356          10 : int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
     357             : {
     358          10 :     int nRowCount = 0;
     359             : 
     360          10 :     if (GetItemCount() > 0 && nColumnCount > 0)
     361             :     {
     362          10 :         nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
     363             :         //        nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
     364          10 :         if (nRowCount < 1)
     365           0 :             nRowCount = 1;
     366             :     }
     367             : 
     368          10 :     return nRowCount;
     369             : }
     370             : 
     371           0 : IMPL_LINK_NOARG(LayoutMenu, ClickHandler)
     372             : {
     373           0 :     AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
     374           0 :     return 0;
     375             : }
     376             : 
     377             : /** The specified layout is assigned to the current page of the view shell
     378             :     in the center pane.
     379             : */
     380           0 : void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
     381             : {
     382             :     using namespace ::sd::slidesorter;
     383             :     using namespace ::sd::slidesorter::controller;
     384             : 
     385             :     do
     386             :     {
     387             :         // The view shell in the center pane has to be present.
     388           0 :         ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
     389           0 :         if (pMainViewShell == NULL)
     390           0 :             break;
     391             : 
     392             :         // Determine if the current view is in an invalid master page mode.
     393             :         // The handout view is always in master page mode and therefore not
     394             :         // invalid.
     395           0 :         bool bMasterPageMode (false);
     396           0 :         switch (pMainViewShell->GetShellType())
     397             :         {
     398             :             case ViewShell::ST_NOTES:
     399             :             case ViewShell::ST_IMPRESS:
     400             :             {
     401           0 :                 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
     402           0 :                 if (pDrawViewShell != NULL)
     403           0 :                     if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
     404           0 :                         bMasterPageMode = true;
     405             :             }
     406             :             default:
     407           0 :                 break;
     408             :         }
     409           0 :         if (bMasterPageMode)
     410           0 :             break;
     411             : 
     412             :         // Get a list of all selected slides and call the SID_MODIFYPAGE
     413             :         // slot for all of them.
     414           0 :         ::sd::slidesorter::SharedPageSelection pPageSelection;
     415             : 
     416             :         // Get a list of selected pages.
     417             :         // First we try to obtain this list from a slide sorter.  This is
     418             :         // possible only some of the view shells in the center pane.  When
     419             :         // no valid slide sorter is available then ask the main view shell
     420             :         // for its current page.
     421           0 :         SlideSorterViewShell* pSlideSorter = NULL;
     422           0 :         switch (pMainViewShell->GetShellType())
     423             :         {
     424             :             case ViewShell::ST_IMPRESS:
     425             :             case ViewShell::ST_NOTES:
     426             :             case ViewShell::ST_SLIDE_SORTER:
     427           0 :                 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
     428           0 :                 break;
     429             :             default:
     430           0 :                 break;
     431             :         }
     432           0 :         if (pSlideSorter != NULL)
     433             :         {
     434             :             // There is a slide sorter visible so get the list of selected pages from it.
     435           0 :             pPageSelection = pSlideSorter->GetPageSelection();
     436             :         }
     437             : 
     438           0 :         if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() )
     439             :         {
     440             :             // No valid slide sorter available.  Ask the main view shell for
     441             :             // its current page.
     442           0 :             pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
     443           0 :             pPageSelection->push_back(pMainViewShell->GetActualPage());
     444             :         }
     445             : 
     446           0 :         if (pPageSelection->empty())
     447           0 :             break;
     448             : 
     449           0 :         ::std::vector<SdPage*>::iterator iPage;
     450           0 :         for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
     451             :             {
     452           0 :                 if ((*iPage) == NULL)
     453           0 :                     continue;
     454             : 
     455             :                 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
     456           0 :                 SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
     457           0 :                 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
     458           0 :                 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
     459           0 :                 pMainViewShell->ExecuteSlot (aRequest, false);
     460           0 :             }
     461             :     }
     462             :     while(false);
     463           0 : }
     464             : 
     465           0 : SfxRequest LayoutMenu::CreateRequest (
     466             :     sal_uInt16 nSlotId,
     467             :     AutoLayout aLayout)
     468             : {
     469           0 :     SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
     470             : 
     471             :     do
     472             :     {
     473           0 :         SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
     474             :         sal_uInt8 aBackground (rLayerAdmin.GetLayerID(
     475           0 :             SD_RESSTR(STR_LAYER_BCKGRND), false));
     476             :         sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(
     477           0 :             SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false));
     478           0 :         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
     479           0 :         if (pViewShell == NULL)
     480           0 :             break;
     481           0 :         SdPage* pPage = pViewShell->GetActualPage();
     482           0 :         if (pPage == NULL)
     483           0 :             break;
     484             : 
     485           0 :         SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
     486             : 
     487             :         aRequest.AppendItem(
     488           0 :             SfxStringItem (ID_VAL_PAGENAME, OUString()));//pPage->GetName()));
     489           0 :         aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
     490             :         aRequest.AppendItem(
     491           0 :             SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
     492             :         aRequest.AppendItem(
     493             :             SfxBoolItem(
     494             :                 ID_VAL_ISPAGEOBJ,
     495           0 :                 aVisibleLayers.IsSet(aBackgroundObject)));
     496             :     }
     497             :     while (false);
     498             : 
     499           0 :     return aRequest;
     500             : }
     501             : 
     502          22 : void LayoutMenu::Fill()
     503             : {
     504          22 :     SvtLanguageOptions aLanguageOptions;
     505          22 :     bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
     506          22 :     SdDrawDocument* pDocument = mrBase.GetDocument();
     507             :     bool bRightToLeft = (pDocument!=NULL
     508          22 :         && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
     509             : 
     510             :     // Get URL of the view in the center pane.
     511          44 :     OUString sCenterPaneViewName;
     512             :     try
     513             :     {
     514             :         Reference<XControllerManager> xControllerManager (
     515          22 :             Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
     516             :         Reference<XResourceId> xPaneId (ResourceId::create(
     517             :             ::comphelper::getProcessComponentContext(),
     518          44 :             FrameworkHelper::msCenterPaneURL));
     519          44 :         Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
     520          22 :         if (xView.is())
     521          44 :             sCenterPaneViewName = xView->getResourceId()->getResourceURL();
     522             :     }
     523           0 :     catch (RuntimeException&)
     524             :     {}
     525             : 
     526          22 :     const snewfoil_value_info* pInfo = NULL;
     527          22 :     if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
     528             :     {
     529           0 :         pInfo = notes;
     530             :     }
     531          22 :     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
     532             :     {
     533           0 :         pInfo = handout;
     534             :     }
     535          44 :     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
     536          22 :         || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
     537             :     {
     538          22 :         pInfo = standard;
     539             :     }
     540             :     else
     541             :     {
     542           0 :         pInfo = NULL;
     543             :     }
     544             : 
     545          22 :     Clear();
     546          22 :     int n = 0;
     547         374 :     for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
     548             :     {
     549         352 :         if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
     550             :         {
     551         352 :             BitmapEx aBmp(SdResId(pInfo->mnBmpResId));
     552             : 
     553         352 :             if (GetDPIScaleFactor() > 1)
     554           0 :                 aBmp.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BmpScaleFlag::Fast);
     555             : 
     556         352 :             if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
     557           0 :                 aBmp.Mirror (BmpMirrorFlags::Horizontal);
     558             : 
     559         352 :             InsertItem(i, Image(aBmp), SdResId (pInfo->mnStrResId));
     560         352 :             SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
     561         352 :             n++;
     562             :         }
     563             :     }
     564             : 
     565          44 :     mbSelectionUpdatePending = true;
     566          22 : }
     567             : 
     568          32 : void LayoutMenu::Clear()
     569             : {
     570         384 :     for (size_t nId=1; nId<=GetItemCount(); nId++)
     571         352 :         delete static_cast<AutoLayout*>(GetItemData(nId));
     572          32 :     ValueSet::Clear();
     573          32 : }
     574             : 
     575           0 : void LayoutMenu::StartDrag (sal_Int8 , const Point& )
     576             : {
     577           0 : }
     578             : 
     579           0 : sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
     580             : {
     581           0 :     return 0;
     582             : }
     583             : 
     584           0 : sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
     585             : {
     586           0 :     return 0;
     587             : }
     588             : 
     589           0 : void LayoutMenu::Command (const CommandEvent& rEvent)
     590             : {
     591           0 :     switch (rEvent.GetCommand())
     592             :     {
     593             :         case CommandEventId::ContextMenu:
     594           0 :             if ( ! SD_MOD()->GetWaterCan())
     595             :             {
     596             :                 // Determine the position where to show the menu.
     597           0 :                 Point aMenuPosition;
     598           0 :                 if (rEvent.IsMouseEvent())
     599             :                 {
     600           0 :                     if (GetItemId(rEvent.GetMousePosPixel()) <= 0)
     601           0 :                         return;
     602           0 :                     aMenuPosition = rEvent.GetMousePosPixel();
     603             :                 }
     604             :                 else
     605             :                 {
     606           0 :                     if (GetSelectItemId() == (sal_uInt16)-1)
     607           0 :                         return;
     608           0 :                     Rectangle aBBox (GetItemRect(GetSelectItemId()));
     609           0 :                     aMenuPosition = aBBox.Center();
     610             :                 }
     611             : 
     612             :                 // Setup the menu.
     613           0 :                 ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP)));
     614           0 :                 FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
     615           0 :                 if (pMenuWindow != NULL)
     616             :                     pMenuWindow->SetPopupModeFlags(
     617           0 :                         pMenuWindow->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose);
     618           0 :                 pMenu->SetSelectHdl(LINK(this, LayoutMenu, OnMenuItemSelected));
     619             : 
     620             :                 // Disable the SID_INSERTPAGE_LAYOUT_MENU item when
     621             :                 // the document is read-only.
     622           0 :                 const SfxPoolItem* pItem = NULL;
     623             :                 const SfxItemState aState (
     624           0 :                     mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
     625           0 :                 if (aState == SfxItemState::DISABLED)
     626           0 :                     pMenu->EnableItem(SID_INSERTPAGE_LAYOUT_MENU, false);
     627             : 
     628             :                 // Show the menu.
     629           0 :                 pMenu->Execute(this, Rectangle(aMenuPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
     630             :             }
     631           0 :             break;
     632             : 
     633             :         default:
     634           0 :             ValueSet::Command(rEvent);
     635           0 :             break;
     636             :     }
     637             : }
     638             : 
     639          24 : IMPL_LINK_NOARG(LayoutMenu, StateChangeHandler)
     640             : {
     641          12 :     InvalidateContent();
     642          12 :     return 0;
     643             : }
     644             : 
     645           0 : IMPL_LINK(LayoutMenu, OnMenuItemSelected, Menu*, pMenu)
     646             : {
     647           0 :     if (pMenu == NULL)
     648             :     {
     649             :         OSL_ENSURE(pMenu!=NULL, "LayoutMenu::OnMenuItemSelected: illegal menu!");
     650           0 :         return 0;
     651             :     }
     652             : 
     653           0 :     pMenu->Deactivate();
     654           0 :     const sal_Int32 nIndex (pMenu->GetCurItemId());
     655             : 
     656           0 :     if (nIndex == SID_TP_APPLY_TO_SELECTED_SLIDES)
     657             :     {
     658           0 :         AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
     659             :     }
     660           0 :     else if (nIndex == SID_INSERTPAGE_LAYOUT_MENU)
     661             :     {
     662             :         // Add arguments to this slot and forward it to the main view
     663             :         // shell.
     664           0 :         InsertPageWithLayout(GetSelectedAutoLayout());
     665             :     }
     666             : 
     667           0 :     return 0;
     668             : }
     669             : 
     670          12 : void LayoutMenu::UpdateSelection()
     671             : {
     672          12 :     bool bItemSelected = false;
     673             : 
     674             :     do
     675             :     {
     676             :         // Get current page of main view.
     677          12 :         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
     678          12 :         if (pViewShell == NULL)
     679           0 :             break;
     680             : 
     681          12 :         SdPage* pCurrentPage = pViewShell->getCurrentPage();
     682          12 :         if (pCurrentPage == NULL)
     683           0 :             break;
     684             : 
     685             :         // Get layout of current page.
     686          12 :         AutoLayout aLayout (pCurrentPage->GetAutoLayout());
     687          12 :         if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
     688             :             break;
     689             : 
     690             :         // Find the entry of the menu for to the layout.
     691          12 :         SetNoSelection();
     692          12 :         sal_uInt16 nItemCount (GetItemCount());
     693          24 :         for (sal_uInt16 nId=1; nId<=nItemCount; nId++)
     694             :         {
     695          24 :             if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
     696             :             {
     697          12 :                 SelectItem(nId);
     698          12 :                 bItemSelected = true;
     699          12 :                 break;
     700             :             }
     701             :         }
     702             :     }
     703             :     while (false);
     704             : 
     705          12 :     if ( ! bItemSelected)
     706           0 :         SetNoSelection();
     707          12 : }
     708             : 
     709         250 : IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
     710             : {
     711         125 :     switch (pEvent->meEventId)
     712             :     {
     713             :         case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
     714             :         case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
     715           0 :             if ( ! mbSelectionUpdatePending)
     716           0 :                 UpdateSelection();
     717           0 :             break;
     718             : 
     719             :         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
     720           0 :             mbIsMainViewChangePending = true;
     721           0 :             break;
     722             : 
     723             :         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
     724          10 :             HideFocus();
     725          10 :             break;
     726             : 
     727             :         case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
     728          29 :             if (mbIsMainViewChangePending)
     729             :             {
     730           0 :                 mbIsMainViewChangePending = false;
     731           0 :                 InvalidateContent();
     732             :             }
     733          29 :             break;
     734             : 
     735             :         default:
     736             :             /* Ignored */
     737          86 :             break;
     738             :     }
     739             : 
     740         125 :     return 0;
     741             : }
     742             : 
     743         170 : IMPL_LINK(LayoutMenu, WindowEventHandler, VclWindowEvent*, pEvent)
     744             : {
     745          85 :     if (pEvent != NULL)
     746             :     {
     747          85 :         switch (pEvent->GetId())
     748             :         {
     749             :             case VCLEVENT_WINDOW_SHOW:
     750             :             case VCLEVENT_WINDOW_RESIZE:
     751          35 :                 SetSizePixel(GetParent()->GetSizePixel());
     752          35 :                 return sal_IntPtr(true);
     753             : 
     754             :             default:
     755          50 :                 return sal_IntPtr(false);
     756             :         }
     757             :     }
     758             : 
     759           0 :     return sal_IntPtr(false);
     760             : }
     761             : 
     762           0 : void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
     763             : {
     764           0 :     Fill();
     765           0 :     ValueSet::DataChanged(rEvent);
     766           0 :     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
     767           0 :     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
     768           0 : }
     769             : 
     770          66 : } } // end of namespace ::sd::sidebar
     771             : 
     772             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11