Refactored wxStaticBox, and changed wxStaticBox and wxRadioBox border

style from sunken to the default Motif style.
  Added some convenience macros for checking Motif/Lesstif version.
  Fixed the bug that caused wxStaticBox size to change when label text
was changed.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-03-02 20:08:45 +00:00
parent a73903480f
commit 483561c568
5 changed files with 69 additions and 82 deletions

View File

@@ -96,7 +96,8 @@ wxMotif:
with Motif 1.x compatibility with Motif 1.x compatibility
- implemented wxToggleButton - implemented wxToggleButton
- made wxButton a bit smaller by default - made wxButton a bit smaller by default
- wxRadioBox and wxStaticBox now use the default shadow (border) style
instead of
wxUniv: wxUniv:
- Controls in toolbars now supported. - Controls in toolbars now supported.

View File

@@ -20,6 +20,18 @@
// Put any private declarations here: native Motif types may be used because // Put any private declarations here: native Motif types may be used because
// this header is included after Xm/Xm.h // this header is included after Xm/Xm.h
// ----------------------------------------------------------------------------
// convenience macros
// ----------------------------------------------------------------------------
#define wxCHECK_MOTIF_VERSION( major, minor ) \
( XmVersion >= (major) * 1000 + (minor) )
#define wxCHECK_LESSTIF_VERSION( major, minor ) \
( LesstifVersion >= (major) * 1000 + (minor) )
#define wxCHECK_LESSTIF() ( defined(LesstifVersion) && LesstifVersion > 0 )
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// common callbacks // common callbacks
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -16,12 +16,10 @@
#pragma interface "statbox.h" #pragma interface "statbox.h"
#endif #endif
#include "wx/control.h"
WXDLLEXPORT_DATA(extern const char*) wxStaticBoxNameStr; WXDLLEXPORT_DATA(extern const char*) wxStaticBoxNameStr;
// Group box // Group box
class WXDLLEXPORT wxStaticBox: public wxControl class WXDLLEXPORT wxStaticBox: public wxStaticBoxBase
{ {
DECLARE_DYNAMIC_CLASS(wxStaticBox) DECLARE_DYNAMIC_CLASS(wxStaticBox)
@@ -36,6 +34,7 @@ public:
{ {
Create(parent, id, label, pos, size, style, name); Create(parent, id, label, pos, size, style, name);
} }
~wxStaticBox(); ~wxStaticBox();
bool Create(wxWindow *parent, wxWindowID id, bool Create(wxWindow *parent, wxWindowID id,
@@ -49,15 +48,12 @@ public:
{ {
return FALSE; return FALSE;
} }
void SetLabel(const wxString& label); virtual WXWidget GetLabelWidget() const { return m_labelWidget; }
wxString GetLabel() const;
virtual void SetLabel(const wxString& label);
// Implementation
virtual void ChangeFont(bool keepOriginalSize = TRUE); private:
protected:
// Motif-specific
WXWidget m_labelWidget; WXWidget m_labelWidget;
private: private:

View File

@@ -30,7 +30,6 @@
#include <Xm/ToggleB.h> #include <Xm/ToggleB.h>
#include <Xm/ToggleBG.h> #include <Xm/ToggleBG.h>
#include <Xm/RowColumn.h> #include <Xm/RowColumn.h>
#include <Xm/Form.h>
#include <Xm/Frame.h> #include <Xm/Frame.h>
#ifdef __VMS__ #ifdef __VMS__
#pragma message enable nosimpint #pragma message enable nosimpint
@@ -92,7 +91,6 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
m_mainWidget = XtVaCreateWidget ("radioboxframe", m_mainWidget = XtVaCreateWidget ("radioboxframe",
xmFrameWidgetClass, parentWidget, xmFrameWidgetClass, parentWidget,
XmNshadowType, XmSHADOW_IN,
XmNresizeHeight, True, XmNresizeHeight, True,
XmNresizeWidth, True, XmNresizeWidth, True,
NULL); NULL);

View File

@@ -26,9 +26,7 @@
#pragma message disable nosimpint #pragma message disable nosimpint
#endif #endif
#include <Xm/Frame.h> #include <Xm/Frame.h>
#include <Xm/Form.h>
#include <Xm/Label.h> #include <Xm/Label.h>
#include <Xm/LabelG.h>
#ifdef __VMS__ #ifdef __VMS__
#pragma message enable nosimpint #pragma message enable nosimpint
#endif #endif
@@ -41,6 +39,40 @@ BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground) //EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
END_EVENT_TABLE() END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// wxXmSizeKeeper
// ----------------------------------------------------------------------------
// helper class to reduce code duplication
class wxXmSizeKeeper
{
Dimension m_x, m_y;
Widget m_widget;
public:
wxXmSizeKeeper( Widget w )
: m_widget( w )
{
XtVaGetValues( m_widget,
XmNwidth, &m_x,
XmNheight, &m_y,
NULL );
}
void Restore()
{
int x, y;
XtVaGetValues( m_widget,
XmNwidth, &x,
XmNheight, &y,
NULL );
if( x != m_x || y != m_y )
XtVaSetValues( m_widget,
XmNwidth, m_x,
XmNheight, m_y,
NULL );
}
};
/* /*
* Static box * Static box
@@ -58,41 +90,30 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
long style, long style,
const wxString& name) const wxString& name)
{ {
m_backgroundColour = parent->GetBackgroundColour(); if( !CreateControl( parent, id, pos, size, style,
m_foregroundColour = parent->GetForegroundColour(); wxDefaultValidator, name ) )
m_font = parent->GetFont(); return false;
SetName(name);
if (parent) parent->AddChild(this);
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
m_windowStyle = style;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
m_mainWidget = XtVaCreateManagedWidget ("staticboxframe", m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
xmFrameWidgetClass, parentWidget, xmFrameWidgetClass, parentWidget,
XmNshadowType, XmSHADOW_IN, // MBN: why override default?
//XmNmarginHeight, 0, // XmNshadowType, XmSHADOW_IN,
//XmNmarginWidth, 0,
NULL); NULL);
bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ; bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
if (hasLabel) if (hasLabel)
{ {
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay( parentWidget ) );
wxString label1(wxStripMenuCodes(label)); wxString label1(wxStripMenuCodes(label));
wxXmString text(label1); wxXmString text(label1);
m_labelWidget = (WXWidget) XtVaCreateManagedWidget (label1.c_str(),
m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
xmLabelWidgetClass, (Widget)m_mainWidget, xmLabelWidgetClass, (Widget)m_mainWidget,
XmNfontList, fontList, XmNfontList, fontList,
XmNlabelString, text(), XmNlabelString, text(),
#if (XmVersion > 1200) #if wxCHECK_MOTIF_VERSION( 2, 0 )
XmNframeChildType, XmFRAME_TITLE_CHILD, XmNframeChildType, XmFRAME_TITLE_CHILD,
#else #else
XmNchildType, XmFRAME_TITLE_CHILD, XmNchildType, XmFRAME_TITLE_CHILD,
@@ -116,52 +137,11 @@ wxStaticBox::~wxStaticBox()
m_labelWidget = (WXWidget) 0; m_labelWidget = (WXWidget) 0;
} }
void wxStaticBox::SetLabel(const wxString& label) void wxStaticBox::SetLabel( const wxString& label )
{ {
if (!m_labelWidget) wxXmSizeKeeper sk( (Widget)GetMainWidget() );
return;
if (!label.IsNull()) wxStaticBoxBase::SetLabel( label );
{
wxString label1(wxStripMenuCodes(label));
wxXmString text(label1); sk.Restore();
XtVaSetValues ((Widget) m_labelWidget,
XmNlabelString, text(),
XmNlabelType, XmSTRING,
NULL);
}
} }
wxString wxStaticBox::GetLabel() const
{
if (!m_labelWidget)
return wxEmptyString;
XmString text = 0;
char *s;
XtVaGetValues ((Widget) m_labelWidget,
XmNlabelString, &text,
NULL);
if (!text)
return wxEmptyString;
if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
{
wxString str(s);
XtFree (s);
return str;
}
else
{
return wxEmptyString;
}
}
void wxStaticBox::ChangeFont(bool keepOriginalSize)
{
wxWindow::ChangeFont(keepOriginalSize);
}