1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LayoutMenu.cxx,v $
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"
38 #include "drawdoc.hxx"
39 #include "DrawDocShell.hxx"
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"
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
;
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
97 LayoutMenuFactory (ViewShellBase
& rBase
, DrawDocShell
& rDocShell
)
103 virtual TreeNode
* InternalCreateControl (TreeNode
* pTreeNode
)
105 ScrollPanel
* pScrollPanel
= new ScrollPanel (pTreeNode
);
106 ::std::auto_ptr
<TreeNode
> pMenu (
112 pScrollPanel
->AddControl(pMenu
);
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
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
,
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
,
169 {BMP_FOIL_00
, BMP_FOIL_00_H
, STR_AUTOLAYOUT_TITLE
, WritingMode_LR_TB
,
171 {BMP_FOIL_01
, BMP_FOIL_01_H
, STR_AUTOLAYOUT_ENUM
, WritingMode_LR_TB
,
173 {BMP_FOIL_03
, BMP_FOIL_03_H
, STR_AUTOLAYOUT_2TEXT
, WritingMode_LR_TB
,
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
,
181 {BMP_FOIL_02
, BMP_FOIL_02_H
, STR_AUTOLAYOUT_CHART
, WritingMode_LR_TB
,
183 {BMP_FOIL_08
, BMP_FOIL_08_H
, STR_AUTOLAYOUT_TAB
, WritingMode_LR_TB
,
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
,
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
,
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
,
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
},
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 (
230 DrawDocShell
& rDocumentShell
,
231 ViewShellBase
& rViewShellBase
,
232 bool bUseOwnScrollBar
)
233 : ValueSet (pParent
->GetWindow()),
235 DragSourceHelper(this),
236 DropTargetHelper(this),
237 mrBase (rViewShellBase
),
238 mbUseOwnScrollBar (bUseOwnScrollBar
),
239 mnPreferredColumnCount(3),
241 mbSelectionUpdatePending(true),
242 mbIsMainViewChangePending(false)
245 ( GetStyle() & ~(WB_ITEMBORDER
) )
249 if (mbUseOwnScrollBar
)
250 SetStyle (GetStyle() | WB_VSCROLL
);
252 SetSelectHdl (LINK(this, LayoutMenu
, ClickHandler
));
253 SetPool (&rDocumentShell
.GetDoc()->GetPool());
254 SetName(String(RTL_CONSTASCII_USTRINGPARAM("LayoutMenu")));
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(
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
);
291 xComponent
->dispose();
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()));
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 (
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();
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)
389 else if (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)
424 void LayoutMenu::UpdateEnabledState (const MasterMode eMode
)
426 bool bIsEnabled (false);
428 ::boost::shared_ptr
<ViewShell
> pMainViewShell (mrBase
.GetMainViewShell());
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
445 case ViewShell::ST_DRAW
:
446 case ViewShell::ST_IMPRESS
:
452 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
453 ::boost::dynamic_pointer_cast
<DrawViewShell
>(pMainViewShell
));
455 bIsEnabled
= pDrawViewShell
->GetEditMode() != EM_MASTERPAGE
;
469 case ViewShell::ST_HANDOUT
:
470 case ViewShell::ST_NOTES
:
471 case ViewShell::ST_SLIDE_SORTER
:
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)
500 void LayoutMenu::Paint (const Rectangle
& rRect
)
502 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
504 if (mbSelectionUpdatePending
)
506 mbSelectionUpdatePending
= false;
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)
533 else if (nColumnCount
> 4)
536 int nRowCount
= CalculateRowCount (aItemSize
, nColumnCount
);
538 SetColCount ((USHORT
)nColumnCount
);
539 SetLineCount ((USHORT
)nRowCount
);
549 void LayoutMenu::MouseButtonDown (const MouseEvent
& rEvent
)
551 // As a preparation for the context menu the item under the mouse is
553 if (rEvent
.IsRight())
556 USHORT nIndex
= GetItemId (rEvent
.GetPosPixel());
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());
576 case SID_INSERTPAGE_LAYOUT_MENU
:
577 // Add arguments to this slot and forward it to the main view
579 InsertPageWithLayout(GetSelectedAutoLayout());
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
)
613 SfxViewFrame
* pViewFrame
= mrBase
.GetViewFrame();
614 if (pViewFrame
== NULL
)
617 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
618 if (pDispatcher
== NULL
)
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(
628 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
629 *aRequest
.GetArgs());
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.
643 // Throw away the current set and fill the menu anew according to the
644 // current settings (this includes the support for vertical writing.)
651 int LayoutMenu::CalculateRowCount (const Size
&, int nColumnCount
)
655 if (GetItemCount() > 0 && nColumnCount
> 0)
657 nRowCount
= (GetItemCount() + nColumnCount
- 1) / nColumnCount
;
658 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
669 IMPL_LINK(LayoutMenu
, ClickHandler
, ValueSet
*, EMPTYARG
)
671 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
678 /** The specified layout is assigned to the current page of the view shell
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
)
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
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;
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
);
733 if (pSlideSorter
!= NULL
)
735 // There is a slide sorter visible so get the list of selected pages from it.
736 pPageSelection
= pSlideSorter
->GetPageSelection();
740 // No valid slide sorter available. Ask the main view shell for
742 pPageSelection
.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
743 pPageSelection
->push_back(pMainViewShell
->GetActualPage());
747 if (pPageSelection
->empty())
750 ::std::vector
<SdPage
*>::iterator iPage
;
751 for (iPage
=pPageSelection
->begin(); iPage
!=pPageSelection
->end(); ++iPage
)
753 if ((*iPage
) == NULL
)
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
));
769 SfxRequest
LayoutMenu::CreateRequest (
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
)
785 SdPage
* pPage
= pViewShell
->GetActualPage();
789 SetOfByte
aVisibleLayers (pPage
->TRG_GetMasterPageVisibleLayers());
792 SfxStringItem (ID_VAL_PAGENAME
, String()));//pPage->GetName()));
793 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, aLayout
));
795 SfxBoolItem(ID_VAL_ISPAGEBACK
, aVisibleLayers
.IsSet(aBackground
)));
799 aVisibleLayers
.IsSet(aBackgroundObject
)));
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
));
829 sCenterPaneViewName
= xView
->getResourceId()->getResourceURL();
831 catch (RuntimeException
&)
834 snewfoil_value_info
* pInfo
= NULL
;
835 if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msNotesViewURL
))
839 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msHandoutViewURL
))
843 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msImpressViewURL
)
844 || sCenterPaneViewName
.equals(framework::FrameworkHelper::msSlideSorterURL
))
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
));
872 mbSelectionUpdatePending
= true;
878 void LayoutMenu::Clear (void)
880 for (USHORT nId
=1; nId
<=GetItemCount(); nId
++)
881 delete static_cast<AutoLayout
*>(GetItemData(nId
));
887 void LayoutMenu::StartDrag (sal_Int8
, const Point
& )
894 sal_Int8
LayoutMenu::AcceptDrop (const AcceptDropEvent
& )
902 sal_Int8
LayoutMenu::ExecuteDrop (const ExecuteDropEvent
& )
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
));
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
),
941 ValueSet::Command(rEvent
);
949 IMPL_LINK(LayoutMenu
, StateChangeHandler
, ::rtl::OUString
*, EMPTYARG
)
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
)
969 SdPage
* pCurrentPage
= pViewShell
->getCurrentPage();
970 if (pCurrentPage
== NULL
)
973 // Get layout of current page.
974 AutoLayout
aLayout (pCurrentPage
->GetAutoLayout());
975 if (aLayout
<AUTOLAYOUT__START
|| aLayout
>AUTOLAYOUT__END
)
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
)
985 bItemSelected
= true;
992 if ( ! bItemSelected
)
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
)
1009 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
:
1010 mbIsMainViewChangePending
= true;
1011 UpdateEnabledState(MM_UNKNOWN
);
1014 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
:
1018 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
:
1019 if (mbIsMainViewChangePending
)
1021 mbIsMainViewChangePending
= false;
1022 InvalidateContent();
1026 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
:
1027 UpdateEnabledState(MM_NORMAL
);
1030 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
:
1031 UpdateEnabledState(MM_MASTER
);
1045 void LayoutMenu::DataChanged (const DataChangedEvent
& rEvent
)
1048 ValueSet::DataChanged(rEvent
);
1052 } } // end of namespace ::sd::toolpanel