]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/checklst.cpp
Applying patch #10784: eliminate gauge flicker
[wxWidgets.git] / src / gtk / checklst.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/checklst.cpp
3// Purpose:
4// Author: Robert Roebling
5// Modified by: Ryan Norton (Native GTK2.0+ checklist)
6// Id: $Id$
7// Copyright: (c) 1998 Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#if wxUSE_CHECKLISTBOX
15
16#include "wx/checklst.h"
17#include "wx/gtk/private.h"
18#include "wx/gtk/treeentry_gtk.h"
19
20#include <gdk/gdk.h>
21#include <gtk/gtk.h>
22
23//-----------------------------------------------------------------------------
24// "toggled"
25//-----------------------------------------------------------------------------
26extern "C" {
27static void gtk_checklist_toggled(GtkCellRendererToggle * WXUNUSED(renderer),
28 gchar *stringpath,
29 wxCheckListBox *listbox)
30{
31 wxCHECK_RET( listbox->m_treeview != NULL, wxT("invalid listbox") );
32
33 GtkTreePath* path = gtk_tree_path_new_from_string(stringpath);
34 wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,
35 listbox->GetId() );
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 );
42}
43}
44
45//-----------------------------------------------------------------------------
46// wxCheckListBox
47//-----------------------------------------------------------------------------
48
49IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox)
50
51wxCheckListBox::wxCheckListBox() : wxListBox()
52{
53 m_hasCheckBoxes = true;
54}
55
56wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
57 const wxPoint& pos,
58 const wxSize& size,
59 int nStrings,
60 const wxString *choices,
61 long style,
62 const wxValidator& validator,
63 const wxString& name )
64{
65 m_hasCheckBoxes = true;
66 wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name );
67}
68
69wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
70 const wxPoint& pos,
71 const wxSize& size,
72 const wxArrayString& choices,
73 long style,
74 const wxValidator& validator,
75 const wxString& name )
76{
77 m_hasCheckBoxes = true;
78 wxListBox::Create( parent, id, pos, size, choices,
79 style, validator, name );
80}
81
82void wxCheckListBox::DoCreateCheckList()
83{
84 //Create the checklist in our treeview and set up events for it
85 GtkCellRenderer* renderer =
86 gtk_cell_renderer_toggle_new();
87 GtkTreeViewColumn* column =
88 gtk_tree_view_column_new_with_attributes( "", renderer,
89 "active", 0,
90 NULL );
91 gtk_tree_view_column_set_fixed_width(column, 22);
92 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
93 gtk_tree_view_column_set_clickable(column, TRUE);
94
95 g_signal_connect (renderer, "toggled",
96 G_CALLBACK (gtk_checklist_toggled),
97 this);
98
99 gtk_tree_view_append_column(m_treeview, column);
100}
101
102bool wxCheckListBox::IsChecked(unsigned int index) const
103{
104 wxCHECK_MSG( m_treeview != NULL, false, wxT("invalid checklistbox") );
105
106 GtkTreeIter iter;
107 gboolean res = gtk_tree_model_iter_nth_child(
108 GTK_TREE_MODEL(m_liststore),
109 &iter, NULL, //NULL = parent = get first
110 index
111 );
112 if(!res)
113 return false;
114
115 GValue value = {0, };
116 gtk_tree_model_get_value(GTK_TREE_MODEL(m_liststore),
117 &iter,
118 0, //column
119 &value);
120
121 return g_value_get_boolean(&value) == TRUE ? true : false;
122}
123
124void wxCheckListBox::Check(unsigned int index, bool check)
125{
126 wxCHECK_RET( m_treeview != NULL, wxT("invalid checklistbox") );
127
128 GtkTreeIter iter;
129 gboolean res = gtk_tree_model_iter_nth_child(
130 GTK_TREE_MODEL(m_liststore),
131 &iter, NULL, //NULL = parent = get first
132 index
133 );
134 if(!res)
135 return;
136
137 gtk_list_store_set(m_liststore,
138 &iter,
139 0, //column
140 check ? TRUE : FALSE, -1);
141}
142
143int wxCheckListBox::GetItemHeight() const
144{
145 wxCHECK_MSG( m_treeview != NULL, 0, wxT("invalid listbox"));
146
147 gint height;
148 gtk_tree_view_column_cell_get_size(
149 gtk_tree_view_get_column(m_treeview, 0),
150 NULL, NULL, NULL, NULL,
151 &height);
152 return height;
153}
154
155#endif //wxUSE_CHECKLISTBOX