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