1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ExtensionNotPresent.cxx,v $
10 * $Revision: 1.2.158.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_dbaccess.hxx"
32 #include "dbaccess_helpid.hrc"
33 #include "dbu_resource.hrc"
34 #include "ExtensionNotPresent.hrc"
35 #include "ExtensionNotPresent.hxx"
36 #include "moduledbu.hxx"
37 #include "UITools.hxx"
39 /** === begin UNO includes === **/
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 /** === end UNO includes === **/
46 #include <connectivity/dbconversion.hxx>
47 #include <svtools/syslocale.hxx>
48 #include <svx/globlmn.hrc>
49 #include <svx/svxids.hrc>
50 #include <tools/debug.hxx>
51 #include <tools/diagnose_ex.h>
52 #include <unotools/confignode.hxx>
53 #include <vcl/msgbox.hxx>
58 using namespace ::com::sun::star
;
59 using namespace ::comphelper
;
61 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
63 DBG_NAME( dbu_OExtensionNotPresentDialog
)
64 //========================================================================
65 // class OExtensionNotPresentDialog
66 //========================================================================
67 OExtensionNotPresentDialog::OExtensionNotPresentDialog( Window
* _pParent
, uno::Reference
< lang::XMultiServiceFactory
> _xORB
)
68 : ModalDialog( _pParent
, ModuleRes(RID_EXTENSION_NOT_PRESENT_DLG
) )
69 ,m_aFI_WARNING(this, ModuleRes(FI_WARNING
))
70 ,m_aFT_TEXT(this, ModuleRes(FT_TEXT
) )
71 ,m_aPB_DOWNLOAD(this, ModuleRes(PB_DOWNLOAD
))
72 ,m_aPB_CANCEL(this, ModuleRes(PB_CANCEL
))
73 ,m_xMultiServiceFactory(_xORB
)
75 DBG_CTOR( dbu_OExtensionNotPresentDialog
, NULL
);
79 SvtSysLocale aSysLocale
;
80 m_nLocale
= aSysLocale
.GetLocaleData().getLocale();
82 catch(uno::Exception
&)
86 // set a ClickHandler for the 'Download' button
87 m_aPB_DOWNLOAD
.SetClickHdl( LINK( this, OExtensionNotPresentDialog
, Download_Click
) );
89 // get message string out of the resource
90 String sText
= String( ModuleRes( RID_STR_EXTENSION_NOT_PRESENT
) );
91 // String sExtensionName = String( ModuleRes( RID_STR_EXTENSION_NAME ) );
92 String sExtensionName
= getFromConfigurationExtension("Name");
93 sText
.SearchAndReplaceAscii("%RPT_EXTENSION_NAME", sExtensionName
);
95 m_aFT_TEXT
.SetText(sText
);
97 // calulate the size of the text field
98 Rectangle
aPrimaryRect( Point(0,0), m_aFT_TEXT
.GetSizePixel() );
99 Rectangle
aSuggestedRect( GetTextRect( aPrimaryRect
, sText
, TEXT_DRAW_MULTILINE
| TEXT_DRAW_LEFT
) );
101 Size aTempSize
= LogicToPixel( Size(LEFT_PADDING
+ RIGHT_PADDING
, 1), MAP_APPFONT
); // real pixel size of LEFT and RIGHT_PADDING
102 sal_Int32 nWidthWithoutFixedText
= aTempSize
.getWidth() ;
103 sal_Int32 nHeightWithoutFixedText
= GetSizePixel().getHeight() - m_aFT_TEXT
.GetSizePixel().getHeight();
105 Size aNewSize
= aSuggestedRect
.GetSize();
106 m_aFT_TEXT
.SetSizePixel( aNewSize
);
107 sal_Int32 nNewWidth
= nWidthWithoutFixedText
+ aSuggestedRect
.GetWidth();
108 sal_Int32 nNewHeight
= nHeightWithoutFixedText
+ aSuggestedRect
.GetHeight();
110 // set new window width & height
111 Size aDialogWindowSize
= GetSizePixel();
112 aDialogWindowSize
.setWidth( nNewWidth
);
113 aDialogWindowSize
.setHeight( nNewHeight
);
114 SetSizePixel(aDialogWindowSize
);
117 sal_Int32 nWindowWidth
= GetSizePixel().getWidth();
118 sal_Int32 nWindowHeight
= GetSizePixel().getHeight();
120 Size aButtonSize
= LogicToPixel( Size(BUTTON_WIDTH
, BUTTON_HEIGHT
), MAP_APPFONT
); // real pixel size of a button
122 Point aNewPos
= m_aPB_DOWNLOAD
.GetPosPixel();
123 aNewPos
.setX(nWindowWidth
/ 2 - m_aPB_DOWNLOAD
.GetSizePixel().getWidth() - 8);
124 aNewPos
.setY(nWindowHeight
- aButtonSize
.getHeight() - 5);
125 m_aPB_DOWNLOAD
.SetPosPixel(aNewPos
);
127 aNewPos
= m_aPB_CANCEL
.GetPosPixel();
128 aNewPos
.setX(nWindowWidth
/ 2 + 8);
129 aNewPos
.setY(nWindowHeight
- aButtonSize
.getHeight() - 5);
130 m_aPB_CANCEL
.SetPosPixel(aNewPos
);
132 m_aFI_WARNING
.SetImage(WarningBox::GetStandardImage());
134 // set an image in high contrast
135 // m_aFI_WARNING.SetModeImage(Image(BMP_EXCEPTION_WARNING_SCH), BMP_COLOR_HIGHCONTRAST);
138 // WinBits aBits = m_aFI_WARNING.GetStyle();
139 // aBits |= WB_SCALE;
140 // m_aFI_WARNING.SetStyle(aBits);
142 // Size aImageSize = m_aFI_WARNING.GetSizePixel();
143 // (void) aImageSize;
144 // m_aFI_WARNING.Resize();
151 //------------------------------------------------------------------------
152 OExtensionNotPresentDialog::~OExtensionNotPresentDialog()
154 DBG_DTOR( dbu_OExtensionNotPresentDialog
, NULL
);
156 // -----------------------------------------------------------------------------
157 short OExtensionNotPresentDialog::Execute()
159 DBG_CHKTHIS( dbu_OExtensionNotPresentDialog
,NULL
);
160 short nRet
= ModalDialog::Execute();
166 //------------------------------------------------------------------------------
168 uno::Reference
< com::sun::star::system::XSystemShellExecute
> OExtensionNotPresentDialog::getShellExecuter() const
170 uno::Reference
<com::sun::star::system::XSystemShellExecute
> xExecuter( m_xMultiServiceFactory
->createInstance( UNISTRING( "com.sun.star.system.SystemShellExecute" )), uno::UNO_QUERY_THROW
);
173 // -----------------------------------------------------------------------------
174 rtl::OUString
OExtensionNotPresentDialog::getFromConfigurationExtension(rtl::OUString
const& _sPropertyName
) const
176 // get the URL to open in a browser from Configuration
177 static const ::rtl::OUString
sConfigName( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.ReportDesign/Extension" ) );
179 ::utl::OConfigurationTreeRoot
aConfiguration( ::utl::OConfigurationTreeRoot::createWithServiceFactory( m_xMultiServiceFactory
, sConfigName
) );
181 rtl::OUString aValue
;
182 aConfiguration
.getNodeValue( _sPropertyName
) >>= aValue
;
186 // -----------------------------------------------------------------------------
187 rtl::OUString
OExtensionNotPresentDialog::getFromConfigurationExtension(rtl::OString
const& _sPropertyName
) const
189 return getFromConfigurationExtension(rtl::OStringToOUString( _sPropertyName
, RTL_TEXTENCODING_UTF8
) );
192 // -----------------------------------------------------------------------------
193 // handle the click on the download button
194 IMPL_LINK( OExtensionNotPresentDialog
, Download_Click
, PushButton
*, EMPTYARG
)
200 rtl::OUString suDownloadURL
= getFromConfigurationExtension("DownloadURL");
201 if (suDownloadURL
.getLength() == 0)
204 suDownloadURL
= UNISTRING("http://extensions.go-oo.org");
207 // open such URL in a browser
208 uno::Reference
< com::sun::star::system::XSystemShellExecute
> xShellExecute( getShellExecuter() );
209 xShellExecute
->execute( suDownloadURL
, ::rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::DEFAULTS
);
211 catch( const uno::Exception
& )
213 DBG_UNHANDLED_EXCEPTION();
218 // =============================================================================
220 // =============================================================================