]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
Don't remove generic status bar from parent, since it can be used on
[wxWidgets.git] / src / motif / statbox.cpp
CommitLineData
4bb6408c
JS
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
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
4bb6408c
JS
13#pragma implementation "statbox.h"
14#endif
15
1248b41f
MB
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
bcd055ae
JJ
19#ifdef __VMS
20#define XtDisplay XTDISPLAY
21#endif
22
f6045f99
GD
23#include "wx/defs.h"
24
4bb6408c 25#include "wx/statbox.h"
47bc1060
JS
26#include "wx/utils.h"
27
338dd992
JJ
28#ifdef __VMS__
29#pragma message disable nosimpint
30#endif
47bc1060 31#include <Xm/Frame.h>
47bc1060 32#include <Xm/Label.h>
338dd992
JJ
33#ifdef __VMS__
34#pragma message enable nosimpint
35#endif
47bc1060 36
3096bd2f 37#include "wx/motif/private.h"
4bb6408c 38
4bb6408c
JS
39IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
40
41BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
31528cd3 42//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
4bb6408c
JS
43END_EVENT_TABLE()
44
483561c5
MB
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};
4bb6408c
JS
79
80/*
81 * Static box
82 */
31528cd3 83
47bc1060
JS
84wxStaticBox::wxStaticBox()
85{
47bc1060
JS
86 m_labelWidget = (WXWidget) 0;
87}
88
4bb6408c
JS
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{
483561c5
MB
96 if( !CreateControl( parent, id, pos, size, style,
97 wxDefaultValidator, name ) )
98 return false;
4bb6408c 99
47bc1060
JS
100 Widget parentWidget = (Widget) parent->GetClientWidget();
101
2b5f62a0
VZ
102 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
103 xmFrameWidgetClass, parentWidget,
483561c5
MB
104 // MBN: why override default?
105 // XmNshadowType, XmSHADOW_IN,
31528cd3 106 NULL);
47bc1060 107
2b5f62a0 108 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
47bc1060
JS
109 if (hasLabel)
110 {
da494b40 111 WXFontType fontType = m_font.GetFontType( XtDisplay( parentWidget ) );
47bc1060 112 wxString label1(wxStripMenuCodes(label));
2b5f62a0 113 wxXmString text(label1);
483561c5
MB
114
115 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
2b5f62a0 116 xmLabelWidgetClass, (Widget)m_mainWidget,
da494b40 117 wxFont::GetFontTag(), fontType,
2b5f62a0 118 XmNlabelString, text(),
483561c5 119#if wxCHECK_MOTIF_VERSION( 2, 0 )
2b5f62a0
VZ
120 XmNframeChildType, XmFRAME_TITLE_CHILD,
121#else
122 XmNchildType, XmFRAME_TITLE_CHILD,
123#endif
31528cd3 124 NULL);
47bc1060 125 }
2b5f62a0 126
2b5f62a0 127 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
0d57be45 128 ChangeBackgroundColour();
47bc1060
JS
129
130 return TRUE;
4bb6408c
JS
131}
132
b412f9be
JS
133wxStaticBox::~wxStaticBox()
134{
15d5ab67
JS
135 DetachWidget(m_mainWidget);
136 XtDestroyWidget((Widget) m_mainWidget);
15d5ab67
JS
137
138 m_mainWidget = (WXWidget) 0;
139 m_labelWidget = (WXWidget) 0;
b412f9be
JS
140}
141
483561c5 142void wxStaticBox::SetLabel( const wxString& label )
47bc1060 143{
483561c5 144 wxXmSizeKeeper sk( (Widget)GetMainWidget() );
47bc1060 145
483561c5 146 wxStaticBoxBase::SetLabel( label );
47bc1060 147
483561c5 148 sk.Restore();
0d57be45 149}