]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
WinCE build fixes.
[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
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
bcd055ae
JJ
15#ifdef __VMS
16#define XtDisplay XTDISPLAY
17#endif
18
f6045f99
GD
19#include "wx/defs.h"
20
4bb6408c 21#include "wx/statbox.h"
47bc1060
JS
22#include "wx/utils.h"
23
338dd992
JJ
24#ifdef __VMS__
25#pragma message disable nosimpint
26#endif
47bc1060 27#include <Xm/Frame.h>
47bc1060 28#include <Xm/Label.h>
338dd992
JJ
29#ifdef __VMS__
30#pragma message enable nosimpint
31#endif
47bc1060 32
3096bd2f 33#include "wx/motif/private.h"
4bb6408c 34
4bb6408c
JS
35IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
36
37BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
31528cd3 38//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
4bb6408c
JS
39END_EVENT_TABLE()
40
483561c5
MB
41// ----------------------------------------------------------------------------
42// wxXmSizeKeeper
43// ----------------------------------------------------------------------------
44
45// helper class to reduce code duplication
46class wxXmSizeKeeper
47{
48 Dimension m_x, m_y;
49 Widget m_widget;
50public:
51 wxXmSizeKeeper( Widget w )
52 : m_widget( w )
53 {
54 XtVaGetValues( m_widget,
55 XmNwidth, &m_x,
56 XmNheight, &m_y,
57 NULL );
58 }
59
60 void Restore()
61 {
62 int x, y;
63
64 XtVaGetValues( m_widget,
65 XmNwidth, &x,
66 XmNheight, &y,
67 NULL );
68 if( x != m_x || y != m_y )
69 XtVaSetValues( m_widget,
70 XmNwidth, m_x,
71 XmNheight, m_y,
72 NULL );
73 }
74};
4bb6408c
JS
75
76/*
77 * Static box
78 */
31528cd3 79
47bc1060
JS
80wxStaticBox::wxStaticBox()
81{
47bc1060
JS
82 m_labelWidget = (WXWidget) 0;
83}
84
4bb6408c
JS
85bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
86 const wxString& label,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
91{
483561c5
MB
92 if( !CreateControl( parent, id, pos, size, style,
93 wxDefaultValidator, name ) )
94 return false;
4bb6408c 95
47bc1060
JS
96 Widget parentWidget = (Widget) parent->GetClientWidget();
97
2b5f62a0
VZ
98 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
99 xmFrameWidgetClass, parentWidget,
483561c5
MB
100 // MBN: why override default?
101 // XmNshadowType, XmSHADOW_IN,
31528cd3 102 NULL);
47bc1060 103
2b5f62a0 104 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
47bc1060
JS
105 if (hasLabel)
106 {
107 wxString label1(wxStripMenuCodes(label));
2b5f62a0 108 wxXmString text(label1);
73608949 109 Display* dpy = XtDisplay( parentWidget );
483561c5
MB
110
111 m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
2b5f62a0 112 xmLabelWidgetClass, (Widget)m_mainWidget,
73608949 113 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
2b5f62a0 114 XmNlabelString, text(),
483561c5 115#if wxCHECK_MOTIF_VERSION( 2, 0 )
2b5f62a0
VZ
116 XmNframeChildType, XmFRAME_TITLE_CHILD,
117#else
118 XmNchildType, XmFRAME_TITLE_CHILD,
119#endif
31528cd3 120 NULL);
47bc1060 121 }
2b5f62a0 122
2b5f62a0 123 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
0d57be45 124 ChangeBackgroundColour();
47bc1060 125
96be256b 126 return true;
4bb6408c
JS
127}
128
b412f9be
JS
129wxStaticBox::~wxStaticBox()
130{
15d5ab67
JS
131 DetachWidget(m_mainWidget);
132 XtDestroyWidget((Widget) m_mainWidget);
15d5ab67
JS
133
134 m_mainWidget = (WXWidget) 0;
135 m_labelWidget = (WXWidget) 0;
b412f9be
JS
136}
137
483561c5 138void wxStaticBox::SetLabel( const wxString& label )
47bc1060 139{
483561c5 140 wxXmSizeKeeper sk( (Widget)GetMainWidget() );
47bc1060 141
483561c5 142 wxStaticBoxBase::SetLabel( label );
47bc1060 143
483561c5 144 sk.Restore();
0d57be45 145}
13abe5c0
MB
146
147void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
148{
149 Dimension shadow, border;
150
151 XtVaGetValues( (Widget) GetMainWidget(),
152 XmNshadowThickness, &shadow,
153 XmNborderWidth, &border,
154 NULL);
155
156 *borderOther = shadow + border;
157
158 if( GetLabelWidget() )
159 {
160 XtWidgetGeometry preferred;
161 XtQueryGeometry( (Widget) GetLabelWidget(), NULL, &preferred );
162
163 *borderTop = preferred.height;
164 }
165 else
166 {
167 *borderTop = shadow;
168 }
169}