Browse Source

Moved OS X code base to the more moder Cocoa toolkit thanks to the awesome work of Manolo Gouy (STR #2221). This is a big one! I tested all test applications under 32-bit autoconf and Xcode, and a few apps under 64bit intel. No PPC testing was done. Please verify this patch if you have the machine!

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6951 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Matthias Melcher 16 years ago
parent
commit
b2cffc688e
  1. 2
      CHANGES
  2. 6
      CREDITS
  3. 8
      FL/Fl_Scroll.H
  4. 69
      FL/mac.H
  5. 1
      configh.in
  6. 3
      configure.in
  7. 4484
      ide/Xcode3.1/FLTK.xcodeproj/project.pbxproj
  8. 4
      ide/Xcode3.1/plists/tabs-Info.plist
  9. 6
      makeinclude.in
  10. 52
      src/Fl.cxx
  11. 4
      src/Fl_Bitmap.cxx
  12. 3
      src/Fl_Font.H
  13. 62
      src/Fl_Gl_Choice.cxx
  14. 29
      src/Fl_Gl_Window.cxx
  15. 586
      src/Fl_Input.cxx
  16. 183
      src/Fl_Sys_Menu_Bar.cxx
  17. 5
      src/Fl_Window.cxx
  18. 4
      src/Fl_Window_iconize.cxx
  19. 7
      src/Fl_arg.cxx
  20. 3105
      src/Fl_cocoa.mm
  21. 12
      src/Fl_compose.cxx
  22. 18
      src/Fl_grab.cxx
  23. 1
      src/cgdebug.h
  24. 12
      src/fl_arci.cxx
  25. 3
      src/fl_ask.cxx
  26. 111
      src/fl_cursor.cxx
  27. 6
      src/fl_dnd_mac.cxx
  28. 199
      src/fl_font_mac.cxx
  29. 11
      src/fl_line_style.cxx
  30. 32
      src/fl_read_image_mac.cxx
  31. 202
      src/fl_rect.cxx
  32. 12
      src/fl_scroll_area.cxx
  33. 31
      src/fl_set_fonts_mac.cxx
  34. 37
      src/fl_vertex.cxx
  35. 111
      src/gl_draw.cxx
  36. 8
      src/makedepend
  37. 5
      src/screen_xywh.cxx
  38. 10
      test/browser.cxx
  39. 42
      test/color_chooser.cxx
  40. 46
      test/demo.cxx
  41. 4
      test/fullscreen.cxx

2
CHANGES

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
CHANGES IN FLTK 1.3.0
- Moved OS X code base to the more moder Cocoa toolkit thanks
to the awesome work of Manolo Gouy (STR #2221)
- Added template to generate new projects with Xcode.
- Managing all Widget flags in a single location now (STR #2161)
- Fixed all color related call to Fl_Color type (STR #2208)

6
CREDITS

@ -12,7 +12,7 @@ CORE DEVELOPERS @@ -12,7 +12,7 @@ CORE DEVELOPERS
The following people do the day-to-day development of FLTK:
Fabien Costantini (fabien67@users.sf.net)
Craig P. Earls
Craig P. Earls
Curtis Edwards (trilec@users.sourceforge.net)
Gustavo Hime (hime@users.sourceforge.net)
Talbot Hughes
@ -21,7 +21,7 @@ CORE DEVELOPERS @@ -21,7 +21,7 @@ CORE DEVELOPERS
James Dean Palmer (jamespalmer@users.sourceforge.net)
Vincent Penne (vincentp@users.sourceforge.net)
Bill Spitzak (spitzak@users.sourceforge.net)
Michael Sweet (easysw@users.sourceforge.net)
Michael Sweet (easysw@users.sourceforge.net)
Carl Thompson (clip@users.sourceforge.net)
Nafees Bin Zafar (nafees@users.sourceforge.net)
@ -47,7 +47,7 @@ OTHER CONTRIBUTORS @@ -47,7 +47,7 @@ OTHER CONTRIBUTORS
Alexander Rabi
James Roth
Albrecht Schlosser
Andrea Suatoni
Andrea Suatoni
Paul Sydney
Aaron Ucko
Emanuele Vicentini

8
FL/Fl_Scroll.H

@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
/**
This container widget lets you maneuver around a set of widgets much
larger than your window. If the child widgets are larger than the size
larger than your window. If the child widgets are larger than the size
of this object then scrollbars will appear so that you can scroll over
to them:
\image html Fl_Scroll.gif
@ -73,8 +73,8 @@ @@ -73,8 +73,8 @@
considered. The flags in hscrollbar however are ignored.
This widget can also be used to pan around a single child widget
"canvas". This child widget should be of your own class, with a
draw() method that draws the contents. The scrolling is done by
"canvas". This child widget should be of your own class, with a
draw() method that draws the contents. The scrolling is done by
changing the x() and y() of the widget, so this child
must use the x() and y() to position its drawing.
To speed up drawing it should test fl_push_clip().
@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
of individually-openable panels.
Fluid lets you create these, but you can only lay out objects that
fit inside the Fl_Scroll without scrolling. Be sure to leave
fit inside the Fl_Scroll without scrolling. Be sure to leave
space for the scrollbars, as Fluid won't show these either.
<I>You cannot use Fl_Window as a child of this since the

69
FL/mac.H

@ -36,16 +36,47 @@ @@ -36,16 +36,47 @@
// Standard MacOS Carbon API includes...
#include <Carbon/Carbon.h>
#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) && !__LP64__
typedef float CGFloat;
#endif
#include <config.h>
// Now make some fixes to the headers...
#undef check // Dunno where this comes from...
// Some random X equivalents
typedef WindowPtr Window;
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
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) = CGRectMake(x, y, w - 1, h - 1);
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;
void fl_clip_region(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);
@ -54,6 +85,14 @@ inline Fl_Region XRectangleRegion(int x, int y, int w, int h) { @@ -54,6 +85,14 @@ inline Fl_Region XRectangleRegion(int x, int y, int w, int h) {
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"
@ -62,15 +101,19 @@ inline void XDestroyRegion(Fl_Region r) { @@ -62,15 +101,19 @@ inline void XDestroyRegion(Fl_Region r) {
class Fl_X
{
public:
Window xid; // Mac WindowPtr
GWorldPtr other_xid; // pointer for offscreen bitmaps (doublebuffer)
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&);
@ -78,8 +121,10 @@ public: @@ -78,8 +121,10 @@ public:
void flush();
// Quartz additions:
CGContextRef gc; // graphics context (NULL when using QD)
#ifndef __APPLE_COCOA__
static ATSUTextLayout atsu_layout; // windows share a global font
static ATSUStyle atsu_style;
#endif
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
@ -87,18 +132,27 @@ public: @@ -87,18 +132,27 @@ public:
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);
extern void fl_open_callback(void (*cb)(const char *));
inline Window fl_xid(const Fl_Window*w)
{
return Fl_X::i(w)->xid;
}
extern CursHandle fl_default_cursor;
extern struct Fl_XMap {
RGBColor rgb;
ulong pen;
@ -107,10 +161,8 @@ extern struct Fl_XMap { @@ -107,10 +161,8 @@ extern struct Fl_XMap {
extern FL_EXPORT void *fl_display;
extern FL_EXPORT Window fl_window;
extern FL_EXPORT CGContextRef fl_gc;
extern FL_EXPORT Handle fl_system_menu;
extern FL_EXPORT class Fl_Sys_Menu_Bar *fl_sys_menu_bar;
typedef GWorldPtr Fl_Offscreen;
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);
@ -118,7 +170,6 @@ extern void fl_delete_offscreen(Fl_Offscreen gWorld); @@ -118,7 +170,6 @@ extern void fl_delete_offscreen(Fl_Offscreen gWorld);
extern void fl_begin_offscreen(Fl_Offscreen gWorld);
extern void fl_end_offscreen();
typedef GWorldPtr Fl_Bitmask; // Carbon requires a 1-bit GWorld instead of a BitMap
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);

1
configh.in

@ -128,6 +128,7 @@ @@ -128,6 +128,7 @@
#define USE_QUARTZ 0
#undef __APPLE_QUARTZ__
#undef __APPLE_COCOA__
#undef __APPLE_QD__

3
configure.in

@ -364,6 +364,7 @@ case $uname in @@ -364,6 +364,7 @@ case $uname in
# QD is not supported anymore since 1.3
AC_DEFINE(USE_QUARTZ, 1)
AC_DEFINE(__APPLE_QUARTZ__)
AC_DEFINE(__APPLE_COCOA__)
;;
esac
@ -828,7 +829,7 @@ case $uname_GUI in @@ -828,7 +829,7 @@ case $uname_GUI in
Darwin*)
# MacOS X uses Carbon for graphics...
LIBS="$LIBS -framework Carbon -framework ApplicationServices"
LIBS="$LIBS -framework Carbon -framework Cocoa -framework ApplicationServices"
if test x$have_pthread = xyes; then
AC_DEFINE(HAVE_PTHREAD)

4484
ide/Xcode3.1/FLTK.xcodeproj/project.pbxproj

File diff suppressed because it is too large Load Diff

4
ide/Xcode3.1/plists/tabs-Info.plist

@ -7,13 +7,13 @@ @@ -7,13 +7,13 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.tabs</string>
<string>org.fltk.table</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<string>FLTK</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>

6
makeinclude.in

@ -152,7 +152,11 @@ UNINSTALL_DESKTOP = @UNINSTALL_DESKTOP@ @@ -152,7 +152,11 @@ UNINSTALL_DESKTOP = @UNINSTALL_DESKTOP@
.cxx.o:
echo Compiling $<...
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -c $< -o $@
@if [ $< = Fl.cxx ]; then \
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -x objective-c++ -c $< -o $@; \
else \
$(CXX) -I.. $(ARCHFLAGS) @PNGINC@ @JPEGINC@ @ZLIBINC@ $(CXXFLAGS) -c $< -o $@; \
fi
.man.0 .man.1 .man.3 .man.6:
echo Formatting $<...

52
src/Fl.cxx

@ -40,6 +40,10 @@ @@ -40,6 +40,10 @@
#include <stdlib.h>
#include "flstring.h"
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
#import <Cocoa/Cocoa.h>
#endif
#ifdef DEBUG
# include <stdio.h>
#endif // DEBUG
@ -406,10 +410,17 @@ double Fl::wait(double time_to_wait) { @@ -406,10 +410,17 @@ double Fl::wait(double time_to_wait) {
// the idle function may turn off idle, we can then wait:
if (idle) time_to_wait = 0.0;
}
#ifdef __APPLE_COCOA__
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
flush();
if (idle && !in_idle) // 'idle' may have been set within flush()
time_to_wait = 0.0;
return fl_wait(time_to_wait);
double retval = fl_wait(time_to_wait);
#ifdef __APPLE_COCOA__
[pool release];
#endif
return retval;
#else
@ -586,12 +597,13 @@ Fl_Window* fl_find(Window xid) { @@ -586,12 +597,13 @@ Fl_Window* fl_find(Window xid) {
Fl_X *window;
for (Fl_X **pp = &Fl_X::first; (window = *pp); pp = &window->next)
#if defined(WIN32) || defined(USE_X11)
if (window->xid == xid) {
if (window->xid == xid)
#elif defined(__APPLE_QUARTZ__)
if (window->xid == xid && !window->w->window()) {
if (window->xid == xid && !window->w->window())
#else
# error unsupported platform
#endif // __APPLE__
{
if (window != Fl_X::first && !Fl::modal()) {
// make this window be first to speed up searches
// this is not done if modal is true to avoid messing up modal stack
@ -1278,7 +1290,11 @@ int Fl_Window::handle(int ev) @@ -1278,7 +1290,11 @@ int Fl_Window::handle(int ev)
#if defined(USE_X11) || defined(WIN32)
XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless
#elif defined(__APPLE_QUARTZ__)
MacMapWindow(this, fl_xid(this));
#ifdef __APPLE_COCOA__
MacMapWindow(this, i->xid);
#else
MacMapWindow(this, fl_xid(this));
#endif
#else
# error unsupported platform
#endif // __APPLE__
@ -1300,7 +1316,11 @@ int Fl_Window::handle(int ev) @@ -1300,7 +1316,11 @@ int Fl_Window::handle(int ev)
#if defined(USE_X11) || defined(WIN32)
XUnmapWindow(fl_display, fl_xid(this));
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
MacUnmapWindow(this, i->xid);
#else
MacUnmapWindow(this, fl_xid(this));
#endif
#else
# error platform unsupported
#endif
@ -1453,10 +1473,22 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) { @@ -1453,10 +1473,22 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
CombineRgn(i->region, i->region, R, RGN_OR);
XDestroyRegion(R);
#elif defined(__APPLE_QUARTZ__)
Fl_Region R = NewRgn();
SetRectRgn(R, X, Y, X+W, Y+H);
UnionRgn(R, i->region, i->region);
DisposeRgn(R);
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(X,Y,W - 1,H - 1);
int j;//don't add a rectangle totally inside the Fl_Region
for(j = 0; j < i->region->count; j++) {
if(CGRectContainsRect(i->region->rects[j], arg)) break;
}
if( j >= i->region->count) {
i->region->rects = (CGRect*)realloc(i->region->rects, (++(i->region->count)) * sizeof(CGRect));
i->region->rects[i->region->count - 1] = arg;
}
#else
Fl_Region R = NewRgn();
SetRectRgn(R, X, Y, X+W, Y+H);
UnionRgn(R, i->region, i->region);
DisposeRgn(R);
#endif
#else
# error unsupported platform
#endif
@ -1480,8 +1512,12 @@ void Fl_Window::flush() { @@ -1480,8 +1512,12 @@ void Fl_Window::flush() {
#ifdef WIN32
# include "Fl_win32.cxx"
#elif defined(__APPLE__)
#ifdef __APPLE_COCOA__
# include "Fl_cocoa.mm"
#else
# include "Fl_mac.cxx"
#endif
#endif
//
// The following methods allow callbacks to schedule the deletion of

4
src/Fl_Bitmap.cxx

@ -325,7 +325,11 @@ Fl_Bitmap::~Fl_Bitmap() { @@ -325,7 +325,11 @@ Fl_Bitmap::~Fl_Bitmap() {
void Fl_Bitmap::uncache() {
if (id) {
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
fl_delete_bitmask((Fl_Bitmask)id);
#else
fl_delete_bitmask((Fl_Offscreen)id);
#endif
id = 0;
}
}

3
src/Fl_Font.H

@ -67,6 +67,9 @@ public: @@ -67,6 +67,9 @@ public:
# elif defined(__APPLE_QUARTZ__)
FL_EXPORT Fl_Font_Descriptor(const char* fontname, Fl_Fontsize size);
ATSUTextLayout layout;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
CTFontRef fontref;
#endif
ATSUStyle style;
short ascent, descent, q_width;
// short width[256];

62
src/Fl_Gl_Choice.cxx

@ -295,21 +295,35 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay @@ -295,21 +295,35 @@ GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int lay
}
# elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context, shared_ctx = 0;
if (context_list && nContext) shared_ctx = context_list[0];
context = aglCreateContext( g->pixelformat, shared_ctx);
if (!context) return 0;
add_context((GLContext)context);
if ( window->parent() ) {
Rect wrect; GetWindowPortBounds( fl_xid(window), &wrect );
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
aglEnable( (GLContext)context, AGL_BUFFER_RECT );
}
aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
return (context);
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
GLContext fl_create_gl_context(Fl_Window* window, const Fl_Gl_Choice* g, int layer) {
GLContext context, shared_ctx = 0;
if (context_list && nContext) shared_ctx = context_list[0];
context = aglCreateContext( g->pixelformat, shared_ctx);
if (!context) return 0;
add_context((GLContext)context);
if ( window->parent() ) {
#ifdef __APPLE_COCOA__
int H = window->window()->h();
GLint rect[] = { window->x(), H-window->h()-window->y(), window->w(), window->h() };
#else
Rect wrect;
GetWindowPortBounds( fl_xid(window), &wrect );
GLint rect[] = { window->x(), wrect.bottom-window->h()-window->y(), window->w(), window->h() };
#endif
aglSetInteger( (GLContext)context, AGL_BUFFER_RECT, rect );
aglEnable( (GLContext)context, AGL_BUFFER_RECT );
}
#if defined(__APPLE_COCOA__)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
aglSetWindowRef(context, MACwindowRef(window) );
#else
aglSetDrawable( context, GetWindowPort( MACwindowRef(window) ) );
#endif
#else
aglSetDrawable( context, GetWindowPort( fl_xid(window) ) );
#endif
return (context);
}
# else
# error unsupported platform
@ -329,12 +343,26 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) { @@ -329,12 +343,26 @@ void fl_set_gl_context(Fl_Window* w, GLContext context) {
# elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
if ( w->parent() ) { //: resize our GL buffer rectangle
Rect wrect; GetWindowPortBounds( fl_xid(w), &wrect );
#ifdef __APPLE_COCOA__
int H = w->window()->h();
GLint rect[] = { w->x(), H-w->h()-w->y(), w->w(), w->h() };
#else
Rect wrect;
GetWindowPortBounds( fl_xid(w), &wrect );
GLint rect[] = { w->x(), wrect.bottom-w->h()-w->y(), w->w(), w->h() };
#endif
aglSetInteger( context, AGL_BUFFER_RECT, rect );
aglEnable( context, AGL_BUFFER_RECT );
}
aglSetDrawable(context, GetWindowPort( fl_xid(w) ) );
#if defined(__APPLE_COCOA__)
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
aglSetWindowRef(context, MACwindowRef(w) );
#else
aglSetDrawable( context, GetWindowPort( MACwindowRef(w) ) );
#endif
#else
aglSetDrawable( context, GetWindowPort( fl_xid(w) ) );
#endif
aglSetCurrentContext(context);
# else
# error unsupported platform

29
src/Fl_Gl_Window.cxx

@ -66,6 +66,9 @@ int Fl_Gl_Window::can_do(int a, const int *b) { @@ -66,6 +66,9 @@ int Fl_Gl_Window::can_do(int a, const int *b) {
}
void Fl_Gl_Window::show() {
#if defined(__APPLE__) && defined(__APPLE_COCOA__)
int need_redraw = 0;
#endif
if (!shown()) {
if (!g) {
g = Fl_Gl_Choice::find(mode_,alist);
@ -83,12 +86,19 @@ void Fl_Gl_Window::show() { @@ -83,12 +86,19 @@ void Fl_Gl_Window::show() {
#if !defined(WIN32) && !defined(__APPLE__)
Fl_X::make_xid(this, g->vis, g->colormap);
if (overlay && overlay != this) ((Fl_Gl_Window*)overlay)->show();
#elif defined(__APPLE__) && defined(__APPLE_COCOA__)
extern void MACsetContainsGLsubwindow(Fl_Window *);
if( ! parent() ) need_redraw=1;
else MACsetContainsGLsubwindow( window() );
#endif
}
Fl_Window::show();
#ifdef __APPLE__
set_visible();
#ifdef __APPLE_COCOA__
if(need_redraw) redraw();//necessary only after creation of a top-level GL window
#endif
#endif /* __APPLE__ */
}
@ -154,6 +164,7 @@ int Fl_Gl_Window::mode(int m, const int *a) { @@ -154,6 +164,7 @@ int Fl_Gl_Window::mode(int m, const int *a) {
being called and can also be used to implement feedback and/or
selection within the handle() method.
*/
void Fl_Gl_Window::make_current() {
// puts("Fl_Gl_Window::make_current()");
// printf("make_current: context_=%p\n", context_);
@ -237,6 +248,15 @@ void Fl_Gl_Window::swap_buffers() { @@ -237,6 +248,15 @@ void Fl_Gl_Window::swap_buffers() {
# endif
#elif defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
#ifdef __APPLE_COCOA__
if(overlay != NULL) {
//aglSwapBuffers does not work well with overlays under cocoa
glReadBuffer(GL_BACK);
glDrawBuffer(GL_FRONT);
glCopyPixels(0,0,w(),h(),GL_COLOR);
}
else
#endif
aglSwapBuffers((AGLContext)context_);
#else
# error unsupported platform
@ -248,6 +268,7 @@ uchar fl_overlay; // changes how fl_color() works @@ -248,6 +268,7 @@ uchar fl_overlay; // changes how fl_color() works
int fl_overlay_depth = 0;
#endif
void Fl_Gl_Window::flush() {
uchar save_valid = valid_f_ & 1;
#if HAVE_GL_OVERLAY && defined(WIN32)
@ -257,13 +278,19 @@ void Fl_Gl_Window::flush() { @@ -257,13 +278,19 @@ void Fl_Gl_Window::flush() {
#if defined(__APPLE_QUARTZ__)
// warning: the Quartz version should probably use Core GL (CGL) instead of AGL
//: clear previous clipping in this shared port
#if ! __LP64__
#ifdef __APPLE_COCOA__
GrafPtr port = GetWindowPort( MACwindowRef(this) );
#else
GrafPtr port = GetWindowPort( fl_xid(this) );
#endif
Rect rect; SetRect( &rect, 0, 0, 0x7fff, 0x7fff );
GrafPtr old; GetPort( &old );
SetPort( port );
ClipRect( &rect );
SetPort( old );
#endif
#endif
#if HAVE_GL_OVERLAY && defined(WIN32)
@ -327,7 +354,7 @@ void Fl_Gl_Window::flush() { @@ -327,7 +354,7 @@ void Fl_Gl_Window::flush() {
// don't draw if only the overlay is damaged:
if (damage() != FL_DAMAGE_OVERLAY || !save_valid) draw();
swap_buffers();
swap_buffers();
} else { // SWAP_TYPE == UNDEFINED

586
src/Fl_Input.cxx

@ -108,7 +108,7 @@ int Fl_Input::handle_key() { @@ -108,7 +108,7 @@ int Fl_Input::handle_key() {
// the following line is not a true memory leak because the array is only
// allocated once if required, and automatically freed when the program quits
char *chars = (char*)malloc(len+1);
legal_fp_chars = chars;
legal_fp_chars = chars;
strcpy(chars, standard_fp_chars);
if (lc) {
if (lc->decimal_point) strcat(chars, lc->decimal_point);
@ -129,8 +129,8 @@ int Fl_Input::handle_key() { @@ -129,8 +129,8 @@ int Fl_Input::handle_key() {
&& (ascii>='A'&& ascii<='F' || ascii>='a'&& ascii<='f'))
|| input_type()==FL_FLOAT_INPUT && ascii && strchr(legal_fp_chars, ascii))
{
if (readonly()) fl_beep();
else replace(position(), mark(), &ascii, 1);
if (readonly()) fl_beep();
else replace(position(), mark(), &ascii, 1);
}
return 1;
}
@ -138,342 +138,342 @@ int Fl_Input::handle_key() { @@ -138,342 +138,342 @@ int Fl_Input::handle_key() {
if (del || Fl::event_length()) {
if (readonly()) fl_beep();
else replace(position(), del ? position()-del : mark(),
Fl::event_text(), Fl::event_length());
Fl::event_text(), Fl::event_length());
}
return 1;
}
unsigned int mods = Fl::event_state() & (FL_META|FL_CTRL|FL_ALT);
switch (Fl::event_key()) {
case FL_Insert:
if (Fl::event_state() & FL_CTRL) ascii = ctrl('C');
else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V');
break;
case FL_Delete:
case FL_Insert:
if (Fl::event_state() & FL_CTRL) ascii = ctrl('C');
else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V');
break;
case FL_Delete:
#ifdef __APPLE__
if (mods==0 || mods==FL_CTRL) { // delete next char
ascii = ctrl('D');
} else if (mods==FL_ALT) { // delete next word
if (mark() != position()) return cut();
cut(position(), word_end(position()));
return 1;
} else if (mods==FL_META) { // delete to the end of the line
if (mark() != position()) return cut();
cut(position(), line_end(position()));
return 1;
} else return 1;
if (mods==0 || mods==FL_CTRL) { // delete next char
ascii = ctrl('D');
} else if (mods==FL_ALT) { // delete next word
if (mark() != position()) return cut();
cut(position(), word_end(position()));
return 1;
} else if (mods==FL_META) { // delete to the end of the line
if (mark() != position()) return cut();
cut(position(), line_end(position()));
return 1;
} else return 1;
#else
if (mods==0) {
ascii = ctrl('D');
} else if (mods==FL_SHIFT) {
ascii = ctrl('X');
} else return 1;
if (mods==0) {
ascii = ctrl('D');
} else if (mods==FL_SHIFT) {
ascii = ctrl('X');
} else return 1;
#endif
break;
case FL_Left:
break;
case FL_Left:
#ifdef __APPLE__
if (mods==0) { // char left
ascii = ctrl('B');
} else if (mods==FL_ALT) { // word left
shift_position(word_start(position()));
return 1;
} else if (mods==FL_CTRL || mods==FL_META) { // start of line
shift_position(line_start(position()));
return 1;
} else return 1;
if (mods==0) { // char left
ascii = ctrl('B');
} else if (mods==FL_ALT) { // word left
shift_position(word_start(position()));
return 1;
} else if (mods==FL_CTRL || mods==FL_META) { // start of line
shift_position(line_start(position()));
return 1;
} else return 1;
#else
if (mods==0) { // char left
ascii = ctrl('B');
} else if (mods==FL_CTRL) { // word left
shift_position(word_start(position()));
return 1;
} else return 1;
if (mods==0) { // char left
ascii = ctrl('B');
} else if (mods==FL_CTRL) { // word left
shift_position(word_start(position()));
return 1;
} else return 1;
#endif
break;
case FL_Right:
break;
case FL_Right:
#ifdef __APPLE__
if (mods==0) { // char right
ascii = ctrl('F');
} else if (mods==FL_ALT) { // word right
shift_position(word_end(position()));
return 1;
} else if (mods==FL_CTRL || mods==FL_META) { // end of line
shift_position(line_end(position()));
return 1;
} else return 1;
if (mods==0) { // char right
ascii = ctrl('F');
} else if (mods==FL_ALT) { // word right
shift_position(word_end(position()));
return 1;
} else if (mods==FL_CTRL || mods==FL_META) { // end of line
shift_position(line_end(position()));
return 1;
} else return 1;
#else
if (mods==0) { // char right
ascii = ctrl('F');
} else if (mods==FL_CTRL) { // word right
shift_position(word_end(position()));
return 1;
} else return 1;
if (mods==0) { // char right
ascii = ctrl('F');
} else if (mods==FL_CTRL) { // word right
shift_position(word_end(position()));
return 1;
} else return 1;
#endif // __APPLE__
break;
case FL_Page_Up:
break;
case FL_Page_Up:
#ifdef __APPLE__
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else return 1;
break;
#else
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
// fall through
ascii = ctrl('P');
} else return 1;
break;
#else
repeat_num = linesPerPage();
// fall through
#endif
case FL_Up:
case FL_Up:
#ifdef __APPLE__
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) { // scroll text down one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // line start and up
if (line_start(position())==position() && position()>0)
return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE;
else
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
} else if (mods==FL_META) { // start of document
shift_position(0);
return 1;
} else return 1;
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) { // scroll text down one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('P');
} else if (mods==FL_ALT) { // line start and up
if (line_start(position())==position() && position()>0)
return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE;
else
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
} else if (mods==FL_META) { // start of document
shift_position(0);
return 1;
} else return 1;
#else
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) { // scroll text down one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('P');
} else return 1;
if (mods==0) { // line up
ascii = ctrl('P');
} else if (mods==FL_CTRL) { // scroll text down one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('P');
} else return 1;
#endif
break;
case FL_Page_Down:
break;
case FL_Page_Down:
#ifdef __APPLE__
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else return 1;
break;
#else
if (mods==0) { // scroll text one page
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
// fall through
ascii = ctrl('N');
} else if (mods==FL_ALT) { // move cursor one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else return 1;
break;
#else
repeat_num = linesPerPage();
// fall through
#endif
case FL_Down:
case FL_Down:
#ifdef __APPLE__
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) {
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else if (mods==FL_ALT) { // line end and down
if (line_end(position())==position() && position()<size())
return shift_position(line_end(position()+1)) + NORMAL_INPUT_MOVE;
else
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
} else if (mods==FL_META) { // end of document
shift_position(size());
return 1;
} else return 1;
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) {
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
repeat_num = linesPerPage();
ascii = ctrl('N');
} else if (mods==FL_ALT) { // line end and down
if (line_end(position())==position() && position()<size())
return shift_position(line_end(position()+1)) + NORMAL_INPUT_MOVE;
else
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
} else if (mods==FL_META) { // end of document
shift_position(size());
return 1;
} else return 1;
#else
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) { // scroll text up one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('N');
} else return 1;
if (mods==0) { // line down
ascii = ctrl('N');
} else if (mods==FL_CTRL) { // scroll text up one line
// Fl_Input has no scroll control, so instead we move the cursor by one page
ascii = ctrl('N');
} else return 1;
#endif
break;
case FL_Home:
break;
case FL_Home:
#ifdef __APPLE__
if (mods==0) { // scroll display to the top
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(0);
return 1;
} else return 1;
if (mods==0) { // scroll display to the top
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(0);
return 1;
} else return 1;
#else
if (mods==0) {
ascii = ctrl('A');
} else if (mods==FL_CTRL) {
shift_position(0);
return 1;
}
if (mods==0) {
ascii = ctrl('A');
} else if (mods==FL_CTRL) {
shift_position(0);
return 1;
}
#endif
break;
case FL_End:
break;
case FL_End:
#ifdef __APPLE__
if (mods==0) { // scroll display to the bottom
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(size());
return 1;
} else return 1;
if (mods==0) { // scroll display to the bottom
// OS X scrolls the view, but does not move the cursor
// Fl_Input has no scroll control, so instead we move the cursor by one page
shift_position(size());
return 1;
} else return 1;
#else
if (mods==0) {
ascii = ctrl('E');
} else if (mods==FL_CTRL) {
shift_position(size());
return 1;
} else return 1;
if (mods==0) {
ascii = ctrl('E');
} else if (mods==FL_CTRL) {
shift_position(size());
return 1;
} else return 1;
#endif
break;
case FL_BackSpace:
break;
case FL_BackSpace:
#ifdef __APPLE__
if (mods==0 || mods==FL_CTRL) { // delete previous char
ascii = ctrl('H');
} else if (mods==FL_ALT) { // delete previous word
if (mark() != position()) return cut();
cut(word_start(position()), position());
return 1;
} else if (mods==FL_META) { // delete to the beginning of the line
if (mark() != position()) return cut();
cut(line_start(position()), position());
return 1;
} else return 1;
#else
if (mods==0 || mods==FL_CTRL) { // delete previous char
ascii = ctrl('H');
} else if (mods==FL_ALT) { // delete previous word
if (mark() != position()) return cut();
cut(word_start(position()), position());
return 1;
} else if (mods==FL_META) { // delete to the beginning of the line
if (mark() != position()) return cut();
cut(line_start(position()), position());
return 1;
} else return 1;
#else
ascii = ctrl('H');
#endif
break;
case FL_Enter:
case FL_KP_Enter:
if (when() & FL_WHEN_ENTER_KEY) {
position(size(), 0);
maybe_do_callback();
return 1;
} else if (input_type() == FL_MULTILINE_INPUT && !readonly())
return replace(position(), mark(), "\n", 1);
else
return 0; // reserved for shortcuts
case FL_Tab:
if (Fl::event_state(FL_CTRL|FL_SHIFT) || input_type()!=FL_MULTILINE_INPUT || readonly()) return 0;
return replace(position(), mark(), &ascii, 1);
break;
case FL_Enter:
case FL_KP_Enter:
if (when() & FL_WHEN_ENTER_KEY) {
position(size(), 0);
maybe_do_callback();
return 1;
} else if (input_type() == FL_MULTILINE_INPUT && !readonly())
return replace(position(), mark(), "\n", 1);
else
return 0; // reserved for shortcuts
case FL_Tab:
if (Fl::event_state(FL_CTRL|FL_SHIFT) || input_type()!=FL_MULTILINE_INPUT || readonly()) return 0;
return replace(position(), mark(), &ascii, 1);
#ifdef __APPLE__
case 'c' :
case 'v' :
case 'x' :
case 'z' :
// printf("'%c' (0x%02x) pressed with%s%s%s%s\n", ascii, ascii,
// Fl::event_state(FL_SHIFT) ? " FL_SHIFT" : "",
// Fl::event_state(FL_CTRL) ? " FL_CTRL" : "",
// Fl::event_state(FL_ALT) ? " FL_ALT" : "",
// Fl::event_state(FL_META) ? " FL_META" : "");
if (Fl::event_state(FL_META)) ascii -= 0x60;
// printf("using '%c' (0x%02x)...\n", ascii, ascii);
break;
case 'c' :
case 'v' :
case 'x' :
case 'z' :
// printf("'%c' (0x%02x) pressed with%s%s%s%s\n", ascii, ascii,
// Fl::event_state(FL_SHIFT) ? " FL_SHIFT" : "",
// Fl::event_state(FL_CTRL) ? " FL_CTRL" : "",
// Fl::event_state(FL_ALT) ? " FL_ALT" : "",
// Fl::event_state(FL_META) ? " FL_META" : "");
if (Fl::event_state(FL_META)) ascii -= 0x60;
// printf("using '%c' (0x%02x)...\n", ascii, ascii);
break;
#endif // __APPLE__
}
int i;
switch (ascii) {
case ctrl('A'): // go to the beginning of the current line
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
case ctrl('B'): // go one character backward
return shift_position(position()-1) + NORMAL_INPUT_MOVE;
case ctrl('C'): // copy
return copy(1);
case ctrl('D'): // cut the next character
case ctrl('?'):
if (readonly()) {
fl_beep();
return 1;
}
if (mark() != position()) return cut();
else return cut(1);
case ctrl('E'): // go to the end of the line
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
case ctrl('F'): // go to the next character
return shift_position(position()+1) + NORMAL_INPUT_MOVE;
case ctrl('H'): // cut the previous character
if (readonly()) {
fl_beep();
return 1;
}
if (mark() != position()) cut();
else cut(-1);
case ctrl('A'): // go to the beginning of the current line
return shift_position(line_start(position())) + NORMAL_INPUT_MOVE;
case ctrl('B'): // go one character backward
return shift_position(position()-1) + NORMAL_INPUT_MOVE;
case ctrl('C'): // copy
return copy(1);
case ctrl('D'): // cut the next character
case ctrl('?'):
if (readonly()) {
fl_beep();
return 1;
case ctrl('K'): // cut to the end of the line
if (readonly()) {
fl_beep();
return 1;
}
if (position()>=size()) return 0;
i = line_end(position());
if (i == position() && i < size()) i++;
cut(position(), i);
return copy_cuts();
case ctrl('N'): // go down one line
i = position();
if (line_end(i) >= size()) return NORMAL_INPUT_MOVE;
while (repeat_num--) {
i = line_end(i);
if (i >= size()) break;
i++;
}
shift_up_down_position(i);
}
if (mark() != position()) return cut();
else return cut(1);
case ctrl('E'): // go to the end of the line
return shift_position(line_end(position())) + NORMAL_INPUT_MOVE;
case ctrl('F'): // go to the next character
return shift_position(position()+1) + NORMAL_INPUT_MOVE;
case ctrl('H'): // cut the previous character
if (readonly()) {
fl_beep();
return 1;
case ctrl('P'): // go up one line
i = position();
if (!line_start(i)) return NORMAL_INPUT_MOVE;
while(repeat_num--) {
i = line_start(i);
if (!i) break;
i--;
}
shift_up_down_position(line_start(i));
}
if (mark() != position()) cut();
else cut(-1);
return 1;
case ctrl('K'): // cut to the end of the line
if (readonly()) {
fl_beep();
return 1;
case ctrl('U'): // clear the whole document?
if (readonly()) {
fl_beep();
return 1;
}
return cut(0, size());
case ctrl('V'): // paste text
case ctrl('Y'):
if (readonly()) {
fl_beep();
return 1;
}
Fl::paste(*this, 1);
}
if (position()>=size()) return 0;
i = line_end(position());
if (i == position() && i < size()) i++;
cut(position(), i);
return copy_cuts();
case ctrl('N'): // go down one line
i = position();
if (line_end(i) >= size()) return NORMAL_INPUT_MOVE;
while (repeat_num--) {
i = line_end(i);
if (i >= size()) break;
i++;
}
shift_up_down_position(i);
return 1;
case ctrl('P'): // go up one line
i = position();
if (!line_start(i)) return NORMAL_INPUT_MOVE;
while(repeat_num--) {
i = line_start(i);
if (!i) break;
i--;
}
shift_up_down_position(line_start(i));
return 1;
case ctrl('U'): // clear the whole document?
if (readonly()) {
fl_beep();
return 1;
case ctrl('X'): // cut the selected text
case ctrl('W'):
if (readonly()) {
fl_beep();
return 1;
}
copy(1);
return cut();
case ctrl('Z'): // undo
case ctrl('_'):
if (readonly()) {
fl_beep();
return 1;
}
return undo();
case ctrl('I'): // insert literal
case ctrl('J'):
case ctrl('L'):
case ctrl('M'):
if (readonly()) {
fl_beep();
return 1;
}
// insert a few selected control characters literally:
if (input_type() != FL_FLOAT_INPUT && input_type() != FL_INT_INPUT)
return replace(position(), mark(), &ascii, 1);
}
return cut(0, size());
case ctrl('V'): // paste text
case ctrl('Y'):
if (readonly()) {
fl_beep();
return 1;
}
Fl::paste(*this, 1);
return 1;
case ctrl('X'): // cut the selected text
case ctrl('W'):
if (readonly()) {
fl_beep();
return 1;
}
copy(1);
return cut();
case ctrl('Z'): // undo
case ctrl('_'):
if (readonly()) {
fl_beep();
return 1;
}
return undo();
case ctrl('I'): // insert literal
case ctrl('J'):
case ctrl('L'):
case ctrl('M'):
if (readonly()) {
fl_beep();
return 1;
}
// insert a few selected control characters literally:
if (input_type() != FL_FLOAT_INPUT && input_type() != FL_INT_INPUT)
return replace(position(), mark(), &ascii, 1);
}
return 0;

183
src/Fl_Sys_Menu_Bar.cxx

@ -61,6 +61,12 @@ @@ -61,6 +61,12 @@
#include "flstring.h"
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#ifdef __APPLE_COCOA__
extern void *MACMenuOrItemOperation(const char *operation, ...);
#define MenuHandle void *
#endif
typedef const Fl_Menu_Item *pFl_Menu_Item;
@ -69,7 +75,9 @@ typedef const Fl_Menu_Item *pFl_Menu_Item; @@ -69,7 +75,9 @@ typedef const Fl_Menu_Item *pFl_Menu_Item;
* Skip all '&' which would mark the shortcut in FLTK
* Skip all Mac control characters ('(', '<', ';', '^', '!' )
*/
static void catMenuText( const char *src, char *dst )
#ifndef __APPLE_COCOA__
static void catMenuText( const char *src, char *dst )
{
char c;
while ( *dst )
@ -88,6 +96,7 @@ static void catMenuText( const char *src, char *dst ) @@ -88,6 +96,7 @@ static void catMenuText( const char *src, char *dst )
* append a marker to identify the menu font style
* <B, I, U, O, and S
*/
static void catMenuFont( const Fl_Menu_Item *m, char *dst )
{
if ( !m->labeltype_ && !m->labelfont_ )
@ -122,7 +131,9 @@ enum { @@ -122,7 +131,9 @@ enum {
kMenuControlModifier = (1 << 2),
kMenuNoCommandModifier = (1 << 3)
};
*/
*/
#endif
static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
{
if ( !m->shortcut_ )
@ -135,6 +146,11 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) @@ -135,6 +146,11 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
if ( !isalnum( key ) )
return;
#ifdef __APPLE_COCOA__
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
MACMenuOrItemOperation("setKeyEquivalent", menuItem, key );
MACMenuOrItemOperation("setKeyEquivalentModifierMask", menuItem, m->shortcut_ );
#else
long macMod = kMenuNoCommandModifier;
if ( m->shortcut_ & FL_META ) macMod = kMenuNoModifiers;
if ( m->shortcut_ & FL_SHIFT || isupper(key) ) macMod |= kMenuShiftModifier;
@ -144,8 +160,10 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m ) @@ -144,8 +160,10 @@ static void setMenuShortcut( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
//SetMenuItemKeyGlyph( mh, miCnt, key );
SetItemCmd( mh, miCnt, toupper(key) );
SetMenuItemModifiers( mh, miCnt, macMod );
#endif
}
#if 0
// this function needs to be verified before we compile it back in.
static void catMenuShortcut( const Fl_Menu_Item *m, char *dst )
@ -166,16 +184,113 @@ static void catMenuShortcut( const Fl_Menu_Item *m, char *dst ) @@ -166,16 +184,113 @@ static void catMenuShortcut( const Fl_Menu_Item *m, char *dst )
}
#endif
static void setMenuFlags( MenuHandle mh, int miCnt, const Fl_Menu_Item *m )
{
if ( m->flags & FL_MENU_TOGGLE )
{
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 );
#ifdef __APPLE_COCOA__
void *menuItem = MACMenuOrItemOperation("itemAtIndex", mh, miCnt);
MACMenuOrItemOperation("setState", menuItem, m->flags & FL_MENU_VALUE );
#else
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x12 : 0 );
#endif
}
else if ( m->flags & FL_MENU_RADIO ) {
#ifndef __APPLE_COCOA__
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 );
#endif
}
}
#ifdef __APPLE_COCOA__
/**
* create a sub menu for a specific menu handle
*/
static void createSubMenu( void * mh, pFl_Menu_Item &mm )
{
void *submenu;
int miCnt, flags;
void *menuItem;
submenu = MACMenuOrItemOperation("initWithTitle", mm->text);
int cnt;
MACMenuOrItemOperation("numberOfItems", mh, &cnt);
cnt--;
menuItem = MACMenuOrItemOperation("itemAtIndex", mh, cnt);
MACMenuOrItemOperation("setSubmenu", menuItem, submenu);
if ( mm->flags & FL_MENU_INACTIVE ) {
MACMenuOrItemOperation("setEnabled", menuItem, 0);
}
mm++;
while ( mm->text )
{
MACMenuOrItemOperation("addNewItem", submenu, mm->text, mm->callback_, mm->user_data_, &miCnt);
setMenuFlags( submenu, miCnt, mm );
setMenuShortcut( submenu, miCnt, mm );
if ( mm->flags & FL_MENU_INACTIVE ) {
void *item = MACMenuOrItemOperation("itemAtIndex", submenu, miCnt);
MACMenuOrItemOperation("setEnabled", item, 0);
}
flags = mm->flags;
if ( mm->flags & FL_SUBMENU )
{
createSubMenu( submenu, mm );
}
else if ( mm->flags & FL_SUBMENU_POINTER )
{
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
createSubMenu( submenu, smm );
}
if ( flags & FL_MENU_DIVIDER ) {
MACMenuOrItemOperation("addSeparatorItem", submenu);
}
mm++;
}
}
/**
* create a system menu bar using the given list of menu structs
*
* \author Matthias Melcher
*
* @param m list of Fl_Menu_Item
*/
extern void *MACmainMenu(void);
void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
{
fl_open_display();
Fl_Menu_Bar::menu( m );
fl_sys_menu_bar = this;
const Fl_Menu_Item *mm = m;
for (;;)
{
if ( !mm || !mm->text )
break;
char visible = mm->visible() ? 1 : 0;
MACMenuOrItemOperation("addNewItem", MACmainMenu(), mm->text, NULL, NULL, NULL);
if ( mm->flags & FL_SUBMENU )
createSubMenu( MACmainMenu(), mm );
else if ( mm->flags & FL_SUBMENU_POINTER ) {
const Fl_Menu_Item *smm = (Fl_Menu_Item*)mm->user_data_;
createSubMenu( MACmainMenu(), smm );
}
if ( visible ) {
// InsertMenu( mh, 0 );
}
mm++;
}
else if ( m->flags & FL_MENU_RADIO )
SetItemMark( mh, miCnt, ( m->flags & FL_MENU_VALUE ) ? 0x13 : 0 );
}
#else
static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
{
if ( !m->flags )
@ -184,6 +299,7 @@ static void catMenuFlags( const Fl_Menu_Item *m, char *dst ) @@ -184,6 +299,7 @@ static void catMenuFlags( const Fl_Menu_Item *m, char *dst )
strcat( dst, "(" );
}
/**
* create a sub menu for a specific menu handle
*/
@ -276,6 +392,8 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m) @@ -276,6 +392,8 @@ void Fl_Sys_Menu_Bar::menu(const Fl_Menu_Item *m)
DrawMenuBar();
}
#endif //__APPLE_COCOA__
/*
const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) {
Fl_menu_Item *ret = Fl_Menu_Bar::picked( v );
@ -290,42 +408,31 @@ const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) { @@ -290,42 +408,31 @@ const Fl_Menu_Item* Fl_Sys_Menu_Bar::picked(const Fl_Menu_Item* v) {
*/
void Fl_Sys_Menu_Bar::draw() {
/* -- nothing to do, system should take care of this
draw_box();
if (!menu() || !menu()->text) return;
const Fl_Menu_Item* m;
int X = x()+6;
for (m=menu(); m->text; m = m->next()) {
int W = m->measure(0,this) + 16;
m->draw(X, y(), W, h(), this);
X += W;
}
*/
}
/*
int Fl_Menu_Bar::handle(int event) {
const Fl_Menu_Item* v;
if (menu() && menu()->text) switch (event) {
case FL_ENTER:
case FL_LEAVE:
return 1;
case FL_PUSH:
v = 0;
J1:
v = menu()->pulldown(x(), y(), w(), h(), v, this, 0, 1);
picked(v);
return 1;
case FL_SHORTCUT:
if (visible_r()) {
v = menu()->find_shortcut();
if (v && v->submenu()) goto J1;
}
return test_shortcut() != 0;
}
return 0;
}
*/
int Fl_Menu_Bar::handle(int event) {
const Fl_Menu_Item* v;
if (menu() && menu()->text) switch (event) {
case FL_ENTER:
case FL_LEAVE:
return 1;
case FL_PUSH:
v = 0;
J1:
v = menu()->pulldown(x(), y(), w(), h(), v, this, 0, 1);
picked(v);
return 1;
case FL_SHORTCUT:
if (visible_r()) {
v = menu()->find_shortcut();
if (v && v->submenu()) goto J1;
}
return test_shortcut() != 0;
}
return 0;
}
*/
#endif /* __APPLE__ */

5
src/Fl_Window.cxx

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
// equivalent (but totally different) crap for MSWindows is in Fl_win32.cxx
#include "config.h"
#include <FL/Fl.H>
#include <FL/x.H>
#include <FL/Fl_Window.H>
#include <stdlib.h>
#include "flstring.h"
@ -125,6 +126,10 @@ void Fl_Window::draw() { @@ -125,6 +126,10 @@ void Fl_Window::draw() {
int i;
for (i=dx; i<12; i++) {
fl_color(c[i&3]);
#ifdef __APPLE_COCOA__
extern CGContextRef fl_gc;
if(fl_gc)
#endif
fl_line(x1--, y1, x2, y2--);
}
}

4
src/Fl_Window_iconize.cxx

@ -37,7 +37,11 @@ void Fl_Window::iconize() { @@ -37,7 +37,11 @@ void Fl_Window::iconize() {
#ifdef WIN32
ShowWindow(i->xid, SW_SHOWMINNOACTIVE);
#elif defined(__APPLE__)
#ifdef __APPLE_COCOA__
MacCollapseWindow((Window)i->xid);
#else
CollapseWindow( i->xid, true );
#endif
#else
XIconifyWindow(fl_display, i->xid, fl_screen);
#endif

7
src/Fl_arg.cxx

@ -88,13 +88,6 @@ int Fl::arg(int argc, char **argv, int &i) { @@ -88,13 +88,6 @@ int Fl::arg(int argc, char **argv, int &i) {
if (s[0] != '-' || s[1] == '-' || !s[1]) {return_i = 1; return 0;}
s++; // point after the dash
#ifdef __APPLE__
if (!strncmp(s, "psn", 3)) {
// Skip process serial number...
i++;
}
else
#endif // __APPLE__
if (fl_match(s, "iconic")) {
fl_show_iconic = 1;
i++;

3105
src/Fl_cocoa.mm

File diff suppressed because it is too large Load Diff

12
src/Fl_compose.cxx

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
//
#include <FL/Fl.H>
#include <FL/x.H>
//
// MRS: Uncomment the following define to get the original (pre-1.1.2)
@ -38,6 +39,15 @@ @@ -38,6 +39,15 @@
#ifdef __APPLE__
#ifdef __APPLE_COCOA__
static const char* const compose_pairs =
" ! % # $ y=| & : c a <<~ - r _ * +-2 3 ' u p . , 1 o >>141234? "//00A0 ...
"`A'A^A~A:A*AAE,C`E'E^E:E`I'I^I:I-D~N`O'O^O~O:Ox O/`U'U^U:U'YTHss" //00C0 ...
"`a'a^a~a:a*aae,c`e'e^e:e`i'i^i:i-d~n`o'o^o~o:o-:o/`u'u^u:u'yth:y";//00E0 ...
#else
static const char* const compose_pairs =
":A*A,C'E~N:O:U'a`a^a:a~a*a,c'e`e"
"^e:e'i`i^i:i~n'o`o^o:o~o'u`u^u:u"
@ -48,6 +58,8 @@ static const char* const compose_pairs = @@ -48,6 +58,8 @@ static const char* const compose_pairs =
"++..,,_\"%%^A^E'A:E`E'I^I:I`I'O^O"
"mc`O'U^U`U||^ ~^_ u . * , ~-; v ";
#endif
#else
static const char* const compose_pairs =

18
src/Fl_grab.cxx

@ -48,7 +48,12 @@ extern HWND fl_capture; @@ -48,7 +48,12 @@ extern HWND fl_capture;
#ifdef __APPLE__
// MacOS Carbon does not seem to have a mechanism to grab the mouse pointer
extern WindowRef fl_capture;
#ifdef __APPLE_COCOA__
extern void MACsetkeywindow(void *nsw);
extern void *fl_capture;
#else
extern Window fl_capture;
#endif
#endif
void Fl::grab(Fl_Window* win) {
@ -58,8 +63,13 @@ void Fl::grab(Fl_Window* win) { @@ -58,8 +63,13 @@ void Fl::grab(Fl_Window* win) {
SetActiveWindow(fl_capture = fl_xid(first_window()));
SetCapture(fl_capture);
#elif defined(__APPLE__)
fl_capture = fl_xid( first_window() );
SetUserFocusWindow( fl_capture );
#ifdef __APPLE_COCOA__
fl_capture = Fl_X::i(first_window())->xid;
MACsetkeywindow(fl_capture);
#else
fl_capture = fl_xid( first_window() );
SetUserFocusWindow( fl_capture );
#endif
#else
XGrabPointer(fl_display,
fl_xid(first_window()),
@ -87,7 +97,9 @@ void Fl::grab(Fl_Window* win) { @@ -87,7 +97,9 @@ void Fl::grab(Fl_Window* win) {
ReleaseCapture();
#elif defined(__APPLE__)
fl_capture = 0;
#ifndef __APPLE_COCOA__
SetUserFocusWindow( (WindowRef)kUserFocusAuto );
#endif
#else
XUngrabKeyboard(fl_display, fl_event_time);
XUngrabPointer(fl_display, fl_event_time);

1
src/cgdebug.h

@ -212,3 +212,4 @@ inline void dbgCGContextRestoreGState(CGContextRef context) @@ -212,3 +212,4 @@ inline void dbgCGContextRestoreGState(CGContextRef context)
//
// End of "$Id$".
//

12
src/fl_arci.cxx

@ -86,6 +86,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) { @@ -86,6 +86,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE_QUARTZ__)
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
if (w!=h) {
CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, cx, cy);
@ -97,6 +100,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) { @@ -97,6 +100,9 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
CGContextAddArc(fl_gc, cx, cy, r, a1, a2, 1);
}
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -136,6 +142,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) { @@ -136,6 +142,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE_QUARTZ__)
a1 = (-a1)/180.0f*M_PI; a2 = (-a2)/180.0f*M_PI;
float cx = x + 0.5f*w - 0.5f, cy = y + 0.5f*h - 0.5f;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
if (w!=h) {
CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, cx, cy);
@ -151,6 +160,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) { @@ -151,6 +160,9 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
CGContextClosePath(fl_gc);
}
CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif

3
src/fl_ask.cxx

@ -273,7 +273,8 @@ void fl_beep(int type) { @@ -273,7 +273,8 @@ void fl_beep(int type) {
switch (type) {
case FL_BEEP_DEFAULT :
case FL_BEEP_ERROR :
SysBeep(30);
// SysBeep(30);
AlertSoundPlay();
break;
default :
break;

111
src/fl_cursor.cxx

@ -134,6 +134,113 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color c1, Fl_Color c2) { @@ -134,6 +134,113 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color c1, Fl_Color c2) {
# error "Either __LITTLE_ENDIAN__ or __BIG_ENDIAN__ must be defined"
#endif
#ifdef __APPLE_COCOA__
extern void *MACSetCursor(Fl_Cursor c);
extern Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h);
CGContextRef CreateHelpImage(void)
{
int w = 20, h = 20;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
fl_color(FL_BLACK);
fl_font(FL_COURIER_BOLD, 20);
fl_draw("?", 1, h-1);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNoneImage(void)
{
int w = 20, h = 20;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateWatchImage(void)
{
int w, h, r = 5;
w = 2*r+6;
h = 4*r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, w/2, h/2);
fl_color(FL_WHITE);
fl_circle(0, 0, r+1);
fl_color(FL_BLACK);
fl_rectf(-r*0.7, -r*1.7, 1.4*r, 3.4*r);
fl_rectf(r-1, -1, 3, 3);
fl_color(FL_WHITE);
fl_pie(-r, -r, 2*r, 2*r, 0, 360);
fl_color(FL_BLACK);
fl_circle(0,0,r);
fl_xyline(0, 0, -r*.7);
fl_xyline(0, 0, 0, -r*.7);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNESWImage(void)
{
int c = 7, r = 2*c;
int w = r, h = r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, 0, h);
CGContextScaleCTM( (CGContextRef)off, 1, -1);
fl_color(FL_BLACK);
fl_polygon(0, 0, c, 0, 0, c);
fl_polygon(r, r, r, r-c, r-c, r);
fl_line_style(FL_SOLID, 2, 0);
fl_line(0,1, r,r+1);
fl_line_style(FL_SOLID, 0, 0);
fl_end_offscreen();
return (CGContextRef)off;
}
CGContextRef CreateNWSEImage(void)
{
int c = 7, r = 2*c;
int w = r, h = r;
Fl_Offscreen off = fl_create_offscreen_with_alpha(w, h);
fl_begin_offscreen(off);
CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
fl_rectf(0,0,w,h);
CGContextTranslateCTM( (CGContextRef)off, 0, h);
CGContextScaleCTM( (CGContextRef)off, 1, -1);
fl_color(FL_BLACK);
fl_polygon(r-1, 0, r-1, c, r-1-c, 0);
fl_polygon(-1, r, c-1, r, -1, r-c);
fl_line_style(FL_SOLID, 2, 0);
fl_line(r-1,1, -1,r+1);
fl_line_style(FL_SOLID, 0, 0);
fl_end_offscreen();
return (CGContextRef)off;
}
void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
if (c == FL_CURSOR_DEFAULT) {
c = cursor_default;
}
void *cursor = MACSetCursor( c );
if (i) {
i->cursor = cursor;
}
}
#else
static Cursor crsrHAND =
{
{ E(0x0600), E(0x0900), E(0x0900), E(0x0900), E(0x09C0), E(0x0938), E(0x6926), E(0x9805),
@ -214,7 +321,7 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) { @@ -214,7 +321,7 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
c = cursor_default;
}
CursHandle icrsr = fl_default_cursor;
switch (c) {
switch (c) {
case FL_CURSOR_CROSS: icrsr = GetCursor( crossCursor ); break;
case FL_CURSOR_WAIT: icrsr = GetCursor( watchCursor ); break;
case FL_CURSOR_INSERT: icrsr = GetCursor( iBeamCursor ); break;
@ -246,6 +353,8 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) { @@ -246,6 +353,8 @@ void Fl_Window::cursor(Fl_Cursor c, Fl_Color, Fl_Color) {
}
}
#endif //__APPLE_COCOA__
#else
// I like the MSWindows resize cursors, so I duplicate them here:

6
src/fl_dnd_mac.cxx

@ -46,6 +46,11 @@ extern int fl_selection_length; @@ -46,6 +46,11 @@ extern int fl_selection_length;
*/
int Fl::dnd()
{
#ifdef __APPLE_COCOA__
extern int MACpreparedrag(void);
return MACpreparedrag();
#else
OSErr result;
DragReference dragRef;
result = NewDrag( &dragRef );
@ -82,6 +87,7 @@ int Fl::dnd() @@ -82,6 +87,7 @@ int Fl::dnd()
DisposeRgn( region );
DisposeDrag( dragRef );
return true;
#endif //__APPLE_COCOA__
}

199
src/fl_font_mac.cxx

@ -33,6 +33,8 @@ extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* @@ -33,6 +33,8 @@ extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short*
// if no font has been selected yet by the user, get one.
#define check_default_font() {if (!fl_fontsize) fl_font(0, 12);}
static const CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 };
Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
next = 0;
# if HAVE_GL
@ -43,13 +45,39 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { @@ -43,13 +45,39 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
// OpenGL needs those for its font handling
q_name = strdup(name);
size = Size;
minsize = maxsize = Size;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CFStringRef str = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
fontref = CTFontCreateWithName(str, size, NULL);
CGGlyph glyph[2];
const UniChar A[2]={'W','.'};
CTFontGetGlyphsForCharacters(fontref, A, glyph, 2);
CGSize advances[2];
double w;
CTFontGetAdvancesForGlyphs(fontref, kCTFontHorizontalOrientation, glyph, advances, 2);
w = advances[0].width;
if( abs(advances[0].width - advances[1].width) < 1E-2 ) {//this is a fixed-width font
//slightly rescale fixed-width fonts so the character width has an integral value
CFRelease(fontref);
CGFloat fsize = size / ( w/floor(w + 0.5) );
fontref = CTFontCreateWithName(str, fsize, NULL);
w = CTFontGetAdvancesForGlyphs(fontref, kCTFontHorizontalOrientation, glyph, NULL, 1);
}
CFRelease(str);
ascent = (short)(CTFontGetAscent(fontref) + 0.5);
descent = (short)(CTFontGetDescent(fontref) + 0.5);
q_width = w + 0.5;
}
else {
#endif
#if ! __LP64__
OSStatus err;
// fill our structure with a few default values
ascent = Size*3/4;
descent = Size-ascent;
q_width = Size*2/3;
minsize = maxsize = Size;
// now use ATS to get the actual Glyph size information
// now use ATS to get the actual Glyph size information
// say that our passed-in name is encoded as UTF-8, since this works for plain ASCII names too...
CFStringRef cfname = CFStringCreateWithCString(0L, name, kCFStringEncodingUTF8);
ATSFontRef font = ATSFontFindFromName(cfname, kATSOptionFlagsDefault);
@ -112,6 +140,10 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { @@ -112,6 +140,10 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
// cause ATSU to find a suitable font to render any chars the current font can't do...
ATSUSetTransientFontMatching (layout, true);
# endif
#endif//__LP64__
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}
Fl_Font_Descriptor* fl_fontsize = 0L;
@ -132,8 +164,12 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() { @@ -132,8 +164,12 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() {
#endif
*/
if (this == fl_fontsize) fl_fontsize = 0;
ATSUDisposeTextLayout(layout);
ATSUDisposeStyle(style);
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) CFRelease(fontref);
#else
/* ATSUDisposeTextLayout(layout);
ATSUDisposeStyle(style); */
#endif
}
////////////////////////////////////////////////////////////////
@ -235,7 +271,25 @@ double fl_width(const UniChar* txt, int n) { @@ -235,7 +271,25 @@ double fl_width(const UniChar* txt, int n) {
if (!fl_fontsize)
return 8*n; // user must select a font first!
}
OSStatus err;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str, NULL);
CFMutableAttributedStringRef mastr = CFAttributedStringCreateMutableCopy(NULL, 0, astr);
CFRelease(astr);
CFAttributedStringSetAttribute(mastr, CFRangeMake(0, CFStringGetLength(str)), kCTFontAttributeName, fontref);
CFRelease(str);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
double retval = CTLineGetTypographicBounds(ctline, NULL, NULL, NULL);
CFRelease(ctline);
return retval;
}
else {
#endif
#if ! __LP64__
OSStatus err;
Fixed bBefore, bAfter, bAscent, bDescent;
ATSUTextLayout layout;
ByteCount iSize;
@ -256,6 +310,10 @@ double fl_width(const UniChar* txt, int n) { @@ -256,6 +310,10 @@ double fl_width(const UniChar* txt, int n) {
// If err is OK then return length, else return 0. Or something...
int len = FixedToInt(bAfter);
return len;
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}
double fl_width(const char* txt, int n) {
@ -281,6 +339,30 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h @@ -281,6 +339,30 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h
h = 8.0;
return;
}
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CTFontRef fontref = fl_fontsize->fontref;
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n *sizeof(UniChar), kCFStringEncodingUTF16, false);
CFAttributedStringRef astr = CFAttributedStringCreate(NULL, str16, NULL);
CFMutableAttributedStringRef mastr = CFAttributedStringCreateMutableCopy(NULL, 0, astr);
CFRelease(astr);
CFAttributedStringSetAttribute(mastr, CFRangeMake(0, CFStringGetLength(str16)), kCTFontAttributeName, fontref);
CFRelease(str16);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
CGContextSetTextPosition(fl_gc, 0, 0);
CGContextSetShouldAntialias(fl_gc, true);
CGRect rect = CTLineGetImageBounds(ctline, fl_gc);
CGContextSetShouldAntialias(fl_gc, false);
CFRelease(ctline);
dx = floor(rect.origin.x + 0.5);
dy = floor(- rect.origin.y - rect.size.height + 0.5);
w = rect.size.width + 0.5;
h = rect.size.height + 0.5;
}
else {
#endif
#if ! __LP64__
OSStatus err;
ATSUTextLayout layout;
ByteCount iSize;
@ -304,6 +386,10 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h @@ -304,6 +386,10 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h
dx = bbox.left;
dy = -bbox.bottom;
//printf("r: %d l: %d t: %d b: %d w: %d h: %d\n", bbox.right, bbox.left, bbox.top, bbox.bottom, w, h);
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
return;
} // fl_text_extents
@ -320,13 +406,76 @@ void fl_draw(const char* str, int n, int x, int y) { @@ -320,13 +406,76 @@ void fl_draw(const char* str, int n, int x, int y) {
fl_draw(str, n, (float)x-0.0f, (float)y-0.5f);
}
#if defined(__APPLE_COCOA__)
static unsigned fl_cmap[256] = {
#include "fl_cmap.h" // this is a file produced by "cmap.cxx":
};
CGColorRef flcolortocgcolor(Fl_Color i)
{
int index;
uchar r, g, b;
if (i & 0xFFFFFF00) {
// translate rgb colors into color index
r = i>>24;
g = i>>16;
b = i>> 8;
} else {
// translate index into rgb:
index = i;
unsigned c = fl_cmap[i];
r = c>>24;
g = c>>16;
b = c>> 8;
}
CGFloat components[4] = {r/255.0f, g/255.0f, b/255.0f, 1.};
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB), components);
#else
return CGColorCreate(CGColorSpaceCreateWithName(kCGColorSpaceUserRGB), components);
#endif
}
#endif
void fl_draw(const char *str, int n, float x, float y) {
OSStatus err;
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
// avoid a crash if no font has been selected by user yet !
check_default_font();
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CFStringRef keys[2];
CFTypeRef values[2];
CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)uniStr, n * sizeof(UniChar), kCFStringEncodingUTF16, false);
CGColorRef color = flcolortocgcolor(fl_color());
keys[0] = kCTFontAttributeName;
keys[1] = kCTForegroundColorAttributeName;
values[0] = fl_fontsize->fontref;
values[1] = color;
CFDictionaryRef attributes = CFDictionaryCreate(kCFAllocatorDefault,
(const void**)&keys,
(const void**)&values,
2,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFAttributedStringRef mastr = CFAttributedStringCreate(kCFAllocatorDefault, str16, attributes);
CFRelease(str16);
CFRelease(attributes);
CFRelease(color);
CTLineRef ctline = CTLineCreateWithAttributedString(mastr);
CFRelease(mastr);
CGContextSetTextMatrix(fl_gc, font_mx);
CGContextSetTextPosition(fl_gc, x, y);
CGContextSetShouldAntialias(fl_gc, true);
CTLineDraw(ctline, fl_gc);
CGContextSetShouldAntialias(fl_gc, false);
CFRelease(ctline);
}
else {
#endif
#if ! __LP64__
OSStatus err;
// now collect our ATSU resources
ATSUTextLayout layout = fl_fontsize->layout;
@ -337,10 +486,25 @@ void fl_draw(const char *str, int n, float x, float y) { @@ -337,10 +486,25 @@ void fl_draw(const char *str, int n, float x, float y) {
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y));
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}
void fl_draw(int angle, const char *str, int n, int x, int y) {
OSStatus err;
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, x, y);
CGContextRotateCTM(fl_gc, - angle*(M_PI/180) );
fl_draw(str, n, (float)0., (float)0.);
CGContextRestoreGState(fl_gc);
}
else {
#endif
#if ! __LP64__
OSStatus err;
// convert to UTF-16 first
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
@ -360,10 +524,21 @@ void fl_draw(int angle, const char *str, int n, int x, int y) { @@ -360,10 +524,21 @@ void fl_draw(int angle, const char *str, int n, int x, int y) {
//restore layout baseline
ang = IntToFixed(0);
ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr);
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}
void fl_rtl_draw(const char* c, int n, int x, int y) {
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text...
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithName != NULL) {
fl_draw(c, n, x - fl_width(c, n), y); //to check;
}
else {
#endif
#if ! __LP64__
// I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text...
double offs = fl_width(c, n);
OSStatus err;
// convert to UTF-16 first
@ -379,6 +554,10 @@ void fl_rtl_draw(const char* c, int n, int x, int y) { @@ -379,6 +554,10 @@ void fl_rtl_draw(const char* c, int n, int x, int y) {
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y));
#endif
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}
//

11
src/fl_line_style.cxx

@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
float fl_quartz_line_width_ = 1.0f;
static enum CGLineCap fl_quartz_line_cap_ = kCGLineCapButt;
static enum CGLineJoin fl_quartz_line_join_ = kCGLineJoinMiter;
static float *fl_quartz_line_pattern = 0;
static CGFloat *fl_quartz_line_pattern = 0;
static int fl_quartz_line_pattern_size = 0;
void fl_quartz_restore_line_style_() {
CGContextSetLineWidth(fl_gc, fl_quartz_line_width_);
@ -145,9 +145,9 @@ void fl_line_style(int style, int width, char* dashes) { @@ -145,9 +145,9 @@ void fl_line_style(int style, int width, char* dashes) {
fl_quartz_line_cap_ = Cap[(style>>8)&3];
fl_quartz_line_join_ = Join[(style>>12)&3];
char *d = dashes;
static float pattern[16];
static CGFloat pattern[16];
if (d && *d) {
float *p = pattern;
CGFloat *p = pattern;
while (*d) { *p++ = (float)*d++; }
fl_quartz_line_pattern = pattern;
fl_quartz_line_pattern_size = d-dashes;
@ -162,7 +162,7 @@ void fl_line_style(int style, int width, char* dashes) { @@ -162,7 +162,7 @@ void fl_line_style(int style, int width, char* dashes) {
dash = char(3*width);
dot = gap = char(width);
}
float *p = pattern;
CGFloat *p = pattern;
switch (style & 0xff) {
case FL_DASH: *p++ = dash; *p++ = gap; break;
case FL_DOT: *p++ = dot; *p++ = gap; break;
@ -172,7 +172,8 @@ void fl_line_style(int style, int width, char* dashes) { @@ -172,7 +172,8 @@ void fl_line_style(int style, int width, char* dashes) {
fl_quartz_line_pattern_size = p-pattern;
fl_quartz_line_pattern = pattern;
} else {
fl_quartz_line_pattern = 0; fl_quartz_line_pattern_size = 0;
fl_quartz_line_pattern = 0;
fl_quartz_line_pattern_size = 0;
}
fl_quartz_restore_line_style_();
#else

32
src/fl_read_image_mac.cxx

@ -26,9 +26,9 @@ @@ -26,9 +26,9 @@
//
#include <config.h>
// warning: this function is only implemented in Quickdraw. The function
// below may not work If FLTK is compiled with Quartz enabled
#ifdef __APPLE_COCOA__
extern unsigned char *MACbitmapFromRectOfWindow(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
#endif
//
// 'fl_read_image()' - Read an image from the current window.
@ -41,6 +41,29 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate @@ -41,6 +41,29 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
int w, // I - Width of area to read
int h, // I - Height of area to read
int alpha) { // I - Alpha value for image (0 for none)
#if defined(__APPLE_COCOA__)
Fl_Window *window = Fl_Window::current();
while(window->window()) window = window->window();
int delta;
uchar *base = MACbitmapFromRectOfWindow(window,x,y,w,h,&delta);
int rowBytes = delta*w;
// Allocate the image data array as needed...
int d = alpha ? 4 : 3;
if (!p) p = new uchar[w * h * d];
// Initialize the default colors/alpha in the whole image...
memset(p, alpha, w * h * d);
// Copy the image from the off-screen buffer to the memory buffer.
int idx, idy; // Current X & Y in image
uchar *pdst, *psrc;
for (idy = 0, pdst = p; idy < h; idy ++) {
for (idx = 0, psrc = base + idy * rowBytes; idx < w; idx ++, psrc += delta, pdst += d) {
/*R*/ pdst[0] = psrc[0];
/*G*/ pdst[1] = psrc[1];
/*B*/ pdst[2] = psrc[2];
}
}
delete base;
#else
Rect src, // Source rectangle
dst; // Destination rectangle
GWorldPtr osbuffer; // Temporary off-screen buffer for copy
@ -128,7 +151,8 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate @@ -128,7 +151,8 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
DisposeGWorld(osbuffer);
SetPort(srcPort);
return p;
#endif
return p;
}

202
src/fl_rect.cxx

@ -59,10 +59,18 @@ void fl_rect(int x, int y, int w, int h) { @@ -59,10 +59,18 @@ void fl_rect(int x, int y, int w, int h) {
LineTo(fl_gc, x, y+h-1);
LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextStrokeRect(fl_gc, rect);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -81,10 +89,18 @@ void fl_rectf(int x, int y, int w, int h) { @@ -81,10 +89,18 @@ void fl_rectf(int x, int y, int w, int h) {
rect.right = x + w; rect.bottom = y + h;
FillRect(fl_gc, &rect, fl_brush());
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGRect rect = CGRectMake(x, y, w-1, h-1);
CGContextFillRect(fl_gc, rect);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -99,11 +115,19 @@ void fl_xyline(int x, int y, int x1) { @@ -99,11 +115,19 @@ void fl_xyline(int x, int y, int x1) {
#elif defined(WIN32)
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x1+1, y);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -125,12 +149,20 @@ void fl_xyline(int x, int y, int x1, int y2) { @@ -125,12 +149,20 @@ void fl_xyline(int x, int y, int x1, int y2) {
LineTo(fl_gc, x1, y);
LineTo(fl_gc, x1, y2);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
#error unsupported platform
#endif
@ -155,13 +187,21 @@ void fl_xyline(int x, int y, int x1, int y2, int x3) { @@ -155,13 +187,21 @@ void fl_xyline(int x, int y, int x1, int y2, int x3) {
LineTo(fl_gc, x1, y2);
LineTo(fl_gc, x3, y2);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y);
CGContextAddLineToPoint(fl_gc, x1, y2);
CGContextAddLineToPoint(fl_gc, x3, y2);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -178,11 +218,19 @@ void fl_yxline(int x, int y, int y1) { @@ -178,11 +218,19 @@ void fl_yxline(int x, int y, int y1) {
else y1++;
MoveToEx(fl_gc, x, y, 0L); LineTo(fl_gc, x, y1);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -204,12 +252,20 @@ void fl_yxline(int x, int y, int y1, int x2) { @@ -204,12 +252,20 @@ void fl_yxline(int x, int y, int y1, int x2) {
LineTo(fl_gc, x, y1);
LineTo(fl_gc, x2, y1);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -234,13 +290,21 @@ void fl_yxline(int x, int y, int y1, int x2, int y3) { @@ -234,13 +290,21 @@ void fl_yxline(int x, int y, int y1, int x2, int y3) {
LineTo(fl_gc, x2, y1);
LineTo(fl_gc, x2, y3);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x, y1);
CGContextAddLineToPoint(fl_gc, x2, y1);
CGContextAddLineToPoint(fl_gc, x2, y3);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -259,11 +323,19 @@ void fl_line(int x, int y, int x1, int y1) { @@ -259,11 +323,19 @@ void fl_line(int x, int y, int x1, int y1) {
// functions will not draw the last point ("it's a feature!"...)
SetPixel(fl_gc, x1, y1, fl_RGB());
#elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -287,12 +359,20 @@ void fl_line(int x, int y, int x1, int y1, int x2, int y2) { @@ -287,12 +359,20 @@ void fl_line(int x, int y, int x1, int y1, int x2, int y2) {
// functions will not draw the last point ("it's a feature!"...)
SetPixel(fl_gc, x2, y2, fl_RGB());
#elif defined(__APPLE_QUARTZ__)
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, false);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextStrokePath(fl_gc);
if (fl_quartz_line_width_==1.0f ) CGContextSetShouldAntialias(fl_gc, true);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -315,11 +395,17 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2) { @@ -315,11 +395,17 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2) {
LineTo(fl_gc, x2, y2);
LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -344,12 +430,18 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { @@ -344,12 +430,18 @@ void fl_loop(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
LineTo(fl_gc, x3, y3);
LineTo(fl_gc, x, y);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextAddLineToPoint(fl_gc, x3, y3);
CGContextClosePath(fl_gc);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -371,11 +463,17 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) { @@ -371,11 +463,17 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2) {
SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 3);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -398,12 +496,18 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) { @@ -398,12 +496,18 @@ void fl_polygon(int x, int y, int x1, int y1, int x2, int y2, int x3, int y3) {
SelectObject(fl_gc, fl_brush());
Polygon(fl_gc, p, 4);
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, x, y);
CGContextAddLineToPoint(fl_gc, x1, y1);
CGContextAddLineToPoint(fl_gc, x2, y2);
CGContextAddLineToPoint(fl_gc, x3, y3);
CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -418,11 +522,19 @@ void fl_point(int x, int y) { @@ -418,11 +522,19 @@ void fl_point(int x, int y) {
#elif defined(WIN32)
SetPixel(fl_gc, x, y, fl_RGB());
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
CGContextMoveToPoint(fl_gc, x-.5, y); // Quartz needs a line that is one pixel long, or it will not draw anything
CGContextAddLineToPoint(fl_gc, x+.5, y);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -467,7 +579,17 @@ void fl_restore_clip() { @@ -467,7 +579,17 @@ void fl_restore_clip() {
#elif defined(__APPLE_QUARTZ__)
if ( fl_window ) // clipping for a true window
{
GrafPtr port = GetWindowPort( fl_window );
#ifdef __APPLE_COCOA__
Fl_X::q_clear_clipping();
Fl_X::q_fill_context();//flip coords and translate if subwindow
//apply window's clip
CGContextClipToRects(fl_gc, fl_window_region->rects, fl_window_region->count );
//apply additional program clip
if(r) {
CGContextClipToRects(fl_gc, r->rects, r->count);
}
#else
GrafPtr port = GetWindowPort( fl_window );
if ( port ) {
RgnHandle portClip = NewRgn();
CopyRgn( fl_window_region, portClip ); // changed
@ -479,16 +601,22 @@ void fl_restore_clip() { @@ -479,16 +601,22 @@ void fl_restore_clip() {
Fl_X::q_fill_context();
DisposeRgn( portClip );
}
#endif
} else if (fl_gc) { // clipping for an offscreen drawing world (CGBitmap)
Rect portRect;
portRect.top = 0;
portRect.left = 0;
portRect.bottom = CGBitmapContextGetHeight(fl_gc);
portRect.right = CGBitmapContextGetWidth(fl_gc);
Fl_X::q_clear_clipping();
if (r)
ClipCGContextToRegion(fl_gc, &portRect, r);
Fl_X::q_fill_context();
Rect portRect;
portRect.top = 0;
portRect.left = 0;
portRect.bottom = CGBitmapContextGetHeight(fl_gc);
portRect.right = CGBitmapContextGetWidth(fl_gc);
Fl_X::q_clear_clipping();
if (r) {
#ifdef __APPLE_COCOA__
CGContextClipToRects(fl_gc, r->rects, r->count);
#else
ClipCGContextToRegion(fl_gc, &portRect, r);
#endif
}
Fl_X::q_fill_context();
}
#else
# error unsupported platform
@ -534,19 +662,33 @@ void fl_push_clip(int x, int y, int w, int h) { @@ -534,19 +662,33 @@ void fl_push_clip(int x, int y, int w, int h) {
#elif defined(WIN32)
CombineRgn(r,r,current,RGN_AND);
#elif defined(__APPLE_QUARTZ__)
SectRgn(r, current, r);
#ifdef __APPLE_COCOA__
XDestroyRegion(r);
r = MacRectRegionIntersect(current, x,y,w,h);
#else
SectRgn(r, current, r);
#endif
#else
# error unsupported platform
#endif
}
#if defined(__APPLE_QUARTZ__)
else {
r = XRectangleRegion(x,y,w,h);
}
#endif
} else { // make empty clip region:
#if defined(USE_X11)
r = XCreateRegion();
#elif defined(WIN32)
r = CreateRectRgn(0,0,0,0);
#elif defined(__APPLE_QUARTZ__)
r = NewRgn();
SetEmptyRgn(r);
#ifdef __APPLE_COCOA__
r = NULL;
#else
r = NewRgn();
SetEmptyRgn(r);
#endif
#else
# error unsupported platform
#endif
@ -604,9 +746,18 @@ int fl_not_clipped(int x, int y, int w, int h) { @@ -604,9 +746,18 @@ int fl_not_clipped(int x, int y, int w, int h) {
return RectInRegion(r,&rect);
#elif defined(__APPLE_QUARTZ__)
if (!r) return 1;
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x,y,w - 1,h - 1);
for(int i = 0; i < r->count; i++) {
CGRect test = CGRectIntersection(r->rects[i], arg);
if( ! CGRectIsEmpty(test)) return 1;
}
return 0;
#else
Rect rect;
rect.left = x; rect.top = y; rect.right = x+w; rect.bottom = y+h;
return RectInRgn(&rect, r);
#endif
#else
# error unsupported platform
#endif
@ -673,6 +824,24 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){ @@ -673,6 +824,24 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
DeleteObject(rr);
return ret;
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
CGRect arg = CGRectMake(x,y,w - 1,h - 1);
CGRect u = CGRectMake(0,0,0,0);
CGRect test;
for(int i = 0; i < r->count; i++) {
test = CGRectIntersection(r->rects[i], arg);
if( ! CGRectIsEmpty(test) ) {
if(CGRectIsEmpty(u)) u = test;
else u = CGRectUnion(u, test);
}
}
X = u.origin.x;
Y = u.origin.y;
W = u.size.width;
H = u.size.height;
if(CGRectIsEmpty(u)) W = H = 0;
return ! CGRectEqualToRect(arg, u);
#else
RgnHandle rr = NewRgn();
SetRectRgn( rr, x, y, x+w, y+h );
SectRgn( r, rr, rr );
@ -685,6 +854,7 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){ @@ -685,6 +854,7 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
if ( H==0 ) return 2;
if ( h==H && w==W ) return 0;
return 0;
#endif
#else
# error unsupported platform
#endif

12
src/fl_scroll_area.cxx

@ -151,6 +151,16 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy, @@ -151,6 +151,16 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
BitBlt(fl_gc, dest_x, dest_y, src_w, src_h, fl_gc, src_x, src_y,SRCCOPY);
#elif defined(__APPLE_QUARTZ__)
#if defined(__APPLE_COCOA__)
extern CGImageRef MAC_CGImageFromRectOfWindow(Fl_Window*, int x, int y, int w, int h);
CGImageRef img = MAC_CGImageFromRectOfWindow(Fl_Window::current(), src_x, src_y, src_w, src_h);
CGRect rect = { { dest_x, dest_y }, { src_w, src_h } };
Fl_X::q_begin_image(rect, 0, 0, src_w, src_h);
CGContextDrawImage(fl_gc, rect, img);
Fl_X::q_end_image();
CFRelease(img);
#else
// warning: there does not seem to be an equivalent to this function in Quartz
// ScrollWindowRect is a QuickDraw function and won't work here.
// Since on OS X all windows are fully double buffered, we need not
@ -161,6 +171,8 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy, @@ -161,6 +171,8 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
static RGBColor fg = { 0x0000, 0x0000, 0x0000 }; RGBForeColor( &fg );
CopyBits( GetPortBitMapForCopyBits( GetWindowPort(fl_window) ),
GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), &src, &dst, srcCopy, 0L);
#endif
#else
# error unsupported platform
#endif

31
src/fl_set_fonts_mac.cxx

@ -60,6 +60,33 @@ static int fl_free_font = FL_FREE_FONT; @@ -60,6 +60,33 @@ static int fl_free_font = FL_FREE_FONT;
Fl_Font Fl::set_fonts(const char* xstarname) {
#pragma unused ( xstarname )
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if(CTFontCreateWithFontDescriptor != NULL) {
int value[1] = {1};
CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)kCTFontCollectionRemoveDuplicatesOption,
(const void **)&value, 1, NULL, NULL);
CTFontCollectionRef fcref = CTFontCollectionCreateFromAvailableFonts(dict);
CFRelease(dict);
CFArrayRef arrayref = CTFontCollectionCreateMatchingFontDescriptors(fcref);
CFRelease(fcref);
CFIndex count = CFArrayGetCount(arrayref);
CFIndex i;
for (i = 0; i < count; i++) {
CTFontDescriptorRef fdesc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(arrayref, i);
CTFontRef font = CTFontCreateWithFontDescriptor(fdesc, 0., NULL);
CFStringRef cfname = CTFontCopyPostScriptName(font);
CFRelease(font);
static char fname[100];
CFStringGetCString(cfname, fname, sizeof(fname), kCFStringEncodingUTF8);
CFRelease(cfname);
Fl::set_font((Fl_Font)(fl_free_font++), strdup(fname));
}
CFRelease(arrayref);
return (Fl_Font)fl_free_font;
}
else {
#endif
#if ! __LP64__
#if defined(OLD__APPLE_QUARTZ__)
ATSFontIterator it;
ATSFontIteratorCreate(kATSFontContextGlobal, 0L, 0L, kATSOptionFlagsUnRestrictedScope, &it);
@ -114,6 +141,10 @@ Fl_Font Fl::set_fonts(const char* xstarname) { @@ -114,6 +141,10 @@ Fl_Font Fl::set_fonts(const char* xstarname) {
}
free(oFontIDs);
return (Fl_Font)fl_free_font;
#endif //OLD__APPLE_QUARTZ__
#endif //__LP64__
#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
}
#endif
}

37
src/fl_vertex.cxx

@ -229,13 +229,21 @@ void fl_end_points() { @@ -229,13 +229,21 @@ void fl_end_points() {
#elif defined(WIN32)
for (int i=0; i<n; i++) SetPixel(fl_gc, p[i].x, p[i].y, fl_RGB());
#elif defined(__APPLE_QUARTZ__)
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, true);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#endif
for (int i=0; i<n; i++) {
CGContextMoveToPoint(fl_gc, p[i].x, p[i].y);
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextStrokePath(fl_gc);
}
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, false);
#ifdef __APPLE_COCOA__
if (fl_quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(fl_gc, false);
#else
if (fl_quartz_line_width_==1.0f) CGContextSetShouldAntialias(fl_gc, true);
#endif
#else
# error unsupported platform
#endif
@ -255,10 +263,16 @@ void fl_end_line() { @@ -255,10 +263,16 @@ void fl_end_line() {
if (n>1) Polyline(fl_gc, p, n);
#elif defined(__APPLE_QUARTZ__)
if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextStrokePath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -295,11 +309,17 @@ void fl_end_polygon() { @@ -295,11 +309,17 @@ void fl_end_polygon() {
}
#elif defined(__APPLE_QUARTZ__)
if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -370,11 +390,17 @@ void fl_end_complex_polygon() { @@ -370,11 +390,17 @@ void fl_end_complex_polygon() {
}
#elif defined(__APPLE_QUARTZ__)
if (n<=1) return;
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextMoveToPoint(fl_gc, p[0].x, p[0].y);
for (int i=1; i<n; i++)
CGContextAddLineToPoint(fl_gc, p[i].x, p[i].y);
CGContextClosePath(fl_gc);
CGContextFillPath(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif
@ -412,8 +438,15 @@ void fl_circle(double x, double y,double r) { @@ -412,8 +438,15 @@ void fl_circle(double x, double y,double r) {
Arc(fl_gc, llx, lly, llx+w, lly+h, 0,0, 0,0);
#elif defined(__APPLE_QUARTZ__)
// Quartz warning : circle won't scale to current matrix!
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 1);
//last argument must be 0 (counterclockwise) or it draws nothing under __LP64__ !!!!
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, true);
#endif
CGContextAddArc(fl_gc, xt, yt, (w+h)*0.25f, 0, 2.0f*M_PI, 0);
(what == POLYGON ? CGContextFillPath : CGContextStrokePath)(fl_gc);
#ifdef __APPLE_COCOA__
CGContextSetShouldAntialias(fl_gc, false);
#endif
#else
# error unsupported platform
#endif

111
src/gl_draw.cxx

@ -110,6 +110,9 @@ void gl_font(int fontid, int size) { @@ -110,6 +110,9 @@ void gl_font(int fontid, int size) {
wglUseFontBitmaps(fl_gc, base, count, fl_fontsize->listbase+base);
SelectObject(fl_gc, oldFid);
# elif defined(__APPLE_QUARTZ__)
#if ! __LP64__
//AGL is not supported for use in 64-bit applications:
//http://developer.apple.com/mac/library/documentation/Carbon/Conceptual/Carbon64BitGuide/OtherAPIChanges/OtherAPIChanges.html
short font, face, size;
uchar fn[256];
fn[0]=strlen(fl_fontsize->q_name);
@ -118,8 +121,9 @@ void gl_font(int fontid, int size) { @@ -118,8 +121,9 @@ void gl_font(int fontid, int size) {
face = 0;
size = fl_fontsize->size;
fl_fontsize->listbase = glGenLists(256);
aglUseFont(aglGetCurrentContext(), font, face,
aglUseFont(aglGetCurrentContext(), font, face,
size, 0, 256, fl_fontsize->listbase);
#endif
# else
# error unsupported platform
# endif
@ -128,7 +132,9 @@ void gl_font(int fontid, int size) { @@ -128,7 +132,9 @@ void gl_font(int fontid, int size) {
}
gl_fontsize = fl_fontsize;
#if !( defined(__APPLE__) && __LP64__ )
glListBase(fl_fontsize->listbase);
#endif
}
#ifndef __APPLE__
@ -204,10 +210,20 @@ void gl_remove_displaylist_fonts() @@ -204,10 +210,20 @@ void gl_remove_displaylist_fonts()
Draws an array of n characters of the string in the current font
at the current position.
*/
#if defined(__APPLE__) && __LP64__
static void gl_draw_cocoa(const char* str, int n);
#endif
void gl_draw(const char* str, int n) {
#ifdef __APPLE__
#if __LP64__
gl_draw_cocoa(str, n);
#else
// Should be converting the text here, as for other platforms???
glCallLists(n, GL_UNSIGNED_BYTE, str);
#endif
#else
static xchar *buf = NULL;
static int l = 0;
@ -236,7 +252,7 @@ void gl_draw(const char* str, int n) { @@ -236,7 +252,7 @@ void gl_draw(const char* str, int n) {
}
/**
Draws n charachters of the string in the current font at the given position
Draws n characters of the string in the current font at the given position
*/
void gl_draw(const char* str, int n, int x, int y) {
glRasterPos2i(x, y);
@ -244,7 +260,7 @@ void gl_draw(const char* str, int n, int x, int y) { @@ -244,7 +260,7 @@ void gl_draw(const char* str, int n, int x, int y) {
}
/**
Draws n charachters of the string in the current font at the given position
Draws n characters of the string in the current font at the given position
*/
void gl_draw(const char* str, int n, float x, float y) {
glRasterPos2f(x, y);
@ -351,6 +367,95 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) { @@ -351,6 +367,95 @@ void gl_draw_image(const uchar* b, int x, int y, int w, int h, int d, int ld) {
glDrawPixels(w,h,d<4?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,(const ulong*)b);
}
#if defined(__APPLE__) && defined(__APPLE_COCOA__) && __LP64__
#include <FL/glu.h>
static void gl_draw_cocoa(const char* str, int n)
{
//setup matrices
GLint matrixMode;
glGetIntegerv (GL_MATRIX_MODE, &matrixMode);
glMatrixMode (GL_PROJECTION);
glPushMatrix();
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glPushMatrix();
glLoadIdentity ();
float winw = Fl_Window::current()->w();
float winh = Fl_Window::current()->h();
glScalef (2.0f / winw, 2.0f / winh, 1.0f);
glTranslatef (-winw / 2.0f, -winh / 2.0f, 0.0f);
//write str to a bitmap just big enough
int w = 0, h = 0;
fl_measure(str, w, h, 0);
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
void *base = calloc(4*w, h);
if(base == NULL) return;
fl_gc = CGBitmapContextCreate(base, w, h, 8, w*4, lut, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(lut);
fl_fontsize = gl_fontsize;
fl_draw(str, 0, h - fl_descent());
//put this bitmap in a texture
static GLuint texName = 0;
glPushAttrib(GL_TEXTURE_BIT);
if (0 == texName) glGenTextures (1, &texName);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, base);
glPopAttrib();
CGContextRelease(fl_gc);
fl_gc = NULL;
free(base);
GLfloat pos[4];
glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
if (texName) {//write the texture on screen
CGRect bounds = CGRectMake (pos[0], pos[1] - fl_descent(), w, h);
glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); // GL_COLOR_BUFFER_BIT for glBlendFunc, GL_ENABLE_BIT for glEnable / glDisable
glDisable (GL_DEPTH_TEST); // ensure text is not removed by depth buffer test.
glEnable (GL_BLEND); // for text fading
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // ditto
glEnable (GL_TEXTURE_RECTANGLE_EXT);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName);
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 0.0f); // draw lower left in world coordinates
glVertex2f (bounds.origin.x, bounds.origin.y);
glTexCoord2f (0.0f, h); // draw upper left in world coordinates
glVertex2f (bounds.origin.x, bounds.origin.y + bounds.size.height);
glTexCoord2f (w, h); // draw upper right in world coordinates
glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height);
glTexCoord2f (w, 0.0f); // draw lower right in world coordinates
glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y);
glEnd ();
glPopAttrib();
glDeleteTextures(1, &texName);
}
// reset original matrices
glPopMatrix(); // GL_MODELVIEW
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glMatrixMode (matrixMode);
//set the raster position to end of string
pos[0] += w;
GLdouble modelmat[16];
glGetDoublev (GL_MODELVIEW_MATRIX, modelmat);
GLdouble projmat[16];
glGetDoublev (GL_PROJECTION_MATRIX, projmat);
GLdouble objX, objY, objZ;
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
gluUnProject(pos[0], pos[1], pos[2], modelmat, projmat, viewport, &objX, &objY, &objZ);
glRasterPos2d(objX, objY);
}
#endif
#endif
//

8
src/makedepend

@ -383,9 +383,9 @@ Fl_Widget.o: ../FL/Fl_Tooltip.H ../FL/fl_draw.H ../FL/Fl_Window.H flstring.h @@ -383,9 +383,9 @@ Fl_Widget.o: ../FL/Fl_Tooltip.H ../FL/fl_draw.H ../FL/Fl_Window.H flstring.h
Fl_Widget.o: ../config.h
Fl_Window.o: ../config.h ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H
Fl_Window.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
Fl_Window.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/Fl_Window.H
Fl_Window.o: ../FL/Fl_Group.H ../FL/Fl_Widget.H flstring.h ../FL/fl_draw.H
Fl_Window.o: ../FL/Fl_Window.H
Fl_Window.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/x.H ../FL/Fl_Window.H
Fl_Window.o: ../FL/Fl_Window.H ../FL/Fl_Group.H ../FL/Fl_Widget.H flstring.h
Fl_Window.o: ../FL/fl_draw.H
Fl_Window_fullscreen.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H
Fl_Window_fullscreen.o: ../FL/fl_types.h ../FL/Xutf8.h ../FL/Enumerations.H
Fl_Window_fullscreen.o: ../FL/Fl_Export.H ../FL/fl_types.h ../FL/x.H
@ -423,7 +423,7 @@ Fl_arg.o: ../FL/Fl_Widget.H ../FL/filename.H ../FL/fl_draw.H flstring.h @@ -423,7 +423,7 @@ Fl_arg.o: ../FL/Fl_Widget.H ../FL/filename.H ../FL/fl_draw.H flstring.h
Fl_arg.o: ../config.h
Fl_compose.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h
Fl_compose.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_compose.o: ../FL/fl_types.h
Fl_compose.o: ../FL/fl_types.h ../FL/x.H ../FL/Fl_Window.H
Fl_display.o: ../FL/Fl.H ../FL/fl_utf8.h ../FL/Fl_Export.H ../FL/fl_types.h
Fl_display.o: ../FL/Xutf8.h ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_display.o: ../FL/fl_types.h flstring.h ../config.h

5
src/screen_xywh.cxx

@ -107,7 +107,11 @@ static void screen_init() { @@ -107,7 +107,11 @@ static void screen_init() {
#elif defined(__APPLE__)
XRectangle screens[16];
extern int MACscreen_init(XRectangle screens[]);
static void screen_init() {
#ifdef __APPLE_COCOA__
num_screens = MACscreen_init(screens);
#else
GDHandle gd;
for (gd = GetDeviceList(), num_screens = 0; gd; gd = GetNextDevice(gd)) {
@ -120,6 +124,7 @@ static void screen_init() { @@ -120,6 +124,7 @@ static void screen_init() {
num_screens ++;
if (num_screens >= 16) break;
}
#endif
}
#elif HAVE_XINERAMA
# include <X11/extensions/Xinerama.h>

10
test/browser.cxx

@ -148,13 +148,17 @@ int main(int argc, char **argv) { @@ -148,13 +148,17 @@ int main(int argc, char **argv) {
#elif defined(USING_XCODE)
if ( i == argc )
{
fname = "../../../../test/browser.cxx";
done = browser->load(fname);
char buf[2048];
strcpy(buf, argv[0]);
char *slash = strrchr(buf, '/');
if (slash)
strcpy(slash, "/../Resources/browser.cxx");
done = browser->load(buf);
}
#endif
if ( !done )
{
printf("Can't load %s, %s\n", fname, strerror(errno));
fl_message("Can't load %s, %s\n", fname, strerror(errno));
exit(1);
}
}

42
test/color_chooser.cxx

@ -63,7 +63,7 @@ class Pens : public Fl_Box { @@ -63,7 +63,7 @@ class Pens : public Fl_Box {
void draw();
public:
Pens(int X, int Y, int W, int H, const char* L)
: Fl_Box(X,Y,W,H,L) {}
: Fl_Box(X,Y,W,H,L) {}
};
void Pens::draw() {
// use every color in the gray ramp:
@ -112,11 +112,11 @@ int main(int argc, char ** argv) { @@ -112,11 +112,11 @@ int main(int argc, char ** argv) {
Pens p(80,200,3*8,120,"lines");
p.align(FL_ALIGN_TOP);
int i = 1;
if (!Fl::args(argc,argv,i) || i != argc-1) {
if (!Fl::args(argc,argv,i) || i < argc-1) {
printf("usage: %s <switches> visual-number\n"
" - : default visual\n"
" r : call Fl::visual(FL_RGB)\n"
" c : call Fl::own_colormap()\n",argv[0]);
" - : default visual\n"
" r : call Fl::visual(FL_RGB)\n"
" c : call Fl::own_colormap()\n",argv[0]);
#if !defined(WIN32) && !defined(__APPLE__)
printf(" # : use this visual with an empty colormap:\n");
list_visuals();
@ -124,24 +124,26 @@ int main(int argc, char ** argv) { @@ -124,24 +124,26 @@ int main(int argc, char ** argv) {
puts(Fl::help);
exit(1);
}
if (argv[i][0] == 'r') {
if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n");
} else if (argv[i][0] == 'c') {
Fl::own_colormap();
} else if (argv[i][0] != '-') {
if (i!=argc) {
if (argv[i][0] == 'r') {
if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n");
} else if (argv[i][0] == 'c') {
Fl::own_colormap();
} else if (argv[i][0] != '-') {
#if !defined(WIN32) && !defined(__APPLE__)
int visid = atoi(argv[i]);
fl_open_display();
XVisualInfo templt; int num;
templt.visualid = visid;
fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
if (!fl_visual) Fl::fatal("No visual with id %d",visid);
fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
fl_visual->visual, AllocNone);
fl_xpixel(FL_BLACK); // make sure black is allocated
int visid = atoi(argv[i]);
fl_open_display();
XVisualInfo templt; int num;
templt.visualid = visid;
fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
if (!fl_visual) Fl::fatal("No visual with id %d",visid);
fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
fl_visual->visual, AllocNone);
fl_xpixel(FL_BLACK); // make sure black is allocated
#else
Fl::fatal("Visual id's not supported on MSWindows or MacOS.");
Fl::fatal("Visual id's not supported on MSWindows or MacOS.");
#endif
}
}
window.show(argc,argv);
return Fl::run();

46
test/demo.cxx

@ -154,7 +154,7 @@ int b2n[][9] = { @@ -154,7 +154,7 @@ int b2n[][9] = {
{ 0, -1, 1, 2, 3, 4, 5, -1, 6},
{ 0, 1, 2, 3, -1, 4, 5, 6, 7},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8}
};
};
int n2b[][9] = {
{ 4, -1, -1, -1, -1, -1, -1, -1, -1},
{ 3, 5, -1, -1, -1, -1, -1, -1, -1},
@ -165,17 +165,17 @@ int n2b[][9] = { @@ -165,17 +165,17 @@ int n2b[][9] = {
{ 0, 2, 3, 4, 5, 6, 8, -1, -1},
{ 0, 1, 2, 3, 5, 6, 7, 8, -1},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8}
};
};
int but2numb(int bnumb, int maxnumb)
/* Transforms a button number to an item number when there are
maxnumb items in total. -1 if the button should not exist. */
{ return b2n[maxnumb][bnumb]; }
maxnumb items in total. -1 if the button should not exist. */
{ return b2n[maxnumb][bnumb]; }
int numb2but(int inumb, int maxnumb)
/* Transforms an item number to a button number when there are
maxnumb items in total. -1 if the item should not exist. */
{ return n2b[maxnumb][inumb]; }
maxnumb items in total. -1 if the item should not exist. */
{ return n2b[maxnumb][inumb]; }
/* Pushing and Popping menus */
@ -276,15 +276,23 @@ void dobut(Fl_Widget *, long arg) @@ -276,15 +276,23 @@ void dobut(Fl_Widget *, long arg)
delete[] copy_of_icommand;
#elif defined USING_XCODE
int icommand_length = strlen(menus[men].icommand[bn]);
char* command = new char[icommand_length+24]; // extraspace for 'open ../../(name).app &\0'
sprintf(command, "open ../../../%s.app &", menus[men].icommand[bn]);
char *cmd = strdup(menus[men].icommand[bn]);
char *arg = strchr(cmd, ' ');
char command[2048];
if (arg) {
*arg = 0;
if (strcmp(cmd, "../fluid/fluid")==0)
sprintf(command, "open ../../../Fluid.app --args %s", arg+1);
else
sprintf(command, "open ../../../%s.app --args %s", cmd, arg+1);
} else {
sprintf(command, "open ../../../%s.app", cmd);
}
puts(command);
system(command);
delete[] command;
free(cmd);
#else // NON WIN32 systems.
int icommand_length = strlen(menus[men].icommand[bn]);
@ -312,7 +320,7 @@ int load_the_menu(const char* fname) @@ -312,7 +320,7 @@ int load_the_menu(const char* fname)
if (fin == NULL)
{
#if defined ( __APPLE__ )
// mac os bundle menu detection:
// mac os bundle menu detection:
char* pos = strrchr(fname,'/');
if (!pos) return 0;
*pos='\0';
@ -322,7 +330,7 @@ int load_the_menu(const char* fname) @@ -322,7 +330,7 @@ int load_the_menu(const char* fname)
fin = fopen(fname,"r");
if (fin == NULL)
#endif
return 0;
return 0;
}
for (;;) {
if (fgets(line,256,fin) == NULL) break;
@ -345,10 +353,10 @@ int load_the_menu(const char* fname) @@ -345,10 +353,10 @@ int load_the_menu(const char* fname)
while (line[i] != ':' && line[i] != '\n')
{
if (line[i] == '\\') {
i++;
if (line[i] == 'n') iname[j++] = '\n';
else iname[j++] = line[i];
i++;
i++;
if (line[i] == 'n') iname[j++] = '\n';
else iname[j++] = line[i];
i++;
} else
iname[j++] = line[i++];
}

4
test/fullscreen.cxx

@ -161,6 +161,10 @@ void fullscreen_cb(Fl_Widget *o, void *p) { @@ -161,6 +161,10 @@ void fullscreen_cb(Fl_Widget *o, void *p) {
py = w->y();
pw = w->w();
ph = w->h();
#ifndef WIN32//necessary because fullscreen removes border
border_button->value(0);
border_button->do_callback();
#endif
w->fullscreen();
} else {
w->fullscreen_off(px,py,pw,ph);

Loading…
Cancel
Save