mac.H 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // "$Id: mac.H 10159 2014-05-23 16:47:21Z 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. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. // Do not directly include this file, instead use <FL/x.H>. It will
  19. // include this file if "__APPLE__" is defined. This is to encourage
  20. // portability of even the system-specific code...
  21. #ifndef FL_DOXYGEN
  22. #if !defined(Fl_X_H)
  23. # error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
  24. #endif // !Fl_X_H
  25. #ifdef __OBJC__
  26. @class FLWindow; // a subclass of the NSWindow Cocoa class
  27. typedef FLWindow *Window;
  28. #else
  29. typedef class FLWindow_opaque *Window; // pointer to the FLWindow objective-c class
  30. #endif // __OBJC__
  31. #if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
  32. # include <FL/Fl_Widget.H>
  33. typedef struct flCocoaRegion* Fl_Region;
  34. typedef struct CGContext* CGContextRef;
  35. typedef struct OpaquePMPrintSettings* PMPrintSettings;
  36. typedef struct OpaquePMPageFormat* PMPageFormat;
  37. typedef struct OpaquePMPrintSession* PMPrintSession;
  38. typedef struct CGImage* CGImageRef;
  39. typedef CGContextRef Fl_Offscreen;
  40. #else // this part must be compiled when building the FLTK libraries
  41. // Standard MacOS C/C++ includes...
  42. #include <ApplicationServices/ApplicationServices.h>
  43. #undef check // because of Fl::check()
  44. #ifndef MAC_OS_X_VERSION_10_4
  45. #define MAC_OS_X_VERSION_10_4 1040
  46. #endif
  47. #ifndef MAC_OS_X_VERSION_10_5
  48. #define MAC_OS_X_VERSION_10_5 1050
  49. #endif
  50. #ifndef MAC_OS_X_VERSION_10_6
  51. #define MAC_OS_X_VERSION_10_6 1060
  52. #endif
  53. #ifndef MAC_OS_X_VERSION_10_7
  54. #define MAC_OS_X_VERSION_10_7 1070
  55. #endif
  56. #ifndef MAC_OS_X_VERSION_10_8
  57. #define MAC_OS_X_VERSION_10_8 1080
  58. #endif
  59. #ifdef __OBJC__
  60. @class NSCursor;
  61. #else
  62. class NSCursor;
  63. #endif // __OBJC__
  64. typedef CGContextRef Fl_Offscreen;
  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. # include "../src/Fl_Font.H"
  71. // Some random X equivalents
  72. struct XPoint { int x, y; };
  73. struct XRectangle {int x, y, width, height;};
  74. #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
  75. #if defined(__LP64__) && __LP64__
  76. typedef double CGFloat;
  77. #else
  78. typedef float CGFloat;
  79. #endif
  80. #endif // CGFLOAT_DEFINED
  81. extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
  82. inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
  83. Fl_Region R = (Fl_Region)malloc(sizeof(*R));
  84. R->count = 1;
  85. R->rects = (CGRect *)malloc(sizeof(CGRect));
  86. *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
  87. return R;
  88. }
  89. inline void XDestroyRegion(Fl_Region r) {
  90. if(r) {
  91. free(r->rects);
  92. free(r);
  93. }
  94. }
  95. extern NSCursor *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. NSCursor *cursor;
  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 CFDataRef CGBitmapContextToTIFF(CGContextRef c);
  133. static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
  134. static CGContextRef watch_cursor_image(void);
  135. static CGContextRef help_cursor_image(void);
  136. static CGContextRef nesw_cursor_image(void);
  137. static CGContextRef nwse_cursor_image(void);
  138. static CGContextRef none_cursor_image(void);
  139. static void *get_carbon_function(const char *name);
  140. static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
  141. static int next_marked_length; // next length of marked text after current marked text will have been replaced
  142. static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
  143. static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text
  144. static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
  145. private:
  146. static void relink(Fl_Window*, Fl_Window*);
  147. bool subwindow;
  148. };
  149. extern Window fl_window;
  150. #endif // FL_LIBRARY || FL_INTERNALS
  151. typedef CGImageRef Fl_Bitmask;
  152. extern CGContextRef fl_gc;
  153. extern Window fl_xid(const Fl_Window*);
  154. extern Fl_Window* fl_find(Window xid);
  155. void fl_clip_region(Fl_Region);
  156. extern Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  157. extern Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  158. extern void fl_delete_bitmask(Fl_Bitmask bm);
  159. extern Fl_Offscreen fl_create_offscreen(int w, int h);
  160. extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
  161. extern void fl_delete_offscreen(Fl_Offscreen gWorld);
  162. extern void fl_begin_offscreen(Fl_Offscreen gWorld);
  163. extern void fl_end_offscreen();
  164. extern int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  165. extern void fl_open_display();
  166. #endif // FL_DOXYGEN
  167. /** \file
  168. Mac OS X-specific symbols.
  169. */
  170. /** \defgroup group_macosx Mac OS X-specific symbols
  171. Mac OS X-specific symbols declared in <FL/x.H> or <FL/gl.h>
  172. \sa \ref osissues_macos
  173. @{ */
  174. /** @brief Register a function called for each file dropped onto an application icon.
  175. \e cb will be called with a single Unix-style file name and path.
  176. If multiple files were dropped, \e cb will be called multiple times.
  177. */
  178. extern void fl_open_callback(void (*cb)(const char *));
  179. /**
  180. * \brief Attaches a callback to the "About myprog" item of the system application menu.
  181. *
  182. * \param cb a callback that will be called by "About myprog" menu item
  183. * with NULL 1st argument.
  184. * \param user_data a pointer transmitted as 2nd argument to the callback.
  185. * \param shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
  186. */
  187. extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
  188. /** \brief The version number of the running Mac OS X (e.g., 100604 for 10.6.4)
  189. */
  190. extern int fl_mac_os_version;
  191. /** The system menu bar.
  192. */
  193. extern class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
  194. class Fl_Mac_App_Menu {
  195. public:
  196. /** Localizable text for the "About xxx" application menu item */
  197. static const char *about;
  198. /** Localizable text for the "Print Front Window" application menu item.
  199. This menu item won't be displayed if Fl_Mac_App_Menu::print
  200. is set to an empty string.
  201. */
  202. static const char *print;
  203. /** Localizable text for the "Services" application menu item */
  204. static const char *services;
  205. /** Localizable text for the "Hide xxx" application menu item */
  206. static const char *hide;
  207. /** Localizable text for the "Hide Others" application menu item */
  208. static const char *hide_others;
  209. /** Localizable text for the "Show All" application menu item */
  210. static const char *show;
  211. /** Localizable text for the "Quit xxx" application menu item */
  212. static const char *quit;
  213. };
  214. /** @} */
  215. //
  216. // End of "$Id: mac.H 10159 2014-05-23 16:47:21Z manolo $".
  217. //