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