More Motif changes (colour/font stuff)
[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 m_backgroundColour = parent->GetBackgroundColour();
44 m_foregroundColour = parent->GetForegroundColour();
45
46 if (parent) parent->AddChild(this);
47
48 if ( id == -1 )
49 m_windowId = NewControlId();
50 else
51 m_windowId = id;
52
53 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
54
55 XmString text = XmStringCreateSimple (label1);
56 Widget parentWidget = (Widget) parent->GetClientWidget();
57
58 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
59 xmToggleButtonWidgetClass, parentWidget,
60 XmNlabelString, text,
61 NULL);
62 XmStringFree (text);
63
64 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
65 (XtPointer) this);
66
67 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
68
69 SetCanAddEventHandler(TRUE);
70 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
71
72 ChangeBackgroundColour();
73 SetFont(* parent->GetFont());
74
75 return TRUE;
76 }
77
78 void wxCheckBox::SetValue(bool val)
79 {
80 m_inSetValue = TRUE;
81 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
82 m_inSetValue = FALSE;
83 }
84
85 bool wxCheckBox::GetValue() const
86 {
87 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
88 }
89
90 void wxCheckBox::Command (wxCommandEvent & event)
91 {
92 SetValue ((event.GetInt() != 0));
93 ProcessCommand (event);
94 }
95
96 // Bitmap checkbox
97 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
98 const wxPoint& pos,
99 const wxSize& size, long style,
100 const wxValidator& validator,
101 const wxString& name)
102 {
103 SetName(name);
104 SetValidator(validator);
105 m_windowStyle = style;
106
107 if (parent) parent->AddChild(this);
108
109 if ( id == -1 )
110 m_windowId = NewControlId();
111 else
112 m_windowId = id;
113
114 // TODO: Create the bitmap checkbox
115
116 return FALSE;
117 }
118
119 void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
120 {
121 // TODO
122 }
123
124 void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
125 {
126 // TODO
127 }
128
129 void wxBitmapCheckBox::SetValue(bool val)
130 {
131 // TODO
132 }
133
134 bool wxBitmapCheckBox::GetValue() const
135 {
136 // TODOD
137 return FALSE;
138 }
139
140 void wxCheckBoxCallback (Widget w, XtPointer clientData,
141 XtPointer ptr)
142 {
143 wxCheckBox *item = (wxCheckBox *) clientData;
144
145 if (item->InSetValue())
146 return;
147
148 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
149 event.SetInt((int) item->GetValue ());
150 event.SetEventObject(item);
151 item->ProcessCommand (event);
152 }
153
154 void wxCheckBox::ChangeFont()
155 {
156 wxWindow::ChangeFont();
157 }
158
159 void wxCheckBox::ChangeBackgroundColour()
160 {
161 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
162 (wxColour*) NULL);
163
164 XtVaSetValues ((Widget) m_mainWidget,
165 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
166 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
167 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
168 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
169 NULL);
170
171 XtVaSetValues ((Widget) m_mainWidget,
172 XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
173 NULL);
174 }
175
176 void wxCheckBox::ChangeForegroundColour()
177 {
178 wxWindow::ChangeForegroundColour();
179 }