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