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