xref: /AOO41X/main/sd/source/ui/view/viewshe3.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "ViewShell.hxx"
33*cdf0e10cSrcweir #include "GraphicViewShell.hxx"
34*cdf0e10cSrcweir #include "GraphicViewShellBase.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
37*cdf0e10cSrcweir #include <svtools/svtools.hrc>
38*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
39*cdf0e10cSrcweir #include <svtools/svtdata.hxx>
40*cdf0e10cSrcweir #include <utility>
41*cdf0e10cSrcweir #include <vector>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include "app.hrc"
44*cdf0e10cSrcweir #include "strings.hrc"
45*cdf0e10cSrcweir #include "res_bmp.hrc"
46*cdf0e10cSrcweir #include "glob.hrc"
47*cdf0e10cSrcweir #include "sdabstdlg.hxx"
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include "fupoor.hxx"
50*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
51*cdf0e10cSrcweir #include <svx/prtqry.hxx>
52*cdf0e10cSrcweir #include <svx/svdopage.hxx>
53*cdf0e10cSrcweir #include <sfx2/progress.hxx>
54*cdf0e10cSrcweir #include <svx/svdobj.hxx>
55*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
56*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
57*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
58*cdf0e10cSrcweir #include <svx/svdetc.hxx>
59*cdf0e10cSrcweir #include <editeng/outliner.hxx>
60*cdf0e10cSrcweir #include <editeng/editstat.hxx>
61*cdf0e10cSrcweir #include <tools/multisel.hxx>
62*cdf0e10cSrcweir #include <svl/intitem.hxx>
63*cdf0e10cSrcweir #include <svl/style.hxx>
64*cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
65*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
66*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
67*cdf0e10cSrcweir #include "stlsheet.hxx"
68*cdf0e10cSrcweir #ifndef SD_WINDOW_UPDATER_HXX
69*cdf0e10cSrcweir #include "WindowUpdater.hxx"
70*cdf0e10cSrcweir #endif
71*cdf0e10cSrcweir #include "DrawViewShell.hxx"
72*cdf0e10cSrcweir #include "OutlineViewShell.hxx"
73*cdf0e10cSrcweir #include "drawview.hxx"
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir #include "sdattr.hxx"
76*cdf0e10cSrcweir #include "drawdoc.hxx"
77*cdf0e10cSrcweir #include "sdpage.hxx"
78*cdf0e10cSrcweir #include "unoaprms.hxx"                 // Undo-Action
79*cdf0e10cSrcweir #include "sdundogr.hxx"                 // Undo Gruppe
80*cdf0e10cSrcweir #include "Window.hxx"
81*cdf0e10cSrcweir #include "DrawDocShell.hxx"
82*cdf0e10cSrcweir #include "FrameView.hxx"
83*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
84*cdf0e10cSrcweir #include "optsitem.hxx"
85*cdf0e10cSrcweir #include "sdresid.hxx"
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // #96090#
88*cdf0e10cSrcweir #ifndef _SVXIDS_HXX
89*cdf0e10cSrcweir #include <svx/svxids.hrc>
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #include <sfx2/request.hxx>
92*cdf0e10cSrcweir #include <svl/aeitem.hxx>
93*cdf0e10cSrcweir #include <basic/sbstar.hxx>
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir using namespace ::com::sun::star;
96*cdf0e10cSrcweir using namespace ::rtl;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir namespace sd {
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir /*************************************************************************
101*cdf0e10cSrcweir |*
102*cdf0e10cSrcweir |* Status (Enabled/Disabled) von Menue-SfxSlots setzen
103*cdf0e10cSrcweir |*
104*cdf0e10cSrcweir \************************************************************************/
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir void  ViewShell::GetMenuState( SfxItemSet &rSet )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STYLE_FAMILY ) )
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		sal_uInt16 nFamily = (sal_uInt16)GetDocSh()->GetStyleFamily();
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 		SdrView* pDrView = GetDrawView();
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 		if( pDrView->AreObjectsMarked() )
115*cdf0e10cSrcweir 		{
116*cdf0e10cSrcweir 			SfxStyleSheet* pStyleSheet = pDrView->GetStyleSheet();
117*cdf0e10cSrcweir 			if( pStyleSheet )
118*cdf0e10cSrcweir 			{
119*cdf0e10cSrcweir 				if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
120*cdf0e10cSrcweir 					pStyleSheet = ((SdStyleSheet*)pStyleSheet)->GetPseudoStyleSheet();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 				if( pStyleSheet )
123*cdf0e10cSrcweir 				{
124*cdf0e10cSrcweir 					SfxStyleFamily eFamily = pStyleSheet->GetFamily();
125*cdf0e10cSrcweir 					if(eFamily == SD_STYLE_FAMILY_GRAPHICS)
126*cdf0e10cSrcweir 						nFamily = 2;
127*cdf0e10cSrcweir 					else if(eFamily == SD_STYLE_FAMILY_CELL )
128*cdf0e10cSrcweir 						nFamily = 3;
129*cdf0e10cSrcweir 					else // SD_STYLE_FAMILY_PSEUDO
130*cdf0e10cSrcweir 						nFamily = 5;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 					GetDocSh()->SetStyleFamily(nFamily);
133*cdf0e10cSrcweir 				}
134*cdf0e10cSrcweir 			}
135*cdf0e10cSrcweir 		}
136*cdf0e10cSrcweir 		rSet.Put(SfxUInt16Item(SID_STYLE_FAMILY, nFamily ));
137*cdf0e10cSrcweir 	}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	// #96090#
140*cdf0e10cSrcweir     if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETUNDOSTRINGS))
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		ImpGetUndoStrings(rSet);
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	// #96090#
146*cdf0e10cSrcweir     if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETREDOSTRINGS))
147*cdf0e10cSrcweir 	{
148*cdf0e10cSrcweir 		ImpGetRedoStrings(rSet);
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 	// #96090#
152*cdf0e10cSrcweir     if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_UNDO))
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
155*cdf0e10cSrcweir 		sal_Bool bActivate(sal_False);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		if(pUndoManager)
158*cdf0e10cSrcweir 		{
159*cdf0e10cSrcweir 			if(pUndoManager->GetUndoActionCount() != 0)
160*cdf0e10cSrcweir 			{
161*cdf0e10cSrcweir 				bActivate = sal_True;
162*cdf0e10cSrcweir 			}
163*cdf0e10cSrcweir 		}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 		if(bActivate)
166*cdf0e10cSrcweir 		{
167*cdf0e10cSrcweir 			// #87229# Set the necessary string like in
168*cdf0e10cSrcweir 			// sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
169*cdf0e10cSrcweir 			String aTmp( SvtResId( STR_UNDO ) );
170*cdf0e10cSrcweir 			aTmp += pUndoManager->GetUndoActionComment(0);
171*cdf0e10cSrcweir 			rSet.Put(SfxStringItem(SID_UNDO, aTmp));
172*cdf0e10cSrcweir 		}
173*cdf0e10cSrcweir 		else
174*cdf0e10cSrcweir 		{
175*cdf0e10cSrcweir 			rSet.DisableItem(SID_UNDO);
176*cdf0e10cSrcweir 		}
177*cdf0e10cSrcweir 	}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	// #96090#
180*cdf0e10cSrcweir     if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_REDO))
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
183*cdf0e10cSrcweir 		sal_Bool bActivate(sal_False);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 		if(pUndoManager)
186*cdf0e10cSrcweir 		{
187*cdf0e10cSrcweir 			if(pUndoManager->GetRedoActionCount() != 0)
188*cdf0e10cSrcweir 			{
189*cdf0e10cSrcweir 				bActivate = sal_True;
190*cdf0e10cSrcweir 			}
191*cdf0e10cSrcweir 		}
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		if(bActivate)
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 			// #87229# Set the necessary string like in
196*cdf0e10cSrcweir 			// sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
197*cdf0e10cSrcweir 			String aTmp(SvtResId(STR_REDO));
198*cdf0e10cSrcweir 			aTmp += pUndoManager->GetRedoActionComment(0);
199*cdf0e10cSrcweir 			rSet.Put(SfxStringItem(SID_REDO, aTmp));
200*cdf0e10cSrcweir 		}
201*cdf0e10cSrcweir 		else
202*cdf0e10cSrcweir 		{
203*cdf0e10cSrcweir 			rSet.DisableItem(SID_REDO);
204*cdf0e10cSrcweir 		}
205*cdf0e10cSrcweir 	}
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir /** This method consists basically of three parts:
212*cdf0e10cSrcweir     1. Process the arguments of the SFX request.
213*cdf0e10cSrcweir     2. Use the model to create a new page or duplicate an existing one.
214*cdf0e10cSrcweir     3. Update the tab control and switch to the new page.
215*cdf0e10cSrcweir */
216*cdf0e10cSrcweir SdPage* ViewShell::CreateOrDuplicatePage (
217*cdf0e10cSrcweir     SfxRequest& rRequest,
218*cdf0e10cSrcweir     PageKind ePageKind,
219*cdf0e10cSrcweir     SdPage* pPage,
220*cdf0e10cSrcweir     const sal_Int32 nInsertPosition)
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir 	sal_uInt16 nSId = rRequest.GetSlot();
223*cdf0e10cSrcweir     SdDrawDocument* pDocument = GetDoc();
224*cdf0e10cSrcweir     SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
225*cdf0e10cSrcweir     sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
226*cdf0e10cSrcweir     sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
227*cdf0e10cSrcweir     SetOfByte aVisibleLayers;
228*cdf0e10cSrcweir     // Determine the page from which to copy some values, such as layers,
229*cdf0e10cSrcweir     // size, master page, to the new page.  This is usually the given page.
230*cdf0e10cSrcweir     // When the given page is NULL then use the first page of the document.
231*cdf0e10cSrcweir     SdPage* pTemplatePage = pPage;
232*cdf0e10cSrcweir     if (pTemplatePage == NULL)
233*cdf0e10cSrcweir         if (pDocument->GetSdPage(0, ePageKind) > 0)
234*cdf0e10cSrcweir             pTemplatePage = pDocument->GetSdPage(0, ePageKind);
235*cdf0e10cSrcweir     if (pTemplatePage != NULL && pTemplatePage->TRG_HasMasterPage())
236*cdf0e10cSrcweir         aVisibleLayers = pTemplatePage->TRG_GetMasterPageVisibleLayers();
237*cdf0e10cSrcweir     else
238*cdf0e10cSrcweir         aVisibleLayers.SetAll();
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     String aStandardPageName;
241*cdf0e10cSrcweir     String aNotesPageName;
242*cdf0e10cSrcweir     AutoLayout eStandardLayout (AUTOLAYOUT_NONE);
243*cdf0e10cSrcweir     AutoLayout eNotesLayout (AUTOLAYOUT_NOTES);
244*cdf0e10cSrcweir     sal_Bool bIsPageBack = aVisibleLayers.IsSet(aBckgrnd);
245*cdf0e10cSrcweir     sal_Bool bIsPageObj = aVisibleLayers.IsSet(aBckgrndObj);
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     // 1. Process the arguments.
248*cdf0e10cSrcweir     const SfxItemSet* pArgs = rRequest.GetArgs();
249*cdf0e10cSrcweir     if (! pArgs)
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir /*
252*cdf0e10cSrcweir         // Make the layout menu visible in the tool pane.
253*cdf0e10cSrcweir         const ViewShellBase& rBase (GetViewShellBase());
254*cdf0e10cSrcweir 		if (rBase.GetMainViewShell()!=NULL
255*cdf0e10cSrcweir             && rBase.GetMainViewShell()->GetShellType()!=ViewShell::ST_OUTLINE
256*cdf0e10cSrcweir             && rBase.GetMainViewShell()->GetShellType()!=ViewShell::ST_DRAW)
257*cdf0e10cSrcweir         {
258*cdf0e10cSrcweir             framework::FrameworkHelper::Instance(GetViewShellBase())->RequestTaskPanel(
259*cdf0e10cSrcweir                 framework::FrameworkHelper::msLayoutTaskPanelURL,
260*cdf0e10cSrcweir                 false);
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir */
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         // AutoLayouts muessen fertig sein
265*cdf0e10cSrcweir         pDocument->StopWorkStartupDelay();
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         // Use the layouts of the previous page and notes page as template.
268*cdf0e10cSrcweir         if (pTemplatePage != NULL)
269*cdf0e10cSrcweir         {
270*cdf0e10cSrcweir             eStandardLayout = pTemplatePage->GetAutoLayout();
271*cdf0e10cSrcweir 			if( eStandardLayout == AUTOLAYOUT_TITLE )
272*cdf0e10cSrcweir 				eStandardLayout = AUTOLAYOUT_ENUM;
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir             SdPage* pNotesTemplatePage = static_cast<SdPage*>(pDocument->GetPage(pTemplatePage->GetPageNum()+1));
275*cdf0e10cSrcweir             if (pNotesTemplatePage != NULL)
276*cdf0e10cSrcweir                 eNotesLayout = pNotesTemplatePage->GetAutoLayout();
277*cdf0e10cSrcweir         }
278*cdf0e10cSrcweir     }
279*cdf0e10cSrcweir     else if (pArgs->Count() == 1)
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         pDocument->StopWorkStartupDelay();
282*cdf0e10cSrcweir         SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, sal_False);
283*cdf0e10cSrcweir 		if( pLayout )
284*cdf0e10cSrcweir 		{
285*cdf0e10cSrcweir             if (ePageKind == PK_NOTES)
286*cdf0e10cSrcweir             {
287*cdf0e10cSrcweir                 eNotesLayout   = (AutoLayout) pLayout->GetValue ();
288*cdf0e10cSrcweir             }
289*cdf0e10cSrcweir             else
290*cdf0e10cSrcweir             {
291*cdf0e10cSrcweir                 eStandardLayout   = (AutoLayout) pLayout->GetValue ();
292*cdf0e10cSrcweir             }
293*cdf0e10cSrcweir 		}
294*cdf0e10cSrcweir 	}
295*cdf0e10cSrcweir     else if (pArgs->Count() == 4)
296*cdf0e10cSrcweir     {
297*cdf0e10cSrcweir         // AutoLayouts muessen fertig sein
298*cdf0e10cSrcweir         pDocument->StopWorkStartupDelay();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir         SFX_REQUEST_ARG (rRequest, pPageName, SfxStringItem, ID_VAL_PAGENAME, sal_False);
301*cdf0e10cSrcweir         SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, sal_False);
302*cdf0e10cSrcweir         SFX_REQUEST_ARG (rRequest, pIsPageBack, SfxBoolItem, ID_VAL_ISPAGEBACK, sal_False);
303*cdf0e10cSrcweir         SFX_REQUEST_ARG (rRequest, pIsPageObj, SfxBoolItem, ID_VAL_ISPAGEOBJ, sal_False);
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir         if (CHECK_RANGE (AUTOLAYOUT__START, (AutoLayout) pLayout->GetValue (), AUTOLAYOUT__END))
306*cdf0e10cSrcweir         {
307*cdf0e10cSrcweir             if (ePageKind == PK_NOTES)
308*cdf0e10cSrcweir             {
309*cdf0e10cSrcweir                 aNotesPageName = pPageName->GetValue ();
310*cdf0e10cSrcweir                 eNotesLayout   = (AutoLayout) pLayout->GetValue ();
311*cdf0e10cSrcweir             }
312*cdf0e10cSrcweir             else
313*cdf0e10cSrcweir             {
314*cdf0e10cSrcweir                 aStandardPageName = pPageName->GetValue ();
315*cdf0e10cSrcweir                 eStandardLayout   = (AutoLayout) pLayout->GetValue ();
316*cdf0e10cSrcweir             }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir             bIsPageBack = pIsPageBack->GetValue ();
319*cdf0e10cSrcweir             bIsPageObj	= pIsPageObj->GetValue ();
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir         else
322*cdf0e10cSrcweir         {
323*cdf0e10cSrcweir             Cancel();
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir             if(HasCurrentFunction( SID_BEZIER_EDIT ) )
326*cdf0e10cSrcweir                 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir             StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
329*cdf0e10cSrcweir             rRequest.Ignore ();
330*cdf0e10cSrcweir             return NULL;
331*cdf0e10cSrcweir         }
332*cdf0e10cSrcweir     }
333*cdf0e10cSrcweir     else
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         Cancel();
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir         if(HasCurrentFunction(SID_BEZIER_EDIT) )
338*cdf0e10cSrcweir             GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir         StarBASIC::FatalError (SbERR_WRONG_ARGS);
341*cdf0e10cSrcweir         rRequest.Ignore ();
342*cdf0e10cSrcweir         return NULL;
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     // 2. Create a new page or duplicate an existing one.
346*cdf0e10cSrcweir     View* pDrView = GetView();
347*cdf0e10cSrcweir 	const bool bUndo = pDrView && pDrView->IsUndoEnabled();
348*cdf0e10cSrcweir 	if( bUndo )
349*cdf0e10cSrcweir 		pDrView->BegUndo( String( SdResId(STR_INSERTPAGE) ) );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     sal_uInt16 nNewPageIndex = 0xffff;
352*cdf0e10cSrcweir     switch (nSId)
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         case SID_INSERTPAGE:
355*cdf0e10cSrcweir         case SID_INSERTPAGE_QUICK:
356*cdf0e10cSrcweir         case SID_INSERT_MASTER_PAGE:
357*cdf0e10cSrcweir             // There are three cases.  a) pPage is not NULL: we use it as a
358*cdf0e10cSrcweir             // template and create a new slide behind it. b) pPage is NULL
359*cdf0e10cSrcweir             // but the document is not empty: we use the first slide/notes
360*cdf0e10cSrcweir             // page as template, create a new slide after it and move it
361*cdf0e10cSrcweir             // then to the head of the document. c) pPage is NULL and the
362*cdf0e10cSrcweir             // document is empty: We use CreateFirstPages to create the
363*cdf0e10cSrcweir             // first page of the document.
364*cdf0e10cSrcweir             if (pPage == NULL)
365*cdf0e10cSrcweir                 if (pTemplatePage == NULL)
366*cdf0e10cSrcweir                 {
367*cdf0e10cSrcweir                     pDocument->CreateFirstPages();
368*cdf0e10cSrcweir                     nNewPageIndex = 0;
369*cdf0e10cSrcweir                 }
370*cdf0e10cSrcweir                 else
371*cdf0e10cSrcweir                 {
372*cdf0e10cSrcweir                     // Create a new page with the first page as template and
373*cdf0e10cSrcweir                     // insert it after the first page.
374*cdf0e10cSrcweir                     nNewPageIndex = pDocument->CreatePage (
375*cdf0e10cSrcweir                         pTemplatePage,
376*cdf0e10cSrcweir                         ePageKind,
377*cdf0e10cSrcweir                         aStandardPageName,
378*cdf0e10cSrcweir                         aNotesPageName,
379*cdf0e10cSrcweir                         eStandardLayout,
380*cdf0e10cSrcweir                         eNotesLayout,
381*cdf0e10cSrcweir                         bIsPageBack,
382*cdf0e10cSrcweir                         bIsPageObj,
383*cdf0e10cSrcweir                         nInsertPosition);
384*cdf0e10cSrcweir                     // Select exactly the new page.
385*cdf0e10cSrcweir                     sal_uInt16 nPageCount (pDocument->GetSdPageCount(ePageKind));
386*cdf0e10cSrcweir                     for (sal_uInt16 i=0; i<nPageCount; i++)
387*cdf0e10cSrcweir                     {
388*cdf0e10cSrcweir                         pDocument->GetSdPage(i, PK_STANDARD)->SetSelected(
389*cdf0e10cSrcweir                             i == nNewPageIndex);
390*cdf0e10cSrcweir                         pDocument->GetSdPage(i, PK_NOTES)->SetSelected(
391*cdf0e10cSrcweir                             i == nNewPageIndex);
392*cdf0e10cSrcweir                     }
393*cdf0e10cSrcweir                     // Move the selected page to the head of the document
394*cdf0e10cSrcweir                     pDocument->MovePages ((sal_uInt16)-1);
395*cdf0e10cSrcweir                     nNewPageIndex = 0;
396*cdf0e10cSrcweir                 }
397*cdf0e10cSrcweir             else
398*cdf0e10cSrcweir                 nNewPageIndex = pDocument->CreatePage (
399*cdf0e10cSrcweir                     pPage,
400*cdf0e10cSrcweir                     ePageKind,
401*cdf0e10cSrcweir                     aStandardPageName,
402*cdf0e10cSrcweir                     aNotesPageName,
403*cdf0e10cSrcweir                     eStandardLayout,
404*cdf0e10cSrcweir                     eNotesLayout,
405*cdf0e10cSrcweir                     bIsPageBack,
406*cdf0e10cSrcweir                     bIsPageObj,
407*cdf0e10cSrcweir                     nInsertPosition);
408*cdf0e10cSrcweir             break;
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 		case SID_DUPLICATE_PAGE:
411*cdf0e10cSrcweir             // Duplication makes no sense when pPage is NULL.
412*cdf0e10cSrcweir             if (pPage != NULL)
413*cdf0e10cSrcweir                 nNewPageIndex = pDocument->DuplicatePage (
414*cdf0e10cSrcweir                     pPage,
415*cdf0e10cSrcweir                     ePageKind,
416*cdf0e10cSrcweir                     aStandardPageName,
417*cdf0e10cSrcweir                     aNotesPageName,
418*cdf0e10cSrcweir                     eStandardLayout,
419*cdf0e10cSrcweir                     eNotesLayout,
420*cdf0e10cSrcweir                     bIsPageBack,
421*cdf0e10cSrcweir                     bIsPageObj,
422*cdf0e10cSrcweir                     nInsertPosition);
423*cdf0e10cSrcweir             break;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         default:
426*cdf0e10cSrcweir             DBG_WARNING("wrong slot id given to CreateOrDuplicatePage");
427*cdf0e10cSrcweir             // Try to handle another slot id gracefully.
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir 	SdPage* pNewPage = 0;
430*cdf0e10cSrcweir 	if(nNewPageIndex != 0xffff)
431*cdf0e10cSrcweir 		pNewPage = pDocument->GetSdPage(nNewPageIndex, PK_STANDARD);
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	if( bUndo )
434*cdf0e10cSrcweir 	{
435*cdf0e10cSrcweir 		if( pNewPage )
436*cdf0e10cSrcweir 		{
437*cdf0e10cSrcweir 			pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage));
438*cdf0e10cSrcweir 			pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pDocument->GetSdPage (nNewPageIndex, PK_NOTES)));
439*cdf0e10cSrcweir 		}
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 		pDrView->EndUndo();
442*cdf0e10cSrcweir 	}
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     return pNewPage;
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir } // end of namespace sd
449