Ejemplo n.º 1
0
int 
Java_org_squeak_android_SqueakVM_sendEvent(JNIEnv *env, jobject self, int 
					   type, int stamp,
					   int arg3, int arg4, int arg5,
					   int arg6, int arg7, int arg8) {

  sqInputEvent *event = sqNextEventPut();
  event->type = type;
  event->timeStamp = stamp;
  event->unused1 = arg3;
  event->unused2 = arg4;
  event->unused3 = arg5;
  event->unused4 = arg6;
  event->unused5 = arg7;
  event->windowIndex = arg8;
  if(inputSemaphoreIndex) signalSemaphoreWithIndex(inputSemaphoreIndex);
}
LRESULT CALLBACK HostWndProcW (HWND hwnd,
                              UINT message,
                              WPARAM wParam,
                              LPARAM lParam) {
  RECT boundingRect;

 switch(message){
  /*  mousing */

  case WM_MOUSEMOVE:
      recordMouseEvent(lastMessage);
      break;

  case WM_LBUTTONDOWN:
  case WM_RBUTTONDOWN:
  case WM_MBUTTONDOWN:
    if(GetFocus() != hwnd) SetFocus(hwnd);
    SetCapture(hwnd); /* capture mouse input */
      recordMouseEvent(lastMessage);
      break;

  case WM_LBUTTONUP:
  case WM_RBUTTONUP:
  case WM_MBUTTONUP:
    if(GetFocus() != hwnd) SetFocus(hwnd);
    ReleaseCapture(); /* release mouse capture */
      recordMouseEvent(lastMessage);
      break;


  /*keyboard events*/
  case WM_KEYDOWN:
  case WM_SYSKEYDOWN:
  case WM_KEYUP:
  case WM_SYSKEYUP:
  case WM_CHAR:
  case WM_SYSCHAR:
   recordKeyboardEvent(lastMessage);
   break;


  /*window events*/
  case WM_MOVE:
  case WM_SIZE:
    if ((GetWindowRect(hwnd, &boundingRect)) != 0){

	sqWindowEvent *windowevent = (sqWindowEvent*) sqNextEventPut();
	windowevent->type = EventTypeWindow;
	windowevent->timeStamp = lastMessage ? lastMessage->time : GetTickCount();
	windowevent->action = WindowEventMetricChange;
	windowevent->value1 = boundingRect.left ;
	windowevent->value2 = boundingRect.top;
	windowevent->value3 = boundingRect.right;
	windowevent->value4 = boundingRect.bottom;
	windowevent->windowIndex =(int) hwnd;
    }
    break;
	
  case WM_PAINT:	
    if ((GetWindowRect(hwnd, &boundingRect)) != 0){

	sqWindowEvent *windowevent = (sqWindowEvent*) sqNextEventPut();
	windowevent->type = EventTypeWindow;
	windowevent->timeStamp = lastMessage ? lastMessage->time : GetTickCount();
	windowevent->action = WindowEventPaint;
	windowevent->value1 = boundingRect.left ;
	windowevent->value2 = boundingRect.top;
	windowevent->value3 = boundingRect.right;
	windowevent->value4 = boundingRect.bottom;
	windowevent->windowIndex =(int) hwnd;
    }
    break;


  case WM_CLOSE:
    {
	sqWindowEvent *windowevent = (sqWindowEvent*) sqNextEventPut();
	windowevent->type = EventTypeWindow;
	windowevent->timeStamp = lastMessage ? lastMessage->time : GetTickCount();
	windowevent->action = WindowEventClose;
	windowevent->windowIndex =(int) hwnd;
    }
    break;
	
  case WM_ACTIVATE:
    {
        sqWindowEvent *windowevent = (sqWindowEvent*) sqNextEventPut();
        windowevent->type = EventTypeWindow;
        windowevent->timeStamp = lastMessage ? lastMessage->time : GetTickCount();
        if (wParam == WA_INACTIVE) windowevent->action = WindowEventIconise;
        else windowevent->action = WindowEventActivated;
       	windowevent->windowIndex =(int) hwnd;      
    }
    break; 
    	
  case WM_GETMINMAXINFO:
    {
        sqWindowEvent *windowevent = (sqWindowEvent*) sqNextEventPut();
        windowevent->type = EventTypeWindow;
        windowevent->timeStamp = lastMessage ? lastMessage->time : GetTickCount();
        if (IsIconic(hwnd) != 0)windowevent->action = WindowEventIconise;
        else windowevent->action = WindowEventActivated;
       	windowevent->windowIndex =(int) hwnd;      
    }
    break;   
 }
 return DefWindowProcW(hwnd,message,wParam,lParam);
}
Ejemplo n.º 3
0
/* get pending input from the device up to the baseEvt*/
void GetBufferedMouseTrail(DWORD firstTick, DWORD lastTick, 
			   sqMouseEvent *proto) 
{
  DIDEVICEOBJECTDATA  data;
  DWORD               count, seqNum, timeStamp;
  HRESULT             hr;

  sqMouseEvent *evt;
  static int lastX = 0;
  static int lastY = 0;
  static int nextX = 0;
  static int nextY = 0;
  int numExtra;

  /* printf("[%d@%d] -- %d\n", x, y, lastTick - firstTick);*/

  if(!lpDev) return;

  seqNum = 0;
  nextX = lastX;
  nextY = lastY;
  numExtra = 0;

  while(1) {
    count = 1;
    hr = lpDev->lpVtbl->GetDeviceData(lpDev,
				      sizeof(DIDEVICEOBJECTDATA), 
				      &data,
				      &count,
				      0);

    if (hr == DIERR_INPUTLOST) {
      /* re-aquire the device if possible */
      hr = lpDev->lpVtbl->Acquire(lpDev);
      if(FAILED(hr) || hr == S_FALSE) {
	/* sorry, can't do it */
	break;
      }
      continue; /* start over reading */
    }

    if(FAILED(hr) || count == 0) {
      /* no data or error */
      break;
    }

    /* if data arrived before first tick, ignore it */
    if(data.dwTimeStamp <= firstTick) continue;

    /* if data arrives at or after last tick, we're done */
    if(data.dwTimeStamp >= lastTick) break;

    /* otherwise process it */
    switch (data.dwOfs) {
      case DIMOFS_X:
      case DIMOFS_Y:
	if(seqNum != 0 && seqNum != data.dwSequence) {
	  /* flush last event */
	  if(numExtra < BUFFER_SIZE) {
	    xData[numExtra] = nextX;
	    yData[numExtra] = nextY;
	    stampData[numExtra] = timeStamp;
	    numExtra++;
	  }
	  /* printf("(%d)%d@%d\n", timeStamp - firstTick, x, y); */
	}
	timeStamp = data.dwTimeStamp;
	seqNum = data.dwSequence;
	if(data.dwOfs == DIMOFS_X) {
	  nextX += (int)data.dwData;
	} else {
	  nextY += (int)data.dwData;
	}
	break;
      /* ignore all buttons */
      case DIMOFS_BUTTON0:
      case DIMOFS_BUTTON1:
      case DIMOFS_BUTTON2:
      case DIMOFS_BUTTON3:
	break;
    }
  }

  if(seqNum != 0 && (numExtra < BUFFER_SIZE)) {
    xData[numExtra] = nextX;
    yData[numExtra] = nextY;
    stampData[numExtra] = timeStamp;
    numExtra++;
  }
  if(numExtra > 0) {
    int i;
    /* check if lastX and lastY match what we got from the proto event.
       we need this as windows settings can affect the mouse events,
       and we really want to fill the stuff obtained here so that it
       matches in/out as close as possible. */
    if(nextX != proto->x || nextY != proto->y) {
      /* rescale the trail to fit proto's expectations */
      int protoDx = proto->x - lastX;
      int protoDy = proto->y - lastY;
      int trailDx = nextX - lastX;
      int trailDy = nextY - lastY;

      for(i=0; i<numExtra;i++) {
	xData[i] = MulDiv(xData[i]-lastX, protoDx, trailDx) + lastX;
	yData[i] = MulDiv(yData[i]-lastY, protoDy, trailDy) + lastY;
      }
    }
    /* create the trail events */
    for(i=0; i<numExtra;i++) {
      evt = (sqMouseEvent*) sqNextEventPut();
      *evt = *proto;
      evt->x = xData[i];
      evt->y = yData[i];
      evt->timeStamp = stampData[i];
    }
  }
  /* remember x and y */
  lastX = proto->x;
  lastY = proto->y;
}