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