]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checkbox.cpp
compilation fix for Mac and reformatted the code
[wxWidgets.git] / src / motif / checkbox.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: checkbox.cpp
3// Purpose: wxCheckBox
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "checkbox.h"
14#endif
15
bcd055ae
JJ
16#ifdef __VMS
17#define XtDisplay XTDISPLAY
18#endif
19
f6045f99
GD
20#include "wx/defs.h"
21
4bb6408c 22#include "wx/checkbox.h"
08e5319b 23#include "wx/tglbtn.h"
9838df2c 24#include "wx/utils.h"
4bb6408c 25
338dd992
JJ
26#ifdef __VMS__
27#pragma message disable nosimpint
28#endif
02e8b2f9
JS
29#include <Xm/Label.h>
30#include <Xm/LabelG.h>
31#include <Xm/ToggleB.h>
32#include <Xm/ToggleBG.h>
338dd992
JJ
33#ifdef __VMS__
34#pragma message enable nosimpint
35#endif
02e8b2f9
JS
36
37#include "wx/motif/private.h"
38
39void wxCheckBoxCallback (Widget w, XtPointer clientData,
2d120f83 40 XtPointer ptr);
02e8b2f9 41
4bb6408c 42IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
4bb6408c
JS
43
44// Single check box item
45bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
2d120f83
JS
46 const wxPoint& pos,
47 const wxSize& size, long style,
48 const wxValidator& validator,
49 const wxString& name)
4bb6408c 50{
a969055e
MB
51 if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
52 name ) )
53 return FALSE;
7a4b8f27 54
a969055e 55 wxString label1(wxStripMenuCodes(label));
dc1efb1d 56 wxXmString text( label1 );
7a4b8f27 57
02e8b2f9 58 Widget parentWidget = (Widget) parent->GetClientWidget();
31528cd3 59
02e8b2f9 60 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
2d120f83 61 xmToggleButtonWidgetClass, parentWidget,
da494b40 62 wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
7a4b8f27 63 XmNlabelString, text(),
d3a80c92 64 XmNrecomputeSize, False,
2d120f83 65 NULL);
7a4b8f27 66
a969055e
MB
67 XtAddCallback( (Widget)m_mainWidget,
68 XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback,
69 (XtPointer)this );
31528cd3 70
02e8b2f9 71 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
31528cd3 72
a969055e
MB
73 AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
74 pos.x, pos.y, size.x, size.y );
31528cd3 75
0d57be45 76 ChangeBackgroundColour();
02e8b2f9 77 return TRUE;
4bb6408c
JS
78}
79
80void wxCheckBox::SetValue(bool val)
81{
a4294b78 82 m_inSetValue = TRUE;
02e8b2f9 83 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
a4294b78 84 m_inSetValue = FALSE;
4bb6408c
JS
85}
86
87bool wxCheckBox::GetValue() const
88{
02e8b2f9 89 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
90}
91
92void wxCheckBox::Command (wxCommandEvent & event)
93{
94 SetValue ((event.GetInt() != 0));
95 ProcessCommand (event);
96}
97
af111fc3
JS
98void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
99 XtPointer WXUNUSED(ptr))
02e8b2f9 100{
2d120f83 101 wxCheckBox *item = (wxCheckBox *) clientData;
31528cd3 102
2d120f83
JS
103 if (item->InSetValue())
104 return;
31528cd3 105
08e5319b 106 wxCommandEvent event (item->m_evtType, item->GetId());
2d120f83
JS
107 event.SetInt((int) item->GetValue ());
108 event.SetEventObject(item);
109 item->ProcessCommand (event);
02e8b2f9 110}
0d57be45 111
0d57be45
JS
112void wxCheckBox::ChangeBackgroundColour()
113{
2d120f83
JS
114 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
115 (wxColour*) NULL);
31528cd3 116
2d120f83
JS
117 XtVaSetValues ((Widget) m_mainWidget,
118 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
119 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
120 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
121 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
122 NULL);
31528cd3 123
eb6fa4b4 124 int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
9838df2c
JS
125
126 // Better to have the checkbox selection in black, or it's
127 // hard to determine what state it is in.
2d120f83 128 XtVaSetValues ((Widget) m_mainWidget,
9838df2c 129 XmNselectColor, selectPixel,
2d120f83 130 NULL);
0d57be45 131}
08e5319b
MB
132
133///////////////////////////////////////////////////////////////////////////////
134// wxToggleButton
135///////////////////////////////////////////////////////////////////////////////
136
137#if wxUSE_TOGGLEBTN
138
139DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
140IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
141
142bool wxToggleButton::Create( wxWindow* parent, wxWindowID id,
143 const wxString& label,
144 const wxPoint& pos,
145 const wxSize& size,
146 long style,
147 const wxValidator& val,
148 const wxString &name )
149{
150 if( !wxCheckBox::Create( parent, id, label, pos, size, style, val, name ) )
151 return false;
152
153 XtVaSetValues( (Widget)m_mainWidget,
154 XmNindicatorSize, 0,
155#if XmVersion >= 2000
156 XmNindicatorOn, XmINDICATOR_NONE,
157#else
158 XmNindicatorOn, False,
159#endif
160 XmNfillOnSelect, False,
161 XmNshadowThickness, 2,
162 XmNalignment, XmALIGNMENT_CENTER,
163 XmNmarginLeft, 0,
164 XmNmarginRight, 0,
165 NULL );
166
167 // set it again, because the XtVaSetValue above resets it
168 if( size.x != -1 || size.y != -1 )
169 SetSize( size );
170
171 return true;
172}
173
174#endif // wxUSE_TOGGLEBUTTON