FLTK 1.3.9
Loading...
Searching...
No Matches
mac.H
Go to the documentation of this file.
1//
2// "$Id$"
3//
4// Mac header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2016 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
30typedef FLWindow *Window;
31#else
32typedef class FLWindow *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
38typedef struct flCocoaRegion* Fl_Region;
39typedef struct CGContext* CGContextRef;
40typedef struct OpaquePMPrintSettings* PMPrintSettings;
41typedef struct OpaquePMPageFormat* PMPageFormat;
42typedef struct OpaquePMPrintSession* PMPrintSession;
43typedef struct CGImage* CGImageRef;
44typedef struct __CFData* CFMutableDataRef; // used in Fl_Copy_Surface.H
45typedef CGContextRef Fl_Offscreen;
46
47#else // this part must be compiled when building the FLTK libraries
48
49// Standard MacOS C/C++ includes...
50#include <ApplicationServices/ApplicationServices.h>
51#undef check // because of Fl::check()
52
53#ifndef MAC_OS_X_VERSION_10_4
54#define MAC_OS_X_VERSION_10_4 1040
55#endif
56#ifndef MAC_OS_X_VERSION_10_5
57#define MAC_OS_X_VERSION_10_5 1050
58#endif
59#ifndef MAC_OS_X_VERSION_10_6
60#define MAC_OS_X_VERSION_10_6 1060
61#endif
62#ifndef MAC_OS_X_VERSION_10_7
63#define MAC_OS_X_VERSION_10_7 1070
64#endif
65#ifndef MAC_OS_X_VERSION_10_8
66#define MAC_OS_X_VERSION_10_8 1080
67#endif
68#ifndef MAC_OS_X_VERSION_10_9
69#define MAC_OS_X_VERSION_10_9 1090
70#endif
71#ifndef MAC_OS_X_VERSION_10_10
72#define MAC_OS_X_VERSION_10_10 101000
73#endif
74#ifndef MAC_OS_X_VERSION_10_11
75#define MAC_OS_X_VERSION_10_11 101100
76#endif
77#ifndef MAC_OS_X_VERSION_10_12
78#define MAC_OS_X_VERSION_10_12 101200
79#endif
80#ifndef MAC_OS_X_VERSION_10_13
81#define MAC_OS_X_VERSION_10_13 101300
82#endif
83#ifndef MAC_OS_X_VERSION_10_14
84#define MAC_OS_X_VERSION_10_14 101400
85#endif
86#ifndef MAC_OS_X_VERSION_10_15
87#define MAC_OS_X_VERSION_10_15 101500
88#endif
89#ifndef MAC_OS_X_VERSION_10_16
90#define MAC_OS_X_VERSION_10_16 101600
91#endif
92#ifndef MAC_OS_VERSION_11_0
93#define MAC_OS_VERSION_11_0 110000
94#endif
95#ifndef MAC_OS_VERSION_12_0
96#define MAC_OS_VERSION_12_0 120000
97#endif
98#ifndef MAC_OS_VERSION_13_0
99#define MAC_OS_VERSION_13_0 130000
100#endif
101#ifndef MAC_OS_VERSION_14_0
102#define MAC_OS_VERSION_14_0 140000
103#endif
104
105#ifndef NSINTEGER_DEFINED // appears with 10.5 in NSObjCRuntime.h
106#if defined(__LP64__) && __LP64__
107typedef long NSInteger;
108typedef unsigned long NSUInteger;
109#else
110typedef int NSInteger;
111typedef unsigned int NSUInteger;
112#endif
113#endif
114
115#ifdef __OBJC__
116@class NSCursor;
117@class NSOpenGLPixelFormat;
118@class NSOpenGLContext;
119#else
120class NSCursor;
121class NSOpenGLPixelFormat;
122class NSOpenGLContext;
123#endif // __OBJC__
124
125typedef CGContextRef Fl_Offscreen;
126#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
127typedef CGImageAlphaInfo CGBitmapInfo;
128#endif
129
130typedef struct flCocoaRegion {
131 int count;
132 CGRect *rects;
133} *Fl_Region; // a region is the union of a series of rectangles
134
135# include "Fl_Window.H"
136# include "../src/Fl_Font.H"
137
138// Some random X equivalents
139struct XPoint { int x, y; };
140struct XRectangle {int x, y, width, height;};
141#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
142#if defined(__LP64__) && __LP64__
143typedef double CGFloat;
144#else
145typedef float CGFloat;
146#endif
147#endif // CGFLOAT_DEFINED
148
149extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
150inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
151 Fl_Region R = (Fl_Region)malloc(sizeof(*R));
152 R->count = 1;
153 R->rects = (CGRect *)malloc(sizeof(CGRect));
154 *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
155 return R;
156}
157inline void XDestroyRegion(Fl_Region r) {
158 if(r) {
159 free(r->rects);
160 free(r);
161 }
162}
163extern NSCursor *fl_default_cursor;
164
165// This object contains all mac-specific stuff about a window:
166// WARNING: this object is highly subject to change!
167class Fl_X {
168
169public:
170 Window xid; // pointer to the Cocoa window object (FLWindow*)
171 Fl_Offscreen other_xid; // pointer for offscreen bitmaps (overlay window)
172 Fl_Window *w; // FLTK window for
173 Fl_Region region;
174#if FLTK_ABI_VERSION < 10304
175 Fl_Region subRegion; // for ABI compatibility, recycled to replace subRect_
176#endif
177 Fl_X *next; // chain of mapped windows
178#if FLTK_ABI_VERSION < 10304
179 Fl_X *xidChildren; // useless with true subwindows, recycled to replace mapped_to_retina_
180 Fl_X *xidNext; // useless with true subwindows
181#endif
182 int wait_for_expose;
183 NSCursor *cursor;
184 static Fl_X* first;
185 static Fl_X* i(const Fl_Window* w) {return w->i;}
186 static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&,int,int,int,int);
187 static void make(Fl_Window*);
188 void flush();
189 static void set_high_resolution(bool);
190#if FLTK_ABI_VERSION >= 10304
191 CGRect* subRect() { return subRect_; } // getter
192 void subRect(CGRect *r) { subRect_ = r; } // setter
193#else
194 CGRect* subRect() { return (CGRect*)subRegion; } // getter
195 void subRect(CGRect *r) { subRegion = (Fl_Region)r; } // setter
196#endif
197 bool mapped_to_retina(); // is window mapped to retina display?
198 void mapped_to_retina(bool); // sets whether window is mapped to retina display
199 bool changed_resolution(); // did window just moved to display with another resolution?
200 void changed_resolution(bool);// sets whether window just moved to display with another resolution
201 bool in_windowDidResize(); // is window performing windowDidResize?
202 void in_windowDidResize(bool); // sets whether window is performing windowDidResize
203 // Quartz additions:
204 CGContextRef gc; // graphics context (NULL when using QD)
205 static void q_fill_context(); // fill a Quartz context with current FLTK state
206 static void q_clear_clipping(); // remove all clipping from a Quartz context
207 static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
208 static void q_begin_image(CGRect&, int x, int y, int w, int h);
209 static void q_end_image();
210 // Cocoa additions
211 static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // computes NSOpenGLPixelFormat from Gl window's mode
212 static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window);
213 static void GLcontext_update(NSOpenGLContext*);
214 static void GLcontext_flushbuffer(NSOpenGLContext*);
215 static void GLcontext_release(NSOpenGLContext*);
216 static void GLcontext_makecurrent(NSOpenGLContext*);
217 static void GL_cleardrawable(void);
218 static void gl_start(NSOpenGLContext*);
219 void destroy(void);
220 void map(void);
221 void unmap(void);
222 void collapse(void);
223 WindowRef window_ref(void); // useless with cocoa GL windows
224 void set_key_window(void);
225 // OS X doesn't have per window icons
226 static void set_default_icons(const Fl_RGB_Image*[], int) {};
227 void set_icons() {};
228 int set_cursor(Fl_Cursor);
229 int set_cursor(const Fl_RGB_Image*, int, int);
230 static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
231 static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
232 static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
233 static void *get_carbon_function(const char *name);
234 static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen
235 static int next_marked_length; // next length of marked text after current marked text will have been replaced
236 static int insertion_point_location(int *px, int *py, int *pheight); // computes window coordinates & height of insertion point
237 static const int CoreText_threshold; // Mac OS version from which the Core Text API is used to display text
238 static Fl_Fontdesc* calc_fl_fonts(void); // computes the fl_fonts global variable
239 static int dnd(int use_selection); // call Fl_X::dnd(1) to support text dragging
240 static int calc_mac_os_version(void); // computes the fl_mac_os_version global variable
241 static void clip_to_rounded_corners(CGContextRef gc, int w, int h);
242 static void *get_titlebar_layer(Fl_Window *win);
243 static void draw_layer_to_context(void *layer, CGContextRef ctxt, int w, int h);
244private:
245#if FLTK_ABI_VERSION >= 10304
246 CGRect* subRect_; // makes sure subwindow remains inside its parent window
247 // stores 3 binary flags: whether window is mapped to retina display; whether resolution just changed;
248 // whether window is OpenGL and is currently being resized.
249 unsigned mapped_to_retina_;
250#else
251 bool subwindow; // for ABI compatibility, useless with true subwindows
252#endif
253};
254
255extern Window fl_window;
256
257#endif // FL_LIBRARY || FL_INTERNALS
258
259typedef CGImageRef Fl_Bitmask;
260
261extern CGContextRef fl_gc;
262
263extern Window fl_xid(const Fl_Window*);
264extern Fl_Window* fl_find(Window xid);
265void fl_clip_region(Fl_Region);
266
267extern Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
268extern Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
269extern void fl_delete_bitmask(Fl_Bitmask bm);
270extern Fl_Offscreen fl_create_offscreen(int w, int h);
271extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
272extern void fl_delete_offscreen(Fl_Offscreen gWorld);
273extern void fl_begin_offscreen(Fl_Offscreen gWorld);
274extern void fl_end_offscreen();
275
276extern int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
277extern void fl_open_display();
278
279#endif // FL_DOXYGEN
293extern void fl_open_callback(void (*cb)(const char *));
294
303extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
304
307extern int fl_mac_os_version;
308
315extern int fl_mac_quit_early;
316
319extern class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
320
321struct Fl_Menu_Item;
322
324public:
326 static const char *about;
331 static const char *print;
333 static const char *services;
335 static const char *hide;
337 static const char *hide_others;
339 static const char *show;
341 static const char *quit;
342 static void custom_application_menu_items(const Fl_Menu_Item *m);
343};
344
347//
348// End of "$Id$".
349//
350
Fl_Cursor
The following constants define the mouse cursors that are available in FLTK.
Definition Enumerations.H:1046
Fl_Widget, Fl_Label classes .
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 .
Mac OS-specific class allowing to customize and localize the application menu.
Definition mac.H:323
static void custom_application_menu_items(const Fl_Menu_Item *m)
Adds custom menu item(s) to the application menu of the system menu bar.
Definition Fl_Sys_Menu_Bar.mm:526
static const char * about
Localizable text for the "About xxx" application menu item.
Definition mac.H:326
static const char * quit
Localizable text for the "Quit xxx" application menu item.
Definition mac.H:341
static const char * hide
Localizable text for the "Hide xxx" application menu item.
Definition mac.H:335
static const char * print
Localizable text for the "Print Front Window" application menu item.
Definition mac.H:331
static const char * services
Localizable text for the "Services" application menu item.
Definition mac.H:333
static const char * hide_others
Localizable text for the "Hide Others" application menu item.
Definition mac.H:337
static const char * show
Localizable text for the "Show All" application menu item.
Definition mac.H:339
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition Fl_Image.H:202
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:48
This widget produces an actual window.
Definition Fl_Window.H:57
unsigned char uchar
unsigned char
Definition fl_types.h:30
FL_EXPORT void gl_start()
Creates an OpenGL context.
Definition gl_start.cxx:56
void fl_begin_offscreen(Fl_Offscreen ctx)
Send all subsequent drawing commands to this offscreen buffer.
Definition Fl_Double_Window.cxx:345
Fl_Offscreen fl_create_offscreen(int w, int h)
Creation of an offscreen graphics buffer.
Definition Fl_Double_Window.cxx:287
Fl_Region fl_clip_region()
Returns the current clipping region.
Definition fl_draw.H:140
void fl_delete_offscreen(Fl_Offscreen ctx)
Deletion of an offscreen graphics buffer.
Definition Fl_Double_Window.cxx:328
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:94
void fl_end_offscreen()
Quit sending drawing commands to the current offscreen buffer.
Definition Fl_Double_Window.cxx:363
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:208
int fl_mac_quit_early
Determines whether cmd-Q or the "Quit xxx" item of application menu terminates the app or only the ev...
class Fl_Sys_Menu_Bar * fl_sys_menu_bar
The system menu bar.
Definition Fl_Sys_Menu_Bar.mm:50
Definition Fl_Font.H:86
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:112