+ if(!buf[0]) return eventNotHandledErr; // shouldn't happen
+ // odd, when the ctrl key is pressed a-"`" become 1-31, this brings them back to the corect values
+ if(modifiers & controlKey && buf[0] < 32) buf[0] += 0x60;
+ break;
+ }
+ }
+
+ if(eKind == kEventRawKeyUp)
+ surface->KeyReleased(js);
+ else
+ surface->KeyPressed(js);
+ return noErr;
+ }
+ case kEventRawKeyModifiersChanged: {
+ const static struct {
+ UInt32 mask;
+ jstring xwtKey;
+ } modifiersTable[] = {
+ { shiftKey, JvNewStringLatin1("shift") },
+ { alphaLock, JvNewStringLatin1("caps_lock") },
+ { controlKey, JvNewStringLatin1("control") },
+ { optionKey, JvNewStringLatin1("alt") },
+ { kEventKeyModifierNumLockMask, JvNewStringLatin1("num_lock") },
+ { 0, 0 }
+ };
+
+ UInt32 oldModifiers = (UInt32) surface->modifiers;
+ UInt32 newModifiers;
+ r = GetEventParameter(e,kEventParamKeyModifiers,typeUInt32,NULL,sizeof(newModifiers),NULL,&newModifiers);
+ checkStatus(r,"GetEventParameter");
+ surface->modifiers = (jint) newModifiers;
+ UInt32 changedModifiers = oldModifiers ^ newModifiers;
+
+ for(int i=0;modifiersTable[i].mask;i++) {
+ UInt32 mask = modifiersTable[i].mask;
+ if(!(changedModifiers & mask)) continue;
+ if(newModifiers & mask)
+ surface->KeyPressed(modifiersTable[i].xwtKey);
+ else
+ surface->KeyReleased(modifiersTable[i].xwtKey);
+ }
+ return noErr;
+ }
+ }
+ break;
+ case kEventClassMouse:
+ // The default handler gets first dibs on mouse events
+ // (this catches the titlebar, resize box, etc)
+ r = CallNextEventHandler(handler, e);
+ if(r != eventNotHandledErr && eKind != kEventMouseMoved && eKind != kEventMouseDragged) return r;
+
+ switch(eKind) {
+ case kEventMouseMoved:
+ case kEventMouseDragged: {
+ WindowRef window = (WindowRef) surface->rawWindowRef;
+ Point p;
+ Rect rect;
+
+ r = GetEventParameter(e,kEventParamMouseLocation,typeQDPoint,NULL,sizeof(p),NULL,&p);
+ checkStatus(r,"GetEventParameter");
+ r = GetWindowBounds(window,kWindowContentRgn,&rect);
+ checkStatus(r,"GetWindowBounds");
+ surface->Move(p.h-rect.left,p.v-rect.top);
+ return noErr;
+ }
+ case kEventMouseDown:
+ case kEventMouseUp: {
+ EventMouseButton button;
+ UInt32 clickCount;
+ jint xwtButton;
+ r = GetEventParameter(e,kEventParamMouseButton,typeMouseButton,NULL,sizeof(button),NULL,&button);
+ checkStatus(r,"GetEventParameter");
+ r = GetEventParameter(e,kEventParamClickCount,typeUInt32,NULL,sizeof(clickCount),NULL,&clickCount);
+ checkStatus(r,"GetEventParameter");
+
+ switch(button) {
+ case kEventMouseButtonPrimary: xwtButton = 1; break;
+ case kEventMouseButtonSecondary: xwtButton = 2; break;
+ case kEventMouseButtonTertiary: xwtButton = 3; break;
+ default: return noErr;
+ }
+ if(eKind == kEventMouseDown) {
+ surface->Press(xwtButton);
+ } else {
+ surface->Release(xwtButton);
+ while(clickCount > 1) {
+ surface->DoubleClick(xwtButton);
+ clickCount-=2;
+ }
+ if(clickCount) surface->Click(xwtButton);
+ }
+ return noErr;
+ }
+ case kEventMouseWheelMoved: {
+ EventMouseWheelAxis axis;
+ SInt32 delta;
+ r = GetEventParameter(e,kEventParamMouseWheelAxis,typeMouseWheelAxis,NULL,sizeof(axis),NULL,&axis);
+ checkStatus(r,"GetEventParameter");
+ if(axis != kEventMouseWheelAxisY) break;
+ r = GetEventParameter(e,kEventParamMouseWheelDelta,typeSInt32,NULL,sizeof(delta),NULL,&delta);
+ checkStatus(r,"GetEventParameter");
+ fprintf(stderr,"kEventMouseWheelMoved: delta: %d",delta);
+ // surface->MouseWheelMoved(...) IMPROVMENT: mouse wheel support in xwt
+ return noErr;
+ }
+ }
+ break;
+
+ case kEventClassWindow: {
+ WindowRef window;
+ r = GetEventParameter(e,kEventParamDirectObject,typeWindowRef,NULL,sizeof(window),NULL,&window);
+ checkStatus(r,"kEventClassWindow/GetEventParameter");
+
+ if((RawData*)window != surface->rawWindowRef) Carbon::abort(JvNewStringLatin1("window != surface->window"));
+
+ switch(eKind) {
+ case kEventWindowUpdate: {
+ surface->Dirty(0,0,surface->width,surface->height);
+ return noErr;
+ }
+ case kEventWindowBoundsChanged: {
+ UInt32 attr;
+ Rect rect;
+ r = GetEventParameter(e,kEventParamAttributes,typeUInt32,NULL,sizeof(attr),NULL,&attr);
+ checkStatus(r,"kEventWindowBoundsChanged/GetEventParameter");
+ r = GetWindowBounds(window,kWindowContentRgn,&rect);
+ checkStatus(r,"GetWindowBounds");
+ if(attr & kWindowBoundsChangeSizeChanged) {
+ jint w = rect.right-rect.left;
+ jint h = rect.bottom-rect.top;
+ if(attr & kWindowBoundsChangeUserResize && surface->maximized)
+ surface->Maximized(false);
+ surface->reshape(w,h);
+ surface->SizeChange(w,h);
+ surface->Dirty(0,0,w,h);
+ surface->blitDirtyScreenRegions();
+ }
+ if(attr & kWindowBoundsChangeOriginChanged) {
+ surface->PosChange(rect.left,rect.top);
+ }
+ return noErr;
+ }
+ case kEventWindowActivated:
+ case kEventWindowDeactivated: {
+ surface->Focused(eKind == kEventWindowActivated);
+ return noErr;
+ }
+ case kEventWindowZoomed: {
+ fprintf(stderr,"Zoomed....\n");
+ surface->Maximized(true);
+ return noErr;
+ }
+ case kEventWindowCollapsed: {
+ surface->Minimized(true);
+ return noErr;
+ }
+ case kEventWindowExpanded: {
+ surface->Minimized(false);
+ return noErr;
+ }
+ case kEventWindowClose: {
+ surface->Close();
+ return noErr;
+ }
+ case kEventWindowClosed: {
+ DisposeEventHandlerUPP((EventHandlerUPP)surface->rawEventHandlerUPP);
+ GCJ$Retainer::release(surface);
+ return noErr;
+ }
+ }
+ }
+ break;
+ }
+ return eventNotHandledErr;
+}
+} // end namespace