]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/control.h" | |
02e8b2f9 JS |
17 | #include "wx/utils.h" |
18 | ||
19 | #include <Xm/Xm.h> | |
4bb6408c JS |
20 | |
21 | #if !USE_SHARED_LIBRARY | |
22 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
23 | ||
24 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
25 | END_EVENT_TABLE() | |
26 | #endif | |
27 | ||
28 | // Item members | |
29 | wxControl::wxControl() | |
30 | { | |
31 | m_backgroundColour = *wxWHITE; | |
32 | m_foregroundColour = *wxBLACK; | |
33 | m_callback = 0; | |
a4294b78 | 34 | m_inSetValue = FALSE; |
4bb6408c JS |
35 | } |
36 | ||
37 | wxControl::~wxControl() | |
38 | { | |
39 | // If we delete an item, we should initialize the parent panel, | |
40 | // because it could now be invalid. | |
41 | wxWindow *parent = (wxWindow *)GetParent(); | |
42 | if (parent) | |
43 | { | |
44 | if (parent->GetDefaultItem() == (wxButton*) this) | |
45 | parent->SetDefaultItem(NULL); | |
46 | } | |
47 | } | |
48 | ||
49 | void wxControl::SetLabel(const wxString& label) | |
50 | { | |
a4294b78 JS |
51 | Widget widget = (Widget) GetLabelWidget() ; |
52 | if (!widget) | |
53 | return; | |
2d120f83 | 54 | |
a4294b78 | 55 | wxStripMenuCodes((char*) (const char*) label, wxBuffer); |
2d120f83 | 56 | |
a4294b78 JS |
57 | XmString text = XmStringCreateSimple (wxBuffer); |
58 | XtVaSetValues (widget, | |
2d120f83 JS |
59 | XmNlabelString, text, |
60 | XmNlabelType, XmSTRING, | |
61 | NULL); | |
a4294b78 | 62 | XmStringFree (text); |
4bb6408c JS |
63 | } |
64 | ||
65 | wxString wxControl::GetLabel() const | |
66 | { | |
a4294b78 JS |
67 | Widget widget = (Widget) GetLabelWidget() ; |
68 | if (!widget) | |
69 | return wxEmptyString; | |
2d120f83 | 70 | |
a4294b78 JS |
71 | XmString text; |
72 | char *s; | |
73 | XtVaGetValues (widget, | |
2d120f83 JS |
74 | XmNlabelString, &text, |
75 | NULL); | |
76 | ||
a4294b78 | 77 | if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s)) |
02e8b2f9 | 78 | { |
a4294b78 JS |
79 | wxString str(s); |
80 | XtFree (s); | |
81 | XmStringFree(text); | |
82 | return str; | |
02e8b2f9 | 83 | } |
a4294b78 | 84 | else |
02e8b2f9 | 85 | { |
a4294b78 JS |
86 | XmStringFree(text); |
87 | return wxEmptyString; | |
02e8b2f9 | 88 | } |
4bb6408c JS |
89 | } |
90 | ||
91 | void wxControl::ProcessCommand (wxCommandEvent & event) | |
92 | { | |
2d120f83 JS |
93 | // Tries: |
94 | // 1) A callback function (to become obsolete) | |
95 | // 2) OnCommand, starting at this window and working up parent hierarchy | |
96 | // 3) OnCommand then calls ProcessEvent to search the event tables. | |
97 | if (m_callback) | |
4bb6408c | 98 | { |
2d120f83 | 99 | (void) (*(m_callback)) (*this, event); |
4bb6408c JS |
100 | } |
101 | else | |
102 | { | |
2d120f83 | 103 | GetEventHandler()->OnCommand(*this, event); |
4bb6408c JS |
104 | } |
105 | } | |
106 | ||
107 | void wxControl::Centre (int direction) | |
108 | { | |
2d120f83 JS |
109 | int x, y, width, height, panel_width, panel_height, new_x, new_y; |
110 | ||
111 | wxWindow *parent = (wxWindow *) GetParent (); | |
112 | if (!parent) | |
113 | return; | |
114 | ||
115 | parent->GetClientSize (&panel_width, &panel_height); | |
116 | GetSize (&width, &height); | |
117 | GetPosition (&x, &y); | |
118 | ||
119 | new_x = x; | |
120 | new_y = y; | |
121 | ||
122 | if (direction & wxHORIZONTAL) | |
123 | new_x = (int) ((panel_width - width) / 2); | |
124 | ||
125 | if (direction & wxVERTICAL) | |
126 | new_y = (int) ((panel_height - height) / 2); | |
127 | ||
128 | SetSize (new_x, new_y, width, height); | |
4bb6408c JS |
129 | } |
130 |