merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / present.cxx
blob349fb7871bd02543135c9c9152deede5da971b7f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: present.cxx,v $
10 * $Revision: 1.12 $
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
36 #endif
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <svtools/itemset.hxx>
43 #include "sdattr.hxx"
44 #include "present.hxx"
45 #include "present.hrc"
46 #include "sdresid.hxx"
47 #include "cusshow.hxx"
49 using ::rtl::OUString;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::container;
53 using namespace ::com::sun::star::beans;
55 /*************************************************************************
56 |* Ctor
57 \************************************************************************/
58 SdStartPresentationDlg::SdStartPresentationDlg( Window* pWindow,
59 const SfxItemSet& rInAttrs,
60 List& rPageNames, List* pCSList ) :
61 ModalDialog ( pWindow, SdResId( DLG_START_PRESENTATION ) ),
62 aGrpRange ( this, SdResId( GRP_RANGE ) ),
63 aRbtAll ( this, SdResId( RBT_ALL ) ),
64 aRbtAtDia ( this, SdResId( RBT_AT_DIA ) ),
65 aRbtCustomshow ( this, SdResId( RBT_CUSTOMSHOW ) ),
66 aLbDias ( this, SdResId( LB_DIAS ) ),
67 aLbCustomshow ( this, SdResId( LB_CUSTOMSHOW ) ),
69 aGrpKind ( this, SdResId( GRP_KIND ) ),
70 aRbtStandard ( this, SdResId( RBT_STANDARD ) ),
71 aRbtWindow ( this, SdResId( RBT_WINDOW ) ),
72 aRbtAuto ( this, SdResId( RBT_AUTO ) ),
73 aTmfPause ( this, SdResId( TMF_PAUSE ) ),
74 aCbxAutoLogo ( this, SdResId( CBX_AUTOLOGO ) ),
76 aGrpOptions ( this, SdResId( GRP_OPTIONS ) ),
77 aCbxManuel ( this, SdResId( CBX_MANUEL ) ),
78 aCbxMousepointer ( this, SdResId( CBX_MOUSEPOINTER ) ),
79 aCbxPen ( this, SdResId( CBX_PEN ) ),
80 aCbxNavigator ( this, SdResId( CBX_NAVIGATOR ) ),
81 aCbxAnimationAllowed ( this, SdResId( CBX_ANIMATION_ALLOWED ) ),
82 aCbxChangePage ( this, SdResId( CBX_CHANGE_PAGE ) ),
83 aCbxAlwaysOnTop ( this, SdResId( CBX_ALWAYS_ON_TOP ) ),
85 maGrpMonitor ( this, SdResId( GRP_MONITOR ) ),
86 maFtMonitor ( this, SdResId( FT_MONITOR ) ),
87 maLBMonitor ( this, SdResId( LB_MONITOR ) ),
89 aBtnOK ( this, SdResId( BTN_OK ) ),
90 aBtnCancel ( this, SdResId( BTN_CANCEL ) ),
91 aBtnHelp ( this, SdResId( BTN_HELP ) ),
93 pCustomShowList ( pCSList ),
94 rOutAttrs ( rInAttrs ),
95 mnMonitors ( 0 ),
97 msPrimaryMonitor( SdResId(STR_PRIMARY_MONITOR ) ),
98 msMonitor( SdResId( STR_MONITOR ) ),
99 msAllMonitors( SdResId( STR_ALL_MONITORS ) )
101 FreeResource();
103 Link aLink( LINK( this, SdStartPresentationDlg, ChangeRangeHdl ) );
105 aRbtAll.SetClickHdl( aLink );
106 aRbtAtDia.SetClickHdl( aLink );
107 aRbtCustomshow.SetClickHdl( aLink );
109 aLink = LINK( this, SdStartPresentationDlg, ClickWindowPresentationHdl );
110 aRbtStandard.SetClickHdl( aLink );
111 aRbtWindow.SetClickHdl( aLink );
112 aRbtAuto.SetClickHdl( aLink );
114 aTmfPause.SetModifyHdl( LINK( this, SdStartPresentationDlg, ChangePauseHdl ) );
115 aTmfPause.SetFormat( TIMEF_SEC );
117 // Listbox mit Seitennamen fuellen
118 rPageNames.First();
119 for( UINT16 i = 0;
120 i < rPageNames.Count();
121 i++ )
123 aLbDias.InsertEntry( *( String* ) rPageNames.GetCurObject() );
124 rPageNames.Next();
127 if( pCustomShowList )
129 USHORT nPosToSelect = (USHORT) pCustomShowList->GetCurPos();
130 SdCustomShow* pCustomShow;
131 // Listbox mit CustomShows fuellen
132 for( pCustomShow = (SdCustomShow*) pCustomShowList->First();
133 pCustomShow != NULL;
134 pCustomShow = (SdCustomShow*) pCustomShowList->Next() )
136 aLbCustomshow.InsertEntry( pCustomShow->GetName() );
138 aLbCustomshow.SelectEntryPos( nPosToSelect );
139 pCustomShowList->Seek( nPosToSelect );
141 else
142 aRbtCustomshow.Disable();
144 if( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_CUSTOMSHOW ) ).GetValue() && pCSList )
145 aRbtCustomshow.Check();
146 else if( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ALL ) ).GetValue() )
147 aRbtAll.Check();
148 else
149 aRbtAtDia.Check();
151 aLbDias.SelectEntry( ( ( const SfxStringItem& ) rOutAttrs.Get( ATTR_PRESENT_DIANAME ) ).GetValue() );
152 aCbxManuel.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_MANUEL ) ).GetValue() );
153 aCbxMousepointer.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_MOUSE ) ).GetValue() );
154 aCbxPen.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_PEN ) ).GetValue() );
155 aCbxNavigator.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_NAVIGATOR ) ).GetValue() );
156 aCbxAnimationAllowed.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ANIMATION_ALLOWED ) ).GetValue() );
157 aCbxChangePage.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_CHANGE_PAGE ) ).GetValue() );
158 aCbxAlwaysOnTop.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ALWAYS_ON_TOP ) ).GetValue() );
160 const BOOL bEndless = ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ENDLESS ) ).GetValue();
161 const BOOL bWindow = !( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_FULLSCREEN ) ).GetValue();
162 const long nPause = ( ( const SfxUInt32Item& ) rOutAttrs.Get( ATTR_PRESENT_PAUSE_TIMEOUT ) ).GetValue();
164 aTmfPause.SetTime( Time( 0, 0, nPause ) );
165 // set cursor in timefield
166 Edit *pEdit = aTmfPause.GetField();
167 Selection aSel( pEdit->GetMaxTextLen(), pEdit->GetMaxTextLen() );
168 pEdit->SetSelection( aSel );
170 aCbxAutoLogo.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_SHOW_PAUSELOGO ) ).GetValue() );
172 if( bWindow )
173 aRbtWindow.Check( TRUE );
174 else if( bEndless )
175 aRbtAuto.Check( TRUE );
176 else
177 aRbtStandard.Check( TRUE );
179 InitMonitorSettings();
181 ChangeRangeHdl( this );
183 ClickWindowPresentationHdl( NULL );
184 ChangePauseHdl( NULL );
187 void SdStartPresentationDlg::InitMonitorSettings()
191 Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
192 Reference< XIndexAccess > xMultiMon( xFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), UNO_QUERY_THROW );
193 maGrpMonitor.Show( true );
194 maFtMonitor.Show( true );
195 maLBMonitor.Show( true );
197 mnMonitors = xMultiMon->getCount();
199 if( mnMonitors <= 1 )
201 maFtMonitor.Enable( false );
202 maLBMonitor.Enable( false );
204 else
206 sal_Bool bMultiscreen = false;
207 sal_Int32 nPrimaryIndex = 0;
208 Reference< XPropertySet > xMonProps( xMultiMon, UNO_QUERY );
209 if( xMonProps.is() ) try
211 const OUString sPropName1( RTL_CONSTASCII_USTRINGPARAM( "MultiDisplay" ) );
212 xMonProps->getPropertyValue( sPropName1 ) >>= bMultiscreen;
213 const OUString sPropName2( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
214 xMonProps->getPropertyValue( sPropName2 ) >>= nPrimaryIndex;
216 catch( Exception& )
220 const String sPlaceHolder( RTL_CONSTASCII_USTRINGPARAM( "%1" ) );
221 for( sal_Int32 nDisplay = 0; nDisplay < mnMonitors; nDisplay++ )
223 String aName( nDisplay == nPrimaryIndex ? msPrimaryMonitor : msMonitor );
224 const String aNumber( String::CreateFromInt32( nDisplay + 1 ) );
225 aName.SearchAndReplace( sPlaceHolder, aNumber );
226 maLBMonitor.InsertEntry( aName );
229 if( !bMultiscreen )
230 maLBMonitor.InsertEntry( msAllMonitors );
232 sal_Int32 nSelected = ( ( const SfxInt32Item& ) rOutAttrs.Get( ATTR_PRESENT_DISPLAY ) ).GetValue();
233 if( nSelected <= 0 )
234 nSelected = nPrimaryIndex;
235 else
236 nSelected--;
238 maLBMonitor.SelectEntryPos( (USHORT)nSelected );
241 catch( Exception& )
246 /*************************************************************************
247 |* Setzt die ausgewaehlten Attribute des Dialogs
248 \************************************************************************/
249 void SdStartPresentationDlg::GetAttr( SfxItemSet& rAttr )
251 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALL, aRbtAll.IsChecked() ) );
252 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CUSTOMSHOW, aRbtCustomshow.IsChecked() ) );
253 rAttr.Put( SfxStringItem ( ATTR_PRESENT_DIANAME, aLbDias.GetSelectEntry() ) );
254 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MANUEL, aCbxManuel.IsChecked() ) );
255 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MOUSE, aCbxMousepointer.IsChecked() ) );
256 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_PEN, aCbxPen.IsChecked() ) );
257 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_NAVIGATOR, aCbxNavigator.IsChecked() ) );
258 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ANIMATION_ALLOWED, aCbxAnimationAllowed.IsChecked() ) );
259 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CHANGE_PAGE, aCbxChangePage.IsChecked() ) );
260 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALWAYS_ON_TOP, aCbxAlwaysOnTop.IsChecked() ) );
261 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_FULLSCREEN, !aRbtWindow.IsChecked() ) );
262 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ENDLESS, aRbtAuto.IsChecked() ) );
263 rAttr.Put( SfxUInt32Item ( ATTR_PRESENT_PAUSE_TIMEOUT, aTmfPause.GetTime().GetMSFromTime() / 1000 ) );
264 rAttr.Put( SfxBoolItem ( ATTR_PRESENT_SHOW_PAUSELOGO, aCbxAutoLogo.IsChecked() ) );
266 USHORT nPos = maLBMonitor.GetSelectEntryPos();
267 if( nPos != LISTBOX_ENTRY_NOTFOUND )
268 rAttr.Put( SfxInt32Item ( ATTR_PRESENT_DISPLAY, nPos + 1 ) );
270 nPos = aLbCustomshow.GetSelectEntryPos();
271 if( nPos != LISTBOX_ENTRY_NOTFOUND )
272 pCustomShowList->Seek( nPos );
275 /*************************************************************************
276 |* Handler: Enabled/Disabled Listbox "Dias"
277 \************************************************************************/
278 IMPL_LINK( SdStartPresentationDlg, ChangeRangeHdl, void *, EMPTYARG )
280 aLbDias.Enable( aRbtAtDia.IsChecked() );
281 aLbCustomshow.Enable( aRbtCustomshow.IsChecked() );
283 return( 0L );
286 /*************************************************************************
287 |* Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
288 \************************************************************************/
289 IMPL_LINK( SdStartPresentationDlg, ClickWindowPresentationHdl, void *, EMPTYARG )
291 const bool bAuto = aRbtAuto.IsChecked();
292 const bool bWindow = aRbtWindow.IsChecked();
294 // aFtPause.Enable( bAuto );
295 aTmfPause.Enable( bAuto );
296 aCbxAutoLogo.Enable( bAuto && ( aTmfPause.GetTime().GetMSFromTime() > 0 ) );
298 const bool bDisplay = !bWindow && ( mnMonitors > 1 );
299 maFtMonitor.Enable( bDisplay );
300 maLBMonitor.Enable( bDisplay );
302 if( bWindow )
304 aCbxAlwaysOnTop.Enable( FALSE );
305 aCbxAlwaysOnTop.Check( FALSE );
307 else
308 aCbxAlwaysOnTop.Enable();
310 return( 0L );
313 /*************************************************************************
314 |* Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
315 \************************************************************************/
316 IMPL_LINK( SdStartPresentationDlg, ChangePauseHdl, void *, EMPTYARG )
318 aCbxAutoLogo.Enable( aRbtAuto.IsChecked() && ( aTmfPause.GetTime().GetMSFromTime() > 0 ) );
319 return( 0L );