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"
19 #include <Xm/LabelG.h>
20 #include <Xm/ToggleB.h>
21 #include <Xm/ToggleBG.h>
23 #include "wx/motif/private.h"
25 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox
, wxControl
)
30 IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox
, wxCheckBox
)
33 // Single check box item
34 bool wxCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
36 const wxSize
& size
, long style
,
37 const wxValidator
& validator
,
41 SetValidator(validator
);
42 m_windowStyle
= style
;
43 m_backgroundColour
= parent
->GetBackgroundColour();
44 m_foregroundColour
= parent
->GetForegroundColour();
45 m_windowFont
= parent
->GetFont();
47 if (parent
) parent
->AddChild(this);
50 m_windowId
= NewControlId();
54 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
56 XmString text
= XmStringCreateSimple (label1
);
57 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
58 XmFontList fontList
= (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(parentWidget
));
60 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("toggle",
61 xmToggleButtonWidgetClass
, parentWidget
,
62 XmNfontList
, fontList
,
67 XtAddCallback ((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
) wxCheckBoxCallback
,
70 XmToggleButtonSetState ((Widget
) m_mainWidget
, FALSE
, TRUE
);
72 SetCanAddEventHandler(TRUE
);
73 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
75 ChangeBackgroundColour();
79 void wxCheckBox::SetValue(bool val
)
82 XmToggleButtonSetState ((Widget
) m_mainWidget
, (Boolean
) val
, TRUE
);
86 bool wxCheckBox::GetValue() const
88 return (XmToggleButtonGetState ((Widget
) m_mainWidget
) != 0);
91 void wxCheckBox::Command (wxCommandEvent
& event
)
93 SetValue ((event
.GetInt() != 0));
94 ProcessCommand (event
);
98 bool wxBitmapCheckBox::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
*label
,
100 const wxSize
& size
, long style
,
101 const wxValidator
& validator
,
102 const wxString
& name
)
105 SetValidator(validator
);
106 m_windowStyle
= style
;
108 if (parent
) parent
->AddChild(this);
111 m_windowId
= NewControlId();
115 // TODO: Create the bitmap checkbox
120 void wxBitmapCheckBox::SetLabel(const wxBitmap
*bitmap
)
125 void wxBitmapCheckBox::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
130 void wxBitmapCheckBox::SetValue(bool val
)
135 bool wxBitmapCheckBox::GetValue() const
141 void wxCheckBoxCallback (Widget w
, XtPointer clientData
,
144 wxCheckBox
*item
= (wxCheckBox
*) clientData
;
146 if (item
->InSetValue())
149 wxCommandEvent
event (wxEVT_COMMAND_CHECKBOX_CLICKED
, item
->GetId());
150 event
.SetInt((int) item
->GetValue ());
151 event
.SetEventObject(item
);
152 item
->ProcessCommand (event
);
155 void wxCheckBox::ChangeFont(bool keepOriginalSize
)
157 wxWindow::ChangeFont(keepOriginalSize
);
160 void wxCheckBox::ChangeBackgroundColour()
162 wxComputeColours (XtDisplay((Widget
) m_mainWidget
), & m_backgroundColour
,
165 XtVaSetValues ((Widget
) m_mainWidget
,
166 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
167 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
168 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
169 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
172 XtVaSetValues ((Widget
) m_mainWidget
,
173 XmNselectColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
177 void wxCheckBox::ChangeForegroundColour()
179 wxWindow::ChangeForegroundColour();