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
;
41 m_backgroundColour
= parent
->GetBackgroundColour();
42 m_foregroundColour
= parent
->GetForegroundColour();
44 parent
->AddChild((wxButton
*)this);
47 m_windowId
= NewControlId();
51 wxString
label1(wxStripMenuCodes(label
));
53 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
54 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
57 * Patch Note (important)
58 * There is no major reason to put a defaultButtonThickness here.
59 * Not requesting it give the ability to put wxButton with a spacing
60 * as small as requested. However, if some button become a DefaultButton,
61 * other buttons are no more aligned -- This is why we set
62 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
63 * in the ::SetDefaultButton method.
65 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("button",
66 xmPushButtonWidgetClass
,
69 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
74 XtAddCallback ((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
78 SetCanAddEventHandler(TRUE
);
79 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
81 SetFont(* parent
->GetFont());
82 ChangeBackgroundColour();
87 void wxButton::SetDefault()
89 wxWindow
*parent
= (wxWindow
*)GetParent();
91 parent
->SetDefaultItem(this);
93 // We initially do not set XmNdefaultShadowThickness, to have small buttons.
94 // Unfortunately, buttons are now mis-aligned. We try to correct this
95 // now -- setting this ressource to 1 for each button in the same row.
96 // Because it's very hard to find wxButton in the same row,
97 // correction is straighforward: we set resource for all wxButton
98 // in this parent (but not sub panels)
99 for (wxNode
* node
= parent
->GetChildren ()->First (); node
; node
= node
->Next ())
101 wxButton
*item
= (wxButton
*) node
->Data ();
102 if (item
->IsKindOf(CLASSINFO(wxButton
)))
104 bool managed
= XtIsManaged((Widget
) item
->GetMainWidget());
106 XtUnmanageChild ((Widget
) item
->GetMainWidget());
108 XtVaSetValues ((Widget
) item
->GetMainWidget(),
109 XmNdefaultButtonShadowThickness
, 1,
113 XtManageChild ((Widget
) item
->GetMainWidget());
117 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
118 XtVaSetValues ((Widget
) parent
->GetMainWidget(), XmNdefaultButton
, (Widget
) GetMainWidget(), NULL
);
121 void wxButton::Command (wxCommandEvent
& event
)
123 ProcessCommand (event
);
126 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
)
128 if (!wxGetWindowFromTable(w
))
129 // Widget has been deleted!
132 wxButton
*item
= (wxButton
*) clientData
;
133 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
134 event
.SetEventObject(item
);
135 item
->ProcessCommand (event
);
138 void wxButton::ChangeFont()
143 void wxButton::ChangeBackgroundColour()
148 void wxButton::ChangeForegroundColour()