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"
17 #include "wx/gtk/private.h"
18 #include "wx/gtk/treeentry_gtk.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 static void gtk_checklist_toggled(GtkCellRendererToggle
* WXUNUSED(renderer
),
29 wxCheckListBox
*listbox
)
31 wxCHECK_RET( listbox
->m_treeview
!= NULL
, wxT("invalid listbox") );
33 GtkTreePath
* path
= gtk_tree_path_new_from_string(stringpath
);
34 wxCommandEvent
new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
,
36 new_event
.SetEventObject( listbox
);
37 new_event
.SetInt( gtk_tree_path_get_indices(path
)[0] );
38 new_event
.SetString( listbox
->GetString( new_event
.GetInt() ));
39 gtk_tree_path_free(path
);
40 listbox
->Check( new_event
.GetInt(), !listbox
->IsChecked(new_event
.GetInt()));
41 listbox
->HandleWindowEvent( new_event
);
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 wxCheckListBox::wxCheckListBox() : wxListBox()
51 m_hasCheckBoxes
= true;
54 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
58 const wxString
*choices
,
60 const wxValidator
& validator
,
61 const wxString
& name
)
63 m_hasCheckBoxes
= true;
64 wxListBox::Create( parent
, id
, pos
, size
, nStrings
, choices
, style
, validator
, name
);
67 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
70 const wxArrayString
& choices
,
72 const wxValidator
& validator
,
73 const wxString
& name
)
75 m_hasCheckBoxes
= true;
76 wxListBox::Create( parent
, id
, pos
, size
, choices
,
77 style
, validator
, name
);
80 void wxCheckListBox::DoCreateCheckList()
82 //Create the checklist in our treeview and set up events for it
83 GtkCellRenderer
* renderer
=
84 gtk_cell_renderer_toggle_new();
85 GtkTreeViewColumn
* column
=
86 gtk_tree_view_column_new_with_attributes( "", renderer
,
90 gtk_tree_view_column_set_fixed_width(column
, 40);
92 gtk_tree_view_column_set_fixed_width(column
, 22);
93 #endif // wxUSE_LIBHILDON2/!wxUSE_LIBHILDON2
95 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_FIXED
);
96 gtk_tree_view_column_set_clickable(column
, TRUE
);
98 g_signal_connect (renderer
, "toggled",
99 G_CALLBACK (gtk_checklist_toggled
),
102 gtk_tree_view_append_column(m_treeview
, column
);
105 bool wxCheckListBox::IsChecked(unsigned int index
) const
107 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid checklistbox") );
110 gboolean res
= gtk_tree_model_iter_nth_child(
111 GTK_TREE_MODEL(m_liststore
),
112 &iter
, NULL
, //NULL = parent = get first
118 GValue value
= {0, };
119 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore
),
124 return g_value_get_boolean(&value
) != 0;
127 void wxCheckListBox::Check(unsigned int index
, bool check
)
129 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid checklistbox") );
132 gboolean res
= gtk_tree_model_iter_nth_child(
133 GTK_TREE_MODEL(m_liststore
),
134 &iter
, NULL
, //NULL = parent = get first
140 gtk_list_store_set(m_liststore
,
143 check
? TRUE
: FALSE
, -1);
146 int wxCheckListBox::GetItemHeight() const
148 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox"));
151 gtk_tree_view_column_cell_get_size(
152 gtk_tree_view_get_column(m_treeview
, 0),
153 NULL
, NULL
, NULL
, NULL
,
158 #endif //wxUSE_CHECKLISTBOX