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