1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "ViewShellImplementation.hxx"
24 #include "drawdoc.hxx"
25 #include "sdresid.hxx"
28 #include "strings.hrc"
31 #include "sdabstdlg.hxx"
32 #include "unmodpg.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"
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"
56 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::drawing::framework
;
60 using ::sd::framework::FrameworkHelper
;
64 ViewShell::Implementation::Implementation (ViewShell
& rViewShell
)
65 : mbIsShowingUIControls(false),
66 mbIsMainViewShell(false),
67 mbIsInitialized(false),
68 mbArrangeActive(false),
70 mpUpdateLockForMouse(),
71 mrViewShell(rViewShell
)
78 ViewShell::Implementation::~Implementation (void)
80 if ( ! mpUpdateLockForMouse
.expired())
82 ::boost::shared_ptr
<ToolBarManagerLock
> pLock(mpUpdateLockForMouse
);
83 if (pLock
.get() != NULL
)
85 // Force the ToolBarManagerLock to be released even when the
86 // IsUICaptured() returns <TRUE/>.
95 void ViewShell::Implementation::ProcessModifyPageSlot (
100 SdDrawDocument
* pDocument
= mrViewShell
.GetDoc();
101 SdrLayerAdmin
& rLayerAdmin
= pDocument
->GetLayerAdmin();
102 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
);
103 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
);
104 SetOfByte aVisibleLayers
;
105 sal_Bool bHandoutMode
= sal_False
;
106 SdPage
* pHandoutMPage
= NULL
;
109 AutoLayout aNewAutoLayout
;
112 sal_Bool bBObjsVisible
;
113 const SfxItemSet
* pArgs
= rRequest
.GetArgs();
115 if (pCurrentPage
!= NULL
&& pCurrentPage
->TRG_HasMasterPage())
116 aVisibleLayers
= pCurrentPage
->TRG_GetMasterPageVisibleLayers();
118 aVisibleLayers
.SetAll();
122 if (pCurrentPage
== NULL
)
125 if (!pArgs
|| pArgs
->Count() == 1 || pArgs
->Count() == 2 )
128 // Make the layout menu visible in the tool pane.
129 SfxBoolItem
aMakeToolPaneVisible (ID_VAL_ISVISIBLE
, sal_True
);
130 SfxUInt32Item
aPanelId (ID_VAL_PANEL_INDEX
, sidebar::PID_LAYOUT
);
131 SfxViewFrame
* pFrame
= mrViewShell
.GetViewFrame();
132 if (pFrame
!=NULL
&& pFrame
->GetDispatcher()!=NULL
)
134 pFrame
->GetDispatcher()->Execute (
136 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
137 &aMakeToolPaneVisible
,
143 DBG_ASSERT(pFrame
!=NULL
&& pFrame
->GetDispatcher()!=NULL
,
144 "ViewShell::Implementation::ProcessModifyPageSlot(): can not get dispatcher");
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.
152 else if (pArgs
->Count() == 4)
154 SFX_REQUEST_ARG (rRequest
, pNewName
, SfxStringItem
, ID_VAL_PAGENAME
, sal_False
);
155 SFX_REQUEST_ARG (rRequest
, pNewAutoLayout
, SfxUInt32Item
, ID_VAL_WHATLAYOUT
, sal_False
);
156 SFX_REQUEST_ARG (rRequest
, pBVisible
, SfxBoolItem
, ID_VAL_ISPAGEBACK
, sal_False
);
157 SFX_REQUEST_ARG (rRequest
, pBObjsVisible
, SfxBoolItem
, ID_VAL_ISPAGEOBJ
, sal_False
);
158 AutoLayout
aLayout ((AutoLayout
)pNewAutoLayout
->GetValue ());
159 if (aLayout
>= AUTOLAYOUT__START
160 && aLayout
< AUTOLAYOUT__END
)
162 aNewName
= pNewName
->GetValue ();
163 aNewAutoLayout
= (AutoLayout
) pNewAutoLayout
->GetValue ();
164 bBVisible
= pBVisible
->GetValue ();
165 bBObjsVisible
= pBObjsVisible
->GetValue ();
169 #ifndef DISABLE_SCRIPTING
170 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE
);
175 if (ePageKind
== PK_HANDOUT
)
177 bHandoutMode
= sal_True
;
178 pHandoutMPage
= pDocument
->GetMasterSdPage(0, PK_HANDOUT
);
183 #ifndef DISABLE_SCRIPTING
184 StarBASIC::FatalError (SbERR_WRONG_ARGS
);
191 bHandoutMode
? pHandoutMPage
: pCurrentPage
;
193 ::svl::IUndoManager
* pUndoManager
= mrViewShell
.GetDocSh()->GetUndoManager();
194 DBG_ASSERT(pUndoManager
, "No UNDO MANAGER ?!?");
198 String
aComment( SdResId(STR_UNDO_MODIFY_PAGE
) );
199 pUndoManager
->EnterListAction(aComment
, aComment
);
200 ModifyPageUndoAction
* pAction
= new ModifyPageUndoAction(
201 pDocument
, pUndoPage
, aNewName
, aNewAutoLayout
, bBVisible
, bBObjsVisible
);
202 pUndoManager
->AddUndoAction(pAction
);
204 // Clear the selection because the selectec object may be removed as
205 // a result of the ssignment of the layout.
206 mrViewShell
.GetDrawView()->UnmarkAll();
210 if (pCurrentPage
->GetName() != aNewName
)
212 pCurrentPage
->SetName(aNewName
);
214 if (ePageKind
== PK_STANDARD
)
216 sal_uInt16 nPage
= (pCurrentPage
->GetPageNum()-1) / 2;
217 SdPage
* pNotesPage
= pDocument
->GetSdPage(nPage
, PK_NOTES
);
218 if (pNotesPage
!= NULL
)
219 pNotesPage
->SetName(aNewName
);
223 pCurrentPage
->SetAutoLayout(aNewAutoLayout
, sal_True
);
225 aBckgrnd
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
);
226 aBckgrndObj
= rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
);
227 aVisibleLayers
.Set(aBckgrnd
, bBVisible
);
228 aVisibleLayers
.Set(aBckgrndObj
, bBObjsVisible
);
229 pCurrentPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
233 pHandoutMPage
->SetAutoLayout(aNewAutoLayout
, sal_True
);
236 mrViewShell
.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE
,
237 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
239 sal_Bool bSetModified
= sal_True
;
241 if (pArgs
&& pArgs
->Count() == 1)
243 bSetModified
= (sal_Bool
) ((SfxBoolItem
&) pArgs
->Get(SID_MODIFYPAGE
)).GetValue();
246 pUndoManager
->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage
) );
247 pUndoManager
->LeaveListAction();
249 pDocument
->SetChanged(bSetModified
);
254 mrViewShell
.Cancel();
258 void ViewShell::Implementation::AssignLayout ( SfxRequest
& rRequest
, PageKind ePageKind
)
260 const SfxUInt32Item
* pWhatPage
= static_cast< const SfxUInt32Item
* > ( rRequest
.GetArg( ID_VAL_WHATPAGE
, sal_False
, TYPE(SfxUInt32Item
) ) );
261 const SfxUInt32Item
* pWhatLayout
= static_cast< const SfxUInt32Item
* > ( rRequest
.GetArg( ID_VAL_WHATLAYOUT
, sal_False
, TYPE(SfxUInt32Item
) ) );
263 SdDrawDocument
* pDocument
= mrViewShell
.GetDoc();
270 pPage
= pDocument
->GetSdPage(static_cast<sal_uInt16
>(pWhatPage
->GetValue()), ePageKind
);
274 pPage
= mrViewShell
.getCurrentPage();
278 AutoLayout eLayout
= pPage
->GetAutoLayout();
281 eLayout
= static_cast< AutoLayout
>( pWhatLayout
->GetValue() );
283 // Transform the given request into the four argument form that is
284 // understood by ProcessModifyPageSlot().
285 SdrLayerAdmin
& rLayerAdmin (mrViewShell
.GetViewShellBase().GetDocument()->GetLayerAdmin());
286 sal_uInt8
aBackground (rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRND
)), sal_False
));
287 sal_uInt8
aBackgroundObject (rLayerAdmin
.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ
)), sal_False
));
289 SetOfByte aVisibleLayers
;
291 if( pPage
->GetPageKind() == PK_HANDOUT
)
292 aVisibleLayers
.SetAll();
294 aVisibleLayers
= pPage
->TRG_GetMasterPageVisibleLayers();
296 SfxRequest
aRequest (mrViewShell
.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE
);
297 aRequest
.AppendItem(SfxStringItem (ID_VAL_PAGENAME
, pPage
->GetName()));
298 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, eLayout
));
299 aRequest
.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK
, aVisibleLayers
.IsSet(aBackground
)));
300 aRequest
.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ
, aVisibleLayers
.IsSet(aBackgroundObject
)));
302 // Forward the call with the new arguments.
303 ProcessModifyPageSlot( aRequest
, pPage
, pPage
->GetPageKind());
310 sal_uInt16
ViewShell::Implementation::GetViewId (void)
312 switch (mrViewShell
.GetShellType())
314 case ViewShell::ST_IMPRESS
:
315 case ViewShell::ST_NOTES
:
316 case ViewShell::ST_HANDOUT
:
317 return IMPRESS_FACTORY_ID
;
319 case ViewShell::ST_DRAW
:
320 return DRAW_FACTORY_ID
;
322 case ViewShell::ST_OUTLINE
:
323 return OUTLINE_FACTORY_ID
;
325 case ViewShell::ST_SLIDE_SORTER
:
326 return SLIDE_SORTER_FACTORY_ID
;
328 case ViewShell::ST_PRESENTATION
:
329 return PRESENTATION_FACTORY_ID
;
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
:
338 return IMPRESS_FACTORY_ID
;
345 SvxIMapDlg
* ViewShell::Implementation::GetImageMapDialog (void)
347 SvxIMapDlg
* pDialog
= NULL
;
348 SfxChildWindow
* pChildWindow
= SfxViewFrame::Current()->GetChildWindow(
349 SvxIMapDlgChildWindow::GetChildWindowId());
350 if (pChildWindow
!= NULL
)
351 pDialog
= dynamic_cast<SvxIMapDlg
*>(pChildWindow
->GetWindow());
357 //===== ToolBarManagerLock ====================================================
359 class ViewShell::Implementation::ToolBarManagerLock::Deleter
{ public:
360 void operator() (ToolBarManagerLock
* pObject
) { delete pObject
; }
363 ::boost::shared_ptr
<ViewShell::Implementation::ToolBarManagerLock
>
364 ViewShell::Implementation::ToolBarManagerLock::Create (
365 const ::boost::shared_ptr
<ToolBarManager
>& rpManager
)
367 ::boost::shared_ptr
<ToolBarManagerLock
> pLock (
368 new ViewShell::Implementation::ToolBarManagerLock(rpManager
),
369 ViewShell::Implementation::ToolBarManagerLock::Deleter());
370 pLock
->mpSelf
= pLock
;
377 ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
378 const ::boost::shared_ptr
<ToolBarManager
>& rpManager
)
379 : mpLock(new ToolBarManager::UpdateLock(rpManager
)),
382 // Start a timer that will unlock the ToolBarManager update lock when
383 // that is not done explicitly by calling Release().
384 maTimer
.SetTimeoutHdl(LINK(this,ToolBarManagerLock
,TimeoutCallback
));
385 maTimer
.SetTimeout(100);
392 IMPL_LINK_NOARG(ViewShell::Implementation::ToolBarManagerLock
, TimeoutCallback
)
394 // If possible then release the lock now. Otherwise start the timer
395 // and try again later.
396 if (Application::IsUICaptured())
410 void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce
)
412 // If possible then release the lock now. Otherwise try again when the
414 if (bForce
|| ! Application::IsUICaptured())
423 ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock (void)
428 } // end of namespace sd
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */