fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / view / viewshe3.cxx
blob54d5fcaf587198420c945cb0ce67614f8aba47cb
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 "ViewShell.hxx"
21 #include "GraphicViewShell.hxx"
22 #include "GraphicViewShellBase.hxx"
24 #include <sfx2/viewfrm.hxx>
25 #include <svtools/svtools.hrc>
26 #include <com/sun/star/lang/Locale.hpp>
27 #include <svtools/svtresid.hxx>
28 #include <utility>
29 #include <vector>
31 #include "app.hrc"
32 #include "strings.hrc"
33 #include "res_bmp.hrc"
34 #include "glob.hrc"
35 #include "sdabstdlg.hxx"
37 #include "fupoor.hxx"
38 #include <sfx2/dispatch.hxx>
39 #include <svx/prtqry.hxx>
40 #include <svx/svdopage.hxx>
41 #include <sfx2/progress.hxx>
42 #include <svx/svdobj.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <svx/svdpagv.hxx>
46 #include <svx/svdetc.hxx>
47 #include <editeng/outliner.hxx>
48 #include <editeng/editstat.hxx>
49 #include <tools/multisel.hxx>
50 #include <svl/intitem.hxx>
51 #include <svl/style.hxx>
52 #include <unotools/localedatawrapper.hxx>
53 #include <comphelper/processfactory.hxx>
54 #include <rtl/ustrbuf.hxx>
55 #include "stlsheet.hxx"
56 #include "WindowUpdater.hxx"
57 #include "DrawViewShell.hxx"
58 #include "OutlineViewShell.hxx"
59 #include "drawview.hxx"
61 #include "sdattr.hxx"
62 #include "drawdoc.hxx"
63 #include "sdpage.hxx"
64 #include "unoaprms.hxx" // Undo-Action
65 #include "sdundogr.hxx" // Undo Gruppe
66 #include "Window.hxx"
67 #include "DrawDocShell.hxx"
68 #include "FrameView.hxx"
69 #include "framework/FrameworkHelper.hxx"
70 #include "optsitem.hxx"
71 #include "sdresid.hxx"
73 #include <svx/svxids.hrc>
74 #include <sfx2/request.hxx>
75 #include <svl/aeitem.hxx>
76 #include <basic/sbstar.hxx>
78 using namespace ::com::sun::star;
79 using namespace ::rtl;
81 namespace sd {
83 /**
84 * set state (enabled/disabled) of Menu SfxSlots
86 void ViewShell::GetMenuState( SfxItemSet &rSet )
88 if( SFX_ITEM_AVAILABLE == rSet.GetItemState( SID_STYLE_FAMILY ) )
90 sal_uInt16 nFamily = (sal_uInt16)GetDocSh()->GetStyleFamily();
92 SdrView* pDrView = GetDrawView();
94 if( pDrView->AreObjectsMarked() )
96 SfxStyleSheet* pStyleSheet = pDrView->GetStyleSheet();
97 if( pStyleSheet )
99 if (pStyleSheet->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE)
100 pStyleSheet = ((SdStyleSheet*)pStyleSheet)->GetPseudoStyleSheet();
102 if( pStyleSheet )
104 SfxStyleFamily eFamily = pStyleSheet->GetFamily();
105 if(eFamily == SD_STYLE_FAMILY_GRAPHICS)
106 nFamily = 2;
107 else if(eFamily == SD_STYLE_FAMILY_CELL )
108 nFamily = 3;
109 else // SD_STYLE_FAMILY_PSEUDO
110 nFamily = 5;
112 GetDocSh()->SetStyleFamily(nFamily);
116 rSet.Put(SfxUInt16Item(SID_STYLE_FAMILY, nFamily ));
119 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETUNDOSTRINGS))
121 ImpGetUndoStrings(rSet);
124 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_GETREDOSTRINGS))
126 ImpGetRedoStrings(rSet);
129 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_UNDO))
131 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
132 sal_Bool bActivate(sal_False);
134 if(pUndoManager)
136 if(pUndoManager->GetUndoActionCount() != 0)
138 bActivate = sal_True;
142 if(bActivate)
144 // Set the necessary string like in
145 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
146 String aTmp( SvtResId( STR_UNDO ) );
147 aTmp += pUndoManager->GetUndoActionComment(0);
148 rSet.Put(SfxStringItem(SID_UNDO, aTmp));
150 else
152 rSet.DisableItem(SID_UNDO);
156 if(SFX_ITEM_AVAILABLE == rSet.GetItemState(SID_REDO))
158 ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
159 sal_Bool bActivate(sal_False);
161 if(pUndoManager)
163 if(pUndoManager->GetRedoActionCount() != 0)
165 bActivate = sal_True;
169 if(bActivate)
171 // Set the necessary string like in
172 // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
173 String aTmp(SvtResId(STR_REDO));
174 aTmp += pUndoManager->GetRedoActionComment(0);
175 rSet.Put(SfxStringItem(SID_REDO, aTmp));
177 else
179 rSet.DisableItem(SID_REDO);
187 /** This method consists basically of three parts:
188 1. Process the arguments of the SFX request.
189 2. Use the model to create a new page or duplicate an existing one.
190 3. Update the tab control and switch to the new page.
192 SdPage* ViewShell::CreateOrDuplicatePage (
193 SfxRequest& rRequest,
194 PageKind ePageKind,
195 SdPage* pPage,
196 const sal_Int32 nInsertPosition)
198 sal_uInt16 nSId = rRequest.GetSlot();
199 SdDrawDocument* pDocument = GetDoc();
200 SdrLayerAdmin& rLayerAdmin = pDocument->GetLayerAdmin();
201 sal_uInt8 aBckgrnd = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRND)), sal_False);
202 sal_uInt8 aBckgrndObj = rLayerAdmin.GetLayerID(String(SdResId(STR_LAYER_BCKGRNDOBJ)), sal_False);
203 SetOfByte aVisibleLayers;
204 // Determine the page from which to copy some values, such as layers,
205 // size, master page, to the new page. This is usually the given page.
206 // When the given page is NULL then use the first page of the document.
207 SdPage* pTemplatePage = pPage;
208 if (pTemplatePage == NULL)
209 pTemplatePage = pDocument->GetSdPage(0, ePageKind);
210 if (pTemplatePage != NULL && pTemplatePage->TRG_HasMasterPage())
211 aVisibleLayers = pTemplatePage->TRG_GetMasterPageVisibleLayers();
212 else
213 aVisibleLayers.SetAll();
215 String aStandardPageName;
216 String aNotesPageName;
217 AutoLayout eStandardLayout (AUTOLAYOUT_NONE);
218 AutoLayout eNotesLayout (AUTOLAYOUT_NOTES);
219 sal_Bool bIsPageBack = aVisibleLayers.IsSet(aBckgrnd);
220 sal_Bool bIsPageObj = aVisibleLayers.IsSet(aBckgrndObj);
222 // 1. Process the arguments.
223 const SfxItemSet* pArgs = rRequest.GetArgs();
224 if (! pArgs)
226 // AutoLayouts must be ready
227 pDocument->StopWorkStartupDelay();
229 // Use the layouts of the previous page and notes page as template.
230 if (pTemplatePage != NULL)
232 eStandardLayout = pTemplatePage->GetAutoLayout();
233 if( eStandardLayout == AUTOLAYOUT_TITLE )
234 eStandardLayout = AUTOLAYOUT_ENUM;
236 SdPage* pNotesTemplatePage = static_cast<SdPage*>(pDocument->GetPage(pTemplatePage->GetPageNum()+1));
237 if (pNotesTemplatePage != NULL)
238 eNotesLayout = pNotesTemplatePage->GetAutoLayout();
241 else if (pArgs->Count() == 1)
243 pDocument->StopWorkStartupDelay();
244 SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, sal_False);
245 if( pLayout )
247 if (ePageKind == PK_NOTES)
249 eNotesLayout = (AutoLayout) pLayout->GetValue ();
251 else
253 eStandardLayout = (AutoLayout) pLayout->GetValue ();
257 else if (pArgs->Count() == 4)
259 // AutoLayouts must be ready
260 pDocument->StopWorkStartupDelay();
262 SFX_REQUEST_ARG (rRequest, pPageName, SfxStringItem, ID_VAL_PAGENAME, sal_False);
263 SFX_REQUEST_ARG (rRequest, pLayout, SfxUInt32Item, ID_VAL_WHATLAYOUT, sal_False);
264 SFX_REQUEST_ARG (rRequest, pIsPageBack, SfxBoolItem, ID_VAL_ISPAGEBACK, sal_False);
265 SFX_REQUEST_ARG (rRequest, pIsPageObj, SfxBoolItem, ID_VAL_ISPAGEOBJ, sal_False);
267 if (CHECK_RANGE (AUTOLAYOUT__START, (AutoLayout) pLayout->GetValue (), AUTOLAYOUT__END))
269 if (ePageKind == PK_NOTES)
271 aNotesPageName = pPageName->GetValue ();
272 eNotesLayout = (AutoLayout) pLayout->GetValue ();
274 else
276 aStandardPageName = pPageName->GetValue ();
277 eStandardLayout = (AutoLayout) pLayout->GetValue ();
280 bIsPageBack = pIsPageBack->GetValue ();
281 bIsPageObj = pIsPageObj->GetValue ();
283 else
285 Cancel();
287 if(HasCurrentFunction( SID_BEZIER_EDIT ) )
288 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
289 #ifndef DISABLE_SCRIPTING
290 StarBASIC::FatalError (SbERR_BAD_PROP_VALUE);
291 #endif
292 rRequest.Ignore ();
293 return NULL;
296 else
298 Cancel();
300 if(HasCurrentFunction(SID_BEZIER_EDIT) )
301 GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
302 #ifndef DISABLE_SCRIPTING
303 StarBASIC::FatalError (SbERR_WRONG_ARGS);
304 #endif
305 rRequest.Ignore ();
306 return NULL;
309 // 2. Create a new page or duplicate an existing one.
310 View* pDrView = GetView();
311 const bool bUndo = pDrView && pDrView->IsUndoEnabled();
312 if( bUndo )
313 pDrView->BegUndo( String( SdResId(STR_INSERTPAGE) ) );
315 sal_uInt16 nNewPageIndex = 0xffff;
316 switch (nSId)
318 case SID_INSERTPAGE:
319 case SID_INSERTPAGE_QUICK:
320 case SID_INSERT_MASTER_PAGE:
321 // There are three cases. a) pPage is not NULL: we use it as a
322 // template and create a new slide behind it. b) pPage is NULL
323 // but the document is not empty: we use the first slide/notes
324 // page as template, create a new slide after it and move it
325 // then to the head of the document. c) pPage is NULL and the
326 // document is empty: We use CreateFirstPages to create the
327 // first page of the document.
328 if (pPage == NULL)
329 if (pTemplatePage == NULL)
331 pDocument->CreateFirstPages();
332 nNewPageIndex = 0;
334 else
336 // Create a new page with the first page as template and
337 // insert it after the first page.
338 nNewPageIndex = pDocument->CreatePage (
339 pTemplatePage,
340 ePageKind,
341 aStandardPageName,
342 aNotesPageName,
343 eStandardLayout,
344 eNotesLayout,
345 bIsPageBack,
346 bIsPageObj,
347 nInsertPosition);
348 // Select exactly the new page.
349 sal_uInt16 nPageCount (pDocument->GetSdPageCount(ePageKind));
350 for (sal_uInt16 i=0; i<nPageCount; i++)
352 pDocument->GetSdPage(i, PK_STANDARD)->SetSelected(
353 i == nNewPageIndex);
354 pDocument->GetSdPage(i, PK_NOTES)->SetSelected(
355 i == nNewPageIndex);
357 // Move the selected page to the head of the document
358 pDocument->MovePages ((sal_uInt16)-1);
359 nNewPageIndex = 0;
361 else
362 nNewPageIndex = pDocument->CreatePage (
363 pPage,
364 ePageKind,
365 aStandardPageName,
366 aNotesPageName,
367 eStandardLayout,
368 eNotesLayout,
369 bIsPageBack,
370 bIsPageObj,
371 nInsertPosition);
372 break;
374 case SID_DUPLICATE_PAGE:
375 // Duplication makes no sense when pPage is NULL.
376 if (pPage != NULL)
377 nNewPageIndex = pDocument->DuplicatePage (
378 pPage,
379 ePageKind,
380 aStandardPageName,
381 aNotesPageName,
382 bIsPageBack,
383 bIsPageObj,
384 nInsertPosition);
385 break;
387 default:
388 DBG_WARNING("wrong slot id given to CreateOrDuplicatePage");
389 // Try to handle another slot id gracefully.
391 SdPage* pNewPage = 0;
392 if(nNewPageIndex != 0xffff)
393 pNewPage = pDocument->GetSdPage(nNewPageIndex, PK_STANDARD);
395 if( bUndo )
397 if( pNewPage )
399 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pNewPage));
400 pDrView->AddUndo(pDocument->GetSdrUndoFactory().CreateUndoNewPage(*pDocument->GetSdPage (nNewPageIndex, PK_NOTES)));
403 pDrView->EndUndo();
406 return pNewPage;
410 } // end of namespace sd
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */