]> git.saurik.com Git - wxWidgets.git/blob - src/motif/button.cpp
TVS_CHECKBOXES doesn't seem to exist in Borland C++
[wxWidgets.git] / src / motif / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "button.h"
14 #endif
15
16 #include "wx/button.h"
17 #include "wx/utils.h"
18 #include "wx/panel.h"
19
20 #include <Xm/PushBG.h>
21 #include <Xm/PushB.h>
22
23 #include "wx/motif/private.h"
24
25 void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr);
26
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
29 #endif
30
31 // Button
32
33 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
34 const wxPoint& pos,
35 const wxSize& size, long style,
36 const wxValidator& validator,
37 const wxString& name)
38 {
39 SetName(name);
40 SetValidator(validator);
41 m_windowStyle = style;
42 m_backgroundColour = parent->GetBackgroundColour();
43 m_foregroundColour = parent->GetForegroundColour();
44 m_font = parent->GetFont();
45
46 parent->AddChild((wxButton *)this);
47
48 if (id == -1)
49 m_windowId = NewControlId();
50 else
51 m_windowId = id;
52
53 wxString label1(wxStripMenuCodes(label));
54
55 XmString text = XmStringCreateSimple ((char*) (const char*) label1);
56 Widget parentWidget = (Widget) parent->GetClientWidget();
57
58 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
59
60 /*
61 * Patch Note (important)
62 * There is no major reason to put a defaultButtonThickness here.
63 * Not requesting it give the ability to put wxButton with a spacing
64 * as small as requested. However, if some button become a DefaultButton,
65 * other buttons are no more aligned -- This is why we set
66 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
67 * in the ::SetDefaultButton method.
68 */
69 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button",
70 xmPushButtonWidgetClass,
71 parentWidget,
72 XmNfontList, fontList,
73 XmNlabelString, text,
74 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
75 NULL);
76
77 XmStringFree (text);
78
79 XtAddCallback ((Widget) m_mainWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback,
80 (XtPointer) this);
81
82 SetCanAddEventHandler(TRUE);
83 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
84
85 ChangeBackgroundColour();
86
87 return TRUE;
88 }
89
90 void wxButton::SetDefault()
91 {
92 wxWindow *parent = GetParent();
93 wxPanel *panel = wxDynamicCast(panel, wxPanel);
94 if ( panel )
95 panel->SetDefaultItem(this);
96
97 // We initially do not set XmNdefaultShadowThickness, to have small buttons.
98 // Unfortunately, buttons are now mis-aligned. We try to correct this
99 // now -- setting this ressource to 1 for each button in the same row.
100 // Because it's very hard to find wxButton in the same row,
101 // correction is straighforward: we set resource for all wxButton
102 // in this parent (but not sub panels)
103 for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ())
104 {
105 wxButton *item = (wxButton *) node->Data ();
106 if (item->IsKindOf(CLASSINFO(wxButton)))
107 {
108 bool managed = XtIsManaged((Widget) item->GetMainWidget());
109 if (managed)
110 XtUnmanageChild ((Widget) item->GetMainWidget());
111
112 XtVaSetValues ((Widget) item->GetMainWidget(),
113 XmNdefaultButtonShadowThickness, 1,
114 NULL);
115
116 if (managed)
117 XtManageChild ((Widget) item->GetMainWidget());
118 }
119 } // while
120
121 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
122 XtVaSetValues ((Widget) parent->GetMainWidget(), XmNdefaultButton, (Widget) GetMainWidget(), NULL);
123 }
124
125 /* static */
126 wxSize wxButton::GetDefaultSize()
127 {
128 // TODO: check font size as in wxMSW ? MB
129 //
130 return wxSize(80,26);
131 }
132
133 void wxButton::Command (wxCommandEvent & event)
134 {
135 ProcessCommand (event);
136 }
137
138 void wxButtonCallback (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr))
139 {
140 if (!wxGetWindowFromTable(w))
141 // Widget has been deleted!
142 return;
143
144 wxButton *item = (wxButton *) clientData;
145 wxCommandEvent event (wxEVT_COMMAND_BUTTON_CLICKED, item->GetId());
146 event.SetEventObject(item);
147 item->ProcessCommand (event);
148 }
149
150 void wxButton::ChangeFont(bool keepOriginalSize)
151 {
152 wxWindow::ChangeFont(keepOriginalSize);
153 }
154
155 void wxButton::ChangeBackgroundColour()
156 {
157 DoChangeBackgroundColour(m_mainWidget, m_backgroundColour, TRUE);
158 }
159
160 void wxButton::ChangeForegroundColour()
161 {
162 wxWindow::ChangeForegroundColour();
163 }
164