Motif additions
[wxWidgets.git] / src / motif / checkbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: checkbox.cpp
3 // Purpose: wxCheckBox
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "checkbox.h"
14 #endif
15
16 #include "wx/checkbox.h"
17
18 #include <Xm/Label.h>
19 #include <Xm/LabelG.h>
20 #include <Xm/ToggleB.h>
21 #include <Xm/ToggleBG.h>
22
23 #include "wx/motif/private.h"
24
25 void wxCheckBoxCallback (Widget w, XtPointer clientData,
26 XtPointer ptr);
27
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
31 #endif
32
33 // Single check box item
34 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
35 const wxPoint& pos,
36 const wxSize& size, long style,
37 const wxValidator& validator,
38 const wxString& name)
39 {
40 SetName(name);
41 SetValidator(validator);
42 m_windowStyle = style;
43
44 if (parent) parent->AddChild(this);
45
46 if ( id == -1 )
47 m_windowId = NewControlId();
48 else
49 m_windowId = id;
50
51 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
52
53 XmString text = XmStringCreateSimple (label1);
54 Widget parentWidget = (Widget) parent->GetClientWidget();
55
56 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
57 xmToggleButtonWidgetClass, parentWidget,
58 XmNlabelString, text,
59 NULL);
60 XmStringFree (text);
61
62 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
63 (XtPointer) this);
64
65 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
66
67 SetCanAddEventHandler(TRUE);
68 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
69
70 ChangeColour(m_mainWidget);
71 SetFont(* parent->GetFont());
72
73 return TRUE;
74 }
75
76 void wxCheckBox::SetValue(bool val)
77 {
78 m_inSetValue = TRUE;
79 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
80 m_inSetValue = FALSE;
81 }
82
83 bool wxCheckBox::GetValue() const
84 {
85 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
86 }
87
88 void wxCheckBox::Command (wxCommandEvent & event)
89 {
90 SetValue ((event.GetInt() != 0));
91 ProcessCommand (event);
92 }
93
94 // Bitmap checkbox
95 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
96 const wxPoint& pos,
97 const wxSize& size, long style,
98 const wxValidator& validator,
99 const wxString& name)
100 {
101 SetName(name);
102 SetValidator(validator);
103 m_windowStyle = style;
104
105 if (parent) parent->AddChild(this);
106
107 if ( id == -1 )
108 m_windowId = NewControlId();
109 else
110 m_windowId = id;
111
112 // TODO: Create the bitmap checkbox
113
114 return FALSE;
115 }
116
117 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
118 {
119 // TODO
120 }
121
122 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
123 {
124 // TODO
125 }
126
127 void wxBitmapCheckBox::SetValue(bool val)
128 {
129 // TODO
130 }
131
132 bool wxBitmapCheckBox::GetValue() const
133 {
134 // TODOD
135 return FALSE;
136 }
137
138 void wxCheckBoxCallback (Widget w, XtPointer clientData,
139 XtPointer ptr)
140 {
141 wxCheckBox *item = (wxCheckBox *) clientData;
142
143 if (item->InSetValue())
144 return;
145
146 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
147 event.SetInt((int) item->GetValue ());
148 event.SetEventObject(item);
149 item->ProcessCommand (event);
150 }