xref: /trunk/main/sd/source/ui/dlg/present.cxx (revision 5b190011)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #ifdef SD_DLLIMPLEMENTATION
28 #undef SD_DLLIMPLEMENTATION
29 #endif
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/container/XIndexAccess.hpp>
33 #include <comphelper/processfactory.hxx>
34 #include <svl/itemset.hxx>
35 
36 #include "sdattr.hxx"
37 #include "present.hxx"
38 #include "present.hrc"
39 #include "sdresid.hxx"
40 #include "cusshow.hxx"
41 
42 using ::rtl::OUString;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::beans;
47 
48 /*************************************************************************
49 |* Ctor
50 \************************************************************************/
SdStartPresentationDlg(Window * pWindow,const SfxItemSet & rInAttrs,List & rPageNames,List * pCSList)51 SdStartPresentationDlg::SdStartPresentationDlg( Window* pWindow,
52 								  const SfxItemSet& rInAttrs,
53 								  List& rPageNames, List* pCSList ) :
54 				ModalDialog     ( pWindow, SdResId( DLG_START_PRESENTATION ) ),
55 				aGrpRange               ( this, SdResId( GRP_RANGE ) ),
56 				aRbtAll                 ( this, SdResId( RBT_ALL ) ),
57 				aRbtAtDia               ( this, SdResId( RBT_AT_DIA ) ),
58 				aRbtCustomshow          ( this, SdResId( RBT_CUSTOMSHOW ) ),
59 				aLbDias                 ( this, SdResId( LB_DIAS ) ),
60 				aLbCustomshow           ( this, SdResId( LB_CUSTOMSHOW ) ),
61 
62 				aGrpKind				( this, SdResId( GRP_KIND ) ),
63 				aRbtStandard			( this, SdResId( RBT_STANDARD ) ),
64 				aRbtWindow				( this, SdResId( RBT_WINDOW ) ),
65 				aRbtAuto				( this, SdResId( RBT_AUTO ) ),
66 				aTmfPause				( this, SdResId( TMF_PAUSE ) ),
67 				aCbxAutoLogo			( this, SdResId( CBX_AUTOLOGO ) ),
68 
69 				aGrpOptions             ( this, SdResId( GRP_OPTIONS ) ),
70 				aCbxManuel              ( this, SdResId( CBX_MANUEL ) ),
71 				aCbxMousepointer        ( this, SdResId( CBX_MOUSEPOINTER ) ),
72 				aCbxPen                 ( this, SdResId( CBX_PEN ) ),
73 				aCbxNavigator           ( this, SdResId( CBX_NAVIGATOR ) ),
74 				aCbxAnimationAllowed    ( this, SdResId( CBX_ANIMATION_ALLOWED ) ),
75 				aCbxChangePage          ( this, SdResId( CBX_CHANGE_PAGE ) ),
76 				aCbxAlwaysOnTop         ( this, SdResId( CBX_ALWAYS_ON_TOP ) ),
77 
78 				maGrpMonitor			( this, SdResId( GRP_MONITOR ) ),
79 				maFtMonitor				( this, SdResId( FT_MONITOR ) ),
80 				maLBMonitor				( this, SdResId( LB_MONITOR ) ),
81 
82 				aBtnOK                  ( this, SdResId( BTN_OK ) ),
83 				aBtnCancel              ( this, SdResId( BTN_CANCEL ) ),
84 				aBtnHelp                ( this, SdResId( BTN_HELP ) ),
85 
86 				pCustomShowList			( pCSList ),
87 				rOutAttrs               ( rInAttrs ),
88 				mnMonitors				( 0 ),
89 
90 				msPrimaryMonitor( SdResId(STR_PRIMARY_MONITOR ) ),
91 				msMonitor( SdResId( STR_MONITOR ) ),
92 				msAllMonitors( SdResId( STR_ALL_MONITORS ) )
93 {
94 	FreeResource();
95 
96 	Link aLink( LINK( this, SdStartPresentationDlg, ChangeRangeHdl ) );
97 
98 	aRbtAll.SetClickHdl( aLink );
99 	aRbtAtDia.SetClickHdl( aLink );
100 	aRbtCustomshow.SetClickHdl( aLink );
101 
102 	aLink = LINK( this, SdStartPresentationDlg, ClickWindowPresentationHdl );
103 	aRbtStandard.SetClickHdl( aLink );
104 	aRbtWindow.SetClickHdl( aLink );
105 	aRbtAuto.SetClickHdl( aLink );
106 
107 	aTmfPause.SetModifyHdl( LINK( this, SdStartPresentationDlg, ChangePauseHdl ) );
108 	aTmfPause.SetFormat( TIMEF_SEC );
109 
110 	aLbDias.SetAccessibleRelationLabeledBy( &aRbtAtDia );
111 	aLbDias.SetAccessibleName(aRbtAtDia.GetText());
112 	aLbCustomshow.SetAccessibleRelationLabeledBy( &aRbtCustomshow );
113 	aTmfPause.SetAccessibleRelationLabeledBy( &aRbtAuto );
114 	aTmfPause.SetAccessibleName(aRbtAuto.GetText());
115 
116 	// Listbox mit Seitennamen fuellen
117 	rPageNames.First();
118 	for( sal_uInt16 i = 0;
119 		 i < rPageNames.Count();
120 		 i++ )
121 	{
122 		aLbDias.InsertEntry( *( String* ) rPageNames.GetCurObject() );
123 		rPageNames.Next();
124 	}
125 
126 	if( pCustomShowList )
127 	{
128 		sal_uInt16 nPosToSelect = (sal_uInt16) pCustomShowList->GetCurPos();
129 		SdCustomShow* pCustomShow;
130 		// Listbox mit CustomShows fuellen
131 		for( pCustomShow = (SdCustomShow*) pCustomShowList->First();
132 			 pCustomShow != NULL;
133 			 pCustomShow = (SdCustomShow*) pCustomShowList->Next() )
134 		{
135 			aLbCustomshow.InsertEntry( pCustomShow->GetName() );
136 		}
137 		aLbCustomshow.SelectEntryPos( nPosToSelect );
138 		pCustomShowList->Seek( nPosToSelect );
139 	}
140 	else
141 		aRbtCustomshow.Disable();
142 
143 	if( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_CUSTOMSHOW ) ).GetValue() && pCSList )
144 		aRbtCustomshow.Check();
145 	else if( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ALL ) ).GetValue() )
146 		aRbtAll.Check();
147 	else
148 		aRbtAtDia.Check();
149 
150 	aLbDias.SelectEntry( ( ( const SfxStringItem& ) rOutAttrs.Get( ATTR_PRESENT_DIANAME ) ).GetValue() );
151 	aCbxManuel.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_MANUEL ) ).GetValue() );
152 	aCbxMousepointer.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_MOUSE ) ).GetValue() );
153 	aCbxPen.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_PEN ) ).GetValue() );
154 	aCbxNavigator.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_NAVIGATOR ) ).GetValue() );
155 	aCbxAnimationAllowed.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ANIMATION_ALLOWED ) ).GetValue() );
156 	aCbxChangePage.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_CHANGE_PAGE ) ).GetValue() );
157 	aCbxAlwaysOnTop.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ALWAYS_ON_TOP ) ).GetValue() );
158 
159 	const sal_Bool	bEndless = ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_ENDLESS ) ).GetValue();
160 	const sal_Bool	bWindow = !( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_FULLSCREEN ) ).GetValue();
161 	const long	nPause = ( ( const SfxUInt32Item& ) rOutAttrs.Get( ATTR_PRESENT_PAUSE_TIMEOUT ) ).GetValue();
162 
163 	aTmfPause.SetTime( Time( 0, 0, nPause ) );
164 	// set cursor in timefield
165 	Edit *pEdit = aTmfPause.GetField();
166 	Selection aSel( pEdit->GetMaxTextLen(), pEdit->GetMaxTextLen() );
167 	pEdit->SetSelection( aSel );
168 
169 	aCbxAutoLogo.Check( ( ( const SfxBoolItem& ) rOutAttrs.Get( ATTR_PRESENT_SHOW_PAUSELOGO ) ).GetValue() );
170 
171 	if( bWindow )
172 		aRbtWindow.Check( sal_True );
173 	else if( bEndless )
174 		aRbtAuto.Check( sal_True );
175 	else
176 		aRbtStandard.Check( sal_True );
177 
178 	InitMonitorSettings();
179 
180 	ChangeRangeHdl( this );
181 
182 	ClickWindowPresentationHdl( NULL );
183 	ChangePauseHdl( NULL );
184 }
185 
InitMonitorSettings()186 void SdStartPresentationDlg::InitMonitorSettings()
187 {
188 	try
189 	{
190         Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
191 		Reference< XIndexAccess > xMultiMon( xFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), UNO_QUERY_THROW );
192 		maGrpMonitor.Show( true );
193 		maFtMonitor.Show( true );
194 		maLBMonitor.Show( true );
195 
196 		mnMonitors = xMultiMon->getCount();
197 
198 		if( mnMonitors <= 1 )
199 		{
200 			maFtMonitor.Enable( false );
201 			maLBMonitor.Enable( false );
202 		}
203 		else
204 		{
205 			sal_Bool bMultiscreen = false;
206 			sal_Int32 nDefaultDisplay (0);
207 			Reference< XPropertySet > xMonProps( xMultiMon, UNO_QUERY );
208 			if( xMonProps.is() ) try
209 			{
210 				const OUString sPropName1( RTL_CONSTASCII_USTRINGPARAM( "MultiDisplay" ) );
211 				xMonProps->getPropertyValue( sPropName1 ) >>= bMultiscreen;
212 				const OUString sPropName2( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
213 				xMonProps->getPropertyValue( sPropName2 ) >>= nDefaultDisplay;
214 			}
215 			catch( Exception& )
216 			{
217 			}
218 
219             sal_Int32 nSelectedIndex (-1);
220             sal_Int32 nDefaultDisplayIndex (-1);
221 			const sal_Int32 nDefaultSelectedDisplay (
222                 ( ( const SfxInt32Item& ) rOutAttrs.Get( ATTR_PRESENT_DISPLAY ) ).GetValue());
223 			const String sPlaceHolder( RTL_CONSTASCII_USTRINGPARAM( "%1" ) );
224 			for( sal_Int32 nDisplay = 0; nDisplay < mnMonitors; nDisplay++ )
225 			{
226 				String aName( nDisplay == nDefaultDisplay ? msPrimaryMonitor : msMonitor );
227 				const String aNumber( String::CreateFromInt32( nDisplay + 1 ) );
228 				aName.SearchAndReplace( sPlaceHolder, aNumber );
229 				maLBMonitor.InsertEntry( aName );
230 
231                 // Store display index together with name.
232                 const sal_uInt32 nEntryIndex (maLBMonitor.GetEntryCount()-1);
233                 maLBMonitor.SetEntryData(nEntryIndex, (void*)nDisplay);
234 
235                 // Remember the index of the default selection.
236                 if (nDefaultSelectedDisplay == nDisplay)
237                     nSelectedIndex = nEntryIndex;
238 
239                 // Remember index of the default display.
240                 if (nDisplay == nDefaultDisplay)
241                     nDefaultDisplayIndex = nEntryIndex;
242 			}
243 
244 			if( !bMultiscreen )
245             {
246 				maLBMonitor.InsertEntry( msAllMonitors );
247                 const sal_uInt32 nEntryIndex (maLBMonitor.GetEntryCount()-1);
248 				maLBMonitor.SetEntryData(nEntryIndex, (void*)-1);
249                 if (nDefaultSelectedDisplay == -1)
250                     nSelectedIndex = nEntryIndex;
251             }
252 
253 			if (nSelectedIndex < 0)
254             {
255                 if (nDefaultSelectedDisplay < 0)
256                     nSelectedIndex = 0;
257                 else
258                     nSelectedIndex = nDefaultDisplayIndex;
259             }
260 
261 			maLBMonitor.SelectEntryPos((sal_uInt16)nSelectedIndex);
262 		}
263 	}
264 	catch( Exception& )
265 	{
266 	}
267 }
268 
269 /*************************************************************************
270 |* Setzt die ausgewaehlten Attribute des Dialogs
271 \************************************************************************/
GetAttr(SfxItemSet & rAttr)272 void SdStartPresentationDlg::GetAttr( SfxItemSet& rAttr )
273 {
274 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALL, aRbtAll.IsChecked() ) );
275 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CUSTOMSHOW, aRbtCustomshow.IsChecked() ) );
276 	rAttr.Put( SfxStringItem ( ATTR_PRESENT_DIANAME, aLbDias.GetSelectEntry() ) );
277 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MANUEL, aCbxManuel.IsChecked() ) );
278 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_MOUSE, aCbxMousepointer.IsChecked() ) );
279 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_PEN, aCbxPen.IsChecked() ) );
280 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_NAVIGATOR, aCbxNavigator.IsChecked() ) );
281 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ANIMATION_ALLOWED, aCbxAnimationAllowed.IsChecked() ) );
282 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_CHANGE_PAGE, aCbxChangePage.IsChecked() ) );
283 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ALWAYS_ON_TOP, aCbxAlwaysOnTop.IsChecked() ) );
284 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_FULLSCREEN, !aRbtWindow.IsChecked() ) );
285 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_ENDLESS, aRbtAuto.IsChecked() ) );
286 	rAttr.Put( SfxUInt32Item ( ATTR_PRESENT_PAUSE_TIMEOUT, aTmfPause.GetTime().GetMSFromTime() / 1000 ) );
287 	rAttr.Put( SfxBoolItem ( ATTR_PRESENT_SHOW_PAUSELOGO, aCbxAutoLogo.IsChecked() ) );
288 
289 	sal_uInt16 nPos = maLBMonitor.GetSelectEntryPos();
290 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
291         rAttr.Put( SfxInt32Item ( ATTR_PRESENT_DISPLAY, (sal_Int32)(sal_IntPtr)maLBMonitor.GetEntryData(nPos)) );
292 
293 	nPos = aLbCustomshow.GetSelectEntryPos();
294 	if( nPos != LISTBOX_ENTRY_NOTFOUND )
295 		pCustomShowList->Seek( nPos );
296 }
297 
298 /*************************************************************************
299 |*      Handler: Enabled/Disabled Listbox "Dias"
300 \************************************************************************/
IMPL_LINK(SdStartPresentationDlg,ChangeRangeHdl,void *,EMPTYARG)301 IMPL_LINK( SdStartPresentationDlg, ChangeRangeHdl, void *, EMPTYARG )
302 {
303 	aLbDias.Enable( aRbtAtDia.IsChecked() );
304 	aLbCustomshow.Enable( aRbtCustomshow.IsChecked() );
305 
306 	return( 0L );
307 }
308 
309 /*************************************************************************
310 |*      Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
311 \************************************************************************/
IMPL_LINK(SdStartPresentationDlg,ClickWindowPresentationHdl,void *,EMPTYARG)312 IMPL_LINK( SdStartPresentationDlg, ClickWindowPresentationHdl, void *, EMPTYARG )
313 {
314 	const bool bAuto = aRbtAuto.IsChecked();
315 	const bool bWindow = aRbtWindow.IsChecked();
316 
317 	// aFtPause.Enable( bAuto );
318 	aTmfPause.Enable( bAuto );
319 	aCbxAutoLogo.Enable( bAuto && ( aTmfPause.GetTime().GetMSFromTime() > 0 ) );
320 
321 	const bool bDisplay = !bWindow && ( mnMonitors > 1 );
322 	maFtMonitor.Enable( bDisplay );
323 	maLBMonitor.Enable( bDisplay );
324 
325 	if( bWindow )
326 	{
327 		aCbxAlwaysOnTop.Enable( sal_False );
328 		aCbxAlwaysOnTop.Check( sal_False );
329 	}
330 	else
331 		aCbxAlwaysOnTop.Enable();
332 
333 	return( 0L );
334 }
335 
336 /*************************************************************************
337 |*      Handler: Enabled/Disabled Checkbox "AlwaysOnTop"
338 \************************************************************************/
IMPL_LINK(SdStartPresentationDlg,ChangePauseHdl,void *,EMPTYARG)339 IMPL_LINK( SdStartPresentationDlg, ChangePauseHdl, void *, EMPTYARG )
340 {
341 	aCbxAutoLogo.Enable( aRbtAuto.IsChecked() && ( aTmfPause.GetTime().GetMSFromTime() > 0 ) );
342 	return( 0L );
343 }
344 
345 
346