]> git.saurik.com Git - wxWidgets.git/blob - src/motif/control.cpp
no message
[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/utils.h"
18
19 #include <Xm/Xm.h>
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;
34 m_inSetValue = FALSE;
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 /*
42 TODO
43 wxWindow *parent = (wxWindow *)GetParent();
44 if (parent)
45 {
46 if (parent->GetDefaultItem() == (wxButton*) this)
47 parent->SetDefaultItem((wxButton*) NULL);
48 }
49 */
50 }
51
52 void wxControl::SetLabel(const wxString& label)
53 {
54 Widget widget = (Widget) GetLabelWidget() ;
55 if (!widget)
56 return;
57
58 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
59
60 XmString text = XmStringCreateSimple (wxBuffer);
61 XtVaSetValues (widget,
62 XmNlabelString, text,
63 XmNlabelType, XmSTRING,
64 NULL);
65 XmStringFree (text);
66 }
67
68 wxString wxControl::GetLabel() const
69 {
70 Widget widget = (Widget) GetLabelWidget() ;
71 if (!widget)
72 return wxEmptyString;
73
74 XmString text;
75 char *s;
76 XtVaGetValues (widget,
77 XmNlabelString, &text,
78 NULL);
79
80 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
81 {
82 wxString str(s);
83 XtFree (s);
84 XmStringFree(text);
85 return str;
86 }
87 else
88 {
89 // XmStringFree(text);
90 return wxEmptyString;
91 }
92 }
93
94 void wxControl::ProcessCommand (wxCommandEvent & event)
95 {
96 // Tries:
97 // 1) A callback function (to become obsolete)
98 // 2) OnCommand, starting at this window and working up parent hierarchy
99 // 3) OnCommand then calls ProcessEvent to search the event tables.
100 if (m_callback)
101 {
102 (void) (*(m_callback)) (*this, event);
103 }
104 else
105 {
106 GetEventHandler()->OnCommand(*this, event);
107 }
108 }
109
110 void wxControl::Centre (int direction)
111 {
112 int x, y, width, height, panel_width, panel_height, new_x, new_y;
113
114 wxWindow *parent = (wxWindow *) GetParent ();
115 if (!parent)
116 return;
117
118 parent->GetClientSize (&panel_width, &panel_height);
119 GetSize (&width, &height);
120 GetPosition (&x, &y);
121
122 new_x = x;
123 new_y = y;
124
125 if (direction & wxHORIZONTAL)
126 new_x = (int) ((panel_width - width) / 2);
127
128 if (direction & wxVERTICAL)
129 new_y = (int) ((panel_height - height) / 2);
130
131 SetSize (new_x, new_y, width, height);
132 }
133