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