FLTK 1.3.0
mac.H
00001 //
00002 // "$Id: mac.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
00003 //
00004 // Mac header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2011 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 #include <FL/Fl_Widget.H>
00028 
00029 typedef void* Window;       // this is really a pointer to the subclass FLWindow of NSWindow
00030 typedef void* Fl_Offscreen; // this is really a CGContextRef
00031 typedef void* Fl_Bitmask;   // this is really a CGImageRef
00032 
00033 #include <AvailabilityMacros.h>
00034 #ifndef MAC_OS_X_VERSION_10_3
00035 #define MAC_OS_X_VERSION_10_3 1030
00036 #endif
00037 #ifndef MAC_OS_X_VERSION_10_4
00038 #define MAC_OS_X_VERSION_10_4 1040
00039 #endif
00040 #ifndef MAC_OS_X_VERSION_10_5
00041 #define MAC_OS_X_VERSION_10_5 1050
00042 #endif
00043 #ifndef MAC_OS_X_VERSION_10_6
00044 #define MAC_OS_X_VERSION_10_6 1060
00045 #endif
00046 
00047 #if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
00048 
00049 typedef void* Fl_Region;
00050 typedef void* Fl_CGContextRef;
00051 typedef void* Fl_PMPrintSettings;
00052 typedef void* Fl_PMPageFormat;
00053 typedef void* Fl_PMPrintSession;
00054 
00055 #else // this part must be compiled when building the FLTK libraries
00056 
00057 // Standard MacOS C/C++ includes...
00058 #include <ApplicationServices/ApplicationServices.h>
00059 #undef check // because of Fl::check()
00060 
00061 typedef CGContextRef    Fl_CGContextRef;
00062 typedef PMPrintSettings Fl_PMPrintSettings;
00063 typedef PMPageFormat    Fl_PMPageFormat;
00064 typedef PMPrintSession  Fl_PMPrintSession;
00065 
00066 typedef struct flCocoaRegion {
00067   int count;
00068   CGRect *rects;
00069 } *Fl_Region;  // a region is the union of a series of rectangles
00070 
00071 #  include "Fl_Window.H"
00072 
00073 // Some random X equivalents
00074 struct XPoint { int x, y; };
00075 struct XRectangle {int x, y, width, height;};
00076 #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
00077 #if defined(__LP64__) && __LP64__
00078 typedef double CGFloat;
00079 #else
00080 typedef float CGFloat;
00081 #endif
00082 #endif // CGFLOAT_DEFINED
00083 
00084 extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
00085 inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
00086   Fl_Region R = (Fl_Region)malloc(sizeof(*R));
00087   R->count = 1;
00088   R->rects = (CGRect *)malloc(sizeof(CGRect));
00089   *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
00090   return R;
00091 }
00092 inline void XDestroyRegion(Fl_Region r) {
00093   if(r) {
00094     free(r->rects);
00095     free(r);
00096   }
00097 }
00098 extern void *fl_system_menu;
00099 extern void *fl_default_cursor;
00100 
00101 // This object contains all mac-specific stuff about a window:
00102 // WARNING: this object is highly subject to change!
00103 class Fl_X {
00104   
00105 public:
00106   Window xid;              // pointer to the Cocoa window object (FLWindow*)
00107   Fl_Offscreen other_xid;  // pointer for offscreen bitmaps (overlay window)
00108   Fl_Window *w;            // FLTK window for 
00109   Fl_Region region;
00110   Fl_Region subRegion;     // region for this specific subwindow
00111   Fl_X *next;              // linked tree to support subwindows
00112   Fl_X *xidChildren, *xidNext; // more subwindow tree
00113   int wait_for_expose;
00114   void *cursor;            // is really NSCursor*
00115   static Fl_X* first;
00116   static Fl_X* i(const Fl_Window* w) {return w->i;}
00117   static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
00118   static void make(Fl_Window*);
00119   void flush();
00120   // Quartz additions:
00121   CGContextRef gc;                 // graphics context (NULL when using QD)
00122   static void q_fill_context();    // fill a Quartz context with current FLTK state
00123   static void q_clear_clipping();  // remove all clipping from a Quartz context
00124   static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
00125   static void q_begin_image(CGRect&, int x, int y, int w, int h);
00126   static void q_end_image();
00127   // Cocoa additions
00128   void destroy(void);
00129   void map(void);
00130   void unmap(void);
00131   int unlink(Fl_X* start = NULL);
00132   void collapse(void);
00133   WindowRef window_ref(void);
00134   void set_key_window(void);
00135   void set_cursor(Fl_Cursor);
00136   static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
00137   static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
00138   static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
00139   static CGContextRef watch_cursor_image(void);
00140   static CGContextRef help_cursor_image(void);
00141   static CGContextRef nesw_cursor_image(void);
00142   static CGContextRef nwse_cursor_image(void);
00143   static CGContextRef none_cursor_image(void);
00144   static void *get_carbon_function(const char *name);
00145 private:
00146   static void relink(Fl_Window*, Fl_Window*);
00147   bool subwindow;
00148 };
00149 
00150 extern struct Fl_XMap {
00151   RGBColor rgb;
00152   ulong pen;
00153 } *fl_current_xmap;
00154 extern FL_EXPORT Window fl_window;
00155 
00156 #endif // FL_LIBRARY || FL_INTERNALS
00157 
00158 extern FL_EXPORT Fl_CGContextRef fl_gc;
00159 extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
00160 
00161 extern Window fl_xid(const Fl_Window*);
00162 void fl_clip_region(Fl_Region);
00163 
00164 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
00165 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
00166 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
00167 extern Fl_Offscreen fl_create_offscreen(int w, int h);
00168 extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
00169 extern void fl_delete_offscreen(Fl_Offscreen gWorld);
00170 extern void fl_begin_offscreen(Fl_Offscreen gWorld);
00171 extern void fl_end_offscreen();
00172 
00173 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
00174 extern void fl_open_display();
00175 
00176 #endif // FL_DOXYGEN
00177 
00186 extern void fl_open_callback(void (*cb)(const char *));
00187 
00196 extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
00197 
00200 extern int fl_mac_os_version;
00201 
00202 class Fl_Mac_App_Menu {
00203 public:
00205   static const char *about;
00210   static const char *print;
00212   static const char *services;
00214   static const char *hide;
00216   static const char *hide_others;
00218   static const char *show;
00220   static const char *quit;
00221 };
00222 
00225 //
00226 // End of "$Id: mac.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
00227 //
00228