]> git.saurik.com Git - wxWidgets.git/blame_incremental - 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
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/motif/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// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#include "wx/statbmp.h"
16
17#ifdef __VMS__
18#pragma message disable nosimpint
19#endif
20#include <Xm/Xm.h>
21#include <Xm/Label.h>
22#include <Xm/LabelG.h>
23#ifdef __VMS__
24#pragma message enable nosimpint
25#endif
26
27#include "wx/motif/private.h"
28
29IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
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{
42 if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
43 name ) )
44 return false;
45 PreCreation();
46
47 m_messageBitmap = bitmap;
48 m_messageBitmapOriginal = bitmap;
49
50 Widget parentWidget = (Widget) parent->GetClientWidget();
51
52 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap",
53#if wxUSE_GADGETS
54 xmLabelGadgetClass, parentWidget,
55#else
56 xmLabelWidgetClass, parentWidget,
57#endif
58 XmNalignment, XmALIGNMENT_BEGINNING,
59 NULL);
60
61 wxSize actualSize(size);
62 // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
63 if (actualSize.x == -1)
64 actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1;
65 if (actualSize.y == -1)
66 actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1;
67
68 PostCreation();
69 DoSetBitmap();
70 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
71 pos.x, pos.y, actualSize.x, actualSize.y);
72
73 return true;
74}
75
76wxStaticBitmap::~wxStaticBitmap()
77{
78 SetBitmap(wxNullBitmap);
79}
80
81void wxStaticBitmap::DoSetBitmap()
82{
83 Widget widget = (Widget) m_mainWidget;
84 int w2, h2;
85
86 if (m_messageBitmapOriginal.Ok())
87 {
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 {
97 WXPixel backgroundPixel;
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
107 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
108 }
109 else
110 {
111 m_bitmapCache.SetBitmap( m_messageBitmap );
112 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
113 }
114
115 XtVaSetValues (widget,
116 XmNlabelPixmap, pixmap,
117 XmNlabelType, XmPIXMAP,
118 NULL);
119
120 SetSize(w2, h2);
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,
128 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
129 NULL);
130 }
131}
132
133void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
134{
135 m_messageBitmap = bitmap;
136 m_messageBitmapOriginal = bitmap;
137
138 DoSetBitmap();
139}
140
141void wxStaticBitmap::ChangeBackgroundColour()
142{
143 wxWindow::ChangeBackgroundColour();
144
145 // must recalculate the background colour
146 m_bitmapCache.SetColoursChanged();
147 DoSetBitmap();
148}
149
150void wxStaticBitmap::ChangeForegroundColour()
151{
152 m_bitmapCache.SetColoursChanged();
153 wxWindow::ChangeForegroundColour();
154}