More Motif stuff, minor stubs correction
[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 // TODO: m_inSetValue
79 // inSetValue = TRUE;
80 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
81 // inSetValue = FALSE;
82 }
83
84 bool wxCheckBox::GetValue() const
85 {
86 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
87 }
88
89 void wxCheckBox::Command (wxCommandEvent & event)
90 {
91 SetValue ((event.GetInt() != 0));
92 ProcessCommand (event);
93 }
94
95 // Bitmap checkbox
96 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
97 const wxPoint& pos,
98 const wxSize& size, long style,
99 const wxValidator& validator,
100 const wxString& name)
101 {
102 SetName(name);
103 SetValidator(validator);
104 m_windowStyle = style;
105
106 if (parent) parent->AddChild(this);
107
108 if ( id == -1 )
109 m_windowId = NewControlId();
110 else
111 m_windowId = id;
112
113 // TODO: Create the bitmap checkbox
114
115 return FALSE;
116 }
117
118 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
119 {
120 // TODO
121 }
122
123 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
124 {
125 // TODO
126 }
127
128 void wxBitmapCheckBox::SetValue(bool val)
129 {
130 // TODO
131 }
132
133 bool wxBitmapCheckBox::GetValue() const
134 {
135 // TODOD
136 return FALSE;
137 }
138
139 void wxCheckBoxCallback (Widget w, XtPointer clientData,
140 XtPointer ptr)
141 {
142 wxCheckBox *item = (wxCheckBox *) clientData;
143 // TODO
144 // if (item->inSetValue)
145 // return;
146
147 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
148 event.SetInt((int) item->GetValue ());
149 event.SetEventObject(item);
150 item->ProcessCommand (event);
151 }