Update git submodules
[LibreOffice.git] / sdext / source / minimizer / optimizerdialogcontrols.cxx
blob4ab29d9694e674ac26adb76410141e3be7dbf245
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
38 #include <o3tl/string_view.hxx>
40 using namespace ::com::sun::star::awt;
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::drawing;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::presentation;
51 static void SetBold( OptimizerDialog& rOptimizerDialog, const OUString& rControl )
53 FontDescriptor aFontDescriptor;
54 if ( rOptimizerDialog.getControlProperty( rControl, "FontDescriptor" ) >>= aFontDescriptor )
56 aFontDescriptor.Weight = com::sun::star::awt::FontWeight::BOLD;
57 rOptimizerDialog.setControlProperty( rControl, "FontDescriptor", Any( aFontDescriptor ) );
62 static OUString InsertSeparator( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, sal_Int32 nOrientation,
63 sal_Int32 nPosX, sal_Int32 nPosY, sal_Int32 nWidth, sal_Int32 nHeight )
65 OUString pNames[] = {
66 OUString("Height"),
67 OUString("Orientation"),
68 OUString("PositionX"),
69 OUString("PositionY"),
70 OUString("Step"),
71 OUString("Width") };
73 Any pValues[] = {
74 Any( nHeight ),
75 Any( nOrientation ),
76 Any( nPosX ),
77 Any( nPosY ),
78 Any( sal_Int16( 0 ) ),
79 Any( nWidth ) };
81 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
83 Sequence< OUString > aNames( pNames, nCount );
84 Sequence< Any > aValues( pValues, nCount );
86 rOptimizerDialog.insertControlModel( "com.sun.star.awt.UnoControlFixedLineModel",
87 rControlName, aNames, aValues );
88 return rControlName;
92 static OUString InsertButton( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, Reference< XActionListener > const & xActionListener,
93 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int16 nTabIndex, bool bEnabled, PPPOptimizerTokenEnum nResID, css::awt::PushButtonType nPushButtonType )
95 sal_Int32 nHeight = BUTTON_HEIGHT;
96 OUString pNames[] = {
97 OUString("Enabled"),
98 OUString("Height"),
99 OUString("Label"),
100 OUString("PositionX"),
101 OUString("PositionY"),
102 OUString("PushButtonType"),
103 OUString("Step"),
104 OUString("TabIndex"),
105 OUString("Width") };
107 Any pValues[] = {
108 Any( bEnabled ),
109 Any( nHeight ),
110 Any( rOptimizerDialog.getString( nResID ) ),
111 Any( nXPos ),
112 Any( nYPos ),
113 Any( static_cast< sal_Int16 >(nPushButtonType) ),
114 Any( sal_Int16(0) ),
115 Any( nTabIndex ),
116 Any( nWidth ) };
119 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
121 Sequence< OUString > aNames( pNames, nCount );
122 Sequence< Any > aValues( pValues, nCount );
124 rOptimizerDialog.insertButton( rControlName, xActionListener, aNames, aValues );
125 return rControlName;
129 static OUString InsertFixedText( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, const OUString& rLabel,
130 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, bool bMultiLine, bool bBold, sal_Int16 nTabIndex )
132 OUString pNames[] = {
133 OUString("Height"),
134 OUString("Label"),
135 OUString("MultiLine"),
136 OUString("PositionX"),
137 OUString("PositionY"),
138 OUString("Step"),
139 OUString("TabIndex"),
140 OUString("Width") };
142 Any pValues[] = {
143 Any( nHeight ),
144 Any( rLabel ),
145 Any( bMultiLine ),
146 Any( nXPos ),
147 Any( nYPos ),
148 Any( sal_Int16(0) ),
149 Any( nTabIndex ),
150 Any( nWidth ) };
152 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
154 Sequence< OUString > aNames( pNames, nCount );
155 Sequence< Any > aValues( pValues, nCount );
157 rOptimizerDialog.insertFixedText( rControlName, aNames, aValues );
158 if ( bBold )
159 SetBold( rOptimizerDialog, rControlName );
160 return rControlName;
164 static OUString InsertCheckBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
165 const Reference< XItemListener >& xItemListener, const OUString& rLabel,
166 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int16 nTabIndex )
168 sal_Int32 nHeight = 8;
169 OUString pNames[] = {
170 OUString("Enabled"),
171 OUString("Height"),
172 OUString("Label"),
173 OUString("PositionX"),
174 OUString("PositionY"),
175 OUString("Step"),
176 OUString("TabIndex"),
177 OUString("Width") };
179 Any pValues[] = {
180 Any( true ),
181 Any( nHeight ),
182 Any( rLabel ),
183 Any( nXPos ),
184 Any( nYPos ),
185 Any( sal_Int16(0) ),
186 Any( nTabIndex ),
187 Any( nWidth ) };
189 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
191 Sequence< OUString > aNames( pNames, nCount );
192 Sequence< Any > aValues( pValues, nCount );
194 Reference< XCheckBox > xCheckBox( rOptimizerDialog.insertCheckBox( rControlName, aNames, aValues ) );
195 if ( xItemListener.is() )
196 xCheckBox->addItemListener( xItemListener );
197 return rControlName;
201 static OUString InsertFormattedField( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
202 const Reference< XTextListener >& xTextListener, const Reference< XSpinListener >& xSpinListener, sal_Int32 nXPos, sal_Int32 nYPos,
203 double fEffectiveMin, double fEffectiveMax, sal_Int16 nTabIndex )
205 sal_Int32 nWidth = 50;
206 OUString pNames[] = {
207 OUString("EffectiveMax"),
208 OUString("EffectiveMin"),
209 OUString("Enabled"),
210 OUString("Height"),
211 OUString("PositionX"),
212 OUString("PositionY"),
213 OUString("Repeat"),
214 OUString("Spin"),
215 OUString("Step"),
216 OUString("TabIndex"),
217 OUString("Width") };
219 Any pValues[] = {
220 Any( fEffectiveMax ),
221 Any( fEffectiveMin ),
222 Any( true ),
223 Any( sal_Int32(12) ),
224 Any( nXPos ),
225 Any( nYPos ),
226 Any( true ),
227 Any( true ),
228 Any( sal_Int16(0) ),
229 Any( nTabIndex ),
230 Any( nWidth ) };
232 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
234 Sequence< OUString > aNames( pNames, nCount );
235 Sequence< Any > aValues( pValues, nCount );
237 Reference< XTextComponent > xTextComponent( rOptimizerDialog.insertFormattedField( rControlName, aNames, aValues ), UNO_QUERY_THROW );
238 if ( xTextListener.is() )
239 xTextComponent->addTextListener( xTextListener );
240 if ( xSpinListener.is() )
242 Reference< XSpinField > xSpinField( xTextComponent, UNO_QUERY_THROW );
243 xSpinField->addSpinListener( xSpinListener );
245 return rControlName;
249 static OUString InsertComboBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
250 const Reference< XTextListener >& rTextListener, const bool bEnabled, const Sequence< OUString >& rItemList,
251 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int16 nTabIndex )
253 sal_Int32 nHeight = 12;
254 sal_Int32 nWidth = 100;
255 OUString pNames[] = {
256 OUString("Dropdown"),
257 OUString("Enabled"),
258 OUString("Height"),
259 OUString("LineCount"),
260 OUString("PositionX"),
261 OUString("PositionY"),
262 OUString("Step"),
263 OUString("StringItemList"),
264 OUString("TabIndex"),
265 OUString("Width") };
267 Any pValues[] = {
268 Any( true ),
269 Any( bEnabled ),
270 Any( nHeight ),
271 Any( sal_Int16(8)),
272 Any( nXPos ),
273 Any( nYPos ),
274 Any( sal_Int16(0) ),
275 Any( rItemList ),
276 Any( nTabIndex ),
277 Any( nWidth ) };
279 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
281 Sequence< OUString > aNames( pNames, nCount );
282 Sequence< Any > aValues( pValues, nCount );
284 Reference< XTextComponent > xTextComponent( rOptimizerDialog.insertComboBox( rControlName, aNames, aValues ), UNO_QUERY_THROW );
285 if ( rTextListener.is() )
286 xTextComponent->addTextListener( rTextListener );
287 return rControlName;
291 static OUString InsertRadioButton( OptimizerDialog& rOptimizerDialog, const OUString& rControlName, const Reference< XItemListener >& rItemListener,
292 const OUString& rLabel, sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int16 nTabIndex )
294 sal_Int32 nHeight = 8;
295 OUString pNames[] = {
296 OUString("Height"),
297 OUString("Label"),
298 OUString("MultiLine"),
299 OUString("PositionX"),
300 OUString("PositionY"),
301 OUString("Step"),
302 OUString("TabIndex"),
303 OUString("Width") };
305 Any pValues[] = {
306 Any( nHeight ),
307 Any( rLabel ),
308 Any( false ), // bMultiLine
309 Any( nXPos ),
310 Any( nYPos ),
311 Any( sal_Int16(0) ),
312 Any( nTabIndex ),
313 Any( nWidth ) };
315 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
317 Sequence< OUString > aNames( pNames, nCount );
318 Sequence< Any > aValues( pValues, nCount );
320 Reference< XRadioButton > xRadioButton( rOptimizerDialog.insertRadioButton( rControlName, aNames, aValues ) );
321 if ( rItemListener.is() )
322 xRadioButton->addItemListener( rItemListener );
323 return rControlName;
327 static OUString InsertListBox( OptimizerDialog& rOptimizerDialog, const OUString& rControlName,
328 const Reference< XActionListener >& rActionListener, const bool bEnabled, const Sequence< OUString >& rItemList,
329 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int16 nTabIndex )
331 sal_Int32 nHeight = 12;
332 OUString pNames[] = {
333 OUString("Dropdown"),
334 OUString("Enabled"),
335 OUString("Height"),
336 OUString("LineCount"),
337 OUString("MultiSelection"),
338 OUString("PositionX"),
339 OUString("PositionY"),
340 OUString("Step"),
341 OUString("StringItemList"),
342 OUString("TabIndex"),
343 OUString("Width") };
345 Any pValues[] = {
346 Any( true ),
347 Any( bEnabled ),
348 Any( nHeight ),
349 Any( sal_Int16(8)),
350 Any( false ),
351 Any( nXPos ),
352 Any( nYPos ),
353 Any( sal_Int16(0) ),
354 Any( rItemList ),
355 Any( nTabIndex ),
356 Any( nWidth ) };
358 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
360 Sequence< OUString > aNames( pNames, nCount );
361 Sequence< Any > aValues( pValues, nCount );
363 Reference< XListBox > xListBox( rOptimizerDialog.insertListBox( rControlName, aNames, aValues ) );
364 if ( xListBox.is() )
365 xListBox->addActionListener( rActionListener );
366 return rControlName;
370 void OptimizerDialog::InitNavigationBar()
372 sal_Int32 nCancelPosX = OD_DIALOG_WIDTH - BUTTON_WIDTH - 6;
373 sal_Int32 nFinishPosX = nCancelPosX - 6 - BUTTON_WIDTH;
374 sal_Int32 nNextPosX = nFinishPosX - 6 - BUTTON_WIDTH;
375 sal_Int32 nBackPosX = nNextPosX - 3 - BUTTON_WIDTH;
377 InsertSeparator( *this, "lnNavSep1", 0, 0, DIALOG_HEIGHT - 26, OD_DIALOG_WIDTH, 1 );
378 InsertSeparator( *this, "lnNavSep2", 1, 85, 0, 1, BUTTON_POS_Y - 6 );
380 InsertButton( *this, "btnNavBack", mxActionListener, nBackPosX, BUTTON_POS_Y, BUTTON_WIDTH, mnTabIndex++, false, STR_BACK, PushButtonType_STANDARD );
381 InsertButton( *this, "btnNavNext", mxActionListener, nNextPosX, BUTTON_POS_Y, BUTTON_WIDTH, mnTabIndex++, true, STR_NEXT, PushButtonType_STANDARD );
382 InsertButton( *this, "btnNavFinish", mxActionListener, nFinishPosX, BUTTON_POS_Y, BUTTON_WIDTH, mnTabIndex++, true, STR_FINISH, PushButtonType_STANDARD );
383 InsertButton( *this, "btnNavCancel", mxActionListener, nCancelPosX, BUTTON_POS_Y, BUTTON_WIDTH, mnTabIndex++, true, STR_CANCEL, PushButtonType_STANDARD );
385 setControlProperty( "btnNavNext", "DefaultButton", Any( true ) );
389 void OptimizerDialog::UpdateControlStatesPage0()
391 short nSelectedItem = -1;
392 Sequence< OUString > aItemList;
393 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
394 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
396 aItemList.realloc( rList.size() - 1 );
397 auto pItemList = aItemList.getArray();
398 for ( std::vector<OptimizerSettings>::size_type i = 1; i < rList.size(); i++ )
400 pItemList[ i - 1 ] = rList[ i ].maName;
401 if ( nSelectedItem < 0 )
403 if ( rList[ i ] == rList[ 0 ] )
404 nSelectedItem = static_cast< short >( i - 1 );
408 bool bRemoveButtonEnabled = false;
409 Sequence< short > aSelectedItems;
410 if ( nSelectedItem >= 0 )
412 aSelectedItems = { nSelectedItem };
413 if ( nSelectedItem > 2 ) // only allowing to delete custom themes, the first can|t be deleted
414 bRemoveButtonEnabled = true;
416 setControlProperty( "ListBox0Pg0", "StringItemList", Any( aItemList ) );
417 setControlProperty( "ListBox0Pg0", "SelectedItems", Any( aSelectedItems ) );
418 setControlProperty( "Button0Pg0", "Enabled", Any( bRemoveButtonEnabled ) );
420 void OptimizerDialog::InitPage0()
422 Sequence< OUString > aItemList;
423 std::vector< OUString > aControlList
425 InsertFixedText( *this, "FixedText0Pg0", getString( STR_INTRODUCTION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, false, true, mnTabIndex++ ),
426 InsertFixedText( *this, "FixedText1Pg0", getString( STR_INTRODUCTION_T ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 100, true, false, mnTabIndex++ ),
427 InsertSeparator( *this, "Separator1Pg0", 0, PAGE_POS_X + 6, DIALOG_HEIGHT - 66, PAGE_WIDTH - 12, 1 ),
428 InsertFixedText( *this, "FixedText2Pg0", getString( STR_CHOSE_SETTINGS ), PAGE_POS_X + 6, DIALOG_HEIGHT - 60, PAGE_WIDTH - 12, 8, true, false, mnTabIndex++ ),
429 InsertListBox( *this, "ListBox0Pg0", mxActionListenerListBox0Pg0, true, aItemList, PAGE_POS_X + 6, DIALOG_HEIGHT - 48, ( OD_DIALOG_WIDTH - 50 ) - ( PAGE_POS_X + 6 ), mnTabIndex++ ),
430 InsertButton( *this, "Button0Pg0", mxActionListener, OD_DIALOG_WIDTH - 46, DIALOG_HEIGHT - 49, 40, mnTabIndex++, true, STR_REMOVE, PushButtonType_STANDARD )
432 maControlPages.push_back( aControlList );
433 DeactivatePage( 0 );
434 UpdateControlStatesPage0();
438 void OptimizerDialog::UpdateControlStatesPage1()
440 bool bDeleteUnusedMasterPages( GetConfigProperty( TK_DeleteUnusedMasterPages, false ) );
441 bool bDeleteHiddenSlides( GetConfigProperty( TK_DeleteHiddenSlides, false ) );
442 bool bDeleteNotesPages( GetConfigProperty( TK_DeleteNotesPages, false ) );
444 setControlProperty( "CheckBox0Pg3", "State", Any( static_cast<sal_Int16>(bDeleteUnusedMasterPages) ) );
445 setControlProperty( "CheckBox1Pg3", "State", Any( static_cast<sal_Int16>(bDeleteNotesPages) ) );
446 setControlProperty( "CheckBox2Pg3", "State", Any( static_cast<sal_Int16>(bDeleteHiddenSlides) ) );
448 void OptimizerDialog::InitPage1()
450 Sequence< OUString > aCustomShowList;
451 Reference< XModel > xModel( mxController->getModel() );
452 if ( xModel.is() )
454 Reference< XCustomPresentationSupplier > aXCPSup( xModel, UNO_QUERY_THROW );
455 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
456 if ( aXCont.is() )
457 aCustomShowList = aXCont->getElementNames();
459 std::vector< OUString > aControlList
461 InsertFixedText( *this, "FixedText0Pg3", getString( STR_CHOOSE_SLIDES ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, false, true, mnTabIndex++ ),
462 InsertCheckBox( *this, "CheckBox0Pg3", mxItemListener, getString( STR_DELETE_MASTER_PAGES ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, mnTabIndex++ ),
463 InsertCheckBox( *this, "CheckBox2Pg3", mxItemListener, getString( STR_DELETE_HIDDEN_SLIDES ), PAGE_POS_X + 6, PAGE_POS_Y + 28, PAGE_WIDTH - 12, mnTabIndex++ ),
464 InsertCheckBox( *this, "CheckBox3Pg3", mxItemListener, getString( STR_CUSTOM_SHOW ), PAGE_POS_X + 6, PAGE_POS_Y + 42, PAGE_WIDTH - 12, mnTabIndex++ ),
465 InsertListBox( *this, "ListBox0Pg3", mxActionListener, true, aCustomShowList, PAGE_POS_X + 14, PAGE_POS_Y + 54, 150, mnTabIndex++ ),
466 InsertCheckBox( *this, "CheckBox1Pg3", mxItemListener, getString( STR_DELETE_NOTES_PAGES ), PAGE_POS_X + 6, PAGE_POS_Y + 70, PAGE_WIDTH - 12, mnTabIndex++ )
468 maControlPages.push_back( aControlList );
469 DeactivatePage( 1 );
471 setControlProperty( "CheckBox3Pg3", "State", Any( false ) );
472 setControlProperty( "CheckBox3Pg3", "Enabled", Any( aCustomShowList.hasElements() ) );
473 setControlProperty( "ListBox0Pg3", "Enabled", Any( false ) );
475 UpdateControlStatesPage1();
478 namespace
481 bool lcl_getResolutionText(OUString& rResolutionText, std::u16string_view rImageResolution, sal_Int32 nTargetRes)
483 sal_Int32 nIdx{ 0 };
484 if (o3tl::toInt32(o3tl::getToken(rImageResolution, 0, ';', nIdx))!=nTargetRes)
485 return false;
486 rResolutionText = o3tl::getToken(rImageResolution, 0, ';', nIdx);
487 return true;
492 void OptimizerDialog::UpdateControlStatesPage2()
494 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, false ) );
495 bool bRemoveCropArea( GetConfigProperty( TK_RemoveCropArea, false ) );
496 bool bEmbedLinkedGraphics( GetConfigProperty( TK_EmbedLinkedGraphics, true ) );
497 sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, sal_Int32(90) ) );
499 sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, sal_Int32(0) ) );
501 OUString aResolutionText;
502 for (int nIR{ STR_IMAGE_RESOLUTION_0 }; nIR<=STR_IMAGE_RESOLUTION_3; ++nIR)
504 if (lcl_getResolutionText(aResolutionText, getString(static_cast<PPPOptimizerTokenEnum>(nIR)), nImageResolution))
505 break;
507 if ( aResolutionText.isEmpty() )
508 aResolutionText = OUString::number( nImageResolution );
510 setControlProperty( "RadioButton0Pg1", "State", Any( static_cast<sal_Int16>( !bJPEGCompression ) ) );
511 setControlProperty( "RadioButton1Pg1", "State", Any( static_cast<sal_Int16>(bJPEGCompression) ) );
512 setControlProperty( "FixedText1Pg1", "Enabled", Any( bJPEGCompression ) );
513 setControlProperty( "FormattedField0Pg1", "Enabled", Any( bJPEGCompression ) );
514 setControlProperty( "FormattedField0Pg1", "EffectiveValue", Any( static_cast<double>(nJPEGQuality) ) );
515 setControlProperty( "CheckBox1Pg1", "State", Any( static_cast<sal_Int16>(bRemoveCropArea) ) );
516 setControlProperty( "ComboBox0Pg1", "Text", Any( aResolutionText ) );
517 setControlProperty( "CheckBox2Pg1", "State", Any( static_cast<sal_Int16>(bEmbedLinkedGraphics) ) );
519 void OptimizerDialog::InitPage2()
521 Sequence< OUString > aResolutionItemList{
522 getString( STR_IMAGE_RESOLUTION_0 ).getToken( 1, ';' ),
523 getString( STR_IMAGE_RESOLUTION_1 ).getToken( 1, ';' ),
524 getString( STR_IMAGE_RESOLUTION_2 ).getToken( 1, ';' ),
525 getString( STR_IMAGE_RESOLUTION_3 ).getToken( 1, ';' )
528 std::vector< OUString > aControlList
530 InsertFixedText( *this, "FixedText0Pg1", getString( STR_GRAPHIC_OPTIMIZATION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, false, true, mnTabIndex++ ),
531 InsertRadioButton( *this, "RadioButton0Pg1", mxItemListener, getString( STR_LOSSLESS_COMPRESSION ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, mnTabIndex++ ),
532 InsertRadioButton( *this, "RadioButton1Pg1", mxItemListener, getString( STR_JPEG_COMPRESSION ), PAGE_POS_X + 6, PAGE_POS_Y + 28, PAGE_WIDTH - 12, mnTabIndex++ ),
533 InsertFixedText( *this, "FixedText1Pg1", getString( STR_QUALITY ), PAGE_POS_X + 20, PAGE_POS_Y + 40, 72, 8, false, false, mnTabIndex++ ),
534 InsertFormattedField( *this, "FormattedField0Pg1", mxTextListenerFormattedField0Pg1, mxSpinListenerFormattedField0Pg1, PAGE_POS_X + 106, PAGE_POS_Y + 38, 0, 100, mnTabIndex++ ),
535 InsertFixedText( *this, "FixedText2Pg1", getString( STR_IMAGE_RESOLUTION ), PAGE_POS_X + 6, PAGE_POS_Y + 54, 94, 8, false, false, mnTabIndex++ ),
536 InsertComboBox( *this, "ComboBox0Pg1", mxTextListenerComboBox0Pg1, true, aResolutionItemList, PAGE_POS_X + 106, PAGE_POS_Y + 52, mnTabIndex++ ),
537 InsertCheckBox( *this, "CheckBox1Pg1", mxItemListener, getString( STR_REMOVE_CROP_AREA ), PAGE_POS_X + 6, PAGE_POS_Y + 68, PAGE_WIDTH - 12, mnTabIndex++ ),
538 InsertCheckBox( *this, "CheckBox2Pg1", mxItemListener, getString( STR_EMBED_LINKED_GRAPHICS ), PAGE_POS_X + 6, PAGE_POS_Y + 82, PAGE_WIDTH - 12, mnTabIndex++ )
540 maControlPages.push_back( aControlList );
541 DeactivatePage( 2 );
542 UpdateControlStatesPage2();
546 void OptimizerDialog::UpdateControlStatesPage3()
548 bool bConvertOLEObjects( GetConfigProperty( TK_OLEOptimization, false ) );
549 sal_Int16 nOLEOptimizationType( GetConfigProperty( TK_OLEOptimizationType, sal_Int16(0) ) );
551 setControlProperty( "CheckBox0Pg2", "State", Any( static_cast<sal_Int16>(bConvertOLEObjects) ) );
552 setControlProperty( "RadioButton0Pg2", "Enabled", Any( bConvertOLEObjects ) );
553 setControlProperty( "RadioButton0Pg2", "State", Any( static_cast<sal_Int16>( nOLEOptimizationType == 0 ) ) );
554 setControlProperty( "RadioButton1Pg2", "Enabled", Any( bConvertOLEObjects ) );
555 setControlProperty( "RadioButton1Pg2", "State", Any( static_cast<sal_Int16>( nOLEOptimizationType == 1 ) ) );
557 void OptimizerDialog::InitPage3()
559 int nOLECount = 0;
560 Reference< XModel > xModel( mxController->getModel() );
561 Reference< XDrawPagesSupplier > xDrawPagesSupplier( xModel, UNO_QUERY_THROW );
562 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
563 for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
565 Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
566 for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
568 Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
569 if ( xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
570 nOLECount++;
574 std::vector< OUString > aControlList
576 InsertFixedText( *this, "FixedText0Pg2", getString( STR_OLE_OPTIMIZATION ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, false, true, mnTabIndex++ ),
577 InsertCheckBox( *this, "CheckBox0Pg2", mxItemListener, getString( STR_OLE_REPLACE ), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, mnTabIndex++ ),
578 InsertRadioButton( *this, "RadioButton0Pg2", mxItemListener, getString( STR_ALL_OLE_OBJECTS ), PAGE_POS_X + 14, PAGE_POS_Y + 28, PAGE_WIDTH - 22, mnTabIndex++ ),
579 InsertRadioButton( *this, "RadioButton1Pg2", mxItemListener, getString( STR_ALIEN_OLE_OBJECTS_ONLY ), PAGE_POS_X + 14, PAGE_POS_Y + 40, PAGE_WIDTH - 22, mnTabIndex++ ),
580 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++ )
582 maControlPages.push_back( aControlList );
583 DeactivatePage( 3 );
584 UpdateControlStatesPage3();
588 static OUString ImpValueOfInMB( sal_Int64 rVal, sal_Unicode nSeparator )
590 double fVal( static_cast<double>( rVal ) );
591 fVal /= ( 1 << 20 );
592 fVal += 0.05;
593 OUStringBuffer aVal( OUString::number( fVal ) );
594 sal_Int32 nX( aVal.indexOf( '.' ) );
595 if ( nX >= 0 )
597 aVal.setLength( nX + 2 );
598 aVal[nX] = nSeparator;
600 aVal.append( " MB" );
601 return aVal.makeStringAndClear();
604 void OptimizerDialog::UpdateControlStatesPage4()
606 bool bSaveAs( GetConfigProperty( TK_SaveAs, true ) );
607 if ( mbIsReadonly )
609 setControlProperty( "RadioButton0Pg4", "State", Any( sal_Int16(false) ) );
610 setControlProperty( "RadioButton1Pg4", "State", Any( sal_Int16(true) ) );
612 else
614 setControlProperty( "RadioButton0Pg4", "State", Any( static_cast<sal_Int16>( !bSaveAs ) ) );
615 setControlProperty( "RadioButton1Pg4", "State", Any( static_cast<sal_Int16>(bSaveAs) ) );
617 setControlProperty( "ComboBox0Pg4", "Enabled", Any( false ) );
619 Sequence< OUString > aItemList;
620 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
621 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
623 aItemList.realloc( rList.size() - 1 );
624 auto pItemList = aItemList.getArray();
625 for ( std::vector<OptimizerSettings>::size_type w = 1; w < rList.size(); w++ )
626 pItemList[ w - 1 ] = rList[ w ].maName;
628 setControlProperty( "ComboBox0Pg4", "StringItemList", Any( aItemList ) );
630 // now check if it is sensible to enable the combo box
631 bool bSaveSettingsEnabled = true;
632 if ( rList.size() > 1 ) // the first session in the list is the actual one -> skipping first one
634 for ( std::vector<OptimizerSettings>::size_type w = 1; w < rList.size(); w++ )
636 if ( rList[ w ] == rList[ 0 ] )
638 bSaveSettingsEnabled = false;
639 break;
643 sal_Int16 nInt16 = 0;
644 getControlProperty( "CheckBox1Pg4", "State" ) >>= nInt16;
645 setControlProperty( "CheckBox1Pg4", "Enabled", Any( bSaveSettingsEnabled ) );
646 setControlProperty( "ComboBox0Pg4", "Enabled", Any( bSaveSettingsEnabled && nInt16 ) );
648 std::vector< OUString > aSummaryStrings;
650 // taking care of deleted slides
651 sal_Int32 nDeletedSlides = 0;
652 if ( getControlProperty( "CheckBox3Pg3", "State" ) >>= nInt16 )
654 if ( nInt16 )
656 Sequence< short > aSelectedItems;
657 Sequence< OUString > aStringItemList;
658 Any aAny = getControlProperty( "ListBox0Pg3", "SelectedItems" );
659 if ( aAny >>= aSelectedItems )
661 if ( aSelectedItems.hasElements() )
663 sal_Int16 nSelectedItem = aSelectedItems[ 0 ];
664 aAny = getControlProperty( "ListBox0Pg3", "StringItemList" );
665 if ( aAny >>= aStringItemList )
667 if ( aStringItemList.getLength() > nSelectedItem )
668 SetConfigProperty( TK_CustomShowName, Any( aStringItemList[ nSelectedItem ] ) );
674 if ( GetConfigProperty( TK_DeleteHiddenSlides, false ) )
676 Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
677 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
678 for( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
680 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
681 Reference< XPropertySet > xPropSet( xDrawPage, UNO_QUERY_THROW );
683 bool bVisible = true;
684 if ( xPropSet->getPropertyValue( "Visible" ) >>= bVisible )
686 if (!bVisible )
687 nDeletedSlides++;
691 if ( GetConfigProperty( TK_DeleteUnusedMasterPages, false ) )
693 std::vector< PageCollector::MasterPageEntity > aMasterPageList;
694 PageCollector::CollectMasterPages( mxController->getModel(), aMasterPageList );
695 Reference< XMasterPagesSupplier > xMasterPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
696 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
697 nDeletedSlides += std::count_if(aMasterPageList.begin(), aMasterPageList.end(),
698 [](const PageCollector::MasterPageEntity& rEntity) { return !rEntity.bUsed; });
700 if ( nDeletedSlides > 1 )
702 OUString aStr( getString( STR_DELETE_SLIDES ) );
703 OUString aPlaceholder( "%SLIDES" );
704 sal_Int32 i = aStr.indexOf( aPlaceholder );
705 if ( i >= 0 )
706 aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::number( nDeletedSlides ) );
707 aSummaryStrings.push_back( aStr );
710 // generating graphic compression info
711 sal_Int32 nGraphics = 0;
712 bool bJPEGCompression( GetConfigProperty( TK_JPEGCompression, false ) );
713 sal_Int32 nJPEGQuality( GetConfigProperty( TK_JPEGQuality, sal_Int32(90) ) );
714 sal_Int32 nImageResolution( GetConfigProperty( TK_ImageResolution, sal_Int32(0) ) );
715 GraphicSettings aGraphicSettings( bJPEGCompression, nJPEGQuality, GetConfigProperty( TK_RemoveCropArea, false ),
716 nImageResolution, GetConfigProperty( TK_EmbedLinkedGraphics, true ) );
717 GraphicCollector::CountGraphics( UnoDialog::mxContext, mxController->getModel(), aGraphicSettings, nGraphics );
718 if ( nGraphics > 1 )
720 OUString aStr( getString( STR_OPTIMIZE_IMAGES ) );
721 OUString aImagePlaceholder( "%IMAGES" );
722 OUString aQualityPlaceholder( "%QUALITY" );
723 OUString aResolutionPlaceholder( "%RESOLUTION" );
724 sal_Int32 i = aStr.indexOf( aImagePlaceholder );
725 if ( i >= 0 )
726 aStr = aStr.replaceAt( i, aImagePlaceholder.getLength(), OUString::number( nGraphics ) );
728 sal_Int32 j = aStr.indexOf( aQualityPlaceholder );
729 if ( j >= 0 )
730 aStr = aStr.replaceAt( j, aQualityPlaceholder.getLength(), OUString::number( nJPEGQuality ) );
732 sal_Int32 k = aStr.indexOf( aResolutionPlaceholder );
733 if ( k >= 0 )
734 aStr = aStr.replaceAt( k, aResolutionPlaceholder.getLength(), OUString::number( nImageResolution ) );
736 aSummaryStrings.push_back( aStr );
739 if ( GetConfigProperty( TK_OLEOptimization, false ) )
741 sal_Int32 nOLEReplacements = 0;
742 Reference< XDrawPagesSupplier > xDrawPagesSupplier( mxController->getModel(), UNO_QUERY_THROW );
743 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
744 for ( sal_Int32 i = 0; i < xDrawPages->getCount(); i++ )
746 Reference< XShapes > xShapes( xDrawPages->getByIndex( i ), UNO_QUERY_THROW );
747 for ( sal_Int32 j = 0; j < xShapes->getCount(); j++ )
749 Reference< XShape > xShape( xShapes->getByIndex( j ), UNO_QUERY_THROW );
750 if ( xShape->getShapeType() == "com.sun.star.drawing.OLE2Shape" )
751 nOLEReplacements++;
754 if ( nOLEReplacements > 1 )
756 OUString aStr( getString( STR_CREATE_REPLACEMENT ) );
757 OUString aPlaceholder( "%OLE" );
758 sal_Int32 i = aStr.indexOf( aPlaceholder );
759 if ( i >= 0 )
760 aStr = aStr.replaceAt( i, aPlaceholder.getLength(), OUString::number( nOLEReplacements ) );
761 aSummaryStrings.push_back( aStr );
764 while( aSummaryStrings.size() < 3 )
765 aSummaryStrings.emplace_back( );
766 setControlProperty( "FixedText4Pg4", "Label", Any( aSummaryStrings[ 0 ] ) );
767 setControlProperty( "FixedText5Pg4", "Label", Any( aSummaryStrings[ 1 ] ) );
768 setControlProperty( "FixedText6Pg4", "Label", Any( aSummaryStrings[ 2 ] ) );
770 sal_Int64 nCurrentFileSize = 0;
771 sal_Int64 nEstimatedFileSize = 0;
772 Reference< XStorable > xStorable( mxController->getModel(), UNO_QUERY );
773 if ( xStorable.is() && xStorable->hasLocation() )
774 nCurrentFileSize = PPPOptimizer::GetFileSize( xStorable->getLocation() );
776 if ( nCurrentFileSize )
778 double fE = static_cast< double >( nCurrentFileSize );
779 if ( nImageResolution )
781 double v = ( static_cast< double >( nImageResolution ) + 75.0 ) / 300.0;
782 if ( v < 1.0 )
783 fE *= v;
785 if ( bJPEGCompression )
787 double v = 0.75 - ( ( 100.0 - static_cast< double >( nJPEGQuality ) ) / 400.0 ) ;
788 fE *= v;
790 nEstimatedFileSize = static_cast< sal_Int64 >( fE );
792 sal_Unicode nSeparator = '.';
793 OUString aStr( getString( STR_FILESIZESEPARATOR ) );
794 if ( !aStr.isEmpty() )
795 nSeparator = aStr[ 0 ];
796 setControlProperty( "FixedText7Pg4", "Label", Any( ImpValueOfInMB( nCurrentFileSize, nSeparator ) ) );
797 setControlProperty( "FixedText8Pg4", "Label", Any( ImpValueOfInMB( nEstimatedFileSize, nSeparator ) ) );
798 SetConfigProperty( TK_EstimatedFileSize, Any( nEstimatedFileSize ) );
801 void OptimizerDialog::InitPage4()
803 { // creating progress bar:
804 OUString pNames[] = {
805 OUString("Height"),
806 OUString("Name"),
807 OUString("PositionX"),
808 OUString("PositionY"),
809 OUString("ProgressValue"),
810 OUString("ProgressValueMax"),
811 OUString("ProgressValueMin"),
812 OUString("Width") };
814 Any pValues[] = {
815 Any( sal_Int32(12) ),
816 Any( OUString("STR_SAVE_AS") ),
817 Any( sal_Int32( PAGE_POS_X + 6 ) ),
818 Any( sal_Int32( DIALOG_HEIGHT - 75 ) ),
819 Any( sal_Int32(0) ),
820 Any( sal_Int32(100) ),
821 Any( sal_Int32(0) ),
822 Any( sal_Int32( PAGE_WIDTH - 12 ) ) };
824 sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
826 Sequence< OUString > aNames( pNames, nCount );
827 Sequence< Any > aValues( pValues, nCount );
829 insertControlModel( "com.sun.star.awt.UnoControlProgressBarModel",
830 "Progress", aNames, aValues );
832 Reference< XTextListener > xTextListener;
833 Sequence< OUString > aItemList;
834 std::vector< OUString > aControlList
836 InsertFixedText( *this, "FixedText0Pg4", getString( STR_SUMMARY_TITLE ), PAGE_POS_X, PAGE_POS_Y, PAGE_WIDTH, 8, false, true, mnTabIndex++ ),
837 // InsertSeparator( *this, "Separator0Pg4", 0, PAGE_POS_X + 6, PAGE_POS_Y + 90, PAGE_WIDTH - 12, 1 ),
839 InsertFixedText( *this, "FixedText4Pg4", OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 14, PAGE_WIDTH - 12, 8, false, false, mnTabIndex++ ),
840 InsertFixedText( *this, "FixedText5Pg4", OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 22, PAGE_WIDTH - 12, 8, false, false, mnTabIndex++ ),
841 InsertFixedText( *this, "FixedText6Pg4", OUString(), PAGE_POS_X + 6, PAGE_POS_Y + 30, PAGE_WIDTH - 12, 8, false, false, mnTabIndex++ ),
843 InsertFixedText( *this, "FixedText2Pg4", getString( STR_CURRENT_FILESIZE ), PAGE_POS_X + 6, PAGE_POS_Y + 50, 88, 8, false, false, mnTabIndex++ ),
844 InsertFixedText( *this, "FixedText7Pg4", OUString(), PAGE_POS_X + 100, PAGE_POS_Y + 50, 30, 8, false, false, mnTabIndex++ )
846 setControlProperty( "FixedText7Pg4", "Align", Any( static_cast< short >( 2 ) ) );
847 aControlList.push_back( InsertFixedText( *this, "FixedText3Pg4", getString( STR_ESTIMATED_FILESIZE ), PAGE_POS_X + 6, PAGE_POS_Y + 58, 88, 8, false, false, mnTabIndex++ ) );
848 aControlList.push_back( InsertFixedText( *this, "FixedText8Pg4", OUString(), PAGE_POS_X + 100, PAGE_POS_Y + 58, 30, 8, false, false, mnTabIndex++ ) );
849 setControlProperty( "FixedText8Pg4", "Align", Any( static_cast< short >( 2 ) ) );
851 aControlList.push_back( InsertRadioButton( *this, "RadioButton0Pg4", mxItemListener, getString( STR_APPLY_TO_CURRENT ), PAGE_POS_X + 6, PAGE_POS_Y + 78, PAGE_WIDTH - 12, mnTabIndex++ ) );
852 aControlList.push_back( InsertRadioButton( *this, "RadioButton1Pg4", mxItemListener, getString( STR_SAVE_AS ), PAGE_POS_X + 6, PAGE_POS_Y + 90, PAGE_WIDTH - 12, mnTabIndex++ ) );
853 aControlList.push_back( InsertFixedText( *this, "FixedText1Pg4", OUString(), PAGE_POS_X + 6, DIALOG_HEIGHT - 87, PAGE_WIDTH - 12, 8, true, false, mnTabIndex++ ) );
854 aControlList.emplace_back("Progress" );
855 aControlList.push_back( InsertSeparator( *this, "Separator1Pg4", 0, PAGE_POS_X + 6, DIALOG_HEIGHT - 58, PAGE_WIDTH - 12, 1 ) );
856 aControlList.push_back( InsertCheckBox( *this, "CheckBox1Pg4", mxItemListener, getString( STR_SAVE_SETTINGS ), PAGE_POS_X + 6, DIALOG_HEIGHT - 47, 100, mnTabIndex++ ) );
857 aControlList.push_back( InsertComboBox( *this, "ComboBox0Pg4", xTextListener, true, aItemList, PAGE_POS_X + 106, DIALOG_HEIGHT - 48, mnTabIndex++ ) );
858 maControlPages.push_back( aControlList );
859 DeactivatePage( 4 );
861 // creating a default session name that hasn't been used yet
862 OUString aSettingsName;
863 OUString aDefault( getString( STR_MY_SETTINGS ) );
864 sal_Int32 nSession = 1;
865 std::vector<OptimizerSettings>::size_type i;
866 const std::vector< OptimizerSettings >& rList( GetOptimizerSettings() );
869 OUString aTemp = aDefault + OUString::number( nSession++ );
870 for ( i = 1; i < rList.size(); i++ )
872 if ( rList[ i ].maName == aTemp )
873 break;
875 if ( i == rList.size() )
876 aSettingsName = aTemp;
878 while( aSettingsName.isEmpty() );
880 setControlProperty( "ComboBox0Pg4", "Text", Any( aSettingsName ) );
881 setControlProperty( "RadioButton0Pg4", "Enabled", Any( !mbIsReadonly ) );
882 setControlProperty( "RadioButton1Pg4", "Enabled", Any( !mbIsReadonly ) );
884 UpdateControlStatesPage4();
888 void OptimizerDialog::EnablePage( sal_Int16 nStep )
890 for( const auto& rItem : maControlPages[ nStep ] )
891 setControlProperty( rItem, "Enabled", Any( true ) );
893 void OptimizerDialog::DisablePage( sal_Int16 nStep )
895 for( const auto& rItem : maControlPages[ nStep ] )
896 setControlProperty( rItem, "Enabled", Any( false ) );
898 void OptimizerDialog::ActivatePage( sal_Int16 nStep )
900 for( const auto& rItem : maControlPages[ nStep ] )
901 setVisible( rItem, true );
903 void OptimizerDialog::DeactivatePage( sal_Int16 nStep )
905 for( const auto& rItem : maControlPages[ nStep ] )
906 setVisible( rItem, false );
909 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */