1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bmpbuttn.h"
17 #define XtScreen XTSCREEN
20 #include "wx/bmpbuttn.h"
23 #pragma message disable nosimpint
25 #include <Xm/PushBG.h>
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
33 // Implemented in button.cpp
34 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
36 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
38 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
40 wxBitmapButton::wxBitmapButton()
42 m_marginX
= wxDEFAULT_BUTTON_MARGIN
; m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
43 m_insensPixmap
= (WXPixmap
) 0;
46 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
48 const wxSize
& size
, long style
,
49 const wxValidator
& validator
,
52 m_buttonBitmap
= bitmap
;
53 m_buttonBitmapOriginal
= bitmap
;
54 m_buttonBitmapSelected
= bitmap
;
55 m_buttonBitmapSelectedOriginal
= bitmap
;
58 SetValidator(validator
);
59 parent
->AddChild(this);
61 m_backgroundColour
= parent
->GetBackgroundColour() ;
62 m_foregroundColour
= parent
->GetForegroundColour() ;
63 m_windowStyle
= style
;
75 m_windowId
= NewControlId();
79 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
82 * Patch Note (important)
83 * There is no major reason to put a defaultButtonThickness here.
84 * Not requesting it give the ability to put wxButton with a spacing
85 * as small as requested. However, if some button become a DefaultButton,
86 * other buttons are no more aligned -- This is why we set
87 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
88 * in the ::SetDefaultButton method.
90 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
92 // Gadget causes problems for default button operation.
94 xmPushButtonGadgetClass
, parentWidget
,
96 xmPushButtonWidgetClass
, parentWidget
,
98 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
101 m_mainWidget
= (WXWidget
) buttonWidget
;
103 m_font
= parent
->GetFont();
106 ChangeBackgroundColour ();
110 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
113 SetCanAddEventHandler(TRUE
);
114 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
119 wxBitmapButton::~wxBitmapButton()
121 SetBitmapLabel(wxNullBitmap
);
124 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
127 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
129 m_buttonBitmapOriginal
= bitmap
;
130 m_buttonBitmap
= bitmap
;
135 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
137 m_buttonBitmapSelected
= sel
;
138 m_buttonBitmapSelectedOriginal
= sel
;
143 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
145 m_buttonBitmapFocus
= focus
;
149 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
151 m_buttonBitmapDisabled
= disabled
;
152 m_buttonBitmapDisabledOriginal
= disabled
;
157 void wxBitmapButton::DoSetBitmap()
159 if (m_buttonBitmapOriginal
.Ok())
162 Pixmap insensPixmap
= 0;
163 Pixmap armPixmap
= 0;
165 // Must re-make the bitmap to have its transparent areas drawn
166 // in the current widget background colour.
167 if (m_buttonBitmapOriginal
.GetMask())
170 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
174 col
.SetPixel(backgroundPixel
);
176 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
177 m_buttonBitmap
= newBitmap
;
179 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
182 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
184 if (m_buttonBitmapDisabledOriginal
.Ok())
186 if (m_buttonBitmapDisabledOriginal
.GetMask())
189 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
193 col
.SetPixel(backgroundPixel
);
195 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
196 m_buttonBitmapDisabled
= newBitmap
;
198 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
201 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
204 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
206 // Now make the bitmap representing the armed state
207 if (m_buttonBitmapSelectedOriginal
.Ok())
209 if (m_buttonBitmapSelectedOriginal
.GetMask())
212 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
216 col
.SetPixel(backgroundPixel
);
218 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
219 m_buttonBitmapSelected
= newBitmap
;
221 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
224 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
227 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
229 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
232 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
233 m_insensPixmap
= (WXPixmap
) insensPixmap
;
236 XtVaSetValues ((Widget
) m_mainWidget
,
237 XmNlabelPixmap
, pixmap
,
238 XmNlabelInsensitivePixmap
, insensPixmap
,
239 XmNarmPixmap
, armPixmap
,
240 XmNlabelType
, XmPIXMAP
,
245 // Null bitmap: must not use current pixmap
246 // since it is no longer valid.
247 XtVaSetValues ((Widget
) m_mainWidget
,
248 XmNlabelType
, XmSTRING
,
249 XmNlabelPixmap
, XmUNSPECIFIED_PIXMAP
,
250 XmNlabelInsensitivePixmap
, XmUNSPECIFIED_PIXMAP
,
251 XmNarmPixmap
, XmUNSPECIFIED_PIXMAP
,
256 void wxBitmapButton::ChangeBackgroundColour()
258 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
260 // Must reset the bitmaps since the colours have changed.