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>
23 #include <strings.hrc>
25 #include <bitmaps.hlst>
26 #include <sdpreslt.hxx>
28 #include <sdresid.hxx>
29 #include <drawdoc.hxx>
31 #include <DrawDocShell.hxx>
34 SdPresLayoutDlg::SdPresLayoutDlg(::sd::DrawDocShell
* pDocShell
,
35 vcl::Window
* pWindow
, const SfxItemSet
& rInAttrs
)
36 : ModalDialog(pWindow
, "SlideDesignDialog",
37 "modules/simpress/ui/slidedesigndialog.ui")
39 , mrOutAttrs(rInAttrs
)
40 , maStrNone(SdResId(STR_NULL
))
43 Size
aPref(LogicToPixel(Size(144 , 141), MapMode(MapUnit::MapAppFont
)));
44 m_pVS
->set_width_request(aPref
.Width());
45 m_pVS
->set_height_request(aPref
.Height());
46 get(m_pCbxMasterPage
, "masterpage");
47 get(m_pCbxCheckMasters
, "checkmasters");
48 get(m_pBtnLoad
, "load");
50 m_pVS
->SetDoubleClickHdl(LINK(this, SdPresLayoutDlg
, ClickLayoutHdl
));
51 m_pBtnLoad
->SetClickHdl(LINK(this, SdPresLayoutDlg
, ClickLoadHdl
));
56 SdPresLayoutDlg::~SdPresLayoutDlg()
61 void SdPresLayoutDlg::dispose()
64 m_pCbxMasterPage
.clear();
65 m_pCbxCheckMasters
.clear();
67 ModalDialog::dispose();
73 void SdPresLayoutDlg::Reset()
75 const SfxPoolItem
*pPoolItem
= nullptr;
78 // replace master page
79 if( mrOutAttrs
.GetItemState( ATTR_PRESLAYOUT_MASTER_PAGE
, false, &pPoolItem
) == SfxItemState::SET
)
81 bool bMasterPage
= static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue();
82 m_pCbxMasterPage
->Enable( !bMasterPage
);
83 m_pCbxMasterPage
->Check( bMasterPage
);
86 // remove not used master pages
87 m_pCbxCheckMasters
->Check(false);
89 if(mrOutAttrs
.GetItemState(ATTR_PRESLAYOUT_NAME
, true, &pPoolItem
) == SfxItemState::SET
)
90 maName
= static_cast<const SfxStringItem
*>(pPoolItem
)->GetValue();
96 mnLayoutCount
= maLayoutNames
.size();
97 for( nName
= 0; nName
< mnLayoutCount
; nName
++ )
99 if (maLayoutNames
[nName
] == maName
)
102 DBG_ASSERT(nName
< mnLayoutCount
, "Layout not found");
104 m_pVS
->SelectItem(static_cast<sal_uInt16
>(nName
) + 1); // Indices of the ValueSets start at 1
109 * Fills the provided Item-Set with dialog box attributes
111 void SdPresLayoutDlg::GetAttr(SfxItemSet
& rOutAttrs
)
113 short nId
= m_pVS
->GetSelectedItemId();
114 bool bLoad
= nId
> mnLayoutCount
;
115 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_LOAD
, bLoad
) );
117 OUString aLayoutName
;
121 aLayoutName
= maName
+ "#" + maLayoutNames
[ nId
- 1 ];
125 aLayoutName
= maLayoutNames
[ nId
- 1 ];
126 if( aLayoutName
== maStrNone
)
127 aLayoutName
.clear(); // that way we encode "- nothing -" (see below)
130 rOutAttrs
.Put( SfxStringItem( ATTR_PRESLAYOUT_NAME
, aLayoutName
) );
131 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_MASTER_PAGE
, m_pCbxMasterPage
->IsChecked() ) );
132 rOutAttrs
.Put( SfxBoolItem( ATTR_PRESLAYOUT_CHECK_MASTERS
, m_pCbxCheckMasters
->IsChecked() ) );
136 * Fills ValueSet with bitmaps
138 void SdPresLayoutDlg::FillValueSet()
140 m_pVS
->SetStyle(m_pVS
->GetStyle() | WB_ITEMBORDER
| WB_DOUBLEBORDER
141 | WB_VSCROLL
| WB_NAMEFIELD
);
143 m_pVS
->SetColCount(2);
144 m_pVS
->SetLineCount(2);
145 m_pVS
->SetExtraSpacing(2);
147 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
149 sal_uInt16 nCount
= pDoc
->GetMasterPageCount();
151 for (sal_uInt16 nLayout
= 0; nLayout
< nCount
; nLayout
++)
153 SdPage
* pMaster
= static_cast<SdPage
*>(pDoc
->GetMasterPage(nLayout
));
154 if (pMaster
->GetPageKind() == PageKind::Standard
)
156 OUString
aLayoutName(pMaster
->GetLayoutName());
157 aLayoutName
= aLayoutName
.copy(0, aLayoutName
.indexOf(SD_LT_SEPARATOR
));
158 maLayoutNames
.push_back(aLayoutName
);
160 Image
aBitmap(mpDocSh
->GetPagePreviewBitmap(pMaster
));
161 m_pVS
->InsertItem(static_cast<sal_uInt16
>(maLayoutNames
.size()), aBitmap
, aLayoutName
);
169 * DoubleClick handler
171 IMPL_LINK_NOARG(SdPresLayoutDlg
, ClickLayoutHdl
, ValueSet
*, void)
177 * Click handler for load button
179 IMPL_LINK_NOARG(SdPresLayoutDlg
, ClickLoadHdl
, Button
*, void)
181 SfxNewFileDialog
aDlg(GetFrameWeld(), SfxNewFileDialogMode::Preview
);
182 aDlg
.set_title(SdResId(STR_LOAD_PRESENTATION_LAYOUT
));
184 if(!IsReallyVisible())
187 sal_uInt16 nResult
= aDlg
.run();
188 // Inserted update to force repaint
191 bool bCancel
= false;
197 if (aDlg
.IsTemplate())
199 maName
= aDlg
.GetTemplateFileName();
203 // that way we encode "- nothing -"
215 // check if template already exists
216 bool bExists
= false;
217 OUString
aCompareStr(maName
);
218 if (aCompareStr
.isEmpty())
219 aCompareStr
= maStrNone
;
222 for (std::vector
<OUString
>::iterator it
= maLayoutNames
.begin();
223 it
!= maLayoutNames
.end() && !bExists
; ++it
, ++aPos
)
225 if( aCompareStr
== *it
)
229 m_pVS
->SelectItem( aPos
+ 1 );
235 // load document in order to determine preview bitmap (if template is selected)
236 if (!maName
.isEmpty())
238 // determine document in order to call OpenBookmarkDoc
239 SdDrawDocument
* pDoc
= mpDocSh
->GetDoc();
240 SdDrawDocument
* pTemplDoc
= pDoc
->OpenBookmarkDoc( maName
);
244 ::sd::DrawDocShell
* pTemplDocSh
= pTemplDoc
->GetDocSh();
246 sal_uInt16 nCount
= pTemplDoc
->GetMasterPageCount();
248 for (sal_uInt16 nLayout
= 0; nLayout
< nCount
; nLayout
++)
250 SdPage
* pMaster
= static_cast<SdPage
*>( pTemplDoc
->GetMasterPage(nLayout
) );
251 if (pMaster
->GetPageKind() == PageKind::Standard
)
253 OUString
aLayoutName(pMaster
->GetLayoutName());
254 aLayoutName
= aLayoutName
.copy(0, aLayoutName
.indexOf(SD_LT_SEPARATOR
));
255 maLayoutNames
.push_back(aLayoutName
);
257 Image
aBitmap(pTemplDocSh
->GetPagePreviewBitmap(pMaster
));
258 m_pVS
->InsertItem(static_cast<sal_uInt16
>(maLayoutNames
.size()), aBitmap
, aLayoutName
);
267 pDoc
->CloseBookmarkDoc();
272 maLayoutNames
.push_back(maStrNone
);
273 m_pVS
->InsertItem( static_cast<sal_uInt16
>(maLayoutNames
.size()),
274 Image(BMP_FOIL_NONE
), maStrNone
);
280 m_pVS
->SelectItem( static_cast<sal_uInt16
>(maLayoutNames
.size()) );
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */