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