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
)
42 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
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
,
52 SetValidator(validator
);
53 m_windowStyle
= style
;
54 m_backgroundColour
= parent
->GetBackgroundColour();
55 m_foregroundColour
= parent
->GetForegroundColour();
56 m_font
= parent
->GetFont();
58 if (parent
) parent
->AddChild(this);
61 m_windowId
= NewControlId();
65 #if 0 // gcc 2.95 doesn't like this apparently
66 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
67 XmString text
= XmStringCreateSimple (label1
);
69 wxString
label1(wxStripMenuCodes(label
));
71 wxXmString
text( label1
);
73 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
74 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
76 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
77 xmToggleButtonWidgetClass
, parentWidget
,
78 XmNfontList
, fontList
,
79 XmNlabelString
, text(),
85 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
88 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
90 SetCanAddEventHandler(TRUE
);
91 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
93 ChangeBackgroundColour();
97 void wxCheckBox::SetValue(bool val
)
100 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
101 m_inSetValue
= FALSE
;
104 bool wxCheckBox::GetValue() const
106 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
109 void wxCheckBox::Command (wxCommandEvent
& event
)
111 SetValue ((event
.GetInt() != 0));
112 ProcessCommand (event
);
116 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
117 const wxPoint
& WXUNUSED(pos
),
118 const wxSize
& WXUNUSED(size
), long style
,
119 const wxValidator
& validator
,
120 const wxString
& name
)
123 SetValidator(validator
);
124 m_windowStyle
= style
;
126 if (parent
) parent
->AddChild(this);
129 m_windowId
= NewControlId();
133 // TODO: Create the bitmap checkbox
138 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
143 void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(sizeFlags
))
148 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
153 bool wxBitmapCheckBox::GetValue() const
159 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
160 XtPointer
WXUNUSED(ptr
))
162 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
164 if (item
->InSetValue())
167 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
168 event
.SetInt((int) item
->GetValue ());
169 event
.SetEventObject(item
);
170 item
->ProcessCommand (event
);
173 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
175 wxWindow::ChangeFont(keepOriginalSize
);
178 void wxCheckBox::ChangeBackgroundColour()
180 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
183 XtVaSetValues ((Widget
) m_mainWidget
,
184 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
185 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
186 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
187 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
190 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
192 // Better to have the checkbox selection in black, or it's
193 // hard to determine what state it is in.
194 XtVaSetValues ((Widget
) m_mainWidget
,
195 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
196 XmNselectColor
, selectPixel
,
200 void wxCheckBox::ChangeForegroundColour()
202 wxWindow::ChangeForegroundColour();