]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: stattext.cpp | |
3 | // Purpose: wxStaticText | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "stattext.h" | |
14 | #endif | |
15 | ||
16 | #ifdef __VMS | |
17 | #define XtDisplay XTDISPLAY | |
18 | #endif | |
19 | ||
20 | #include "wx/app.h" | |
21 | #include "wx/stattext.h" | |
22 | ||
23 | #include <stdio.h> | |
24 | ||
25 | #ifdef __VMS__ | |
26 | #pragma message disable nosimpint | |
27 | #endif | |
28 | #include <Xm/Frame.h> | |
29 | #include <Xm/Label.h> | |
30 | #include <Xm/LabelG.h> | |
31 | #include <Xm/PushBG.h> | |
32 | #ifdef __VMS__ | |
33 | #pragma message enable nosimpint | |
34 | #endif | |
35 | ||
36 | IMPLEMENT_DYNAMIC_CLASS(wxStaticText, wxControl) | |
37 | ||
38 | bool wxStaticText::Create(wxWindow *parent, wxWindowID id, | |
39 | const wxString& label, | |
40 | const wxPoint& pos, | |
41 | const wxSize& size, | |
42 | long style, | |
43 | const wxString& name) | |
44 | { | |
45 | SetName(name); | |
46 | if (parent) parent->AddChild(this); | |
47 | ||
48 | m_backgroundColour = parent->GetBackgroundColour(); | |
49 | m_foregroundColour = parent->GetForegroundColour(); | |
50 | ||
51 | if ( id == -1 ) | |
52 | m_windowId = (int)NewControlId(); | |
53 | else | |
54 | m_windowId = id; | |
55 | ||
56 | m_windowStyle = style; | |
57 | m_font = parent->GetFont(); | |
58 | ||
59 | #if 0 // gcc 2.95 doesn't like this apparently | |
60 | char* label1 = (label.IsNull() ? "" : (char*) (const char*) label); | |
61 | #endif | |
62 | ||
63 | Widget parentWidget = (Widget) parent->GetClientWidget(); | |
64 | ||
65 | Widget borderWidget = NULL; | |
66 | ||
67 | // Decorate the label widget if a border style is specified. | |
68 | if (style & wxSIMPLE_BORDER) | |
69 | { | |
70 | borderWidget = XtVaCreateManagedWidget | |
71 | ( | |
72 | "simpleBorder", | |
73 | xmFrameWidgetClass, parentWidget, | |
74 | XmNshadowType, XmSHADOW_ETCHED_IN, | |
75 | XmNshadowThickness, 1, | |
76 | NULL | |
77 | ); | |
78 | } else if (style & wxSUNKEN_BORDER) | |
79 | { | |
80 | borderWidget = XtVaCreateManagedWidget | |
81 | ( | |
82 | "sunkenBorder", | |
83 | xmFrameWidgetClass, parentWidget, | |
84 | XmNshadowType, XmSHADOW_IN, | |
85 | NULL | |
86 | ); | |
87 | } else if (style & wxRAISED_BORDER) | |
88 | { | |
89 | borderWidget = XtVaCreateManagedWidget | |
90 | ( | |
91 | "raisedBorder", | |
92 | xmFrameWidgetClass, parentWidget, | |
93 | XmNshadowType, XmSHADOW_OUT, | |
94 | NULL | |
95 | ); | |
96 | } | |
97 | ||
98 | #if 0 // gcc 2.95 doesn't like this apparently | |
99 | // Use XmStringCreateLtoR(), since XmStringCreateSimple | |
100 | // doesn't obey separators. | |
101 | // XmString text = XmStringCreateSimple (label1); | |
102 | XmString text = XmStringCreateLtoR (label1, XmSTRING_DEFAULT_CHARSET); | |
103 | #endif // 0 | |
104 | ||
105 | XmString text = XmStringCreateLtoR ((char *)(const char*)label, XmSTRING_DEFAULT_CHARSET); | |
106 | ||
107 | XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget)); | |
108 | ||
109 | Widget labelWidget = XtVaCreateManagedWidget ((char*) (const char*) name, | |
110 | xmLabelWidgetClass, | |
111 | borderWidget ? borderWidget : parentWidget, | |
112 | XmNfontList, fontList, | |
113 | XmNlabelString, text, | |
114 | XmNalignment, | |
115 | ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END : | |
116 | ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER : | |
117 | XmALIGNMENT_BEGINNING)), | |
118 | NULL); | |
119 | ||
120 | XmStringFree (text); | |
121 | ||
122 | m_mainWidget = borderWidget ? borderWidget : labelWidget; | |
123 | ||
124 | SetCanAddEventHandler(TRUE); | |
125 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); | |
126 | ||
127 | ChangeBackgroundColour (); | |
128 | ||
129 | return TRUE; | |
130 | } | |
131 | ||
132 | void wxStaticText::ChangeFont(bool keepOriginalSize) | |
133 | { | |
134 | wxWindow::ChangeFont(keepOriginalSize); | |
135 | } | |
136 | ||
137 | void wxStaticText::ChangeBackgroundColour() | |
138 | { | |
139 | wxWindow::ChangeBackgroundColour(); | |
140 | } | |
141 | ||
142 | void wxStaticText::ChangeForegroundColour() | |
143 | { | |
144 | wxWindow::ChangeForegroundColour(); | |
145 | } | |
146 |