merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / toolpanel / LayoutMenu.cxx
blob7b479e102addd48562da2dfc4ab0c63578d431dd
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 {BMP_FOIL_26, BMP_FOIL_26_H, STR_AUTOLAYOUT_4CLIPART, WritingMode_LR_TB, AUTOLAYOUT_4CLIPART},
210 {BMP_FOIL_27, BMP_FOIL_27_H, STR_AUTOLAYOUT_6CLIPART, WritingMode_LR_TB, AUTOLAYOUT_6CLIPART},
212 // vertical
213 {BMP_FOIL_21, BMP_FOIL_21_H, STR_AL_VERT_TITLE_TEXT_CHART,
214 WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
215 {BMP_FOIL_22, BMP_FOIL_22_H, STR_AL_VERT_TITLE_VERT_OUTLINE,
216 WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
217 {BMP_FOIL_23, BMP_FOIL_23_H, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL,
218 AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
219 {BMP_FOIL_24, BMP_FOIL_24_H, STR_AL_TITLE_VERT_OUTLINE_CLIPART,
220 WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
222 {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
228 LayoutMenu::LayoutMenu (
229 TreeNode* pParent,
230 DrawDocShell& rDocumentShell,
231 ViewShellBase& rViewShellBase,
232 bool bUseOwnScrollBar)
233 : ValueSet (pParent->GetWindow()),
234 TreeNode(pParent),
235 DragSourceHelper(this),
236 DropTargetHelper(this),
237 mrBase (rViewShellBase),
238 mbUseOwnScrollBar (bUseOwnScrollBar),
239 mnPreferredColumnCount(3),
240 mxListener(NULL),
241 mbSelectionUpdatePending(true),
242 mbIsMainViewChangePending(false)
244 SetStyle (
245 ( GetStyle() & ~(WB_ITEMBORDER) )
246 | WB_TABSTOP
247 | WB_NO_DIRECTSELECT
249 if (mbUseOwnScrollBar)
250 SetStyle (GetStyle() | WB_VSCROLL);
251 SetExtraSpacing(2);
252 SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
253 SetPool (&rDocumentShell.GetDoc()->GetPool());
254 SetName(String(RTL_CONSTASCII_USTRINGPARAM("LayoutMenu")));
255 InvalidateContent();
257 Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
258 mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
259 ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
260 | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
261 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
262 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
263 | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
264 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
265 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
267 SetSmartHelpId(SmartId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS));
268 SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
270 Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
271 mxListener = new ::sd::tools::SlotStateListener(
272 aStateChangeLink,
273 Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
274 ::rtl::OUString::createFromAscii(".uno:VerticalTextState"));
276 // Add this new object as shell to the shell factory.
277 GetShellManager()->AddSubShell(HID_SD_TASK_PANE_PREVIEW_LAYOUTS,this,this);
283 LayoutMenu::~LayoutMenu (void)
285 // Tell the shell factory that this object is no longer available.
286 if (GetShellManager() != NULL)
287 GetShellManager()->RemoveSubShell(this);
289 Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
290 if (xComponent.is())
291 xComponent->dispose();
293 Clear();
294 Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
295 mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
301 ::std::auto_ptr<ControlFactory> LayoutMenu::CreateControlFactory (
302 ViewShellBase& rBase,
303 DrawDocShell& rDocShell)
305 return ::std::auto_ptr<ControlFactory>(new LayoutMenuFactory(rBase, rDocShell));
311 String LayoutMenu::GetSelectedLayoutName (void)
313 return GetItemText (GetSelectItemId());
319 AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
321 AutoLayout aResult = AUTOLAYOUT_NONE;
323 if ( ! IsNoSelection() && GetSelectItemId()!=0)
325 AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
326 if (pLayout != NULL)
327 aResult = *pLayout;
330 return aResult;
336 /** The preferred size depends on the preferred number of columns, the
337 number of items, and the size of the items.
339 Size LayoutMenu::GetPreferredSize (void)
341 Size aItemSize = CalcItemSizePixel (Size());
342 Size aPreferredWindowSize = CalcWindowSizePixel (
343 aItemSize,
344 (USHORT)mnPreferredColumnCount,
345 (USHORT)CalculateRowCount (aItemSize,mnPreferredColumnCount));
346 return aPreferredWindowSize;
352 sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight)
354 sal_Int32 nPreferredWidth = 100;
355 if (GetItemCount() > 0)
357 Image aImage = GetItemImage(GetItemId(0));
358 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
359 if (nHeight>0 && aItemSize.Height()>0)
361 int nRowCount = nHeight / aItemSize.Height();
362 if (nRowCount <= 0)
363 nRowCount = 1;
364 int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount;
365 nPreferredWidth = nColumnCount * aItemSize.Width();
369 return nPreferredWidth;
375 sal_Int32 LayoutMenu::GetPreferredHeight (sal_Int32 nWidth)
377 sal_Int32 nPreferredHeight = 200;
378 if ( ! mbUseOwnScrollBar && GetItemCount()>0)
380 Image aImage = GetItemImage(GetItemId(0));
381 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
382 if (nWidth>0 && aItemSize.Width()>0)
384 aItemSize.Width() += 8;
385 aItemSize.Height() += 8;
386 int nColumnCount = nWidth / aItemSize.Width();
387 if (nColumnCount <= 0)
388 nColumnCount = 1;
389 else if (nColumnCount > 4)
390 nColumnCount = 4;
391 int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
392 nPreferredHeight = nRowCount * aItemSize.Height();
395 return nPreferredHeight;
401 sal_Int32 LayoutMenu::GetMinimumWidth (void)
403 sal_Int32 nMinimumWidth = 0;
404 if (GetItemCount()>0)
406 Image aImage = GetItemImage(GetItemId(0));
407 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
408 nMinimumWidth = aItemSize.Width();
410 return nMinimumWidth;
416 bool LayoutMenu::IsResizable (void)
418 return true;
424 void LayoutMenu::UpdateEnabledState (const MasterMode eMode)
426 bool bIsEnabled (false);
428 ::boost::shared_ptr<ViewShell> pMainViewShell (mrBase.GetMainViewShell());
429 if (pMainViewShell)
431 switch (pMainViewShell->GetShellType())
433 case ViewShell::ST_NONE:
434 case ViewShell::ST_OUTLINE:
435 case ViewShell::ST_PRESENTATION:
436 case ViewShell::ST_TASK_PANE:
437 // The complete task pane is disabled for these values or
438 // not even visible. Disabling the LayoutMenu would be
439 // logical but unnecessary. The main disadvantage is that
440 // after re-enabling it (typically) another panel is
441 // expanded.
442 bIsEnabled = true;
443 break;
445 case ViewShell::ST_DRAW:
446 case ViewShell::ST_IMPRESS:
448 switch (eMode)
450 case MM_UNKNOWN:
452 ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
453 ::boost::dynamic_pointer_cast<DrawViewShell>(pMainViewShell));
454 if (pDrawViewShell)
455 bIsEnabled = pDrawViewShell->GetEditMode() != EM_MASTERPAGE;
456 break;
458 case MM_NORMAL:
459 bIsEnabled = true;
460 break;
462 case MM_MASTER:
463 bIsEnabled = false;
464 break;
466 break;
469 case ViewShell::ST_HANDOUT:
470 case ViewShell::ST_NOTES:
471 case ViewShell::ST_SLIDE_SORTER:
472 default:
473 bIsEnabled = true;
474 break;
477 TreeNode* pParentNode = GetParentNode();
478 if (pParentNode != NULL)
480 TitledControl* pGrandParentNode
481 = dynamic_cast<TitledControl*>(pParentNode->GetParentNode());
482 if (pGrandParentNode != NULL)
483 pGrandParentNode->SetEnabledState(bIsEnabled);
492 ::Window* LayoutMenu::GetWindow (void)
494 return this;
500 void LayoutMenu::Paint (const Rectangle& rRect)
502 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
504 if (mbSelectionUpdatePending)
506 mbSelectionUpdatePending = false;
507 UpdateSelection();
509 ValueSet::Paint (rRect);
511 SetBackground (Wallpaper());
517 void LayoutMenu::Resize (void)
519 Size aWindowSize = GetOutputSizePixel();
520 if (IsVisible() && aWindowSize.Width() > 0)
522 // Calculate the number of rows and columns.
523 if (GetItemCount() > 0)
525 Image aImage = GetItemImage(GetItemId(0));
526 Size aItemSize = CalcItemSizePixel (
527 aImage.GetSizePixel());
528 aItemSize.Width() += 8;
529 aItemSize.Height() += 8;
530 int nColumnCount = aWindowSize.Width() / aItemSize.Width();
531 if (nColumnCount < 1)
532 nColumnCount = 1;
533 else if (nColumnCount > 4)
534 nColumnCount = 4;
536 int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
538 SetColCount ((USHORT)nColumnCount);
539 SetLineCount ((USHORT)nRowCount);
543 ValueSet::Resize ();
549 void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
551 // As a preparation for the context menu the item under the mouse is
552 // selected.
553 if (rEvent.IsRight())
555 ReleaseMouse();
556 USHORT nIndex = GetItemId (rEvent.GetPosPixel());
557 if (nIndex > 0)
558 SelectItem(nIndex);
561 ValueSet::MouseButtonDown (rEvent);
567 void LayoutMenu::Execute (SfxRequest& rRequest)
569 switch (rRequest.GetSlot())
571 case SID_TP_APPLY_TO_SELECTED_SLIDES:
572 AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
573 rRequest.Done();
574 break;
576 case SID_INSERTPAGE_LAYOUT_MENU:
577 // Add arguments to this slot and forward it to the main view
578 // shell.
579 InsertPageWithLayout(GetSelectedAutoLayout());
580 break;
587 void LayoutMenu::GetState (SfxItemSet& rItemSet)
589 // Cut and paste is not supported. The SID_(CUT,COPY,PASTE) entries
590 // therefore must not show up in the context menu.
591 rItemSet.DisableItem (SID_CUT);
592 rItemSet.DisableItem (SID_COPY);
593 rItemSet.DisableItem (SID_PASTE);
595 // The SID_INSERTPAGE_LAYOUT_MENU slot depends on the SID_INSERTPAGE
596 // slot being supported elsewhere.
597 const SfxPoolItem* pItem = NULL;
598 const SfxItemState aState (
599 mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
600 if (aState == SFX_ITEM_DISABLED)
601 rItemSet.DisableItem(SID_INSERTPAGE_LAYOUT_MENU);
607 void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
609 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
610 if (pViewShell == NULL)
611 return;
613 SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
614 if (pViewFrame == NULL)
615 return;
617 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
618 if (pDispatcher == NULL)
619 return;
621 // Call SID_INSERTPAGE with the right arguments. This is because
622 // the popup menu can not call this slot with arguments directly.
623 SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
624 if (aRequest.GetArgs() != NULL)
626 pDispatcher->Execute(
627 SID_INSERTPAGE,
628 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
629 *aRequest.GetArgs());
631 UpdateSelection();
637 void LayoutMenu::InvalidateContent (void)
639 // The number of items may have changed. Request a resize so that the
640 // vertical size of this control can be adapted.
641 RequestResize();
643 // Throw away the current set and fill the menu anew according to the
644 // current settings (this includes the support for vertical writing.)
645 Fill();
651 int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
653 int nRowCount = 0;
655 if (GetItemCount() > 0 && nColumnCount > 0)
657 nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
658 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
659 if (nRowCount < 1)
660 nRowCount = 1;
663 return nRowCount;
669 IMPL_LINK(LayoutMenu, ClickHandler, ValueSet*, EMPTYARG)
671 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
672 return 0;
678 /** The specified layout is assigned to the current page of the view shell
679 in the center pane.
681 void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
683 using namespace ::sd::slidesorter;
684 using namespace ::sd::slidesorter::controller;
688 // The view shell in the center pane has to be present.
689 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
690 if (pMainViewShell == NULL)
691 break;
693 // Determine if the current view is in an invalid master page mode.
694 // The handout view is always in master page mode and therefore not
695 // invalid.
696 bool bMasterPageMode (false);
697 switch (pMainViewShell->GetShellType())
699 case ViewShell::ST_NOTES:
700 case ViewShell::ST_IMPRESS:
702 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
703 if (pDrawViewShell != NULL)
704 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
705 bMasterPageMode = true;
707 default:
708 break;
710 if (bMasterPageMode)
711 break;
713 // Get a list of all selected slides and call the SID_MODIFYPAGE
714 // slot for all of them.
715 ::sd::slidesorter::SharedPageSelection pPageSelection;
717 // Get a list of selected pages.
718 // First we try to obtain this list from a slide sorter. This is
719 // possible only some of the view shells in the center pane. When
720 // no valid slide sorter is available then ask the main view shell
721 // for its current page.
722 SlideSorterViewShell* pSlideSorter = NULL;
723 switch (pMainViewShell->GetShellType())
725 case ViewShell::ST_IMPRESS:
726 case ViewShell::ST_NOTES:
727 case ViewShell::ST_SLIDE_SORTER:
728 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
729 break;
730 default:
731 break;
733 if (pSlideSorter != NULL)
735 // There is a slide sorter visible so get the list of selected pages from it.
736 pPageSelection = pSlideSorter->GetPageSelection();
738 else
740 // No valid slide sorter available. Ask the main view shell for
741 // its current page.
742 pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
743 pPageSelection->push_back(pMainViewShell->GetActualPage());
747 if (pPageSelection->empty())
748 break;
750 ::std::vector<SdPage*>::iterator iPage;
751 for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
753 if ((*iPage) == NULL)
754 continue;
756 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
757 SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
758 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
759 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
760 pMainViewShell->ExecuteSlot (aRequest, BOOL(FALSE));
763 while(false);
769 SfxRequest LayoutMenu::CreateRequest (
770 USHORT nSlotId,
771 AutoLayout aLayout)
773 SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
777 SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
778 BYTE aBackground (rLayerAdmin.GetLayerID(
779 String(SdResId(STR_LAYER_BCKGRND)), FALSE));
780 BYTE aBackgroundObject (rLayerAdmin.GetLayerID(
781 String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE));
782 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
783 if (pViewShell == NULL)
784 break;
785 SdPage* pPage = pViewShell->GetActualPage();
786 if (pPage == NULL)
787 break;
789 SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
791 aRequest.AppendItem(
792 SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName()));
793 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
794 aRequest.AppendItem(
795 SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
796 aRequest.AppendItem(
797 SfxBoolItem(
798 ID_VAL_ISPAGEOBJ,
799 aVisibleLayers.IsSet(aBackgroundObject)));
801 while (false);
803 return aRequest;
809 void LayoutMenu::Fill (void)
811 const bool bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
812 SvtLanguageOptions aLanguageOptions;
813 sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
814 SdDrawDocument* pDocument = mrBase.GetDocument();
815 sal_Bool bRightToLeft = (pDocument!=NULL
816 && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
818 // Get URL of the view in the center pane.
819 ::rtl::OUString sCenterPaneViewName;
822 Reference<XControllerManager> xControllerManager (
823 Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
824 Reference<XResourceId> xPaneId (ResourceId::create(
825 ::comphelper::getProcessComponentContext(),
826 FrameworkHelper::msCenterPaneURL));
827 Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
828 if (xView.is())
829 sCenterPaneViewName = xView->getResourceId()->getResourceURL();
831 catch (RuntimeException&)
834 snewfoil_value_info* pInfo = NULL;
835 if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
837 pInfo = notes;
839 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
841 pInfo = handout;
843 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
844 || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
846 pInfo = standard;
848 else
850 pInfo = NULL;
853 Clear();
854 int n = 0;
855 for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
857 if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
859 BitmapEx aBmp (SdResId (bHighContrast
860 ? pInfo->mnHCBmpResId
861 : pInfo->mnBmpResId));
863 if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
864 aBmp.Mirror (BMP_MIRROR_HORZ);
866 InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId)));
867 SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
868 n++;
872 mbSelectionUpdatePending = true;
878 void LayoutMenu::Clear (void)
880 for (USHORT nId=1; nId<=GetItemCount(); nId++)
881 delete static_cast<AutoLayout*>(GetItemData(nId));
882 ValueSet::Clear();
887 void LayoutMenu::StartDrag (sal_Int8 , const Point& )
894 sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
896 return 0;
902 sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
904 return 0;
910 void LayoutMenu::Command (const CommandEvent& rEvent)
912 switch (rEvent.GetCommand())
914 case COMMAND_CONTEXTMENU:
915 if ( ! SD_MOD()->GetWaterCan())
917 if (GetShellManager() != NULL)
918 GetShellManager()->MoveToTop(this);
919 if (rEvent.IsMouseEvent())
920 mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
921 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP));
922 else
924 // When the command event was not caused by a mouse
925 // event (for example a key press instead) then show the
926 // popup menu at the center of the current item.
927 if (GetSelectItemId() != (USHORT)-1)
929 Rectangle aBBox (GetItemRect(GetSelectItemId()));
930 Point aPosition (aBBox.Center());
931 mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
932 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP),
933 this,
934 &aPosition);
938 break;
940 default:
941 ValueSet::Command(rEvent);
942 break;
949 IMPL_LINK(LayoutMenu, StateChangeHandler, ::rtl::OUString*, EMPTYARG)
951 InvalidateContent();
952 return 0;
958 void LayoutMenu::UpdateSelection (void)
960 bool bItemSelected = false;
964 // Get current page of main view.
965 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
966 if (pViewShell == NULL)
967 break;
969 SdPage* pCurrentPage = pViewShell->getCurrentPage();
970 if (pCurrentPage == NULL)
971 break;
973 // Get layout of current page.
974 AutoLayout aLayout (pCurrentPage->GetAutoLayout());
975 if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
976 break;
978 // Find the entry of the menu for to the layout.
979 USHORT nItemCount (GetItemCount());
980 for (USHORT nId=1; nId<=nItemCount; nId++)
982 if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
984 SelectItem(nId);
985 bItemSelected = true;
986 break;
990 while (false);
992 if ( ! bItemSelected)
993 SetNoSelection();
999 IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
1001 switch (pEvent->meEventId)
1003 case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
1004 case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
1005 if ( ! mbSelectionUpdatePending)
1006 UpdateSelection();
1007 break;
1009 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
1010 mbIsMainViewChangePending = true;
1011 UpdateEnabledState(MM_UNKNOWN);
1012 break;
1014 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
1015 HideFocus();
1016 break;
1018 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
1019 if (mbIsMainViewChangePending)
1021 mbIsMainViewChangePending = false;
1022 InvalidateContent();
1024 break;
1026 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
1027 UpdateEnabledState(MM_NORMAL);
1028 break;
1030 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
1031 UpdateEnabledState(MM_MASTER);
1032 break;
1034 default:
1035 /* Ignored */
1036 break;
1039 return 0;
1045 void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
1047 Fill();
1048 ValueSet::DataChanged(rEvent);
1052 } } // end of namespace ::sd::toolpanel