Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "LayoutMenu.hxx"
21 :
22 : #include "app.hrc"
23 : #include "drawdoc.hxx"
24 : #include "framework/FrameworkHelper.hxx"
25 : #include "glob.hrc"
26 : #include "glob.hxx"
27 : #include "helpids.h"
28 : #include "pres.hxx"
29 : #include "res_bmp.hrc"
30 : #include "sdpage.hxx"
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>
41 :
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>
51 :
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>
56 :
57 : #include <vector>
58 :
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;
65 :
66 : namespace sd { namespace sidebar {
67 :
68 : struct snewfoil_value_info
69 : {
70 : sal_uInt16 mnBmpResId;
71 : sal_uInt16 mnStrResId;
72 : WritingMode meWritingMode;
73 : AutoLayout maAutoLayout;
74 : };
75 :
76 : static const snewfoil_value_info notes[] =
77 : {
78 : {BMP_FOILN_01, STR_AUTOLAYOUT_NOTES, WritingMode_LR_TB,
79 : AUTOLAYOUT_NOTES},
80 : {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
81 : };
82 :
83 : static const snewfoil_value_info handout[] =
84 : {
85 : {BMP_FOILH_01, STR_AUTOLAYOUT_HANDOUT1, WritingMode_LR_TB,
86 : AUTOLAYOUT_HANDOUT1},
87 : {BMP_FOILH_02, STR_AUTOLAYOUT_HANDOUT2, WritingMode_LR_TB,
88 : AUTOLAYOUT_HANDOUT2},
89 : {BMP_FOILH_03, STR_AUTOLAYOUT_HANDOUT3, WritingMode_LR_TB,
90 : AUTOLAYOUT_HANDOUT3},
91 : {BMP_FOILH_04, STR_AUTOLAYOUT_HANDOUT4, WritingMode_LR_TB,
92 : AUTOLAYOUT_HANDOUT4},
93 : {BMP_FOILH_06, STR_AUTOLAYOUT_HANDOUT6, WritingMode_LR_TB,
94 : AUTOLAYOUT_HANDOUT6},
95 : {BMP_FOILH_09, STR_AUTOLAYOUT_HANDOUT9, WritingMode_LR_TB,
96 : AUTOLAYOUT_HANDOUT9},
97 : {0, 0, WritingMode_LR_TB, AUTOLAYOUT_NONE},
98 : };
99 :
100 : static const snewfoil_value_info standard[] =
101 : {
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},
114 :
115 : // vertical
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}
121 : };
122 :
123 24 : 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),
133 : mxListener(NULL),
134 : mbSelectionUpdatePending(true),
135 : mbIsMainViewChangePending(false),
136 : mxSidebar(rxSidebar),
137 24 : mbIsDisposed(false)
138 : {
139 24 : implConstruct( *mrBase.GetDocument()->GetDocSh() );
140 : OSL_TRACE("created LayoutMenu at %x", this);
141 :
142 24 : SetStyle(GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_TABSTOP);
143 :
144 24 : SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
145 24 : SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
146 :
147 : #ifdef DEBUG
148 : SetText(OUString("sd:LayoutMenu"));
149 : #endif
150 24 : }
151 :
152 24 : void LayoutMenu::implConstruct( DrawDocShell& rDocumentShell )
153 : {
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;
158 :
159 : SetStyle (
160 24 : ( GetStyle() & ~(WB_ITEMBORDER) )
161 : | WB_TABSTOP
162 : | WB_MENUSTYLEVALUESET
163 : | WB_NO_DIRECTSELECT
164 24 : );
165 24 : if (mbUseOwnScrollBar)
166 0 : SetStyle (GetStyle() | WB_VSCROLL);
167 24 : SetExtraSpacing(2);
168 24 : SetSelectHdl (LINK(this, LayoutMenu, ClickHandler));
169 24 : InvalidateContent();
170 :
171 24 : 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 24 : | ::sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
180 :
181 24 : Window::SetHelpId(HID_SD_TASK_PANE_PREVIEW_LAYOUTS);
182 24 : SetAccessibleName(SdResId(STR_TASKPANEL_LAYOUT_MENU_TITLE));
183 :
184 24 : Link aStateChangeLink (LINK(this,LayoutMenu,StateChangeHandler));
185 72 : mxListener = new ::sd::tools::SlotStateListener(
186 : aStateChangeLink,
187 48 : Reference<frame::XDispatchProvider>(mrBase.GetController()->getFrame(), UNO_QUERY),
188 48 : ".uno:VerticalTextState");
189 :
190 24 : SetSizePixel(GetParent()->GetSizePixel());
191 24 : Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
192 24 : GetParent()->AddEventListener(aWindowEventHandlerLink);
193 24 : }
194 :
195 72 : LayoutMenu::~LayoutMenu (void)
196 : {
197 : OSL_TRACE("destroying LayoutMenu at %x", this);
198 24 : Dispose();
199 48 : }
200 :
201 24 : void LayoutMenu::Dispose (void)
202 : {
203 24 : if (mbIsDisposed)
204 24 : return;
205 :
206 : OSL_TRACE("disposing LayoutMenu at %x", this);
207 :
208 24 : mbIsDisposed = true;
209 :
210 24 : Reference<lang::XComponent> xComponent (mxListener, UNO_QUERY);
211 24 : if (xComponent.is())
212 24 : xComponent->dispose();
213 :
214 24 : Clear();
215 24 : Link aLink (LINK(this,LayoutMenu,EventMultiplexerListener));
216 24 : mrBase.GetEventMultiplexer()->RemoveEventListener (aLink);
217 :
218 24 : Link aWindowEventHandlerLink (LINK(this,LayoutMenu,WindowEventHandler));
219 24 : GetParent()->RemoveEventListener(aWindowEventHandlerLink);
220 : }
221 :
222 0 : AutoLayout LayoutMenu::GetSelectedAutoLayout (void)
223 : {
224 0 : AutoLayout aResult = AUTOLAYOUT_NONE;
225 :
226 0 : if ( ! IsNoSelection() && GetSelectItemId()!=0)
227 : {
228 0 : AutoLayout* pLayout = static_cast<AutoLayout*>(GetItemData(GetSelectItemId()));
229 0 : if (pLayout != NULL)
230 0 : aResult = *pLayout;
231 : }
232 :
233 0 : return aResult;
234 : }
235 :
236 148 : ui::LayoutSize LayoutMenu::GetHeightForWidth (const sal_Int32 nWidth)
237 : {
238 148 : sal_Int32 nPreferredHeight = 200;
239 148 : if ( ! mbUseOwnScrollBar && GetItemCount()>0)
240 : {
241 148 : Image aImage = GetItemImage(GetItemId(0));
242 148 : Size aItemSize = CalcItemSizePixel (aImage.GetSizePixel());
243 148 : if (nWidth>0 && aItemSize.Width()>0)
244 : {
245 148 : aItemSize.Width() += 8;
246 148 : aItemSize.Height() += 8;
247 148 : int nColumnCount = nWidth / aItemSize.Width();
248 148 : if (nColumnCount <= 0)
249 0 : nColumnCount = 1;
250 148 : else if (nColumnCount > 4)
251 0 : nColumnCount = 4;
252 148 : int nRowCount = (GetItemCount() + nColumnCount-1) / nColumnCount;
253 148 : nPreferredHeight = nRowCount * aItemSize.Height();
254 148 : }
255 : }
256 148 : return ui::LayoutSize(nPreferredHeight,nPreferredHeight,nPreferredHeight);
257 : }
258 :
259 21 : void LayoutMenu::Paint (const Rectangle& rRect)
260 : {
261 21 : if (mbSelectionUpdatePending)
262 : {
263 18 : mbSelectionUpdatePending = false;
264 18 : UpdateSelection();
265 : }
266 21 : ValueSet::Paint (rRect);
267 21 : }
268 :
269 48 : void LayoutMenu::Resize (void)
270 : {
271 48 : Size aWindowSize = GetOutputSizePixel();
272 48 : if (IsVisible() && aWindowSize.Width() > 0)
273 : {
274 : // Calculate the number of rows and columns.
275 24 : if (GetItemCount() > 0)
276 : {
277 24 : Image aImage = GetItemImage(GetItemId(0));
278 : Size aItemSize = CalcItemSizePixel (
279 24 : aImage.GetSizePixel());
280 24 : aItemSize.Width() += 8;
281 24 : aItemSize.Height() += 8;
282 24 : int nColumnCount = aWindowSize.Width() / aItemSize.Width();
283 24 : if (nColumnCount < 1)
284 0 : nColumnCount = 1;
285 24 : else if (nColumnCount > 4)
286 0 : nColumnCount = 4;
287 :
288 24 : int nRowCount = CalculateRowCount (aItemSize, nColumnCount);
289 :
290 24 : SetColCount ((sal_uInt16)nColumnCount);
291 24 : SetLineCount ((sal_uInt16)nRowCount);
292 : }
293 : }
294 :
295 48 : ValueSet::Resize ();
296 48 : }
297 :
298 0 : void LayoutMenu::MouseButtonDown (const MouseEvent& rEvent)
299 : {
300 : // As a preparation for the context menu the item under the mouse is
301 : // selected.
302 0 : if (rEvent.IsRight())
303 : {
304 0 : ReleaseMouse();
305 0 : sal_uInt16 nIndex = GetItemId (rEvent.GetPosPixel());
306 0 : if (nIndex > 0)
307 0 : SelectItem(nIndex);
308 : }
309 :
310 0 : ValueSet::MouseButtonDown (rEvent);
311 0 : }
312 :
313 0 : void LayoutMenu::InsertPageWithLayout (AutoLayout aLayout)
314 : {
315 0 : ViewShell* pViewShell = mrBase.GetMainViewShell().get();
316 0 : if (pViewShell == NULL)
317 0 : return;
318 :
319 0 : SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
320 0 : if (pViewFrame == NULL)
321 0 : return;
322 :
323 0 : SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
324 0 : if (pDispatcher == NULL)
325 0 : return;
326 :
327 : // Call SID_INSERTPAGE with the right arguments. This is because
328 : // the popup menu can not call this slot with arguments directly.
329 0 : SfxRequest aRequest (CreateRequest(SID_INSERTPAGE, aLayout));
330 0 : if (aRequest.GetArgs() != NULL)
331 : {
332 : pDispatcher->Execute(
333 : SID_INSERTPAGE,
334 : SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
335 0 : *aRequest.GetArgs());
336 : }
337 0 : UpdateSelection();
338 : }
339 :
340 48 : void LayoutMenu::InvalidateContent (void)
341 : {
342 : // Throw away the current set and fill the menu anew according to the
343 : // current settings (this includes the support for vertical writing.)
344 48 : Fill();
345 :
346 48 : if (mxSidebar.is())
347 48 : mxSidebar->requestLayout();
348 48 : }
349 :
350 24 : int LayoutMenu::CalculateRowCount (const Size&, int nColumnCount)
351 : {
352 24 : int nRowCount = 0;
353 :
354 24 : if (GetItemCount() > 0 && nColumnCount > 0)
355 : {
356 24 : nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
357 : // nRowCount = GetOutputSizePixel().Height() / rItemSize.Height();
358 24 : if (nRowCount < 1)
359 0 : nRowCount = 1;
360 : }
361 :
362 24 : return nRowCount;
363 : }
364 :
365 0 : IMPL_LINK_NOARG(LayoutMenu, ClickHandler)
366 : {
367 0 : AssignLayoutToSelectedSlides (GetSelectedAutoLayout());
368 0 : return 0;
369 : }
370 :
371 : /** The specified layout is assigned to the current page of the view shell
372 : in the center pane.
373 : */
374 0 : void LayoutMenu::AssignLayoutToSelectedSlides (AutoLayout aLayout)
375 : {
376 : using namespace ::sd::slidesorter;
377 : using namespace ::sd::slidesorter::controller;
378 :
379 : do
380 : {
381 : // The view shell in the center pane has to be present.
382 0 : ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
383 0 : if (pMainViewShell == NULL)
384 0 : break;
385 :
386 : // Determine if the current view is in an invalid master page mode.
387 : // The handout view is always in master page mode and therefore not
388 : // invalid.
389 0 : bool bMasterPageMode (false);
390 0 : switch (pMainViewShell->GetShellType())
391 : {
392 : case ViewShell::ST_NOTES:
393 : case ViewShell::ST_IMPRESS:
394 : {
395 0 : DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(pMainViewShell);
396 0 : if (pDrawViewShell != NULL)
397 0 : if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
398 0 : bMasterPageMode = true;
399 : }
400 : default:
401 0 : break;
402 : }
403 0 : if (bMasterPageMode)
404 0 : break;
405 :
406 : // Get a list of all selected slides and call the SID_MODIFYPAGE
407 : // slot for all of them.
408 0 : ::sd::slidesorter::SharedPageSelection pPageSelection;
409 :
410 : // Get a list of selected pages.
411 : // First we try to obtain this list from a slide sorter. This is
412 : // possible only some of the view shells in the center pane. When
413 : // no valid slide sorter is available then ask the main view shell
414 : // for its current page.
415 0 : SlideSorterViewShell* pSlideSorter = NULL;
416 0 : switch (pMainViewShell->GetShellType())
417 : {
418 : case ViewShell::ST_IMPRESS:
419 : case ViewShell::ST_NOTES:
420 : case ViewShell::ST_SLIDE_SORTER:
421 0 : pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
422 0 : break;
423 : default:
424 0 : break;
425 : }
426 0 : if (pSlideSorter != NULL)
427 : {
428 : // There is a slide sorter visible so get the list of selected pages from it.
429 0 : pPageSelection = pSlideSorter->GetPageSelection();
430 : }
431 :
432 0 : if( (pSlideSorter == NULL) || (pPageSelection.get() == 0) || pPageSelection->empty() )
433 : {
434 : // No valid slide sorter available. Ask the main view shell for
435 : // its current page.
436 0 : pPageSelection.reset(new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
437 0 : pPageSelection->push_back(pMainViewShell->GetActualPage());
438 : }
439 :
440 0 : if (pPageSelection->empty())
441 0 : break;
442 :
443 0 : ::std::vector<SdPage*>::iterator iPage;
444 0 : for (iPage=pPageSelection->begin(); iPage!=pPageSelection->end(); ++iPage)
445 : {
446 0 : if ((*iPage) == NULL)
447 0 : continue;
448 :
449 : // Call the SID_ASSIGN_LAYOUT slot with all the necessary parameters.
450 0 : SfxRequest aRequest (mrBase.GetViewFrame(), SID_ASSIGN_LAYOUT);
451 0 : aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATPAGE, ((*iPage)->GetPageNum()-1)/2));
452 0 : aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
453 0 : pMainViewShell->ExecuteSlot (aRequest, false);
454 0 : }
455 : }
456 : while(false);
457 0 : }
458 :
459 0 : SfxRequest LayoutMenu::CreateRequest (
460 : sal_uInt16 nSlotId,
461 : AutoLayout aLayout)
462 : {
463 0 : SfxRequest aRequest (mrBase.GetViewFrame(), nSlotId);
464 :
465 : do
466 : {
467 0 : SdrLayerAdmin& rLayerAdmin (mrBase.GetDocument()->GetLayerAdmin());
468 : sal_uInt8 aBackground (rLayerAdmin.GetLayerID(
469 0 : SD_RESSTR(STR_LAYER_BCKGRND), false));
470 : sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(
471 0 : SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false));
472 0 : ViewShell* pViewShell = mrBase.GetMainViewShell().get();
473 0 : if (pViewShell == NULL)
474 0 : break;
475 0 : SdPage* pPage = pViewShell->GetActualPage();
476 0 : if (pPage == NULL)
477 0 : break;
478 :
479 0 : SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
480 :
481 : aRequest.AppendItem(
482 0 : SfxStringItem (ID_VAL_PAGENAME, OUString()));//pPage->GetName()));
483 0 : aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
484 : aRequest.AppendItem(
485 0 : SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
486 : aRequest.AppendItem(
487 : SfxBoolItem(
488 : ID_VAL_ISPAGEOBJ,
489 0 : aVisibleLayers.IsSet(aBackgroundObject)));
490 : }
491 : while (false);
492 :
493 0 : return aRequest;
494 : }
495 :
496 48 : void LayoutMenu::Fill (void)
497 : {
498 48 : SvtLanguageOptions aLanguageOptions;
499 48 : bool bVertical = aLanguageOptions.IsVerticalTextEnabled();
500 48 : SdDrawDocument* pDocument = mrBase.GetDocument();
501 : bool bRightToLeft = (pDocument!=NULL
502 48 : && pDocument->GetDefaultWritingMode() == WritingMode_RL_TB);
503 :
504 : // Get URL of the view in the center pane.
505 96 : OUString sCenterPaneViewName;
506 : try
507 : {
508 : Reference<XControllerManager> xControllerManager (
509 48 : Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY_THROW);
510 : Reference<XResourceId> xPaneId (ResourceId::create(
511 : ::comphelper::getProcessComponentContext(),
512 96 : FrameworkHelper::msCenterPaneURL));
513 96 : Reference<XView> xView (FrameworkHelper::Instance(mrBase)->GetView(xPaneId));
514 48 : if (xView.is())
515 96 : sCenterPaneViewName = xView->getResourceId()->getResourceURL();
516 : }
517 0 : catch (RuntimeException&)
518 : {}
519 :
520 48 : const snewfoil_value_info* pInfo = NULL;
521 48 : if (sCenterPaneViewName.equals(framework::FrameworkHelper::msNotesViewURL))
522 : {
523 0 : pInfo = notes;
524 : }
525 48 : else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msHandoutViewURL))
526 : {
527 0 : pInfo = handout;
528 : }
529 96 : else if (sCenterPaneViewName.equals(framework::FrameworkHelper::msImpressViewURL)
530 48 : || sCenterPaneViewName.equals(framework::FrameworkHelper::msSlideSorterURL))
531 : {
532 48 : pInfo = standard;
533 : }
534 : else
535 : {
536 0 : pInfo = NULL;
537 : }
538 :
539 48 : Clear();
540 48 : int n = 0;
541 816 : for (sal_uInt16 i=1; pInfo!=NULL&&pInfo->mnBmpResId!=0; i++,pInfo++)
542 : {
543 768 : if ((WritingMode_TB_RL != pInfo->meWritingMode) || bVertical)
544 : {
545 768 : BitmapEx aBmp(SdResId(pInfo->mnBmpResId));
546 :
547 768 : if (GetDPIScaleFactor() > 1)
548 0 : aBmp.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BMP_SCALE_FAST);
549 :
550 768 : if (bRightToLeft && (WritingMode_TB_RL != pInfo->meWritingMode))
551 0 : aBmp.Mirror (BMP_MIRROR_HORZ);
552 :
553 768 : InsertItem(i, Image(aBmp), SdResId (pInfo->mnStrResId));
554 768 : SetItemData (i, new AutoLayout(pInfo->maAutoLayout));
555 768 : n++;
556 : }
557 : }
558 :
559 96 : mbSelectionUpdatePending = true;
560 48 : }
561 :
562 72 : void LayoutMenu::Clear (void)
563 : {
564 840 : for (sal_uInt16 nId=1; nId<=GetItemCount(); nId++)
565 768 : delete static_cast<AutoLayout*>(GetItemData(nId));
566 72 : ValueSet::Clear();
567 72 : }
568 :
569 0 : void LayoutMenu::StartDrag (sal_Int8 , const Point& )
570 : {
571 0 : }
572 :
573 0 : sal_Int8 LayoutMenu::AcceptDrop (const AcceptDropEvent& )
574 : {
575 0 : return 0;
576 : }
577 :
578 0 : sal_Int8 LayoutMenu::ExecuteDrop (const ExecuteDropEvent& )
579 : {
580 0 : return 0;
581 : }
582 :
583 0 : void LayoutMenu::Command (const CommandEvent& rEvent)
584 : {
585 0 : switch (rEvent.GetCommand())
586 : {
587 : case COMMAND_CONTEXTMENU:
588 0 : if ( ! SD_MOD()->GetWaterCan())
589 : {
590 : // Determine the position where to show the menu.
591 0 : Point aMenuPosition;
592 0 : if (rEvent.IsMouseEvent())
593 : {
594 0 : if (GetItemId(rEvent.GetMousePosPixel()) <= 0)
595 0 : return;
596 0 : aMenuPosition = rEvent.GetMousePosPixel();
597 : }
598 : else
599 : {
600 0 : if (GetSelectItemId() == (sal_uInt16)-1)
601 0 : return;
602 0 : Rectangle aBBox (GetItemRect(GetSelectItemId()));
603 0 : aMenuPosition = aBBox.Center();
604 : }
605 :
606 : // Setup the menu.
607 0 : ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu(SdResId(RID_TASKPANE_LAYOUTMENU_POPUP)));
608 0 : FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
609 0 : if (pMenuWindow != NULL)
610 : pMenuWindow->SetPopupModeFlags(
611 0 : pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE);
612 0 : pMenu->SetSelectHdl(LINK(this, LayoutMenu, OnMenuItemSelected));
613 :
614 : // Disable the SID_INSERTPAGE_LAYOUT_MENU item when
615 : // the document is read-only.
616 0 : const SfxPoolItem* pItem = NULL;
617 : const SfxItemState aState (
618 0 : mrBase.GetViewFrame()->GetDispatcher()->QueryState(SID_INSERTPAGE, pItem));
619 0 : if (aState == SfxItemState::DISABLED)
620 0 : pMenu->EnableItem(SID_INSERTPAGE_LAYOUT_MENU, false);
621 :
622 : // Show the menu.
623 0 : pMenu->Execute(this, Rectangle(aMenuPosition,Size(1,1)), POPUPMENU_EXECUTE_DOWN);
624 : }
625 0 : break;
626 :
627 : default:
628 0 : ValueSet::Command(rEvent);
629 0 : break;
630 : }
631 : }
632 :
633 48 : IMPL_LINK_NOARG(LayoutMenu, StateChangeHandler)
634 : {
635 24 : InvalidateContent();
636 24 : return 0;
637 : }
638 :
639 0 : IMPL_LINK(LayoutMenu, OnMenuItemSelected, Menu*, pMenu)
640 : {
641 0 : if (pMenu == NULL)
642 : {
643 : OSL_ENSURE(pMenu!=NULL, "LayoutMenu::OnMenuItemSelected: illegal menu!");
644 0 : return 0;
645 : }
646 :
647 0 : pMenu->Deactivate();
648 0 : const sal_Int32 nIndex (pMenu->GetCurItemId());
649 :
650 0 : if (nIndex == SID_TP_APPLY_TO_SELECTED_SLIDES)
651 : {
652 0 : AssignLayoutToSelectedSlides(GetSelectedAutoLayout());
653 : }
654 0 : else if (nIndex == SID_INSERTPAGE_LAYOUT_MENU)
655 : {
656 : // Add arguments to this slot and forward it to the main view
657 : // shell.
658 0 : InsertPageWithLayout(GetSelectedAutoLayout());
659 : }
660 :
661 0 : return 0;
662 : }
663 :
664 18 : void LayoutMenu::UpdateSelection (void)
665 : {
666 18 : bool bItemSelected = false;
667 :
668 : do
669 : {
670 : // Get current page of main view.
671 18 : ViewShell* pViewShell = mrBase.GetMainViewShell().get();
672 18 : if (pViewShell == NULL)
673 0 : break;
674 :
675 18 : SdPage* pCurrentPage = pViewShell->getCurrentPage();
676 18 : if (pCurrentPage == NULL)
677 0 : break;
678 :
679 : // Get layout of current page.
680 18 : AutoLayout aLayout (pCurrentPage->GetAutoLayout());
681 18 : if (aLayout<AUTOLAYOUT__START || aLayout>AUTOLAYOUT__END)
682 : break;
683 :
684 : // Find the entry of the menu for to the layout.
685 18 : SetNoSelection();
686 18 : sal_uInt16 nItemCount (GetItemCount());
687 36 : for (sal_uInt16 nId=1; nId<=nItemCount; nId++)
688 : {
689 36 : if (*static_cast<AutoLayout*>(GetItemData(nId)) == aLayout)
690 : {
691 18 : SelectItem(nId);
692 18 : bItemSelected = true;
693 18 : break;
694 : }
695 : }
696 : }
697 : while (false);
698 :
699 18 : if ( ! bItemSelected)
700 0 : SetNoSelection();
701 18 : }
702 :
703 580 : IMPL_LINK(LayoutMenu, EventMultiplexerListener, ::sd::tools::EventMultiplexerEvent*, pEvent)
704 : {
705 290 : switch (pEvent->meEventId)
706 : {
707 : case ::sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
708 : case ::sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
709 0 : if ( ! mbSelectionUpdatePending)
710 0 : UpdateSelection();
711 0 : break;
712 :
713 : case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
714 0 : mbIsMainViewChangePending = true;
715 0 : break;
716 :
717 : case ::sd::tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
718 24 : HideFocus();
719 24 : break;
720 :
721 : case ::sd::tools::EventMultiplexerEvent::EID_CONFIGURATION_UPDATED:
722 69 : if (mbIsMainViewChangePending)
723 : {
724 0 : mbIsMainViewChangePending = false;
725 0 : InvalidateContent();
726 : }
727 69 : break;
728 :
729 : default:
730 : /* Ignored */
731 197 : break;
732 : }
733 :
734 290 : return 0;
735 : }
736 :
737 362 : IMPL_LINK(LayoutMenu, WindowEventHandler, VclWindowEvent*, pEvent)
738 : {
739 181 : if (pEvent != NULL)
740 : {
741 181 : switch (pEvent->GetId())
742 : {
743 : case VCLEVENT_WINDOW_SHOW:
744 : case VCLEVENT_WINDOW_RESIZE:
745 78 : SetSizePixel(GetParent()->GetSizePixel());
746 78 : return sal_True;
747 :
748 : default:
749 103 : return sal_False;
750 : }
751 : }
752 :
753 0 : return sal_False;
754 : }
755 :
756 0 : void LayoutMenu::DataChanged (const DataChangedEvent& rEvent)
757 : {
758 0 : Fill();
759 0 : ValueSet::DataChanged(rEvent);
760 0 : SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
761 0 : SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
762 0 : }
763 :
764 114 : } } // end of namespace ::sd::sidebar
765 :
766 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|