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