]> git.saurik.com Git - wxWidgets.git/blame - src/motif/radiobut.cpp
Added a check for -lresolv in configure.in
[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();
da175b2c 50 m_font = parent->GetFont();
31528cd3 51
4bb6408c 52 if (parent) parent->AddChild(this);
31528cd3 53
4bb6408c 54 if ( id == -1 )
2d120f83 55 m_windowId = (int)NewControlId();
4bb6408c 56 else
2d120f83 57 m_windowId = id;
31528cd3 58
4bb6408c 59 m_windowStyle = style ;
31528cd3 60
a4294b78 61 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 62
a4294b78 63 wxString label1(wxStripMenuCodes(label));
31528cd3 64
a4294b78 65 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
31528cd3 66
da175b2c 67 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
31528cd3 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);
31528cd3 81
a4294b78 82 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
2d120f83 83 (XtCallbackProc) this);
31528cd3 84
a4294b78 85 m_mainWidget = (WXWidget) radioButtonWidget;
31528cd3 86
a4294b78 87 XtManageChild (radioButtonWidget);
31528cd3 88
a4294b78 89 SetCanAddEventHandler(TRUE);
b412f9be 90 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 91
0d57be45 92 ChangeBackgroundColour();
31528cd3 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;
31528cd3 143
2d120f83
JS
144 wxRadioButton *item = (wxRadioButton *) clientData;
145 if (item->InSetValue())
146 return;
31528cd3 147
2d120f83
JS
148 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
149 event.SetEventObject(item);
31528cd3 150
2d120f83 151 item->ProcessCommand (event);
a4294b78 152}
4bb6408c 153