]> git.saurik.com Git - wxWidgets.git/blob - src/motif/radiobut.cpp
The new SORT parameter for SelectViewType() and SelectDocumentType() sorted the displ...
[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 #ifdef __VMS__
91 #pragma message disable voiincconext
92 // VMS gives here the compiler warning:
93 // conversion from pointer to function to void* permitted
94 // as an extension
95 #endif
96 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
97 (XtCallbackProc) this);
98 #ifdef __VMS__
99 #pragma message enable voiincconext
100 #endif
101
102 m_mainWidget = (WXWidget) radioButtonWidget;
103
104 XtManageChild (radioButtonWidget);
105
106 SetCanAddEventHandler(TRUE);
107 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
108
109 ChangeBackgroundColour();
110
111 return TRUE;
112 }
113
114 void wxRadioButton::SetValue(bool value)
115 {
116 m_inSetValue = TRUE;
117 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE);
118 m_inSetValue = FALSE;
119 }
120
121 // Get single selection, for single choice list items
122 bool wxRadioButton::GetValue() const
123 {
124 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
125 }
126
127 void wxRadioButton::Command (wxCommandEvent & event)
128 {
129 SetValue ( (event.m_commandInt != 0) );
130 ProcessCommand (event);
131 }
132
133 void wxRadioButton::ChangeFont(bool keepOriginalSize)
134 {
135 wxWindow::ChangeFont(keepOriginalSize);
136 }
137
138 void wxRadioButton::ChangeBackgroundColour()
139 {
140 wxWindow::ChangeBackgroundColour();
141
142 // What colour should this be?
143 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
144
145 XtVaSetValues ((Widget) GetMainWidget(),
146 XmNselectColor, selectPixel,
147 NULL);
148 }
149
150 void wxRadioButton::ChangeForegroundColour()
151 {
152 wxWindow::ChangeForegroundColour();
153 }
154
155 void wxRadioButtonCallback (Widget w, XtPointer clientData,
156 XmToggleButtonCallbackStruct * cbs)
157 {
158 if (!cbs->set)
159 return;
160
161 wxRadioButton *item = (wxRadioButton *) clientData;
162 if (item->InSetValue())
163 return;
164
165 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
166 event.SetEventObject(item);
167
168 item->ProcessCommand (event);
169 }
170