]> git.saurik.com Git - wxWidgets.git/blame - src/motif/control.cpp
Added lots of files. Enough now so that all wxHTML samples link.
[wxWidgets.git] / src / motif / control.cpp
CommitLineData
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
16#include "wx/control.h"
dfe1eee3 17#include "wx/panel.h"
02e8b2f9
JS
18#include "wx/utils.h"
19
20#include <Xm/Xm.h>
4bb6408c
JS
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;
a4294b78 35 m_inSetValue = FALSE;
4bb6408c
JS
36}
37
38wxControl::~wxControl()
39{
40 // If we delete an item, we should initialize the parent panel,
41 // because it could now be invalid.
dfe1eee3
VZ
42 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
43 if (panel)
4bb6408c 44 {
dfe1eee3
VZ
45 if (panel->GetDefaultItem() == this)
46 panel->SetDefaultItem((wxButton*) NULL);
4bb6408c
JS
47 }
48}
49
50void wxControl::SetLabel(const wxString& label)
51{
a4294b78
JS
52 Widget widget = (Widget) GetLabelWidget() ;
53 if (!widget)
54 return;
dfe1eee3 55
a4294b78 56 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
dfe1eee3 57
a4294b78
JS
58 XmString text = XmStringCreateSimple (wxBuffer);
59 XtVaSetValues (widget,
2d120f83
JS
60 XmNlabelString, text,
61 XmNlabelType, XmSTRING,
62 NULL);
a4294b78 63 XmStringFree (text);
4bb6408c
JS
64}
65
66wxString wxControl::GetLabel() const
67{
a4294b78
JS
68 Widget widget = (Widget) GetLabelWidget() ;
69 if (!widget)
70 return wxEmptyString;
dfe1eee3 71
a4294b78
JS
72 XmString text;
73 char *s;
74 XtVaGetValues (widget,
2d120f83
JS
75 XmNlabelString, &text,
76 NULL);
dfe1eee3 77
a4294b78 78 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
02e8b2f9 79 {
a4294b78
JS
80 wxString str(s);
81 XtFree (s);
82 XmStringFree(text);
83 return str;
02e8b2f9 84 }
a4294b78 85 else
02e8b2f9 86 {
15d5ab67 87 // XmStringFree(text);
a4294b78 88 return wxEmptyString;
02e8b2f9 89 }
4bb6408c
JS
90}
91
92void wxControl::ProcessCommand (wxCommandEvent & event)
93{
2d120f83
JS
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)
4bb6408c 99 {
2d120f83 100 (void) (*(m_callback)) (*this, event);
4bb6408c
JS
101 }
102 else
103 {
2d120f83 104 GetEventHandler()->OnCommand(*this, event);
4bb6408c
JS
105 }
106}
107
108void wxControl::Centre (int direction)
109{
2d120f83 110 int x, y, width, height, panel_width, panel_height, new_x, new_y;
dfe1eee3 111
2d120f83
JS
112 wxWindow *parent = (wxWindow *) GetParent ();
113 if (!parent)
114 return;
dfe1eee3 115
2d120f83
JS
116 parent->GetClientSize (&panel_width, &panel_height);
117 GetSize (&width, &height);
118 GetPosition (&x, &y);
dfe1eee3 119
2d120f83
JS
120 new_x = x;
121 new_y = y;
dfe1eee3 122
2d120f83
JS
123 if (direction & wxHORIZONTAL)
124 new_x = (int) ((panel_width - width) / 2);
dfe1eee3 125
2d120f83
JS
126 if (direction & wxVERTICAL)
127 new_y = (int) ((panel_height - height) / 2);
dfe1eee3 128
2d120f83 129 SetSize (new_x, new_y, width, height);
4bb6408c
JS
130}
131