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