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