]> git.saurik.com Git - wxWidgets.git/blame - src/motif/bmpbuttn.cpp
More Motif additions: mdi and sashtest samples now just about work!
[wxWidgets.git] / src / motif / bmpbuttn.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "bmpbuttn.h"
14#endif
15
16#include "wx/bmpbuttn.h"
17
a4294b78
JS
18#include <Xm/PushBG.h>
19#include <Xm/PushB.h>
20
21#include "wx/motif/private.h"
22
23// Implemented in button.cpp
24void wxButtonCallback (Widget w, XtPointer clientData, XtPointer ptr);
25
26Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap );
27
4bb6408c
JS
28#if !USE_SHARED_LIBRARY
29IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
30#endif
31
a4294b78
JS
32wxBitmapButton::wxBitmapButton()
33{
34 m_marginX = wxDEFAULT_BUTTON_MARGIN; m_marginY = wxDEFAULT_BUTTON_MARGIN;
35 m_insensPixmap = (WXPixmap) 0;
36}
37
4bb6408c
JS
38bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
39 const wxPoint& pos,
40 const wxSize& size, long style,
41 const wxValidator& validator,
42 const wxString& name)
43{
44 m_buttonBitmap = bitmap;
45 SetName(name);
46 SetValidator(validator);
47 parent->AddChild(this);
48
47bc1060
JS
49 m_backgroundColour = parent->GetBackgroundColour() ;
50 m_foregroundColour = parent->GetForegroundColour() ;
4bb6408c
JS
51 m_windowStyle = style;
52 m_marginX = 0;
53 m_marginY = 0;
54
55 int x = pos.x;
56 int y = pos.y;
57 int width = size.x;
58 int height = size.y;
59
60 if (id == -1)
61 m_windowId = NewControlId();
62 else
63 m_windowId = id;
64
a4294b78
JS
65 Widget parentWidget = (Widget) parent->GetClientWidget();
66
67 /*
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.
75 */
76 Widget buttonWidget = XtVaCreateManagedWidget ("button",
77
78 // Gadget causes problems for default button operation.
79#if wxUSE_GADGETS
80 xmPushButtonGadgetClass, parentWidget,
81#else
82 xmPushButtonWidgetClass, parentWidget,
83#endif
84// XmNdefaultButtonShadowThickness, 1, // See comment for wxButton::SetDefault
85 NULL);
86
87 m_mainWidget = (WXWidget) buttonWidget;
88
89 if (bitmap.Ok())
90 {
91 Pixmap p1, p2;
92
93 p1 = (Pixmap) ((wxBitmap&)bitmap).GetLabelPixmap(m_mainWidget);
94 p2 = (Pixmap) ((wxBitmap&)bitmap).GetInsensPixmap(m_mainWidget);
95
96 if(p1 == p2) // <- the Get...Pixmap()-functions return the same pixmap!
97 {
98 p2 =
99 XCreateInsensitivePixmap(DisplayOfScreen(XtScreen(buttonWidget)), p1);
100 m_insensPixmap = (WXPixmap) p2;
101 }
102
103 XtVaSetValues (buttonWidget,
104 XmNlabelPixmap, p1,
105 XmNlabelInsensitivePixmap, p2,
106 XmNarmPixmap, (Pixmap) ((wxBitmap&)bitmap).GetArmPixmap (m_mainWidget),
107 XmNlabelType, XmPIXMAP,
108 NULL);
109 }
110
111 XtAddCallback (buttonWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback,
112 (XtPointer) this);
113
114 SetCanAddEventHandler(TRUE);
115 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
116
117 SetFont(* parent->GetFont());
4bb6408c 118
a4294b78 119 ChangeColour (m_mainWidget);
4bb6408c 120
4bb6408c 121
a4294b78
JS
122 return TRUE;
123}
124
125wxBitmapButton::~wxBitmapButton()
126{
127 SetBitmapLabel(wxNullBitmap);
128
129 if (m_insensPixmap)
130 XmDestroyPixmap (DefaultScreenOfDisplay ((Display*) GetXDisplay()), (Pixmap) m_insensPixmap);
4bb6408c
JS
131}
132
133void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
134{
135 m_buttonBitmap = bitmap;
a4294b78
JS
136
137 if (bitmap.Ok())
138 {
139 Pixmap labelPixmap, insensPixmap, armPixmap;
140
141 labelPixmap = (Pixmap) ((wxBitmap&)bitmap).GetLabelPixmap(m_mainWidget);
142
143 if (m_buttonBitmapSelected.Ok())
144 armPixmap = (Pixmap) m_buttonBitmapSelected.GetLabelPixmap(m_mainWidget);
145 else
146 armPixmap = (Pixmap) ((wxBitmap&)bitmap).GetArmPixmap(m_mainWidget);
147
148 if (m_buttonBitmapDisabled.Ok())
149 insensPixmap = (Pixmap) m_buttonBitmapDisabled.GetLabelPixmap(m_mainWidget);
150 else
151 insensPixmap = (Pixmap) ((wxBitmap&)bitmap).GetInsensPixmap(m_mainWidget);
152
153 if (!insensPixmap || (insensPixmap == labelPixmap)) // <- the Get...Pixmap()-functions return the same pixmap!
154 {
155 insensPixmap = XCreateInsensitivePixmap(DisplayOfScreen(XtScreen((Widget) m_mainWidget)), labelPixmap);
156 m_insensPixmap = (WXPixmap) insensPixmap;
157 }
158
159 XtVaSetValues ((Widget) m_mainWidget,
160 XmNlabelPixmap, labelPixmap,
161 XmNlabelInsensitivePixmap, insensPixmap,
162 XmNarmPixmap, armPixmap,
163 XmNlabelType, XmPIXMAP,
164 NULL);
165 }
166 else
167 {
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,
174 XmNarmPixmap, NULL,
175 NULL);
176 }
4bb6408c
JS
177}
178
a4294b78
JS
179void wxBitmapButton::SetBitmapSelected(const wxBitmap& sel)
180{
181 m_buttonBitmapSelected = sel;
182};
183
184void wxBitmapButton::SetBitmapFocus(const wxBitmap& focus)
185{
186 m_buttonBitmapFocus = focus;
187 // Not used in Motif
188};
189
190void wxBitmapButton::SetBitmapDisabled(const wxBitmap& disabled)
191{
192 m_buttonBitmapDisabled = disabled;
193};
194
195