update ooo310-m15
[ooovba.git] / sd / source / ui / toolpanel / LayoutMenu.cxx
blobc1d86c04b4d4e853933ae571052f61f7e1681548
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LayoutMenu.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "LayoutMenu.hxx"
36 #include "TaskPaneShellManager.hxx"
37 #include "pres.hxx"
38 #include "drawdoc.hxx"
39 #include "DrawDocShell.hxx"
40 #include "sdpage.hxx"
41 #include "glob.hxx"
42 #include "glob.hrc"
43 #include "app.hrc"
44 #include "helpids.h"
45 #include "res_bmp.hrc"
46 #include "strings.hrc"
47 #include "ViewShellBase.hxx"
48 #include "DrawViewShell.hxx"
49 #include "SlideSorterViewShell.hxx"
50 #include "controller/SlideSorterController.hxx"
51 #include "controller/SlsPageSelector.hxx"
52 #include "taskpane/TaskPaneControlFactory.hxx"
53 #include "taskpane/ScrollPanel.hxx"
54 #include "tools/SlotStateListener.hxx"
55 #include "EventMultiplexer.hxx"
56 #include "DrawController.hxx"
57 #include "framework/FrameworkHelper.hxx"
59 #include <vector>
60 #include <memory>
61 #include <sfx2/objface.hxx>
62 #include "sdresid.hxx"
63 #include <vcl/image.hxx>
64 #include <svtools/languageoptions.hxx>
65 #include <sfx2/app.hxx>
66 #include "taskpane/TitledControl.hxx"
67 #include <sfx2/dispatch.hxx>
68 #include <sfx2/request.hxx>
69 #include <comphelper/processfactory.hxx>
70 #include <sfx2/viewfrm.hxx>
72 #include <com/sun/star/frame/XController.hpp>
73 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
74 #include <com/sun/star/drawing/framework/XView.hpp>
75 #include <com/sun/star/drawing/framework/ResourceId.hpp>
77 using namespace ::sd::toolpanel;
78 #define LayoutMenu
79 #include "sdslots.hxx"
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::text;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star::drawing::framework;
85 using namespace ::sd::slidesorter;
86 using ::sd::framework::FrameworkHelper;
88 namespace sd { namespace toolpanel {
90 /** This factory class stores references to ViewShellBase and DrawDocShell
91 and passes them to new LayoutMenu objects.
93 class LayoutMenuFactory
94 : public ControlFactory
96 public:
97 LayoutMenuFactory (ViewShellBase& rBase, DrawDocShell& rDocShell)
98 : mrBase(rBase),
99 mrDocShell(rDocShell)
102 protected:
103 virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
105 ScrollPanel* pScrollPanel = new ScrollPanel (pTreeNode);
106 ::std::auto_ptr<TreeNode> pMenu (
107 new LayoutMenu (
108 pScrollPanel,
109 mrDocShell,
110 mrBase,
111 false));
112 pScrollPanel->AddControl(pMenu);
113 return pScrollPanel;
116 private:
117 ViewShellBase& mrBase;
118 DrawDocShell& mrDocShell;
124 SFX_IMPL_INTERFACE(LayoutMenu, SfxShell,
125 SdResId(STR_TASKPANELAYOUTMENU))
127 SFX_POPUPMENU_REGISTRATION(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP));
130 TYPEINIT1(LayoutMenu, SfxShell);
132 struct snewfoil_value_info
134 USHORT mnBmpResId;
135 USHORT mnHCBmpResId;
136 USHORT mnStrResId;
137 WritingMode meWritingMode;
138 AutoLayout maAutoLayout;
141 static snewfoil_value_info notes[] =
143 {BMP_FOILN_01, BMP_FOILN_01_H, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
144 AUTOLAYOUT_NOTES},
145 {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
148 static snewfoil_value_info handout[] =
150 {BMP_FOILH_01, BMP_FOILH_01_H, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
151 AUTOLAYOUT_HANDOUT1},
152 {BMP_FOILH_02, BMP_FOILH_02_H, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
153 AUTOLAYOUT_HANDOUT2},
154 {BMP_FOILH_03, BMP_FOILH_03_H, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
155 AUTOLAYOUT_HANDOUT3},
156 {BMP_FOILH_04, BMP_FOILH_04_H, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
157 AUTOLAYOUT_HANDOUT4},
158 {BMP_FOILH_06, BMP_FOILH_06_H, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
159 AUTOLAYOUT_HANDOUT6},
160 {BMP_FOILH_09, BMP_FOILH_09_H, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
161 AUTOLAYOUT_HANDOUT9},
162 {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
165 static snewfoil_value_info standard[] =
167 {BMP_FOIL_20, BMP_FOIL_20_H, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB,
168 AUTOLAYOUT_NONE},
169 {BMP_FOIL_00, BMP_FOIL_00_H, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB,
170 AUTOLAYOUT_TITLE},
171 {BMP_FOIL_01, BMP_FOIL_01_H, STR_AUTOLAYOUT_ENUM, WritingMode_LR_TB,
172 AUTOLAYOUT_ENUM},
173 {BMP_FOIL_03, BMP_FOIL_03_H, STR_AUTOLAYOUT_2TEXT, WritingMode_LR_TB,
174 AUTOLAYOUT_2TEXT},
175 {BMP_FOIL_19, BMP_FOIL_19_H, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB,
176 AUTOLAYOUT_ONLY_TITLE},
177 {BMP_FOIL_25, BMP_FOIL_25_H, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB,
178 AUTOLAYOUT_ONLY_TEXT},
179 {BMP_FOIL_11, BMP_FOIL_11_H, STR_AUTOLAYOUT_OBJ, WritingMode_LR_TB,
180 AUTOLAYOUT_OBJ},
181 {BMP_FOIL_02, BMP_FOIL_02_H, STR_AUTOLAYOUT_CHART, WritingMode_LR_TB,
182 AUTOLAYOUT_CHART},
183 {BMP_FOIL_08, BMP_FOIL_08_H, STR_AUTOLAYOUT_TAB, WritingMode_LR_TB,
184 AUTOLAYOUT_TAB},
185 {BMP_FOIL_09, BMP_FOIL_09_H, STR_AUTOLAYOUT_CLIPTEXT, WritingMode_LR_TB,
186 AUTOLAYOUT_CLIPTEXT},
187 {BMP_FOIL_04, BMP_FOIL_04_H, STR_AUTOLAYOUT_TEXTCHART, WritingMode_LR_TB,
188 AUTOLAYOUT_TEXTCHART},
189 {BMP_FOIL_06, BMP_FOIL_06_H, STR_AUTOLAYOUT_TEXTCLIP, WritingMode_LR_TB,
190 AUTOLAYOUT_TEXTCLIP},
191 {BMP_FOIL_07, BMP_FOIL_07_H, STR_AUTOLAYOUT_CHARTTEXT, WritingMode_LR_TB,
192 AUTOLAYOUT_CHARTTEXT},
193 {BMP_FOIL_10, BMP_FOIL_10_H, STR_AUTOLAYOUT_TEXTOBJ, WritingMode_LR_TB,
194 AUTOLAYOUT_TEXTOBJ},
195 {BMP_FOIL_12, BMP_FOIL_12_H, STR_AUTOLAYOUT_TEXT2OBJ, WritingMode_LR_TB,
196 AUTOLAYOUT_TEXT2OBJ},
197 {BMP_FOIL_13, BMP_FOIL_13_H, STR_AUTOLAYOUT_OBJTEXT, WritingMode_LR_TB,
198 AUTOLAYOUT_OBJTEXT},
199 {BMP_FOIL_14, BMP_FOIL_14_H, STR_AUTOLAYOUT_OBJOVERTEXT, WritingMode_LR_TB,
200 AUTOLAYOUT_OBJOVERTEXT},
201 {BMP_FOIL_15, BMP_FOIL_15_H, STR_AUTOLAYOUT_2OBJTEXT, WritingMode_LR_TB,
202 AUTOLAYOUT_2OBJTEXT},
203 {BMP_FOIL_16, BMP_FOIL_16_H, STR_AUTOLAYOUT_2OBJOVERTEXT,
204 WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT},
205 {BMP_FOIL_17, BMP_FOIL_17_H, STR_AUTOLAYOUT_TEXTOVEROBJ, WritingMode_LR_TB,
206 AUTOLAYOUT_TEXTOVEROBJ},
207 {BMP_FOIL_18, BMP_FOIL_18_H, STR_AUTOLAYOUT_4OBJ, WritingMode_LR_TB,
208 AUTOLAYOUT_4OBJ},
209 // vertical
210 {BMP_FOIL_21, BMP_FOIL_21_H, STR_AL_VERT_TITLE_TEXT_CHART,
211 WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
212 {BMP_FOIL_22, BMP_FOIL_22_H, STR_AL_VERT_TITLE_VERT_OUTLINE,
213 WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
214 {BMP_FOIL_23, BMP_FOIL_23_H, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL,
215 AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
216 {BMP_FOIL_24, BMP_FOIL_24_H, STR_AL_TITLE_VERT_OUTLINE_CLIPART,
217 WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
219 {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
225 LayoutMenu::LayoutMenu (
226 TreeNode* pParent,
227 DrawDocShell& rDocumentShell,
228 ViewShellBase& rViewShellBase,
229 bool bUseOwnScrollBar)
230 : ValueSet (pParent->GetWindow()),
231 TreeNode(pParent),
232 DragSourceHelper(this),
233 DropTargetHelper(this),
234 mrBase (rViewShellBase),
235 mbUseOwnScrollBar (bUseOwnScrollBar),
236 mnPreferredColumnCount(3),
237 mxListener(NULL),
238 mbSelectionUpdatePending(true),
239 mbIsMainViewChangePending(false)
241 SetStyle (
242 GetStyle()
243 & ~(WB_ITEMBORDER)
244 | WB_TABSTOP
245 | WB_NO_DIRECTSELECT
247 if (mbUseOwnScrollBar)
248 SetStyle (GetStyle() | WB_VSCROLL);
249 SetExtraSpacing(2);
250 SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
251 SetPool (&rDocumentShell.GetDoc()->GetPool());
252 SetName(String(RTL_CONSTASCII_USTRINGPARAM("LayoutMenu")));
253 InvalidateContent();
255 Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
256 mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
257 ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
258 | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
259 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
260 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
261 | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED);
263 SetSmartHelpId(SmartId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS));
264 SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
266 Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
267 mxListener = new ::sd::tools::SlotStateListener(
268 aStateChangeLink,
269 Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
270 ::rtl::OUString::createFromAscii(".uno:VerticalTextState"));
272 // Add this new object as shell to the shell factory.
273 GetShellManager()->AddSubShell(HID_SD_TASK_PANE_PREVIEW_LAYOUTS,this,this);
279 LayoutMenu::~LayoutMenu (void)
281 // Tell the shell factory that this object is no longer available.
282 if (GetShellManager() != NULL)
283 GetShellManager()->RemoveSubShell(this);
285 Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
286 if (xComponent.is())
287 xComponent->dispose();
289 Clear();
290 Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
291 mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
297 ::std::auto_ptr<ControlFactory> LayoutMenu::CreateControlFactory (
298 ViewShellBase& rBase,
299 DrawDocShell& rDocShell)
301 return ::std::auto_ptr<ControlFactory>(new LayoutMenuFactory(rBase, rDocShell));
307 String LayoutMenu::GetSelectedLayoutName (void)
309 return GetItemText (GetSelectItemId());
315 AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
317 AutoLayout aResult = AUTOLAYOUT_NONE;
319 if ( ! IsNoSelection() && GetSelectItemId()!=0)
321 AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
322 if (pLayout != NULL)
323 aResult = *pLayout;
326 return aResult;
332 /** The preferred size depends on the preferred number of columns, the
333 number of items, and the size of the items.
335 Size LayoutMenu::GetPreferredSize (void)
337 Size aItemSize = CalcItemSizePixel (Size());
338 Size aPreferredWindowSize = CalcWindowSizePixel (
339 aItemSize,
340 (USHORT)mnPreferredColumnCount,
341 (USHORT)CalculateRowCount (aItemSize,mnPreferredColumnCount));
342 return aPreferredWindowSize;
348 sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight)
350 sal_Int32 nPreferredWidth = 100;
351 if (GetItemCount() > 0)
353 Image aImage = GetItemImage(GetItemId(0));
354 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
355 if (nHeight>0 && aItemSize.Height()>0)
357 int nRowCount = nHeight / aItemSize.Height();
358 if (nRowCount <= 0)
359 nRowCount = 1;
360 int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount;
361 nPreferredWidth = nColumnCount * aItemSize.Width();
365 return nPreferredWidth;
371 sal_Int32 LayoutMenu::GetPreferredHeight (sal_Int32 nWidth)
373 sal_Int32 nPreferredHeight = 200;
374 if ( ! mbUseOwnScrollBar && GetItemCount()>0)
376 Image aImage = GetItemImage(GetItemId(0));
377 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
378 if (nWidth>0 && aItemSize.Width()>0)
380 aItemSize.Width() += 8;
381 aItemSize.Height() += 8;
382 int nColumnCount = nWidth / aItemSize.Width();
383 if (nColumnCount <= 0)
384 nColumnCount = 1;
385 else if (nColumnCount > 4)
386 nColumnCount = 4;
387 int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
388 nPreferredHeight = nRowCount * aItemSize.Height();
391 return nPreferredHeight;
397 sal_Int32 LayoutMenu::GetMinimumWidth (void)
399 sal_Int32 nMinimumWidth = 0;
400 if (GetItemCount()>0)
402 Image aImage = GetItemImage(GetItemId(0));
403 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
404 nMinimumWidth = aItemSize.Width();
406 return nMinimumWidth;
412 bool LayoutMenu::IsResizable (void)
414 return true;
417 void LayoutMenu::DetectEnabledState(bool bFlag)
419 TreeNode* pParentNode = GetParentNode();
420 TreeNode* pGrandparentNode = pParentNode->GetParentNode();
421 dynamic_cast<TitledControl*>(pGrandparentNode)->SetEnabledState(bFlag);
424 ::Window* LayoutMenu::GetWindow (void)
426 return this;
432 void LayoutMenu::Paint (const Rectangle& rRect)
434 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
436 if (mbSelectionUpdatePending)
438 mbSelectionUpdatePending = false;
439 UpdateSelection();
441 ValueSet::Paint (rRect);
443 SetBackground (Wallpaper());
449 void LayoutMenu::Resize (void)
451 Size aWindowSize = GetOutputSizePixel();
452 if (IsVisible() && aWindowSize.Width() > 0)
454 // Calculate the number of rows and columns.
455 if (GetItemCount() > 0)
457 Image aImage = GetItemImage(GetItemId(0));
458 Size aItemSize = CalcItemSizePixel (
459 aImage.GetSizePixel());
460 aItemSize.Width() += 8;
461 aItemSize.Height() += 8;
462 int nColumnCount = aWindowSize.Width() / aItemSize.Width();
463 if (nColumnCount < 1)
464 nColumnCount = 1;
465 else if (nColumnCount > 4)
466 nColumnCount = 4;
468 int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
470 SetColCount ((USHORT)nColumnCount);
471 SetLineCount ((USHORT)nRowCount);
475 ValueSet::Resize ();
481 void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
483 // As a preparation for the context menu the item under the mouse is
484 // selected.
485 if (rEvent.IsRight())
487 ReleaseMouse();
488 USHORT nIndex = GetItemId (rEvent.GetPosPixel());
489 if (nIndex > 0)
490 SelectItem(nIndex);
493 ValueSet::MouseButtonDown (rEvent);
499 void LayoutMenu::Execute (SfxRequest& rRequest)
501 switch (rRequest.GetSlot())
503 case SID_TP_APPLY_TO_SELECTED_SLIDES:
504 AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
505 rRequest.Done();
506 break;
508 case SID_INSERTPAGE_LAYOUT_MENU:
509 // Add arguments to this slot and forward it to the main view
510 // shell.
511 InsertPageWithLayout(GetSelectedAutoLayout());
512 break;
519 void LayoutMenu::GetState (SfxItemSet& rItemSet)
521 // Cut and paste is not supported. The SID_(CUT,COPY,PASTE) entries
522 // therefore must not show up in the context menu.
523 rItemSet.DisableItem (SID_CUT);
524 rItemSet.DisableItem (SID_COPY);
525 rItemSet.DisableItem (SID_PASTE);
527 // The SID_INSERTPAGE_LAYOUT_MENU slot depends on the SID_INSERTPAGE
528 // slot being supported elsewhere.
529 const SfxPoolItem* pItem = NULL;
530 const SfxItemState aState (
531 mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
532 if (aState == SFX_ITEM_DISABLED)
533 rItemSet.DisableItem(SID_INSERTPAGE_LAYOUT_MENU);
539 void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
541 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
542 if (pViewShell == NULL)
543 return;
545 SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
546 if (pViewFrame == NULL)
547 return;
549 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
550 if (pDispatcher == NULL)
551 return;
553 // Call SID_INSERTPAGE with the right arguments. This is because
554 // the popup menu can not call this slot with arguments directly.
555 SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
556 if (aRequest.GetArgs() != NULL)
558 pDispatcher->Execute(
559 SID_INSERTPAGE,
560 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
561 *aRequest.GetArgs());
563 UpdateSelection();
569 void LayoutMenu::InvalidateContent (void)
571 // The number of items may have changed. Request a resize so that the
572 // vertical size of this control can be adapted.
573 RequestResize();
575 // Throw away the current set and fill the menu anew according to the
576 // current settings (this includes the support for vertical writing.)
577 Fill();
583 int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
585 int nRowCount = 0;
587 if (GetItemCount() > 0 && nColumnCount > 0)
589 nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
590 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
591 if (nRowCount < 1)
592 nRowCount = 1;
595 return nRowCount;
601 IMPL_LINK(LayoutMenu, ClickHandler, ValueSet*, EMPTYARG)
603 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
604 return 0;
610 /** The specified layout is assigned to the current page of the view shell
611 in the center pane.
613 void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
615 using namespace ::sd::slidesorter;
616 using namespace ::sd::slidesorter::controller;
620 // The view shell in the center pane has to be present.
621 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
622 if (pMainViewShell == NULL)
623 break;
625 // Determine if the current view is in an invalid master page mode.
626 // The handout view is always in master page mode and therefore not
627 // invalid.
628 bool bMasterPageMode (false);
629 switch (pMainViewShell->GetShellType())
631 case ViewShell::ST_NOTES:
632 case ViewShell::ST_IMPRESS:
634 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
635 if (pDrawViewShell != NULL)
636 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
637 bMasterPageMode = true;
639 default:
640 break;
642 if (bMasterPageMode)
643 break;
645 // Get a list of all selected slides and call the SID_MODIFYPAGE
646 // slot for all of them.
647 ::sd::slidesorter::SharedPageSelection pPageSelection;
649 // Get a list of selected pages.
650 // First we try to obtain this list from a slide sorter. This is
651 // possible only some of the view shells in the center pane. When
652 // no valid slide sorter is available then ask the main view shell
653 // for its current page.
654 SlideSorterViewShell* pSlideSorter = NULL;
655 switch (pMainViewShell->GetShellType())
657 case ViewShell::ST_IMPRESS:
658 case ViewShell::ST_NOTES:
659 case ViewShell::ST_SLIDE_SORTER:
660 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
661 break;
662 default:
663 break;
665 if (pSlideSorter != NULL)
667 // There is a slide sorter visible so get the list of selected pages from it.
668 pPageSelection = pSlideSorter->GetPageSelection();
670 else
672 // No valid slide sorter available. Ask the main view shell for
673 // its current page.
674 pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
675 pPageSelection->push_back(pMainViewShell->GetActualPage());
679 if (pPageSelection->empty())
680 break;
682 ::std::vector<SdPage*>::iterator iPage;
683 for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
685 if ((*iPage) == NULL)
686 continue;
688 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
689 SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
690 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
691 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
692 pMainViewShell->ExecuteSlot (aRequest, BOOL(FALSE));
695 while(false);
701 SfxRequest LayoutMenu::CreateRequest (
702 USHORT nSlotId,
703 AutoLayout aLayout)
705 SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
709 SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
710 BYTE aBackground (rLayerAdmin.GetLayerID(
711 String(SdResId(STR_LAYER_BCKGRND)), FALSE));
712 BYTE aBackgroundObject (rLayerAdmin.GetLayerID(
713 String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE));
714 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
715 if (pViewShell == NULL)
716 break;
717 SdPage* pPage = pViewShell->GetActualPage();
718 if (pPage == NULL)
719 break;
721 SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
723 aRequest.AppendItem(
724 SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName()));
725 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
726 aRequest.AppendItem(
727 SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
728 aRequest.AppendItem(
729 SfxBoolItem(
730 ID_VAL_ISPAGEOBJ,
731 aVisibleLayers.IsSet(aBackgroundObject)));
733 while (false);
735 return aRequest;
741 void LayoutMenu::Fill (void)
743 const bool bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
744 SvtLanguageOptions aLanguageOptions;
745 sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
746 SdDrawDocument* pDocument = mrBase.GetDocument();
747 sal_Bool bRightToLeft = (pDocument!=NULL
748 && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
750 // Get URL of the view in the center pane.
751 ::rtl::OUString sCenterPaneViewName;
754 Reference<XControllerManager> xControllerManager (
755 Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
756 Reference<XResourceId> xPaneId (ResourceId::create(
757 comphelper_getProcessComponentContext(),
758 FrameworkHelper::msCenterPaneURL));
759 Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
760 if (xView.is())
761 sCenterPaneViewName = xView->getResourceId()->getResourceURL();
763 catch (RuntimeException&)
766 snewfoil_value_info* pInfo = NULL;
767 if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
769 pInfo = notes;
771 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
773 pInfo = handout;
775 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
776 || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
778 pInfo = standard;
780 else
782 pInfo = NULL;
785 Clear();
786 int n = 0;
787 for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
789 if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
791 BitmapEx aBmp (SdResId (bHighContrast
792 ? pInfo->mnHCBmpResId
793 : pInfo->mnBmpResId));
795 if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
796 aBmp.Mirror (BMP_MIRROR_HORZ);
798 InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId)));
799 SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
800 n++;
804 mbSelectionUpdatePending = true;
810 void LayoutMenu::Clear (void)
812 for (USHORT nId=1; nId<=GetItemCount(); nId++)
813 delete static_cast<AutoLayout*>(GetItemData(nId));
814 ValueSet::Clear();
819 void LayoutMenu::StartDrag (sal_Int8 , const Point& )
826 sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
828 return 0;
834 sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
836 return 0;
842 void LayoutMenu::Command (const CommandEvent& rEvent)
844 switch (rEvent.GetCommand())
846 case COMMAND_CONTEXTMENU:
847 if ( ! SD_MOD()->GetWaterCan())
849 if (GetShellManager() != NULL)
850 GetShellManager()->MoveToTop(this);
851 if (rEvent.IsMouseEvent())
852 mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
853 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP));
854 else
856 // When the command event was not caused by a mouse
857 // event (for example a key press instead) then show the
858 // popup menu at the center of the current item.
859 if (GetSelectItemId() != (USHORT)-1)
861 Rectangle aBBox (GetItemRect(GetSelectItemId()));
862 Point aPosition (aBBox.Center());
863 mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
864 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP),
865 this,
866 &aPosition);
870 break;
872 default:
873 ValueSet::Command(rEvent);
874 break;
881 IMPL_LINK(LayoutMenu, StateChangeHandler, ::rtl::OUString*, EMPTYARG)
883 InvalidateContent();
884 return 0;
890 void LayoutMenu::UpdateSelection (void)
892 bool bItemSelected = false;
896 // Get current page of main view.
897 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
898 if (pViewShell == NULL)
899 break;
901 SdPage* pCurrentPage = pViewShell->getCurrentPage();
902 if (pCurrentPage == NULL)
903 break;
905 // Get layout of current page.
906 AutoLayout aLayout (pCurrentPage->GetAutoLayout());
907 if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
908 break;
910 // Find the entry of the menu for to the layout.
911 USHORT nItemCount (GetItemCount());
912 for (USHORT nId=1; nId<=nItemCount; nId++)
914 if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
916 SelectItem(nId);
917 bItemSelected = true;
918 break;
922 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell);
923 if (pDrawViewShell != NULL)
925 DetectEnabledState(pDrawViewShell->GetEditMode() != EM_MASTERPAGE);
928 while (false);
930 if ( ! bItemSelected)
931 SetNoSelection();
937 IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
939 switch (pEvent->meEventId)
941 case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
942 case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
943 if ( ! mbSelectionUpdatePending)
944 UpdateSelection();
945 break;
947 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
948 mbIsMainViewChangePending = true;
949 break;
951 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
952 HideFocus();
953 break;
955 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
956 if (mbIsMainViewChangePending)
958 mbIsMainViewChangePending = false;
959 InvalidateContent();
961 break;
963 default:
964 /* Ignored */
965 break;
968 return 0;
974 void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
976 Fill();
977 ValueSet::DataChanged(rEvent);
981 } } // end of namespace ::sd::toolpanel