]> git.saurik.com Git - wxWidgets.git/blame - src/motif/bmpbuttn.cpp
Send window create events
[wxWidgets.git] / src / motif / bmpbuttn.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
dfe1eee3 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
4bb6408c
JS
13#pragma implementation "bmpbuttn.h"
14#endif
15
bcd055ae
JJ
16#ifdef __VMS
17#define XtScreen XTSCREEN
18#endif
19
f6045f99
GD
20#include "wx/defs.h"
21
4bb6408c
JS
22#include "wx/bmpbuttn.h"
23
338dd992
JJ
24#ifdef __VMS__
25#pragma message disable nosimpint
26#endif
a4294b78
JS
27#include <Xm/PushBG.h>
28#include <Xm/PushB.h>
338dd992
JJ
29#ifdef __VMS__
30#pragma message enable nosimpint
31#endif
a4294b78
JS
32
33#include "wx/motif/private.h"
34
35// Implemented in button.cpp
36void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr);
37
aae91497 38// Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap );
a4294b78 39
4bb6408c 40IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
4bb6408c 41
a4294b78
JS
42wxBitmapButton::wxBitmapButton()
43{
ea9868e8 44 m_marginX = m_marginY = wxDEFAULT_BUTTON_MARGIN;
a4294b78
JS
45 m_insensPixmap = (WXPixmap) 0;
46}
47
ea9868e8
MB
48bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
49 const wxBitmap& bitmap,
2d120f83
JS
50 const wxPoint& pos,
51 const wxSize& size, long style,
52 const wxValidator& validator,
53 const wxString& name)
4bb6408c 54{
ea9868e8
MB
55 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
56 return false;
dfe1eee3 57
ea9868e8
MB
58 m_bmpNormal = m_bmpNormalOriginal = bitmap;
59 m_bmpSelected = m_bmpSelectedOriginal = bitmap;
dfe1eee3 60
a4294b78 61 Widget parentWidget = (Widget) parent->GetClientWidget();
dfe1eee3 62
2d120f83
JS
63 /*
64 * Patch Note (important)
65 * There is no major reason to put a defaultButtonThickness here.
66 * Not requesting it give the ability to put wxButton with a spacing
67 * as small as requested. However, if some button become a DefaultButton,
68 * other buttons are no more aligned -- This is why we set
69 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
70 * in the ::SetDefaultButton method.
71 */
a4294b78 72 Widget buttonWidget = XtVaCreateManagedWidget ("button",
dfe1eee3 73
2d120f83 74 // Gadget causes problems for default button operation.
a4294b78 75#if wxUSE_GADGETS
2d120f83 76 xmPushButtonGadgetClass, parentWidget,
a4294b78 77#else
2d120f83 78 xmPushButtonWidgetClass, parentWidget,
a4294b78 79#endif
ea9868e8
MB
80 // See comment for wxButton::SetDefault
81 // XmNdefaultButtonShadowThickness, 1,
82 XmNrecomputeSize, False,
2d120f83 83 NULL);
dfe1eee3 84
a4294b78 85 m_mainWidget = (WXWidget) buttonWidget;
dfe1eee3 86
4b5f3fe6 87 ChangeFont(FALSE);
dfe1eee3 88
321db4b6 89 ChangeBackgroundColour ();
dfe1eee3 90
321db4b6 91 DoSetBitmap();
dfe1eee3 92
ea9868e8
MB
93 XtAddCallback (buttonWidget,
94 XmNactivateCallback, (XtCallbackProc) wxButtonCallback,
95 (XtPointer) this);
dfe1eee3 96
ea9868e8
MB
97 wxSize best = m_bmpNormal.Ok() ? GetBestSize() : wxSize(30, 30);
98 if( size.x != -1 ) best.x = size.x;
99 if( size.y != -1 ) best.y = size.y;
100
101 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
102 pos.x, pos.y, best.x, best.y);
dfe1eee3 103
a4294b78
JS
104 return TRUE;
105}
106
107wxBitmapButton::~wxBitmapButton()
108{
109 SetBitmapLabel(wxNullBitmap);
dfe1eee3 110
a4294b78 111 if (m_insensPixmap)
ea9868e8
MB
112 XmDestroyPixmap (DefaultScreenOfDisplay ((Display*) GetXDisplay()),
113 (Pixmap) m_insensPixmap);
4bb6408c
JS
114}
115
116void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
117{
ea9868e8
MB
118 m_bmpNormalOriginal = bitmap;
119 m_bmpNormal = bitmap;
dfe1eee3 120
321db4b6
JS
121 DoSetBitmap();
122}
123
124void wxBitmapButton::SetBitmapSelected(const wxBitmap& sel)
125{
ea9868e8
MB
126 m_bmpSelected = sel;
127 m_bmpSelectedOriginal = sel;
dfe1eee3 128
321db4b6
JS
129 DoSetBitmap();
130};
131
132void wxBitmapButton::SetBitmapFocus(const wxBitmap& focus)
133{
ea9868e8 134 m_bmpFocus = focus;
321db4b6
JS
135 // Not used in Motif
136};
137
138void wxBitmapButton::SetBitmapDisabled(const wxBitmap& disabled)
139{
ea9868e8
MB
140 m_bmpDisabled = disabled;
141 m_bmpDisabledOriginal = disabled;
dfe1eee3 142
321db4b6
JS
143 DoSetBitmap();
144};
145
146void wxBitmapButton::DoSetBitmap()
147{
ea9868e8 148 if (m_bmpNormalOriginal.Ok())
a4294b78 149 {
321db4b6
JS
150 Pixmap pixmap = 0;
151 Pixmap insensPixmap = 0;
152 Pixmap armPixmap = 0;
dfe1eee3 153
321db4b6
JS
154 // Must re-make the bitmap to have its transparent areas drawn
155 // in the current widget background colour.
ea9868e8 156 if (m_bmpNormalOriginal.GetMask())
321db4b6
JS
157 {
158 int backgroundPixel;
ea9868e8
MB
159 XtVaGetValues((Widget) m_mainWidget,
160 XmNbackground, &backgroundPixel,
161 NULL);
dfe1eee3 162
321db4b6
JS
163 wxColour col;
164 col.SetPixel(backgroundPixel);
dfe1eee3 165
ea9868e8
MB
166 wxBitmap newBitmap =
167 wxCreateMaskedBitmap(m_bmpNormalOriginal, col);
168 m_bmpNormal = newBitmap;
aae91497 169 m_bitmapCache.SetBitmap( m_bmpNormal );
dfe1eee3 170
aae0472b 171 pixmap = (Pixmap) m_bmpNormal.GetDrawable();
321db4b6 172 }
a4294b78 173 else
aae91497
MB
174 {
175 m_bitmapCache.SetBitmap( m_bmpNormal );
176 pixmap = (Pixmap) m_bitmapCache.GetLabelPixmap(m_mainWidget);
177 }
dfe1eee3 178
ea9868e8 179 if (m_bmpDisabledOriginal.Ok())
321db4b6 180 {
ea9868e8 181 if (m_bmpDisabledOriginal.GetMask())
321db4b6
JS
182 {
183 int backgroundPixel;
ea9868e8
MB
184 XtVaGetValues((Widget) m_mainWidget,
185 XmNbackground, &backgroundPixel,
186 NULL);
dfe1eee3 187
321db4b6
JS
188 wxColour col;
189 col.SetPixel(backgroundPixel);
dfe1eee3 190
ea9868e8
MB
191 wxBitmap newBitmap =
192 wxCreateMaskedBitmap(m_bmpDisabledOriginal, col);
193 m_bmpDisabled = newBitmap;
dfe1eee3 194
aae0472b 195 insensPixmap = (Pixmap) m_bmpDisabled.GetDrawable();
321db4b6
JS
196 }
197 else
aae91497 198 insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);
321db4b6 199 }
a4294b78 200 else
aae91497 201 insensPixmap = (Pixmap) m_bitmapCache.GetInsensPixmap(m_mainWidget);
dfe1eee3 202
321db4b6 203 // Now make the bitmap representing the armed state
ea9868e8 204 if (m_bmpSelectedOriginal.Ok())
a4294b78 205 {
ea9868e8 206 if (m_bmpSelectedOriginal.GetMask())
321db4b6
JS
207 {
208 int backgroundPixel;
ea9868e8
MB
209 XtVaGetValues((Widget) m_mainWidget,
210 XmNarmColor, &backgroundPixel,
211 NULL);
dfe1eee3 212
321db4b6
JS
213 wxColour col;
214 col.SetPixel(backgroundPixel);
dfe1eee3 215
ea9868e8
MB
216 wxBitmap newBitmap =
217 wxCreateMaskedBitmap(m_bmpSelectedOriginal, col);
218 m_bmpSelected = newBitmap;
dfe1eee3 219
aae0472b 220 armPixmap = (Pixmap) m_bmpSelected.GetDrawable();
321db4b6
JS
221 }
222 else
aae91497 223 armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget);
321db4b6
JS
224 }
225 else
aae91497 226 armPixmap = (Pixmap) m_bitmapCache.GetArmPixmap(m_mainWidget);
dfe1eee3 227
a4294b78 228 XtVaSetValues ((Widget) m_mainWidget,
321db4b6
JS
229 XmNlabelPixmap, pixmap,
230 XmNlabelInsensitivePixmap, insensPixmap,
a4294b78
JS
231 XmNarmPixmap, armPixmap,
232 XmNlabelType, XmPIXMAP,
233 NULL);
234 }
235 else
236 {
237 // Null bitmap: must not use current pixmap
238 // since it is no longer valid.
239 XtVaSetValues ((Widget) m_mainWidget,
240 XmNlabelType, XmSTRING,
1a3ac83f 241 XmNlabelPixmap, XmUNSPECIFIED_PIXMAP,
2d120f83 242 XmNlabelInsensitivePixmap, XmUNSPECIFIED_PIXMAP,
321db4b6 243 XmNarmPixmap, XmUNSPECIFIED_PIXMAP,
a4294b78
JS
244 NULL);
245 }
4bb6408c
JS
246}
247
321db4b6 248void wxBitmapButton::ChangeBackgroundColour()
a4294b78 249{
a8680e3e 250 wxDoChangeBackgroundColour(m_mainWidget, m_backgroundColour, TRUE);
dfe1eee3 251
321db4b6
JS
252 // Must reset the bitmaps since the colours have changed.
253 DoSetBitmap();
254}
401eb3de
RR
255
256wxSize wxBitmapButton::DoGetBestSize() const
257{
258 wxSize ret( 30,30 );
259
ea9868e8 260 if (m_bmpNormal.Ok())
401eb3de
RR
261 {
262 int border = (GetWindowStyle() & wxNO_BORDER) ? 4 : 10;
ea9868e8
MB
263 ret.x = m_bmpNormal.GetWidth()+border;
264 ret.y = m_bmpNormal.GetHeight()+border;
401eb3de
RR
265 }
266
267 return ret;
268}
269