fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / dlg / sdpreslt.cxx
blob8a958bce65ec19bfd03b8f2f12d99847c84338e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
28 #include "sdattr.hxx"
29 #include "sdresid.hxx"
30 #include "drawdoc.hxx"
31 #include "sdpage.hxx"
32 #include "DrawDocShell.hxx"
34 #define DOCUMENT_TOKEN (sal_Unicode('#'))
36 SdPresLayoutDlg::SdPresLayoutDlg(
37 ::sd::DrawDocShell* pDocShell,
38 ::Window* pWindow,
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 ) )
53 FreeResource();
55 maVS.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
56 maBtnLoad.SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
58 Reset();
61 SdPresLayoutDlg::~SdPresLayoutDlg()
65 /**
66 * Initialize
68 void SdPresLayoutDlg::Reset()
70 const SfxPoolItem *pPoolItem = NULL;
71 long nName;
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();
86 else
87 maName.Erase();
89 FillValueSet();
91 mnLayoutCount = maLayoutNames.size();
92 for( nName = 0; nName < mnLayoutCount; nName++ )
94 if (maLayoutNames[nName] == maName)
95 break;
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 ) );
112 String aLayoutName;
114 if( bLoad )
116 aLayoutName = maName;
117 aLayoutName.Append( DOCUMENT_TOKEN );
118 aLayoutName.Append( maLayoutNames[ nId - 1 ] );
120 else
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);
141 maVS.SetColCount(2);
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);
163 maVS.Show();
168 * DoubleClick handler
170 IMPL_LINK_NOARG(SdPresLayoutDlg, ClickLayoutHdl)
172 EndDialog(RET_OK);
173 return 0;
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())
186 delete pDlg;
187 return 0;
190 sal_uInt16 nResult = pDlg->Execute();
191 // Inserted update to force repaint
192 Update();
194 sal_Bool bCancel = sal_False;
196 switch (nResult)
198 case RET_OK:
200 if (pDlg->IsTemplate())
202 maName = pDlg->GetTemplateFileName();
204 else
206 // that way we encode "- nothing -"
207 maName.Erase();
210 break;
212 default:
213 bCancel = sal_True;
215 delete pDlg;
217 if( !bCancel )
219 // check if template already ecists
220 sal_Bool bExists = sal_False;
221 String aCompareStr( maName );
222 if( maName.Len() == 0 )
223 aCompareStr = maStrNone;
225 sal_uInt16 aPos = 0;
226 for (boost::ptr_vector<String>::iterator it = maLayoutNames.begin();
227 it != maLayoutNames.end() && !bExists; ++it, ++aPos)
229 if( aCompareStr == *it )
231 bExists = sal_True;
232 // select template
233 maVS.SelectItem( aPos + 1 );
237 if( !bExists )
239 // load document in order to determine preview bitmap (if template is selected)
240 if( maName.Len() )
242 // determine document in order to call OpenBookmarkDoc
243 SdDrawDocument* pDoc = mpDocSh->GetDoc();
244 SdDrawDocument* pTemplDoc = pDoc->OpenBookmarkDoc( maName );
246 if (pTemplDoc)
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);
266 else
268 bCancel = sal_True;
271 pDoc->CloseBookmarkDoc();
273 else
275 // empty layout
276 maLayoutNames.push_back( new String( maStrNone ) );
277 maVS.InsertItem( (sal_uInt16) maLayoutNames.size(),
278 Bitmap( SdResId( BMP_FOIL_NONE ) ), maStrNone );
281 if (!bCancel)
283 // select template
284 maVS.SelectItem( (sal_uInt16) maLayoutNames.size() );
289 return( 0 );
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */