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