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