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