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"
18 #include <Xm/PushBG.h>
21 #include "wx/motif/private.h"
23 // Implemented in button.cpp
24 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
26 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
32 wxBitmapButton::wxBitmapButton()
34 m_marginX
= wxDEFAULT_BUTTON_MARGIN
; m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
35 m_insensPixmap
= (WXPixmap
) 0;
38 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
40 const wxSize
& size
, long style
,
41 const wxValidator
& validator
,
44 m_buttonBitmap
= bitmap
;
45 m_buttonBitmapOriginal
= bitmap
;
46 m_buttonBitmapSelected
= bitmap
;
47 m_buttonBitmapSelectedOriginal
= bitmap
;
50 SetValidator(validator
);
51 parent
->AddChild(this);
53 m_backgroundColour
= parent
->GetBackgroundColour() ;
54 m_foregroundColour
= parent
->GetForegroundColour() ;
55 m_windowStyle
= style
;
67 m_windowId
= NewControlId();
71 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
74 * Patch Note (important)
75 * There is no major reason to put a defaultButtonThickness here.
76 * Not requesting it give the ability to put wxButton with a spacing
77 * as small as requested. However, if some button become a DefaultButton,
78 * other buttons are no more aligned -- This is why we set
79 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
80 * in the ::SetDefaultButton method.
82 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
84 // Gadget causes problems for default button operation.
86 xmPushButtonGadgetClass
, parentWidget
,
88 xmPushButtonWidgetClass
, parentWidget
,
90 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
93 m_mainWidget
= (WXWidget
) buttonWidget
;
95 m_windowFont
= parent
->GetFont();
98 ChangeBackgroundColour ();
102 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
105 SetCanAddEventHandler(TRUE
);
106 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
111 wxBitmapButton::~wxBitmapButton()
113 SetBitmapLabel(wxNullBitmap
);
116 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
119 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
121 m_buttonBitmapOriginal
= bitmap
;
122 m_buttonBitmap
= bitmap
;
127 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
129 m_buttonBitmapSelected
= sel
;
130 m_buttonBitmapSelectedOriginal
= sel
;
135 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
137 m_buttonBitmapFocus
= focus
;
141 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
143 m_buttonBitmapDisabled
= disabled
;
144 m_buttonBitmapDisabledOriginal
= disabled
;
149 void wxBitmapButton::DoSetBitmap()
151 if (m_buttonBitmapOriginal
.Ok())
154 Pixmap insensPixmap
= 0;
155 Pixmap armPixmap
= 0;
157 // Must re-make the bitmap to have its transparent areas drawn
158 // in the current widget background colour.
159 if (m_buttonBitmapOriginal
.GetMask())
162 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
166 col
.SetPixel(backgroundPixel
);
168 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
169 m_buttonBitmap
= newBitmap
;
171 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
174 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
176 if (m_buttonBitmapDisabledOriginal
.Ok())
178 if (m_buttonBitmapDisabledOriginal
.GetMask())
181 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
185 col
.SetPixel(backgroundPixel
);
187 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
188 m_buttonBitmapDisabled
= newBitmap
;
190 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
193 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
196 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
198 // Now make the bitmap representing the armed state
199 if (m_buttonBitmapSelectedOriginal
.Ok())
201 if (m_buttonBitmapSelectedOriginal
.GetMask())
204 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
208 col
.SetPixel(backgroundPixel
);
210 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
211 m_buttonBitmapSelected
= newBitmap
;
213 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
216 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
219 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
221 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
224 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
225 m_insensPixmap
= (WXPixmap
) insensPixmap
;
228 XtVaSetValues ((Widget
) m_mainWidget
,
229 XmNlabelPixmap
, pixmap
,
230 XmNlabelInsensitivePixmap
, insensPixmap
,
231 XmNarmPixmap
, armPixmap
,
232 XmNlabelType
, XmPIXMAP
,
237 // Null bitmap: must not use current pixmap
238 // since it is no longer valid.
239 XtVaSetValues ((Widget
) m_mainWidget
,
240 XmNlabelType
, XmSTRING
,
241 XmNlabelPixmap
, XmUNSPECIFIED_PIXMAP
,
242 XmNlabelInsensitivePixmap
, XmUNSPECIFIED_PIXMAP
,
243 XmNarmPixmap
, XmUNSPECIFIED_PIXMAP
,
248 void wxBitmapButton::ChangeBackgroundColour()
250 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
252 // Must reset the bitmaps since the colours have changed.