]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbmp.cpp
Allow 2-step creation of wxGenericProgressDialog.
[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
JS
29/*
30 * wxStaticBitmap
31 */
32
33bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
34 const wxBitmap& bitmap,
35 const wxPoint& pos,
36 const wxSize& size,
37 long style,
38 const wxString& name)
39{
9a595736
MB
40 if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
41 name ) )
42 return false;
105fbe1f 43 PreCreation();
9a595736 44
4bb6408c 45 m_messageBitmap = bitmap;
7af68c66 46 m_messageBitmapOriginal = bitmap;
4bb6408c 47
a4294b78
JS
48 Widget parentWidget = (Widget) parent->GetClientWidget();
49
50 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap",
8c624a14 51#if wxUSE_GADGETS
a4294b78
JS
52 xmLabelGadgetClass, parentWidget,
53#else
54 xmLabelWidgetClass, parentWidget,
55#endif
56 XmNalignment, XmALIGNMENT_BEGINNING,
57 NULL);
58
dc1efb1d 59 wxSize actualSize(size);
7af68c66 60 // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
dc1efb1d 61 if (actualSize.x == -1)
a1b806b9 62 actualSize.x = bitmap.IsOk() ? bitmap.GetWidth() : 1;
dc1efb1d 63 if (actualSize.y == -1)
a1b806b9 64 actualSize.y = bitmap.IsOk() ? bitmap.GetHeight() : 1;
105fbe1f
MB
65
66 PostCreation();
67 DoSetBitmap();
9a595736
MB
68 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
69 pos.x, pos.y, actualSize.x, actualSize.y);
a4294b78 70
9a595736 71 return true;
a4294b78
JS
72}
73
74wxStaticBitmap::~wxStaticBitmap()
75{
76 SetBitmap(wxNullBitmap);
4bb6408c
JS
77}
78
7af68c66 79void wxStaticBitmap::DoSetBitmap()
4bb6408c 80{
a4294b78 81 Widget widget = (Widget) m_mainWidget;
c8ec0b3d 82 int w2, h2;
a4294b78 83
a1b806b9 84 if (m_messageBitmapOriginal.IsOk())
a4294b78 85 {
7af68c66
MB
86 w2 = m_messageBitmapOriginal.GetWidth();
87 h2 = m_messageBitmapOriginal.GetHeight();
88
89 Pixmap pixmap;
90
91 // Must re-make the bitmap to have its transparent areas drawn
92 // in the current widget background colour.
93 if (m_messageBitmapOriginal.GetMask())
94 {
3e0071d9 95 WXPixel backgroundPixel;
7af68c66
MB
96 XtVaGetValues( widget, XmNbackground, &backgroundPixel,
97 NULL);
98
99 wxColour col;
100 col.SetPixel(backgroundPixel);
101
102 wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
103 m_messageBitmap = newBitmap;
104
aae0472b 105 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
7af68c66
MB
106 }
107 else
aae91497
MB
108 {
109 m_bitmapCache.SetBitmap( m_messageBitmap );
110 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
111 }
7af68c66 112
a4294b78 113 XtVaSetValues (widget,
7af68c66 114 XmNlabelPixmap, pixmap,
a4294b78 115 XmNlabelType, XmPIXMAP,
31528cd3 116 NULL);
a4294b78 117
c8ec0b3d 118 SetSize(w2, h2);
a4294b78
JS
119 }
120 else
121 {
122 // Null bitmap: must not use current pixmap
123 // since it is no longer valid.
124 XtVaSetValues (widget,
125 XmNlabelType, XmSTRING,
1a3ac83f 126 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
a4294b78 127 NULL);
7520f3da 128 }
7af68c66
MB
129}
130
131void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
132{
133 m_messageBitmap = bitmap;
134 m_messageBitmapOriginal = bitmap;
135
136 DoSetBitmap();
4bb6408c
JS
137}
138
0d57be45
JS
139void wxStaticBitmap::ChangeBackgroundColour()
140{
321db4b6 141 wxWindow::ChangeBackgroundColour();
7af68c66
MB
142
143 // must recalculate the background colour
aae91497 144 m_bitmapCache.SetColoursChanged();
7af68c66 145 DoSetBitmap();
0d57be45
JS
146}
147
148void wxStaticBitmap::ChangeForegroundColour()
149{
aae91497 150 m_bitmapCache.SetColoursChanged();
321db4b6 151 wxWindow::ChangeForegroundColour();
0d57be45 152}