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