]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checkbox.cpp
More Motif additions: mdi and sashtest samples now just about work!
[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"
17
02e8b2f9
JS
18#include <Xm/Label.h>
19#include <Xm/LabelG.h>
20#include <Xm/ToggleB.h>
21#include <Xm/ToggleBG.h>
22
23#include "wx/motif/private.h"
24
25void wxCheckBoxCallback (Widget w, XtPointer clientData,
26 XtPointer ptr);
27
4bb6408c
JS
28#if !USE_SHARED_LIBRARY
29IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
30IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
31#endif
32
33// Single check box item
34bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
35 const wxPoint& pos,
36 const wxSize& size, long style,
37 const wxValidator& validator,
38 const wxString& name)
39{
40 SetName(name);
41 SetValidator(validator);
42 m_windowStyle = style;
43
44 if (parent) parent->AddChild(this);
45
46 if ( id == -1 )
47 m_windowId = NewControlId();
48 else
49 m_windowId = id;
50
02e8b2f9 51 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
4bb6408c 52
02e8b2f9
JS
53 XmString text = XmStringCreateSimple (label1);
54 Widget parentWidget = (Widget) parent->GetClientWidget();
4bb6408c 55
02e8b2f9
JS
56 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
57 xmToggleButtonWidgetClass, parentWidget,
58 XmNlabelString, text,
59 NULL);
60 XmStringFree (text);
4bb6408c 61
02e8b2f9
JS
62 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
63 (XtPointer) this);
64
65 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
66
67 SetCanAddEventHandler(TRUE);
68 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
69
70 ChangeColour(m_mainWidget);
71 SetFont(* parent->GetFont());
72
73 return TRUE;
4bb6408c
JS
74}
75
76void wxCheckBox::SetValue(bool val)
77{
a4294b78 78 m_inSetValue = TRUE;
02e8b2f9 79 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
a4294b78 80 m_inSetValue = FALSE;
4bb6408c
JS
81}
82
83bool wxCheckBox::GetValue() const
84{
02e8b2f9 85 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
86}
87
88void wxCheckBox::Command (wxCommandEvent & event)
89{
90 SetValue ((event.GetInt() != 0));
91 ProcessCommand (event);
92}
93
94// Bitmap checkbox
95bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
96 const wxPoint& pos,
97 const wxSize& size, long style,
98 const wxValidator& validator,
99 const wxString& name)
100{
101 SetName(name);
102 SetValidator(validator);
103 m_windowStyle = style;
104
105 if (parent) parent->AddChild(this);
106
107 if ( id == -1 )
108 m_windowId = NewControlId();
109 else
110 m_windowId = id;
111
112 // TODO: Create the bitmap checkbox
113
114 return FALSE;
115}
116
117void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
118{
119 // TODO
120}
121
122void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
123{
124 // TODO
125}
126
127void wxBitmapCheckBox::SetValue(bool val)
128{
129 // TODO
130}
131
132bool wxBitmapCheckBox::GetValue() const
133{
134 // TODOD
135 return FALSE;
136}
137
02e8b2f9
JS
138void wxCheckBoxCallback (Widget w, XtPointer clientData,
139 XtPointer ptr)
140{
141 wxCheckBox *item = (wxCheckBox *) clientData;
a4294b78
JS
142
143 if (item->InSetValue())
144 return;
02e8b2f9
JS
145
146 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
147 event.SetInt((int) item->GetValue ());
148 event.SetEventObject(item);
149 item->ProcessCommand (event);
150}