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