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();
43 m_windowFont
= parent
->GetFont();
45 parent
->AddChild((wxButton
*)this);
48 m_windowId
= NewControlId();
52 wxString
label1(wxStripMenuCodes(label
));
54 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
55 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
57 XmFontList fontList
= (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(parentWidget
));
60 * Patch Note (important)
61 * There is no major reason to put a defaultButtonThickness here.
62 * Not requesting it give the ability to put wxButton with a spacing
63 * as small as requested. However, if some button become a DefaultButton,
64 * other buttons are no more aligned -- This is why we set
65 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
66 * in the ::SetDefaultButton method.
68 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("button",
69 xmPushButtonWidgetClass
,
71 XmNfontList
, fontList
,
73 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
78 XtAddCallback ((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
81 SetCanAddEventHandler(TRUE
);
82 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
84 ChangeBackgroundColour();
89 void wxButton::SetDefault()
91 wxWindow
*parent
= (wxWindow
*)GetParent();
93 parent
->SetDefaultItem(this);
95 // We initially do not set XmNdefaultShadowThickness, to have small buttons.
96 // Unfortunately, buttons are now mis-aligned. We try to correct this
97 // now -- setting this ressource to 1 for each button in the same row.
98 // Because it's very hard to find wxButton in the same row,
99 // correction is straighforward: we set resource for all wxButton
100 // in this parent (but not sub panels)
101 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
103 wxButton
*item
= (wxButton
*) node
->Data ();
104 if (item
->IsKindOf(CLASSINFO(wxButton
)))
106 bool managed
= XtIsManaged((Widget
) item
->GetMainWidget());
108 XtUnmanageChild ((Widget
) item
->GetMainWidget());
110 XtVaSetValues ((Widget
) item
->GetMainWidget(),
111 XmNdefaultButtonShadowThickness
, 1,
115 XtManageChild ((Widget
) item
->GetMainWidget());
119 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
120 XtVaSetValues ((Widget
) parent
->GetMainWidget(), XmNdefaultButton
, (Widget
) GetMainWidget(), NULL
);
123 void wxButton::Command (wxCommandEvent
& event
)
125 ProcessCommand (event
);
128 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer
WXUNUSED(ptr
))
130 if (!wxGetWindowFromTable(w
))
131 // Widget has been deleted!
134 wxButton
*item
= (wxButton
*) clientData
;
135 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
136 event
.SetEventObject(item
);
137 item
->ProcessCommand (event
);
140 void wxButton::ChangeFont(bool keepOriginalSize
)
142 wxWindow::ChangeFont(keepOriginalSize
);
145 void wxButton::ChangeBackgroundColour()
147 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
150 void wxButton::ChangeForegroundColour()
152 wxWindow::ChangeForegroundColour();