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