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 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
36 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
38 // Single check box item
39 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
41 const wxSize
& size
, long style
,
42 const wxValidator
& validator
,
46 SetValidator(validator
);
47 m_windowStyle
= style
;
48 m_backgroundColour
= parent
->GetBackgroundColour();
49 m_foregroundColour
= parent
->GetForegroundColour();
50 m_font
= parent
->GetFont();
52 if (parent
) parent
->AddChild(this);
55 m_windowId
= NewControlId();
59 #if 0 // gcc 2.95 doesn't like this apparently
60 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
61 XmString text
= XmStringCreateSimple (label1
);
64 wxXmString
text( label
);
66 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
67 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
69 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
70 xmToggleButtonWidgetClass
, parentWidget
,
71 XmNfontList
, fontList
,
72 XmNlabelString
, text(),
78 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
81 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
83 SetCanAddEventHandler(TRUE
);
84 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
86 ChangeBackgroundColour();
90 void wxCheckBox::SetValue(bool val
)
93 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
97 bool wxCheckBox::GetValue() const
99 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
102 void wxCheckBox::Command (wxCommandEvent
& event
)
104 SetValue ((event
.GetInt() != 0));
105 ProcessCommand (event
);
109 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
110 const wxPoint
& WXUNUSED(pos
),
111 const wxSize
& WXUNUSED(size
), long style
,
112 const wxValidator
& validator
,
113 const wxString
& name
)
116 SetValidator(validator
);
117 m_windowStyle
= style
;
119 if (parent
) parent
->AddChild(this);
122 m_windowId
= NewControlId();
126 // TODO: Create the bitmap checkbox
131 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
136 void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(sizeFlags
))
141 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
146 bool wxBitmapCheckBox::GetValue() const
152 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
153 XtPointer
WXUNUSED(ptr
))
155 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
157 if (item
->InSetValue())
160 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
161 event
.SetInt((int) item
->GetValue ());
162 event
.SetEventObject(item
);
163 item
->ProcessCommand (event
);
166 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
168 wxWindow::ChangeFont(keepOriginalSize
);
171 void wxCheckBox::ChangeBackgroundColour()
173 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
176 XtVaSetValues ((Widget
) m_mainWidget
,
177 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
178 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
179 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
180 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
183 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
185 // Better to have the checkbox selection in black, or it's
186 // hard to determine what state it is in.
187 XtVaSetValues ((Widget
) m_mainWidget
,
188 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
189 XmNselectColor
, selectPixel
,
193 void wxCheckBox::ChangeForegroundColour()
195 wxWindow::ChangeForegroundColour();