1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/checklst.cpp
4 // Author: Robert Roebling
5 // Modified by: Ryan Norton (Native GTK2.0+ checklist)
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_CHECKLISTBOX
15 #include "wx/checklst.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 static void gtk_checklist_toggled(GtkCellRendererToggle
* WXUNUSED(renderer
),
25 wxCheckListBox
*listbox
)
27 wxCHECK_RET( listbox
->m_treeview
!= NULL
, wxT("invalid listbox") );
29 GtkTreePath
* path
= gtk_tree_path_new_from_string(stringpath
);
30 wxCommandEvent
new_event( wxEVT_CHECKLISTBOX
,
32 new_event
.SetEventObject( listbox
);
33 new_event
.SetInt( gtk_tree_path_get_indices(path
)[0] );
34 new_event
.SetString( listbox
->GetString( new_event
.GetInt() ));
35 gtk_tree_path_free(path
);
36 listbox
->Check( new_event
.GetInt(), !listbox
->IsChecked(new_event
.GetInt()));
37 listbox
->HandleWindowEvent( new_event
);
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 wxCheckListBox::wxCheckListBox() : wxCheckListBoxBase()
47 m_hasCheckBoxes
= true;
50 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
54 const wxString
*choices
,
56 const wxValidator
& validator
,
57 const wxString
& name
)
59 m_hasCheckBoxes
= true;
60 wxListBox::Create( parent
, id
, pos
, size
, nStrings
, choices
, style
, validator
, name
);
63 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
66 const wxArrayString
& choices
,
68 const wxValidator
& validator
,
69 const wxString
& name
)
71 m_hasCheckBoxes
= true;
72 wxListBox::Create( parent
, id
, pos
, size
, choices
,
73 style
, validator
, name
);
76 void wxCheckListBox::DoCreateCheckList()
78 //Create the checklist in our treeview and set up events for it
79 GtkCellRenderer
* renderer
=
80 gtk_cell_renderer_toggle_new();
81 GtkTreeViewColumn
* column
=
82 gtk_tree_view_column_new_with_attributes( "", renderer
,
86 gtk_tree_view_column_set_fixed_width(column
, 40);
88 gtk_tree_view_column_set_fixed_width(column
, 22);
89 #endif // wxUSE_LIBHILDON2/!wxUSE_LIBHILDON2
91 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_FIXED
);
92 gtk_tree_view_column_set_clickable(column
, TRUE
);
94 g_signal_connect (renderer
, "toggled",
95 G_CALLBACK (gtk_checklist_toggled
),
98 gtk_tree_view_append_column(m_treeview
, column
);
101 bool wxCheckListBox::IsChecked(unsigned int index
) const
103 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid checklistbox") );
106 gboolean res
= gtk_tree_model_iter_nth_child(
107 GTK_TREE_MODEL(m_liststore
),
108 &iter
, NULL
, //NULL = parent = get first
114 GValue value
= {0, };
115 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore
),
120 return g_value_get_boolean(&value
) != 0;
123 void wxCheckListBox::Check(unsigned int index
, bool check
)
125 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid checklistbox") );
128 gboolean res
= gtk_tree_model_iter_nth_child(
129 GTK_TREE_MODEL(m_liststore
),
130 &iter
, NULL
, //NULL = parent = get first
136 gtk_list_store_set(m_liststore
,
139 check
? TRUE
: FALSE
, -1);
142 int wxCheckListBox::GetItemHeight() const
144 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox"));
147 gtk_tree_view_column_cell_get_size(
148 gtk_tree_view_get_column(m_treeview
, 0),
149 NULL
, NULL
, NULL
, NULL
,
154 #endif //wxUSE_CHECKLISTBOX