fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / toolpanel / LayoutMenu.cxx
blob8f444a355c6bf40ead70cd8710b93a17e4ecdc09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "LayoutMenu.hxx"
23 #include "TaskPaneShellManager.hxx"
24 #include "pres.hxx"
25 #include "drawdoc.hxx"
26 #include "DrawDocShell.hxx"
27 #include "sdpage.hxx"
28 #include "glob.hxx"
29 #include "glob.hrc"
30 #include "app.hrc"
31 #include "helpids.h"
32 #include "res_bmp.hrc"
33 #include "strings.hrc"
34 #include "ViewShellBase.hxx"
35 #include "DrawViewShell.hxx"
36 #include "SlideSorterViewShell.hxx"
37 #include "controller/SlideSorterController.hxx"
38 #include "controller/SlsPageSelector.hxx"
39 #include "taskpane/TaskPaneControlFactory.hxx"
40 #include "taskpane/ToolPanelViewShell.hxx"
41 #include "taskpane/ScrollPanel.hxx"
42 #include "tools/SlotStateListener.hxx"
43 #include "EventMultiplexer.hxx"
44 #include "DrawController.hxx"
45 #include "framework/FrameworkHelper.hxx"
47 #include <vector>
48 #include <memory>
49 #include <sfx2/objface.hxx>
50 #include "sdresid.hxx"
51 #include <vcl/image.hxx>
52 #include <svl/languageoptions.hxx>
53 #include <sfx2/app.hxx>
54 #include "taskpane/TitledControl.hxx"
55 #include <sfx2/dispatch.hxx>
56 #include <sfx2/request.hxx>
57 #include <comphelper/processfactory.hxx>
58 #include <sfx2/viewfrm.hxx>
60 #include <com/sun/star/frame/XController.hpp>
61 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
62 #include <com/sun/star/drawing/framework/XView.hpp>
63 #include <com/sun/star/drawing/framework/ResourceId.hpp>
65 using namespace ::sd::toolpanel;
66 #define LayoutMenu
67 #include "sdslots.hxx"
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::text;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::drawing::framework;
73 using namespace ::sd::slidesorter;
74 using ::sd::framework::FrameworkHelper;
76 namespace sd { namespace toolpanel {
78 class LayoutMenuRootFactory
79 : public ControlFactory
81 public:
82 LayoutMenuRootFactory (ToolPanelViewShell& i_rPanelViewShell)
83 :mrPanelViewShell(i_rPanelViewShell)
87 protected:
88 virtual TreeNode* InternalCreateControl( ::Window& i_rParent )
90 ScrollPanel* pScrollPanel = new ScrollPanel (i_rParent);
91 ::std::auto_ptr<TreeNode> pMenu (
92 new LayoutMenu (
93 pScrollPanel,
94 mrPanelViewShell));
95 pScrollPanel->AddControl(pMenu);
96 return pScrollPanel;
99 private:
100 ToolPanelViewShell& mrPanelViewShell;
104 SFX_IMPL_INTERFACE(LayoutMenu, SfxShell,
105 SdResId(STR_TASKPANELAYOUTMENU))
107 SFX_POPUPMENU_REGISTRATION(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP));
110 TYPEINIT1(LayoutMenu, SfxShell);
112 struct snewfoil_value_info
114 sal_uInt16 mnBmpResId;
115 sal_uInt16 mnStrResId;
116 WritingMode meWritingMode;
117 AutoLayout maAutoLayout;
120 static snewfoil_value_info notes[] =
122 {BMP_FOILN_01, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
123 AUTOLAYOUT_NOTES},
124 {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
127 static snewfoil_value_info handout[] =
129 {BMP_FOILH_01, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
130 AUTOLAYOUT_HANDOUT1},
131 {BMP_FOILH_02, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
132 AUTOLAYOUT_HANDOUT2},
133 {BMP_FOILH_03, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
134 AUTOLAYOUT_HANDOUT3},
135 {BMP_FOILH_04, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
136 AUTOLAYOUT_HANDOUT4},
137 {BMP_FOILH_06, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
138 AUTOLAYOUT_HANDOUT6},
139 {BMP_FOILH_09, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
140 AUTOLAYOUT_HANDOUT9},
141 {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
144 static snewfoil_value_info standard[] =
146 {BMP_LAYOUT_EMPTY, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB, AUTOLAYOUT_NONE},
147 {BMP_LAYOUT_HEAD03, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB, AUTOLAYOUT_TITLE},
148 {BMP_LAYOUT_HEAD02, STR_AUTOLAYOUT_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_ENUM},
149 {BMP_LAYOUT_HEAD02A, STR_AUTOLAYOUT_2CONTENT, WritingMode_LR_TB, AUTOLAYOUT_2TEXT},
150 {BMP_LAYOUT_HEAD01, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB, AUTOLAYOUT_ONLY_TITLE},
151 {BMP_LAYOUT_TEXTONLY, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB, AUTOLAYOUT_ONLY_TEXT},
152 {BMP_LAYOUT_HEAD03B, STR_AUTOLAYOUT_2CONTENT_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_2OBJTEXT},
153 {BMP_LAYOUT_HEAD03C, STR_AUTOLAYOUT_CONTENT_2CONTENT, WritingMode_LR_TB, AUTOLAYOUT_TEXT2OBJ},
154 {BMP_LAYOUT_HEAD03A, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT},
155 {BMP_LAYOUT_HEAD02B, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT},
156 {BMP_LAYOUT_HEAD04, STR_AUTOLAYOUT_4CONTENT, WritingMode_LR_TB, AUTOLAYOUT_4OBJ},
157 {BMP_LAYOUT_HEAD06, STR_AUTOLAYOUT_6CONTENT, WritingMode_LR_TB, AUTOLAYOUT_6CLIPART},
159 // vertical
160 {BMP_LAYOUT_VERTICAL02, STR_AL_VERT_TITLE_TEXT_CHART, WritingMode_TB_RL,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
161 {BMP_LAYOUT_VERTICAL01, STR_AL_VERT_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
162 {BMP_LAYOUT_HEAD02, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
163 {BMP_LAYOUT_HEAD02A, STR_AL_TITLE_VERT_OUTLINE_CLIPART, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
164 {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
167 LayoutMenu::LayoutMenu( TreeNode* pParent, ToolPanelViewShell& i_rPanelViewShell )
168 : ValueSet(pParent->GetWindow(), WB_ITEMBORDER),
169 TreeNode(pParent),
170 DragSourceHelper(this),
171 DropTargetHelper(this),
172 mrBase( i_rPanelViewShell.GetViewShellBase() ),
173 mpShellManager (&i_rPanelViewShell.GetSubShellManager()),
174 mbUseOwnScrollBar( false ),
175 mnPreferredColumnCount(3),
176 mxListener(NULL),
177 mbSelectionUpdatePending(true),
178 mbIsMainViewChangePending(false)
180 implConstruct( *mrBase.GetDocument()->GetDocSh() );
184 void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell )
186 OSL_ENSURE( mrBase.GetDocument()->GetDocSh() == &rDocumentShell,
187 "LayoutMenu::implConstruct: hmm?" );
188 // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
190 SetStyle (
191 ( GetStyle() & ~(WB_ITEMBORDER) )
192 | WB_TABSTOP
193 | WB_NO_DIRECTSELECT
195 if (mbUseOwnScrollBar)
196 SetStyle (GetStyle() | WB_VSCROLL);
197 SetExtraSpacing(2);
198 SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
199 SetPool (&rDocumentShell.GetDoc()->GetPool());
200 SetName(OUString("LayoutMenu"));
201 InvalidateContent();
203 Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
204 mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
205 ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
206 | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
207 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
208 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
209 | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
210 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
211 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
213 Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS);
214 SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
216 Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
217 mxListener = new ::sd::tools::SlotStateListener(
218 aStateChangeLink,
219 Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
220 ".uno:VerticalTextState");
222 // Add this new object as shell to the shell factory.
223 GetShellManager()->AddSubShell(SHELLID_SD_TASK_PANE_PREVIEW_LAYOUTS,this,this);
228 LayoutMenu::~LayoutMenu (void)
230 // Tell the shell factory that this object is no longer available.
231 if (GetShellManager() != NULL)
232 GetShellManager()->RemoveSubShell(this);
234 Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
235 if (xComponent.is())
236 xComponent->dispose();
238 Clear();
239 Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
240 mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
246 ::std::auto_ptr<ControlFactory> LayoutMenu::CreateControlFactory (
247 ToolPanelViewShell& i_rPanelViewShell )
249 return ::std::auto_ptr<ControlFactory>(new LayoutMenuRootFactory(i_rPanelViewShell));
255 AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
257 AutoLayout aResult = AUTOLAYOUT_NONE;
259 if ( ! IsNoSelection() && GetSelectItemId()!=0)
261 AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
262 if (pLayout != NULL)
263 aResult = *pLayout;
266 return aResult;
272 /** The preferred size depends on the preferred number of columns, the
273 number of items, and the size of the items.
275 Size LayoutMenu::GetPreferredSize (void)
277 Size aItemSize = CalcItemSizePixel (Size());
278 Size aPreferredWindowSize = CalcWindowSizePixel (
279 aItemSize,
280 (sal_uInt16)mnPreferredColumnCount,
281 (sal_uInt16)CalculateRowCount (aItemSize,mnPreferredColumnCount));
282 return aPreferredWindowSize;
288 sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight)
290 sal_Int32 nPreferredWidth = 100;
291 if (GetItemCount() > 0)
293 Image aImage = GetItemImage(GetItemId(0));
294 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
295 if (nHeight>0 && aItemSize.Height()>0)
297 int nRowCount = nHeight / aItemSize.Height();
298 if (nRowCount <= 0)
299 nRowCount = 1;
300 int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount;
301 nPreferredWidth = nColumnCount * aItemSize.Width();
305 return nPreferredWidth;
311 sal_Int32 LayoutMenu::GetPreferredHeight (sal_Int32 nWidth)
313 sal_Int32 nPreferredHeight = 200;
314 if ( ! mbUseOwnScrollBar && GetItemCount()>0)
316 Image aImage = GetItemImage(GetItemId(0));
317 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
318 if (nWidth>0 && aItemSize.Width()>0)
320 aItemSize.Width() += 8;
321 aItemSize.Height() += 8;
322 int nColumnCount = nWidth / aItemSize.Width();
323 if (nColumnCount <= 0)
324 nColumnCount = 1;
325 else if (nColumnCount > 4)
326 nColumnCount = 4;
327 int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
328 nPreferredHeight = nRowCount * aItemSize.Height();
331 return nPreferredHeight;
337 sal_Int32 LayoutMenu::GetMinimumWidth (void)
339 sal_Int32 nMinimumWidth = 0;
340 if (GetItemCount()>0)
342 Image aImage = GetItemImage(GetItemId(0));
343 Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
344 nMinimumWidth = aItemSize.Width();
346 return nMinimumWidth;
352 bool LayoutMenu::IsResizable (void)
354 return true;
360 void LayoutMenu::UpdateEnabledState (const MasterMode eMode)
362 bool bIsEnabled (false);
364 ::boost::shared_ptr<ViewShell> pMainViewShell (mrBase.GetMainViewShell());
365 if (pMainViewShell)
367 switch (pMainViewShell->GetShellType())
369 case ViewShell::ST_NONE:
370 case ViewShell::ST_OUTLINE:
371 case ViewShell::ST_PRESENTATION:
372 case ViewShell::ST_TASK_PANE:
373 // The complete task pane is disabled for these values or
374 // not even visible. Disabling the LayoutMenu would be
375 // logical but unnecessary. The main disadvantage is that
376 // after re-enabling it (typically) another panel is
377 // expanded.
378 bIsEnabled = true;
379 break;
381 case ViewShell::ST_DRAW:
382 case ViewShell::ST_IMPRESS:
384 switch (eMode)
386 case MM_UNKNOWN:
388 ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
389 ::boost::dynamic_pointer_cast<DrawViewShell>(pMainViewShell));
390 if (pDrawViewShell)
391 bIsEnabled = pDrawViewShell->GetEditMode() != EM_MASTERPAGE;
392 break;
394 case MM_NORMAL:
395 bIsEnabled = true;
396 break;
398 case MM_MASTER:
399 bIsEnabled = false;
400 break;
402 break;
405 case ViewShell::ST_HANDOUT:
406 case ViewShell::ST_NOTES:
407 case ViewShell::ST_SLIDE_SORTER:
408 default:
409 bIsEnabled = true;
410 break;
413 TreeNode* pParentNode = GetParentNode();
414 if (pParentNode != NULL)
416 TitledControl* pGrandParentNode
417 = dynamic_cast<TitledControl*>(pParentNode->GetParentNode());
418 if (pGrandParentNode != NULL)
419 pGrandParentNode->SetEnabledState(bIsEnabled);
428 ::Window* LayoutMenu::GetWindow (void)
430 return this;
436 void LayoutMenu::Paint (const Rectangle& rRect)
438 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
440 if (mbSelectionUpdatePending)
442 mbSelectionUpdatePending = false;
443 UpdateSelection();
445 ValueSet::Paint (rRect);
447 SetBackground (Wallpaper());
453 void LayoutMenu::Resize (void)
455 Size aWindowSize = GetOutputSizePixel();
456 if (IsVisible() && aWindowSize.Width() > 0)
458 // Calculate the number of rows and columns.
459 if (GetItemCount() > 0)
461 Image aImage = GetItemImage(GetItemId(0));
462 Size aItemSize = CalcItemSizePixel (
463 aImage.GetSizePixel());
464 aItemSize.Width() += 8;
465 aItemSize.Height() += 8;
466 int nColumnCount = aWindowSize.Width() / aItemSize.Width();
467 if (nColumnCount < 1)
468 nColumnCount = 1;
469 else if (nColumnCount > 4)
470 nColumnCount = 4;
472 int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
474 SetColCount ((sal_uInt16)nColumnCount);
475 SetLineCount ((sal_uInt16)nRowCount);
479 ValueSet::Resize ();
485 void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
487 // As a preparation for the context menu the item under the mouse is
488 // selected.
489 if (rEvent.IsRight())
491 ReleaseMouse();
492 sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel());
493 if (nIndex > 0)
494 SelectItem(nIndex);
497 ValueSet::MouseButtonDown (rEvent);
503 void LayoutMenu::Execute (SfxRequest& rRequest)
505 switch (rRequest.GetSlot())
507 case SID_TP_APPLY_TO_SELECTED_SLIDES:
508 AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
509 rRequest.Done();
510 break;
512 case SID_INSERTPAGE_LAYOUT_MENU:
513 // Add arguments to this slot and forward it to the main view
514 // shell.
515 InsertPageWithLayout(GetSelectedAutoLayout());
516 break;
523 void LayoutMenu::GetState (SfxItemSet& rItemSet)
525 // Cut and paste is not supported. The SID_(CUT,COPY,PASTE) entries
526 // therefore must not show up in the context menu.
527 rItemSet.DisableItem (SID_CUT);
528 rItemSet.DisableItem (SID_COPY);
529 rItemSet.DisableItem (SID_PASTE);
531 // The SID_INSERTPAGE_LAYOUT_MENU slot depends on the SID_INSERTPAGE
532 // slot being supported elsewhere.
533 const SfxPoolItem* pItem = NULL;
534 const SfxItemState aState (
535 mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
536 if (aState == SFX_ITEM_DISABLED)
537 rItemSet.DisableItem(SID_INSERTPAGE_LAYOUT_MENU);
543 void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
545 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
546 if (pViewShell == NULL)
547 return;
549 SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
550 if (pViewFrame == NULL)
551 return;
553 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
554 if (pDispatcher == NULL)
555 return;
557 // Call SID_INSERTPAGE with the right arguments. This is because
558 // the popup menu can not call this slot with arguments directly.
559 SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
560 if (aRequest.GetArgs() != NULL)
562 pDispatcher->Execute(
563 SID_INSERTPAGE,
564 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
565 *aRequest.GetArgs());
567 UpdateSelection();
573 TaskPaneShellManager* LayoutMenu::GetShellManager()
575 if ( mpShellManager )
576 return mpShellManager;
577 return TreeNode::GetShellManager();
580 void LayoutMenu::InvalidateContent (void)
582 // The number of items may have changed. Request a resize so that the
583 // vertical size of this control can be adapted.
584 RequestResize();
586 // Throw away the current set and fill the menu anew according to the
587 // current settings (this includes the support for vertical writing.)
588 Fill();
594 int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
596 int nRowCount = 0;
598 if (GetItemCount() > 0 && nColumnCount > 0)
600 nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
601 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
602 if (nRowCount < 1)
603 nRowCount = 1;
606 return nRowCount;
612 IMPL_LINK_NOARG(LayoutMenu, ClickHandler)
614 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
615 return 0;
621 /** The specified layout is assigned to the current page of the view shell
622 in the center pane.
624 void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
626 using namespace ::sd::slidesorter;
627 using namespace ::sd::slidesorter::controller;
631 // The view shell in the center pane has to be present.
632 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
633 if (pMainViewShell == NULL)
634 break;
636 // Determine if the current view is in an invalid master page mode.
637 // The handout view is always in master page mode and therefore not
638 // invalid.
639 bool bMasterPageMode (false);
640 switch (pMainViewShell->GetShellType())
642 case ViewShell::ST_NOTES:
643 case ViewShell::ST_IMPRESS:
645 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
646 if (pDrawViewShell != NULL)
647 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
648 bMasterPageMode = true;
650 default:
651 break;
653 if (bMasterPageMode)
654 break;
656 // Get a list of all selected slides and call the SID_MODIFYPAGE
657 // slot for all of them.
658 ::sd::slidesorter::SharedPageSelection pPageSelection;
660 // Get a list of selected pages.
661 // First we try to obtain this list from a slide sorter. This is
662 // possible only some of the view shells in the center pane. When
663 // no valid slide sorter is available then ask the main view shell
664 // for its current page.
665 SlideSorterViewShell* pSlideSorter = NULL;
666 switch (pMainViewShell->GetShellType())
668 case ViewShell::ST_IMPRESS:
669 case ViewShell::ST_NOTES:
670 case ViewShell::ST_SLIDE_SORTER:
671 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
672 break;
673 default:
674 break;
676 if (pSlideSorter != NULL)
678 // There is a slide sorter visible so get the list of selected pages from it.
679 pPageSelection = pSlideSorter->GetPageSelection();
682 if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() )
684 // No valid slide sorter available. Ask the main view shell for
685 // its current page.
686 pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
687 pPageSelection->push_back(pMainViewShell->GetActualPage());
691 if (pPageSelection->empty())
692 break;
694 ::std::vector<SdPage*>::iterator iPage;
695 for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
697 if ((*iPage) == NULL)
698 continue;
700 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
701 SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
702 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
703 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
704 pMainViewShell->ExecuteSlot (aRequest, sal_Bool(sal_False));
707 while(false);
713 SfxRequest LayoutMenu::CreateRequest (
714 sal_uInt16 nSlotId,
715 AutoLayout aLayout)
717 SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
721 SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
722 sal_uInt8 aBackground (rLayerAdmin.GetLayerID(
723 String(SdResId(STR_LAYER_BCKGRND)), sal_False));
724 sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(
725 String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False));
726 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
727 if (pViewShell == NULL)
728 break;
729 SdPage* pPage = pViewShell->GetActualPage();
730 if (pPage == NULL)
731 break;
733 SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
735 aRequest.AppendItem(
736 SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName()));
737 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
738 aRequest.AppendItem(
739 SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
740 aRequest.AppendItem(
741 SfxBoolItem(
742 ID_VAL_ISPAGEOBJ,
743 aVisibleLayers.IsSet(aBackgroundObject)));
745 while (false);
747 return aRequest;
753 void LayoutMenu::Fill (void)
755 SvtLanguageOptions aLanguageOptions;
756 sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
757 SdDrawDocument* pDocument = mrBase.GetDocument();
758 sal_Bool bRightToLeft = (pDocument!=NULL
759 && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
761 // Get URL of the view in the center pane.
762 OUString sCenterPaneViewName;
765 Reference<XControllerManager> xControllerManager (
766 Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
767 Reference<XResourceId> xPaneId (ResourceId::create(
768 ::comphelper::getProcessComponentContext(),
769 FrameworkHelper::msCenterPaneURL));
770 Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
771 if (xView.is())
772 sCenterPaneViewName = xView->getResourceId()->getResourceURL();
774 catch (RuntimeException&)
777 snewfoil_value_info* pInfo = NULL;
778 if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
780 pInfo = notes;
782 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
784 pInfo = handout;
786 else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
787 || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
789 pInfo = standard;
791 else
793 pInfo = NULL;
796 Clear();
797 int n = 0;
798 for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
800 if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
802 BitmapEx aBmp(SdResId(pInfo->mnBmpResId));
804 if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
805 aBmp.Mirror (BMP_MIRROR_HORZ);
807 InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId)));
808 SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
809 n++;
813 mbSelectionUpdatePending = true;
819 void LayoutMenu::Clear (void)
821 for (sal_uInt16 nId=1; nId<=GetItemCount(); nId++)
822 delete static_cast<AutoLayout*>(GetItemData(nId));
823 ValueSet::Clear();
828 void LayoutMenu::StartDrag (sal_Int8 , const Point& )
835 sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
837 return 0;
843 sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
845 return 0;
851 void LayoutMenu::Command (const CommandEvent& rEvent)
853 switch (rEvent.GetCommand())
855 case COMMAND_CONTEXTMENU:
856 if ( ! SD_MOD()->GetWaterCan())
858 if (GetShellManager() != NULL)
859 GetShellManager()->MoveToTop(this);
860 Point aPosition (0,0);
861 if (rEvent.IsMouseEvent())
863 // Do not show the context menu when the mouse was not
864 // pressed over an item.
865 // We have to explicitly specify the location of the menu
866 // when the LayoutMenu is undocked
867 if (GetItemId(rEvent.GetMousePosPixel()) > 0)
868 aPosition = rEvent.GetMousePosPixel();
870 else
872 // When the command event was not caused by a mouse
873 // event (for example a key press instead) then show the
874 // popup menu at the center of the current item.
875 if (GetSelectItemId() != (sal_uInt16)-1)
877 Rectangle aBBox (GetItemRect(GetSelectItemId()));
878 aPosition = aBBox.Center();
881 mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
882 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP),
883 this,
884 &aPosition);
886 break;
888 default:
889 ValueSet::Command(rEvent);
890 break;
897 IMPL_LINK_NOARG(LayoutMenu, StateChangeHandler)
899 InvalidateContent();
900 return 0;
906 void LayoutMenu::UpdateSelection (void)
908 bool bItemSelected = false;
912 // Get current page of main view.
913 ViewShell* pViewShell = mrBase.GetMainViewShell().get();
914 if (pViewShell == NULL)
915 break;
917 SdPage* pCurrentPage = pViewShell->getCurrentPage();
918 if (pCurrentPage == NULL)
919 break;
921 // Get layout of current page.
922 AutoLayout aLayout (pCurrentPage->GetAutoLayout());
923 if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
924 break;
926 // Find the entry of the menu for to the layout.
927 sal_uInt16 nItemCount (GetItemCount());
928 for (sal_uInt16 nId=1; nId<=nItemCount; nId++)
930 if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
932 SelectItem(nId);
933 bItemSelected = true;
934 break;
938 while (false);
940 if ( ! bItemSelected)
941 SetNoSelection();
947 IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
949 switch (pEvent->meEventId)
951 case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
952 case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
953 if ( ! mbSelectionUpdatePending)
954 UpdateSelection();
955 break;
957 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
958 mbIsMainViewChangePending = true;
959 UpdateEnabledState(MM_UNKNOWN);
960 break;
962 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
963 HideFocus();
964 break;
966 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
967 if (mbIsMainViewChangePending)
969 mbIsMainViewChangePending = false;
970 InvalidateContent();
972 break;
974 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
975 UpdateEnabledState(MM_NORMAL);
976 break;
978 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
979 UpdateEnabledState(MM_MASTER);
980 break;
982 default:
983 /* Ignored */
984 break;
987 return 0;
993 void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
995 Fill();
996 ValueSet::DataChanged(rEvent);
1000 } } // end of namespace ::sd::toolpanel
1002 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */