bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / sdpreslt.cxx
blobbd5fd897af636679895d4f4848214c383f3542c4
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 <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>
28 #include <strings.hrc>
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>
39 SdPresLayoutDlg::SdPresLayoutDlg(::sd::DrawDocShell* pDocShell,
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 SvtValueSet(m_xBuilder->weld_scrolled_window("selectwin")))
49 , m_xVSWin(new weld::CustomWeld(*m_xBuilder, "select", *m_xVS))
51 m_xVSWin->set_size_request(m_xBtnLoad->get_approximate_digit_width() * 60,
52 m_xBtnLoad->get_text_height() * 20);
54 m_xVS->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
55 m_xBtnLoad->connect_clicked(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
57 Reset();
60 SdPresLayoutDlg::~SdPresLayoutDlg()
64 /**
65 * Initialize
67 void SdPresLayoutDlg::Reset()
69 const SfxPoolItem *pPoolItem = nullptr;
70 long nName;
72 // replace master page
73 if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, false, &pPoolItem ) == SfxItemState::SET )
75 bool bMasterPage = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
76 m_xCbxMasterPage->set_sensitive( !bMasterPage );
77 m_xCbxMasterPage->set_active( bMasterPage );
80 // remove not used master pages
81 m_xCbxCheckMasters->set_active(false);
83 if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, true, &pPoolItem) == SfxItemState::SET)
84 maName = static_cast<const SfxStringItem*>(pPoolItem)->GetValue();
85 else
86 maName.clear();
88 FillValueSet();
90 mnLayoutCount = maLayoutNames.size();
91 for( nName = 0; nName < mnLayoutCount; nName++ )
93 if (maLayoutNames[nName] == maName)
94 break;
96 DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
98 m_xVS->SelectItem(static_cast<sal_uInt16>(nName) + 1); // Indices of the ValueSets start at 1
103 * Fills the provided Item-Set with dialog box attributes
105 void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
107 short nId = m_xVS->GetSelectedItemId();
108 bool bLoad = nId > mnLayoutCount;
109 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
111 OUString aLayoutName;
113 if( bLoad )
115 aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
117 else if (nId)
119 aLayoutName = maLayoutNames[ nId - 1 ];
120 if( aLayoutName == maStrNone )
121 aLayoutName.clear(); // that way we encode "- nothing -" (see below)
124 rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
125 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_xCbxMasterPage->get_active() ) );
126 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_xCbxCheckMasters->get_active() ) );
130 * Fills ValueSet with bitmaps
132 void SdPresLayoutDlg::FillValueSet()
134 m_xVS->SetStyle(m_xVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
135 | WB_VSCROLL | WB_NAMEFIELD);
137 m_xVS->SetColCount(2);
138 m_xVS->SetLineCount(2);
139 m_xVS->SetExtraSpacing(2);
141 SdDrawDocument* pDoc = mpDocSh->GetDoc();
143 sal_uInt16 nCount = pDoc->GetMasterPageCount();
145 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
147 SdPage* pMaster = static_cast<SdPage*>(pDoc->GetMasterPage(nLayout));
148 if (pMaster->GetPageKind() == PageKind::Standard)
150 OUString aLayoutName(pMaster->GetLayoutName());
151 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
152 maLayoutNames.push_back(aLayoutName);
154 Image aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster));
155 m_xVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
159 m_xVS->Show();
163 * DoubleClick handler
165 IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl, SvtValueSet*, void)
167 m_xDialog->response(RET_OK);
171 * Click handler for load button
173 IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl, weld::Button&, void)
175 SfxNewFileDialog aDlg(m_xDialog.get(), SfxNewFileDialogMode::Preview);
176 aDlg.set_title(SdResId(STR_LOAD_PRESENTATION_LAYOUT));
177 sal_uInt16 nResult = aDlg.run();
179 bool bCancel = false;
181 switch (nResult)
183 case RET_OK:
185 if (aDlg.IsTemplate())
187 maName = aDlg.GetTemplateFileName();
189 else
191 // that way we encode "- nothing -"
192 maName.clear();
195 break;
197 default:
198 bCancel = true;
201 if( bCancel )
202 return;
204 // check if template already exists
205 OUString aCompareStr(maName);
206 if (aCompareStr.isEmpty())
207 aCompareStr = maStrNone;
209 auto it = std::find(maLayoutNames.begin(), maLayoutNames.end(), aCompareStr);
210 if (it != maLayoutNames.end())
212 sal_uInt16 aPos = static_cast<sal_uInt16>(std::distance(maLayoutNames.begin(), it));
213 // select template
214 m_xVS->SelectItem( aPos + 1 );
216 else
218 // load document in order to determine preview bitmap (if template is selected)
219 if (!maName.isEmpty())
221 // determine document in order to call OpenBookmarkDoc
222 SdDrawDocument* pDoc = mpDocSh->GetDoc();
223 SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
225 if (pTemplDoc)
227 ::sd::DrawDocShell* pTemplDocSh= pTemplDoc->GetDocSh();
229 sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
231 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
233 SdPage* pMaster = static_cast<SdPage*>( pTemplDoc->GetMasterPage(nLayout) );
234 if (pMaster->GetPageKind() == PageKind::Standard)
236 OUString aLayoutName(pMaster->GetLayoutName());
237 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
238 maLayoutNames.push_back(aLayoutName);
240 Image aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster));
241 m_xVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
245 else
247 bCancel = true;
250 pDoc->CloseBookmarkDoc();
252 else
254 // empty layout
255 maLayoutNames.push_back(maStrNone);
256 m_xVS->InsertItem( static_cast<sal_uInt16>(maLayoutNames.size()),
257 Image(BMP_FOIL_NONE), maStrNone );
260 if (!bCancel)
262 // select template
263 m_xVS->SelectItem( static_cast<sal_uInt16>(maLayoutNames.size()) );
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */