1. more warnings fixes in gtk/region.cpp and common/tbarsmpl.cpp
[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 wxControl::wxControl( 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 (void)Create(parent, id, pos, size, style, name);
55
56 #if wxUSE_VALIDATORS
57 SetValidator(validator);
58 #endif
59 }
60
61 wxControl::~wxControl()
62 {
63 // If we delete an item, we should initialize the parent panel,
64 // because it could now be invalid.
65 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
66 if (panel)
67 {
68 if (panel->GetDefaultItem() == this)
69 panel->SetDefaultItem((wxButton*) NULL);
70 }
71 }
72
73 void wxControl::SetLabel(const wxString& label)
74 {
75 Widget widget = (Widget) GetLabelWidget() ;
76 if (!widget)
77 return;
78
79 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
80
81 XmString text = XmStringCreateSimple (wxBuffer);
82 XtVaSetValues (widget,
83 XmNlabelString, text,
84 XmNlabelType, XmSTRING,
85 NULL);
86 XmStringFree (text);
87 }
88
89 wxString wxControl::GetLabel() const
90 {
91 Widget widget = (Widget) GetLabelWidget() ;
92 if (!widget)
93 return wxEmptyString;
94
95 XmString text;
96 char *s;
97 XtVaGetValues (widget,
98 XmNlabelString, &text,
99 NULL);
100
101 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
102 {
103 wxString str(s);
104 XtFree (s);
105 XmStringFree(text);
106 return str;
107 }
108 else
109 {
110 // XmStringFree(text);
111 return wxEmptyString;
112 }
113 }
114
115 bool wxControl::ProcessCommand(wxCommandEvent & event)
116 {
117 #if WXWIN_COMPATIBILITY
118 if ( m_callback )
119 {
120 (void)(*m_callback)(this, event);
121
122 return TRUE;
123 }
124 else
125 #endif // WXWIN_COMPATIBILITY
126
127 return GetEventHandler()->ProcessEvent(event);
128 }