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