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