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