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