X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2d120f8391920145647ec10e84629bc21fa9f1bb..120b822df16ae27b64fe73b27d649cb89f166f46:/src/motif/button.cpp diff --git a/src/motif/button.cpp b/src/motif/button.cpp index 209c03de98..645f99cf44 100644 --- a/src/motif/button.cpp +++ b/src/motif/button.cpp @@ -6,26 +6,37 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ #pragma implementation "button.h" #endif +#ifdef __VMS +#define XtDisplay XTDISPLAY +#endif + +#include "wx/defs.h" + #include "wx/button.h" #include "wx/utils.h" +#include "wx/panel.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr); -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) -#endif // Button @@ -40,22 +51,22 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, m_windowStyle = style; m_backgroundColour = parent->GetBackgroundColour(); m_foregroundColour = parent->GetForegroundColour(); - m_windowFont = parent->GetFont(); - + m_font = parent->GetFont(); + parent->AddChild((wxButton *)this); - + if (id == -1) m_windowId = NewControlId(); else m_windowId = id; - + wxString label1(wxStripMenuCodes(label)); - + XmString text = XmStringCreateSimple ((char*) (const char*) label1); Widget parentWidget = (Widget) parent->GetClientWidget(); - - XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget)); - + + XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); + /* * Patch Note (important) * There is no major reason to put a defaultButtonThickness here. @@ -72,26 +83,36 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, XmNlabelString, text, // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault NULL); - + XmStringFree (text); - + XtAddCallback ((Widget) m_mainWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback, (XtPointer) this); - + SetCanAddEventHandler(TRUE); - AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); + 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); + + ChangeBackgroundColour(); + return TRUE; } void wxButton::SetDefault() { - wxWindow *parent = (wxWindow *)GetParent(); - if (parent) + wxWindow *parent = 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. @@ -106,20 +127,28 @@ void wxButton::SetDefault() 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 - + } // 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) { ProcessCommand (event); @@ -130,7 +159,7 @@ 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);