]> git.saurik.com Git - wxWidgets.git/blame - src/motif/radiobut.cpp
drawing optimization fix
[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,
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
JS
39bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
40 const wxString& label,
41 const wxPoint& pos,
42 const wxSize& size, long style,
43 const wxValidator& validator,
44 const wxString& name)
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();
4bb6408c
JS
51
52 if (parent) parent->AddChild(this);
53
54 if ( id == -1 )
55 m_windowId = (int)NewControlId();
56 else
57 m_windowId = id;
58
59 m_windowStyle = style ;
60
a4294b78 61 Widget parentWidget = (Widget) parent->GetClientWidget();
4bb6408c 62
a4294b78
JS
63 wxString label1(wxStripMenuCodes(label));
64
65 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
66
ea57084d 67 XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
a4294b78
JS
68
69 Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
70#if wxUSE_GADGETS
321db4b6 71 xmToggleButtonGadgetClass, parentWidget,
a4294b78 72#else
321db4b6 73 xmToggleButtonWidgetClass, parentWidget,
a4294b78 74#endif
ea57084d 75 XmNfontList, fontList,
321db4b6
JS
76 XmNlabelString, text,
77 XmNfillOnSelect, True,
78 XmNindicatorType, XmONE_OF_MANY, // diamond-shape
a4294b78 79 NULL);
321db4b6
JS
80 XmStringFree (text);
81
a4294b78
JS
82 XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
83 (XtCallbackProc) this);
84
85 m_mainWidget = (WXWidget) radioButtonWidget;
86
a4294b78
JS
87 XtManageChild (radioButtonWidget);
88
89 SetCanAddEventHandler(TRUE);
321db4b6 90 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
a4294b78 91
0d57be45 92 ChangeBackgroundColour();
a4294b78
JS
93
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{
112 SetValue ( (event.m_commandInt != 0) );
113 ProcessCommand (event);
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();
0d57be45
JS
124}
125
126void wxRadioButton::ChangeForegroundColour()
127{
321db4b6 128 wxWindow::ChangeForegroundColour();
0d57be45
JS
129}
130
a4294b78
JS
131void wxRadioButtonCallback (Widget w, XtPointer clientData,
132 XmToggleButtonCallbackStruct * cbs)
133{
134 if (!cbs->set)
135 return;
136
137 wxRadioButton *item = (wxRadioButton *) clientData;
138 if (item->InSetValue())
139 return;
140
141 wxCommandEvent event (wxEVT_COMMAND_RADIOBUTTON_SELECTED, item->GetId());
142 event.SetEventObject(item);
143
144 item->ProcessCommand (event);
145}
4bb6408c 146