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>
27 
28 #include "license_dialog.hxx"
29 
30 #include <functional>
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 
35 namespace dp_gui {
36 
37 namespace {
38 
39 struct LicenseDialogImpl : public weld::GenericDialogController
40 {
44 
45  std::unique_ptr<weld::Label> m_xFtHead;
46  std::unique_ptr<weld::Widget> m_xArrow1;
47  std::unique_ptr<weld::Widget> m_xArrow2;
48  std::unique_ptr<weld::TextView> m_xLicense;
49  std::unique_ptr<weld::Button> m_xDown;
50  std::unique_ptr<weld::Button> m_xAcceptButton;
51  std::unique_ptr<weld::Button> m_xDeclineButton;
52 
53  void PageDown();
54  DECL_LINK(ScrollTimerHdl, Timer*, void);
55  DECL_LINK(ScrolledHdl, weld::TextView&, void);
56  DECL_LINK(ResizedHdl, Timer*, void);
57  DECL_LINK(CancelHdl, weld::Button&, void);
58  DECL_LINK(AcceptHdl, weld::Button&, void);
59  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
60  DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool);
61  DECL_LINK(MousePressHdl, const MouseEvent&, bool);
62  DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool);
63  DECL_LINK(SizeAllocHdl, const Size&, void);
64 
65  LicenseDialogImpl(weld::Window * pParent,
66  const OUString & sExtensionName,
67  const OUString & sLicenseText);
68 
69  bool IsEndReached() const;
70 };
71 
72 }
73 
74 LicenseDialogImpl::LicenseDialogImpl(
75  weld::Window * pParent,
76  const OUString & sExtensionName,
77  const OUString & sLicenseText)
78  : GenericDialogController(pParent, "desktop/ui/licensedialog.ui", "LicenseDialog")
79  , m_bLicenseRead(false)
80  , m_xFtHead(m_xBuilder->weld_label("head"))
81  , m_xArrow1(m_xBuilder->weld_widget("arrow1"))
82  , m_xArrow2(m_xBuilder->weld_widget("arrow2"))
83  , m_xLicense(m_xBuilder->weld_text_view("textview"))
84  , m_xDown(m_xBuilder->weld_button("down"))
85  , m_xAcceptButton(m_xBuilder->weld_button("ok"))
86  , m_xDeclineButton(m_xBuilder->weld_button("cancel"))
87 {
88  m_xArrow1->show();
89  m_xArrow2->hide();
90 
91  m_xLicense->connect_size_allocate(LINK(this, LicenseDialogImpl, SizeAllocHdl));
92  m_xLicense->set_size_request(m_xLicense->get_approximate_digit_width() * 72,
93  m_xLicense->get_height_rows(21));
94 
95  m_xLicense->set_text(sLicenseText);
96  m_xFtHead->set_label(m_xFtHead->get_label() + "\n" + sExtensionName);
97 
98  m_xAcceptButton->connect_clicked( LINK(this, LicenseDialogImpl, AcceptHdl) );
99  m_xDeclineButton->connect_clicked( LINK(this, LicenseDialogImpl, CancelHdl) );
100 
101  m_xLicense->connect_vadjustment_changed(LINK(this, LicenseDialogImpl, ScrolledHdl));
102  m_xDown->connect_mouse_press(LINK(this, LicenseDialogImpl, MousePressHdl));
103  m_xDown->connect_mouse_release(LINK(this, LicenseDialogImpl, MouseReleaseHdl));
104  m_xDown->connect_key_press(LINK(this, LicenseDialogImpl, KeyInputHdl));
105  m_xDown->connect_key_release(LINK(this, LicenseDialogImpl, KeyReleaseHdl));
106 
107  m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat());
108  m_aRepeat.SetInvokeHandler(LINK(this, LicenseDialogImpl, ScrollTimerHdl));
109 
110  m_aResized.SetPriority(TaskPriority::LOWEST);
111  m_aResized.SetInvokeHandler(LINK(this, LicenseDialogImpl, ResizedHdl));
112 }
113 
114 IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void)
115 {
116  m_aResized.Start();
117 }
118 
119 IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, weld::Button&, void)
120 {
121  m_xDialog->response(RET_OK);
122 }
123 
124 IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, weld::Button&, void)
125 {
126  m_xDialog->response(RET_CANCEL);
127 }
128 
129 bool LicenseDialogImpl::IsEndReached() const
130 {
131  return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper();
132 }
133 
134 IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl, weld::TextView&, void)
135 {
136  if (IsEndReached())
137  {
138  m_xDown->set_sensitive(false);
139  m_aRepeat.Stop();
140 
141  if (!m_bLicenseRead)
142  {
143  m_xAcceptButton->set_sensitive(true);
144  m_xAcceptButton->grab_focus();
145  m_xArrow1->hide();
146  m_xArrow2->show();
147  m_bLicenseRead = true;
148  }
149  }
150  else
151  m_xDown->set_sensitive(true);
152 }
153 
154 void LicenseDialogImpl::PageDown()
155 {
156  m_xLicense->vadjustment_set_value(m_xLicense->vadjustment_get_value() +
157  m_xLicense->vadjustment_get_page_size());
158  ScrolledHdl(*m_xLicense);
159 }
160 
161 IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
162 {
163  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
164  if (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE)
165  PageDown();
166  return false;
167 }
168 
169 IMPL_LINK_NOARG(LicenseDialogImpl, ResizedHdl, Timer*, void)
170 {
171  ScrolledHdl(*m_xLicense);
172 }
173 
174 IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void)
175 {
176  PageDown();
177 }
178 
179 IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool)
180 {
181  return false;
182 }
183 
184 IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool)
185 {
186  PageDown();
187  m_aRepeat.Start();
188  return false;
189 }
190 
191 IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool)
192 {
193  m_aRepeat.Stop();
194  return false;
195 }
196 
197 LicenseDialog::LicenseDialog( Sequence<Any> const& args,
199 {
200  comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
201 }
202 
203 // XExecutableDialog
204 
205 void LicenseDialog::setTitle( OUString const & )
206 {
207 }
208 
209 sal_Int16 LicenseDialog::execute()
210 {
212  std::bind(&LicenseDialog::solar_execute, this));
213 }
214 
215 sal_Int16 LicenseDialog::solar_execute()
216 {
217  LicenseDialogImpl dlg(Application::GetFrameWeld(m_parent), m_sExtensionName, m_sLicenseText);
218  return dlg.run();
219 }
220 
221 } // namespace dp_gui
222 
223 /* 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
virtual void Start() override
std::optional< Reference< awt::XWindow > > m_parent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
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:23