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"
19 #include <Xm/PushBG.h>
22 #include "wx/motif/private.h"
24 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
26 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
32 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
34 const wxSize
& size
, long style
,
35 const wxValidator
& validator
,
39 SetValidator(validator
);
40 m_windowStyle
= style
;
42 parent
->AddChild((wxButton
*)this);
45 m_windowId
= NewControlId();
49 wxString
label1(wxStripMenuCodes(label
));
51 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
52 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
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.
63 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("button",
64 xmPushButtonWidgetClass
,
67 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
72 XtAddCallback ((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
76 SetCanAddEventHandler(TRUE
);
77 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
79 SetFont(* parent
->GetFont());
80 ChangeColour(m_mainWidget
);
85 void wxButton::SetDefault()
87 wxWindow
*parent
= (wxWindow
*)GetParent();
89 parent
->SetDefaultItem(this);
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 ())
99 wxButton
*item
= (wxButton
*) node
->Data ();
100 if (item
->IsKindOf(CLASSINFO(wxButton
)))
102 bool managed
= XtIsManaged((Widget
) item
->GetMainWidget());
104 XtUnmanageChild ((Widget
) item
->GetMainWidget());
106 XtVaSetValues ((Widget
) item
->GetMainWidget(),
107 XmNdefaultButtonShadowThickness
, 1,
111 XtManageChild ((Widget
) item
->GetMainWidget());
115 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
116 XtVaSetValues ((Widget
) parent
->GetMainWidget(), XmNdefaultButton
, (Widget
) GetMainWidget(), NULL
);
119 void wxButton::Command (wxCommandEvent
& event
)
121 ProcessCommand (event
);
124 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
)
126 if (!wxGetWindowFromTable(w
))
127 // Widget has been deleted!
130 wxButton
*item
= (wxButton
*) clientData
;
131 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
132 event
.SetEventObject(item
);
133 item
->ProcessCommand (event
);