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