]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbox.cpp
added AppleEvent Handler, somehow the standard event handler does not take care of...
[wxWidgets.git] / src / motif / statbox.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
31528cd3 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "statbox.h"
14#endif
15
bcd055ae
JJ
16#ifdef __VMS
17#define XtDisplay XTDISPLAY
18#endif
19
f6045f99
GD
20#include "wx/defs.h"
21
4bb6408c 22#include "wx/statbox.h"
47bc1060
JS
23#include "wx/utils.h"
24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
47bc1060
JS
28#include <Xm/Frame.h>
29#include <Xm/Form.h>
30#include <Xm/Label.h>
31#include <Xm/LabelG.h>
338dd992
JJ
32#ifdef __VMS__
33#pragma message enable nosimpint
34#endif
47bc1060 35
3096bd2f 36#include "wx/motif/private.h"
4bb6408c 37
4bb6408c
JS
38IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
39
40BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
31528cd3 41//EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
4bb6408c
JS
42END_EVENT_TABLE()
43
4bb6408c
JS
44
45/*
46 * Static box
47 */
31528cd3 48
47bc1060
JS
49wxStaticBox::wxStaticBox()
50{
47bc1060
JS
51 m_labelWidget = (WXWidget) 0;
52}
53
4bb6408c
JS
54bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
55 const wxString& label,
56 const wxPoint& pos,
57 const wxSize& size,
58 long style,
59 const wxString& name)
60{
0d57be45
JS
61 m_backgroundColour = parent->GetBackgroundColour();
62 m_foregroundColour = parent->GetForegroundColour();
da175b2c 63 m_font = parent->GetFont();
47bc1060 64
4bb6408c
JS
65 SetName(name);
66
67 if (parent) parent->AddChild(this);
68
69 if ( id == -1 )
31528cd3 70 m_windowId = (int)NewControlId();
4bb6408c 71 else
31528cd3 72 m_windowId = id;
4bb6408c
JS
73
74 m_windowStyle = style;
75
47bc1060
JS
76 Widget parentWidget = (Widget) parent->GetClientWidget();
77
2b5f62a0
VZ
78 m_mainWidget = XtVaCreateManagedWidget ("staticboxframe",
79 xmFrameWidgetClass, parentWidget,
80 XmNshadowType, XmSHADOW_IN,
81 //XmNmarginHeight, 0,
82 //XmNmarginWidth, 0,
31528cd3 83 NULL);
47bc1060 84
2b5f62a0 85 bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
47bc1060
JS
86 if (hasLabel)
87 {
da175b2c 88 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
47bc1060 89 wxString label1(wxStripMenuCodes(label));
2b5f62a0
VZ
90 wxXmString text(label1);
91 m_labelWidget = (WXWidget) XtVaCreateManagedWidget (label1.c_str(),
92 xmLabelWidgetClass, (Widget)m_mainWidget,
31528cd3 93 XmNfontList, fontList,
2b5f62a0
VZ
94 XmNlabelString, text(),
95#if (XmVersion > 1200)
96 XmNframeChildType, XmFRAME_TITLE_CHILD,
97#else
98 XmNchildType, XmFRAME_TITLE_CHILD,
99#endif
31528cd3 100 NULL);
47bc1060 101 }
2b5f62a0 102
47bc1060 103 SetCanAddEventHandler(TRUE);
2b5f62a0 104 AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
0d57be45 105 ChangeBackgroundColour();
47bc1060
JS
106
107 return TRUE;
4bb6408c
JS
108}
109
b412f9be
JS
110wxStaticBox::~wxStaticBox()
111{
15d5ab67
JS
112 DetachWidget(m_mainWidget);
113 XtDestroyWidget((Widget) m_mainWidget);
15d5ab67
JS
114
115 m_mainWidget = (WXWidget) 0;
116 m_labelWidget = (WXWidget) 0;
b412f9be
JS
117}
118
4bb6408c
JS
119void wxStaticBox::SetLabel(const wxString& label)
120{
47bc1060
JS
121 if (!m_labelWidget)
122 return;
123
124 if (!label.IsNull())
125 {
126 wxString label1(wxStripMenuCodes(label));
127
2b5f62a0 128 wxXmString text(label1);
47bc1060 129 XtVaSetValues ((Widget) m_labelWidget,
2b5f62a0 130 XmNlabelString, text(),
31528cd3
VZ
131 XmNlabelType, XmSTRING,
132 NULL);
47bc1060
JS
133 }
134}
135
136wxString wxStaticBox::GetLabel() const
137{
138 if (!m_labelWidget)
139 return wxEmptyString;
140
141 XmString text = 0;
142 char *s;
143 XtVaGetValues ((Widget) m_labelWidget,
31528cd3
VZ
144 XmNlabelString, &text,
145 NULL);
47bc1060
JS
146
147 if (!text)
148 return wxEmptyString;
149
150 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
151 {
152 wxString str(s);
153 XtFree (s);
154 return str;
155 }
156 else
157 {
158 return wxEmptyString;
159 }
4bb6408c
JS
160}
161
4b5f3fe6 162void wxStaticBox::ChangeFont(bool keepOriginalSize)
0d57be45 163{
4b5f3fe6 164 wxWindow::ChangeFont(keepOriginalSize);
0d57be45
JS
165}
166
0d57be45 167