]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/checklst.cpp
don't try to paint hidden windows
[wxWidgets.git] / src / gtk / checklst.cpp
CommitLineData
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
RR
6// Id: $Id$
7// Copyright: (c) 1998 Robert Roebling
65571936 8// Licence: wxWindows licence
caaa4cfd
RR
9/////////////////////////////////////////////////////////////////////////////
10
14f355c2
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
dcf924a3
RR
14#if wxUSE_CHECKLISTBOX
15
1e6feb95 16#include "wx/checklst.h"
fab591c5 17#include "wx/gtk/private.h"
4a46cbe8 18#include "wx/gtk/treeentry_gtk.h"
1e6feb95 19
071a2d78
RR
20#include <gdk/gdk.h>
21#include <gtk/gtk.h>
83624f79 22
4a46cbe8
RR
23//-----------------------------------------------------------------------------
24// "toggled"
25//-----------------------------------------------------------------------------
26#if wxUSE_NATIVEGTKCHECKLIST
27extern "C" {
28static void gtk_checklist_toggled(GtkCellRendererToggle *renderer,
29 gchar *stringpath,
30 wxCheckListBox *listbox)
31{
32 wxCHECK_RET( listbox->m_treeview != NULL, wxT("invalid listbox") );
33
34 GtkTreePath* path = gtk_tree_path_new_from_string(stringpath);
caf6e6de 35 wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,
4a46cbe8
RR
36 listbox->GetId() );
37 new_event.SetEventObject( listbox );
38 new_event.SetInt( gtk_tree_path_get_indices(path)[0] );
39 gtk_tree_path_free(path);
40 listbox->Check( new_event.GetInt(), !listbox->IsChecked(new_event.GetInt()));
caf6e6de 41 listbox->GetEventHandler()->ProcessEvent( new_event );
4a46cbe8
RR
42}
43}
44#endif
45
caaa4cfd
RR
46//-----------------------------------------------------------------------------
47// wxCheckListBox
48//-----------------------------------------------------------------------------
49
50IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox)
51
88ac883a 52wxCheckListBox::wxCheckListBox() : wxListBox()
caaa4cfd 53{
caf6e6de 54 m_hasCheckBoxes = true;
caaa4cfd 55}
bbe0af5b 56
caaa4cfd 57wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
d752a3c3
VZ
58 const wxPoint& pos,
59 const wxSize& size,
3d257b8d 60 int nStrings,
d752a3c3
VZ
61 const wxString *choices,
62 long style,
63 const wxValidator& validator,
64 const wxString& name )
caaa4cfd 65{
caf6e6de 66 m_hasCheckBoxes = true;
caaa4cfd
RR
67 wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name );
68}
69
584ad2a3
MB
70wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
71 const wxPoint& pos,
72 const wxSize& size,
73 const wxArrayString& choices,
74 long style,
75 const wxValidator& validator,
76 const wxString& name )
77{
caf6e6de 78 m_hasCheckBoxes = true;
584ad2a3
MB
79 wxListBox::Create( parent, id, pos, size, choices,
80 style, validator, name );
81}
82
4a46cbe8
RR
83#if wxUSE_NATIVEGTKCHECKLIST
84void wxCheckListBox::DoCreateCheckList()
85{
86 //Create the checklist in our treeview and set up events for it
caf6e6de 87 GtkCellRenderer* renderer =
4a46cbe8 88 gtk_cell_renderer_toggle_new();
caf6e6de 89 GtkTreeViewColumn* column =
4a46cbe8
RR
90 gtk_tree_view_column_new_with_attributes( "", renderer,
91 "active", 0,
92 NULL );
93 gtk_tree_view_column_set_fixed_width(column, 20);
94 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
95 gtk_tree_view_column_set_clickable(column, TRUE);
96
97 g_signal_connect (renderer, "toggled",
98 G_CALLBACK (gtk_checklist_toggled),
99 this);
100
101 gtk_tree_view_append_column(m_treeview, column);
102}
103
aa61d352 104bool wxCheckListBox::IsChecked(unsigned int index) const
caaa4cfd 105{
aa61d352 106 wxCHECK_MSG( m_treeview != NULL, false, wxT("invalid checklistbox") );
4a46cbe8
RR
107
108 GtkTreeIter iter;
109 gboolean res = gtk_tree_model_iter_nth_child(
110 GTK_TREE_MODEL(m_liststore),
111 &iter, NULL, //NULL = parent = get first
112 index
aa61d352 113 );
4a46cbe8
RR
114 if(!res)
115 return false;
116
117 GValue value = {0, };
118 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore),
119 &iter,
120 0, //column
caf6e6de 121 &value);
4a46cbe8
RR
122
123 return g_value_get_boolean(&value) == TRUE ? true : false;
124}
ff8bfdbb 125
aa61d352 126void wxCheckListBox::Check(unsigned int index, bool check)
4a46cbe8
RR
127{
128 wxCHECK_RET( m_treeview != NULL, wxT("invalid checklistbox") );
129
130 GtkTreeIter iter;
131 gboolean res = gtk_tree_model_iter_nth_child(
132 GTK_TREE_MODEL(m_liststore),
133 &iter, NULL, //NULL = parent = get first
134 index
aa61d352 135 );
4a46cbe8
RR
136 if(!res)
137 return;
138
139 gtk_list_store_set(m_liststore,
140 &iter,
141 0, //column
caf6e6de 142 check ? TRUE : FALSE, -1);
4a46cbe8
RR
143}
144
145int wxCheckListBox::GetItemHeight() const
146{
147 wxCHECK_MSG( m_treeview != NULL, 0, wxT("invalid listbox"));
148
149 gint height;
150 gtk_tree_view_column_cell_get_size(
151 gtk_tree_view_get_column(m_treeview, 0),
152 NULL, NULL, NULL, NULL,
153 &height);
154 return height;
155}
ff8bfdbb 156
4a46cbe8
RR
157#else //NON-NATIVE
158
159bool wxCheckListBox::IsChecked( int index ) const
160{
caf6e6de 161 wxCHECK_MSG( m_treeview != NULL, false, wxT("invalid checklistbox") );
4a46cbe8
RR
162
163 GtkTreeEntry* entry = GtkGetEntry(index);
164 if (entry)
165 {
166 wxString str( wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry) ) );
ff8bfdbb 167
d752a3c3 168 return str.GetChar(1) == wxCHECKLBOX_CHECKED;
caaa4cfd 169 }
ff8bfdbb 170
223d09f6 171 wxFAIL_MSG(wxT("wrong checklistbox index"));
caf6e6de 172 return false;
caaa4cfd
RR
173}
174
175void wxCheckListBox::Check( int index, bool check )
176{
4a46cbe8 177 wxCHECK_RET( m_treeview != NULL, wxT("invalid checklistbox") );
ff8bfdbb 178
4a46cbe8
RR
179 GtkTreeEntry* entry = GtkGetEntry(index);
180 if (entry)
caaa4cfd 181 {
4a46cbe8 182 wxString str( wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry) ) );
ff8bfdbb 183
d752a3c3
VZ
184 if (check == (str.GetChar(1) == wxCHECKLBOX_CHECKED))
185 return;
ff8bfdbb 186
d752a3c3 187 str.SetChar( 1, check ? wxCHECKLBOX_CHECKED : wxCHECKLBOX_UNCHECKED );
ff8bfdbb 188
4a46cbe8 189 gtk_tree_entry_set_label( entry, wxGTK_CONV( str ) );
ff8bfdbb
VZ
190
191 return;
caaa4cfd 192 }
ff8bfdbb 193
223d09f6 194 wxFAIL_MSG(wxT("wrong checklistbox index"));
caaa4cfd
RR
195}
196
ff8bfdbb 197int wxCheckListBox::GetItemHeight() const
4f22cf8d 198{
ff8bfdbb 199 // FIXME
4f22cf8d
RR
200 return 22;
201}
dcf924a3 202
4a46cbe8
RR
203#endif //wxUSE_NATIVEGTKCHECKLIST
204
205#endif //wxUSE_CHECKLISTBOX