NTK 1.3.0
mac.H
1//
2// "$Id: mac.H 8657 2011-05-12 11:50:43Z 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; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28// Do not directly include this file, instead use <FL/x.H>. It will
29// include this file if "__APPLE__" is defined. This is to encourage
30// portability of even the system-specific code...
31#ifndef FL_DOXYGEN
32
33#if !defined(Fl_X_H)
34# error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
35#endif // !Fl_X_H
36#include <FL/Fl_Widget.H>
37
38typedef void* Window; // this is really a pointer to the subclass FLWindow of NSWindow
39typedef void* Fl_Offscreen; // this is really a CGContextRef
40typedef void* Fl_Bitmask; // this is really a CGImageRef
41
42#include <AvailabilityMacros.h>
43#ifndef MAC_OS_X_VERSION_10_3
44#define MAC_OS_X_VERSION_10_3 1030
45#endif
46#ifndef MAC_OS_X_VERSION_10_4
47#define MAC_OS_X_VERSION_10_4 1040
48#endif
49#ifndef MAC_OS_X_VERSION_10_5
50#define MAC_OS_X_VERSION_10_5 1050
51#endif
52#ifndef MAC_OS_X_VERSION_10_6
53#define MAC_OS_X_VERSION_10_6 1060
54#endif
55
56#if !(defined(FL_LIBRARY) || defined(FL_INTERNALS)) // this part is used when compiling an application program
57
58typedef void* Fl_Region;
59typedef void* Fl_CGContextRef;
60typedef void* Fl_PMPrintSettings;
61typedef void* Fl_PMPageFormat;
62typedef void* Fl_PMPrintSession;
63
64#else // this part must be compiled when building the FLTK libraries
65
66// Standard MacOS C/C++ includes...
67#include <ApplicationServices/ApplicationServices.h>
68#undef check // because of Fl::check()
69
70typedef CGContextRef Fl_CGContextRef;
71typedef PMPrintSettings Fl_PMPrintSettings;
72typedef PMPageFormat Fl_PMPageFormat;
73typedef PMPrintSession Fl_PMPrintSession;
74
75typedef struct flCocoaRegion {
76 int count;
77 CGRect *rects;
78} *Fl_Region; // a region is the union of a series of rectangles
79
80# include "Fl_Window.H"
81
82// Some random X equivalents
83struct XPoint { int x, y; };
84struct XRectangle {int x, y, width, height;};
85#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
86#if defined(__LP64__) && __LP64__
87typedef double CGFloat;
88#else
89typedef float CGFloat;
90#endif
91#endif // CGFLOAT_DEFINED
92
93extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
94inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
95 Fl_Region R = (Fl_Region)malloc(sizeof(*R));
96 R->count = 1;
97 R->rects = (CGRect *)malloc(sizeof(CGRect));
98 *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
99 return R;
100}
101inline void XDestroyRegion(Fl_Region r) {
102 if(r) {
103 free(r->rects);
104 free(r);
105 }
106}
107extern void *fl_system_menu;
108extern void *fl_default_cursor;
109
110// This object contains all mac-specific stuff about a window:
111// WARNING: this object is highly subject to change!
112class Fl_X {
113
114public:
115 Window xid; // pointer to the Cocoa window object (FLWindow*)
116 Fl_Offscreen other_xid; // pointer for offscreen bitmaps (overlay window)
117 Fl_Window *w; // FLTK window for
118 Fl_Region region;
119 Fl_Region subRegion; // region for this specific subwindow
120 Fl_X *next; // linked tree to support subwindows
121 Fl_X *xidChildren, *xidNext; // more subwindow tree
122 int wait_for_expose;
123 void *cursor; // is really NSCursor*
124 static Fl_X* first;
125 static Fl_X* i(const Fl_Window* w) {return w->i;}
126 static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
127 static void make(Fl_Window*);
128 void flush();
129 // Quartz additions:
130 CGContextRef gc; // graphics context (NULL when using QD)
131 static void q_fill_context(); // fill a Quartz context with current FLTK state
132 static void q_clear_clipping(); // remove all clipping from a Quartz context
133 static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
134 static void q_begin_image(CGRect&, int x, int y, int w, int h);
135 static void q_end_image();
136 // Cocoa additions
137 void destroy(void);
138 void map(void);
139 void unmap(void);
140 int unlink(Fl_X* start = NULL);
141 void collapse(void);
142 WindowRef window_ref(void);
143 void set_key_window(void);
144 void set_cursor(Fl_Cursor);
145 static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
146 static unsigned char *bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
147 static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h);
148 static CGContextRef watch_cursor_image(void);
149 static CGContextRef help_cursor_image(void);
150 static CGContextRef nesw_cursor_image(void);
151 static CGContextRef nwse_cursor_image(void);
152 static CGContextRef none_cursor_image(void);
153 static void *get_carbon_function(const char *name);
154private:
155 static void relink(Fl_Window*, Fl_Window*);
156 bool subwindow;
157};
158
159extern struct Fl_XMap {
160 RGBColor rgb;
161 ulong pen;
162} *fl_current_xmap;
163extern FL_EXPORT Window fl_window;
164
165#endif // FL_LIBRARY || FL_INTERNALS
166
167extern FL_EXPORT Fl_CGContextRef fl_gc;
168extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
169
170extern Window fl_xid(const Fl_Window*);
171void fl_clip_region(Fl_Region);
172
173extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
174extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
175extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
176extern Fl_Offscreen fl_create_offscreen(int w, int h);
177extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
178extern void fl_delete_offscreen(Fl_Offscreen gWorld);
179extern void fl_begin_offscreen(Fl_Offscreen gWorld);
180extern void fl_end_offscreen();
181
182extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
183extern void fl_open_display();
184
185#endif // FL_DOXYGEN
186
190
195extern void fl_open_callback(void (*cb)(const char *));
196
205extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
206
209extern int fl_mac_os_version;
210
212public:
214 static const char *about;
219 static const char *print;
221 static const char *services;
223 static const char *hide;
225 static const char *hide_others;
227 static const char *show;
229 static const char *quit;
230};
231
233
234//
235// End of "$Id: mac.H 8657 2011-05-12 11:50:43Z manolo $".
236//
237
Fl_Cursor
The following constants define the mouse cursors that are available in FLTK.
Definition Enumerations.H:879
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:60
Mac OS-specific class allowing to localize the application menu.
Definition mac.H:211
static const char * about
Localizable text for the "About xxx" application menu item.
Definition mac.H:214
static const char * quit
Localizable text for the "Quit xxx" application menu item.
Definition mac.H:229
static const char * hide
Localizable text for the "Hide xxx" application menu item.
Definition mac.H:223
static const char * print
Localizable text for the "Print Front Window" application menu item.
Definition mac.H:219
static const char * services
Localizable text for the "Services" application menu item.
Definition mac.H:221
static const char * hide_others
Localizable text for the "Hide Others" application menu item.
Definition mac.H:225
static const char * show
Localizable text for the "Show All" application menu item.
Definition mac.H:227
void shortcut(int i, int s)
Changes the shortcut of item i to n.
Definition Fl_Menu_.H:112
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
int h() const
Gets the widget height.
Definition Fl_Widget.H:298
void * user_data() const
Gets the user data for this widget.
Definition Fl_Widget.H:592
int w() const
Gets the widget width.
Definition Fl_Widget.H:293
This widget produces an actual window.
Definition Fl_Window.H:58
unsigned char uchar
unsigned char
Definition fl_types.h:39
unsigned long ulong
unsigned long
Definition fl_types.h:41
void fl_begin_offscreen(Fl_Offscreen ctx)
Send all subsequent drawing commands to this offscreen buffer.
Definition Fl_Double_Window.cxx:258
Fl_Offscreen fl_create_offscreen(int w, int h)
Creation of an offscreen graphics buffer.
Definition Fl_Double_Window.cxx:200
Fl_Region fl_clip_region()
Returns the current clipping region.
Definition fl_draw.H:149
void fl_delete_offscreen(Fl_Offscreen ctx)
Deletion of an offscreen graphics buffer.
Definition Fl_Double_Window.cxx:241
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:58
void fl_end_offscreen()
Quit sending drawing commands to the current offscreen buffer.
Definition Fl_Double_Window.cxx:276
void fl_open_callback(void(*cb)(const char *))
Register a function called for each file dropped onto an application icon.
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.