1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "bmpbuttn.h"
16 #include "wx/bmpbuttn.h"
19 #pragma message disable nosimpint
21 #include <Xm/PushBG.h>
24 #pragma message enable nosimpint
27 #include "wx/motif/private.h"
29 // Implemented in button.cpp
30 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
32 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
34 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
36 wxBitmapButton::wxBitmapButton()
38 m_marginX
= wxDEFAULT_BUTTON_MARGIN
; m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
39 m_insensPixmap
= (WXPixmap
) 0;
42 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
44 const wxSize
& size
, long style
,
45 const wxValidator
& validator
,
48 m_buttonBitmap
= bitmap
;
49 m_buttonBitmapOriginal
= bitmap
;
50 m_buttonBitmapSelected
= bitmap
;
51 m_buttonBitmapSelectedOriginal
= bitmap
;
54 SetValidator(validator
);
55 parent
->AddChild(this);
57 m_backgroundColour
= parent
->GetBackgroundColour() ;
58 m_foregroundColour
= parent
->GetForegroundColour() ;
59 m_windowStyle
= style
;
71 m_windowId
= NewControlId();
75 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
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.
86 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
88 // Gadget causes problems for default button operation.
90 xmPushButtonGadgetClass
, parentWidget
,
92 xmPushButtonWidgetClass
, parentWidget
,
94 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
97 m_mainWidget
= (WXWidget
) buttonWidget
;
99 m_font
= parent
->GetFont();
102 ChangeBackgroundColour ();
106 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
109 SetCanAddEventHandler(TRUE
);
110 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
115 wxBitmapButton::~wxBitmapButton()
117 SetBitmapLabel(wxNullBitmap
);
120 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
123 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
125 m_buttonBitmapOriginal
= bitmap
;
126 m_buttonBitmap
= bitmap
;
131 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
133 m_buttonBitmapSelected
= sel
;
134 m_buttonBitmapSelectedOriginal
= sel
;
139 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
141 m_buttonBitmapFocus
= focus
;
145 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
147 m_buttonBitmapDisabled
= disabled
;
148 m_buttonBitmapDisabledOriginal
= disabled
;
153 void wxBitmapButton::DoSetBitmap()
155 if (m_buttonBitmapOriginal
.Ok())
158 Pixmap insensPixmap
= 0;
159 Pixmap armPixmap
= 0;
161 // Must re-make the bitmap to have its transparent areas drawn
162 // in the current widget background colour.
163 if (m_buttonBitmapOriginal
.GetMask())
166 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
170 col
.SetPixel(backgroundPixel
);
172 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
173 m_buttonBitmap
= newBitmap
;
175 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
178 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
180 if (m_buttonBitmapDisabledOriginal
.Ok())
182 if (m_buttonBitmapDisabledOriginal
.GetMask())
185 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
189 col
.SetPixel(backgroundPixel
);
191 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
192 m_buttonBitmapDisabled
= newBitmap
;
194 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
197 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
200 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
202 // Now make the bitmap representing the armed state
203 if (m_buttonBitmapSelectedOriginal
.Ok())
205 if (m_buttonBitmapSelectedOriginal
.GetMask())
208 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
212 col
.SetPixel(backgroundPixel
);
214 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
215 m_buttonBitmapSelected
= newBitmap
;
217 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
220 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
223 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
225 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
228 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
229 m_insensPixmap
= (WXPixmap
) insensPixmap
;
232 XtVaSetValues ((Widget
) m_mainWidget
,
233 XmNlabelPixmap
, pixmap
,
234 XmNlabelInsensitivePixmap
, insensPixmap
,
235 XmNarmPixmap
, armPixmap
,
236 XmNlabelType
, XmPIXMAP
,
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
,
252 void wxBitmapButton::ChangeBackgroundColour()
254 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
256 // Must reset the bitmaps since the colours have changed.