You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fltk-1_v5.3.x-cursor.patch 49KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  1. diff -up fltk-1.3.2/CMakeLists.txt.cursor fltk-1.3.2/CMakeLists.txt
  2. --- fltk-1.3.2/CMakeLists.txt.cursor 2013-01-30 16:07:59.510320246 +0100
  3. +++ fltk-1.3.2/CMakeLists.txt 2013-01-30 16:07:59.528319926 +0100
  4. @@ -529,6 +529,20 @@ else()
  5. endif(OPTION_USE_XFIXES)
  6. #######################################################################
  7. +if(X11_Xcursor_FOUND)
  8. + option(OPTION_USE_XCURSOR "use lib XCURSOR" ON)
  9. +endif(X11_Xcursor_FOUND)
  10. +
  11. +if(OPTION_USE_XCURSOR)
  12. + set(HAVE_XCURSOR ${X11_Xcursor_FOUND})
  13. + include_directories(${X11_Xcursor_INCLUDE_PATH})
  14. + list(APPEND FLTK_LDLIBS -lXcursor)
  15. + set(FLTK_XCURSOR_FOUND TRUE)
  16. +else()
  17. + set(FLTK_XCURSOR_FOUND FALSE)
  18. +endif(OPTION_USE_XCURSOR)
  19. +
  20. +#######################################################################
  21. if(X11_Xft_FOUND)
  22. option(OPTION_USE_XFT "use lib Xft" ON)
  23. endif(X11_Xft_FOUND)
  24. diff -up fltk-1.3.2/configh.cmake.in.cursor fltk-1.3.2/configh.cmake.in
  25. --- fltk-1.3.2/configh.cmake.in.cursor 2013-01-30 16:07:59.510320246 +0100
  26. +++ fltk-1.3.2/configh.cmake.in 2013-01-30 16:07:59.529319908 +0100
  27. @@ -116,6 +116,14 @@
  28. #cmakedefine01 HAVE_XFIXES
  29. /*
  30. + * HAVE_XCURSOR:
  31. + *
  32. + * Do we have the X cursor library?
  33. + */
  34. +
  35. +#cmakedefine01 HAVE_XCURSOR
  36. +
  37. +/*
  38. * __APPLE_QUARTZ__:
  39. *
  40. * If __APPLE_QUARTZ__ is defined, FLTK will be
  41. diff -up fltk-1.3.2/configh.in.cursor fltk-1.3.2/configh.in
  42. --- fltk-1.3.2/configh.in.cursor 2013-01-30 16:07:59.510320246 +0100
  43. +++ fltk-1.3.2/configh.in 2013-01-30 16:07:59.529319908 +0100
  44. @@ -116,6 +116,14 @@
  45. #define HAVE_XFIXES 0
  46. /*
  47. + * HAVE_XCURSOR:
  48. + *
  49. + * Do we have the X cursor library?
  50. + */
  51. +
  52. +#define HAVE_XCURSOR 0
  53. +
  54. +/*
  55. * __APPLE_QUARTZ__:
  56. *
  57. * All Apple implementations are now based on Quartz and Cocoa,
  58. diff -up fltk-1.3.2/configure.in.cursor fltk-1.3.2/configure.in
  59. --- fltk-1.3.2/configure.in.cursor 2013-01-30 16:07:59.511320228 +0100
  60. +++ fltk-1.3.2/configure.in 2013-01-30 16:07:59.529319908 +0100
  61. @@ -1009,6 +1009,16 @@ case $uname_GUI in
  62. LIBS="-lXfixes $LIBS")
  63. fi
  64. + dnl Check for the Xcursor library unless disabled...
  65. + AC_ARG_ENABLE(xcursor, [ --enable-xcursor turn on Xcursor support [default=yes]])
  66. +
  67. + if test x$enable_xcursor != xno; then
  68. + AC_CHECK_HEADER(X11/Xcursor/Xcursor.h, AC_DEFINE(HAVE_XCURSOR),,
  69. + [#include <X11/Xlib.h>])
  70. + AC_CHECK_LIB(Xcursor, XcursorImageCreate,
  71. + LIBS="-lXcursor $LIBS")
  72. + fi
  73. +
  74. dnl Check for overlay visuals...
  75. AC_PATH_PROG(XPROP, xprop)
  76. AC_CACHE_CHECK(for X overlay visuals, ac_cv_have_overlay,
  77. diff -up fltk-1.3.2/FL/Enumerations.H.cursor fltk-1.3.2/FL/Enumerations.H
  78. --- fltk-1.3.2/FL/Enumerations.H.cursor 2013-01-30 16:07:59.486320673 +0100
  79. +++ fltk-1.3.2/FL/Enumerations.H 2013-01-30 16:07:59.530319891 +0100
  80. @@ -879,35 +879,36 @@ inline Fl_Color fl_color_cube(int r, int
  81. /** The following constants define the mouse cursors that are available in FLTK.
  82. - The double-headed arrows are bitmaps provided by FLTK on X, the others
  83. - are provided by system-defined cursors.
  84. + Cursors are provided by the system when available, or bitmaps built into
  85. + FLTK as a fallback.
  86. \todo enum Fl_Cursor needs maybe an image.
  87. */
  88. enum Fl_Cursor {
  89. FL_CURSOR_DEFAULT = 0, /**< the default cursor, usually an arrow. */
  90. - FL_CURSOR_ARROW = 35, /**< an arrow pointer. */
  91. - FL_CURSOR_CROSS = 66, /**< crosshair. */
  92. - FL_CURSOR_WAIT = 76, /**< watch or hourglass. */
  93. - FL_CURSOR_INSERT = 77, /**< I-beam. */
  94. - FL_CURSOR_HAND = 31, /**< hand (uparrow on MSWindows). */
  95. - FL_CURSOR_HELP = 47, /**< question mark. */
  96. - FL_CURSOR_MOVE = 27, /**< 4-pointed arrow. */
  97. - // fltk provides bitmaps for these:
  98. - FL_CURSOR_NS = 78, /**< up/down arrow. */
  99. - FL_CURSOR_WE = 79, /**< left/right arrow. */
  100. - FL_CURSOR_NWSE = 80, /**< diagonal arrow. */
  101. - FL_CURSOR_NESW = 81, /**< diagonal arrow. */
  102. - FL_CURSOR_NONE =255, /**< invisible. */
  103. - // for back compatibility (non MSWindows ones):
  104. - FL_CURSOR_N = 70, /**< for back compatibility. */
  105. - FL_CURSOR_NE = 69, /**< for back compatibility. */
  106. - FL_CURSOR_E = 49, /**< for back compatibility. */
  107. - FL_CURSOR_SE = 8, /**< for back compatibility. */
  108. - FL_CURSOR_S = 9, /**< for back compatibility. */
  109. - FL_CURSOR_SW = 7, /**< for back compatibility. */
  110. - FL_CURSOR_W = 36, /**< for back compatibility. */
  111. - FL_CURSOR_NW = 68 /**< for back compatibility. */
  112. + FL_CURSOR_ARROW = 1, /**< an arrow pointer. */
  113. + FL_CURSOR_CROSS = 2, /**< crosshair. */
  114. + FL_CURSOR_WAIT = 3, /**< busy indicator (e.g. hourglass). */
  115. + FL_CURSOR_INSERT = 4, /**< I-beam. */
  116. + FL_CURSOR_HAND = 5, /**< pointing hand. */
  117. + FL_CURSOR_HELP = 6, /**< question mark pointer. */
  118. + FL_CURSOR_MOVE = 7, /**< 4-pointed arrow or hand. */
  119. +
  120. + /* Resize indicators */
  121. + FL_CURSOR_NS = 101, /**< up/down resize. */
  122. + FL_CURSOR_WE = 102, /**< left/right resize. */
  123. + FL_CURSOR_NWSE = 103, /**< diagonal resize. */
  124. + FL_CURSOR_NESW = 104, /**< diagonal resize. */
  125. + FL_CURSOR_NE = 110, /**< upwards, right resize. */
  126. + FL_CURSOR_N = 111, /**< upwards resize. */
  127. + FL_CURSOR_NW = 112, /**< upwards, left resize. */
  128. + FL_CURSOR_E = 113, /**< leftwards resize. */
  129. + FL_CURSOR_W = 114, /**< rightwards resize. */
  130. + FL_CURSOR_SE = 115, /**< downwards, right resize. */
  131. + FL_CURSOR_S = 116, /**< downwards resize. */
  132. + FL_CURSOR_SW = 117, /**< downwards, left resize. */
  133. +
  134. + FL_CURSOR_NONE = 255, /**< invisible. */
  135. };
  136. /*@}*/ // group: Cursors
  137. diff -up fltk-1.3.2/FL/fl_draw.H.cursor fltk-1.3.2/FL/fl_draw.H
  138. --- fltk-1.3.2/FL/fl_draw.H.cursor 2012-05-08 18:15:34.000000000 +0200
  139. +++ fltk-1.3.2/FL/fl_draw.H 2013-01-30 16:07:59.530319891 +0100
  140. @@ -751,7 +751,8 @@ FL_EXPORT const char* fl_shortcut_label(
  141. FL_EXPORT unsigned int fl_old_shortcut(const char* s);
  142. FL_EXPORT void fl_overlay_rect(int x,int y,int w,int h);
  143. FL_EXPORT void fl_overlay_clear();
  144. -FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg=FL_BLACK, Fl_Color bg=FL_WHITE);
  145. +FL_EXPORT void fl_cursor(Fl_Cursor);
  146. +FL_EXPORT void fl_cursor(Fl_Cursor, Fl_Color fg, Fl_Color bg=FL_WHITE);
  147. FL_EXPORT const char* fl_expand_text(const char* from, char* buf, int maxbuf,
  148. double maxw, int& n, double &width,
  149. int wrap, int draw_symbols = 0);
  150. diff -up fltk-1.3.2/FL/Fl_Window.H.cursor fltk-1.3.2/FL/Fl_Window.H
  151. --- fltk-1.3.2/FL/Fl_Window.H.cursor 2012-11-06 21:46:14.000000000 +0100
  152. +++ fltk-1.3.2/FL/Fl_Window.H 2013-01-30 16:07:59.531319873 +0100
  153. @@ -28,6 +28,7 @@
  154. #define FL_DOUBLE_WINDOW 0xF1 ///< double window type id
  155. class Fl_X;
  156. +class Fl_RGB_Image;
  157. /**
  158. This widget produces an actual window. This can either be a main
  159. @@ -81,7 +82,6 @@ class FL_EXPORT Fl_Window : public Fl_Gr
  160. uchar size_range_set;
  161. // cursor stuff
  162. Fl_Cursor cursor_default;
  163. - Fl_Color cursor_fg, cursor_bg;
  164. void size_range_();
  165. void _Fl_Window(); // constructor innards
  166. void fullscreen_x(); // platform-specific part of sending a window to full screen
  167. @@ -466,14 +466,17 @@ public:
  168. is different.
  169. The type Fl_Cursor is an enumeration defined in <FL/Enumerations.H>.
  170. - (Under X you can get any XC_cursor value by passing
  171. - Fl_Cursor((XC_foo/2)+1)). The colors only work on X, they are
  172. - not implemented on WIN32.
  173. - For back compatibility only.
  174. + \see cursor(const Fl_RGB_Image*, int, int), default_cursor()
  175. */
  176. - void cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE); // platform dependent
  177. - void default_cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE);
  178. + void cursor(Fl_Cursor);
  179. + void cursor(const Fl_RGB_Image*, int, int);
  180. + void default_cursor(Fl_Cursor);
  181. +
  182. + /* for legacy compatibility */
  183. + void cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE);
  184. + void default_cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE);
  185. +
  186. static void default_callback(Fl_Window*, void* v);
  187. /** Returns the window width including any frame added by the window manager.
  188. diff -up fltk-1.3.2/FL/mac.H.cursor fltk-1.3.2/FL/mac.H
  189. --- fltk-1.3.2/FL/mac.H.cursor 2012-11-13 15:45:42.000000000 +0100
  190. +++ fltk-1.3.2/FL/mac.H 2013-01-30 16:07:59.531319873 +0100
  191. @@ -120,7 +120,8 @@ public:
  192. void collapse(void);
  193. WindowRef window_ref(void);
  194. void set_key_window(void);
  195. - void set_cursor(Fl_Cursor);
  196. + int set_cursor(Fl_Cursor);
  197. + int set_cursor(const Fl_RGB_Image*, int, int);
  198. static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
  199. static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
  200. static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
  201. diff -up fltk-1.3.2/FL/win32.H.cursor fltk-1.3.2/FL/win32.H
  202. --- fltk-1.3.2/FL/win32.H.cursor 2012-03-12 12:55:50.000000000 +0100
  203. +++ fltk-1.3.2/FL/win32.H 2013-01-30 16:07:59.531319873 +0100
  204. @@ -73,6 +73,7 @@ public:
  205. int wait_for_expose;
  206. HDC private_dc; // used for OpenGL
  207. HCURSOR cursor;
  208. + int custom_cursor;
  209. HDC saved_hdc; // saves the handle of the DC currently loaded
  210. // static variables, static functions and member functions
  211. static Fl_X* first;
  212. @@ -83,6 +84,8 @@ public:
  213. void flush() {w->flush();}
  214. void set_minmax(LPMINMAXINFO minmax);
  215. void mapraise();
  216. + int set_cursor(Fl_Cursor);
  217. + int set_cursor(const Fl_RGB_Image*, int, int);
  218. static Fl_X* make(Fl_Window*);
  219. };
  220. extern FL_EXPORT HCURSOR fl_default_cursor;
  221. diff -up fltk-1.3.2/FL/x.H.cursor fltk-1.3.2/FL/x.H
  222. --- fltk-1.3.2/FL/x.H.cursor 2012-03-23 17:47:53.000000000 +0100
  223. +++ fltk-1.3.2/FL/x.H 2013-01-30 16:07:59.532319855 +0100
  224. @@ -154,6 +154,8 @@ public:
  225. static Fl_X* i(const Fl_Window* wi) {return wi->i;}
  226. void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
  227. void sendxjunk();
  228. + int set_cursor(Fl_Cursor);
  229. + int set_cursor(const Fl_RGB_Image*, int, int);
  230. static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
  231. static Fl_X* set_xid(Fl_Window*, Window);
  232. // kludges to get around protection:
  233. diff -up fltk-1.3.2/src/CMakeLists.txt.cursor fltk-1.3.2/src/CMakeLists.txt
  234. --- fltk-1.3.2/src/CMakeLists.txt.cursor 2013-01-30 16:09:11.981032475 +0100
  235. +++ fltk-1.3.2/src/CMakeLists.txt 2013-01-30 16:09:26.497774461 +0100
  236. @@ -247,6 +247,10 @@ if(HAVE_XFIXES)
  237. target_link_libraries(fltk ${X11_Xfixes_LIB})
  238. endif(HAVE_XFIXES)
  239. +if(HAVE_XCURSOR)
  240. + target_link_libraries(fltk ${X11_Xcursor_LIB})
  241. +endif(HAVE_XCURSOR)
  242. +
  243. if(USE_XFT)
  244. target_link_libraries(fltk ${X11_Xft_LIB})
  245. endif(USE_XFT)
  246. diff -up fltk-1.3.2/src/Fl_cocoa.mm.cursor fltk-1.3.2/src/Fl_cocoa.mm
  247. --- fltk-1.3.2/src/Fl_cocoa.mm.cursor 2013-01-30 16:07:59.522320033 +0100
  248. +++ fltk-1.3.2/src/Fl_cocoa.mm 2013-01-30 16:07:59.533319837 +0100
  249. @@ -98,7 +98,6 @@ Fl_Display_Device *Fl_Display_Device::_d
  250. CGContextRef fl_gc = 0;
  251. void *fl_system_menu; // this is really a NSMenu*
  252. Fl_Sys_Menu_Bar *fl_sys_menu_bar = 0;
  253. -void *fl_default_cursor; // this is really a NSCursor*
  254. void *fl_capture = 0; // (NSWindow*) we need this to compensate for a missing(?) mouse capture
  255. bool fl_show_iconic; // true if called from iconize() - shows the next created window in collapsed state
  256. //int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
  257. @@ -1392,8 +1391,6 @@ void fl_open_display() {
  258. dequeue:YES];
  259. while (ign_event);
  260. - fl_default_cursor = [NSCursor arrowCursor];
  261. -
  262. // bring the application into foreground without a 'CARB' resource
  263. Boolean same_psn;
  264. ProcessSerialNumber cur_psn, front_psn;
  265. @@ -1698,6 +1695,7 @@ static void q_set_window_title(NSWindow
  266. - (void)drawRect:(NSRect)rect;
  267. - (BOOL)acceptsFirstResponder;
  268. - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent;
  269. +- (void)resetCursorRects;
  270. - (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
  271. - (void)mouseUp:(NSEvent *)theEvent;
  272. - (void)rightMouseUp:(NSEvent *)theEvent;
  273. @@ -1756,6 +1754,16 @@ static void q_set_window_title(NSWindow
  274. Fl_Window *first = Fl::first_window();
  275. return (first == w || !first->modal());
  276. }
  277. +- (void)resetCursorRects {
  278. + Fl_Window *w = [(FLWindow*)[self window] getFl_Window];
  279. + Fl_X *i = Fl_X::i(w);
  280. + // We have to have at least one cursor rect for invalidateCursorRectsForView
  281. + // to work, hence the "else" clause.
  282. + if (i->cursor)
  283. + [self addCursorRect:[self visibleRect] cursor:(NSCursor*)i->cursor];
  284. + else
  285. + [self addCursorRect:[self visibleRect] cursor:[NSCursor arrowCursor]];
  286. +}
  287. - (void)mouseUp:(NSEvent *)theEvent {
  288. cocoaMouseHandler(theEvent);
  289. }
  290. @@ -2331,7 +2339,7 @@ void Fl_X::make(Fl_Window* w)
  291. x->other_xid = 0;
  292. x->region = 0;
  293. x->subRegion = 0;
  294. - x->cursor = fl_default_cursor;
  295. + x->cursor = NULL;
  296. x->gc = 0; // stay 0 for Quickdraw; fill with CGContext for Quartz
  297. Fl_Window *win = w->window();
  298. Fl_X *xo = Fl_X::i(win);
  299. @@ -2427,7 +2435,7 @@ void Fl_X::make(Fl_Window* w)
  300. x->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows
  301. x->region = 0;
  302. x->subRegion = 0;
  303. - x->cursor = fl_default_cursor;
  304. + x->cursor = NULL;
  305. x->xidChildren = 0;
  306. x->xidNext = 0;
  307. x->gc = 0;
  308. @@ -2974,6 +2982,10 @@ void Fl_X::map() {
  309. Fl_X::relink(w, w->window() );
  310. w->redraw();
  311. }
  312. + if (cursor) {
  313. + [(NSCursor*)cursor release];
  314. + cursor = NULL;
  315. + }
  316. }
  317. void Fl_X::unmap() {
  318. @@ -3078,68 +3090,106 @@ static NSImage *CGBitmapContextToNSImage
  319. return [image autorelease];
  320. }
  321. -static NSCursor *PrepareCursor(NSCursor *cursor, CGContextRef (*f)() )
  322. +int Fl_X::set_cursor(Fl_Cursor c)
  323. {
  324. - if (cursor == nil) {
  325. - CGContextRef c = f();
  326. - NSImage *image = CGBitmapContextToNSImage(c);
  327. - fl_delete_offscreen( (Fl_Offscreen)c );
  328. - NSPoint pt = {[image size].width/2, [image size].height/2};
  329. - cursor = [[NSCursor alloc] initWithImage:image hotSpot:pt];
  330. + if (cursor) {
  331. + [(NSCursor*)cursor release];
  332. + cursor = NULL;
  333. }
  334. - return cursor;
  335. -}
  336. -void Fl_X::set_cursor(Fl_Cursor c)
  337. -{
  338. - NSCursor *icrsr;
  339. switch (c) {
  340. - case FL_CURSOR_CROSS: icrsr = [NSCursor crosshairCursor]; break;
  341. - case FL_CURSOR_WAIT:
  342. - static NSCursor *watch = nil;
  343. - watch = PrepareCursor(watch, &Fl_X::watch_cursor_image);
  344. - icrsr = watch;
  345. - break;
  346. - case FL_CURSOR_INSERT: icrsr = [NSCursor IBeamCursor]; break;
  347. - case FL_CURSOR_N: icrsr = [NSCursor resizeUpCursor]; break;
  348. - case FL_CURSOR_S: icrsr = [NSCursor resizeDownCursor]; break;
  349. - case FL_CURSOR_NS: icrsr = [NSCursor resizeUpDownCursor]; break;
  350. - case FL_CURSOR_HELP:
  351. - static NSCursor *help = nil;
  352. - help = PrepareCursor(help, &Fl_X::help_cursor_image);
  353. - icrsr = help;
  354. - break;
  355. - case FL_CURSOR_HAND: icrsr = [NSCursor pointingHandCursor]; break;
  356. - case FL_CURSOR_MOVE: icrsr = [NSCursor openHandCursor]; break;
  357. - case FL_CURSOR_NE:
  358. - case FL_CURSOR_SW:
  359. - case FL_CURSOR_NESW:
  360. - static NSCursor *nesw = nil;
  361. - nesw = PrepareCursor(nesw, &Fl_X::nesw_cursor_image);
  362. - icrsr = nesw;
  363. - break;
  364. - case FL_CURSOR_E: icrsr = [NSCursor resizeRightCursor]; break;
  365. - case FL_CURSOR_W: icrsr = [NSCursor resizeLeftCursor]; break;
  366. - case FL_CURSOR_WE: icrsr = [NSCursor resizeLeftRightCursor]; break;
  367. - case FL_CURSOR_SE:
  368. - case FL_CURSOR_NW:
  369. - case FL_CURSOR_NWSE:
  370. - static NSCursor *nwse = nil;
  371. - nwse = PrepareCursor(nwse, &Fl_X::nwse_cursor_image);
  372. - icrsr = nwse;
  373. - break;
  374. - case FL_CURSOR_NONE:
  375. - static NSCursor *none = nil;
  376. - none = PrepareCursor(none, &Fl_X::none_cursor_image);
  377. - icrsr = none;
  378. - break;
  379. - case FL_CURSOR_ARROW:
  380. - case FL_CURSOR_DEFAULT:
  381. - default: icrsr = [NSCursor arrowCursor];
  382. - break;
  383. + case FL_CURSOR_ARROW: cursor = [NSCursor arrowCursor]; break;
  384. + case FL_CURSOR_CROSS: cursor = [NSCursor crosshairCursor]; break;
  385. + case FL_CURSOR_INSERT: cursor = [NSCursor IBeamCursor]; break;
  386. + case FL_CURSOR_HAND: cursor = [NSCursor pointingHandCursor]; break;
  387. + case FL_CURSOR_MOVE: cursor = [NSCursor openHandCursor]; break;
  388. + case FL_CURSOR_NS: cursor = [NSCursor resizeUpDownCursor]; break;
  389. + case FL_CURSOR_WE: cursor = [NSCursor resizeLeftRightCursor]; break;
  390. + case FL_CURSOR_N: cursor = [NSCursor resizeUpCursor]; break;
  391. + case FL_CURSOR_E: cursor = [NSCursor resizeRightCursor]; break;
  392. + case FL_CURSOR_W: cursor = [NSCursor resizeLeftCursor]; break;
  393. + case FL_CURSOR_S: cursor = [NSCursor resizeDownCursor]; break;
  394. + default:
  395. + return 0;
  396. + }
  397. +
  398. + [(NSCursor*)cursor retain];
  399. +
  400. + [(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
  401. +
  402. + return 1;
  403. +}
  404. +
  405. +int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  406. + if (cursor) {
  407. + [(NSCursor*)cursor release];
  408. + cursor = NULL;
  409. + }
  410. +
  411. + if ((hotx < 0) || (hotx >= image->w()))
  412. + return 0;
  413. + if ((hoty < 0) || (hoty >= image->h()))
  414. + return 0;
  415. +
  416. + // OS X >= 10.6 can create a NSImage from a CGImage, but we need to
  417. + // support older versions, hence this pesky handling.
  418. +
  419. + NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
  420. + initWithBitmapDataPlanes:NULL
  421. + pixelsWide:image->w()
  422. + pixelsHigh:image->h()
  423. + bitsPerSample:8
  424. + samplesPerPixel:image->d()
  425. + hasAlpha:!(image->d() & 1)
  426. + isPlanar:NO
  427. + colorSpaceName:(image->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
  428. + bytesPerRow:(image->w() * image->d())
  429. + bitsPerPixel:(image->d()*8)];
  430. +
  431. + // Alpha needs to be premultiplied for this format
  432. +
  433. + const uchar *i = (const uchar*)*image->data();
  434. + unsigned char *o = [bitmap bitmapData];
  435. + for (int y = 0;y < image->h();y++) {
  436. + if (image->d() & 1) {
  437. + for (int x = 0;x < image->w();x++) {
  438. + unsigned int alpha;
  439. + if (image->d() == 4) {
  440. + alpha = i[3];
  441. + *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
  442. + *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
  443. + }
  444. +
  445. + alpha = i[1];
  446. + *o++ = (unsigned char)((unsigned int)*i++ * alpha / 255);
  447. + *o++ = alpha;
  448. + i++;
  449. + }
  450. + } else {
  451. + // No alpha, so we can just copy everything directly.
  452. + int len = image->w() * image->d();
  453. + memcpy(o, i, len);
  454. + o += len;
  455. + i += len;
  456. + }
  457. + i += image->ld();
  458. }
  459. - [icrsr set];
  460. - cursor = icrsr;
  461. +
  462. + NSImage *nsimage = [[NSImage alloc]
  463. + initWithSize:NSMakeSize(image->w(), image->h())];
  464. +
  465. + [nsimage addRepresentation:bitmap];
  466. +
  467. + cursor = [[NSCursor alloc]
  468. + initWithImage:nsimage
  469. + hotSpot:NSMakePoint(hotx, hoty)];
  470. +
  471. + [(NSWindow*)xid invalidateCursorRectsForView:[(NSWindow*)xid contentView]];
  472. +
  473. + [bitmap release];
  474. + [nsimage release];
  475. +
  476. + return 1;
  477. }
  478. @interface FLaboutItemTarget : NSObject
  479. diff -up fltk-1.3.2/src/fl_cursor.cxx.cursor fltk-1.3.2/src/fl_cursor.cxx
  480. --- fltk-1.3.2/src/fl_cursor.cxx.cursor 2012-03-12 12:55:50.000000000 +0100
  481. +++ fltk-1.3.2/src/fl_cursor.cxx 2013-01-30 16:07:59.534319820 +0100
  482. @@ -24,297 +24,165 @@
  483. #include <FL/Fl.H>
  484. #include <FL/Fl_Window.H>
  485. +#include <FL/Fl_Pixmap.H>
  486. +#include <FL/Fl_RGB_Image.H>
  487. #include <FL/x.H>
  488. -#if !defined(WIN32) && !defined(__APPLE__)
  489. -# include <X11/cursorfont.h>
  490. -#endif
  491. #include <FL/fl_draw.H>
  492. +#include "fl_cursor_wait.xpm"
  493. +#include "fl_cursor_help.xpm"
  494. +#include "fl_cursor_nwse.xpm"
  495. +#include "fl_cursor_nesw.xpm"
  496. +#include "fl_cursor_none.xpm"
  497. +
  498. /**
  499. Sets the cursor for the current window to the specified shape and colors.
  500. The cursors are defined in the <FL/Enumerations.H> header file.
  501. */
  502. +void fl_cursor(Fl_Cursor c) {
  503. + if (Fl::first_window()) Fl::first_window()->cursor(c);
  504. +}
  505. +
  506. +/* For back compatibility only. */
  507. void fl_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
  508. - if (Fl::first_window()) Fl::first_window()->cursor(c,fg,bg);
  509. + fl_cursor(c);
  510. }
  511. +
  512. +
  513. /**
  514. - Sets the default window cursor as well as its color.
  515. + Sets the default window cursor. This is the cursor that will be used
  516. + after the mouse pointer leaves a widget with a custom cursor set.
  517. - For back compatibility only.
  518. + \see cursor(const Fl_RGB_Image*, int, int), default_cursor()
  519. */
  520. -void Fl_Window::default_cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
  521. -// if (c == FL_CURSOR_DEFAULT) c = FL_CURSOR_ARROW;
  522. -
  523. +void Fl_Window::default_cursor(Fl_Cursor c) {
  524. cursor_default = c;
  525. - cursor_fg = fg;
  526. - cursor_bg = bg;
  527. + cursor(c);
  528. +}
  529. +
  530. +
  531. +void fallback_cursor(Fl_Window *w, Fl_Cursor c) {
  532. + const char **xpm;
  533. + int hotx, hoty;
  534. +
  535. + // The standard arrow is our final fallback, so something is broken
  536. + // if we get called back here with that as an argument.
  537. + if (c == FL_CURSOR_ARROW)
  538. + return;
  539. +
  540. + switch (c) {
  541. + case FL_CURSOR_WAIT:
  542. + xpm = (const char**)fl_cursor_wait_xpm;
  543. + hotx = 8;
  544. + hoty = 15;
  545. + break;
  546. + case FL_CURSOR_HELP:
  547. + xpm = (const char**)fl_cursor_help_xpm;
  548. + hotx = 1;
  549. + hoty = 3;
  550. + break;
  551. + case FL_CURSOR_NWSE:
  552. + xpm = (const char**)fl_cursor_nwse_xpm;
  553. + hotx = 7;
  554. + hoty = 7;
  555. + break;
  556. + case FL_CURSOR_NESW:
  557. + xpm = (const char**)fl_cursor_nesw_xpm;
  558. + hotx = 7;
  559. + hoty = 7;
  560. + break;
  561. + case FL_CURSOR_NONE:
  562. + xpm = (const char**)fl_cursor_none_xpm;
  563. + hotx = 0;
  564. + hoty = 0;
  565. + break;
  566. + default:
  567. + w->cursor(FL_CURSOR_ARROW);
  568. + return;
  569. + }
  570. - cursor(c, fg, bg);
  571. + Fl_Pixmap pxm(xpm);
  572. + Fl_RGB_Image image(&pxm);
  573. +
  574. + w->cursor(&image, hotx, hoty);
  575. }
  576. -#ifdef WIN32
  577. -# ifndef IDC_HAND
  578. -# define IDC_HAND MAKEINTRESOURCE(32649)
  579. -# endif // !IDC_HAND
  580. +void Fl_Window::cursor(Fl_Cursor c) {
  581. + int ret;
  582. -void Fl_Window::cursor(Fl_Cursor c, Fl_Color c1, Fl_Color c2) {
  583. - if (!shown()) return;
  584. // the cursor must be set for the top level window, not for subwindows
  585. Fl_Window *w = window(), *toplevel = this;
  586. - while (w) { toplevel = w; w = w->window(); }
  587. - if (toplevel != this) { toplevel->cursor(c, c1, c2); return; }
  588. - // now set the actual cursor
  589. - if (c == FL_CURSOR_DEFAULT) {
  590. - c = cursor_default;
  591. - }
  592. - if (c > FL_CURSOR_NESW) {
  593. - i->cursor = 0;
  594. - } else if (c == FL_CURSOR_DEFAULT) {
  595. - i->cursor = fl_default_cursor;
  596. - } else {
  597. - LPSTR n;
  598. - switch (c) {
  599. - case FL_CURSOR_ARROW: n = IDC_ARROW; break;
  600. - case FL_CURSOR_CROSS: n = IDC_CROSS; break;
  601. - case FL_CURSOR_WAIT: n = IDC_WAIT; break;
  602. - case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
  603. - case FL_CURSOR_HELP: n = IDC_HELP; break;
  604. - case FL_CURSOR_HAND: {
  605. - OSVERSIONINFO osvi;
  606. -
  607. - // Get the OS version: Windows 98 and 2000 have a standard
  608. - // hand cursor.
  609. - memset(&osvi, 0, sizeof(OSVERSIONINFO));
  610. - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  611. - GetVersionEx(&osvi);
  612. -
  613. - if (osvi.dwMajorVersion > 4 ||
  614. - (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion > 0 &&
  615. - osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)) n = IDC_HAND;
  616. - else n = IDC_UPARROW;
  617. - } break;
  618. - case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
  619. - case FL_CURSOR_N:
  620. - case FL_CURSOR_S:
  621. - case FL_CURSOR_NS: n = IDC_SIZENS; break;
  622. - case FL_CURSOR_NE:
  623. - case FL_CURSOR_SW:
  624. - case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
  625. - case FL_CURSOR_E:
  626. - case FL_CURSOR_W:
  627. - case FL_CURSOR_WE: n = IDC_SIZEWE; break;
  628. - case FL_CURSOR_SE:
  629. - case FL_CURSOR_NW:
  630. - case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
  631. - default: n = IDC_NO; break;
  632. - }
  633. - i->cursor = LoadCursor(NULL, n);
  634. +
  635. + while (w) {
  636. + toplevel = w;
  637. + w = w->window();
  638. }
  639. - SetCursor(i->cursor);
  640. -}
  641. -#elif defined(__APPLE__)
  642. + if (toplevel != this) {
  643. + toplevel->cursor(c);
  644. + return;
  645. + }
  646. -#ifdef __BIG_ENDIAN__
  647. -# define E(x) x
  648. -#elif defined __LITTLE_ENDIAN__
  649. -// Don't worry. This will be resolved at compile time
  650. -# define E(x) (x>>8)|((x<<8)&0xff00)
  651. -#else
  652. -# error "Either __LITTLE_ENDIAN__ or __BIG_ENDIAN__ must be defined"
  653. -#endif
  654. -
  655. -CGContextRef Fl_X::help_cursor_image(void)
  656. -{
  657. - int w = 20, h = 20;
  658. - Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  659. - fl_begin_offscreen(off);
  660. - CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
  661. - fl_rectf(0,0,w,h);
  662. - fl_color(FL_BLACK);
  663. - fl_font(FL_COURIER_BOLD, 20);
  664. - fl_draw("?", 1, h-1);
  665. - fl_end_offscreen();
  666. - return (CGContextRef)off;
  667. -}
  668. + if (c == FL_CURSOR_DEFAULT)
  669. + c = cursor_default;
  670. -CGContextRef Fl_X::none_cursor_image(void)
  671. -{
  672. - int w = 20, h = 20;
  673. - Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  674. - fl_begin_offscreen(off);
  675. - CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
  676. - fl_rectf(0,0,w,h);
  677. - fl_end_offscreen();
  678. - return (CGContextRef)off;
  679. -}
  680. + if (!i)
  681. + return;
  682. -CGContextRef Fl_X::watch_cursor_image(void)
  683. -{
  684. - int w, h, r = 5;
  685. - w = 2*r+6;
  686. - h = 4*r;
  687. - Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  688. - fl_begin_offscreen(off);
  689. - CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
  690. - fl_rectf(0,0,w,h);
  691. - CGContextTranslateCTM( (CGContextRef)off, w/2, h/2);
  692. - fl_color(FL_WHITE);
  693. - fl_circle(0, 0, r+1);
  694. - fl_color(FL_BLACK);
  695. - fl_rectf(int(-r*0.7), int(-r*1.7), int(1.4*r), int(3.4*r));
  696. - fl_rectf(r-1, -1, 3, 3);
  697. - fl_color(FL_WHITE);
  698. - fl_pie(-r, -r, 2*r, 2*r, 0, 360);
  699. - fl_color(FL_BLACK);
  700. - fl_circle(0,0,r);
  701. - fl_xyline(0, 0, int(-r*.7));
  702. - fl_xyline(0, 0, 0, int(-r*.7));
  703. - fl_end_offscreen();
  704. - return (CGContextRef)off;
  705. -}
  706. + ret = i->set_cursor(c);
  707. + if (ret)
  708. + return;
  709. -CGContextRef Fl_X::nesw_cursor_image(void)
  710. -{
  711. - int c = 7, r = 2*c;
  712. - int w = r, h = r;
  713. - Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  714. - fl_begin_offscreen(off);
  715. - CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
  716. - fl_rectf(0,0,w,h);
  717. - CGContextTranslateCTM( (CGContextRef)off, 0, h);
  718. - CGContextScaleCTM( (CGContextRef)off, 1, -1);
  719. - fl_color(FL_BLACK);
  720. - fl_polygon(0, 0, c, 0, 0, c);
  721. - fl_polygon(r, r, r, r-c, r-c, r);
  722. - fl_line_style(FL_SOLID, 2, 0);
  723. - fl_line(0,1, r,r+1);
  724. - fl_line_style(FL_SOLID, 0, 0);
  725. - fl_end_offscreen();
  726. - return (CGContextRef)off;
  727. + fallback_cursor(this, c);
  728. }
  729. -CGContextRef Fl_X::nwse_cursor_image(void)
  730. -{
  731. - int c = 7, r = 2*c;
  732. - int w = r, h = r;
  733. - Fl_Offscreen off = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  734. - fl_begin_offscreen(off);
  735. - CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
  736. - fl_rectf(0,0,w,h);
  737. - CGContextTranslateCTM( (CGContextRef)off, 0, h);
  738. - CGContextScaleCTM( (CGContextRef)off, 1, -1);
  739. - fl_color(FL_BLACK);
  740. - fl_polygon(r-1, 0, r-1, c, r-1-c, 0);
  741. - fl_polygon(-1, r, c-1, r, -1, r-c);
  742. - fl_line_style(FL_SOLID, 2, 0);
  743. - fl_line(r-1,1, -1,r+1);
  744. - fl_line_style(FL_SOLID, 0, 0);
  745. - fl_end_offscreen();
  746. - return (CGContextRef)off;
  747. -}
  748. -
  749. -void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
  750. - if (c == FL_CURSOR_DEFAULT) {
  751. - c = cursor_default;
  752. - }
  753. - if (i) i->set_cursor(c);
  754. -}
  755. +/**
  756. + Changes the cursor for this window. This always calls the system, if
  757. + you are changing the cursor a lot you may want to keep track of how
  758. + you set it in a static variable and call this only if the new cursor
  759. + is different.
  760. -#else
  761. + The default cursor will be used if the provided image cannot be used
  762. + as a cursor.
  763. -// I like the MSWindows resize cursors, so I duplicate them here:
  764. + \see cursor(Fl_Cursor), default_cursor()
  765. +*/
  766. +void Fl_Window::cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  767. + int ret;
  768. -#define CURSORSIZE 16
  769. -#define HOTXY 7
  770. -static struct TableEntry {
  771. - uchar bits[CURSORSIZE*CURSORSIZE/8];
  772. - uchar mask[CURSORSIZE*CURSORSIZE/8];
  773. - Cursor cursor;
  774. -} table[] = {
  775. - {{ // FL_CURSOR_NS
  776. - 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0x80, 0x01, 0x80, 0x01,
  777. - 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01,
  778. - 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00},
  779. - {
  780. - 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf0, 0x0f, 0xc0, 0x03,
  781. - 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xf0, 0x0f,
  782. - 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01}},
  783. - {{ // FL_CURSOR_EW
  784. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10,
  785. - 0x0c, 0x30, 0xfe, 0x7f, 0xfe, 0x7f, 0x0c, 0x30, 0x08, 0x10, 0x00, 0x00,
  786. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  787. - {
  788. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1c, 0x38,
  789. - 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0x1c, 0x38, 0x18, 0x18,
  790. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
  791. - {{ // FL_CURSOR_NWSE
  792. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x38, 0x00, 0x78, 0x00,
  793. - 0xe8, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x17, 0x00, 0x1e, 0x00, 0x1c,
  794. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  795. - {
  796. - 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x7c, 0x00, 0xfc, 0x00,
  797. - 0xfc, 0x01, 0xec, 0x03, 0xc0, 0x37, 0x80, 0x3f, 0x00, 0x3f, 0x00, 0x3e,
  798. - 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00}},
  799. - {{ // FL_CURSOR_NESW
  800. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x1c, 0x00, 0x1e,
  801. - 0x00, 0x17, 0x80, 0x03, 0xc0, 0x01, 0xe8, 0x00, 0x78, 0x00, 0x38, 0x00,
  802. - 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  803. - {
  804. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3f,
  805. - 0x80, 0x3f, 0xc0, 0x37, 0xec, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0x7c, 0x00,
  806. - 0xfc, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00}},
  807. - {{0}, {0}} // FL_CURSOR_NONE & unknown
  808. -};
  809. + // the cursor must be set for the top level window, not for subwindows
  810. + Fl_Window *w = window(), *toplevel = this;
  811. -void Fl_Window::cursor(Fl_Cursor c, Fl_Color fg, Fl_Color bg) {
  812. - if (!shown()) return;
  813. - Cursor xc;
  814. - int deleteit = 0;
  815. - if (c == FL_CURSOR_DEFAULT) {
  816. - c = cursor_default;
  817. - fg = cursor_fg;
  818. - bg = cursor_bg;
  819. + while (w) {
  820. + toplevel = w;
  821. + w = w->window();
  822. }
  823. - if (!c) {
  824. - xc = None;
  825. - } else {
  826. - if (c >= FL_CURSOR_NS) {
  827. - TableEntry *q = (c > FL_CURSOR_NESW) ? table+4 : table+(c-FL_CURSOR_NS);
  828. - if (!(q->cursor)) {
  829. - XColor dummy = { 0 };
  830. - Pixmap p = XCreateBitmapFromData(fl_display,
  831. - RootWindow(fl_display, fl_screen), (const char*)(q->bits),
  832. - CURSORSIZE, CURSORSIZE);
  833. - Pixmap m = XCreateBitmapFromData(fl_display,
  834. - RootWindow(fl_display, fl_screen), (const char*)(q->mask),
  835. - CURSORSIZE, CURSORSIZE);
  836. - q->cursor = XCreatePixmapCursor(fl_display, p,m,&dummy, &dummy,
  837. - HOTXY, HOTXY);
  838. - XFreePixmap(fl_display, m);
  839. - XFreePixmap(fl_display, p);
  840. - }
  841. - xc = q->cursor;
  842. - } else {
  843. - xc = XCreateFontCursor(fl_display, (c-1)*2);
  844. - deleteit = 1;
  845. - }
  846. - XColor fgc;
  847. - uchar r,g,b;
  848. - Fl::get_color(fg,r,g,b);
  849. - fgc.red = r<<8; fgc.green = g<<8; fgc.blue = b<<8;
  850. - XColor bgc;
  851. - Fl::get_color(bg,r,g,b);
  852. - bgc.red = r<<8; bgc.green = g<<8; bgc.blue = b<<8;
  853. - XRecolorCursor(fl_display, xc, &fgc, &bgc);
  854. + if (toplevel != this) {
  855. + toplevel->cursor(image, hotx, hoty);
  856. + return;
  857. }
  858. - XDefineCursor(fl_display, fl_xid(this), xc);
  859. - if (deleteit) XFreeCursor(fl_display, xc);
  860. +
  861. + if (!i)
  862. + return;
  863. +
  864. + ret = i->set_cursor(image, hotx, hoty);
  865. + if (ret)
  866. + return;
  867. +
  868. + cursor(FL_CURSOR_DEFAULT);
  869. }
  870. -#endif
  871. +/* For back compatibility only. */
  872. +void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
  873. + cursor(c);
  874. +};
  875. +
  876. +void Fl_Window::default_cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
  877. + default_cursor(c);
  878. +};
  879. +
  880. //
  881. // End of "$Id: fl_cursor.cxx 9278 2012-03-12 11:55:50Z manolo $".
  882. diff -up fltk-1.3.2/src/fl_cursor_help.xpm.cursor fltk-1.3.2/src/fl_cursor_help.xpm
  883. --- fltk-1.3.2/src/fl_cursor_help.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
  884. +++ fltk-1.3.2/src/fl_cursor_help.xpm 2013-01-30 16:07:59.534319820 +0100
  885. @@ -0,0 +1,95 @@
  886. +/* XPM */
  887. +static const char * fl_cursor_help_xpm[] = {
  888. +"16 27 65 1",
  889. +" c None",
  890. +". c #FFFFFF",
  891. +"+ c #E2E2E2",
  892. +"@ c #1C1C1C",
  893. +"# c #E7E7E7",
  894. +"$ c #000000",
  895. +"% c #212121",
  896. +"& c #EAEAEA",
  897. +"* c #262626",
  898. +"= c #EDEDED",
  899. +"- c #2C2C2C",
  900. +"; c #F0F0F0",
  901. +"> c #333333",
  902. +", c #F1F1F1",
  903. +"' c #393939",
  904. +") c #F3F3F3",
  905. +"! c #404040",
  906. +"~ c #484848",
  907. +"{ c #F4F4F4",
  908. +"] c #050505",
  909. +"^ c #202020",
  910. +"/ c #707070",
  911. +"( c #F5F5F5",
  912. +"_ c #040404",
  913. +": c #E1E1E1",
  914. +"< c #EEEEEE",
  915. +"[ c #EFEFEF",
  916. +"} c #FEFEFE",
  917. +"| c #3D3D3D",
  918. +"1 c #7E7E7E",
  919. +"2 c #696969",
  920. +"3 c #414141",
  921. +"4 c #131313",
  922. +"5 c #080808",
  923. +"6 c #454545",
  924. +"7 c #F2F2F2",
  925. +"8 c #878787",
  926. +"9 c #7D7D7D",
  927. +"0 c #101010",
  928. +"a c #111111",
  929. +"b c #FDFDFD",
  930. +"c c #8A8A8A",
  931. +"d c #E6E6E6",
  932. +"e c #7B7B7B",
  933. +"f c #4C4C4C",
  934. +"g c #5C5C5C",
  935. +"h c #9F9F9F",
  936. +"i c #F9F9F9",
  937. +"j c #F7F7F7",
  938. +"k c #B1B1B1",
  939. +"l c #2E2E2E",
  940. +"m c #767676",
  941. +"n c #DCDCDC",
  942. +"o c #DEDEDE",
  943. +"p c #C7C7C7",
  944. +"q c #1B1B1B",
  945. +"r c #6B6B6B",
  946. +"s c #575757",
  947. +"t c #797979",
  948. +"u c #020202",
  949. +"v c #010101",
  950. +"w c #FBFBFB",
  951. +"x c #D7D7D7",
  952. +"y c #D8D8D8",
  953. +"z c #060606",
  954. +" ",
  955. +". ",
  956. +".+ ",
  957. +".@# ",
  958. +".$%& ",
  959. +".$$*= ",
  960. +".$$$-; ",
  961. +".$$$$>, ",
  962. +".$$$$$') ",
  963. +".$$$$$$!) ",
  964. +".$$$$$$$~{ ",
  965. +".$$$$]^^^/( ",
  966. +".$$$$_:(<<[} ",
  967. +".$$|1$2< ",
  968. +".$3,(45[ ",
  969. +".67 78$9, ",
  970. +".7 {0a( .... ",
  971. +"b ,c5[defgh, ",
  972. +" )ijk_la$m.",
  973. +" no.p$q.",
  974. +" .r$s.",
  975. +" .t$-= ",
  976. +" 7uv+ ",
  977. +" wxy. ",
  978. +" :$z. ",
  979. +" :$z. ",
  980. +" .... "};
  981. diff -up fltk-1.3.2/src/fl_cursor_nesw.xpm.cursor fltk-1.3.2/src/fl_cursor_nesw.xpm
  982. --- fltk-1.3.2/src/fl_cursor_nesw.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
  983. +++ fltk-1.3.2/src/fl_cursor_nesw.xpm 2013-01-30 16:07:59.534319820 +0100
  984. @@ -0,0 +1,46 @@
  985. +/* XPM */
  986. +static const char * fl_cursor_nesw_xpm[] = {
  987. +"15 15 28 1",
  988. +" c None",
  989. +". c #FFFFFF",
  990. +"+ c #767676",
  991. +"@ c #000000",
  992. +"# c #4E4E4E",
  993. +"$ c #0C0C0C",
  994. +"% c #494949",
  995. +"& c #4D4D4D",
  996. +"* c #1B1B1B",
  997. +"= c #515151",
  998. +"- c #646464",
  999. +"; c #363636",
  1000. +"> c #6A6A6A",
  1001. +", c #545454",
  1002. +"' c #585858",
  1003. +") c #242424",
  1004. +"! c #797979",
  1005. +"~ c #2E2E2E",
  1006. +"{ c #444444",
  1007. +"] c #3B3B3B",
  1008. +"^ c #0A0A0A",
  1009. +"/ c #595959",
  1010. +"( c #F7F7F7",
  1011. +"_ c #080808",
  1012. +": c #6B6B6B",
  1013. +"< c #FDFDFD",
  1014. +"[ c #FCFCFC",
  1015. +"} c #FEFEFE",
  1016. +" ..........",
  1017. +" .+@@@@@@.",
  1018. +" .#@@@@@.",
  1019. +" .$@@@@.",
  1020. +" .%@@@@@.",
  1021. +". .&@@@*@@.",
  1022. +".. .=@@@-.;@.",
  1023. +".>. .,@@@'. .).",
  1024. +".@!.'@@@#. ..",
  1025. +".@@~@@@{. .",
  1026. +".@@@@@]. ",
  1027. +".@@@@^. ",
  1028. +".@@@@@/( ",
  1029. +".______:( ",
  1030. +"<[[[[[[[[} "};
  1031. diff -up fltk-1.3.2/src/fl_cursor_none.xpm.cursor fltk-1.3.2/src/fl_cursor_none.xpm
  1032. --- fltk-1.3.2/src/fl_cursor_none.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
  1033. +++ fltk-1.3.2/src/fl_cursor_none.xpm 2013-01-30 16:07:59.534319820 +0100
  1034. @@ -0,0 +1,19 @@
  1035. +/* XPM */
  1036. +static const char * fl_cursor_none_xpm[] = {
  1037. +"15 15 1 1",
  1038. +" c None",
  1039. +" ",
  1040. +" ",
  1041. +" ",
  1042. +" ",
  1043. +" ",
  1044. +" ",
  1045. +" ",
  1046. +" ",
  1047. +" ",
  1048. +" ",
  1049. +" ",
  1050. +" ",
  1051. +" ",
  1052. +" ",
  1053. +" "};
  1054. diff -up fltk-1.3.2/src/fl_cursor_nwse.xpm.cursor fltk-1.3.2/src/fl_cursor_nwse.xpm
  1055. --- fltk-1.3.2/src/fl_cursor_nwse.xpm.cursor 2013-01-30 16:07:59.534319820 +0100
  1056. +++ fltk-1.3.2/src/fl_cursor_nwse.xpm 2013-01-30 16:07:59.535319802 +0100
  1057. @@ -0,0 +1,46 @@
  1058. +/* XPM */
  1059. +static const char * fl_cursor_nwse_xpm[] = {
  1060. +"15 15 28 1",
  1061. +" c None",
  1062. +". c #FFFFFF",
  1063. +"+ c #000000",
  1064. +"@ c #767676",
  1065. +"# c #4E4E4E",
  1066. +"$ c #0C0C0C",
  1067. +"% c #494949",
  1068. +"& c #1B1B1B",
  1069. +"* c #4D4D4D",
  1070. +"= c #363636",
  1071. +"- c #646464",
  1072. +"; c #515151",
  1073. +"> c #242424",
  1074. +", c #585858",
  1075. +"' c #545454",
  1076. +") c #6A6A6A",
  1077. +"! c #797979",
  1078. +"~ c #444444",
  1079. +"{ c #2E2E2E",
  1080. +"] c #3B3B3B",
  1081. +"^ c #0A0A0A",
  1082. +"/ c #F7F7F7",
  1083. +"( c #595959",
  1084. +"_ c #6B6B6B",
  1085. +": c #080808",
  1086. +"< c #FEFEFE",
  1087. +"[ c #FCFCFC",
  1088. +"} c #FDFDFD",
  1089. +".......... ",
  1090. +".++++++@. ",
  1091. +".+++++#. ",
  1092. +".++++$. ",
  1093. +".+++++%. ",
  1094. +".++&+++*. .",
  1095. +".+=.-+++;. ..",
  1096. +".>. .,+++'. .).",
  1097. +".. .#+++,.!+.",
  1098. +". .~+++{++.",
  1099. +" .]+++++.",
  1100. +" .^++++.",
  1101. +" /(+++++.",
  1102. +" /_::::::.",
  1103. +" <[[[[[[[[}"};
  1104. diff -up fltk-1.3.2/src/fl_cursor_wait.xpm.cursor fltk-1.3.2/src/fl_cursor_wait.xpm
  1105. --- fltk-1.3.2/src/fl_cursor_wait.xpm.cursor 2013-01-30 16:07:59.535319802 +0100
  1106. +++ fltk-1.3.2/src/fl_cursor_wait.xpm 2013-01-30 16:07:59.535319802 +0100
  1107. @@ -0,0 +1,72 @@
  1108. +/* XPM */
  1109. +static const char * fl_cursor_wait_xpm[] = {
  1110. +"17 32 37 1",
  1111. +" c None",
  1112. +". c #FFFFFF",
  1113. +"+ c #2E2E2E",
  1114. +"@ c #202020",
  1115. +"# c #F1F1F1",
  1116. +"$ c #2D2D2D",
  1117. +"% c #000000",
  1118. +"& c #EDEDED",
  1119. +"* c #585858",
  1120. +"= c #575757",
  1121. +"- c #FBFBFB",
  1122. +"; c #848484",
  1123. +"> c #B8B8B8",
  1124. +", c #E5E5E5",
  1125. +"' c #F7F7F7",
  1126. +") c #181818",
  1127. +"! c #F0F0F0",
  1128. +"~ c #616161",
  1129. +"{ c #B7B7B7",
  1130. +"] c #F5F5F5",
  1131. +"^ c #050505",
  1132. +"/ c #D4D4D4",
  1133. +"( c #EEEEEE",
  1134. +"_ c #595959",
  1135. +": c #7B7B7B",
  1136. +"< c #E9E9E9",
  1137. +"[ c #131313",
  1138. +"} c #E3E3E3",
  1139. +"| c #767676",
  1140. +"1 c #505050",
  1141. +"2 c #F3F3F3",
  1142. +"3 c #2A2A2A",
  1143. +"4 c #070707",
  1144. +"5 c #343434",
  1145. +"6 c #939393",
  1146. +"7 c #191919",
  1147. +"8 c #6A6A6A",
  1148. +".................",
  1149. +".+@@@@@@@@@@@@@+.",
  1150. +".................",
  1151. +" #$%%%%%%%%%%%$# ",
  1152. +" &*%%%%%%%%%%%=& ",
  1153. +" -;%%%%%%%%%%%;- ",
  1154. +" >%%%%%%%%%%%> ",
  1155. +" ,%%%%%%%%%%%, ",
  1156. +" ')%%%%%%%%%)' ",
  1157. +" !~%%%%%%%%%~! ",
  1158. +" {%%%%%%%%%{ ",
  1159. +" ]^/...../^] ",
  1160. +" (_:.....:_( ",
  1161. +" <[}...}[< ",
  1162. +" !|1...1|! ",
  1163. +" 2[3.3[2 ",
  1164. +" 2[%.%[2 ",
  1165. +" !|%%.%%|! ",
  1166. +" <4%%.%%4< ",
  1167. +" (_%%%.%%%_( ",
  1168. +" ]^%%%.%%%^] ",
  1169. +" {%%%%.%%%%{ ",
  1170. +" !~%%%%.%%%%~! ",
  1171. +" ')%%%%.%%%%)' ",
  1172. +" ,%%56{.{65%%, ",
  1173. +" >%*.......*%> ",
  1174. +" -;7&.......&7;- ",
  1175. +" &*8.........8=& ",
  1176. +" #$%%%%%%%%%%%$# ",
  1177. +".................",
  1178. +".+@@@@@@@@@@@@@+.",
  1179. +"................."};
  1180. diff -up fltk-1.3.2/src/Fl_win32.cxx.cursor fltk-1.3.2/src/Fl_win32.cxx
  1181. --- fltk-1.3.2/src/Fl_win32.cxx.cursor 2013-01-30 16:07:59.519320086 +0100
  1182. +++ fltk-1.3.2/src/Fl_win32.cxx 2013-01-30 16:07:59.536319784 +0100
  1183. @@ -1633,7 +1633,6 @@ void fl_fix_focus(); // in Fl.cxx
  1184. char fl_show_iconic; // hack for Fl_Window::iconic()
  1185. // int fl_background_pixel = -1; // color to use for background
  1186. -HCURSOR fl_default_cursor;
  1187. UINT fl_wake_msg = 0;
  1188. int fl_disable_transient_for; // secret method of removing TRANSIENT_FOR
  1189. @@ -1682,7 +1681,7 @@ Fl_X* Fl_X::make(Fl_Window* w) {
  1190. if (!w->icon())
  1191. w->icon((void *)LoadIcon(NULL, IDI_APPLICATION));
  1192. wcw.hIcon = wcw.hIconSm = (HICON)w->icon();
  1193. - wcw.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW);
  1194. + wcw.hCursor = LoadCursor(NULL, IDC_ARROW);
  1195. //uchar r,g,b; Fl::get_color(FL_GRAY,r,g,b);
  1196. //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(r,g,b));
  1197. wcw.hbrBackground = NULL;
  1198. @@ -1774,7 +1773,8 @@ Fl_X* Fl_X::make(Fl_Window* w) {
  1199. x->setwindow(w);
  1200. x->region = 0;
  1201. x->private_dc = 0;
  1202. - x->cursor = fl_default_cursor;
  1203. + x->cursor = LoadCursor(NULL, IDC_ARROW);
  1204. + x->custom_cursor = 0;
  1205. if (!fl_codepage) fl_get_codepage();
  1206. WCHAR *lab = NULL;
  1207. @@ -2025,6 +2025,153 @@ void Fl_Window::label(const char *name,c
  1208. }
  1209. ////////////////////////////////////////////////////////////////
  1210. +
  1211. +#ifndef IDC_HAND
  1212. +# define IDC_HAND MAKEINTRESOURCE(32649)
  1213. +#endif // !IDC_HAND
  1214. +
  1215. +int Fl_X::set_cursor(Fl_Cursor c) {
  1216. + LPSTR n;
  1217. + HCURSOR new_cursor;
  1218. +
  1219. + if (c == FL_CURSOR_NONE)
  1220. + new_cursor = NULL;
  1221. + else {
  1222. + switch (c) {
  1223. + case FL_CURSOR_ARROW: n = IDC_ARROW; break;
  1224. + case FL_CURSOR_CROSS: n = IDC_CROSS; break;
  1225. + case FL_CURSOR_WAIT: n = IDC_WAIT; break;
  1226. + case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
  1227. + case FL_CURSOR_HAND: n = IDC_HAND; break;
  1228. + case FL_CURSOR_HELP: n = IDC_HELP; break;
  1229. + case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
  1230. + case FL_CURSOR_N:
  1231. + case FL_CURSOR_S:
  1232. + // FIXME: Should probably have fallbacks for these instead
  1233. + case FL_CURSOR_NS: n = IDC_SIZENS; break;
  1234. + case FL_CURSOR_NE:
  1235. + case FL_CURSOR_SW:
  1236. + // FIXME: Dito.
  1237. + case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
  1238. + case FL_CURSOR_E:
  1239. + case FL_CURSOR_W:
  1240. + // FIXME: Dito.
  1241. + case FL_CURSOR_WE: n = IDC_SIZEWE; break;
  1242. + case FL_CURSOR_SE:
  1243. + case FL_CURSOR_NW:
  1244. + // FIXME: Dito.
  1245. + case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
  1246. + default:
  1247. + return 0;
  1248. + }
  1249. +
  1250. + new_cursor = LoadCursor(NULL, n);
  1251. + if (new_cursor == NULL)
  1252. + return 0;
  1253. + }
  1254. +
  1255. + if ((cursor != NULL) && custom_cursor)
  1256. + DestroyIcon(cursor);
  1257. +
  1258. + cursor = new_cursor;
  1259. + custom_cursor = 0;
  1260. +
  1261. + SetCursor(cursor);
  1262. +
  1263. + return 1;
  1264. +}
  1265. +
  1266. +int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  1267. + BITMAPV5HEADER bi;
  1268. + HBITMAP bitmap, mask;
  1269. + DWORD *bits;
  1270. + HCURSOR new_cursor;
  1271. +
  1272. + if ((hotx < 0) || (hotx >= image->w()))
  1273. + return 0;
  1274. + if ((hoty < 0) || (hoty >= image->h()))
  1275. + return 0;
  1276. +
  1277. + memset(&bi, 0, sizeof(BITMAPV5HEADER));
  1278. +
  1279. + bi.bV5Size = sizeof(BITMAPV5HEADER);
  1280. + bi.bV5Width = image->w();
  1281. + bi.bV5Height = -image->h(); // Negative for top-down
  1282. + bi.bV5Planes = 1;
  1283. + bi.bV5BitCount = 32;
  1284. + bi.bV5Compression = BI_BITFIELDS;
  1285. + bi.bV5RedMask = 0x00FF0000;
  1286. + bi.bV5GreenMask = 0x0000FF00;
  1287. + bi.bV5BlueMask = 0x000000FF;
  1288. + bi.bV5AlphaMask = 0xFF000000;
  1289. +
  1290. + HDC hdc;
  1291. +
  1292. + hdc = GetDC(NULL);
  1293. + bitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
  1294. + ReleaseDC(NULL, hdc);
  1295. +
  1296. + if (bits == NULL)
  1297. + return 0;
  1298. +
  1299. + const uchar *i = (const uchar*)*image->data();
  1300. + for (int y = 0;y < image->h();y++) {
  1301. + for (int x = 0;x < image->w();x++) {
  1302. + switch (image->d()) {
  1303. + case 1:
  1304. + *bits = (0xff<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
  1305. + break;
  1306. + case 2:
  1307. + *bits = (i[1]<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
  1308. + break;
  1309. + case 3:
  1310. + *bits = (0xff<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
  1311. + break;
  1312. + case 4:
  1313. + *bits = (i[3]<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
  1314. + break;
  1315. + }
  1316. + i += image->d();
  1317. + bits++;
  1318. + }
  1319. + i += image->ld();
  1320. + }
  1321. +
  1322. + // A mask bitmap is still needed even though it isn't used
  1323. + mask = CreateBitmap(image->w(),image->h(),1,1,NULL);
  1324. + if (mask == NULL) {
  1325. + DeleteObject(bitmap);
  1326. + return 0;
  1327. + }
  1328. +
  1329. + ICONINFO ii;
  1330. +
  1331. + ii.fIcon = FALSE;
  1332. + ii.xHotspot = hotx;
  1333. + ii.yHotspot = hoty;
  1334. + ii.hbmMask = mask;
  1335. + ii.hbmColor = bitmap;
  1336. +
  1337. + new_cursor = CreateIconIndirect(&ii);
  1338. +
  1339. + DeleteObject(bitmap);
  1340. + DeleteObject(mask);
  1341. +
  1342. + if (new_cursor == NULL)
  1343. + return 0;
  1344. +
  1345. + if ((cursor != NULL) && custom_cursor)
  1346. + DestroyIcon(cursor);
  1347. +
  1348. + cursor = new_cursor;
  1349. + custom_cursor = 1;
  1350. +
  1351. + SetCursor(cursor);
  1352. +
  1353. + return 1;
  1354. +}
  1355. +
  1356. +////////////////////////////////////////////////////////////////
  1357. // Implement the virtual functions for the base Fl_Window class:
  1358. // If the box is a filled rectangle, we can make the redisplay *look*
  1359. diff -up fltk-1.3.2/src/Fl_Window.cxx.cursor fltk-1.3.2/src/Fl_Window.cxx
  1360. --- fltk-1.3.2/src/Fl_Window.cxx.cursor 2012-11-06 21:46:14.000000000 +0100
  1361. +++ fltk-1.3.2/src/Fl_Window.cxx 2013-01-30 16:07:59.536319784 +0100
  1362. @@ -62,8 +62,6 @@ void Fl_Window::_Fl_Window() {
  1363. Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l)
  1364. : Fl_Group(X, Y, W, H, l) {
  1365. cursor_default = FL_CURSOR_DEFAULT;
  1366. - cursor_fg = FL_BLACK;
  1367. - cursor_bg = FL_WHITE;
  1368. _Fl_Window();
  1369. set_flag(FORCE_POSITION);
  1370. @@ -73,8 +71,6 @@ Fl_Window::Fl_Window(int W, int H, const
  1371. // fix common user error of a missing end() with current(0):
  1372. : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) {
  1373. cursor_default = FL_CURSOR_DEFAULT;
  1374. - cursor_fg = FL_BLACK;
  1375. - cursor_bg = FL_WHITE;
  1376. _Fl_Window();
  1377. clear_visible();
  1378. diff -up fltk-1.3.2/src/Fl_x.cxx.cursor fltk-1.3.2/src/Fl_x.cxx
  1379. --- fltk-1.3.2/src/Fl_x.cxx.cursor 2013-01-30 16:07:59.512320211 +0100
  1380. +++ fltk-1.3.2/src/Fl_x.cxx 2013-01-30 16:07:59.537319766 +0100
  1381. @@ -59,6 +59,11 @@ static int xfixes_event_base = 0;
  1382. static bool have_xfixes = false;
  1383. # endif
  1384. +# include <X11/cursorfont.h>
  1385. +
  1386. +# if HAVE_XCURSOR
  1387. +# include <X11/Xcursor/Xcursor.h>
  1388. +# endif
  1389. static Fl_Xlib_Graphics_Driver fl_xlib_driver;
  1390. static Fl_Display_Device fl_xlib_display(&fl_xlib_driver);
  1391. Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display
  1392. @@ -2259,6 +2264,94 @@ void Fl_Window::size_range_() {
  1393. }
  1394. ////////////////////////////////////////////////////////////////
  1395. +
  1396. +int Fl_X::set_cursor(Fl_Cursor c) {
  1397. + unsigned int shape;
  1398. + Cursor xc;
  1399. +
  1400. + switch (c) {
  1401. + case FL_CURSOR_ARROW: shape = XC_left_ptr; break;
  1402. + case FL_CURSOR_CROSS: shape = XC_tcross; break;
  1403. + case FL_CURSOR_WAIT: shape = XC_watch; break;
  1404. + case FL_CURSOR_INSERT: shape = XC_xterm; break;
  1405. + case FL_CURSOR_HAND: shape = XC_hand2; break;
  1406. + case FL_CURSOR_HELP: shape = XC_question_arrow; break;
  1407. + case FL_CURSOR_MOVE: shape = XC_fleur; break;
  1408. + case FL_CURSOR_NS: shape = XC_sb_v_double_arrow; break;
  1409. + case FL_CURSOR_WE: shape = XC_sb_h_double_arrow; break;
  1410. + case FL_CURSOR_NE: shape = XC_top_right_corner; break;
  1411. + case FL_CURSOR_N: shape = XC_top_side; break;
  1412. + case FL_CURSOR_NW: shape = XC_top_left_corner; break;
  1413. + case FL_CURSOR_E: shape = XC_right_side; break;
  1414. + case FL_CURSOR_W: shape = XC_left_side; break;
  1415. + case FL_CURSOR_SE: shape = XC_bottom_right_corner; break;
  1416. + case FL_CURSOR_S: shape = XC_bottom_side; break;
  1417. + case FL_CURSOR_SW: shape = XC_bottom_left_corner; break;
  1418. + default:
  1419. + return 0;
  1420. + }
  1421. +
  1422. + xc = XCreateFontCursor(fl_display, shape);
  1423. + XDefineCursor(fl_display, xid, xc);
  1424. + XFreeCursor(fl_display, xc);
  1425. +
  1426. + return 1;
  1427. +}
  1428. +
  1429. +int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  1430. +#if ! HAVE_XCURSOR
  1431. + return 0;
  1432. +#else
  1433. + XcursorImage *cursor;
  1434. + Cursor xc;
  1435. +
  1436. + if ((hotx < 0) || (hotx >= image->w()))
  1437. + return 0;
  1438. + if ((hoty < 0) || (hoty >= image->h()))
  1439. + return 0;
  1440. +
  1441. + cursor = XcursorImageCreate(image->w(), image->h());
  1442. + if (!cursor)
  1443. + return 0;
  1444. +
  1445. + const uchar *i = (const uchar*)*image->data();
  1446. + XcursorPixel *o = cursor->pixels;
  1447. + for (int y = 0;y < image->h();y++) {
  1448. + for (int x = 0;x < image->w();x++) {
  1449. + switch (image->d()) {
  1450. + case 1:
  1451. + *o = (0xff<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
  1452. + break;
  1453. + case 2:
  1454. + *o = (i[1]<<24) | (i[0]<<16) | (i[0]<<8) | i[0];
  1455. + break;
  1456. + case 3:
  1457. + *o = (0xff<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
  1458. + break;
  1459. + case 4:
  1460. + *o = (i[3]<<24) | (i[0]<<16) | (i[1]<<8) | i[2];
  1461. + break;
  1462. + }
  1463. + i += image->d();
  1464. + o++;
  1465. + }
  1466. + i += image->ld();
  1467. + }
  1468. +
  1469. + cursor->xhot = hotx;
  1470. + cursor->yhot = hoty;
  1471. +
  1472. + xc = XcursorImageLoadCursor(fl_display, cursor);
  1473. + XDefineCursor(fl_display, xid, xc);
  1474. + XFreeCursor(fl_display, xc);
  1475. +
  1476. + XcursorImageDestroy(cursor);
  1477. +
  1478. + return 1;
  1479. +#endif
  1480. +}
  1481. +
  1482. +////////////////////////////////////////////////////////////////
  1483. // returns pointer to the filename, or null if name ends with '/'
  1484. const char *fl_filename_name(const char *name) {
  1485. diff -up fltk-1.3.2/test/cursor.cxx.cursor fltk-1.3.2/test/cursor.cxx
  1486. --- fltk-1.3.2/test/cursor.cxx.cursor 2011-07-19 06:49:30.000000000 +0200
  1487. +++ fltk-1.3.2/test/cursor.cxx 2013-01-30 16:07:59.537319766 +0100
  1488. @@ -23,8 +23,6 @@
  1489. #include <FL/fl_draw.H>
  1490. #include <FL/Fl_Box.H>
  1491. -Fl_Color fg = FL_BLACK;
  1492. -Fl_Color bg = FL_WHITE;
  1493. Fl_Cursor cursor = FL_CURSOR_DEFAULT;
  1494. Fl_Hor_Value_Slider *cursor_slider;
  1495. @@ -32,7 +30,7 @@ Fl_Hor_Value_Slider *cursor_slider;
  1496. void choice_cb(Fl_Widget *, void *v) {
  1497. cursor = (Fl_Cursor)(fl_intptr_t)v;
  1498. cursor_slider->value(cursor);
  1499. - fl_cursor(cursor,fg,bg);
  1500. + fl_cursor(cursor);
  1501. }
  1502. Fl_Menu_Item choices[] = {
  1503. @@ -48,8 +46,6 @@ Fl_Menu_Item choices[] = {
  1504. {"FL_CURSOR_WE",0,choice_cb,(void*)FL_CURSOR_WE},
  1505. {"FL_CURSOR_NWSE",0,choice_cb,(void*)FL_CURSOR_NWSE},
  1506. {"FL_CURSOR_NESW",0,choice_cb,(void*)FL_CURSOR_NESW},
  1507. - {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
  1508. -#if 0
  1509. {"FL_CURSOR_N",0,choice_cb,(void*)FL_CURSOR_N},
  1510. {"FL_CURSOR_NE",0,choice_cb,(void*)FL_CURSOR_NE},
  1511. {"FL_CURSOR_E",0,choice_cb,(void*)FL_CURSOR_E},
  1512. @@ -58,26 +54,14 @@ Fl_Menu_Item choices[] = {
  1513. {"FL_CURSOR_SW",0,choice_cb,(void*)FL_CURSOR_SW},
  1514. {"FL_CURSOR_W",0,choice_cb,(void*)FL_CURSOR_W},
  1515. {"FL_CURSOR_NW",0,choice_cb,(void*)FL_CURSOR_NW},
  1516. -#endif
  1517. + {"FL_CURSOR_NONE",0,choice_cb,(void*)FL_CURSOR_NONE},
  1518. {0}
  1519. };
  1520. void setcursor(Fl_Widget *o, void *) {
  1521. Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  1522. cursor = Fl_Cursor((int)slider->value());
  1523. - fl_cursor(cursor,fg,bg);
  1524. -}
  1525. -
  1526. -void setfg(Fl_Widget *o, void *) {
  1527. - Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  1528. - fg = Fl_Color((int)slider->value());
  1529. - fl_cursor(cursor,fg,bg);
  1530. -}
  1531. -
  1532. -void setbg(Fl_Widget *o, void *) {
  1533. - Fl_Hor_Value_Slider *slider = (Fl_Hor_Value_Slider *)o;
  1534. - bg = Fl_Color((int)slider->value());
  1535. - fl_cursor(cursor,fg,bg);
  1536. + fl_cursor(cursor);
  1537. }
  1538. // draw the label without any ^C or \nnn conversions:
  1539. @@ -103,29 +87,11 @@ int main(int argc, char **argv) {
  1540. slider1.align(FL_ALIGN_LEFT);
  1541. slider1.step(1);
  1542. slider1.precision(0);
  1543. - slider1.bounds(0,100);
  1544. + slider1.bounds(0,255);
  1545. slider1.value(0);
  1546. slider1.callback(setcursor);
  1547. slider1.value(cursor);
  1548. - Fl_Hor_Value_Slider slider2(80,220,310,30,"fgcolor:");
  1549. - slider2.align(FL_ALIGN_LEFT);
  1550. - slider2.step(1);
  1551. - slider2.precision(0);
  1552. - slider2.bounds(0,255);
  1553. - slider2.value(0);
  1554. - slider2.callback(setfg);
  1555. - slider2.value(fg);
  1556. -
  1557. - Fl_Hor_Value_Slider slider3(80,260,310,30,"bgcolor:");
  1558. - slider3.align(FL_ALIGN_LEFT);
  1559. - slider3.step(1);
  1560. - slider3.precision(0);
  1561. - slider3.bounds(0,255);
  1562. - slider3.value(0);
  1563. - slider3.callback(setbg);
  1564. - slider3.value(bg);
  1565. -
  1566. #if 0
  1567. // draw the manual's diagram of cursors...
  1568. window.size(400,800);