Include wx/utils.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / src / motif / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/control.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #endif
20
21 #include "wx/panel.h"
22
23 #ifdef __VMS__
24 #pragma message disable nosimpint
25 #endif
26 #include <Xm/Xm.h>
27 #ifdef __VMS__
28 #pragma message enable nosimpint
29 #endif
30
31 #include "wx/motif/private.h"
32
33 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
34
35 BEGIN_EVENT_TABLE(wxControl, wxWindow)
36 END_EVENT_TABLE()
37
38 // Item members
39 wxControl::wxControl()
40 {
41 m_backgroundColour = *wxWHITE;
42 m_foregroundColour = *wxBLACK;
43
44 m_inSetValue = false;
45 }
46
47 bool wxControl::Create( wxWindow *parent,
48 wxWindowID id,
49 const wxPoint &pos,
50 const wxSize &size,
51 long style,
52 const wxValidator& validator,
53 const wxString &name)
54 {
55 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
56
57 #if wxUSE_VALIDATORS
58 SetValidator(validator);
59 #endif
60
61 return ret;
62 }
63
64 bool wxControl::CreateControl(wxWindow *parent,
65 wxWindowID id,
66 const wxPoint& pos,
67 const wxSize& size,
68 long style,
69 const wxValidator& validator,
70 const wxString& name)
71 {
72 if( !wxControlBase::CreateControl( parent, id, pos, size, style,
73 validator, name ) )
74 return false;
75
76 m_backgroundColour = parent->GetBackgroundColour();
77 m_foregroundColour = parent->GetForegroundColour();
78 m_font = parent->GetFont();
79
80 return true;
81 }
82
83 void wxControl::SetLabel(const wxString& label)
84 {
85 Widget widget = (Widget) GetLabelWidget() ;
86 if (!widget)
87 return;
88
89 wxXmString label_str(wxStripMenuCodes(label));
90
91 XtVaSetValues (widget,
92 XmNlabelString, label_str(),
93 XmNlabelType, XmSTRING,
94 NULL);
95 }
96
97 wxString wxControl::GetLabel() const
98 {
99 Widget widget = (Widget) GetLabelWidget() ;
100 if (!widget)
101 return wxEmptyString;
102
103 XmString text = NULL;
104 XtVaGetValues (widget,
105 XmNlabelString, &text,
106 NULL);
107
108 return wxXmStringToString( text );
109 }
110
111 bool wxControl::ProcessCommand(wxCommandEvent & event)
112 {
113 return GetEventHandler()->ProcessEvent(event);
114 }
115
116 wxSize wxControl::DoGetBestSize() const
117 {
118 Widget w = (Widget)GetTopWidget();
119
120 // Do not return any arbitrary default value...
121 wxASSERT_MSG (w, wxT("DoGetBestSize called before creation"));
122
123 XtWidgetGeometry preferred;
124 XtQueryGeometry (w, NULL, &preferred);
125
126 return wxSize(preferred.width, preferred.height);
127 }