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 "informationdialog.hxx"
22 #include "optimizationstats.hxx"
23 #include <com/sun/star/graphic/GraphicProvider.hpp>
24 #include <com/sun/star/graphic/XGraphicProvider.hpp>
25 #include <com/sun/star/graphic/XGraphic.hpp>
26 #include <com/sun/star/io/TempFile.hpp>
27 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
28 #include "com/sun/star/util/URL.hpp"
29 #include "com/sun/star/util/URLTransformer.hpp"
30 #include "com/sun/star/util/XURLTransformer.hpp"
31 #include <rtl/ustrbuf.hxx>
32 #include <sal/macros.h>
34 #define DIALOG_WIDTH 240
35 #define DIALOG_HEIGHT 80
37 #define PAGE_WIDTH ( DIALOG_WIDTH - PAGE_POS_X ) - 6
40 // ---------------------
41 // - INFORMATIONDIALOG -
42 // ---------------------
44 using namespace ::rtl
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::io
;
47 using namespace ::com::sun::star::ui
;
48 using namespace ::com::sun::star::awt
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::util
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::frame
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::script
;
55 using namespace ::com::sun::star::container
;
59 // -----------------------------------------------------------------------------
61 OUString
InsertFixedText( InformationDialog
& rInformationDialog
, const OUString
& rControlName
, const OUString
& rLabel
,
62 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Bool bMultiLine
, sal_Int16 nTabIndex
)
67 TKGet( TK_MultiLine
),
68 TKGet( TK_PositionX
),
69 TKGet( TK_PositionY
),
84 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
86 Sequence
< OUString
> aNames( pNames
, nCount
);
87 Sequence
< Any
> aValues( pValues
, nCount
);
89 rInformationDialog
.insertFixedText( rControlName
, aNames
, aValues
);
94 InformationDialog
& rInformationDialog
,
95 const OUString
& rControlName
,
103 OUString pNames
[] = {
106 TKGet( TK_ImageURL
),
107 TKGet( TK_PositionX
),
108 TKGet( TK_PositionY
),
109 TKGet( TK_ScaleImage
),
113 Any( sal_Int16( 0 ) ),
120 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
122 Sequence
< OUString
> aNames( pNames
, nCount
);
123 Sequence
< Any
> aValues( pValues
, nCount
);
125 rInformationDialog
.insertImage( rControlName
, aNames
, aValues
);
129 OUString
InsertCheckBox( InformationDialog
& rInformationDialog
, const OUString
& rControlName
,
130 const Reference
< XItemListener
> xItemListener
, const OUString
& rLabel
,
131 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nTabIndex
)
133 OUString pNames
[] = {
137 TKGet( TK_PositionX
),
138 TKGet( TK_PositionY
),
140 TKGet( TK_TabIndex
),
153 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
155 Sequence
< OUString
> aNames( pNames
, nCount
);
156 Sequence
< Any
> aValues( pValues
, nCount
);
158 Reference
< XCheckBox
> xCheckBox( rInformationDialog
.insertCheckBox( rControlName
, aNames
, aValues
) );
159 if ( xItemListener
.is() )
160 xCheckBox
->addItemListener( xItemListener
);
164 OUString
InsertButton( InformationDialog
& rInformationDialog
, const OUString
& rControlName
, Reference
< XActionListener
>& xActionListener
,
165 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nTabIndex
, PPPOptimizerTokenEnum nResID
)
167 OUString pNames
[] = {
171 TKGet( TK_PositionX
),
172 TKGet( TK_PositionY
),
173 TKGet( TK_PushButtonType
),
175 TKGet( TK_TabIndex
),
181 Any( rInformationDialog
.getString( nResID
) ),
184 Any( static_cast< sal_Int16
>( PushButtonType_OK
) ),
190 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
192 Sequence
< OUString
> aNames( pNames
, nCount
);
193 Sequence
< Any
> aValues( pValues
, nCount
);
195 rInformationDialog
.insertButton( rControlName
, xActionListener
, aNames
, aValues
);
200 static OUString
ImpValueOfInMB( const sal_Int64
& rVal
)
202 double fVal( static_cast<double>( rVal
) );
205 OUStringBuffer
aVal( OUString::valueOf( fVal
) );
206 sal_Int32
nX( OUString( aVal
.getStr() ).indexOf( '.', 0 ) );
208 aVal
.setLength( nX
+ 2 );
209 return aVal
.makeStringAndClear();
212 void InformationDialog::InitDialog()
214 sal_Int32 nDialogHeight
= DIALOG_HEIGHT
;
215 if ( maSaveAsURL
.isEmpty() )
218 // setting the dialog properties
219 OUString pNames
[] = {
220 TKGet( TK_Closeable
),
222 TKGet( TK_Moveable
),
223 TKGet( TK_PositionX
),
224 TKGet( TK_PositionY
),
230 Any( nDialogHeight
),
232 Any( sal_Int32( 245 ) ),
233 Any( sal_Int32( 115 ) ),
234 Any( getString( STR_SUN_OPTIMIZATION_WIZARD2
) ),
235 Any( sal_Int32( DIALOG_WIDTH
) ) };
237 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
239 Sequence
< OUString
> aNames( pNames
, nCount
);
240 Sequence
< Any
> aValues( pValues
, nCount
);
242 mxDialogModelMultiPropertySet
->setPropertyValues( aNames
, aValues
);
244 sal_Int64 nSource
= mnSourceSize
;
245 sal_Int64 nDest
= mnDestSize
;
247 PPPOptimizerTokenEnum
eInfoString( STR_INFO_1
);
251 eInfoString
= STR_INFO_1
;
254 eInfoString
= STR_INFO_2
;
255 nDest
= mnApproxSize
;
258 else if ( mnDestSize
)
259 eInfoString
= STR_INFO_3
;
262 eInfoString
= STR_INFO_4
;
263 nDest
= mnApproxSize
;
267 if ( !maSaveAsURL
.isEmpty() )
269 Reference
< XURLTransformer
> xURLTransformer( URLTransformer::create(mxMSF
) );
270 util::URL aURL
, aPresentationURL
;
271 aURL
.Complete
= maSaveAsURL
;
272 xURLTransformer
->parseSmart( aURL
, OUString() );
274 const OUString
sFileProtocol( "file:///" );
275 aPresentationURL
.Complete
= sFileProtocol
.concat( aURL
.Name
);
276 aTitle
= xURLTransformer
->getPresentation( aPresentationURL
, sal_False
);
278 if ( aTitle
.match( sFileProtocol
, 0 ) )
279 aTitle
= aTitle
.replaceAt( 0, sFileProtocol
.getLength(), OUString() );
282 OUString
aInfoString( getString( eInfoString
) );
283 const OUString
aOldSizePlaceholder( "%OLDFILESIZE" );
284 const OUString
aNewSizePlaceholder( "%NEWFILESIZE" );
285 const OUString
aTitlePlaceholder( !aTitle
.isEmpty() ? OUString("%TITLE" )
286 : OUString("'%TITLE'") );
288 sal_Int32 i
= aInfoString
.indexOf( aOldSizePlaceholder
, 0 );
290 aInfoString
= aInfoString
.replaceAt( i
, aOldSizePlaceholder
.getLength(), ImpValueOfInMB( nSource
) );
292 sal_Int32 j
= aInfoString
.indexOf( aNewSizePlaceholder
, 0 );
294 aInfoString
= aInfoString
.replaceAt( j
, aNewSizePlaceholder
.getLength(), ImpValueOfInMB( nDest
) );
296 sal_Int32 k
= aInfoString
.indexOf( aTitlePlaceholder
, 0 );
298 aInfoString
= aInfoString
.replaceAt( k
, aTitlePlaceholder
.getLength(), aTitle
);
300 com::sun::star::uno::Reference
< com::sun::star::awt::XItemListener
> xItemListener
;
302 OUString( "aboutimage" ),
303 OUString( "private:standardimage/query" ),
304 5, 5, 25, 25, sal_False
);
305 InsertFixedText( *this, OUString("fixedtext"), aInfoString
, PAGE_POS_X
, 6, PAGE_WIDTH
, 24, sal_True
, 0 );
306 if ( !maSaveAsURL
.isEmpty() )
307 InsertCheckBox( *this, TKGet( TK_OpenNewDocument
), xItemListener
, getString( STR_AUTOMATICALLY_OPEN
), PAGE_POS_X
, 42, PAGE_WIDTH
, 8, 1 );
308 InsertButton( *this, OUString("button"), mxActionListener
, DIALOG_WIDTH
/ 2 - 25, nDialogHeight
- 20, 50, 14, 2, STR_OK
);
310 sal_Bool bOpenNewDocument
= mrbOpenNewDocument
;
311 setControlProperty( TKGet( TK_OpenNewDocument
), TKGet( TK_State
), Any( (sal_Int16
)bOpenNewDocument
) );
314 // -----------------------------------------------------------------------------
316 InformationDialog::InformationDialog( const Reference
< XComponentContext
> &rxMSF
, Reference
< XFrame
>& rxFrame
, const OUString
& rSaveAsURL
, sal_Bool
& rbOpenNewDocument
, const sal_Int64
& rSourceSize
, const sal_Int64
& rDestSize
, const sal_Int64
& rApproxSize
) :
317 UnoDialog( rxMSF
, rxFrame
),
318 ConfigurationAccess( rxMSF
, NULL
),
321 mxActionListener( new OKActionListener( *this ) ),
322 mnSourceSize( rSourceSize
),
323 mnDestSize( rDestSize
),
324 mnApproxSize( rApproxSize
),
325 mrbOpenNewDocument( rbOpenNewDocument
),
326 maSaveAsURL( rSaveAsURL
)
328 Reference
< XFrame
> xFrame( mxController
->getFrame() );
329 Reference
< XWindow
> xContainerWindow( xFrame
->getContainerWindow() );
330 Reference
< XWindowPeer
> xWindowPeer( xContainerWindow
, UNO_QUERY_THROW
);
331 createWindowPeer( xWindowPeer
);
336 // -----------------------------------------------------------------------------
338 InformationDialog::~InformationDialog()
342 // -----------------------------------------------------------------------------
344 sal_Bool
InformationDialog::execute()
346 UnoDialog::execute();
348 if ( !maSaveAsURL
.isEmpty() )
350 sal_Int16 nInt16
= 0;
351 Any
aAny( getControlProperty( TKGet( TK_OpenNewDocument
), TKGet( TK_State
) ) );
352 if ( aAny
>>= nInt16
)
354 sal_Bool bOpenNewDocument
= static_cast< sal_Bool
>( nInt16
);
355 mrbOpenNewDocument
= bOpenNewDocument
;
361 // -----------------------------------------------------------------------------
363 void OKActionListener::actionPerformed( const ActionEvent
& rEvent
)
364 throw ( com::sun::star::uno::RuntimeException
)
366 if ( rEvent
.ActionCommand
== "button" )
368 mrInformationDialog
.endExecute( sal_True
);
371 void OKActionListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
372 throw ( com::sun::star::uno::RuntimeException
)
376 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */