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