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
41 // - INFORMATIONDIALOG -
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::io
;
46 using namespace ::com::sun::star::ui
;
47 using namespace ::com::sun::star::awt
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::util
;
50 using namespace ::com::sun::star::lang
;
51 using namespace ::com::sun::star::frame
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::script
;
54 using namespace ::com::sun::star::container
;
60 OUString
InsertFixedText( InformationDialog
& rInformationDialog
, const OUString
& rControlName
, const OUString
& rLabel
,
61 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, bool bMultiLine
, sal_Int16 nTabIndex
)
66 OUString("MultiLine"),
67 OUString("PositionX"),
68 OUString("PositionY"),
83 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
85 Sequence
< OUString
> aNames( pNames
, nCount
);
86 Sequence
< Any
> aValues( pValues
, nCount
);
88 rInformationDialog
.insertFixedText( rControlName
, aNames
, aValues
);
93 InformationDialog
& rInformationDialog
,
94 const OUString
& rControlName
,
102 OUString pNames
[] = {
105 OUString("ImageURL"),
106 OUString("PositionX"),
107 OUString("PositionY"),
108 OUString("ScaleImage"),
112 Any( sal_Int16( 0 ) ),
119 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
121 Sequence
< OUString
> aNames( pNames
, nCount
);
122 Sequence
< Any
> aValues( pValues
, nCount
);
124 rInformationDialog
.insertImage( rControlName
, aNames
, aValues
);
128 OUString
InsertCheckBox( InformationDialog
& rInformationDialog
, const OUString
& rControlName
,
129 const Reference
< XItemListener
>& rItemListener
, const OUString
& rLabel
,
130 sal_Int32 nXPos
, sal_Int32 nYPos
, sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int16 nTabIndex
)
132 OUString pNames
[] = {
136 OUString("PositionX"),
137 OUString("PositionY"),
139 OUString("TabIndex"),
152 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
154 Sequence
< OUString
> aNames( pNames
, nCount
);
155 Sequence
< Any
> aValues( pValues
, nCount
);
157 Reference
< XCheckBox
> xCheckBox( rInformationDialog
.insertCheckBox( rControlName
, aNames
, aValues
) );
158 if ( rItemListener
.is() )
159 xCheckBox
->addItemListener( rItemListener
);
163 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
)
166 OUString pNames
[] = {
170 OUString("PositionX"),
171 OUString("PositionY"),
172 OUString("PushButtonType"),
174 OUString("TabIndex"),
180 Any( rInformationDialog
.getString( nResID
) ),
183 Any( static_cast< sal_Int16
>( PushButtonType_OK
) ),
189 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
191 Sequence
< OUString
> aNames( pNames
, nCount
);
192 Sequence
< Any
> aValues( pValues
, nCount
);
194 rInformationDialog
.insertButton( rControlName
, xActionListener
, aNames
, aValues
);
199 static OUString
ImpValueOfInMB( const sal_Int64
& rVal
)
201 double fVal( static_cast<double>( rVal
) );
204 OUStringBuffer
aVal( OUString::number( fVal
) );
205 sal_Int32
nX( OUString( aVal
.getStr() ).indexOf( '.', 0 ) );
207 aVal
.setLength( nX
+ 2 );
208 return aVal
.makeStringAndClear();
211 void InformationDialog::InitDialog()
213 sal_Int32 nDialogHeight
= DIALOG_HEIGHT
;
214 if ( maSaveAsURL
.isEmpty() )
217 // setting the dialog properties
218 OUString pNames
[] = {
219 OUString("Closeable"),
221 OUString("Moveable"),
222 OUString("PositionX"),
223 OUString("PositionY"),
229 Any( nDialogHeight
),
231 Any( sal_Int32( 245 ) ),
232 Any( sal_Int32( 115 ) ),
233 Any( getString( STR_SUN_OPTIMIZATION_WIZARD2
) ),
234 Any( sal_Int32( DIALOG_WIDTH
) ) };
236 sal_Int32 nCount
= SAL_N_ELEMENTS( pNames
);
238 Sequence
< OUString
> aNames( pNames
, nCount
);
239 Sequence
< Any
> aValues( pValues
, nCount
);
241 mxDialogModelMultiPropertySet
->setPropertyValues( aNames
, aValues
);
243 sal_Int64 nSource
= mnSourceSize
;
244 sal_Int64 nDest
= mnDestSize
;
246 PPPOptimizerTokenEnum
eInfoString( STR_INFO_1
);
250 eInfoString
= STR_INFO_1
;
253 eInfoString
= STR_INFO_2
;
254 nDest
= mnApproxSize
;
257 else if ( mnDestSize
)
258 eInfoString
= STR_INFO_3
;
261 eInfoString
= STR_INFO_4
;
262 nDest
= mnApproxSize
;
266 if ( !maSaveAsURL
.isEmpty() )
268 Reference
< XURLTransformer
> xURLTransformer( URLTransformer::create(UnoDialog::mxContext
) );
269 util::URL aURL
, aPresentationURL
;
270 aURL
.Complete
= maSaveAsURL
;
271 xURLTransformer
->parseSmart( aURL
, OUString() );
273 const OUString
sFileProtocol( "file:///" );
274 aPresentationURL
.Complete
= sFileProtocol
.concat( aURL
.Name
);
275 aTitle
= xURLTransformer
->getPresentation( aPresentationURL
, sal_False
);
277 if ( aTitle
.match( sFileProtocol
, 0 ) )
278 aTitle
= aTitle
.replaceAt( 0, sFileProtocol
.getLength(), OUString() );
281 OUString
aInfoString( getString( eInfoString
) );
282 const OUString
aOldSizePlaceholder( "%OLDFILESIZE" );
283 const OUString
aNewSizePlaceholder( "%NEWFILESIZE" );
284 const OUString
aTitlePlaceholder( !aTitle
.isEmpty() ? OUString("%TITLE" )
285 : OUString("'%TITLE'") );
287 sal_Int32 i
= aInfoString
.indexOf( aOldSizePlaceholder
, 0 );
289 aInfoString
= aInfoString
.replaceAt( i
, aOldSizePlaceholder
.getLength(), ImpValueOfInMB( nSource
) );
291 sal_Int32 j
= aInfoString
.indexOf( aNewSizePlaceholder
, 0 );
293 aInfoString
= aInfoString
.replaceAt( j
, aNewSizePlaceholder
.getLength(), ImpValueOfInMB( nDest
) );
295 sal_Int32 k
= aInfoString
.indexOf( aTitlePlaceholder
, 0 );
297 aInfoString
= aInfoString
.replaceAt( k
, aTitlePlaceholder
.getLength(), aTitle
);
299 com::sun::star::uno::Reference
< com::sun::star::awt::XItemListener
> xItemListener
;
301 OUString( "aboutimage" ),
302 OUString( "private:standardimage/query" ),
303 5, 5, 25, 25, false );
304 InsertFixedText( *this, OUString("fixedtext"), aInfoString
, PAGE_POS_X
, 6, PAGE_WIDTH
, 24, true, 0 );
305 if ( !maSaveAsURL
.isEmpty() )
306 InsertCheckBox( *this, "OpenNewDocument", xItemListener
, getString( STR_AUTOMATICALLY_OPEN
), PAGE_POS_X
, 42, PAGE_WIDTH
, 8, 1 );
307 InsertButton( *this, OUString("button"), mxActionListener
, DIALOG_WIDTH
/ 2 - 25, nDialogHeight
- 20, 50, 14, 2, STR_OK
);
309 bool bOpenNewDocument
= mrbOpenNewDocument
;
310 setControlProperty( "OpenNewDocument", "State", Any( (sal_Int16
)bOpenNewDocument
) );
315 InformationDialog::InformationDialog( const Reference
< XComponentContext
> &rxContext
, Reference
< XFrame
>& rxFrame
, const OUString
& rSaveAsURL
, bool& rbOpenNewDocument
, const sal_Int64
& rSourceSize
, const sal_Int64
& rDestSize
, const sal_Int64
& rApproxSize
) :
316 UnoDialog( rxContext
, rxFrame
),
317 ConfigurationAccess( rxContext
, NULL
),
319 mxActionListener( new OKActionListener( *this ) ),
320 mnSourceSize( rSourceSize
),
321 mnDestSize( rDestSize
),
322 mnApproxSize( rApproxSize
),
323 mrbOpenNewDocument( rbOpenNewDocument
),
324 maSaveAsURL( rSaveAsURL
)
326 Reference
< XFrame
> xFrame( mxController
->getFrame() );
327 Reference
< XWindow
> xContainerWindow( xFrame
->getContainerWindow() );
328 Reference
< XWindowPeer
> xWindowPeer( xContainerWindow
, UNO_QUERY_THROW
);
329 createWindowPeer( xWindowPeer
);
336 InformationDialog::~InformationDialog()
342 bool InformationDialog::execute()
344 UnoDialog::execute();
346 if ( !maSaveAsURL
.isEmpty() )
348 sal_Int16 nInt16
= 0;
349 Any
aAny( getControlProperty( "OpenNewDocument", "State" ) );
350 if ( aAny
>>= nInt16
)
352 bool bOpenNewDocument
= static_cast< bool >( nInt16
);
353 mrbOpenNewDocument
= bOpenNewDocument
;
361 void OKActionListener::actionPerformed( const ActionEvent
& rEvent
)
362 throw ( com::sun::star::uno::RuntimeException
, std::exception
)
364 if ( rEvent
.ActionCommand
== "button" )
366 mrInformationDialog
.endExecute( true );
369 void OKActionListener::disposing( const ::com::sun::star::lang::EventObject
& /* Source */ )
370 throw ( com::sun::star::uno::RuntimeException
, std::exception
)
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */