1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "checkbox.h"
16 #include "wx/checkbox.h"
20 #include <Xm/LabelG.h>
21 #include <Xm/ToggleB.h>
22 #include <Xm/ToggleBG.h>
24 #include "wx/motif/private.h"
26 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
31 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
34 // Single check box item
35 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
37 const wxSize
& size
, long style
,
38 const wxValidator
& validator
,
42 SetValidator(validator
);
43 m_windowStyle
= style
;
44 m_backgroundColour
= parent
->GetBackgroundColour();
45 m_foregroundColour
= parent
->GetForegroundColour();
46 m_windowFont
= parent
->GetFont();
48 if (parent
) parent
->AddChild(this);
51 m_windowId
= NewControlId();
55 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
57 XmString text
= XmStringCreateSimple (label1
);
58 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
59 XmFontList fontList
= (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(parentWidget
));
61 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
62 xmToggleButtonWidgetClass
, parentWidget
,
63 XmNfontList
, fontList
,
68 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
71 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
73 SetCanAddEventHandler(TRUE
);
74 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
76 ChangeBackgroundColour();
80 void wxCheckBox::SetValue(bool val
)
83 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
87 bool wxCheckBox::GetValue() const
89 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
92 void wxCheckBox::Command (wxCommandEvent
& event
)
94 SetValue ((event
.GetInt() != 0));
95 ProcessCommand (event
);
99 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
101 const wxSize
& size
, long style
,
102 const wxValidator
& validator
,
103 const wxString
& name
)
106 SetValidator(validator
);
107 m_windowStyle
= style
;
109 if (parent
) parent
->AddChild(this);
112 m_windowId
= NewControlId();
116 // TODO: Create the bitmap checkbox
121 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
126 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
131 void wxBitmapCheckBox::SetValue(bool val
)
136 bool wxBitmapCheckBox::GetValue() const
142 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
145 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
147 if (item
->InSetValue())
150 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
151 event
.SetInt((int) item
->GetValue ());
152 event
.SetEventObject(item
);
153 item
->ProcessCommand (event
);
156 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
158 wxWindow::ChangeFont(keepOriginalSize
);
161 void wxCheckBox::ChangeBackgroundColour()
163 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
166 XtVaSetValues ((Widget
) m_mainWidget
,
167 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
168 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
169 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
170 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
173 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
175 // Better to have the checkbox selection in black, or it's
176 // hard to determine what state it is in.
177 XtVaSetValues ((Widget
) m_mainWidget
,
178 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
179 XmNselectColor
, selectPixel
,
183 void wxCheckBox::ChangeForegroundColour()
185 wxWindow::ChangeForegroundColour();