]> git.saurik.com Git - wxWidgets.git/blame - src/motif/statbmp.cpp
* Apply patch #735595. Add miminumAcceptable{Height,Width}
[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>
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)
7af68c66 72 actualSize.x = bitmap.GetWidth() ? bitmap.GetWidth() : 1;
dc1efb1d 73 if (actualSize.y == -1)
7af68c66 74 actualSize.y = bitmap.GetHeight() ? 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
JS
88 Widget widget = (Widget) m_mainWidget;
89 int x, y, w1, h1, w2, h2;
90
91 GetPosition(&x, &y);
92
7af68c66 93 if (m_messageBitmapOriginal.Ok())
a4294b78 94 {
7af68c66
MB
95 w2 = m_messageBitmapOriginal.GetWidth();
96 h2 = m_messageBitmapOriginal.GetHeight();
97
98 Pixmap pixmap;
99
100 // Must re-make the bitmap to have its transparent areas drawn
101 // in the current widget background colour.
102 if (m_messageBitmapOriginal.GetMask())
103 {
104 int backgroundPixel;
105 XtVaGetValues( widget, XmNbackground, &backgroundPixel,
106 NULL);
107
108 wxColour col;
109 col.SetPixel(backgroundPixel);
110
111 wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
112 m_messageBitmap = newBitmap;
113
aae0472b 114 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
7af68c66
MB
115 }
116 else
aae91497
MB
117 {
118 m_bitmapCache.SetBitmap( m_messageBitmap );
119 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
120 }
7af68c66 121
a4294b78 122 XtVaSetValues (widget,
7af68c66 123 XmNlabelPixmap, pixmap,
a4294b78 124 XmNlabelType, XmPIXMAP,
31528cd3 125 NULL);
a4294b78
JS
126 GetSize(&w1, &h1);
127
128 if (! (w1 == w2) && (h1 == h2))
129 SetSize(x, y, w2, h2);
130 }
131 else
132 {
133 // Null bitmap: must not use current pixmap
134 // since it is no longer valid.
135 XtVaSetValues (widget,
136 XmNlabelType, XmSTRING,
1a3ac83f 137 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
a4294b78 138 NULL);
7af68c66
MB
139 }
140}
141
142void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
143{
144 m_messageBitmap = bitmap;
145 m_messageBitmapOriginal = bitmap;
146
147 DoSetBitmap();
4bb6408c
JS
148}
149
0d57be45
JS
150void wxStaticBitmap::ChangeBackgroundColour()
151{
321db4b6 152 wxWindow::ChangeBackgroundColour();
7af68c66
MB
153
154 // must recalculate the background colour
aae91497 155 m_bitmapCache.SetColoursChanged();
7af68c66 156 DoSetBitmap();
0d57be45
JS
157}
158
159void wxStaticBitmap::ChangeForegroundColour()
160{
aae91497 161 m_bitmapCache.SetColoursChanged();
321db4b6 162 wxWindow::ChangeForegroundColour();
0d57be45
JS
163}
164