CV_IMPL int cvWaitKey (int maxWait) { EventRecord theEvent; // wait at least for one event (to allow mouse, etc. processing), exit if maxWait milliseconds passed (nullEvent) UInt32 start = TickCount(); int iters=0; do { // remaining time until maxWait is over UInt32 wait = EventTimeToTicks (maxWait / 1000.0) - (TickCount() - start); if ((int)wait <= 0) { if( maxWait > 0 && iters > 0 ) break; wait = 1; } iters++; WaitNextEvent (everyEvent, &theEvent, maxWait > 0 ? wait : kDurationForever, NULL); } while (lastKey == NO_KEY && theEvent.what != nullEvent); int key = lastKey; lastKey = NO_KEY; return key; }
static void IdleMovie() { if (mMovieController) { EventRecord myEvent; myEvent.what = nullEvent; myEvent.message = 0; myEvent.modifiers = 0; myEvent.when = EventTimeToTicks(GetCurrentEventTime()); MCIsPlayerEvent(mMovieController, &myEvent); } }
void PoofItGood( Point centerPt ) { CGRect box; WindowRef window; Rect bounds; CGContextRef context; CGImageRef image; float windowWidth; float windowHeight; int i; image = GetThePoofImage(); if ( image == NULL ) goto Bail; windowWidth = CGImageGetWidth( image ) / NUMBER_OF_POOF_ANIM_FRAMES; windowHeight = CGImageGetHeight( image ); // Start our animation bounds at the first item in the animation strip box.origin.x = box.origin.y = 0; box.size.width = CGImageGetWidth( image ); box.size.height = CGImageGetHeight( image ); bounds.top = centerPt.v - (SInt16)(windowHeight / 2); bounds.left = centerPt.h - (SInt16)(windowWidth / 2); bounds.bottom = bounds.top + (SInt16)windowHeight; bounds.right = bounds.left + (SInt16)windowWidth; CreateNewWindow( kOverlayWindowClass, 0, &bounds, &window ); CreateCGContextForPort( GetWindowPort( window ), &context ); ShowWindow( window ); for ( i = 1; i <= NUMBER_OF_POOF_ANIM_FRAMES; i++ ) { CGContextClearRect( context, box ); CGContextDrawImage( context, box, image ); CGContextFlush( context ); Delay( EventTimeToTicks( POOF_ANIMATION_DELAY ), NULL ); box.origin.x -= windowWidth; } CGContextRelease( context ); CGImageRelease( image ); DisposeWindow( window ); Bail: return; }
static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; OSStatus err = noErr ; UInt32 attributes; WindowRef windowRef ; wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, sizeof( WindowRef ), NULL, &windowRef ); switch( GetEventKind( event ) ) { case kEventWindowUpdate : if ( !wxPendingDelete.Member(toplevelWindow) ) toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventWindowActivated : toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; result = noErr ; break ; case kEventWindowDeactivated : toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; result = noErr ; break ; case kEventWindowShown : toplevelWindow->Refresh() ; result = noErr ; break ; case kEventWindowClose : toplevelWindow->Close() ; result = noErr ; break ; case kEventWindowBoundsChanged : err = GetEventParameter( event, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); if ( err == noErr ) { Rect newContentRect ; GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( newContentRect ), NULL, &newContentRect ); toplevelWindow->SetSize( newContentRect.left , newContentRect.top , newContentRect.right - newContentRect.left , newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); result = noErr; } break ; case kEventWindowBoundsChanging : err = GetEventParameter( event, kEventParamAttributes, typeUInt32, NULL, sizeof( UInt32 ), NULL, &attributes ); if ( err == noErr ) { Rect newContentRect ; GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL, sizeof( newContentRect ), NULL, &newContentRect ); wxSize formerSize = toplevelWindow->GetSize() ; if ( (attributes & kWindowBoundsChangeSizeChanged ) || ( attributes & kWindowBoundsChangeOriginChanged ) ) toplevelWindow->SetSize( newContentRect.left , newContentRect.top , newContentRect.right - newContentRect.left , newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); int x , y , w , h ; toplevelWindow->GetPosition( &x , &y ) ; toplevelWindow->GetSize( &w , &h ) ; Rect adjustedRect = { y , x , y + h , x + w } ; if ( !EqualRect( &newContentRect , &adjustedRect ) ) { SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ; } if ( toplevelWindow->GetSize() != formerSize ) toplevelWindow->Update() ; result = noErr ; } break ; default : break ; } return result ; }
pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; Point point ; UInt32 modifiers = 0; EventMouseButton button = 0 ; UInt32 click = 0 ; GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof( Point ), NULL, &point ); GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof( UInt32 ), NULL, &modifiers ); GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, sizeof( EventMouseButton ), NULL, &button ); GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, sizeof( UInt32 ), NULL, &click ); if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) modifiers += btnState ; // temporary hack to support true two button mouse if ( button == kEventMouseButtonSecondary ) { modifiers |= controlKey ; } WindowRef window ; short windowPart = ::FindWindow(point, &window); // either we really are active or we are capturing mouse events if ( (IsWindowActive(window) && windowPart == inContent) || (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) ) { switch ( GetEventKind( event ) ) { case kEventMouseDown : toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseUp : toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseMoved : wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseDragged : toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseWheelMoved : { //bClearTooltip = false; EventMouseWheelAxis axis = kEventMouseWheelAxisY; SInt32 delta = 0; Point mouseLoc = {0, 0}; if (::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(EventMouseWheelAxis), NULL, &axis) == noErr && ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(SInt32), NULL, &delta) == noErr && ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouseLoc) == noErr) { wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL); wheelEvent.m_x = mouseLoc.h; wheelEvent.m_y = mouseLoc.v; wheelEvent.m_wheelRotation = delta; wheelEvent.m_wheelDelta = 1; wheelEvent.m_linesPerAction = 1; wxWindow* currentMouseWindow = NULL; wxWindow::MacGetWindowFromPoint(wxPoint(mouseLoc.h, mouseLoc.v), ¤tMouseWindow); if (currentMouseWindow) { currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent); result = noErr; } } } break ; default : break ; } } return result ; }
static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; wxWindow* focus = wxWindow::FindFocus() ; char charCode ; UInt32 keyCode ; UInt32 modifiers ; Point point ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof( Point ), NULL, &point ); UInt32 message = (keyCode << 8) + charCode; switch( GetEventKind( event ) ) { case kEventRawKeyRepeat : case kEventRawKeyDown : { WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , message , modifiers , when , point.h , point.v ) ) { result = noErr ; } wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; } break ; case kEventRawKeyUp : if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( focus , message , modifiers , when , point.h , point.v ) ) { result = noErr ; } break ; case kEventRawKeyModifiersChanged : { wxKeyEvent event(wxEVT_KEY_DOWN); event.m_shiftDown = modifiers & shiftKey; event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; event.m_x = point.h; event.m_y = point.v; event.SetTimestamp(when); wxWindow* focus = wxWindow::FindFocus() ; event.SetEventObject(focus); if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) { event.m_keyCode = WXK_CONTROL ; event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) { event.m_keyCode = WXK_SHIFT ; event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) { event.m_keyCode = WXK_ALT ; event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey ) { event.m_keyCode = WXK_COMMAND ; event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } wxTheApp->s_lastModifiers = modifiers ; } break ; } return result ; }
// --------------------------------------------------------------------------- // // ------------ void bVirtualStyle::draw(bStdWait& wt){ _bTrace_("bVirtualStyle::draw",false); _tm_("drawing "+_name); if(!_vis){ //_tm_("style not visible"); return; } int i,ri=1; unsigned int t1,t0=EventTimeToTicks(GetCurrentEventTime()); bScreenObj* scr; _scale=scalemgr->get()->coef(); _ctx->setScaleRef(_scaleref); _ctx->setUnitCoef(_unitcoef); _ctx->setElement(NULL); _tm_("applyglobals"); if(!applyglobals()){ //_tm_("globals not applied"); return; } //_tm_("loop"); //int x; //#warning _valbounds->count()-1 ou _valbounds->count() for(i=1;i<=_nbpass;i++){ if(_sort>=0){ // ******************** // TRI CROISSANT // ******************** _ctx->reset(); _ctx->setElement(NULL); findgoodstylesruns(i,1); t1=EventTimeToTicks(GetCurrentEventTime()); if(t1-t0>60){ _ctx->flush(); t0=t1; } // 15/05/2009 -> PLUS DE FLUIDITE EN METTANT LE PROGRESS EN DEHORS DU TEST FLUSH wt.set_progress(0); if(!wt.get_progress()){ break; } if(!_screenobjs->get(1,&scr)){ break; } _ctx->setElement(scr); /* CONDITION 20/01/09 if(!applyconditions()){ continue; } */ for(ri=1;ri<=_goodstyleruns->count();ri++){ if(!applystylesruns(ri)){ continue; } if(!applystylesruns(scr,ri)){ continue; } (*_drawp)(_ctx); } } else{ // ******************** // TRI DECROISSANT // ******************** _ctx->reset(); _ctx->setElement(NULL); findgoodstylesruns(i,1); t1=EventTimeToTicks(GetCurrentEventTime()); if(t1-t0>60){ _ctx->flush(); t0=t1; } // 15/05/2009 -> PLUS DE FLUIDITE EN METTANT LE PROGRESS EN DEHORS DU TEST FLUSH wt.set_progress(0); if(!wt.get_progress()){ break; } if(!_screenobjs->get(1,&scr)){ break; } _ctx->setElement(scr); /* CONDITION 20/01/09 if(!applyconditions()){ continue; } */ for(ri=_goodstyleruns->count();ri>0;ri--){ if(!applystylesruns(ri)){ continue; } if(!applystylesruns(scr,ri)){ continue; } (*_drawp)(_ctx); } } } _ctx->reset(); }