xref: /aoo41x/main/sd/source/ui/sidebar/LayoutMenu.cxx (revision 6dc7b748)
17a32b0c8SAndre Fischer /**************************************************************
27a32b0c8SAndre Fischer  *
37a32b0c8SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
47a32b0c8SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
57a32b0c8SAndre Fischer  * distributed with this work for additional information
67a32b0c8SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
77a32b0c8SAndre Fischer  * to you under the Apache License, Version 2.0 (the
87a32b0c8SAndre Fischer  * "License"); you may not use this file except in compliance
97a32b0c8SAndre Fischer  * with the License.  You may obtain a copy of the License at
107a32b0c8SAndre Fischer  *
117a32b0c8SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
127a32b0c8SAndre Fischer  *
137a32b0c8SAndre Fischer  * Unless required by applicable law or agreed to in writing,
147a32b0c8SAndre Fischer  * software distributed under the License is distributed on an
157a32b0c8SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
167a32b0c8SAndre Fischer  * KIND, either express or implied.  See the License for the
177a32b0c8SAndre Fischer  * specific language governing permissions and limitations
187a32b0c8SAndre Fischer  * under the License.
197a32b0c8SAndre Fischer  *
207a32b0c8SAndre Fischer  *************************************************************/
217a32b0c8SAndre Fischer 
227a32b0c8SAndre Fischer #include "precompiled_sd.hxx"
237a32b0c8SAndre Fischer 
247a32b0c8SAndre Fischer #include "LayoutMenu.hxx"
257a32b0c8SAndre Fischer 
265d65efa0SAndre Fischer #include "SidebarShellManager.hxx"
277a32b0c8SAndre Fischer #include "app.hrc"
287a32b0c8SAndre Fischer #include "drawdoc.hxx"
297a32b0c8SAndre Fischer #include "framework/FrameworkHelper.hxx"
307a32b0c8SAndre Fischer #include "glob.hrc"
317a32b0c8SAndre Fischer #include "glob.hxx"
327a32b0c8SAndre Fischer #include "helpids.h"
337a32b0c8SAndre Fischer #include "pres.hxx"
347a32b0c8SAndre Fischer #include "res_bmp.hrc"
357a32b0c8SAndre Fischer #include "sdpage.hxx"
367a32b0c8SAndre Fischer #include "sdresid.hxx"
377a32b0c8SAndre Fischer #include "strings.hrc"
387a32b0c8SAndre Fischer #include "tools/SlotStateListener.hxx"
397a32b0c8SAndre Fischer #include "DrawController.hxx"
407a32b0c8SAndre Fischer #include "DrawDocShell.hxx"
417a32b0c8SAndre Fischer #include "DrawViewShell.hxx"
427a32b0c8SAndre Fischer #include "EventMultiplexer.hxx"
437a32b0c8SAndre Fischer #include "SlideSorterViewShell.hxx"
447a32b0c8SAndre Fischer #include "ViewShellBase.hxx"
458dcb2a10SAndre Fischer #include <sfx2/sidebar/Theme.hxx>
467a32b0c8SAndre Fischer 
477a32b0c8SAndre Fischer #include <comphelper/processfactory.hxx>
487a32b0c8SAndre Fischer #include <sfx2/app.hxx>
497a32b0c8SAndre Fischer #include <sfx2/dispatch.hxx>
507a32b0c8SAndre Fischer #include <sfx2/objface.hxx>
517a32b0c8SAndre Fischer #include <sfx2/request.hxx>
527a32b0c8SAndre Fischer #include <sfx2/viewfrm.hxx>
537a32b0c8SAndre Fischer #include <svl/languageoptions.hxx>
547a32b0c8SAndre Fischer #include <vcl/image.hxx>
5502c50d82SAndre Fischer #include <vcl/floatwin.hxx>
567a32b0c8SAndre Fischer 
577a32b0c8SAndre Fischer #include <com/sun/star/frame/XController.hpp>
587a32b0c8SAndre Fischer #include <com/sun/star/drawing/framework/XControllerManager.hpp>
597a32b0c8SAndre Fischer #include <com/sun/star/drawing/framework/XView.hpp>
607a32b0c8SAndre Fischer #include <com/sun/star/drawing/framework/ResourceId.hpp>
617a32b0c8SAndre Fischer 
627a32b0c8SAndre Fischer #include <vector>
637a32b0c8SAndre Fischer #include <memory>
647a32b0c8SAndre Fischer 
657a32b0c8SAndre Fischer using namespace ::com::sun::star;
667a32b0c8SAndre Fischer using namespace ::com::sun::star::text;
677a32b0c8SAndre Fischer using namespace ::com::sun::star::uno;
687a32b0c8SAndre Fischer using namespace ::com::sun::star::drawing::framework;
697a32b0c8SAndre Fischer using namespace ::sd::slidesorter;
707a32b0c8SAndre Fischer using ::sd::framework::FrameworkHelper;
717a32b0c8SAndre Fischer 
727a32b0c8SAndre Fischer namespace sd { namespace sidebar {
737a32b0c8SAndre Fischer 
747a32b0c8SAndre Fischer 
757a32b0c8SAndre Fischer 
767a32b0c8SAndre Fischer struct snewfoil_value_info
777a32b0c8SAndre Fischer {
787a32b0c8SAndre Fischer     sal_uInt16 mnBmpResId;
797a32b0c8SAndre Fischer     sal_uInt16 mnHCBmpResId;
807a32b0c8SAndre Fischer     sal_uInt16 mnStrResId;
817a32b0c8SAndre Fischer     WritingMode meWritingMode;
827a32b0c8SAndre Fischer     AutoLayout maAutoLayout;
837a32b0c8SAndre Fischer };
847a32b0c8SAndre Fischer 
857a32b0c8SAndre Fischer static snewfoil_value_info notes[] =
867a32b0c8SAndre Fischer {
877a32b0c8SAndre Fischer     {BMP_FOILN_01, BMP_FOILN_01_H, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
887a32b0c8SAndre Fischer      AUTOLAYOUT_NOTES},
897a32b0c8SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
907a32b0c8SAndre Fischer };
917a32b0c8SAndre Fischer 
927a32b0c8SAndre Fischer static snewfoil_value_info handout[] =
937a32b0c8SAndre Fischer {
947a32b0c8SAndre Fischer     {BMP_FOILH_01, BMP_FOILH_01_H, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
957a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT1},
967a32b0c8SAndre Fischer     {BMP_FOILH_02, BMP_FOILH_02_H, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
977a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT2},
987a32b0c8SAndre Fischer     {BMP_FOILH_03, BMP_FOILH_03_H, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
997a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT3},
1007a32b0c8SAndre Fischer     {BMP_FOILH_04, BMP_FOILH_04_H, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
1017a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT4},
1027a32b0c8SAndre Fischer     {BMP_FOILH_06, BMP_FOILH_06_H, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
1037a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT6},
1047a32b0c8SAndre Fischer     {BMP_FOILH_09, BMP_FOILH_09_H, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
1057a32b0c8SAndre Fischer      AUTOLAYOUT_HANDOUT9},
1067a32b0c8SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
1077a32b0c8SAndre Fischer };
1087a32b0c8SAndre Fischer 
1097a32b0c8SAndre Fischer static snewfoil_value_info standard[] =
1107a32b0c8SAndre Fischer {
1117a32b0c8SAndre Fischer     {BMP_LAYOUT_EMPTY, BMP_LAYOUT_EMPTY_H, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB,        AUTOLAYOUT_NONE},
1127a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD03, BMP_LAYOUT_HEAD03_H, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB,       AUTOLAYOUT_TITLE},
1137a32b0c8SAndre Fischer     {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AUTOLAYOUT_CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_ENUM},
1147a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AUTOLAYOUT_2CONTENT, WritingMode_LR_TB,       AUTOLAYOUT_2TEXT},
1157a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD01, BMP_LAYOUT_HEAD01_H, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB,  AUTOLAYOUT_ONLY_TITLE},
1167a32b0c8SAndre Fischer 	{BMP_LAYOUT_TEXTONLY, BMP_LAYOUT_TEXTONLY_H, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB,   AUTOLAYOUT_ONLY_TEXT},
1177a32b0c8SAndre Fischer     {BMP_LAYOUT_HEAD03B, BMP_LAYOUT_HEAD03B_H, STR_AUTOLAYOUT_2CONTENT_CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_2OBJTEXT},
1187a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD03C, BMP_LAYOUT_HEAD03C_H, STR_AUTOLAYOUT_CONTENT_2CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_TEXT2OBJ},
1197a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD03A, BMP_LAYOUT_HEAD03A_H, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT},
1207a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD02B, BMP_LAYOUT_HEAD02B_H, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT},
1217a32b0c8SAndre Fischer     {BMP_LAYOUT_HEAD04, BMP_LAYOUT_HEAD04_H, STR_AUTOLAYOUT_4CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_4OBJ},
1227a32b0c8SAndre Fischer 	{BMP_LAYOUT_HEAD06, BMP_LAYOUT_HEAD06_H, STR_AUTOLAYOUT_6CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_6CLIPART},
1237a32b0c8SAndre Fischer 
1247a32b0c8SAndre Fischer 	// vertical
1257a32b0c8SAndre Fischer     {BMP_LAYOUT_VERTICAL02, BMP_LAYOUT_VERTICAL02_H, STR_AL_VERT_TITLE_TEXT_CHART, WritingMode_TB_RL,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
1267a32b0c8SAndre Fischer     {BMP_LAYOUT_VERTICAL01, BMP_LAYOUT_VERTICAL01_H, STR_AL_VERT_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
1277a32b0c8SAndre Fischer     {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
1287a32b0c8SAndre Fischer     {BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AL_TITLE_VERT_OUTLINE_CLIPART,   WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
1297a32b0c8SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
1307a32b0c8SAndre Fischer };
1317a32b0c8SAndre Fischer 
1327a32b0c8SAndre Fischer 
1337a32b0c8SAndre Fischer 
1347a32b0c8SAndre Fischer 
LayoutMenu(::Window * pParent,ViewShellBase & rViewShellBase,const cssu::Reference<css::ui::XSidebar> & rxSidebar)1357a32b0c8SAndre Fischer LayoutMenu::LayoutMenu (
1367a32b0c8SAndre Fischer     ::Window* pParent,
1377a32b0c8SAndre Fischer     ViewShellBase& rViewShellBase,
13802c50d82SAndre Fischer     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
1397a32b0c8SAndre Fischer     : ValueSet (pParent),
1407a32b0c8SAndre Fischer       DragSourceHelper(this),
1417a32b0c8SAndre Fischer       DropTargetHelper(this),
1427a32b0c8SAndre Fischer       mrBase(rViewShellBase),
1437a32b0c8SAndre Fischer       mbUseOwnScrollBar(false),
1447a32b0c8SAndre Fischer       mnPreferredColumnCount(3),
1457a32b0c8SAndre Fischer       mxListener(NULL),
1467a32b0c8SAndre Fischer       mbSelectionUpdatePending(true),
1477a32b0c8SAndre Fischer       mbIsMainViewChangePending(false),
14802c50d82SAndre Fischer       mxSidebar(rxSidebar),
1497a32b0c8SAndre Fischer       mbIsDisposed(false)
1507a32b0c8SAndre Fischer {
1517a32b0c8SAndre Fischer     implConstruct( *mrBase.GetDocument()->GetDocSh() );
15202c50d82SAndre Fischer     OSL_TRACE("created LayoutMenu at %x", this);
1538dcb2a10SAndre Fischer 
1548dcb2a10SAndre Fischer     SetStyle(GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_TABSTOP);
1558dcb2a10SAndre Fischer 
1568dcb2a10SAndre Fischer     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
1578dcb2a10SAndre Fischer     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
15802c50d82SAndre Fischer 
1597a32b0c8SAndre Fischer #ifdef DEBUG
1607a32b0c8SAndre Fischer     SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:LayoutMenu")));
1617a32b0c8SAndre Fischer #endif
1627a32b0c8SAndre Fischer }
1637a32b0c8SAndre Fischer 
1647a32b0c8SAndre Fischer 
1657a32b0c8SAndre Fischer 
1667a32b0c8SAndre Fischer 
implConstruct(DrawDocShell & rDocumentShell)1677a32b0c8SAndre Fischer void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell )
1687a32b0c8SAndre Fischer {
1697a32b0c8SAndre Fischer     OSL_ENSURE( mrBase.GetDocument()->GetDocSh() == &rDocumentShell,
1707a32b0c8SAndre Fischer         "LayoutMenu::implConstruct: hmm?" );
1717a32b0c8SAndre Fischer     // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
1727a32b0c8SAndre Fischer 
1737a32b0c8SAndre Fischer 	SetStyle (
1747a32b0c8SAndre Fischer         ( GetStyle()  & ~(WB_ITEMBORDER) )
1757a32b0c8SAndre Fischer         | WB_TABSTOP
1768dcb2a10SAndre Fischer         | WB_MENUSTYLEVALUESET
1777a32b0c8SAndre Fischer         | WB_NO_DIRECTSELECT
1787a32b0c8SAndre Fischer         );
1797a32b0c8SAndre Fischer     if (mbUseOwnScrollBar)
1807a32b0c8SAndre Fischer         SetStyle (GetStyle() | WB_VSCROLL);
1817a32b0c8SAndre Fischer 	SetExtraSpacing(2);
1827a32b0c8SAndre Fischer 	SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
1837a32b0c8SAndre Fischer     InvalidateContent();
1847a32b0c8SAndre Fischer 
1857a32b0c8SAndre Fischer     Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
1867a32b0c8SAndre Fischer     mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
1877a32b0c8SAndre Fischer         ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
1887a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
1897a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
1907a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
1917a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
1927a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
1937a32b0c8SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
1947a32b0c8SAndre Fischer 
1957a32b0c8SAndre Fischer     Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS);
1967a32b0c8SAndre Fischer     SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
1977a32b0c8SAndre Fischer 
1987a32b0c8SAndre Fischer     Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
1997a32b0c8SAndre Fischer     mxListener = new ::sd::tools::SlotStateListener(
2007a32b0c8SAndre Fischer         aStateChangeLink,
2017a32b0c8SAndre Fischer         Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
2027a32b0c8SAndre Fischer         ::rtl::OUString::createFromAscii(".uno:VerticalTextState"));
2037a32b0c8SAndre Fischer 
2047a32b0c8SAndre Fischer     SetSizePixel(GetParent()->GetSizePixel());
2057a32b0c8SAndre Fischer     Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
2067a32b0c8SAndre Fischer     GetParent()->AddEventListener(aWindowEventHandlerLink);
2077a32b0c8SAndre Fischer }
2087a32b0c8SAndre Fischer 
2097a32b0c8SAndre Fischer 
2107a32b0c8SAndre Fischer 
2117a32b0c8SAndre Fischer 
~LayoutMenu(void)2127a32b0c8SAndre Fischer LayoutMenu::~LayoutMenu (void)
2137a32b0c8SAndre Fischer {
21402c50d82SAndre Fischer     OSL_TRACE("destroying LayoutMenu at %x", this);
2157a32b0c8SAndre Fischer     Dispose();
2167a32b0c8SAndre Fischer }
2177a32b0c8SAndre Fischer 
2187a32b0c8SAndre Fischer 
2197a32b0c8SAndre Fischer 
2207a32b0c8SAndre Fischer 
Dispose(void)2217a32b0c8SAndre Fischer void LayoutMenu::Dispose (void)
2227a32b0c8SAndre Fischer {
2237a32b0c8SAndre Fischer     if (mbIsDisposed)
2247a32b0c8SAndre Fischer         return;
2257a32b0c8SAndre Fischer 
22602c50d82SAndre Fischer     OSL_TRACE("disposing LayoutMenu at %x", this);
22702c50d82SAndre Fischer 
2287a32b0c8SAndre Fischer     mbIsDisposed = true;
2297a32b0c8SAndre Fischer 
2307a32b0c8SAndre Fischer     Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
2317a32b0c8SAndre Fischer     if (xComponent.is())
2327a32b0c8SAndre Fischer         xComponent->dispose();
2337a32b0c8SAndre Fischer 
2347a32b0c8SAndre Fischer     Clear();
2357a32b0c8SAndre Fischer     Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
2367a32b0c8SAndre Fischer     mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
2377a32b0c8SAndre Fischer 
2387a32b0c8SAndre Fischer     Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
2397a32b0c8SAndre Fischer     GetParent()->RemoveEventListener(aWindowEventHandlerLink);
2407a32b0c8SAndre Fischer }
2417a32b0c8SAndre Fischer 
2427a32b0c8SAndre Fischer 
2437a32b0c8SAndre Fischer 
2447a32b0c8SAndre Fischer 
GetSelectedAutoLayout(void)2457a32b0c8SAndre Fischer AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
2467a32b0c8SAndre Fischer {
2477a32b0c8SAndre Fischer     AutoLayout aResult = AUTOLAYOUT_NONE;
2487a32b0c8SAndre Fischer 
2497a32b0c8SAndre Fischer     if ( ! IsNoSelection() && GetSelectItemId()!=0)
2507a32b0c8SAndre Fischer     {
2517a32b0c8SAndre Fischer         AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
2527a32b0c8SAndre Fischer         if (pLayout != NULL)
2537a32b0c8SAndre Fischer             aResult = *pLayout;
2547a32b0c8SAndre Fischer     }
2557a32b0c8SAndre Fischer 
2567a32b0c8SAndre Fischer     return aResult;
2577a32b0c8SAndre Fischer }
2587a32b0c8SAndre Fischer 
2597a32b0c8SAndre Fischer 
2607a32b0c8SAndre Fischer 
2617a32b0c8SAndre Fischer 
2627a32b0c8SAndre Fischer /** The preferred size depends on the preferred number of columns, the
2637a32b0c8SAndre Fischer     number of items, and the size of the items.
2647a32b0c8SAndre Fischer */
GetPreferredSize(void)2657a32b0c8SAndre Fischer Size LayoutMenu::GetPreferredSize (void)
2667a32b0c8SAndre Fischer {
2677a32b0c8SAndre Fischer     Size aItemSize = CalcItemSizePixel (Size());
2687a32b0c8SAndre Fischer     Size aPreferredWindowSize = CalcWindowSizePixel (
2697a32b0c8SAndre Fischer         aItemSize,
2707a32b0c8SAndre Fischer          (sal_uInt16)mnPreferredColumnCount,
2717a32b0c8SAndre Fischer         (sal_uInt16)CalculateRowCount (aItemSize,mnPreferredColumnCount));
2727a32b0c8SAndre Fischer     return aPreferredWindowSize;
2737a32b0c8SAndre Fischer }
2747a32b0c8SAndre Fischer 
2757a32b0c8SAndre Fischer 
2767a32b0c8SAndre Fischer 
2777a32b0c8SAndre Fischer 
GetPreferredWidth(sal_Int32 nHeight)2787a32b0c8SAndre Fischer sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight)
2797a32b0c8SAndre Fischer {
2807a32b0c8SAndre Fischer     sal_Int32 nPreferredWidth = 100;
2817a32b0c8SAndre Fischer     if (GetItemCount() > 0)
2827a32b0c8SAndre Fischer     {
2837a32b0c8SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
2847a32b0c8SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
2857a32b0c8SAndre Fischer         if (nHeight>0 && aItemSize.Height()>0)
2867a32b0c8SAndre Fischer         {
2877a32b0c8SAndre Fischer             int nRowCount = nHeight / aItemSize.Height();
2887a32b0c8SAndre Fischer             if (nRowCount <= 0)
2897a32b0c8SAndre Fischer                 nRowCount = 1;
2907a32b0c8SAndre Fischer             int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount;
2917a32b0c8SAndre Fischer             nPreferredWidth = nColumnCount * aItemSize.Width();
2927a32b0c8SAndre Fischer         }
2937a32b0c8SAndre Fischer     }
2947a32b0c8SAndre Fischer 
2957a32b0c8SAndre Fischer     return nPreferredWidth;
2967a32b0c8SAndre Fischer }
2977a32b0c8SAndre Fischer 
2987a32b0c8SAndre Fischer 
2997a32b0c8SAndre Fischer 
3007a32b0c8SAndre Fischer 
GetHeightForWidth(const sal_Int32 nWidth)3017a32b0c8SAndre Fischer ui::LayoutSize LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth)
3027a32b0c8SAndre Fischer {
3037a32b0c8SAndre Fischer     sal_Int32 nPreferredHeight = 200;
3047a32b0c8SAndre Fischer     if ( ! mbUseOwnScrollBar && GetItemCount()>0)
3057a32b0c8SAndre Fischer     {
3067a32b0c8SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
3077a32b0c8SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
3087a32b0c8SAndre Fischer         if (nWidth>0 && aItemSize.Width()>0)
3097a32b0c8SAndre Fischer         {
3107a32b0c8SAndre Fischer             aItemSize.Width() += 8;
3117a32b0c8SAndre Fischer             aItemSize.Height() += 8;
3127a32b0c8SAndre Fischer             int nColumnCount = nWidth / aItemSize.Width();
3137a32b0c8SAndre Fischer             if (nColumnCount <= 0)
3147a32b0c8SAndre Fischer                 nColumnCount = 1;
3157a32b0c8SAndre Fischer             else if (nColumnCount > 4)
3167a32b0c8SAndre Fischer                 nColumnCount = 4;
3177a32b0c8SAndre Fischer             int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
3187a32b0c8SAndre Fischer             nPreferredHeight = nRowCount * aItemSize.Height();
3197a32b0c8SAndre Fischer         }
3207a32b0c8SAndre Fischer     }
3217a32b0c8SAndre Fischer     return ui::LayoutSize(nPreferredHeight,nPreferredHeight,nPreferredHeight);
3227a32b0c8SAndre Fischer }
3237a32b0c8SAndre Fischer 
3247a32b0c8SAndre Fischer 
3257a32b0c8SAndre Fischer 
3267a32b0c8SAndre Fischer 
GetMinimumWidth(void)3277a32b0c8SAndre Fischer sal_Int32 LayoutMenu::GetMinimumWidth (void)
3287a32b0c8SAndre Fischer {
3297a32b0c8SAndre Fischer     sal_Int32 nMinimumWidth = 0;
3307a32b0c8SAndre Fischer     if (GetItemCount()>0)
3317a32b0c8SAndre Fischer     {
3327a32b0c8SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
3337a32b0c8SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
3347a32b0c8SAndre Fischer         nMinimumWidth = aItemSize.Width();
3357a32b0c8SAndre Fischer     }
3367a32b0c8SAndre Fischer     return nMinimumWidth;
3377a32b0c8SAndre Fischer }
3387a32b0c8SAndre Fischer 
3397a32b0c8SAndre Fischer 
3407a32b0c8SAndre Fischer 
3417a32b0c8SAndre Fischer 
Paint(const Rectangle & rRect)3427a32b0c8SAndre Fischer void LayoutMenu::Paint (const Rectangle& rRect)
3437a32b0c8SAndre Fischer {
3447a32b0c8SAndre Fischer     if (mbSelectionUpdatePending)
3457a32b0c8SAndre Fischer     {
3467a32b0c8SAndre Fischer         mbSelectionUpdatePending = false;
3477a32b0c8SAndre Fischer         UpdateSelection();
3487a32b0c8SAndre Fischer     }
3497a32b0c8SAndre Fischer     ValueSet::Paint (rRect);
3507a32b0c8SAndre Fischer }
3517a32b0c8SAndre Fischer 
3527a32b0c8SAndre Fischer 
3537a32b0c8SAndre Fischer 
3547a32b0c8SAndre Fischer 
Resize(void)3557a32b0c8SAndre Fischer void LayoutMenu::Resize (void)
3567a32b0c8SAndre Fischer {
3577a32b0c8SAndre Fischer     Size aWindowSize = GetOutputSizePixel();
3587a32b0c8SAndre Fischer     if (IsVisible() && aWindowSize.Width() > 0)
3597a32b0c8SAndre Fischer     {
3607a32b0c8SAndre Fischer         // Calculate the number of rows and columns.
3617a32b0c8SAndre Fischer         if (GetItemCount() > 0)
3627a32b0c8SAndre Fischer         {
3637a32b0c8SAndre Fischer             Image aImage = GetItemImage(GetItemId(0));
3647a32b0c8SAndre Fischer             Size aItemSize = CalcItemSizePixel (
3657a32b0c8SAndre Fischer                 aImage.GetSizePixel());
3667a32b0c8SAndre Fischer             aItemSize.Width() += 8;
3677a32b0c8SAndre Fischer             aItemSize.Height() += 8;
3687a32b0c8SAndre Fischer             int nColumnCount = aWindowSize.Width() / aItemSize.Width();
3697a32b0c8SAndre Fischer             if (nColumnCount < 1)
3707a32b0c8SAndre Fischer                 nColumnCount = 1;
3717a32b0c8SAndre Fischer             else if (nColumnCount > 4)
3727a32b0c8SAndre Fischer                 nColumnCount = 4;
3737a32b0c8SAndre Fischer 
3747a32b0c8SAndre Fischer             int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
3757a32b0c8SAndre Fischer 
3767a32b0c8SAndre Fischer             SetColCount ((sal_uInt16)nColumnCount);
3777a32b0c8SAndre Fischer             SetLineCount ((sal_uInt16)nRowCount);
3787a32b0c8SAndre Fischer         }
3797a32b0c8SAndre Fischer     }
3807a32b0c8SAndre Fischer 
3817a32b0c8SAndre Fischer     ValueSet::Resize ();
3827a32b0c8SAndre Fischer }
3837a32b0c8SAndre Fischer 
3847a32b0c8SAndre Fischer 
3857a32b0c8SAndre Fischer 
3867a32b0c8SAndre Fischer 
MouseButtonDown(const MouseEvent & rEvent)3877a32b0c8SAndre Fischer void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
3887a32b0c8SAndre Fischer {
3897a32b0c8SAndre Fischer     // As a preparation for the context menu the item under the mouse is
3907a32b0c8SAndre Fischer     // selected.
3917a32b0c8SAndre Fischer     if (rEvent.IsRight())
3927a32b0c8SAndre Fischer     {
3937a32b0c8SAndre Fischer         ReleaseMouse();
3947a32b0c8SAndre Fischer         sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel());
3957a32b0c8SAndre Fischer         if (nIndex > 0)
3967a32b0c8SAndre Fischer             SelectItem(nIndex);
3977a32b0c8SAndre Fischer     }
3987a32b0c8SAndre Fischer 
3997a32b0c8SAndre Fischer     ValueSet::MouseButtonDown (rEvent);
4007a32b0c8SAndre Fischer }
4017a32b0c8SAndre Fischer 
4027a32b0c8SAndre Fischer 
4037a32b0c8SAndre Fischer 
4047a32b0c8SAndre Fischer 
InsertPageWithLayout(AutoLayout aLayout)4057a32b0c8SAndre Fischer void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
4067a32b0c8SAndre Fischer {
4077a32b0c8SAndre Fischer     ViewShell* pViewShell = mrBase.GetMainViewShell().get();
4087a32b0c8SAndre Fischer     if (pViewShell == NULL)
4097a32b0c8SAndre Fischer         return;
4107a32b0c8SAndre Fischer 
4117a32b0c8SAndre Fischer     SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
4127a32b0c8SAndre Fischer     if (pViewFrame == NULL)
4137a32b0c8SAndre Fischer         return;
4147a32b0c8SAndre Fischer 
4157a32b0c8SAndre Fischer     SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
4167a32b0c8SAndre Fischer     if (pDispatcher == NULL)
4177a32b0c8SAndre Fischer         return;
4187a32b0c8SAndre Fischer 
4197a32b0c8SAndre Fischer     // Call SID_INSERTPAGE with the right arguments.  This is because
4207a32b0c8SAndre Fischer     // the popup menu can not call this slot with arguments directly.
4217a32b0c8SAndre Fischer     SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
4227a32b0c8SAndre Fischer     if (aRequest.GetArgs() != NULL)
4237a32b0c8SAndre Fischer     {
4247a32b0c8SAndre Fischer         pDispatcher->Execute(
4257a32b0c8SAndre Fischer             SID_INSERTPAGE,
4267a32b0c8SAndre Fischer             SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
4277a32b0c8SAndre Fischer             *aRequest.GetArgs());
4287a32b0c8SAndre Fischer     }
4297a32b0c8SAndre Fischer     UpdateSelection();
4307a32b0c8SAndre Fischer }
4317a32b0c8SAndre Fischer 
4327a32b0c8SAndre Fischer 
4337a32b0c8SAndre Fischer 
4347a32b0c8SAndre Fischer 
InvalidateContent(void)4357a32b0c8SAndre Fischer void LayoutMenu::InvalidateContent (void)
4367a32b0c8SAndre Fischer {
4377a32b0c8SAndre Fischer     // Throw away the current set and fill the menu anew according to the
4387a32b0c8SAndre Fischer     // current settings (this includes the support for vertical writing.)
4397a32b0c8SAndre Fischer     Fill();
44002c50d82SAndre Fischer 
44102c50d82SAndre Fischer     if (mxSidebar.is())
44202c50d82SAndre Fischer         mxSidebar->requestLayout();
4437a32b0c8SAndre Fischer }
4447a32b0c8SAndre Fischer 
4457a32b0c8SAndre Fischer 
4467a32b0c8SAndre Fischer 
4477a32b0c8SAndre Fischer 
CalculateRowCount(const Size &,int nColumnCount)4487a32b0c8SAndre Fischer int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
4497a32b0c8SAndre Fischer {
4507a32b0c8SAndre Fischer     int nRowCount = 0;
4517a32b0c8SAndre Fischer 
4527a32b0c8SAndre Fischer     if (GetItemCount() > 0 && nColumnCount > 0)
4537a32b0c8SAndre Fischer     {
4547a32b0c8SAndre Fischer         nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
4557a32b0c8SAndre Fischer         //        nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
4567a32b0c8SAndre Fischer         if (nRowCount < 1)
4577a32b0c8SAndre Fischer             nRowCount = 1;
4587a32b0c8SAndre Fischer     }
4597a32b0c8SAndre Fischer 
4607a32b0c8SAndre Fischer     return nRowCount;
4617a32b0c8SAndre Fischer }
4627a32b0c8SAndre Fischer 
4637a32b0c8SAndre Fischer 
4647a32b0c8SAndre Fischer 
4657a32b0c8SAndre Fischer 
IMPL_LINK(LayoutMenu,ClickHandler,ValueSet *,EMPTYARG)4667a32b0c8SAndre Fischer IMPL_LINK(LayoutMenu, ClickHandler, ValueSet*, EMPTYARG)
4677a32b0c8SAndre Fischer {
4687a32b0c8SAndre Fischer     AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
4697a32b0c8SAndre Fischer     return 0;
4707a32b0c8SAndre Fischer }
4717a32b0c8SAndre Fischer 
4727a32b0c8SAndre Fischer 
4737a32b0c8SAndre Fischer 
4747a32b0c8SAndre Fischer 
4757a32b0c8SAndre Fischer /** The specified layout is assigned to the current page of the view shell
4767a32b0c8SAndre Fischer     in the center pane.
4777a32b0c8SAndre Fischer */
AssignLayoutToSelectedSlides(AutoLayout aLayout)4787a32b0c8SAndre Fischer void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
4797a32b0c8SAndre Fischer {
4807a32b0c8SAndre Fischer     using namespace ::sd::slidesorter;
4817a32b0c8SAndre Fischer     using namespace ::sd::slidesorter::controller;
4827a32b0c8SAndre Fischer 
4837a32b0c8SAndre Fischer     do
4847a32b0c8SAndre Fischer     {
4857a32b0c8SAndre Fischer         // The view shell in the center pane has to be present.
4867a32b0c8SAndre Fischer         ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
4877a32b0c8SAndre Fischer         if (pMainViewShell == NULL)
4887a32b0c8SAndre Fischer             break;
4897a32b0c8SAndre Fischer 
4907a32b0c8SAndre Fischer         // Determine if the current view is in an invalid master page mode.
4917a32b0c8SAndre Fischer         // The handout view is always in master page mode and therefore not
4927a32b0c8SAndre Fischer         // invalid.
4937a32b0c8SAndre Fischer         bool bMasterPageMode (false);
4947a32b0c8SAndre Fischer         switch (pMainViewShell->GetShellType())
4957a32b0c8SAndre Fischer         {
4967a32b0c8SAndre Fischer             case ViewShell::ST_NOTES:
4977a32b0c8SAndre Fischer             case ViewShell::ST_IMPRESS:
4987a32b0c8SAndre Fischer             {
4997a32b0c8SAndre Fischer                 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
5007a32b0c8SAndre Fischer                 if (pDrawViewShell != NULL)
5017a32b0c8SAndre Fischer                     if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
5027a32b0c8SAndre Fischer                         bMasterPageMode = true;
5037a32b0c8SAndre Fischer             }
5047a32b0c8SAndre Fischer 			default:
5057a32b0c8SAndre Fischer 				break;
5067a32b0c8SAndre Fischer         }
5077a32b0c8SAndre Fischer         if (bMasterPageMode)
5087a32b0c8SAndre Fischer             break;
5097a32b0c8SAndre Fischer 
5107a32b0c8SAndre Fischer         // Get a list of all selected slides and call the SID_MODIFYPAGE
5117a32b0c8SAndre Fischer         // slot for all of them.
5127a32b0c8SAndre Fischer 		::sd::slidesorter::SharedPageSelection pPageSelection;
5137a32b0c8SAndre Fischer 
5147a32b0c8SAndre Fischer         // Get a list of selected pages.
5157a32b0c8SAndre Fischer         // First we try to obtain this list from a slide sorter.  This is
5167a32b0c8SAndre Fischer         // possible only some of the view shells in the center pane.  When
5177a32b0c8SAndre Fischer         // no valid slide sorter is available then ask the main view shell
5187a32b0c8SAndre Fischer         // for its current page.
5197a32b0c8SAndre Fischer         SlideSorterViewShell* pSlideSorter = NULL;
5207a32b0c8SAndre Fischer         switch (pMainViewShell->GetShellType())
5217a32b0c8SAndre Fischer         {
5227a32b0c8SAndre Fischer             case ViewShell::ST_IMPRESS:
5237a32b0c8SAndre Fischer             case ViewShell::ST_NOTES:
5247a32b0c8SAndre Fischer             case ViewShell::ST_SLIDE_SORTER:
5257a32b0c8SAndre Fischer                 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
5267a32b0c8SAndre Fischer                 break;
5277a32b0c8SAndre Fischer 			default:
5287a32b0c8SAndre Fischer 				break;
5297a32b0c8SAndre Fischer         }
5307a32b0c8SAndre Fischer 		if (pSlideSorter != NULL)
5317a32b0c8SAndre Fischer 		{
5327a32b0c8SAndre Fischer 			// There is a slide sorter visible so get the list of selected pages from it.
5337a32b0c8SAndre Fischer             pPageSelection = pSlideSorter->GetPageSelection();
5347a32b0c8SAndre Fischer 		}
5357a32b0c8SAndre Fischer 
5367a32b0c8SAndre Fischer 		if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() )
5377a32b0c8SAndre Fischer 		{
5387a32b0c8SAndre Fischer 			// No valid slide sorter available.  Ask the main view shell for
5397a32b0c8SAndre Fischer 			// its current page.
5407a32b0c8SAndre Fischer             pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
5417a32b0c8SAndre Fischer             pPageSelection->push_back(pMainViewShell->GetActualPage());
5427a32b0c8SAndre Fischer 		}
5437a32b0c8SAndre Fischer 
5447a32b0c8SAndre Fischer 
5457a32b0c8SAndre Fischer 		if (pPageSelection->empty())
5467a32b0c8SAndre Fischer 			break;
5477a32b0c8SAndre Fischer 
5487a32b0c8SAndre Fischer 		::std::vector<SdPage*>::iterator iPage;
5497a32b0c8SAndre Fischer 		for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
5507a32b0c8SAndre Fischer 			{
5517a32b0c8SAndre Fischer 				if ((*iPage) == NULL)
5527a32b0c8SAndre Fischer 					continue;
5537a32b0c8SAndre Fischer 
5547a32b0c8SAndre Fischer 				// Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
5557a32b0c8SAndre Fischer 				SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
5567a32b0c8SAndre Fischer 				aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
5577a32b0c8SAndre Fischer 				aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
5587a32b0c8SAndre Fischer 				pMainViewShell->ExecuteSlot (aRequest, sal_Bool(sal_False));
5597a32b0c8SAndre Fischer 			}
5607a32b0c8SAndre Fischer     }
5617a32b0c8SAndre Fischer     while(false);
5627a32b0c8SAndre Fischer }
5637a32b0c8SAndre Fischer 
5647a32b0c8SAndre Fischer 
5657a32b0c8SAndre Fischer 
5667a32b0c8SAndre Fischer 
CreateRequest(sal_uInt16 nSlotId,AutoLayout aLayout)5677a32b0c8SAndre Fischer SfxRequest LayoutMenu::CreateRequest (
5687a32b0c8SAndre Fischer     sal_uInt16 nSlotId,
5697a32b0c8SAndre Fischer     AutoLayout aLayout)
5707a32b0c8SAndre Fischer {
5717a32b0c8SAndre Fischer     SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
5727a32b0c8SAndre Fischer 
5737a32b0c8SAndre Fischer     do
5747a32b0c8SAndre Fischer     {
5757a32b0c8SAndre Fischer         SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
5767a32b0c8SAndre Fischer         sal_uInt8 aBackground (rLayerAdmin.GetLayerID(
5777a32b0c8SAndre Fischer             String(SdResId(STR_LAYER_BCKGRND)), sal_False));
5787a32b0c8SAndre Fischer         sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(
5797a32b0c8SAndre Fischer             String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False));
5807a32b0c8SAndre Fischer         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
5817a32b0c8SAndre Fischer         if (pViewShell == NULL)
5827a32b0c8SAndre Fischer             break;
5837a32b0c8SAndre Fischer         SdPage* pPage = pViewShell->GetActualPage();
5847a32b0c8SAndre Fischer         if (pPage == NULL)
5857a32b0c8SAndre Fischer             break;
5867a32b0c8SAndre Fischer 
5877a32b0c8SAndre Fischer         SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
5887a32b0c8SAndre Fischer 
5897a32b0c8SAndre Fischer         aRequest.AppendItem(
5907a32b0c8SAndre Fischer             SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName()));
5917a32b0c8SAndre Fischer         aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
5927a32b0c8SAndre Fischer         aRequest.AppendItem(
5937a32b0c8SAndre Fischer             SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
5947a32b0c8SAndre Fischer         aRequest.AppendItem(
5957a32b0c8SAndre Fischer             SfxBoolItem(
5967a32b0c8SAndre Fischer                 ID_VAL_ISPAGEOBJ,
5977a32b0c8SAndre Fischer                 aVisibleLayers.IsSet(aBackgroundObject)));
5987a32b0c8SAndre Fischer     }
5997a32b0c8SAndre Fischer     while (false);
6007a32b0c8SAndre Fischer 
6017a32b0c8SAndre Fischer     return aRequest;
6027a32b0c8SAndre Fischer }
6037a32b0c8SAndre Fischer 
6047a32b0c8SAndre Fischer 
6057a32b0c8SAndre Fischer 
6067a32b0c8SAndre Fischer 
Fill(void)6077a32b0c8SAndre Fischer void LayoutMenu::Fill (void)
6087a32b0c8SAndre Fischer {
6097a32b0c8SAndre Fischer 	const bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
6107a32b0c8SAndre Fischer 	SvtLanguageOptions aLanguageOptions;
6117a32b0c8SAndre Fischer     sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
6127a32b0c8SAndre Fischer     SdDrawDocument* pDocument = mrBase.GetDocument();
6137a32b0c8SAndre Fischer     sal_Bool bRightToLeft = (pDocument!=NULL
6147a32b0c8SAndre Fischer         && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
6157a32b0c8SAndre Fischer 
6167a32b0c8SAndre Fischer     // Get URL of the view in the center pane.
6177a32b0c8SAndre Fischer     ::rtl::OUString sCenterPaneViewName;
6187a32b0c8SAndre Fischer     try
6197a32b0c8SAndre Fischer     {
6207a32b0c8SAndre Fischer         Reference<XControllerManager> xControllerManager (
6217a32b0c8SAndre Fischer             Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
6227a32b0c8SAndre Fischer         Reference<XResourceId> xPaneId (ResourceId::create(
6237a32b0c8SAndre Fischer             ::comphelper::getProcessComponentContext(),
6247a32b0c8SAndre Fischer             FrameworkHelper::msCenterPaneURL));
6257a32b0c8SAndre Fischer         Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
6267a32b0c8SAndre Fischer         if (xView.is())
6277a32b0c8SAndre Fischer             sCenterPaneViewName = xView->getResourceId()->getResourceURL();
6287a32b0c8SAndre Fischer     }
6297a32b0c8SAndre Fischer     catch (RuntimeException&)
6307a32b0c8SAndre Fischer     {}
6317a32b0c8SAndre Fischer 
6327a32b0c8SAndre Fischer 	snewfoil_value_info* pInfo = NULL;
6337a32b0c8SAndre Fischer     if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
6347a32b0c8SAndre Fischer     {
6357a32b0c8SAndre Fischer         pInfo = notes;
6367a32b0c8SAndre Fischer     }
6377a32b0c8SAndre Fischer     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
6387a32b0c8SAndre Fischer     {
6397a32b0c8SAndre Fischer         pInfo = handout;
6407a32b0c8SAndre Fischer     }
6417a32b0c8SAndre Fischer     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
6427a32b0c8SAndre Fischer         || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
6437a32b0c8SAndre Fischer     {
6447a32b0c8SAndre Fischer         pInfo = standard;
6457a32b0c8SAndre Fischer     }
6467a32b0c8SAndre Fischer     else
6477a32b0c8SAndre Fischer     {
6487a32b0c8SAndre Fischer         pInfo = NULL;
6497a32b0c8SAndre Fischer 	}
6507a32b0c8SAndre Fischer 
6517a32b0c8SAndre Fischer     Clear();
6527a32b0c8SAndre Fischer     int n = 0;
6537a32b0c8SAndre Fischer 	for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
6547a32b0c8SAndre Fischer 	{
6557a32b0c8SAndre Fischer         if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
6567a32b0c8SAndre Fischer         {
6577a32b0c8SAndre Fischer             BitmapEx aBmp (SdResId (bHighContrast
6587a32b0c8SAndre Fischer                              ? pInfo->mnHCBmpResId
6597a32b0c8SAndre Fischer                              : pInfo->mnBmpResId));
6607a32b0c8SAndre Fischer 
6617a32b0c8SAndre Fischer             if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
6627a32b0c8SAndre Fischer                 aBmp.Mirror (BMP_MIRROR_HORZ);
6637a32b0c8SAndre Fischer 
6647a32b0c8SAndre Fischer             InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId)));
6657a32b0c8SAndre Fischer             SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
6667a32b0c8SAndre Fischer             n++;
6677a32b0c8SAndre Fischer         }
6687a32b0c8SAndre Fischer 	}
6697a32b0c8SAndre Fischer 
6707a32b0c8SAndre Fischer     mbSelectionUpdatePending = true;
6717a32b0c8SAndre Fischer }
6727a32b0c8SAndre Fischer 
6737a32b0c8SAndre Fischer 
6747a32b0c8SAndre Fischer 
6757a32b0c8SAndre Fischer 
Clear(void)6767a32b0c8SAndre Fischer void LayoutMenu::Clear (void)
6777a32b0c8SAndre Fischer {
6787a32b0c8SAndre Fischer     for (sal_uInt16 nId=1; nId<=GetItemCount(); nId++)
6797a32b0c8SAndre Fischer         delete static_cast<AutoLayout*>(GetItemData(nId));
6807a32b0c8SAndre Fischer     ValueSet::Clear();
6817a32b0c8SAndre Fischer }
6827a32b0c8SAndre Fischer 
6837a32b0c8SAndre Fischer 
6847a32b0c8SAndre Fischer 
StartDrag(sal_Int8,const Point &)6857a32b0c8SAndre Fischer void LayoutMenu::StartDrag (sal_Int8 , const Point& )
6867a32b0c8SAndre Fischer {
6877a32b0c8SAndre Fischer }
6887a32b0c8SAndre Fischer 
6897a32b0c8SAndre Fischer 
6907a32b0c8SAndre Fischer 
6917a32b0c8SAndre Fischer 
AcceptDrop(const AcceptDropEvent &)6927a32b0c8SAndre Fischer sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
6937a32b0c8SAndre Fischer {
6947a32b0c8SAndre Fischer     return 0;
6957a32b0c8SAndre Fischer }
6967a32b0c8SAndre Fischer 
6977a32b0c8SAndre Fischer 
6987a32b0c8SAndre Fischer 
6997a32b0c8SAndre Fischer 
ExecuteDrop(const ExecuteDropEvent &)7007a32b0c8SAndre Fischer sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
7017a32b0c8SAndre Fischer {
7027a32b0c8SAndre Fischer     return 0;
7037a32b0c8SAndre Fischer }
7047a32b0c8SAndre Fischer 
7057a32b0c8SAndre Fischer 
7067a32b0c8SAndre Fischer 
7077a32b0c8SAndre Fischer 
Command(const CommandEvent & rEvent)7087a32b0c8SAndre Fischer void LayoutMenu::Command (const CommandEvent& rEvent)
7097a32b0c8SAndre Fischer {
7107a32b0c8SAndre Fischer     switch (rEvent.GetCommand())
7117a32b0c8SAndre Fischer     {
7127a32b0c8SAndre Fischer         case COMMAND_CONTEXTMENU:
7137a32b0c8SAndre Fischer             if ( ! SD_MOD()->GetWaterCan())
7147a32b0c8SAndre Fischer             {
71502c50d82SAndre Fischer                 // Determine the position where to show the menu.
71602c50d82SAndre Fischer                 Point aMenuPosition;
7177a32b0c8SAndre Fischer                 if (rEvent.IsMouseEvent())
7187a32b0c8SAndre Fischer                 {
71902c50d82SAndre Fischer                     if (GetItemId(rEvent.GetMousePosPixel()) <= 0)
72002c50d82SAndre Fischer                         return;
72102c50d82SAndre Fischer                     aMenuPosition = rEvent.GetMousePosPixel();
7227a32b0c8SAndre Fischer                 }
7237a32b0c8SAndre Fischer                 else
7247a32b0c8SAndre Fischer                 {
72502c50d82SAndre Fischer                     if (GetSelectItemId() == (sal_uInt16)-1)
72602c50d82SAndre Fischer                         return;
72702c50d82SAndre Fischer                     Rectangle aBBox (GetItemRect(GetSelectItemId()));
72802c50d82SAndre Fischer                     aMenuPosition = aBBox.Center();
7297a32b0c8SAndre Fischer                 }
73002c50d82SAndre Fischer 
73102c50d82SAndre Fischer                 // Setup the menu.
73202c50d82SAndre Fischer                 ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP)));
73302c50d82SAndre Fischer                 FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
73402c50d82SAndre Fischer                 if (pMenuWindow != NULL)
73502c50d82SAndre Fischer                     pMenuWindow->SetPopupModeFlags(
73602c50d82SAndre Fischer                         pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
73702c50d82SAndre Fischer                 pMenu->SetSelectHdl(LINK(this, LayoutMenu, OnMenuItemSelected));
73802c50d82SAndre Fischer 
73902c50d82SAndre Fischer                 // Disable the SID_INSERTPAGE_LAYOUT_MENU item when
74002c50d82SAndre Fischer                 // the document is read-only.
74102c50d82SAndre Fischer                 const SfxPoolItem* pItem = NULL;
74202c50d82SAndre Fischer                 const SfxItemState aState (
74302c50d82SAndre Fischer                     mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
74402c50d82SAndre Fischer                 if (aState == SFX_ITEM_DISABLED)
74502c50d82SAndre Fischer                     pMenu->EnableItem(SID_INSERTPAGE_LAYOUT_MENU, sal_False);
74602c50d82SAndre Fischer 
74702c50d82SAndre Fischer                 // Show the menu.
74802c50d82SAndre Fischer                 pMenu->Execute(this, Rectangle(aMenuPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN);
7497a32b0c8SAndre Fischer             }
7507a32b0c8SAndre Fischer             break;
7517a32b0c8SAndre Fischer 
7527a32b0c8SAndre Fischer         default:
7537a32b0c8SAndre Fischer             ValueSet::Command(rEvent);
7547a32b0c8SAndre Fischer             break;
7557a32b0c8SAndre Fischer     }
7567a32b0c8SAndre Fischer }
7577a32b0c8SAndre Fischer 
7587a32b0c8SAndre Fischer 
7597a32b0c8SAndre Fischer 
7607a32b0c8SAndre Fischer 
IMPL_LINK(LayoutMenu,StateChangeHandler,::rtl::OUString *,EMPTYARG)7617a32b0c8SAndre Fischer IMPL_LINK(LayoutMenu, StateChangeHandler, ::rtl::OUString*, EMPTYARG)
7627a32b0c8SAndre Fischer {
7637a32b0c8SAndre Fischer     InvalidateContent();
7647a32b0c8SAndre Fischer     return 0;
7657a32b0c8SAndre Fischer }
7667a32b0c8SAndre Fischer 
7677a32b0c8SAndre Fischer 
7687a32b0c8SAndre Fischer 
7697a32b0c8SAndre Fischer 
IMPL_LINK(LayoutMenu,OnMenuItemSelected,Menu *,pMenu)77002c50d82SAndre Fischer IMPL_LINK(LayoutMenu, OnMenuItemSelected, Menu*, pMenu)
77102c50d82SAndre Fischer {
77202c50d82SAndre Fischer     if (pMenu == NULL)
77302c50d82SAndre Fischer     {
77402c50d82SAndre Fischer         OSL_ENSURE(pMenu!=NULL, "LayoutMenu::OnMenuItemSelected: illegal menu!");
77502c50d82SAndre Fischer         return 0;
77602c50d82SAndre Fischer     }
77702c50d82SAndre Fischer 
77802c50d82SAndre Fischer     pMenu->Deactivate();
77902c50d82SAndre Fischer     const sal_Int32 nIndex (pMenu->GetCurItemId());
78002c50d82SAndre Fischer 
78102c50d82SAndre Fischer     if (nIndex == SID_TP_APPLY_TO_SELECTED_SLIDES)
78202c50d82SAndre Fischer     {
78302c50d82SAndre Fischer         AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
78402c50d82SAndre Fischer     }
78502c50d82SAndre Fischer     else if (nIndex == SID_INSERTPAGE_LAYOUT_MENU)
78602c50d82SAndre Fischer     {
78702c50d82SAndre Fischer         // Add arguments to this slot and forward it to the main view
78802c50d82SAndre Fischer         // shell.
78902c50d82SAndre Fischer         InsertPageWithLayout(GetSelectedAutoLayout());
79002c50d82SAndre Fischer     }
79102c50d82SAndre Fischer 
79202c50d82SAndre Fischer     return 0;
79302c50d82SAndre Fischer }
79402c50d82SAndre Fischer 
79502c50d82SAndre Fischer 
79602c50d82SAndre Fischer 
79702c50d82SAndre Fischer 
UpdateSelection(void)7987a32b0c8SAndre Fischer void LayoutMenu::UpdateSelection (void)
7997a32b0c8SAndre Fischer {
8007a32b0c8SAndre Fischer     bool bItemSelected = false;
8017a32b0c8SAndre Fischer 
8027a32b0c8SAndre Fischer     do
8037a32b0c8SAndre Fischer     {
8047a32b0c8SAndre Fischer         // Get current page of main view.
8057a32b0c8SAndre Fischer         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
8067a32b0c8SAndre Fischer         if (pViewShell == NULL)
8077a32b0c8SAndre Fischer             break;
8087a32b0c8SAndre Fischer 
8097a32b0c8SAndre Fischer         SdPage* pCurrentPage = pViewShell->getCurrentPage();
8107a32b0c8SAndre Fischer         if (pCurrentPage == NULL)
8117a32b0c8SAndre Fischer             break;
8127a32b0c8SAndre Fischer 
8137a32b0c8SAndre Fischer         // Get layout of current page.
8147a32b0c8SAndre Fischer         AutoLayout aLayout (pCurrentPage->GetAutoLayout());
8157a32b0c8SAndre Fischer         if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
8167a32b0c8SAndre Fischer             break;
8177a32b0c8SAndre Fischer 
8187a32b0c8SAndre Fischer         // Find the entry of the menu for to the layout.
819*6dc7b748SAndre Fischer         SetNoSelection();
8207a32b0c8SAndre Fischer         sal_uInt16 nItemCount (GetItemCount());
8217a32b0c8SAndre Fischer         for (sal_uInt16 nId=1; nId<=nItemCount; nId++)
8227a32b0c8SAndre Fischer         {
8237a32b0c8SAndre Fischer             if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
8247a32b0c8SAndre Fischer             {
8257a32b0c8SAndre Fischer                 SelectItem(nId);
8267a32b0c8SAndre Fischer                 bItemSelected = true;
8277a32b0c8SAndre Fischer                 break;
8287a32b0c8SAndre Fischer             }
8297a32b0c8SAndre Fischer         }
8307a32b0c8SAndre Fischer     }
8317a32b0c8SAndre Fischer     while (false);
8327a32b0c8SAndre Fischer 
8337a32b0c8SAndre Fischer     if ( ! bItemSelected)
8347a32b0c8SAndre Fischer         SetNoSelection();
8357a32b0c8SAndre Fischer }
8367a32b0c8SAndre Fischer 
8377a32b0c8SAndre Fischer 
8387a32b0c8SAndre Fischer 
8397a32b0c8SAndre Fischer 
IMPL_LINK(LayoutMenu,EventMultiplexerListener,::sd::tools::EventMultiplexerEvent *,pEvent)8407a32b0c8SAndre Fischer IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
8417a32b0c8SAndre Fischer {
8427a32b0c8SAndre Fischer     switch (pEvent->meEventId)
8437a32b0c8SAndre Fischer     {
8447a32b0c8SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
8457a32b0c8SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
8467a32b0c8SAndre Fischer             if ( ! mbSelectionUpdatePending)
8477a32b0c8SAndre Fischer                 UpdateSelection();
8487a32b0c8SAndre Fischer             break;
8497a32b0c8SAndre Fischer 
8507a32b0c8SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
8517a32b0c8SAndre Fischer             mbIsMainViewChangePending = true;
8527a32b0c8SAndre Fischer             break;
8537a32b0c8SAndre Fischer 
8547a32b0c8SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
8557a32b0c8SAndre Fischer             HideFocus();
8567a32b0c8SAndre Fischer             break;
8577a32b0c8SAndre Fischer 
8587a32b0c8SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
8597a32b0c8SAndre Fischer             if (mbIsMainViewChangePending)
8607a32b0c8SAndre Fischer             {
8617a32b0c8SAndre Fischer                 mbIsMainViewChangePending = false;
8627a32b0c8SAndre Fischer                 InvalidateContent();
8637a32b0c8SAndre Fischer             }
8647a32b0c8SAndre Fischer             break;
8657a32b0c8SAndre Fischer 
8667a32b0c8SAndre Fischer         default:
8677a32b0c8SAndre Fischer             /* Ignored */
8687a32b0c8SAndre Fischer             break;
8697a32b0c8SAndre Fischer     }
8707a32b0c8SAndre Fischer 
8717a32b0c8SAndre Fischer     return 0;
8727a32b0c8SAndre Fischer }
8737a32b0c8SAndre Fischer 
8747a32b0c8SAndre Fischer 
8757a32b0c8SAndre Fischer 
8767a32b0c8SAndre Fischer 
IMPL_LINK(LayoutMenu,WindowEventHandler,VclWindowEvent *,pEvent)8777a32b0c8SAndre Fischer IMPL_LINK(LayoutMenu, WindowEventHandler, VclWindowEvent*, pEvent)
8787a32b0c8SAndre Fischer {
8797a32b0c8SAndre Fischer     if (pEvent != NULL)
8807a32b0c8SAndre Fischer     {
8817a32b0c8SAndre Fischer         switch (pEvent->GetId())
8827a32b0c8SAndre Fischer         {
8837a32b0c8SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
8847a32b0c8SAndre Fischer             case VCLEVENT_WINDOW_RESIZE:
8857a32b0c8SAndre Fischer                 SetSizePixel(GetParent()->GetSizePixel());
8867a32b0c8SAndre Fischer                 return sal_True;
8877a32b0c8SAndre Fischer 
8887a32b0c8SAndre Fischer             default:
8897a32b0c8SAndre Fischer                 return sal_False;
8907a32b0c8SAndre Fischer         }
8917a32b0c8SAndre Fischer 
8927a32b0c8SAndre Fischer         const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, pEvent);
8937a32b0c8SAndre Fischer         if (pSimpleHint != NULL
8947a32b0c8SAndre Fischer             && pSimpleHint->GetId() == SFX_HINT_DYING)
8957a32b0c8SAndre Fischer         {
8967a32b0c8SAndre Fischer             return sal_True;
8977a32b0c8SAndre Fischer         }
8987a32b0c8SAndre Fischer     }
8997a32b0c8SAndre Fischer 
9007a32b0c8SAndre Fischer     return sal_False;
9017a32b0c8SAndre Fischer }
9027a32b0c8SAndre Fischer 
9037a32b0c8SAndre Fischer 
9047a32b0c8SAndre Fischer 
9057a32b0c8SAndre Fischer 
DataChanged(const DataChangedEvent & rEvent)9067a32b0c8SAndre Fischer void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
9077a32b0c8SAndre Fischer {
9087a32b0c8SAndre Fischer     Fill();
9097a32b0c8SAndre Fischer     ValueSet::DataChanged(rEvent);
9108dcb2a10SAndre Fischer     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
9118dcb2a10SAndre Fischer     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
9127a32b0c8SAndre Fischer }
9137a32b0c8SAndre Fischer 
9147a32b0c8SAndre Fischer 
9157a32b0c8SAndre Fischer 
9167a32b0c8SAndre Fischer 
9177a32b0c8SAndre Fischer 
9187a32b0c8SAndre Fischer } } // end of namespace ::sd::sidebar
919