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 "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>
34 #include "strings.hrc"
35 #include "res_bmp.hrc"
37 #include "sdabstdlg.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"
64 #include "drawdoc.hxx"
66 #include "unoaprms.hxx"
67 #include "sdundogr.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
;
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();
101 if (pStyleSheet
->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE
)
102 pStyleSheet
= static_cast<SdStyleSheet
*>(pStyleSheet
)->GetPseudoStyleSheet();
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);
133 if(pUndoManager
->GetUndoActionCount() != 0)
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
));
149 rSet
.DisableItem(SID_UNDO
);
153 if(SfxItemState::DEFAULT
== rSet
.GetItemState(SID_REDO
))
155 ::svl::IUndoManager
* pUndoManager
= ImpGetUndoManager();
156 bool bActivate(false);
160 if(pUndoManager
->GetRedoActionCount() != 0)
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
));
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
,
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();
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();
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);
241 if (ePageKind
== PK_NOTES
)
243 eNotesLayout
= (AutoLayout
) pLayout
->GetValue ();
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 ();
270 aStandardPageName
= pPageName
->GetValue ();
271 eStandardLayout
= (AutoLayout
) pLayout
->GetValue ();
274 bIsPageBack
= pIsPageBack
->GetValue ();
275 bIsPageObj
= pIsPageObj
->GetValue ();
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
);
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
);
303 // 2. Create a new page or duplicate an existing one.
304 View
* pDrView
= GetView();
305 const bool bUndo
= pDrView
&& pDrView
->IsUndoEnabled();
307 pDrView
->BegUndo(SD_RESSTR(STR_INSERTPAGE
));
309 sal_uInt16 nNewPageIndex
= 0xffff;
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.
323 if (pTemplatePage
== NULL
)
325 pDocument
->CreateFirstPages();
330 // Create a new page with the first page as template and
331 // insert it after the first page.
332 nNewPageIndex
= pDocument
->CreatePage (
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(
348 pDocument
->GetSdPage(i
, PK_NOTES
)->SetSelected(
351 // Move the selected page to the head of the document
352 pDocument
->MovePages ((sal_uInt16
)-1);
356 nNewPageIndex
= pDocument
->CreatePage (
368 case SID_DUPLICATE_PAGE
:
369 // Duplication makes no sense when pPage is NULL.
371 nNewPageIndex
= pDocument
->DuplicatePage (
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
);
393 pDrView
->AddUndo(pDocument
->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage
));
394 pDrView
->AddUndo(pDocument
->GetSdrUndoFactory().CreateUndoNewPage(*pDocument
->GetSdPage (nNewPageIndex
, PK_NOTES
)));
403 } // end of namespace sd
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */