28#include <wx/x11/private.h>
30class ocpCursorRefData :
public wxObjectRefData {
39ocpCursorRefData::ocpCursorRefData() {
44ocpCursorRefData::~ocpCursorRefData() {
45 if (m_cursor) XFreeCursor((Display*)m_display, (Cursor)m_cursor);
50#define M_CURSORDATA ((ocpCursorRefData*)m_refData)
52ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
54 : wxCursor(wxCURSOR_CROSS) {
57 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
59 cImage.LoadFile(cursorName);
61 int width = cImage.GetWidth();
62 int height = cImage.GetHeight();
67 int xscreen = DefaultScreen((Display*)wxGlobalDisplay());
68 Window xroot = RootWindow((Display*)wxGlobalDisplay(), xscreen);
69 Visual* xvisual = DefaultVisual((Display*)wxGlobalDisplay(), xscreen);
71 M_CURSORDATA->m_display = wxGlobalDisplay();
72 wxASSERT_MSG(M_CURSORDATA->m_display,
"No display");
76 XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
79 XImage* data_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
80 ZPixmap, 0, 0, width, height, 32, 0);
82 (
char*)malloc(data_image->bytes_per_line * data_image->height);
86 unsigned char* data = cImage.GetData();
91 unsigned char mr, mg, mb;
93 if (cImage.HasMask()) {
94 XImage* mask_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
95 ZPixmap, 0, 0, width, height, 32, 0);
97 (
char*)malloc(mask_image->bytes_per_line * mask_image->height);
99 cImage.GetOrFindMaskColour(&mr, &mg, &mb);
101 int rit = (mr << 16) + (mg << 8) + mb;
102 for (
int y = 0; y < height; y++) {
103 for (
int x = 0; x < width; x++) {
104 int ri = (int)data[index++];
105 ri += data[index++] << 8;
106 ri += data[index++] << 16;
119 XPutPixel(mask_image, x, y, pixel);
123 cmask = XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
125 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cmask, 0, NULL);
126 XPutImage((Display*)wxGlobalDisplay(), cmask, gc, mask_image, 0, 0, 0, 0,
129 XDestroyImage(mask_image);
130 XFreeGC((Display*)wxGlobalDisplay(), gc);
138 for (
int y = 0; y < height; y++) {
139 for (
int x = 0; x < width; x++) {
140 int ri = (int)data[index++];
141 ri += data[index++] << 8;
142 ri += data[index++] << 16;
155 XPutPixel(data_image, x, y, pixel);
161 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cpixmap, 0, NULL);
162 XPutImage((Display*)wxGlobalDisplay(), cpixmap, gc, data_image, 0, 0, 0, 0,
166 XDestroyImage(data_image);
167 XFreeGC((Display*)wxGlobalDisplay(), gc);
172 fg.red = fg.blue = fg.green = 0xffff;
173 bg.red = bg.blue = bg.green = 0;
175 M_CURSORDATA->m_cursor =
176 (WXCursor)XCreatePixmapCursor((Display*)wxGlobalDisplay(), cpixmap, cmask,
177 &fg, &bg, hotSpotX, hotSpotY);
180ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
182 : wxCursor(wxCURSOR_CROSS) {
183 wxImage cImage(xpm_data);
185 int width = cImage.GetWidth();
186 int height = cImage.GetHeight();
191 int xscreen = DefaultScreen((Display*)wxGlobalDisplay());
192 Window xroot = RootWindow((Display*)wxGlobalDisplay(), xscreen);
193 Visual* xvisual = DefaultVisual((Display*)wxGlobalDisplay(), xscreen);
195 M_CURSORDATA->m_display = wxGlobalDisplay();
196 wxASSERT_MSG(M_CURSORDATA->m_display,
"No display");
200 XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
203 XImage* data_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
204 ZPixmap, 0, 0, width, height, 32, 0);
206 (
char*)malloc(data_image->bytes_per_line * data_image->height);
210 unsigned char* data = cImage.GetData();
215 unsigned char mr, mg, mb;
217 if (cImage.HasMask()) {
218 XImage* mask_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
219 ZPixmap, 0, 0, width, height, 32, 0);
221 (
char*)malloc(mask_image->bytes_per_line * mask_image->height);
223 cImage.GetOrFindMaskColour(&mr, &mg, &mb);
225 int rit = (mr << 16) + (mg << 8) + mb;
226 for (
int y = 0; y < height; y++) {
227 for (
int x = 0; x < width; x++) {
228 int ri = (int)data[index++];
229 ri += data[index++] << 8;
230 ri += data[index++] << 16;
243 XPutPixel(mask_image, x, y, pixel);
247 cmask = XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
249 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cmask, 0, NULL);
250 XPutImage((Display*)wxGlobalDisplay(), cmask, gc, mask_image, 0, 0, 0, 0,
253 XDestroyImage(mask_image);
254 XFreeGC((Display*)wxGlobalDisplay(), gc);
262 for (
int y = 0; y < height; y++) {
263 for (
int x = 0; x < width; x++) {
264 int ri = (int)data[index++];
265 ri += data[index++] << 8;
266 ri += data[index++] << 16;
279 XPutPixel(data_image, x, y, pixel);
285 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cpixmap, 0, NULL);
286 XPutImage((Display*)wxGlobalDisplay(), cpixmap, gc, data_image, 0, 0, 0, 0,
290 XDestroyImage(data_image);
291 XFreeGC((Display*)wxGlobalDisplay(), gc);
296 fg.red = fg.blue = fg.green = 0xffff;
297 bg.red = bg.blue = bg.green = 0;
299 M_CURSORDATA->m_cursor =
300 (WXCursor)XCreatePixmapCursor((Display*)wxGlobalDisplay(), cpixmap, cmask,
301 &fg, &bg, hotSpotX, hotSpotY);
311ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
313 : wxCursor(wxCURSOR_ARROW)
318 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
320 cImage.LoadFile(cursorName);
327 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
329 dwxdc.SelectObject(tbmp);
334 HCURSOR hcursor = NULL;
337 wxLogWarning(_T(
"Failed to create ocpCursor." ));
343 GetGDIImageData()->m_handle = hcursor;
346ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
348 : wxCursor(wxCURSOR_ARROW)
351 wxImage cImage(xpm_data);
358 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
360 dwxdc.SelectObject(tbmp);
366 HCURSOR hcursor = NULL;
369 wxLogWarning(_T(
"Failed to create ocpCursor." ));
375 GetGDIImageData()->m_handle = hcursor;
380ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
382 : wxCursor(wxCURSOR_ARROW)
387 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
389 cImage.LoadFile(cursorName);
396 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
404ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
406 : wxCursor(wxCURSOR_ARROW)
409 wxImage cImage(xpm_data);
411 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
Platform specific wxCursor extension.