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