bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / present.cxx
blob244cfd2188806a9658811b9bd4115735bd3c8783
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 <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <svl/stritem.hxx>
24 #include <vcl/svapp.hxx>
26 #include <sdattr.hrc>
27 #include <present.hxx>
28 #include <cusshow.hxx>
29 #include <customshowlist.hxx>
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
34 SdStartPresentationDlg::SdStartPresentationDlg(weld::Window* pWindow, const SfxItemSet& rInAttrs,
35 const std::vector<OUString> &rPageNames, SdCustomShowList* pCSList)
36 : GenericDialogController(pWindow, "modules/simpress/ui/presentationdialog.ui", "PresentationDialog")
37 , pCustomShowList(pCSList)
38 , rOutAttrs(rInAttrs)
39 , mnMonitors(0)
40 , m_xRbtAll(m_xBuilder->weld_radio_button("allslides"))
41 , m_xRbtAtDia(m_xBuilder->weld_radio_button("from"))
42 , m_xRbtCustomshow(m_xBuilder->weld_radio_button("customslideshow"))
43 , m_xLbDias(m_xBuilder->weld_combo_box("from_cb"))
44 , m_xLbCustomshow(m_xBuilder->weld_combo_box("customslideshow_cb"))
45 , m_xRbtStandard(m_xBuilder->weld_radio_button("default"))
46 , m_xRbtWindow(m_xBuilder->weld_radio_button("window"))
47 , m_xRbtAuto(m_xBuilder->weld_radio_button("auto"))
48 , m_xTmfPause(m_xBuilder->weld_time_spin_button("pauseduration", TimeFieldFormat::F_SEC))
49 , m_xCbxAutoLogo(m_xBuilder->weld_check_button("showlogo"))
50 , m_xCbxManuel(m_xBuilder->weld_check_button("manualslides"))
51 , m_xCbxMousepointer(m_xBuilder->weld_check_button("pointervisible"))
52 , m_xCbxPen(m_xBuilder->weld_check_button("pointeraspen"))
53 , m_xCbxAnimationAllowed(m_xBuilder->weld_check_button("animationsallowed"))
54 , m_xCbxChangePage(m_xBuilder->weld_check_button("changeslidesbyclick"))
55 , m_xCbxAlwaysOnTop(m_xBuilder->weld_check_button("alwaysontop"))
56 , m_xFtMonitor(m_xBuilder->weld_label("presdisplay_label"))
57 , m_xLBMonitor(m_xBuilder->weld_combo_box("presdisplay_cb"))
58 , m_xMonitor(m_xBuilder->weld_label("monitor_str"))
59 , m_xAllMonitors(m_xBuilder->weld_label("allmonitors_str"))
60 , m_xMonitorExternal(m_xBuilder->weld_label("externalmonitor_str"))
61 , m_xExternal(m_xBuilder->weld_label("external_str"))
63 Link<weld::Button&,void> aLink( LINK( this, SdStartPresentationDlg, ChangeRangeHdl ) );
65 m_xRbtAll->connect_clicked( aLink );
66 m_xRbtAtDia->connect_clicked( aLink );
67 m_xRbtCustomshow->connect_clicked( aLink );
69 aLink = LINK( this, SdStartPresentationDlg, ClickWindowPresentationHdl );
70 m_xRbtStandard->connect_clicked( aLink );
71 m_xRbtWindow->connect_clicked( aLink );
72 m_xRbtAuto->connect_clicked( aLink );
74 m_xTmfPause->connect_value_changed( LINK( this, SdStartPresentationDlg, ChangePauseHdl ) );
76 // fill Listbox with page names
77 for (const auto& rPageName : rPageNames)
78 m_xLbDias->append_text(rPageName);
80 if( pCustomShowList )
82 sal_uInt16 nPosToSelect = pCustomShowList->GetCurPos();
83 SdCustomShow* pCustomShow;
84 // fill Listbox with CustomShows
85 for( pCustomShow = pCustomShowList->First();
86 pCustomShow != nullptr;
87 pCustomShow = pCustomShowList->Next() )
89 m_xLbCustomshow->append_text( pCustomShow->GetName() );
91 m_xLbCustomshow->set_active( nPosToSelect );
92 pCustomShowList->Seek( nPosToSelect );
94 else
95 m_xRbtCustomshow->set_sensitive(false);
97 if( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_CUSTOMSHOW ) ).GetValue() && pCSList )
98 m_xRbtCustomshow->set_active(true);
99 else if( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_ALL ) ).GetValue() )
100 m_xRbtAll->set_active(true);
101 else
102 m_xRbtAtDia->set_active(true);
104 m_xLbDias->set_active_text( static_cast<const SfxStringItem&>( rOutAttrs.Get( ATTR_PRESENT_DIANAME ) ).GetValue() );
105 m_xCbxManuel->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_MANUEL ) ).GetValue() );
106 m_xCbxMousepointer->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_MOUSE ) ).GetValue() );
107 m_xCbxPen->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_PEN ) ).GetValue() );
108 m_xCbxAnimationAllowed->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_ANIMATION_ALLOWED ) ).GetValue() );
109 m_xCbxChangePage->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_CHANGE_PAGE ) ).GetValue() );
110 m_xCbxAlwaysOnTop->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_ALWAYS_ON_TOP ) ).GetValue() );
112 const bool bEndless = static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_ENDLESS ) ).GetValue();
113 const bool bWindow = !static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_FULLSCREEN ) ).GetValue();
114 const long nPause = static_cast<const SfxUInt32Item&>( rOutAttrs.Get( ATTR_PRESENT_PAUSE_TIMEOUT ) ).GetValue();
116 m_xTmfPause->set_value( tools::Time( 0, 0, nPause ) );
117 // set cursor in timefield to end
118 m_xTmfPause->set_position(-1);
120 m_xCbxAutoLogo->set_active( static_cast<const SfxBoolItem&>( rOutAttrs.Get( ATTR_PRESENT_SHOW_PAUSELOGO ) ).GetValue() );
122 if( bWindow )
123 m_xRbtWindow->set_active(true);
124 else if( bEndless )
125 m_xRbtAuto->set_active(true);
126 else
127 m_xRbtStandard->set_active(true);
129 InitMonitorSettings();
131 ChangeRangeHdl(*m_xRbtCustomshow);
133 ClickWindowPresentationHdl(*m_xRbtStandard);
134 ChangePause();
137 SdStartPresentationDlg::~SdStartPresentationDlg()
141 OUString SdStartPresentationDlg::GetDisplayName( sal_Int32 nDisplay,
142 DisplayType eType )
144 OUString aName;
146 switch ( eType )
148 case EXTERNAL_IS_NUMBER:
149 aName = m_xExternal->get_label();
150 break;
151 case MONITOR_IS_EXTERNAL:
152 aName = m_xMonitorExternal->get_label();
153 break;
154 default:
155 case MONITOR_NORMAL:
156 aName = m_xMonitor->get_label();
157 break;
159 aName = aName.replaceFirst( "%1", OUString::number( nDisplay ) );
161 return aName;
164 /// Store display index together with name in user data
165 sal_Int32 SdStartPresentationDlg::InsertDisplayEntry(const OUString &aName,
166 sal_Int32 nDisplay)
168 m_xLBMonitor->append(OUString::number(nDisplay), aName);
169 return m_xLBMonitor->get_count() - 1;
172 void SdStartPresentationDlg::InitMonitorSettings()
176 m_xFtMonitor->show();
177 m_xLBMonitor->show();
179 mnMonitors = Application::GetScreenCount();
181 if( mnMonitors <= 1 )
183 m_xFtMonitor->set_sensitive( false );
184 m_xLBMonitor->set_sensitive( false );
186 else
188 bool bUnifiedDisplay = Application::IsUnifiedDisplay();
189 sal_Int32 nExternalIndex = Application::GetDisplayExternalScreen();
191 sal_Int32 nSelectedIndex (-1);
192 sal_Int32 nDefaultExternalIndex (-1);
193 const sal_Int32 nDefaultSelectedDisplay (
194 static_cast<const SfxInt32Item&>( rOutAttrs.Get( ATTR_PRESENT_DISPLAY ) ).GetValue());
196 // Un-conditionally add a version for '0' the default external display
197 sal_Int32 nInsertedEntry;
199 // Initial entry - the auto-detected external monitor
200 OUString aName = GetDisplayName( nExternalIndex + 1, EXTERNAL_IS_NUMBER);
201 nInsertedEntry = InsertDisplayEntry( aName, 0 );
202 if( nDefaultSelectedDisplay == 0)
203 nSelectedIndex = nInsertedEntry;
205 // The user data contains the real setting
206 for( sal_Int32 nDisplay = 0; nDisplay < mnMonitors; nDisplay++ )
208 aName = GetDisplayName( nDisplay + 1,
209 nDisplay == nExternalIndex ?
210 MONITOR_IS_EXTERNAL : MONITOR_NORMAL );
211 nInsertedEntry = InsertDisplayEntry( aName, nDisplay + 1 );
213 // Remember the index of the default selection.
214 if( nDisplay + 1 == nDefaultSelectedDisplay )
215 nSelectedIndex = nInsertedEntry;
217 // Remember index of the default display.
218 if( nDisplay == nExternalIndex )
219 nDefaultExternalIndex = nInsertedEntry;
222 if( bUnifiedDisplay )
224 nInsertedEntry = InsertDisplayEntry( m_xAllMonitors->get_label(), -1 );
225 if( nDefaultSelectedDisplay == -1 )
226 nSelectedIndex = nInsertedEntry;
229 if (nSelectedIndex < 0)
231 if (nExternalIndex < 0)
232 nSelectedIndex = 0;
233 else
234 nSelectedIndex = nDefaultExternalIndex;
237 m_xLBMonitor->set_active(nSelectedIndex);
240 catch( Exception& )
246 * sets the selected attributes of the dialog
248 void SdStartPresentationDlg::GetAttr( SfxItemSet& rAttr )
250 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALL, m_xRbtAll->get_active() ) );
251 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CUSTOMSHOW, m_xRbtCustomshow->get_active() ) );
252 rAttr.Put( SfxStringItem ( ATTR_PRESENT_DIANAME, m_xLbDias->get_active_text() ) );
253 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MANUEL, m_xCbxManuel->get_active() ) );
254 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MOUSE, m_xCbxMousepointer->get_active() ) );
255 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_PEN, m_xCbxPen->get_active() ) );
256 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ANIMATION_ALLOWED, m_xCbxAnimationAllowed->get_active() ) );
257 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CHANGE_PAGE, m_xCbxChangePage->get_active() ) );
258 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALWAYS_ON_TOP, m_xCbxAlwaysOnTop->get_active() ) );
259 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_FULLSCREEN, !m_xRbtWindow->get_active() ) );
260 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ENDLESS, m_xRbtAuto->get_active() ) );
261 rAttr.Put( SfxUInt32Item ( ATTR_PRESENT_PAUSE_TIMEOUT, m_xTmfPause->get_value().GetMSFromTime() / 1000 ) );
262 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_SHOW_PAUSELOGO, m_xCbxAutoLogo->get_active() ) );
264 int nPos = m_xLBMonitor->get_active();
265 if (nPos != -1)
266 rAttr.Put(SfxInt32Item(ATTR_PRESENT_DISPLAY, m_xLBMonitor->get_id(nPos).toInt32()));
268 nPos = m_xLbCustomshow->get_active();
269 if (nPos != -1)
270 pCustomShowList->Seek( nPos );
274 * Handler: Enabled/Disabled Listbox "Dias"
276 IMPL_LINK_NOARG(SdStartPresentationDlg, ChangeRangeHdl, weld::Button&, void)
278 m_xLbDias->set_sensitive( m_xRbtAtDia->get_active() );
279 m_xLbCustomshow->set_sensitive( m_xRbtCustomshow->get_active() );
283 * Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
285 IMPL_LINK_NOARG(SdStartPresentationDlg, ClickWindowPresentationHdl, weld::Button&, void)
287 const bool bAuto = m_xRbtAuto->get_active();
288 const bool bWindow = m_xRbtWindow->get_active();
290 // m_xFtPause.set_sensitive( bAuto );
291 m_xTmfPause->set_sensitive( bAuto );
292 m_xCbxAutoLogo->set_sensitive( bAuto && ( m_xTmfPause->get_value().GetMSFromTime() > 0 ) );
294 const bool bDisplay = !bWindow && ( mnMonitors > 1 );
295 m_xFtMonitor->set_sensitive( bDisplay );
296 m_xLBMonitor->set_sensitive( bDisplay );
298 if( bWindow )
300 m_xCbxAlwaysOnTop->set_sensitive(false);
301 m_xCbxAlwaysOnTop->set_active(false);
303 else
304 m_xCbxAlwaysOnTop->set_sensitive(true);
308 * Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
310 IMPL_LINK_NOARG(SdStartPresentationDlg, ChangePauseHdl, weld::TimeSpinButton&, void)
312 ChangePause();
315 void SdStartPresentationDlg::ChangePause()
317 m_xCbxAutoLogo->set_sensitive(m_xRbtAuto->get_active() && ( m_xTmfPause->get_value().GetMSFromTime() > 0 ));
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */