]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4bb6408c JS |
13 | #pragma implementation "checkbox.h" |
14 | #endif | |
15 | ||
1248b41f MB |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
bcd055ae JJ |
19 | #ifdef __VMS |
20 | #define XtDisplay XTDISPLAY | |
21 | #endif | |
22 | ||
f6045f99 GD |
23 | #include "wx/defs.h" |
24 | ||
4bb6408c | 25 | #include "wx/checkbox.h" |
08e5319b | 26 | #include "wx/tglbtn.h" |
9838df2c | 27 | #include "wx/utils.h" |
4bb6408c | 28 | |
338dd992 JJ |
29 | #ifdef __VMS__ |
30 | #pragma message disable nosimpint | |
31 | #endif | |
02e8b2f9 JS |
32 | #include <Xm/Label.h> |
33 | #include <Xm/LabelG.h> | |
34 | #include <Xm/ToggleB.h> | |
35 | #include <Xm/ToggleBG.h> | |
338dd992 JJ |
36 | #ifdef __VMS__ |
37 | #pragma message enable nosimpint | |
38 | #endif | |
02e8b2f9 JS |
39 | |
40 | #include "wx/motif/private.h" | |
41 | ||
42 | void wxCheckBoxCallback (Widget w, XtPointer clientData, | |
2d120f83 | 43 | XtPointer ptr); |
02e8b2f9 | 44 | |
4bb6408c | 45 | IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl) |
4bb6408c JS |
46 | |
47 | // Single check box item | |
48 | bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, | |
2d120f83 JS |
49 | const wxPoint& pos, |
50 | const wxSize& size, long style, | |
51 | const wxValidator& validator, | |
52 | const wxString& name) | |
4bb6408c | 53 | { |
a969055e MB |
54 | if( !wxControl::CreateControl( parent, id, pos, size, style, validator, |
55 | name ) ) | |
56 | return FALSE; | |
7a4b8f27 | 57 | |
a969055e | 58 | wxString label1(wxStripMenuCodes(label)); |
dc1efb1d | 59 | wxXmString text( label1 ); |
7a4b8f27 | 60 | |
02e8b2f9 | 61 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
31528cd3 | 62 | |
02e8b2f9 | 63 | m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle", |
2d120f83 | 64 | xmToggleButtonWidgetClass, parentWidget, |
da494b40 | 65 | wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), |
7a4b8f27 | 66 | XmNlabelString, text(), |
d3a80c92 | 67 | XmNrecomputeSize, False, |
2d120f83 | 68 | NULL); |
7a4b8f27 | 69 | |
a969055e MB |
70 | XtAddCallback( (Widget)m_mainWidget, |
71 | XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback, | |
72 | (XtPointer)this ); | |
31528cd3 | 73 | |
02e8b2f9 | 74 | XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE); |
31528cd3 | 75 | |
a969055e MB |
76 | AttachWidget( parent, m_mainWidget, (WXWidget)NULL, |
77 | pos.x, pos.y, size.x, size.y ); | |
31528cd3 | 78 | |
0d57be45 | 79 | ChangeBackgroundColour(); |
02e8b2f9 | 80 | return TRUE; |
4bb6408c JS |
81 | } |
82 | ||
83 | void wxCheckBox::SetValue(bool val) | |
84 | { | |
a4294b78 | 85 | m_inSetValue = TRUE; |
02e8b2f9 | 86 | XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE); |
a4294b78 | 87 | m_inSetValue = FALSE; |
4bb6408c JS |
88 | } |
89 | ||
90 | bool wxCheckBox::GetValue() const | |
91 | { | |
02e8b2f9 | 92 | return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); |
4bb6408c JS |
93 | } |
94 | ||
95 | void wxCheckBox::Command (wxCommandEvent & event) | |
96 | { | |
97 | SetValue ((event.GetInt() != 0)); | |
98 | ProcessCommand (event); | |
99 | } | |
100 | ||
af111fc3 JS |
101 | void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData, |
102 | XtPointer WXUNUSED(ptr)) | |
02e8b2f9 | 103 | { |
2d120f83 | 104 | wxCheckBox *item = (wxCheckBox *) clientData; |
31528cd3 | 105 | |
2d120f83 JS |
106 | if (item->InSetValue()) |
107 | return; | |
31528cd3 | 108 | |
08e5319b | 109 | wxCommandEvent event (item->m_evtType, item->GetId()); |
2d120f83 JS |
110 | event.SetInt((int) item->GetValue ()); |
111 | event.SetEventObject(item); | |
112 | item->ProcessCommand (event); | |
02e8b2f9 | 113 | } |
0d57be45 | 114 | |
0d57be45 JS |
115 | void wxCheckBox::ChangeBackgroundColour() |
116 | { | |
2d120f83 JS |
117 | wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour, |
118 | (wxColour*) NULL); | |
31528cd3 | 119 | |
2d120f83 JS |
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); | |
31528cd3 | 126 | |
eb6fa4b4 | 127 | int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget)); |
9838df2c JS |
128 | |
129 | // Better to have the checkbox selection in black, or it's | |
130 | // hard to determine what state it is in. | |
2d120f83 | 131 | XtVaSetValues ((Widget) m_mainWidget, |
9838df2c | 132 | XmNselectColor, selectPixel, |
2d120f83 | 133 | NULL); |
0d57be45 | 134 | } |
08e5319b MB |
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 |