]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
7520f3da | 2 | // Name: src/motif/statbmp.cpp |
4bb6408c JS |
3 | // Purpose: wxStaticBitmap |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
4bb6408c | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
4bb6408c JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
1248b41f MB |
11 | // For compilers that support precompilation, includes "wx.h". |
12 | #include "wx/wxprec.h" | |
13 | ||
4bb6408c JS |
14 | #include "wx/statbmp.h" |
15 | ||
338dd992 JJ |
16 | #ifdef __VMS__ |
17 | #pragma message disable nosimpint | |
18 | #endif | |
a4294b78 JS |
19 | #include <Xm/Xm.h> |
20 | #include <Xm/Label.h> | |
21 | #include <Xm/LabelG.h> | |
338dd992 JJ |
22 | #ifdef __VMS__ |
23 | #pragma message enable nosimpint | |
24 | #endif | |
a4294b78 | 25 | |
3096bd2f | 26 | #include "wx/motif/private.h" |
a4294b78 | 27 | |
4bb6408c JS |
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 | { | |
9a595736 MB |
39 | if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, |
40 | name ) ) | |
41 | return false; | |
105fbe1f | 42 | PreCreation(); |
9a595736 | 43 | |
4bb6408c | 44 | m_messageBitmap = bitmap; |
7af68c66 | 45 | m_messageBitmapOriginal = bitmap; |
4bb6408c | 46 | |
a4294b78 JS |
47 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
48 | ||
49 | m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap", | |
8c624a14 | 50 | #if wxUSE_GADGETS |
a4294b78 JS |
51 | xmLabelGadgetClass, parentWidget, |
52 | #else | |
53 | xmLabelWidgetClass, parentWidget, | |
54 | #endif | |
55 | XmNalignment, XmALIGNMENT_BEGINNING, | |
56 | NULL); | |
57 | ||
dc1efb1d | 58 | wxSize actualSize(size); |
7af68c66 | 59 | // work around the cases where the bitmap is a wxNull(Icon/Bitmap) |
dc1efb1d | 60 | if (actualSize.x == -1) |
a1b806b9 | 61 | actualSize.x = bitmap.IsOk() ? bitmap.GetWidth() : 1; |
dc1efb1d | 62 | if (actualSize.y == -1) |
a1b806b9 | 63 | actualSize.y = bitmap.IsOk() ? bitmap.GetHeight() : 1; |
105fbe1f MB |
64 | |
65 | PostCreation(); | |
66 | DoSetBitmap(); | |
9a595736 MB |
67 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, |
68 | pos.x, pos.y, actualSize.x, actualSize.y); | |
a4294b78 | 69 | |
9a595736 | 70 | return true; |
a4294b78 JS |
71 | } |
72 | ||
73 | wxStaticBitmap::~wxStaticBitmap() | |
74 | { | |
75 | SetBitmap(wxNullBitmap); | |
4bb6408c JS |
76 | } |
77 | ||
7af68c66 | 78 | void wxStaticBitmap::DoSetBitmap() |
4bb6408c | 79 | { |
a4294b78 | 80 | Widget widget = (Widget) m_mainWidget; |
c8ec0b3d | 81 | int w2, h2; |
a4294b78 | 82 | |
a1b806b9 | 83 | if (m_messageBitmapOriginal.IsOk()) |
a4294b78 | 84 | { |
7af68c66 MB |
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 | { | |
3e0071d9 | 94 | WXPixel backgroundPixel; |
7af68c66 MB |
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 | ||
aae0472b | 104 | pixmap = (Pixmap) m_messageBitmap.GetDrawable(); |
7af68c66 MB |
105 | } |
106 | else | |
aae91497 MB |
107 | { |
108 | m_bitmapCache.SetBitmap( m_messageBitmap ); | |
109 | pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget); | |
110 | } | |
7af68c66 | 111 | |
a4294b78 | 112 | XtVaSetValues (widget, |
7af68c66 | 113 | XmNlabelPixmap, pixmap, |
a4294b78 | 114 | XmNlabelType, XmPIXMAP, |
31528cd3 | 115 | NULL); |
a4294b78 | 116 | |
c8ec0b3d | 117 | SetSize(w2, h2); |
a4294b78 JS |
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, | |
1a3ac83f | 125 | XmNlabelPixmap, XmUNSPECIFIED_PIXMAP, |
a4294b78 | 126 | NULL); |
7520f3da | 127 | } |
7af68c66 MB |
128 | } |
129 | ||
130 | void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) | |
131 | { | |
132 | m_messageBitmap = bitmap; | |
133 | m_messageBitmapOriginal = bitmap; | |
134 | ||
135 | DoSetBitmap(); | |
4bb6408c JS |
136 | } |
137 | ||
0d57be45 JS |
138 | void wxStaticBitmap::ChangeBackgroundColour() |
139 | { | |
321db4b6 | 140 | wxWindow::ChangeBackgroundColour(); |
7af68c66 MB |
141 | |
142 | // must recalculate the background colour | |
aae91497 | 143 | m_bitmapCache.SetColoursChanged(); |
7af68c66 | 144 | DoSetBitmap(); |
0d57be45 JS |
145 | } |
146 | ||
147 | void wxStaticBitmap::ChangeForegroundColour() | |
148 | { | |
aae91497 | 149 | m_bitmapCache.SetColoursChanged(); |
321db4b6 | 150 | wxWindow::ChangeForegroundColour(); |
0d57be45 | 151 | } |