]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/statbox.cpp
Backed-out PNG8 patch (no time to look at why
[wxWidgets.git] / src / motif / statbox.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbox.cpp
3// Purpose: wxStaticBox
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "statbox.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __VMS
20#define XtDisplay XTDISPLAY
21#endif
22
23#include "wx/defs.h"
24
25#include "wx/statbox.h"
26#include "wx/utils.h"
27
28#ifdef __VMS__
29#pragma message disable nosimpint
30#endif
31#include <Xm/Frame.h>
32#include <Xm/Label.h>
33#ifdef __VMS__
34#pragma message enable nosimpint
35#endif
36
37#include "wx/motif/private.h"
38
39IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
40
41BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
42//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
43END_EVENT_TABLE()
44
45// ----------------------------------------------------------------------------
46// wxXmSizeKeeper
47// ----------------------------------------------------------------------------
48
49// helper class to reduce code duplication
50class wxXmSizeKeeper
51{
52 Dimension m_x, m_y;
53 Widget m_widget;
54public:
55 wxXmSizeKeeper( Widget w )
56 : m_widget( w )
57 {
58 XtVaGetValues( m_widget,
59 XmNwidth, &m_x,
60 XmNheight, &m_y,
61 NULL );
62 }
63
64 void Restore()
65 {
66 int x, y;
67
68 XtVaGetValues( m_widget,
69 XmNwidth, &x,
70 XmNheight, &y,
71 NULL );
72 if( x != m_x || y != m_y )
73 XtVaSetValues( m_widget,
74 XmNwidth, m_x,
75 XmNheight, m_y,
76 NULL );
77 }
78};
79
80/*
81 * Static box
82 */
83
84wxStaticBox::wxStaticBox()
85{
86 m_labelWidget = (WXWidget) 0;
87}
88
89bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
90 const wxString& label,
91 const wxPoint& pos,
92 const wxSize& size,
93 long style,
94 const wxString& name)
95{
96 if( !CreateControl( parent, id, pos, size, style,
97 wxDefaultValidator, name ) )
98 return false;
99
100 Widget parentWidget = (Widget) parent->GetClientWidget();
101
102 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
103 xmFrameWidgetClass, parentWidget,
104 // MBN: why override default?
105 // XmNshadowType, XmSHADOW_IN,
106 NULL);
107
108 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
109 if (hasLabel)
110 {
111 WXFontType fontType = m_font.GetFontType( XtDisplay( parentWidget ) );
112 wxString label1(wxStripMenuCodes(label));
113 wxXmString text(label1);
114
115 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
116 xmLabelWidgetClass, (Widget)m_mainWidget,
117 wxFont::GetFontTag(), fontType,
118 XmNlabelString, text(),
119#if wxCHECK_MOTIF_VERSION( 2, 0 )
120 XmNframeChildType, XmFRAME_TITLE_CHILD,
121#else
122 XmNchildType, XmFRAME_TITLE_CHILD,
123#endif
124 NULL);
125 }
126
127 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
128 ChangeBackgroundColour();
129
130 return TRUE;
131}
132
133wxStaticBox::~wxStaticBox()
134{
135 DetachWidget(m_mainWidget);
136 XtDestroyWidget((Widget) m_mainWidget);
137
138 m_mainWidget = (WXWidget) 0;
139 m_labelWidget = (WXWidget) 0;
140}
141
142void wxStaticBox::SetLabel( const wxString& label )
143{
144 wxXmSizeKeeper sk( (Widget)GetMainWidget() );
145
146 wxStaticBoxBase::SetLabel( label );
147
148 sk.Restore();
149}