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