Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / gui / license_dialog.cxx
blob9ab343730d893161c0151af51bbebf5f3d0b7c5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <cppuhelper/implementationentry.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <comphelper/unwrapargs.hxx>
24 #include <i18nlangtag/mslangid.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <svl/lstner.hxx>
28 #include <vcl/event.hxx>
29 #include <vcl/idle.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/threadex.hxx>
32 #include <vcl/weld.hxx>
34 #include "license_dialog.hxx"
36 #include <functional>
38 using namespace ::dp_misc;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
42 namespace dp_gui {
44 struct LicenseDialogImpl : public weld::GenericDialogController
46 bool m_bLicenseRead;
47 Idle m_aResized;
48 AutoTimer m_aRepeat;
50 std::unique_ptr<weld::Label> m_xFtHead;
51 std::unique_ptr<weld::Widget> m_xArrow1;
52 std::unique_ptr<weld::Widget> m_xArrow2;
53 std::unique_ptr<weld::TextView> m_xLicense;
54 std::unique_ptr<weld::Button> m_xDown;
55 std::unique_ptr<weld::Button> m_xAcceptButton;
56 std::unique_ptr<weld::Button> m_xDeclineButton;
58 void PageDown();
59 DECL_LINK(ScrollTimerHdl, Timer*, void);
60 DECL_LINK(ScrolledHdl, weld::TextView&, void);
61 DECL_LINK(ResizedHdl, Timer*, void);
62 DECL_LINK(CancelHdl, weld::Button&, void);
63 DECL_LINK(AcceptHdl, weld::Button&, void);
64 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
65 DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool);
66 DECL_LINK(MousePressHdl, const MouseEvent&, bool);
67 DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool);
68 DECL_LINK(SizeAllocHdl, const Size&, void);
70 LicenseDialogImpl(weld::Window * pParent,
71 const OUString & sExtensionName,
72 const OUString & sLicenseText);
74 bool IsEndReached() const;
77 LicenseDialogImpl::LicenseDialogImpl(
78 weld::Window * pParent,
79 const OUString & sExtensionName,
80 const OUString & sLicenseText)
81 : GenericDialogController(pParent, "desktop/ui/licensedialog.ui", "LicenseDialog")
82 , m_bLicenseRead(false)
83 , m_xFtHead(m_xBuilder->weld_label("head"))
84 , m_xArrow1(m_xBuilder->weld_widget("arrow1"))
85 , m_xArrow2(m_xBuilder->weld_widget("arrow2"))
86 , m_xLicense(m_xBuilder->weld_text_view("textview"))
87 , m_xDown(m_xBuilder->weld_button("down"))
88 , m_xAcceptButton(m_xBuilder->weld_button("ok"))
89 , m_xDeclineButton(m_xBuilder->weld_button("cancel"))
91 m_xArrow1->show();
92 m_xArrow2->hide();
94 m_xLicense->connect_size_allocate(LINK(this, LicenseDialogImpl, SizeAllocHdl));
95 m_xLicense->set_size_request(m_xLicense->get_approximate_digit_width() * 72,
96 m_xLicense->get_height_rows(21));
98 m_xLicense->set_text(sLicenseText);
99 m_xFtHead->set_label(m_xFtHead->get_label() + "\n" + sExtensionName);
101 m_xAcceptButton->connect_clicked( LINK(this, LicenseDialogImpl, AcceptHdl) );
102 m_xDeclineButton->connect_clicked( LINK(this, LicenseDialogImpl, CancelHdl) );
104 m_xLicense->connect_vadjustment_changed(LINK(this, LicenseDialogImpl, ScrolledHdl));
105 m_xDown->connect_mouse_press(LINK(this, LicenseDialogImpl, MousePressHdl));
106 m_xDown->connect_mouse_release(LINK(this, LicenseDialogImpl, MouseReleaseHdl));
107 m_xDown->connect_key_press(LINK(this, LicenseDialogImpl, KeyInputHdl));
108 m_xDown->connect_key_release(LINK(this, LicenseDialogImpl, KeyReleaseHdl));
110 m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat());
111 m_aRepeat.SetInvokeHandler(LINK(this, LicenseDialogImpl, ScrollTimerHdl));
113 m_aResized.SetPriority(TaskPriority::LOWEST);
114 m_aResized.SetInvokeHandler(LINK(this, LicenseDialogImpl, ResizedHdl));
117 IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void)
119 m_aResized.Start();
122 IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, weld::Button&, void)
124 m_xDialog->response(RET_OK);
127 IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, weld::Button&, void)
129 m_xDialog->response(RET_CANCEL);
132 bool LicenseDialogImpl::IsEndReached() const
134 return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper();
137 IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl, weld::TextView&, void)
139 if (IsEndReached())
141 m_xDown->set_sensitive(false);
142 m_aRepeat.Stop();
144 if (!m_bLicenseRead)
146 m_xAcceptButton->set_sensitive(true);
147 m_xAcceptButton->grab_focus();
148 m_xArrow1->hide();
149 m_xArrow2->show();
150 m_bLicenseRead = true;
153 else
154 m_xDown->set_sensitive(true);
157 void LicenseDialogImpl::PageDown()
159 m_xLicense->vadjustment_set_value(m_xLicense->vadjustment_get_value() +
160 m_xLicense->vadjustment_get_page_size());
161 ScrolledHdl(*m_xLicense);
164 IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
166 vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
167 if (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE)
168 PageDown();
169 return false;
172 IMPL_LINK_NOARG(LicenseDialogImpl, ResizedHdl, Timer*, void)
174 ScrolledHdl(*m_xLicense);
177 IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void)
179 PageDown();
182 IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool)
184 return false;
187 IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool)
189 PageDown();
190 m_aRepeat.Start();
191 return false;
194 IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool)
196 m_aRepeat.Stop();
197 return false;
200 LicenseDialog::LicenseDialog( Sequence<Any> const& args,
201 Reference<XComponentContext> const& )
203 comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
206 // XExecutableDialog
208 void LicenseDialog::setTitle( OUString const & )
212 sal_Int16 LicenseDialog::execute()
214 return vcl::solarthread::syncExecute(
215 std::bind(&LicenseDialog::solar_execute, this));
218 sal_Int16 LicenseDialog::solar_execute()
220 LicenseDialogImpl dlg(Application::GetFrameWeld(m_parent), m_sExtensionName, m_sLicenseText);
221 return dlg.run();
224 } // namespace dp_gui
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */