1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sdext.hxx" 30 31 #include "informationdialog.hxx" 32 #include "optimizationstats.hxx" 33 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 34 #include <com/sun/star/graphic/XGraphicProvider.hpp> 35 #include <com/sun/star/graphic/XGraphic.hpp> 36 #include <rtl/ustrbuf.hxx> 37 #include "com/sun/star/util/URL.hpp" 38 #include "com/sun/star/util/XURLTransformer.hpp" 39 40 #define DIALOG_WIDTH 240 41 #define DIALOG_HEIGHT 80 42 #define PAGE_POS_X 35 43 #define PAGE_WIDTH ( DIALOG_WIDTH - PAGE_POS_X ) - 6 44 45 46 // --------------------- 47 // - INFORMATIONDIALOG - 48 // --------------------- 49 50 using namespace ::rtl; 51 using namespace ::com::sun::star; 52 using namespace ::com::sun::star::io; 53 using namespace ::com::sun::star::ui; 54 using namespace ::com::sun::star::awt; 55 using namespace ::com::sun::star::uno; 56 using namespace ::com::sun::star::util; 57 using namespace ::com::sun::star::lang; 58 using namespace ::com::sun::star::frame; 59 using namespace ::com::sun::star::beans; 60 using namespace ::com::sun::star::script; 61 using namespace ::com::sun::star::container; 62 63 64 65 // ----------------------------------------------------------------------------- 66 67 rtl::OUString InsertFixedText( InformationDialog& rInformationDialog, const rtl::OUString& rControlName, const OUString& rLabel, 68 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Bool bMultiLine, sal_Int16 nTabIndex ) 69 { 70 OUString pNames[] = { 71 TKGet( TK_Height ), 72 TKGet( TK_Label ), 73 TKGet( TK_MultiLine ), 74 TKGet( TK_PositionX ), 75 TKGet( TK_PositionY ), 76 TKGet( TK_Step ), 77 TKGet( TK_TabIndex ), 78 TKGet( TK_Width ) }; 79 80 Any pValues[] = { 81 Any( nHeight ), 82 Any( rLabel ), 83 Any( bMultiLine ), 84 Any( nXPos ), 85 Any( nYPos ), 86 Any( (sal_Int16)0 ), 87 Any( nTabIndex ), 88 Any( nWidth ) }; 89 90 sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString ); 91 92 Sequence< rtl::OUString > aNames( pNames, nCount ); 93 Sequence< Any > aValues( pValues, nCount ); 94 95 rInformationDialog.insertFixedText( rControlName, aNames, aValues ); 96 return rControlName; 97 } 98 99 rtl::OUString InsertImage( InformationDialog& rInformationDialog, const OUString& rControlName, const OUString& rURL, 100 sal_Int32 nPosX, sal_Int32 nPosY, sal_Int32 nWidth, sal_Int32 nHeight ) 101 { 102 OUString pNames[] = { 103 TKGet( TK_Border ), 104 TKGet( TK_Height ), 105 TKGet( TK_ImageURL ), 106 TKGet( TK_PositionX ), 107 TKGet( TK_PositionY ), 108 TKGet( TK_ScaleImage ), 109 TKGet( TK_Width ) }; 110 111 Any pValues[] = { 112 Any( sal_Int16( 0 ) ), 113 Any( nHeight ), 114 Any( rURL ), 115 Any( nPosX ), 116 Any( nPosY ), 117 Any( sal_True ), 118 Any( nWidth ) }; 119 sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString ); 120 121 Sequence< rtl::OUString > aNames( pNames, nCount ); 122 Sequence< Any > aValues( pValues, nCount ); 123 124 rInformationDialog.insertImage( rControlName, aNames, aValues ); 125 return rControlName; 126 } 127 128 rtl::OUString InsertCheckBox( InformationDialog& rInformationDialog, const OUString& rControlName, 129 const Reference< XItemListener > xItemListener, const OUString& rLabel, 130 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex ) 131 { 132 OUString pNames[] = { 133 TKGet( TK_Enabled ), 134 TKGet( TK_Height ), 135 TKGet( TK_Label ), 136 TKGet( TK_PositionX ), 137 TKGet( TK_PositionY ), 138 TKGet( TK_Step ), 139 TKGet( TK_TabIndex ), 140 TKGet( TK_Width ) }; 141 142 Any pValues[] = { 143 Any( sal_True ), 144 Any( nHeight ), 145 Any( rLabel ), 146 Any( nXPos ), 147 Any( nYPos ), 148 Any( (sal_Int16)0 ), 149 Any( nTabIndex ), 150 Any( nWidth ) }; 151 152 sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString ); 153 154 Sequence< rtl::OUString > aNames( pNames, nCount ); 155 Sequence< Any > aValues( pValues, nCount ); 156 157 Reference< XCheckBox > xCheckBox( rInformationDialog.insertCheckBox( rControlName, aNames, aValues ) ); 158 if ( xItemListener.is() ) 159 xCheckBox->addItemListener( xItemListener ); 160 return rControlName; 161 } 162 163 rtl::OUString InsertButton( InformationDialog& rInformationDialog, const OUString& rControlName, Reference< XActionListener >& xActionListener, 164 sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex, PPPOptimizerTokenEnum nResID ) 165 { 166 OUString pNames[] = { 167 TKGet( TK_Enabled ), 168 TKGet( TK_Height ), 169 TKGet( TK_Label ), 170 TKGet( TK_PositionX ), 171 TKGet( TK_PositionY ), 172 TKGet( TK_PushButtonType ), 173 TKGet( TK_Step ), 174 TKGet( TK_TabIndex ), 175 TKGet( TK_Width ) }; 176 177 Any pValues[] = { 178 Any( sal_True ), 179 Any( nHeight ), 180 Any( rInformationDialog.getString( nResID ) ), 181 Any( nXPos ), 182 Any( nYPos ), 183 Any( static_cast< sal_Int16 >( PushButtonType_OK ) ), 184 Any( (sal_Int16)0 ), 185 Any( nTabIndex ), 186 Any( nWidth ) }; 187 188 189 sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString ); 190 191 Sequence< rtl::OUString > aNames( pNames, nCount ); 192 Sequence< Any > aValues( pValues, nCount ); 193 194 rInformationDialog.insertButton( rControlName, xActionListener, aNames, aValues ); 195 return rControlName; 196 } 197 198 199 static OUString ImpValueOfInMB( const sal_Int64& rVal ) 200 { 201 double fVal( static_cast<double>( rVal ) ); 202 fVal /= ( 1 << 20 ); 203 fVal += 0.05; 204 rtl::OUStringBuffer aVal( OUString::valueOf( fVal ) ); 205 sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.', 0 ) ); 206 if ( nX > 0 ) 207 aVal.setLength( nX + 2 ); 208 return aVal.makeStringAndClear(); 209 } 210 211 OUString InformationDialog::ImpGetStandardImage( const OUString& sPrivateURL ) 212 { 213 rtl::OUString sURL; 214 try 215 { 216 mxTempFile = Reference< XStream >( mxMSF->getServiceManager()->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.io.TempFile" ), mxMSF ), UNO_QUERY_THROW ); 217 Reference< XPropertySet > xPropSet( mxTempFile, UNO_QUERY ); 218 Reference< XOutputStream > xOutputStream( mxTempFile->getOutputStream() ); 219 if ( xOutputStream.is() && xPropSet.is() ) 220 { 221 Reference< graphic::XGraphicProvider > xGraphicProvider( mxMSF->getServiceManager()->createInstanceWithContext( 222 OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ), mxMSF ), UNO_QUERY_THROW ); 223 Sequence< PropertyValue > aArgs( 1 ); 224 aArgs[ 0 ].Name = OUString::createFromAscii( "URL" ); 225 aArgs[ 0 ].Value <<= sPrivateURL; 226 Reference< graphic::XGraphic > xGraphic( xGraphicProvider->queryGraphic( aArgs ) ); 227 if ( xGraphic.is() ) 228 { 229 OUString aDestMimeType( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ); 230 Sequence< PropertyValue > aArgs2( 2 ); 231 aArgs2[ 0 ].Name = TKGet( TK_MimeType ); // the GraphicProvider is using "MimeType", the GraphicExporter "MediaType"... 232 aArgs2[ 0 ].Value <<= aDestMimeType; 233 aArgs2[ 1 ].Name = TKGet( TK_OutputStream ); 234 aArgs2[ 1 ].Value <<= xOutputStream; 235 xGraphicProvider->storeGraphic( xGraphic, aArgs2 ); 236 } 237 xPropSet->getPropertyValue( OUString::createFromAscii( "Uri" ) ) >>= sURL; 238 } 239 } 240 catch( Exception& ) 241 { 242 } 243 return sURL; 244 } 245 246 void InformationDialog::InitDialog() 247 { 248 sal_Int32 nDialogHeight = DIALOG_HEIGHT; 249 if ( !maSaveAsURL.getLength() ) 250 nDialogHeight -= 22; 251 252 // setting the dialog properties 253 OUString pNames[] = { 254 TKGet( TK_Closeable ), 255 TKGet( TK_Height ), 256 TKGet( TK_Moveable ), 257 TKGet( TK_PositionX ), 258 TKGet( TK_PositionY ), 259 TKGet( TK_Title ), 260 TKGet( TK_Width ) }; 261 262 Any pValues[] = { 263 Any( sal_True ), 264 Any( nDialogHeight ), 265 Any( sal_True ), 266 Any( sal_Int32( 245 ) ), 267 Any( sal_Int32( 115 ) ), 268 Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ), 269 Any( sal_Int32( DIALOG_WIDTH ) ) }; 270 271 sal_Int32 nCount = sizeof( pNames ) / sizeof( OUString ); 272 273 Sequence< rtl::OUString > aNames( pNames, nCount ); 274 Sequence< Any > aValues( pValues, nCount ); 275 276 mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues ); 277 278 sal_Int64 nSource = mnSourceSize; 279 sal_Int64 nDest = mnDestSize; 280 281 PPPOptimizerTokenEnum eInfoString( STR_INFO_1 ); 282 if ( mnSourceSize ) 283 { 284 if ( mnDestSize ) 285 eInfoString = STR_INFO_1; 286 else 287 { 288 eInfoString = STR_INFO_2; 289 nDest = mnApproxSize; 290 } 291 } 292 else if ( mnDestSize ) 293 eInfoString = STR_INFO_3; 294 else 295 { 296 eInfoString = STR_INFO_4; 297 nDest = mnApproxSize; 298 } 299 300 rtl::OUString aTitle; 301 if ( maSaveAsURL.getLength() ) 302 { 303 Reference< XURLTransformer > xURLTransformer( mxMSF->getServiceManager()->createInstanceWithContext( 304 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) ), mxMSF ), UNO_QUERY ); 305 if ( xURLTransformer.is() ) 306 { 307 util::URL aURL, aPresentationURL; 308 aURL.Complete = maSaveAsURL; 309 xURLTransformer->parseSmart( aURL, rtl::OUString() ); 310 311 const OUString sFileProtocol( RTL_CONSTASCII_USTRINGPARAM( "file:///" ) ); 312 aPresentationURL.Complete = sFileProtocol.concat( aURL.Name ); 313 aTitle = xURLTransformer->getPresentation( aPresentationURL, sal_False ); 314 315 if ( aTitle.match( sFileProtocol, 0 ) ) 316 aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), rtl::OUString() ); 317 } 318 } 319 320 OUString aInfoString( getString( eInfoString ) ); 321 const OUString aOldSizePlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%OLDFILESIZE" ) ); 322 const OUString aNewSizePlaceholder( RTL_CONSTASCII_USTRINGPARAM( "%NEWFILESIZE" ) ); 323 const OUString aTitlePlaceholder( aTitle.getLength() ? OUString::createFromAscii( "%TITLE" ) : OUString::createFromAscii( "'%TITLE'" ) ); 324 325 sal_Int32 i = aInfoString.indexOf( aOldSizePlaceholder, 0 ); 326 if ( i >= 0 ) 327 aInfoString = aInfoString.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) ); 328 329 sal_Int32 j = aInfoString.indexOf( aNewSizePlaceholder, 0 ); 330 if ( j >= 0 ) 331 aInfoString = aInfoString.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) ); 332 333 sal_Int32 k = aInfoString.indexOf( aTitlePlaceholder, 0 ); 334 if ( k >= 0 ) 335 aInfoString = aInfoString.replaceAt( k, aTitlePlaceholder.getLength(), aTitle ); 336 337 com::sun::star::uno::Reference< com::sun::star::awt::XItemListener > xItemListener; 338 InsertImage( *this, rtl::OUString( rtl::OUString::createFromAscii( "aboutimage" ) ), ImpGetStandardImage( rtl::OUString::createFromAscii( "private:standardimage/query" ) ), 5, 5, 25, 25 ); 339 InsertFixedText( *this, rtl::OUString( rtl::OUString::createFromAscii( "fixedtext" ) ), aInfoString, PAGE_POS_X, 6, PAGE_WIDTH, 24, sal_True, 0 ); 340 if ( maSaveAsURL.getLength() ) 341 InsertCheckBox( *this, TKGet( TK_OpenNewDocument ), xItemListener, getString( STR_AUTOMATICALLY_OPEN ), PAGE_POS_X, 42, PAGE_WIDTH, 8, 1 ); 342 InsertButton( *this, rtl::OUString( rtl::OUString::createFromAscii( "button" ) ), mxActionListener, DIALOG_WIDTH / 2 - 25, nDialogHeight - 20, 50, 14, 2, STR_OK ); 343 344 sal_Bool bOpenNewDocument = mrbOpenNewDocument; 345 setControlProperty( TKGet( TK_OpenNewDocument ), TKGet( TK_State ), Any( (sal_Int16)bOpenNewDocument ) ); 346 } 347 348 // ----------------------------------------------------------------------------- 349 350 InformationDialog::InformationDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame, const rtl::OUString& rSaveAsURL, sal_Bool& rbOpenNewDocument, const sal_Int64& rSourceSize, const sal_Int64& rDestSize, const sal_Int64& rApproxSize ) : 351 UnoDialog( rxMSF, rxFrame ), 352 ConfigurationAccess( rxMSF, NULL ), 353 mxMSF( rxMSF ), 354 mxFrame( rxFrame ), 355 mxActionListener( new OKActionListener( *this ) ), 356 mnSourceSize( rSourceSize ), 357 mnDestSize( rDestSize ), 358 mnApproxSize( rApproxSize ), 359 mrbOpenNewDocument( rbOpenNewDocument ), 360 maSaveAsURL( rSaveAsURL ) 361 { 362 Reference< XFrame > xFrame( mxController->getFrame() ); 363 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() ); 364 Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW ); 365 createWindowPeer( xWindowPeer ); 366 367 InitDialog(); 368 } 369 370 // ----------------------------------------------------------------------------- 371 372 InformationDialog::~InformationDialog() 373 { 374 } 375 376 // ----------------------------------------------------------------------------- 377 378 sal_Bool InformationDialog::execute() 379 { 380 UnoDialog::execute(); 381 382 if ( maSaveAsURL.getLength() ) 383 { 384 sal_Int16 nInt16 = 0; 385 Any aAny( getControlProperty( TKGet( TK_OpenNewDocument ), TKGet( TK_State ) ) ); 386 if ( aAny >>= nInt16 ) 387 { 388 sal_Bool bOpenNewDocument = static_cast< sal_Bool >( nInt16 ); 389 mrbOpenNewDocument = bOpenNewDocument; 390 } 391 } 392 return mbStatus; 393 } 394 395 // ----------------------------------------------------------------------------- 396 397 void OKActionListener::actionPerformed( const ActionEvent& rEvent ) 398 throw ( com::sun::star::uno::RuntimeException ) 399 { 400 if ( rEvent.ActionCommand == rtl::OUString( rtl::OUString::createFromAscii( "button" ) ) ) 401 { 402 mrInformationDialog.endExecute( sal_True ); 403 } 404 } 405 void OKActionListener::disposing( const ::com::sun::star::lang::EventObject& /* Source */ ) 406 throw ( com::sun::star::uno::RuntimeException ) 407 { 408 } 409