]> git.saurik.com Git - wxWidgets.git/blob - src/motif/checkbox.cpp
Unicode compilation fixes after wxFFile change
[wxWidgets.git] / src / motif / checkbox.cpp
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
16 #ifdef __VMS
17 #define XtDisplay XTDISPLAY
18 #endif
19
20 #include "wx/defs.h"
21
22 #include "wx/checkbox.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 #ifdef __VMS__
33 #pragma message enable nosimpint
34 #endif
35
36 #include "wx/motif/private.h"
37
38 void wxCheckBoxCallback (Widget w, XtPointer clientData,
39 XtPointer ptr);
40
41 IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
42
43 // Single check box item
44 bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
45 const wxPoint& pos,
46 const wxSize& size, long style,
47 const wxValidator& validator,
48 const wxString& name)
49 {
50 if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
51 name ) )
52 return FALSE;
53
54 wxString label1(wxStripMenuCodes(label));
55 wxXmString text( label1 );
56
57 Widget parentWidget = (Widget) parent->GetClientWidget();
58 XmFontList fontList =
59 (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
60
61 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
62 xmToggleButtonWidgetClass, parentWidget,
63 XmNfontList, fontList,
64 XmNlabelString, text(),
65 NULL);
66
67 XtAddCallback( (Widget)m_mainWidget,
68 XmNvalueChangedCallback, (XtCallbackProc)wxCheckBoxCallback,
69 (XtPointer)this );
70
71 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
72
73 SetCanAddEventHandler(TRUE);
74 AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
75 pos.x, pos.y, size.x, size.y );
76
77 ChangeBackgroundColour();
78 return TRUE;
79 }
80
81 void wxCheckBox::SetValue(bool val)
82 {
83 m_inSetValue = TRUE;
84 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
85 m_inSetValue = FALSE;
86 }
87
88 bool wxCheckBox::GetValue() const
89 {
90 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
91 }
92
93 void wxCheckBox::Command (wxCommandEvent & event)
94 {
95 SetValue ((event.GetInt() != 0));
96 ProcessCommand (event);
97 }
98
99 void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
100 XtPointer WXUNUSED(ptr))
101 {
102 wxCheckBox *item = (wxCheckBox *) clientData;
103
104 if (item->InSetValue())
105 return;
106
107 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
108 event.SetInt((int) item->GetValue ());
109 event.SetEventObject(item);
110 item->ProcessCommand (event);
111 }
112
113 void wxCheckBox::ChangeBackgroundColour()
114 {
115 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
116 (wxColour*) NULL);
117
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);
124
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.
129 XtVaSetValues ((Widget) m_mainWidget,
130 XmNselectColor, selectPixel,
131 NULL);
132 }