xref: /AOO41X/main/sd/source/ui/sidebar/LayoutMenu.cxx (revision 02c50d825b93d3e4e3bd9073db30bd7615e748eb)
1*02c50d82SAndre Fischer /**************************************************************
2*02c50d82SAndre Fischer  *
3*02c50d82SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4*02c50d82SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5*02c50d82SAndre Fischer  * distributed with this work for additional information
6*02c50d82SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7*02c50d82SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8*02c50d82SAndre Fischer  * "License"); you may not use this file except in compliance
9*02c50d82SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*02c50d82SAndre Fischer  *
11*02c50d82SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*02c50d82SAndre Fischer  *
13*02c50d82SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14*02c50d82SAndre Fischer  * software distributed under the License is distributed on an
15*02c50d82SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*02c50d82SAndre Fischer  * KIND, either express or implied.  See the License for the
17*02c50d82SAndre Fischer  * specific language governing permissions and limitations
18*02c50d82SAndre Fischer  * under the License.
19*02c50d82SAndre Fischer  *
20*02c50d82SAndre Fischer  *************************************************************/
21*02c50d82SAndre Fischer 
22*02c50d82SAndre Fischer #include "precompiled_sd.hxx"
23*02c50d82SAndre Fischer 
24*02c50d82SAndre Fischer #include "LayoutMenu.hxx"
25*02c50d82SAndre Fischer 
26*02c50d82SAndre Fischer #include "SidebarShellManager.hxx"
27*02c50d82SAndre Fischer #include "app.hrc"
28*02c50d82SAndre Fischer #include "drawdoc.hxx"
29*02c50d82SAndre Fischer #include "framework/FrameworkHelper.hxx"
30*02c50d82SAndre Fischer #include "glob.hrc"
31*02c50d82SAndre Fischer #include "glob.hxx"
32*02c50d82SAndre Fischer #include "helpids.h"
33*02c50d82SAndre Fischer #include "pres.hxx"
34*02c50d82SAndre Fischer #include "res_bmp.hrc"
35*02c50d82SAndre Fischer #include "sdpage.hxx"
36*02c50d82SAndre Fischer #include "sdresid.hxx"
37*02c50d82SAndre Fischer #include "strings.hrc"
38*02c50d82SAndre Fischer #include "tools/SlotStateListener.hxx"
39*02c50d82SAndre Fischer #include "DrawController.hxx"
40*02c50d82SAndre Fischer #include "DrawDocShell.hxx"
41*02c50d82SAndre Fischer #include "DrawViewShell.hxx"
42*02c50d82SAndre Fischer #include "EventMultiplexer.hxx"
43*02c50d82SAndre Fischer #include "SlideSorterViewShell.hxx"
44*02c50d82SAndre Fischer #include "ViewShellBase.hxx"
45*02c50d82SAndre Fischer 
46*02c50d82SAndre Fischer #include <comphelper/processfactory.hxx>
47*02c50d82SAndre Fischer #include <sfx2/app.hxx>
48*02c50d82SAndre Fischer #include <sfx2/dispatch.hxx>
49*02c50d82SAndre Fischer #include <sfx2/objface.hxx>
50*02c50d82SAndre Fischer #include <sfx2/request.hxx>
51*02c50d82SAndre Fischer #include <sfx2/viewfrm.hxx>
52*02c50d82SAndre Fischer #include <svl/languageoptions.hxx>
53*02c50d82SAndre Fischer #include <vcl/image.hxx>
54*02c50d82SAndre Fischer #include <vcl/floatwin.hxx>
55*02c50d82SAndre Fischer 
56*02c50d82SAndre Fischer #include <com/sun/star/frame/XController.hpp>
57*02c50d82SAndre Fischer #include <com/sun/star/drawing/framework/XControllerManager.hpp>
58*02c50d82SAndre Fischer #include <com/sun/star/drawing/framework/XView.hpp>
59*02c50d82SAndre Fischer #include <com/sun/star/drawing/framework/ResourceId.hpp>
60*02c50d82SAndre Fischer 
61*02c50d82SAndre Fischer #include <vector>
62*02c50d82SAndre Fischer #include <memory>
63*02c50d82SAndre Fischer 
64*02c50d82SAndre Fischer using namespace ::com::sun::star;
65*02c50d82SAndre Fischer using namespace ::com::sun::star::text;
66*02c50d82SAndre Fischer using namespace ::com::sun::star::uno;
67*02c50d82SAndre Fischer using namespace ::com::sun::star::drawing::framework;
68*02c50d82SAndre Fischer using namespace ::sd::slidesorter;
69*02c50d82SAndre Fischer using ::sd::framework::FrameworkHelper;
70*02c50d82SAndre Fischer 
71*02c50d82SAndre Fischer namespace sd { namespace sidebar {
72*02c50d82SAndre Fischer 
73*02c50d82SAndre Fischer 
74*02c50d82SAndre Fischer 
75*02c50d82SAndre Fischer struct snewfoil_value_info
76*02c50d82SAndre Fischer {
77*02c50d82SAndre Fischer     sal_uInt16 mnBmpResId;
78*02c50d82SAndre Fischer     sal_uInt16 mnHCBmpResId;
79*02c50d82SAndre Fischer     sal_uInt16 mnStrResId;
80*02c50d82SAndre Fischer     WritingMode meWritingMode;
81*02c50d82SAndre Fischer     AutoLayout maAutoLayout;
82*02c50d82SAndre Fischer };
83*02c50d82SAndre Fischer 
84*02c50d82SAndre Fischer static snewfoil_value_info notes[] =
85*02c50d82SAndre Fischer {
86*02c50d82SAndre Fischer     {BMP_FOILN_01, BMP_FOILN_01_H, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
87*02c50d82SAndre Fischer      AUTOLAYOUT_NOTES},
88*02c50d82SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
89*02c50d82SAndre Fischer };
90*02c50d82SAndre Fischer 
91*02c50d82SAndre Fischer static snewfoil_value_info handout[] =
92*02c50d82SAndre Fischer {
93*02c50d82SAndre Fischer     {BMP_FOILH_01, BMP_FOILH_01_H, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
94*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT1},
95*02c50d82SAndre Fischer     {BMP_FOILH_02, BMP_FOILH_02_H, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
96*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT2},
97*02c50d82SAndre Fischer     {BMP_FOILH_03, BMP_FOILH_03_H, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
98*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT3},
99*02c50d82SAndre Fischer     {BMP_FOILH_04, BMP_FOILH_04_H, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
100*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT4},
101*02c50d82SAndre Fischer     {BMP_FOILH_06, BMP_FOILH_06_H, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
102*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT6},
103*02c50d82SAndre Fischer     {BMP_FOILH_09, BMP_FOILH_09_H, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
104*02c50d82SAndre Fischer      AUTOLAYOUT_HANDOUT9},
105*02c50d82SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
106*02c50d82SAndre Fischer };
107*02c50d82SAndre Fischer 
108*02c50d82SAndre Fischer static snewfoil_value_info standard[] =
109*02c50d82SAndre Fischer {
110*02c50d82SAndre Fischer     {BMP_LAYOUT_EMPTY, BMP_LAYOUT_EMPTY_H, STR_AUTOLAYOUT_NONE, WritingMode_LR_TB,        AUTOLAYOUT_NONE},
111*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD03, BMP_LAYOUT_HEAD03_H, STR_AUTOLAYOUT_TITLE, WritingMode_LR_TB,       AUTOLAYOUT_TITLE},
112*02c50d82SAndre Fischer     {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AUTOLAYOUT_CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_ENUM},
113*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AUTOLAYOUT_2CONTENT, WritingMode_LR_TB,       AUTOLAYOUT_2TEXT},
114*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD01, BMP_LAYOUT_HEAD01_H, STR_AUTOLAYOUT_ONLY_TITLE, WritingMode_LR_TB,  AUTOLAYOUT_ONLY_TITLE},
115*02c50d82SAndre Fischer 	{BMP_LAYOUT_TEXTONLY, BMP_LAYOUT_TEXTONLY_H, STR_AUTOLAYOUT_ONLY_TEXT, WritingMode_LR_TB,   AUTOLAYOUT_ONLY_TEXT},
116*02c50d82SAndre Fischer     {BMP_LAYOUT_HEAD03B, BMP_LAYOUT_HEAD03B_H, STR_AUTOLAYOUT_2CONTENT_CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_2OBJTEXT},
117*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD03C, BMP_LAYOUT_HEAD03C_H, STR_AUTOLAYOUT_CONTENT_2CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_TEXT2OBJ},
118*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD03A, BMP_LAYOUT_HEAD03A_H, STR_AUTOLAYOUT_2CONTENT_OVER_CONTENT,WritingMode_LR_TB, AUTOLAYOUT_2OBJOVERTEXT},
119*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD02B, BMP_LAYOUT_HEAD02B_H, STR_AUTOLAYOUT_CONTENT_OVER_CONTENT, WritingMode_LR_TB, AUTOLAYOUT_OBJOVERTEXT},
120*02c50d82SAndre Fischer     {BMP_LAYOUT_HEAD04, BMP_LAYOUT_HEAD04_H, STR_AUTOLAYOUT_4CONTENT, WritingMode_LR_TB,        AUTOLAYOUT_4OBJ},
121*02c50d82SAndre Fischer 	{BMP_LAYOUT_HEAD06, BMP_LAYOUT_HEAD06_H, STR_AUTOLAYOUT_6CONTENT, WritingMode_LR_TB,    AUTOLAYOUT_6CLIPART},
122*02c50d82SAndre Fischer 
123*02c50d82SAndre Fischer 	// vertical
124*02c50d82SAndre Fischer     {BMP_LAYOUT_VERTICAL02, BMP_LAYOUT_VERTICAL02_H, STR_AL_VERT_TITLE_TEXT_CHART, WritingMode_TB_RL,AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART},
125*02c50d82SAndre Fischer     {BMP_LAYOUT_VERTICAL01, BMP_LAYOUT_VERTICAL01_H, STR_AL_VERT_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE},
126*02c50d82SAndre Fischer     {BMP_LAYOUT_HEAD02, BMP_LAYOUT_HEAD02_H, STR_AL_TITLE_VERT_OUTLINE, WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE},
127*02c50d82SAndre Fischer     {BMP_LAYOUT_HEAD02A, BMP_LAYOUT_HEAD02A_H, STR_AL_TITLE_VERT_OUTLINE_CLIPART,   WritingMode_TB_RL, AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART},
128*02c50d82SAndre Fischer     {0, 0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE}
129*02c50d82SAndre Fischer };
130*02c50d82SAndre Fischer 
131*02c50d82SAndre Fischer 
132*02c50d82SAndre Fischer 
133*02c50d82SAndre Fischer 
134*02c50d82SAndre Fischer LayoutMenu::LayoutMenu (
135*02c50d82SAndre Fischer     ::Window* pParent,
136*02c50d82SAndre Fischer     ViewShellBase& rViewShellBase,
137*02c50d82SAndre Fischer     const cssu::Reference<css::ui::XSidebar>& rxSidebar)
138*02c50d82SAndre Fischer     : ValueSet (pParent),
139*02c50d82SAndre Fischer       DragSourceHelper(this),
140*02c50d82SAndre Fischer       DropTargetHelper(this),
141*02c50d82SAndre Fischer       mrBase(rViewShellBase),
142*02c50d82SAndre Fischer       mbUseOwnScrollBar(false),
143*02c50d82SAndre Fischer       mnPreferredColumnCount(3),
144*02c50d82SAndre Fischer       mxListener(NULL),
145*02c50d82SAndre Fischer       mbSelectionUpdatePending(true),
146*02c50d82SAndre Fischer       mbIsMainViewChangePending(false),
147*02c50d82SAndre Fischer       mxSidebar(rxSidebar),
148*02c50d82SAndre Fischer       mbIsDisposed(false)
149*02c50d82SAndre Fischer {
150*02c50d82SAndre Fischer     implConstruct( *mrBase.GetDocument()->GetDocSh() );
151*02c50d82SAndre Fischer     OSL_TRACE("created LayoutMenu at %x", this);
152*02c50d82SAndre Fischer 
153*02c50d82SAndre Fischer #ifdef DEBUG
154*02c50d82SAndre Fischer     SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:LayoutMenu")));
155*02c50d82SAndre Fischer #endif
156*02c50d82SAndre Fischer }
157*02c50d82SAndre Fischer 
158*02c50d82SAndre Fischer 
159*02c50d82SAndre Fischer 
160*02c50d82SAndre Fischer 
161*02c50d82SAndre Fischer void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell )
162*02c50d82SAndre Fischer {
163*02c50d82SAndre Fischer     OSL_ENSURE( mrBase.GetDocument()->GetDocSh() == &rDocumentShell,
164*02c50d82SAndre Fischer         "LayoutMenu::implConstruct: hmm?" );
165*02c50d82SAndre Fischer     // if this fires, then my assumption that the rDocumentShell parameter to our first ctor is superfluous ...
166*02c50d82SAndre Fischer 
167*02c50d82SAndre Fischer 	SetStyle (
168*02c50d82SAndre Fischer         ( GetStyle()  & ~(WB_ITEMBORDER) )
169*02c50d82SAndre Fischer         | WB_TABSTOP
170*02c50d82SAndre Fischer         | WB_NO_DIRECTSELECT
171*02c50d82SAndre Fischer         );
172*02c50d82SAndre Fischer     if (mbUseOwnScrollBar)
173*02c50d82SAndre Fischer         SetStyle (GetStyle() | WB_VSCROLL);
174*02c50d82SAndre Fischer 	SetExtraSpacing(2);
175*02c50d82SAndre Fischer 	SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
176*02c50d82SAndre Fischer     InvalidateContent();
177*02c50d82SAndre Fischer 
178*02c50d82SAndre Fischer     Link aEventListenerLink (LINK(this,LayoutMenu,EventMultiplexerListener));
179*02c50d82SAndre Fischer     mrBase.GetEventMultiplexer()->AddEventListener(aEventListenerLink,
180*02c50d82SAndre Fischer         ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
181*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION
182*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
183*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
184*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED
185*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
186*02c50d82SAndre Fischer         | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
187*02c50d82SAndre Fischer 
188*02c50d82SAndre Fischer     Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS);
189*02c50d82SAndre Fischer     SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
190*02c50d82SAndre Fischer 
191*02c50d82SAndre Fischer     Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
192*02c50d82SAndre Fischer     mxListener = new ::sd::tools::SlotStateListener(
193*02c50d82SAndre Fischer         aStateChangeLink,
194*02c50d82SAndre Fischer         Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
195*02c50d82SAndre Fischer         ::rtl::OUString::createFromAscii(".uno:VerticalTextState"));
196*02c50d82SAndre Fischer 
197*02c50d82SAndre Fischer     SetSizePixel(GetParent()->GetSizePixel());
198*02c50d82SAndre Fischer     Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
199*02c50d82SAndre Fischer     GetParent()->AddEventListener(aWindowEventHandlerLink);
200*02c50d82SAndre Fischer }
201*02c50d82SAndre Fischer 
202*02c50d82SAndre Fischer 
203*02c50d82SAndre Fischer 
204*02c50d82SAndre Fischer 
205*02c50d82SAndre Fischer LayoutMenu::~LayoutMenu (void)
206*02c50d82SAndre Fischer {
207*02c50d82SAndre Fischer     OSL_TRACE("destroying LayoutMenu at %x", this);
208*02c50d82SAndre Fischer     Dispose();
209*02c50d82SAndre Fischer }
210*02c50d82SAndre Fischer 
211*02c50d82SAndre Fischer 
212*02c50d82SAndre Fischer 
213*02c50d82SAndre Fischer 
214*02c50d82SAndre Fischer void LayoutMenu::Dispose (void)
215*02c50d82SAndre Fischer {
216*02c50d82SAndre Fischer     if (mbIsDisposed)
217*02c50d82SAndre Fischer         return;
218*02c50d82SAndre Fischer 
219*02c50d82SAndre Fischer     OSL_TRACE("disposing LayoutMenu at %x", this);
220*02c50d82SAndre Fischer 
221*02c50d82SAndre Fischer     mbIsDisposed = true;
222*02c50d82SAndre Fischer 
223*02c50d82SAndre Fischer     Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
224*02c50d82SAndre Fischer     if (xComponent.is())
225*02c50d82SAndre Fischer         xComponent->dispose();
226*02c50d82SAndre Fischer 
227*02c50d82SAndre Fischer     Clear();
228*02c50d82SAndre Fischer     Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
229*02c50d82SAndre Fischer     mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
230*02c50d82SAndre Fischer 
231*02c50d82SAndre Fischer     Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
232*02c50d82SAndre Fischer     GetParent()->RemoveEventListener(aWindowEventHandlerLink);
233*02c50d82SAndre Fischer }
234*02c50d82SAndre Fischer 
235*02c50d82SAndre Fischer 
236*02c50d82SAndre Fischer 
237*02c50d82SAndre Fischer 
238*02c50d82SAndre Fischer AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
239*02c50d82SAndre Fischer {
240*02c50d82SAndre Fischer     AutoLayout aResult = AUTOLAYOUT_NONE;
241*02c50d82SAndre Fischer 
242*02c50d82SAndre Fischer     if ( ! IsNoSelection() && GetSelectItemId()!=0)
243*02c50d82SAndre Fischer     {
244*02c50d82SAndre Fischer         AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
245*02c50d82SAndre Fischer         if (pLayout != NULL)
246*02c50d82SAndre Fischer             aResult = *pLayout;
247*02c50d82SAndre Fischer     }
248*02c50d82SAndre Fischer 
249*02c50d82SAndre Fischer     return aResult;
250*02c50d82SAndre Fischer }
251*02c50d82SAndre Fischer 
252*02c50d82SAndre Fischer 
253*02c50d82SAndre Fischer 
254*02c50d82SAndre Fischer 
255*02c50d82SAndre Fischer /** The preferred size depends on the preferred number of columns, the
256*02c50d82SAndre Fischer     number of items, and the size of the items.
257*02c50d82SAndre Fischer */
258*02c50d82SAndre Fischer Size LayoutMenu::GetPreferredSize (void)
259*02c50d82SAndre Fischer {
260*02c50d82SAndre Fischer     Size aItemSize = CalcItemSizePixel (Size());
261*02c50d82SAndre Fischer     Size aPreferredWindowSize = CalcWindowSizePixel (
262*02c50d82SAndre Fischer         aItemSize,
263*02c50d82SAndre Fischer          (sal_uInt16)mnPreferredColumnCount,
264*02c50d82SAndre Fischer         (sal_uInt16)CalculateRowCount (aItemSize,mnPreferredColumnCount));
265*02c50d82SAndre Fischer     return aPreferredWindowSize;
266*02c50d82SAndre Fischer }
267*02c50d82SAndre Fischer 
268*02c50d82SAndre Fischer 
269*02c50d82SAndre Fischer 
270*02c50d82SAndre Fischer 
271*02c50d82SAndre Fischer sal_Int32 LayoutMenu::GetPreferredWidth (sal_Int32 nHeight)
272*02c50d82SAndre Fischer {
273*02c50d82SAndre Fischer     sal_Int32 nPreferredWidth = 100;
274*02c50d82SAndre Fischer     if (GetItemCount() > 0)
275*02c50d82SAndre Fischer     {
276*02c50d82SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
277*02c50d82SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
278*02c50d82SAndre Fischer         if (nHeight>0 && aItemSize.Height()>0)
279*02c50d82SAndre Fischer         {
280*02c50d82SAndre Fischer             int nRowCount = nHeight / aItemSize.Height();
281*02c50d82SAndre Fischer             if (nRowCount <= 0)
282*02c50d82SAndre Fischer                 nRowCount = 1;
283*02c50d82SAndre Fischer             int nColumnCount = (GetItemCount() + nRowCount-1) / nRowCount;
284*02c50d82SAndre Fischer             nPreferredWidth = nColumnCount * aItemSize.Width();
285*02c50d82SAndre Fischer         }
286*02c50d82SAndre Fischer     }
287*02c50d82SAndre Fischer 
288*02c50d82SAndre Fischer     return nPreferredWidth;
289*02c50d82SAndre Fischer }
290*02c50d82SAndre Fischer 
291*02c50d82SAndre Fischer 
292*02c50d82SAndre Fischer 
293*02c50d82SAndre Fischer 
294*02c50d82SAndre Fischer ui::LayoutSize LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth)
295*02c50d82SAndre Fischer {
296*02c50d82SAndre Fischer     sal_Int32 nPreferredHeight = 200;
297*02c50d82SAndre Fischer     if ( ! mbUseOwnScrollBar && GetItemCount()>0)
298*02c50d82SAndre Fischer     {
299*02c50d82SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
300*02c50d82SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
301*02c50d82SAndre Fischer         if (nWidth>0 && aItemSize.Width()>0)
302*02c50d82SAndre Fischer         {
303*02c50d82SAndre Fischer             aItemSize.Width() += 8;
304*02c50d82SAndre Fischer             aItemSize.Height() += 8;
305*02c50d82SAndre Fischer             int nColumnCount = nWidth / aItemSize.Width();
306*02c50d82SAndre Fischer             if (nColumnCount <= 0)
307*02c50d82SAndre Fischer                 nColumnCount = 1;
308*02c50d82SAndre Fischer             else if (nColumnCount > 4)
309*02c50d82SAndre Fischer                 nColumnCount = 4;
310*02c50d82SAndre Fischer             int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
311*02c50d82SAndre Fischer             nPreferredHeight = nRowCount * aItemSize.Height();
312*02c50d82SAndre Fischer         }
313*02c50d82SAndre Fischer     }
314*02c50d82SAndre Fischer     return ui::LayoutSize(nPreferredHeight,nPreferredHeight,nPreferredHeight);
315*02c50d82SAndre Fischer }
316*02c50d82SAndre Fischer 
317*02c50d82SAndre Fischer 
318*02c50d82SAndre Fischer 
319*02c50d82SAndre Fischer 
320*02c50d82SAndre Fischer sal_Int32 LayoutMenu::GetMinimumWidth (void)
321*02c50d82SAndre Fischer {
322*02c50d82SAndre Fischer     sal_Int32 nMinimumWidth = 0;
323*02c50d82SAndre Fischer     if (GetItemCount()>0)
324*02c50d82SAndre Fischer     {
325*02c50d82SAndre Fischer         Image aImage = GetItemImage(GetItemId(0));
326*02c50d82SAndre Fischer         Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
327*02c50d82SAndre Fischer         nMinimumWidth = aItemSize.Width();
328*02c50d82SAndre Fischer     }
329*02c50d82SAndre Fischer     return nMinimumWidth;
330*02c50d82SAndre Fischer }
331*02c50d82SAndre Fischer 
332*02c50d82SAndre Fischer 
333*02c50d82SAndre Fischer 
334*02c50d82SAndre Fischer 
335*02c50d82SAndre Fischer void LayoutMenu::UpdateEnabledState (const MasterMode eMode)
336*02c50d82SAndre Fischer {
337*02c50d82SAndre Fischer     bool bIsEnabled (false);
338*02c50d82SAndre Fischer 
339*02c50d82SAndre Fischer     ::boost::shared_ptr<ViewShell> pMainViewShell (mrBase.GetMainViewShell());
340*02c50d82SAndre Fischer     if (pMainViewShell)
341*02c50d82SAndre Fischer     {
342*02c50d82SAndre Fischer         switch (pMainViewShell->GetShellType())
343*02c50d82SAndre Fischer         {
344*02c50d82SAndre Fischer             case ViewShell::ST_NONE:
345*02c50d82SAndre Fischer             case ViewShell::ST_OUTLINE:
346*02c50d82SAndre Fischer             case ViewShell::ST_PRESENTATION:
347*02c50d82SAndre Fischer             case ViewShell::ST_SIDEBAR:
348*02c50d82SAndre Fischer                 // The complete task pane is disabled for these values or
349*02c50d82SAndre Fischer                 // not even visible.  Disabling the LayoutMenu would be
350*02c50d82SAndre Fischer                 // logical but unnecessary.  The main disadvantage is that
351*02c50d82SAndre Fischer                 // after re-enabling it (typically) another panel is
352*02c50d82SAndre Fischer                 // expanded.
353*02c50d82SAndre Fischer                 bIsEnabled = true;
354*02c50d82SAndre Fischer                 break;
355*02c50d82SAndre Fischer 
356*02c50d82SAndre Fischer             case ViewShell::ST_DRAW:
357*02c50d82SAndre Fischer             case ViewShell::ST_IMPRESS:
358*02c50d82SAndre Fischer             {
359*02c50d82SAndre Fischer                 switch (eMode)
360*02c50d82SAndre Fischer                 {
361*02c50d82SAndre Fischer                     case MM_UNKNOWN:
362*02c50d82SAndre Fischer                     {
363*02c50d82SAndre Fischer                         ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
364*02c50d82SAndre Fischer                             ::boost::dynamic_pointer_cast<DrawViewShell>(pMainViewShell));
365*02c50d82SAndre Fischer                         if (pDrawViewShell)
366*02c50d82SAndre Fischer                             bIsEnabled = pDrawViewShell->GetEditMode() != EM_MASTERPAGE;
367*02c50d82SAndre Fischer                         break;
368*02c50d82SAndre Fischer                     }
369*02c50d82SAndre Fischer                     case MM_NORMAL:
370*02c50d82SAndre Fischer                         bIsEnabled = true;
371*02c50d82SAndre Fischer                         break;
372*02c50d82SAndre Fischer 
373*02c50d82SAndre Fischer                     case MM_MASTER:
374*02c50d82SAndre Fischer                         bIsEnabled = false;
375*02c50d82SAndre Fischer                         break;
376*02c50d82SAndre Fischer                 }
377*02c50d82SAndre Fischer                 break;
378*02c50d82SAndre Fischer             }
379*02c50d82SAndre Fischer 
380*02c50d82SAndre Fischer             case ViewShell::ST_HANDOUT:
381*02c50d82SAndre Fischer             case ViewShell::ST_NOTES:
382*02c50d82SAndre Fischer             case ViewShell::ST_SLIDE_SORTER:
383*02c50d82SAndre Fischer             default:
384*02c50d82SAndre Fischer                 bIsEnabled = true;
385*02c50d82SAndre Fischer                 break;
386*02c50d82SAndre Fischer         }
387*02c50d82SAndre Fischer     }
388*02c50d82SAndre Fischer }
389*02c50d82SAndre Fischer 
390*02c50d82SAndre Fischer 
391*02c50d82SAndre Fischer 
392*02c50d82SAndre Fischer 
393*02c50d82SAndre Fischer void LayoutMenu::Paint (const Rectangle& rRect)
394*02c50d82SAndre Fischer {
395*02c50d82SAndre Fischer 	SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
396*02c50d82SAndre Fischer 
397*02c50d82SAndre Fischer     if (mbSelectionUpdatePending)
398*02c50d82SAndre Fischer     {
399*02c50d82SAndre Fischer         mbSelectionUpdatePending = false;
400*02c50d82SAndre Fischer         UpdateSelection();
401*02c50d82SAndre Fischer     }
402*02c50d82SAndre Fischer     ValueSet::Paint (rRect);
403*02c50d82SAndre Fischer 
404*02c50d82SAndre Fischer 	SetBackground (Wallpaper());
405*02c50d82SAndre Fischer }
406*02c50d82SAndre Fischer 
407*02c50d82SAndre Fischer 
408*02c50d82SAndre Fischer 
409*02c50d82SAndre Fischer 
410*02c50d82SAndre Fischer void LayoutMenu::Resize (void)
411*02c50d82SAndre Fischer {
412*02c50d82SAndre Fischer     Size aWindowSize = GetOutputSizePixel();
413*02c50d82SAndre Fischer     if (IsVisible() && aWindowSize.Width() > 0)
414*02c50d82SAndre Fischer     {
415*02c50d82SAndre Fischer         // Calculate the number of rows and columns.
416*02c50d82SAndre Fischer         if (GetItemCount() > 0)
417*02c50d82SAndre Fischer         {
418*02c50d82SAndre Fischer             Image aImage = GetItemImage(GetItemId(0));
419*02c50d82SAndre Fischer             Size aItemSize = CalcItemSizePixel (
420*02c50d82SAndre Fischer                 aImage.GetSizePixel());
421*02c50d82SAndre Fischer             aItemSize.Width() += 8;
422*02c50d82SAndre Fischer             aItemSize.Height() += 8;
423*02c50d82SAndre Fischer             int nColumnCount = aWindowSize.Width() / aItemSize.Width();
424*02c50d82SAndre Fischer             if (nColumnCount < 1)
425*02c50d82SAndre Fischer                 nColumnCount = 1;
426*02c50d82SAndre Fischer             else if (nColumnCount > 4)
427*02c50d82SAndre Fischer                 nColumnCount = 4;
428*02c50d82SAndre Fischer 
429*02c50d82SAndre Fischer             int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
430*02c50d82SAndre Fischer 
431*02c50d82SAndre Fischer             SetColCount ((sal_uInt16)nColumnCount);
432*02c50d82SAndre Fischer             SetLineCount ((sal_uInt16)nRowCount);
433*02c50d82SAndre Fischer         }
434*02c50d82SAndre Fischer     }
435*02c50d82SAndre Fischer 
436*02c50d82SAndre Fischer     ValueSet::Resize ();
437*02c50d82SAndre Fischer }
438*02c50d82SAndre Fischer 
439*02c50d82SAndre Fischer 
440*02c50d82SAndre Fischer 
441*02c50d82SAndre Fischer 
442*02c50d82SAndre Fischer void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
443*02c50d82SAndre Fischer {
444*02c50d82SAndre Fischer     // As a preparation for the context menu the item under the mouse is
445*02c50d82SAndre Fischer     // selected.
446*02c50d82SAndre Fischer     if (rEvent.IsRight())
447*02c50d82SAndre Fischer     {
448*02c50d82SAndre Fischer         ReleaseMouse();
449*02c50d82SAndre Fischer         sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel());
450*02c50d82SAndre Fischer         if (nIndex > 0)
451*02c50d82SAndre Fischer             SelectItem(nIndex);
452*02c50d82SAndre Fischer     }
453*02c50d82SAndre Fischer 
454*02c50d82SAndre Fischer     ValueSet::MouseButtonDown (rEvent);
455*02c50d82SAndre Fischer }
456*02c50d82SAndre Fischer 
457*02c50d82SAndre Fischer 
458*02c50d82SAndre Fischer 
459*02c50d82SAndre Fischer /*
460*02c50d82SAndre Fischer void LayoutMenu::GetState (SfxItemSet& rItemSet)
461*02c50d82SAndre Fischer {
462*02c50d82SAndre Fischer     // Cut and paste is not supported.  The SID_(CUT,COPY,PASTE) entries
463*02c50d82SAndre Fischer     // therefore must not show up in the context menu.
464*02c50d82SAndre Fischer     rItemSet.DisableItem (SID_CUT);
465*02c50d82SAndre Fischer     rItemSet.DisableItem (SID_COPY);
466*02c50d82SAndre Fischer     rItemSet.DisableItem (SID_PASTE);
467*02c50d82SAndre Fischer 
468*02c50d82SAndre Fischer     // The SID_INSERTPAGE_LAYOUT_MENU slot depends on the SID_INSERTPAGE
469*02c50d82SAndre Fischer     // slot being supported elsewhere.
470*02c50d82SAndre Fischer     const SfxPoolItem* pItem = NULL;
471*02c50d82SAndre Fischer     const SfxItemState aState (
472*02c50d82SAndre Fischer         mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
473*02c50d82SAndre Fischer     if (aState == SFX_ITEM_DISABLED)
474*02c50d82SAndre Fischer         rItemSet.DisableItem(SID_INSERTPAGE_LAYOUT_MENU);
475*02c50d82SAndre Fischer }
476*02c50d82SAndre Fischer */
477*02c50d82SAndre Fischer 
478*02c50d82SAndre Fischer 
479*02c50d82SAndre Fischer 
480*02c50d82SAndre Fischer void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
481*02c50d82SAndre Fischer {
482*02c50d82SAndre Fischer     ViewShell* pViewShell = mrBase.GetMainViewShell().get();
483*02c50d82SAndre Fischer     if (pViewShell == NULL)
484*02c50d82SAndre Fischer         return;
485*02c50d82SAndre Fischer 
486*02c50d82SAndre Fischer     SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
487*02c50d82SAndre Fischer     if (pViewFrame == NULL)
488*02c50d82SAndre Fischer         return;
489*02c50d82SAndre Fischer 
490*02c50d82SAndre Fischer     SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
491*02c50d82SAndre Fischer     if (pDispatcher == NULL)
492*02c50d82SAndre Fischer         return;
493*02c50d82SAndre Fischer 
494*02c50d82SAndre Fischer     // Call SID_INSERTPAGE with the right arguments.  This is because
495*02c50d82SAndre Fischer     // the popup menu can not call this slot with arguments directly.
496*02c50d82SAndre Fischer     SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
497*02c50d82SAndre Fischer     if (aRequest.GetArgs() != NULL)
498*02c50d82SAndre Fischer     {
499*02c50d82SAndre Fischer         pDispatcher->Execute(
500*02c50d82SAndre Fischer             SID_INSERTPAGE,
501*02c50d82SAndre Fischer             SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
502*02c50d82SAndre Fischer             *aRequest.GetArgs());
503*02c50d82SAndre Fischer     }
504*02c50d82SAndre Fischer     UpdateSelection();
505*02c50d82SAndre Fischer }
506*02c50d82SAndre Fischer 
507*02c50d82SAndre Fischer 
508*02c50d82SAndre Fischer 
509*02c50d82SAndre Fischer 
510*02c50d82SAndre Fischer void LayoutMenu::InvalidateContent (void)
511*02c50d82SAndre Fischer {
512*02c50d82SAndre Fischer     // The number of items may have changed.  Request a resize so that the
513*02c50d82SAndre Fischer     // vertical size of this control can be adapted.
514*02c50d82SAndre Fischer     //    RequestResize();
515*02c50d82SAndre Fischer 
516*02c50d82SAndre Fischer     // Throw away the current set and fill the menu anew according to the
517*02c50d82SAndre Fischer     // current settings (this includes the support for vertical writing.)
518*02c50d82SAndre Fischer     Fill();
519*02c50d82SAndre Fischer 
520*02c50d82SAndre Fischer     if (mxSidebar.is())
521*02c50d82SAndre Fischer         mxSidebar->requestLayout();
522*02c50d82SAndre Fischer }
523*02c50d82SAndre Fischer 
524*02c50d82SAndre Fischer 
525*02c50d82SAndre Fischer 
526*02c50d82SAndre Fischer 
527*02c50d82SAndre Fischer int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
528*02c50d82SAndre Fischer {
529*02c50d82SAndre Fischer     int nRowCount = 0;
530*02c50d82SAndre Fischer 
531*02c50d82SAndre Fischer     if (GetItemCount() > 0 && nColumnCount > 0)
532*02c50d82SAndre Fischer     {
533*02c50d82SAndre Fischer         nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
534*02c50d82SAndre Fischer         //        nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
535*02c50d82SAndre Fischer         if (nRowCount < 1)
536*02c50d82SAndre Fischer             nRowCount = 1;
537*02c50d82SAndre Fischer     }
538*02c50d82SAndre Fischer 
539*02c50d82SAndre Fischer     return nRowCount;
540*02c50d82SAndre Fischer }
541*02c50d82SAndre Fischer 
542*02c50d82SAndre Fischer 
543*02c50d82SAndre Fischer 
544*02c50d82SAndre Fischer 
545*02c50d82SAndre Fischer IMPL_LINK(LayoutMenu, ClickHandler, ValueSet*, EMPTYARG)
546*02c50d82SAndre Fischer {
547*02c50d82SAndre Fischer     AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
548*02c50d82SAndre Fischer     return 0;
549*02c50d82SAndre Fischer }
550*02c50d82SAndre Fischer 
551*02c50d82SAndre Fischer 
552*02c50d82SAndre Fischer 
553*02c50d82SAndre Fischer 
554*02c50d82SAndre Fischer /** The specified layout is assigned to the current page of the view shell
555*02c50d82SAndre Fischer     in the center pane.
556*02c50d82SAndre Fischer */
557*02c50d82SAndre Fischer void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
558*02c50d82SAndre Fischer {
559*02c50d82SAndre Fischer     using namespace ::sd::slidesorter;
560*02c50d82SAndre Fischer     using namespace ::sd::slidesorter::controller;
561*02c50d82SAndre Fischer 
562*02c50d82SAndre Fischer     do
563*02c50d82SAndre Fischer     {
564*02c50d82SAndre Fischer         // The view shell in the center pane has to be present.
565*02c50d82SAndre Fischer         ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
566*02c50d82SAndre Fischer         if (pMainViewShell == NULL)
567*02c50d82SAndre Fischer             break;
568*02c50d82SAndre Fischer 
569*02c50d82SAndre Fischer         // Determine if the current view is in an invalid master page mode.
570*02c50d82SAndre Fischer         // The handout view is always in master page mode and therefore not
571*02c50d82SAndre Fischer         // invalid.
572*02c50d82SAndre Fischer         bool bMasterPageMode (false);
573*02c50d82SAndre Fischer         switch (pMainViewShell->GetShellType())
574*02c50d82SAndre Fischer         {
575*02c50d82SAndre Fischer             case ViewShell::ST_NOTES:
576*02c50d82SAndre Fischer             case ViewShell::ST_IMPRESS:
577*02c50d82SAndre Fischer             {
578*02c50d82SAndre Fischer                 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
579*02c50d82SAndre Fischer                 if (pDrawViewShell != NULL)
580*02c50d82SAndre Fischer                     if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
581*02c50d82SAndre Fischer                         bMasterPageMode = true;
582*02c50d82SAndre Fischer             }
583*02c50d82SAndre Fischer 			default:
584*02c50d82SAndre Fischer 				break;
585*02c50d82SAndre Fischer         }
586*02c50d82SAndre Fischer         if (bMasterPageMode)
587*02c50d82SAndre Fischer             break;
588*02c50d82SAndre Fischer 
589*02c50d82SAndre Fischer         // Get a list of all selected slides and call the SID_MODIFYPAGE
590*02c50d82SAndre Fischer         // slot for all of them.
591*02c50d82SAndre Fischer 		::sd::slidesorter::SharedPageSelection pPageSelection;
592*02c50d82SAndre Fischer 
593*02c50d82SAndre Fischer         // Get a list of selected pages.
594*02c50d82SAndre Fischer         // First we try to obtain this list from a slide sorter.  This is
595*02c50d82SAndre Fischer         // possible only some of the view shells in the center pane.  When
596*02c50d82SAndre Fischer         // no valid slide sorter is available then ask the main view shell
597*02c50d82SAndre Fischer         // for its current page.
598*02c50d82SAndre Fischer         SlideSorterViewShell* pSlideSorter = NULL;
599*02c50d82SAndre Fischer         switch (pMainViewShell->GetShellType())
600*02c50d82SAndre Fischer         {
601*02c50d82SAndre Fischer             case ViewShell::ST_IMPRESS:
602*02c50d82SAndre Fischer             case ViewShell::ST_NOTES:
603*02c50d82SAndre Fischer             case ViewShell::ST_SLIDE_SORTER:
604*02c50d82SAndre Fischer                 pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
605*02c50d82SAndre Fischer                 break;
606*02c50d82SAndre Fischer 			default:
607*02c50d82SAndre Fischer 				break;
608*02c50d82SAndre Fischer         }
609*02c50d82SAndre Fischer 		if (pSlideSorter != NULL)
610*02c50d82SAndre Fischer 		{
611*02c50d82SAndre Fischer 			// There is a slide sorter visible so get the list of selected pages from it.
612*02c50d82SAndre Fischer             pPageSelection = pSlideSorter->GetPageSelection();
613*02c50d82SAndre Fischer 		}
614*02c50d82SAndre Fischer 
615*02c50d82SAndre Fischer 		if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() )
616*02c50d82SAndre Fischer 		{
617*02c50d82SAndre Fischer 			// No valid slide sorter available.  Ask the main view shell for
618*02c50d82SAndre Fischer 			// its current page.
619*02c50d82SAndre Fischer             pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
620*02c50d82SAndre Fischer             pPageSelection->push_back(pMainViewShell->GetActualPage());
621*02c50d82SAndre Fischer 		}
622*02c50d82SAndre Fischer 
623*02c50d82SAndre Fischer 
624*02c50d82SAndre Fischer 		if (pPageSelection->empty())
625*02c50d82SAndre Fischer 			break;
626*02c50d82SAndre Fischer 
627*02c50d82SAndre Fischer 		::std::vector<SdPage*>::iterator iPage;
628*02c50d82SAndre Fischer 		for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
629*02c50d82SAndre Fischer 			{
630*02c50d82SAndre Fischer 				if ((*iPage) == NULL)
631*02c50d82SAndre Fischer 					continue;
632*02c50d82SAndre Fischer 
633*02c50d82SAndre Fischer 				// Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
634*02c50d82SAndre Fischer 				SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
635*02c50d82SAndre Fischer 				aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
636*02c50d82SAndre Fischer 				aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
637*02c50d82SAndre Fischer 				pMainViewShell->ExecuteSlot (aRequest, sal_Bool(sal_False));
638*02c50d82SAndre Fischer 			}
639*02c50d82SAndre Fischer     }
640*02c50d82SAndre Fischer     while(false);
641*02c50d82SAndre Fischer }
642*02c50d82SAndre Fischer 
643*02c50d82SAndre Fischer 
644*02c50d82SAndre Fischer 
645*02c50d82SAndre Fischer 
646*02c50d82SAndre Fischer SfxRequest LayoutMenu::CreateRequest (
647*02c50d82SAndre Fischer     sal_uInt16 nSlotId,
648*02c50d82SAndre Fischer     AutoLayout aLayout)
649*02c50d82SAndre Fischer {
650*02c50d82SAndre Fischer     SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
651*02c50d82SAndre Fischer 
652*02c50d82SAndre Fischer     do
653*02c50d82SAndre Fischer     {
654*02c50d82SAndre Fischer         SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
655*02c50d82SAndre Fischer         sal_uInt8 aBackground (rLayerAdmin.GetLayerID(
656*02c50d82SAndre Fischer             String(SdResId(STR_LAYER_BCKGRND)), sal_False));
657*02c50d82SAndre Fischer         sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(
658*02c50d82SAndre Fischer             String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False));
659*02c50d82SAndre Fischer         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
660*02c50d82SAndre Fischer         if (pViewShell == NULL)
661*02c50d82SAndre Fischer             break;
662*02c50d82SAndre Fischer         SdPage* pPage = pViewShell->GetActualPage();
663*02c50d82SAndre Fischer         if (pPage == NULL)
664*02c50d82SAndre Fischer             break;
665*02c50d82SAndre Fischer 
666*02c50d82SAndre Fischer         SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
667*02c50d82SAndre Fischer 
668*02c50d82SAndre Fischer         aRequest.AppendItem(
669*02c50d82SAndre Fischer             SfxStringItem (ID_VAL_PAGENAME, String()));//pPage->GetName()));
670*02c50d82SAndre Fischer         aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
671*02c50d82SAndre Fischer         aRequest.AppendItem(
672*02c50d82SAndre Fischer             SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
673*02c50d82SAndre Fischer         aRequest.AppendItem(
674*02c50d82SAndre Fischer             SfxBoolItem(
675*02c50d82SAndre Fischer                 ID_VAL_ISPAGEOBJ,
676*02c50d82SAndre Fischer                 aVisibleLayers.IsSet(aBackgroundObject)));
677*02c50d82SAndre Fischer     }
678*02c50d82SAndre Fischer     while (false);
679*02c50d82SAndre Fischer 
680*02c50d82SAndre Fischer     return aRequest;
681*02c50d82SAndre Fischer }
682*02c50d82SAndre Fischer 
683*02c50d82SAndre Fischer 
684*02c50d82SAndre Fischer 
685*02c50d82SAndre Fischer 
686*02c50d82SAndre Fischer void LayoutMenu::Fill (void)
687*02c50d82SAndre Fischer {
688*02c50d82SAndre Fischer 	const bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
689*02c50d82SAndre Fischer 	SvtLanguageOptions aLanguageOptions;
690*02c50d82SAndre Fischer     sal_Bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
691*02c50d82SAndre Fischer     SdDrawDocument* pDocument = mrBase.GetDocument();
692*02c50d82SAndre Fischer     sal_Bool bRightToLeft = (pDocument!=NULL
693*02c50d82SAndre Fischer         && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
694*02c50d82SAndre Fischer 
695*02c50d82SAndre Fischer     // Get URL of the view in the center pane.
696*02c50d82SAndre Fischer     ::rtl::OUString sCenterPaneViewName;
697*02c50d82SAndre Fischer     try
698*02c50d82SAndre Fischer     {
699*02c50d82SAndre Fischer         Reference<XControllerManager> xControllerManager (
700*02c50d82SAndre Fischer             Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
701*02c50d82SAndre Fischer         Reference<XResourceId> xPaneId (ResourceId::create(
702*02c50d82SAndre Fischer             ::comphelper::getProcessComponentContext(),
703*02c50d82SAndre Fischer             FrameworkHelper::msCenterPaneURL));
704*02c50d82SAndre Fischer         Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
705*02c50d82SAndre Fischer         if (xView.is())
706*02c50d82SAndre Fischer             sCenterPaneViewName = xView->getResourceId()->getResourceURL();
707*02c50d82SAndre Fischer     }
708*02c50d82SAndre Fischer     catch (RuntimeException&)
709*02c50d82SAndre Fischer     {}
710*02c50d82SAndre Fischer 
711*02c50d82SAndre Fischer 	snewfoil_value_info* pInfo = NULL;
712*02c50d82SAndre Fischer     if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
713*02c50d82SAndre Fischer     {
714*02c50d82SAndre Fischer         pInfo = notes;
715*02c50d82SAndre Fischer     }
716*02c50d82SAndre Fischer     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
717*02c50d82SAndre Fischer     {
718*02c50d82SAndre Fischer         pInfo = handout;
719*02c50d82SAndre Fischer     }
720*02c50d82SAndre Fischer     else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
721*02c50d82SAndre Fischer         || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
722*02c50d82SAndre Fischer     {
723*02c50d82SAndre Fischer         pInfo = standard;
724*02c50d82SAndre Fischer     }
725*02c50d82SAndre Fischer     else
726*02c50d82SAndre Fischer     {
727*02c50d82SAndre Fischer         pInfo = NULL;
728*02c50d82SAndre Fischer 	}
729*02c50d82SAndre Fischer 
730*02c50d82SAndre Fischer     Clear();
731*02c50d82SAndre Fischer     int n = 0;
732*02c50d82SAndre Fischer 	for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
733*02c50d82SAndre Fischer 	{
734*02c50d82SAndre Fischer         if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
735*02c50d82SAndre Fischer         {
736*02c50d82SAndre Fischer             BitmapEx aBmp (SdResId (bHighContrast
737*02c50d82SAndre Fischer                              ? pInfo->mnHCBmpResId
738*02c50d82SAndre Fischer                              : pInfo->mnBmpResId));
739*02c50d82SAndre Fischer 
740*02c50d82SAndre Fischer             if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
741*02c50d82SAndre Fischer                 aBmp.Mirror (BMP_MIRROR_HORZ);
742*02c50d82SAndre Fischer 
743*02c50d82SAndre Fischer             InsertItem (i, aBmp, String (SdResId (pInfo->mnStrResId)));
744*02c50d82SAndre Fischer             SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
745*02c50d82SAndre Fischer             n++;
746*02c50d82SAndre Fischer         }
747*02c50d82SAndre Fischer 	}
748*02c50d82SAndre Fischer 
749*02c50d82SAndre Fischer     mbSelectionUpdatePending = true;
750*02c50d82SAndre Fischer }
751*02c50d82SAndre Fischer 
752*02c50d82SAndre Fischer 
753*02c50d82SAndre Fischer 
754*02c50d82SAndre Fischer 
755*02c50d82SAndre Fischer void LayoutMenu::Clear (void)
756*02c50d82SAndre Fischer {
757*02c50d82SAndre Fischer     for (sal_uInt16 nId=1; nId<=GetItemCount(); nId++)
758*02c50d82SAndre Fischer         delete static_cast<AutoLayout*>(GetItemData(nId));
759*02c50d82SAndre Fischer     ValueSet::Clear();
760*02c50d82SAndre Fischer }
761*02c50d82SAndre Fischer 
762*02c50d82SAndre Fischer 
763*02c50d82SAndre Fischer 
764*02c50d82SAndre Fischer void LayoutMenu::StartDrag (sal_Int8 , const Point& )
765*02c50d82SAndre Fischer {
766*02c50d82SAndre Fischer }
767*02c50d82SAndre Fischer 
768*02c50d82SAndre Fischer 
769*02c50d82SAndre Fischer 
770*02c50d82SAndre Fischer 
771*02c50d82SAndre Fischer sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
772*02c50d82SAndre Fischer {
773*02c50d82SAndre Fischer     return 0;
774*02c50d82SAndre Fischer }
775*02c50d82SAndre Fischer 
776*02c50d82SAndre Fischer 
777*02c50d82SAndre Fischer 
778*02c50d82SAndre Fischer 
779*02c50d82SAndre Fischer sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
780*02c50d82SAndre Fischer {
781*02c50d82SAndre Fischer     return 0;
782*02c50d82SAndre Fischer }
783*02c50d82SAndre Fischer 
784*02c50d82SAndre Fischer 
785*02c50d82SAndre Fischer 
786*02c50d82SAndre Fischer 
787*02c50d82SAndre Fischer void LayoutMenu::Command (const CommandEvent& rEvent)
788*02c50d82SAndre Fischer {
789*02c50d82SAndre Fischer     switch (rEvent.GetCommand())
790*02c50d82SAndre Fischer     {
791*02c50d82SAndre Fischer         case COMMAND_CONTEXTMENU:
792*02c50d82SAndre Fischer             if ( ! SD_MOD()->GetWaterCan())
793*02c50d82SAndre Fischer             {
794*02c50d82SAndre Fischer                 // Determine the position where to show the menu.
795*02c50d82SAndre Fischer                 Point aMenuPosition;
796*02c50d82SAndre Fischer                 if (rEvent.IsMouseEvent())
797*02c50d82SAndre Fischer                 {
798*02c50d82SAndre Fischer                     if (GetItemId(rEvent.GetMousePosPixel()) <= 0)
799*02c50d82SAndre Fischer                         return;
800*02c50d82SAndre Fischer                     aMenuPosition = rEvent.GetMousePosPixel();
801*02c50d82SAndre Fischer                 }
802*02c50d82SAndre Fischer                 else
803*02c50d82SAndre Fischer                 {
804*02c50d82SAndre Fischer                     if (GetSelectItemId() == (sal_uInt16)-1)
805*02c50d82SAndre Fischer                         return;
806*02c50d82SAndre Fischer                     Rectangle aBBox (GetItemRect(GetSelectItemId()));
807*02c50d82SAndre Fischer                     aMenuPosition = aBBox.Center();
808*02c50d82SAndre Fischer                 }
809*02c50d82SAndre Fischer 
810*02c50d82SAndre Fischer                 // Setup the menu.
811*02c50d82SAndre Fischer                 ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP)));
812*02c50d82SAndre Fischer                 FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
813*02c50d82SAndre Fischer                 if (pMenuWindow != NULL)
814*02c50d82SAndre Fischer                     pMenuWindow->SetPopupModeFlags(
815*02c50d82SAndre Fischer                         pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
816*02c50d82SAndre Fischer                 pMenu->SetSelectHdl(LINK(this, LayoutMenu, OnMenuItemSelected));
817*02c50d82SAndre Fischer 
818*02c50d82SAndre Fischer                 // Disable the SID_INSERTPAGE_LAYOUT_MENU item when
819*02c50d82SAndre Fischer                 // the document is read-only.
820*02c50d82SAndre Fischer                 const SfxPoolItem* pItem = NULL;
821*02c50d82SAndre Fischer                 const SfxItemState aState (
822*02c50d82SAndre Fischer                     mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
823*02c50d82SAndre Fischer                 if (aState == SFX_ITEM_DISABLED)
824*02c50d82SAndre Fischer                     pMenu->EnableItem(SID_INSERTPAGE_LAYOUT_MENU, sal_False);
825*02c50d82SAndre Fischer 
826*02c50d82SAndre Fischer                 // Show the menu.
827*02c50d82SAndre Fischer                 pMenu->Execute(this, Rectangle(aMenuPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN);
828*02c50d82SAndre Fischer             }
829*02c50d82SAndre Fischer             break;
830*02c50d82SAndre Fischer 
831*02c50d82SAndre Fischer         default:
832*02c50d82SAndre Fischer             ValueSet::Command(rEvent);
833*02c50d82SAndre Fischer             break;
834*02c50d82SAndre Fischer     }
835*02c50d82SAndre Fischer }
836*02c50d82SAndre Fischer 
837*02c50d82SAndre Fischer 
838*02c50d82SAndre Fischer 
839*02c50d82SAndre Fischer 
840*02c50d82SAndre Fischer IMPL_LINK(LayoutMenu, StateChangeHandler, ::rtl::OUString*, EMPTYARG)
841*02c50d82SAndre Fischer {
842*02c50d82SAndre Fischer     InvalidateContent();
843*02c50d82SAndre Fischer     return 0;
844*02c50d82SAndre Fischer }
845*02c50d82SAndre Fischer 
846*02c50d82SAndre Fischer 
847*02c50d82SAndre Fischer 
848*02c50d82SAndre Fischer 
849*02c50d82SAndre Fischer IMPL_LINK(LayoutMenu, OnMenuItemSelected, Menu*, pMenu)
850*02c50d82SAndre Fischer {
851*02c50d82SAndre Fischer     if (pMenu == NULL)
852*02c50d82SAndre Fischer     {
853*02c50d82SAndre Fischer         OSL_ENSURE(pMenu!=NULL, "LayoutMenu::OnMenuItemSelected: illegal menu!");
854*02c50d82SAndre Fischer         return 0;
855*02c50d82SAndre Fischer     }
856*02c50d82SAndre Fischer 
857*02c50d82SAndre Fischer     pMenu->Deactivate();
858*02c50d82SAndre Fischer     const sal_Int32 nIndex (pMenu->GetCurItemId());
859*02c50d82SAndre Fischer 
860*02c50d82SAndre Fischer     if (nIndex == SID_TP_APPLY_TO_SELECTED_SLIDES)
861*02c50d82SAndre Fischer     {
862*02c50d82SAndre Fischer         AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
863*02c50d82SAndre Fischer     }
864*02c50d82SAndre Fischer     else if (nIndex == SID_INSERTPAGE_LAYOUT_MENU)
865*02c50d82SAndre Fischer     {
866*02c50d82SAndre Fischer         // Add arguments to this slot and forward it to the main view
867*02c50d82SAndre Fischer         // shell.
868*02c50d82SAndre Fischer         InsertPageWithLayout(GetSelectedAutoLayout());
869*02c50d82SAndre Fischer     }
870*02c50d82SAndre Fischer 
871*02c50d82SAndre Fischer     return 0;
872*02c50d82SAndre Fischer }
873*02c50d82SAndre Fischer 
874*02c50d82SAndre Fischer 
875*02c50d82SAndre Fischer 
876*02c50d82SAndre Fischer 
877*02c50d82SAndre Fischer void LayoutMenu::UpdateSelection (void)
878*02c50d82SAndre Fischer {
879*02c50d82SAndre Fischer     bool bItemSelected = false;
880*02c50d82SAndre Fischer 
881*02c50d82SAndre Fischer     do
882*02c50d82SAndre Fischer     {
883*02c50d82SAndre Fischer         // Get current page of main view.
884*02c50d82SAndre Fischer         ViewShell* pViewShell = mrBase.GetMainViewShell().get();
885*02c50d82SAndre Fischer         if (pViewShell == NULL)
886*02c50d82SAndre Fischer             break;
887*02c50d82SAndre Fischer 
888*02c50d82SAndre Fischer         SdPage* pCurrentPage = pViewShell->getCurrentPage();
889*02c50d82SAndre Fischer         if (pCurrentPage == NULL)
890*02c50d82SAndre Fischer             break;
891*02c50d82SAndre Fischer 
892*02c50d82SAndre Fischer         // Get layout of current page.
893*02c50d82SAndre Fischer         AutoLayout aLayout (pCurrentPage->GetAutoLayout());
894*02c50d82SAndre Fischer         if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
895*02c50d82SAndre Fischer             break;
896*02c50d82SAndre Fischer 
897*02c50d82SAndre Fischer         // Find the entry of the menu for to the layout.
898*02c50d82SAndre Fischer         sal_uInt16 nItemCount (GetItemCount());
899*02c50d82SAndre Fischer         for (sal_uInt16 nId=1; nId<=nItemCount; nId++)
900*02c50d82SAndre Fischer         {
901*02c50d82SAndre Fischer             if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
902*02c50d82SAndre Fischer             {
903*02c50d82SAndre Fischer                 SelectItem(nId);
904*02c50d82SAndre Fischer                 bItemSelected = true;
905*02c50d82SAndre Fischer                 break;
906*02c50d82SAndre Fischer             }
907*02c50d82SAndre Fischer         }
908*02c50d82SAndre Fischer     }
909*02c50d82SAndre Fischer     while (false);
910*02c50d82SAndre Fischer 
911*02c50d82SAndre Fischer     if ( ! bItemSelected)
912*02c50d82SAndre Fischer         SetNoSelection();
913*02c50d82SAndre Fischer }
914*02c50d82SAndre Fischer 
915*02c50d82SAndre Fischer 
916*02c50d82SAndre Fischer 
917*02c50d82SAndre Fischer 
918*02c50d82SAndre Fischer IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
919*02c50d82SAndre Fischer {
920*02c50d82SAndre Fischer     switch (pEvent->meEventId)
921*02c50d82SAndre Fischer     {
922*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
923*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
924*02c50d82SAndre Fischer             if ( ! mbSelectionUpdatePending)
925*02c50d82SAndre Fischer                 UpdateSelection();
926*02c50d82SAndre Fischer             break;
927*02c50d82SAndre Fischer 
928*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
929*02c50d82SAndre Fischer             mbIsMainViewChangePending = true;
930*02c50d82SAndre Fischer             UpdateEnabledState(MM_UNKNOWN);
931*02c50d82SAndre Fischer             break;
932*02c50d82SAndre Fischer 
933*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
934*02c50d82SAndre Fischer             HideFocus();
935*02c50d82SAndre Fischer             break;
936*02c50d82SAndre Fischer 
937*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
938*02c50d82SAndre Fischer             if (mbIsMainViewChangePending)
939*02c50d82SAndre Fischer             {
940*02c50d82SAndre Fischer                 mbIsMainViewChangePending = false;
941*02c50d82SAndre Fischer                 InvalidateContent();
942*02c50d82SAndre Fischer             }
943*02c50d82SAndre Fischer             break;
944*02c50d82SAndre Fischer 
945*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
946*02c50d82SAndre Fischer             UpdateEnabledState(MM_NORMAL);
947*02c50d82SAndre Fischer             break;
948*02c50d82SAndre Fischer 
949*02c50d82SAndre Fischer         case ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
950*02c50d82SAndre Fischer             UpdateEnabledState(MM_MASTER);
951*02c50d82SAndre Fischer             break;
952*02c50d82SAndre Fischer 
953*02c50d82SAndre Fischer         default:
954*02c50d82SAndre Fischer             /* Ignored */
955*02c50d82SAndre Fischer             break;
956*02c50d82SAndre Fischer     }
957*02c50d82SAndre Fischer 
958*02c50d82SAndre Fischer     return 0;
959*02c50d82SAndre Fischer }
960*02c50d82SAndre Fischer 
961*02c50d82SAndre Fischer 
962*02c50d82SAndre Fischer 
963*02c50d82SAndre Fischer 
964*02c50d82SAndre Fischer IMPL_LINK(LayoutMenu, WindowEventHandler, VclWindowEvent*, pEvent)
965*02c50d82SAndre Fischer {
966*02c50d82SAndre Fischer     if (pEvent != NULL)
967*02c50d82SAndre Fischer     {
968*02c50d82SAndre Fischer         switch (pEvent->GetId())
969*02c50d82SAndre Fischer         {
970*02c50d82SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
971*02c50d82SAndre Fischer             case VCLEVENT_WINDOW_RESIZE:
972*02c50d82SAndre Fischer                 SetSizePixel(GetParent()->GetSizePixel());
973*02c50d82SAndre Fischer                 return sal_True;
974*02c50d82SAndre Fischer 
975*02c50d82SAndre Fischer             default:
976*02c50d82SAndre Fischer                 return sal_False;
977*02c50d82SAndre Fischer         }
978*02c50d82SAndre Fischer 
979*02c50d82SAndre Fischer         const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, pEvent);
980*02c50d82SAndre Fischer         if (pSimpleHint != NULL
981*02c50d82SAndre Fischer             && pSimpleHint->GetId() == SFX_HINT_DYING)
982*02c50d82SAndre Fischer         {
983*02c50d82SAndre Fischer             return sal_True;
984*02c50d82SAndre Fischer         }
985*02c50d82SAndre Fischer     }
986*02c50d82SAndre Fischer 
987*02c50d82SAndre Fischer     return sal_False;
988*02c50d82SAndre Fischer }
989*02c50d82SAndre Fischer 
990*02c50d82SAndre Fischer 
991*02c50d82SAndre Fischer 
992*02c50d82SAndre Fischer 
993*02c50d82SAndre Fischer void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
994*02c50d82SAndre Fischer {
995*02c50d82SAndre Fischer     Fill();
996*02c50d82SAndre Fischer     ValueSet::DataChanged(rEvent);
997*02c50d82SAndre Fischer }
998*02c50d82SAndre Fischer 
999*02c50d82SAndre Fischer 
1000*02c50d82SAndre Fischer 
1001*02c50d82SAndre Fischer 
1002*02c50d82SAndre Fischer 
1003*02c50d82SAndre Fischer } } // end of namespace ::sd::sidebar
1004