]> git.saurik.com Git - wxWidgets.git/blob - src/motif/control.cpp
wxMotif::wxControl() ctor added, now wxCalendarCtrl compiles ok
[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 wxString &name )
52 {
53 (void)Create(parent, id, pos, size, style, name);
54 }
55
56 #if wxUSE_VALIDATORS
57 wxControl::wxControl( wxWindow *parent,
58 wxWindowID id,
59 const wxPoint &pos,
60 const wxSize &size,
61 long style,
62 const wxValidator& validator,
63 const wxString &name)
64 {
65 (void)Create(parent, id, pos, size, style, name);
66 SetValidator(validator);
67 }
68 #endif
69
70 wxControl::~wxControl()
71 {
72 // If we delete an item, we should initialize the parent panel,
73 // because it could now be invalid.
74 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
75 if (panel)
76 {
77 if (panel->GetDefaultItem() == this)
78 panel->SetDefaultItem((wxButton*) NULL);
79 }
80 }
81
82 void wxControl::SetLabel(const wxString& label)
83 {
84 Widget widget = (Widget) GetLabelWidget() ;
85 if (!widget)
86 return;
87
88 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
89
90 XmString text = XmStringCreateSimple (wxBuffer);
91 XtVaSetValues (widget,
92 XmNlabelString, text,
93 XmNlabelType, XmSTRING,
94 NULL);
95 XmStringFree (text);
96 }
97
98 wxString wxControl::GetLabel() const
99 {
100 Widget widget = (Widget) GetLabelWidget() ;
101 if (!widget)
102 return wxEmptyString;
103
104 XmString text;
105 char *s;
106 XtVaGetValues (widget,
107 XmNlabelString, &text,
108 NULL);
109
110 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
111 {
112 wxString str(s);
113 XtFree (s);
114 XmStringFree(text);
115 return str;
116 }
117 else
118 {
119 // XmStringFree(text);
120 return wxEmptyString;
121 }
122 }
123
124 bool wxControl::ProcessCommand(wxCommandEvent & event)
125 {
126 #if WXWIN_COMPATIBILITY
127 if ( m_callback )
128 {
129 (void)(*m_callback)(this, event);
130
131 return TRUE;
132 }
133 else
134 #endif // WXWIN_COMPATIBILITY
135
136 return GetEventHandler()->ProcessEvent(event);
137 }