]>
Commit | Line | Data |
---|---|---|
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 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
15 | #if wxUSE_CHECKLISTBOX | |
16 | ||
17 | #include "wx/checklst.h" | |
18 | #include "wx/gtk1/private.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 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, | |
48 | const wxPoint& pos, | |
49 | const wxSize& size, | |
50 | const wxArrayString& choices, | |
51 | long style, | |
52 | const wxValidator& validator, | |
53 | const wxString& name ) | |
54 | { | |
55 | m_hasCheckBoxes = TRUE; | |
56 | wxListBox::Create( parent, id, pos, size, choices, | |
57 | style, validator, name ); | |
58 | } | |
59 | ||
60 | bool wxCheckListBox::IsChecked( int index ) const | |
61 | { | |
62 | wxCHECK_MSG( m_list != NULL, FALSE, wxT("invalid checklistbox") ); | |
63 | ||
64 | GList *child = g_list_nth( m_list->children, index ); | |
65 | if (child) | |
66 | { | |
67 | GtkBin *bin = GTK_BIN( child->data ); | |
68 | GtkLabel *label = GTK_LABEL( bin->child ); | |
69 | ||
70 | wxString str( wxGTK_CONV_BACK( label->label ) ); | |
71 | ||
72 | return str.GetChar(1) == wxCHECKLBOX_CHECKED; | |
73 | } | |
74 | ||
75 | wxFAIL_MSG(wxT("wrong checklistbox index")); | |
76 | return FALSE; | |
77 | } | |
78 | ||
79 | void wxCheckListBox::Check( int index, bool check ) | |
80 | { | |
81 | wxCHECK_RET( m_list != NULL, wxT("invalid checklistbox") ); | |
82 | ||
83 | GList *child = g_list_nth( m_list->children, index ); | |
84 | if (child) | |
85 | { | |
86 | GtkBin *bin = GTK_BIN( child->data ); | |
87 | GtkLabel *label = GTK_LABEL( bin->child ); | |
88 | ||
89 | wxString str( wxGTK_CONV_BACK( label->label ) ); | |
90 | ||
91 | if (check == (str.GetChar(1) == wxCHECKLBOX_CHECKED)) | |
92 | return; | |
93 | ||
94 | str.SetChar( 1, check ? wxCHECKLBOX_CHECKED : wxCHECKLBOX_UNCHECKED ); | |
95 | ||
96 | gtk_label_set( label, wxGTK_CONV( str ) ); | |
97 | ||
98 | return; | |
99 | } | |
100 | ||
101 | wxFAIL_MSG(wxT("wrong checklistbox index")); | |
102 | } | |
103 | ||
104 | int wxCheckListBox::GetItemHeight() const | |
105 | { | |
106 | // FIXME | |
107 | return 22; | |
108 | } | |
109 | ||
110 | #endif |