1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "checkbox.h"
17 #define XtDisplay XTDISPLAY
22 #include "wx/checkbox.h"
23 #include "wx/tglbtn.h"
27 #pragma message disable nosimpint
30 #include <Xm/LabelG.h>
31 #include <Xm/ToggleB.h>
32 #include <Xm/ToggleBG.h>
34 #pragma message enable nosimpint
37 #include "wx/motif/private.h"
39 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
42 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
44 // Single check box item
45 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
47 const wxSize
& size
, long style
,
48 const wxValidator
& validator
,
51 if( !wxControl::CreateControl( parent
, id
, pos
, size
, style
, validator
,
55 wxString
label1(wxStripMenuCodes(label
));
56 wxXmString
text( label1
);
58 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
60 (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
62 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
63 xmToggleButtonWidgetClass
, parentWidget
,
64 XmNfontList
, fontList
,
65 XmNlabelString
, text(),
68 XtAddCallback( (Widget
)m_mainWidget
,
69 XmNvalueChangedCallback
, (XtCallbackProc
)wxCheckBoxCallback
,
72 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
74 SetCanAddEventHandler(TRUE
);
75 AttachWidget( parent
, m_mainWidget
, (WXWidget
)NULL
,
76 pos
.x
, pos
.y
, size
.x
, size
.y
);
78 ChangeBackgroundColour();
82 void wxCheckBox::SetValue(bool val
)
85 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
89 bool wxCheckBox::GetValue() const
91 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
94 void wxCheckBox::Command (wxCommandEvent
& event
)
96 SetValue ((event
.GetInt() != 0));
97 ProcessCommand (event
);
100 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
101 XtPointer
WXUNUSED(ptr
))
103 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
105 if (item
->InSetValue())
108 wxCommandEvent
event (item
->m_evtType
, item
->GetId());
109 event
.SetInt((int) item
->GetValue ());
110 event
.SetEventObject(item
);
111 item
->ProcessCommand (event
);
114 void wxCheckBox::ChangeBackgroundColour()
116 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
119 XtVaSetValues ((Widget
) m_mainWidget
,
120 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
121 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
122 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
123 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
126 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
128 // Better to have the checkbox selection in black, or it's
129 // hard to determine what state it is in.
130 XtVaSetValues ((Widget
) m_mainWidget
,
131 XmNselectColor
, selectPixel
,
135 ///////////////////////////////////////////////////////////////////////////////
137 ///////////////////////////////////////////////////////////////////////////////
141 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
)
142 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton
, wxControl
)
144 bool wxToggleButton::Create( wxWindow
* parent
, wxWindowID id
,
145 const wxString
& label
,
149 const wxValidator
& val
,
150 const wxString
&name
)
152 if( !wxCheckBox::Create( parent
, id
, label
, pos
, size
, style
, val
, name
) )
155 XtVaSetValues( (Widget
)m_mainWidget
,
157 #if XmVersion >= 2000
158 XmNindicatorOn
, XmINDICATOR_NONE
,
160 XmNindicatorOn
, False
,
162 XmNfillOnSelect
, False
,
163 XmNshadowThickness
, 2,
164 XmNalignment
, XmALIGNMENT_CENTER
,
169 // set it again, because the XtVaSetValue above resets it
170 if( size
.x
!= -1 || size
.y
!= -1 )
176 #endif // wxUSE_TOGGLEBUTTON