Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <config_features.h>
21 :
22 : #include "ViewShell.hxx"
23 : #include "GraphicViewShell.hxx"
24 : #include "GraphicViewShellBase.hxx"
25 :
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>
32 :
33 : #include "app.hrc"
34 : #include "strings.hrc"
35 : #include "res_bmp.hrc"
36 : #include "glob.hrc"
37 : #include "sdabstdlg.hxx"
38 :
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"
62 :
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"
74 :
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>
80 :
81 : using namespace ::com::sun::star;
82 :
83 : namespace sd {
84 :
85 : /**
86 : * set state (enabled/disabled) of Menu SfxSlots
87 : */
88 4221 : void ViewShell::GetMenuState( SfxItemSet &rSet )
89 : {
90 4221 : if( SfxItemState::DEFAULT == rSet.GetItemState( SID_STYLE_FAMILY ) )
91 : {
92 0 : sal_uInt16 nFamily = (sal_uInt16)GetDocSh()->GetStyleFamily();
93 :
94 0 : SdrView* pDrView = GetDrawView();
95 :
96 0 : if( pDrView->AreObjectsMarked() )
97 : {
98 0 : SfxStyleSheet* pStyleSheet = pDrView->GetStyleSheet();
99 0 : if( pStyleSheet )
100 : {
101 0 : if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
102 0 : pStyleSheet = ((SdStyleSheet*)pStyleSheet)->GetPseudoStyleSheet();
103 :
104 0 : if( pStyleSheet )
105 : {
106 0 : SfxStyleFamily eFamily = pStyleSheet->GetFamily();
107 0 : nFamily = SfxTemplate::SfxFamilyIdToNId(eFamily);
108 0 : GetDocSh()->SetStyleFamily(nFamily);
109 : }
110 : }
111 : }
112 :
113 0 : rSet.Put(SfxUInt16Item(SID_STYLE_FAMILY, nFamily ));
114 : }
115 :
116 4221 : if(SfxItemState::DEFAULT == rSet.GetItemState(SID_GETUNDOSTRINGS))
117 : {
118 0 : ImpGetUndoStrings(rSet);
119 : }
120 :
121 4221 : if(SfxItemState::DEFAULT == rSet.GetItemState(SID_GETREDOSTRINGS))
122 : {
123 0 : ImpGetRedoStrings(rSet);
124 : }
125 :
126 4221 : if(SfxItemState::DEFAULT == rSet.GetItemState(SID_UNDO))
127 : {
128 136 : ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
129 136 : bool bActivate(false);
130 :
131 136 : if(pUndoManager)
132 : {
133 136 : if(pUndoManager->GetUndoActionCount() != 0)
134 : {
135 17 : bActivate = true;
136 : }
137 : }
138 :
139 136 : if(bActivate)
140 : {
141 : // Set the necessary string like in
142 : // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
143 17 : OUString aTmp(SVT_RESSTR(STR_UNDO));
144 17 : aTmp += pUndoManager->GetUndoActionComment(0);
145 17 : rSet.Put(SfxStringItem(SID_UNDO, aTmp));
146 : }
147 : else
148 : {
149 119 : rSet.DisableItem(SID_UNDO);
150 : }
151 : }
152 :
153 4221 : if(SfxItemState::DEFAULT == rSet.GetItemState(SID_REDO))
154 : {
155 128 : ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
156 128 : bool bActivate(false);
157 :
158 128 : if(pUndoManager)
159 : {
160 128 : if(pUndoManager->GetRedoActionCount() != 0)
161 : {
162 4 : bActivate = true;
163 : }
164 : }
165 :
166 128 : if(bActivate)
167 : {
168 : // Set the necessary string like in
169 : // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
170 4 : OUString aTmp(SVT_RESSTR(STR_REDO));
171 4 : aTmp += pUndoManager->GetRedoActionComment(0);
172 4 : rSet.Put(SfxStringItem(SID_REDO, aTmp));
173 : }
174 : else
175 : {
176 124 : rSet.DisableItem(SID_REDO);
177 : }
178 : }
179 4221 : }
180 :
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.
185 : */
186 0 : SdPage* ViewShell::CreateOrDuplicatePage (
187 : SfxRequest& rRequest,
188 : PageKind ePageKind,
189 : SdPage* pPage,
190 : const sal_Int32 nInsertPosition)
191 : {
192 0 : sal_uInt16 nSId = rRequest.GetSlot();
193 0 : SdDrawDocument* pDocument = GetDoc();
194 0 : SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
195 0 : sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRND), false);
196 0 : sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(SD_RESSTR(STR_LAYER_BCKGRNDOBJ), false);
197 0 : 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 0 : SdPage* pTemplatePage = pPage;
202 0 : if (pTemplatePage == NULL)
203 0 : pTemplatePage = pDocument->GetSdPage(0, ePageKind);
204 0 : if (pTemplatePage != NULL && pTemplatePage->TRG_HasMasterPage())
205 0 : aVisibleLayers = pTemplatePage->TRG_GetMasterPageVisibleLayers();
206 : else
207 0 : aVisibleLayers.SetAll();
208 :
209 0 : OUString aStandardPageName;
210 0 : OUString aNotesPageName;
211 0 : AutoLayout eStandardLayout (AUTOLAYOUT_NONE);
212 0 : AutoLayout eNotesLayout (AUTOLAYOUT_NOTES);
213 0 : bool bIsPageBack = aVisibleLayers.IsSet(aBckgrnd);
214 0 : bool bIsPageObj = aVisibleLayers.IsSet(aBckgrndObj);
215 :
216 : // 1. Process the arguments.
217 0 : const SfxItemSet* pArgs = rRequest.GetArgs();
218 0 : if (! pArgs)
219 : {
220 : // AutoLayouts must be ready
221 0 : pDocument->StopWorkStartupDelay();
222 :
223 : // Use the layouts of the previous page and notes page as template.
224 0 : if (pTemplatePage != NULL)
225 : {
226 0 : eStandardLayout = pTemplatePage->GetAutoLayout();
227 0 : if( eStandardLayout == AUTOLAYOUT_TITLE )
228 0 : eStandardLayout = AUTOLAYOUT_ENUM;
229 :
230 0 : SdPage* pNotesTemplatePage = static_cast<SdPage*>(pDocument->GetPage(pTemplatePage->GetPageNum()+1));
231 0 : if (pNotesTemplatePage != NULL)
232 0 : eNotesLayout = pNotesTemplatePage->GetAutoLayout();
233 : }
234 : }
235 0 : else if (pArgs->Count() == 1)
236 : {
237 0 : pDocument->StopWorkStartupDelay();
238 0 : SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, false);
239 0 : if( pLayout )
240 : {
241 0 : if (ePageKind == PK_NOTES)
242 : {
243 0 : eNotesLayout = (AutoLayout) pLayout->GetValue ();
244 : }
245 : else
246 : {
247 0 : eStandardLayout = (AutoLayout) pLayout->GetValue ();
248 : }
249 : }
250 : }
251 0 : else if (pArgs->Count() == 4)
252 : {
253 : // AutoLayouts must be ready
254 0 : pDocument->StopWorkStartupDelay();
255 :
256 0 : SFX_REQUEST_ARG (rRequest, pPageName, SfxStringItem, ID_VAL_PAGENAME, false);
257 0 : SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, false);
258 0 : SFX_REQUEST_ARG (rRequest, pIsPageBack, SfxBoolItem, ID_VAL_ISPAGEBACK, false);
259 0 : SFX_REQUEST_ARG (rRequest, pIsPageObj, SfxBoolItem, ID_VAL_ISPAGEOBJ, false);
260 :
261 0 : if (CHECK_RANGE (AUTOLAYOUT__START, (AutoLayout) pLayout->GetValue (), AUTOLAYOUT__END))
262 : {
263 0 : if (ePageKind == PK_NOTES)
264 : {
265 0 : aNotesPageName = pPageName->GetValue ();
266 0 : eNotesLayout = (AutoLayout) pLayout->GetValue ();
267 : }
268 : else
269 : {
270 0 : aStandardPageName = pPageName->GetValue ();
271 0 : eStandardLayout = (AutoLayout) pLayout->GetValue ();
272 : }
273 :
274 0 : bIsPageBack = pIsPageBack->GetValue ();
275 0 : bIsPageObj = pIsPageObj->GetValue ();
276 : }
277 : else
278 : {
279 0 : Cancel();
280 :
281 0 : if(HasCurrentFunction( SID_BEZIER_EDIT ) )
282 0 : GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
283 : #if HAVE_FEATURE_SCRIPTING
284 0 : StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
285 : #endif
286 0 : rRequest.Ignore ();
287 0 : return NULL;
288 : }
289 : }
290 : else
291 : {
292 0 : Cancel();
293 :
294 0 : if(HasCurrentFunction(SID_BEZIER_EDIT) )
295 0 : GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
296 : #if HAVE_FEATURE_SCRIPTING
297 0 : StarBASIC::FatalError (SbERR_WRONG_ARGS);
298 : #endif
299 0 : rRequest.Ignore ();
300 0 : return NULL;
301 : }
302 :
303 : // 2. Create a new page or duplicate an existing one.
304 0 : View* pDrView = GetView();
305 0 : const bool bUndo = pDrView && pDrView->IsUndoEnabled();
306 0 : if( bUndo )
307 0 : pDrView->BegUndo(SD_RESSTR(STR_INSERTPAGE));
308 :
309 0 : sal_uInt16 nNewPageIndex = 0xffff;
310 0 : switch (nSId)
311 : {
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 0 : if (pPage == NULL)
323 0 : if (pTemplatePage == NULL)
324 : {
325 0 : pDocument->CreateFirstPages();
326 0 : nNewPageIndex = 0;
327 : }
328 : else
329 : {
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 0 : nInsertPosition);
342 : // Select exactly the new page.
343 0 : sal_uInt16 nPageCount (pDocument->GetSdPageCount(ePageKind));
344 0 : for (sal_uInt16 i=0; i<nPageCount; i++)
345 : {
346 : pDocument->GetSdPage(i, PK_STANDARD)->SetSelected(
347 0 : i == nNewPageIndex);
348 : pDocument->GetSdPage(i, PK_NOTES)->SetSelected(
349 0 : i == nNewPageIndex);
350 : }
351 : // Move the selected page to the head of the document
352 0 : pDocument->MovePages ((sal_uInt16)-1);
353 0 : nNewPageIndex = 0;
354 : }
355 : else
356 : nNewPageIndex = pDocument->CreatePage (
357 : pPage,
358 : ePageKind,
359 : aStandardPageName,
360 : aNotesPageName,
361 : eStandardLayout,
362 : eNotesLayout,
363 : bIsPageBack,
364 : bIsPageObj,
365 0 : nInsertPosition);
366 0 : break;
367 :
368 : case SID_DUPLICATE_PAGE:
369 : // Duplication makes no sense when pPage is NULL.
370 0 : if (pPage != NULL)
371 : nNewPageIndex = pDocument->DuplicatePage (
372 : pPage,
373 : ePageKind,
374 : aStandardPageName,
375 : aNotesPageName,
376 : bIsPageBack,
377 : bIsPageObj,
378 0 : nInsertPosition);
379 0 : break;
380 :
381 : default:
382 : DBG_WARNING("wrong slot id given to CreateOrDuplicatePage");
383 : // Try to handle another slot id gracefully.
384 : }
385 0 : SdPage* pNewPage = 0;
386 0 : if(nNewPageIndex != 0xffff)
387 0 : pNewPage = pDocument->GetSdPage(nNewPageIndex, PK_STANDARD);
388 :
389 0 : if( bUndo )
390 : {
391 0 : if( pNewPage )
392 : {
393 0 : pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage));
394 0 : pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pDocument->GetSdPage (nNewPageIndex, PK_NOTES)));
395 : }
396 :
397 0 : pDrView->EndUndo();
398 : }
399 :
400 0 : return pNewPage;
401 : }
402 :
403 114 : } // end of namespace sd
404 :
405 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|