]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbmp.cpp
Added wxDC::GetPartialTextExtents
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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.Ok() ? bitmap.GetWidth() : 1;
73 if (actualSize.y == -1)
74 actualSize.y = bitmap.Ok() ? 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 w2, h2;
90
91 if (m_messageBitmapOriginal.Ok())
92 {
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
112 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
113 }
114 else
115 {
116 m_bitmapCache.SetBitmap( m_messageBitmap );
117 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
118 }
119
120 XtVaSetValues (widget,
121 XmNlabelPixmap, pixmap,
122 XmNlabelType, XmPIXMAP,
123 NULL);
124
125 SetSize(w2, h2);
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,
133 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
134 NULL);
135 }
136 }
137
138 void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
139 {
140 m_messageBitmap = bitmap;
141 m_messageBitmapOriginal = bitmap;
142
143 DoSetBitmap();
144 }
145
146 void wxStaticBitmap::ChangeBackgroundColour()
147 {
148 wxWindow::ChangeBackgroundColour();
149
150 // must recalculate the background colour
151 m_bitmapCache.SetColoursChanged();
152 DoSetBitmap();
153 }
154
155 void wxStaticBitmap::ChangeForegroundColour()
156 {
157 m_bitmapCache.SetColoursChanged();
158 wxWindow::ChangeForegroundColour();
159 }
160