LibreOffice Module desktop (master) 1
license_dialog.cxx
Go to the documentation of this file.
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
22#include <vcl/event.hxx>
23#include <vcl/idle.hxx>
24#include <vcl/svapp.hxx>
25#include <vcl/threadex.hxx>
26#include <vcl/weld.hxx>
28
29#include "license_dialog.hxx"
30
31#include <functional>
32#include <string_view>
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36
37namespace dp_gui {
38
39namespace {
40
41struct LicenseDialogImpl : public weld::GenericDialogController
42{
46
47 std::unique_ptr<weld::Label> m_xFtHead;
48 std::unique_ptr<weld::Widget> m_xArrow1;
49 std::unique_ptr<weld::Widget> m_xArrow2;
50 std::unique_ptr<weld::TextView> m_xLicense;
51 std::unique_ptr<weld::Button> m_xDown;
52 std::unique_ptr<weld::Button> m_xAcceptButton;
53 std::unique_ptr<weld::Button> m_xDeclineButton;
54
55 void PageDown();
56 DECL_LINK(ScrollTimerHdl, Timer*, void);
57 DECL_LINK(ScrolledHdl, weld::TextView&, void);
58 DECL_LINK(ResizedHdl, Timer*, void);
59 DECL_LINK(CancelHdl, weld::Button&, void);
60 DECL_LINK(AcceptHdl, weld::Button&, void);
61 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
62 DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool);
63 DECL_LINK(MousePressHdl, const MouseEvent&, bool);
64 DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool);
65 DECL_LINK(SizeAllocHdl, const Size&, void);
66
67 LicenseDialogImpl(weld::Window * pParent,
68 std::u16string_view sExtensionName,
69 const OUString & sLicenseText);
70
71 bool IsEndReached() const;
72};
73
74}
75
76LicenseDialogImpl::LicenseDialogImpl(
77 weld::Window * pParent,
78 std::u16string_view sExtensionName,
79 const OUString & sLicenseText)
80 : GenericDialogController(pParent, "desktop/ui/licensedialog.ui", "LicenseDialog")
81 , m_bLicenseRead(false)
82 , m_aResized("desktop LicenseDialogImpl m_aResized")
83 , m_aRepeat("LicenseDialogImpl m_aRepeat")
84 , m_xFtHead(m_xBuilder->weld_label("head"))
85 , m_xArrow1(m_xBuilder->weld_widget("arrow1"))
86 , m_xArrow2(m_xBuilder->weld_widget("arrow2"))
87 , m_xLicense(m_xBuilder->weld_text_view("textview"))
88 , m_xDown(m_xBuilder->weld_button("down"))
89 , m_xAcceptButton(m_xBuilder->weld_button("ok"))
90 , m_xDeclineButton(m_xBuilder->weld_button("cancel"))
91{
92 m_xArrow1->show();
93 m_xArrow2->hide();
94
95 m_xLicense->connect_size_allocate(LINK(this, LicenseDialogImpl, SizeAllocHdl));
96 m_xLicense->set_size_request(m_xLicense->get_approximate_digit_width() * 72,
97 m_xLicense->get_height_rows(21));
98
99 m_xLicense->set_text(sLicenseText);
100 m_xFtHead->set_label(m_xFtHead->get_label() + "\n" + sExtensionName);
101
102 m_xAcceptButton->connect_clicked( LINK(this, LicenseDialogImpl, AcceptHdl) );
103 m_xDeclineButton->connect_clicked( LINK(this, LicenseDialogImpl, CancelHdl) );
104
105 m_xLicense->connect_vadjustment_changed(LINK(this, LicenseDialogImpl, ScrolledHdl));
106 m_xDown->connect_mouse_press(LINK(this, LicenseDialogImpl, MousePressHdl));
107 m_xDown->connect_mouse_release(LINK(this, LicenseDialogImpl, MouseReleaseHdl));
108 m_xDown->connect_key_press(LINK(this, LicenseDialogImpl, KeyInputHdl));
109 m_xDown->connect_key_release(LINK(this, LicenseDialogImpl, KeyReleaseHdl));
110
111 m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat());
112 m_aRepeat.SetInvokeHandler(LINK(this, LicenseDialogImpl, ScrollTimerHdl));
113
114 m_aResized.SetPriority(TaskPriority::LOWEST);
115 m_aResized.SetInvokeHandler(LINK(this, LicenseDialogImpl, ResizedHdl));
116}
117
118IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void)
119{
121}
122
123IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, weld::Button&, void)
124{
125 m_xDialog->response(RET_OK);
126}
127
128IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, weld::Button&, void)
129{
130 m_xDialog->response(RET_CANCEL);
131}
132
133bool LicenseDialogImpl::IsEndReached() const
134{
135 return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper();
136}
137
138IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl, weld::TextView&, void)
139{
140 if (IsEndReached())
141 {
142 m_xDown->set_sensitive(false);
143 m_aRepeat.Stop();
144
145 if (!m_bLicenseRead)
146 {
147 m_xAcceptButton->set_sensitive(true);
148 m_xAcceptButton->grab_focus();
149 m_xArrow1->hide();
150 m_xArrow2->show();
151 m_bLicenseRead = true;
152 }
153 }
154 else
155 m_xDown->set_sensitive(true);
156}
157
158void LicenseDialogImpl::PageDown()
159{
160 m_xLicense->vadjustment_set_value(m_xLicense->vadjustment_get_value() +
161 m_xLicense->vadjustment_get_page_size());
162 ScrolledHdl(*m_xLicense);
163}
164
165IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
166{
167 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
168 if (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE)
169 PageDown();
170 return false;
171}
172
173IMPL_LINK_NOARG(LicenseDialogImpl, ResizedHdl, Timer*, void)
174{
175 ScrolledHdl(*m_xLicense);
176}
177
178IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void)
179{
180 PageDown();
181}
182
183IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool)
184{
185 return false;
186}
187
188IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool)
189{
190 PageDown();
192 return false;
193}
194
195IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool)
196{
197 m_aRepeat.Stop();
198 return false;
199}
200
201LicenseDialog::LicenseDialog( Sequence<Any> const& args,
202 Reference<XComponentContext> const& )
203{
204 comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
205}
206
207// XServiceInfo
208OUString LicenseDialog::getImplementationName()
209{
210 return "com.sun.star.comp.deployment.ui.LicenseDialog";
211}
212
213sal_Bool LicenseDialog::supportsService( const OUString& ServiceName )
214{
216}
217
218css::uno::Sequence< OUString > LicenseDialog::getSupportedServiceNames()
219{
220 return { "com.sun.star.deployment.ui.LicenseDialog" };
221}
222
223
224// XExecutableDialog
225
226void LicenseDialog::setTitle( OUString const & )
227{
228}
229
230sal_Int16 LicenseDialog::execute()
231{
233 std::bind(&LicenseDialog::solar_execute, this));
234}
235
236sal_Int16 LicenseDialog::solar_execute()
237{
238 LicenseDialogImpl dlg(Application::GetFrameWeld(m_parent), m_sExtensionName, m_sLicenseText);
239 return dlg.run();
240}
241
242} // namespace dp_gui
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
static const AllSettings & GetSettings()
virtual void Start(bool bStartTimer=true) override
void SetPriority(TaskPriority ePriority)
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
sal_uInt16 GetCode() const
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
std::optional< Reference< awt::XWindow > > m_parent
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_SPACE
std::unique_ptr< weld::Button > m_xDeclineButton
std::unique_ptr< weld::Label > m_xFtHead
std::unique_ptr< weld::Button > m_xDown
std::unique_ptr< weld::Button > m_xAcceptButton
Idle m_aResized
bool m_bLicenseRead
AutoTimer m_aRepeat
std::unique_ptr< weld::Widget > m_xArrow2
std::unique_ptr< weld::Widget > m_xArrow1
std::unique_ptr< weld::TextView > m_xLicense
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &... args)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Definition: dp_gui.h:22
IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent &, rKEvt, bool)
IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent &, bool)
IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent &, bool)
args
auto syncExecute(FuncT const &func) -> decltype(func())
unsigned char sal_Bool
RET_OK
RET_CANCEL