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