]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checkbox.cpp
more combobox appearance fixes
[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
JS
41IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
42IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
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
JS
50{
51 SetName(name);
52 SetValidator(validator);
53 m_windowStyle = style;
0d57be45
JS
54 m_backgroundColour = parent->GetBackgroundColour();
55 m_foregroundColour = parent->GetForegroundColour();
da175b2c 56 m_font = parent->GetFont();
31528cd3 57
4bb6408c 58 if (parent) parent->AddChild(this);
31528cd3 59
4bb6408c
JS
60 if ( id == -1 )
61 m_windowId = NewControlId();
62 else
63 m_windowId = id;
31528cd3 64
7a4b8f27 65#if 0 // gcc 2.95 doesn't like this apparently
02e8b2f9 66 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
02e8b2f9 67 XmString text = XmStringCreateSimple (label1);
7a4b8f27 68#endif
dc1efb1d 69 wxString label1(wxStripMenuCodes(label));
7a4b8f27 70
dc1efb1d 71 wxXmString text( label1 );
7a4b8f27 72
02e8b2f9 73 Widget parentWidget = (Widget) parent->GetClientWidget();
da175b2c 74 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
31528cd3 75
02e8b2f9 76 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
2d120f83
JS
77 xmToggleButtonWidgetClass, parentWidget,
78 XmNfontList, fontList,
7a4b8f27 79 XmNlabelString, text(),
2d120f83 80 NULL);
7a4b8f27 81#if 0
02e8b2f9 82 XmStringFree (text);
7a4b8f27
MB
83#endif
84
02e8b2f9 85 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
2d120f83 86 (XtPointer) this);
31528cd3 87
02e8b2f9 88 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
31528cd3 89
02e8b2f9
JS
90 SetCanAddEventHandler(TRUE);
91 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
31528cd3 92
0d57be45 93 ChangeBackgroundColour();
02e8b2f9 94 return TRUE;
4bb6408c
JS
95}
96
97void wxCheckBox::SetValue(bool val)
98{
a4294b78 99 m_inSetValue = TRUE;
02e8b2f9 100 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
a4294b78 101 m_inSetValue = FALSE;
4bb6408c
JS
102}
103
104bool wxCheckBox::GetValue() const
105{
02e8b2f9 106 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
107}
108
109void wxCheckBox::Command (wxCommandEvent & event)
110{
111 SetValue ((event.GetInt() != 0));
112 ProcessCommand (event);
113}
114
115// Bitmap checkbox
af111fc3
JS
116bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *WXUNUSED(label),
117 const wxPoint& WXUNUSED(pos),
118 const wxSize& WXUNUSED(size), long style,
2d120f83
JS
119 const wxValidator& validator,
120 const wxString& name)
4bb6408c
JS
121{
122 SetName(name);
123 SetValidator(validator);
124 m_windowStyle = style;
31528cd3 125
4bb6408c 126 if (parent) parent->AddChild(this);
31528cd3 127
4bb6408c
JS
128 if ( id == -1 )
129 m_windowId = NewControlId();
130 else
131 m_windowId = id;
31528cd3 132
4bb6408c 133 // TODO: Create the bitmap checkbox
31528cd3 134
4bb6408c
JS
135 return FALSE;
136}
137
af111fc3 138void wxBitmapCheckBox::SetLabel(const wxBitmap& WXUNUSED(bitmap))
4bb6408c
JS
139{
140 // TODO
141}
142
af111fc3 143void wxBitmapCheckBox::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height), int WXUNUSED(sizeFlags))
4bb6408c
JS
144{
145 // TODO
146}
147
af111fc3 148void wxBitmapCheckBox::SetValue(bool WXUNUSED(val))
4bb6408c
JS
149{
150 // TODO
151}
152
153bool wxBitmapCheckBox::GetValue() const
154{
155 // TODOD
156 return FALSE;
157}
158
af111fc3
JS
159void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
160 XtPointer WXUNUSED(ptr))
02e8b2f9 161{
2d120f83 162 wxCheckBox *item = (wxCheckBox *) clientData;
31528cd3 163
2d120f83
JS
164 if (item->InSetValue())
165 return;
31528cd3 166
2d120f83
JS
167 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
168 event.SetInt((int) item->GetValue ());
169 event.SetEventObject(item);
170 item->ProcessCommand (event);
02e8b2f9 171}
0d57be45 172
4b5f3fe6 173void wxCheckBox::ChangeFont(bool keepOriginalSize)
0d57be45 174{
4b5f3fe6 175 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
176}
177
178void wxCheckBox::ChangeBackgroundColour()
179{
2d120f83
JS
180 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
181 (wxColour*) NULL);
31528cd3 182
2d120f83
JS
183 XtVaSetValues ((Widget) m_mainWidget,
184 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
185 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
186 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
187 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
188 NULL);
31528cd3 189
9838df2c
JS
190 int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
191
192 // Better to have the checkbox selection in black, or it's
193 // hard to determine what state it is in.
2d120f83 194 XtVaSetValues ((Widget) m_mainWidget,
9838df2c
JS
195 // XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
196 XmNselectColor, selectPixel,
2d120f83 197 NULL);
0d57be45
JS
198}
199
200void wxCheckBox::ChangeForegroundColour()
201{
321db4b6 202 wxWindow::ChangeForegroundColour();
0d57be45 203}