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