29#include <wx/x11/private.h>
31class ocpCursorRefData :
public wxObjectRefData {
40ocpCursorRefData::ocpCursorRefData() {
45ocpCursorRefData::~ocpCursorRefData() {
46 if (m_cursor) XFreeCursor((Display*)m_display, (Cursor)m_cursor);
51#define M_CURSORDATA ((ocpCursorRefData*)m_refData)
53ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
55 : wxCursor(wxCURSOR_CROSS) {
58 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
60 cImage.LoadFile(cursorName);
62 int width = cImage.GetWidth();
63 int height = cImage.GetHeight();
68 int xscreen = DefaultScreen((Display*)wxGlobalDisplay());
69 Window xroot = RootWindow((Display*)wxGlobalDisplay(), xscreen);
70 Visual* xvisual = DefaultVisual((Display*)wxGlobalDisplay(), xscreen);
72 M_CURSORDATA->m_display = wxGlobalDisplay();
73 wxASSERT_MSG(M_CURSORDATA->m_display, wxT(
"No display"));
77 XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
80 XImage* data_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
81 ZPixmap, 0, 0, width, height, 32, 0);
83 (
char*)malloc(data_image->bytes_per_line * data_image->height);
87 unsigned char* data = cImage.GetData();
92 unsigned char mr, mg, mb;
94 if (cImage.HasMask()) {
95 XImage* mask_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
96 ZPixmap, 0, 0, width, height, 32, 0);
98 (
char*)malloc(mask_image->bytes_per_line * mask_image->height);
100 cImage.GetOrFindMaskColour(&mr, &mg, &mb);
102 int rit = (mr << 16) + (mg << 8) + mb;
103 for (
int y = 0; y < height; y++) {
104 for (
int x = 0; x < width; x++) {
105 int ri = (int)data[index++];
106 ri += data[index++] << 8;
107 ri += data[index++] << 16;
120 XPutPixel(mask_image, x, y, pixel);
124 cmask = XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
126 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cmask, 0, NULL);
127 XPutImage((Display*)wxGlobalDisplay(), cmask, gc, mask_image, 0, 0, 0, 0,
130 XDestroyImage(mask_image);
131 XFreeGC((Display*)wxGlobalDisplay(), gc);
139 for (
int y = 0; y < height; y++) {
140 for (
int x = 0; x < width; x++) {
141 int ri = (int)data[index++];
142 ri += data[index++] << 8;
143 ri += data[index++] << 16;
156 XPutPixel(data_image, x, y, pixel);
162 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cpixmap, 0, NULL);
163 XPutImage((Display*)wxGlobalDisplay(), cpixmap, gc, data_image, 0, 0, 0, 0,
167 XDestroyImage(data_image);
168 XFreeGC((Display*)wxGlobalDisplay(), gc);
173 fg.red = fg.blue = fg.green = 0xffff;
174 bg.red = bg.blue = bg.green = 0;
176 M_CURSORDATA->m_cursor =
177 (WXCursor)XCreatePixmapCursor((Display*)wxGlobalDisplay(), cpixmap, cmask,
178 &fg, &bg, hotSpotX, hotSpotY);
181ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
183 : wxCursor(wxCURSOR_CROSS) {
184 wxImage cImage(xpm_data);
186 int width = cImage.GetWidth();
187 int height = cImage.GetHeight();
192 int xscreen = DefaultScreen((Display*)wxGlobalDisplay());
193 Window xroot = RootWindow((Display*)wxGlobalDisplay(), xscreen);
194 Visual* xvisual = DefaultVisual((Display*)wxGlobalDisplay(), xscreen);
196 M_CURSORDATA->m_display = wxGlobalDisplay();
197 wxASSERT_MSG(M_CURSORDATA->m_display, wxT(
"No display"));
201 XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
204 XImage* data_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
205 ZPixmap, 0, 0, width, height, 32, 0);
207 (
char*)malloc(data_image->bytes_per_line * data_image->height);
211 unsigned char* data = cImage.GetData();
216 unsigned char mr, mg, mb;
218 if (cImage.HasMask()) {
219 XImage* mask_image = XCreateImage((Display*)wxGlobalDisplay(), xvisual, 1,
220 ZPixmap, 0, 0, width, height, 32, 0);
222 (
char*)malloc(mask_image->bytes_per_line * mask_image->height);
224 cImage.GetOrFindMaskColour(&mr, &mg, &mb);
226 int rit = (mr << 16) + (mg << 8) + mb;
227 for (
int y = 0; y < height; y++) {
228 for (
int x = 0; x < width; x++) {
229 int ri = (int)data[index++];
230 ri += data[index++] << 8;
231 ri += data[index++] << 16;
244 XPutPixel(mask_image, x, y, pixel);
248 cmask = XCreatePixmap((Display*)wxGlobalDisplay(), xroot, width, height, 1);
250 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cmask, 0, NULL);
251 XPutImage((Display*)wxGlobalDisplay(), cmask, gc, mask_image, 0, 0, 0, 0,
254 XDestroyImage(mask_image);
255 XFreeGC((Display*)wxGlobalDisplay(), gc);
263 for (
int y = 0; y < height; y++) {
264 for (
int x = 0; x < width; x++) {
265 int ri = (int)data[index++];
266 ri += data[index++] << 8;
267 ri += data[index++] << 16;
280 XPutPixel(data_image, x, y, pixel);
286 GC gc = XCreateGC((Display*)wxGlobalDisplay(), cpixmap, 0, NULL);
287 XPutImage((Display*)wxGlobalDisplay(), cpixmap, gc, data_image, 0, 0, 0, 0,
291 XDestroyImage(data_image);
292 XFreeGC((Display*)wxGlobalDisplay(), gc);
297 fg.red = fg.blue = fg.green = 0xffff;
298 bg.red = bg.blue = bg.green = 0;
300 M_CURSORDATA->m_cursor =
301 (WXCursor)XCreatePixmapCursor((Display*)wxGlobalDisplay(), cpixmap, cmask,
302 &fg, &bg, hotSpotX, hotSpotY);
312ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
314 : wxCursor(wxCURSOR_ARROW)
319 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
321 cImage.LoadFile(cursorName);
328 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
330 dwxdc.SelectObject(tbmp);
335 HCURSOR hcursor = NULL;
338 wxLogWarning(_T(
"Failed to create ocpCursor." ));
344 GetGDIImageData()->m_handle = hcursor;
347ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
349 : wxCursor(wxCURSOR_ARROW)
352 wxImage cImage(xpm_data);
359 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
361 dwxdc.SelectObject(tbmp);
367 HCURSOR hcursor = NULL;
370 wxLogWarning(_T(
"Failed to create ocpCursor." ));
376 GetGDIImageData()->m_handle = hcursor;
381ocpCursor::ocpCursor(
const wxString& cursorName,
long type,
int hotSpotX,
383 : wxCursor(wxCURSOR_ARROW)
388 if (!cImage.CanRead(cursorName)) ::wxInitAllImageHandlers();
390 cImage.LoadFile(cursorName);
397 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);
405ocpCursor::ocpCursor(
const char** xpm_data,
long type,
int hotSpotX,
407 : wxCursor(wxCURSOR_ARROW)
410 wxImage cImage(xpm_data);
412 wxBitmap tbmp(cImage.GetWidth(), cImage.GetHeight(), -1);