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 :
21 : #include "ViewShellImplementation.hxx"
22 :
23 : #include "sdpage.hxx"
24 : #include "drawdoc.hxx"
25 : #include "sdresid.hxx"
26 : #include "glob.hrc"
27 : #include "app.hrc"
28 : #include "strings.hrc"
29 : #include "helpids.h"
30 : #include "sdattr.hxx"
31 : #include "sdabstdlg.hxx"
32 : #include "unmodpg.hxx"
33 : #include "Window.hxx"
34 : #include "optsitem.hxx"
35 : #include "DrawDocShell.hxx"
36 : #include "DrawController.hxx"
37 : #include "FactoryIds.hxx"
38 : #include "slideshow.hxx"
39 : #include "ViewShellBase.hxx"
40 : #include "FrameView.hxx"
41 : #include "DrawViewShell.hxx"
42 : #include "ViewShellHint.hxx"
43 : #include "taskpane/PanelId.hxx"
44 : #include "SidebarPanelId.hxx"
45 : #include "framework/FrameworkHelper.hxx"
46 :
47 : #include <sfx2/bindings.hxx>
48 : #include <sfx2/dispatch.hxx>
49 : #include <sfx2/request.hxx>
50 : #include <svl/aeitem.hxx>
51 : #include <svx/imapdlg.hxx>
52 : #include <vcl/msgbox.hxx>
53 : #include <basic/sbstar.hxx>
54 : #include "undo/undoobjects.hxx"
55 :
56 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
57 :
58 : using namespace ::com::sun::star::uno;
59 : using namespace ::com::sun::star::drawing::framework;
60 : using ::sd::framework::FrameworkHelper;
61 :
62 : namespace sd {
63 :
64 143 : ViewShell::Implementation::Implementation (ViewShell& rViewShell)
65 : : mbIsShowingUIControls(false),
66 : mbIsMainViewShell(false),
67 : mbIsInitialized(false),
68 : mbArrangeActive(false),
69 : mpSubShellFactory(),
70 : mpUpdateLockForMouse(),
71 143 : mrViewShell(rViewShell)
72 : {
73 143 : }
74 :
75 :
76 :
77 :
78 286 : ViewShell::Implementation::~Implementation (void)
79 : {
80 143 : if ( ! mpUpdateLockForMouse.expired())
81 : {
82 0 : ::boost::shared_ptr<ToolBarManagerLock> pLock(mpUpdateLockForMouse);
83 0 : if (pLock.get() != NULL)
84 : {
85 : // Force the ToolBarManagerLock to be released even when the
86 : // IsUICaptured() returns <TRUE/>.
87 0 : pLock->Release(true);
88 0 : }
89 : }
90 143 : }
91 :
92 :
93 :
94 :
95 0 : void ViewShell::Implementation::ProcessModifyPageSlot (
96 : SfxRequest& rRequest,
97 : SdPage* pCurrentPage,
98 : PageKind ePageKind)
99 : {
100 0 : SdDrawDocument* pDocument = mrViewShell.GetDoc();
101 0 : SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
102 0 : sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
103 0 : sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
104 0 : SetOfByte aVisibleLayers;
105 0 : sal_Bool bHandoutMode = sal_False;
106 0 : SdPage* pHandoutMPage = NULL;
107 0 : String aNewName;
108 :
109 : AutoLayout aNewAutoLayout;
110 :
111 : sal_Bool bBVisible;
112 : sal_Bool bBObjsVisible;
113 0 : const SfxItemSet* pArgs = rRequest.GetArgs();
114 :
115 0 : if (pCurrentPage != NULL && pCurrentPage->TRG_HasMasterPage())
116 0 : aVisibleLayers = pCurrentPage->TRG_GetMasterPageVisibleLayers();
117 : else
118 0 : aVisibleLayers.SetAll();
119 :
120 : do
121 : {
122 0 : if (pCurrentPage == NULL)
123 0 : break;
124 :
125 0 : if (!pArgs || pArgs->Count() == 1 || pArgs->Count() == 2 )
126 : {
127 :
128 : // Make the layout menu visible in the tool pane.
129 0 : SfxBoolItem aMakeToolPaneVisible (ID_VAL_ISVISIBLE, sal_True);
130 0 : SfxUInt32Item aPanelId (ID_VAL_PANEL_INDEX, sidebar::PID_LAYOUT);
131 0 : SfxViewFrame* pFrame = mrViewShell.GetViewFrame();
132 0 : if (pFrame!=NULL && pFrame->GetDispatcher()!=NULL)
133 : {
134 : pFrame->GetDispatcher()->Execute (
135 : SID_SHOW_TOOL_PANEL,
136 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
137 : &aMakeToolPaneVisible,
138 : &aPanelId,
139 0 : NULL);
140 : }
141 : else
142 : {
143 : DBG_ASSERT(pFrame!=NULL && pFrame->GetDispatcher()!=NULL,
144 : "ViewShell::Implementation::ProcessModifyPageSlot(): can not get dispatcher");
145 : }
146 :
147 : // We have activated a non-modal control in the task pane.
148 : // Because it does not return anything we can not do anything
149 : // more right now and have to exit here.
150 0 : break;
151 : }
152 0 : else if (pArgs->Count() == 4)
153 : {
154 0 : SFX_REQUEST_ARG (rRequest, pNewName, SfxStringItem, ID_VAL_PAGENAME, sal_False);
155 0 : SFX_REQUEST_ARG (rRequest, pNewAutoLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, sal_False);
156 0 : SFX_REQUEST_ARG (rRequest, pBVisible, SfxBoolItem, ID_VAL_ISPAGEBACK, sal_False);
157 0 : SFX_REQUEST_ARG (rRequest, pBObjsVisible, SfxBoolItem, ID_VAL_ISPAGEOBJ, sal_False);
158 0 : AutoLayout aLayout ((AutoLayout)pNewAutoLayout->GetValue ());
159 0 : if (aLayout >= AUTOLAYOUT__START
160 0 : && aLayout < AUTOLAYOUT__END)
161 : {
162 0 : aNewName = pNewName->GetValue ();
163 0 : aNewAutoLayout = (AutoLayout) pNewAutoLayout->GetValue ();
164 0 : bBVisible = pBVisible->GetValue ();
165 0 : bBObjsVisible = pBObjsVisible->GetValue ();
166 : }
167 : else
168 : {
169 : #ifndef DISABLE_SCRIPTING
170 0 : StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
171 : #endif
172 0 : rRequest.Ignore ();
173 0 : break;
174 : }
175 0 : if (ePageKind == PK_HANDOUT)
176 : {
177 0 : bHandoutMode = sal_True;
178 0 : pHandoutMPage = pDocument->GetMasterSdPage(0, PK_HANDOUT);
179 : }
180 : }
181 : else
182 : {
183 : #ifndef DISABLE_SCRIPTING
184 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
185 : #endif
186 0 : rRequest.Ignore ();
187 0 : break;
188 : }
189 :
190 : SdPage* pUndoPage =
191 0 : bHandoutMode ? pHandoutMPage : pCurrentPage;
192 :
193 0 : ::svl::IUndoManager* pUndoManager = mrViewShell.GetDocSh()->GetUndoManager();
194 : DBG_ASSERT(pUndoManager, "No UNDO MANAGER ?!?");
195 :
196 0 : if( pUndoManager )
197 : {
198 0 : String aComment( SdResId(STR_UNDO_MODIFY_PAGE) );
199 0 : pUndoManager->EnterListAction(aComment, aComment);
200 : ModifyPageUndoAction* pAction = new ModifyPageUndoAction(
201 0 : pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible);
202 0 : pUndoManager->AddUndoAction(pAction);
203 :
204 : // Clear the selection because the selectec object may be removed as
205 : // a result of the ssignment of the layout.
206 0 : mrViewShell.GetDrawView()->UnmarkAll();
207 :
208 0 : if (!bHandoutMode)
209 : {
210 0 : if (pCurrentPage->GetName() != aNewName)
211 : {
212 0 : pCurrentPage->SetName(aNewName);
213 :
214 0 : if (ePageKind == PK_STANDARD)
215 : {
216 0 : sal_uInt16 nPage = (pCurrentPage->GetPageNum()-1) / 2;
217 0 : SdPage* pNotesPage = pDocument->GetSdPage(nPage, PK_NOTES);
218 0 : if (pNotesPage != NULL)
219 0 : pNotesPage->SetName(aNewName);
220 : }
221 : }
222 :
223 0 : pCurrentPage->SetAutoLayout(aNewAutoLayout, sal_True);
224 :
225 0 : aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
226 0 : aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
227 0 : aVisibleLayers.Set(aBckgrnd, bBVisible);
228 0 : aVisibleLayers.Set(aBckgrndObj, bBObjsVisible);
229 0 : pCurrentPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
230 : }
231 : else
232 : {
233 0 : pHandoutMPage->SetAutoLayout(aNewAutoLayout, sal_True);
234 : }
235 :
236 : mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
237 0 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
238 :
239 0 : sal_Bool bSetModified = sal_True;
240 :
241 0 : if (pArgs && pArgs->Count() == 1)
242 : {
243 0 : bSetModified = (sal_Bool) ((SfxBoolItem&) pArgs->Get(SID_MODIFYPAGE)).GetValue();
244 : }
245 :
246 0 : pUndoManager->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage ) );
247 0 : pUndoManager->LeaveListAction();
248 :
249 0 : pDocument->SetChanged(bSetModified);
250 : }
251 : }
252 : while (false);
253 :
254 0 : mrViewShell.Cancel();
255 0 : rRequest.Done ();
256 0 : }
257 :
258 0 : void ViewShell::Implementation::AssignLayout ( SfxRequest& rRequest, PageKind ePageKind )
259 : {
260 0 : const SfxUInt32Item* pWhatPage = static_cast< const SfxUInt32Item* > ( rRequest.GetArg( ID_VAL_WHATPAGE, sal_False, TYPE(SfxUInt32Item) ) );
261 0 : const SfxUInt32Item* pWhatLayout = static_cast< const SfxUInt32Item* > ( rRequest.GetArg( ID_VAL_WHATLAYOUT, sal_False, TYPE(SfxUInt32Item) ) );
262 :
263 0 : SdDrawDocument* pDocument = mrViewShell.GetDoc();
264 0 : if( !pDocument )
265 0 : return;
266 :
267 0 : SdPage* pPage = 0;
268 0 : if( pWhatPage )
269 : {
270 0 : pPage = pDocument->GetSdPage(static_cast<sal_uInt16>(pWhatPage->GetValue()), ePageKind);
271 : }
272 :
273 0 : if( pPage == 0 )
274 0 : pPage = mrViewShell.getCurrentPage();
275 :
276 0 : if( pPage )
277 : {
278 0 : AutoLayout eLayout = pPage->GetAutoLayout();
279 :
280 0 : if( pWhatLayout )
281 0 : eLayout = static_cast< AutoLayout >( pWhatLayout->GetValue() );
282 :
283 : // Transform the given request into the four argument form that is
284 : // understood by ProcessModifyPageSlot().
285 0 : SdrLayerAdmin& rLayerAdmin (mrViewShell.GetViewShellBase().GetDocument()->GetLayerAdmin());
286 0 : sal_uInt8 aBackground (rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False));
287 0 : sal_uInt8 aBackgroundObject (rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False));
288 :
289 0 : SetOfByte aVisibleLayers;
290 :
291 0 : if( pPage->GetPageKind() == PK_HANDOUT )
292 0 : aVisibleLayers.SetAll();
293 : else
294 0 : aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
295 :
296 0 : SfxRequest aRequest (mrViewShell.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE);
297 0 : aRequest.AppendItem(SfxStringItem (ID_VAL_PAGENAME, pPage->GetName()));
298 0 : aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, eLayout));
299 0 : aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
300 0 : aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ, aVisibleLayers.IsSet(aBackgroundObject)));
301 :
302 : // Forward the call with the new arguments.
303 0 : ProcessModifyPageSlot( aRequest, pPage, pPage->GetPageKind());
304 : }
305 : }
306 :
307 :
308 :
309 :
310 67 : sal_uInt16 ViewShell::Implementation::GetViewId (void)
311 : {
312 67 : switch (mrViewShell.GetShellType())
313 : {
314 : case ViewShell::ST_IMPRESS:
315 : case ViewShell::ST_NOTES:
316 : case ViewShell::ST_HANDOUT:
317 13 : return IMPRESS_FACTORY_ID;
318 :
319 : case ViewShell::ST_DRAW:
320 54 : return DRAW_FACTORY_ID;
321 :
322 : case ViewShell::ST_OUTLINE:
323 0 : return OUTLINE_FACTORY_ID;
324 :
325 : case ViewShell::ST_SLIDE_SORTER:
326 0 : return SLIDE_SORTER_FACTORY_ID;
327 :
328 : case ViewShell::ST_PRESENTATION:
329 0 : return PRESENTATION_FACTORY_ID;
330 :
331 : // Since we have to return a view id for every possible shell type
332 : // and there is not (yet) a proper ViewShellBase sub class for the
333 : // remaining types we chose the Impress factory as a fall back.
334 : case ViewShell::ST_TASK_PANE:
335 : case ViewShell::ST_SIDEBAR:
336 : case ViewShell::ST_NONE:
337 : default:
338 0 : return IMPRESS_FACTORY_ID;
339 : }
340 : }
341 :
342 :
343 :
344 :
345 0 : SvxIMapDlg* ViewShell::Implementation::GetImageMapDialog (void)
346 : {
347 0 : SvxIMapDlg* pDialog = NULL;
348 : SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
349 0 : SvxIMapDlgChildWindow::GetChildWindowId());
350 0 : if (pChildWindow != NULL)
351 0 : pDialog = dynamic_cast<SvxIMapDlg*>(pChildWindow->GetWindow());
352 0 : return pDialog;
353 : }
354 :
355 :
356 :
357 : //===== ToolBarManagerLock ====================================================
358 :
359 : class ViewShell::Implementation::ToolBarManagerLock::Deleter { public:
360 0 : void operator() (ToolBarManagerLock* pObject) { delete pObject; }
361 : };
362 :
363 : ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock>
364 0 : ViewShell::Implementation::ToolBarManagerLock::Create (
365 : const ::boost::shared_ptr<ToolBarManager>& rpManager)
366 : {
367 : ::boost::shared_ptr<ToolBarManagerLock> pLock (
368 0 : new ViewShell::Implementation::ToolBarManagerLock(rpManager),
369 0 : ViewShell::Implementation::ToolBarManagerLock::Deleter());
370 0 : pLock->mpSelf = pLock;
371 0 : return pLock;
372 : }
373 :
374 :
375 :
376 :
377 0 : ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
378 : const ::boost::shared_ptr<ToolBarManager>& rpManager)
379 0 : : mpLock(new ToolBarManager::UpdateLock(rpManager)),
380 0 : maTimer()
381 : {
382 : // Start a timer that will unlock the ToolBarManager update lock when
383 : // that is not done explicitly by calling Release().
384 0 : maTimer.SetTimeoutHdl(LINK(this,ToolBarManagerLock,TimeoutCallback));
385 0 : maTimer.SetTimeout(100);
386 0 : maTimer.Start();
387 0 : }
388 :
389 :
390 :
391 :
392 0 : IMPL_LINK_NOARG(ViewShell::Implementation::ToolBarManagerLock, TimeoutCallback)
393 : {
394 : // If possible then release the lock now. Otherwise start the timer
395 : // and try again later.
396 0 : if (Application::IsUICaptured())
397 : {
398 0 : maTimer.Start();
399 : }
400 : else
401 : {
402 0 : mpSelf.reset();
403 : }
404 0 : return 0;
405 : }
406 :
407 :
408 :
409 :
410 0 : void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce)
411 : {
412 : // If possible then release the lock now. Otherwise try again when the
413 : // timer expires.
414 0 : if (bForce || ! Application::IsUICaptured())
415 : {
416 0 : mpSelf.reset();
417 : }
418 0 : }
419 :
420 :
421 :
422 :
423 0 : ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock (void)
424 : {
425 0 : mpLock.reset();
426 0 : }
427 :
428 33 : } // end of namespace sd
429 :
430 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|