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"
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 #include "wx/motif/private.h"
38 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
41 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
43 // Single check box item
44 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
50 if( !wxControl::CreateControl( parent
, id
, pos
, size
, style
, validator
,
54 wxString
label1(wxStripMenuCodes(label
));
55 wxXmString
text( label1
);
57 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
59 (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
61 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
62 xmToggleButtonWidgetClass
, parentWidget
,
63 XmNfontList
, fontList
,
64 XmNlabelString
, text(),
67 XtAddCallback( (Widget
)m_mainWidget
,
68 XmNvalueChangedCallback
, (XtCallbackProc
)wxCheckBoxCallback
,
71 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
73 SetCanAddEventHandler(TRUE
);
74 AttachWidget( parent
, m_mainWidget
, (WXWidget
)NULL
,
75 pos
.x
, pos
.y
, size
.x
, size
.y
);
77 ChangeBackgroundColour();
81 void wxCheckBox::SetValue(bool val
)
84 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
88 bool wxCheckBox::GetValue() const
90 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
93 void wxCheckBox::Command (wxCommandEvent
& event
)
95 SetValue ((event
.GetInt() != 0));
96 ProcessCommand (event
);
99 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
100 XtPointer
WXUNUSED(ptr
))
102 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
104 if (item
->InSetValue())
107 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
108 event
.SetInt((int) item
->GetValue ());
109 event
.SetEventObject(item
);
110 item
->ProcessCommand (event
);
113 void wxCheckBox::ChangeBackgroundColour()
115 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
118 XtVaSetValues ((Widget
) m_mainWidget
,
119 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
120 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
121 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
122 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
125 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
127 // Better to have the checkbox selection in black, or it's
128 // hard to determine what state it is in.
129 XtVaSetValues ((Widget
) m_mainWidget
,
130 XmNselectColor
, selectPixel
,