1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
16 #define XtDisplay XTDISPLAY
21 #include "wx/checkbox.h"
22 #include "wx/tglbtn.h"
26 #pragma message disable nosimpint
29 #include <Xm/LabelG.h>
30 #include <Xm/ToggleB.h>
31 #include <Xm/ToggleBG.h>
33 #pragma message enable nosimpint
36 // define symbols that are missing in old versions of Motif.
37 #if (XmVersion < 2000)
38 #define XmNtoggleMode 0
39 #define XmTOGGLE_INDETERMINATE 1
40 #define XmTOGGLE_BOOLEAN 2
43 #define XmINDETERMINATE 5
47 #include "wx/motif/private.h"
49 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
52 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
54 // Single check box item
55 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
57 const wxSize
& size
, long style
,
58 const wxValidator
& validator
,
61 if( !wxControl::CreateControl( parent
, id
, pos
, size
, style
, validator
,
65 wxString
label1(wxStripMenuCodes(label
));
66 wxXmString
text( label1
);
68 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
70 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
71 xmToggleButtonWidgetClass
, parentWidget
,
72 wxFont::GetFontTag(), m_font
.GetFontTypeC(XtDisplay(parentWidget
)),
73 XmNlabelString
, text(),
74 XmNrecomputeSize
, False
,
75 // XmNindicatorOn, XmINDICATOR_CHECK_BOX,
76 // XmNfillOnSelect, False,
77 XmNtoggleMode
, Is3State() ? XmTOGGLE_INDETERMINATE
: XmTOGGLE_BOOLEAN
,
80 XtAddCallback( (Widget
)m_mainWidget
,
81 XmNvalueChangedCallback
, (XtCallbackProc
)wxCheckBoxCallback
,
84 XmToggleButtonSetState ((Widget
) m_mainWidget
, False
, True
);
86 AttachWidget( parent
, m_mainWidget
, (WXWidget
)NULL
,
87 pos
.x
, pos
.y
, size
.x
, size
.y
);
89 ChangeBackgroundColour();
93 void wxCheckBox::SetValue(bool val
)
97 Set3StateValue(wxCHK_CHECKED
);
101 Set3StateValue(wxCHK_UNCHECKED
);
105 bool wxCheckBox::GetValue() const
107 return (Get3StateValue() != 0);
110 void wxCheckBox::Command (wxCommandEvent
& event
)
112 int state
= event
.GetInt();
113 wxCHECK_RET( (state
== wxCHK_UNCHECKED
) || (state
== wxCHK_CHECKED
)
114 || (state
== wxCHK_UNDETERMINED
),
115 wxT("event.GetInt() returned an invalid checkbox state") );
117 Set3StateValue((wxCheckBoxState
) state
);
118 ProcessCommand(event
);
121 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
122 XtPointer
WXUNUSED(ptr
))
124 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
126 if (item
->InSetValue())
129 wxCheckBoxState state
= item
->Get3StateValue();
131 if( !item
->Is3rdStateAllowedForUser() && state
== wxCHK_UNDETERMINED
)
133 state
= wxCHK_UNCHECKED
;
134 item
->Set3StateValue( state
);
137 wxCommandEvent
event( item
->m_evtType
, item
->GetId() );
138 event
.SetInt( (int)state
);
139 event
.SetEventObject( item
);
140 item
->ProcessCommand( event
);
143 void wxCheckBox::ChangeBackgroundColour()
145 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
148 XtVaSetValues ((Widget
) m_mainWidget
,
149 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
150 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
151 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
152 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
155 int selectPixel
= wxBLACK
->AllocColour(XtDisplay((Widget
)m_mainWidget
));
157 // Better to have the checkbox selection in black, or it's
158 // hard to determine what state it is in.
159 XtVaSetValues ((Widget
) m_mainWidget
,
160 XmNselectColor
, selectPixel
,
164 void wxCheckBox::DoSet3StateValue(wxCheckBoxState state
)
172 case wxCHK_UNCHECKED
: value
= XmUNSET
; break;
173 case wxCHK_CHECKED
: value
= XmSET
; break;
174 case wxCHK_UNDETERMINED
: value
= XmINDETERMINATE
; break;
175 default: wxASSERT(0); return;
178 XtVaSetValues( (Widget
) m_mainWidget
,
182 m_inSetValue
= false;
185 wxCheckBoxState
wxCheckBox::DoGet3StateValue() const
187 unsigned char value
= 0;
189 XtVaGetValues( (Widget
) m_mainWidget
,
195 case XmUNSET
: return wxCHK_UNCHECKED
;
196 case XmSET
: return wxCHK_CHECKED
;
197 case XmINDETERMINATE
: return wxCHK_UNDETERMINED
;
201 return wxCHK_UNDETERMINED
;
204 ///////////////////////////////////////////////////////////////////////////////
206 ///////////////////////////////////////////////////////////////////////////////
210 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
211 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
213 bool wxToggleButton::Create( wxWindow
* parent
, wxWindowID id
,
214 const wxString
& label
,
218 const wxValidator
& val
,
219 const wxString
&name
)
221 if( !wxCheckBox::Create( parent
, id
, label
, pos
, size
, style
, val
, name
) )
224 XtVaSetValues( (Widget
)m_mainWidget
,
226 #if XmVersion >= 2000
227 XmNindicatorOn
, XmINDICATOR_NONE
,
229 XmNindicatorOn
, False
,
231 XmNfillOnSelect
, False
,
232 XmNshadowThickness
, 2,
233 XmNalignment
, XmALIGNMENT_CENTER
,
238 // set it again, because the XtVaSetValue above resets it
239 if( size
.x
!= -1 || size
.y
!= -1 )
245 #endif // wxUSE_TOGGLEBUTTON