• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

mac.H

Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // Mac header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2016 by Bill Spitzak and others.
00007 //
00008 // This library is free software. Distribution and use rights are outlined in
00009 // the file "COPYING" which should have been included with this file.  If this
00010 // file is missing or damaged, see the license at:
00011 //
00012 //     http://www.fltk.org/COPYING.php
00013 //
00014 // Please report all bugs and problems on the following page:
00015 //
00016 //     http://www.fltk.org/str.php
00017 //
00018 
00019 // Do not directly include this file, instead use <FL/x.H>.  It will
00020 // include this file if "__APPLE__" is defined.  This is to encourage
00021 // portability of even the system-specific code...
00022 #ifndef FL_DOXYGEN
00023 
00024 #if !defined(Fl_X_H)
00025 #  error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
00026 #endif // !Fl_X_H
00027 
00028 #ifdef __OBJC__
00029 @class FLWindow; // a subclass of the NSWindow Cocoa class
00030 typedef FLWindow *Window;
00031 #else
00032 typedef class FLWindow *Window; // pointer to the FLWindow objective-c class
00033 #endif // __OBJC__
00034 
00035 #if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
00036 #  include <FL/Fl_Widget.H>
00037 
00038 typedef struct flCocoaRegion* Fl_Region;
00039 typedef struct CGContext* CGContextRef;
00040 typedef struct OpaquePMPrintSettings*   PMPrintSettings;
00041 typedef struct OpaquePMPageFormat*      PMPageFormat;
00042 typedef struct OpaquePMPrintSession*    PMPrintSession;
00043 typedef struct CGImage* CGImageRef;
00044 typedef struct __CFData* CFMutableDataRef; // used in Fl_Copy_Surface.H
00045 typedef CGContextRef Fl_Offscreen;
00046 
00047 #else // this part must be compiled when building the FLTK libraries
00048 
00049 // Standard MacOS C/C++ includes...
00050 #include <ApplicationServices/ApplicationServices.h>
00051 #undef check // because of Fl::check()
00052 
00053 #ifndef MAC_OS_X_VERSION_10_4
00054 #define MAC_OS_X_VERSION_10_4 1040
00055 #endif
00056 #ifndef MAC_OS_X_VERSION_10_5
00057 #define MAC_OS_X_VERSION_10_5 1050
00058 #endif
00059 #ifndef MAC_OS_X_VERSION_10_6
00060 #define MAC_OS_X_VERSION_10_6 1060
00061 #endif
00062 #ifndef MAC_OS_X_VERSION_10_7
00063 #define MAC_OS_X_VERSION_10_7 1070
00064 #endif
00065 #ifndef MAC_OS_X_VERSION_10_8
00066 #define MAC_OS_X_VERSION_10_8 1080
00067 #endif
00068 #ifndef MAC_OS_X_VERSION_10_9
00069 #define MAC_OS_X_VERSION_10_9 1090
00070 #endif
00071 #ifndef MAC_OS_X_VERSION_10_10
00072 #define MAC_OS_X_VERSION_10_10 101000
00073 #endif
00074 #ifndef MAC_OS_X_VERSION_10_11
00075 #define MAC_OS_X_VERSION_10_11 101100
00076 #endif
00077 #ifndef MAC_OS_X_VERSION_10_12
00078 #define MAC_OS_X_VERSION_10_12 101200
00079 #endif
00080 #ifndef MAC_OS_X_VERSION_10_13
00081 #define MAC_OS_X_VERSION_10_13 101300
00082 #endif
00083 #ifndef MAC_OS_X_VERSION_10_14
00084 #define MAC_OS_X_VERSION_10_14 101400
00085 #endif
00086 
00087 #ifndef NSINTEGER_DEFINED // appears with 10.5 in NSObjCRuntime.h
00088 #if defined(__LP64__) && __LP64__
00089 typedef long NSInteger;
00090 typedef unsigned long NSUInteger;
00091 #else
00092 typedef int NSInteger;
00093 typedef unsigned int NSUInteger;
00094 #endif
00095 #endif
00096 
00097 #ifdef __OBJC__
00098 @class NSCursor;
00099 @class NSOpenGLPixelFormat;
00100 @class NSOpenGLContext;
00101 #else
00102 class NSCursor;
00103 class NSOpenGLPixelFormat;
00104 class NSOpenGLContext;
00105 #endif // __OBJC__
00106 
00107 typedef CGContextRef Fl_Offscreen;
00108 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
00109 typedef CGImageAlphaInfo CGBitmapInfo;
00110 #endif
00111 
00112 typedef struct flCocoaRegion {
00113   int count;
00114   CGRect *rects;
00115 } *Fl_Region;  // a region is the union of a series of rectangles
00116 
00117 #  include "Fl_Window.H"
00118 #  include "../src/Fl_Font.H"
00119 
00120 // Some random X equivalents
00121 struct XPoint { int x, y; };
00122 struct XRectangle {int x, y, width, height;};
00123 #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
00124 #if defined(__LP64__) && __LP64__
00125 typedef double CGFloat;
00126 #else
00127 typedef float CGFloat;
00128 #endif
00129 #endif // CGFLOAT_DEFINED
00130 
00131 extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
00132 inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
00133   Fl_Region R = (Fl_Region)malloc(sizeof(*R));
00134   R->count = 1;
00135   R->rects = (CGRect *)malloc(sizeof(CGRect));
00136   *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
00137   return R;
00138 }
00139 inline void XDestroyRegion(Fl_Region r) {
00140   if(r) {
00141     free(r->rects);
00142     free(r);
00143   }
00144 }
00145 extern NSCursor *fl_default_cursor;
00146 
00147 // This object contains all mac-specific stuff about a window:
00148 // WARNING: this object is highly subject to change!
00149 class Fl_X {
00150   
00151 public:
00152   Window xid;              // pointer to the Cocoa window object (FLWindow*)
00153   Fl_Offscreen other_xid;  // pointer for offscreen bitmaps (overlay window)
00154   Fl_Window *w;            // FLTK window for 
00155   Fl_Region region;
00156 #if FLTK_ABI_VERSION < 10304
00157   Fl_Region subRegion;     // for ABI compatibility, recycled to replace subRect_
00158 #endif
00159   Fl_X *next;              // chain of mapped windows
00160 #if FLTK_ABI_VERSION < 10304
00161   Fl_X *xidChildren;       // useless with true subwindows, recycled to replace mapped_to_retina_
00162   Fl_X *xidNext;           // useless with true subwindows
00163 #endif
00164   int wait_for_expose;
00165   NSCursor *cursor;
00166   static Fl_X* first;
00167   static Fl_X* i(const Fl_Window* w) {return w->i;}
00168   static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
00169   static void make(Fl_Window*);
00170   void flush();
00171   static void set_high_resolution(bool);
00172 #if FLTK_ABI_VERSION >= 10304
00173   CGRect* subRect() { return subRect_; } // getter
00174   void subRect(CGRect *r) { subRect_ = r; } // setter
00175 #else
00176   CGRect* subRect() { return (CGRect*)subRegion; } // getter
00177   void subRect(CGRect *r) { subRegion = (Fl_Region)r; } // setter
00178 #endif
00179   bool mapped_to_retina();      // is window mapped to retina display?
00180   void mapped_to_retina(bool);  // sets whether window is mapped to retina display
00181   bool changed_resolution();      // did window just moved to display with another resolution?
00182   void changed_resolution(bool);// sets whether window just moved to display with another resolution
00183   bool in_windowDidResize();      // is window performing windowDidResize?
00184   void in_windowDidResize(bool);  // sets whether window is performing windowDidResize
00185   // Quartz additions:
00186   CGContextRef gc;                 // graphics context (NULL when using QD)
00187   static void q_fill_context();    // fill a Quartz context with current FLTK state
00188   static void q_clear_clipping();  // remove all clipping from a Quartz context
00189   static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
00190   static void q_begin_image(CGRect&, int x, int y, int w, int h);
00191   static void q_end_image();
00192   // Cocoa additions
00193   static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // computes NSOpenGLPixelFormat from Gl window's mode
00194   static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window);
00195   static void GLcontext_update(NSOpenGLContext*);
00196   static void GLcontext_flushbuffer(NSOpenGLContext*);
00197   static void GLcontext_release(NSOpenGLContext*);
00198   static void GLcontext_makecurrent(NSOpenGLContext*);
00199   static void GL_cleardrawable(void);
00200   static void gl_start(NSOpenGLContext*);
00201   void destroy(void);
00202   void map(void);
00203   void unmap(void);
00204   void collapse(void);
00205   WindowRef window_ref(void); // useless with cocoa GL windows
00206   void set_key_window(void);
00207   // OS X doesn't have per window icons
00208   static void set_default_icons(const Fl_RGB_Image*[], int) {};
00209   void set_icons() {};
00210   int set_cursor(Fl_Cursor);
00211   int set_cursor(const Fl_RGB_Image*, int, int);
00212   static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
00213   static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
00214   static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
00215   static void *get_carbon_function(const char *name);
00216   static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
00217   static int next_marked_length; // next length of marked text after current marked text will have been replaced
00218   static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
00219   static const int CoreText_threshold;  // Mac OS version from which the Core Text API is used to display text
00220   static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
00221   static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
00222   static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
00223   static void clip_to_rounded_corners(CGContextRef gc, int w, int h);
00224   static void *get_titlebar_layer(Fl_Window *win);
00225   static void draw_layer_to_context(void *layer, CGContextRef ctxt, int w, int h);
00226 private:
00227 #if FLTK_ABI_VERSION >= 10304
00228   CGRect* subRect_;           // makes sure subwindow remains inside its parent window
00229   // stores 3 binary flags: whether window is mapped to retina display; whether resolution just changed;
00230   // whether window is OpenGL and is currently being resized.
00231   unsigned mapped_to_retina_;
00232 #else
00233   bool subwindow;     // for ABI compatibility, useless with true subwindows
00234 #endif
00235 };
00236 
00237 extern Window fl_window;
00238 
00239 #endif // FL_LIBRARY || FL_INTERNALS
00240 
00241 typedef CGImageRef Fl_Bitmask;
00242 
00243 extern CGContextRef fl_gc;
00244 
00245 extern Window fl_xid(const Fl_Window*);
00246 extern Fl_Window* fl_find(Window xid);
00247 void fl_clip_region(Fl_Region);
00248 
00249 extern Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
00250 extern Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
00251 extern void fl_delete_bitmask(Fl_Bitmask bm);
00252 extern Fl_Offscreen fl_create_offscreen(int w, int h);
00253 extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
00254 extern void fl_delete_offscreen(Fl_Offscreen gWorld);
00255 extern void fl_begin_offscreen(Fl_Offscreen gWorld);
00256 extern void fl_end_offscreen();
00257 
00258 extern int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
00259 extern void fl_open_display();
00260 
00261 #endif // FL_DOXYGEN
00262 
00275 extern void fl_open_callback(void (*cb)(const char *));
00276 
00285 extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
00286 
00289 extern int fl_mac_os_version;
00290 
00297 extern int fl_mac_quit_early;
00298 
00301 extern class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
00302 
00303 struct Fl_Menu_Item;
00304 
00305 class Fl_Mac_App_Menu {
00306 public:
00308   static const char *about;
00313   static const char *print;
00315   static const char *services;
00317   static const char *hide;
00319   static const char *hide_others;
00321   static const char *show;
00323   static const char *quit;
00324   static void custom_application_menu_items(const Fl_Menu_Item *m);
00325 };
00326 
00329 //
00330 // End of "$Id$".
00331 //
00332 
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.