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_font
= parent
->GetFont();
48 if (parent
) parent
->AddChild(this);
51 m_windowId
= NewControlId();
55 #if 0 // gcc 2.95 doesn't like this apparently
56 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
57 XmString text
= XmStringCreateSimple (label1
);
60 wxXmString
text( label
);
62 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
63 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
65 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
66 xmToggleButtonWidgetClass
, parentWidget
,
67 XmNfontList
, fontList
,
68 XmNlabelString
, text(),
74 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
77 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
79 SetCanAddEventHandler(TRUE
);
80 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
82 ChangeBackgroundColour();
86 void wxCheckBox::SetValue(bool val
)
89 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
93 bool wxCheckBox::GetValue() const
95 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
98 void wxCheckBox::Command (wxCommandEvent
& event
)
100 SetValue ((event
.GetInt() != 0));
101 ProcessCommand (event
);
105 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
107 const wxSize
& size
, long style
,
108 const wxValidator
& validator
,
109 const wxString
& name
)
112 SetValidator(validator
);
113 m_windowStyle
= style
;
115 if (parent
) parent
->AddChild(this);
118 m_windowId
= NewControlId();
122 // TODO: Create the bitmap checkbox
127 void wxBitmapCheckBox::SetLabel(const wxBitmap
& bitmap
)
132 void wxBitmapCheckBox::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
137 void wxBitmapCheckBox::SetValue(bool val
)
142 bool wxBitmapCheckBox::GetValue() const
148 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
151 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
153 if (item
->InSetValue())
156 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
157 event
.SetInt((int) item
->GetValue ());
158 event
.SetEventObject(item
);
159 item
->ProcessCommand (event
);
162 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
164 wxWindow::ChangeFont(keepOriginalSize
);
167 void wxCheckBox::ChangeBackgroundColour()
169 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
172 XtVaSetValues ((Widget
) m_mainWidget
,
173 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
174 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
175 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
176 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
179 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
181 // Better to have the checkbox selection in black, or it's
182 // hard to determine what state it is in.
183 XtVaSetValues ((Widget
) m_mainWidget
,
184 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
185 XmNselectColor
, selectPixel
,
189 void wxCheckBox::ChangeForegroundColour()
191 wxWindow::ChangeForegroundColour();