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