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")
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 
118 IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void)
119 {
120  m_aResized.Start();
121 }
122 
123 IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, weld::Button&, void)
124 {
125  m_xDialog->response(RET_OK);
126 }
127 
128 IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, weld::Button&, void)
129 {
130  m_xDialog->response(RET_CANCEL);
131 }
132 
133 bool LicenseDialogImpl::IsEndReached() const
134 {
135  return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper();
136 }
137 
138 IMPL_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 
158 void 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 
165 IMPL_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 
173 IMPL_LINK_NOARG(LicenseDialogImpl, ResizedHdl, Timer*, void)
174 {
175  ScrolledHdl(*m_xLicense);
176 }
177 
178 IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void)
179 {
180  PageDown();
181 }
182 
183 IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool)
184 {
185  return false;
186 }
187 
188 IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool)
189 {
190  PageDown();
191  m_aRepeat.Start();
192  return false;
193 }
194 
195 IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool)
196 {
197  m_aRepeat.Stop();
198  return false;
199 }
200 
201 LicenseDialog::LicenseDialog( Sequence<Any> const& args,
203 {
204  comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
205 }
206 
207 // XServiceInfo
208 OUString LicenseDialog::getImplementationName()
209 {
210  return "com.sun.star.comp.deployment.ui.LicenseDialog";
211 }
212 
213 sal_Bool LicenseDialog::supportsService( const OUString& ServiceName )
214 {
215  return cppu::supportsService(this, ServiceName);
216 }
217 
218 css::uno::Sequence< OUString > LicenseDialog::getSupportedServiceNames()
219 {
220  return { "com.sun.star.deployment.ui.LicenseDialog" };
221 }
222 
223 
224 // XExecutableDialog
225 
226 void LicenseDialog::setTitle( OUString const & )
227 {
228 }
229 
230 sal_Int16 LicenseDialog::execute()
231 {
233  std::bind(&LicenseDialog::solar_execute, this));
234 }
235 
236 sal_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: */
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
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)
std::optional< Reference< awt::XWindow > > m_parent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
virtual void Start(bool bStartTimer=true) override
unsigned char sal_Bool
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
virtual void Start(bool bStartTimer=true) override
void SetPriority(TaskPriority ePriority)
std::unique_ptr< weld::Label > m_xFtHead
Definition: dp_gui.h:22
bool m_bDetectedRangeSegmentation false