]>
Commit | Line | Data |
---|---|---|
caaa4cfd RR |
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/checklst.h" | |
15 | ||
83624f79 RR |
16 | #include "gdk/gdk.h" |
17 | #include "gtk/gtk.h" | |
18 | ||
caaa4cfd RR |
19 | //----------------------------------------------------------------------------- |
20 | // wxCheckListBox | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox) | |
24 | ||
25 | wxCheckListBox::wxCheckListBox() : | |
26 | wxListBox() | |
27 | { | |
28 | m_hasCheckBoxes = TRUE; | |
29 | } | |
bbe0af5b | 30 | |
caaa4cfd | 31 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, |
bbe0af5b RR |
32 | const wxPoint& pos, |
33 | const wxSize& size, | |
34 | int nStrings, | |
35 | const wxString choices[], | |
36 | long style, | |
37 | const wxValidator& validator, | |
38 | const wxString& name ) | |
caaa4cfd RR |
39 | { |
40 | m_hasCheckBoxes = TRUE; | |
41 | wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name ); | |
42 | } | |
43 | ||
44 | bool wxCheckListBox::IsChecked( int index ) const | |
45 | { | |
46 | wxCHECK_MSG( m_list != NULL, FALSE, "invalid checklistbox" ); | |
47 | ||
48 | GList *child = g_list_nth( m_list->children, index ); | |
49 | if (child) | |
50 | { | |
51 | GtkBin *bin = GTK_BIN( child->data ); | |
52 | GtkLabel *label = GTK_LABEL( bin->child ); | |
53 | ||
54 | wxString str = label->label; | |
55 | ||
56 | return (str[1] == 'X'); | |
57 | } | |
58 | ||
59 | wxFAIL_MSG("wrong checklistbox index"); | |
60 | return FALSE; | |
61 | } | |
62 | ||
63 | void wxCheckListBox::Check( int index, bool check ) | |
64 | { | |
65 | wxCHECK_RET( m_list != NULL, "invalid checklistbox" ); | |
66 | ||
67 | GList *child = g_list_nth( m_list->children, index ); | |
68 | if (child) | |
69 | { | |
70 | GtkBin *bin = GTK_BIN( child->data ); | |
71 | GtkLabel *label = GTK_LABEL( bin->child ); | |
72 | ||
73 | wxString str = label->label; | |
74 | ||
75 | if (check == (str[1] == 'X')) return; | |
76 | ||
77 | if (check) | |
78 | str.SetChar( 1, 'X' ); | |
79 | else | |
80 | str.SetChar( 1, '-' ); | |
81 | ||
82 | gtk_label_set( label, str ); | |
83 | ||
84 | return; | |
85 | } | |
86 | ||
87 | wxFAIL_MSG("wrong checklistbox index"); | |
88 | } | |
89 | ||
4f22cf8d RR |
90 | int wxCheckListBox::GetItemHeight() |
91 | { | |
92 | return 22; | |
93 | } |