]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/checklst.cpp
wxITEM_FOO instead of wxItem_Foo, for the sake of consistency
[wxWidgets.git] / src / gtk1 / checklst.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checklst.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "checklst.h"
12 #endif
13
14 #include "wx/defs.h"
15
16 #if wxUSE_CHECKLISTBOX
17
18 #include "wx/checklst.h"
19
20 #include <gdk/gdk.h>
21 #include <gtk/gtk.h>
22
23 //-----------------------------------------------------------------------------
24 // wxCheckListBox
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox)
28
29 wxCheckListBox::wxCheckListBox() : wxListBox()
30 {
31 m_hasCheckBoxes = TRUE;
32 }
33
34 wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
35 const wxPoint& pos,
36 const wxSize& size,
37 int nStrings,
38 const wxString *choices,
39 long style,
40 const wxValidator& validator,
41 const wxString& name )
42 {
43 m_hasCheckBoxes = TRUE;
44 wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name );
45 }
46
47 bool wxCheckListBox::IsChecked( int index ) const
48 {
49 wxCHECK_MSG( m_list != NULL, FALSE, wxT("invalid checklistbox") );
50
51 GList *child = g_list_nth( m_list->children, index );
52 if (child)
53 {
54 GtkBin *bin = GTK_BIN( child->data );
55 GtkLabel *label = GTK_LABEL( bin->child );
56
57 wxString str = wxString(label->label,*wxConvCurrent);
58
59 return str.GetChar(1) == wxCHECKLBOX_CHECKED;
60 }
61
62 wxFAIL_MSG(wxT("wrong checklistbox index"));
63 return FALSE;
64 }
65
66 void wxCheckListBox::Check( int index, bool check )
67 {
68 wxCHECK_RET( m_list != NULL, wxT("invalid checklistbox") );
69
70 GList *child = g_list_nth( m_list->children, index );
71 if (child)
72 {
73 GtkBin *bin = GTK_BIN( child->data );
74 GtkLabel *label = GTK_LABEL( bin->child );
75
76 wxString str = wxString(label->label,*wxConvCurrent);
77
78 if (check == (str.GetChar(1) == wxCHECKLBOX_CHECKED))
79 return;
80
81 str.SetChar( 1, check ? wxCHECKLBOX_CHECKED : wxCHECKLBOX_UNCHECKED );
82
83 gtk_label_set( label, str.mbc_str() );
84
85 return;
86 }
87
88 wxFAIL_MSG(wxT("wrong checklistbox index"));
89 }
90
91 int wxCheckListBox::GetItemHeight() const
92 {
93 // FIXME
94 return 22;
95 }
96
97 #endif