]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbmp.cpp
Correct wxCommandEvent.IsChecked() when generated from
[wxWidgets.git] / src / motif / statbmp.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "statbmp.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/statbmp.h"
19
20 #ifdef __VMS__
21 #pragma message disable nosimpint
22 #endif
23 #include <Xm/Xm.h>
24 #include <Xm/Label.h>
25 #include <Xm/LabelG.h>
26 #ifdef __VMS__
27 #pragma message enable nosimpint
28 #endif
29
30 #include "wx/motif/private.h"
31
32 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap, wxControl)
33
34 /*
35 * wxStaticBitmap
36 */
37
38 bool 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 {
45 if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
46 name ) )
47 return false;
48
49 m_messageBitmap = bitmap;
50 m_messageBitmapOriginal = bitmap;
51
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
63 ChangeBackgroundColour ();
64
65 DoSetBitmap();
66
67 ChangeFont(FALSE);
68
69 wxSize actualSize(size);
70 // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
71 if (actualSize.x == -1)
72 actualSize.x = bitmap.GetWidth() ? bitmap.GetWidth() : 1;
73 if (actualSize.y == -1)
74 actualSize.y = bitmap.GetHeight() ? bitmap.GetHeight() : 1;
75 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
76 pos.x, pos.y, actualSize.x, actualSize.y);
77
78 return true;
79 }
80
81 wxStaticBitmap::~wxStaticBitmap()
82 {
83 SetBitmap(wxNullBitmap);
84 }
85
86 void wxStaticBitmap::DoSetBitmap()
87 {
88 Widget widget = (Widget) m_mainWidget;
89 int x, y, w1, h1, w2, h2;
90
91 GetPosition(&x, &y);
92
93 if (m_messageBitmapOriginal.Ok())
94 {
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
114 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
115 }
116 else
117 {
118 m_bitmapCache.SetBitmap( m_messageBitmap );
119 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
120 }
121
122 XtVaSetValues (widget,
123 XmNlabelPixmap, pixmap,
124 XmNlabelType, XmPIXMAP,
125 NULL);
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,
137 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
138 NULL);
139 }
140 }
141
142 void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
143 {
144 m_messageBitmap = bitmap;
145 m_messageBitmapOriginal = bitmap;
146
147 DoSetBitmap();
148 }
149
150 void wxStaticBitmap::ChangeBackgroundColour()
151 {
152 wxWindow::ChangeBackgroundColour();
153
154 // must recalculate the background colour
155 m_bitmapCache.SetColoursChanged();
156 DoSetBitmap();
157 }
158
159 void wxStaticBitmap::ChangeForegroundColour()
160 {
161 m_bitmapCache.SetColoursChanged();
162 wxWindow::ChangeForegroundColour();
163 }
164