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