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