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