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