diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Double_Window.cxx | 34 | ||||
| -rw-r--r-- | src/Fl_grab.cxx | 17 | ||||
| -rw-r--r-- | src/Fl_mac.cxx | 130 | ||||
| -rw-r--r-- | src/fl_font_mac.cxx | 6 | ||||
| -rw-r--r-- | src/fl_rect.cxx | 23 |
5 files changed, 167 insertions, 43 deletions
diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index 9bf615e2d..a36b61386 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.3 2001/12/06 00:17:47 matthiaswm Exp $" +// "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.4 2001/12/20 05:27:14 matthiaswm Exp $" // // Double-buffered window code for the Fast Light Tool Kit (FLTK). // @@ -146,10 +146,18 @@ void fl_begin_offscreen(GWorldPtr gWorld) { GetGWorld( &prevPort, &prevGD ); if ( gWorld ) { - SetGWorld( gWorld, 0L ); // sets the correct port + SetGWorld( gWorld, 0 ); // sets the correct port PixMapHandle pm = GetGWorldPixMap(gWorld); - LockPixels(pm); - fl_window = GetWindowFromPort( gWorld ); + Boolean ret = LockPixels(pm); + if ( ret == false ) + { + Rect rect; + GetPortBounds( gWorld, &rect ); + UpdateGWorld( &gWorld, 0, &rect, 0, 0, 0 ); + pm = GetGWorldPixMap( gWorld ); + LockPixels( pm ); + } + fl_window = 0; } fl_push_no_clip(); } @@ -190,7 +198,7 @@ void Fl_Double_Window::flush(int eraseoverlay) { #ifdef __APPLE__ // the Apple OS X window manager double buffers ALL windows anyway, so there is no need to waste memory and time // BTW: Windows2000 and later also forces doublebuffering if transparent windows are beeing used (alpha channel) - if ( !QDIsPortBuffered( GetWindowPort(myi->xid) ) ) + if ( ( !QDIsPortBuffered( GetWindowPort(myi->xid) ) ) || force_doublebuffering_ ) myi->other_xid = fl_create_offscreen(w(), h()); #else myi->other_xid = fl_create_offscreen(w(), h()); @@ -233,12 +241,14 @@ void Fl_Double_Window::flush(int eraseoverlay) { DeleteDC(fl_gc); fl_gc = _sgc; #elif defined(__APPLE__) - if ( myi->other_xid ) fl_begin_offscreen( myi->other_xid ); - fl_restore_clip(); // duplicate region into new gc - draw(); - if ( myi->other_xid ) fl_end_offscreen(); - } else { - fl_clip_region( 0 ); + if ( myi->other_xid ) { + fl_begin_offscreen( myi->other_xid ); + fl_clip_region( 0 ); + draw(); + fl_end_offscreen(); + } else { + draw(); + } #else // X: fl_window = myi->other_xid; draw(); @@ -286,5 +296,5 @@ Fl_Double_Window::~Fl_Double_Window() { } // -// End of "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.3 2001/12/06 00:17:47 matthiaswm Exp $". +// End of "$Id: Fl_Double_Window.cxx,v 1.12.2.4.2.4 2001/12/20 05:27:14 matthiaswm Exp $". // diff --git a/src/Fl_grab.cxx b/src/Fl_grab.cxx index 56c13ba47..ee760b159 100644 --- a/src/Fl_grab.cxx +++ b/src/Fl_grab.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_grab.cxx,v 1.1.2.4.2.3 2001/12/12 07:50:37 matthiaswm Exp $" +// "$Id: Fl_grab.cxx,v 1.1.2.4.2.4 2001/12/20 05:27:14 matthiaswm Exp $" // // Grab/release code for the Fast Light Tool Kit (FLTK). // @@ -44,6 +44,11 @@ extern void fl_fix_focus(); // in Fl.cxx extern HWND fl_capture; #endif +#ifdef __APPLE__ +// MacOS Carbon does not seem to have a mechanism to grab the mouse pointer +extern WindowRef fl_capture; +#endif + void Fl::grab(Fl_Window* w) { if (w) { if (!grab_) { @@ -51,7 +56,9 @@ void Fl::grab(Fl_Window* w) { SetActiveWindow(fl_capture = fl_xid(first_window())); SetCapture(fl_capture); #elif defined(__APPLE__) - BeginAppModalStateForWindow( fl_xid(first_window()) ); +// BeginAppModalStateForWindow( fl_xid(first_window()) ); //+ please check if we need this (sample app?) + fl_capture = fl_xid( first_window() ); + SetUserFocusWindow( fl_capture ); #else XGrabPointer(fl_display, fl_xid(first_window()), @@ -78,7 +85,9 @@ void Fl::grab(Fl_Window* w) { fl_capture = 0; ReleaseCapture(); #elif defined(__APPLE__) - EndAppModalStateForWindow( fl_xid(first_window()) ); +// EndAppModalStateForWindow( fl_xid(first_window()) ); //+ Please check if we need this + fl_capture = 0; + SetUserFocusWindow( (WindowRef)kUserFocusAuto ); #else XUngrabKeyboard(fl_display, fl_event_time); XUngrabPointer(fl_display, fl_event_time); @@ -93,5 +102,5 @@ void Fl::grab(Fl_Window* w) { } // -// End of "$Id: Fl_grab.cxx,v 1.1.2.4.2.3 2001/12/12 07:50:37 matthiaswm Exp $". +// End of "$Id: Fl_grab.cxx,v 1.1.2.4.2.4 2001/12/20 05:27:14 matthiaswm Exp $". // diff --git a/src/Fl_mac.cxx b/src/Fl_mac.cxx index 5ccbd3045..d3547afa9 100644 --- a/src/Fl_mac.cxx +++ b/src/Fl_mac.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_mac.cxx,v 1.1.2.7 2001/12/19 09:10:00 matthiaswm Exp $" +// "$Id: Fl_mac.cxx,v 1.1.2.8 2001/12/20 05:27:14 matthiaswm Exp $" // // MacOS specific code for the Fast Light Tool Kit (FLTK). // @@ -23,6 +23,22 @@ // Please report all bugs and problems to "fltk-bugs@fltk.org". // +/** + * From the inner edge of a MetroWerks CodeWarrior CD: + * (without permission) + * + * Three Compiles for 68Ks under the sky, + * Seven Compiles for PPCs in their fragments of code, + * Nine Compiles for Mortal Carbon doomed to die, + * One Compile for Mach-O Cocoa on its Mach-O throne, + * in the Land of MacOS X where the Drop-Shadows lie. + * + * One Compile to link them all, One Compile to merge them, + * One Compile to copy them all and in the bundle bind them, + * in the Land of MacOS X where the Drop-Shadows lie. + */ + + // we don't need the following definition because we deliver only // true mouse moves. On very slow systems however, this flag may // still be useful. @@ -178,6 +194,50 @@ void printMacEvent( const EventRecord &ev ) printf("Event: w:0x%04x m:0x%08x mod:0x%04x flags:%08x x:%d, y:%d\n", ev.what, ev.message, ev.modifiers, 0, ev.where.h, ev.where.v ); } + + +WindowRef fl_capture = 0; // we need this to compensate for a missing(?) mouse capture +WindowRef fl_os_capture = 0; // the dispatch handler will redirect mose move and drag events to these windows + +/** + * We can make every event pass through this function + * - mouse events need to be manipulated to use a mouse focus window + * - keyboard, mouse and some window events need to quit the Apple Event Loop + * so FLTK can continue its own management + */ +pascal OSStatus carbonDispatchHandler( EventHandlerCallRef nextHandler, EventRef event, void *userData ) +{ + OSStatus ret = eventNotHandledErr; + switch ( GetEventClass( event ) ) + { + case kEventClassMouse: + switch ( GetEventKind( event ) ) + { + case kEventMouseUp: + case kEventMouseMoved: + case kEventMouseDragged: + if ( fl_capture ) + ret = SendEventToEventTarget( event, GetWindowEventTarget( fl_capture ) ); + else if ( fl_os_capture ) + ret = SendEventToEventTarget( event, GetWindowEventTarget( fl_os_capture ) ); + break; + } + break; + } + if ( ret == eventNotHandledErr ) + ret = CallNextEventHandler( nextHandler, event ); // let the OS handle the activation, but continue to get a click-through effect + QuitApplicationEventLoop(); + return ret; +} + +/** + * this callback simply quits the main event loop handler, so FLTK can do its magic + */ +static void timerProcCB( EventLoopTimerRef, void* ) +{ + QuitApplicationEventLoop(); +} + /** * This function iss the central event handler. * It reads events from the event queue using the given maximum time @@ -222,7 +282,38 @@ static double do_queued_events( double time = 0.0 ) OSStatus ret; EventRef ev; static EventTargetRef target = 0; - if ( !target ) target = GetEventDispatcherTarget(); + static EventLoopTimerRef timer = 0; + if ( !target ) + { + target = GetEventDispatcherTarget(); + + EventHandlerUPP dispatchHandler = NewEventHandlerUPP( carbonDispatchHandler ); // will not be disposed by Carbon... + static EventTypeSpec dispatchEvents[] = { + { kEventClassWindow, kEventWindowShown }, + { kEventClassWindow, kEventWindowHidden }, + { kEventClassWindow, kEventWindowActivated }, + { kEventClassWindow, kEventWindowDeactivated }, + { kEventClassWindow, kEventWindowClose }, + { kEventClassKeyboard, kEventRawKeyDown }, + { kEventClassKeyboard, kEventRawKeyRepeat }, + { kEventClassKeyboard, kEventRawKeyUp }, + { kEventClassKeyboard, kEventRawKeyModifiersChanged }, + { kEventClassMouse, kEventMouseDown }, + { kEventClassMouse, kEventMouseUp }, + { kEventClassMouse, kEventMouseMoved }, + { kEventClassMouse, kEventMouseWheelMoved }, + { kEventClassMouse, kEventMouseDragged } }; + ret = InstallEventHandler( target, dispatchHandler, 14, dispatchEvents, 0, 0L ); + ret = InstallEventLoopTimer( GetMainEventLoop(), 0, 0, NewEventLoopTimerUPP( timerProcCB ), 0, &timer ); + } + + // InstallEventLoopTimer(); SetEventLoopNextFireTime(); + if ( time > 0.0 ) + SetEventLoopTimerNextFireTime( timer, time ); + RunApplicationEventLoop(); + // ;;;; printf("Left Event Loop!\n"); + //RunCurrentEventLoop(0.1); + /* ret = ReceiveNextEvent( 0, NULL, time, true, &ev ); if ( ret == noErr ) { @@ -235,6 +326,7 @@ static double do_queued_events( double time = 0.0 ) } ReleaseEvent( ev ); } + */ #else EventRecord ev; unsigned long ticks = (int)(time*60.0); // setting ticks to 7fffffff will wait forever @@ -385,11 +477,10 @@ pascal OSStatus carbonWindowHandler( EventHandlerCallRef nextHandler, EventRef e if ( !window->parent() ) Fl::handle(FL_UNFOCUS, window); break; case kEventWindowClose: - //printf("Close\n"); - Fl::handle( FL_CLOSE, window ); + Fl::handle( FL_CLOSE, window ); // this might or might not close the window // if there are no more windows, send a high-level quit event if (!Fl_X::first) QuitAppleEventHandler( 0, 0, 0 ); - ret = noErr; + ret = noErr; // returning noErr tells Carbon to stop following up on this event break; } @@ -456,26 +547,30 @@ pascal OSStatus carbonMouseHandler( EventHandlerCallRef nextHandler, EventRef ev switch ( GetEventKind( event ) ) { case kEventMouseDown: - //printf("mouse down window %08x (%08x) [%08x]\n", window, xid, nextHandler ); + // ;;;; printf("Carb-win-hdlr: mouse down (x:%d, y:d)\n", pos.h, pos.v ); part = FindWindow( pos, &tempXid ); if ( part != inContent ) return CallNextEventHandler( nextHandler, event ); // let the OS handle this for us if ( !IsWindowActive( xid ) ) CallNextEventHandler( nextHandler, event ); // let the OS handle the activation, but continue to get a click-through effect // normal handling of mouse-down follows + fl_os_capture = xid; sendEvent = FL_PUSH; Fl::e_is_click = 1; px = pos.h; py = pos.v; - Fl::e_clicks = clickCount; + Fl::e_clicks = clickCount-1; // fall through case kEventMouseUp: - if (!window) break; + // ;;;; if ( !sendEvent ) printf("Carb-win-hdlr: mouse up (x:%d, y:d)\n", pos.h, pos.v ); + if ( !window ) break; if ( !sendEvent ) sendEvent = FL_RELEASE; Fl::e_keysym = keysym[ btn ]; // fall through case kEventMouseMoved: + // ;;;; if ( !sendEvent ) printf("Carb-win-hdlr: mouse moved (x:%d, y:d)\n", pos.h, pos.v ); if ( !sendEvent ) { sendEvent = FL_MOVE; chord = 0; } // fall through case kEventMouseDragged: + // ;;;; if ( !sendEvent ) printf("Carb-win-hdlr: mouse dragged (x:%d, y:d)\n", pos.h, pos.v ); if ( !sendEvent ) { sendEvent = FL_DRAG; if (abs(pos.h-px)>5 || abs(pos.v-py)>5) Fl::e_is_click = 0; @@ -542,6 +637,7 @@ pascal OSStatus carbonKeyboardHandler( EventHandlerCallRef nextHandler, EventRef GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); char key; GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key ); + // ;;;; printf( "kb: %08x %08x %02x %04x\n", mods, keyCode, key, GetEventKind( event ) ); switch ( GetEventKind( event ) ) { case kEventRawKeyDown: @@ -551,10 +647,12 @@ pascal OSStatus carbonKeyboardHandler( EventHandlerCallRef nextHandler, EventRef case kEventRawKeyUp: if ( !sendEvent ) sendEvent = FL_KEYUP; Fl::e_keysym = macKeyLookUp[ keyCode & 0x7f ]; - if ( key=='\t' || key==27 || key>=32 ) - { + if ( key=='\t' || key==27 || ( key>=32 && key!=0x7f ) ) { buffer[0] = key; Fl::e_length = 1; + } else if ( key==3 || key==0x0d ) { + buffer[0] = 0x0d; + Fl::e_length = 1; } else { buffer[0] = 0; Fl::e_length = 0; @@ -782,7 +880,7 @@ static unsigned short macKeyLookUp[128] = FL_F+5, FL_F+6, FL_F+7, FL_F+3, FL_F+8, FL_F+9, 0, FL_F+11, 0, 0, 0, 0, 0, FL_F+10, 0, FL_F+12, - 0, 0, FL_Pause, FL_Home, FL_Page_Up, 0, FL_F+4, 0, + 0, 0, FL_Pause, FL_Home, FL_Page_Up, FL_Delete, FL_F+4, 0, FL_F+2, FL_Page_Down, FL_F+1, FL_Left, FL_Right, FL_Down, FL_Up, 0, }; @@ -1217,6 +1315,7 @@ void Fl_X::make(Fl_Window* w) //++ hmmm, this should maybe set by the activate event?! Fl::handle(FL_FOCUS, w); //++ if (w->modal()) { Fl::modal_ = w; fl_fix_focus(); } + // ;;;; printf("Created subwindow %08x (%08x)\n", w, x->xid ); } else // create a desktop window { @@ -1360,6 +1459,7 @@ void Fl_X::make(Fl_Window* w) //++ hmmm, this should maybe set by the activate event?! Fl::handle(FL_FOCUS, w); //++ if (w->modal()) { Fl::modal_ = w; fl_fix_focus(); } + //;;;; printf("Created top level window %08x (%08x)\n", w, x->xid ); } } @@ -1432,7 +1532,7 @@ void Fl_Window::show() { { if ( IsWindowCollapsed( i->xid ) ) CollapseWindow( i->xid, false ); //++ do we need to do grab and icon handling here? - /*if (!fl_capture)*/ + if (!fl_capture) //++ Do we need this? It should keep the mouse modal window in front BringToFront(i->xid); } } @@ -1470,7 +1570,6 @@ void Fl_Window::make_current() { if ( !fl_window_region ) fl_window_region = NewRgn(); - //- printf(" make current: 0x%08x\n", this); fl_window = i->xid; current_ = this; @@ -1590,7 +1689,10 @@ elapsedNanoseconds = AbsoluteToNanoseconds(elapsedTime); */ +//++ when using OpenGL in a Mach-O executable and include<aglMacro.h> +//++ we MUST call aglConfigure(AGL_TARGET_OS_MAC_OSX, GL_TRUE); + // -// End of "$Id: Fl_mac.cxx,v 1.1.2.7 2001/12/19 09:10:00 matthiaswm Exp $". +// End of "$Id: Fl_mac.cxx,v 1.1.2.8 2001/12/20 05:27:14 matthiaswm Exp $". // diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index 5afc378a2..f35b22544 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.2 2001/12/04 03:03:17 matthiaswm Exp $" +// "$Id: fl_font_mac.cxx,v 1.1.2.3 2001/12/20 05:27:14 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( GetWindowPort(fl_window) ); + if (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.2 2001/12/04 03:03:17 matthiaswm Exp $". +// End of "$Id: fl_font_mac.cxx,v 1.1.2.3 2001/12/20 05:27:14 matthiaswm Exp $". // diff --git a/src/fl_rect.cxx b/src/fl_rect.cxx index 3d55405e1..5675961ca 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.5 2001/12/18 00:24:01 matthiaswm Exp $" +// "$Id: fl_rect.cxx,v 1.10.2.4.2.6 2001/12/20 05:27:14 matthiaswm Exp $" // // Rectangle drawing routines for the Fast Light Tool Kit (FLTK). // @@ -340,14 +340,17 @@ void fl_restore_clip() { SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared #elif defined(__APPLE__) # if 1 - GrafPtr port = GetWindowPort( fl_window ); - if ( port ) { // port will be NULL if we are using a GWorld (and fl_window_region is invalid) - RgnHandle portClip = NewRgn(); - CopyRgn( fl_window_region, portClip ); // changed - if ( r ) - SectRgn( portClip, r, portClip ); - SetPortClipRegion( port, portClip ); - DisposeRgn( portClip ); + if ( fl_window ) + { + GrafPtr port = GetWindowPort( fl_window ); + if ( port ) { // port will be NULL if we are using a GWorld (and fl_window_region is invalid) + RgnHandle portClip = NewRgn(); + CopyRgn( fl_window_region, portClip ); // changed + if ( r ) + SectRgn( portClip, r, portClip ); + SetPortClipRegion( port, portClip ); + DisposeRgn( portClip ); + } } # else if (r) SetClip(r); @@ -500,5 +503,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.5 2001/12/18 00:24:01 matthiaswm Exp $". +// End of "$Id: fl_rect.cxx,v 1.10.2.4.2.6 2001/12/20 05:27:14 matthiaswm Exp $". // |
