1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdpreslt.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
39 #include <svtools/itemset.hxx>
40 #include <sfx2/new.hxx>
41 #include <vcl/msgbox.hxx>
43 #include "strings.hrc"
44 #include "res_bmp.hrc"
45 #include "sdpreslt.hxx"
46 #include "sdpreslt.hrc"
48 #include "sdresid.hxx"
49 #include "drawdoc.hxx"
51 #include "DrawDocShell.hxx"
52 #include "ViewShell.hxx"
54 #define DOCUMENT_TOKEN (sal_Unicode('#'))
56 /*************************************************************************
60 \************************************************************************/
62 SdPresLayoutDlg::SdPresLayoutDlg(
63 ::sd::DrawDocShell
* pDocShell
,
64 ::sd::ViewShell
* pViewShell
,
66 const SfxItemSet
& rInAttrs
):
67 ModalDialog (pWindow
, SdResId(DLG_PRESLT
)),
68 mpDocSh ( pDocShell
),
69 mpViewSh ( pViewShell
),
70 maFtLayout (this, SdResId(FT_LAYOUT
)),
71 maVS (this, SdResId(VS_LAYOUT
)),
72 maBtnOK (this, SdResId(BTN_OK
)),
73 maBtnCancel (this, SdResId(BTN_CANCEL
)),
74 maBtnHelp (this, SdResId(BTN_HELP
)),
75 maCbxMasterPage (this, SdResId(CBX_MASTER_PAGE
)),
76 maCbxCheckMasters (this, SdResId(CBX_CHECK_MASTERS
)),
77 maBtnLoad (this, SdResId(BTN_LOAD
)),
78 mrOutAttrs (rInAttrs
),
79 maStrNone ( SdResId( STR_NULL
) )
83 mpLayoutNames
= new List
;
85 maVS
.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg
, ClickLayoutHdl
));
86 maBtnLoad
.SetClickHdl(LINK(this, SdPresLayoutDlg
, ClickLoadHdl
));
91 /*************************************************************************
95 *************************************************************************/
97 SdPresLayoutDlg::~SdPresLayoutDlg()
99 String
* pName
= (String
*)mpLayoutNames
->First();
103 pName
= (String
*)mpLayoutNames
->Next();
106 delete mpLayoutNames
;
109 /*************************************************************************
113 *************************************************************************/
115 void SdPresLayoutDlg::Reset()
117 const SfxPoolItem
*pPoolItem
= NULL
;
120 // MasterPage austauschen
121 if( mrOutAttrs
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
, FALSE
, &pPoolItem
) == SFX_ITEM_SET
)
123 BOOL bMasterPage
= ( (const SfxBoolItem
*) pPoolItem
)->GetValue();
124 maCbxMasterPage
.Enable( !bMasterPage
);
125 maCbxMasterPage
.Check( bMasterPage
);
128 // Nicht verwendete MasterPages entfernen
129 maCbxCheckMasters
.Check(FALSE
);
131 if(mrOutAttrs
.GetItemState(ATTR_PRESLAYOUT_NAME
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
132 maName
= ((const SfxStringItem
*)pPoolItem
)->GetValue();
138 mnLayoutCount
= mpLayoutNames
->Count();
139 for( nName
= 0; nName
< mnLayoutCount
; nName
++ )
141 if (*((String
*)mpLayoutNames
->GetObject(nName
)) == maName
)
144 DBG_ASSERT(nName
< mnLayoutCount
, "Layout nicht gefunden");
146 maVS
.SelectItem((USHORT
)nName
+ 1); // Inizes des ValueSets beginnen bei 1
150 /*************************************************************************
152 |* Fuellt uebergebenen Item-Set mit Dialogbox-Attributen
154 *************************************************************************/
156 void SdPresLayoutDlg::GetAttr(SfxItemSet
& rOutAttrs
)
158 short nId
= maVS
.GetSelectItemId();
159 BOOL bLoad
= nId
> mnLayoutCount
;
160 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
) );
166 aLayoutName
= maName
;
167 aLayoutName
.Append( DOCUMENT_TOKEN
);
168 aLayoutName
.Append( *(String
*)mpLayoutNames
->GetObject( nId
- 1 ) );
172 aLayoutName
= *(String
*)mpLayoutNames
->GetObject( nId
- 1 );
173 if( aLayoutName
== maStrNone
)
174 aLayoutName
.Erase(); // so wird "- keine -" codiert (s.u.)
177 rOutAttrs
.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME
, aLayoutName
) );
178 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, maCbxMasterPage
.IsChecked() ) );
179 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, maCbxCheckMasters
.IsChecked() ) );
183 /*************************************************************************
185 |* Fuellt das ValueSet mit Bitmaps
187 \************************************************************************/
189 void SdPresLayoutDlg::FillValueSet()
191 maVS
.SetStyle(maVS
.GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
192 | WB_VSCROLL
| WB_NAMEFIELD
);
195 maVS
.SetLineCount(2);
196 maVS
.SetExtraSpacing(2);
198 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
200 USHORT nCount
= pDoc
->GetMasterPageCount();
202 for (USHORT nLayout
= 0; nLayout
< nCount
; nLayout
++)
204 SdPage
* pMaster
= (SdPage
*)pDoc
->GetMasterPage(nLayout
);
205 if (pMaster
->GetPageKind() == PK_STANDARD
)
207 String
aLayoutName(pMaster
->GetLayoutName());
208 aLayoutName
.Erase( aLayoutName
.SearchAscii( SD_LT_SEPARATOR
) );
209 mpLayoutNames
->Insert(new String(aLayoutName
), LIST_APPEND
);
211 Bitmap
aBitmap(mpDocSh
->GetPagePreviewBitmap(pMaster
, 90));
212 maVS
.InsertItem((USHORT
)mpLayoutNames
->Count(), aBitmap
, aLayoutName
);
220 /*************************************************************************
222 |* Doppelklick-Handler
224 \************************************************************************/
226 IMPL_LINK(SdPresLayoutDlg
, ClickLayoutHdl
, void *, EMPTYARG
)
232 /*************************************************************************
234 |* Klick-Handler fuer Laden-Button
236 \************************************************************************/
238 IMPL_LINK(SdPresLayoutDlg
, ClickLoadHdl
, void *, EMPTYARG
)
240 SfxNewFileDialog
* pDlg
= new SfxNewFileDialog(this, SFXWB_PREVIEW
);
241 pDlg
->SetText(String(SdResId(STR_LOAD_PRESENTATION_LAYOUT
)));
243 if(!IsReallyVisible())
249 USHORT nResult
= pDlg
->Execute();
250 // #96072# OJ: Inserted update to force repaint
254 BOOL bCancel
= FALSE
;
260 if (pDlg
->IsTemplate())
262 maName
= pDlg
->GetTemplateFileName();
266 // so wird "- keine -" codiert
278 // EndDialog(RET_OK);
282 // Pruefen, ob Vorlage schon vorhanden
283 BOOL bExists
= FALSE
;
284 String
* pName
= (String
*)mpLayoutNames
->First();
285 String
aCompareStr( maName
);
286 if( maName
.Len() == 0 )
287 aCompareStr
= maStrNone
;
289 while( pName
&& !bExists
)
291 if( aCompareStr
== *pName
)
294 // Vorlage selektieren
295 USHORT nId
= (USHORT
) mpLayoutNames
->GetCurPos() + 1;
296 maVS
.SelectItem( nId
);
298 pName
= (String
*)mpLayoutNames
->Next();
303 // Dokument laden um Preview-Bitmap zu ermitteln (wenn Vorlage ausgewaehlt)
306 // Dokument ermitteln, um OpenBookmarkDoc rufen zu koennen
307 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
308 SdDrawDocument
* pTemplDoc
= pDoc
->OpenBookmarkDoc( maName
);
312 ::sd::DrawDocShell
* pTemplDocSh
= pTemplDoc
->GetDocSh();
314 /* SdPage* pMaster = pTemplDoc->GetMasterSdPage( 0, PK_STANDARD );
315 mpLayoutNames->Insert( new String( maName ), LIST_APPEND );
317 Bitmap aBitmap( pTemplDocSh->GetPagePreviewBitmap( pMaster, 90 ) );
318 maVS.InsertItem( (USHORT) mpLayoutNames->Count(), aBitmap, maName);
320 USHORT nCount
= pTemplDoc
->GetMasterPageCount();
322 for (USHORT nLayout
= 0; nLayout
< nCount
; nLayout
++)
324 SdPage
* pMaster
= (SdPage
*) pTemplDoc
->GetMasterPage(nLayout
);
325 if (pMaster
->GetPageKind() == PK_STANDARD
)
327 String
aLayoutName(pMaster
->GetLayoutName());
328 aLayoutName
.Erase( aLayoutName
.SearchAscii( SD_LT_SEPARATOR
) );
329 mpLayoutNames
->Insert(new String(aLayoutName
), LIST_APPEND
);
331 Bitmap
aBitmap(pTemplDocSh
->GetPagePreviewBitmap(pMaster
, 90));
332 maVS
.InsertItem((USHORT
)mpLayoutNames
->Count(), aBitmap
, aLayoutName
);
341 pDoc
->CloseBookmarkDoc();
346 mpLayoutNames
->Insert( new String( maStrNone
), LIST_APPEND
);
347 maVS
.InsertItem( (USHORT
) mpLayoutNames
->Count(),
348 Bitmap( SdResId( BMP_FOIL_NONE
) ), maStrNone
);
353 // Vorlage selektieren
354 maVS
.SelectItem( (USHORT
) mpLayoutNames
->Count() );