Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #ifdef SD_DLLIMPLEMENTATION
31 : : #undef SD_DLLIMPLEMENTATION
32 : : #endif
33 : :
34 : :
35 : : #include <svl/itemset.hxx>
36 : : #include <sfx2/new.hxx>
37 : : #include <vcl/msgbox.hxx>
38 : :
39 : : #include "strings.hrc"
40 : : #include "res_bmp.hrc"
41 : : #include "sdpreslt.hxx"
42 : : #include "sdpreslt.hrc"
43 : : #include "sdattr.hxx"
44 : : #include "sdresid.hxx"
45 : : #include "drawdoc.hxx"
46 : : #include "sdpage.hxx"
47 : : #include "DrawDocShell.hxx"
48 : : #include "ViewShell.hxx"
49 : :
50 : : #define DOCUMENT_TOKEN (sal_Unicode('#'))
51 : :
52 : : /*************************************************************************
53 : : |*
54 : : |* Konstruktor
55 : : |*
56 : : \************************************************************************/
57 : :
58 : 0 : SdPresLayoutDlg::SdPresLayoutDlg(
59 : : ::sd::DrawDocShell* pDocShell,
60 : : ::sd::ViewShell* pViewShell,
61 : : ::Window* pWindow,
62 : : const SfxItemSet& rInAttrs ):
63 : : ModalDialog (pWindow, SdResId(DLG_PRESLT)),
64 : : mpDocSh ( pDocShell ),
65 : : mpViewSh ( pViewShell ),
66 : : maFtLayout (this, SdResId(FT_LAYOUT)),
67 : : maVS (this, SdResId(VS_LAYOUT)),
68 : : maBtnOK (this, SdResId(BTN_OK)),
69 : : maBtnCancel (this, SdResId(BTN_CANCEL)),
70 : : maBtnHelp (this, SdResId(BTN_HELP)),
71 : : maCbxMasterPage (this, SdResId(CBX_MASTER_PAGE)),
72 : : maCbxCheckMasters (this, SdResId(CBX_CHECK_MASTERS)),
73 : : maBtnLoad (this, SdResId(BTN_LOAD)),
74 : : mrOutAttrs (rInAttrs),
75 : 0 : maStrNone ( SdResId( STR_NULL ) )
76 : : {
77 : 0 : FreeResource();
78 : :
79 : 0 : maVS.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
80 : 0 : maBtnLoad.SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
81 : :
82 : 0 : Reset();
83 : 0 : }
84 : :
85 : : /*************************************************************************
86 : : |*
87 : : |* Dtor
88 : : |*
89 : : *************************************************************************/
90 : :
91 : 0 : SdPresLayoutDlg::~SdPresLayoutDlg()
92 : : {
93 : 0 : }
94 : :
95 : : /*************************************************************************
96 : : |*
97 : : |* Initialisierung
98 : : |*
99 : : *************************************************************************/
100 : :
101 : 0 : void SdPresLayoutDlg::Reset()
102 : : {
103 : 0 : const SfxPoolItem *pPoolItem = NULL;
104 : : long nName;
105 : :
106 : : // MasterPage austauschen
107 : 0 : if( mrOutAttrs.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE, sal_False, &pPoolItem ) == SFX_ITEM_SET )
108 : : {
109 : 0 : sal_Bool bMasterPage = ( (const SfxBoolItem*) pPoolItem)->GetValue();
110 : 0 : maCbxMasterPage.Enable( !bMasterPage );
111 : 0 : maCbxMasterPage.Check( bMasterPage );
112 : : }
113 : :
114 : : // Nicht verwendete MasterPages entfernen
115 : 0 : maCbxCheckMasters.Check(sal_False);
116 : :
117 : 0 : if(mrOutAttrs.GetItemState(ATTR_PRESLAYOUT_NAME, sal_True, &pPoolItem) == SFX_ITEM_SET)
118 : 0 : maName = ((const SfxStringItem*)pPoolItem)->GetValue();
119 : : else
120 : 0 : maName.Erase();
121 : :
122 : 0 : FillValueSet();
123 : :
124 : 0 : mnLayoutCount = maLayoutNames.size();
125 : 0 : for( nName = 0; nName < mnLayoutCount; nName++ )
126 : : {
127 : 0 : if (maLayoutNames[nName] == maName)
128 : 0 : break;
129 : : }
130 : : DBG_ASSERT(nName < mnLayoutCount, "Layout nicht gefunden");
131 : :
132 : 0 : maVS.SelectItem((sal_uInt16)nName + 1); // Inizes des ValueSets beginnen bei 1
133 : :
134 : 0 : }
135 : :
136 : : /*************************************************************************
137 : : |*
138 : : |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
139 : : |*
140 : : *************************************************************************/
141 : :
142 : 0 : void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
143 : : {
144 : 0 : short nId = maVS.GetSelectItemId();
145 : 0 : sal_Bool bLoad = nId > mnLayoutCount;
146 : 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD, bLoad ) );
147 : :
148 : 0 : String aLayoutName;
149 : :
150 : 0 : if( bLoad )
151 : : {
152 : 0 : aLayoutName = maName;
153 : 0 : aLayoutName.Append( DOCUMENT_TOKEN );
154 : 0 : aLayoutName.Append( maLayoutNames[ nId - 1 ] );
155 : : }
156 : : else
157 : : {
158 : 0 : aLayoutName = maLayoutNames[ nId - 1 ];
159 : 0 : if( aLayoutName == maStrNone )
160 : 0 : aLayoutName.Erase(); // so wird "- keine -" codiert (s.u.)
161 : : }
162 : :
163 : 0 : rOutAttrs.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME, aLayoutName ) );
164 : 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE, maCbxMasterPage.IsChecked() ) );
165 : 0 : rOutAttrs.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS, maCbxCheckMasters.IsChecked() ) );
166 : 0 : }
167 : :
168 : :
169 : : /*************************************************************************
170 : : |*
171 : : |* Fuellt das ValueSet mit Bitmaps
172 : : |*
173 : : \************************************************************************/
174 : :
175 : 0 : void SdPresLayoutDlg::FillValueSet()
176 : : {
177 : 0 : maVS.SetStyle(maVS.GetStyle() | WB_ITEMBORDER | WB_DOUBLEBORDER
178 : 0 : | WB_VSCROLL | WB_NAMEFIELD);
179 : :
180 : 0 : maVS.SetColCount(2);
181 : 0 : maVS.SetLineCount(2);
182 : 0 : maVS.SetExtraSpacing(2);
183 : :
184 : 0 : SdDrawDocument* pDoc = mpDocSh->GetDoc();
185 : :
186 : 0 : sal_uInt16 nCount = pDoc->GetMasterPageCount();
187 : :
188 : 0 : for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
189 : : {
190 : 0 : SdPage* pMaster = (SdPage*)pDoc->GetMasterPage(nLayout);
191 : 0 : if (pMaster->GetPageKind() == PK_STANDARD)
192 : : {
193 : 0 : String aLayoutName(pMaster->GetLayoutName());
194 : 0 : aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
195 : 0 : maLayoutNames.push_back(new String(aLayoutName));
196 : :
197 : 0 : Bitmap aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90));
198 : 0 : maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
199 : : }
200 : : }
201 : :
202 : 0 : maVS.Show();
203 : 0 : }
204 : :
205 : :
206 : : /*************************************************************************
207 : : |*
208 : : |* Doppelklick-Handler
209 : : |*
210 : : \************************************************************************/
211 : :
212 : 0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
213 : : {
214 : 0 : EndDialog(RET_OK);
215 : 0 : return 0;
216 : : }
217 : :
218 : : /*************************************************************************
219 : : |*
220 : : |* Klick-Handler fuer Laden-Button
221 : : |*
222 : : \************************************************************************/
223 : :
224 : 0 : IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLoadHdl)
225 : : {
226 : 0 : SfxNewFileDialog* pDlg = new SfxNewFileDialog(this, SFXWB_PREVIEW);
227 : 0 : pDlg->SetText(String(SdResId(STR_LOAD_PRESENTATION_LAYOUT)));
228 : :
229 : 0 : if(!IsReallyVisible())
230 : : {
231 : 0 : delete pDlg;
232 : 0 : return 0;
233 : : }
234 : :
235 : 0 : sal_uInt16 nResult = pDlg->Execute();
236 : : // Inserted update to force repaint
237 : 0 : Update();
238 : :
239 : 0 : String aFile;
240 : 0 : sal_Bool bCancel = sal_False;
241 : :
242 : 0 : switch (nResult)
243 : : {
244 : : case RET_OK:
245 : : {
246 : 0 : if (pDlg->IsTemplate())
247 : : {
248 : 0 : maName = pDlg->GetTemplateFileName();
249 : : }
250 : : else
251 : : {
252 : : // so wird "- keine -" codiert
253 : 0 : maName.Erase();
254 : : }
255 : : }
256 : 0 : break;
257 : :
258 : : default:
259 : 0 : bCancel = sal_True;
260 : : }
261 : 0 : delete pDlg;
262 : :
263 : 0 : if( !bCancel )
264 : : {
265 : : // Pruefen, ob Vorlage schon vorhanden
266 : 0 : sal_Bool bExists = sal_False;
267 : 0 : String aCompareStr( maName );
268 : 0 : if( maName.Len() == 0 )
269 : 0 : aCompareStr = maStrNone;
270 : :
271 : 0 : sal_uInt16 aPos = 0;
272 : 0 : for (boost::ptr_vector<String>::iterator it = maLayoutNames.begin();
273 : 0 : it != maLayoutNames.end() && !bExists; ++it, ++aPos)
274 : : {
275 : 0 : if( aCompareStr == *it )
276 : : {
277 : 0 : bExists = sal_True;
278 : : // Vorlage selektieren
279 : 0 : maVS.SelectItem( aPos + 1 );
280 : : }
281 : : }
282 : :
283 : 0 : if( !bExists )
284 : : {
285 : : // Dokument laden um Preview-Bitmap zu ermitteln (wenn Vorlage ausgewaehlt)
286 : 0 : if( maName.Len() )
287 : : {
288 : : // Dokument ermitteln, um OpenBookmarkDoc rufen zu koennen
289 : 0 : SdDrawDocument* pDoc = mpDocSh->GetDoc();
290 : 0 : SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
291 : :
292 : 0 : if (pTemplDoc)
293 : : {
294 : 0 : ::sd::DrawDocShell* pTemplDocSh= pTemplDoc->GetDocSh();
295 : :
296 : 0 : sal_uInt16 nCount = pTemplDoc->GetMasterPageCount();
297 : :
298 : 0 : for (sal_uInt16 nLayout = 0; nLayout < nCount; nLayout++)
299 : : {
300 : 0 : SdPage* pMaster = (SdPage*) pTemplDoc->GetMasterPage(nLayout);
301 : 0 : if (pMaster->GetPageKind() == PK_STANDARD)
302 : : {
303 : 0 : String aLayoutName(pMaster->GetLayoutName());
304 : 0 : aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
305 : 0 : maLayoutNames.push_back(new String(aLayoutName));
306 : :
307 : 0 : Bitmap aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90));
308 : 0 : maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
309 : : }
310 : : }
311 : : }
312 : : else
313 : : {
314 : 0 : bCancel = sal_True;
315 : : }
316 : :
317 : 0 : pDoc->CloseBookmarkDoc();
318 : : }
319 : : else
320 : : {
321 : : // leeres Layout
322 : 0 : maLayoutNames.push_back( new String( maStrNone ) );
323 : 0 : maVS.InsertItem( (sal_uInt16) maLayoutNames.size(),
324 : 0 : Bitmap( SdResId( BMP_FOIL_NONE ) ), maStrNone );
325 : : }
326 : :
327 : 0 : if (!bCancel)
328 : : {
329 : : // Vorlage selektieren
330 : 0 : maVS.SelectItem( (sal_uInt16) maLayoutNames.size() );
331 : : }
332 : 0 : }
333 : : }
334 : :
335 : 0 : return( 0 );
336 : : }
337 : :
338 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|