1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
31 #include "LayoutMenu.hxx"
33 #include "TaskPaneShellManager.hxx"
35 #include "drawdoc.hxx"
36 #include "DrawDocShell.hxx"
42 #include "res_bmp.hrc"
43 #include "strings.hrc"
44 #include "ViewShellBase.hxx"
45 #include "DrawViewShell.hxx"
46 #include "SlideSorterViewShell.hxx"
47 #include "controller/SlideSorterController.hxx"
48 #include "controller/SlsPageSelector.hxx"
49 #include "taskpane/TaskPaneControlFactory.hxx"
50 #include "taskpane/ToolPanelViewShell.hxx"
51 #include "taskpane/ScrollPanel.hxx"
52 #include "tools/SlotStateListener.hxx"
53 #include "EventMultiplexer.hxx"
54 #include "DrawController.hxx"
55 #include "framework/FrameworkHelper.hxx"
59 #include <sfx2/objface.hxx>
60 #include "sdresid.hxx"
61 #include <vcl/image.hxx>
62 #include <svl/languageoptions.hxx>
63 #include <sfx2/app.hxx>
64 #include "taskpane/TitledControl.hxx"
65 #include <sfx2/dispatch.hxx>
66 #include <sfx2/request.hxx>
67 #include <comphelper/processfactory.hxx>
68 #include <sfx2/viewfrm.hxx>
70 #include <com/sun/star/frame/XController.hpp>
71 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
72 #include <com/sun/star/drawing/framework/XView.hpp>
73 #include <com/sun/star/drawing/framework/ResourceId.hpp>
75 using namespace ::sd::toolpanel
;
77 #include "sdslots.hxx"
79 using namespace ::com::sun::star
;
80 using namespace ::com::sun::star::text
;
81 using namespace ::com::sun::star::uno
;
82 using namespace ::com::sun::star::drawing::framework
;
83 using namespace ::sd::slidesorter
;
84 using ::sd::framework::FrameworkHelper
;
86 namespace sd
{ namespace toolpanel
{
88 class LayoutMenuRootFactory
89 : public ControlFactory
92 LayoutMenuRootFactory (ToolPanelViewShell
& i_rPanelViewShell
)
93 :mrPanelViewShell(i_rPanelViewShell
)
98 virtual TreeNode
* InternalCreateControl( ::Window
& i_rParent
)
100 ScrollPanel
* pScrollPanel
= new ScrollPanel (i_rParent
);
101 ::std::auto_ptr
<TreeNode
> pMenu (
105 pScrollPanel
->AddControl(pMenu
);
110 ToolPanelViewShell
& mrPanelViewShell
;
114 SFX_IMPL_INTERFACE(LayoutMenu
, SfxShell
,
115 SdResId(STR_TASKPANELAYOUTMENU
))
117 SFX_POPUPMENU_REGISTRATION(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP
));
120 TYPEINIT1(LayoutMenu
, SfxShell
);
122 struct snewfoil_value_info
124 sal_uInt16 mnBmpResId
;
125 sal_uInt16 mnHCBmpResId
;
126 sal_uInt16 mnStrResId
;
127 WritingMode meWritingMode
;
128 AutoLayout maAutoLayout
;
131 static snewfoil_value_info notes
[] =
133 {BMP_FOILN_01
, BMP_FOILN_01_H
, STR_AUTOLAYOUT_NOTES
, WritingMode_LR_TB
,
135 {0, 0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
138 static snewfoil_value_info handout
[] =
140 {BMP_FOILH_01
, BMP_FOILH_01_H
, STR_AUTOLAYOUT_HANDOUT1
, WritingMode_LR_TB
,
141 AUTOLAYOUT_HANDOUT1
},
142 {BMP_FOILH_02
, BMP_FOILH_02_H
, STR_AUTOLAYOUT_HANDOUT2
, WritingMode_LR_TB
,
143 AUTOLAYOUT_HANDOUT2
},
144 {BMP_FOILH_03
, BMP_FOILH_03_H
, STR_AUTOLAYOUT_HANDOUT3
, WritingMode_LR_TB
,
145 AUTOLAYOUT_HANDOUT3
},
146 {BMP_FOILH_04
, BMP_FOILH_04_H
, STR_AUTOLAYOUT_HANDOUT4
, WritingMode_LR_TB
,
147 AUTOLAYOUT_HANDOUT4
},
148 {BMP_FOILH_06
, BMP_FOILH_06_H
, STR_AUTOLAYOUT_HANDOUT6
, WritingMode_LR_TB
,
149 AUTOLAYOUT_HANDOUT6
},
150 {BMP_FOILH_09
, BMP_FOILH_09_H
, STR_AUTOLAYOUT_HANDOUT9
, WritingMode_LR_TB
,
151 AUTOLAYOUT_HANDOUT9
},
152 {0, 0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
155 static snewfoil_value_info standard
[] =
157 {BMP_LAYOUT_EMPTY
, BMP_LAYOUT_EMPTY_H
, STR_AUTOLAYOUT_NONE
, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
158 {BMP_LAYOUT_HEAD03
, BMP_LAYOUT_HEAD03_H
, STR_AUTOLAYOUT_TITLE
, WritingMode_LR_TB
, AUTOLAYOUT_TITLE
},
159 {BMP_LAYOUT_HEAD02
, BMP_LAYOUT_HEAD02_H
, STR_AUTOLAYOUT_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_ENUM
},
160 {BMP_LAYOUT_HEAD02A
, BMP_LAYOUT_HEAD02A_H
, STR_AUTOLAYOUT_2CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_2TEXT
},
161 {BMP_LAYOUT_HEAD01
, BMP_LAYOUT_HEAD01_H
, STR_AUTOLAYOUT_ONLY_TITLE
, WritingMode_LR_TB
, AUTOLAYOUT_ONLY_TITLE
},
162 {BMP_LAYOUT_TEXTONLY
, BMP_LAYOUT_TEXTONLY_H
, STR_AUTOLAYOUT_ONLY_TEXT
, WritingMode_LR_TB
, AUTOLAYOUT_ONLY_TEXT
},
163 {BMP_LAYOUT_HEAD03B
, BMP_LAYOUT_HEAD03B_H
, STR_AUTOLAYOUT_2CONTENT_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_2OBJTEXT
},
164 {BMP_LAYOUT_HEAD03C
, BMP_LAYOUT_HEAD03C_H
, STR_AUTOLAYOUT_CONTENT_2CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_TEXT2OBJ
},
165 {BMP_LAYOUT_HEAD03A
, BMP_LAYOUT_HEAD03A_H
, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT
,WritingMode_LR_TB
, AUTOLAYOUT_2OBJOVERTEXT
},
166 {BMP_LAYOUT_HEAD02B
, BMP_LAYOUT_HEAD02B_H
, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_OBJOVERTEXT
},
167 {BMP_LAYOUT_HEAD04
, BMP_LAYOUT_HEAD04_H
, STR_AUTOLAYOUT_4CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_4OBJ
},
168 {BMP_LAYOUT_HEAD06
, BMP_LAYOUT_HEAD06_H
, STR_AUTOLAYOUT_6CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_6CLIPART
},
171 {BMP_LAYOUT_VERTICAL02
, BMP_LAYOUT_VERTICAL02_H
, STR_AL_VERT_TITLE_TEXT_CHART
, WritingMode_TB_RL
,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
},
172 {BMP_LAYOUT_VERTICAL01
, BMP_LAYOUT_VERTICAL01_H
, STR_AL_VERT_TITLE_VERT_OUTLINE
, WritingMode_TB_RL
, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
},
173 {BMP_LAYOUT_HEAD02
, BMP_LAYOUT_HEAD02_H
, STR_AL_TITLE_VERT_OUTLINE
, WritingMode_TB_RL
, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
},
174 {BMP_LAYOUT_HEAD02A
, BMP_LAYOUT_HEAD02A_H
, STR_AL_TITLE_VERT_OUTLINE_CLIPART
, WritingMode_TB_RL
, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
},
175 {0, 0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
}
178 LayoutMenu::LayoutMenu( TreeNode
* pParent
, ToolPanelViewShell
& i_rPanelViewShell
)
179 : ValueSet (pParent
->GetWindow()),
181 DragSourceHelper(this),
182 DropTargetHelper(this),
183 mrBase( i_rPanelViewShell
.GetViewShellBase() ),
184 mpShellManager (&i_rPanelViewShell
.GetSubShellManager()),
185 mbUseOwnScrollBar( false ),
186 mnPreferredColumnCount(3),
188 mbSelectionUpdatePending(true),
189 mbIsMainViewChangePending(false)
191 implConstruct( *mrBase
.GetDocument()->GetDocSh() );
195 void LayoutMenu::implConstruct( DrawDocShell
& rDocumentShell
)
197 OSL_ENSURE( mrBase
.GetDocument()->GetDocSh() == &rDocumentShell
,
198 "LayoutMenu::implConstruct: hmm?" );
199 // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
202 ( GetStyle() & ~(WB_ITEMBORDER
) )
206 if (mbUseOwnScrollBar
)
207 SetStyle (GetStyle() | WB_VSCROLL
);
209 SetSelectHdl (LINK(this, LayoutMenu
, ClickHandler
));
210 SetPool (&rDocumentShell
.GetDoc()->GetPool());
211 SetName(String(RTL_CONSTASCII_USTRINGPARAM("LayoutMenu")));
214 Link
aEventListenerLink (LINK(this,LayoutMenu
,EventMultiplexerListener
));
215 mrBase
.GetEventMultiplexer()->AddEventListener(aEventListenerLink
,
216 ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
217 | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
218 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
219 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
220 | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
221 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
222 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
);
224 Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS
);
225 SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE
));
227 Link
aStateChangeLink (LINK(this,LayoutMenu
,StateChangeHandler
));
228 mxListener
= new ::sd::tools::SlotStateListener(
230 Reference
<frame::XDispatchProvider
>(mrBase
.GetController()->getFrame(), UNO_QUERY
),
231 ::rtl::OUString::createFromAscii(".uno:VerticalTextState"));
233 // Add this new object as shell to the shell factory.
234 GetShellManager()->AddSubShell(SHELLID_SD_TASK_PANE_PREVIEW_LAYOUTS
,this,this);
239 LayoutMenu::~LayoutMenu (void)
241 // Tell the shell factory that this object is no longer available.
242 if (GetShellManager() != NULL
)
243 GetShellManager()->RemoveSubShell(this);
245 Reference
<lang::XComponent
> xComponent (mxListener
, UNO_QUERY
);
247 xComponent
->dispose();
250 Link
aLink (LINK(this,LayoutMenu
,EventMultiplexerListener
));
251 mrBase
.GetEventMultiplexer()->RemoveEventListener (aLink
);
257 ::std::auto_ptr
<ControlFactory
> LayoutMenu::CreateControlFactory (
258 ToolPanelViewShell
& i_rPanelViewShell
)
260 return ::std::auto_ptr
<ControlFactory
>(new LayoutMenuRootFactory(i_rPanelViewShell
));
266 AutoLayout
LayoutMenu::GetSelectedAutoLayout (void)
268 AutoLayout aResult
= AUTOLAYOUT_NONE
;
270 if ( ! IsNoSelection() && GetSelectItemId()!=0)
272 AutoLayout
* pLayout
= static_cast<AutoLayout
*>(GetItemData(GetSelectItemId()));
283 /** The preferred size depends on the preferred number of columns, the
284 number of items, and the size of the items.
286 Size
LayoutMenu::GetPreferredSize (void)
288 Size aItemSize
= CalcItemSizePixel (Size());
289 Size aPreferredWindowSize
= CalcWindowSizePixel (
291 (sal_uInt16
)mnPreferredColumnCount
,
292 (sal_uInt16
)CalculateRowCount (aItemSize
,mnPreferredColumnCount
));
293 return aPreferredWindowSize
;
299 sal_Int32
LayoutMenu::GetPreferredWidth (sal_Int32 nHeight
)
301 sal_Int32 nPreferredWidth
= 100;
302 if (GetItemCount() > 0)
304 Image aImage
= GetItemImage(GetItemId(0));
305 Size aItemSize
= CalcItemSizePixel (aImage
.GetSizePixel());
306 if (nHeight
>0 && aItemSize
.Height()>0)
308 int nRowCount
= nHeight
/ aItemSize
.Height();
311 int nColumnCount
= (GetItemCount() + nRowCount
-1) / nRowCount
;
312 nPreferredWidth
= nColumnCount
* aItemSize
.Width();
316 return nPreferredWidth
;
322 sal_Int32
LayoutMenu::GetPreferredHeight (sal_Int32 nWidth
)
324 sal_Int32 nPreferredHeight
= 200;
325 if ( ! mbUseOwnScrollBar
&& GetItemCount()>0)
327 Image aImage
= GetItemImage(GetItemId(0));
328 Size aItemSize
= CalcItemSizePixel (aImage
.GetSizePixel());
329 if (nWidth
>0 && aItemSize
.Width()>0)
331 aItemSize
.Width() += 8;
332 aItemSize
.Height() += 8;
333 int nColumnCount
= nWidth
/ aItemSize
.Width();
334 if (nColumnCount
<= 0)
336 else if (nColumnCount
> 4)
338 int nRowCount
= (GetItemCount() + nColumnCount
-1) / nColumnCount
;
339 nPreferredHeight
= nRowCount
* aItemSize
.Height();
342 return nPreferredHeight
;
348 sal_Int32
LayoutMenu::GetMinimumWidth (void)
350 sal_Int32 nMinimumWidth
= 0;
351 if (GetItemCount()>0)
353 Image aImage
= GetItemImage(GetItemId(0));
354 Size aItemSize
= CalcItemSizePixel (aImage
.GetSizePixel());
355 nMinimumWidth
= aItemSize
.Width();
357 return nMinimumWidth
;
363 bool LayoutMenu::IsResizable (void)
371 void LayoutMenu::UpdateEnabledState (const MasterMode eMode
)
373 bool bIsEnabled (false);
375 ::boost::shared_ptr
<ViewShell
> pMainViewShell (mrBase
.GetMainViewShell());
378 switch (pMainViewShell
->GetShellType())
380 case ViewShell::ST_NONE
:
381 case ViewShell::ST_OUTLINE
:
382 case ViewShell::ST_PRESENTATION
:
383 case ViewShell::ST_TASK_PANE
:
384 // The complete task pane is disabled for these values or
385 // not even visible. Disabling the LayoutMenu would be
386 // logical but unnecessary. The main disadvantage is that
387 // after re-enabling it (typically) another panel is
392 case ViewShell::ST_DRAW
:
393 case ViewShell::ST_IMPRESS
:
399 ::boost::shared_ptr
<DrawViewShell
> pDrawViewShell (
400 ::boost::dynamic_pointer_cast
<DrawViewShell
>(pMainViewShell
));
402 bIsEnabled
= pDrawViewShell
->GetEditMode() != EM_MASTERPAGE
;
416 case ViewShell::ST_HANDOUT
:
417 case ViewShell::ST_NOTES
:
418 case ViewShell::ST_SLIDE_SORTER
:
424 TreeNode
* pParentNode
= GetParentNode();
425 if (pParentNode
!= NULL
)
427 TitledControl
* pGrandParentNode
428 = dynamic_cast<TitledControl
*>(pParentNode
->GetParentNode());
429 if (pGrandParentNode
!= NULL
)
430 pGrandParentNode
->SetEnabledState(bIsEnabled
);
439 ::Window
* LayoutMenu::GetWindow (void)
447 void LayoutMenu::Paint (const Rectangle
& rRect
)
449 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
451 if (mbSelectionUpdatePending
)
453 mbSelectionUpdatePending
= false;
456 ValueSet::Paint (rRect
);
458 SetBackground (Wallpaper());
464 void LayoutMenu::Resize (void)
466 Size aWindowSize
= GetOutputSizePixel();
467 if (IsVisible() && aWindowSize
.Width() > 0)
469 // Calculate the number of rows and columns.
470 if (GetItemCount() > 0)
472 Image aImage
= GetItemImage(GetItemId(0));
473 Size aItemSize
= CalcItemSizePixel (
474 aImage
.GetSizePixel());
475 aItemSize
.Width() += 8;
476 aItemSize
.Height() += 8;
477 int nColumnCount
= aWindowSize
.Width() / aItemSize
.Width();
478 if (nColumnCount
< 1)
480 else if (nColumnCount
> 4)
483 int nRowCount
= CalculateRowCount (aItemSize
, nColumnCount
);
485 SetColCount ((sal_uInt16
)nColumnCount
);
486 SetLineCount ((sal_uInt16
)nRowCount
);
496 void LayoutMenu::MouseButtonDown (const MouseEvent
& rEvent
)
498 // As a preparation for the context menu the item under the mouse is
500 if (rEvent
.IsRight())
503 sal_uInt16 nIndex
= GetItemId (rEvent
.GetPosPixel());
508 ValueSet::MouseButtonDown (rEvent
);
514 void LayoutMenu::Execute (SfxRequest
& rRequest
)
516 switch (rRequest
.GetSlot())
518 case SID_TP_APPLY_TO_SELECTED_SLIDES
:
519 AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
523 case SID_INSERTPAGE_LAYOUT_MENU
:
524 // Add arguments to this slot and forward it to the main view
526 InsertPageWithLayout(GetSelectedAutoLayout());
534 void LayoutMenu::GetState (SfxItemSet
& rItemSet
)
536 // Cut and paste is not supported. The SID_(CUT,COPY,PASTE) entries
537 // therefore must not show up in the context menu.
538 rItemSet
.DisableItem (SID_CUT
);
539 rItemSet
.DisableItem (SID_COPY
);
540 rItemSet
.DisableItem (SID_PASTE
);
542 // The SID_INSERTPAGE_LAYOUT_MENU slot depends on the SID_INSERTPAGE
543 // slot being supported elsewhere.
544 const SfxPoolItem
* pItem
= NULL
;
545 const SfxItemState
aState (
546 mrBase
.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE
, pItem
));
547 if (aState
== SFX_ITEM_DISABLED
)
548 rItemSet
.DisableItem(SID_INSERTPAGE_LAYOUT_MENU
);
554 void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout
)
556 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
557 if (pViewShell
== NULL
)
560 SfxViewFrame
* pViewFrame
= mrBase
.GetViewFrame();
561 if (pViewFrame
== NULL
)
564 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
565 if (pDispatcher
== NULL
)
568 // Call SID_INSERTPAGE with the right arguments. This is because
569 // the popup menu can not call this slot with arguments directly.
570 SfxRequest
aRequest (CreateRequest(SID_INSERTPAGE
, aLayout
));
571 if (aRequest
.GetArgs() != NULL
)
573 pDispatcher
->Execute(
575 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
576 *aRequest
.GetArgs());
584 TaskPaneShellManager
* LayoutMenu::GetShellManager()
586 if ( mpShellManager
)
587 return mpShellManager
;
588 return TreeNode::GetShellManager();
591 void LayoutMenu::InvalidateContent (void)
593 // The number of items may have changed. Request a resize so that the
594 // vertical size of this control can be adapted.
597 // Throw away the current set and fill the menu anew according to the
598 // current settings (this includes the support for vertical writing.)
605 int LayoutMenu::CalculateRowCount (const Size
&, int nColumnCount
)
609 if (GetItemCount() > 0 && nColumnCount
> 0)
611 nRowCount
= (GetItemCount() + nColumnCount
- 1) / nColumnCount
;
612 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
623 IMPL_LINK(LayoutMenu
, ClickHandler
, ValueSet
*, EMPTYARG
)
625 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
632 /** The specified layout is assigned to the current page of the view shell
635 void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout
)
637 using namespace ::sd::slidesorter
;
638 using namespace ::sd::slidesorter::controller
;
642 // The view shell in the center pane has to be present.
643 ViewShell
* pMainViewShell
= mrBase
.GetMainViewShell().get();
644 if (pMainViewShell
== NULL
)
647 // Determine if the current view is in an invalid master page mode.
648 // The handout view is always in master page mode and therefore not
650 bool bMasterPageMode (false);
651 switch (pMainViewShell
->GetShellType())
653 case ViewShell::ST_NOTES
:
654 case ViewShell::ST_IMPRESS
:
656 DrawViewShell
* pDrawViewShell
= static_cast<DrawViewShell
*>(pMainViewShell
);
657 if (pDrawViewShell
!= NULL
)
658 if (pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
659 bMasterPageMode
= true;
667 // Get a list of all selected slides and call the SID_MODIFYPAGE
668 // slot for all of them.
669 ::sd::slidesorter::SharedPageSelection pPageSelection
;
671 // Get a list of selected pages.
672 // First we try to obtain this list from a slide sorter. This is
673 // possible only some of the view shells in the center pane. When
674 // no valid slide sorter is available then ask the main view shell
675 // for its current page.
676 SlideSorterViewShell
* pSlideSorter
= NULL
;
677 switch (pMainViewShell
->GetShellType())
679 case ViewShell::ST_IMPRESS
:
680 case ViewShell::ST_NOTES
:
681 case ViewShell::ST_SLIDE_SORTER
:
682 pSlideSorter
= SlideSorterViewShell::GetSlideSorter(mrBase
);
687 if (pSlideSorter
!= NULL
)
689 // There is a slide sorter visible so get the list of selected pages from it.
690 pPageSelection
= pSlideSorter
->GetPageSelection();
693 if( (pSlideSorter
== NULL
) || (pPageSelection
.get() == 0) || pPageSelection
->empty() )
695 // No valid slide sorter available. Ask the main view shell for
697 pPageSelection
.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
698 pPageSelection
->push_back(pMainViewShell
->GetActualPage());
702 if (pPageSelection
->empty())
705 ::std::vector
<SdPage
*>::iterator iPage
;
706 for (iPage
=pPageSelection
->begin(); iPage
!=pPageSelection
->end(); ++iPage
)
708 if ((*iPage
) == NULL
)
711 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
712 SfxRequest
aRequest (mrBase
.GetViewFrame(), SID_ASSIGN_LAYOUT
);
713 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE
, ((*iPage
)->GetPageNum()-1)/2));
714 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, aLayout
));
715 pMainViewShell
->ExecuteSlot (aRequest
, sal_Bool(sal_False
));
724 SfxRequest
LayoutMenu::CreateRequest (
728 SfxRequest
aRequest (mrBase
.GetViewFrame(), nSlotId
);
732 SdrLayerAdmin
& rLayerAdmin (mrBase
.GetDocument()->GetLayerAdmin());
733 sal_uInt8
aBackground (rLayerAdmin
.GetLayerID(
734 String(SdResId(STR_LAYER_BCKGRND
)), sal_False
));
735 sal_uInt8
aBackgroundObject (rLayerAdmin
.GetLayerID(
736 String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
));
737 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
738 if (pViewShell
== NULL
)
740 SdPage
* pPage
= pViewShell
->GetActualPage();
744 SetOfByte
aVisibleLayers (pPage
->TRG_GetMasterPageVisibleLayers());
747 SfxStringItem (ID_VAL_PAGENAME
, String()));//pPage->GetName()));
748 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, aLayout
));
750 SfxBoolItem(ID_VAL_ISPAGEBACK
, aVisibleLayers
.IsSet(aBackground
)));
754 aVisibleLayers
.IsSet(aBackgroundObject
)));
764 void LayoutMenu::Fill (void)
766 const bool bHighContrast
= GetSettings().GetStyleSettings().GetHighContrastMode();
767 SvtLanguageOptions aLanguageOptions
;
768 sal_Bool bVertical
= aLanguageOptions
.IsVerticalTextEnabled();
769 SdDrawDocument
* pDocument
= mrBase
.GetDocument();
770 sal_Bool bRightToLeft
= (pDocument
!=NULL
771 && pDocument
->GetDefaultWritingMode() == WritingMode_RL_TB
);
773 // Get URL of the view in the center pane.
774 ::rtl::OUString sCenterPaneViewName
;
777 Reference
<XControllerManager
> xControllerManager (
778 Reference
<XWeak
>(&mrBase
.GetDrawController()), UNO_QUERY_THROW
);
779 Reference
<XResourceId
> xPaneId (ResourceId::create(
780 ::comphelper::getProcessComponentContext(),
781 FrameworkHelper::msCenterPaneURL
));
782 Reference
<XView
> xView (FrameworkHelper::Instance(mrBase
)->GetView(xPaneId
));
784 sCenterPaneViewName
= xView
->getResourceId()->getResourceURL();
786 catch (RuntimeException
&)
789 snewfoil_value_info
* pInfo
= NULL
;
790 if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msNotesViewURL
))
794 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msHandoutViewURL
))
798 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msImpressViewURL
)
799 || sCenterPaneViewName
.equals(framework::FrameworkHelper::msSlideSorterURL
))
810 for (sal_uInt16 i
=1; pInfo
!=NULL
&&pInfo
->mnBmpResId
!=0; i
++,pInfo
++)
812 if ((WritingMode_TB_RL
!= pInfo
->meWritingMode
) || bVertical
)
814 BitmapEx
aBmp (SdResId (bHighContrast
815 ? pInfo
->mnHCBmpResId
816 : pInfo
->mnBmpResId
));
818 if (bRightToLeft
&& (WritingMode_TB_RL
!= pInfo
->meWritingMode
))
819 aBmp
.Mirror (BMP_MIRROR_HORZ
);
821 InsertItem (i
, aBmp
, String (SdResId (pInfo
->mnStrResId
)));
822 SetItemData (i
, new AutoLayout(pInfo
->maAutoLayout
));
827 mbSelectionUpdatePending
= true;
833 void LayoutMenu::Clear (void)
835 for (sal_uInt16 nId
=1; nId
<=GetItemCount(); nId
++)
836 delete static_cast<AutoLayout
*>(GetItemData(nId
));
842 void LayoutMenu::StartDrag (sal_Int8
, const Point
& )
849 sal_Int8
LayoutMenu::AcceptDrop (const AcceptDropEvent
& )
857 sal_Int8
LayoutMenu::ExecuteDrop (const ExecuteDropEvent
& )
865 void LayoutMenu::Command (const CommandEvent
& rEvent
)
867 switch (rEvent
.GetCommand())
869 case COMMAND_CONTEXTMENU
:
870 if ( ! SD_MOD()->GetWaterCan())
872 if (GetShellManager() != NULL
)
873 GetShellManager()->MoveToTop(this);
874 if (rEvent
.IsMouseEvent())
876 // Do not show the context menu when the mouse was not
877 // pressed over an item.
878 if (GetItemId(rEvent
.GetMousePosPixel()) > 0)
879 mrBase
.GetViewFrame()->GetDispatcher()->ExecutePopup(
880 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP
));
884 // When the command event was not caused by a mouse
885 // event (for example a key press instead) then show the
886 // popup menu at the center of the current item.
887 if (GetSelectItemId() != (sal_uInt16
)-1)
889 Rectangle
aBBox (GetItemRect(GetSelectItemId()));
890 Point
aPosition (aBBox
.Center());
891 mrBase
.GetViewFrame()->GetDispatcher()->ExecutePopup(
892 SdResId(RID_TASKPANE_LAYOUTMENU_POPUP
),
901 ValueSet::Command(rEvent
);
909 IMPL_LINK(LayoutMenu
, StateChangeHandler
, ::rtl::OUString
*, EMPTYARG
)
918 void LayoutMenu::UpdateSelection (void)
920 bool bItemSelected
= false;
924 // Get current page of main view.
925 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
926 if (pViewShell
== NULL
)
929 SdPage
* pCurrentPage
= pViewShell
->getCurrentPage();
930 if (pCurrentPage
== NULL
)
933 // Get layout of current page.
934 AutoLayout
aLayout (pCurrentPage
->GetAutoLayout());
935 if (aLayout
<AUTOLAYOUT__START
|| aLayout
>AUTOLAYOUT__END
)
938 // Find the entry of the menu for to the layout.
939 sal_uInt16
nItemCount (GetItemCount());
940 for (sal_uInt16 nId
=1; nId
<=nItemCount
; nId
++)
942 if (*static_cast<AutoLayout
*>(GetItemData(nId
)) == aLayout
)
945 bItemSelected
= true;
952 if ( ! bItemSelected
)
959 IMPL_LINK(LayoutMenu
, EventMultiplexerListener
, ::sd::tools::EventMultiplexerEvent
*, pEvent
)
961 switch (pEvent
->meEventId
)
963 case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
:
964 case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
:
965 if ( ! mbSelectionUpdatePending
)
969 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
:
970 mbIsMainViewChangePending
= true;
971 UpdateEnabledState(MM_UNKNOWN
);
974 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
:
978 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
:
979 if (mbIsMainViewChangePending
)
981 mbIsMainViewChangePending
= false;
986 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
:
987 UpdateEnabledState(MM_NORMAL
);
990 case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
:
991 UpdateEnabledState(MM_MASTER
);
1005 void LayoutMenu::DataChanged (const DataChangedEvent
& rEvent
)
1008 ValueSet::DataChanged(rEvent
);
1012 } } // end of namespace ::sd::toolpanel