]> git.saurik.com Git - wxWidgets.git/blob - src/motif/checkbox.cpp
No real changes.
[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/defs.h"
21
22 #include "wx/checkbox.h"
23 #include "wx/tglbtn.h"
24 #include "wx/utils.h"
25
26 #ifdef __VMS__
27 #pragma message disable nosimpint
28 #endif
29 #include <Xm/Label.h>
30 #include <Xm/LabelG.h>
31 #include <Xm/ToggleB.h>
32 #include <Xm/ToggleBG.h>
33 #ifdef __VMS__
34 #pragma message enable nosimpint
35 #endif
36
37 #include "wx/motif/private.h"
38
39 void wxCheckBoxCallback (Widget w, XtPointer clientData,
40 XtPointer ptr);
41
42 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
43
44 // Single check box item
45 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
46 const wxPoint& pos,
47 const wxSize& size, long style,
48 const wxValidator& validator,
49 const wxString& name)
50 {
51 if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
52 name ) )
53 return FALSE;
54
55 wxString label1(wxStripMenuCodes(label));
56 wxXmString text( label1 );
57
58 Widget parentWidget = (Widget) parent->GetClientWidget();
59
60 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
61 xmToggleButtonWidgetClass, parentWidget,
62 wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
63 XmNlabelString, text(),
64 XmNrecomputeSize, False,
65 NULL);
66
67 XtAddCallback( (Widget)m_mainWidget,
68 XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback,
69 (XtPointer)this );
70
71 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
72
73 SetCanAddEventHandler(TRUE);
74 AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
75 pos.x, pos.y, size.x, size.y );
76
77 ChangeBackgroundColour();
78 return TRUE;
79 }
80
81 void wxCheckBox::SetValue(bool val)
82 {
83 m_inSetValue = TRUE;
84 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
85 m_inSetValue = FALSE;
86 }
87
88 bool wxCheckBox::GetValue() const
89 {
90 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
91 }
92
93 void wxCheckBox::Command (wxCommandEvent & event)
94 {
95 SetValue ((event.GetInt() != 0));
96 ProcessCommand (event);
97 }
98
99 void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
100 XtPointer WXUNUSED(ptr))
101 {
102 wxCheckBox *item = (wxCheckBox *) clientData;
103
104 if (item->InSetValue())
105 return;
106
107 wxCommandEvent event (item->m_evtType, item->GetId());
108 event.SetInt((int) item->GetValue ());
109 event.SetEventObject(item);
110 item->ProcessCommand (event);
111 }
112
113 void wxCheckBox::ChangeBackgroundColour()
114 {
115 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
116 (wxColour*) NULL);
117
118 XtVaSetValues ((Widget) m_mainWidget,
119 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
120 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
121 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
122 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
123 NULL);
124
125 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
126
127 // Better to have the checkbox selection in black, or it's
128 // hard to determine what state it is in.
129 XtVaSetValues ((Widget) m_mainWidget,
130 XmNselectColor, selectPixel,
131 NULL);
132 }
133
134 ///////////////////////////////////////////////////////////////////////////////
135 // wxToggleButton
136 ///////////////////////////////////////////////////////////////////////////////
137
138 #if wxUSE_TOGGLEBTN
139
140 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
141 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
142
143 bool wxToggleButton::Create( wxWindow* parent, wxWindowID id,
144 const wxString& label,
145 const wxPoint& pos,
146 const wxSize& size,
147 long style,
148 const wxValidator& val,
149 const wxString &name )
150 {
151 if( !wxCheckBox::Create( parent, id, label, pos, size, style, val, name ) )
152 return false;
153
154 XtVaSetValues( (Widget)m_mainWidget,
155 XmNindicatorSize, 0,
156 #if XmVersion >= 2000
157 XmNindicatorOn, XmINDICATOR_NONE,
158 #else
159 XmNindicatorOn, False,
160 #endif
161 XmNfillOnSelect, False,
162 XmNshadowThickness, 2,
163 XmNalignment, XmALIGNMENT_CENTER,
164 XmNmarginLeft, 0,
165 XmNmarginRight, 0,
166 NULL );
167
168 // set it again, because the XtVaSetValue above resets it
169 if( size.x != -1 || size.y != -1 )
170 SetSize( size );
171
172 return true;
173 }
174
175 #endif // wxUSE_TOGGLEBUTTON