1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/itemset.hxx>
21 #include <sfx2/new.hxx>
22 #include <vcl/msgbox.hxx>
24 #include "strings.hrc"
25 #include "res_bmp.hrc"
26 #include "sdpreslt.hxx"
27 #include "sdpreslt.hrc"
29 #include "sdresid.hxx"
30 #include "drawdoc.hxx"
32 #include "DrawDocShell.hxx"
34 #define DOCUMENT_TOKEN (sal_Unicode('#'))
36 SdPresLayoutDlg::SdPresLayoutDlg(
37 ::sd::DrawDocShell
* pDocShell
,
39 const SfxItemSet
& rInAttrs
):
40 ModalDialog (pWindow
, SdResId(DLG_PRESLT
)),
41 mpDocSh ( pDocShell
),
42 maFtLayout (this, SdResId(FT_LAYOUT
)),
43 maVS (this, SdResId(VS_LAYOUT
)),
44 maBtnOK (this, SdResId(BTN_OK
)),
45 maBtnCancel (this, SdResId(BTN_CANCEL
)),
46 maBtnHelp (this, SdResId(BTN_HELP
)),
47 maCbxMasterPage (this, SdResId(CBX_MASTER_PAGE
)),
48 maCbxCheckMasters (this, SdResId(CBX_CHECK_MASTERS
)),
49 maBtnLoad (this, SdResId(BTN_LOAD
)),
50 mrOutAttrs (rInAttrs
),
51 maStrNone ( SdResId( STR_NULL
) )
55 maVS
.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg
, ClickLayoutHdl
));
56 maBtnLoad
.SetClickHdl(LINK(this, SdPresLayoutDlg
, ClickLoadHdl
));
61 SdPresLayoutDlg::~SdPresLayoutDlg()
68 void SdPresLayoutDlg::Reset()
70 const SfxPoolItem
*pPoolItem
= NULL
;
73 // replace master page
74 if( mrOutAttrs
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
, sal_False
, &pPoolItem
) == SFX_ITEM_SET
)
76 sal_Bool bMasterPage
= ( (const SfxBoolItem
*) pPoolItem
)->GetValue();
77 maCbxMasterPage
.Enable( !bMasterPage
);
78 maCbxMasterPage
.Check( bMasterPage
);
81 // remove not used master pages
82 maCbxCheckMasters
.Check(sal_False
);
84 if(mrOutAttrs
.GetItemState(ATTR_PRESLAYOUT_NAME
, sal_True
, &pPoolItem
) == SFX_ITEM_SET
)
85 maName
= ((const SfxStringItem
*)pPoolItem
)->GetValue();
91 mnLayoutCount
= maLayoutNames
.size();
92 for( nName
= 0; nName
< mnLayoutCount
; nName
++ )
94 if (maLayoutNames
[nName
] == maName
)
97 DBG_ASSERT(nName
< mnLayoutCount
, "Layout not found");
99 maVS
.SelectItem((sal_uInt16
)nName
+ 1); // Indices of the ValueSets start at 1
104 * Fills the provided Item-Set with dialog box attributes
106 void SdPresLayoutDlg::GetAttr(SfxItemSet
& rOutAttrs
)
108 short nId
= maVS
.GetSelectItemId();
109 sal_Bool bLoad
= nId
> mnLayoutCount
;
110 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
) );
116 aLayoutName
= maName
;
117 aLayoutName
.Append( DOCUMENT_TOKEN
);
118 aLayoutName
.Append( maLayoutNames
[ nId
- 1 ] );
122 aLayoutName
= maLayoutNames
[ nId
- 1 ];
123 if( aLayoutName
== maStrNone
)
124 aLayoutName
.Erase(); // that way we encode "- nothing -" (see below)
127 rOutAttrs
.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME
, aLayoutName
) );
128 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, maCbxMasterPage
.IsChecked() ) );
129 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, maCbxCheckMasters
.IsChecked() ) );
134 * Fills ValueSet with bitmaps
136 void SdPresLayoutDlg::FillValueSet()
138 maVS
.SetStyle(maVS
.GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
139 | WB_VSCROLL
| WB_NAMEFIELD
);
142 maVS
.SetLineCount(2);
143 maVS
.SetExtraSpacing(2);
145 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
147 sal_uInt16 nCount
= pDoc
->GetMasterPageCount();
149 for (sal_uInt16 nLayout
= 0; nLayout
< nCount
; nLayout
++)
151 SdPage
* pMaster
= (SdPage
*)pDoc
->GetMasterPage(nLayout
);
152 if (pMaster
->GetPageKind() == PK_STANDARD
)
154 String
aLayoutName(pMaster
->GetLayoutName());
155 aLayoutName
.Erase( aLayoutName
.SearchAscii( SD_LT_SEPARATOR
) );
156 maLayoutNames
.push_back(new String(aLayoutName
));
158 Bitmap
aBitmap(mpDocSh
->GetPagePreviewBitmap(pMaster
, 90));
159 maVS
.InsertItem((sal_uInt16
)maLayoutNames
.size(), aBitmap
, aLayoutName
);
168 * DoubleClick handler
170 IMPL_LINK_NOARG(SdPresLayoutDlg
, ClickLayoutHdl
)
177 * Click handler for load button
179 IMPL_LINK_NOARG(SdPresLayoutDlg
, ClickLoadHdl
)
181 SfxNewFileDialog
* pDlg
= new SfxNewFileDialog(this, SFXWB_PREVIEW
);
182 pDlg
->SetText(String(SdResId(STR_LOAD_PRESENTATION_LAYOUT
)));
184 if(!IsReallyVisible())
190 sal_uInt16 nResult
= pDlg
->Execute();
191 // Inserted update to force repaint
194 sal_Bool bCancel
= sal_False
;
200 if (pDlg
->IsTemplate())
202 maName
= pDlg
->GetTemplateFileName();
206 // that way we encode "- nothing -"
219 // check if template already ecists
220 sal_Bool bExists
= sal_False
;
221 String
aCompareStr( maName
);
222 if( maName
.Len() == 0 )
223 aCompareStr
= maStrNone
;
226 for (boost::ptr_vector
<String
>::iterator it
= maLayoutNames
.begin();
227 it
!= maLayoutNames
.end() && !bExists
; ++it
, ++aPos
)
229 if( aCompareStr
== *it
)
233 maVS
.SelectItem( aPos
+ 1 );
239 // load document in order to determine preview bitmap (if template is selected)
242 // determine document in order to call OpenBookmarkDoc
243 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
244 SdDrawDocument
* pTemplDoc
= pDoc
->OpenBookmarkDoc( maName
);
248 ::sd::DrawDocShell
* pTemplDocSh
= pTemplDoc
->GetDocSh();
250 sal_uInt16 nCount
= pTemplDoc
->GetMasterPageCount();
252 for (sal_uInt16 nLayout
= 0; nLayout
< nCount
; nLayout
++)
254 SdPage
* pMaster
= (SdPage
*) pTemplDoc
->GetMasterPage(nLayout
);
255 if (pMaster
->GetPageKind() == PK_STANDARD
)
257 String
aLayoutName(pMaster
->GetLayoutName());
258 aLayoutName
.Erase( aLayoutName
.SearchAscii( SD_LT_SEPARATOR
) );
259 maLayoutNames
.push_back(new String(aLayoutName
));
261 Bitmap
aBitmap(pTemplDocSh
->GetPagePreviewBitmap(pMaster
, 90));
262 maVS
.InsertItem((sal_uInt16
)maLayoutNames
.size(), aBitmap
, aLayoutName
);
271 pDoc
->CloseBookmarkDoc();
276 maLayoutNames
.push_back( new String( maStrNone
) );
277 maVS
.InsertItem( (sal_uInt16
) maLayoutNames
.size(),
278 Bitmap( SdResId( BMP_FOIL_NONE
) ), maStrNone
);
284 maVS
.SelectItem( (sal_uInt16
) maLayoutNames
.size() );
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */