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