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