]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: radiobut.cpp | |
3 | // Purpose: wxRadioButton | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "radiobut.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/radiobut.h" | |
a4294b78 JS |
17 | #include "wx/utils.h" |
18 | ||
338dd992 JJ |
19 | #ifdef __VMS__ |
20 | #pragma message disable nosimpint | |
21 | #endif | |
a4294b78 JS |
22 | #include <Xm/Label.h> |
23 | #include <Xm/LabelG.h> | |
24 | #include <Xm/ToggleB.h> | |
25 | #include <Xm/ToggleBG.h> | |
26 | #include <Xm/RowColumn.h> | |
27 | #include <Xm/Form.h> | |
338dd992 JJ |
28 | #ifdef __VMS__ |
29 | #pragma message enable nosimpint | |
30 | #endif | |
a4294b78 | 31 | |
3096bd2f | 32 | #include "wx/motif/private.h" |
a4294b78 JS |
33 | |
34 | void wxRadioButtonCallback (Widget w, XtPointer clientData, | |
2d120f83 | 35 | XmToggleButtonCallbackStruct * cbs); |
4bb6408c JS |
36 | |
37 | #if !USE_SHARED_LIBRARY | |
38 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) | |
39 | #endif | |
40 | ||
a4294b78 JS |
41 | wxRadioButton::wxRadioButton() |
42 | { | |
a4294b78 JS |
43 | } |
44 | ||
4bb6408c | 45 | bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, |
2d120f83 JS |
46 | const wxString& label, |
47 | const wxPoint& pos, | |
48 | const wxSize& size, long style, | |
49 | const wxValidator& validator, | |
50 | const wxString& name) | |
4bb6408c JS |
51 | { |
52 | SetName(name); | |
53 | SetValidator(validator); | |
0d57be45 JS |
54 | m_backgroundColour = parent->GetBackgroundColour(); |
55 | m_foregroundColour = parent->GetForegroundColour(); | |
da175b2c | 56 | m_font = parent->GetFont(); |
31528cd3 | 57 | |
4bb6408c | 58 | if (parent) parent->AddChild(this); |
31528cd3 | 59 | |
4bb6408c | 60 | if ( id == -1 ) |
2d120f83 | 61 | m_windowId = (int)NewControlId(); |
4bb6408c | 62 | else |
2d120f83 | 63 | m_windowId = id; |
31528cd3 | 64 | |
4bb6408c | 65 | m_windowStyle = style ; |
31528cd3 | 66 | |
a4294b78 | 67 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
31528cd3 | 68 | |
a4294b78 | 69 | wxString label1(wxStripMenuCodes(label)); |
31528cd3 | 70 | |
a4294b78 | 71 | XmString text = XmStringCreateSimple ((char*) (const char*) label1); |
31528cd3 | 72 | |
da175b2c | 73 | XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); |
31528cd3 | 74 | |
a4294b78 JS |
75 | Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle", |
76 | #if wxUSE_GADGETS | |
2d120f83 | 77 | xmToggleButtonGadgetClass, parentWidget, |
a4294b78 | 78 | #else |
2d120f83 | 79 | xmToggleButtonWidgetClass, parentWidget, |
a4294b78 | 80 | #endif |
2d120f83 JS |
81 | XmNfontList, fontList, |
82 | XmNlabelString, text, | |
83 | XmNfillOnSelect, True, | |
84 | XmNindicatorType, XmONE_OF_MANY, // diamond-shape | |
85 | NULL); | |
321db4b6 | 86 | XmStringFree (text); |
31528cd3 | 87 | |
338dd992 JJ |
88 | #ifdef __VMS__ |
89 | #pragma message disable voiincconext | |
90 | // VMS gives here the compiler warning: | |
91 | // conversion from pointer to function to void* permitted | |
92 | // as an extension | |
93 | #endif | |
a4294b78 | 94 | XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback, |
2d120f83 | 95 | (XtCallbackProc) this); |
338dd992 JJ |
96 | #ifdef __VMS__ |
97 | #pragma message enable voiincconext | |
98 | #endif | |
31528cd3 | 99 | |
a4294b78 | 100 | m_mainWidget = (WXWidget) radioButtonWidget; |
31528cd3 | 101 | |
a4294b78 | 102 | XtManageChild (radioButtonWidget); |
31528cd3 | 103 | |
a4294b78 | 104 | SetCanAddEventHandler(TRUE); |
b412f9be | 105 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); |
31528cd3 | 106 | |
0d57be45 | 107 | ChangeBackgroundColour(); |
31528cd3 | 108 | |
a4294b78 | 109 | return TRUE; |
4bb6408c JS |
110 | } |
111 | ||
112 | void wxRadioButton::SetValue(bool value) | |
113 | { | |
a4294b78 JS |
114 | m_inSetValue = TRUE; |
115 | XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE); | |
116 | m_inSetValue = FALSE; | |
4bb6408c JS |
117 | } |
118 | ||
119 | // Get single selection, for single choice list items | |
120 | bool wxRadioButton::GetValue() const | |
121 | { | |
a4294b78 | 122 | return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); |
4bb6408c JS |
123 | } |
124 | ||
125 | void wxRadioButton::Command (wxCommandEvent & event) | |
126 | { | |
2d120f83 JS |
127 | SetValue ( (event.m_commandInt != 0) ); |
128 | ProcessCommand (event); | |
4bb6408c JS |
129 | } |
130 | ||
4b5f3fe6 | 131 | void wxRadioButton::ChangeFont(bool keepOriginalSize) |
0d57be45 | 132 | { |
4b5f3fe6 | 133 | wxWindow::ChangeFont(keepOriginalSize); |
0d57be45 JS |
134 | } |
135 | ||
136 | void wxRadioButton::ChangeBackgroundColour() | |
137 | { | |
321db4b6 | 138 | wxWindow::ChangeBackgroundColour(); |
9838df2c JS |
139 | |
140 | // What colour should this be? | |
141 | int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); | |
142 | ||
143 | XtVaSetValues ((Widget) GetMainWidget(), | |
144 | XmNselectColor, selectPixel, | |
145 | NULL); | |
0d57be45 JS |
146 | } |
147 | ||
148 | void wxRadioButton::ChangeForegroundColour() | |
149 | { | |
321db4b6 | 150 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
151 | } |
152 | ||
a4294b78 | 153 | void wxRadioButtonCallback (Widget w, XtPointer clientData, |
2d120f83 | 154 | XmToggleButtonCallbackStruct * cbs) |
a4294b78 | 155 | { |
2d120f83 JS |
156 | if (!cbs->set) |
157 | return; | |
31528cd3 | 158 | |
2d120f83 JS |
159 | wxRadioButton *item = (wxRadioButton *) clientData; |
160 | if (item->InSetValue()) | |
161 | return; | |
31528cd3 | 162 | |
2d120f83 JS |
163 | wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId()); |
164 | event.SetEventObject(item); | |
31528cd3 | 165 | |
2d120f83 | 166 | item->ProcessCommand (event); |
a4294b78 | 167 | } |
4bb6408c | 168 |