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 #if !USE_SHARED_LIBRARY
35 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
38 wxBitmapButton::wxBitmapButton()
40 m_marginX
= wxDEFAULT_BUTTON_MARGIN
; m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
41 m_insensPixmap
= (WXPixmap
) 0;
44 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
46 const wxSize
& size
, long style
,
47 const wxValidator
& validator
,
50 m_buttonBitmap
= bitmap
;
51 m_buttonBitmapOriginal
= bitmap
;
52 m_buttonBitmapSelected
= bitmap
;
53 m_buttonBitmapSelectedOriginal
= bitmap
;
56 SetValidator(validator
);
57 parent
->AddChild(this);
59 m_backgroundColour
= parent
->GetBackgroundColour() ;
60 m_foregroundColour
= parent
->GetForegroundColour() ;
61 m_windowStyle
= style
;
73 m_windowId
= NewControlId();
77 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
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.
88 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
90 // Gadget causes problems for default button operation.
92 xmPushButtonGadgetClass
, parentWidget
,
94 xmPushButtonWidgetClass
, parentWidget
,
96 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
99 m_mainWidget
= (WXWidget
) buttonWidget
;
101 m_font
= parent
->GetFont();
104 ChangeBackgroundColour ();
108 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
111 SetCanAddEventHandler(TRUE
);
112 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
117 wxBitmapButton::~wxBitmapButton()
119 SetBitmapLabel(wxNullBitmap
);
122 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
125 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
127 m_buttonBitmapOriginal
= bitmap
;
128 m_buttonBitmap
= bitmap
;
133 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
135 m_buttonBitmapSelected
= sel
;
136 m_buttonBitmapSelectedOriginal
= sel
;
141 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
143 m_buttonBitmapFocus
= focus
;
147 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
149 m_buttonBitmapDisabled
= disabled
;
150 m_buttonBitmapDisabledOriginal
= disabled
;
155 void wxBitmapButton::DoSetBitmap()
157 if (m_buttonBitmapOriginal
.Ok())
160 Pixmap insensPixmap
= 0;
161 Pixmap armPixmap
= 0;
163 // Must re-make the bitmap to have its transparent areas drawn
164 // in the current widget background colour.
165 if (m_buttonBitmapOriginal
.GetMask())
168 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
172 col
.SetPixel(backgroundPixel
);
174 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
175 m_buttonBitmap
= newBitmap
;
177 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
180 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
182 if (m_buttonBitmapDisabledOriginal
.Ok())
184 if (m_buttonBitmapDisabledOriginal
.GetMask())
187 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
191 col
.SetPixel(backgroundPixel
);
193 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
194 m_buttonBitmapDisabled
= newBitmap
;
196 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
199 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
202 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
204 // Now make the bitmap representing the armed state
205 if (m_buttonBitmapSelectedOriginal
.Ok())
207 if (m_buttonBitmapSelectedOriginal
.GetMask())
210 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
214 col
.SetPixel(backgroundPixel
);
216 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
217 m_buttonBitmapSelected
= newBitmap
;
219 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
222 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
225 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
227 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
230 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
231 m_insensPixmap
= (WXPixmap
) insensPixmap
;
234 XtVaSetValues ((Widget
) m_mainWidget
,
235 XmNlabelPixmap
, pixmap
,
236 XmNlabelInsensitivePixmap
, insensPixmap
,
237 XmNarmPixmap
, armPixmap
,
238 XmNlabelType
, XmPIXMAP
,
243 // Null bitmap: must not use current pixmap
244 // since it is no longer valid.
245 XtVaSetValues ((Widget
) m_mainWidget
,
246 XmNlabelType
, XmSTRING
,
247 XmNlabelPixmap
, XmUNSPECIFIED_PIXMAP
,
248 XmNlabelInsensitivePixmap
, XmUNSPECIFIED_PIXMAP
,
249 XmNarmPixmap
, XmUNSPECIFIED_PIXMAP
,
254 void wxBitmapButton::ChangeBackgroundColour()
256 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
258 // Must reset the bitmaps since the colours have changed.