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