1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "checkbox.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #define XtDisplay XTDISPLAY
25 #include "wx/checkbox.h"
26 #include "wx/tglbtn.h"
30 #pragma message disable nosimpint
33 #include <Xm/LabelG.h>
34 #include <Xm/ToggleB.h>
35 #include <Xm/ToggleBG.h>
37 #pragma message enable nosimpint
40 #include "wx/motif/private.h"
42 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
45 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
47 // Single check box item
48 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
50 const wxSize
& size
, long style
,
51 const wxValidator
& validator
,
54 if( !wxControl::CreateControl( parent
, id
, pos
, size
, style
, validator
,
58 wxString
label1(wxStripMenuCodes(label
));
59 wxXmString
text( label1
);
61 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
63 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
64 xmToggleButtonWidgetClass
, parentWidget
,
65 wxFont::GetFontTag(), m_font
.GetFontType(XtDisplay(parentWidget
)),
66 XmNlabelString
, text(),
67 XmNrecomputeSize
, False
,
70 XtAddCallback( (Widget
)m_mainWidget
,
71 XmNvalueChangedCallback
, (XtCallbackProc
)wxCheckBoxCallback
,
74 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
76 AttachWidget( parent
, m_mainWidget
, (WXWidget
)NULL
,
77 pos
.x
, pos
.y
, size
.x
, size
.y
);
79 ChangeBackgroundColour();
83 void wxCheckBox::SetValue(bool val
)
86 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
90 bool wxCheckBox::GetValue() const
92 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
95 void wxCheckBox::Command (wxCommandEvent
& event
)
97 SetValue ((event
.GetInt() != 0));
98 ProcessCommand (event
);
101 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
102 XtPointer
WXUNUSED(ptr
))
104 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
106 if (item
->InSetValue())
109 wxCommandEvent
event (item
->m_evtType
, item
->GetId());
110 event
.SetInt((int) item
->GetValue ());
111 event
.SetEventObject(item
);
112 item
->ProcessCommand (event
);
115 void wxCheckBox::ChangeBackgroundColour()
117 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
120 XtVaSetValues ((Widget
) m_mainWidget
,
121 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
122 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
123 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
124 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
127 int selectPixel
= wxBLACK
->AllocColour(XtDisplay((Widget
)m_mainWidget
));
129 // Better to have the checkbox selection in black, or it's
130 // hard to determine what state it is in.
131 XtVaSetValues ((Widget
) m_mainWidget
,
132 XmNselectColor
, selectPixel
,
136 ///////////////////////////////////////////////////////////////////////////////
138 ///////////////////////////////////////////////////////////////////////////////
142 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
143 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
145 bool wxToggleButton::Create( wxWindow
* parent
, wxWindowID id
,
146 const wxString
& label
,
150 const wxValidator
& val
,
151 const wxString
&name
)
153 if( !wxCheckBox::Create( parent
, id
, label
, pos
, size
, style
, val
, name
) )
156 XtVaSetValues( (Widget
)m_mainWidget
,
158 #if XmVersion >= 2000
159 XmNindicatorOn
, XmINDICATOR_NONE
,
161 XmNindicatorOn
, False
,
163 XmNfillOnSelect
, False
,
164 XmNshadowThickness
, 2,
165 XmNalignment
, XmALIGNMENT_CENTER
,
170 // set it again, because the XtVaSetValue above resets it
171 if( size
.x
!= -1 || size
.y
!= -1 )
177 #endif // wxUSE_TOGGLEBUTTON