]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr); | |
25 | ||
4bb6408c JS |
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 | ||
42 | parent->AddChild((wxButton *)this); | |
43 | ||
44 | if (id == -1) | |
45 | m_windowId = NewControlId(); | |
46 | else | |
47 | m_windowId = id; | |
48 | ||
89c7e962 | 49 | wxString label1(wxStripMenuCodes(label)); |
4bb6408c | 50 | |
89c7e962 | 51 | XmString text = XmStringCreateSimple ((char*) (const char*) label1); |
02e8b2f9 | 52 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
4bb6408c | 53 | |
02e8b2f9 JS |
54 | /* |
55 | * Patch Note (important) | |
56 | * There is no major reason to put a defaultButtonThickness here. | |
57 | * Not requesting it give the ability to put wxButton with a spacing | |
58 | * as small as requested. However, if some button become a DefaultButton, | |
59 | * other buttons are no more aligned -- This is why we set | |
60 | * defaultButtonThickness of ALL buttons belonging to the same wxPanel, | |
61 | * in the ::SetDefaultButton method. | |
62 | */ | |
63 | m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button", | |
64 | xmPushButtonWidgetClass, | |
65 | parentWidget, | |
66 | XmNlabelString, text, | |
67 | // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault | |
68 | NULL); | |
69 | ||
70 | XmStringFree (text); | |
71 | ||
72 | XtAddCallback ((Widget) m_mainWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback, | |
73 | (XtPointer) this); | |
74 | ||
75 | ||
76 | SetCanAddEventHandler(TRUE); | |
77 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
78 | ||
79 | SetFont(* parent->GetFont()); | |
80 | ChangeColour(m_mainWidget); | |
81 | ||
82 | return TRUE; | |
4bb6408c JS |
83 | } |
84 | ||
85 | void wxButton::SetDefault() | |
86 | { | |
87 | wxWindow *parent = (wxWindow *)GetParent(); | |
88 | if (parent) | |
89 | parent->SetDefaultItem(this); | |
90 | ||
02e8b2f9 JS |
91 | // We initially do not set XmNdefaultShadowThickness, to have small buttons. |
92 | // Unfortunately, buttons are now mis-aligned. We try to correct this | |
93 | // now -- setting this ressource to 1 for each button in the same row. | |
94 | // Because it's very hard to find wxButton in the same row, | |
95 | // correction is straighforward: we set resource for all wxButton | |
96 | // in this parent (but not sub panels) | |
97 | for (wxNode * node = parent->GetChildren ()->First (); node; node = node->Next ()) | |
98 | { | |
99 | wxButton *item = (wxButton *) node->Data (); | |
100 | if (item->IsKindOf(CLASSINFO(wxButton))) | |
101 | { | |
102 | bool managed = XtIsManaged((Widget) item->GetMainWidget()); | |
103 | if (managed) | |
104 | XtUnmanageChild ((Widget) item->GetMainWidget()); | |
105 | ||
106 | XtVaSetValues ((Widget) item->GetMainWidget(), | |
107 | XmNdefaultButtonShadowThickness, 1, | |
108 | NULL); | |
109 | ||
110 | if (managed) | |
111 | XtManageChild ((Widget) item->GetMainWidget()); | |
112 | } | |
113 | } // while | |
114 | ||
115 | // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL); | |
116 | XtVaSetValues ((Widget) parent->GetMainWidget(), XmNdefaultButton, (Widget) GetMainWidget(), NULL); | |
4bb6408c JS |
117 | } |
118 | ||
119 | void wxButton::Command (wxCommandEvent & event) | |
120 | { | |
121 | ProcessCommand (event); | |
122 | } | |
123 | ||
02e8b2f9 JS |
124 | void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr) |
125 | { | |
126 | if (!wxGetWindowFromTable(w)) | |
127 | // Widget has been deleted! | |
128 | return; | |
129 | ||
130 | wxButton *item = (wxButton *) clientData; | |
131 | wxCommandEvent event (wxEVT_COMMAND_BUTTON_CLICKED, item->GetId()); | |
132 | event.SetEventObject(item); | |
133 | item->ProcessCommand (event); | |
134 | } |