bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / viewshe3.cxx
blob32551c14bd9d34ae402ba64e2706001c7c6254ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ViewShell.hxx"
23 #include "GraphicViewShell.hxx"
24 #include "GraphicViewShellBase.hxx"
26 #include <sfx2/viewfrm.hxx>
27 #include <svtools/svtools.hrc>
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <svtools/svtresid.hxx>
30 #include <utility>
31 #include <vector>
33 #include "app.hrc"
34 #include "strings.hrc"
35 #include "res_bmp.hrc"
36 #include "glob.hrc"
37 #include "sdabstdlg.hxx"
39 #include "fupoor.hxx"
40 #include <sfx2/dispatch.hxx>
41 #include <svx/prtqry.hxx>
42 #include <svx/svdopage.hxx>
43 #include <sfx2/progress.hxx>
44 #include <svx/svdobj.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <svx/svdpagv.hxx>
48 #include <svx/svdetc.hxx>
49 #include <editeng/outliner.hxx>
50 #include <editeng/editstat.hxx>
51 #include <tools/multisel.hxx>
52 #include <svl/intitem.hxx>
53 #include <svl/style.hxx>
54 #include <unotools/localedatawrapper.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <rtl/ustrbuf.hxx>
57 #include "stlsheet.hxx"
58 #include "WindowUpdater.hxx"
59 #include "DrawViewShell.hxx"
60 #include "OutlineViewShell.hxx"
61 #include "drawview.hxx"
63 #include "sdattr.hxx"
64 #include "drawdoc.hxx"
65 #include "sdpage.hxx"
66 #include "unoaprms.hxx"
67 #include "sdundogr.hxx"
68 #include "Window.hxx"
69 #include "DrawDocShell.hxx"
70 #include "FrameView.hxx"
71 #include "framework/FrameworkHelper.hxx"
72 #include "optsitem.hxx"
73 #include "sdresid.hxx"
75 #include <svx/svxids.hrc>
76 #include <sfx2/request.hxx>
77 #include <sfx2/templdlg.hxx>
78 #include <svl/aeitem.hxx>
79 #include <basic/sbstar.hxx>
81 using namespace ::com::sun::star;
83 namespace sd {
85 /**
86 * set state (enabled/disabled) of Menu SfxSlots
88 void ViewShell::GetMenuState( SfxItemSet &rSet )
90 if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STYLE_FAMILY ) )
92 sal_uInt16 nFamily = (sal_uInt16)GetDocSh()->GetStyleFamily();
94 SdrView* pDrView = GetDrawView();
96 if( pDrView->AreObjectsMarked() )
98 SfxStyleSheet* pStyleSheet = pDrView->GetStyleSheet();
99 if( pStyleSheet )
101 if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
102 pStyleSheet = static_cast<SdStyleSheet*>(pStyleSheet)->GetPseudoStyleSheet();
104 if( pStyleSheet )
106 SfxStyleFamily eFamily = pStyleSheet->GetFamily();
107 nFamily = SfxTemplate::SfxFamilyIdToNId(eFamily);
108 GetDocSh()->SetStyleFamily(nFamily);
113 rSet.Put(SfxUInt16Item(SID_STYLE_FAMILY, nFamily ));
116 if(SfxItemState::DEFAULT == rSet.GetItemState(SID_GETUNDOSTRINGS))
118 ImpGetUndoStrings(rSet);
121 if(SfxItemState::DEFAULT == rSet.GetItemState(SID_GETREDOSTRINGS))
123 ImpGetRedoStrings(rSet);
126 if(SfxItemState::DEFAULT == rSet.GetItemState(SID_UNDO))
128 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
129 bool bActivate(false);
131 if(pUndoManager)
133 if(pUndoManager->GetUndoActionCount() != 0)
135 bActivate = true;
139 if(bActivate)
141 // Set the necessary string like in
142 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
143 OUString aTmp(SVT_RESSTR(STR_UNDO));
144 aTmp += pUndoManager->GetUndoActionComment(0);
145 rSet.Put(SfxStringItem(SID_UNDO, aTmp));
147 else
149 rSet.DisableItem(SID_UNDO);
153 if(SfxItemState::DEFAULT == rSet.GetItemState(SID_REDO))
155 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
156 bool bActivate(false);
158 if(pUndoManager)
160 if(pUndoManager->GetRedoActionCount() != 0)
162 bActivate = true;
166 if(bActivate)
168 // Set the necessary string like in
169 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
170 OUString aTmp(SVT_RESSTR(STR_REDO));
171 aTmp += pUndoManager->GetRedoActionComment(0);
172 rSet.Put(SfxStringItem(SID_REDO, aTmp));
174 else
176 rSet.DisableItem(SID_REDO);
181 /** This method consists basically of three parts:
182 1. Process the arguments of the SFX request.
183 2. Use the model to create a new page or duplicate an existing one.
184 3. Update the tab control and switch to the new page.
186 SdPage* ViewShell::CreateOrDuplicatePage (
187 SfxRequest& rRequest,
188 PageKind ePageKind,
189 SdPage* pPage,
190 const sal_Int32 nInsertPosition)
192 sal_uInt16 nSId = rRequest.GetSlot();
193 SdDrawDocument* pDocument = GetDoc();
194 SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
195 sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
196 sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
197 SetOfByte aVisibleLayers;
198 // Determine the page from which to copy some values, such as layers,
199 // size, master page, to the new page. This is usually the given page.
200 // When the given page is NULL then use the first page of the document.
201 SdPage* pTemplatePage = pPage;
202 if (pTemplatePage == NULL)
203 pTemplatePage = pDocument->GetSdPage(0, ePageKind);
204 if (pTemplatePage != NULL && pTemplatePage->TRG_HasMasterPage())
205 aVisibleLayers = pTemplatePage->TRG_GetMasterPageVisibleLayers();
206 else
207 aVisibleLayers.SetAll();
209 OUString aStandardPageName;
210 OUString aNotesPageName;
211 AutoLayout eStandardLayout (AUTOLAYOUT_NONE);
212 AutoLayout eNotesLayout (AUTOLAYOUT_NOTES);
213 bool bIsPageBack = aVisibleLayers.IsSet(aBckgrnd);
214 bool bIsPageObj = aVisibleLayers.IsSet(aBckgrndObj);
216 // 1. Process the arguments.
217 const SfxItemSet* pArgs = rRequest.GetArgs();
218 if (! pArgs)
220 // AutoLayouts must be ready
221 pDocument->StopWorkStartupDelay();
223 // Use the layouts of the previous page and notes page as template.
224 if (pTemplatePage != NULL)
226 eStandardLayout = pTemplatePage->GetAutoLayout();
227 if( eStandardLayout == AUTOLAYOUT_TITLE )
228 eStandardLayout = AUTOLAYOUT_ENUM;
230 SdPage* pNotesTemplatePage = static_cast<SdPage*>(pDocument->GetPage(pTemplatePage->GetPageNum()+1));
231 if (pNotesTemplatePage != NULL)
232 eNotesLayout = pNotesTemplatePage->GetAutoLayout();
235 else if (pArgs->Count() == 1)
237 pDocument->StopWorkStartupDelay();
238 SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, false);
239 if( pLayout )
241 if (ePageKind == PK_NOTES)
243 eNotesLayout = (AutoLayout) pLayout->GetValue ();
245 else
247 eStandardLayout = (AutoLayout) pLayout->GetValue ();
251 else if (pArgs->Count() == 4)
253 // AutoLayouts must be ready
254 pDocument->StopWorkStartupDelay();
256 SFX_REQUEST_ARG (rRequest, pPageName, SfxStringItem, ID_VAL_PAGENAME, false);
257 SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, false);
258 SFX_REQUEST_ARG (rRequest, pIsPageBack, SfxBoolItem, ID_VAL_ISPAGEBACK, false);
259 SFX_REQUEST_ARG (rRequest, pIsPageObj, SfxBoolItem, ID_VAL_ISPAGEOBJ, false);
261 if (CHECK_RANGE (AUTOLAYOUT__START, (AutoLayout) pLayout->GetValue (), AUTOLAYOUT__END))
263 if (ePageKind == PK_NOTES)
265 aNotesPageName = pPageName->GetValue ();
266 eNotesLayout = (AutoLayout) pLayout->GetValue ();
268 else
270 aStandardPageName = pPageName->GetValue ();
271 eStandardLayout = (AutoLayout) pLayout->GetValue ();
274 bIsPageBack = pIsPageBack->GetValue ();
275 bIsPageObj = pIsPageObj->GetValue ();
277 else
279 Cancel();
281 if(HasCurrentFunction( SID_BEZIER_EDIT ) )
282 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
283 #if HAVE_FEATURE_SCRIPTING
284 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
285 #endif
286 rRequest.Ignore ();
287 return NULL;
290 else
292 Cancel();
294 if(HasCurrentFunction(SID_BEZIER_EDIT) )
295 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
296 #if HAVE_FEATURE_SCRIPTING
297 StarBASIC::FatalError (SbERR_WRONG_ARGS);
298 #endif
299 rRequest.Ignore ();
300 return NULL;
303 // 2. Create a new page or duplicate an existing one.
304 View* pDrView = GetView();
305 const bool bUndo = pDrView && pDrView->IsUndoEnabled();
306 if( bUndo )
307 pDrView->BegUndo(SD_RESSTR(STR_INSERTPAGE));
309 sal_uInt16 nNewPageIndex = 0xffff;
310 switch (nSId)
312 case SID_INSERTPAGE:
313 case SID_INSERTPAGE_QUICK:
314 case SID_INSERT_MASTER_PAGE:
315 // There are three cases. a) pPage is not NULL: we use it as a
316 // template and create a new slide behind it. b) pPage is NULL
317 // but the document is not empty: we use the first slide/notes
318 // page as template, create a new slide after it and move it
319 // then to the head of the document. c) pPage is NULL and the
320 // document is empty: We use CreateFirstPages to create the
321 // first page of the document.
322 if (pPage == NULL)
323 if (pTemplatePage == NULL)
325 pDocument->CreateFirstPages();
326 nNewPageIndex = 0;
328 else
330 // Create a new page with the first page as template and
331 // insert it after the first page.
332 nNewPageIndex = pDocument->CreatePage (
333 pTemplatePage,
334 ePageKind,
335 aStandardPageName,
336 aNotesPageName,
337 eStandardLayout,
338 eNotesLayout,
339 bIsPageBack,
340 bIsPageObj,
341 nInsertPosition);
342 // Select exactly the new page.
343 sal_uInt16 nPageCount (pDocument->GetSdPageCount(ePageKind));
344 for (sal_uInt16 i=0; i<nPageCount; i++)
346 pDocument->GetSdPage(i, PK_STANDARD)->SetSelected(
347 i == nNewPageIndex);
348 pDocument->GetSdPage(i, PK_NOTES)->SetSelected(
349 i == nNewPageIndex);
351 // Move the selected page to the head of the document
352 pDocument->MovePages ((sal_uInt16)-1);
353 nNewPageIndex = 0;
355 else
356 nNewPageIndex = pDocument->CreatePage (
357 pPage,
358 ePageKind,
359 aStandardPageName,
360 aNotesPageName,
361 eStandardLayout,
362 eNotesLayout,
363 bIsPageBack,
364 bIsPageObj,
365 nInsertPosition);
366 break;
368 case SID_DUPLICATE_PAGE:
369 // Duplication makes no sense when pPage is NULL.
370 if (pPage != NULL)
371 nNewPageIndex = pDocument->DuplicatePage (
372 pPage,
373 ePageKind,
374 aStandardPageName,
375 aNotesPageName,
376 bIsPageBack,
377 bIsPageObj,
378 nInsertPosition);
379 break;
381 default:
382 DBG_WARNING("wrong slot id given to CreateOrDuplicatePage");
383 // Try to handle another slot id gracefully.
385 SdPage* pNewPage = 0;
386 if(nNewPageIndex != 0xffff)
387 pNewPage = pDocument->GetSdPage(nNewPageIndex, PK_STANDARD);
389 if( bUndo )
391 if( pNewPage )
393 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage));
394 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pDocument->GetSdPage (nNewPageIndex, PK_NOTES)));
397 pDrView->EndUndo();
400 return pNewPage;
403 } // end of namespace sd
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */