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