Files
libreoffice/sdext/source/minimizer/informationdialog.cxx

373 lines
12 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2007-05-11 13:01:25 +00:00
2007-05-11 13:01:25 +00:00
#include "informationdialog.hxx"
#include "optimizationstats.hxx"
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
2007-05-24 09:08:36 +00:00
#include "com/sun/star/util/URL.hpp"
#include "com/sun/star/util/URLTransformer.hpp"
2007-05-24 09:08:36 +00:00
#include "com/sun/star/util/XURLTransformer.hpp"
#include <rtl/ustrbuf.hxx>
#include <sal/macros.h>
2007-05-11 13:01:25 +00:00
#define DIALOG_WIDTH 240
2007-05-24 09:08:36 +00:00
#define DIALOG_HEIGHT 80
2007-05-11 13:01:25 +00:00
#define PAGE_POS_X 35
#define PAGE_WIDTH ( DIALOG_WIDTH - PAGE_POS_X ) - 6
2007-05-11 13:01:25 +00:00
// - INFORMATIONDIALOG -
2007-05-11 13:01:25 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::io;
2007-05-11 13:01:25 +00:00
using namespace ::com::sun::star::ui;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::script;
using namespace ::com::sun::star::container;
2007-05-11 13:01:25 +00:00
OUString InsertFixedText( InformationDialog& rInformationDialog, const OUString& rControlName, const OUString& rLabel,
sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, bool bMultiLine, sal_Int16 nTabIndex )
2007-05-11 13:01:25 +00:00
{
OUString pNames[] = {
OUString("Height"),
OUString("Label"),
OUString("MultiLine"),
OUString("PositionX"),
OUString("PositionY"),
OUString("Step"),
OUString("TabIndex"),
OUString("Width") };
2007-05-11 13:01:25 +00:00
Any pValues[] = {
Any( nHeight ),
Any( rLabel ),
Any( bMultiLine ),
Any( nXPos ),
Any( nYPos ),
Any( (sal_Int16)0 ),
Any( nTabIndex ),
Any( nWidth ) };
2010-12-03 13:59:22 +00:00
sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
2007-05-11 13:01:25 +00:00
Sequence< OUString > aNames( pNames, nCount );
2007-05-11 13:01:25 +00:00
Sequence< Any > aValues( pValues, nCount );
rInformationDialog.insertFixedText( rControlName, aNames, aValues );
return rControlName;
}
OUString InsertImage(
InformationDialog& rInformationDialog,
const OUString& rControlName,
const OUString& rURL,
sal_Int32 nPosX,
sal_Int32 nPosY,
sal_Int32 nWidth,
sal_Int32 nHeight,
bool bScale )
2007-05-11 13:01:25 +00:00
{
OUString pNames[] = {
OUString("Border"),
OUString("Height"),
OUString("ImageURL"),
OUString("PositionX"),
OUString("PositionY"),
OUString("ScaleImage"),
OUString("Width") };
2007-05-11 13:01:25 +00:00
Any pValues[] = {
Any( sal_Int16( 0 ) ),
2007-05-11 13:01:25 +00:00
Any( nHeight ),
Any( rURL ),
Any( nPosX ),
Any( nPosY ),
Any( bScale ),
2007-05-11 13:01:25 +00:00
Any( nWidth ) };
2010-12-03 13:59:22 +00:00
sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
2007-05-11 13:01:25 +00:00
Sequence< OUString > aNames( pNames, nCount );
2007-05-11 13:01:25 +00:00
Sequence< Any > aValues( pValues, nCount );
rInformationDialog.insertImage( rControlName, aNames, aValues );
return rControlName;
}
OUString InsertCheckBox( InformationDialog& rInformationDialog, const OUString& rControlName,
const Reference< XItemListener >& rItemListener, const OUString& rLabel,
2007-05-11 13:01:25 +00:00
sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex )
{
OUString pNames[] = {
OUString("Enabled"),
OUString("Height"),
OUString("Label"),
OUString("PositionX"),
OUString("PositionY"),
OUString("Step"),
OUString("TabIndex"),
OUString("Width") };
2007-05-11 13:01:25 +00:00
Any pValues[] = {
Any( sal_True ),
Any( nHeight ),
Any( rLabel ),
Any( nXPos ),
Any( nYPos ),
Any( (sal_Int16)0 ),
Any( nTabIndex ),
Any( nWidth ) };
2010-12-03 13:59:22 +00:00
sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
2007-05-11 13:01:25 +00:00
Sequence< OUString > aNames( pNames, nCount );
2007-05-11 13:01:25 +00:00
Sequence< Any > aValues( pValues, nCount );
Reference< XCheckBox > xCheckBox( rInformationDialog.insertCheckBox( rControlName, aNames, aValues ) );
if ( rItemListener.is() )
xCheckBox->addItemListener( rItemListener );
2007-05-11 13:01:25 +00:00
return rControlName;
}
OUString InsertButton( InformationDialog& rInformationDialog, const OUString& rControlName, Reference< XActionListener >& xActionListener,
2007-05-11 13:01:25 +00:00
sal_Int32 nXPos, sal_Int32 nYPos, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nTabIndex, PPPOptimizerTokenEnum nResID )
{
OUString pNames[] = {
OUString("Enabled"),
OUString("Height"),
OUString("Label"),
OUString("PositionX"),
OUString("PositionY"),
OUString("PushButtonType"),
OUString("Step"),
OUString("TabIndex"),
OUString("Width") };
2007-05-11 13:01:25 +00:00
Any pValues[] = {
Any( sal_True ),
Any( nHeight ),
Any( rInformationDialog.getString( nResID ) ),
Any( nXPos ),
Any( nYPos ),
Any( static_cast< sal_Int16 >( PushButtonType_OK ) ),
Any( (sal_Int16)0 ),
Any( nTabIndex ),
Any( nWidth ) };
2010-12-03 13:59:22 +00:00
sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
2007-05-11 13:01:25 +00:00
Sequence< OUString > aNames( pNames, nCount );
2007-05-11 13:01:25 +00:00
Sequence< Any > aValues( pValues, nCount );
rInformationDialog.insertButton( rControlName, xActionListener, aNames, aValues );
return rControlName;
}
static OUString ImpValueOfInMB( const sal_Int64& rVal )
{
double fVal( static_cast<double>( rVal ) );
fVal /= ( 1 << 20 );
fVal += 0.05;
OUStringBuffer aVal( OUString::number( fVal ) );
sal_Int32 nX( OUString( aVal.getStr() ).indexOf( '.' ) );
2007-05-11 13:01:25 +00:00
if ( nX > 0 )
aVal.setLength( nX + 2 );
return aVal.makeStringAndClear();
}
void InformationDialog::InitDialog()
{
2007-05-24 09:08:36 +00:00
sal_Int32 nDialogHeight = DIALOG_HEIGHT;
if ( maSaveAsURL.isEmpty() )
2007-05-24 09:08:36 +00:00
nDialogHeight -= 22;
2007-05-11 13:01:25 +00:00
// setting the dialog properties
Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at <http://lists.freedesktop.org/archives/libreoffice/2013-May/052449.html> "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel<UnoControlDialogModel> instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998
2013-05-24 22:44:30 +02:00
OUString pNames[] = {
OUString("Closeable"),
OUString("Height"),
OUString("Moveable"),
OUString("PositionX"),
OUString("PositionY"),
OUString("Title"),
OUString("Width") };
Revert "fdo#46808, Convert awt::UnoControlDialogModel to new style" This reverts commit 6c61b20a8d4a6dcac28801cde82a211fb7e30654. As discussed at <http://lists.freedesktop.org/archives/libreoffice/2013-May/052449.html> "Re: fdo#46808, Convert awt::UnoControlDialogModel to new style problem" why the odd change in 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again" appears to fix things again: The problem is that the implementation of the css.awt.UnoControlDialogModel involves UNO aggregation (IMPL_CREATE_INSTANCE_WITH_GEOMETRY(UnoControlDialogModel) in toolkit/soruce/helper/registerservices.cxx creating a OGeometryControlModel<UnoControlDialogModel> instance that aggregates a UnoControlDialogModel instance). That means that queryInterface can return a reference to something that is technically a different object, and that's what's happening here, and explains why calling setPropertyValue in two different ways on what logically appears to be a single object can end up calling two different implementations (of two different physical objects). (UNO aggregation is known to be broken and should not be used. Nevertheless, there's still code that does---code that is a horrible mess and hard to clean up.) That all this worked as intended in the past is just sheer luck, but any way of substantially touching it is asking for trouble. I'm going to revert 6c61b20a8d4a6dcac28801cde82a211fb7e30654 again. I wasn't able to revert without also reverting be50ad28f5bbdaeff527f646481ce263843c2401 "fdo#46808, Convert awt::XUnoControlDialog to new style," as the two were tightly dependant. Also reverts all the follow-up fixes cb4b6dde8fda2a5848e11063028bf44d72f85431 "-Werror,-Wuninitialized" (sans the const-ness fix in UpdateHandler::insertControlModel), 697a007c61b9cabceb9767fad87cd5822b300452 "Fix exception specifications," 2ce6828bbbf6ba181bb2276adeec279e74151ef6 "fix awt::UnoControlModelDialog crash," and 2e2a4827ce6708f0e8677dba9cc92e1479a44086 "scripting: get CreateUnoDialog() work again." Conflicts: basctl/source/dlged/dlged.cxx filter/source/t602/t602filter.cxx xmlscript/test/imexp.cxx Change-Id: I5d133468062f3ca36300db52fbd699be1ac72998
2013-05-24 22:44:30 +02:00
Any pValues[] = {
Any( sal_True ),
Any( nDialogHeight ),
Any( sal_True ),
Any( sal_Int32( 245 ) ),
Any( sal_Int32( 115 ) ),
Any( getString( STR_SUN_OPTIMIZATION_WIZARD2 ) ),
Any( sal_Int32( DIALOG_WIDTH ) ) };
sal_Int32 nCount = SAL_N_ELEMENTS( pNames );
Sequence< OUString > aNames( pNames, nCount );
Sequence< Any > aValues( pValues, nCount );
mxDialogModelMultiPropertySet->setPropertyValues( aNames, aValues );
2007-05-11 13:01:25 +00:00
sal_Int64 nSource = mnSourceSize;
sal_Int64 nDest = mnDestSize;
PPPOptimizerTokenEnum eInfoString( STR_INFO_1 );
if ( mnSourceSize )
{
if ( mnDestSize )
eInfoString = STR_INFO_1;
else
2007-05-24 09:08:36 +00:00
{
eInfoString = STR_INFO_2;
2007-05-24 09:08:36 +00:00
nDest = mnApproxSize;
}
}
else if ( mnDestSize )
eInfoString = STR_INFO_3;
else
2007-05-24 09:08:36 +00:00
{
eInfoString = STR_INFO_4;
2007-05-24 09:08:36 +00:00
nDest = mnApproxSize;
}
OUString aTitle;
if ( !maSaveAsURL.isEmpty() )
2007-05-24 09:08:36 +00:00
{
Reference< XURLTransformer > xURLTransformer( URLTransformer::create(UnoDialog::mxContext) );
util::URL aURL, aPresentationURL;
aURL.Complete = maSaveAsURL;
xURLTransformer->parseSmart( aURL, OUString() );
const OUString sFileProtocol( "file:///" );
aPresentationURL.Complete = sFileProtocol.concat( aURL.Name );
aTitle = xURLTransformer->getPresentation( aPresentationURL, sal_False );
if ( aTitle.match( sFileProtocol ) )
aTitle = aTitle.replaceAt( 0, sFileProtocol.getLength(), OUString() );
2007-05-24 09:08:36 +00:00
}
OUString aInfoString( getString( eInfoString ) );
const OUString aOldSizePlaceholder( "%OLDFILESIZE" );
const OUString aNewSizePlaceholder( "%NEWFILESIZE" );
const OUString aTitlePlaceholder( !aTitle.isEmpty() ? OUString("%TITLE" )
: OUString("'%TITLE'") );
sal_Int32 i = aInfoString.indexOf( aOldSizePlaceholder );
2007-05-11 13:01:25 +00:00
if ( i >= 0 )
aInfoString = aInfoString.replaceAt( i, aOldSizePlaceholder.getLength(), ImpValueOfInMB( nSource ) );
2007-05-11 13:01:25 +00:00
sal_Int32 j = aInfoString.indexOf( aNewSizePlaceholder );
2007-05-11 13:01:25 +00:00
if ( j >= 0 )
aInfoString = aInfoString.replaceAt( j, aNewSizePlaceholder.getLength(), ImpValueOfInMB( nDest ) );
sal_Int32 k = aInfoString.indexOf( aTitlePlaceholder );
if ( k >= 0 )
2007-05-24 09:08:36 +00:00
aInfoString = aInfoString.replaceAt( k, aTitlePlaceholder.getLength(), aTitle );
css::uno::Reference< css::awt::XItemListener > xItemListener;
InsertImage( *this,
"aboutimage",
"private:standardimage/query",
5, 5, 25, 25, false );
InsertFixedText( *this, "fixedtext", aInfoString, PAGE_POS_X, 6, PAGE_WIDTH, 24, true, 0 );
if ( !maSaveAsURL.isEmpty() )
InsertCheckBox( *this, "OpenNewDocument", xItemListener, getString( STR_AUTOMATICALLY_OPEN ), PAGE_POS_X, 42, PAGE_WIDTH, 8, 1 );
InsertButton( *this, "button", mxActionListener, DIALOG_WIDTH / 2 - 25, nDialogHeight - 20, 50, 14, 2, STR_OK );
bool bOpenNewDocument = mrbOpenNewDocument;
setControlProperty( "OpenNewDocument", "State", Any( (sal_Int16)bOpenNewDocument ) );
2007-05-11 13:01:25 +00:00
}
2007-05-11 13:01:25 +00:00
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 ) :
UnoDialog( rxContext, rxFrame ),
ConfigurationAccess( rxContext, nullptr ),
2007-05-11 13:01:25 +00:00
mxActionListener( new OKActionListener( *this ) ),
mnSourceSize( rSourceSize ),
mnDestSize( rDestSize ),
mnApproxSize( rApproxSize ),
2007-05-24 09:08:36 +00:00
mrbOpenNewDocument( rbOpenNewDocument ),
maSaveAsURL( rSaveAsURL )
2007-05-11 13:01:25 +00:00
{
Reference< XFrame > xFrame( mxController->getFrame() );
Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
Reference< XWindowPeer > xWindowPeer( xContainerWindow, UNO_QUERY_THROW );
createWindowPeer( xWindowPeer );
InitDialog();
}
2007-05-11 13:01:25 +00:00
InformationDialog::~InformationDialog()
{
}
2007-05-11 13:01:25 +00:00
void InformationDialog::execute()
2007-05-11 13:01:25 +00:00
{
UnoDialog::execute();
if ( !maSaveAsURL.isEmpty() )
2007-05-11 13:01:25 +00:00
{
2007-10-29 11:30:01 +00:00
sal_Int16 nInt16 = 0;
Any aAny( getControlProperty( "OpenNewDocument", "State" ) );
2007-05-24 09:08:36 +00:00
if ( aAny >>= nInt16 )
{
bool bOpenNewDocument = static_cast< bool >( nInt16 );
2007-05-24 09:08:36 +00:00
mrbOpenNewDocument = bOpenNewDocument;
}
2007-05-11 13:01:25 +00:00
}
}
2007-05-11 13:01:25 +00:00
void OKActionListener::actionPerformed( const ActionEvent& rEvent )
throw ( css::uno::RuntimeException, std::exception )
2007-05-11 13:01:25 +00:00
{
if ( rEvent.ActionCommand == "button" )
2007-05-11 13:01:25 +00:00
{
mrInformationDialog.endExecute( true );
2007-05-11 13:01:25 +00:00
}
}
void OKActionListener::disposing( const css::lang::EventObject& /* Source */ )
throw ( css::uno::RuntimeException, std::exception )
2007-05-11 13:01:25 +00:00
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */