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"
20 #include <Xm/PushBG.h>
23 #include "wx/motif/private.h"
25 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_DYNAMIC_CLASS(wxButton
, wxControl
)
33 bool wxButton::Create(wxWindow
*parent
, wxWindowID id
, const wxString
& label
,
35 const wxSize
& size
, long style
,
36 const wxValidator
& validator
,
40 SetValidator(validator
);
41 m_windowStyle
= style
;
42 m_backgroundColour
= parent
->GetBackgroundColour();
43 m_foregroundColour
= parent
->GetForegroundColour();
44 m_font
= parent
->GetFont();
46 parent
->AddChild((wxButton
*)this);
49 m_windowId
= NewControlId();
53 wxString
label1(wxStripMenuCodes(label
));
55 XmString text
= XmStringCreateSimple ((char*) (const char*) label1
);
56 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
58 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(parentWidget
));
61 * Patch Note (important)
62 * There is no major reason to put a defaultButtonThickness here.
63 * Not requesting it give the ability to put wxButton with a spacing
64 * as small as requested. However, if some button become a DefaultButton,
65 * other buttons are no more aligned -- This is why we set
66 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
67 * in the ::SetDefaultButton method.
69 m_mainWidget
= (WXWidget
) XtVaCreateManagedWidget ("button",
70 xmPushButtonWidgetClass
,
72 XmNfontList
, fontList
,
74 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
79 XtAddCallback ((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
82 SetCanAddEventHandler(TRUE
);
83 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
85 ChangeBackgroundColour();
90 void wxButton::SetDefault()
92 wxWindow
*parent
= GetParent();
93 wxPanel
*panel
= wxDynamicCast(panel
, wxPanel
);
95 panel
->SetDefaultItem(this);
97 // We initially do not set XmNdefaultShadowThickness, to have small buttons.
98 // Unfortunately, buttons are now mis-aligned. We try to correct this
99 // now -- setting this ressource to 1 for each button in the same row.
100 // Because it's very hard to find wxButton in the same row,
101 // correction is straighforward: we set resource for all wxButton
102 // in this parent (but not sub panels)
103 for (wxNode
* node
= parent
->GetChildren().First (); node
; node
= node
->Next ())
105 wxButton
*item
= (wxButton
*) node
->Data ();
106 if (item
->IsKindOf(CLASSINFO(wxButton
)))
108 bool managed
= XtIsManaged((Widget
) item
->GetMainWidget());
110 XtUnmanageChild ((Widget
) item
->GetMainWidget());
112 XtVaSetValues ((Widget
) item
->GetMainWidget(),
113 XmNdefaultButtonShadowThickness
, 1,
117 XtManageChild ((Widget
) item
->GetMainWidget());
121 // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL);
122 XtVaSetValues ((Widget
) parent
->GetMainWidget(), XmNdefaultButton
, (Widget
) GetMainWidget(), NULL
);
125 void wxButton::Command (wxCommandEvent
& event
)
127 ProcessCommand (event
);
130 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer
WXUNUSED(ptr
))
132 if (!wxGetWindowFromTable(w
))
133 // Widget has been deleted!
136 wxButton
*item
= (wxButton
*) clientData
;
137 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
138 event
.SetEventObject(item
);
139 item
->ProcessCommand (event
);
142 void wxButton::ChangeFont(bool keepOriginalSize
)
144 wxWindow::ChangeFont(keepOriginalSize
);
147 void wxButton::ChangeBackgroundColour()
149 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
152 void wxButton::ChangeForegroundColour()
154 wxWindow::ChangeForegroundColour();