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