xref: /AOO41X/main/desktop/source/deployment/gui/license_dialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
32*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
33*cdf0e10cSrcweir #include "unotools/configmgr.hxx"
34*cdf0e10cSrcweir #include "comphelper/servicedecl.hxx"
35*cdf0e10cSrcweir #include "comphelper/unwrapargs.hxx"
36*cdf0e10cSrcweir #include "i18npool/mslangid.hxx"
37*cdf0e10cSrcweir #include "vcl/svapp.hxx"
38*cdf0e10cSrcweir #include "vcl/msgbox.hxx"
39*cdf0e10cSrcweir #include "toolkit/helper/vclunohelper.hxx"
40*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
41*cdf0e10cSrcweir #include "com/sun/star/task/XJobExecutor.hpp"
42*cdf0e10cSrcweir #include "svtools/svmedit.hxx"
43*cdf0e10cSrcweir #include "svl/lstner.hxx"
44*cdf0e10cSrcweir #include "svtools/xtextedt.hxx"
45*cdf0e10cSrcweir #include <vcl/scrbar.hxx>
46*cdf0e10cSrcweir #include "vcl/threadex.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "boost/bind.hpp"
51*cdf0e10cSrcweir #include "dp_gui_shared.hxx"
52*cdf0e10cSrcweir #include "license_dialog.hxx"
53*cdf0e10cSrcweir #include "dp_gui.hrc"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace ::dp_misc;
56*cdf0e10cSrcweir namespace cssu = ::com::sun::star::uno;
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
59*cdf0e10cSrcweir using ::rtl::OUString;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir namespace dp_gui {
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir class LicenseView : public MultiLineEdit, public SfxListener
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir     sal_Bool            mbEndReached;
66*cdf0e10cSrcweir     Link            maEndReachedHdl;
67*cdf0e10cSrcweir     Link            maScrolledHdl;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir public:
70*cdf0e10cSrcweir     LicenseView( Window* pParent, const ResId& rResId );
71*cdf0e10cSrcweir     ~LicenseView();
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     void ScrollDown( ScrollType eScroll );
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     sal_Bool IsEndReached() const;
76*cdf0e10cSrcweir     sal_Bool EndReached() const { return mbEndReached; }
77*cdf0e10cSrcweir     void SetEndReached( sal_Bool bEnd ) { mbEndReached = bEnd; }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     void SetEndReachedHdl( const Link& rHdl )  { maEndReachedHdl = rHdl; }
80*cdf0e10cSrcweir     const Link& GetAutocompleteHdl() const { return maEndReachedHdl; }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     void SetScrolledHdl( const Link& rHdl )  { maScrolledHdl = rHdl; }
83*cdf0e10cSrcweir     const Link& GetScrolledHdl() const { return maScrolledHdl; }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir protected:
88*cdf0e10cSrcweir     using MultiLineEdit::Notify;
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir struct LicenseDialogImpl : public ModalDialog
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	cssu::Reference<cssu::XComponentContext> m_xComponentContext;
94*cdf0e10cSrcweir 	FixedText m_ftHead;
95*cdf0e10cSrcweir     FixedText m_ftBody1;
96*cdf0e10cSrcweir     FixedText m_ftBody1Txt;
97*cdf0e10cSrcweir     FixedText m_ftBody2;
98*cdf0e10cSrcweir     FixedText m_ftBody2Txt;
99*cdf0e10cSrcweir 	FixedImage m_fiArrow1;
100*cdf0e10cSrcweir 	FixedImage m_fiArrow2;
101*cdf0e10cSrcweir     LicenseView m_mlLicense;
102*cdf0e10cSrcweir     PushButton m_pbDown;
103*cdf0e10cSrcweir 	FixedLine m_flBottom;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     OKButton m_acceptButton;
106*cdf0e10cSrcweir 	CancelButton m_declineButton;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	DECL_LINK(PageDownHdl, PushButton*);
109*cdf0e10cSrcweir 	DECL_LINK(ScrolledHdl, LicenseView*);
110*cdf0e10cSrcweir 	DECL_LINK(EndReachedHdl, LicenseView*);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	bool m_bLicenseRead;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     virtual ~LicenseDialogImpl();
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	LicenseDialogImpl(
117*cdf0e10cSrcweir         Window * pParent,
118*cdf0e10cSrcweir         css::uno::Reference< css::uno::XComponentContext > const & xContext,
119*cdf0e10cSrcweir         const ::rtl::OUString & sExtensionName,
120*cdf0e10cSrcweir 		const ::rtl::OUString & sLicenseText);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	virtual void Activate();
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir };
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir LicenseView::LicenseView( Window* pParent, const ResId& rResId )
127*cdf0e10cSrcweir     : MultiLineEdit( pParent, rResId )
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     SetLeftMargin( 5 );
130*cdf0e10cSrcweir     mbEndReached = IsEndReached();
131*cdf0e10cSrcweir     StartListening( *GetTextEngine() );
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir LicenseView::~LicenseView()
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     maEndReachedHdl = Link();
137*cdf0e10cSrcweir     maScrolledHdl   = Link();
138*cdf0e10cSrcweir     EndListeningAll();
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir void LicenseView::ScrollDown( ScrollType eScroll )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     ScrollBar*  pScroll = GetVScrollBar();
144*cdf0e10cSrcweir     if ( pScroll )
145*cdf0e10cSrcweir         pScroll->DoScrollAction( eScroll );
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir sal_Bool LicenseView::IsEndReached() const
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     sal_Bool bEndReached;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     ExtTextView*    pView = GetTextView();
153*cdf0e10cSrcweir     ExtTextEngine*  pEdit = GetTextEngine();
154*cdf0e10cSrcweir     sal_uLong           nHeight = pEdit->GetTextHeight();
155*cdf0e10cSrcweir     Size            aOutSize = pView->GetWindow()->GetOutputSizePixel();
156*cdf0e10cSrcweir     Point           aBottom( 0, aOutSize.Height() );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     if ( (sal_uLong) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 )
159*cdf0e10cSrcweir         bEndReached = sal_True;
160*cdf0e10cSrcweir     else
161*cdf0e10cSrcweir         bEndReached = sal_False;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     return bEndReached;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint )
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     if ( rHint.IsA( TYPE(TextHint) ) )
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         sal_Bool    bLastVal = EndReached();
171*cdf0e10cSrcweir         sal_uLong   nId = ((const TextHint&)rHint).GetId();
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         if ( nId == TEXT_HINT_PARAINSERTED )
174*cdf0e10cSrcweir         {
175*cdf0e10cSrcweir             if ( bLastVal )
176*cdf0e10cSrcweir                 mbEndReached = IsEndReached();
177*cdf0e10cSrcweir         }
178*cdf0e10cSrcweir         else if ( nId == TEXT_HINT_VIEWSCROLLED )
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             if ( ! mbEndReached )
181*cdf0e10cSrcweir                 mbEndReached = IsEndReached();
182*cdf0e10cSrcweir             maScrolledHdl.Call( this );
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         if ( EndReached() && !bLastVal )
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             maEndReachedHdl.Call( this );
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir //==============================================================================================================
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir LicenseDialogImpl::LicenseDialogImpl(
195*cdf0e10cSrcweir 	Window * pParent,
196*cdf0e10cSrcweir 	cssu::Reference< cssu::XComponentContext > const & xContext,
197*cdf0e10cSrcweir     const ::rtl::OUString & sExtensionName,
198*cdf0e10cSrcweir     const ::rtl::OUString & sLicenseText):
199*cdf0e10cSrcweir 		ModalDialog(pParent, DpGuiResId(RID_DLG_LICENSE))
200*cdf0e10cSrcweir 		,m_xComponentContext(xContext)
201*cdf0e10cSrcweir 		,m_ftHead(this, DpGuiResId(FT_LICENSE_HEADER))
202*cdf0e10cSrcweir 		,m_ftBody1(this, DpGuiResId(FT_LICENSE_BODY_1))
203*cdf0e10cSrcweir 		,m_ftBody1Txt(this, DpGuiResId(FT_LICENSE_BODY_1_TXT))
204*cdf0e10cSrcweir 		,m_ftBody2(this, DpGuiResId(FT_LICENSE_BODY_2))
205*cdf0e10cSrcweir 		,m_ftBody2Txt(this, DpGuiResId(FT_LICENSE_BODY_2_TXT))
206*cdf0e10cSrcweir 		,m_fiArrow1(this, DpGuiResId(FI_LICENSE_ARROW1))
207*cdf0e10cSrcweir 		,m_fiArrow2(this, DpGuiResId(FI_LICENSE_ARROW2))
208*cdf0e10cSrcweir 		,m_mlLicense(this, DpGuiResId(ML_LICENSE))
209*cdf0e10cSrcweir 		,m_pbDown(this, DpGuiResId(PB_LICENSE_DOWN))
210*cdf0e10cSrcweir 		,m_flBottom(this, DpGuiResId(FL_LICENSE))
211*cdf0e10cSrcweir 		,m_acceptButton(this, DpGuiResId(BTN_LICENSE_ACCEPT))
212*cdf0e10cSrcweir 		,m_declineButton(this, DpGuiResId(BTN_LICENSE_DECLINE))
213*cdf0e10cSrcweir 		,m_bLicenseRead(false)
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	if (GetSettings().GetStyleSettings().GetHighContrastMode())
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         // high contrast mode needs other images
220*cdf0e10cSrcweir         m_fiArrow1.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC)));
221*cdf0e10cSrcweir         m_fiArrow2.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC)));
222*cdf0e10cSrcweir 	}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	FreeResource();
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	m_acceptButton.SetUniqueId(UID_BTN_LICENSE_ACCEPT);
227*cdf0e10cSrcweir 	m_fiArrow1.Show(true);
228*cdf0e10cSrcweir 	m_fiArrow2.Show(false);
229*cdf0e10cSrcweir 	m_mlLicense.SetText(sLicenseText);
230*cdf0e10cSrcweir     m_ftHead.SetText(m_ftHead.GetText() + OUString('\n') + sExtensionName);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	m_mlLicense.SetEndReachedHdl( LINK(this, LicenseDialogImpl, EndReachedHdl) );
233*cdf0e10cSrcweir 	m_mlLicense.SetScrolledHdl( LINK(this, LicenseDialogImpl, ScrolledHdl) );
234*cdf0e10cSrcweir     m_pbDown.SetClickHdl( LINK(this, LicenseDialogImpl, PageDownHdl) );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	// We want a automatic repeating page down button
237*cdf0e10cSrcweir     WinBits aStyle = m_pbDown.GetStyle();
238*cdf0e10cSrcweir     aStyle |= WB_REPEAT;
239*cdf0e10cSrcweir     m_pbDown.SetStyle( aStyle );
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir LicenseDialogImpl::~LicenseDialogImpl()
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void LicenseDialogImpl::Activate()
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir 	if (!m_bLicenseRead)
249*cdf0e10cSrcweir 	{
250*cdf0e10cSrcweir 		//Only enable the scroll down button if the license text does not fit into the window
251*cdf0e10cSrcweir 		if (m_mlLicense.IsEndReached())
252*cdf0e10cSrcweir 		{
253*cdf0e10cSrcweir 			m_pbDown.Disable();
254*cdf0e10cSrcweir 			m_acceptButton.Enable();
255*cdf0e10cSrcweir 			m_acceptButton.GrabFocus();
256*cdf0e10cSrcweir 		}
257*cdf0e10cSrcweir 		else
258*cdf0e10cSrcweir 		{
259*cdf0e10cSrcweir 			m_pbDown.Enable();
260*cdf0e10cSrcweir 			m_pbDown.GrabFocus();
261*cdf0e10cSrcweir 			m_acceptButton.Disable();
262*cdf0e10cSrcweir 		}
263*cdf0e10cSrcweir 	}
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, ScrolledHdl, LicenseView *, EMPTYARG )
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	if (m_mlLicense.IsEndReached())
270*cdf0e10cSrcweir         m_pbDown.Disable();
271*cdf0e10cSrcweir 	else
272*cdf0e10cSrcweir         m_pbDown.Enable();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     return 0;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, PageDownHdl, PushButton *, EMPTYARG )
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     m_mlLicense.ScrollDown( SCROLL_PAGEDOWN );
280*cdf0e10cSrcweir     return 0;
281*cdf0e10cSrcweir }
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, EndReachedHdl, LicenseView *, EMPTYARG )
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir     m_acceptButton.Enable();
286*cdf0e10cSrcweir 	m_acceptButton.GrabFocus();
287*cdf0e10cSrcweir 	m_fiArrow1.Show(false);
288*cdf0e10cSrcweir 	m_fiArrow2.Show(true);
289*cdf0e10cSrcweir 	m_bLicenseRead = true;
290*cdf0e10cSrcweir     return 0;
291*cdf0e10cSrcweir }
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir //=================================================================================
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir LicenseDialog::LicenseDialog( Sequence<Any> const& args,
299*cdf0e10cSrcweir                           Reference<XComponentContext> const& xComponentContext)
300*cdf0e10cSrcweir     : m_xComponentContext(xComponentContext)
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir     comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir // XExecutableDialog
306*cdf0e10cSrcweir //______________________________________________________________________________
307*cdf0e10cSrcweir void LicenseDialog::setTitle( OUString const & ) throw (RuntimeException)
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir //______________________________________________________________________________
313*cdf0e10cSrcweir sal_Int16 LicenseDialog::execute() throw (RuntimeException)
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     return vcl::solarthread::syncExecute(
316*cdf0e10cSrcweir         boost::bind( &LicenseDialog::solar_execute, this));
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir sal_Int16 LicenseDialog::solar_execute()
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir 	std::auto_ptr<LicenseDialogImpl> dlg(
322*cdf0e10cSrcweir         new LicenseDialogImpl(
323*cdf0e10cSrcweir             VCLUnoHelper::GetWindow(m_parent),
324*cdf0e10cSrcweir             m_xComponentContext, m_sExtensionName, m_sLicenseText));
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     return dlg->Execute();
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir } // namespace dp_gui
330*cdf0e10cSrcweir 
331