FLTK 1.3.2
mac.H
Go to the documentation of this file.
00001 //
00002 // "$Id: mac.H 9885 2013-04-16 14:02:42Z manolo $"
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_default_cursor;
00087 
00088 // This object contains all mac-specific stuff about a window:
00089 // WARNING: this object is highly subject to change!
00090 class Fl_X {
00091   
00092 public:
00093   Window xid;              // pointer to the Cocoa window object (FLWindow*)
00094   Fl_Offscreen other_xid;  // pointer for offscreen bitmaps (overlay window)
00095   Fl_Window *w;            // FLTK window for 
00096   Fl_Region region;
00097   Fl_Region subRegion;     // region for this specific subwindow
00098   Fl_X *next;              // linked tree to support subwindows
00099   Fl_X *xidChildren, *xidNext; // more subwindow tree
00100   int wait_for_expose;
00101   void *cursor;            // is really NSCursor*
00102   static Fl_X* first;
00103   static Fl_X* i(const Fl_Window* w) {return w->i;}
00104   static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
00105   static void make(Fl_Window*);
00106   void flush();
00107   // Quartz additions:
00108   CGContextRef gc;                 // graphics context (NULL when using QD)
00109   static void q_fill_context();    // fill a Quartz context with current FLTK state
00110   static void q_clear_clipping();  // remove all clipping from a Quartz context
00111   static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
00112   static void q_begin_image(CGRect&, int x, int y, int w, int h);
00113   static void q_end_image();
00114   // Cocoa additions
00115   void destroy(void);
00116   void map(void);
00117   void unmap(void);
00118   int unlink(Fl_X* start = NULL);
00119   void collapse(void);
00120   WindowRef window_ref(void);
00121   void set_key_window(void);
00122   void set_cursor(Fl_Cursor);
00123   static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
00124   static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
00125   static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
00126   static CGContextRef watch_cursor_image(void);
00127   static CGContextRef help_cursor_image(void);
00128   static CGContextRef nesw_cursor_image(void);
00129   static CGContextRef nwse_cursor_image(void);
00130   static CGContextRef none_cursor_image(void);
00131   static void *get_carbon_function(const char *name);
00132   static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
00133   static int next_marked_length; // next length of marked text after current marked text will have been replaced
00134   static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
00135 private:
00136   static void relink(Fl_Window*, Fl_Window*);
00137   bool subwindow;
00138 };
00139 
00140 extern Window fl_window;
00141 
00142 #endif // FL_LIBRARY || FL_INTERNALS
00143 
00144 #ifndef MAC_OS_X_VERSION_10_4
00145 #define MAC_OS_X_VERSION_10_4 1040
00146 #endif
00147 #ifndef MAC_OS_X_VERSION_10_5
00148 #define MAC_OS_X_VERSION_10_5 1050
00149 #endif
00150 #ifndef MAC_OS_X_VERSION_10_6
00151 #define MAC_OS_X_VERSION_10_6 1060
00152 #endif
00153 #ifndef MAC_OS_X_VERSION_10_7
00154 #define MAC_OS_X_VERSION_10_7 1070
00155 #endif
00156 #ifndef MAC_OS_X_VERSION_10_8
00157 #define MAC_OS_X_VERSION_10_8 1080
00158 #endif
00159 
00160 typedef CGImageRef Fl_Bitmask;
00161 
00162 extern CGContextRef fl_gc;
00163 extern class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
00164 
00165 extern Window fl_xid(const Fl_Window*);
00166 extern Fl_Window* fl_find(Window xid);
00167 void fl_clip_region(Fl_Region);
00168 
00169 extern Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
00170 extern Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
00171 extern void fl_delete_bitmask(Fl_Bitmask bm);
00172 extern Fl_Offscreen fl_create_offscreen(int w, int h);
00173 extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
00174 extern void fl_delete_offscreen(Fl_Offscreen gWorld);
00175 extern void fl_begin_offscreen(Fl_Offscreen gWorld);
00176 extern void fl_end_offscreen();
00177 
00178 extern int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
00179 extern void fl_open_display();
00180 
00181 #endif // FL_DOXYGEN
00182 
00195 extern void fl_open_callback(void (*cb)(const char *));
00196 
00205 extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
00206 
00209 extern int fl_mac_os_version;
00210 
00211 class Fl_Mac_App_Menu {
00212 public:
00214   static const char *about;
00219   static const char *print;
00221   static const char *services;
00223   static const char *hide;
00225   static const char *hide_others;
00227   static const char *show;
00229   static const char *quit;
00230 };
00231 
00234 //
00235 // End of "$Id: mac.H 9885 2013-04-16 14:02:42Z manolo $".
00236 //
00237