include/svtools/ctrlbox.hxx | 3 ++- include/vcl/toolkit/combobox.hxx | 1 + include/vcl/weld.hxx | 2 +- svtools/source/control/ctrlbox.cxx | 26 +++++++++++++++++--------- svx/source/tbxctrls/tbcontrl.cxx | 16 ++++++++++------ vcl/inc/salvtables.hxx | 4 ++-- vcl/source/app/salvtables.cxx | 18 ++++++++++++------ vcl/source/control/combobox.cxx | 5 +++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 36 +++++++++++++++++++++++++----------- 9 files changed, 75 insertions(+), 36 deletions(-)
New commits: commit a5f95804c1a730fb393c33b49e6fbe0f5a5e9eac Author: Caolán McNamara <[email protected]> AuthorDate: Sat Jul 4 18:00:52 2020 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Sun Jul 5 16:42:39 2020 +0200 tdf#134479 allow disable font preview to work on existing font comboboxes not just newly created one. you can only restore back to a text-only view, not a text+(icon/whatever) view Change-Id: Ic3becd7a942ee6b1dbabb57eebf1e25d1b626fdb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97991 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx index 301a9c13047f..1c3185915b7d 100644 --- a/include/svtools/ctrlbox.hxx +++ b/include/svtools/ctrlbox.hxx @@ -353,7 +353,8 @@ public: void Fill( const FontList* pList ); - void EnableWYSIWYG(); + void EnableWYSIWYG(bool bEnable); + bool IsWYSIWYGEnabled() const { return mbWYSIWYG; } void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xComboBox->connect_changed(rLink); } void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xComboBox->connect_focus_in(rLink); } diff --git a/include/vcl/toolkit/combobox.hxx b/include/vcl/toolkit/combobox.hxx index a3c4e1cee5b3..611bce590add 100644 --- a/include/vcl/toolkit/combobox.hxx +++ b/include/vcl/toolkit/combobox.hxx @@ -102,6 +102,7 @@ public: void SetUserItemSize( const Size& rSz ); void EnableUserDraw( bool bUserDraw ); + bool IsUserDrawEnabled() const; void DrawEntry( const UserDrawEvent& rEvt ); void SetBorderStyle( WindowBorderStyle nBorderStyle ); diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index cad56785acb2..cae26c1ffccf 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -732,7 +732,7 @@ public: } void connect_custom_render(const Link<render_args, void>& rLink) { m_aRenderHdl = rLink; } // call set_custom_renderer after setting custom callbacks - virtual void set_custom_renderer() = 0; + virtual void set_custom_renderer(bool bOn) = 0; // create a virtual device compatible with the device passed in render_args wrt alpha virtual VclPtr<VirtualDevice> create_render_virtual_device() const = 0; // set a sub menu for a entry, only works with custom rendering diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index e60494a51097..555d35a94aa0 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -466,14 +466,16 @@ void FontNameBox::Fill( const FontList* pList ) set_active_or_entry_text(aOldText); } -void FontNameBox::EnableWYSIWYG() +void FontNameBox::EnableWYSIWYG(bool bEnable) { - if (mbWYSIWYG || comphelper::LibreOfficeKit::isActive()) + if (comphelper::LibreOfficeKit::isActive()) return; - mbWYSIWYG = true; + if (mbWYSIWYG == bEnable) + return; + mbWYSIWYG = bEnable; static bool bGlobalsInited; - if (!bGlobalsInited) + if (mbWYSIWYG && !bGlobalsInited) { gUserItemSz = Size(m_xComboBox->get_approximate_digit_width() * 52, m_xComboBox->get_text_height()); gUserItemSz.setHeight(gUserItemSz.Height() * 16); @@ -485,11 +487,17 @@ void FontNameBox::EnableWYSIWYG() bGlobalsInited = true; } - m_xComboBox->connect_custom_get_size(LINK(this, FontNameBox, CustomGetSizeHdl)); - m_xComboBox->connect_custom_render(LINK(this, FontNameBox, CustomRenderHdl)); - m_xComboBox->set_custom_renderer(); - - mbWYSIWYG = true; + if (mbWYSIWYG) + { + m_xComboBox->connect_custom_get_size(LINK(this, FontNameBox, CustomGetSizeHdl)); + m_xComboBox->connect_custom_render(LINK(this, FontNameBox, CustomRenderHdl)); + } + else + { + m_xComboBox->connect_custom_get_size(Link<OutputDevice&, Size>()); + m_xComboBox->connect_custom_render(Link<weld::ComboBox::render_args, void>()); + } + m_xComboBox->set_custom_renderer(mbWYSIWYG); } IMPL_STATIC_LINK_NOARG(FontNameBox, CustomGetSizeHdl, OutputDevice&, Size) diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 732ad7d9f835..d64e033d6823 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -856,7 +856,7 @@ SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl)); m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl)); - m_xWidget->set_custom_renderer(); + m_xWidget->set_custom_renderer(true); m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS); } @@ -1635,9 +1635,13 @@ void SvxFontNameBox_Base::ReleaseFocus_Impl() void SvxFontNameBox_Base::EnableControls_Impl() { SvtFontOptions aFontOpt; - bool bEnable = aFontOpt.IsFontHistoryEnabled(); - sal_uInt16 nEntries = bEnable ? MAX_MRU_FONTNAME_ENTRIES : 0; - if (m_xWidget->get_max_mru_count() != nEntries) + bool bEnableMRU = aFontOpt.IsFontHistoryEnabled(); + sal_uInt16 nEntries = bEnableMRU ? MAX_MRU_FONTNAME_ENTRIES : 0; + + bool bNewWYSIWYG = aFontOpt.IsFontWYSIWYGEnabled(); + bool bOldWYSIWYG = m_xWidget->IsWYSIWYGEnabled(); + + if (m_xWidget->get_max_mru_count() != nEntries || bNewWYSIWYG != bOldWYSIWYG) { // refill in the next GetFocus-Handler pFontList = nullptr; @@ -1645,8 +1649,8 @@ void SvxFontNameBox_Base::EnableControls_Impl() m_xWidget->set_max_mru_count(nEntries); } - if (aFontOpt.IsFontWYSIWYGEnabled()) - m_xWidget->EnableWYSIWYG(); + if (bNewWYSIWYG != bOldWYSIWYG) + m_xWidget->EnableWYSIWYG(bNewWYSIWYG); } IMPL_LINK(SvxFontNameBox_Base, SelectHdl, weld::ComboBox&, rCombo, void) diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index a71c31941d51..5cde0ae6a4bd 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -910,7 +910,7 @@ public: virtual vcl::Font get_entry_font() override; - virtual void set_custom_renderer() override; + virtual void set_custom_renderer(bool bOn) override; virtual int get_max_mru_count() const override; @@ -980,7 +980,7 @@ public: virtual vcl::Font get_entry_font() override; - virtual void set_custom_renderer() override; + virtual void set_custom_renderer(bool bOn) override; virtual int get_max_mru_count() const override; diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 535ac3566cde..930590fb7dc7 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -5739,7 +5739,7 @@ void SalInstanceComboBoxWithoutEdit::set_entry_font(const vcl::Font&) { assert(f vcl::Font SalInstanceComboBoxWithoutEdit::get_entry_font() { assert(false); return vcl::Font(); } -void SalInstanceComboBoxWithoutEdit::set_custom_renderer() +void SalInstanceComboBoxWithoutEdit::set_custom_renderer(bool /*bOn*/) { assert(false && "not implemented"); } @@ -5907,16 +5907,22 @@ vcl::Font SalInstanceComboBoxWithEdit::get_entry_font() return pEdit->GetPointFont(*pEdit); } -void SalInstanceComboBoxWithEdit::set_custom_renderer() +void SalInstanceComboBoxWithEdit::set_custom_renderer(bool bOn) { + if (m_xComboBox->IsUserDrawEnabled() == bOn) + return; + auto nOldEntryHeight = m_xComboBox->GetDropDownEntryHeight(); auto nDropDownLineCount = m_xComboBox->GetDropDownLineCount(); - m_xComboBox->EnableUserDraw(true); - m_xComboBox->SetUserDrawHdl(LINK(this, SalInstanceComboBoxWithEdit, UserDrawHdl)); + m_xComboBox->EnableUserDraw(bOn); + if (bOn) + m_xComboBox->SetUserDrawHdl(LINK(this, SalInstanceComboBoxWithEdit, UserDrawHdl)); + else + m_xComboBox->SetUserDrawHdl(Link<UserDrawEvent*, void>()); // adjust the line count to fit approx the height it would have been before - // using a custom renderer + // changing the renderer auto nNewEntryHeight = m_xComboBox->GetDropDownEntryHeight(); double fRatio = nOldEntryHeight / static_cast<double>(nNewEntryHeight); m_xComboBox->SetDropDownLineCount(nDropDownLineCount * fRatio); @@ -6082,7 +6088,7 @@ public: virtual bool changed_by_direct_pick() const override { return m_bTreeChange; } - virtual void set_custom_renderer() override + virtual void set_custom_renderer(bool /*bOn*/) override { assert(false && "not implemented"); } diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index 13a3bc8dfeaa..0de42f530856 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -1268,6 +1268,11 @@ void ComboBox::EnableUserDraw( bool bUserDraw ) m_pImpl->m_pImplLB->GetMainWindow()->EnableUserDraw( bUserDraw ); } +bool ComboBox::IsUserDrawEnabled() const +{ + return m_pImpl->m_pImplLB->GetMainWindow()->IsUserDrawEnabled(); +} + void ComboBox::DrawEntry(const UserDrawEvent& rEvt) { SAL_WARN_IF(rEvt.GetWindow() != m_pImpl->m_pImplLB->GetMainWindow(), "vcl", "DrawEntry?!"); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index e4449b121e41..f2b3b8fb310a 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -12739,6 +12739,7 @@ private: bool m_bAutoComplete; bool m_bAutoCompleteCaseSensitive; bool m_bChangedByMenu; + bool m_bCustomRenderer; bool m_bActivateCalled; gint m_nTextCol; gint m_nIdCol; @@ -13752,6 +13753,7 @@ public: , m_bAutoComplete(false) , m_bAutoCompleteCaseSensitive(false) , m_bChangedByMenu(false) + , m_bCustomRenderer(false) , m_bActivateCalled(false) , m_nTextCol(gtk_combo_box_get_entry_text_column(pComboBox)) , m_nIdCol(gtk_combo_box_get_id_column(pComboBox)) @@ -14274,22 +14276,34 @@ public: return m_bChangedByMenu; } - virtual void set_custom_renderer() override + virtual void set_custom_renderer(bool bOn) override { + if (bOn == m_bCustomRenderer) + return; GList* pColumns = gtk_tree_view_get_columns(m_pTreeView); // keep the original height around for optimal popup height calculation - m_nNonCustomLineHeight = ::get_height_row(m_pTreeView, pColumns); + m_nNonCustomLineHeight = bOn ? ::get_height_row(m_pTreeView, pColumns) : -1; GtkTreeViewColumn* pColumn = GTK_TREE_VIEW_COLUMN(pColumns->data); gtk_cell_layout_clear(GTK_CELL_LAYOUT(pColumn)); - GtkCellRenderer *pRenderer = custom_cell_renderer_surface_new(); - GValue value = G_VALUE_INIT; - g_value_init(&value, G_TYPE_POINTER); - g_value_set_pointer(&value, static_cast<gpointer>(this)); - g_object_set_property(G_OBJECT(pRenderer), "instance", &value); - gtk_tree_view_column_pack_start(pColumn, pRenderer, true); - gtk_tree_view_column_add_attribute(pColumn, pRenderer, "text", m_nTextCol); - gtk_tree_view_column_add_attribute(pColumn, pRenderer, "id", m_nIdCol); + if (bOn) + { + GtkCellRenderer *pRenderer = custom_cell_renderer_surface_new(); + GValue value = G_VALUE_INIT; + g_value_init(&value, G_TYPE_POINTER); + g_value_set_pointer(&value, static_cast<gpointer>(this)); + g_object_set_property(G_OBJECT(pRenderer), "instance", &value); + gtk_tree_view_column_pack_start(pColumn, pRenderer, true); + gtk_tree_view_column_add_attribute(pColumn, pRenderer, "text", m_nTextCol); + gtk_tree_view_column_add_attribute(pColumn, pRenderer, "id", m_nIdCol); + } + else + { + GtkCellRenderer *pRenderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(pColumn, pRenderer, true); + gtk_tree_view_column_add_attribute(pColumn, pRenderer, "text", m_nTextCol); + } g_list_free(pColumns); + m_bCustomRenderer = bOn; } void call_signal_custom_render(VirtualDevice& rOutput, const tools::Rectangle& rRect, bool bSelected, const OUString& rId) @@ -14762,7 +14776,7 @@ public: return m_bTreeChange; } - virtual void set_custom_renderer() override + virtual void set_custom_renderer(bool /*bOn*/) override { assert(false && "not implemented"); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
