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