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