]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: checkbox.cpp | |
3 | // Purpose: wxCheckBox | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "checkbox.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/checkbox.h" | |
9838df2c | 17 | #include "wx/utils.h" |
4bb6408c | 18 | |
02e8b2f9 JS |
19 | #include <Xm/Label.h> |
20 | #include <Xm/LabelG.h> | |
21 | #include <Xm/ToggleB.h> | |
22 | #include <Xm/ToggleBG.h> | |
23 | ||
24 | #include "wx/motif/private.h" | |
25 | ||
26 | void wxCheckBoxCallback (Widget w, XtPointer clientData, | |
2d120f83 | 27 | XtPointer ptr); |
02e8b2f9 | 28 | |
4bb6408c JS |
29 | #if !USE_SHARED_LIBRARY |
30 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) | |
31 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox) | |
32 | #endif | |
33 | ||
34 | // Single check box item | |
35 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
2d120f83 JS |
36 | const wxPoint& pos, |
37 | const wxSize& size, long style, | |
38 | const wxValidator& validator, | |
39 | const wxString& name) | |
4bb6408c JS |
40 | { |
41 | SetName(name); | |
42 | SetValidator(validator); | |
43 | m_windowStyle = style; | |
0d57be45 JS |
44 | m_backgroundColour = parent->GetBackgroundColour(); |
45 | m_foregroundColour = parent->GetForegroundColour(); | |
da175b2c | 46 | m_font = parent->GetFont(); |
31528cd3 | 47 | |
4bb6408c | 48 | if (parent) parent->AddChild(this); |
31528cd3 | 49 | |
4bb6408c JS |
50 | if ( id == -1 ) |
51 | m_windowId = NewControlId(); | |
52 | else | |
53 | m_windowId = id; | |
31528cd3 | 54 | |
7a4b8f27 | 55 | #if 0 // gcc 2.95 doesn't like this apparently |
02e8b2f9 | 56 | char* label1 = (label.IsNull() ? "" : (char*) (const char*) label); |
02e8b2f9 | 57 | XmString text = XmStringCreateSimple (label1); |
7a4b8f27 MB |
58 | #endif |
59 | ||
60 | wxXmString text( label ); | |
61 | ||
02e8b2f9 | 62 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
da175b2c | 63 | XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); |
31528cd3 | 64 | |
02e8b2f9 | 65 | m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle", |
2d120f83 JS |
66 | xmToggleButtonWidgetClass, parentWidget, |
67 | XmNfontList, fontList, | |
7a4b8f27 | 68 | XmNlabelString, text(), |
2d120f83 | 69 | NULL); |
7a4b8f27 | 70 | #if 0 |
02e8b2f9 | 71 | XmStringFree (text); |
7a4b8f27 MB |
72 | #endif |
73 | ||
02e8b2f9 | 74 | XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback, |
2d120f83 | 75 | (XtPointer) this); |
31528cd3 | 76 | |
02e8b2f9 | 77 | XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE); |
31528cd3 | 78 | |
02e8b2f9 JS |
79 | SetCanAddEventHandler(TRUE); |
80 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
31528cd3 | 81 | |
0d57be45 | 82 | ChangeBackgroundColour(); |
02e8b2f9 | 83 | return TRUE; |
4bb6408c JS |
84 | } |
85 | ||
86 | void wxCheckBox::SetValue(bool val) | |
87 | { | |
a4294b78 | 88 | m_inSetValue = TRUE; |
02e8b2f9 | 89 | XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE); |
a4294b78 | 90 | m_inSetValue = FALSE; |
4bb6408c JS |
91 | } |
92 | ||
93 | bool wxCheckBox::GetValue() const | |
94 | { | |
02e8b2f9 | 95 | return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); |
4bb6408c JS |
96 | } |
97 | ||
98 | void wxCheckBox::Command (wxCommandEvent & event) | |
99 | { | |
100 | SetValue ((event.GetInt() != 0)); | |
101 | ProcessCommand (event); | |
102 | } | |
103 | ||
104 | // Bitmap checkbox | |
105 | bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label, | |
2d120f83 JS |
106 | const wxPoint& pos, |
107 | const wxSize& size, long style, | |
108 | const wxValidator& validator, | |
109 | const wxString& name) | |
4bb6408c JS |
110 | { |
111 | SetName(name); | |
112 | SetValidator(validator); | |
113 | m_windowStyle = style; | |
31528cd3 | 114 | |
4bb6408c | 115 | if (parent) parent->AddChild(this); |
31528cd3 | 116 | |
4bb6408c JS |
117 | if ( id == -1 ) |
118 | m_windowId = NewControlId(); | |
119 | else | |
120 | m_windowId = id; | |
31528cd3 | 121 | |
4bb6408c | 122 | // TODO: Create the bitmap checkbox |
31528cd3 | 123 | |
4bb6408c JS |
124 | return FALSE; |
125 | } | |
126 | ||
acbd13a3 | 127 | void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap) |
4bb6408c JS |
128 | { |
129 | // TODO | |
130 | } | |
131 | ||
bfc6fde4 | 132 | void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
4bb6408c JS |
133 | { |
134 | // TODO | |
135 | } | |
136 | ||
137 | void wxBitmapCheckBox::SetValue(bool val) | |
138 | { | |
139 | // TODO | |
140 | } | |
141 | ||
142 | bool wxBitmapCheckBox::GetValue() const | |
143 | { | |
144 | // TODOD | |
145 | return FALSE; | |
146 | } | |
147 | ||
02e8b2f9 | 148 | void wxCheckBoxCallback (Widget w, XtPointer clientData, |
2d120f83 | 149 | XtPointer ptr) |
02e8b2f9 | 150 | { |
2d120f83 | 151 | wxCheckBox *item = (wxCheckBox *) clientData; |
31528cd3 | 152 | |
2d120f83 JS |
153 | if (item->InSetValue()) |
154 | return; | |
31528cd3 | 155 | |
2d120f83 JS |
156 | wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId()); |
157 | event.SetInt((int) item->GetValue ()); | |
158 | event.SetEventObject(item); | |
159 | item->ProcessCommand (event); | |
02e8b2f9 | 160 | } |
0d57be45 | 161 | |
4b5f3fe6 | 162 | void wxCheckBox::ChangeFont(bool keepOriginalSize) |
0d57be45 | 163 | { |
4b5f3fe6 | 164 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
165 | } |
166 | ||
167 | void wxCheckBox::ChangeBackgroundColour() | |
168 | { | |
2d120f83 JS |
169 | wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour, |
170 | (wxColour*) NULL); | |
31528cd3 | 171 | |
2d120f83 JS |
172 | XtVaSetValues ((Widget) m_mainWidget, |
173 | XmNbackground, g_itemColors[wxBACK_INDEX].pixel, | |
174 | XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel, | |
175 | XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel, | |
176 | XmNforeground, g_itemColors[wxFORE_INDEX].pixel, | |
177 | NULL); | |
31528cd3 | 178 | |
9838df2c JS |
179 | int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); |
180 | ||
181 | // Better to have the checkbox selection in black, or it's | |
182 | // hard to determine what state it is in. | |
2d120f83 | 183 | XtVaSetValues ((Widget) m_mainWidget, |
9838df2c JS |
184 | // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel, |
185 | XmNselectColor, selectPixel, | |
2d120f83 | 186 | NULL); |
0d57be45 JS |
187 | } |
188 | ||
189 | void wxCheckBox::ChangeForegroundColour() | |
190 | { | |
321db4b6 | 191 | wxWindow::ChangeForegroundColour(); |
0d57be45 | 192 | } |