]>
Commit | Line | Data |
---|---|---|
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" | |
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 | ||
28 | void wxRadioButtonCallback (Widget w, XtPointer clientData, | |
29 | XmToggleButtonCallbackStruct * cbs); | |
30 | ||
31 | #if !USE_SHARED_LIBRARY | |
32 | IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl) | |
33 | #endif | |
34 | ||
35 | wxRadioButton::wxRadioButton() | |
36 | { | |
37 | } | |
38 | ||
39 | bool 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); | |
48 | m_backgroundColour = parent->GetBackgroundColour(); | |
49 | m_foregroundColour = parent->GetForegroundColour(); | |
50 | m_font = parent->GetFont(); | |
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 | ||
61 | Widget parentWidget = (Widget) parent->GetClientWidget(); | |
62 | ||
63 | wxString label1(wxStripMenuCodes(label)); | |
64 | ||
65 | XmString text = XmStringCreateSimple ((char*) (const char*) label1); | |
66 | ||
67 | XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); | |
68 | ||
69 | Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle", | |
70 | #if wxUSE_GADGETS | |
71 | xmToggleButtonGadgetClass, parentWidget, | |
72 | #else | |
73 | xmToggleButtonWidgetClass, parentWidget, | |
74 | #endif | |
75 | XmNfontList, fontList, | |
76 | XmNlabelString, text, | |
77 | XmNfillOnSelect, True, | |
78 | XmNindicatorType, XmONE_OF_MANY, // diamond-shape | |
79 | NULL); | |
80 | XmStringFree (text); | |
81 | ||
82 | XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback, | |
83 | (XtCallbackProc) this); | |
84 | ||
85 | m_mainWidget = (WXWidget) radioButtonWidget; | |
86 | ||
87 | XtManageChild (radioButtonWidget); | |
88 | ||
89 | SetCanAddEventHandler(TRUE); | |
90 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
91 | ||
92 | ChangeBackgroundColour(); | |
93 | ||
94 | return TRUE; | |
95 | } | |
96 | ||
97 | void wxRadioButton::SetValue(bool value) | |
98 | { | |
99 | m_inSetValue = TRUE; | |
100 | XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, FALSE); | |
101 | m_inSetValue = FALSE; | |
102 | } | |
103 | ||
104 | // Get single selection, for single choice list items | |
105 | bool wxRadioButton::GetValue() const | |
106 | { | |
107 | return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0); | |
108 | } | |
109 | ||
110 | void wxRadioButton::Command (wxCommandEvent & event) | |
111 | { | |
112 | SetValue ( (event.m_commandInt != 0) ); | |
113 | ProcessCommand (event); | |
114 | } | |
115 | ||
116 | void wxRadioButton::ChangeFont(bool keepOriginalSize) | |
117 | { | |
118 | wxWindow::ChangeFont(keepOriginalSize); | |
119 | } | |
120 | ||
121 | void wxRadioButton::ChangeBackgroundColour() | |
122 | { | |
123 | wxWindow::ChangeBackgroundColour(); | |
124 | ||
125 | // What colour should this be? | |
126 | int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); | |
127 | ||
128 | XtVaSetValues ((Widget) GetMainWidget(), | |
129 | XmNselectColor, selectPixel, | |
130 | NULL); | |
131 | } | |
132 | ||
133 | void wxRadioButton::ChangeForegroundColour() | |
134 | { | |
135 | wxWindow::ChangeForegroundColour(); | |
136 | } | |
137 | ||
138 | void wxRadioButtonCallback (Widget w, XtPointer clientData, | |
139 | XmToggleButtonCallbackStruct * cbs) | |
140 | { | |
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); | |
152 | } | |
153 |