1 /////////////////////////////////////////////////////////////////////////////
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"
16 #if wxUSE_CHECKLISTBOX
18 #include "wx/checklst.h"
19 #include "wx/gtk/private.h"
20 #include "wx/gtk/treeentry_gtk.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
28 #if wxUSE_NATIVEGTKCHECKLIST
30 static void gtk_checklist_toggled(GtkCellRendererToggle
*renderer
,
32 wxCheckListBox
*listbox
)
34 wxCHECK_RET( listbox
->m_treeview
!= NULL
, wxT("invalid listbox") );
36 GtkTreePath
* path
= gtk_tree_path_new_from_string(stringpath
);
37 wxCommandEvent
new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
,
39 new_event
.SetEventObject( listbox
);
40 new_event
.SetInt( gtk_tree_path_get_indices(path
)[0] );
41 gtk_tree_path_free(path
);
42 listbox
->Check( new_event
.GetInt(), !listbox
->IsChecked(new_event
.GetInt()));
43 listbox
->GetEventHandler()->ProcessEvent( new_event
);
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
,wxListBox
)
54 wxCheckListBox::wxCheckListBox() : wxListBox()
56 m_hasCheckBoxes
= TRUE
;
59 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
63 const wxString
*choices
,
65 const wxValidator
& validator
,
66 const wxString
& name
)
68 m_hasCheckBoxes
= TRUE
;
69 wxListBox::Create( parent
, id
, pos
, size
, nStrings
, choices
, style
, validator
, name
);
72 wxCheckListBox::wxCheckListBox(wxWindow
*parent
, wxWindowID id
,
75 const wxArrayString
& choices
,
77 const wxValidator
& validator
,
78 const wxString
& name
)
80 m_hasCheckBoxes
= TRUE
;
81 wxListBox::Create( parent
, id
, pos
, size
, choices
,
82 style
, validator
, name
);
85 #if wxUSE_NATIVEGTKCHECKLIST
86 void wxCheckListBox::DoCreateCheckList()
88 //Create the checklist in our treeview and set up events for it
89 GtkCellRenderer
* renderer
=
90 gtk_cell_renderer_toggle_new();
91 GtkTreeViewColumn
* column
=
92 gtk_tree_view_column_new_with_attributes( "", renderer
,
95 gtk_tree_view_column_set_fixed_width(column
, 20);
96 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_FIXED
);
97 gtk_tree_view_column_set_clickable(column
, TRUE
);
99 g_signal_connect (renderer
, "toggled",
100 G_CALLBACK (gtk_checklist_toggled
),
103 gtk_tree_view_append_column(m_treeview
, column
);
106 bool wxCheckListBox::IsChecked( int index
) const
108 wxCHECK_MSG( m_treeview
!= NULL
, FALSE
, wxT("invalid checklistbox") );
111 gboolean res
= gtk_tree_model_iter_nth_child(
112 GTK_TREE_MODEL(m_liststore
),
113 &iter
, NULL
, //NULL = parent = get first
119 GValue value
= {0, };
120 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore
),
125 return g_value_get_boolean(&value
) == TRUE
? true : false;
128 void wxCheckListBox::Check( int index
, bool check
)
130 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid checklistbox") );
133 gboolean res
= gtk_tree_model_iter_nth_child(
134 GTK_TREE_MODEL(m_liststore
),
135 &iter
, NULL
, //NULL = parent = get first
141 gtk_list_store_set(m_liststore
,
144 check
? TRUE
: FALSE
, -1);
147 int wxCheckListBox::GetItemHeight() const
149 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox"));
152 gtk_tree_view_column_cell_get_size(
153 gtk_tree_view_get_column(m_treeview
, 0),
154 NULL
, NULL
, NULL
, NULL
,
161 bool wxCheckListBox::IsChecked( int index
) const
163 wxCHECK_MSG( m_treeview
!= NULL
, FALSE
, wxT("invalid checklistbox") );
165 GtkTreeEntry
* entry
= GtkGetEntry(index
);
168 wxString
str( wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) ) );
170 return str
.GetChar(1) == wxCHECKLBOX_CHECKED
;
173 wxFAIL_MSG(wxT("wrong checklistbox index"));
177 void wxCheckListBox::Check( int index
, bool check
)
179 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid checklistbox") );
181 GtkTreeEntry
* entry
= GtkGetEntry(index
);
184 wxString
str( wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) ) );
186 if (check
== (str
.GetChar(1) == wxCHECKLBOX_CHECKED
))
189 str
.SetChar( 1, check
? wxCHECKLBOX_CHECKED
: wxCHECKLBOX_UNCHECKED
);
191 gtk_tree_entry_set_label( entry
, wxGTK_CONV( str
) );
196 wxFAIL_MSG(wxT("wrong checklistbox index"));
199 int wxCheckListBox::GetItemHeight() const
205 #endif //wxUSE_NATIVEGTKCHECKLIST
207 #endif //wxUSE_CHECKLISTBOX