]>
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 | ||
19 | // FIXME: We use GtkList to implement wxListBox | |
20 | #ifdef GTK_DISABLE_DEPRECATED | |
21 | #undef GTK_DISABLE_DEPRECATED | |
22 | #endif | |
23 | ||
24 | #include "wx/gtk/private.h" | |
25 | ||
26 | #include <gdk/gdk.h> | |
27 | #include <gtk/gtk.h> | |
28 | ||
29 | //----------------------------------------------------------------------------- | |
30 | // wxCheckListBox | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox) | |
34 | ||
35 | wxCheckListBox::wxCheckListBox() : wxListBox() | |
36 | { | |
37 | m_hasCheckBoxes = TRUE; | |
38 | } | |
39 | ||
40 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, | |
41 | const wxPoint& pos, | |
42 | const wxSize& size, | |
43 | int nStrings, | |
44 | const wxString *choices, | |
45 | long style, | |
46 | const wxValidator& validator, | |
47 | const wxString& name ) | |
48 | { | |
49 | m_hasCheckBoxes = TRUE; | |
50 | wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name ); | |
51 | } | |
52 | ||
53 | wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id, | |
54 | const wxPoint& pos, | |
55 | const wxSize& size, | |
56 | const wxArrayString& choices, | |
57 | long style, | |
58 | const wxValidator& validator, | |
59 | const wxString& name ) | |
60 | { | |
61 | m_hasCheckBoxes = TRUE; | |
62 | wxListBox::Create( parent, id, pos, size, choices, | |
63 | style, validator, name ); | |
64 | } | |
65 | ||
66 | bool wxCheckListBox::IsChecked( int index ) const | |
67 | { | |
68 | wxCHECK_MSG( m_list != NULL, FALSE, 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( wxGTK_CONV_BACK( label->label ) ); | |
77 | ||
78 | return str.GetChar(1) == wxCHECKLBOX_CHECKED; | |
79 | } | |
80 | ||
81 | wxFAIL_MSG(wxT("wrong checklistbox index")); | |
82 | return FALSE; | |
83 | } | |
84 | ||
85 | void wxCheckListBox::Check( int index, bool check ) | |
86 | { | |
87 | wxCHECK_RET( m_list != NULL, wxT("invalid checklistbox") ); | |
88 | ||
89 | GList *child = g_list_nth( m_list->children, index ); | |
90 | if (child) | |
91 | { | |
92 | GtkBin *bin = GTK_BIN( child->data ); | |
93 | GtkLabel *label = GTK_LABEL( bin->child ); | |
94 | ||
95 | wxString str( wxGTK_CONV_BACK( label->label ) ); | |
96 | ||
97 | if (check == (str.GetChar(1) == wxCHECKLBOX_CHECKED)) | |
98 | return; | |
99 | ||
100 | str.SetChar( 1, check ? wxCHECKLBOX_CHECKED : wxCHECKLBOX_UNCHECKED ); | |
101 | ||
102 | gtk_label_set_text( label, wxGTK_CONV( str ) ); | |
103 | ||
104 | return; | |
105 | } | |
106 | ||
107 | wxFAIL_MSG(wxT("wrong checklistbox index")); | |
108 | } | |
109 | ||
110 | int wxCheckListBox::GetItemHeight() const | |
111 | { | |
112 | // FIXME | |
113 | return 22; | |
114 | } | |
115 | ||
116 | #endif |