]> git.saurik.com Git - wxWidgets.git/blob - src/motif/checkbox.cpp
Removed unused code.
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "checkbox.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __VMS
20 #define XtDisplay XTDISPLAY
21 #endif
22
23 #include "wx/defs.h"
24
25 #include "wx/checkbox.h"
26 #include "wx/tglbtn.h"
27 #include "wx/utils.h"
28
29 #ifdef __VMS__
30 #pragma message disable nosimpint
31 #endif
32 #include <Xm/Label.h>
33 #include <Xm/LabelG.h>
34 #include <Xm/ToggleB.h>
35 #include <Xm/ToggleBG.h>
36 #ifdef __VMS__
37 #pragma message enable nosimpint
38 #endif
39
40 #include "wx/motif/private.h"
41
42 void wxCheckBoxCallback (Widget w, XtPointer clientData,
43 XtPointer ptr);
44
45 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
46
47 // Single check box item
48 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
49 const wxPoint& pos,
50 const wxSize& size, long style,
51 const wxValidator& validator,
52 const wxString& name)
53 {
54 if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
55 name ) )
56 return FALSE;
57
58 wxString label1(wxStripMenuCodes(label));
59 wxXmString text( label1 );
60
61 Widget parentWidget = (Widget) parent->GetClientWidget();
62
63 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
64 xmToggleButtonWidgetClass, parentWidget,
65 wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
66 XmNlabelString, text(),
67 XmNrecomputeSize, False,
68 // XmNindicatorOn, XmINDICATOR_CHECK_BOX,
69 // XmNfillOnSelect, False,
70 XmNtoggleMode, Is3State() ? XmTOGGLE_INDETERMINATE : XmTOGGLE_BOOLEAN,
71 NULL);
72
73 XtAddCallback( (Widget)m_mainWidget,
74 XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback,
75 (XtPointer)this );
76
77 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
78
79 AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
80 pos.x, pos.y, size.x, size.y );
81
82 ChangeBackgroundColour();
83 return TRUE;
84 }
85
86 void wxCheckBox::SetValue(bool val)
87 {
88 if (val)
89 {
90 Set3StateValue(wxCHK_CHECKED);
91 }
92 else
93 {
94 Set3StateValue(wxCHK_UNCHECKED);
95 }
96 }
97
98 bool wxCheckBox::GetValue() const
99 {
100 return (Get3StateValue() != 0);
101 }
102
103 void wxCheckBox::Command (wxCommandEvent & event)
104 {
105 int state = event.GetInt();
106 wxCHECK_RET( (state == wxCHK_UNCHECKED) || (state == wxCHK_CHECKED)
107 || (state == wxCHK_UNDETERMINED),
108 wxT("event.GetInt() returned an invalid checkbox state") );
109
110 Set3StateValue((wxCheckBoxState) state);
111 ProcessCommand(event);
112 }
113
114 void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
115 XtPointer WXUNUSED(ptr))
116 {
117 wxCheckBox *item = (wxCheckBox *) clientData;
118
119 if (item->InSetValue())
120 return;
121
122 wxCheckBoxState state = item->Get3StateValue();
123
124 if( !item->Is3rdStateAllowedForUser() && state == wxCHK_UNDETERMINED )
125 {
126 state = wxCHK_UNCHECKED;
127 item->Set3StateValue( state );
128 }
129
130 wxCommandEvent event( item->m_evtType, item->GetId() );
131 event.SetInt( (int)state );
132 event.SetEventObject( item );
133 item->ProcessCommand( event );
134 }
135
136 void wxCheckBox::ChangeBackgroundColour()
137 {
138 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
139 (wxColour*) NULL);
140
141 XtVaSetValues ((Widget) m_mainWidget,
142 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
143 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
144 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
145 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
146 NULL);
147
148 int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
149
150 // Better to have the checkbox selection in black, or it's
151 // hard to determine what state it is in.
152 XtVaSetValues ((Widget) m_mainWidget,
153 XmNselectColor, selectPixel,
154 NULL);
155 }
156
157 void wxCheckBox::DoSet3StateValue(wxCheckBoxState state)
158 {
159 m_inSetValue = true;
160
161 unsigned char value;
162
163 switch (state)
164 {
165 case wxCHK_UNCHECKED: value = XmUNSET; break;
166 case wxCHK_CHECKED: value = XmSET; break;
167 case wxCHK_UNDETERMINED: value = XmINDETERMINATE; break;
168 }
169
170 XtVaSetValues( (Widget) m_mainWidget,
171 XmNset, value,
172 NULL );
173
174 m_inSetValue = false;
175 }
176
177 wxCheckBoxState wxCheckBox::DoGet3StateValue() const
178 {
179 unsigned char value = 0;
180
181 XtVaGetValues( (Widget) m_mainWidget,
182 XmNset, &value,
183 NULL );
184
185 switch (value)
186 {
187 case XmUNSET: return wxCHK_UNCHECKED;
188 case XmSET: return wxCHK_CHECKED;
189 case XmINDETERMINATE: return wxCHK_UNDETERMINED;
190 }
191
192 // impossible...
193 return wxCHK_UNDETERMINED;
194 }
195
196 ///////////////////////////////////////////////////////////////////////////////
197 // wxToggleButton
198 ///////////////////////////////////////////////////////////////////////////////
199
200 #if wxUSE_TOGGLEBTN
201
202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
203 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
204
205 bool wxToggleButton::Create( wxWindow* parent, wxWindowID id,
206 const wxString& label,
207 const wxPoint& pos,
208 const wxSize& size,
209 long style,
210 const wxValidator& val,
211 const wxString &name )
212 {
213 if( !wxCheckBox::Create( parent, id, label, pos, size, style, val, name ) )
214 return false;
215
216 XtVaSetValues( (Widget)m_mainWidget,
217 XmNindicatorSize, 0,
218 #if XmVersion >= 2000
219 XmNindicatorOn, XmINDICATOR_NONE,
220 #else
221 XmNindicatorOn, False,
222 #endif
223 XmNfillOnSelect, False,
224 XmNshadowThickness, 2,
225 XmNalignment, XmALIGNMENT_CENTER,
226 XmNmarginLeft, 0,
227 XmNmarginRight, 0,
228 NULL );
229
230 // set it again, because the XtVaSetValue above resets it
231 if( size.x != -1 || size.y != -1 )
232 SetSize( size );
233
234 return true;
235 }
236
237 #endif // wxUSE_TOGGLEBUTTON