]> git.saurik.com Git - wxWidgets.git/blob - src/motif/radiobut.cpp
Committing in .
[wxWidgets.git] / src / motif / radiobut.cpp
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"
17 #include "wx/utils.h"
18
19 #ifdef __VMS__
20 #pragma message disable nosimpint
21 #endif
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>
28 #ifdef __VMS__
29 #pragma message enable nosimpint
30 #endif
31
32 #include "wx/motif/private.h"
33
34 void wxRadioButtonCallback (Widget w, XtPointer clientData,
35 XmToggleButtonCallbackStruct * cbs);
36
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
39 #endif
40
41 wxRadioButton::wxRadioButton()
42 {
43 }
44
45 bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
46 const wxString& label,
47 const wxPoint& pos,
48 const wxSize& size, long style,
49 const wxValidator& validator,
50 const wxString& name)
51 {
52 SetName(name);
53 SetValidator(validator);
54 m_backgroundColour = parent->GetBackgroundColour();
55 m_foregroundColour = parent->GetForegroundColour();
56 m_font = parent->GetFont();
57
58 if (parent) parent->AddChild(this);
59
60 if ( id == -1 )
61 m_windowId = (int)NewControlId();
62 else
63 m_windowId = id;
64
65 m_windowStyle = style ;
66
67 Widget parentWidget = (Widget) parent->GetClientWidget();
68
69 wxString label1(wxStripMenuCodes(label));
70
71 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
72
73 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
74
75 Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
76 #if wxUSE_GADGETS
77 xmToggleButtonGadgetClass, parentWidget,
78 #else
79 xmToggleButtonWidgetClass, parentWidget,
80 #endif
81 XmNfontList, fontList,
82 XmNlabelString, text,
83 XmNfillOnSelect, True,
84 XmNindicatorType, XmONE_OF_MANY, // diamond-shape
85 NULL);
86 XmStringFree (text);
87
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
94 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
95 (XtCallbackProc) this);
96 #ifdef __VMS__
97 #pragma message enable voiincconext
98 #endif
99
100 m_mainWidget = (WXWidget) radioButtonWidget;
101
102 XtManageChild (radioButtonWidget);
103
104 SetCanAddEventHandler(TRUE);
105 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
106
107 ChangeBackgroundColour();
108
109 return TRUE;
110 }
111
112 void wxRadioButton::SetValue(bool value)
113 {
114 m_inSetValue = TRUE;
115 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE);
116 m_inSetValue = FALSE;
117 }
118
119 // Get single selection, for single choice list items
120 bool wxRadioButton::GetValue() const
121 {
122 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
123 }
124
125 void wxRadioButton::Command (wxCommandEvent & event)
126 {
127 SetValue ( (event.m_commandInt != 0) );
128 ProcessCommand (event);
129 }
130
131 void wxRadioButton::ChangeFont(bool keepOriginalSize)
132 {
133 wxWindow::ChangeFont(keepOriginalSize);
134 }
135
136 void wxRadioButton::ChangeBackgroundColour()
137 {
138 wxWindow::ChangeBackgroundColour();
139
140 // What colour should this be?
141 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
142
143 XtVaSetValues ((Widget) GetMainWidget(),
144 XmNselectColor, selectPixel,
145 NULL);
146 }
147
148 void wxRadioButton::ChangeForegroundColour()
149 {
150 wxWindow::ChangeForegroundColour();
151 }
152
153 void wxRadioButtonCallback (Widget w, XtPointer clientData,
154 XmToggleButtonCallbackStruct * cbs)
155 {
156 if (!cbs->set)
157 return;
158
159 wxRadioButton *item = (wxRadioButton *) clientData;
160 if (item->InSetValue())
161 return;
162
163 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
164 event.SetEventObject(item);
165
166 item->ProcessCommand (event);
167 }
168