]> git.saurik.com Git - wxWidgets.git/blob - src/motif/statbmp.cpp
Use "<Application> Preferences" as generic wxPreferencesEditor dialog title.
[wxWidgets.git] / src / motif / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/statbmp.h"
16
17 #ifdef __VMS__
18 #pragma message disable nosimpint
19 #endif
20 #include <Xm/Xm.h>
21 #include <Xm/Label.h>
22 #include <Xm/LabelG.h>
23 #ifdef __VMS__
24 #pragma message enable nosimpint
25 #endif
26
27 #include "wx/motif/private.h"
28
29 /*
30 * wxStaticBitmap
31 */
32
33 bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
34 const wxBitmap& bitmap,
35 const wxPoint& pos,
36 const wxSize& size,
37 long style,
38 const wxString& name)
39 {
40 if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
41 name ) )
42 return false;
43 PreCreation();
44
45 m_messageBitmap = bitmap;
46 m_messageBitmapOriginal = bitmap;
47
48 Widget parentWidget = (Widget) parent->GetClientWidget();
49
50 m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("staticBitmap",
51 #if wxUSE_GADGETS
52 xmLabelGadgetClass, parentWidget,
53 #else
54 xmLabelWidgetClass, parentWidget,
55 #endif
56 XmNalignment, XmALIGNMENT_BEGINNING,
57 NULL);
58
59 wxSize actualSize(size);
60 // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
61 if (actualSize.x == -1)
62 actualSize.x = bitmap.IsOk() ? bitmap.GetWidth() : 1;
63 if (actualSize.y == -1)
64 actualSize.y = bitmap.IsOk() ? bitmap.GetHeight() : 1;
65
66 PostCreation();
67 DoSetBitmap();
68 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
69 pos.x, pos.y, actualSize.x, actualSize.y);
70
71 return true;
72 }
73
74 wxStaticBitmap::~wxStaticBitmap()
75 {
76 SetBitmap(wxNullBitmap);
77 }
78
79 void wxStaticBitmap::DoSetBitmap()
80 {
81 Widget widget = (Widget) m_mainWidget;
82 int w2, h2;
83
84 if (m_messageBitmapOriginal.IsOk())
85 {
86 w2 = m_messageBitmapOriginal.GetWidth();
87 h2 = m_messageBitmapOriginal.GetHeight();
88
89 Pixmap pixmap;
90
91 // Must re-make the bitmap to have its transparent areas drawn
92 // in the current widget background colour.
93 if (m_messageBitmapOriginal.GetMask())
94 {
95 WXPixel backgroundPixel;
96 XtVaGetValues( widget, XmNbackground, &backgroundPixel,
97 NULL);
98
99 wxColour col;
100 col.SetPixel(backgroundPixel);
101
102 wxBitmap newBitmap = wxCreateMaskedBitmap(m_messageBitmapOriginal, col);
103 m_messageBitmap = newBitmap;
104
105 pixmap = (Pixmap) m_messageBitmap.GetDrawable();
106 }
107 else
108 {
109 m_bitmapCache.SetBitmap( m_messageBitmap );
110 pixmap = (Pixmap)m_bitmapCache.GetLabelPixmap(widget);
111 }
112
113 XtVaSetValues (widget,
114 XmNlabelPixmap, pixmap,
115 XmNlabelType, XmPIXMAP,
116 NULL);
117
118 SetSize(w2, h2);
119 }
120 else
121 {
122 // Null bitmap: must not use current pixmap
123 // since it is no longer valid.
124 XtVaSetValues (widget,
125 XmNlabelType, XmSTRING,
126 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
127 NULL);
128 }
129 }
130
131 void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
132 {
133 m_messageBitmap = bitmap;
134 m_messageBitmapOriginal = bitmap;
135
136 DoSetBitmap();
137 }
138
139 void wxStaticBitmap::ChangeBackgroundColour()
140 {
141 wxWindow::ChangeBackgroundColour();
142
143 // must recalculate the background colour
144 m_bitmapCache.SetColoursChanged();
145 DoSetBitmap();
146 }
147
148 void wxStaticBitmap::ChangeForegroundColour()
149 {
150 m_bitmapCache.SetColoursChanged();
151 wxWindow::ChangeForegroundColour();
152 }