mac.H 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // "$Id: mac.H 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Mac header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 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. // Standard MacOS Carbon API includes...
  35. #include <Carbon/Carbon.h>
  36. #ifndef MAC_OS_X_VERSION_10_3
  37. #define MAC_OS_X_VERSION_10_3 1030
  38. #endif
  39. #ifndef MAC_OS_X_VERSION_10_4
  40. #define MAC_OS_X_VERSION_10_4 1040
  41. #endif
  42. #ifndef MAC_OS_X_VERSION_10_5
  43. #define MAC_OS_X_VERSION_10_5 1050
  44. #endif
  45. #ifndef MAC_OS_X_VERSION_10_6
  46. #define MAC_OS_X_VERSION_10_6 1060
  47. #endif
  48. #ifndef MAC_OS_X_VERSION_MAX_ALLOWED
  49. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
  50. #endif
  51. #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
  52. #if defined(__LP64__) && __LP64__
  53. typedef double CGFloat;
  54. #else
  55. typedef float CGFloat;
  56. #endif
  57. #endif // CGFLOAT_DEFINED
  58. // Now make some fixes to the headers...
  59. #undef check // Dunno where this comes from...
  60. // Some random X equivalents
  61. struct XPoint { int x, y; };
  62. struct XRectangle {int x, y, width, height;};
  63. typedef void *Window; // this is really a pter to the subclass FLWindow of NSWindow
  64. typedef struct flCocoaRegion {
  65. int count;
  66. CGRect *rects;
  67. } *Fl_Region; // a region is the union of a series of rectangles
  68. extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
  69. inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
  70. Fl_Region R = (Fl_Region)malloc(sizeof(*R));
  71. R->count = 1;
  72. R->rects = (CGRect *)malloc(sizeof(CGRect));
  73. *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
  74. return R;
  75. }
  76. inline void XDestroyRegion(Fl_Region r) {
  77. if(r) {
  78. free(r->rects);
  79. free(r);
  80. }
  81. }
  82. extern void *fl_default_cursor;
  83. extern void *fl_system_menu;
  84. typedef CGContextRef Fl_Offscreen;
  85. typedef CGImageRef Fl_Bitmask;
  86. void fl_clip_region(Fl_Region);
  87. # include "Fl_Window.H"
  88. // This object contains all mac-specific stuff about a window:
  89. // WARNING: this object is highly subject to change!
  90. class Fl_X
  91. {
  92. public:
  93. Window xid; // Cocoa: FLWindow* ; Carbon: WindowRef
  94. Fl_Offscreen other_xid; // pointer for offscreen bitmaps (doublebuffer)
  95. Fl_Window *w; // FLTK window for
  96. Fl_Region region;
  97. Fl_Region subRegion; // region for this specific subwindow
  98. Fl_X *next; // linked tree to support subwindows
  99. Fl_X *xidChildren, *xidNext; // more subwindow tree
  100. int wait_for_expose;
  101. void *cursor; // is really NSCursor*
  102. static Fl_X* first;
  103. static Fl_X* i(const Fl_Window* w) {return w->i;}
  104. static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
  105. static void make(Fl_Window*);
  106. void flush();
  107. // Quartz additions:
  108. CGContextRef gc; // graphics context (NULL when using QD)
  109. static void q_fill_context(); // fill a Quartz context with current FLTK state
  110. static void q_clear_clipping(); // remove all clipping from a Quartz context
  111. static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
  112. static void q_begin_image(CGRect&, int x, int y, int w, int h);
  113. static void q_end_image();
  114. };
  115. extern void MacDestroyWindow(Fl_Window*,void *);
  116. extern void MacMapWindow(Fl_Window*,void *);
  117. extern void MacUnmapWindow(Fl_Window*,void *);
  118. extern WindowRef MACwindowRef(Fl_Window *w);
  119. extern Fl_Region MacRectRegionIntersect(Fl_Region current, int x,int y,int w, int h);
  120. extern void MacCollapseWindow(Window w);
  121. extern int MacUnlinkWindow(Fl_X*,Fl_X*start=0L);
  122. inline Window fl_xid(const Fl_Window*w)
  123. {
  124. return Fl_X::i(w)->xid;
  125. }
  126. extern struct Fl_XMap {
  127. RGBColor rgb;
  128. ulong pen;
  129. } *fl_current_xmap;
  130. extern FL_EXPORT void *fl_display;
  131. extern FL_EXPORT Window fl_window;
  132. extern FL_EXPORT CGContextRef fl_gc;
  133. extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
  134. extern Fl_Offscreen fl_create_offscreen(int w, int h);
  135. extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
  136. extern void fl_delete_offscreen(Fl_Offscreen gWorld);
  137. extern void fl_begin_offscreen(Fl_Offscreen gWorld);
  138. extern void fl_end_offscreen();
  139. extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
  140. extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
  141. extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
  142. extern void fl_open_display();
  143. extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  144. #endif // FL_DOXYGEN
  145. /** \defgroup group_macosx Mac OS X-specific functions
  146. @{ */
  147. /** @brief Register a function called for each file dropped onto an application icon
  148. * \note \#include <FL/x.H>
  149. */
  150. extern void fl_open_callback(void (*cb)(const char *));
  151. /**
  152. * \brief Attaches a callback to the "About myprog" item of the system application menu.
  153. * \note \#include <FL/x.H>
  154. *
  155. * \param cb a callback that will be called by "About myprog" menu item
  156. * with NULL 1st argument.
  157. * \param user_data a pointer transmitted as 2nd argument to the callback.
  158. * \param shortcut optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
  159. */
  160. extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
  161. /** The version number of the running Mac OS X (e.g., 0x1064 for 10.6.4)
  162. */
  163. extern int fl_mac_os_version;
  164. /** @} */
  165. //
  166. // End of "$Id: mac.H 7903 2010-11-28 21:06:39Z matt $".
  167. //