Update ooo320-m1
[ooovba.git] / svx / source / cui / optimprove.cxx
blobe644cc58d7b8a5c66a41b6cb1b166e9924e4fc1a
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: optimprove.cxx,v $
10 * $Revision: 1.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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
37 // include ---------------------------------------------------------------
39 #define _SVX_OPTIMPROVE_CXX
41 #include <svx/optimprove.hxx>
42 #include <svx/dialmgr.hxx>
43 #include <vcl/msgbox.hxx>
45 #include "optimprove.hrc"
46 #include "helpid.hrc"
47 #include <svx/dialogs.hrc>
49 #include <com/sun/star/uno/Any.hxx>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/system/XSystemShellExecute.hpp>
52 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
53 #include <com/sun/star/oooimprovement/XCoreController.hpp>
54 #include <comphelper/configurationhelper.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <comphelper/uieventslogger.hxx>
57 #include <tools/testtoolloader.hxx>
59 namespace lang = ::com::sun::star::lang;
60 namespace uno = ::com::sun::star::uno;
61 using namespace com::sun::star::system;
63 // class SvxImprovementPage ----------------------------------------------
65 SvxImprovementPage::SvxImprovementPage( Window* pParent ) :
67 TabPage( pParent, SVX_RES( RID_SVXPAGE_IMPROVEMENT ) ),
69 m_aImproveFL ( this, SVX_RES( FL_IMPROVE ) ),
70 m_aInvitationFT ( this, SVX_RES( FT_INVITATION ) ),
71 m_aYesRB ( this, SVX_RES( RB_YES ) ),
72 m_aNoRB ( this, SVX_RES( RB_NO ) ),
73 m_aDataFL ( this, SVX_RES( FL_DATA ) ),
74 m_aNumberOfReportsFT ( this, SVX_RES( FT_NR_REPORTS ) ),
75 m_aNumberOfReportsValueFT ( this, SVX_RES( FT_NR_REPORTS_VALUE ) ),
76 m_aNumberOfActionsFT ( this, SVX_RES( FT_NR_ACTIONS ) ),
77 m_aNumberOfActionsValueFT ( this, SVX_RES( FT_NR_ACTIONS_VALUE ) ),
78 m_aShowDataPB ( this, SVX_RES( PB_SHOWDATA ) ),
80 m_sInfo ( SVX_RES( STR_INFO ) ),
81 m_sMoreInfo ( SVX_RES( STR_MOREINFO ) )
84 FreeResource();
86 m_aInvitationFT.Show();
87 m_aDataFL.Hide();
88 m_aNumberOfReportsFT.Hide();
89 m_aNumberOfReportsValueFT.Hide();
90 m_aNumberOfActionsFT.Hide();
91 m_aNumberOfActionsValueFT.Hide();
92 m_aShowDataPB.Hide();
94 Size aNewSize = m_aInvitationFT.GetSizePixel();
95 const long nMinWidth = m_aYesRB.CalcMinimumSize().Width();
96 const long nNewWidth = std::max( aNewSize.Width() * 4 / 5, nMinWidth );
97 const long nWDelta = aNewSize.Width() - nNewWidth;
98 aNewSize.Width() = nNewWidth;
99 const Size aCalcSize = m_aInvitationFT.CalcMinimumSize( nNewWidth );
100 const long nHDelta = aCalcSize.Height() - aNewSize.Height();
101 aNewSize.Height() = aCalcSize.Height();
102 m_aInvitationFT.SetSizePixel( aNewSize );
104 aNewSize = m_aYesRB.GetSizePixel();
105 aNewSize.Width() = nNewWidth;
106 Point aNewPos = m_aYesRB.GetPosPixel();
107 aNewPos.Y() += nHDelta;
108 m_aYesRB.SetPosSizePixel( aNewPos, aNewSize );
109 aNewSize = m_aNoRB.GetSizePixel();
110 aNewSize.Width() = nNewWidth;
111 aNewPos = m_aNoRB.GetPosPixel();
112 aNewPos.Y() += nHDelta;
113 m_aNoRB.SetPosSizePixel( aNewPos, aNewSize );
114 aNewSize = m_aImproveFL.GetSizePixel();
115 aNewSize.Width() -= nWDelta;
116 m_aImproveFL.SetSizePixel( aNewSize );
118 Size aSize = GetOutputSizePixel();
119 aSize.Width() -= nWDelta;
120 aSize.Height() = m_aDataFL.GetPosPixel().Y();
121 aSize.Height() += nHDelta;
122 SetSizePixel( aSize );
125 // -----------------------------------------------------------------------
127 SvxImprovementPage::~SvxImprovementPage()
131 // class SvxImprovementDialog --------------------------------------------
133 SvxImprovementDialog::SvxImprovementDialog( Window* pParent, const String& rInfoURL ) :
135 SfxSingleTabDialog( pParent, RID_SVXPAGE_IMPROVEMENT, rInfoURL ),
137 m_pPage( NULL )
140 m_pPage = new SvxImprovementPage( this );
141 SetInfoLink( LINK( this, SvxImprovementDialog, HandleHyperlink ) );
142 SetPage( m_pPage );
143 if ( GetOKButton() )
144 GetOKButton()->SetClickHdl( LINK( this, SvxImprovementDialog, HandleOK ) );
147 IMPL_LINK( SvxImprovementDialog, HandleHyperlink, svt::FixedHyperlinkImage*, pHyperlinkImage )
149 ::rtl::OUString sURL( pHyperlinkImage->GetURL() );
151 if ( sURL.getLength() > 0 )
155 uno::Reference< lang::XMultiServiceFactory > xSMGR =
156 ::comphelper::getProcessServiceFactory();
157 uno::Reference< XSystemShellExecute > xSystemShell(
158 xSMGR->createInstance( ::rtl::OUString(
159 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ),
160 uno::UNO_QUERY_THROW );
161 if ( xSystemShell.is() )
163 xSystemShell->execute(
164 sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
167 catch( const uno::Exception& e )
169 OSL_TRACE( "Caught exception: %s\n thread terminated.\n",
170 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
174 return 0;
177 IMPL_LINK( SvxImprovementDialog, HandleOK, OKButton*, EMPTYARG )
179 uno::Reference< lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
180 uno::Reference< com::sun::star::oooimprovement::XCoreController > core_c(
181 xSMGR->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.oooimprovement.CoreController")),
182 uno::UNO_QUERY);
183 if(core_c.is())
185 ::comphelper::ConfigurationHelper::writeDirectKey(
186 xSMGR,
187 ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
188 ::rtl::OUString::createFromAscii("Participation"),
189 ::rtl::OUString::createFromAscii("ShowedInvitation"),
190 uno::makeAny( true ),
191 ::comphelper::ConfigurationHelper::E_STANDARD );
192 ::comphelper::ConfigurationHelper::writeDirectKey(
193 xSMGR,
194 ::rtl::OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings"),
195 ::rtl::OUString::createFromAscii("Participation"),
196 ::rtl::OUString::createFromAscii("InvitationAccepted"),
197 uno::makeAny( m_pPage->IsYesChecked() ),
198 ::comphelper::ConfigurationHelper::E_STANDARD );
199 // TODO: refactor
200 ::comphelper::UiEventsLogger::reinit();
201 ::tools::InitTestToolLib();
203 EndDialog( RET_OK );
204 return 0;
207 // class SvxInfoWindow ---------------------------------------------------
209 SvxInfoWindow::SvxInfoWindow( Window* pParent, const ResId& rResId ) :
210 Window( pParent, rResId ),
211 m_aInfoText( this )
213 m_aInfoText.SetPosSizePixel( Point( 10, 10 ), Size( 150, 10 ) );
215 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
216 Wallpaper aWall( rSettings.GetWindowColor() );
217 SetBackground( aWall );
218 Font aNewFont( m_aInfoText.GetFont() );
219 aNewFont.SetTransparent( TRUE );
220 m_aInfoText.SetFont( aNewFont );
221 m_aInfoText.SetBackground( aWall );
222 m_aInfoText.SetControlForeground( rSettings.GetWindowTextColor() );
225 void SvxInfoWindow::SetInfoText( const String& rText )
227 m_aInfoText.SetText( rText );
228 Size aSize = m_aInfoText.CalcMinimumSize();
229 Size aWinSize = GetSizePixel();
230 Point aPos( ( aWinSize.Width() - aSize.Width() ) / 2, ( aWinSize.Height() - aSize.Height() ) / 2 );
231 m_aInfoText.SetPosSizePixel( aPos, aSize );