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