]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbmp.cpp
Applied patch [ 602924 ] colours and effects in wxMSW::wxFontDialog
[wxWidgets.git] / src / motif / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbmp.cpp
3 // Purpose: wxStaticBitmap
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 "statbmp.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/statbmp.h"
19
20 #ifdef __VMS__
21 #pragma message disable nosimpint
22 #endif
23 #include <Xm/Xm.h>
24 #include <Xm/Label.h>
25 #include <Xm/LabelG.h>
26 #include <Xm/RowColumn.h>
27 #ifdef __VMS__
28 #pragma message enable nosimpint
29 #endif
30
31 #include "wx/motif/private.h"
32
33 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
34
35 /*
36 * wxStaticBitmap
37 */
38
39 bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
40 const wxBitmap& bitmap,
41 const wxPoint& pos,
42 const wxSize& size,
43 long style,
44 const wxString& name)
45 {
46 m_messageBitmap = bitmap;
47 m_messageBitmapOriginal = bitmap;
48 SetName(name);
49 m_backgroundColour = parent->GetBackgroundColour();
50 m_foregroundColour = parent->GetForegroundColour();
51 if (parent) parent->AddChild(this);
52
53 if ( id == -1 )
54 m_windowId = (int)NewControlId();
55 else
56 m_windowId = id;
57
58 m_windowStyle = style;
59
60 Widget parentWidget = (Widget) parent->GetClientWidget();
61
62 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap",
63 #if USE_GADGETS
64 xmLabelGadgetClass, parentWidget,
65 #else
66 xmLabelWidgetClass, parentWidget,
67 #endif
68 XmNalignment, XmALIGNMENT_BEGINNING,
69 NULL);
70
71 ChangeBackgroundColour ();
72
73 DoSetBitmap();
74
75 m_font = parent->GetFont();
76 ChangeFont(FALSE);
77
78 SetCanAddEventHandler(TRUE);
79
80 wxSize actualSize(size);
81 // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
82 if (actualSize.x == -1)
83 actualSize.x = bitmap.GetWidth() ? bitmap.GetWidth() : 1;
84 if (actualSize.y == -1)
85 actualSize.y = bitmap.GetHeight() ? bitmap.GetHeight() : 1;
86 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, actualSize.x, actualSize.y);
87
88 return TRUE;
89 }
90
91 wxStaticBitmap::~wxStaticBitmap()
92 {
93 SetBitmap(wxNullBitmap);
94 }
95
96 void wxStaticBitmap::DoSetBitmap()
97 {
98 Widget widget = (Widget) m_mainWidget;
99 int x, y, w1, h1, w2, h2;
100
101 GetPosition(&x, &y);
102
103 if (m_messageBitmapOriginal.Ok())
104 {
105 w2 = m_messageBitmapOriginal.GetWidth();
106 h2 = m_messageBitmapOriginal.GetHeight();
107
108 Pixmap pixmap;
109
110 // Must re-make the bitmap to have its transparent areas drawn
111 // in the current widget background colour.
112 if (m_messageBitmapOriginal.GetMask())
113 {
114 int backgroundPixel;
115 XtVaGetValues( widget, XmNbackground, &backgroundPixel,
116 NULL);
117
118 wxColour col;
119 col.SetPixel(backgroundPixel);
120
121 wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
122 m_messageBitmap = newBitmap;
123
124 pixmap = (Pixmap) m_messageBitmap.GetPixmap();
125 }
126 else
127 pixmap = (Pixmap) m_messageBitmap.GetLabelPixmap(widget);
128
129 XtVaSetValues (widget,
130 XmNlabelPixmap, pixmap,
131 XmNlabelType, XmPIXMAP,
132 NULL);
133 GetSize(&w1, &h1);
134
135 if (! (w1 == w2) && (h1 == h2))
136 SetSize(x, y, w2, h2);
137 }
138 else
139 {
140 // Null bitmap: must not use current pixmap
141 // since it is no longer valid.
142 XtVaSetValues (widget,
143 XmNlabelType, XmSTRING,
144 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
145 NULL);
146 }
147 }
148
149 void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
150 {
151 m_messageBitmap = bitmap;
152 m_messageBitmapOriginal = bitmap;
153
154 DoSetBitmap();
155 }
156
157 void wxStaticBitmap::ChangeFont(bool keepOriginalSize)
158 {
159 wxWindow::ChangeFont(keepOriginalSize);
160 }
161
162 void wxStaticBitmap::ChangeBackgroundColour()
163 {
164 wxWindow::ChangeBackgroundColour();
165
166 // must recalculate the background colour
167 DoSetBitmap();
168 }
169
170 void wxStaticBitmap::ChangeForegroundColour()
171 {
172 wxWindow::ChangeForegroundColour();
173 }
174