1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "button.h"
16 #include "wx/button.h"
18 #include <Xm/PushBG.h>
21 #include "wx/motif/private.h"
23 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
25 #if !USE_SHARED_LIBRARY
26 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
31 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
33 const wxSize
& size
, long style
,
34 const wxValidator
& validator
,
38 SetValidator(validator
);
39 m_windowStyle
= style
;
41 parent
->AddChild((wxButton
*)this);
44 m_windowId
= NewControlId();
48 char* label1
= (label
.IsNull() ? "" : (char*) (const char*) label
);
50 XmString text
= XmStringCreateSimple (label1
);
51 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
54 * Patch Note (important)
55 * There is no major reason to put a defaultButtonThickness here.
56 * Not requesting it give the ability to put wxButton with a spacing
57 * as small as requested. However, if some button become a DefaultButton,
58 * other buttons are no more aligned -- This is why we set
59 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
60 * in the ::SetDefaultButton method.
62 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("button",
63 xmPushButtonWidgetClass
,
66 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
71 XtAddCallback ((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
75 SetCanAddEventHandler(TRUE
);
76 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
78 SetFont(* parent
->GetFont());
79 ChangeColour(m_mainWidget
);
84 void wxButton::SetDefault()
86 wxWindow
*parent
= (wxWindow
*)GetParent();
88 parent
->SetDefaultItem(this);
90 // We initially do not set XmNdefaultShadowThickness, to have small buttons.
91 // Unfortunately, buttons are now mis-aligned. We try to correct this
92 // now -- setting this ressource to 1 for each button in the same row.
93 // Because it's very hard to find wxButton in the same row,
94 // correction is straighforward: we set resource for all wxButton
95 // in this parent (but not sub panels)
96 for (wxNode
* node
= parent
->GetChildren ()->First (); node
; node
= node
->Next ())
98 wxButton
*item
= (wxButton
*) node
->Data ();
99 if (item
->IsKindOf(CLASSINFO(wxButton
)))
101 bool managed
= XtIsManaged((Widget
) item
->GetMainWidget());
103 XtUnmanageChild ((Widget
) item
->GetMainWidget());
105 XtVaSetValues ((Widget
) item
->GetMainWidget(),
106 XmNdefaultButtonShadowThickness
, 1,
110 XtManageChild ((Widget
) item
->GetMainWidget());
114 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
115 XtVaSetValues ((Widget
) parent
->GetMainWidget(), XmNdefaultButton
, (Widget
) GetMainWidget(), NULL
);
118 void wxButton::Command (wxCommandEvent
& event
)
120 ProcessCommand (event
);
123 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
)
125 if (!wxGetWindowFromTable(w
))
126 // Widget has been deleted!
129 wxButton
*item
= (wxButton
*) clientData
;
130 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
131 event
.SetEventObject(item
);
132 item
->ProcessCommand (event
);