Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / sdpreslt.cxx
blobc4d16cd7037e44a143714ae45ce0a3ca64eeaa2f
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 <sfx2/new.hxx>
23 #include <strings.hrc>
25 #include <bitmaps.hlst>
26 #include <sdpreslt.hxx>
27 #include <sdattr.hxx>
28 #include <sdresid.hxx>
29 #include <drawdoc.hxx>
30 #include <sdpage.hxx>
31 #include <DrawDocShell.hxx>
32 #include <memory>
34 SdPresLayoutDlg::SdPresLayoutDlg(::sd::DrawDocShell* pDocShell,
35 vcl::Window* pWindow, const SfxItemSet& rInAttrs)
36 : ModalDialog(pWindow, "SlideDesignDialog",
37 "modules/simpress/ui/slidedesigndialog.ui")
38 , mpDocSh(pDocShell)
39 , mrOutAttrs(rInAttrs)
40 , maStrNone(SdResId(STR_NULL))
42 get(m_pVS, "select");
43 Size aPref(LogicToPixel(Size(144 , 141), MapMode(MapUnit::MapAppFont)));
44 m_pVS->set_width_request(aPref.Width());
45 m_pVS->set_height_request(aPref.Height());
46 get(m_pCbxMasterPage, "masterpage");
47 get(m_pCbxCheckMasters, "checkmasters");
48 get(m_pBtnLoad, "load");
50 m_pVS->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
51 m_pBtnLoad->SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
53 Reset();
56 SdPresLayoutDlg::~SdPresLayoutDlg()
58 disposeOnce();
61 void SdPresLayoutDlg::dispose()
63 m_pVS.clear();
64 m_pCbxMasterPage.clear();
65 m_pCbxCheckMasters.clear();
66 m_pBtnLoad.clear();
67 ModalDialog::dispose();
70 /**
71 * Initialize
73 void SdPresLayoutDlg::Reset()
75 const SfxPoolItem *pPoolItem = nullptr;
76 long nName;
78 // replace master page
79 if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, false, &pPoolItem ) == SfxItemState::SET )
81 bool bMasterPage = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
82 m_pCbxMasterPage->Enable( !bMasterPage );
83 m_pCbxMasterPage->Check( bMasterPage );
86 // remove not used master pages
87 m_pCbxCheckMasters->Check(false);
89 if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, true, &pPoolItem) == SfxItemState::SET)
90 maName = static_cast<const SfxStringItem*>(pPoolItem)->GetValue();
91 else
92 maName.clear();
94 FillValueSet();
96 mnLayoutCount = maLayoutNames.size();
97 for( nName = 0; nName < mnLayoutCount; nName++ )
99 if (maLayoutNames[nName] == maName)
100 break;
102 DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
104 m_pVS->SelectItem(static_cast<sal_uInt16>(nName) + 1); // Indices of the ValueSets start at 1
109 * Fills the provided Item-Set with dialog box attributes
111 void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
113 short nId = m_pVS->GetSelectedItemId();
114 bool bLoad = nId > mnLayoutCount;
115 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
117 OUString aLayoutName;
119 if( bLoad )
121 aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
123 else if (nId)
125 aLayoutName = maLayoutNames[ nId - 1 ];
126 if( aLayoutName == maStrNone )
127 aLayoutName.clear(); // that way we encode "- nothing -" (see below)
130 rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
131 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_pCbxMasterPage->IsChecked() ) );
132 rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_pCbxCheckMasters->IsChecked() ) );
136 * Fills ValueSet with bitmaps
138 void SdPresLayoutDlg::FillValueSet()
140 m_pVS->SetStyle(m_pVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
141 | WB_VSCROLL | WB_NAMEFIELD);
143 m_pVS->SetColCount(2);
144 m_pVS->SetLineCount(2);
145 m_pVS->SetExtraSpacing(2);
147 SdDrawDocument* pDoc = mpDocSh->GetDoc();
149 sal_uInt16 nCount = pDoc->GetMasterPageCount();
151 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
153 SdPage* pMaster = static_cast<SdPage*>(pDoc->GetMasterPage(nLayout));
154 if (pMaster->GetPageKind() == PageKind::Standard)
156 OUString aLayoutName(pMaster->GetLayoutName());
157 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
158 maLayoutNames.push_back(aLayoutName);
160 Image aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster));
161 m_pVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
165 m_pVS->Show();
169 * DoubleClick handler
171 IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl, ValueSet*, void)
173 EndDialog(RET_OK);
177 * Click handler for load button
179 IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl, Button*, void)
181 SfxNewFileDialog aDlg(GetFrameWeld(), SfxNewFileDialogMode::Preview);
182 aDlg.set_title(SdResId(STR_LOAD_PRESENTATION_LAYOUT));
184 if(!IsReallyVisible())
185 return;
187 sal_uInt16 nResult = aDlg.run();
188 // Inserted update to force repaint
189 Update();
191 bool bCancel = false;
193 switch (nResult)
195 case RET_OK:
197 if (aDlg.IsTemplate())
199 maName = aDlg.GetTemplateFileName();
201 else
203 // that way we encode "- nothing -"
204 maName.clear();
207 break;
209 default:
210 bCancel = true;
213 if( !bCancel )
215 // check if template already exists
216 bool bExists = false;
217 OUString aCompareStr(maName);
218 if (aCompareStr.isEmpty())
219 aCompareStr = maStrNone;
221 sal_uInt16 aPos = 0;
222 for (std::vector<OUString>::iterator it = maLayoutNames.begin();
223 it != maLayoutNames.end() && !bExists; ++it, ++aPos)
225 if( aCompareStr == *it )
227 bExists = true;
228 // select template
229 m_pVS->SelectItem( aPos + 1 );
233 if( !bExists )
235 // load document in order to determine preview bitmap (if template is selected)
236 if (!maName.isEmpty())
238 // determine document in order to call OpenBookmarkDoc
239 SdDrawDocument* pDoc = mpDocSh->GetDoc();
240 SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
242 if (pTemplDoc)
244 ::sd::DrawDocShell* pTemplDocSh= pTemplDoc->GetDocSh();
246 sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
248 for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
250 SdPage* pMaster = static_cast<SdPage*>( pTemplDoc->GetMasterPage(nLayout) );
251 if (pMaster->GetPageKind() == PageKind::Standard)
253 OUString aLayoutName(pMaster->GetLayoutName());
254 aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
255 maLayoutNames.push_back(aLayoutName);
257 Image aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster));
258 m_pVS->InsertItem(static_cast<sal_uInt16>(maLayoutNames.size()), aBitmap, aLayoutName);
262 else
264 bCancel = true;
267 pDoc->CloseBookmarkDoc();
269 else
271 // empty layout
272 maLayoutNames.push_back(maStrNone);
273 m_pVS->InsertItem( static_cast<sal_uInt16>(maLayoutNames.size()),
274 Image(BMP_FOIL_NONE), maStrNone );
277 if (!bCancel)
279 // select template
280 m_pVS->SelectItem( static_cast<sal_uInt16>(maLayoutNames.size()) );
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */