]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
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 | |
31528cd3 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
4bb6408c JS |
13 | #pragma implementation "statbmp.h" |
14 | #endif | |
15 | ||
1248b41f MB |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
f6045f99 GD |
19 | #include "wx/defs.h" |
20 | ||
4bb6408c JS |
21 | #include "wx/statbmp.h" |
22 | ||
338dd992 JJ |
23 | #ifdef __VMS__ |
24 | #pragma message disable nosimpint | |
25 | #endif | |
a4294b78 JS |
26 | #include <Xm/Xm.h> |
27 | #include <Xm/Label.h> | |
28 | #include <Xm/LabelG.h> | |
338dd992 JJ |
29 | #ifdef __VMS__ |
30 | #pragma message enable nosimpint | |
31 | #endif | |
a4294b78 | 32 | |
3096bd2f | 33 | #include "wx/motif/private.h" |
a4294b78 | 34 | |
4bb6408c | 35 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl) |
4bb6408c JS |
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 | { | |
9a595736 MB |
48 | if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, |
49 | name ) ) | |
50 | return false; | |
51 | ||
4bb6408c | 52 | m_messageBitmap = bitmap; |
7af68c66 | 53 | m_messageBitmapOriginal = bitmap; |
4bb6408c | 54 | |
a4294b78 JS |
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 | ||
7af68c66 MB |
66 | ChangeBackgroundColour (); |
67 | ||
68 | DoSetBitmap(); | |
a4294b78 | 69 | |
4b5f3fe6 JS |
70 | ChangeFont(FALSE); |
71 | ||
dc1efb1d | 72 | wxSize actualSize(size); |
7af68c66 | 73 | // work around the cases where the bitmap is a wxNull(Icon/Bitmap) |
dc1efb1d | 74 | if (actualSize.x == -1) |
c8ec0b3d | 75 | actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1; |
dc1efb1d | 76 | if (actualSize.y == -1) |
c8ec0b3d | 77 | actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1; |
9a595736 MB |
78 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, |
79 | pos.x, pos.y, actualSize.x, actualSize.y); | |
a4294b78 | 80 | |
9a595736 | 81 | return true; |
a4294b78 JS |
82 | } |
83 | ||
84 | wxStaticBitmap::~wxStaticBitmap() | |
85 | { | |
86 | SetBitmap(wxNullBitmap); | |
4bb6408c JS |
87 | } |
88 | ||
7af68c66 | 89 | void wxStaticBitmap::DoSetBitmap() |
4bb6408c | 90 | { |
a4294b78 | 91 | Widget widget = (Widget) m_mainWidget; |
c8ec0b3d | 92 | int w2, h2; |
a4294b78 | 93 | |
7af68c66 | 94 | if (m_messageBitmapOriginal.Ok()) |
a4294b78 | 95 | { |
7af68c66 MB |
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 | ||
aae0472b | 115 | pixmap = (Pixmap) m_messageBitmap.GetDrawable(); |
7af68c66 MB |
116 | } |
117 | else | |
aae91497 MB |
118 | { |
119 | m_bitmapCache.SetBitmap( m_messageBitmap ); | |
120 | pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget); | |
121 | } | |
7af68c66 | 122 | |
a4294b78 | 123 | XtVaSetValues (widget, |
7af68c66 | 124 | XmNlabelPixmap, pixmap, |
a4294b78 | 125 | XmNlabelType, XmPIXMAP, |
31528cd3 | 126 | NULL); |
a4294b78 | 127 | |
c8ec0b3d | 128 | SetSize(w2, h2); |
a4294b78 JS |
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, | |
1a3ac83f | 136 | XmNlabelPixmap, XmUNSPECIFIED_PIXMAP, |
a4294b78 | 137 | NULL); |
7af68c66 MB |
138 | } |
139 | } | |
140 | ||
141 | void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap) | |
142 | { | |
143 | m_messageBitmap = bitmap; | |
144 | m_messageBitmapOriginal = bitmap; | |
145 | ||
146 | DoSetBitmap(); | |
4bb6408c JS |
147 | } |
148 | ||
0d57be45 JS |
149 | void wxStaticBitmap::ChangeBackgroundColour() |
150 | { | |
321db4b6 | 151 | wxWindow::ChangeBackgroundColour(); |
7af68c66 MB |
152 | |
153 | // must recalculate the background colour | |
aae91497 | 154 | m_bitmapCache.SetColoursChanged(); |
7af68c66 | 155 | DoSetBitmap(); |
0d57be45 JS |
156 | } |
157 | ||
158 | void wxStaticBitmap::ChangeForegroundColour() | |
159 | { | |
aae91497 | 160 | m_bitmapCache.SetColoursChanged(); |
321db4b6 | 161 | wxWindow::ChangeForegroundColour(); |
0d57be45 JS |
162 | } |
163 |