]> git.saurik.com Git - wxWidgets.git/blame - src/motif/radiobut.cpp
renamed scrolwin file - no other way to make wxGTK/Univ compile
[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
a4294b78 90 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
d7dcb939 91 (XtPointer) this);
31528cd3 92
a4294b78 93 m_mainWidget = (WXWidget) radioButtonWidget;
31528cd3 94
a4294b78 95 XtManageChild (radioButtonWidget);
31528cd3 96
a4294b78 97 SetCanAddEventHandler(TRUE);
b412f9be 98 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 99
0d57be45 100 ChangeBackgroundColour();
31528cd3 101
a4294b78 102 return TRUE;
4bb6408c
JS
103}
104
105void wxRadioButton::SetValue(bool value)
106{
a4294b78
JS
107 m_inSetValue = TRUE;
108 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE);
109 m_inSetValue = FALSE;
4bb6408c
JS
110}
111
112// Get single selection, for single choice list items
113bool wxRadioButton::GetValue() const
114{
a4294b78 115 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
116}
117
118void wxRadioButton::Command (wxCommandEvent & event)
119{
2d120f83
JS
120 SetValue ( (event.m_commandInt != 0) );
121 ProcessCommand (event);
4bb6408c
JS
122}
123
4b5f3fe6 124void wxRadioButton::ChangeFont(bool keepOriginalSize)
0d57be45 125{
4b5f3fe6 126 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
127}
128
129void wxRadioButton::ChangeBackgroundColour()
130{
321db4b6 131 wxWindow::ChangeBackgroundColour();
9838df2c
JS
132
133 // What colour should this be?
134 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
135
136 XtVaSetValues ((Widget) GetMainWidget(),
137 XmNselectColor, selectPixel,
138 NULL);
0d57be45
JS
139}
140
141void wxRadioButton::ChangeForegroundColour()
142{
321db4b6 143 wxWindow::ChangeForegroundColour();
0d57be45
JS
144}
145
a4294b78 146void wxRadioButtonCallback (Widget w, XtPointer clientData,
2d120f83 147 XmToggleButtonCallbackStruct * cbs)
a4294b78 148{
2d120f83
JS
149 if (!cbs->set)
150 return;
31528cd3 151
2d120f83
JS
152 wxRadioButton *item = (wxRadioButton *) clientData;
153 if (item->InSetValue())
154 return;
31528cd3 155
2d120f83
JS
156 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
157 event.SetEventObject(item);
31528cd3 158
2d120f83 159 item->ProcessCommand (event);
a4294b78 160}
4bb6408c 161