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 #pragma message disable nosimpint
23 #include <Xm/LabelG.h>
24 #include <Xm/ToggleB.h>
25 #include <Xm/ToggleBG.h>
27 #pragma message enable nosimpint
30 #include "wx/motif/private.h"
32 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
35 #if !USE_SHARED_LIBRARY
36 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
37 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
40 // Single check box item
41 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
43 const wxSize
& size
, long style
,
44 const wxValidator
& validator
,
48 SetValidator(validator
);
49 m_windowStyle
= style
;
50 m_backgroundColour
= parent
->GetBackgroundColour();
51 m_foregroundColour
= parent
->GetForegroundColour();
52 m_font
= parent
->GetFont();
54 if (parent
) parent
->AddChild(this);
57 m_windowId
= NewControlId();
61 #if 0 // gcc 2.95 doesn't like this apparently
62 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
63 XmString text
= XmStringCreateSimple (label1
);
66 wxXmString
text( label
);
68 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
69 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
71 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
72 xmToggleButtonWidgetClass
, parentWidget
,
73 XmNfontList
, fontList
,
74 XmNlabelString
, text(),
80 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
83 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
85 SetCanAddEventHandler(TRUE
);
86 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
88 ChangeBackgroundColour();
92 void wxCheckBox::SetValue(bool val
)
95 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
99 bool wxCheckBox::GetValue() const
101 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
104 void wxCheckBox::Command (wxCommandEvent
& event
)
106 SetValue ((event
.GetInt() != 0));
107 ProcessCommand (event
);
111 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
112 const wxPoint
& WXUNUSED(pos
),
113 const wxSize
& WXUNUSED(size
), long style
,
114 const wxValidator
& validator
,
115 const wxString
& name
)
118 SetValidator(validator
);
119 m_windowStyle
= style
;
121 if (parent
) parent
->AddChild(this);
124 m_windowId
= NewControlId();
128 // TODO: Create the bitmap checkbox
133 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
138 void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(sizeFlags
))
143 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
148 bool wxBitmapCheckBox::GetValue() const
154 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
155 XtPointer
WXUNUSED(ptr
))
157 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
159 if (item
->InSetValue())
162 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
163 event
.SetInt((int) item
->GetValue ());
164 event
.SetEventObject(item
);
165 item
->ProcessCommand (event
);
168 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
170 wxWindow::ChangeFont(keepOriginalSize
);
173 void wxCheckBox::ChangeBackgroundColour()
175 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
178 XtVaSetValues ((Widget
) m_mainWidget
,
179 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
180 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
181 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
182 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
185 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
187 // Better to have the checkbox selection in black, or it's
188 // hard to determine what state it is in.
189 XtVaSetValues ((Widget
) m_mainWidget
,
190 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
191 XmNselectColor
, selectPixel
,
195 void wxCheckBox::ChangeForegroundColour()
197 wxWindow::ChangeForegroundColour();