]> git.saurik.com Git - wxWidgets.git/blob - src/motif/checkbox.cpp
Corrected Motif build,
[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 #include "wx/utils.h"
18
19 #include <Xm/Label.h>
20 #include <Xm/LabelG.h>
21 #include <Xm/ToggleB.h>
22 #include <Xm/ToggleBG.h>
23
24 #include "wx/motif/private.h"
25
26 void wxCheckBoxCallback (Widget w, XtPointer clientData,
27 XtPointer ptr);
28
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
31 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
32 #endif
33
34 // Single check box item
35 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 const wxValidator& validator,
39 const wxString& name)
40 {
41 SetName(name);
42 SetValidator(validator);
43 m_windowStyle = style;
44 m_backgroundColour = parent->GetBackgroundColour();
45 m_foregroundColour = parent->GetForegroundColour();
46 m_font = parent->GetFont();
47
48 if (parent) parent->AddChild(this);
49
50 if ( id == -1 )
51 m_windowId = NewControlId();
52 else
53 m_windowId = id;
54
55 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
56
57 XmString text = XmStringCreateSimple (label1);
58 Widget parentWidget = (Widget) parent->GetClientWidget();
59 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
60
61 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
62 xmToggleButtonWidgetClass, parentWidget,
63 XmNfontList, fontList,
64 XmNlabelString, text,
65 NULL);
66 XmStringFree (text);
67
68 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
69 (XtPointer) this);
70
71 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
72
73 SetCanAddEventHandler(TRUE);
74 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
75
76 ChangeBackgroundColour();
77 return TRUE;
78 }
79
80 void wxCheckBox::SetValue(bool val)
81 {
82 m_inSetValue = TRUE;
83 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
84 m_inSetValue = FALSE;
85 }
86
87 bool wxCheckBox::GetValue() const
88 {
89 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
90 }
91
92 void wxCheckBox::Command (wxCommandEvent & event)
93 {
94 SetValue ((event.GetInt() != 0));
95 ProcessCommand (event);
96 }
97
98 // Bitmap checkbox
99 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
100 const wxPoint& pos,
101 const wxSize& size, long style,
102 const wxValidator& validator,
103 const wxString& name)
104 {
105 SetName(name);
106 SetValidator(validator);
107 m_windowStyle = style;
108
109 if (parent) parent->AddChild(this);
110
111 if ( id == -1 )
112 m_windowId = NewControlId();
113 else
114 m_windowId = id;
115
116 // TODO: Create the bitmap checkbox
117
118 return FALSE;
119 }
120
121 void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
122 {
123 // TODO
124 }
125
126 void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
127 {
128 // TODO
129 }
130
131 void wxBitmapCheckBox::SetValue(bool val)
132 {
133 // TODO
134 }
135
136 bool wxBitmapCheckBox::GetValue() const
137 {
138 // TODOD
139 return FALSE;
140 }
141
142 void wxCheckBoxCallback (Widget w, XtPointer clientData,
143 XtPointer ptr)
144 {
145 wxCheckBox *item = (wxCheckBox *) clientData;
146
147 if (item->InSetValue())
148 return;
149
150 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
151 event.SetInt((int) item->GetValue ());
152 event.SetEventObject(item);
153 item->ProcessCommand (event);
154 }
155
156 void wxCheckBox::ChangeFont(bool keepOriginalSize)
157 {
158 wxWindow::ChangeFont(keepOriginalSize);
159 }
160
161 void wxCheckBox::ChangeBackgroundColour()
162 {
163 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
164 (wxColour*) NULL);
165
166 XtVaSetValues ((Widget) m_mainWidget,
167 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
168 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
169 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
170 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
171 NULL);
172
173 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
174
175 // Better to have the checkbox selection in black, or it's
176 // hard to determine what state it is in.
177 XtVaSetValues ((Widget) m_mainWidget,
178 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
179 XmNselectColor, selectPixel,
180 NULL);
181 }
182
183 void wxCheckBox::ChangeForegroundColour()
184 {
185 wxWindow::ChangeForegroundColour();
186 }