]> git.saurik.com Git - wxWidgets.git/blob - src/motif/checkbox.cpp
Added GSocket/wxSocket alias to socket.h to prevent us from using GSocket
[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 #if 0 // gcc 2.95 doesn't like this apparently
56 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
57 XmString text = XmStringCreateSimple (label1);
58 #endif
59
60 wxXmString text( label );
61
62 Widget parentWidget = (Widget) parent->GetClientWidget();
63 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
64
65 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
66 xmToggleButtonWidgetClass, parentWidget,
67 XmNfontList, fontList,
68 XmNlabelString, text(),
69 NULL);
70 #if 0
71 XmStringFree (text);
72 #endif
73
74 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
75 (XtPointer) this);
76
77 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
78
79 SetCanAddEventHandler(TRUE);
80 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
81
82 ChangeBackgroundColour();
83 return TRUE;
84 }
85
86 void wxCheckBox::SetValue(bool val)
87 {
88 m_inSetValue = TRUE;
89 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
90 m_inSetValue = FALSE;
91 }
92
93 bool wxCheckBox::GetValue() const
94 {
95 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
96 }
97
98 void wxCheckBox::Command (wxCommandEvent & event)
99 {
100 SetValue ((event.GetInt() != 0));
101 ProcessCommand (event);
102 }
103
104 // Bitmap checkbox
105 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
106 const wxPoint& pos,
107 const wxSize& size, long style,
108 const wxValidator& validator,
109 const wxString& name)
110 {
111 SetName(name);
112 SetValidator(validator);
113 m_windowStyle = style;
114
115 if (parent) parent->AddChild(this);
116
117 if ( id == -1 )
118 m_windowId = NewControlId();
119 else
120 m_windowId = id;
121
122 // TODO: Create the bitmap checkbox
123
124 return FALSE;
125 }
126
127 void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
128 {
129 // TODO
130 }
131
132 void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
133 {
134 // TODO
135 }
136
137 void wxBitmapCheckBox::SetValue(bool val)
138 {
139 // TODO
140 }
141
142 bool wxBitmapCheckBox::GetValue() const
143 {
144 // TODOD
145 return FALSE;
146 }
147
148 void wxCheckBoxCallback (Widget w, XtPointer clientData,
149 XtPointer ptr)
150 {
151 wxCheckBox *item = (wxCheckBox *) clientData;
152
153 if (item->InSetValue())
154 return;
155
156 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
157 event.SetInt((int) item->GetValue ());
158 event.SetEventObject(item);
159 item->ProcessCommand (event);
160 }
161
162 void wxCheckBox::ChangeFont(bool keepOriginalSize)
163 {
164 wxWindow::ChangeFont(keepOriginalSize);
165 }
166
167 void wxCheckBox::ChangeBackgroundColour()
168 {
169 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
170 (wxColour*) NULL);
171
172 XtVaSetValues ((Widget) m_mainWidget,
173 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
174 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
175 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
176 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
177 NULL);
178
179 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
180
181 // Better to have the checkbox selection in black, or it's
182 // hard to determine what state it is in.
183 XtVaSetValues ((Widget) m_mainWidget,
184 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
185 XmNselectColor, selectPixel,
186 NULL);
187 }
188
189 void wxCheckBox::ChangeForegroundColour()
190 {
191 wxWindow::ChangeForegroundColour();
192 }