1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "optimizerdialog.hxx"
24 #include "pppoptimizer.hxx"
25 #include "graphiccollector.hxx"
26 #include "pagecollector.hxx"
27 #include <com/sun/star/awt/PushButtonType.hpp>
28 #include <com/sun/star/awt/XSpinField.hpp>
29 #include <com/sun/star/awt/XTextComponent.hpp>
30 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
31 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
32 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
33 #include <com/sun/star/awt/FontDescriptor.hpp>
34 #include <com/sun/star/awt/FontWeight.hpp>
35 #include <com/sun/star/frame/XStorable.hpp>
36 #include <rtl/ustrbuf.hxx>
37 #include <sal/macros.h>
39 using namespace ::com::sun::star::awt
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::util
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::frame
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::drawing
;
46 using namespace ::com::sun::star::container
;
47 using namespace ::com::sun::star::presentation
;
50 static void SetBold( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControl
)
52 FontDescriptor aFontDescriptor
;
53 if ( rOptimizerDialog
.getControlProperty( rControl
, "FontDescriptor" ) >>= aFontDescriptor
)
55 aFontDescriptor
.Weight
= com::sun::star::awt::FontWeight::BOLD
;
56 rOptimizerDialog
.setControlProperty( rControl
, "FontDescriptor", Any( aFontDescriptor
) );
61 static OUString
InsertSeparator( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
, sal_Int32 nOrientation
,
62 sal_Int32 nPosX
, sal_Int32 nPosY
, sal_Int32 nWidth
, sal_Int32 nHeight
)
66 OUString("Orientation"),
67 OUString("PositionX"),
68 OUString("PositionY"),
77 Any( sal_Int16( 0 ) ),
80 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
82 Sequence
< OUString
> aNames( pNames
, nCount
);
83 Sequence
< Any
> aValues( pValues
, nCount
);
85 rOptimizerDialog
.insertControlModel( "com.sun.star.awt.UnoControlFixedLineModel",
86 rControlName
, aNames
, aValues
);
91 static OUString
InsertButton( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
, Reference
< XActionListener
> const & xActionListener
,
92 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int16 nTabIndex
, bool bEnabled
, PPPOptimizerTokenEnum nResID
, css::awt::PushButtonType nPushButtonType
)
94 sal_Int32 nHeight
= BUTTON_HEIGHT
;
99 OUString("PositionX"),
100 OUString("PositionY"),
101 OUString("PushButtonType"),
103 OUString("TabIndex"),
109 Any( rOptimizerDialog
.getString( nResID
) ),
112 Any( static_cast< sal_Int16
>(nPushButtonType
) ),
118 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
120 Sequence
< OUString
> aNames( pNames
, nCount
);
121 Sequence
< Any
> aValues( pValues
, nCount
);
123 rOptimizerDialog
.insertButton( rControlName
, xActionListener
, aNames
, aValues
);
128 static OUString
InsertFixedText( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
, const OUString
& rLabel
,
129 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, bool bMultiLine
, bool bBold
, sal_Int16 nTabIndex
)
131 OUString pNames
[] = {
134 OUString("MultiLine"),
135 OUString("PositionX"),
136 OUString("PositionY"),
138 OUString("TabIndex"),
151 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
153 Sequence
< OUString
> aNames( pNames
, nCount
);
154 Sequence
< Any
> aValues( pValues
, nCount
);
156 rOptimizerDialog
.insertFixedText( rControlName
, aNames
, aValues
);
158 SetBold( rOptimizerDialog
, rControlName
);
163 static OUString
InsertCheckBox( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
,
164 const Reference
< XItemListener
>& xItemListener
, const OUString
& rLabel
,
165 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int16 nTabIndex
)
167 sal_Int32 nHeight
= 8;
168 OUString pNames
[] = {
172 OUString("PositionX"),
173 OUString("PositionY"),
175 OUString("TabIndex"),
188 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
190 Sequence
< OUString
> aNames( pNames
, nCount
);
191 Sequence
< Any
> aValues( pValues
, nCount
);
193 Reference
< XCheckBox
> xCheckBox( rOptimizerDialog
.insertCheckBox( rControlName
, aNames
, aValues
) );
194 if ( xItemListener
.is() )
195 xCheckBox
->addItemListener( xItemListener
);
200 static OUString
InsertFormattedField( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
,
201 const Reference
< XTextListener
>& xTextListener
, const Reference
< XSpinListener
>& xSpinListener
, sal_Int32 nXPos
, sal_Int32 nYPos
,
202 double fEffectiveMin
, double fEffectiveMax
, sal_Int16 nTabIndex
)
204 sal_Int32 nWidth
= 50;
205 OUString pNames
[] = {
206 OUString("EffectiveMax"),
207 OUString("EffectiveMin"),
210 OUString("PositionX"),
211 OUString("PositionY"),
215 OUString("TabIndex"),
219 Any( fEffectiveMax
),
220 Any( fEffectiveMin
),
222 Any( sal_Int32(12) ),
231 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
233 Sequence
< OUString
> aNames( pNames
, nCount
);
234 Sequence
< Any
> aValues( pValues
, nCount
);
236 Reference
< XTextComponent
> xTextComponent( rOptimizerDialog
.insertFormattedField( rControlName
, aNames
, aValues
), UNO_QUERY_THROW
);
237 if ( xTextListener
.is() )
238 xTextComponent
->addTextListener( xTextListener
);
239 if ( xSpinListener
.is() )
241 Reference
< XSpinField
> xSpinField( xTextComponent
, UNO_QUERY_THROW
);
242 xSpinField
->addSpinListener( xSpinListener
);
248 static OUString
InsertComboBox( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
,
249 const Reference
< XTextListener
>& rTextListener
, const bool bEnabled
, const Sequence
< OUString
>& rItemList
,
250 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int16 nTabIndex
)
252 sal_Int32 nHeight
= 12;
253 sal_Int32 nWidth
= 100;
254 OUString pNames
[] = {
255 OUString("Dropdown"),
258 OUString("LineCount"),
259 OUString("PositionX"),
260 OUString("PositionY"),
262 OUString("StringItemList"),
263 OUString("TabIndex"),
278 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
280 Sequence
< OUString
> aNames( pNames
, nCount
);
281 Sequence
< Any
> aValues( pValues
, nCount
);
283 Reference
< XTextComponent
> xTextComponent( rOptimizerDialog
.insertComboBox( rControlName
, aNames
, aValues
), UNO_QUERY_THROW
);
284 if ( rTextListener
.is() )
285 xTextComponent
->addTextListener( rTextListener
);
290 static OUString
InsertRadioButton( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
, const Reference
< XItemListener
>& rItemListener
,
291 const OUString
& rLabel
, sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int16 nTabIndex
)
293 sal_Int32 nHeight
= 8;
294 OUString pNames
[] = {
297 OUString("MultiLine"),
298 OUString("PositionX"),
299 OUString("PositionY"),
301 OUString("TabIndex"),
307 Any( false ), // bMultiLine
314 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
316 Sequence
< OUString
> aNames( pNames
, nCount
);
317 Sequence
< Any
> aValues( pValues
, nCount
);
319 Reference
< XRadioButton
> xRadioButton( rOptimizerDialog
.insertRadioButton( rControlName
, aNames
, aValues
) );
320 if ( rItemListener
.is() )
321 xRadioButton
->addItemListener( rItemListener
);
326 static OUString
InsertListBox( OptimizerDialog
& rOptimizerDialog
, const OUString
& rControlName
,
327 const Reference
< XActionListener
>& rActionListener
, const bool bEnabled
, const Sequence
< OUString
>& rItemList
,
328 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int16 nTabIndex
)
330 sal_Int32 nHeight
= 12;
331 OUString pNames
[] = {
332 OUString("Dropdown"),
335 OUString("LineCount"),
336 OUString("MultiSelection"),
337 OUString("PositionX"),
338 OUString("PositionY"),
340 OUString("StringItemList"),
341 OUString("TabIndex"),
357 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
359 Sequence
< OUString
> aNames( pNames
, nCount
);
360 Sequence
< Any
> aValues( pValues
, nCount
);
362 Reference
< XListBox
> xListBox( rOptimizerDialog
.insertListBox( rControlName
, aNames
, aValues
) );
364 xListBox
->addActionListener( rActionListener
);
369 void OptimizerDialog::InitNavigationBar()
371 sal_Int32 nCancelPosX
= OD_DIALOG_WIDTH
- BUTTON_WIDTH
- 6;
372 sal_Int32 nFinishPosX
= nCancelPosX
- 6 - BUTTON_WIDTH
;
373 sal_Int32 nNextPosX
= nFinishPosX
- 6 - BUTTON_WIDTH
;
374 sal_Int32 nBackPosX
= nNextPosX
- 3 - BUTTON_WIDTH
;
376 InsertSeparator( *this, "lnNavSep1", 0, 0, DIALOG_HEIGHT
- 26, OD_DIALOG_WIDTH
, 1 );
377 InsertSeparator( *this, "lnNavSep2", 1, 85, 0, 1, BUTTON_POS_Y
- 6 );
379 InsertButton( *this, "btnNavBack", mxActionListener
, nBackPosX
, BUTTON_POS_Y
, BUTTON_WIDTH
, mnTabIndex
++, false, STR_BACK
, PushButtonType_STANDARD
);
380 InsertButton( *this, "btnNavNext", mxActionListener
, nNextPosX
, BUTTON_POS_Y
, BUTTON_WIDTH
, mnTabIndex
++, true, STR_NEXT
, PushButtonType_STANDARD
);
381 InsertButton( *this, "btnNavFinish", mxActionListener
, nFinishPosX
, BUTTON_POS_Y
, BUTTON_WIDTH
, mnTabIndex
++, true, STR_FINISH
, PushButtonType_STANDARD
);
382 InsertButton( *this, "btnNavCancel", mxActionListener
, nCancelPosX
, BUTTON_POS_Y
, BUTTON_WIDTH
, mnTabIndex
++, true, STR_CANCEL
, PushButtonType_STANDARD
);
384 setControlProperty( "btnNavNext", "DefaultButton", Any( true ) );
388 void OptimizerDialog::UpdateControlStatesPage0()
390 short nSelectedItem
= -1;
391 Sequence
< OUString
> aItemList
;
392 const std::vector
< OptimizerSettings
>& rList( GetOptimizerSettings() );
393 if ( rList
.size() > 1 ) // the first session in the list is the actual one -> skipping first one
395 aItemList
.realloc( rList
.size() - 1 );
396 for ( std::vector
<OptimizerSettings
>::size_type i
= 1; i
< rList
.size(); i
++ )
398 aItemList
[ i
- 1 ] = rList
[ i
].maName
;
399 if ( nSelectedItem
< 0 )
401 if ( rList
[ i
] == rList
[ 0 ] )
402 nSelectedItem
= static_cast< short >( i
- 1 );
406 bool bRemoveButtonEnabled
= false;
407 Sequence
< short > aSelectedItems
;
408 if ( nSelectedItem
>= 0 )
410 aSelectedItems
.realloc( 1 );
411 aSelectedItems
[ 0 ] = nSelectedItem
;
412 if ( nSelectedItem
> 2 ) // only allowing to delete custom themes, the first can|t be deleted
413 bRemoveButtonEnabled
= true;
415 setControlProperty( "ListBox0Pg0", "StringItemList", Any( aItemList
) );
416 setControlProperty( "ListBox0Pg0", "SelectedItems", Any( aSelectedItems
) );
417 setControlProperty( "Button0Pg0", "Enabled", Any( bRemoveButtonEnabled
) );
419 void OptimizerDialog::InitPage0()
421 Sequence
< OUString
> aItemList
;
422 std::vector
< OUString
> aControlList
;
423 aControlList
.push_back( InsertFixedText( *this, "FixedText0Pg0", getString( STR_INTRODUCTION
), PAGE_POS_X
, PAGE_POS_Y
, PAGE_WIDTH
, 8, false, true, mnTabIndex
++ ) );
424 aControlList
.push_back( InsertFixedText( *this, "FixedText1Pg0", getString( STR_INTRODUCTION_T
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 14, PAGE_WIDTH
- 12, 100, true, false, mnTabIndex
++ ) );
425 aControlList
.push_back( InsertSeparator( *this, "Separator1Pg0", 0, PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 66, PAGE_WIDTH
- 12, 1 ) );
426 aControlList
.push_back( InsertFixedText( *this, "FixedText2Pg0", getString( STR_CHOSE_SETTINGS
), PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 60, PAGE_WIDTH
- 12, 8, true, false, mnTabIndex
++ ) );
427 aControlList
.push_back( InsertListBox( *this, "ListBox0Pg0", mxActionListenerListBox0Pg0
, true, aItemList
, PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 48, ( OD_DIALOG_WIDTH
- 50 ) - ( PAGE_POS_X
+ 6 ), mnTabIndex
++ ) );
428 aControlList
.push_back( InsertButton( *this, "Button0Pg0", mxActionListener
, OD_DIALOG_WIDTH
- 46, DIALOG_HEIGHT
- 49, 40, mnTabIndex
++, true, STR_REMOVE
, PushButtonType_STANDARD
) );
429 maControlPages
.push_back( aControlList
);
431 UpdateControlStatesPage0();
435 void OptimizerDialog::UpdateControlStatesPage1()
437 bool bDeleteUnusedMasterPages( GetConfigProperty( TK_DeleteUnusedMasterPages
, false ) );
438 bool bDeleteHiddenSlides( GetConfigProperty( TK_DeleteHiddenSlides
, false ) );
439 bool bDeleteNotesPages( GetConfigProperty( TK_DeleteNotesPages
, false ) );
441 setControlProperty( "CheckBox0Pg3", "State", Any( static_cast<sal_Int16
>(bDeleteUnusedMasterPages
) ) );
442 setControlProperty( "CheckBox1Pg3", "State", Any( static_cast<sal_Int16
>(bDeleteNotesPages
) ) );
443 setControlProperty( "CheckBox2Pg3", "State", Any( static_cast<sal_Int16
>(bDeleteHiddenSlides
) ) );
445 void OptimizerDialog::InitPage1()
447 Sequence
< OUString
> aCustomShowList
;
448 Reference
< XModel
> xModel( mxController
->getModel() );
451 Reference
< XCustomPresentationSupplier
> aXCPSup( xModel
, UNO_QUERY_THROW
);
452 Reference
< XNameContainer
> aXCont( aXCPSup
->getCustomPresentations() );
454 aCustomShowList
= aXCont
->getElementNames();
456 std::vector
< OUString
> aControlList
;
457 aControlList
.push_back( InsertFixedText( *this, "FixedText0Pg3", getString( STR_CHOOSE_SLIDES
), PAGE_POS_X
, PAGE_POS_Y
, PAGE_WIDTH
, 8, false, true, mnTabIndex
++ ) );
458 aControlList
.push_back( InsertCheckBox( *this, "CheckBox0Pg3", mxItemListener
, getString( STR_DELETE_MASTER_PAGES
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 14, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
459 aControlList
.push_back( InsertCheckBox( *this, "CheckBox2Pg3", mxItemListener
, getString( STR_DELETE_HIDDEN_SLIDES
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 28, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
460 aControlList
.push_back( InsertCheckBox( *this, "CheckBox3Pg3", mxItemListener
, getString( STR_CUSTOM_SHOW
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 42, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
461 aControlList
.push_back( InsertListBox( *this, "ListBox0Pg3", mxActionListener
, true, aCustomShowList
, PAGE_POS_X
+ 14, PAGE_POS_Y
+ 54, 150, mnTabIndex
++ ) );
462 aControlList
.push_back( InsertCheckBox( *this, "CheckBox1Pg3", mxItemListener
, getString( STR_DELETE_NOTES_PAGES
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 70, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
463 maControlPages
.push_back( aControlList
);
466 setControlProperty( "CheckBox3Pg3", "State", Any( false ) );
467 setControlProperty( "CheckBox3Pg3", "Enabled", Any( aCustomShowList
.hasElements() ) );
468 setControlProperty( "ListBox0Pg3", "Enabled", Any( false ) );
470 UpdateControlStatesPage1();
476 bool lcl_getResolutionText(OUString
& rResolutionText
, const OUString
& rImageResolution
, sal_Int32 nTargetRes
)
479 if (rImageResolution
.getToken(0, ';', nIdx
).toInt32()!=nTargetRes
)
481 rResolutionText
= rImageResolution
.getToken(0, ';', nIdx
);
487 void OptimizerDialog::UpdateControlStatesPage2()
489 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression
, false ) );
490 bool bRemoveCropArea( GetConfigProperty( TK_RemoveCropArea
, false ) );
491 bool bEmbedLinkedGraphics( GetConfigProperty( TK_EmbedLinkedGraphics
, true ) );
492 sal_Int32
nJPEGQuality( GetConfigProperty( TK_JPEGQuality
, sal_Int32(90) ) );
494 sal_Int32
nImageResolution( GetConfigProperty( TK_ImageResolution
, sal_Int32(0) ) );
496 OUString aResolutionText
;
497 for (int nIR
{ STR_IMAGE_RESOLUTION_0
}; nIR
<=STR_IMAGE_RESOLUTION_3
; ++nIR
)
499 if (lcl_getResolutionText(aResolutionText
, getString(static_cast<PPPOptimizerTokenEnum
>(nIR
)), nImageResolution
))
502 if ( aResolutionText
.isEmpty() )
503 aResolutionText
= OUString::number( nImageResolution
);
505 setControlProperty( "RadioButton0Pg1", "State", Any( static_cast<sal_Int16
>( !bJPEGCompression
) ) );
506 setControlProperty( "RadioButton1Pg1", "State", Any( static_cast<sal_Int16
>(bJPEGCompression
) ) );
507 setControlProperty( "FixedText1Pg1", "Enabled", Any( bJPEGCompression
) );
508 setControlProperty( "FormattedField0Pg1", "Enabled", Any( bJPEGCompression
) );
509 setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast<double>(nJPEGQuality
) ) );
510 setControlProperty( "CheckBox1Pg1", "State", Any( static_cast<sal_Int16
>(bRemoveCropArea
) ) );
511 setControlProperty( "ComboBox0Pg1", "Text", Any( aResolutionText
) );
512 setControlProperty( "CheckBox2Pg1", "State", Any( static_cast<sal_Int16
>(bEmbedLinkedGraphics
) ) );
514 void OptimizerDialog::InitPage2()
516 Sequence
< OUString
> aResolutionItemList( 4 );
517 aResolutionItemList
[ 0 ] = getString( STR_IMAGE_RESOLUTION_0
).getToken( 1, ';' );
518 aResolutionItemList
[ 1 ] = getString( STR_IMAGE_RESOLUTION_1
).getToken( 1, ';' );
519 aResolutionItemList
[ 2 ] = getString( STR_IMAGE_RESOLUTION_2
).getToken( 1, ';' );
520 aResolutionItemList
[ 3 ] = getString( STR_IMAGE_RESOLUTION_3
).getToken( 1, ';' );
522 std::vector
< OUString
> aControlList
;
523 aControlList
.push_back( InsertFixedText( *this, "FixedText0Pg1", getString( STR_GRAPHIC_OPTIMIZATION
), PAGE_POS_X
, PAGE_POS_Y
, PAGE_WIDTH
, 8, false, true, mnTabIndex
++ ) );
524 aControlList
.push_back( InsertRadioButton( *this, "RadioButton0Pg1", mxItemListener
, getString( STR_LOSSLESS_COMPRESSION
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 14, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
525 aControlList
.push_back( InsertRadioButton( *this, "RadioButton1Pg1", mxItemListener
, getString( STR_JPEG_COMPRESSION
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 28, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
526 aControlList
.push_back( InsertFixedText( *this, "FixedText1Pg1", getString( STR_QUALITY
), PAGE_POS_X
+ 20, PAGE_POS_Y
+ 40, 72, 8, false, false, mnTabIndex
++ ) );
527 aControlList
.push_back( InsertFormattedField( *this, "FormattedField0Pg1", mxTextListenerFormattedField0Pg1
, mxSpinListenerFormattedField0Pg1
, PAGE_POS_X
+ 106, PAGE_POS_Y
+ 38, 0, 100, mnTabIndex
++ ) );
528 aControlList
.push_back( InsertFixedText( *this, "FixedText2Pg1", getString( STR_IMAGE_RESOLUTION
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 54, 94, 8, false, false, mnTabIndex
++ ) );
529 aControlList
.push_back( InsertComboBox( *this, "ComboBox0Pg1", mxTextListenerComboBox0Pg1
, true, aResolutionItemList
, PAGE_POS_X
+ 106, PAGE_POS_Y
+ 52, mnTabIndex
++ ) );
530 aControlList
.push_back( InsertCheckBox( *this, "CheckBox1Pg1", mxItemListener
, getString( STR_REMOVE_CROP_AREA
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 68, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
531 aControlList
.push_back( InsertCheckBox( *this, "CheckBox2Pg1", mxItemListener
, getString( STR_EMBED_LINKED_GRAPHICS
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 82, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
532 maControlPages
.push_back( aControlList
);
534 UpdateControlStatesPage2();
538 void OptimizerDialog::UpdateControlStatesPage3()
540 bool bConvertOLEObjects( GetConfigProperty( TK_OLEOptimization
, false ) );
541 sal_Int16
nOLEOptimizationType( GetConfigProperty( TK_OLEOptimizationType
, sal_Int16(0) ) );
543 setControlProperty( "CheckBox0Pg2", "State", Any( static_cast<sal_Int16
>(bConvertOLEObjects
) ) );
544 setControlProperty( "RadioButton0Pg2", "Enabled", Any( bConvertOLEObjects
) );
545 setControlProperty( "RadioButton0Pg2", "State", Any( static_cast<sal_Int16
>( nOLEOptimizationType
== 0 ) ) );
546 setControlProperty( "RadioButton1Pg2", "Enabled", Any( bConvertOLEObjects
) );
547 setControlProperty( "RadioButton1Pg2", "State", Any( static_cast<sal_Int16
>( nOLEOptimizationType
== 1 ) ) );
549 void OptimizerDialog::InitPage3()
552 Reference
< XModel
> xModel( mxController
->getModel() );
553 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier( xModel
, UNO_QUERY_THROW
);
554 Reference
< XDrawPages
> xDrawPages( xDrawPagesSupplier
->getDrawPages(), UNO_SET_THROW
);
555 for ( sal_Int32 i
= 0; i
< xDrawPages
->getCount(); i
++ )
557 Reference
< XShapes
> xShapes( xDrawPages
->getByIndex( i
), UNO_QUERY_THROW
);
558 for ( sal_Int32 j
= 0; j
< xShapes
->getCount(); j
++ )
560 Reference
< XShape
> xShape( xShapes
->getByIndex( j
), UNO_QUERY_THROW
);
561 if ( xShape
->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
566 std::vector
< OUString
> aControlList
;
567 aControlList
.push_back( InsertFixedText( *this, "FixedText0Pg2", getString( STR_OLE_OPTIMIZATION
), PAGE_POS_X
, PAGE_POS_Y
, PAGE_WIDTH
, 8, false, true, mnTabIndex
++ ) );
568 aControlList
.push_back( InsertCheckBox( *this, "CheckBox0Pg2", mxItemListener
, getString( STR_OLE_REPLACE
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 14, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
569 aControlList
.push_back( InsertRadioButton( *this, "RadioButton0Pg2", mxItemListener
, getString( STR_ALL_OLE_OBJECTS
), PAGE_POS_X
+ 14, PAGE_POS_Y
+ 28, PAGE_WIDTH
- 22, mnTabIndex
++ ) );
570 aControlList
.push_back( InsertRadioButton( *this, "RadioButton1Pg2", mxItemListener
, getString( STR_ALIEN_OLE_OBJECTS_ONLY
), PAGE_POS_X
+ 14, PAGE_POS_Y
+ 40, PAGE_WIDTH
- 22, mnTabIndex
++ ) );
571 aControlList
.push_back( InsertFixedText( *this, "FixedText1Pg2", nOLECount
? getString( STR_OLE_OBJECTS_DESC
) : getString( STR_NO_OLE_OBJECTS_DESC
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 64, PAGE_WIDTH
- 22, 50, true, false, mnTabIndex
++ ) );
572 maControlPages
.push_back( aControlList
);
574 UpdateControlStatesPage3();
578 static OUString
ImpValueOfInMB( sal_Int64 rVal
, sal_Unicode nSeparator
)
580 double fVal( static_cast<double>( rVal
) );
583 OUStringBuffer
aVal( OUString::number( fVal
) );
584 sal_Int32
nX( aVal
.indexOf( '.' ) );
587 aVal
.setLength( nX
+ 2 );
588 aVal
[nX
] = nSeparator
;
590 aVal
.append( " MB" );
591 return aVal
.makeStringAndClear();
594 void OptimizerDialog::UpdateControlStatesPage4()
596 bool bSaveAs( GetConfigProperty( TK_SaveAs
, true ) );
599 setControlProperty( "RadioButton0Pg4", "State", Any( sal_Int16(false) ) );
600 setControlProperty( "RadioButton1Pg4", "State", Any( sal_Int16(true) ) );
604 setControlProperty( "RadioButton0Pg4", "State", Any( static_cast<sal_Int16
>( !bSaveAs
) ) );
605 setControlProperty( "RadioButton1Pg4", "State", Any( static_cast<sal_Int16
>(bSaveAs
) ) );
607 setControlProperty( "ComboBox0Pg4", "Enabled", Any( false ) );
609 Sequence
< OUString
> aItemList
;
610 const std::vector
< OptimizerSettings
>& rList( GetOptimizerSettings() );
611 if ( rList
.size() > 1 ) // the first session in the list is the actual one -> skipping first one
613 aItemList
.realloc( rList
.size() - 1 );
614 for ( std::vector
<OptimizerSettings
>::size_type w
= 1; w
< rList
.size(); w
++ )
615 aItemList
[ w
- 1 ] = rList
[ w
].maName
;
617 setControlProperty( "ComboBox0Pg4", "StringItemList", Any( aItemList
) );
619 // now check if it is sensible to enable the combo box
620 bool bSaveSettingsEnabled
= true;
621 if ( rList
.size() > 1 ) // the first session in the list is the actual one -> skipping first one
623 for ( std::vector
<OptimizerSettings
>::size_type w
= 1; w
< rList
.size(); w
++ )
625 if ( rList
[ w
] == rList
[ 0 ] )
627 bSaveSettingsEnabled
= false;
632 sal_Int16 nInt16
= 0;
633 getControlProperty( "CheckBox1Pg4", "State" ) >>= nInt16
;
634 setControlProperty( "CheckBox1Pg4", "Enabled", Any( bSaveSettingsEnabled
) );
635 setControlProperty( "ComboBox0Pg4", "Enabled", Any( bSaveSettingsEnabled
&& nInt16
) );
637 std::vector
< OUString
> aSummaryStrings
;
639 // taking care of deleted slides
640 sal_Int32 nDeletedSlides
= 0;
641 if ( getControlProperty( "CheckBox3Pg3", "State" ) >>= nInt16
)
645 Sequence
< short > aSelectedItems
;
646 Sequence
< OUString
> aStringItemList
;
647 Any aAny
= getControlProperty( "ListBox0Pg3", "SelectedItems" );
648 if ( aAny
>>= aSelectedItems
)
650 if ( aSelectedItems
.hasElements() )
652 sal_Int16 nSelectedItem
= aSelectedItems
[ 0 ];
653 aAny
= getControlProperty( "ListBox0Pg3", "StringItemList" );
654 if ( aAny
>>= aStringItemList
)
656 if ( aStringItemList
.getLength() > nSelectedItem
)
657 SetConfigProperty( TK_CustomShowName
, Any( aStringItemList
[ nSelectedItem
] ) );
663 if ( GetConfigProperty( TK_DeleteHiddenSlides
, false ) )
665 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier( mxController
->getModel(), UNO_QUERY_THROW
);
666 Reference
< XDrawPages
> xDrawPages( xDrawPagesSupplier
->getDrawPages(), UNO_SET_THROW
);
667 for( sal_Int32 i
= 0; i
< xDrawPages
->getCount(); i
++ )
669 Reference
< XDrawPage
> xDrawPage( xDrawPages
->getByIndex( i
), UNO_QUERY_THROW
);
670 Reference
< XPropertySet
> xPropSet( xDrawPage
, UNO_QUERY_THROW
);
672 bool bVisible
= true;
673 if ( xPropSet
->getPropertyValue( "Visible" ) >>= bVisible
)
680 if ( GetConfigProperty( TK_DeleteUnusedMasterPages
, false ) )
682 std::vector
< PageCollector::MasterPageEntity
> aMasterPageList
;
683 PageCollector::CollectMasterPages( mxController
->getModel(), aMasterPageList
);
684 Reference
< XMasterPagesSupplier
> xMasterPagesSupplier( mxController
->getModel(), UNO_QUERY_THROW
);
685 Reference
< XDrawPages
> xMasterPages( xMasterPagesSupplier
->getMasterPages(), UNO_SET_THROW
);
686 nDeletedSlides
+= std::count_if(aMasterPageList
.begin(), aMasterPageList
.end(),
687 [](const PageCollector::MasterPageEntity
& rEntity
) { return !rEntity
.bUsed
; });
689 if ( nDeletedSlides
> 1 )
691 OUString
aStr( getString( STR_DELETE_SLIDES
) );
692 OUString
aPlaceholder( "%SLIDES" );
693 sal_Int32 i
= aStr
.indexOf( aPlaceholder
);
695 aStr
= aStr
.replaceAt( i
, aPlaceholder
.getLength(), OUString::number( nDeletedSlides
) );
696 aSummaryStrings
.push_back( aStr
);
699 // generating graphic compression info
700 sal_Int32 nGraphics
= 0;
701 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression
, false ) );
702 sal_Int32
nJPEGQuality( GetConfigProperty( TK_JPEGQuality
, sal_Int32(90) ) );
703 sal_Int32
nImageResolution( GetConfigProperty( TK_ImageResolution
, sal_Int32(0) ) );
704 GraphicSettings
aGraphicSettings( bJPEGCompression
, nJPEGQuality
, GetConfigProperty( TK_RemoveCropArea
, false ),
705 nImageResolution
, GetConfigProperty( TK_EmbedLinkedGraphics
, true ) );
706 GraphicCollector::CountGraphics( UnoDialog::mxContext
, mxController
->getModel(), aGraphicSettings
, nGraphics
);
709 OUString
aStr( getString( STR_OPTIMIZE_IMAGES
) );
710 OUString
aImagePlaceholder( "%IMAGES" );
711 OUString
aQualityPlaceholder( "%QUALITY" );
712 OUString
aResolutionPlaceholder( "%RESOLUTION" );
713 sal_Int32 i
= aStr
.indexOf( aImagePlaceholder
);
715 aStr
= aStr
.replaceAt( i
, aImagePlaceholder
.getLength(), OUString::number( nGraphics
) );
717 sal_Int32 j
= aStr
.indexOf( aQualityPlaceholder
);
719 aStr
= aStr
.replaceAt( j
, aQualityPlaceholder
.getLength(), OUString::number( nJPEGQuality
) );
721 sal_Int32 k
= aStr
.indexOf( aResolutionPlaceholder
);
723 aStr
= aStr
.replaceAt( k
, aResolutionPlaceholder
.getLength(), OUString::number( nImageResolution
) );
725 aSummaryStrings
.push_back( aStr
);
728 if ( GetConfigProperty( TK_OLEOptimization
, false ) )
730 sal_Int32 nOLEReplacements
= 0;
731 Reference
< XDrawPagesSupplier
> xDrawPagesSupplier( mxController
->getModel(), UNO_QUERY_THROW
);
732 Reference
< XDrawPages
> xDrawPages( xDrawPagesSupplier
->getDrawPages(), UNO_SET_THROW
);
733 for ( sal_Int32 i
= 0; i
< xDrawPages
->getCount(); i
++ )
735 Reference
< XShapes
> xShapes( xDrawPages
->getByIndex( i
), UNO_QUERY_THROW
);
736 for ( sal_Int32 j
= 0; j
< xShapes
->getCount(); j
++ )
738 Reference
< XShape
> xShape( xShapes
->getByIndex( j
), UNO_QUERY_THROW
);
739 if ( xShape
->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
743 if ( nOLEReplacements
> 1 )
745 OUString
aStr( getString( STR_CREATE_REPLACEMENT
) );
746 OUString
aPlaceholder( "%OLE" );
747 sal_Int32 i
= aStr
.indexOf( aPlaceholder
);
749 aStr
= aStr
.replaceAt( i
, aPlaceholder
.getLength(), OUString::number( nOLEReplacements
) );
750 aSummaryStrings
.push_back( aStr
);
753 while( aSummaryStrings
.size() < 3 )
754 aSummaryStrings
.emplace_back( );
755 setControlProperty( "FixedText4Pg4", "Label", Any( aSummaryStrings
[ 0 ] ) );
756 setControlProperty( "FixedText5Pg4", "Label", Any( aSummaryStrings
[ 1 ] ) );
757 setControlProperty( "FixedText6Pg4", "Label", Any( aSummaryStrings
[ 2 ] ) );
759 sal_Int64 nCurrentFileSize
= 0;
760 sal_Int64 nEstimatedFileSize
= 0;
761 Reference
< XStorable
> xStorable( mxController
->getModel(), UNO_QUERY
);
762 if ( xStorable
.is() && xStorable
->hasLocation() )
763 nCurrentFileSize
= PPPOptimizer::GetFileSize( xStorable
->getLocation() );
765 if ( nCurrentFileSize
)
767 double fE
= static_cast< double >( nCurrentFileSize
);
768 if ( nImageResolution
)
770 double v
= ( static_cast< double >( nImageResolution
) + 75.0 ) / 300.0;
774 if ( bJPEGCompression
)
776 double v
= 0.75 - ( ( 100.0 - static_cast< double >( nJPEGQuality
) ) / 400.0 ) ;
779 nEstimatedFileSize
= static_cast< sal_Int64
>( fE
);
781 sal_Unicode nSeparator
= '.';
782 OUString
aStr( getString( STR_FILESIZESEPARATOR
) );
783 if ( !aStr
.isEmpty() )
784 nSeparator
= aStr
[ 0 ];
785 setControlProperty( "FixedText7Pg4", "Label", Any( ImpValueOfInMB( nCurrentFileSize
, nSeparator
) ) );
786 setControlProperty( "FixedText8Pg4", "Label", Any( ImpValueOfInMB( nEstimatedFileSize
, nSeparator
) ) );
787 SetConfigProperty( TK_EstimatedFileSize
, Any( nEstimatedFileSize
) );
790 void OptimizerDialog::InitPage4()
792 { // creating progress bar:
793 OUString pNames
[] = {
796 OUString("PositionX"),
797 OUString("PositionY"),
798 OUString("ProgressValue"),
799 OUString("ProgressValueMax"),
800 OUString("ProgressValueMin"),
804 Any( sal_Int32(12) ),
805 Any( OUString("STR_SAVE_AS") ),
806 Any( sal_Int32( PAGE_POS_X
+ 6 ) ),
807 Any( sal_Int32( DIALOG_HEIGHT
- 75 ) ),
809 Any( sal_Int32(100) ),
811 Any( sal_Int32( PAGE_WIDTH
- 12 ) ) };
813 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
815 Sequence
< OUString
> aNames( pNames
, nCount
);
816 Sequence
< Any
> aValues( pValues
, nCount
);
818 insertControlModel( "com.sun.star.awt.UnoControlProgressBarModel",
819 "Progress", aNames
, aValues
);
821 Reference
< XTextListener
> xTextListener
;
822 Sequence
< OUString
> aItemList
;
823 std::vector
< OUString
> aControlList
;
824 aControlList
.push_back( InsertFixedText( *this, "FixedText0Pg4", getString( STR_SUMMARY_TITLE
), PAGE_POS_X
, PAGE_POS_Y
, PAGE_WIDTH
, 8, false, true, mnTabIndex
++ ) );
825 // aControlList.push_back( InsertSeparator( *this, "Separator0Pg4", 0, PAGE_POS_X + 6, PAGE_POS_Y + 90, PAGE_WIDTH - 12, 1 ) );
827 aControlList
.push_back( InsertFixedText( *this, "FixedText4Pg4", OUString(), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 14, PAGE_WIDTH
- 12, 8, false, false, mnTabIndex
++ ) );
828 aControlList
.push_back( InsertFixedText( *this, "FixedText5Pg4", OUString(), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 22, PAGE_WIDTH
- 12, 8, false, false, mnTabIndex
++ ) );
829 aControlList
.push_back( InsertFixedText( *this, "FixedText6Pg4", OUString(), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 30, PAGE_WIDTH
- 12, 8, false, false, mnTabIndex
++ ) );
831 aControlList
.push_back( InsertFixedText( *this, "FixedText2Pg4", getString( STR_CURRENT_FILESIZE
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 50, 88, 8, false, false, mnTabIndex
++ ) );
832 aControlList
.push_back( InsertFixedText( *this, "FixedText7Pg4", OUString(), PAGE_POS_X
+ 100, PAGE_POS_Y
+ 50, 30, 8, false, false, mnTabIndex
++ ) );
833 setControlProperty( "FixedText7Pg4", "Align", Any( static_cast< short >( 2 ) ) );
834 aControlList
.push_back( InsertFixedText( *this, "FixedText3Pg4", getString( STR_ESTIMATED_FILESIZE
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 58, 88, 8, false, false, mnTabIndex
++ ) );
835 aControlList
.push_back( InsertFixedText( *this, "FixedText8Pg4", OUString(), PAGE_POS_X
+ 100, PAGE_POS_Y
+ 58, 30, 8, false, false, mnTabIndex
++ ) );
836 setControlProperty( "FixedText8Pg4", "Align", Any( static_cast< short >( 2 ) ) );
838 aControlList
.push_back( InsertRadioButton( *this, "RadioButton0Pg4", mxItemListener
, getString( STR_APPLY_TO_CURRENT
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 78, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
839 aControlList
.push_back( InsertRadioButton( *this, "RadioButton1Pg4", mxItemListener
, getString( STR_SAVE_AS
), PAGE_POS_X
+ 6, PAGE_POS_Y
+ 90, PAGE_WIDTH
- 12, mnTabIndex
++ ) );
840 aControlList
.push_back( InsertFixedText( *this, "FixedText1Pg4", OUString(), PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 87, PAGE_WIDTH
- 12, 8, true, false, mnTabIndex
++ ) );
841 aControlList
.emplace_back("Progress" );
842 aControlList
.push_back( InsertSeparator( *this, "Separator1Pg4", 0, PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 58, PAGE_WIDTH
- 12, 1 ) );
843 aControlList
.push_back( InsertCheckBox( *this, "CheckBox1Pg4", mxItemListener
, getString( STR_SAVE_SETTINGS
), PAGE_POS_X
+ 6, DIALOG_HEIGHT
- 47, 100, mnTabIndex
++ ) );
844 aControlList
.push_back( InsertComboBox( *this, "ComboBox0Pg4", xTextListener
, true, aItemList
, PAGE_POS_X
+ 106, DIALOG_HEIGHT
- 48, mnTabIndex
++ ) );
845 maControlPages
.push_back( aControlList
);
848 // creating a default session name that hasn't been used yet
849 OUString aSettingsName
;
850 OUString
aDefault( getString( STR_MY_SETTINGS
) );
851 sal_Int32 nSession
= 1;
852 std::vector
<OptimizerSettings
>::size_type i
;
853 const std::vector
< OptimizerSettings
>& rList( GetOptimizerSettings() );
856 OUString aTemp
= aDefault
+ OUString::number( nSession
++ );
857 for ( i
= 1; i
< rList
.size(); i
++ )
859 if ( rList
[ i
].maName
== aTemp
)
862 if ( i
== rList
.size() )
863 aSettingsName
= aTemp
;
865 while( aSettingsName
.isEmpty() );
867 setControlProperty( "ComboBox0Pg4", "Text", Any( aSettingsName
) );
868 setControlProperty( "RadioButton0Pg4", "Enabled", Any( !mbIsReadonly
) );
869 setControlProperty( "RadioButton1Pg4", "Enabled", Any( !mbIsReadonly
) );
871 UpdateControlStatesPage4();
875 void OptimizerDialog::EnablePage( sal_Int16 nStep
)
877 for( const auto& rItem
: maControlPages
[ nStep
] )
878 setControlProperty( rItem
, "Enabled", Any( true ) );
880 void OptimizerDialog::DisablePage( sal_Int16 nStep
)
882 for( const auto& rItem
: maControlPages
[ nStep
] )
883 setControlProperty( rItem
, "Enabled", Any( false ) );
885 void OptimizerDialog::ActivatePage( sal_Int16 nStep
)
887 for( const auto& rItem
: maControlPages
[ nStep
] )
888 setVisible( rItem
, true );
890 void OptimizerDialog::DeactivatePage( sal_Int16 nStep
)
892 for( const auto& rItem
: maControlPages
[ nStep
] )
893 setVisible( rItem
, false );
896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */