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