diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-02-23 13:42:55 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-02-27 22:18:22 +0100 |
commit | cfe41185bc8514949d1938ee1d7cd56968682510 (patch) | |
tree | 8d990aae964cf0ed6ed49c06a86133057481ae7d /desktop | |
parent | 3e1306c283c2aca372a8384801a1e206f208e1cb (diff) |
weld LicenseDialogImpl
Change-Id: I4b2dbd2446779e7179d2b79bf81cc2ff879377bf
Reviewed-on: https://gerrit.libreoffice.org/68389
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/deployment/gui/license_dialog.cxx | 285 | ||||
-rw-r--r-- | desktop/uiconfig/ui/licensedialog.ui | 62 |
2 files changed, 134 insertions, 213 deletions
diff --git a/desktop/source/deployment/gui/license_dialog.cxx b/desktop/source/deployment/gui/license_dialog.cxx index b64ba25d4399..aa8d45d4cf65 100644 --- a/desktop/source/deployment/gui/license_dialog.cxx +++ b/desktop/source/deployment/gui/license_dialog.cxx @@ -22,6 +22,7 @@ #include <unotools/configmgr.hxx> #include <comphelper/unwrapargs.hxx> #include <i18nlangtag/mslangid.hxx> +#include <vcl/event.hxx> #include <vcl/svapp.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -32,6 +33,7 @@ #include <vcl/scrbar.hxx> #include <vcl/threadex.hxx> #include <vcl/builderfactory.hxx> +#include <vcl/weld.hxx> #include "license_dialog.hxx" @@ -43,235 +45,162 @@ using namespace ::com::sun::star::uno; namespace dp_gui { -class LicenseView : public MultiLineEdit, public SfxListener +struct LicenseDialogImpl : public weld::GenericDialogController { - bool mbEndReached; - Link<LicenseView&,void> maEndReachedHdl; - Link<LicenseView&,void> maScrolledHdl; - -public: - LicenseView( vcl::Window* pParent, WinBits nStyle ); - virtual ~LicenseView() override; - virtual void dispose() override; - - void ScrollDown( ScrollType eScroll ); + bool m_bLicenseRead; + Idle m_aResized; + AutoTimer m_aRepeat; + + std::unique_ptr<weld::Label> m_xFtHead; + std::unique_ptr<weld::Widget> m_xArrow1; + std::unique_ptr<weld::Widget> m_xArrow2; + std::unique_ptr<weld::TextView> m_xLicense; + std::unique_ptr<weld::Button> m_xDown; + std::unique_ptr<weld::Button> m_xAcceptButton; + std::unique_ptr<weld::Button> m_xDeclineButton; + + void PageDown(); + DECL_LINK(ScrollTimerHdl, Timer*, void); + DECL_LINK(ScrolledHdl, weld::TextView&, void); + DECL_LINK(ResizedHdl, Timer*, void); + DECL_LINK(CancelHdl, weld::Button&, void); + DECL_LINK(AcceptHdl, weld::Button&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_STATIC_LINK(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool); + DECL_LINK(MousePressHdl, const MouseEvent&, bool); + DECL_LINK(MouseReleaseHdl, const MouseEvent&, bool); + DECL_LINK(SizeAllocHdl, const Size&, void); + + LicenseDialogImpl(weld::Window * pParent, + const OUString & sExtensionName, + const OUString & sLicenseText); bool IsEndReached() const; - bool EndReached() const { return mbEndReached; } - - void SetEndReachedHdl( const Link<LicenseView&,void>& rHdl ) { maEndReachedHdl = rHdl; } - - void SetScrolledHdl( const Link<LicenseView&,void>& rHdl ) { maScrolledHdl = rHdl; } - - virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; }; -struct LicenseDialogImpl : public ModalDialog +LicenseDialogImpl::LicenseDialogImpl( + weld::Window * pParent, + const OUString & sExtensionName, + const OUString & sLicenseText) + : GenericDialogController(pParent, "desktop/ui/licensedialog.ui", "LicenseDialog") + , m_bLicenseRead(false) + , m_xFtHead(m_xBuilder->weld_label("head")) + , m_xArrow1(m_xBuilder->weld_widget("arrow1")) + , m_xArrow2(m_xBuilder->weld_widget("arrow2")) + , m_xLicense(m_xBuilder->weld_text_view("textview")) + , m_xDown(m_xBuilder->weld_button("down")) + , m_xAcceptButton(m_xBuilder->weld_button("ok")) + , m_xDeclineButton(m_xBuilder->weld_button("cancel")) { - VclPtr<FixedText> m_pFtHead; - VclPtr<FixedImage> m_pArrow1; - VclPtr<FixedImage> m_pArrow2; - VclPtr<LicenseView> m_pLicense; - VclPtr<PushButton> m_pDown; - - VclPtr<PushButton> m_pAcceptButton; - VclPtr<PushButton> m_pDeclineButton; + m_xArrow1->show(); + m_xArrow2->hide(); - DECL_LINK(PageDownHdl, Button*, void); - DECL_LINK(ScrolledHdl, LicenseView&, void); - DECL_LINK(EndReachedHdl, LicenseView&, void); - DECL_LINK(CancelHdl, Button*, void); - DECL_LINK(AcceptHdl, Button*, void); + m_xLicense->connect_size_allocate(LINK(this, LicenseDialogImpl, SizeAllocHdl)); + m_xLicense->set_size_request(m_xLicense->get_approximate_digit_width() * 72, + m_xLicense->get_height_rows(21)); - bool m_bLicenseRead; + m_xLicense->set_text(sLicenseText); + m_xFtHead->set_label(m_xFtHead->get_label() + "\n" + sExtensionName); - LicenseDialogImpl( - vcl::Window * pParent, - const OUString & sExtensionName, - const OUString & sLicenseText); - virtual ~LicenseDialogImpl() override { disposeOnce(); } - virtual void dispose() override; + m_xAcceptButton->connect_clicked( LINK(this, LicenseDialogImpl, AcceptHdl) ); + m_xDeclineButton->connect_clicked( LINK(this, LicenseDialogImpl, CancelHdl) ); - virtual void Activate() override; + m_xLicense->connect_vadjustment_changed(LINK(this, LicenseDialogImpl, ScrolledHdl)); + m_xDown->connect_mouse_press(LINK(this, LicenseDialogImpl, MousePressHdl)); + m_xDown->connect_mouse_release(LINK(this, LicenseDialogImpl, MouseReleaseHdl)); + m_xDown->connect_key_press(LINK(this, LicenseDialogImpl, KeyInputHdl)); + m_xDown->connect_key_release(LINK(this, LicenseDialogImpl, KeyReleaseHdl)); -}; + m_aRepeat.SetTimeout(Application::GetSettings().GetMouseSettings().GetButtonRepeat()); + m_aRepeat.SetInvokeHandler(LINK(this, LicenseDialogImpl, ScrollTimerHdl)); -void LicenseDialogImpl::dispose() -{ - m_pFtHead.clear(); - m_pArrow1.clear(); - m_pArrow2.clear(); - m_pLicense.clear(); - m_pDown.clear(); - m_pAcceptButton.clear(); - m_pDeclineButton.clear(); - ModalDialog::dispose(); + m_aResized.SetPriority(TaskPriority::LOWEST); + m_aResized.SetInvokeHandler(LINK(this, LicenseDialogImpl, ResizedHdl)); } - -LicenseView::LicenseView( vcl::Window* pParent, WinBits nStyle ) - : MultiLineEdit( pParent, nStyle ) +IMPL_LINK_NOARG(LicenseDialogImpl, SizeAllocHdl, const Size&, void) { - SetLeftMargin( 5 ); - mbEndReached = IsEndReached(); - StartListening( *GetTextEngine() ); + m_aResized.Start(); } -VCL_BUILDER_FACTORY_CONSTRUCTOR(LicenseView, WB_CLIPCHILDREN|WB_LEFT|WB_VSCROLL) - -LicenseView::~LicenseView() +IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, weld::Button&, void) { - disposeOnce(); + m_xDialog->response(RET_OK); } -void LicenseView::dispose() +IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, weld::Button&, void) { - maEndReachedHdl = Link<LicenseView&,void>(); - maScrolledHdl = Link<LicenseView&,void>(); - EndListeningAll(); - MultiLineEdit::dispose(); + m_xDialog->response(RET_CANCEL); } -void LicenseView::ScrollDown( ScrollType eScroll ) +bool LicenseDialogImpl::IsEndReached() const { - ScrollBar* pScroll = GetVScrollBar(); - if ( pScroll ) - pScroll->DoScrollAction( eScroll ); -} - -bool LicenseView::IsEndReached() const -{ - bool bEndReached; - - TextView* pView = GetTextView(); - ExtTextEngine* pEdit = GetTextEngine(); - const long nHeight = pEdit->GetTextHeight(); - Size aOutSize = pView->GetWindow()->GetOutputSizePixel(); - Point aBottom( 0, aOutSize.Height() ); - - bEndReached = pView->GetDocPos( aBottom ).Y() >= nHeight - 1; - - return bEndReached; + return m_xLicense->vadjustment_get_value() + m_xLicense->vadjustment_get_page_size() >= m_xLicense->vadjustment_get_upper(); } -void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint ) +IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl, weld::TextView&, void) { - const TextHint* pTextHint = dynamic_cast<const TextHint*>(&rHint); - if ( pTextHint ) + if (IsEndReached()) { - bool bLastVal = EndReached(); - const SfxHintId nId = pTextHint->GetId(); + m_xDown->set_sensitive(false); + m_aRepeat.Stop(); - if ( nId == SfxHintId::TextParaInserted ) + if (!m_bLicenseRead) { - if ( bLastVal ) - mbEndReached = IsEndReached(); - } - else if ( nId == SfxHintId::TextViewScrolled ) - { - if ( ! mbEndReached ) - mbEndReached = IsEndReached(); - maScrolledHdl.Call( *this ); - } - - if ( EndReached() && !bLastVal ) - { - maEndReachedHdl.Call( *this ); + m_xAcceptButton->set_sensitive(true); + m_xAcceptButton->grab_focus(); + m_xArrow1->hide(); + m_xArrow2->show(); + m_bLicenseRead = true; } } + else + m_xDown->set_sensitive(true); } - -LicenseDialogImpl::LicenseDialogImpl( - vcl::Window * pParent, - const OUString & sExtensionName, - const OUString & sLicenseText) - : ModalDialog(pParent, "LicenseDialog", "desktop/ui/licensedialog.ui") - , m_bLicenseRead(false) +void LicenseDialogImpl::PageDown() { - get(m_pFtHead, "head"); - get(m_pArrow1, "arrow1"); - get(m_pArrow2, "arrow2"); - get(m_pDown, "down"); - get(m_pAcceptButton, "accept"); - get(m_pDeclineButton, "decline"); - m_pArrow1->Show(); - m_pArrow2->Show(false); - get(m_pLicense, "textview"); - - Size aSize(m_pLicense->LogicToPixel(Size(290, 170), MapMode(MapUnit::MapAppFont))); - m_pLicense->set_width_request(aSize.Width()); - m_pLicense->set_height_request(aSize.Height()); - - m_pLicense->SetText(sLicenseText); - m_pFtHead->SetText(m_pFtHead->GetText() + "\n" + sExtensionName); - - m_pAcceptButton->SetClickHdl( LINK(this, LicenseDialogImpl, AcceptHdl) ); - m_pDeclineButton->SetClickHdl( LINK(this, LicenseDialogImpl, CancelHdl) ); - - m_pLicense->SetEndReachedHdl( LINK(this, LicenseDialogImpl, EndReachedHdl) ); - m_pLicense->SetScrolledHdl( LINK(this, LicenseDialogImpl, ScrolledHdl) ); - m_pDown->SetClickHdl( LINK(this, LicenseDialogImpl, PageDownHdl) ); - - // We want a automatic repeating page down button - WinBits aStyle = m_pDown->GetStyle(); - aStyle |= WB_REPEAT; - m_pDown->SetStyle( aStyle ); + m_xLicense->vadjustment_set_value(m_xLicense->vadjustment_get_value() + + m_xLicense->vadjustment_get_page_size()); + ScrolledHdl(*m_xLicense); } -IMPL_LINK_NOARG(LicenseDialogImpl, AcceptHdl, Button*, void) +IMPL_LINK(LicenseDialogImpl, KeyInputHdl, const KeyEvent&, rKEvt, bool) { - EndDialog(RET_OK); + vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); + if (aKeyCode.GetCode() == KEY_RETURN || aKeyCode.GetCode() == KEY_SPACE) + PageDown(); + return false; } -IMPL_LINK_NOARG(LicenseDialogImpl, CancelHdl, Button*, void) +IMPL_LINK_NOARG(LicenseDialogImpl, ResizedHdl, Timer*, void) { - EndDialog(); + ScrolledHdl(*m_xLicense); } -void LicenseDialogImpl::Activate() +IMPL_LINK_NOARG(LicenseDialogImpl, ScrollTimerHdl, Timer*, void) { - if (!m_bLicenseRead) - { - //Only enable the scroll down button if the license text does not fit into the window - if (m_pLicense->IsEndReached()) - { - m_pDown->Disable(); - m_pAcceptButton->Enable(); - m_pAcceptButton->GrabFocus(); - } - else - { - m_pDown->Enable(); - m_pDown->GrabFocus(); - m_pAcceptButton->Disable(); - } - } + PageDown(); } -IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl, LicenseView&, void) +IMPL_STATIC_LINK_NOARG(LicenseDialogImpl, KeyReleaseHdl, const KeyEvent&, bool) { - if (m_pLicense->IsEndReached()) - m_pDown->Disable(); - else - m_pDown->Enable(); + return false; } -IMPL_LINK_NOARG(LicenseDialogImpl, PageDownHdl, Button*, void) +IMPL_LINK_NOARG(LicenseDialogImpl, MousePressHdl, const MouseEvent&, bool) { - m_pLicense->ScrollDown( ScrollType::PageDown ); + PageDown(); + m_aRepeat.Start(); + return false; } -IMPL_LINK_NOARG(LicenseDialogImpl, EndReachedHdl, LicenseView&, void) +IMPL_LINK_NOARG(LicenseDialogImpl, MouseReleaseHdl, const MouseEvent&, bool) { - m_pAcceptButton->Enable(); - m_pAcceptButton->GrabFocus(); - m_pArrow1->Show(false); - m_pArrow2->Show(); - m_bLicenseRead = true; + m_aRepeat.Stop(); + return false; } - LicenseDialog::LicenseDialog( Sequence<Any> const& args, Reference<XComponentContext> const& ) { @@ -282,10 +211,8 @@ LicenseDialog::LicenseDialog( Sequence<Any> const& args, void LicenseDialog::setTitle( OUString const & ) { - } - sal_Int16 LicenseDialog::execute() { return vcl::solarthread::syncExecute( @@ -294,10 +221,8 @@ sal_Int16 LicenseDialog::execute() sal_Int16 LicenseDialog::solar_execute() { - ScopedVclPtrInstance<LicenseDialogImpl> dlg( - VCLUnoHelper::GetWindow(m_parent), m_sExtensionName, m_sLicenseText); - - return dlg->Execute(); + LicenseDialogImpl dlg(Application::GetFrameWeld(m_parent), m_sExtensionName, m_sLicenseText); + return dlg.run(); } } // namespace dp_gui diff --git a/desktop/uiconfig/ui/licensedialog.ui b/desktop/uiconfig/ui/licensedialog.ui index d7e77615b29a..bb139219e353 100644 --- a/desktop/uiconfig/ui/licensedialog.ui +++ b/desktop/uiconfig/ui/licensedialog.ui @@ -1,12 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> <interface domain="dkt"> <requires lib="gtk+" version="3.18"/> - <requires lib="LibreOffice" version="1.0"/> <object class="GtkDialog" id="LicenseDialog"> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="licensedialog|LicenseDialog">Extension Software License Agreement</property> <property name="type_hint">dialog</property> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> <property name="can_focus">False</property> @@ -17,7 +20,7 @@ <property name="can_focus">False</property> <property name="layout_style">end</property> <child> - <object class="GtkButton" id="accept"> + <object class="GtkButton" id="ok"> <property name="label" translatable="yes" context="licensedialog|accept">Accept</property> <property name="visible">True</property> <property name="can_focus">True</property> @@ -32,7 +35,7 @@ </packing> </child> <child> - <object class="GtkButton" id="decline"> + <object class="GtkButton" id="cancel"> <property name="label" translatable="yes" context="licensedialog|decline">Decline</property> <property name="visible">True</property> <property name="can_focus">True</property> @@ -63,14 +66,12 @@ <object class="GtkLabel" id="head"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="licensedialog|head">Please follow these steps to proceed with the installation of the extension:</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">0</property> <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -86,14 +87,12 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="licensedialog|label2">1.</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">1</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -101,14 +100,12 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="licensedialog|label3">2.</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">1</property> <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -116,13 +113,11 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="pixbuf">res/sc06300.png</property> + <property name="icon_name">res/sc06300.png</property> </object> <packing> <property name="left_attach">0</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -130,13 +125,11 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="valign">start</property> - <property name="pixbuf">res/sc06300.png</property> + <property name="icon_name">res/sc06300.png</property> </object> <packing> <property name="left_attach">0</property> <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -145,16 +138,15 @@ <property name="can_focus">False</property> <property name="valign">start</property> <property name="hexpand">True</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="licensedialog|label4">Read the complete License Agreement. Use the scroll bar or the 'Scroll Down' button in this dialog to view the entire license text.</property> <property name="wrap">True</property> + <property name="width_chars">55</property> <property name="max_width_chars">55</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">2</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -163,16 +155,15 @@ <property name="can_focus">False</property> <property name="valign">start</property> <property name="hexpand">True</property> - <property name="xalign">0</property> <property name="label" translatable="yes" context="licensedialog|label5">Accept the License Agreement for the extension by pressing the 'Accept' button.</property> <property name="wrap">True</property> + <property name="width_chars">55</property> <property name="max_width_chars">55</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">2</property> <property name="top_attach">1</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> @@ -181,13 +172,13 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> + <property name="events">GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_STRUCTURE_MASK</property> <property name="valign">start</property> <property name="use_underline">True</property> </object> <packing> <property name="left_attach">3</property> <property name="top_attach">0</property> - <property name="width">1</property> <property name="height">2</property> </packing> </child> @@ -195,23 +186,28 @@ <packing> <property name="left_attach">0</property> <property name="top_attach">2</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> <child> - <object class="deploymentgui-LicenseView" id="textview:border"> + <object class="GtkScrolledWindow"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> - <property name="editable">False</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTextView" id="textview"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="editable">False</property> + </object> + </child> </object> <packing> <property name="left_attach">0</property> <property name="top_attach">0</property> - <property name="width">1</property> - <property name="height">1</property> </packing> </child> </object> @@ -224,8 +220,8 @@ </object> </child> <action-widgets> - <action-widget response="0">accept</action-widget> - <action-widget response="0">decline</action-widget> + <action-widget response="-5">ok</action-widget> + <action-widget response="-6">cancel</action-widget> </action-widgets> </object> </interface> |