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