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
);
126 wxSize
wxButton::GetDefaultSize()
128 // TODO: check font size as in wxMSW ? MB
130 return wxSize(80,26);
133 void wxButton::Command (wxCommandEvent
& event
)
135 ProcessCommand (event
);
138 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer
WXUNUSED(ptr
))
140 if (!wxGetWindowFromTable(w
))
141 // Widget has been deleted!
144 wxButton
*item
= (wxButton
*) clientData
;
145 wxCommandEvent
event (wxEVT_COMMAND_BUTTON_CLICKED
, item
->GetId());
146 event
.SetEventObject(item
);
147 item
->ProcessCommand (event
);
150 void wxButton::ChangeFont(bool keepOriginalSize
)
152 wxWindow::ChangeFont(keepOriginalSize
);
155 void wxButton::ChangeBackgroundColour()
157 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
160 void wxButton::ChangeForegroundColour()
162 wxWindow::ChangeForegroundColour();