include/vcl/weld.hxx | 44 +++++++++++++++++++++++++++++++++++++------- vcl/unx/gtk3/gtkinst.cxx | 12 +++++++----- 2 files changed, 44 insertions(+), 12 deletions(-)
New commits: commit 77b505b0b9fd86d2bd8e82f2be7d40307dfd1493 Author: Caolán McNamara <[email protected]> AuthorDate: Fri May 21 17:23:12 2021 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Sat May 22 18:00:21 2021 +0200 document how the on-demand treeview entries work Put the expand related methods beside eachother and give a hint how to avoid placeholder inconsistencies Change-Id: I798e5e69d5a7a1c5e30e5b77b9bcfbfe731a0536 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115951 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 680b1db92c69..858218e3b5d8 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -933,6 +933,7 @@ public: m_aQueryTooltipHdl = rLink; } + // see 'expanding on-demand node details' for bChildrenOnDemand of true virtual void insert(const TreeIter* pParent, int pos, const OUString* pStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface, bool bChildrenOnDemand, TreeIter* pRet) @@ -1105,13 +1106,8 @@ public: //Don't select when frozen, select after thaw. Note selection doesn't survive a freeze. virtual void select(const TreeIter& rIter) = 0; virtual void unselect(const TreeIter& rIter) = 0; - virtual bool get_row_expanded(const TreeIter& rIter) const = 0; - virtual bool get_children_on_demand(const TreeIter& rIter) const = 0; - virtual void set_children_on_demand(const TreeIter& rIter, bool bChildrenOnDemand) = 0; //visually indent this row as if it was at get_iter_depth() + nIndentLevel virtual void set_extra_row_indent(const TreeIter& rIter, int nIndentLevel) = 0; - virtual void expand_row(const TreeIter& rIter) = 0; - virtual void collapse_row(const TreeIter& rIter) = 0; // col index -1 sets the first text column virtual void set_text(const TreeIter& rIter, const OUString& rStr, int col = -1) = 0; // col index -1 sets the first text column @@ -1167,6 +1163,42 @@ public: const std::vector<int>* pFixedWidths = nullptr) = 0; + /* expanding on-demand node details + + When a node is added with children-on-demand (typically via 'insert' with + bChildrenOnDemand of true), then initially in reality the + children-on-demand node is given a 'placeholder' child entry to indicate + the load-on-demand state. + + The 'placeholder' needs to be there for the expander indicator to be + drawn/shown even when there are no "real" entries yet. This child doesn't + exist for the purposes of any of the iterator methods, e.g. iter_has_child + on an on-demand node which hasn't been expanded yet is false. Likewise the + rest of the iterator methods skip over or otherwise ignore that node. + + Normal usage is the user clicks on the expander, the expansion mechanism + removes the 'placeholder' entry (set_children_on_demand(false)) and calls + any installed expanding-callback (installable via connect_expanding) which + has the opportunity to populate the node with children. + + If you decide to directly populate the children of an on-demand node + outside of the expanding-callback then you also need to explicitly remove + the 'placeholder' with set_children_on_demand(false) otherwise the treeview + is in an inconsistent state. */ + + virtual bool get_row_expanded(const TreeIter& rIter) const = 0; + // expand row will first trigger the callback set via connect_expanding before expanding + virtual void expand_row(const TreeIter& rIter) = 0; + // collapse row will first trigger the callback set via connect_collapsing before collapsing + virtual void collapse_row(const TreeIter& rIter) = 0; + // set the empty node to appear as if it has children, true is equivalent + // to 'insert' with a bChildrenOnDemand of true. See notes above. + virtual void set_children_on_demand(const TreeIter& rIter, bool bChildrenOnDemand) = 0; + // return if the node is configured to be populated on-demand + virtual bool get_children_on_demand(const TreeIter& rIter) const = 0; + // set if the expanders are shown or not + virtual void set_show_expanders(bool bShow) = 0; + void connect_expanding(const Link<const TreeIter&, bool>& rLink) { m_aExpandingHdl = rLink; } void connect_collapsing(const Link<const TreeIter&, bool>& rLink) { m_aCollapsingHdl = rLink; } @@ -1251,8 +1283,6 @@ public: OUString const& get_saved_value() const { return m_sSavedValue; } bool get_value_changed_from_saved() const { return m_sSavedValue != get_selected_text(); } - virtual void set_show_expanders(bool bShow) = 0; - // for custom rendering a cell void connect_custom_get_size(const Link<get_size_args, Size>& rLink) { m_aGetSizeHdl = rLink; } void connect_custom_render(const Link<render_args, void>& rLink) { m_aRenderHdl = rLink; } commit 1a0ff2476622d10167997939b66262ec674cbd10 Author: Caolán McNamara <[email protected]> AuthorDate: Fri May 21 15:44:30 2021 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Sat May 22 17:59:54 2021 +0200 gtk4: use gtk_window_is_active instead of gtk_window_has_toplevel_focus Change-Id: I0ff19754e4a4505a73ece999d16ec981e5616e42 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115982 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 8ca636e6d22c..8742521b878d 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -2059,16 +2059,19 @@ GdkDragAction VclToGdk(sal_Int8 dragOperation) } #endif -GtkWindow* get_focus_window() +GtkWindow* get_active_window() { GtkWindow* pFocus = nullptr; -#if !GTK_CHECK_VERSION(4, 0, 0) GList* pList = gtk_window_list_toplevels(); for (GList* pEntry = pList; pEntry; pEntry = pEntry->next) { +#if GTK_CHECK_VERSION(4, 0, 0) + if (gtk_window_is_active(GTK_WINDOW(pEntry->data))) +#else if (gtk_window_has_toplevel_focus(GTK_WINDOW(pEntry->data))) +#endif { pFocus = GTK_WINDOW(pEntry->data); break; @@ -2076,7 +2079,6 @@ GtkWindow* get_focus_window() } g_list_free(pList); -#endif return pFocus; } @@ -2087,7 +2089,7 @@ void LocalizeDecimalSeparator(GdkEventKey* pEvent) // #i1820# use locale specific decimal separator if (pEvent->keyval == GDK_KEY_KP_Decimal && Application::GetSettings().GetMiscSettings().GetEnableLocalizedDecimalSep()) { - GtkWindow* pFocusWin = get_focus_window(); + GtkWindow* pFocusWin = get_active_window(); GtkWidget* pFocus = pFocusWin ? gtk_window_get_focus(pFocusWin) : nullptr; // tdf#138932 except if the target is a GtkEntry used for passwords if (!pFocus || !GTK_IS_ENTRY(pFocus) || gtk_entry_get_visibility(GTK_ENTRY(pFocus))) @@ -2837,7 +2839,7 @@ public: // to a widget is considered a child of that widget virtual bool has_child_focus() const override { - GtkWindow* pFocusWin = get_focus_window(); + GtkWindow* pFocusWin = get_active_window(); if (!pFocusWin) return false; GtkWidget* pFocus = gtk_window_get_focus(pFocusWin); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
