merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / ViewShellImplementation.cxx
blob4b870f432a887b9f623c3244e4c33a828f2d3faf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ViewShellImplementation.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "ViewShellImplementation.hxx"
36 #include "sdpage.hxx"
37 #include "drawdoc.hxx"
38 #include "sdresid.hxx"
39 #include "glob.hrc"
40 #include "app.hrc"
41 #include "strings.hrc"
42 #include "strings.hrc"
43 #include "helpids.h"
44 #include "sdattr.hxx"
45 #include "sdabstdlg.hxx"
46 #include "unmodpg.hxx"
47 #include "Window.hxx"
48 #include "optsitem.hxx"
49 #include "DrawDocShell.hxx"
50 #include "DrawController.hxx"
51 #include "FactoryIds.hxx"
52 #include "slideshow.hxx"
53 #include "TaskPaneViewShell.hxx"
54 #include "ViewShellBase.hxx"
55 #include "FrameView.hxx"
56 #include "DrawViewShell.hxx"
57 #include "ViewShellHint.hxx"
58 #include "framework/FrameworkHelper.hxx"
60 #include <sfx2/bindings.hxx>
61 #include <sfx2/dispatch.hxx>
62 #include <sfx2/request.hxx>
63 #include <svtools/aeitem.hxx>
64 #include <svx/imapdlg.hxx>
65 #include <vcl/msgbox.hxx>
66 #include <basic/sbstar.hxx>
67 #include "undo/undoobjects.hxx"
69 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::drawing::framework;
73 using ::sd::framework::FrameworkHelper;
75 namespace {
77 class ImpUndoDeleteWarning : public ModalDialog
79 private:
80 FixedImage maImage;
81 FixedText maWarningFT;
82 CheckBox maDisableCB;
83 OKButton maYesBtn;
84 CancelButton maNoBtn;
86 public:
87 ImpUndoDeleteWarning(Window* pParent);
88 BOOL IsWarningDisabled() const { return maDisableCB.IsChecked(); }
91 ImpUndoDeleteWarning::ImpUndoDeleteWarning(Window* pParent)
92 : ModalDialog(pParent, SdResId(RID_UNDO_DELETE_WARNING)),
93 maImage(this, SdResId(IMG_UNDO_DELETE_WARNING)),
94 maWarningFT(this, SdResId(FT_UNDO_DELETE_WARNING)),
95 maDisableCB(this, SdResId(CB_UNDO_DELETE_DISABLE)),
96 maYesBtn(this, SdResId(BTN_UNDO_DELETE_YES)),
97 maNoBtn(this, SdResId(BTN_UNDO_DELETE_NO))
99 FreeResource();
101 SetHelpId( HID_SD_UNDODELETEWARNING_DLG );
102 maDisableCB.SetHelpId( HID_SD_UNDODELETEWARNING_CBX );
104 maYesBtn.SetText(Button::GetStandardText(BUTTON_YES));
105 maNoBtn.SetText(Button::GetStandardText(BUTTON_NO));
106 maImage.SetImage(WarningBox::GetStandardImage());
108 // #93721# Set focus to YES-Button
109 maYesBtn.GrabFocus();
112 } // end of anonymous namespace
117 namespace sd {
119 ViewShell::Implementation::Implementation (ViewShell& rViewShell)
120 : mbIsShowingUIControls(false),
121 mbIsMainViewShell(false),
122 mbIsInitialized(false),
123 mbArrangeActive(false),
124 mpSubShellFactory(),
125 mpUpdateLockForMouse(),
126 mrViewShell(rViewShell)
133 ViewShell::Implementation::~Implementation (void)
135 if ( ! mpUpdateLockForMouse.expired())
137 ::boost::shared_ptr<ToolBarManagerLock> pLock(mpUpdateLockForMouse);
138 if (pLock.get() != NULL)
140 // Force the ToolBarManagerLock to be released even when the
141 // IsUICaptured() returns <TRUE/>.
142 pLock->Release(true);
150 void ViewShell::Implementation::ProcessModifyPageSlot (
151 SfxRequest& rRequest,
152 SdPage* pCurrentPage,
153 PageKind ePageKind)
155 SdDrawDocument* pDocument = mrViewShell.GetDoc();
156 SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
157 BYTE aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), FALSE);
158 BYTE aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE);
159 SetOfByte aVisibleLayers;
160 BOOL bHandoutMode = FALSE;
161 SdPage* pHandoutMPage = NULL;
162 String aNewName;
164 // #95981#
165 String aOldName;
167 AutoLayout aNewAutoLayout;
169 BOOL bBVisible;
170 BOOL bBObjsVisible;
171 const SfxItemSet* pArgs = rRequest.GetArgs();
173 if (pCurrentPage != NULL && pCurrentPage->TRG_HasMasterPage())
174 aVisibleLayers = pCurrentPage->TRG_GetMasterPageVisibleLayers();
175 else
176 aVisibleLayers.SetAll();
180 if (pCurrentPage == NULL)
181 break;
183 if (!pArgs || pArgs->Count() == 1 || pArgs->Count() == 2 )
185 if (pArgs && pArgs->Count() == 2)
187 // We have been called with a request that contains two
188 // arguments. One was used as preselected layout in a
189 // dialog. We could select that layout in the
190 // layout panel instead.
192 SFX_REQUEST_ARG (rRequest, pNewAutoLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, FALSE);
193 eNewAutoLayout = (AutoLayout) pNewAutoLayout->GetValue
198 // Make the layout menu visible in the tool pane.
199 SfxBoolItem aMakeToolPaneVisible (ID_VAL_ISVISIBLE, TRUE);
200 SfxUInt32Item aPanelId (ID_VAL_PANEL_INDEX,
201 ::sd::toolpanel::TaskPaneViewShell::PID_LAYOUT);
202 SfxViewFrame* pFrame = mrViewShell.GetViewFrame();
203 if (pFrame!=NULL && pFrame->GetDispatcher()!=NULL)
205 pFrame->GetDispatcher()->Execute (
206 SID_TASK_PANE,
207 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
208 &aMakeToolPaneVisible,
209 &aPanelId,
210 NULL);
212 else
214 DBG_ASSERT(pFrame!=NULL && pFrame->GetDispatcher()!=NULL,
215 "ViewShell::Implementation::ProcessModifyPageSlot(): can not get dispatcher");
218 // We have activated a non-modal control in the task pane.
219 // Because it does not return anything we can not do anything
220 // more right now and have to exit here.
221 break;
223 else if (pArgs->Count() == 4)
225 SFX_REQUEST_ARG (rRequest, pNewName, SfxStringItem, ID_VAL_PAGENAME, FALSE);
226 SFX_REQUEST_ARG (rRequest, pNewAutoLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, FALSE);
227 SFX_REQUEST_ARG (rRequest, pBVisible, SfxBoolItem, ID_VAL_ISPAGEBACK, FALSE);
228 SFX_REQUEST_ARG (rRequest, pBObjsVisible, SfxBoolItem, ID_VAL_ISPAGEOBJ, FALSE);
229 AutoLayout aLayout ((AutoLayout)pNewAutoLayout->GetValue ());
230 if (aLayout >= AUTOLAYOUT__START
231 && aLayout < AUTOLAYOUT__END)
233 aNewName = pNewName->GetValue ();
234 aNewAutoLayout = (AutoLayout) pNewAutoLayout->GetValue ();
235 bBVisible = pBVisible->GetValue ();
236 bBObjsVisible = pBObjsVisible->GetValue ();
238 else
240 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
241 rRequest.Ignore ();
242 break;
244 if (ePageKind == PK_HANDOUT)
246 bHandoutMode = TRUE;
247 pHandoutMPage = pDocument->GetMasterSdPage(0, PK_HANDOUT);
250 else
252 StarBASIC::FatalError (SbERR_WRONG_ARGS);
253 rRequest.Ignore ();
254 break;
257 SdPage* pUndoPage =
258 bHandoutMode ? pHandoutMPage : pCurrentPage;
260 SfxUndoManager* pUndoManager = mrViewShell.GetDocSh()->GetUndoManager();
261 DBG_ASSERT(pUndoManager, "No UNDO MANAGER ?!?");
263 if( pUndoManager )
265 String aComment( SdResId(STR_UNDO_MODIFY_PAGE) );
266 pUndoManager->EnterListAction(aComment, aComment);
267 ModifyPageUndoAction* pAction = new ModifyPageUndoAction(
268 pUndoManager, pDocument, pUndoPage, aNewName, aNewAutoLayout, bBVisible, bBObjsVisible);
269 pUndoManager->AddUndoAction(pAction);
271 // Clear the selection because the selectec object may be removed as
272 // a result of the ssignment of the layout.
273 mrViewShell.GetDrawView()->UnmarkAll();
275 if (!bHandoutMode)
277 if (pCurrentPage->GetName() != aNewName)
279 pCurrentPage->SetName(aNewName);
281 if (ePageKind == PK_STANDARD)
283 USHORT nPage = (pCurrentPage->GetPageNum()-1) / 2;
284 SdPage* pNotesPage = pDocument->GetSdPage(nPage, PK_NOTES);
285 if (pNotesPage != NULL)
286 pNotesPage->SetName(aNewName);
290 pCurrentPage->SetAutoLayout(aNewAutoLayout, TRUE);
292 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), FALSE);
293 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE);
294 aVisibleLayers.Set(aBckgrnd, bBVisible);
295 aVisibleLayers.Set(aBckgrndObj, bBObjsVisible);
296 pCurrentPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
298 else
300 pHandoutMPage->SetAutoLayout(aNewAutoLayout, TRUE);
303 mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SWITCHPAGE,
304 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
306 BOOL bSetModified = TRUE;
308 if (pArgs && pArgs->Count() == 1)
310 bSetModified = (BOOL) ((SfxBoolItem&) pArgs->Get(SID_MODIFYPAGE)).GetValue();
313 pUndoManager->AddUndoAction( new UndoAutoLayoutPosAndSize( *pUndoPage ) );
314 pUndoManager->LeaveListAction();
316 pDocument->SetChanged(bSetModified);
319 while (false);
321 mrViewShell.Cancel();
322 rRequest.Done ();
328 void ViewShell::Implementation::AssignLayout (
329 SdPage* pPage,
330 AutoLayout aLayout)
332 // Transform the given request into the four argument form that is
333 // understood by ProcessModifyPageSlot().
334 SdrLayerAdmin& rLayerAdmin (mrViewShell.GetViewShellBase().GetDocument()->GetLayerAdmin());
335 BYTE aBackground (rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), FALSE));
336 BYTE aBackgroundObject (rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE));
337 SetOfByte aVisibleLayers (pPage->TRG_GetMasterPageVisibleLayers());
338 SfxRequest aRequest (mrViewShell.GetViewShellBase().GetViewFrame(), SID_MODIFYPAGE);
339 aRequest.AppendItem(SfxStringItem (ID_VAL_PAGENAME, pPage->GetName()));
340 aRequest.AppendItem(SfxUInt32Item (ID_VAL_WHATLAYOUT, aLayout));
341 aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEBACK, aVisibleLayers.IsSet(aBackground)));
342 aRequest.AppendItem(SfxBoolItem(ID_VAL_ISPAGEOBJ, aVisibleLayers.IsSet(aBackgroundObject)));
344 // Forward the call with the new arguments.
345 ProcessModifyPageSlot (
346 aRequest,
347 pPage,
348 pPage->GetPageKind());
354 sal_uInt16 ViewShell::Implementation::GetViewId (void)
356 switch (mrViewShell.GetShellType())
358 case ViewShell::ST_IMPRESS:
359 case ViewShell::ST_NOTES:
360 case ViewShell::ST_HANDOUT:
361 return IMPRESS_FACTORY_ID;
363 case ViewShell::ST_DRAW:
364 return DRAW_FACTORY_ID;
366 case ViewShell::ST_OUTLINE:
367 return OUTLINE_FACTORY_ID;
369 case ViewShell::ST_SLIDE_SORTER:
370 return SLIDE_SORTER_FACTORY_ID;
372 case ViewShell::ST_PRESENTATION:
373 return PRESENTATION_FACTORY_ID;
375 // Since we have to return a view id for every possible shell type
376 // and there is not (yet) a proper ViewShellBase sub class for the
377 // remaining types we chose the Impress factory as a fall back.
378 case ViewShell::ST_TASK_PANE:
379 case ViewShell::ST_NONE:
380 default:
381 return IMPRESS_FACTORY_ID;
388 SvxIMapDlg* ViewShell::Implementation::GetImageMapDialog (void)
390 SvxIMapDlg* pDialog = NULL;
391 SfxChildWindow* pChildWindow = SfxViewFrame::Current()->GetChildWindow(
392 SvxIMapDlgChildWindow::GetChildWindowId());
393 if (pChildWindow != NULL)
394 pDialog = dynamic_cast<SvxIMapDlg*>(pChildWindow->GetWindow());
395 return pDialog;
400 //===== ToolBarManagerLock ====================================================
402 class ViewShell::Implementation::ToolBarManagerLock::Deleter { public:
403 void operator() (ToolBarManagerLock* pObject) { delete pObject; }
406 ::boost::shared_ptr<ViewShell::Implementation::ToolBarManagerLock>
407 ViewShell::Implementation::ToolBarManagerLock::Create (
408 const ::boost::shared_ptr<ToolBarManager>& rpManager)
410 ::boost::shared_ptr<ToolBarManagerLock> pLock (
411 new ViewShell::Implementation::ToolBarManagerLock(rpManager),
412 ViewShell::Implementation::ToolBarManagerLock::Deleter());
413 pLock->mpSelf = pLock;
414 return pLock;
420 ViewShell::Implementation::ToolBarManagerLock::ToolBarManagerLock (
421 const ::boost::shared_ptr<ToolBarManager>& rpManager)
422 : mpLock(new ToolBarManager::UpdateLock(rpManager)),
423 maTimer()
425 // Start a timer that will unlock the ToolBarManager update lock when
426 // that is not done explicitly by calling Release().
427 maTimer.SetTimeoutHdl(LINK(this,ToolBarManagerLock,TimeoutCallback));
428 maTimer.SetTimeout(100);
429 maTimer.Start();
435 IMPL_LINK(ViewShell::Implementation::ToolBarManagerLock,TimeoutCallback,Timer*,EMPTYARG)
437 // If possible then release the lock now. Otherwise start the timer
438 // and try again later.
439 if (Application::IsUICaptured())
441 maTimer.Start();
443 else
445 mpSelf.reset();
447 return 0;
453 void ViewShell::Implementation::ToolBarManagerLock::Release (bool bForce)
455 // If possible then release the lock now. Otherwise try again when the
456 // timer expires.
457 if (bForce || ! Application::IsUICaptured())
459 mpSelf.reset();
466 ViewShell::Implementation::ToolBarManagerLock::~ToolBarManagerLock (void)
468 mpLock.reset();
471 } // end of namespace sd