FLTK for Mac:

Reversed to outdated (but working) event handling.
 Added README.mac
 Added mac.r minimal resource fork
 Still lots of bugs, but initial rendering works


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1804 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2001-12-04 03:03:17 +00:00
parent 9e6b78b5ca
commit 1d06051e8c
9 changed files with 237 additions and 44 deletions

26
FL/mac.r Normal file
View File

@ -0,0 +1,26 @@
data 'MBAR' (128) {
$"0001 0080" /* ...*/
};
data 'MENU' (128, "Apple") {
$"0080 0000 0000 0000 0000 FFFF FFFB 0114" /* .€........ÿÿÿû.. */
$"0A41 626F 7574 2046 4C54 4B00 0000 0001" /* ÂAbout FLTK..... */
$"2D00 0000 0000" /* -..... */
};
data 'cfrg' (0) {
$"0000 0000 0000 0000 0000 0001 0000 0000" /* ................ */
$"0000 0000 0000 0000 0000 0000 0000 0001" /* ................ */
$"7077 7063 0000 0000 0000 0000 0000 0000" /* pwpc............ */
$"0001 0000 0000 0101 0000 0000 0000 0000" /* ................ */
$"0000 0000 0000 0000 0034 0662 7574 746F" /* .........4.butto */
$"6E00 0000" /* n... */
};
data 'SIZE' (-1) {
$"58C0 0006 0000 0006 0000" /* XÀ........ */
};
data 'carb' (0) {
};

97
README.mac Normal file
View File

@ -0,0 +1,97 @@
README.mac - 12/03/2001 - Building FLTK under MacOS and OS X
------------------------------------------------------------
INTRODUCTION
------------
FLTK for Mac OS X is in pre-beta stage. Expect rapid changes to the
source code and build environment. Expect many crashes and funny
bliking patterns.
FLTK currently supports the following development environment on the
Mac OS X platform:
- gcc (Carbon)
- (Metrowerks CodeWarrior - future releases)
- (Apple Project Builder - future releases)
- (MPW - future releases)
FLTK for Mac is carbonized, i.e. all applicatiosn should run on Mac
OS 8.1 and higher and OS X without changes.
gcc (Carbon) - how to buid
--------------------------
Since the Max OS X command line build environment is based on BSD
Unix, the normal Unix build procedure as described in 'README'
applies. Compiled applications can only be started from within
the terminal though.
A 'resource fork' needs to be attached to applications to make
them visible to the Finder. A sample resource file is ./FL/mac.r .
To make 'hello' a full application, compile and link 'hello', then
change into the test directory and type:
> Rez -t APPL -c Fltk ../FL/mac.r -o hello
scripts
-------
When using Finder applications on source files (i.e. FileMerge)
I found the following script very useful. It adds resource forks to
all text files.
#!/bin/tcsh
setenv SET_MAC_TYPE "SetFile -t TEXT -c ttxt "
setenv F1MAC_N 7
echo "Setting Mac File Types. Please wait..."
echo "[1/"$F1MAC_N"]"
find . -name '*.H' -exec $SET_MAC_TYPE {} \;
echo "[2/"$F1MAC_N"]"
find . -name '*.h' -exec $SET_MAC_TYPE {} \;
echo "[3/"$F1MAC_N"]"
find . -name '*.c' -exec $SET_MAC_TYPE {} \;
echo "[4/"$F1MAC_N"]"
find . -name '*.cxx' -exec $SET_MAC_TYPE {} \;
echo "[5/"$F1MAC_N"]"
find . -name '*.fl' -exec $SET_MAC_TYPE {} \;
echo "[6/"$F1MAC_N"]"
find . -name 'make*' -exec $SET_MAC_TYPE {} \;
echo "[7/"$F1MAC_N"]"
find . -name 'Make*' -exec $SET_MAC_TYPE {} \;
echo "done."
other stuff
-----------
The following creator ID's 'FLTK', 'Fltk', 'FLID' and 'Flid' are
officially registered with Aplle Computers and can be used for
FLTK applications ('FLTK') and fluid files ('Flid').
All applications shout be ended with exit(0); or they might
hang until killed.
FLTK 1.0.x for Mac
------------------
FLTK 1.0.6 for Mac OS 8.x and OS 9.x is in beta stage and can be
downloaded from http://www.matthiasm.com/fltk/mac.shtml. The
archive contains build files for Metrowerks CodeWarrior 5 and 6.
FLTK 1.0.6 for Mac is not supported by the FLTK team and will not
be further developed by the author. Instead it will be replaced
by FLTK 1.1.x for Mac in the near future.

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.1 2001/11/27 17:44:06 easysw Exp $"
// "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.2 2001/12/04 03:03:17 matthiaswm Exp $"
//
// Double-buffered window code for the Fast Light Tool Kit (FLTK).
//
@ -149,7 +149,7 @@ void fl_begin_offscreen(GWorldPtr gWorld) {
PixMapHandle pm = GetGWorldPixMap(gWorld);
LockPixels(pm);
fl_window = (Window)prevPort;
SetPort( (GrafPtr)fl_window );
SetPort( GetWindowPort(fl_window) );
}
fl_push_no_clip();
}
@ -275,5 +275,5 @@ Fl_Double_Window::~Fl_Double_Window() {
}
//
// End of "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.1 2001/11/27 17:44:06 easysw Exp $".
// End of "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.2 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.10 2001/11/27 17:44:06 easysw Exp $"
// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.11 2001/12/04 03:03:17 matthiaswm Exp $"
//
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
//
@ -120,7 +120,7 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
CopyMask(
GetPortBitMapForCopyBits((GrafPtr)id),
GetPortBitMapForCopyBits((GrafPtr)mask),
GetPortBitMapForCopyBits((GrafPtr)fl_window),
GetPortBitMapForCopyBits( GetWindowPort(fl_window) ),
&src, &src, &dst);
}
else
@ -485,5 +485,5 @@ void Fl_Pixmap::desaturate() {
}
//
// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.10 2001/11/27 17:44:06 easysw Exp $".
// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.11 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_mac.cxx,v 1.1.2.1 2001/11/27 17:44:06 easysw Exp $"
// "$Id: Fl_mac.cxx,v 1.1.2.2 2001/12/04 03:03:17 matthiaswm Exp $"
//
// MacOS specific code for the Fast Light Tool Kit (FLTK).
//
@ -40,7 +40,7 @@
#include <unistd.h>
int fl_handle(const EventRef event);
int fl_handle(const EventRecord &event);
int fl_screen;
Handle fl_system_menu;
@ -183,13 +183,35 @@ static double do_queued_events( double time = 0.0 )
//++ SystemEventMask ( MouseUp )
been_here = 1;
}
#ifdef STRICTLY_CARBON
EventRef ev;
while ( ReceiveNextEvent(0, NULL, time, true, &ev) )
//static int evn = 0, evnn = 0;
//printf( "do events %d %g\n", evn++, time );
//if (time>0.1) time=0.1;
time = 0.1; // TODO: cheat
for (;;)
{
OSStatus status = ReceiveNextEvent(0, NULL, time, true, &ev);
if ( status==eventLoopTimedOutErr )
break;
// TODO: status is 'eventLoopTimedOutErr' if we didn't receive an event in time
// It is (against previous documentation) 0 whenever we receive an event
//printf( " status 0x%08x\n", status );
//printf( " events %d\n", evnn++ );
//if ( status!=0 ) break;
fl_handle(ev); //: handle the nullEvent to get mouse up events
break; // TODO: cheat
// SetRectRgn(rgn, ev.where.h, ev.where.v, ev.where.h+1, ev.where.v+1 );
}
#else
EventRecord ev;
unsigned long ticks = (int)(time*60.0);
while ( WaitNextEvent(everyEvent, &ev, ticks, rgn) )
{
fl_handle(ev); //: handle the nullEvent to get mouse up events
SetRectRgn(rgn, ev.where.h, ev.where.v, ev.where.h+1, ev.where.v+1 );
}
#endif
#if CONSOLIDATE_MOTION
if (send_motion && send_motion == fl_xmousewin) {
@ -276,6 +298,15 @@ static void HandleMenu( long mResult )
HiliteMenu( 0 );
}
static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
{
// call 'close' for every window. If any window returns unclosed, don't exit to the shell!
// Fl::handle(FL_CLOSE, fl_find(xid));
ExitToShell();
return noErr;
}
/**
* initialize the Mac toolboxes and set the default menubar
@ -299,6 +330,9 @@ void fl_open_display() {
// MaxApplZone();
// SysEnvirons( 1, &MacWorld );
// this thing call the quit-app function which in turn either quits our app or calls 'close' on all windows?!
// (don't know which one would be better)
AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false );
// OK, this is just ridiculous...
GetQDGlobalsArrow(&default_cursor);
@ -312,9 +346,18 @@ void fl_open_display() {
// create a minimal menu bar (\todo "about app", "FLTK settings")
// Any FLTK application may replace this menu later with its own bar.
fl_system_menu = GetNewMBar( 1 );
fl_system_menu = GetNewMBar( 128 );
if ( fl_system_menu ) {
SetMenuBar( fl_system_menu );
/* This is used to remove the Quit menu item from the File Drop Down in 'normal' Mac Apps
err = Gestalt(gestaltMenuMgrAttr, &response);
if ((err == noErr) && (response & gestaltMenuMgrAquaLayoutMask))
{
menu = GetMenuHandle( mFile );
DeleteMenuItem( menu, iQuit );
DeleteMenuItem( menu, iQuitSeparator );
}
*/
AppendResMenu( GetMenuHandle( 1 ), 'DRVR' );
}
@ -520,14 +563,19 @@ void Fl_X::MacGrowWindow(WindowPtr xid, const EventRecord &macevent)
*/
void Fl_X::MacDragWindow(WindowPtr xid, const EventRecord &macevent)
{
// copied from a Carbon sample file
Rect tempRect;
GetRegionBounds(GetGrayRgn(), &tempRect);
DragWindow(xid, macevent.where, &tempRect);
/*
BitMap bm;
GetQDGlobalsScreenBits(&bm);
DragWindow(xid, macevent.where, &(bm.bounds));
*/
Fl_Window *win = fl_find(xid);
if (!win) return;
Point pt; pt.h = 0; pt.v = 0;
SetPort((GrafPtr)xid); SetOrigin(0, 0); LocalToGlobal(&pt);
SetPort( GetWindowPort(xid) ); SetOrigin(0, 0); LocalToGlobal(&pt);
win->resize( pt.h, pt.v, win->w(), win->h() );
//++ win->x(pt.h); win->y(pt.v);
}
@ -575,7 +623,9 @@ void handleUpdateEvent( WindowPtr xid )
{
Fl_Window *window = fl_find( xid );
if ( !window ) return;
SetPort( (GrafPtr)xid );
GrafPtr oldPort;
GetPort( &oldPort );
SetPort( GetWindowPort(xid) );
Fl_X *i = Fl_X::i( window );
i->wait_for_expose = 0; //++ what about this flag?!
if ( window->damage() ) {
@ -589,6 +639,8 @@ void handleUpdateEvent( WindowPtr xid )
}
BeginUpdate( xid );
DrawControls(xid); // do we need this?
DrawGrowIcon(xid); // do we need this?
for ( Fl_X *cx = i->xidChildren; cx; cx = cx->xidNext )
{
cx->w->clear_damage(window->damage()|FL_DAMAGE_EXPOSE);
@ -598,16 +650,19 @@ void handleUpdateEvent( WindowPtr xid )
window->clear_damage(window->damage()|FL_DAMAGE_EXPOSE);
i->flush();
window->clear_damage();
EndUpdate( xid );
SetPort( oldPort );
}
/**
* dispatch all mac events
*/
#ifdef STRICTLY_CARBON
int fl_handle(const EventRef event)
{
EventRecord &macevent = *event;
UInt32 eventclass, eventkind;
static char buffer[5];
static unsigned short prevMod = 0;
@ -619,13 +674,23 @@ int fl_handle(const EventRef event)
eventkind = GetEventKind(event);
memcpy(buffer, &eventclass, 4);
buffer[4] = '\0';
printf("fl_event(): class = %s, kind = %d\n", buffer, eventkind);
#if 0
switch (macevent.what)
printf("fl_event(): class = %s, kind = %ld\n", buffer, eventkind);
}
#else
int fl_handle(const EventRecord &macevent)
{
static char buffer[2];
static unsigned short prevMod = 0;
static WindowPtr prevMouseDownXid;
WindowPtr xid;
int event = 0;
Fl_Window *window = 0L;
switch (macevent.what)
{
case mouseDown: {
// handle the differnt mouseDown events in various areas of the screen
int part = FindWindow(macevent.where, &xid);
printf("mousedown in part %d\n", part );
prevMouseDownXid = xid;
switch (part) {
case inDesk: break;
@ -635,15 +700,17 @@ int fl_handle(const EventRef event)
if (xid!=FrontWindow()) SelectWindow( xid ); //{ SelectWindow(xid); return 1; }
window = fl_find(xid);
if (!window) break;
SetPort((GrafPtr)xid); SetOrigin(0, 0);
SetPort( GetWindowPort(xid) ); SetOrigin(0, 0);
Fl::e_keysym = FL_Button+((macevent.modifiers&controlKey)?3:1); //++ simulate three button using modifiers
set_event_xy(macevent); checkdouble();
Fl::e_state |= ((macevent.modifiers&controlKey)?FL_BUTTON3:FL_BUTTON1);
return Fl::handle(FL_PUSH, window); }
case inDrag: Fl_X::MacDragWindow(xid, macevent); break;
case inGrow: Fl_X::MacGrowWindow(xid, macevent); break;
case inGoAway:
case inGoAway:
if (TrackGoAway(xid, macevent.where)) Fl::handle(FL_CLOSE, fl_find(xid));
// if there are no more windows, send a high-level quit event
if (!Fl_X::first) QuitAppleEventHandler( 0, 0, 0 );
break;
case inZoomIn: case inZoomOut:
// if (TrackBox(xid, event.where, part)) DoZoomWindow(xid, part);
@ -654,7 +721,7 @@ int fl_handle(const EventRef event)
xid = FrontWindow();
window = fl_find( xid );
if (!window) break;
SetPort((GrafPtr)xid);
SetPort( GetWindowPort(xid) );
SetOrigin(0, 0);
Fl::e_keysym = FL_Button+((Fl::e_state&FL_BUTTON1)?1:3); // macevent.modifiers ...
set_event_xy(macevent);
@ -732,7 +799,7 @@ int fl_handle(const EventRef event)
xid = FrontWindow();
window = fl_find( xid );
if (!window) break;
SetPort((GrafPtr)xid); SetOrigin(0, 0);
SetPort( GetWindowPort(xid) ); SetOrigin(0, 0);
set_event_xy(macevent);
#if CONSOLIDATE_MOTION
send_motion = fl_xmousewin = window;
@ -867,9 +934,12 @@ void Fl_X::make(Fl_Window* w)
Fl_Group::current(0);
fl_open_display();
int winclass = kDocumentWindowClass;
// int winattr = kCloseBoxAttribute | kCollapseBoxAttribute | kWindowStandardHandlerAttribute;
int winattr = kWindowCloseBoxAttribute
| kWindowCollapseBoxAttribute
//| kWindowStandardHandlerAttribute
;
// int winattr = kWindowStandardHandlerAttribute;
int winattr = 0;
// int winattr = 0;
int xp = w->x();
int yp = w->y();
int wp = w->w();
@ -880,8 +950,8 @@ void Fl_X::make(Fl_Window* w)
int minw = o->w(); if (minw > 100) minw = 100;
int minh = o->h(); if (minh > 100) minh = 100;
w->size_range(w->w() - o->w() + minw, w->h() - o->h() + minh, 0, 0);
// winattr |= kWindowFullZoomAttribute | kWindowResizeableAttribute;
winattr |= kWindowFullZoomAttribute;
winattr |= kWindowFullZoomAttribute | kWindowResizableAttribute;
//winattr |= kWindowFullZoomAttribute;
} else {
w->size_range(w->w(), w->h(), w->w(), w->h());
}
@ -1057,7 +1127,7 @@ void Fl_Window::make_current()
fl_window = i->xid;
current_ = this;
SetPort((GrafPtr)(i->xid));
SetPort( GetWindowPort(i->xid) );
int xp = 0, yp = 0;
Fl_Window *win = this;
@ -1088,7 +1158,7 @@ void Fl_Window::make_current()
}
fl_clip_region( 0 );
CopyRgn( fl_window_region, GetPortClipRegion((GrafPtr)(i->xid), 0) ); // for Fl_GL_Window
CopyRgn( fl_window_region, GetPortClipRegion( GetWindowPort(i->xid), 0) ); // for Fl_GL_Window
return;
}
@ -1153,6 +1223,6 @@ elapsedNanoseconds = AbsoluteToNanoseconds(elapsedTime);
*/
//
// End of "$Id: Fl_mac.cxx,v 1.1.2.1 2001/11/27 17:44:06 easysw Exp $".
// End of "$Id: Fl_mac.cxx,v 1.1.2.2 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_arci.cxx,v 1.4.2.5.2.1 2001/11/27 17:44:07 easysw Exp $"
// "$Id: fl_arci.cxx,v 1.4.2.5.2.2 2001/12/04 03:03:17 matthiaswm Exp $"
//
// Arc (integer) drawing functions for the Fast Light Tool Kit (FLTK).
//
@ -50,7 +50,7 @@ void fl_arc(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE__)
Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
a1 = a2-a1; a2 = 450-a2;
FrameArc(&r, a2, a1);
FrameArc(&r, (short int)a2, (short int)a1);
#else
XDrawArc(fl_display, fl_window, fl_gc, x,y,w-1,h-1, int(a1*64),int((a2-a1)*64));
#endif
@ -69,12 +69,12 @@ void fl_pie(int x,int y,int w,int h,double a1,double a2) {
#elif defined(__APPLE__)
Rect r; r.left=x; r.right=x+w; r.top=y; r.bottom=y+h;
a1 = a2-a1; a2 = 450-a2;
PaintArc(&r, a2, a1);
PaintArc(&r, (short int)a2, (short int)a1);
#else
XFillArc(fl_display, fl_window, fl_gc, x,y,w,h, int(a1*64),int((a2-a1)*64));
#endif
}
//
// End of "$Id: fl_arci.cxx,v 1.4.2.5.2.1 2001/11/27 17:44:07 easysw Exp $".
// End of "$Id: fl_arci.cxx,v 1.4.2.5.2.2 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_font_mac.cxx,v 1.1.2.1 2001/11/27 17:44:08 easysw Exp $"
// "$Id: fl_font_mac.cxx,v 1.1.2.2 2001/12/04 03:03:17 matthiaswm Exp $"
//
// MacOS font selection routines for the Fast Light Tool Kit (FLTK).
//
@ -106,7 +106,7 @@ Fl_Fontdesc* fl_fonts = built_in_table;
void fl_font(Fl_FontSize* s) {
fl_fontsize = s;
SetPort( (GrafPtr)fl_window );
SetPort( GetWindowPort(fl_window) );
TextFont(fl_fontsize->font); //: select font into current QuickDraw GC
TextFace(fl_fontsize->face);
TextSize(fl_fontsize->size);
@ -172,5 +172,5 @@ void fl_draw(const char* str, int x, int y) {
}
//
// End of "$Id: fl_font_mac.cxx,v 1.1.2.1 2001/11/27 17:44:08 easysw Exp $".
// End of "$Id: fl_font_mac.cxx,v 1.1.2.2 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_rect.cxx,v 1.10.2.4.2.2 2001/11/27 17:44:08 easysw Exp $"
// "$Id: fl_rect.cxx,v 1.10.2.4.2.3 2001/12/04 03:03:17 matthiaswm Exp $"
//
// Rectangle drawing routines for the Fast Light Tool Kit (FLTK).
//
@ -340,9 +340,9 @@ void fl_restore_clip() {
SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared
#elif defined(__APPLE__)
# if 1
CopyRgn( fl_window_region, GetPortClipRegion((GrafPtr)fl_window, 0) );
CopyRgn( fl_window_region, GetPortClipRegion( GetWindowPort(fl_window), 0) ); // changed
if ( r )
SectRgn( GetPortClipRegion((GrafPtr)fl_window, 0), r, GetPortClipRegion((GrafPtr)fl_window, 0) );
SectRgn( GetPortClipRegion( GetWindowPort(fl_window), 0), r, GetPortClipRegion( GetWindowPort(fl_window), 0) );
# else
if (r) SetClip(r);
else {
@ -494,5 +494,5 @@ int fl_clip_box(int x, int y, int w, int h, int& X, int& Y, int& W, int& H){
}
//
// End of "$Id: fl_rect.cxx,v 1.10.2.4.2.2 2001/11/27 17:44:08 easysw Exp $".
// End of "$Id: fl_rect.cxx,v 1.10.2.4.2.3 2001/12/04 03:03:17 matthiaswm Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_scroll_area.cxx,v 1.4.2.3.2.1 2001/11/27 17:44:08 easysw Exp $"
// "$Id: fl_scroll_area.cxx,v 1.4.2.3.2.2 2001/12/04 03:03:17 matthiaswm Exp $"
//
// Scrolling routines for the Fast Light Tool Kit (FLTK).
//
@ -76,8 +76,8 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
Rect dst = { dest_y, dest_x, dest_y+src_h, dest_x+src_w };
static RGBColor bg = { 0xffff, 0xffff, 0xffff }; RGBBackColor( &bg );
static RGBColor fg = { 0x0000, 0x0000, 0x0000 }; RGBForeColor( &fg );
CopyBits( GetPortBitMapForCopyBits((GrafPtr)fl_window),
GetPortBitMapForCopyBits((GrafPtr)fl_window), &src, &dst, srcCopy, 0L);
CopyBits( GetPortBitMapForCopyBits( GetWindowPort(fl_window) ),
GetPortBitMapForCopyBits( GetWindowPort(fl_window) ), &src, &dst, srcCopy, 0L);
#else
XCopyArea(fl_display, fl_window, fl_window, fl_gc,
src_x, src_y, src_w, src_h, dest_x, dest_y);
@ -96,5 +96,5 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy,
}
//
// End of "$Id: fl_scroll_area.cxx,v 1.4.2.3.2.1 2001/11/27 17:44:08 easysw Exp $".
// End of "$Id: fl_scroll_area.cxx,v 1.4.2.3.2.2 2001/12/04 03:03:17 matthiaswm Exp $".
//