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
22 #include "wx/bmpbuttn.h"
25 #pragma message disable nosimpint
27 #include <Xm/PushBG.h>
30 #pragma message enable nosimpint
33 #include "wx/motif/private.h"
35 // Implemented in button.cpp
36 void wxButtonCallback (Widget w
, XtPointer clientData
, XtPointer ptr
);
38 Pixmap
XCreateInsensitivePixmap( Display
*display
, Pixmap pixmap
);
40 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
42 wxBitmapButton::wxBitmapButton()
44 m_marginX
= wxDEFAULT_BUTTON_MARGIN
; m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
45 m_insensPixmap
= (WXPixmap
) 0;
48 bool wxBitmapButton::Create(wxWindow
*parent
, wxWindowID id
, const wxBitmap
& bitmap
,
50 const wxSize
& size
, long style
,
51 const wxValidator
& validator
,
54 m_buttonBitmap
= bitmap
;
55 m_buttonBitmapOriginal
= bitmap
;
56 m_buttonBitmapSelected
= bitmap
;
57 m_buttonBitmapSelectedOriginal
= bitmap
;
60 SetValidator(validator
);
61 parent
->AddChild(this);
63 m_backgroundColour
= parent
->GetBackgroundColour() ;
64 m_foregroundColour
= parent
->GetForegroundColour() ;
65 m_windowStyle
= style
;
77 m_windowId
= NewControlId();
81 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
84 * Patch Note (important)
85 * There is no major reason to put a defaultButtonThickness here.
86 * Not requesting it give the ability to put wxButton with a spacing
87 * as small as requested. However, if some button become a DefaultButton,
88 * other buttons are no more aligned -- This is why we set
89 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
90 * in the ::SetDefaultButton method.
92 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
94 // Gadget causes problems for default button operation.
96 xmPushButtonGadgetClass
, parentWidget
,
98 xmPushButtonWidgetClass
, parentWidget
,
100 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
103 m_mainWidget
= (WXWidget
) buttonWidget
;
105 m_font
= parent
->GetFont();
108 ChangeBackgroundColour ();
112 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
115 SetCanAddEventHandler(TRUE
);
116 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
121 wxBitmapButton::~wxBitmapButton()
123 SetBitmapLabel(wxNullBitmap
);
126 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
129 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
131 m_buttonBitmapOriginal
= bitmap
;
132 m_buttonBitmap
= bitmap
;
137 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
139 m_buttonBitmapSelected
= sel
;
140 m_buttonBitmapSelectedOriginal
= sel
;
145 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
147 m_buttonBitmapFocus
= focus
;
151 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
153 m_buttonBitmapDisabled
= disabled
;
154 m_buttonBitmapDisabledOriginal
= disabled
;
159 void wxBitmapButton::DoSetBitmap()
161 if (m_buttonBitmapOriginal
.Ok())
164 Pixmap insensPixmap
= 0;
165 Pixmap armPixmap
= 0;
167 // Must re-make the bitmap to have its transparent areas drawn
168 // in the current widget background colour.
169 if (m_buttonBitmapOriginal
.GetMask())
172 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
176 col
.SetPixel(backgroundPixel
);
178 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
179 m_buttonBitmap
= newBitmap
;
181 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
184 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
186 if (m_buttonBitmapDisabledOriginal
.Ok())
188 if (m_buttonBitmapDisabledOriginal
.GetMask())
191 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
195 col
.SetPixel(backgroundPixel
);
197 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
198 m_buttonBitmapDisabled
= newBitmap
;
200 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
203 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
206 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
208 // Now make the bitmap representing the armed state
209 if (m_buttonBitmapSelectedOriginal
.Ok())
211 if (m_buttonBitmapSelectedOriginal
.GetMask())
214 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
218 col
.SetPixel(backgroundPixel
);
220 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
221 m_buttonBitmapSelected
= newBitmap
;
223 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
226 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
229 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
231 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
234 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
235 m_insensPixmap
= (WXPixmap
) insensPixmap
;
238 XtVaSetValues ((Widget
) m_mainWidget
,
239 XmNlabelPixmap
, pixmap
,
240 XmNlabelInsensitivePixmap
, insensPixmap
,
241 XmNarmPixmap
, armPixmap
,
242 XmNlabelType
, XmPIXMAP
,
247 // Null bitmap: must not use current pixmap
248 // since it is no longer valid.
249 XtVaSetValues ((Widget
) m_mainWidget
,
250 XmNlabelType
, XmSTRING
,
251 XmNlabelPixmap
, XmUNSPECIFIED_PIXMAP
,
252 XmNlabelInsensitivePixmap
, XmUNSPECIFIED_PIXMAP
,
253 XmNarmPixmap
, XmUNSPECIFIED_PIXMAP
,
258 void wxBitmapButton::ChangeBackgroundColour()
260 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
262 // Must reset the bitmaps since the colours have changed.