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