diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-04 18:00:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-04 19:55:29 +0200 |
commit | f9d86399e92d9c734fdffc6a7c83a2007877ba93 (patch) | |
tree | a3f511ff9734e2c9e688bfa74d64f609e3aedd52 | |
parent | d70da0b9e24991f8d58e83f53dbbf5b58c721f43 (diff) |
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/+/97972
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/svtools/ctrlbox.hxx | 3 | ||||
-rw-r--r-- | include/vcl/toolkit/combobox.hxx | 1 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 2 | ||||
-rw-r--r-- | svtools/source/control/ctrlbox.cxx | 26 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 16 | ||||
-rw-r--r-- | vcl/inc/salvtables.hxx | 4 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 18 | ||||
-rw-r--r-- | vcl/source/control/combobox.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 36 |
9 files changed, 75 insertions, 36 deletions
diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx index 4b5035fbdec4..367b3ff42872 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 cf4abaf5011d..ee110a049888 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -735,7 +735,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 d8e0e6d90991..2d398c992dff 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); } @@ -1632,9 +1632,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; @@ -1642,8 +1646,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 d621e3fc470c..6eb671fa820c 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -917,7 +917,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; @@ -987,7 +987,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 e670a8fe4d6b..22b8329cb9f5 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -5912,7 +5912,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"); } @@ -6080,16 +6080,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); @@ -6255,7 +6261,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 5cfbb85d4810..881acd2a654c 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 144cb6b66563..a7d8a9cd30a7 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -12949,6 +12949,7 @@ private: bool m_bAutoComplete; bool m_bAutoCompleteCaseSensitive; bool m_bChangedByMenu; + bool m_bCustomRenderer; bool m_bActivateCalled; gint m_nTextCol; gint m_nIdCol; @@ -13950,6 +13951,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)) @@ -14472,22 +14474,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) @@ -14960,7 +14974,7 @@ public: return m_bTreeChange; } - virtual void set_custom_renderer() override + virtual void set_custom_renderer(bool /*bOn*/) override { assert(false && "not implemented"); } |