Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "optimizerdialog.hxx"
31 : : #include "fileopendialog.hxx"
32 : : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
33 : : #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
34 : : #include <com/sun/star/io/XInputStream.hpp>
35 : : #include <com/sun/star/util/XCloseBroadcaster.hpp>
36 : : #include <com/sun/star/frame/XComponentLoader.hpp>
37 : : #include <com/sun/star/frame/XLayoutManager.hpp>
38 : : #include <sal/macros.h>
39 : : #include <osl/time.h>
40 : :
41 : : // -------------------
42 : : // - OPTIMIZERDIALOG -
43 : : // -------------------
44 : :
45 : : using namespace ::rtl;
46 : : using namespace ::com::sun::star::io;
47 : : using namespace ::com::sun::star::ui;
48 : : using namespace ::com::sun::star::awt;
49 : : using namespace ::com::sun::star::ucb;
50 : : using namespace ::com::sun::star::uno;
51 : : using namespace ::com::sun::star::util;
52 : : using namespace ::com::sun::star::lang;
53 : : using namespace ::com::sun::star::frame;
54 : : using namespace ::com::sun::star::beans;
55 : : using namespace ::com::sun::star::script;
56 : : using namespace ::com::sun::star::container;
57 : :
58 : :
59 : : // -----------------------------------------------------------------------------
60 : :
61 : 0 : void OptimizerDialog::InitDialog()
62 : : {
63 : : // setting the dialog properties
64 : : OUString pNames[] = {
65 : : TKGet( TK_Closeable ),
66 : : TKGet( TK_Height ),
67 : : TKGet( TK_Moveable ),
68 : : TKGet( TK_PositionX ),
69 : : TKGet( TK_PositionY ),
70 : : TKGet( TK_Title ),
71 : 0 : TKGet( TK_Width ) };
72 : :
73 : : Any pValues[] = {
74 : : Any( sal_True ),
75 : : Any( sal_Int32( DIALOG_HEIGHT ) ),
76 : : Any( sal_True ),
77 : : Any( sal_Int32( 200 ) ),
78 : : Any( sal_Int32( 52 ) ),
79 : : Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ),
80 : 0 : Any( sal_Int32( OD_DIALOG_WIDTH ) ) };
81 : :
82 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
83 : :
84 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
85 : 0 : Sequence< Any > aValues( pValues, nCount );
86 : :
87 : 0 : mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
88 : 0 : }
89 : :
90 : : // -----------------------------------------------------------------------------
91 : :
92 : 0 : void OptimizerDialog::InitRoadmap()
93 : : {
94 : : try
95 : : {
96 : : OUString pNames[] = {
97 : : TKGet( TK_Height ),
98 : : TKGet( TK_PositionX ),
99 : : TKGet( TK_PositionY ),
100 : : TKGet( TK_Step ),
101 : : TKGet( TK_TabIndex ),
102 : 0 : TKGet( TK_Width ) };
103 : :
104 : : Any pValues[] = {
105 : : Any( sal_Int32( DIALOG_HEIGHT - 26 ) ),
106 : : Any( sal_Int32( 0 ) ),
107 : : Any( sal_Int32( 0 ) ),
108 : : Any( sal_Int32( 0 ) ),
109 : : Any( mnTabIndex++ ),
110 : 0 : Any( sal_Int32( 85 ) ) };
111 : :
112 : 0 : sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
113 : :
114 : 0 : Sequence< rtl::OUString > aNames( pNames, nCount );
115 : 0 : Sequence< Any > aValues( pValues, nCount );
116 : :
117 : : mxRoadmapControlModel = insertControlModel( OUString( "com.sun.star.awt.UnoControlRoadmapModel" ),
118 : 0 : TKGet( TK_rdmNavi ), aNames, aValues );
119 : :
120 : 0 : Reference< XPropertySet > xPropertySet( mxRoadmapControlModel, UNO_QUERY_THROW );
121 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Name ), Any( TKGet( TK_rdmNavi ) ) );
122 : 0 : mxRoadmapControl = mxDialogControlContainer->getControl( TKGet( TK_rdmNavi ) );
123 : 0 : InsertRoadmapItem( 0, sal_True, getString( STR_INTRODUCTION ), ITEM_ID_INTRODUCTION );
124 : 0 : InsertRoadmapItem( 1, sal_True, getString( STR_SLIDES ), ITEM_ID_SLIDES );
125 : 0 : InsertRoadmapItem( 2, sal_True, getString( STR_IMAGE_OPTIMIZATION ), ITEM_ID_GRAPHIC_OPTIMIZATION );
126 : 0 : InsertRoadmapItem( 3, sal_True, getString( STR_OLE_OBJECTS ), ITEM_ID_OLE_OPTIMIZATION );
127 : 0 : InsertRoadmapItem( 4, sal_True, getString( STR_SUMMARY ), ITEM_ID_SUMMARY );
128 : :
129 : 0 : rtl::OUString sBitmapPath( getPath( TK_BitmapPath ) );
130 : 0 : rtl::OUString sBitmap( "/minimizepresi_80.png" );
131 : 0 : rtl::OUString sURL( sBitmapPath += sBitmap );
132 : :
133 : 0 : xPropertySet->setPropertyValue( TKGet( TK_ImageURL ), Any( sURL ) );
134 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Activated ), Any( (sal_Bool)sal_True ) );
135 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Complete ), Any( (sal_Bool)sal_True ) );
136 : 0 : xPropertySet->setPropertyValue( TKGet( TK_CurrentItemID ), Any( (sal_Int16)ITEM_ID_INTRODUCTION ) );
137 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Text ), Any( getString( STR_STEPS ) ) );
138 : : }
139 : 0 : catch( Exception& )
140 : : {
141 : : }
142 : 0 : }
143 : :
144 : : // -----------------------------------------------------------------------------
145 : :
146 : 0 : void OptimizerDialog::InsertRoadmapItem( const sal_Int32 nIndex, const sal_Bool bEnabled, const rtl::OUString& rLabel, const sal_Int32 nItemID )
147 : : {
148 : : try
149 : : {
150 : 0 : Reference< XSingleServiceFactory > xSFRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
151 : 0 : Reference< XIndexContainer > aIndexContainerRoadmap( mxRoadmapControlModel, UNO_QUERY_THROW );
152 : 0 : Reference< XInterface > xRoadmapItem( xSFRoadmap->createInstance(), UNO_QUERY_THROW );
153 : 0 : Reference< XPropertySet > xPropertySet( xRoadmapItem, UNO_QUERY_THROW );
154 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Label ), Any( rLabel ) );
155 : 0 : xPropertySet->setPropertyValue( TKGet( TK_Enabled ), Any( bEnabled ) );
156 : 0 : xPropertySet->setPropertyValue( TKGet( TK_ID ), Any( nItemID ) );
157 : 0 : aIndexContainerRoadmap->insertByIndex( nIndex, Any( xRoadmapItem ) );
158 : : }
159 : 0 : catch( Exception& )
160 : : {
161 : :
162 : : }
163 : 0 : }
164 : :
165 : : // -----------------------------------------------------------------------------
166 : :
167 : 0 : void OptimizerDialog::UpdateConfiguration()
168 : : {
169 : 0 : sal_Int16 nInt16 = 0;
170 : 0 : OUString aString;
171 : 0 : Any aAny;
172 : :
173 : 0 : Sequence< sal_Int16 > aSelectedItems;
174 : 0 : Sequence< OUString > aStringItemList;
175 : :
176 : : // page0
177 : 0 : aAny = getControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_SelectedItems ) );
178 : 0 : if ( aAny >>= aSelectedItems )
179 : : {
180 : 0 : if ( aSelectedItems.getLength() )
181 : : {
182 : 0 : sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
183 : 0 : aAny = getControlProperty( TKGet( TK_ListBox0Pg0 ), TKGet( TK_StringItemList ) );
184 : 0 : if ( aAny >>= aStringItemList )
185 : : {
186 : 0 : if ( aStringItemList.getLength() > nSelectedItem )
187 : 0 : SetConfigProperty( TK_Name, Any( aStringItemList[ nSelectedItem ] ) );
188 : : }
189 : : }
190 : : }
191 : :
192 : 0 : aAny = getControlProperty( TKGet( TK_CheckBox3Pg3 ), TKGet( TK_State ) );
193 : 0 : if ( aAny >>= nInt16 )
194 : : {
195 : 0 : if ( nInt16 )
196 : : {
197 : 0 : aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_SelectedItems ) );
198 : 0 : if ( aAny >>= aSelectedItems )
199 : : {
200 : 0 : if ( aSelectedItems.getLength() )
201 : : {
202 : 0 : sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
203 : 0 : aAny = getControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_StringItemList ) );
204 : 0 : if ( aAny >>= aStringItemList )
205 : : {
206 : 0 : if ( aStringItemList.getLength() > nSelectedItem )
207 : 0 : SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
208 : : }
209 : : }
210 : : }
211 : : }
212 : 0 : }
213 : 0 : }
214 : :
215 : : // -----------------------------------------------------------------------------
216 : :
217 : 0 : OptimizerDialog::OptimizerDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame, Reference< XDispatch > rxStatusDispatcher ) :
218 : : UnoDialog( rxMSF, rxFrame ),
219 : : ConfigurationAccess( rxMSF, NULL ),
220 : : mnCurrentStep( 0 ),
221 : : mnTabIndex( 0 ),
222 : : mxMSF( rxMSF ),
223 : : mxFrame( rxFrame ),
224 : 0 : mxItemListener( new ItemListener( *this ) ),
225 : 0 : mxActionListener( new ActionListener( *this ) ),
226 : 0 : mxActionListenerListBox0Pg0( new ActionListenerListBox0Pg0( *this ) ),
227 : 0 : mxTextListenerFormattedField0Pg1( new TextListenerFormattedField0Pg1( *this ) ),
228 : 0 : mxTextListenerComboBox0Pg1( new TextListenerComboBox0Pg1( *this ) ),
229 : 0 : mxSpinListenerFormattedField0Pg1( new SpinListenerFormattedField0Pg1( *this ) ),
230 : 0 : mxStatusDispatcher( rxStatusDispatcher )
231 : : {
232 : 0 : Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY_THROW );
233 : 0 : mbIsReadonly = xStorable->isReadonly();
234 : :
235 : 0 : InitDialog();
236 : 0 : InitRoadmap();
237 : 0 : InitNavigationBar();
238 : 0 : InitPage0();
239 : 0 : InitPage1();
240 : 0 : InitPage2();
241 : 0 : InitPage3();
242 : 0 : InitPage4();
243 : 0 : ActivatePage( 0 );
244 : :
245 : 0 : OptimizationStats aStats;
246 : 0 : aStats.InitializeStatusValuesFromDocument( mxController->getModel() );
247 : 0 : Sequence< PropertyValue > aStatusSequence( aStats.GetStatusSequence() );
248 : 0 : UpdateStatus( aStatusSequence );
249 : 0 : }
250 : :
251 : : // -----------------------------------------------------------------------------
252 : :
253 : 0 : OptimizerDialog::~OptimizerDialog()
254 : : {
255 : : // not saving configuration if the dialog has been finished via cancel or close window
256 : 0 : if ( mbStatus )
257 : 0 : SaveConfiguration();
258 : 0 : }
259 : :
260 : : // -----------------------------------------------------------------------------
261 : :
262 : 0 : sal_Bool OptimizerDialog::execute()
263 : : {
264 : 0 : Reference< XItemEventBroadcaster > maRoadmapBroadcaster( mxRoadmapControl, UNO_QUERY_THROW );
265 : 0 : maRoadmapBroadcaster->addItemListener( mxItemListener );
266 : 0 : UnoDialog::execute();
267 : 0 : UpdateConfiguration(); // taking actual control settings for the configuration
268 : 0 : maRoadmapBroadcaster->removeItemListener( mxItemListener );
269 : 0 : return mbStatus;
270 : : }
271 : :
272 : : // -----------------------------------------------------------------------------
273 : :
274 : 0 : void OptimizerDialog::SwitchPage( sal_Int16 nNewStep )
275 : : {
276 : 0 : if ( ( nNewStep != mnCurrentStep ) && ( nNewStep <= MAX_STEP ) && ( nNewStep >= 0 ) )
277 : : {
278 : 0 : sal_Int16 nOldStep = mnCurrentStep;
279 : 0 : if ( nNewStep == 0 )
280 : 0 : disableControl( TKGet( TK_btnNavBack ) );
281 : 0 : else if ( nOldStep == 0 )
282 : 0 : enableControl( TKGet( TK_btnNavBack ) );
283 : :
284 : 0 : if ( nNewStep == MAX_STEP )
285 : 0 : disableControl( TKGet( TK_btnNavNext ) );
286 : 0 : else if ( nOldStep == MAX_STEP )
287 : 0 : enableControl( TKGet( TK_btnNavNext ) );
288 : :
289 : 0 : setControlProperty( TKGet( TK_rdmNavi ), TKGet( TK_CurrentItemID ), Any( nNewStep ) );
290 : :
291 : 0 : DeactivatePage( nOldStep );
292 : 0 : UpdateControlStates( nNewStep );
293 : :
294 : 0 : ActivatePage( nNewStep );
295 : 0 : mnCurrentStep = nNewStep;
296 : : }
297 : 0 : }
298 : :
299 : 0 : void OptimizerDialog::UpdateControlStates( sal_Int16 nPage )
300 : : {
301 : 0 : switch( nPage )
302 : : {
303 : 0 : case 0 : UpdateControlStatesPage0(); break;
304 : 0 : case 1 : UpdateControlStatesPage1(); break;
305 : 0 : case 2 : UpdateControlStatesPage2(); break;
306 : 0 : case 3 : UpdateControlStatesPage3(); break;
307 : 0 : case 4 : UpdateControlStatesPage4(); break;
308 : : default:
309 : : {
310 : 0 : UpdateControlStatesPage0();
311 : 0 : UpdateControlStatesPage1();
312 : 0 : UpdateControlStatesPage2();
313 : 0 : UpdateControlStatesPage3();
314 : 0 : UpdateControlStatesPage4();
315 : : }
316 : : }
317 : 0 : }
318 : :
319 : : // -----------------------------------------------------------------------------
320 : :
321 : 0 : rtl::OUString OptimizerDialog::GetSelectedString( const PPPOptimizerTokenEnum eToken )
322 : : {
323 : 0 : OUString aSelectedItem;
324 : 0 : Sequence< sal_Int16 > sSelectedItems;
325 : 0 : Sequence< OUString > sItemList;
326 : :
327 : 0 : if ( ( getControlProperty( TKGet( eToken ), TKGet( TK_SelectedItems ) ) >>= sSelectedItems ) &&
328 : 0 : ( getControlProperty( TKGet( eToken ), TKGet( TK_StringItemList ) ) >>= sItemList ) )
329 : : {
330 : 0 : if ( sSelectedItems.getLength() == 1 )
331 : : {
332 : 0 : sal_Int16 nSelectedItem = sSelectedItems[ 0 ];
333 : 0 : if ( nSelectedItem < sItemList.getLength() )
334 : 0 : aSelectedItem = sItemList[ nSelectedItem ];
335 : : }
336 : : }
337 : 0 : return aSelectedItem;
338 : : }
339 : :
340 : : // -----------------------------------------------------------------------------
341 : :
342 : 0 : void OptimizerDialog::UpdateStatus( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rStatus )
343 : : {
344 : 0 : if ( mxReschedule.is() )
345 : : {
346 : 0 : maStats.InitializeStatusValues( rStatus );
347 : 0 : const Any* pVal( maStats.GetStatusValue( TK_Status ) );
348 : 0 : if ( pVal )
349 : : {
350 : 0 : rtl::OUString sStatus;
351 : 0 : if ( *pVal >>= sStatus )
352 : : {
353 : 0 : setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) );
354 : 0 : setControlProperty( TKGet( TK_FixedText1Pg4 ), TKGet( TK_Label ), Any( getString( TKGet( sStatus ) ) ) );
355 : 0 : }
356 : : }
357 : 0 : pVal = maStats.GetStatusValue( TK_Progress );
358 : 0 : if ( pVal )
359 : : {
360 : 0 : sal_Int32 nProgress = 0;
361 : 0 : if ( *pVal >>= nProgress )
362 : 0 : setControlProperty( TKGet( TK_Progress ), TKGet( TK_ProgressValue ), Any( nProgress ) );
363 : : }
364 : 0 : pVal = maStats.GetStatusValue( TK_OpenNewDocument );
365 : 0 : if ( pVal )
366 : 0 : SetConfigProperty( TK_OpenNewDocument, *pVal );
367 : :
368 : 0 : mxReschedule->reschedule();
369 : : }
370 : 0 : }
371 : :
372 : : // -----------------------------------------------------------------------------
373 : :
374 : 0 : void ItemListener::itemStateChanged( const ItemEvent& Event )
375 : : throw ( RuntimeException )
376 : : {
377 : : try
378 : : {
379 : : sal_Int16 nState;
380 : 0 : OUString aControlName;
381 : 0 : Reference< XControl > xControl;
382 : 0 : Any aSource( Event.Source );
383 : 0 : if ( aSource >>= xControl )
384 : : {
385 : 0 : Reference< XPropertySet > xPropertySet( xControl->getModel(), UNO_QUERY_THROW );
386 : 0 : xPropertySet->getPropertyValue( TKGet( TK_Name ) ) >>= aControlName;
387 : 0 : PPPOptimizerTokenEnum eControl( TKGet( aControlName ) );
388 : 0 : switch( eControl )
389 : : {
390 : : case TK_rdmNavi :
391 : : {
392 : 0 : mrOptimizerDialog.SwitchPage( static_cast< sal_Int16 >( Event.ItemId ) );
393 : : }
394 : 0 : break;
395 : : case TK_CheckBox1Pg1 :
396 : : {
397 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
398 : 0 : mrOptimizerDialog.SetConfigProperty( TK_RemoveCropArea, Any( nState != 0 ) );
399 : : }
400 : 0 : break;
401 : : case TK_CheckBox2Pg1 :
402 : : {
403 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
404 : 0 : mrOptimizerDialog.SetConfigProperty( TK_EmbedLinkedGraphics, Any( nState != 0 ) );
405 : : }
406 : 0 : break;
407 : : case TK_CheckBox0Pg2 :
408 : : {
409 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
410 : : {
411 : 0 : mrOptimizerDialog.SetConfigProperty( TK_OLEOptimization, Any( nState != 0 ) );
412 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_RadioButton0Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
413 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_RadioButton1Pg2 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
414 : : }
415 : : }
416 : 0 : break;
417 : : case TK_RadioButton0Pg1 :
418 : : {
419 : 0 : sal_Int16 nInt16 = 0;
420 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 )
421 : : {
422 : 0 : nInt16 ^= 1;
423 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nInt16 != 0 ) );
424 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) );
425 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nInt16 != 0 ) );
426 : : }
427 : : }
428 : 0 : break;
429 : : case TK_RadioButton1Pg1 :
430 : : {
431 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
432 : : {
433 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGCompression, Any( nState != 0 ) );
434 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText1Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
435 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
436 : : }
437 : : }
438 : 0 : break;
439 : : case TK_RadioButton0Pg2 :
440 : : {
441 : : sal_Int16 nInt16;
442 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nInt16 )
443 : : {
444 : 0 : nInt16 ^= 1;
445 : 0 : mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nInt16 ) );
446 : : }
447 : : }
448 : 0 : break;
449 : : case TK_RadioButton1Pg2 :
450 : : {
451 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
452 : 0 : mrOptimizerDialog.SetConfigProperty( TK_OLEOptimizationType, Any( nState ) );
453 : : }
454 : 0 : break;
455 : : case TK_CheckBox0Pg3 :
456 : : {
457 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
458 : 0 : mrOptimizerDialog.SetConfigProperty( TK_DeleteUnusedMasterPages, Any( nState != 0 ) );
459 : : }
460 : 0 : break;
461 : : case TK_CheckBox1Pg3 :
462 : : {
463 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
464 : 0 : mrOptimizerDialog.SetConfigProperty( TK_DeleteNotesPages, Any( nState != 0 ) );
465 : : }
466 : 0 : break;
467 : : case TK_CheckBox2Pg3 :
468 : : {
469 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
470 : 0 : mrOptimizerDialog.SetConfigProperty( TK_DeleteHiddenSlides, Any( nState != 0 ) );
471 : : }
472 : 0 : break;
473 : : case TK_CheckBox3Pg3 :
474 : : {
475 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
476 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_ListBox0Pg3 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
477 : : }
478 : 0 : break;
479 : : case TK_CheckBox1Pg4 :
480 : : {
481 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
482 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Enabled ), Any( nState != 0 ) );
483 : : }
484 : 0 : break;
485 : : case TK_RadioButton0Pg4 :
486 : : case TK_RadioButton1Pg4 :
487 : : {
488 : 0 : if ( xPropertySet->getPropertyValue( TKGet( TK_State ) ) >>= nState )
489 : 0 : mrOptimizerDialog.SetConfigProperty( TK_SaveAs, Any( eControl == TK_RadioButton1Pg4 ? nState != 0 : nState == 0 ) );
490 : : }
491 : 0 : break;
492 : : default:
493 : 0 : break;
494 : 0 : }
495 : 0 : }
496 : : }
497 : 0 : catch ( Exception& )
498 : : {
499 : :
500 : : }
501 : 0 : }
502 : 0 : void ItemListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
503 : : throw ( com::sun::star::uno::RuntimeException )
504 : : {
505 : 0 : }
506 : :
507 : : // -----------------------------------------------------------------------------
508 : :
509 : 0 : void ActionListener::actionPerformed( const ActionEvent& rEvent )
510 : : throw ( com::sun::star::uno::RuntimeException )
511 : : {
512 : 0 : switch( TKGet( rEvent.ActionCommand ) )
513 : : {
514 : 0 : case TK_btnNavBack : mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep - 1 ); break;
515 : 0 : case TK_btnNavNext : mrOptimizerDialog.SwitchPage( mrOptimizerDialog.mnCurrentStep + 1 ); break;
516 : : case TK_btnNavFinish :
517 : : {
518 : 0 : mrOptimizerDialog.UpdateConfiguration();
519 : :
520 : 0 : mrOptimizerDialog.SwitchPage( ITEM_ID_SUMMARY );
521 : 0 : mrOptimizerDialog.DisablePage( ITEM_ID_SUMMARY );
522 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_False ) );
523 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) );
524 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_False ) );
525 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_False ) );
526 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FixedText0Pg4 ), TKGet( TK_Enabled ), Any( sal_True ) );
527 : :
528 : : // check if we have to open the FileDialog
529 : 0 : sal_Bool bSuccessfullyExecuted = sal_True;
530 : 0 : sal_Int16 nInt16 = 0;
531 : 0 : mrOptimizerDialog.getControlProperty( TKGet( TK_RadioButton1Pg4 ), TKGet( TK_State ) ) >>= nInt16;
532 : 0 : if ( nInt16 )
533 : : {
534 : 0 : rtl::OUString aSaveAsURL;
535 : 0 : FileOpenDialog aFileOpenDialog( ((UnoDialog&)mrOptimizerDialog).mxMSF );
536 : :
537 : : // generating default file name
538 : 0 : Reference< XStorable > xStorable( mrOptimizerDialog.mxController->getModel(), UNO_QUERY );
539 : 0 : if ( xStorable.is() && xStorable->hasLocation() )
540 : : {
541 : 0 : rtl::OUString aLocation( xStorable->getLocation() );
542 : 0 : if ( !aLocation.isEmpty() )
543 : : {
544 : 0 : sal_Int32 nIndex = aLocation.lastIndexOf( '/', aLocation.getLength() - 1 );
545 : 0 : if ( nIndex >= 0 )
546 : : {
547 : 0 : if ( nIndex < aLocation.getLength() - 1 )
548 : 0 : aLocation = aLocation.copy( nIndex + 1 );
549 : :
550 : : // remove extension
551 : 0 : nIndex = aLocation.lastIndexOf( '.', aLocation.getLength() - 1 );
552 : 0 : if ( nIndex >= 0 )
553 : 0 : aLocation = aLocation.copy( 0, nIndex );
554 : :
555 : : // adding .mini
556 : 0 : aLocation = aLocation.concat( OUString(".mini") );
557 : 0 : aFileOpenDialog.setDefaultName( aLocation );
558 : : }
559 : 0 : }
560 : : }
561 : 0 : sal_Bool bDialogExecuted = aFileOpenDialog.execute() == dialogs::ExecutableDialogResults::OK;
562 : 0 : if ( bDialogExecuted )
563 : : {
564 : 0 : aSaveAsURL = aFileOpenDialog.getURL();
565 : 0 : mrOptimizerDialog.SetConfigProperty( TK_SaveAsURL, Any( aSaveAsURL ) );
566 : 0 : mrOptimizerDialog.SetConfigProperty( TK_FilterName, Any( aFileOpenDialog.getFilterName() ) );
567 : : }
568 : 0 : if ( aSaveAsURL.isEmpty() )
569 : : {
570 : : // something goes wrong...
571 : 0 : bSuccessfullyExecuted = sal_False;
572 : : }
573 : :
574 : : // waiting for 500ms
575 : 0 : if ( mrOptimizerDialog.mxReschedule.is() )
576 : : {
577 : 0 : mrOptimizerDialog.mxReschedule->reschedule();
578 : 0 : for ( sal_uInt32 i = osl_getGlobalTimer(); ( i + 500 ) > ( osl_getGlobalTimer() ); )
579 : 0 : mrOptimizerDialog.mxReschedule->reschedule();
580 : 0 : }
581 : : }
582 : 0 : if ( bSuccessfullyExecuted )
583 : : { // now check if we have to store a session template
584 : 0 : nInt16 = 0;
585 : 0 : OUString aSettingsName;
586 : 0 : mrOptimizerDialog.getControlProperty( TKGet( TK_CheckBox1Pg4 ), TKGet( TK_State ) ) >>= nInt16;
587 : 0 : mrOptimizerDialog.getControlProperty( TKGet( TK_ComboBox0Pg4 ), TKGet( TK_Text ) ) >>= aSettingsName;
588 : 0 : if ( nInt16 && !aSettingsName.isEmpty() )
589 : : {
590 : 0 : std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSettingsName ) );
591 : 0 : std::vector< OptimizerSettings >& rSettings( mrOptimizerDialog.GetOptimizerSettings() );
592 : 0 : OptimizerSettings aNewSettings( rSettings[ 0 ] );
593 : 0 : aNewSettings.maName = aSettingsName;
594 : 0 : if ( aIter == rSettings.end() )
595 : 0 : rSettings.push_back( aNewSettings );
596 : : else
597 : 0 : *aIter = aNewSettings;
598 : 0 : }
599 : : }
600 : 0 : if ( bSuccessfullyExecuted )
601 : : {
602 : 0 : Sequence< Any > aArgs( 1 );
603 : 0 : aArgs[ 0 ] <<= mrOptimizerDialog.GetFrame();
604 : :
605 : 0 : Reference < XDispatch > xDispatch( mrOptimizerDialog.GetComponentContext()->getServiceManager()->createInstanceWithArgumentsAndContext(
606 : 0 : OUString("com.sun.star.comp.PPPOptimizer"), aArgs, mrOptimizerDialog.GetComponentContext() ), UNO_QUERY );
607 : :
608 : 0 : URL aURL;
609 : 0 : aURL.Protocol = OUString( "vnd.com.sun.star.comp.PPPOptimizer:" );
610 : 0 : aURL.Path = OUString( "optimize" );
611 : :
612 : 0 : Sequence< PropertyValue > lArguments( 3 );
613 : 0 : lArguments[ 0 ].Name = TKGet( TK_Settings );
614 : 0 : lArguments[ 0 ].Value <<= mrOptimizerDialog.GetConfigurationSequence();
615 : 0 : lArguments[ 1 ].Name = TKGet( TK_StatusDispatcher );
616 : 0 : lArguments[ 1 ].Value <<= mrOptimizerDialog.GetStatusDispatcher();
617 : 0 : lArguments[ 2 ].Name = TKGet( TK_InformationDialog );
618 : 0 : lArguments[ 2 ].Value <<= mrOptimizerDialog.GetFrame();
619 : :
620 : 0 : if( xDispatch.is() )
621 : 0 : xDispatch->dispatch( aURL, lArguments );
622 : :
623 : 0 : mrOptimizerDialog.endExecute( bSuccessfullyExecuted );
624 : : }
625 : : else
626 : : {
627 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavBack ), TKGet( TK_Enabled ), Any( sal_True ) );
628 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavNext ), TKGet( TK_Enabled ), Any( sal_False ) );
629 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavFinish ), TKGet( TK_Enabled ), Any( sal_True ) );
630 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_btnNavCancel ), TKGet( TK_Enabled ), Any( sal_True ) );
631 : 0 : mrOptimizerDialog.EnablePage( ITEM_ID_SUMMARY );
632 : : }
633 : : }
634 : 0 : break;
635 : 0 : case TK_btnNavCancel : mrOptimizerDialog.endExecute( sal_False ); break;
636 : : case TK_Button0Pg0 : // delete configuration
637 : : {
638 : 0 : OUString aSelectedItem( mrOptimizerDialog.GetSelectedString( TK_ListBox0Pg0 ) );
639 : 0 : if ( !aSelectedItem.isEmpty() )
640 : : {
641 : 0 : std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( aSelectedItem ) );
642 : 0 : std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
643 : 0 : if ( aIter != rList.end() )
644 : : {
645 : 0 : rList.erase( aIter );
646 : 0 : mrOptimizerDialog.UpdateControlStates();
647 : : }
648 : 0 : }
649 : : }
650 : 0 : break;
651 : 0 : default: break;
652 : : }
653 : 0 : }
654 : 0 : void ActionListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
655 : : throw ( com::sun::star::uno::RuntimeException )
656 : : {
657 : 0 : }
658 : :
659 : : // -----------------------------------------------------------------------------
660 : :
661 : 0 : void ActionListenerListBox0Pg0::actionPerformed( const ActionEvent& rEvent )
662 : : throw ( com::sun::star::uno::RuntimeException )
663 : : {
664 : 0 : if ( !rEvent.ActionCommand.isEmpty() )
665 : : {
666 : 0 : std::vector< OptimizerSettings >::iterator aIter( mrOptimizerDialog.GetOptimizerSettingsByName( rEvent.ActionCommand ) );
667 : 0 : std::vector< OptimizerSettings >& rList( mrOptimizerDialog.GetOptimizerSettings() );
668 : 0 : if ( aIter != rList.end() )
669 : 0 : rList[ 0 ] = *aIter;
670 : : }
671 : 0 : mrOptimizerDialog.UpdateControlStates();
672 : 0 : }
673 : 0 : void ActionListenerListBox0Pg0::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
674 : : throw ( com::sun::star::uno::RuntimeException )
675 : : {
676 : 0 : }
677 : :
678 : : // -----------------------------------------------------------------------------
679 : :
680 : 0 : void TextListenerFormattedField0Pg1::textChanged( const TextEvent& /* rEvent */ )
681 : : throw ( com::sun::star::uno::RuntimeException )
682 : : {
683 : 0 : double fDouble = 0;
684 : 0 : Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
685 : 0 : if ( aAny >>= fDouble )
686 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
687 : 0 : }
688 : 0 : void TextListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
689 : : throw ( com::sun::star::uno::RuntimeException )
690 : : {
691 : 0 : }
692 : :
693 : : // -----------------------------------------------------------------------------
694 : :
695 : 0 : void TextListenerComboBox0Pg1::textChanged( const TextEvent& /* rEvent */ )
696 : : throw ( com::sun::star::uno::RuntimeException )
697 : : {
698 : 0 : rtl::OUString aString;
699 : 0 : Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_ComboBox0Pg1 ), TKGet( TK_Text ) );
700 : 0 : if ( aAny >>= aString )
701 : : {
702 : : sal_Int32 nI0, nI1, nI2, nI3, nI4;
703 : 0 : nI0 = nI1 = nI2 = nI3 = nI4 = 0;
704 : :
705 : 0 : if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';', nI0 ) == aString )
706 : 0 : aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_0 ).getToken( 0, ';', nI4 );
707 : 0 : else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';', nI1 ) == aString )
708 : 0 : aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_1 ).getToken( 0, ';', nI4 );
709 : 0 : else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';', nI2 ) == aString )
710 : 0 : aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_2 ).getToken( 0, ';', nI4 );
711 : 0 : else if ( mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';', nI3 ) == aString )
712 : 0 : aString = mrOptimizerDialog.getString( STR_IMAGE_RESOLUTION_3 ).getToken( 0, ';', nI4 );
713 : :
714 : 0 : mrOptimizerDialog.SetConfigProperty( TK_ImageResolution, Any( aString.toInt32() ) );
715 : 0 : }
716 : 0 : }
717 : 0 : void TextListenerComboBox0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
718 : : throw ( com::sun::star::uno::RuntimeException )
719 : : {
720 : 0 : }
721 : :
722 : : // -----------------------------------------------------------------------------
723 : :
724 : 0 : void SpinListenerFormattedField0Pg1::up( const SpinEvent& /* rEvent */ )
725 : : throw ( com::sun::star::uno::RuntimeException )
726 : : {
727 : : double fDouble;
728 : 0 : Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
729 : 0 : if ( aAny >>= fDouble )
730 : : {
731 : 0 : fDouble += 9;
732 : 0 : if ( fDouble > 100 )
733 : 0 : fDouble = 100;
734 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) );
735 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
736 : 0 : }
737 : 0 : }
738 : 0 : void SpinListenerFormattedField0Pg1::down( const SpinEvent& /* rEvent */ )
739 : : throw ( com::sun::star::uno::RuntimeException )
740 : : {
741 : : double fDouble;
742 : 0 : Any aAny = mrOptimizerDialog.getControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ) );
743 : 0 : if ( aAny >>= fDouble )
744 : : {
745 : 0 : fDouble -= 9;
746 : 0 : if ( fDouble < 0 )
747 : 0 : fDouble = 0;
748 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( fDouble ) );
749 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)fDouble ) );
750 : 0 : }
751 : 0 : }
752 : 0 : void SpinListenerFormattedField0Pg1::first( const SpinEvent& /* rEvent */ )
753 : : throw ( com::sun::star::uno::RuntimeException )
754 : : {
755 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 0 ) ) );
756 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)0 ) );
757 : 0 : }
758 : 0 : void SpinListenerFormattedField0Pg1::last( const SpinEvent& /* rEvent */ )
759 : : throw ( com::sun::star::uno::RuntimeException )
760 : : {
761 : 0 : mrOptimizerDialog.setControlProperty( TKGet( TK_FormattedField0Pg1 ), TKGet( TK_EffectiveValue ), Any( static_cast< double >( 100 ) ) );
762 : 0 : mrOptimizerDialog.SetConfigProperty( TK_JPEGQuality, Any( (sal_Int32)100 ) );
763 : 0 : }
764 : 0 : void SpinListenerFormattedField0Pg1::disposing( const ::com::sun::star::lang::EventObject& /* Source */ )
765 : : throw ( com::sun::star::uno::RuntimeException )
766 : : {
767 : 0 : }
768 : :
769 : : // -----------------------------------------------------------------------------
770 : :
771 : 0 : void HelpCloseListener::addCloseListener( const Reference < XCloseListener >& ) throw( RuntimeException )
772 : : {
773 : 0 : }
774 : 0 : void HelpCloseListener::removeCloseListener( const Reference < XCloseListener >& ) throw( RuntimeException )
775 : : {
776 : 0 : }
777 : 0 : void HelpCloseListener::queryClosing( const EventObject&, sal_Bool /* bDeliverOwnership */ )
778 : : throw ( RuntimeException, CloseVetoException )
779 : : {
780 : 0 : }
781 : 0 : void HelpCloseListener::notifyClosing( const EventObject& )
782 : : throw ( RuntimeException )
783 : : {
784 : 0 : }
785 : 0 : void HelpCloseListener::disposing( const EventObject& ) throw ( RuntimeException )
786 : : {
787 : 0 : mrXFrame = NULL;
788 : 0 : }
789 : :
790 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|