1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/checklst.cpp
4 // Author: Robert Roebling
5 // Modified by: Ryan Norton (Native GTK2.0+ checklist)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #if wxUSE_CHECKLISTBOX
16 #include "wx/checklst.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 static void gtk_checklist_toggled(GtkCellRendererToggle
* WXUNUSED(renderer
),
26 wxCheckListBox
*listbox
)
28 wxCHECK_RET( listbox
->m_treeview
!= NULL
, wxT("invalid listbox") );
30 GtkTreePath
* path
= gtk_tree_path_new_from_string(stringpath
);
31 wxCommandEvent
new_event( wxEVT_CHECKLISTBOX
,
33 new_event
.SetEventObject( listbox
);
34 new_event
.SetInt( gtk_tree_path_get_indices(path
)[0] );
35 new_event
.SetString( listbox
->GetString( new_event
.GetInt() ));
36 gtk_tree_path_free(path
);
37 listbox
->Check( new_event
.GetInt(), !listbox
->IsChecked(new_event
.GetInt()));
38 listbox
->HandleWindowEvent( new_event
);
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 wxCheckListBox::wxCheckListBox() : wxCheckListBoxBase()
48 m_hasCheckBoxes
= true;
51 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
55 const wxString
*choices
,
57 const wxValidator
& validator
,
58 const wxString
& name
)
60 m_hasCheckBoxes
= true;
61 wxListBox::Create( parent
, id
, pos
, size
, nStrings
, choices
, style
, validator
, name
);
64 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
67 const wxArrayString
& choices
,
69 const wxValidator
& validator
,
70 const wxString
& name
)
72 m_hasCheckBoxes
= true;
73 wxListBox::Create( parent
, id
, pos
, size
, choices
,
74 style
, validator
, name
);
77 void wxCheckListBox::DoCreateCheckList()
79 //Create the checklist in our treeview and set up events for it
80 GtkCellRenderer
* renderer
=
81 gtk_cell_renderer_toggle_new();
82 GtkTreeViewColumn
* column
=
83 gtk_tree_view_column_new_with_attributes( "", renderer
,
87 gtk_tree_view_column_set_fixed_width(column
, 40);
89 gtk_tree_view_column_set_fixed_width(column
, 22);
90 #endif // wxUSE_LIBHILDON2/!wxUSE_LIBHILDON2
92 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_FIXED
);
93 gtk_tree_view_column_set_clickable(column
, TRUE
);
95 g_signal_connect (renderer
, "toggled",
96 G_CALLBACK (gtk_checklist_toggled
),
99 gtk_tree_view_append_column(m_treeview
, column
);
102 bool wxCheckListBox::IsChecked(unsigned int index
) const
104 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid checklistbox") );
107 gboolean res
= gtk_tree_model_iter_nth_child(
108 GTK_TREE_MODEL(m_liststore
),
109 &iter
, NULL
, //NULL = parent = get first
115 GValue value
= {0, };
116 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore
),
121 return g_value_get_boolean(&value
) != 0;
124 void wxCheckListBox::Check(unsigned int index
, bool check
)
126 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid checklistbox") );
129 gboolean res
= gtk_tree_model_iter_nth_child(
130 GTK_TREE_MODEL(m_liststore
),
131 &iter
, NULL
, //NULL = parent = get first
137 gtk_list_store_set(m_liststore
,
140 check
? TRUE
: FALSE
, -1);
143 int wxCheckListBox::GetItemHeight() const
145 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox"));
148 gtk_tree_view_column_cell_get_size(
149 gtk_tree_view_get_column(m_treeview
, 0),
150 NULL
, NULL
, NULL
, NULL
,
155 #endif //wxUSE_CHECKLISTBOX