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