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 <svl/itemset.hxx>
21 : #include <sfx2/new.hxx>
22 : #include <vcl/msgbox.hxx>
23 :
24 : #include "strings.hrc"
25 : #include "res_bmp.hrc"
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 :
33 :
34 0 : SdPresLayoutDlg::SdPresLayoutDlg(::sd::DrawDocShell* pDocShell,
35 : ::Window* pWindow, const SfxItemSet& rInAttrs)
36 : : ModalDialog(pWindow, "SlideDesignDialog",
37 : "modules/simpress/ui/slidedesigndialog.ui")
38 : , mpDocSh(pDocShell)
39 : , mrOutAttrs(rInAttrs)
40 0 : , maStrNone(SD_RESSTR(STR_NULL))
41 : {
42 0 : get(m_pVS, "select");
43 0 : Size aPref(LogicToPixel(Size(144 , 141), MAP_APPFONT));
44 0 : m_pVS->set_width_request(aPref.Width());
45 0 : m_pVS->set_height_request(aPref.Height());
46 0 : get(m_pCbxMasterPage, "masterpage");
47 0 : get(m_pCbxCheckMasters, "checkmasters");
48 0 : get(m_pBtnLoad, "load");
49 :
50 0 : m_pVS->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
51 0 : m_pBtnLoad->SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
52 :
53 0 : Reset();
54 0 : }
55 :
56 0 : SdPresLayoutDlg::~SdPresLayoutDlg()
57 : {
58 0 : }
59 :
60 : /**
61 : * Initialize
62 : */
63 0 : void SdPresLayoutDlg::Reset()
64 : {
65 0 : const SfxPoolItem *pPoolItem = NULL;
66 : long nName;
67 :
68 : // replace master page
69 0 : if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, false, &pPoolItem ) == SFX_ITEM_SET )
70 : {
71 0 : sal_Bool bMasterPage = ( (const SfxBoolItem*) pPoolItem)->GetValue();
72 0 : m_pCbxMasterPage->Enable( !bMasterPage );
73 0 : m_pCbxMasterPage->Check( bMasterPage );
74 : }
75 :
76 : // remove not used master pages
77 0 : m_pCbxCheckMasters->Check(false);
78 :
79 0 : if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, true, &pPoolItem) == SFX_ITEM_SET)
80 0 : maName = ((const SfxStringItem*)pPoolItem)->GetValue();
81 : else
82 0 : maName = "";
83 :
84 0 : FillValueSet();
85 :
86 0 : mnLayoutCount = maLayoutNames.size();
87 0 : for( nName = 0; nName < mnLayoutCount; nName++ )
88 : {
89 0 : if (maLayoutNames[nName] == maName)
90 0 : break;
91 : }
92 : DBG_ASSERT(nName < mnLayoutCount, "Layout not found");
93 :
94 0 : m_pVS->SelectItem((sal_uInt16)nName + 1); // Indices of the ValueSets start at 1
95 :
96 0 : }
97 :
98 : /**
99 : * Fills the provided Item-Set with dialog box attributes
100 : */
101 0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
102 : {
103 0 : short nId = m_pVS->GetSelectItemId();
104 0 : sal_Bool bLoad = nId > mnLayoutCount;
105 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
106 :
107 0 : OUString aLayoutName;
108 :
109 0 : if( bLoad )
110 : {
111 0 : aLayoutName = maName + "#" + maLayoutNames[ nId - 1 ];
112 : }
113 : else
114 : {
115 0 : aLayoutName = maLayoutNames[ nId - 1 ];
116 0 : if( aLayoutName == maStrNone )
117 0 : aLayoutName = ""; // that way we encode "- nothing -" (see below)
118 : }
119 :
120 0 : rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
121 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, m_pCbxMasterPage->IsChecked() ) );
122 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, m_pCbxCheckMasters->IsChecked() ) );
123 0 : }
124 :
125 :
126 : /**
127 : * Fills ValueSet with bitmaps
128 : */
129 0 : void SdPresLayoutDlg::FillValueSet()
130 : {
131 0 : m_pVS->SetStyle(m_pVS->GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
132 0 : | WB_VSCROLL | WB_NAMEFIELD);
133 :
134 0 : m_pVS->SetColCount(2);
135 0 : m_pVS->SetLineCount(2);
136 0 : m_pVS->SetExtraSpacing(2);
137 :
138 0 : SdDrawDocument* pDoc = mpDocSh->GetDoc();
139 :
140 0 : sal_uInt16 nCount = pDoc->GetMasterPageCount();
141 :
142 0 : for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
143 : {
144 0 : SdPage* pMaster = (SdPage*)pDoc->GetMasterPage(nLayout);
145 0 : if (pMaster->GetPageKind() == PK_STANDARD)
146 : {
147 0 : OUString aLayoutName(pMaster->GetLayoutName());
148 0 : aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
149 0 : maLayoutNames.push_back(aLayoutName);
150 :
151 0 : Image aBitmap(Bitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90)));
152 0 : m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
153 : }
154 : }
155 :
156 0 : m_pVS->Show();
157 0 : }
158 :
159 :
160 : /**
161 : * DoubleClick handler
162 : */
163 0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
164 : {
165 0 : EndDialog(RET_OK);
166 0 : return 0;
167 : }
168 :
169 : /**
170 : * Click handler for load button
171 : */
172 0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
173 : {
174 0 : SfxNewFileDialog* pDlg = new SfxNewFileDialog(this, SFXWB_PREVIEW);
175 0 : pDlg->SetText(SD_RESSTR(STR_LOAD_PRESENTATION_LAYOUT));
176 :
177 0 : if(!IsReallyVisible())
178 : {
179 0 : delete pDlg;
180 0 : return 0;
181 : }
182 :
183 0 : sal_uInt16 nResult = pDlg->Execute();
184 : // Inserted update to force repaint
185 0 : Update();
186 :
187 0 : sal_Bool bCancel = sal_False;
188 :
189 0 : switch (nResult)
190 : {
191 : case RET_OK:
192 : {
193 0 : if (pDlg->IsTemplate())
194 : {
195 0 : maName = pDlg->GetTemplateFileName();
196 : }
197 : else
198 : {
199 : // that way we encode "- nothing -"
200 0 : maName = "";
201 : }
202 : }
203 0 : break;
204 :
205 : default:
206 0 : bCancel = sal_True;
207 : }
208 0 : delete pDlg;
209 :
210 0 : if( !bCancel )
211 : {
212 : // check if template already ecists
213 0 : sal_Bool bExists = sal_False;
214 0 : OUString aCompareStr(maName);
215 0 : if (aCompareStr.isEmpty())
216 0 : aCompareStr = maStrNone;
217 :
218 0 : sal_uInt16 aPos = 0;
219 0 : for (std::vector<OUString>::iterator it = maLayoutNames.begin();
220 0 : it != maLayoutNames.end() && !bExists; ++it, ++aPos)
221 : {
222 0 : if( aCompareStr == *it )
223 : {
224 0 : bExists = sal_True;
225 : // select template
226 0 : m_pVS->SelectItem( aPos + 1 );
227 : }
228 : }
229 :
230 0 : if( !bExists )
231 : {
232 : // load document in order to determine preview bitmap (if template is selected)
233 0 : if (!maName.isEmpty())
234 : {
235 : // determine document in order to call OpenBookmarkDoc
236 0 : SdDrawDocument* pDoc = mpDocSh->GetDoc();
237 0 : SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
238 :
239 0 : if (pTemplDoc)
240 : {
241 0 : ::sd::DrawDocShell* pTemplDocSh= pTemplDoc->GetDocSh();
242 :
243 0 : sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
244 :
245 0 : for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
246 : {
247 0 : SdPage* pMaster = (SdPage*) pTemplDoc->GetMasterPage(nLayout);
248 0 : if (pMaster->GetPageKind() == PK_STANDARD)
249 : {
250 0 : OUString aLayoutName(pMaster->GetLayoutName());
251 0 : aLayoutName = aLayoutName.copy(0, aLayoutName.indexOf(SD_LT_SEPARATOR));
252 0 : maLayoutNames.push_back(aLayoutName);
253 :
254 0 : Image aBitmap(Bitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90)));
255 0 : m_pVS->InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
256 : }
257 : }
258 : }
259 : else
260 : {
261 0 : bCancel = sal_True;
262 : }
263 :
264 0 : pDoc->CloseBookmarkDoc();
265 : }
266 : else
267 : {
268 : // empty layout
269 0 : maLayoutNames.push_back(maStrNone);
270 0 : m_pVS->InsertItem( (sal_uInt16) maLayoutNames.size(),
271 0 : Image(Bitmap(SdResId(BMP_FOIL_NONE))), maStrNone );
272 : }
273 :
274 0 : if (!bCancel)
275 : {
276 : // select template
277 0 : m_pVS->SelectItem( (sal_uInt16) maLayoutNames.size() );
278 : }
279 0 : }
280 : }
281 :
282 0 : return( 0 );
283 : }
284 :
285 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|