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