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