]>
Commit | Line | Data |
---|---|---|
caaa4cfd | 1 | ///////////////////////////////////////////////////////////////////////////// |
caf6e6de | 2 | // Name: src/gtk/checklst.cpp |
caaa4cfd RR |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
caf6e6de | 5 | // Modified by: Ryan Norton (Native GTK2.0+ checklist) |
caaa4cfd RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 8 | // Licence: wxWindows licence |
caaa4cfd RR |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
14f355c2 VS |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
dcf924a3 RR |
14 | #if wxUSE_CHECKLISTBOX |
15 | ||
1e6feb95 | 16 | #include "wx/checklst.h" |
fab591c5 | 17 | #include "wx/gtk/private.h" |
4a46cbe8 | 18 | #include "wx/gtk/treeentry_gtk.h" |
1e6feb95 | 19 | |
071a2d78 RR |
20 | #include <gdk/gdk.h> |
21 | #include <gtk/gtk.h> | |
83624f79 | 22 | |
4a46cbe8 RR |
23 | //----------------------------------------------------------------------------- |
24 | // "toggled" | |
25 | //----------------------------------------------------------------------------- | |
4a46cbe8 | 26 | extern "C" { |
e4161a2a | 27 | static void gtk_checklist_toggled(GtkCellRendererToggle * WXUNUSED(renderer), |
4a46cbe8 RR |
28 | gchar *stringpath, |
29 | wxCheckListBox *listbox) | |
30 | { | |
31 | wxCHECK_RET( listbox->m_treeview != NULL, wxT("invalid listbox") ); | |
32 | ||
33 | GtkTreePath* path = gtk_tree_path_new_from_string(stringpath); | |
ce7fe42e | 34 | wxCommandEvent new_event( wxEVT_CHECKLISTBOX, |
4a46cbe8 RR |
35 | listbox->GetId() ); |
36 | new_event.SetEventObject( listbox ); | |
37 | new_event.SetInt( gtk_tree_path_get_indices(path)[0] ); | |
51fbe4cc | 38 | new_event.SetString( listbox->GetString( new_event.GetInt() )); |
4a46cbe8 RR |
39 | gtk_tree_path_free(path); |
40 | listbox->Check( new_event.GetInt(), !listbox->IsChecked(new_event.GetInt())); | |
937013e0 | 41 | listbox->HandleWindowEvent( new_event ); |
4a46cbe8 RR |
42 | } |
43 | } | |
4a46cbe8 | 44 | |
caaa4cfd RR |
45 | //----------------------------------------------------------------------------- |
46 | // wxCheckListBox | |
47 | //----------------------------------------------------------------------------- | |
48 | ||
0444602e | 49 | wxCheckListBox::wxCheckListBox() : wxCheckListBoxBase() |
caaa4cfd | 50 | { |
caf6e6de | 51 | m_hasCheckBoxes = true; |
caaa4cfd | 52 | } |
bbe0af5b | 53 | |
caaa4cfd | 54 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, |
d752a3c3 VZ |
55 | const wxPoint& pos, |
56 | const wxSize& size, | |
3d257b8d | 57 | int nStrings, |
d752a3c3 VZ |
58 | const wxString *choices, |
59 | long style, | |
60 | const wxValidator& validator, | |
61 | const wxString& name ) | |
caaa4cfd | 62 | { |
caf6e6de | 63 | m_hasCheckBoxes = true; |
caaa4cfd RR |
64 | wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name ); |
65 | } | |
66 | ||
584ad2a3 MB |
67 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, |
68 | const wxPoint& pos, | |
69 | const wxSize& size, | |
70 | const wxArrayString& choices, | |
71 | long style, | |
72 | const wxValidator& validator, | |
73 | const wxString& name ) | |
74 | { | |
caf6e6de | 75 | m_hasCheckBoxes = true; |
584ad2a3 MB |
76 | wxListBox::Create( parent, id, pos, size, choices, |
77 | style, validator, name ); | |
78 | } | |
79 | ||
4a46cbe8 RR |
80 | void wxCheckListBox::DoCreateCheckList() |
81 | { | |
82 | //Create the checklist in our treeview and set up events for it | |
caf6e6de | 83 | GtkCellRenderer* renderer = |
4a46cbe8 | 84 | gtk_cell_renderer_toggle_new(); |
caf6e6de | 85 | GtkTreeViewColumn* column = |
4a46cbe8 RR |
86 | gtk_tree_view_column_new_with_attributes( "", renderer, |
87 | "active", 0, | |
88 | NULL ); | |
426d19f1 JS |
89 | #if wxUSE_LIBHILDON2 |
90 | gtk_tree_view_column_set_fixed_width(column, 40); | |
91 | #else | |
302c7351 | 92 | gtk_tree_view_column_set_fixed_width(column, 22); |
426d19f1 JS |
93 | #endif // wxUSE_LIBHILDON2/!wxUSE_LIBHILDON2 |
94 | ||
4a46cbe8 RR |
95 | gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); |
96 | gtk_tree_view_column_set_clickable(column, TRUE); | |
97 | ||
98 | g_signal_connect (renderer, "toggled", | |
99 | G_CALLBACK (gtk_checklist_toggled), | |
100 | this); | |
101 | ||
102 | gtk_tree_view_append_column(m_treeview, column); | |
103 | } | |
104 | ||
aa61d352 | 105 | bool wxCheckListBox::IsChecked(unsigned int index) const |
caaa4cfd | 106 | { |
aa61d352 | 107 | wxCHECK_MSG( m_treeview != NULL, false, wxT("invalid checklistbox") ); |
4a46cbe8 RR |
108 | |
109 | GtkTreeIter iter; | |
110 | gboolean res = gtk_tree_model_iter_nth_child( | |
111 | GTK_TREE_MODEL(m_liststore), | |
112 | &iter, NULL, //NULL = parent = get first | |
113 | index | |
aa61d352 | 114 | ); |
4a46cbe8 RR |
115 | if(!res) |
116 | return false; | |
117 | ||
118 | GValue value = {0, }; | |
119 | gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore), | |
120 | &iter, | |
121 | 0, //column | |
caf6e6de | 122 | &value); |
4a46cbe8 | 123 | |
d5027818 | 124 | return g_value_get_boolean(&value) != 0; |
4a46cbe8 | 125 | } |
ff8bfdbb | 126 | |
aa61d352 | 127 | void wxCheckListBox::Check(unsigned int index, bool check) |
4a46cbe8 RR |
128 | { |
129 | wxCHECK_RET( m_treeview != NULL, wxT("invalid checklistbox") ); | |
130 | ||
131 | GtkTreeIter iter; | |
132 | gboolean res = gtk_tree_model_iter_nth_child( | |
133 | GTK_TREE_MODEL(m_liststore), | |
134 | &iter, NULL, //NULL = parent = get first | |
135 | index | |
aa61d352 | 136 | ); |
4a46cbe8 RR |
137 | if(!res) |
138 | return; | |
139 | ||
140 | gtk_list_store_set(m_liststore, | |
141 | &iter, | |
142 | 0, //column | |
caf6e6de | 143 | check ? TRUE : FALSE, -1); |
4a46cbe8 RR |
144 | } |
145 | ||
146 | int wxCheckListBox::GetItemHeight() const | |
147 | { | |
148 | wxCHECK_MSG( m_treeview != NULL, 0, wxT("invalid listbox")); | |
149 | ||
150 | gint height; | |
151 | gtk_tree_view_column_cell_get_size( | |
152 | gtk_tree_view_get_column(m_treeview, 0), | |
153 | NULL, NULL, NULL, NULL, | |
154 | &height); | |
155 | return height; | |
156 | } | |
ff8bfdbb | 157 | |
4a46cbe8 | 158 | #endif //wxUSE_CHECKLISTBOX |