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.

238 lines
8.2KB

  1. //
  2. // "$Id: mac.H 8657 2011-05-12 11:50:43Z manolo $"
  3. //
  4. // Mac header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2011 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // Do not directly include this file, instead use <FL/x.H>. It will
  28. // include this file if "__APPLE__" is defined. This is to encourage
  29. // portability of even the system-specific code...
  30. #ifndef FL_DOXYGEN
  31. #if !defined(Fl_X_H)
  32. # error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
  33. #endif // !Fl_X_H
  34. #include <FL/Fl_Widget.H>
  35. typedef void* Window; // this is really a pointer to the subclass FLWindow of NSWindow
  36. typedef void* Fl_Offscreen; // this is really a CGContextRef
  37. typedef void* Fl_Bitmask; // this is really a CGImageRef
  38. #include <AvailabilityMacros.h>
  39. #ifndef MAC_OS_X_VERSION_10_3
  40. #define MAC_OS_X_VERSION_10_3 1030
  41. #endif
  42. #ifndef MAC_OS_X_VERSION_10_4
  43. #define MAC_OS_X_VERSION_10_4 1040
  44. #endif
  45. #ifndef MAC_OS_X_VERSION_10_5
  46. #define MAC_OS_X_VERSION_10_5 1050
  47. #endif
  48. #ifndef MAC_OS_X_VERSION_10_6
  49. #define MAC_OS_X_VERSION_10_6 1060
  50. #endif
  51. #if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
  52. typedef void* Fl_Region;
  53. typedef void* Fl_CGContextRef;
  54. typedef void* Fl_PMPrintSettings;
  55. typedef void* Fl_PMPageFormat;
  56. typedef void* Fl_PMPrintSession;
  57. #else // this part must be compiled when building the FLTK libraries
  58. // Standard MacOS C/C++ includes...
  59. #include <ApplicationServices/ApplicationServices.h>
  60. #undef check // because of Fl::check()
  61. typedef CGContextRef Fl_CGContextRef;
  62. typedef PMPrintSettings Fl_PMPrintSettings;
  63. typedef PMPageFormat Fl_PMPageFormat;
  64. typedef PMPrintSession Fl_PMPrintSession;
  65. typedef struct flCocoaRegion {
  66. int count;
  67. CGRect *rects;
  68. } *Fl_Region; // a region is the union of a series of rectangles
  69. # include "Fl_Window.H"
  70. // Some random X equivalents
  71. struct XPoint { int x, y; };
  72. struct XRectangle {int x, y, width, height;};
  73. #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
  74. #if defined(__LP64__) && __LP64__
  75. typedef double CGFloat;
  76. #else
  77. typedef float CGFloat;
  78. #endif
  79. #endif // CGFLOAT_DEFINED
  80. extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
  81. inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
  82. Fl_Region R = (Fl_Region)malloc(sizeof(*R));
  83. R->count = 1;
  84. R->rects = (CGRect *)malloc(sizeof(CGRect));
  85. *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
  86. return R;
  87. }
  88. inline void XDestroyRegion(Fl_Region r) {
  89. if(r) {
  90. free(r->rects);
  91. free(r);
  92. }
  93. }
  94. extern void *fl_system_menu;
  95. extern void *fl_default_cursor;
  96. // This object contains all mac-specific stuff about a window:
  97. // WARNING: this object is highly subject to change!
  98. class Fl_X {
  99. public:
  100. Window xid; // pointer to the Cocoa window object (FLWindow*)
  101. Fl_Offscreen other_xid; // pointer for offscreen bitmaps (overlay window)
  102. Fl_Window *w; // FLTK window for
  103. Fl_Region region;
  104. Fl_Region subRegion; // region for this specific subwindow
  105. Fl_X *next; // linked tree to support subwindows
  106. Fl_X *xidChildren, *xidNext; // more subwindow tree
  107. int wait_for_expose;
  108. void *cursor; // is really NSCursor*
  109. static Fl_X* first;
  110. static Fl_X* i(const Fl_Window* w) {return w->i;}
  111. static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
  112. static void make(Fl_Window*);
  113. void flush();
  114. // Quartz additions:
  115. CGContextRef gc; // graphics context (NULL when using QD)
  116. static void q_fill_context(); // fill a Quartz context with current FLTK state
  117. static void q_clear_clipping(); // remove all clipping from a Quartz context
  118. static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
  119. static void q_begin_image(CGRect&, int x, int y, int w, int h);
  120. static void q_end_image();
  121. // Cocoa additions
  122. void destroy(void);
  123. void map(void);
  124. void unmap(void);
  125. int unlink(Fl_X* start = NULL);
  126. void collapse(void);
  127. WindowRef window_ref(void);
  128. void set_key_window(void);
  129. void set_cursor(Fl_Cursor);
  130. static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
  131. static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
  132. static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
  133. static CGContextRef watch_cursor_image(void);
  134. static CGContextRef help_cursor_image(void);
  135. static CGContextRef nesw_cursor_image(void);
  136. static CGContextRef nwse_cursor_image(void);
  137. static CGContextRef none_cursor_image(void);
  138. static void *get_carbon_function(const char *name);
  139. private:
  140. static void relink(Fl_Window*, Fl_Window*);
  141. bool subwindow;
  142. };
  143. extern struct Fl_XMap {
  144. RGBColor rgb;
  145. ulong pen;
  146. } *fl_current_xmap;
  147. extern FL_EXPORT Window fl_window;
  148. #endif // FL_LIBRARY || FL_INTERNALS
  149. extern FL_EXPORT Fl_CGContextRef fl_gc;
  150. extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
  151. extern Window fl_xid(const Fl_Window*);
  152. void fl_clip_region(Fl_Region);
  153. extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  154. extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  155. extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
  156. extern Fl_Offscreen fl_create_offscreen(int w, int h);
  157. extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
  158. extern void fl_delete_offscreen(Fl_Offscreen gWorld);
  159. extern void fl_begin_offscreen(Fl_Offscreen gWorld);
  160. extern void fl_end_offscreen();
  161. extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  162. extern void fl_open_display();
  163. #endif // FL_DOXYGEN
  164. /** \defgroup group_macosx Mac OS X-specific symbols
  165. Mac OS X-specific symbols declared in <FL/x.H> or <FL/gl.h>
  166. @{ */
  167. /** @brief Register a function called for each file dropped onto an application icon.
  168. \e cb will be called with a single Unix-style file name and path.
  169. If multiple files were dropped, \e cb will be called multiple times.
  170. */
  171. extern void fl_open_callback(void (*cb)(const char *));
  172. /**
  173. * \brief Attaches a callback to the "About myprog" item of the system application menu.
  174. *
  175. * \param cb a callback that will be called by "About myprog" menu item
  176. * with NULL 1st argument.
  177. * \param user_data a pointer transmitted as 2nd argument to the callback.
  178. * \param shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
  179. */
  180. extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
  181. /** \brief The version number of the running Mac OS X (e.g., 100604 for 10.6.4)
  182. */
  183. extern int fl_mac_os_version;
  184. class Fl_Mac_App_Menu {
  185. public:
  186. /** Localizable text for the "About xxx" application menu item */
  187. static const char *about;
  188. /** Localizable text for the "Print Front Window" application menu item.
  189. This menu item won't be displayed if Fl_Mac_App_Menu::print
  190. is set to an empty string.
  191. */
  192. static const char *print;
  193. /** Localizable text for the "Services" application menu item */
  194. static const char *services;
  195. /** Localizable text for the "Hide xxx" application menu item */
  196. static const char *hide;
  197. /** Localizable text for the "Hide Others" application menu item */
  198. static const char *hide_others;
  199. /** Localizable text for the "Show All" application menu item */
  200. static const char *show;
  201. /** Localizable text for the "Quit xxx" application menu item */
  202. static const char *quit;
  203. };
  204. /** @} */
  205. //
  206. // End of "$Id: mac.H 8657 2011-05-12 11:50:43Z manolo $".
  207. //