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
);
63 wxString
label1(wxStripMenuCodes(label
));
65 wxXmString
text( label1
);
67 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
68 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
70 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
71 xmToggleButtonWidgetClass
, parentWidget
,
72 XmNfontList
, fontList
,
73 XmNlabelString
, text(),
79 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
82 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
84 SetCanAddEventHandler(TRUE
);
85 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
87 ChangeBackgroundColour();
91 void wxCheckBox::SetValue(bool val
)
94 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
98 bool wxCheckBox::GetValue() const
100 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
103 void wxCheckBox::Command (wxCommandEvent
& event
)
105 SetValue ((event
.GetInt() != 0));
106 ProcessCommand (event
);
110 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*WXUNUSED(label
),
111 const wxPoint
& WXUNUSED(pos
),
112 const wxSize
& WXUNUSED(size
), long style
,
113 const wxValidator
& validator
,
114 const wxString
& name
)
117 SetValidator(validator
);
118 m_windowStyle
= style
;
120 if (parent
) parent
->AddChild(this);
123 m_windowId
= NewControlId();
127 // TODO: Create the bitmap checkbox
132 void wxBitmapCheckBox::SetLabel(const wxBitmap
& WXUNUSED(bitmap
))
137 void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
), int WXUNUSED(sizeFlags
))
142 void wxBitmapCheckBox::SetValue(bool WXUNUSED(val
))
147 bool wxBitmapCheckBox::GetValue() const
153 void wxCheckBoxCallback (Widget
WXUNUSED(w
), XtPointer clientData
,
154 XtPointer
WXUNUSED(ptr
))
156 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
158 if (item
->InSetValue())
161 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
162 event
.SetInt((int) item
->GetValue ());
163 event
.SetEventObject(item
);
164 item
->ProcessCommand (event
);
167 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
169 wxWindow::ChangeFont(keepOriginalSize
);
172 void wxCheckBox::ChangeBackgroundColour()
174 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
177 XtVaSetValues ((Widget
) m_mainWidget
,
178 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
179 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
180 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
181 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
184 int selectPixel
= wxBLACK
->AllocColour(wxGetDisplay());
186 // Better to have the checkbox selection in black, or it's
187 // hard to determine what state it is in.
188 XtVaSetValues ((Widget
) m_mainWidget
,
189 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
190 XmNselectColor
, selectPixel
,
194 void wxCheckBox::ChangeForegroundColour()
196 wxWindow::ChangeForegroundColour();