]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checkbox.cpp
(very) preliminary DnD docs
[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;
0d57be45
JS
43 m_backgroundColour = parent->GetBackgroundColour();
44 m_foregroundColour = parent->GetForegroundColour();
ea57084d 45 m_windowFont = parent->GetFont();
4bb6408c
JS
46
47 if (parent) parent->AddChild(this);
48
49 if ( id == -1 )
50 m_windowId = NewControlId();
51 else
52 m_windowId = id;
53
02e8b2f9 54 char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
4bb6408c 55
02e8b2f9
JS
56 XmString text = XmStringCreateSimple (label1);
57 Widget parentWidget = (Widget) parent->GetClientWidget();
ea57084d 58 XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
4bb6408c 59
02e8b2f9
JS
60 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
61 xmToggleButtonWidgetClass, parentWidget,
ea57084d 62 XmNfontList, fontList,
02e8b2f9
JS
63 XmNlabelString, text,
64 NULL);
65 XmStringFree (text);
4bb6408c 66
02e8b2f9
JS
67 XtAddCallback ((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc) wxCheckBoxCallback,
68 (XtPointer) this);
69
70 XmToggleButtonSetState ((Widget) m_mainWidget, FALSE, TRUE);
71
72 SetCanAddEventHandler(TRUE);
73 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
74
0d57be45 75 ChangeBackgroundColour();
02e8b2f9 76 return TRUE;
4bb6408c
JS
77}
78
79void wxCheckBox::SetValue(bool val)
80{
a4294b78 81 m_inSetValue = TRUE;
02e8b2f9 82 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) val, TRUE);
a4294b78 83 m_inSetValue = FALSE;
4bb6408c
JS
84}
85
86bool wxCheckBox::GetValue() const
87{
02e8b2f9 88 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
89}
90
91void wxCheckBox::Command (wxCommandEvent & event)
92{
93 SetValue ((event.GetInt() != 0));
94 ProcessCommand (event);
95}
96
97// Bitmap checkbox
98bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
99 const wxPoint& pos,
100 const wxSize& size, long style,
101 const wxValidator& validator,
102 const wxString& name)
103{
104 SetName(name);
105 SetValidator(validator);
106 m_windowStyle = style;
107
108 if (parent) parent->AddChild(this);
109
110 if ( id == -1 )
111 m_windowId = NewControlId();
112 else
113 m_windowId = id;
114
115 // TODO: Create the bitmap checkbox
116
117 return FALSE;
118}
119
120void wxBitmapCheckBox::SetLabel(const wxBitmap *bitmap)
121{
122 // TODO
123}
124
125void wxBitmapCheckBox::SetSize(int x, int y, int width, int height, int sizeFlags)
126{
127 // TODO
128}
129
130void wxBitmapCheckBox::SetValue(bool val)
131{
132 // TODO
133}
134
135bool wxBitmapCheckBox::GetValue() const
136{
137 // TODOD
138 return FALSE;
139}
140
02e8b2f9
JS
141void wxCheckBoxCallback (Widget w, XtPointer clientData,
142 XtPointer ptr)
143{
144 wxCheckBox *item = (wxCheckBox *) clientData;
a4294b78
JS
145
146 if (item->InSetValue())
147 return;
02e8b2f9
JS
148
149 wxCommandEvent event (wxEVT_COMMAND_CHECKBOX_CLICKED, item->GetId());
150 event.SetInt((int) item->GetValue ());
151 event.SetEventObject(item);
152 item->ProcessCommand (event);
153}
0d57be45 154
4b5f3fe6 155void wxCheckBox::ChangeFont(bool keepOriginalSize)
0d57be45 156{
4b5f3fe6 157 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
158}
159
160void wxCheckBox::ChangeBackgroundColour()
161{
321db4b6
JS
162 wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
163 (wxColour*) NULL);
164
165 XtVaSetValues ((Widget) m_mainWidget,
166 XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
167 XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
168 XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
169 XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
170 NULL);
171
172 XtVaSetValues ((Widget) m_mainWidget,
173 XmNselectColor, g_itemColors[wxSELE_INDEX].pixel,
174 NULL);
0d57be45
JS
175}
176
177void wxCheckBox::ChangeForegroundColour()
178{
321db4b6 179 wxWindow::ChangeForegroundColour();
0d57be45 180}