]> git.saurik.com Git - wxWidgets.git/blob - src/motif/control.cpp
wxWindow::Fit() infinite loop bug fixed
[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 wxWindow *parent = (wxWindow *)GetParent();
42 if (parent)
43 {
44 if (parent->GetDefaultItem() == (wxButton*) this)
45 parent->SetDefaultItem((wxButton*) NULL);
46 }
47 }
48
49 void wxControl::SetLabel(const wxString& label)
50 {
51 Widget widget = (Widget) GetLabelWidget() ;
52 if (!widget)
53 return;
54
55 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
56
57 XmString text = XmStringCreateSimple (wxBuffer);
58 XtVaSetValues (widget,
59 XmNlabelString, text,
60 XmNlabelType, XmSTRING,
61 NULL);
62 XmStringFree (text);
63 }
64
65 wxString wxControl::GetLabel() const
66 {
67 Widget widget = (Widget) GetLabelWidget() ;
68 if (!widget)
69 return wxEmptyString;
70
71 XmString text;
72 char *s;
73 XtVaGetValues (widget,
74 XmNlabelString, &text,
75 NULL);
76
77 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
78 {
79 wxString str(s);
80 XtFree (s);
81 XmStringFree(text);
82 return str;
83 }
84 else
85 {
86 // XmStringFree(text);
87 return wxEmptyString;
88 }
89 }
90
91 void wxControl::ProcessCommand (wxCommandEvent & event)
92 {
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)
98 {
99 (void) (*(m_callback)) (*this, event);
100 }
101 else
102 {
103 GetEventHandler()->OnCommand(*this, event);
104 }
105 }
106
107 void wxControl::Centre (int direction)
108 {
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);
129 }
130