1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "LayoutMenu.hxx"
23 #include "drawdoc.hxx"
24 #include "framework/FrameworkHelper.hxx"
29 #include "res_bmp.hrc"
31 #include "sdresid.hxx"
32 #include "strings.hrc"
33 #include "tools/SlotStateListener.hxx"
34 #include "DrawController.hxx"
35 #include "DrawDocShell.hxx"
36 #include "DrawViewShell.hxx"
37 #include "EventMultiplexer.hxx"
38 #include "SlideSorterViewShell.hxx"
39 #include "ViewShellBase.hxx"
40 #include <sfx2/sidebar/Theme.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <sfx2/app.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/objface.hxx>
46 #include <sfx2/request.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <svl/languageoptions.hxx>
49 #include <vcl/image.hxx>
50 #include <vcl/floatwin.hxx>
52 #include <com/sun/star/frame/XController.hpp>
53 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
54 #include <com/sun/star/drawing/framework/XView.hpp>
55 #include <com/sun/star/drawing/framework/ResourceId.hpp>
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::text
;
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::drawing::framework
;
63 using namespace ::sd::slidesorter
;
64 using ::sd::framework::FrameworkHelper
;
66 namespace sd
{ namespace sidebar
{
68 struct snewfoil_value_info
70 sal_uInt16 mnBmpResId
;
71 sal_uInt16 mnStrResId
;
72 WritingMode meWritingMode
;
73 AutoLayout maAutoLayout
;
76 static const snewfoil_value_info notes
[] =
78 {BMP_FOILN_01
, STR_AUTOLAYOUT_NOTES
, WritingMode_LR_TB
,
80 {0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
83 static const snewfoil_value_info handout
[] =
85 {BMP_FOILH_01
, STR_AUTOLAYOUT_HANDOUT1
, WritingMode_LR_TB
,
87 {BMP_FOILH_02
, STR_AUTOLAYOUT_HANDOUT2
, WritingMode_LR_TB
,
89 {BMP_FOILH_03
, STR_AUTOLAYOUT_HANDOUT3
, WritingMode_LR_TB
,
91 {BMP_FOILH_04
, STR_AUTOLAYOUT_HANDOUT4
, WritingMode_LR_TB
,
93 {BMP_FOILH_06
, STR_AUTOLAYOUT_HANDOUT6
, WritingMode_LR_TB
,
95 {BMP_FOILH_09
, STR_AUTOLAYOUT_HANDOUT9
, WritingMode_LR_TB
,
97 {0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
100 static const snewfoil_value_info standard
[] =
102 {BMP_LAYOUT_EMPTY
, STR_AUTOLAYOUT_NONE
, WritingMode_LR_TB
, AUTOLAYOUT_NONE
},
103 {BMP_LAYOUT_HEAD03
, STR_AUTOLAYOUT_TITLE
, WritingMode_LR_TB
, AUTOLAYOUT_TITLE
},
104 {BMP_LAYOUT_HEAD02
, STR_AUTOLAYOUT_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_ENUM
},
105 {BMP_LAYOUT_HEAD02A
, STR_AUTOLAYOUT_2CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_2TEXT
},
106 {BMP_LAYOUT_HEAD01
, STR_AUTOLAYOUT_ONLY_TITLE
, WritingMode_LR_TB
, AUTOLAYOUT_ONLY_TITLE
},
107 {BMP_LAYOUT_TEXTONLY
, STR_AUTOLAYOUT_ONLY_TEXT
, WritingMode_LR_TB
, AUTOLAYOUT_ONLY_TEXT
},
108 {BMP_LAYOUT_HEAD03B
, STR_AUTOLAYOUT_2CONTENT_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_2OBJTEXT
},
109 {BMP_LAYOUT_HEAD03C
, STR_AUTOLAYOUT_CONTENT_2CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_TEXT2OBJ
},
110 {BMP_LAYOUT_HEAD03A
, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT
,WritingMode_LR_TB
, AUTOLAYOUT_2OBJOVERTEXT
},
111 {BMP_LAYOUT_HEAD02B
, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_OBJOVERTEXT
},
112 {BMP_LAYOUT_HEAD04
, STR_AUTOLAYOUT_4CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_4OBJ
},
113 {BMP_LAYOUT_HEAD06
, STR_AUTOLAYOUT_6CONTENT
, WritingMode_LR_TB
, AUTOLAYOUT_6CLIPART
},
116 {BMP_LAYOUT_VERTICAL02
, STR_AL_VERT_TITLE_TEXT_CHART
, WritingMode_TB_RL
,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
},
117 {BMP_LAYOUT_VERTICAL01
, STR_AL_VERT_TITLE_VERT_OUTLINE
, WritingMode_TB_RL
, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
},
118 {BMP_LAYOUT_HEAD02
, STR_AL_TITLE_VERT_OUTLINE
, WritingMode_TB_RL
, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
},
119 {BMP_LAYOUT_HEAD02A
, STR_AL_TITLE_VERT_OUTLINE_CLIPART
, WritingMode_TB_RL
, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
},
120 {0, 0, WritingMode_LR_TB
, AUTOLAYOUT_NONE
}
123 LayoutMenu::LayoutMenu (
124 vcl::Window
* pParent
,
125 ViewShellBase
& rViewShellBase
,
126 const css::uno::Reference
<css::ui::XSidebar
>& rxSidebar
)
127 : ValueSet (pParent
, WB_ITEMBORDER
),
128 DragSourceHelper(this),
129 DropTargetHelper(this),
130 mrBase(rViewShellBase
),
131 mbUseOwnScrollBar(false),
132 mnPreferredColumnCount(3),
134 mbSelectionUpdatePending(true),
135 mbIsMainViewChangePending(false),
136 mxSidebar(rxSidebar
),
139 implConstruct( *mrBase
.GetDocument()->GetDocSh() );
140 SAL_INFO("sd.ui", "created LayoutMenu at " << this);
142 SetStyle(GetStyle() | WB_ITEMBORDER
| WB_FLATVALUESET
| WB_TABSTOP
);
144 SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground
));
145 SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground
));
148 SetText(OUString("sd:LayoutMenu"));
152 void LayoutMenu::implConstruct( DrawDocShell
& rDocumentShell
)
154 OSL_ENSURE( mrBase
.GetDocument()->GetDocSh() == &rDocumentShell
,
155 "LayoutMenu::implConstruct: hmm?" );
156 // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
157 (void) rDocumentShell
;
160 ( GetStyle() & ~(WB_ITEMBORDER
) )
162 | WB_MENUSTYLEVALUESET
165 if (mbUseOwnScrollBar
)
166 SetStyle (GetStyle() | WB_VSCROLL
);
168 SetSelectHdl (LINK(this, LayoutMenu
, ClickHandler
));
171 Link
<> aEventListenerLink (LINK(this,LayoutMenu
,EventMultiplexerListener
));
172 mrBase
.GetEventMultiplexer()->AddEventListener(aEventListenerLink
,
173 ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
174 | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
175 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
176 | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
177 | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
178 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
179 | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
);
181 Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS
);
182 SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE
));
184 Link
<> aStateChangeLink (LINK(this,LayoutMenu
,StateChangeHandler
));
185 mxListener
= new ::sd::tools::SlotStateListener(
187 Reference
<frame::XDispatchProvider
>(mrBase
.GetController()->getFrame(), UNO_QUERY
),
188 ".uno:VerticalTextState");
190 SetSizePixel(GetParent()->GetSizePixel());
191 Link
<> aWindowEventHandlerLink (LINK(this,LayoutMenu
,WindowEventHandler
));
192 GetParent()->AddEventListener(aWindowEventHandlerLink
);
195 LayoutMenu::~LayoutMenu()
200 void LayoutMenu::dispose()
202 SAL_INFO("sd.ui", "destroying LayoutMenu at " << this);
207 void LayoutMenu::Dispose()
212 SAL_INFO("sd.ui", "disposing LayoutMenu at " << this);
216 Reference
<lang::XComponent
> xComponent (mxListener
, UNO_QUERY
);
218 xComponent
->dispose();
221 Link
<> aLink (LINK(this,LayoutMenu
,EventMultiplexerListener
));
222 mrBase
.GetEventMultiplexer()->RemoveEventListener (aLink
);
224 Link
<> aWindowEventHandlerLink (LINK(this,LayoutMenu
,WindowEventHandler
));
225 GetParent()->RemoveEventListener(aWindowEventHandlerLink
);
228 AutoLayout
LayoutMenu::GetSelectedAutoLayout()
230 AutoLayout aResult
= AUTOLAYOUT_NONE
;
232 if ( ! IsNoSelection() && GetSelectItemId()!=0)
234 AutoLayout
* pLayout
= static_cast<AutoLayout
*>(GetItemData(GetSelectItemId()));
242 ui::LayoutSize
LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth
)
244 sal_Int32 nPreferredHeight
= 200;
245 if ( ! mbUseOwnScrollBar
&& GetItemCount()>0)
247 Image aImage
= GetItemImage(GetItemId(0));
248 Size aItemSize
= CalcItemSizePixel (aImage
.GetSizePixel());
249 if (nWidth
>0 && aItemSize
.Width()>0)
251 aItemSize
.Width() += 8;
252 aItemSize
.Height() += 8;
253 int nColumnCount
= nWidth
/ aItemSize
.Width();
254 if (nColumnCount
<= 0)
256 else if (nColumnCount
> 4)
258 int nRowCount
= (GetItemCount() + nColumnCount
-1) / nColumnCount
;
259 nPreferredHeight
= nRowCount
* aItemSize
.Height();
262 return ui::LayoutSize(nPreferredHeight
,nPreferredHeight
,nPreferredHeight
);
265 void LayoutMenu::Paint (vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
267 if (mbSelectionUpdatePending
)
269 mbSelectionUpdatePending
= false;
272 ValueSet::Paint(rRenderContext
, rRect
);
275 void LayoutMenu::Resize()
277 Size aWindowSize
= GetOutputSizePixel();
278 if (IsVisible() && aWindowSize
.Width() > 0)
280 // Calculate the number of rows and columns.
281 if (GetItemCount() > 0)
283 Image aImage
= GetItemImage(GetItemId(0));
284 Size aItemSize
= CalcItemSizePixel (
285 aImage
.GetSizePixel());
286 aItemSize
.Width() += 8;
287 aItemSize
.Height() += 8;
288 int nColumnCount
= aWindowSize
.Width() / aItemSize
.Width();
289 if (nColumnCount
< 1)
291 else if (nColumnCount
> 4)
294 int nRowCount
= CalculateRowCount (aItemSize
, nColumnCount
);
296 SetColCount ((sal_uInt16
)nColumnCount
);
297 SetLineCount ((sal_uInt16
)nRowCount
);
304 void LayoutMenu::MouseButtonDown (const MouseEvent
& rEvent
)
306 // As a preparation for the context menu the item under the mouse is
308 if (rEvent
.IsRight())
311 sal_uInt16 nIndex
= GetItemId (rEvent
.GetPosPixel());
316 ValueSet::MouseButtonDown (rEvent
);
319 void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout
)
321 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
322 if (pViewShell
== NULL
)
325 SfxViewFrame
* pViewFrame
= mrBase
.GetViewFrame();
326 if (pViewFrame
== NULL
)
329 SfxDispatcher
* pDispatcher
= pViewFrame
->GetDispatcher();
330 if (pDispatcher
== NULL
)
333 // Call SID_INSERTPAGE with the right arguments. This is because
334 // the popup menu can not call this slot with arguments directly.
335 SfxRequest
aRequest (CreateRequest(SID_INSERTPAGE
, aLayout
));
336 if (aRequest
.GetArgs() != NULL
)
338 pDispatcher
->Execute(
340 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
341 *aRequest
.GetArgs());
346 void LayoutMenu::InvalidateContent()
348 // Throw away the current set and fill the menu anew according to the
349 // current settings (this includes the support for vertical writing.)
353 mxSidebar
->requestLayout();
356 int LayoutMenu::CalculateRowCount (const Size
&, int nColumnCount
)
360 if (GetItemCount() > 0 && nColumnCount
> 0)
362 nRowCount
= (GetItemCount() + nColumnCount
- 1) / nColumnCount
;
363 // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
371 IMPL_LINK_NOARG(LayoutMenu
, ClickHandler
)
373 AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
377 /** The specified layout is assigned to the current page of the view shell
380 void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout
)
382 using namespace ::sd::slidesorter
;
383 using namespace ::sd::slidesorter::controller
;
387 // The view shell in the center pane has to be present.
388 ViewShell
* pMainViewShell
= mrBase
.GetMainViewShell().get();
389 if (pMainViewShell
== NULL
)
392 // Determine if the current view is in an invalid master page mode.
393 // The handout view is always in master page mode and therefore not
395 bool bMasterPageMode (false);
396 switch (pMainViewShell
->GetShellType())
398 case ViewShell::ST_NOTES
:
399 case ViewShell::ST_IMPRESS
:
401 DrawViewShell
* pDrawViewShell
= static_cast<DrawViewShell
*>(pMainViewShell
);
402 if (pDrawViewShell
!= NULL
)
403 if (pDrawViewShell
->GetEditMode() == EM_MASTERPAGE
)
404 bMasterPageMode
= true;
412 // Get a list of all selected slides and call the SID_MODIFYPAGE
413 // slot for all of them.
414 ::sd::slidesorter::SharedPageSelection pPageSelection
;
416 // Get a list of selected pages.
417 // First we try to obtain this list from a slide sorter. This is
418 // possible only some of the view shells in the center pane. When
419 // no valid slide sorter is available then ask the main view shell
420 // for its current page.
421 SlideSorterViewShell
* pSlideSorter
= NULL
;
422 switch (pMainViewShell
->GetShellType())
424 case ViewShell::ST_IMPRESS
:
425 case ViewShell::ST_NOTES
:
426 case ViewShell::ST_SLIDE_SORTER
:
427 pSlideSorter
= SlideSorterViewShell::GetSlideSorter(mrBase
);
432 if (pSlideSorter
!= NULL
)
434 // There is a slide sorter visible so get the list of selected pages from it.
435 pPageSelection
= pSlideSorter
->GetPageSelection();
438 if( (pSlideSorter
== NULL
) || (pPageSelection
.get() == 0) || pPageSelection
->empty() )
440 // No valid slide sorter available. Ask the main view shell for
442 pPageSelection
.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
443 pPageSelection
->push_back(pMainViewShell
->GetActualPage());
446 if (pPageSelection
->empty())
449 ::std::vector
<SdPage
*>::iterator iPage
;
450 for (iPage
=pPageSelection
->begin(); iPage
!=pPageSelection
->end(); ++iPage
)
452 if ((*iPage
) == NULL
)
455 // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
456 SfxRequest
aRequest (mrBase
.GetViewFrame(), SID_ASSIGN_LAYOUT
);
457 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE
, ((*iPage
)->GetPageNum()-1)/2));
458 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, aLayout
));
459 pMainViewShell
->ExecuteSlot (aRequest
, false);
465 SfxRequest
LayoutMenu::CreateRequest (
469 SfxRequest
aRequest (mrBase
.GetViewFrame(), nSlotId
);
473 SdrLayerAdmin
& rLayerAdmin (mrBase
.GetDocument()->GetLayerAdmin());
474 sal_uInt8
aBackground (rLayerAdmin
.GetLayerID(
475 SD_RESSTR(STR_LAYER_BCKGRND
), false));
476 sal_uInt8
aBackgroundObject (rLayerAdmin
.GetLayerID(
477 SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false));
478 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
479 if (pViewShell
== NULL
)
481 SdPage
* pPage
= pViewShell
->GetActualPage();
485 SetOfByte
aVisibleLayers (pPage
->TRG_GetMasterPageVisibleLayers());
488 SfxStringItem (ID_VAL_PAGENAME
, OUString()));//pPage->GetName()));
489 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, aLayout
));
491 SfxBoolItem(ID_VAL_ISPAGEBACK
, aVisibleLayers
.IsSet(aBackground
)));
495 aVisibleLayers
.IsSet(aBackgroundObject
)));
502 void LayoutMenu::Fill()
504 SvtLanguageOptions aLanguageOptions
;
505 bool bVertical
= aLanguageOptions
.IsVerticalTextEnabled();
506 SdDrawDocument
* pDocument
= mrBase
.GetDocument();
507 bool bRightToLeft
= (pDocument
!=NULL
508 && pDocument
->GetDefaultWritingMode() == WritingMode_RL_TB
);
510 // Get URL of the view in the center pane.
511 OUString sCenterPaneViewName
;
514 Reference
<XControllerManager
> xControllerManager (
515 Reference
<XWeak
>(&mrBase
.GetDrawController()), UNO_QUERY_THROW
);
516 Reference
<XResourceId
> xPaneId (ResourceId::create(
517 ::comphelper::getProcessComponentContext(),
518 FrameworkHelper::msCenterPaneURL
));
519 Reference
<XView
> xView (FrameworkHelper::Instance(mrBase
)->GetView(xPaneId
));
521 sCenterPaneViewName
= xView
->getResourceId()->getResourceURL();
523 catch (RuntimeException
&)
526 const snewfoil_value_info
* pInfo
= NULL
;
527 if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msNotesViewURL
))
531 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msHandoutViewURL
))
535 else if (sCenterPaneViewName
.equals(framework::FrameworkHelper::msImpressViewURL
)
536 || sCenterPaneViewName
.equals(framework::FrameworkHelper::msSlideSorterURL
))
547 for (sal_uInt16 i
=1; pInfo
!=NULL
&&pInfo
->mnBmpResId
!=0; i
++,pInfo
++)
549 if ((WritingMode_TB_RL
!= pInfo
->meWritingMode
) || bVertical
)
551 BitmapEx
aBmp(SdResId(pInfo
->mnBmpResId
));
553 if (GetDPIScaleFactor() > 1)
554 aBmp
.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BmpScaleFlag::Fast
);
556 if (bRightToLeft
&& (WritingMode_TB_RL
!= pInfo
->meWritingMode
))
557 aBmp
.Mirror (BmpMirrorFlags::Horizontal
);
559 InsertItem(i
, Image(aBmp
), SdResId (pInfo
->mnStrResId
));
560 SetItemData (i
, new AutoLayout(pInfo
->maAutoLayout
));
565 mbSelectionUpdatePending
= true;
568 void LayoutMenu::Clear()
570 for (sal_uInt16 nId
=1; nId
<=GetItemCount(); nId
++)
571 delete static_cast<AutoLayout
*>(GetItemData(nId
));
575 void LayoutMenu::StartDrag (sal_Int8
, const Point
& )
579 sal_Int8
LayoutMenu::AcceptDrop (const AcceptDropEvent
& )
584 sal_Int8
LayoutMenu::ExecuteDrop (const ExecuteDropEvent
& )
589 void LayoutMenu::Command (const CommandEvent
& rEvent
)
591 switch (rEvent
.GetCommand())
593 case CommandEventId::ContextMenu
:
594 if ( ! SD_MOD()->GetWaterCan())
596 // Determine the position where to show the menu.
598 if (rEvent
.IsMouseEvent())
600 if (GetItemId(rEvent
.GetMousePosPixel()) <= 0)
602 aMenuPosition
= rEvent
.GetMousePosPixel();
606 if (GetSelectItemId() == (sal_uInt16
)-1)
608 Rectangle
aBBox (GetItemRect(GetSelectItemId()));
609 aMenuPosition
= aBBox
.Center();
613 ::boost::shared_ptr
<PopupMenu
> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP
)));
614 FloatingWindow
* pMenuWindow
= dynamic_cast<FloatingWindow
*>(pMenu
->GetWindow());
615 if (pMenuWindow
!= NULL
)
616 pMenuWindow
->SetPopupModeFlags(
617 pMenuWindow
->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose
);
618 pMenu
->SetSelectHdl(LINK(this, LayoutMenu
, OnMenuItemSelected
));
620 // Disable the SID_INSERTPAGE_LAYOUT_MENU item when
621 // the document is read-only.
622 const SfxPoolItem
* pItem
= NULL
;
623 const SfxItemState
aState (
624 mrBase
.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE
, pItem
));
625 if (aState
== SfxItemState::DISABLED
)
626 pMenu
->EnableItem(SID_INSERTPAGE_LAYOUT_MENU
, false);
629 pMenu
->Execute(this, Rectangle(aMenuPosition
,Size(1,1)), PopupMenuFlags::ExecuteDown
);
634 ValueSet::Command(rEvent
);
639 IMPL_LINK_NOARG(LayoutMenu
, StateChangeHandler
)
645 IMPL_LINK(LayoutMenu
, OnMenuItemSelected
, Menu
*, pMenu
)
649 OSL_ENSURE(pMenu
!=NULL
, "LayoutMenu::OnMenuItemSelected: illegal menu!");
654 const sal_Int32
nIndex (pMenu
->GetCurItemId());
656 if (nIndex
== SID_TP_APPLY_TO_SELECTED_SLIDES
)
658 AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
660 else if (nIndex
== SID_INSERTPAGE_LAYOUT_MENU
)
662 // Add arguments to this slot and forward it to the main view
664 InsertPageWithLayout(GetSelectedAutoLayout());
670 void LayoutMenu::UpdateSelection()
672 bool bItemSelected
= false;
676 // Get current page of main view.
677 ViewShell
* pViewShell
= mrBase
.GetMainViewShell().get();
678 if (pViewShell
== NULL
)
681 SdPage
* pCurrentPage
= pViewShell
->getCurrentPage();
682 if (pCurrentPage
== NULL
)
685 // Get layout of current page.
686 AutoLayout
aLayout (pCurrentPage
->GetAutoLayout());
687 if (aLayout
<AUTOLAYOUT__START
|| aLayout
>AUTOLAYOUT__END
)
690 // Find the entry of the menu for to the layout.
692 sal_uInt16
nItemCount (GetItemCount());
693 for (sal_uInt16 nId
=1; nId
<=nItemCount
; nId
++)
695 if (*static_cast<AutoLayout
*>(GetItemData(nId
)) == aLayout
)
698 bItemSelected
= true;
705 if ( ! bItemSelected
)
709 IMPL_LINK(LayoutMenu
, EventMultiplexerListener
, ::sd::tools::EventMultiplexerEvent
*, pEvent
)
711 switch (pEvent
->meEventId
)
713 case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
:
714 case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
:
715 if ( ! mbSelectionUpdatePending
)
719 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
:
720 mbIsMainViewChangePending
= true;
723 case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
:
727 case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
:
728 if (mbIsMainViewChangePending
)
730 mbIsMainViewChangePending
= false;
743 IMPL_LINK(LayoutMenu
, WindowEventHandler
, VclWindowEvent
*, pEvent
)
747 switch (pEvent
->GetId())
749 case VCLEVENT_WINDOW_SHOW
:
750 case VCLEVENT_WINDOW_RESIZE
:
751 SetSizePixel(GetParent()->GetSizePixel());
752 return sal_IntPtr(true);
755 return sal_IntPtr(false);
759 return sal_IntPtr(false);
762 void LayoutMenu::DataChanged (const DataChangedEvent
& rEvent
)
765 ValueSet::DataChanged(rEvent
);
766 SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground
));
767 SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground
));
770 } } // end of namespace ::sd::sidebar
772 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */