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 .
20 #include <config_features.h>
22 #include "ViewShellImplementation.hxx"
25 #include "drawdoc.hxx"
26 #include "sdresid.hxx"
29 #include "strings.hrc"
32 #include "sdabstdlg.hxx"
33 #include "unmodpg.hxx"
35 #include "optsitem.hxx"
36 #include "DrawDocShell.hxx"
37 #include "DrawController.hxx"
38 #include "FactoryIds.hxx"
39 #include "slideshow.hxx"
40 #include "ViewShellBase.hxx"
41 #include "FrameView.hxx"
42 #include "DrawViewShell.hxx"
43 #include "ViewShellHint.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 <sfx2/sidebar/Sidebar.hxx>
51 #include <svl/aeitem.hxx>
52 #include <svx/imapdlg.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <basic/sbstar.hxx>
55 #include "undo/undoobjects.hxx"
57 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::drawing::framework
;
61 using ::sd::framework::FrameworkHelper
;
65 ViewShell::Implementation::Implementation (ViewShell
& rViewShell
)
66 : mbIsShowingUIControls(false),
67 mbIsMainViewShell(false),
68 mbIsInitialized(false),
69 mbArrangeActive(false),
71 mpUpdateLockForMouse(),
72 mrViewShell(rViewShell
)
76 ViewShell::Implementation::~Implementation()
78 if ( ! mpUpdateLockForMouse
.expired())
80 ::boost::shared_ptr
<ToolBarManagerLock
> pLock(mpUpdateLockForMouse
);
81 if (pLock
.get() != NULL
)
83 // Force the ToolBarManagerLock to be released even when the
84 // IsUICaptured() returns <TRUE/>.
90 void ViewShell::Implementation::ProcessModifyPageSlot (
95 SdDrawDocument
* pDocument
= mrViewShell
.GetDoc();
96 SdrLayerAdmin
& rLayerAdmin
= pDocument
->GetLayerAdmin();
97 sal_uInt8 aBckgrnd
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false);
98 sal_uInt8 aBckgrndObj
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false);
99 SetOfByte aVisibleLayers
;
100 bool bHandoutMode
= false;
101 SdPage
* pHandoutMPage
= NULL
;
104 AutoLayout aNewAutoLayout
;
108 const SfxItemSet
* pArgs
= rRequest
.GetArgs();
110 if (pCurrentPage
!= NULL
&& pCurrentPage
->TRG_HasMasterPage())
111 aVisibleLayers
= pCurrentPage
->TRG_GetMasterPageVisibleLayers();
113 aVisibleLayers
.SetAll();
117 if (pCurrentPage
== NULL
)
120 if (!pArgs
|| pArgs
->Count() == 1 || pArgs
->Count() == 2 )
122 // First make sure that the sidebar is visible
123 mrViewShell
.GetViewFrame()->ShowChildWindow(SID_SIDEBAR
);
124 sfx2::sidebar::Sidebar::ShowPanel(
125 OUString("ImpressLayoutsPanel"),
126 mrViewShell
.GetViewFrame()->GetFrame().GetFrameInterface());
129 else if (pArgs
->Count() == 4)
131 SFX_REQUEST_ARG (rRequest
, pNewName
, SfxStringItem
, ID_VAL_PAGENAME
, false);
132 SFX_REQUEST_ARG (rRequest
, pNewAutoLayout
, SfxUInt32Item
, ID_VAL_WHATLAYOUT
, false);
133 SFX_REQUEST_ARG (rRequest
, pBVisible
, SfxBoolItem
, ID_VAL_ISPAGEBACK
, false);
134 SFX_REQUEST_ARG (rRequest
, pBObjsVisible
, SfxBoolItem
, ID_VAL_ISPAGEOBJ
, false);
135 AutoLayout
aLayout ((AutoLayout
)pNewAutoLayout
->GetValue ());
136 if (aLayout
>= AUTOLAYOUT__START
137 && aLayout
< AUTOLAYOUT__END
)
139 aNewName
= pNewName
->GetValue ();
140 aNewAutoLayout
= (AutoLayout
) pNewAutoLayout
->GetValue ();
141 bBVisible
= pBVisible
->GetValue ();
142 bBObjsVisible
= pBObjsVisible
->GetValue ();
146 #if HAVE_FEATURE_SCRIPTING
147 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE
);
152 if (ePageKind
== PK_HANDOUT
)
155 pHandoutMPage
= pDocument
->GetMasterSdPage(0, PK_HANDOUT
);
160 #if HAVE_FEATURE_SCRIPTING
161 StarBASIC::FatalError (SbERR_WRONG_ARGS
);
168 bHandoutMode
? pHandoutMPage
: pCurrentPage
;
170 ::svl::IUndoManager
* pUndoManager
= mrViewShell
.GetDocSh()->GetUndoManager();
171 DBG_ASSERT(pUndoManager
, "No UNDO MANAGER ?!?");
175 OUString
aComment( SdResId(STR_UNDO_MODIFY_PAGE
) );
176 pUndoManager
->EnterListAction(aComment
, aComment
);
177 ModifyPageUndoAction
* pAction
= new ModifyPageUndoAction(
178 pDocument
, pUndoPage
, aNewName
, aNewAutoLayout
, bBVisible
, bBObjsVisible
);
179 pUndoManager
->AddUndoAction(pAction
);
181 // Clear the selection because the selected object may be removed as
182 // a result of the assignment of the layout.
183 mrViewShell
.GetDrawView()->UnmarkAll();
187 if (pCurrentPage
->GetName() != aNewName
)
189 pCurrentPage
->SetName(aNewName
);
191 if (ePageKind
== PK_STANDARD
)
193 sal_uInt16 nPage
= (pCurrentPage
->GetPageNum()-1) / 2;
194 SdPage
* pNotesPage
= pDocument
->GetSdPage(nPage
, PK_NOTES
);
195 if (pNotesPage
!= NULL
)
196 pNotesPage
->SetName(aNewName
);
200 pCurrentPage
->SetAutoLayout(aNewAutoLayout
, true);
202 aBckgrnd
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false);
203 aBckgrndObj
= rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false);
204 aVisibleLayers
.Set(aBckgrnd
, bBVisible
);
205 aVisibleLayers
.Set(aBckgrndObj
, bBObjsVisible
);
206 pCurrentPage
->TRG_SetMasterPageVisibleLayers(aVisibleLayers
);
210 pHandoutMPage
->SetAutoLayout(aNewAutoLayout
, true);
213 mrViewShell
.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE
,
214 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
216 bool bSetModified
= true;
218 if (pArgs
&& pArgs
->Count() == 1)
220 bSetModified
= static_cast<const SfxBoolItem
&>(pArgs
->Get(SID_MODIFYPAGE
)).GetValue();
223 pUndoManager
->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage
) );
224 pUndoManager
->LeaveListAction();
226 pDocument
->SetChanged(bSetModified
);
231 mrViewShell
.Cancel();
235 void ViewShell::Implementation::AssignLayout ( SfxRequest
& rRequest
, PageKind ePageKind
)
237 const SfxUInt32Item
* pWhatPage
= static_cast< const SfxUInt32Item
* > ( rRequest
.GetArg( ID_VAL_WHATPAGE
, false, TYPE(SfxUInt32Item
) ) );
238 const SfxUInt32Item
* pWhatLayout
= static_cast< const SfxUInt32Item
* > ( rRequest
.GetArg( ID_VAL_WHATLAYOUT
, false, TYPE(SfxUInt32Item
) ) );
240 SdDrawDocument
* pDocument
= mrViewShell
.GetDoc();
247 pPage
= pDocument
->GetSdPage(static_cast<sal_uInt16
>(pWhatPage
->GetValue()), ePageKind
);
251 pPage
= mrViewShell
.getCurrentPage();
255 AutoLayout eLayout
= pPage
->GetAutoLayout();
258 eLayout
= static_cast< AutoLayout
>( pWhatLayout
->GetValue() );
260 // Transform the given request into the four argument form that is
261 // understood by ProcessModifyPageSlot().
262 SdrLayerAdmin
& rLayerAdmin (mrViewShell
.GetViewShellBase().GetDocument()->GetLayerAdmin());
263 sal_uInt8
aBackground (rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND
), false));
264 sal_uInt8
aBackgroundObject (rLayerAdmin
.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ
), false));
266 SetOfByte aVisibleLayers
;
268 if( pPage
->GetPageKind() == PK_HANDOUT
)
269 aVisibleLayers
.SetAll();
271 aVisibleLayers
= pPage
->TRG_GetMasterPageVisibleLayers();
273 SfxRequest
aRequest (mrViewShell
.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE
);
274 aRequest
.AppendItem(SfxStringItem (ID_VAL_PAGENAME
, pPage
->GetName()));
275 aRequest
.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT
, eLayout
));
276 aRequest
.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK
, aVisibleLayers
.IsSet(aBackground
)));
277 aRequest
.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ
, aVisibleLayers
.IsSet(aBackgroundObject
)));
279 // Forward the call with the new arguments.
280 ProcessModifyPageSlot( aRequest
, pPage
, pPage
->GetPageKind());
284 sal_uInt16
ViewShell::Implementation::GetViewId()
286 switch (mrViewShell
.GetShellType())
288 case ViewShell::ST_IMPRESS
:
289 case ViewShell::ST_NOTES
:
290 case ViewShell::ST_HANDOUT
:
291 return IMPRESS_FACTORY_ID
;
293 case ViewShell::ST_DRAW
:
294 return DRAW_FACTORY_ID
;
296 case ViewShell::ST_OUTLINE
:
297 return OUTLINE_FACTORY_ID
;
299 case ViewShell::ST_SLIDE_SORTER
:
300 return SLIDE_SORTER_FACTORY_ID
;
302 case ViewShell::ST_PRESENTATION
:
303 return PRESENTATION_FACTORY_ID
;
305 // Since we have to return a view id for every possible shell type
306 // and there is not (yet) a proper ViewShellBase sub class for the
307 // remaining types we chose the Impress factory as a fall back.
308 case ViewShell::ST_SIDEBAR
:
309 case ViewShell::ST_NONE
:
311 return IMPRESS_FACTORY_ID
;
315 SvxIMapDlg
* ViewShell::Implementation::GetImageMapDialog()
317 SvxIMapDlg
* pDialog
= NULL
;
318 SfxChildWindow
* pChildWindow
= SfxViewFrame::Current()->GetChildWindow(
319 SvxIMapDlgChildWindow::GetChildWindowId());
320 if (pChildWindow
!= NULL
)
321 pDialog
= dynamic_cast<SvxIMapDlg
*>(pChildWindow
->GetWindow());
325 //===== ToolBarManagerLock ====================================================
327 class ViewShell::Implementation::ToolBarManagerLock::Deleter
{ public:
328 void operator() (ToolBarManagerLock
* pObject
) { delete pObject
; }
331 ::boost::shared_ptr
<ViewShell::Implementation::ToolBarManagerLock
>
332 ViewShell::Implementation::ToolBarManagerLock::Create (
333 const ::boost::shared_ptr
<ToolBarManager
>& rpManager
)
335 ::boost::shared_ptr
<ToolBarManagerLock
> pLock (
336 new ViewShell::Implementation::ToolBarManagerLock(rpManager
),
337 ViewShell::Implementation::ToolBarManagerLock::Deleter());
338 pLock
->mpSelf
= pLock
;
342 ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
343 const ::boost::shared_ptr
<ToolBarManager
>& rpManager
)
344 : mpLock(new ToolBarManager::UpdateLock(rpManager
)),
347 // Start a timer that will unlock the ToolBarManager update lock when
348 // that is not done explicitly by calling Release().
349 maTimer
.SetTimeoutHdl(LINK(this,ToolBarManagerLock
,TimeoutCallback
));
350 maTimer
.SetTimeout(100);
354 IMPL_LINK_NOARG_TYPED(ViewShell::Implementation::ToolBarManagerLock
, TimeoutCallback
, Timer
*, void)
356 // If possible then release the lock now. Otherwise start the timer
357 // and try again later.
358 if (Application::IsUICaptured())
368 void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce
)
370 // If possible then release the lock now. Otherwise try again when the
372 if (bForce
|| ! Application::IsUICaptured())
378 ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock()
383 } // end of namespace sd
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */