wxControl child of wxControlBase
[wxWidgets.git] / src / motif / control.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
16 #include "wx/control.h"
17 #include "wx/panel.h"
18 #include "wx/utils.h"
19
20 #ifdef __VMS__
21 #pragma message disable nosimpint
22 #endif
23 #include <Xm/Xm.h>
24 #ifdef __VMS__
25 #pragma message enable nosimpint
26 #endif
27
28 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30 BEGIN_EVENT_TABLE(wxControl, wxWindow)
31 END_EVENT_TABLE()
32
33 // Item members
34 wxControl::wxControl()
35 {
36 m_backgroundColour = *wxWHITE;
37 m_foregroundColour = *wxBLACK;
38
39 #if WXWIN_COMPATIBILITY
40 m_callback = 0;
41 #endif // WXWIN_COMPATIBILITY
42
43 m_inSetValue = FALSE;
44 }
45
46 bool wxControl::Create( wxWindow *parent,
47 wxWindowID id,
48 const wxPoint &pos,
49 const wxSize &size,
50 long style,
51 const wxValidator& validator,
52 const wxString &name)
53 {
54 bool ret = wxWindow::Create(parent, id, pos, size, style, name);
55
56 #if wxUSE_VALIDATORS
57 SetValidator(validator);
58 #endif
59
60 return ret;
61 }
62
63 wxControl::~wxControl()
64 {
65 // If we delete an item, we should initialize the parent panel,
66 // because it could now be invalid.
67 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
68 if (panel)
69 {
70 if (panel->GetDefaultItem() == this)
71 panel->SetDefaultItem((wxButton*) NULL);
72 }
73 }
74
75 void wxControl::SetLabel(const wxString& label)
76 {
77 Widget widget = (Widget) GetLabelWidget() ;
78 if (!widget)
79 return;
80
81 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
82
83 XmString text = XmStringCreateSimple (wxBuffer);
84 XtVaSetValues (widget,
85 XmNlabelString, text,
86 XmNlabelType, XmSTRING,
87 NULL);
88 XmStringFree (text);
89 }
90
91 wxString wxControl::GetLabel() const
92 {
93 Widget widget = (Widget) GetLabelWidget() ;
94 if (!widget)
95 return wxEmptyString;
96
97 XmString text;
98 char *s;
99 XtVaGetValues (widget,
100 XmNlabelString, &text,
101 NULL);
102
103 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
104 {
105 wxString str(s);
106 XtFree (s);
107 XmStringFree(text);
108 return str;
109 }
110 else
111 {
112 // XmStringFree(text);
113 return wxEmptyString;
114 }
115 }
116
117 bool wxControl::ProcessCommand(wxCommandEvent & event)
118 {
119 #if WXWIN_COMPATIBILITY
120 if ( m_callback )
121 {
122 (void)(*m_callback)(this, event);
123
124 return TRUE;
125 }
126 else
127 #endif // WXWIN_COMPATIBILITY
128
129 return GetEventHandler()->ProcessEvent(event);
130 }