FLTK 1.3.3
mac.H
Go to the documentation of this file.
1 //
2 // "$Id: mac.H 10305 2014-09-13 14:29:53Z manolo $"
3 //
4 // Mac header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2011 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // Do not directly include this file, instead use <FL/x.H>. It will
20 // include this file if "__APPLE__" is defined. This is to encourage
21 // portability of even the system-specific code...
22 #ifndef FL_DOXYGEN
23 
24 #if !defined(Fl_X_H)
25 # error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
26 #endif // !Fl_X_H
27 
28 #ifdef __OBJC__
29 @class FLWindow; // a subclass of the NSWindow Cocoa class
30 typedef FLWindow *Window;
31 #else
32 typedef class FLWindow_opaque *Window; // pointer to the FLWindow objective-c class
33 #endif // __OBJC__
34 
35 #if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
36 # include <FL/Fl_Widget.H>
37 
38 typedef struct flCocoaRegion* Fl_Region;
39 typedef struct CGContext* CGContextRef;
40 typedef struct OpaquePMPrintSettings* PMPrintSettings;
41 typedef struct OpaquePMPageFormat* PMPageFormat;
42 typedef struct OpaquePMPrintSession* PMPrintSession;
43 typedef struct CGImage* CGImageRef;
44 typedef CGContextRef Fl_Offscreen;
45 
46 #else // this part must be compiled when building the FLTK libraries
47 
48 // Standard MacOS C/C++ includes...
49 #include <ApplicationServices/ApplicationServices.h>
50 #undef check // because of Fl::check()
51 
52 #ifndef MAC_OS_X_VERSION_10_4
53 #define MAC_OS_X_VERSION_10_4 1040
54 #endif
55 #ifndef MAC_OS_X_VERSION_10_5
56 #define MAC_OS_X_VERSION_10_5 1050
57 #endif
58 #ifndef MAC_OS_X_VERSION_10_6
59 #define MAC_OS_X_VERSION_10_6 1060
60 #endif
61 #ifndef MAC_OS_X_VERSION_10_7
62 #define MAC_OS_X_VERSION_10_7 1070
63 #endif
64 #ifndef MAC_OS_X_VERSION_10_8
65 #define MAC_OS_X_VERSION_10_8 1080
66 #endif
67 #ifndef MAC_OS_X_VERSION_10_9
68 #define MAC_OS_X_VERSION_10_9 1090
69 #endif
70 #ifndef MAC_OS_X_VERSION_10_10
71 #define MAC_OS_X_VERSION_10_10 101000
72 #endif
73 
74 #ifdef __OBJC__
75 @class NSCursor;
76 #else
77 class NSCursor;
78 #endif // __OBJC__
79 
80 typedef CGContextRef Fl_Offscreen;
81 
82 typedef struct flCocoaRegion {
83  int count;
84  CGRect *rects;
85 } *Fl_Region; // a region is the union of a series of rectangles
86 
87 # include "Fl_Window.H"
88 # include "../src/Fl_Font.H"
89 
90 // Some random X equivalents
91 struct XPoint { int x, y; };
92 struct XRectangle {int x, y, width, height;};
93 #ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
94 #if defined(__LP64__) && __LP64__
95 typedef double CGFloat;
96 #else
97 typedef float CGFloat;
98 #endif
99 #endif // CGFLOAT_DEFINED
100 
101 extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
102 inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
103  Fl_Region R = (Fl_Region)malloc(sizeof(*R));
104  R->count = 1;
105  R->rects = (CGRect *)malloc(sizeof(CGRect));
106  *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
107  return R;
108 }
109 inline void XDestroyRegion(Fl_Region r) {
110  if(r) {
111  free(r->rects);
112  free(r);
113  }
114 }
115 extern NSCursor *fl_default_cursor;
116 
117 // This object contains all mac-specific stuff about a window:
118 // WARNING: this object is highly subject to change!
119 class Fl_X {
120 
121 public:
122  Window xid; // pointer to the Cocoa window object (FLWindow*)
123  Fl_Offscreen other_xid; // pointer for offscreen bitmaps (overlay window)
124  Fl_Window *w; // FLTK window for
125  Fl_Region region;
126  Fl_Region subRegion; // region for this specific subwindow
127  Fl_X *next; // linked tree to support subwindows
128  Fl_X *xidChildren, *xidNext; // more subwindow tree
129  int wait_for_expose;
130  NSCursor *cursor;
131  static Fl_X* first;
132  static Fl_X* i(const Fl_Window* w) {return w->i;}
133  static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
134  static void make(Fl_Window*);
135  void flush();
136  // Quartz additions:
137  CGContextRef gc; // graphics context (NULL when using QD)
138  static void q_fill_context(); // fill a Quartz context with current FLTK state
139  static void q_clear_clipping(); // remove all clipping from a Quartz context
140  static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
141  static void q_begin_image(CGRect&, int x, int y, int w, int h);
142  static void q_end_image();
143  // Cocoa additions
144  void destroy(void);
145  void map(void);
146  void unmap(void);
147  int unlink(Fl_X* start = NULL);
148  void collapse(void);
149  WindowRef window_ref(void);
150  void set_key_window(void);
151  // OS X doesn't have per window icons
152  static void set_default_icons(const Fl_RGB_Image*[], int) {};
153  void set_icons() {};
154  int set_cursor(Fl_Cursor);
155  int set_cursor(const Fl_RGB_Image*, int, int);
156  static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
157  static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
158  static CFDataRef CGBitmapContextToTIFF(CGContextRef c);
159  static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
160  static CGContextRef watch_cursor_image(void);
161  static CGContextRef help_cursor_image(void);
162  static CGContextRef nesw_cursor_image(void);
163  static CGContextRef nwse_cursor_image(void);
164  static CGContextRef none_cursor_image(void);
165  static void *get_carbon_function(const char *name);
166  static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
167  static int next_marked_length; // next length of marked text after current marked text will have been replaced
168  static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
169  static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text
170  static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
171 private:
172  static void relink(Fl_Window*, Fl_Window*);
173  bool subwindow;
174 };
175 
176 extern Window fl_window;
177 
178 #endif // FL_LIBRARY || FL_INTERNALS
179 
180 typedef CGImageRef Fl_Bitmask;
181 
182 extern CGContextRef fl_gc;
183 
184 extern Window fl_xid(const Fl_Window*);
185 extern Fl_Window* fl_find(Window xid);
186 void fl_clip_region(Fl_Region);
187 
188 extern Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
189 extern Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
190 extern void fl_delete_bitmask(Fl_Bitmask bm);
191 extern Fl_Offscreen fl_create_offscreen(int w, int h);
192 extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
193 extern void fl_delete_offscreen(Fl_Offscreen gWorld);
194 extern void fl_begin_offscreen(Fl_Offscreen gWorld);
195 extern void fl_end_offscreen();
196 
197 extern int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
198 extern void fl_open_display();
199 
200 #endif // FL_DOXYGEN
201 
214 extern void fl_open_callback(void (*cb)(const char *));
215 
224 extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
225 
228 extern int fl_mac_os_version;
229 
232 extern class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
233 
234 
236 public:
238  static const char *about;
243  static const char *print;
245  static const char *services;
247  static const char *hide;
249  static const char *hide_others;
251  static const char *show;
253  static const char *quit;
254 };
255 
258 //
259 // End of "$Id: mac.H 10305 2014-09-13 14:29:53Z manolo $".
260 //
261 
This widget produces an actual window.
Definition: Fl_Window.H:57
Fl_Cursor
The following constants define the mouse cursors that are available in FLTK.
Definition: Enumerations.H:910
void fl_clip_region(Fl_Region r)
Replaces the top of the clipping stack with a clipping region of any shape.
Definition: fl_draw.H:136
Mac OS-specific class allowing to localize the application menu.
Definition: mac.H:235
static const char * services
Localizable text for the "Services" application menu item.
Definition: mac.H:245
void fl_delete_offscreen(Fl_Offscreen ctx)
Deletion of an offscreen graphics buffer.
Definition: Fl_Double_Window.cxx:298
void fl_open_callback(void(*cb)(const char *))
Register a function called for each file dropped onto an application icon.
static const char * show
Localizable text for the "Show All" application menu item.
Definition: mac.H:251
void fl_begin_offscreen(Fl_Offscreen ctx)
Send all subsequent drawing commands to this offscreen buffer.
Definition: Fl_Double_Window.cxx:315
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition: Fl_Image.H:183
class Fl_Sys_Menu_Bar * fl_sys_menu_bar
The system menu bar.
Definition: Fl_Sys_Menu_Bar.mm:60
Fl_Offscreen fl_create_offscreen(int w, int h)
Creation of an offscreen graphics buffer.
Definition: Fl_Double_Window.cxx:257
void( Fl_Callback)(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition: Fl_Widget.H:49
Fl_Window widget .
Fl_Widget, Fl_Label classes .
A class to create, modify and delete menus that appear on Mac OS X in the menu bar at the top of the ...
Definition: Fl_Sys_Menu_Bar.H:41
static const char * about
Localizable text for the "About xxx" application menu item.
Definition: mac.H:238
static const char * hide_others
Localizable text for the "Hide Others" application menu item.
Definition: mac.H:249
static const char * print
Localizable text for the "Print Front Window" application menu item.
Definition: mac.H:243
Definition: Fl_Font.H:86
int fl_mac_os_version
The version number of the running Mac OS X (e.g., 100604 for 10.6.4)
void fl_mac_set_about(Fl_Callback *cb, void *user_data, int shortcut=0)
Attaches a callback to the "About myprog" item of the system application menu.
Definition: Fl_Sys_Menu_Bar.mm:191
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
Copy a rectangular area of the given offscreen buffer into the current drawing destination.
Definition: Fl_Double_Window.cxx:98
unsigned char uchar
unsigned char
Definition: fl_types.h:30
static const char * quit
Localizable text for the "Quit xxx" application menu item.
Definition: mac.H:253
void fl_end_offscreen()
Quit sending drawing commands to the current offscreen buffer.
Definition: Fl_Double_Window.cxx:333
static const char * hide
Localizable text for the "Hide xxx" application menu item.
Definition: mac.H:247