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

Generated by: LCOV version 1.10