]> git.saurik.com Git - wxWidgets.git/blame - src/motif/control.cpp
Fix for crash when the child has no menu
[wxWidgets.git] / src / motif / control.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
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
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
4bb6408c
JS
13#pragma implementation "control.h"
14#endif
15
1248b41f
MB
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
f6045f99
GD
19#include "wx/defs.h"
20
4bb6408c 21#include "wx/control.h"
dfe1eee3 22#include "wx/panel.h"
02e8b2f9
JS
23#include "wx/utils.h"
24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
02e8b2f9 28#include <Xm/Xm.h>
338dd992
JJ
29#ifdef __VMS__
30#pragma message enable nosimpint
31#endif
4bb6408c 32
ea19087e
JS
33#include "wx/motif/private.h"
34
4bb6408c
JS
35IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
36
37BEGIN_EVENT_TABLE(wxControl, wxWindow)
38END_EVENT_TABLE()
4bb6408c
JS
39
40// Item members
41wxControl::wxControl()
42{
43 m_backgroundColour = *wxWHITE;
44 m_foregroundColour = *wxBLACK;
31528cd3 45
0c02f070 46 m_inSetValue = false;
4bb6408c
JS
47}
48
5a2155ef 49bool wxControl::Create( wxWindow *parent,
0148fe1e
VZ
50 wxWindowID id,
51 const wxPoint &pos,
52 const wxSize &size,
53 long style,
54 const wxValidator& validator,
55 const wxString &name)
56{
5a2155ef 57 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
674ac8b9
VZ
58
59#if wxUSE_VALIDATORS
0148fe1e 60 SetValidator(validator);
0148fe1e 61#endif
5a2155ef
BJ
62
63 return ret;
674ac8b9 64}
0148fe1e 65
ec75d791
MB
66bool wxControl::CreateControl(wxWindow *parent,
67 wxWindowID id,
68 const wxPoint& pos,
69 const wxSize& size,
70 long style,
71 const wxValidator& validator,
72 const wxString& name)
73{
74 if( !wxControlBase::CreateControl( parent, id, pos, size, style,
75 validator, name ) )
0c02f070 76 return false;
ec75d791
MB
77
78 m_backgroundColour = parent->GetBackgroundColour();
79 m_foregroundColour = parent->GetForegroundColour();
80 m_font = parent->GetFont();
81
0c02f070 82 return true;
ec75d791
MB
83}
84
4bb6408c
JS
85void wxControl::SetLabel(const wxString& label)
86{
a4294b78
JS
87 Widget widget = (Widget) GetLabelWidget() ;
88 if (!widget)
89 return;
dfe1eee3 90
ed0c2af3 91 wxXmString label_str(wxStripMenuCodes(label));
dfe1eee3 92
a4294b78 93 XtVaSetValues (widget,
ea19087e 94 XmNlabelString, label_str(),
2d120f83
JS
95 XmNlabelType, XmSTRING,
96 NULL);
4bb6408c
JS
97}
98
99wxString wxControl::GetLabel() const
100{
a4294b78
JS
101 Widget widget = (Widget) GetLabelWidget() ;
102 if (!widget)
103 return wxEmptyString;
dfe1eee3 104
88793548 105 XmString text = NULL;
a4294b78 106 XtVaGetValues (widget,
2d120f83
JS
107 XmNlabelString, &text,
108 NULL);
dfe1eee3 109
da494b40 110 return wxXmStringToString( text );
4bb6408c
JS
111}
112
31528cd3 113bool wxControl::ProcessCommand(wxCommandEvent & event)
4bb6408c 114{
31528cd3 115 return GetEventHandler()->ProcessEvent(event);
4bb6408c 116}
0c02f070
MB
117
118wxSize wxControl::DoGetBestSize() const
119{
120 Widget w = (Widget)GetTopWidget();
121
122 // Do not return any arbitrary default value...
123 wxASSERT_MSG (w, wxT("DoGetBestSize called before creation"));
124
125 XtWidgetGeometry preferred;
126 XtQueryGeometry (w, NULL, &preferred);
127
128 return wxSize(preferred.width, preferred.height);
129}