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