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