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