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