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