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