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