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