]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checkbox.cpp
added Add/InsertTool() (patch 672032)
[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"
9838df2c 23#include "wx/utils.h"
4bb6408c 24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
02e8b2f9
JS
28#include <Xm/Label.h>
29#include <Xm/LabelG.h>
30#include <Xm/ToggleB.h>
31#include <Xm/ToggleBG.h>
338dd992
JJ
32#ifdef __VMS__
33#pragma message enable nosimpint
34#endif
02e8b2f9
JS
35
36#include "wx/motif/private.h"
37
38void wxCheckBoxCallback (Widget w, XtPointer clientData,
2d120f83 39 XtPointer ptr);
02e8b2f9 40
4bb6408c 41IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
4bb6408c
JS
42
43// Single check box item
44bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
2d120f83
JS
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 const wxValidator& validator,
48 const wxString& name)
4bb6408c 49{
a969055e
MB
50 if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
51 name ) )
52 return FALSE;
7a4b8f27 53
a969055e 54 wxString label1(wxStripMenuCodes(label));
dc1efb1d 55 wxXmString text( label1 );
7a4b8f27 56
02e8b2f9 57 Widget parentWidget = (Widget) parent->GetClientWidget();
a969055e
MB
58 XmFontList fontList =
59 (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
31528cd3 60
02e8b2f9 61 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
2d120f83
JS
62 xmToggleButtonWidgetClass, parentWidget,
63 XmNfontList, fontList,
7a4b8f27 64 XmNlabelString, text(),
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
02e8b2f9 73 SetCanAddEventHandler(TRUE);
a969055e
MB
74 AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
75 pos.x, pos.y, size.x, size.y );
31528cd3 76
0d57be45 77 ChangeBackgroundColour();
02e8b2f9 78 return TRUE;
4bb6408c
JS
79}
80
81void wxCheckBox::SetValue(bool val)
82{
a4294b78 83 m_inSetValue = TRUE;
02e8b2f9 84 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
a4294b78 85 m_inSetValue = FALSE;
4bb6408c
JS
86}
87
88bool wxCheckBox::GetValue() const
89{
02e8b2f9 90 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
91}
92
93void wxCheckBox::Command (wxCommandEvent & event)
94{
95 SetValue ((event.GetInt() != 0));
96 ProcessCommand (event);
97}
98
af111fc3
JS
99void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
100 XtPointer WXUNUSED(ptr))
02e8b2f9 101{
2d120f83 102 wxCheckBox *item = (wxCheckBox *) clientData;
31528cd3 103
2d120f83
JS
104 if (item->InSetValue())
105 return;
31528cd3 106
2d120f83
JS
107 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
108 event.SetInt((int) item->GetValue ());
109 event.SetEventObject(item);
110 item->ProcessCommand (event);
02e8b2f9 111}
0d57be45 112
0d57be45
JS
113void wxCheckBox::ChangeBackgroundColour()
114{
2d120f83
JS
115 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
116 (wxColour*) NULL);
31528cd3 117
2d120f83
JS
118 XtVaSetValues ((Widget) m_mainWidget,
119 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
120 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
121 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
122 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
123 NULL);
31528cd3 124
9838df2c
JS
125 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
126
127 // Better to have the checkbox selection in black, or it's
128 // hard to determine what state it is in.
2d120f83 129 XtVaSetValues ((Widget) m_mainWidget,
9838df2c 130 XmNselectColor, selectPixel,
2d120f83 131 NULL);
0d57be45 132}