summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2001-12-04 03:03:17 +0000
committerMatthias Melcher <fltk@matthiasm.com>2001-12-04 03:03:17 +0000
commit1d06051e8c1769e2fead7ef38c7beff65d899b42 (patch)
treefb238bc7f5e6799f356e14337461029ebdf3e1bb /src
parent9e6b78b5ca25aaf10a5d7414efc4257ed3741471 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Double_Window.cxx6
-rw-r--r--src/Fl_Pixmap.cxx6
-rw-r--r--src/Fl_mac.cxx116
-rw-r--r--src/fl_arci.cxx8
-rw-r--r--src/fl_font_mac.cxx6
-rw-r--r--src/fl_rect.cxx8
-rw-r--r--src/fl_scroll_area.cxx8
7 files changed, 114 insertions, 44 deletions
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx
index 6e2a741bc..8145dfdf1 100644
--- a/src/Fl_Double_Window.cxx
+++ b/src/Fl_Double_Window.cxx
@@ -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 $".
//
diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx
index aac769590..83dc96593 100644
--- a/src/Fl_Pixmap.cxx
+++ b/src/Fl_Pixmap.cxx
@@ -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 $".
//
diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx
index 087795a27..9cab1e8e3 100644
--- a/src/Fl_mac.cxx
+++ b/src/Fl_mac.cxx
@@ -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 $".
//
diff --git a/src/fl_arci.cxx b/src/fl_arci.cxx
index 7ea47f2f9..1974b5aee 100644
--- a/src/fl_arci.cxx
+++ b/src/fl_arci.cxx
@@ -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 $".
//
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx
index 5d8e61247..5afc378a2 100644
--- a/src/fl_font_mac.cxx
+++ b/src/fl_font_mac.cxx
@@ -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 $".
//
diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx
index 822961a7b..ea4f9c08e 100644
--- a/src/fl_rect.cxx
+++ b/src/fl_rect.cxx
@@ -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 $".
//
diff --git a/src/fl_scroll_area.cxx b/src/fl_scroll_area.cxx
index 632e094d2..b0383354d 100644
--- a/src/fl_scroll_area.cxx
+++ b/src/fl_scroll_area.cxx
@@ -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 $".
//