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