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