]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/checklst.cpp
move Ellipsize() to wxControl so it can be easily used by other controls
[wxWidgets.git] / src / gtk1 / checklst.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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 #if wxUSE_CHECKLISTBOX
14
15 #include "wx/checklst.h"
16 #include "wx/gtk1/private.h"
17
18 #include <gdk/gdk.h>
19 #include <gtk/gtk.h>
20
21 //-----------------------------------------------------------------------------
22 // wxCheckListBox
23 //-----------------------------------------------------------------------------
24
25 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox,wxListBox)
26
27 wxCheckListBox::wxCheckListBox() : wxListBox()
28 {
29 m_hasCheckBoxes = true;
30 }
31
32 wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
33 const wxPoint& pos,
34 const wxSize& size,
35 int nStrings,
36 const wxString *choices,
37 long style,
38 const wxValidator& validator,
39 const wxString& name )
40 {
41 m_hasCheckBoxes = true;
42 wxListBox::Create( parent, id, pos, size, nStrings, choices, style, validator, name );
43 }
44
45 wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
46 const wxPoint& pos,
47 const wxSize& size,
48 const wxArrayString& choices,
49 long style,
50 const wxValidator& validator,
51 const wxString& name )
52 {
53 m_hasCheckBoxes = true;
54 wxListBox::Create( parent, id, pos, size, choices,
55 style, validator, name );
56 }
57
58 bool wxCheckListBox::IsChecked(unsigned int index) const
59 {
60 wxCHECK_MSG( m_list != NULL, false, wxT("invalid checklistbox") );
61
62 GList *child = g_list_nth( m_list->children, index );
63 if (child)
64 {
65 GtkBin *bin = GTK_BIN( child->data );
66 GtkLabel *label = GTK_LABEL( bin->child );
67
68 wxString str( wxGTK_CONV_BACK( label->label ) );
69
70 return str.GetChar(1) == wxCHECKLBOX_CHECKED;
71 }
72
73 wxFAIL_MSG(wxT("wrong checklistbox index"));
74 return false;
75 }
76
77 void wxCheckListBox::Check(unsigned int index, bool check )
78 {
79 wxCHECK_RET( m_list != NULL, wxT("invalid checklistbox") );
80
81 GList *child = g_list_nth( m_list->children, index );
82 if (child)
83 {
84 GtkBin *bin = GTK_BIN( child->data );
85 GtkLabel *label = GTK_LABEL( bin->child );
86
87 wxString str( wxGTK_CONV_BACK( label->label ) );
88
89 if (check == (str.GetChar(1) == wxCHECKLBOX_CHECKED))
90 return;
91
92 str.SetChar( 1, check ? wxCHECKLBOX_CHECKED : wxCHECKLBOX_UNCHECKED );
93
94 gtk_label_set( label, wxGTK_CONV( str ) );
95
96 return;
97 }
98
99 wxFAIL_MSG(wxT("wrong checklistbox index"));
100 }
101
102 int wxCheckListBox::GetItemHeight() const
103 {
104 // FIXME
105 return 22;
106 }
107
108 #endif