diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-18 16:54:43 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-18 20:11:40 +0100 |
commit | 16f84d79ad209a4a6e033880d3059810c37e73c0 (patch) | |
tree | 90f40eaa40e6448709d0ad83e699f4a3cd6350ee /vcl/unx | |
parent | 86b160886f6d5580a84f5008682cc93fa8c63e39 (diff) |
add id column support to tree view
Change-Id: I11702f58e488bcf3fcd49c45c11b5059298f81fd
Reviewed-on: https://gerrit.libreoffice.org/51512
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index e249a21dc5aa..13b957dff0f2 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -2080,6 +2080,22 @@ private: GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget); pThis->signal_row_activated(); } + + OUString get(int pos, int col) const + { + OUString sRet; + GtkTreeModel *pModel = GTK_TREE_MODEL(m_pListStore); + GtkTreeIter iter; + if (gtk_tree_model_iter_nth_child(pModel, &iter, nullptr, pos)) + { + gchar* pStr; + gtk_tree_model_get(pModel, &iter, col, &pStr, -1); + sRet = OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); + g_free(pStr); + } + return sRet; + } + public: GtkInstanceTreeView(GtkTreeView* pTreeView, bool bTakeOwnership) : GtkInstanceContainer(GTK_CONTAINER(pTreeView), bTakeOwnership) @@ -2091,17 +2107,24 @@ public: { } - virtual void append(const OUString& rText) override + virtual void insert_text(const OUString& rText, int pos) override { - insert(rText, -1); + disable_notify_events(); + GtkTreeIter iter; + gtk_list_store_insert(m_pListStore, &iter, pos); + gtk_list_store_set(m_pListStore, &iter, 0, OUStringToOString(rText, RTL_TEXTENCODING_UTF8).getStr(), -1); + enable_notify_events(); } - virtual void insert(const OUString& rText, int pos) override + virtual void insert(int pos, const OUString& rId, const OUString& rText) override { disable_notify_events(); GtkTreeIter iter; gtk_list_store_insert(m_pListStore, &iter, pos); - gtk_list_store_set(m_pListStore, &iter, 0, OUStringToOString(rText, RTL_TEXTENCODING_UTF8).getStr(), -1); + gtk_list_store_set(m_pListStore, &iter, + 0, OUStringToOString(rText, RTL_TEXTENCODING_UTF8).getStr(), + 1, OUStringToOString(rId, RTL_TEXTENCODING_UTF8).getStr(), + -1); enable_notify_events(); } @@ -2175,7 +2198,7 @@ public: enable_notify_events(); } - virtual OUString get_selected() override + virtual OUString get_selected() const override { OUString sRet; GtkTreeIter iter; @@ -2190,18 +2213,17 @@ public: return sRet; } - virtual OUString get(int pos) override + virtual OUString get(int pos) const override { - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_pListStore), &iter, nullptr, pos); - gchar *pStr = nullptr; - gtk_tree_model_get(GTK_TREE_MODEL(m_pListStore), &iter, 0, &pStr, -1); - OUString sRet = OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); - g_free(pStr); - return sRet; + return get(pos, 0); } - virtual int get_selected_index() override + virtual OUString get_id(int pos) const override + { + return get(pos, 1); + } + + virtual int get_selected_index() const override { int nRet = -1; GtkTreeIter iter; @@ -2632,7 +2654,7 @@ private: { gchar* pStr; gtk_tree_model_get(pModel, &iter, col, &pStr, -1); - sRet = OUString(pStr, strlen(pStr), RTL_TEXTENCODING_UTF8); + sRet = OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); g_free(pStr); } return sRet; @@ -2730,28 +2752,20 @@ public: return get(pos, id_column); } - virtual void append_text(const OUString& rStr) override - { - gtk_combo_box_text_append_text(m_pComboBoxText, OUStringToOString(rStr, RTL_TEXTENCODING_UTF8).getStr()); - } - virtual void insert_text(int pos, const OUString& rStr) override { + disable_notify_events(); gtk_combo_box_text_insert_text(m_pComboBoxText, pos, OUStringToOString(rStr, RTL_TEXTENCODING_UTF8).getStr()); - } - - virtual void append(const OUString& rId, const OUString& rStr) override - { - gtk_combo_box_text_append(m_pComboBoxText, - OUStringToOString(rId, RTL_TEXTENCODING_UTF8).getStr(), - OUStringToOString(rStr, RTL_TEXTENCODING_UTF8).getStr()); + enable_notify_events(); } virtual void insert(int pos, const OUString& rId, const OUString& rStr) override { + disable_notify_events(); gtk_combo_box_text_insert(m_pComboBoxText, pos, OUStringToOString(rId, RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString(rStr, RTL_TEXTENCODING_UTF8).getStr()); + enable_notify_events(); } virtual int get_count() const override |