summaryrefslogtreecommitdiff
path: root/FL/mac.H
blob: 6b204db2c8ba375c2225f8841215a62e3ae57d56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//
// "$Id$"
//
// Mac header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2009 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//

// Do not directly include this file, instead use <FL/x.H>.  It will
// include this file if "__APPLE__" is defined.  This is to encourage
// portability of even the system-specific code...
#ifndef FL_DOXYGEN

#if !defined(Fl_X_H)
#  error "Never use <FL/mac.H> directly; include <FL/x.H> instead."
#endif // !Fl_X_H

// Standard MacOS Carbon API includes...
#include <Carbon/Carbon.h>
#include <config.h>

#ifdef __APPLE_COCOA__
#ifndef MAC_OS_X_VERSION_10_3
#define MAC_OS_X_VERSION_10_3 1030
#endif
#ifndef MAC_OS_X_VERSION_10_4
#define MAC_OS_X_VERSION_10_4 1040
#endif
#ifndef MAC_OS_X_VERSION_10_5
#define MAC_OS_X_VERSION_10_5 1050
#endif
#ifndef MAC_OS_X_VERSION_10_6
#define MAC_OS_X_VERSION_10_6 1060
#endif
#ifndef MAC_OS_X_VERSION_MAX_ALLOWED
#define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#endif
#endif // __APPLE_COCOA__

#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
#if defined(__LP64__) && __LP64__
typedef double CGFloat;
#else
typedef float CGFloat;
#endif
#endif // CGFLOAT_DEFINED


// Now make some fixes to the headers...
#undef check			// Dunno where this comes from...

// Some random X equivalents
struct XPoint { int x, y; };
struct XRectangle {int x, y, width, height;};

#ifdef __APPLE_COCOA__

typedef void *Window; // this is really a pter to the subclass FLWindow of NSWindow
typedef struct flCocoaRegion {
  int count;
  CGRect *rects;
} *Fl_Region;  // a region is the union of a series of rectangles
extern CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);

inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
  Fl_Region R = (Fl_Region)malloc(sizeof(*R));
  R->count = 1;
  R->rects = (CGRect *)malloc(sizeof(CGRect));
  *(R->rects) = fl_cgrectmake_cocoa(x, y, w, h);
  return R;
}
inline void XDestroyRegion(Fl_Region r) {
  if(r) {
	free(r->rects);
	free(r);
	}
}
extern void *fl_default_cursor;
extern void *fl_system_menu;
typedef CGContextRef Fl_Offscreen;
typedef CGImageRef Fl_Bitmask;

#else

typedef WindowRef Window;
typedef RgnHandle Fl_Region;
inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
  Fl_Region R = NewRgn();
  SetRectRgn(R, x, y, x+w, y+h);
  return R;
}
inline void XDestroyRegion(Fl_Region r) {
  DisposeRgn(r);
}
extern CursHandle fl_default_cursor;
extern Handle fl_system_menu;
typedef GWorldPtr Fl_Offscreen;
typedef GWorldPtr Fl_Bitmask; // Carbon requires a 1-bit GWorld instead of a BitMap

#endif

void fl_clip_region(Fl_Region);

#  include "Fl_Window.H"

// This object contains all mac-specific stuff about a window:
// WARNING: this object is highly subject to change!
class Fl_X 
{
public:
  Window xid;              // Cocoa: FLWindow* ; Carbon: WindowRef
  Fl_Offscreen other_xid;  // pointer for offscreen bitmaps (doublebuffer)
  Fl_Window *w;            // FLTK window for 
  Fl_Region region;
  Fl_Region subRegion;     // region for this specific subwindow
  Fl_X *next;              // linked tree to support subwindows
  Fl_X *xidChildren, *xidNext; // more subwindow tree
  int wait_for_expose;
#ifdef __APPLE_COCOA__
  void *cursor;			  // is really NSCursor*
#else
  CursHandle cursor;
#endif
  static Fl_X* first;
  static Fl_X* i(const Fl_Window* w) {return w->i;}
  static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&);
  static void make(Fl_Window*);
  void flush();
  // Quartz additions:
  CGContextRef gc;                 // graphics context (NULL when using QD)
  static void q_fill_context();    // fill a Quartz context with current FLTK state
  static void q_clear_clipping();  // remove all clipping from a Quartz context
  static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
  static void q_begin_image(CGRect&, int x, int y, int w, int h);
  static void q_end_image();
};

#ifdef __APPLE_COCOA__
extern void MacDestroyWindow(Fl_Window*,void *);
extern void MacMapWindow(Fl_Window*,void *);
extern void MacUnmapWindow(Fl_Window*,void *);
extern WindowRef MACwindowRef(Fl_Window *w);
extern Fl_Region MacRectRegionIntersect(Fl_Region current, int x,int y,int w, int h);
extern void MacCollapseWindow(Window w);
#else
extern void MacDestroyWindow(Fl_Window*,WindowPtr);
extern void MacMapWindow(Fl_Window*,WindowPtr);
extern void MacUnmapWindow(Fl_Window*,WindowPtr);
#endif

extern int MacUnlinkWindow(Fl_X*,Fl_X*start=0L);

inline Window fl_xid(const Fl_Window*w) 
{
  return Fl_X::i(w)->xid;
}

extern struct Fl_XMap {
  RGBColor rgb;
  ulong pen;
} *fl_current_xmap;

extern FL_EXPORT void *fl_display;
extern FL_EXPORT Window fl_window;
extern FL_EXPORT CGContextRef fl_gc;
extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;


extern Fl_Offscreen fl_create_offscreen(int w, int h);
extern void fl_copy_offscreen(int x,int y,int w,int h, Fl_Offscreen gWorld, int srcx,int srcy);
extern void fl_delete_offscreen(Fl_Offscreen gWorld);
extern void fl_begin_offscreen(Fl_Offscreen gWorld);
extern void fl_end_offscreen();


extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);

extern void fl_open_display();

// Register a function for opening files via the finder...
extern void fl_open_callback(void (*cb)(const char *));

extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
#endif // FL_DOXYGEN

#if defined(__APPLE_COCOA__) || defined(FL_DOXYGEN)
/** \defgroup group_macosx Mac OS X-specific functions
 @{ */

/** 
 * \brief Mac OS X: attaches a callback to the "About myprog" item of the system application menu.
 * \note  #include <FL/x.H>
 *
 * \param cb   a callback that will be called by "About myprog" menu item
 *		   with NULL 1st argument.
 * \param user_data   a pointer transmitted as 2nd argument to the callback.
 * \param shortcut    optional shortcut to attach to the "About myprog" menu item (e.g., FL_META+'a')
 */
extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0);
/** @} */
#endif

//
// End of "$Id$".
//