update dev300-m58
[ooovba.git] / sd / source / ui / view / viewshe3.cxx
blob03276941ef402ea130cd0f15672fafc692220a74
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: viewshe3.cxx,v $
10 * $Revision: 1.59.38.1 $
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"
35 #include "ViewShell.hxx"
36 #include "GraphicViewShell.hxx"
37 #include "GraphicViewShellBase.hxx"
39 #include <sfx2/viewfrm.hxx>
40 #include <com/sun/star/lang/Locale.hpp>
42 #include <utility>
43 #include <vector>
45 #include "app.hrc"
46 #include "strings.hrc"
47 #include "res_bmp.hrc"
48 #include "glob.hrc"
49 #include "sdabstdlg.hxx"
51 #include "fupoor.hxx"
52 #include <sfx2/dispatch.hxx>
53 #include <svx/prtqry.hxx>
54 #include <svx/svdopage.hxx>
55 #include <sfx2/progress.hxx>
56 #include <svx/svdobj.hxx>
57 #include <vcl/msgbox.hxx>
58 #include <sfx2/bindings.hxx>
59 #include <svx/svdpagv.hxx>
60 #include <svx/svdetc.hxx>
61 #include <svx/outliner.hxx>
62 #include <svtools/misccfg.hxx>
63 #include <svx/editstat.hxx>
64 #include <tools/multisel.hxx>
65 #include <svtools/intitem.hxx>
66 #include <svtools/style.hxx>
67 #include <unotools/localedatawrapper.hxx>
68 #include <comphelper/processfactory.hxx>
69 #include <rtl/ustrbuf.hxx>
70 #include "stlsheet.hxx"
71 #ifndef SD_WINDOW_UPDATER_HXX
72 #include "WindowUpdater.hxx"
73 #endif
74 #include "DrawViewShell.hxx"
75 #include "OutlineViewShell.hxx"
76 #include "TaskPaneViewShell.hxx"
77 #include "drawview.hxx"
79 #include "sdattr.hxx"
80 #include "drawdoc.hxx"
81 #include "sdpage.hxx"
82 #include "unoaprms.hxx" // Undo-Action
83 #include "sdundogr.hxx" // Undo Gruppe
84 #include "Window.hxx"
85 #include "DrawDocShell.hxx"
86 #include "FrameView.hxx"
87 #include "optsitem.hxx"
88 #include "sdresid.hxx"
90 // #96090#
91 #ifndef _SVXIDS_HXX
92 #include <svx/svxids.hrc>
93 #endif
94 #include <sfx2/request.hxx>
95 #include <svtools/aeitem.hxx>
96 #include <basic/sbstar.hxx>
98 using namespace ::com::sun::star;
99 using namespace ::rtl;
101 namespace sd {
103 /*************************************************************************
105 |* Status (Enabled/Disabled) von Menue-SfxSlots setzen
107 \************************************************************************/
109 void ViewShell::GetMenuState( SfxItemSet &rSet )
111 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STYLE_FAMILY ) )
113 UINT16 nFamily = (UINT16)GetDocSh()->GetStyleFamily();
115 SdrView* pDrView = GetDrawView();
117 if( pDrView->AreObjectsMarked() )
119 SfxStyleSheet* pStyleSheet = pDrView->GetStyleSheet();
120 if( pStyleSheet )
122 if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
123 pStyleSheet = ((SdStyleSheet*)pStyleSheet)->GetPseudoStyleSheet();
125 if( pStyleSheet )
127 SfxStyleFamily eFamily = pStyleSheet->GetFamily();
128 if(eFamily == SD_STYLE_FAMILY_GRAPHICS)
129 nFamily = 2;
130 else if(eFamily == SD_STYLE_FAMILY_CELL )
131 nFamily = 3;
132 else // SD_STYLE_FAMILY_PSEUDO
133 nFamily = 5;
135 GetDocSh()->SetStyleFamily(nFamily);
139 rSet.Put(SfxUInt16Item(SID_STYLE_FAMILY, nFamily ));
142 // #96090#
143 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETUNDOSTRINGS))
145 ImpGetUndoStrings(rSet);
148 // #96090#
149 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETREDOSTRINGS))
151 ImpGetRedoStrings(rSet);
154 // #96090#
155 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_UNDO))
157 SfxUndoManager* pUndoManager = ImpGetUndoManager();
158 sal_Bool bActivate(FALSE);
160 if(pUndoManager)
162 if(pUndoManager->GetUndoActionCount() != 0)
164 bActivate = TRUE;
168 if(bActivate)
170 // #87229# Set the necessary string like in
171 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
172 String aTmp(ResId(STR_UNDO, *SFX_APP()->GetSfxResManager()));
173 aTmp += pUndoManager->GetUndoActionComment(0);
174 rSet.Put(SfxStringItem(SID_UNDO, aTmp));
176 else
178 rSet.DisableItem(SID_UNDO);
182 // #96090#
183 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_REDO))
185 SfxUndoManager* pUndoManager = ImpGetUndoManager();
186 sal_Bool bActivate(FALSE);
188 if(pUndoManager)
190 if(pUndoManager->GetRedoActionCount() != 0)
192 bActivate = TRUE;
196 if(bActivate)
198 // #87229# Set the necessary string like in
199 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
200 String aTmp(ResId(STR_REDO, *SFX_APP()->GetSfxResManager()));
201 aTmp += pUndoManager->GetRedoActionComment(0);
202 rSet.Put(SfxStringItem(SID_REDO, aTmp));
204 else
206 rSet.DisableItem(SID_REDO);
214 /** This method consists basically of three parts:
215 1. Process the arguments of the SFX request.
216 2. Use the model to create a new page or duplicate an existing one.
217 3. Update the tab control and switch to the new page.
219 SdPage* ViewShell::CreateOrDuplicatePage (
220 SfxRequest& rRequest,
221 PageKind ePageKind,
222 SdPage* pPage)
224 USHORT nSId = rRequest.GetSlot();
225 SdDrawDocument* pDocument = GetDoc();
226 SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
227 BYTE aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), FALSE);
228 BYTE aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), FALSE);
229 SetOfByte aVisibleLayers;
230 // Determine the page from which to copy some values, such as layers,
231 // size, master page, to the new page. This is usually the given page.
232 // When the given page is NULL then use the first page of the document.
233 SdPage* pTemplatePage = pPage;
234 if (pTemplatePage == NULL)
235 if (pDocument->GetSdPage(0, ePageKind) > 0)
236 pTemplatePage = pDocument->GetSdPage(0, ePageKind);
237 if (pTemplatePage != NULL && pTemplatePage->TRG_HasMasterPage())
238 aVisibleLayers = pTemplatePage->TRG_GetMasterPageVisibleLayers();
239 else
240 aVisibleLayers.SetAll();
242 String aStandardPageName;
243 String aNotesPageName;
244 AutoLayout eStandardLayout (AUTOLAYOUT_NONE);
245 AutoLayout eNotesLayout (AUTOLAYOUT_NOTES);
246 BOOL bIsPageBack = aVisibleLayers.IsSet(aBckgrnd);
247 BOOL bIsPageObj = aVisibleLayers.IsSet(aBckgrndObj);
249 // 1. Process the arguments.
250 const SfxItemSet* pArgs = rRequest.GetArgs();
251 if (! pArgs)
253 // Make the layout menu visible in the tool pane.
254 const ViewShellBase& rBase (GetViewShellBase());
255 if (rBase.GetMainViewShell()!=NULL
256 && rBase.GetMainViewShell()->GetShellType()!=ViewShell::ST_OUTLINE
257 && rBase.GetMainViewShell()->GetShellType()!=ViewShell::ST_DRAW)
259 framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel(
260 framework::FrameworkHelper::msLayoutTaskPanelURL);
263 // AutoLayouts muessen fertig sein
264 pDocument->StopWorkStartupDelay();
266 // Use the layouts of the previous page and notes page as template.
267 if (pTemplatePage != NULL)
269 eStandardLayout = pTemplatePage->GetAutoLayout();
270 SdPage* pNotesTemplatePage = static_cast<SdPage*>(pDocument->GetPage(pTemplatePage->GetPageNum()+1));
271 if (pNotesTemplatePage != NULL)
272 eNotesLayout = pNotesTemplatePage->GetAutoLayout();
275 else if (pArgs->Count () != 4)
277 Cancel();
279 if(HasCurrentFunction(SID_BEZIER_EDIT) )
280 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
282 StarBASIC::FatalError (SbERR_WRONG_ARGS);
283 rRequest.Ignore ();
284 return NULL;
286 else
288 // AutoLayouts muessen fertig sein
289 pDocument->StopWorkStartupDelay();
291 SFX_REQUEST_ARG (rRequest, pPageName, SfxStringItem, ID_VAL_PAGENAME, FALSE);
292 SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, FALSE);
293 SFX_REQUEST_ARG (rRequest, pIsPageBack, SfxBoolItem, ID_VAL_ISPAGEBACK, FALSE);
294 SFX_REQUEST_ARG (rRequest, pIsPageObj, SfxBoolItem, ID_VAL_ISPAGEOBJ, FALSE);
296 if (CHECK_RANGE (AUTOLAYOUT__START, (AutoLayout) pLayout->GetValue (), AUTOLAYOUT__END))
298 if (ePageKind == PK_NOTES)
300 aNotesPageName = pPageName->GetValue ();
301 eNotesLayout = (AutoLayout) pLayout->GetValue ();
303 else
305 aStandardPageName = pPageName->GetValue ();
306 eStandardLayout = (AutoLayout) pLayout->GetValue ();
309 bIsPageBack = pIsPageBack->GetValue ();
310 bIsPageObj = pIsPageObj->GetValue ();
312 else
314 Cancel();
316 if(HasCurrentFunction( SID_BEZIER_EDIT ) )
317 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
319 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
320 rRequest.Ignore ();
321 return NULL;
325 // 2. Create a new page or duplicate an existing one.
326 View* pDrView = GetView();
327 const bool bUndo = pDrView && pDrView->IsUndoEnabled();
328 if( bUndo )
329 pDrView->BegUndo( String( SdResId(STR_INSERTPAGE) ) );
331 USHORT nNewPageIndex = 0xffff;
332 switch (nSId)
334 case SID_INSERTPAGE:
335 case SID_INSERTPAGE_QUICK:
336 case SID_INSERT_MASTER_PAGE:
337 // There are three cases. a) pPage is not NULL: we use it as a
338 // template and create a new slide behind it. b) pPage is NULL
339 // but the document is not empty: we use the first slide/notes
340 // page as template, create a new slide after it and move it
341 // then to the head of the document. c) pPage is NULL and the
342 // document is empty: We use CreateFirstPages to create the
343 // first page of the document.
344 if (pPage == NULL)
345 if (pTemplatePage == NULL)
347 pDocument->CreateFirstPages();
348 nNewPageIndex = 0;
350 else
352 // Create a new page with the first page as template and
353 // insert it after the first page.
354 nNewPageIndex = pDocument->CreatePage (
355 pTemplatePage,
356 ePageKind,
357 aStandardPageName,
358 aNotesPageName,
359 eStandardLayout,
360 eNotesLayout,
361 bIsPageBack,
362 bIsPageObj);
363 // Select exactly the new page.
364 USHORT nPageCount (pDocument->GetSdPageCount(ePageKind));
365 for (USHORT i=0; i<nPageCount; i++)
367 pDocument->GetSdPage(i, PK_STANDARD)->SetSelected(
368 i == nNewPageIndex);
369 pDocument->GetSdPage(i, PK_NOTES)->SetSelected(
370 i == nNewPageIndex);
372 // Move the selected page to the head of the document
373 pDocument->MovePages ((USHORT)-1);
374 nNewPageIndex = 0;
376 else
377 nNewPageIndex = pDocument->CreatePage (
378 pPage,
379 ePageKind,
380 aStandardPageName,
381 aNotesPageName,
382 eStandardLayout,
383 eNotesLayout,
384 bIsPageBack,
385 bIsPageObj);
386 break;
388 case SID_DUPLICATE_PAGE:
389 // Duplication makes no sense when pPage is NULL.
390 if (pPage != NULL)
391 nNewPageIndex = pDocument->DuplicatePage (
392 pPage,
393 ePageKind,
394 aStandardPageName,
395 aNotesPageName,
396 eStandardLayout,
397 eNotesLayout,
398 bIsPageBack,
399 bIsPageObj);
400 break;
402 default:
403 DBG_WARNING("wrong slot id given to CreateOrDuplicatePage");
404 // Try to handle another slot id gracefully.
406 SdPage* pNewPage = 0;
407 if(nNewPageIndex != 0xffff)
408 pNewPage = pDocument->GetSdPage(nNewPageIndex, PK_STANDARD);
410 if( bUndo )
412 if( pNewPage )
414 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage));
415 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pDocument->GetSdPage (nNewPageIndex, PK_NOTES)));
418 pDrView->EndUndo();
421 return pNewPage;
425 } // end of namespace sd