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
;
46 SetValidator(validator
);
47 parent
->AddChild(this);
49 m_backgroundColour
= parent
->GetBackgroundColour() ;
50 m_foregroundColour
= parent
->GetForegroundColour() ;
51 m_windowStyle
= style
;
61 m_windowId
= NewControlId();
65 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
68 * Patch Note (important)
69 * There is no major reason to put a defaultButtonThickness here.
70 * Not requesting it give the ability to put wxButton with a spacing
71 * as small as requested. However, if some button become a DefaultButton,
72 * other buttons are no more aligned -- This is why we set
73 * defaultButtonThickness of ALL buttons belonging to the same wxPanel,
74 * in the ::SetDefaultButton method.
76 Widget buttonWidget
= XtVaCreateManagedWidget ("button",
78 // Gadget causes problems for default button operation.
80 xmPushButtonGadgetClass
, parentWidget
,
82 xmPushButtonWidgetClass
, parentWidget
,
84 // XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
87 m_mainWidget
= (WXWidget
) buttonWidget
;
93 p1
= (Pixmap
) ((wxBitmap
&)bitmap
).GetLabelPixmap(m_mainWidget
);
94 p2
= (Pixmap
) ((wxBitmap
&)bitmap
).GetInsensPixmap(m_mainWidget
);
96 if(p1
== p2
) // <- the Get...Pixmap()-functions return the same pixmap!
99 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen(buttonWidget
)), p1
);
100 m_insensPixmap
= (WXPixmap
) p2
;
103 XtVaSetValues (buttonWidget
,
105 XmNlabelInsensitivePixmap
, p2
,
106 XmNarmPixmap
, (Pixmap
) ((wxBitmap
&)bitmap
).GetArmPixmap (m_mainWidget
),
107 XmNlabelType
, XmPIXMAP
,
111 XtAddCallback (buttonWidget
, XmNactivateCallback
, (XtCallbackProc
) wxButtonCallback
,
114 SetCanAddEventHandler(TRUE
);
115 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
117 SetFont(* parent
->GetFont());
119 ChangeColour (m_mainWidget
);
125 wxBitmapButton::~wxBitmapButton()
127 SetBitmapLabel(wxNullBitmap
);
130 XmDestroyPixmap (DefaultScreenOfDisplay ((Display
*) GetXDisplay()), (Pixmap
) m_insensPixmap
);
133 void wxBitmapButton::SetBitmapLabel(const wxBitmap
& bitmap
)
135 m_buttonBitmap
= bitmap
;
139 Pixmap labelPixmap
, insensPixmap
, armPixmap
;
141 labelPixmap
= (Pixmap
) ((wxBitmap
&)bitmap
).GetLabelPixmap(m_mainWidget
);
143 if (m_buttonBitmapSelected
.Ok())
144 armPixmap
= (Pixmap
) m_buttonBitmapSelected
.GetLabelPixmap(m_mainWidget
);
146 armPixmap
= (Pixmap
) ((wxBitmap
&)bitmap
).GetArmPixmap(m_mainWidget
);
148 if (m_buttonBitmapDisabled
.Ok())
149 insensPixmap
= (Pixmap
) m_buttonBitmapDisabled
.GetLabelPixmap(m_mainWidget
);
151 insensPixmap
= (Pixmap
) ((wxBitmap
&)bitmap
).GetInsensPixmap(m_mainWidget
);
153 if (!insensPixmap
|| (insensPixmap
== labelPixmap
)) // <- the Get...Pixmap()-functions return the same pixmap!
155 insensPixmap
= XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget
) m_mainWidget
)), labelPixmap
);
156 m_insensPixmap
= (WXPixmap
) insensPixmap
;
159 XtVaSetValues ((Widget
) m_mainWidget
,
160 XmNlabelPixmap
, labelPixmap
,
161 XmNlabelInsensitivePixmap
, insensPixmap
,
162 XmNarmPixmap
, armPixmap
,
163 XmNlabelType
, XmPIXMAP
,
168 // Null bitmap: must not use current pixmap
169 // since it is no longer valid.
170 XtVaSetValues ((Widget
) m_mainWidget
,
171 XmNlabelType
, XmSTRING
,
172 XmNlabelPixmap
, NULL
, // TODO: Does this work?
173 XmNlabelInsensitivePixmap
, NULL
,
179 void wxBitmapButton::SetBitmapSelected(const wxBitmap
& sel
)
181 m_buttonBitmapSelected
= sel
;
184 void wxBitmapButton::SetBitmapFocus(const wxBitmap
& focus
)
186 m_buttonBitmapFocus
= focus
;
190 void wxBitmapButton::SetBitmapDisabled(const wxBitmap
& disabled
)
192 m_buttonBitmapDisabled
= disabled
;