Update ooo320-m1
[ooovba.git] / desktop / source / deployment / gui / license_dialog.cxx
blobd0e2c44be22fd9de23c74378f0483a22493d886c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: license_dialog.cxx,v $
10 * $Revision: 1.9 $
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_desktop.hxx"
34 #include "cppuhelper/implbase2.hxx"
35 #include "cppuhelper/implementationentry.hxx"
36 #include "unotools/configmgr.hxx"
37 #include "comphelper/servicedecl.hxx"
38 #include "comphelper/unwrapargs.hxx"
39 #include "i18npool/mslangid.hxx"
40 #include "vcl/svapp.hxx"
41 #include "vcl/msgbox.hxx"
42 #include "toolkit/helper/vclunohelper.hxx"
43 #include "com/sun/star/lang/XServiceInfo.hpp"
44 #include "com/sun/star/task/XJobExecutor.hpp"
45 #include "svtools/svmedit.hxx"
46 #include "svtools/lstner.hxx"
47 #include "svtools/xtextedt.hxx"
48 #include <vcl/scrbar.hxx>
49 #include "vcl/threadex.hxx"
53 #include "boost/bind.hpp"
54 #include "dp_gui_shared.hxx"
55 #include "license_dialog.hxx"
56 #include "dp_gui.hrc"
58 using namespace ::dp_misc;
59 namespace cssu = ::com::sun::star::uno;
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using ::rtl::OUString;
64 namespace dp_gui {
66 class LicenseView : public MultiLineEdit, public SfxListener
68 BOOL mbEndReached;
69 Link maEndReachedHdl;
70 Link maScrolledHdl;
72 public:
73 LicenseView( Window* pParent, const ResId& rResId );
74 ~LicenseView();
76 void ScrollDown( ScrollType eScroll );
78 BOOL IsEndReached() const;
79 BOOL EndReached() const { return mbEndReached; }
80 void SetEndReached( BOOL bEnd ) { mbEndReached = bEnd; }
82 void SetEndReachedHdl( const Link& rHdl ) { maEndReachedHdl = rHdl; }
83 const Link& GetAutocompleteHdl() const { return maEndReachedHdl; }
85 void SetScrolledHdl( const Link& rHdl ) { maScrolledHdl = rHdl; }
86 const Link& GetScrolledHdl() const { return maScrolledHdl; }
88 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
90 protected:
91 using MultiLineEdit::Notify;
94 struct LicenseDialogImpl : public ModalDialog
96 cssu::Reference<cssu::XComponentContext> m_xComponentContext;
97 FixedText m_ftHead;
98 FixedText m_ftBody1;
99 FixedText m_ftBody1Txt;
100 FixedText m_ftBody2;
101 FixedText m_ftBody2Txt;
102 FixedImage m_fiArrow1;
103 FixedImage m_fiArrow2;
104 LicenseView m_mlLicense;
105 PushButton m_pbDown;
106 FixedLine m_flBottom;
108 OKButton m_acceptButton;
109 CancelButton m_declineButton;
111 DECL_LINK(PageDownHdl, PushButton*);
112 DECL_LINK(ScrolledHdl, LicenseView*);
113 DECL_LINK(EndReachedHdl, LicenseView*);
115 bool m_bLicenseRead;
117 virtual ~LicenseDialogImpl();
119 LicenseDialogImpl(
120 Window * pParent,
121 css::uno::Reference< css::uno::XComponentContext > const & xContext,
122 const ::rtl::OUString & sLicenseText);
124 virtual void Activate();
128 LicenseView::LicenseView( Window* pParent, const ResId& rResId )
129 : MultiLineEdit( pParent, rResId )
131 SetLeftMargin( 5 );
132 mbEndReached = IsEndReached();
133 StartListening( *GetTextEngine() );
136 LicenseView::~LicenseView()
138 maEndReachedHdl = Link();
139 maScrolledHdl = Link();
140 EndListeningAll();
143 void LicenseView::ScrollDown( ScrollType eScroll )
145 ScrollBar* pScroll = GetVScrollBar();
146 if ( pScroll )
147 pScroll->DoScrollAction( eScroll );
150 BOOL LicenseView::IsEndReached() const
152 BOOL bEndReached;
154 ExtTextView* pView = GetTextView();
155 ExtTextEngine* pEdit = GetTextEngine();
156 ULONG nHeight = pEdit->GetTextHeight();
157 Size aOutSize = pView->GetWindow()->GetOutputSizePixel();
158 Point aBottom( 0, aOutSize.Height() );
160 if ( (ULONG) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 )
161 bEndReached = TRUE;
162 else
163 bEndReached = FALSE;
165 return bEndReached;
168 void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint )
170 if ( rHint.IsA( TYPE(TextHint) ) )
172 BOOL bLastVal = EndReached();
173 ULONG nId = ((const TextHint&)rHint).GetId();
175 if ( nId == TEXT_HINT_PARAINSERTED )
177 if ( bLastVal )
178 mbEndReached = IsEndReached();
180 else if ( nId == TEXT_HINT_VIEWSCROLLED )
182 if ( ! mbEndReached )
183 mbEndReached = IsEndReached();
184 maScrolledHdl.Call( this );
187 if ( EndReached() && !bLastVal )
189 maEndReachedHdl.Call( this );
194 //==============================================================================================================
196 LicenseDialogImpl::LicenseDialogImpl(
197 Window * pParent,
198 cssu::Reference< cssu::XComponentContext > const & xContext,
199 const ::rtl::OUString & sLicenseText):
200 ModalDialog(pParent, DpGuiResId(RID_DLG_LICENSE))
201 ,m_xComponentContext(xContext)
202 ,m_ftHead(this, DpGuiResId(FT_LICENSE_HEADER))
203 ,m_ftBody1(this, DpGuiResId(FT_LICENSE_BODY_1))
204 ,m_ftBody1Txt(this, DpGuiResId(FT_LICENSE_BODY_1_TXT))
205 ,m_ftBody2(this, DpGuiResId(FT_LICENSE_BODY_2))
206 ,m_ftBody2Txt(this, DpGuiResId(FT_LICENSE_BODY_2_TXT))
207 ,m_fiArrow1(this, DpGuiResId(FI_LICENSE_ARROW1))
208 ,m_fiArrow2(this, DpGuiResId(FI_LICENSE_ARROW2))
209 ,m_mlLicense(this, DpGuiResId(ML_LICENSE))
210 ,m_pbDown(this, DpGuiResId(PB_LICENSE_DOWN))
211 ,m_flBottom(this, DpGuiResId(FL_LICENSE))
212 ,m_acceptButton(this, DpGuiResId(BTN_LICENSE_ACCEPT))
213 ,m_declineButton(this, DpGuiResId(BTN_LICENSE_DECLINE))
214 ,m_bLicenseRead(false)
218 if (GetBackground().GetColor().IsDark())
220 // high contrast mode needs other images
221 m_fiArrow1.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC)));
222 m_fiArrow2.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC)));
225 FreeResource();
227 m_acceptButton.SetUniqueId(UID_BTN_LICENSE_ACCEPT);
228 m_fiArrow1.Show(true);
229 m_fiArrow2.Show(false);
230 m_mlLicense.SetText(sLicenseText);
232 m_mlLicense.SetEndReachedHdl( LINK(this, LicenseDialogImpl, EndReachedHdl) );
233 m_mlLicense.SetScrolledHdl( LINK(this, LicenseDialogImpl, ScrolledHdl) );
234 m_pbDown.SetClickHdl( LINK(this, LicenseDialogImpl, PageDownHdl) );
236 // We want a automatic repeating page down button
237 WinBits aStyle = m_pbDown.GetStyle();
238 aStyle |= WB_REPEAT;
239 m_pbDown.SetStyle( aStyle );
242 LicenseDialogImpl::~LicenseDialogImpl()
246 void LicenseDialogImpl::Activate()
248 if (!m_bLicenseRead)
250 //Only enable the scroll down button if the license text does not fit into the window
251 if (m_mlLicense.IsEndReached())
253 m_pbDown.Disable();
254 m_acceptButton.Enable();
255 m_acceptButton.GrabFocus();
257 else
259 m_pbDown.Enable();
260 m_pbDown.GrabFocus();
261 m_acceptButton.Disable();
266 IMPL_LINK( LicenseDialogImpl, ScrolledHdl, LicenseView *, EMPTYARG )
269 if (m_mlLicense.IsEndReached())
270 m_pbDown.Disable();
271 else
272 m_pbDown.Enable();
274 return 0;
277 IMPL_LINK( LicenseDialogImpl, PageDownHdl, PushButton *, EMPTYARG )
279 m_mlLicense.ScrollDown( SCROLL_PAGEDOWN );
280 return 0;
283 IMPL_LINK( LicenseDialogImpl, EndReachedHdl, LicenseView *, EMPTYARG )
285 m_acceptButton.Enable();
286 m_acceptButton.GrabFocus();
287 m_fiArrow1.Show(false);
288 m_fiArrow2.Show(true);
289 m_bLicenseRead = true;
290 return 0;
293 //=================================================================================
298 LicenseDialog::LicenseDialog( Sequence<Any> const& args,
299 Reference<XComponentContext> const& xComponentContext)
300 : m_xComponentContext(xComponentContext)
302 comphelper::unwrapArgs( args, m_parent, m_sLicenseText );
305 // XExecutableDialog
306 //______________________________________________________________________________
307 void LicenseDialog::setTitle( OUString const & ) throw (RuntimeException)
312 //______________________________________________________________________________
313 sal_Int16 LicenseDialog::execute() throw (RuntimeException)
315 return vcl::solarthread::syncExecute(
316 boost::bind( &LicenseDialog::solar_execute, this));
319 sal_Int16 LicenseDialog::solar_execute()
321 std::auto_ptr<LicenseDialogImpl> dlg(new LicenseDialogImpl(
322 VCLUnoHelper::GetWindow(m_parent), m_xComponentContext, m_sLicenseText));
324 return dlg->Execute();
327 } // namespace dp_gui