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