X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/321db4b6bf15df209942b9c0e6c744c8e7074d1b..a3e7d24d21f5371c88caffe4a85c8e4a5362db3f:/src/motif/button.cpp?ds=sidebyside diff --git a/src/motif/button.cpp b/src/motif/button.cpp index 6a402a0229..610a94ef19 100644 --- a/src/motif/button.cpp +++ b/src/motif/button.cpp @@ -6,7 +6,7 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -15,6 +15,7 @@ #include "wx/button.h" #include "wx/utils.h" +#include "wx/panel.h" #include #include @@ -30,16 +31,17 @@ IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) // Button bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, - const wxPoint& pos, - const wxSize& size, long style, - const wxValidator& validator, - const wxString& name) + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) { SetName(name); SetValidator(validator); m_windowStyle = style; m_backgroundColour = parent->GetBackgroundColour(); m_foregroundColour = parent->GetForegroundColour(); + m_font = parent->GetFont(); parent->AddChild((wxButton *)this); @@ -53,32 +55,43 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, XmString text = XmStringCreateSimple ((char*) (const char*) label1); Widget parentWidget = (Widget) parent->GetClientWidget(); + XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); + /* - * Patch Note (important) - * There is no major reason to put a defaultButtonThickness here. - * Not requesting it give the ability to put wxButton with a spacing - * as small as requested. However, if some button become a DefaultButton, - * other buttons are no more aligned -- This is why we set - * defaultButtonThickness of ALL buttons belonging to the same wxPanel, - * in the ::SetDefaultButton method. - */ + * Patch Note (important) + * There is no major reason to put a defaultButtonThickness here. + * Not requesting it give the ability to put wxButton with a spacing + * as small as requested. However, if some button become a DefaultButton, + * other buttons are no more aligned -- This is why we set + * defaultButtonThickness of ALL buttons belonging to the same wxPanel, + * in the ::SetDefaultButton method. + */ m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button", - xmPushButtonWidgetClass, - parentWidget, - XmNlabelString, text, -// XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault - NULL); + xmPushButtonWidgetClass, + parentWidget, + XmNfontList, fontList, + XmNlabelString, text, + // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault + NULL); XmStringFree (text); XtAddCallback ((Widget) m_mainWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback, - (XtPointer) this); - + (XtPointer) this); SetCanAddEventHandler(TRUE); - AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); + + int x = 0; int y = 0; + wxFont new_font( parent->GetFont() ); + GetTextExtent( label1, &x, &y, (int*)NULL, (int*)NULL, &new_font ); + + wxSize newSize = size; + if (newSize.x == -1) newSize.x = 30+x; + if (newSize.y == -1) newSize.y = 27+y; + SetSize( newSize.x, newSize.y ); + + AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, newSize.x, newSize.y); - SetFont(* parent->GetFont()); ChangeBackgroundColour(); return TRUE; @@ -86,36 +99,45 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, void wxButton::SetDefault() { - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) - parent->SetDefaultItem(this); - - // We initially do not set XmNdefaultShadowThickness, to have small buttons. - // Unfortunately, buttons are now mis-aligned. We try to correct this - // now -- setting this ressource to 1 for each button in the same row. - // Because it's very hard to find wxButton in the same row, - // correction is straighforward: we set resource for all wxButton - // in this parent (but not sub panels) - for (wxNode * node = parent->GetChildren ()->First (); node; node = node->Next ()) + wxWindow *parent = GetParent(); + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + panel->SetDefaultItem(this); + + // We initially do not set XmNdefaultShadowThickness, to have small buttons. + // Unfortunately, buttons are now mis-aligned. We try to correct this + // now -- setting this ressource to 1 for each button in the same row. + // Because it's very hard to find wxButton in the same row, + // correction is straighforward: we set resource for all wxButton + // in this parent (but not sub panels) + for (wxNode * node = parent->GetChildren().First (); node; node = node->Next ()) { - wxButton *item = (wxButton *) node->Data (); - if (item->IsKindOf(CLASSINFO(wxButton))) - { - bool managed = XtIsManaged((Widget) item->GetMainWidget()); - if (managed) - XtUnmanageChild ((Widget) item->GetMainWidget()); - - XtVaSetValues ((Widget) item->GetMainWidget(), - XmNdefaultButtonShadowThickness, 1, - NULL); - - if (managed) - XtManageChild ((Widget) item->GetMainWidget()); - } - } // while - -// XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL); - XtVaSetValues ((Widget) parent->GetMainWidget(), XmNdefaultButton, (Widget) GetMainWidget(), NULL); + wxButton *item = (wxButton *) node->Data (); + if (item->IsKindOf(CLASSINFO(wxButton))) + { + bool managed = XtIsManaged((Widget) item->GetMainWidget()); + if (managed) + XtUnmanageChild ((Widget) item->GetMainWidget()); + + XtVaSetValues ((Widget) item->GetMainWidget(), + XmNdefaultButtonShadowThickness, 1, + NULL); + + if (managed) + XtManageChild ((Widget) item->GetMainWidget()); + } + } // while + + // XtVaSetValues((Widget)handle, XmNshowAsDefault, 1, NULL); + XtVaSetValues ((Widget) parent->GetMainWidget(), XmNdefaultButton, (Widget) GetMainWidget(), NULL); +} + +/* static */ +wxSize wxButton::GetDefaultSize() +{ + // TODO: check font size as in wxMSW ? MB + // + return wxSize(80,26); } void wxButton::Command (wxCommandEvent & event) @@ -123,21 +145,21 @@ void wxButton::Command (wxCommandEvent & event) ProcessCommand (event); } -void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr) +void wxButtonCallback (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr)) { - if (!wxGetWindowFromTable(w)) - // Widget has been deleted! - return; - - wxButton *item = (wxButton *) clientData; - wxCommandEvent event (wxEVT_COMMAND_BUTTON_CLICKED, item->GetId()); - event.SetEventObject(item); - item->ProcessCommand (event); + if (!wxGetWindowFromTable(w)) + // Widget has been deleted! + return; + + wxButton *item = (wxButton *) clientData; + wxCommandEvent event (wxEVT_COMMAND_BUTTON_CLICKED, item->GetId()); + event.SetEventObject(item); + item->ProcessCommand (event); } -void wxButton::ChangeFont() +void wxButton::ChangeFont(bool keepOriginalSize) { - wxWindow::ChangeFont(); + wxWindow::ChangeFont(keepOriginalSize); } void wxButton::ChangeBackgroundColour()