2016-05-14 00:35:41 +00:00
|
|
|
#if __ORCAC__
|
|
|
|
#pragma lint -1
|
2015-09-24 00:40:17 +00:00
|
|
|
#pragma noroot
|
2016-05-14 02:44:12 +00:00
|
|
|
segment "VNCview GS";
|
2016-05-14 00:35:41 +00:00
|
|
|
#endif
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#include <window.h>
|
|
|
|
#include <quickdraw.h>
|
|
|
|
#include <qdaux.h>
|
|
|
|
#include <desk.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <resources.h>
|
|
|
|
#include <tcpip.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <control.h>
|
|
|
|
#include <misctool.h>
|
|
|
|
#include <scrap.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <event.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "vncsession.h"
|
|
|
|
#include "vncview.h"
|
|
|
|
#include "vncdisplay.h"
|
|
|
|
#include "colortables.h"
|
|
|
|
#include "menus.h"
|
|
|
|
#include "clipboard.h"
|
|
|
|
#include "desktopsize.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "copyrect.h"
|
|
|
|
#include "raw.h"
|
|
|
|
#include "hextile.h"
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned char * cursor = NULL; /* Cursor from server */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Send a DoPointerEvent reflecting the status of the mouse to the server */
|
|
|
|
/* This routine also maintains the appropriate cursor when using local cursor */
|
|
|
|
void DoPointerEvent (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
static struct {
|
|
|
|
unsigned char messageType;
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned char buttonMask;
|
|
|
|
unsigned int xPos;
|
|
|
|
unsigned int yPos;
|
2015-09-24 01:56:33 +00:00
|
|
|
} pointerEventStruct = { 5 /* message type */ };
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
Point mouseCoords;
|
2016-05-29 04:58:04 +00:00
|
|
|
Origin contentOrigin;
|
2015-09-24 00:40:17 +00:00
|
|
|
RegionHndl contentRgnHndl;
|
|
|
|
unsigned int oldButtonMask;
|
|
|
|
GrafPortPtr winPtr;
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned long key1 = 0x0000; /* Keys to release & re-press, if any */
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned long key2 = 0x0000;
|
|
|
|
|
|
|
|
if (viewOnlyMode)
|
2015-09-24 01:26:03 +00:00
|
|
|
return;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
mouseCoords = myEvent.where;
|
|
|
|
|
|
|
|
SetPort(vncWindow);
|
|
|
|
|
|
|
|
/* Check if mouse is in content region of VNC window; don't send mouse
|
|
|
|
* updates if it isn't.
|
|
|
|
*/
|
|
|
|
if (FindWindow(&winPtr, myEvent.where.h, myEvent.where.v) != wInContent ||
|
2015-09-24 01:26:03 +00:00
|
|
|
winPtr != vncWindow) {
|
|
|
|
if (cursor && GetCursorAdr() == cursor)
|
|
|
|
InitCursor();
|
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
GlobalToLocal(&mouseCoords);
|
|
|
|
|
2016-05-29 04:58:04 +00:00
|
|
|
contentOrigin.l = GetContentOrigin(vncWindow);
|
|
|
|
mouseCoords.h += contentOrigin.pt.h;
|
|
|
|
mouseCoords.v += contentOrigin.pt.v;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
mouseCoords.h = SwapBytes2(mouseCoords.h);
|
|
|
|
mouseCoords.v = SwapBytes2(mouseCoords.v);
|
|
|
|
|
|
|
|
/* Set up correct state of mouse buttons */
|
|
|
|
oldButtonMask = pointerEventStruct.buttonMask;
|
|
|
|
pointerEventStruct.buttonMask = 0x00;
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
if ((myEvent.modifiers & btn0State) == 0x00) { /* Mouse button pressed */
|
|
|
|
if (emulate3ButtonMouse) {
|
|
|
|
if (myEvent.modifiers & optionKey) {
|
|
|
|
pointerEventStruct.buttonMask = 0x02;
|
|
|
|
key1 = 0xFFE9;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
if (myEvent.modifiers & appleKey) {
|
|
|
|
pointerEventStruct.buttonMask |= 0x04;
|
|
|
|
key2 = 0xFFE7;
|
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
|
|
|
|
/* If no modifiers, just send a normal left click. */
|
|
|
|
if (pointerEventStruct.buttonMask == 0x00)
|
|
|
|
pointerEventStruct.buttonMask = 0x01;
|
2015-09-24 06:33:01 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
if ((myEvent.modifiers & btn1State) == 0x00) /* If 2nd (right) */
|
|
|
|
pointerEventStruct.buttonMask |= 0x04; /* button is pressed */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Don't waste bandwidth by sending update if mouse hasn't changed.
|
|
|
|
* This may occasionally result in an initial mouse update not being
|
|
|
|
* sent. If this occurs, the user can simply move the mouse slightly
|
|
|
|
* in order to send it.
|
|
|
|
*/
|
2015-09-24 01:26:03 +00:00
|
|
|
if ( (pointerEventStruct.xPos == mouseCoords.h) &&
|
|
|
|
(pointerEventStruct.yPos == mouseCoords.v) &&
|
2015-09-24 00:40:17 +00:00
|
|
|
(pointerEventStruct.buttonMask == oldButtonMask) )
|
2015-09-24 01:26:03 +00:00
|
|
|
return;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
pointerEventStruct.xPos = mouseCoords.h;
|
2015-09-24 00:40:17 +00:00
|
|
|
pointerEventStruct.yPos = mouseCoords.v;
|
|
|
|
|
|
|
|
if (key1)
|
2015-09-24 01:26:03 +00:00
|
|
|
SendKeyEvent(FALSE, key1);
|
2015-09-24 00:40:17 +00:00
|
|
|
if (key2)
|
2015-09-24 01:26:03 +00:00
|
|
|
SendKeyEvent(FALSE, key2);
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
TCPIPWriteTCP(hostIpid, (Pointer) &pointerEventStruct.messageType,
|
2015-09-24 01:26:03 +00:00
|
|
|
sizeof(pointerEventStruct), TRUE, FALSE);
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Can't do useful error checking here */
|
|
|
|
|
|
|
|
if (key1)
|
2015-09-24 01:26:03 +00:00
|
|
|
SendKeyEvent(TRUE, key1);
|
2015-09-24 00:40:17 +00:00
|
|
|
if (key2)
|
2015-09-24 01:26:03 +00:00
|
|
|
SendKeyEvent(TRUE, key2);
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
//printf("Sent mouse update: x = %u, y = %u\n", mouseCoords.h, mouseCoords.v);
|
|
|
|
//printf(" xPos = %x, yPos = %x, buttons = %x\n", pointerEventStruct.xPos, pointerEventStruct.yPos, (int) pointerEventStruct.buttonMask);
|
|
|
|
|
|
|
|
/* Note that we don't have to request a display update here. That has
|
|
|
|
* been or will be done elsewhere when we're ready for it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cursor && GetCursorAdr() != cursor)
|
2015-09-24 01:26:03 +00:00
|
|
|
SetCursor(cursor);
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoCursor (void) {
|
|
|
|
unsigned char *cursorPixels;
|
|
|
|
unsigned char *bitmask;
|
|
|
|
unsigned char *dataPtr;
|
|
|
|
/* Elements of the cursor structure (which isn't a C struct) */
|
|
|
|
unsigned int *cursorHeightPtr, *cursorWidthPtr;
|
|
|
|
unsigned char *cursorImage, *cursorMask;
|
|
|
|
unsigned int *hotSpotYPtr, *hotSpotXPtr;
|
|
|
|
unsigned long bitmaskByte;
|
|
|
|
unsigned long bitmaskLineBytes, lineWords;
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned int line, n, j; /* Loop counters */
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned char *maskLine, *imageLine;
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned char *oldCursor = cursor; /* So we can free() it later */
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned int outBytes640;
|
|
|
|
unsigned long outBytes320;
|
|
|
|
|
2015-09-24 23:33:27 +00:00
|
|
|
bitmaskLineBytes = ((unsigned long)rectWidth + 7) / 8;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 23:33:27 +00:00
|
|
|
if (!DoReadTCP((unsigned long)rectWidth * rectHeight + bitmaskLineBytes * rectHeight))
|
2015-09-24 01:26:03 +00:00
|
|
|
return; /* Try again later */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
cursorPixels = (unsigned char *)(*readBufferHndl);
|
2015-09-24 23:33:27 +00:00
|
|
|
bitmask = (unsigned char *)(*readBufferHndl) + (unsigned long)rectWidth * rectHeight;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
if (hRez == 640)
|
2015-09-24 23:33:27 +00:00
|
|
|
lineWords = ((unsigned long)rectWidth + 7) / 8 + 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
else /* hRez == 320 */
|
2015-09-24 23:33:27 +00:00
|
|
|
lineWords = ((unsigned long)rectWidth + 3) / 4 + 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 23:33:27 +00:00
|
|
|
/* Don't overflow loop indices, and don't use really large cursors.
|
|
|
|
* (Is there a limit to the cursor sizes QuickDraw II can handle?) */
|
|
|
|
if (lineWords > 16 || rectHeight > 128 || rectWidth == 0 || rectHeight == 0) {
|
2015-09-24 06:33:01 +00:00
|
|
|
InitCursor();
|
2015-09-24 23:33:27 +00:00
|
|
|
cursor = NULL;
|
2015-09-24 06:33:01 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
cursor = malloc(8 + 4 * lineWords * rectHeight);
|
|
|
|
/* Sub-optimal error handling */
|
2015-09-24 06:33:01 +00:00
|
|
|
if (cursor == NULL) {
|
|
|
|
InitCursor();
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
cursorHeightPtr = (unsigned int *)(void *)cursor;
|
|
|
|
cursorWidthPtr = cursorHeightPtr + 1;
|
|
|
|
cursorImage = cursor + 4;
|
|
|
|
cursorMask = cursorImage + lineWords * rectHeight * 2;
|
|
|
|
hotSpotYPtr = (unsigned int *)(cursorMask + lineWords * rectHeight * 2);
|
|
|
|
hotSpotXPtr = hotSpotYPtr + 1;
|
|
|
|
|
|
|
|
*cursorHeightPtr = rectHeight;
|
|
|
|
*cursorWidthPtr = lineWords;
|
|
|
|
*hotSpotYPtr = rectY;
|
|
|
|
*hotSpotXPtr = rectX;
|
|
|
|
|
|
|
|
/* Make cursorImage using translation tables */
|
|
|
|
/* Make cursorMask from bitmask */
|
|
|
|
|
|
|
|
dataPtr = cursorPixels;
|
|
|
|
|
|
|
|
if (hRez == 320) {
|
2015-09-24 01:26:03 +00:00
|
|
|
for (line = 0; line < rectHeight; line++) { /* for each line ... */
|
2015-09-24 00:40:17 +00:00
|
|
|
maskLine = cursorMask + line * lineWords * 2;
|
|
|
|
imageLine = cursorImage + line * lineWords * 2;
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
for (j = 0; j < bitmaskLineBytes; j++) {
|
2015-09-24 00:40:17 +00:00
|
|
|
bitmaskByte = *(bitmask + line*bitmaskLineBytes + j);
|
|
|
|
outBytes320 =
|
2015-09-26 06:24:58 +00:00
|
|
|
(((unsigned)bitmaskByte & 0x80) ) + (((unsigned)bitmaskByte & 0x80) >> 1) +
|
|
|
|
(((unsigned)bitmaskByte & 0x80) >> 2) + (((unsigned)bitmaskByte & 0x80) >> 3) +
|
|
|
|
(((unsigned)bitmaskByte & 0x40) >> 3) + (((unsigned)bitmaskByte & 0x40) >> 4) +
|
|
|
|
(((unsigned)bitmaskByte & 0x40) >> 5) + (((unsigned)bitmaskByte & 0x40) >> 6) +
|
|
|
|
(((unsigned)bitmaskByte & 0x20) << 10) + (((unsigned)bitmaskByte & 0x20) << 9) +
|
|
|
|
(((unsigned)bitmaskByte & 0x20) << 8) + (((unsigned)bitmaskByte & 0x20) << 7) +
|
|
|
|
(((unsigned)bitmaskByte & 0x10) << 7) + (((unsigned)bitmaskByte & 0x10) << 6) +
|
|
|
|
(((unsigned)bitmaskByte & 0x10) << 5) + (((unsigned)bitmaskByte & 0x10) << 4) +
|
2015-09-24 00:40:17 +00:00
|
|
|
((bitmaskByte & 0x08) << 20) + ((bitmaskByte & 0x08) << 19) +
|
|
|
|
((bitmaskByte & 0x08) << 18) + ((bitmaskByte & 0x08) << 17) +
|
|
|
|
((bitmaskByte & 0x04) << 17) + ((bitmaskByte & 0x04) << 16) +
|
|
|
|
((bitmaskByte & 0x04) << 15) + ((bitmaskByte & 0x04) << 14) +
|
|
|
|
((bitmaskByte & 0x02) << 30) + ((bitmaskByte & 0x02) << 29) +
|
|
|
|
((bitmaskByte & 0x02) << 28) + ((bitmaskByte & 0x02) << 27) +
|
|
|
|
((bitmaskByte & 0x01) << 27) + ((bitmaskByte & 0x01) << 26) +
|
|
|
|
((bitmaskByte & 0x01) << 25) + ((bitmaskByte & 0x01) << 24);
|
|
|
|
*((unsigned long *)maskLine + j) = outBytes320;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
*((unsigned int *)maskLine + lineWords - 1) = 0;
|
|
|
|
|
|
|
|
for (n = 0; n < rectWidth/2; n++) {
|
|
|
|
*(imageLine + n) = coltab320[*(dataPtr++)] & 0xF0;
|
|
|
|
*(imageLine + n) += coltab320[*(dataPtr++)] & 0x0F;
|
2015-09-24 01:26:03 +00:00
|
|
|
*(imageLine + n) ^= 0xFF; /* Reverse color */
|
2015-09-24 00:40:17 +00:00
|
|
|
*(imageLine + n) &= *(maskLine + n);
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-26 05:33:08 +00:00
|
|
|
if (rectWidth & 0x01) {
|
2015-09-24 01:26:03 +00:00
|
|
|
*(imageLine + n) = coltab320[*(dataPtr++)] & 0xF0;
|
|
|
|
*(imageLine + n) ^= 0xFF; /* Reverse color */
|
2015-09-24 00:40:17 +00:00
|
|
|
*(imageLine + n) &= *(maskLine + n);
|
|
|
|
n++;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
*(imageLine + n) = 0;
|
|
|
|
*((unsigned int *)imageLine + lineWords - 1) = 0;
|
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
else { /* hRez == 640 */
|
2015-09-24 01:26:03 +00:00
|
|
|
for (line = 0; line < rectHeight; line++) { /* for each line ... */
|
2015-09-24 00:40:17 +00:00
|
|
|
maskLine = cursorMask + line * lineWords * 2;
|
|
|
|
imageLine = cursorImage + line * lineWords * 2;
|
|
|
|
|
|
|
|
for (j = 0; j < bitmaskLineBytes; j++) {
|
|
|
|
bitmaskByte = *(bitmask + line*bitmaskLineBytes + j);
|
|
|
|
outBytes640 =
|
2015-09-26 06:24:58 +00:00
|
|
|
(((unsigned)bitmaskByte & 0x80) ) + (((unsigned)bitmaskByte & 0xC0) >> 1) +
|
|
|
|
(((unsigned)bitmaskByte & 0x60) >> 2) + (((unsigned)bitmaskByte & 0x30) >> 3) +
|
|
|
|
(((unsigned)bitmaskByte & 0x10) >> 4) + (((unsigned)bitmaskByte & 0x08) << 12) +
|
|
|
|
(((unsigned)bitmaskByte & 0x0C) << 11) + (((unsigned)bitmaskByte & 0x06) << 10) +
|
|
|
|
(((unsigned)bitmaskByte & 0x03) << 9) + (((unsigned)bitmaskByte & 0x01) << 8);
|
2015-09-24 00:40:17 +00:00
|
|
|
*((unsigned int *)maskLine + j) = outBytes640;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
*((unsigned int *)maskLine + lineWords - 1) = 0;
|
|
|
|
|
2015-09-24 06:33:01 +00:00
|
|
|
for (n = 0; n < rectWidth / 4; n++) {
|
2015-09-24 00:40:17 +00:00
|
|
|
*(imageLine + n) = coltab640[*(dataPtr++)] & 0xC0;
|
|
|
|
*(imageLine + n) += coltab640[*(dataPtr++)] & 0x30;
|
|
|
|
*(imageLine + n) += coltab640[*(dataPtr++)] & 0x0C;
|
|
|
|
*(imageLine + n) += coltab640[*(dataPtr++)] & 0x03;
|
2015-09-24 01:26:03 +00:00
|
|
|
*(imageLine + n) ^= 0xFF; /* Reverse color */
|
2015-09-24 00:40:17 +00:00
|
|
|
*(imageLine + n) &= *(maskLine + n);
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 06:33:01 +00:00
|
|
|
|
2015-09-26 05:33:08 +00:00
|
|
|
if (rectWidth & 0x03) {
|
2015-09-24 06:33:01 +00:00
|
|
|
*(imageLine + n) = 0;
|
2015-09-26 05:33:08 +00:00
|
|
|
for (j = 0; j < (rectWidth & 0x03); j++) {
|
2015-09-26 04:47:09 +00:00
|
|
|
*(imageLine + n) += coltab640[*(dataPtr++)] & (0xC0 >> j*2);
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 06:33:01 +00:00
|
|
|
*(imageLine + n) ^= 0xFF; /* Reverse color */
|
|
|
|
*(imageLine + n) &= *(maskLine + n);
|
|
|
|
n++;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 06:33:01 +00:00
|
|
|
*(unsigned int *)(imageLine + n) = 0;
|
|
|
|
*((unsigned int *)imageLine + lineWords - 1) = 0;
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
if (GetCursorAdr() == oldCursor)
|
|
|
|
SetCursor(cursor);
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/***************/
|
|
|
|
{
|
|
|
|
unsigned char * k;
|
|
|
|
FILE *foo = fopen("out.txt", "a");
|
|
|
|
fprintf(foo, "Width = %u, Height = %u, Hotspot X = %u, Hotspot Y = %u:\n",
|
|
|
|
rectWidth, rectHeight, rectX, rectY);
|
|
|
|
fprintf(foo, "\n");
|
|
|
|
for (k = cursor; k < cursorImage; k++)
|
2015-09-24 01:26:03 +00:00
|
|
|
fprintf(foo, "%02X ", *k);
|
2015-09-24 06:33:01 +00:00
|
|
|
fprintf(foo, "\n");
|
2015-09-24 00:40:17 +00:00
|
|
|
for (j = 0; j < lineWords * rectHeight * 4; j++) {
|
2015-09-24 01:26:03 +00:00
|
|
|
fprintf(foo, "%02X", *(cursorImage + j));
|
2015-09-24 00:40:17 +00:00
|
|
|
if ((j+1) % (lineWords * 2) == 0)
|
2015-09-24 01:26:03 +00:00
|
|
|
fprintf(foo, "\n");
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
for (k = cursorImage + j; k < cursorImage + j + 4; k = k + 1)
|
2015-09-24 01:26:03 +00:00
|
|
|
fprintf(foo, "%02X ", *k);
|
2015-09-24 00:40:17 +00:00
|
|
|
fprintf(foo, "\n");
|
|
|
|
fclose(foo);
|
2015-09-24 06:33:01 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
/***************/
|
|
|
|
#endif
|
|
|
|
|
2015-09-24 06:33:01 +00:00
|
|
|
done:
|
2015-09-24 23:33:27 +00:00
|
|
|
free(oldCursor);
|
2015-09-24 00:40:17 +00:00
|
|
|
NextRect(); /* Prepare for next rect */
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|