Committing in .
[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 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
30
31 BEGIN_EVENT_TABLE(wxControl, wxWindow)
32 END_EVENT_TABLE()
33 #endif
34
35 // Item members
36 wxControl::wxControl()
37 {
38 m_backgroundColour = *wxWHITE;
39 m_foregroundColour = *wxBLACK;
40
41 #if WXWIN_COMPATIBILITY
42 m_callback = 0;
43 #endif // WXWIN_COMPATIBILITY
44
45 m_inSetValue = FALSE;
46 }
47
48 wxControl::~wxControl()
49 {
50 // If we delete an item, we should initialize the parent panel,
51 // because it could now be invalid.
52 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
53 if (panel)
54 {
55 if (panel->GetDefaultItem() == this)
56 panel->SetDefaultItem((wxButton*) NULL);
57 }
58 }
59
60 void wxControl::SetLabel(const wxString& label)
61 {
62 Widget widget = (Widget) GetLabelWidget() ;
63 if (!widget)
64 return;
65
66 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
67
68 XmString text = XmStringCreateSimple (wxBuffer);
69 XtVaSetValues (widget,
70 XmNlabelString, text,
71 XmNlabelType, XmSTRING,
72 NULL);
73 XmStringFree (text);
74 }
75
76 wxString wxControl::GetLabel() const
77 {
78 Widget widget = (Widget) GetLabelWidget() ;
79 if (!widget)
80 return wxEmptyString;
81
82 XmString text;
83 char *s;
84 XtVaGetValues (widget,
85 XmNlabelString, &text,
86 NULL);
87
88 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
89 {
90 wxString str(s);
91 XtFree (s);
92 XmStringFree(text);
93 return str;
94 }
95 else
96 {
97 // XmStringFree(text);
98 return wxEmptyString;
99 }
100 }
101
102 bool wxControl::ProcessCommand(wxCommandEvent & event)
103 {
104 #if WXWIN_COMPATIBILITY
105 if ( m_callback )
106 {
107 (void)(*m_callback)(this, event);
108
109 return TRUE;
110 }
111 else
112 #endif // WXWIN_COMPATIBILITY
113
114 return GetEventHandler()->ProcessEvent(event);
115 }