1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "checkbox.h"
17 #define XtDisplay XTDISPLAY
20 #include "wx/checkbox.h"
24 #pragma message disable nosimpint
27 #include <Xm/LabelG.h>
28 #include <Xm/ToggleB.h>
29 #include <Xm/ToggleBG.h>
31 #pragma message enable nosimpint
34 #include "wx/motif/private.h"
36 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
39 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
40 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
42 // Single check box item
43 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
45 const wxSize
& size
, long style
,
46 const wxValidator
& validator
,
50 SetValidator(validator
);
51 m_windowStyle
= style
;
52 m_backgroundColour
= parent
->GetBackgroundColour();
53 m_foregroundColour
= parent
->GetForegroundColour();
54 m_font
= parent
->GetFont();
56 if (parent
) parent
->AddChild(this);
59 m_windowId
= NewControlId();
63 #if 0 // gcc 2.95 doesn't like this apparently
64 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
65 XmString text
= XmStringCreateSimple (label1
);
67 wxString
label1(wxStripMenuCodes(label
));
69 wxXmString
text( label1
);
71 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
72 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
74 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
75 xmToggleButtonWidgetClass
, parentWidget
,
76 XmNfontList
, fontList
,
77 XmNlabelString
, text(),
83 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
86 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
88 SetCanAddEventHandler(TRUE
);
89 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
91 ChangeBackgroundColour();
95 void wxCheckBox::SetValue(bool val
)
98 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
102 bool wxCheckBox::GetValue() const
104 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
107 void wxCheckBox::Command (wxCommandEvent
& event
)
109 SetValue ((event
.GetInt() != 0));
110 ProcessCommand (event
);
114 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
115 const wxPoint
& WXUNUSED(pos
),
116 const wxSize
& WXUNUSED(size
), long style
,
117 const wxValidator
& validator
,
118 const wxString
& name
)
121 SetValidator(validator
);
122 m_windowStyle
= style
;
124 if (parent
) parent
->AddChild(this);
127 m_windowId
= NewControlId();
131 // TODO: Create the bitmap checkbox
136 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
141 void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(sizeFlags
))
146 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
151 bool wxBitmapCheckBox::GetValue() const
157 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
158 XtPointer
WXUNUSED(ptr
))
160 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
162 if (item
->InSetValue())
165 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
166 event
.SetInt((int) item
->GetValue ());
167 event
.SetEventObject(item
);
168 item
->ProcessCommand (event
);
171 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
173 wxWindow::ChangeFont(keepOriginalSize
);
176 void wxCheckBox::ChangeBackgroundColour()
178 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
181 XtVaSetValues ((Widget
) m_mainWidget
,
182 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
183 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
184 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
185 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
188 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
190 // Better to have the checkbox selection in black, or it's
191 // hard to determine what state it is in.
192 XtVaSetValues ((Widget
) m_mainWidget
,
193 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
194 XmNselectColor
, selectPixel
,
198 void wxCheckBox::ChangeForegroundColour()
200 wxWindow::ChangeForegroundColour();