LibreOffice Module sd (master) 1
sdpreslt.cxx
Go to the documentation of this file.
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 <svl/itemset.hxx>
21#include <svl/eitem.hxx>
22#include <svl/stritem.hxx>
23#include <sfx2/new.hxx>
24#include <svtools/valueset.hxx>
25#include <tools/debug.hxx>
26#include <vcl/image.hxx>
27
28#include <strings.hrc>
29
30#include <bitmaps.hlst>
31#include <sdpreslt.hxx>
32#include <sdattr.hrc>
33#include <sdresid.hxx>
34#include <drawdoc.hxx>
35#include <sdpage.hxx>
36#include <DrawDocShell.hxx>
37#include <memory>
38
40 weld::Window* pWindow, const SfxItemSet& rInAttrs)
41 : GenericDialogController(pWindow, "modules/simpress/ui/slidedesigndialog.ui", "SlideDesignDialog")
42 , mpDocSh(pDocShell)
43 , mrOutAttrs(rInAttrs)
44 , maStrNone(SdResId(STR_NULL))
45 , m_xCbxMasterPage(m_xBuilder->weld_check_button("masterpage"))
46 , m_xCbxCheckMasters(m_xBuilder->weld_check_button("checkmasters"))
47 , m_xBtnLoad(m_xBuilder->weld_button("load"))
48 , m_xVS(new ValueSet(m_xBuilder->weld_scrolled_window("selectwin", true)))
49 , m_xVSWin(new weld::CustomWeld(*m_xBuilder, "select", *m_xVS))
50 , m_xLabel(m_xBuilder->weld_label("label1"))
51{
53 {
54 m_xDialog->set_title(SdResId(STR_AVAILABLE_MASTERPAGE));
55 m_xLabel->set_label(SdResId(STR_SELECT_PAGE));
56 }
57 else
58 {
59 m_xDialog->set_title(SdResId(STR_AVAILABLE_MASTERSLIDE));
60 m_xLabel->set_label(SdResId(STR_SELECT_SLIDE));
61 }
62 m_xVSWin->set_size_request(m_xBtnLoad->get_approximate_digit_width() * 60,
63 m_xBtnLoad->get_text_height() * 20);
64
65 m_xVS->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
66 m_xBtnLoad->connect_clicked(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
67
68 Reset();
69}
70
72{
73}
74
79{
80 tools::Long nName;
81
82 // replace master page
83 if( const SfxBoolItem* pPoolItem = mrOutAttrs.GetItemIfSet( ATTR_PRESLAYOUT_MASTER_PAGE, false ) )
84 {
85 bool bMasterPage = pPoolItem->GetValue();
86 m_xCbxMasterPage->set_sensitive( !bMasterPage );
87 m_xCbxMasterPage->set_active( bMasterPage );
88 }
89
90 // remove not used master pages
91 m_xCbxCheckMasters->set_active(false);
92
93 if( const SfxStringItem* pPoolItem = mrOutAttrs.GetItemIfSet(ATTR_PRESLAYOUT_NAME) )
94 maName = pPoolItem->GetValue();
95 else
96 maName.clear();
97
99
101 for( nName = 0; nName < mnLayoutCount; nName++ )
102 {
103 if (maLayoutNames[nName] == maName)
104 break;
105 }
106 DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
107
108 m_xVS->SelectItem(static_cast<sal_uInt16>(nName) + 1); // Indices of the ValueSets start at 1
109
110}
111
116{
117 short nId = m_xVS->GetSelectedItemId();
118 bool bLoad = nId > mnLayoutCount;
119 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
120
121 OUString aLayoutName;
122
123 if( bLoad )
124 {
125 aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
126 }
127 else if (nId)
128 {
129 aLayoutName = maLayoutNames[ nId - 1 ];
130 if( aLayoutName == maStrNone )
131 aLayoutName.clear(); // that way we encode "- nothing -" (see below)
132 }
133
134 rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
135 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_xCbxMasterPage->get_active() ) );
136 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_xCbxCheckMasters->get_active() ) );
137}
138
143{
144 m_xVS->SetStyle(m_xVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
146
147 m_xVS->SetColCount(2);
148 m_xVS->SetLineCount(2);
149 m_xVS->SetExtraSpacing(2);
150
151 SdDrawDocument* pDoc = mpDocSh->GetDoc();
152
153 sal_uInt16 nCount = pDoc->GetMasterPageCount();
154
155 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
156 {
157 SdPage* pMaster = static_cast<SdPage*>(pDoc->GetMasterPage(nLayout));
158 if (pMaster->GetPageKind() == PageKind::Standard)
159 {
160 OUString aLayoutName(pMaster->GetLayoutName());
161 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
162 maLayoutNames.push_back(aLayoutName);
163
164 Image aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster));
165 m_xVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
166 }
167 }
168
169 m_xVS->Show();
170}
171
176{
177 m_xDialog->response(RET_OK);
178}
179
184{
185 SfxNewFileDialog aDlg(m_xDialog.get(), SfxNewFileDialogMode::Preview);
186 if (mpDocSh->GetDoc()->GetDocumentType() == DocumentType::Draw)
187 aDlg.set_title(SdResId(STR_LOAD_DRAWING_LAYOUT));
188 else
189 aDlg.set_title(SdResId(STR_LOAD_PRESENTATION_LAYOUT));
190 sal_uInt16 nResult = aDlg.run();
191
192 bool bCancel = false;
193
194 switch (nResult)
195 {
196 case RET_OK:
197 {
198 if (aDlg.IsTemplate())
199 {
201 }
202 else
203 {
204 // that way we encode "- nothing -"
205 maName.clear();
206 }
207 }
208 break;
209
210 default:
211 bCancel = true;
212 }
213
214 if( bCancel )
215 return;
216
217 // check if template already exists
218 OUString aCompareStr(maName);
219 if (aCompareStr.isEmpty())
220 aCompareStr = maStrNone;
221
222 auto it = std::find(maLayoutNames.begin(), maLayoutNames.end(), aCompareStr);
223 if (it != maLayoutNames.end())
224 {
225 sal_uInt16 aPos = static_cast<sal_uInt16>(std::distance(maLayoutNames.begin(), it));
226 // select template
227 m_xVS->SelectItem( aPos + 1 );
228 }
229 else
230 {
231 // load document in order to determine preview bitmap (if template is selected)
232 if (!maName.isEmpty())
233 {
234 // determine document in order to call OpenBookmarkDoc
235 SdDrawDocument* pDoc = mpDocSh->GetDoc();
236 SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
237
238 if (pTemplDoc)
239 {
240 ::sd::DrawDocShell* pTemplDocSh= pTemplDoc->GetDocSh();
241
242 sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
243
244 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
245 {
246 SdPage* pMaster = static_cast<SdPage*>( pTemplDoc->GetMasterPage(nLayout) );
247 if (pMaster->GetPageKind() == PageKind::Standard)
248 {
249 OUString aLayoutName(pMaster->GetLayoutName());
250 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
251 maLayoutNames.push_back(aLayoutName);
252
253 Image aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster));
254 m_xVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
255 }
256 }
257 }
258 else
259 {
260 bCancel = true;
261 }
262
263 pDoc->CloseBookmarkDoc();
264 }
265 else
266 {
267 // empty layout
268 maLayoutNames.push_back(maStrNone);
269 m_xVS->InsertItem( static_cast<sal_uInt16>(maLayoutNames.size()),
270 Image(BMP_SLIDE_NONE), maStrNone );
271 }
272
273 if (!bCancel)
274 {
275 // select template
276 m_xVS->SelectItem( static_cast<sal_uInt16>(maLayoutNames.size()) );
277 }
278 }
279}
280
281/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
OUString maName
SdDrawDocument * OpenBookmarkDoc(const OUString &rBookmarkFile)
Definition: drawdoc3.cxx:256
void CloseBookmarkDoc()
Definition: drawdoc3.cxx:1129
SAL_DLLPRIVATE::sd::DrawDocShell * GetDocSh() const
Definition: drawdoc.hxx:242
SAL_DLLPRIVATE DocumentType GetDocumentType() const
Definition: drawdoc.hxx:251
PageKind GetPageKind() const
Definition: sdpage.hxx:205
virtual OUString GetLayoutName() const override
Definition: sdpage.hxx:255
SdPresLayoutDlg(::sd::DrawDocShell *pDocShell, weld::Window *pWindow, const SfxItemSet &rInAttrs)
Definition: sdpreslt.cxx:39
void Reset()
Initialize.
Definition: sdpreslt.cxx:78
std::unique_ptr< weld::Button > m_xBtnLoad
Definition: sdpreslt.hxx:62
std::unique_ptr< weld::Label > m_xLabel
Definition: sdpreslt.hxx:65
std::unique_ptr< weld::CustomWeld > m_xVSWin
Definition: sdpreslt.hxx:64
std::unique_ptr< weld::CheckButton > m_xCbxMasterPage
Definition: sdpreslt.hxx:60
tools::Long mnLayoutCount
number of master pages in the document
Definition: sdpreslt.hxx:57
void GetAttr(SfxItemSet &rOutAttrs)
Fills the provided Item-Set with dialog box attributes.
Definition: sdpreslt.cxx:115
std::unique_ptr< weld::CheckButton > m_xCbxCheckMasters
Definition: sdpreslt.hxx:61
void FillValueSet()
Fills ValueSet with bitmaps.
Definition: sdpreslt.cxx:142
std::vector< OUString > maLayoutNames
Definition: sdpreslt.hxx:54
const OUString maStrNone
Definition: sdpreslt.hxx:58
::sd::DrawDocShell * mpDocSh
Definition: sdpreslt.hxx:50
const SfxItemSet & mrOutAttrs
Definition: sdpreslt.hxx:52
virtual ~SdPresLayoutDlg() override
Definition: sdpreslt.cxx:71
std::unique_ptr< ValueSet > m_xVS
Definition: sdpreslt.hxx:63
OUString maName
layout name or file name
Definition: sdpreslt.hxx:56
const SdrPage * GetMasterPage(sal_uInt16 nPgNum) const
sal_uInt16 GetMasterPageCount() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool IsTemplate() const
OUString GetTemplateFileName() const
std::unique_ptr< weld::Label > m_xLabel
BitmapEx GetPagePreviewBitmap(SdPage *pPage)
Creates a bitmap of an arbitrary page.
Definition: docshel2.cxx:175
SdDrawDocument * GetDoc()
std::shared_ptr< weld::Dialog > m_xDialog
int nCount
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral SD_LT_SEPARATOR
Definition: glob.hxx:49
long Long
sal_Int16 nId
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl, ValueSet *, void)
DoubleClick handler.
Definition: sdpreslt.cxx:175
#define WB_ITEMBORDER
#define WB_DOUBLEBORDER
#define WB_NAMEFIELD
RET_OK
WinBits const WB_VSCROLL