]> git.saurik.com Git - wxWidgets.git/blame - src/motif/control.cpp
why cvs thinks that I modified these files?
[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
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
22IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
23
24BEGIN_EVENT_TABLE(wxControl, wxWindow)
25END_EVENT_TABLE()
26#endif
27
28// Item members
29wxControl::wxControl()
30{
31 m_backgroundColour = *wxWHITE;
32 m_foregroundColour = *wxBLACK;
33 m_callback = 0;
a4294b78 34 m_inSetValue = FALSE;
4bb6408c
JS
35}
36
37wxControl::~wxControl()
38{
39 // If we delete an item, we should initialize the parent panel,
40 // because it could now be invalid.
da175b2c
RR
41/*
42 TODO
4bb6408c
JS
43 wxWindow *parent = (wxWindow *)GetParent();
44 if (parent)
45 {
46 if (parent->GetDefaultItem() == (wxButton*) this)
cba2db0c 47 parent->SetDefaultItem((wxButton*) NULL);
4bb6408c 48 }
da175b2c 49*/
4bb6408c
JS
50}
51
52void wxControl::SetLabel(const wxString& label)
53{
a4294b78
JS
54 Widget widget = (Widget) GetLabelWidget() ;
55 if (!widget)
56 return;
2d120f83 57
a4294b78 58 wxStripMenuCodes((char*) (const char*) label, wxBuffer);
2d120f83 59
a4294b78
JS
60 XmString text = XmStringCreateSimple (wxBuffer);
61 XtVaSetValues (widget,
2d120f83
JS
62 XmNlabelString, text,
63 XmNlabelType, XmSTRING,
64 NULL);
a4294b78 65 XmStringFree (text);
4bb6408c
JS
66}
67
68wxString wxControl::GetLabel() const
69{
a4294b78
JS
70 Widget widget = (Widget) GetLabelWidget() ;
71 if (!widget)
72 return wxEmptyString;
2d120f83 73
a4294b78
JS
74 XmString text;
75 char *s;
76 XtVaGetValues (widget,
2d120f83
JS
77 XmNlabelString, &text,
78 NULL);
79
a4294b78 80 if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
02e8b2f9 81 {
a4294b78
JS
82 wxString str(s);
83 XtFree (s);
84 XmStringFree(text);
85 return str;
02e8b2f9 86 }
a4294b78 87 else
02e8b2f9 88 {
15d5ab67 89 // XmStringFree(text);
a4294b78 90 return wxEmptyString;
02e8b2f9 91 }
4bb6408c
JS
92}
93
94void wxControl::ProcessCommand (wxCommandEvent & event)
95{
2d120f83
JS
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)
4bb6408c 101 {
2d120f83 102 (void) (*(m_callback)) (*this, event);
4bb6408c
JS
103 }
104 else
105 {
2d120f83 106 GetEventHandler()->OnCommand(*this, event);
4bb6408c
JS
107 }
108}
109
110void wxControl::Centre (int direction)
111{
2d120f83
JS
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);
4bb6408c
JS
132}
133