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
;
65 m_windowId
= NewControlId();
69 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
72 * Patch Note (important)
73 * There is no major reason to put a defaultButtonThickness here.
74 * Not requesting it give the ability to put wxButton with a spacing
75 * as small as requested. However, if some button become a DefaultButton,
76 * other buttons are no more aligned -- This is why we set
77 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
78 * in the ::SetDefaultButton method.
80 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
82 // Gadget causes problems for default button operation.
84 xmPushButtonGadgetClass
, parentWidget
,
86 xmPushButtonWidgetClass
, parentWidget
,
88 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
91 m_mainWidget
= (WXWidget
) buttonWidget
;
93 m_windowFont
= parent
->GetFont();
96 ChangeBackgroundColour ();
100 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
103 SetCanAddEventHandler(TRUE
);
104 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
109 wxBitmapButton::~wxBitmapButton()
111 SetBitmapLabel(wxNullBitmap
);
114 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
117 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
119 m_buttonBitmapOriginal
= bitmap
;
120 m_buttonBitmap
= bitmap
;
125 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
127 m_buttonBitmapSelected
= sel
;
128 m_buttonBitmapSelectedOriginal
= sel
;
133 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
135 m_buttonBitmapFocus
= focus
;
139 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
141 m_buttonBitmapDisabled
= disabled
;
142 m_buttonBitmapDisabledOriginal
= disabled
;
147 void wxBitmapButton::DoSetBitmap()
149 if (m_buttonBitmapOriginal
.Ok())
152 Pixmap insensPixmap
= 0;
153 Pixmap armPixmap
= 0;
155 // Must re-make the bitmap to have its transparent areas drawn
156 // in the current widget background colour.
157 if (m_buttonBitmapOriginal
.GetMask())
160 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
164 col
.SetPixel(backgroundPixel
);
166 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapOriginal
, col
);
167 m_buttonBitmap
= newBitmap
;
169 pixmap
= (Pixmap
) m_buttonBitmap
.GetPixmap();
172 pixmap
= (Pixmap
) m_buttonBitmap
.GetLabelPixmap(m_mainWidget
);
174 if (m_buttonBitmapDisabledOriginal
.Ok())
176 if (m_buttonBitmapDisabledOriginal
.GetMask())
179 XtVaGetValues((Widget
) m_mainWidget
, XmNbackground
, &backgroundPixel
,
183 col
.SetPixel(backgroundPixel
);
185 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapDisabledOriginal
, col
);
186 m_buttonBitmapDisabled
= newBitmap
;
188 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetPixmap();
191 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
194 insensPixmap
= (Pixmap
) m_buttonBitmap
.GetInsensPixmap(m_mainWidget
);
196 // Now make the bitmap representing the armed state
197 if (m_buttonBitmapSelectedOriginal
.Ok())
199 if (m_buttonBitmapSelectedOriginal
.GetMask())
202 XtVaGetValues((Widget
) m_mainWidget
, XmNarmColor
, &backgroundPixel
,
206 col
.SetPixel(backgroundPixel
);
208 wxBitmap newBitmap
= wxCreateMaskedBitmap(m_buttonBitmapSelectedOriginal
, col
);
209 m_buttonBitmapSelected
= newBitmap
;
211 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetPixmap();
214 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
217 armPixmap
= (Pixmap
) m_buttonBitmap
.GetArmPixmap(m_mainWidget
);
219 if (insensPixmap
== pixmap
) // <- the Get...Pixmap()-functions return the same pixmap!
222 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), pixmap
);
223 m_insensPixmap
= (WXPixmap
) insensPixmap
;
226 XtVaSetValues ((Widget
) m_mainWidget
,
227 XmNlabelPixmap
, pixmap
,
228 XmNlabelInsensitivePixmap
, insensPixmap
,
229 XmNarmPixmap
, armPixmap
,
230 XmNlabelType
, XmPIXMAP
,
235 // Null bitmap: must not use current pixmap
236 // since it is no longer valid.
237 XtVaSetValues ((Widget
) m_mainWidget
,
238 XmNlabelType
, XmSTRING
,
239 XmNlabelPixmap
, XmUNSPECIFIED_PIXMAP
,
240 XmNlabelInsensitivePixmap
, XmUNSPECIFIED_PIXMAP
,
241 XmNarmPixmap
, XmUNSPECIFIED_PIXMAP
,
246 void wxBitmapButton::ChangeBackgroundColour()
248 DoChangeBackgroundColour(m_mainWidget
, m_backgroundColour
, TRUE
);
250 // Must reset the bitmaps since the colours have changed.