📄 wpadproc.c
字号:
varcInk[1].right = varcInk[1].left + BOX_WRITING_AREA;
varcInk[1].bottom = varcInk[1].top + BOX_WRITING_AREA;
varc[0].top = BUTTON_ROW_00;
varc[0].left = BUTTON_COL_00;
varc[0].bottom = varc[0].top + SMALL_BUTTON_HEIGHT;
varc[0].right = varc[0].left + BCKSP_BUTTON_WIDTH;
varc[1] = varc[0];
varc[1].left = BUTTON_COL_01;
varc[1].right = varc[1].left + ESCAP_BUTTON_WIDTH;
varc[2] = varc[1];
varc[2].left = BUTTON_COL_02;
varc[2].right = varc[2].left + QUERY_BUTTON_WIDTH;
varc[3].top = BUTTON_ROW_01;
varc[3].left = BUTTON_COL_00;
varc[3].bottom = varc[3].top + LARGE_BUTTON_HEIGHT;
varc[3].right = varc[3].left + LARGE_BUTTON_WIDTH;
varc[4] = varc[3];
varc[4].left = BUTTON_COL_03;
varc[4].right = varc[4].left + LARGE_BUTTON_WIDTH;
varc[5].top = BUTTON_ROW_02;
varc[5].left = BUTTON_COL_00;
varc[5].bottom = varc[5].top + LARGE_BUTTON_HEIGHT;
varc[5].right = varc[5].left + LARGE_BUTTON_WIDTH;
varc[6] = varc[5];
varc[6].left = BUTTON_COL_03;
varc[6].right = varc[6].left + LARGE_BUTTON_WIDTH;
varc[7].top = BUTTON_ROW_03;
varc[7].left = BUTTON_COL_00;
varc[7].bottom = varc[7].top + LARGE_BUTTON_HEIGHT;
varc[7].right = varc[7].left + LARGE_BUTTON_WIDTH;
varc[8] = varc[7];
varc[8].left = BUTTON_COL_03;
varc[8].right = varc[8].left + LARGE_BUTTON_WIDTH;
}
// Common code for handling pen points.
void ClipToBox(POINT *ppt)
{
if (ppt->x < glob.rcClip.left)
ppt->x = glob.rcClip.left;
else if (ppt->x > glob.rcClip.right)
ppt->x = glob.rcClip.right;
if (ppt->y < glob.rcClip.top)
ppt->y = glob.rcClip.top;
else if (ppt->y > glob.rcClip.bottom)
ppt->y = glob.rcClip.bottom;
}
// Common code for handling pen points.
BOOL PointInBox(POINT *ppt)
{
if ((ppt->x < glob.rcClip.left) || (ppt->x > glob.rcClip.right))
return FALSE;
if ((ppt->y < glob.rcClip.top) || (ppt->y > glob.rcClip.bottom))
return FALSE;
return TRUE;
}
// Common code for handling pen points
void AddPoints(POINT *ppt, int cpt)
{
int cptAdd = 0;
while (cpt--)
{
if (glob.cptRaw < SMOOTHING_BUFFER_LIMIT)
glob.aptRaw[glob.cptRaw++] = *ppt;
else
{
// Remove duplicate points from the data stream
if ((ppt->x == glob.aptRaw[SMOOTHING_BUFFER_LIMIT - 1].x) &&
(ppt->y == glob.aptRaw[SMOOTHING_BUFFER_LIMIT - 1].y))
{
ppt++;
continue;
}
if (glob.cptOut == glob.maxOut)
{
POINT *ppt = (POINT *) LocalAlloc(LPTR, (glob.maxOut + 16) * sizeof(POINT));
if (ppt == (POINT *) NULL)
return;
memcpy(ppt, glob.pptOut, glob.cptOut * sizeof(POINT));
LocalFree(glob.pptOut);
glob.pptOut = ppt;
glob.maxOut += 16;
}
// Add this point to the processed buffer
cptAdd++;
glob.pptOut[glob.cptOut++] = glob.aptRaw[0];
// Move the points in the raw buffer to make room
memmove(&glob.aptRaw[0], &glob.aptRaw[1], sizeof(POINT) * (SMOOTHING_BUFFER_LIMIT - 1));
// Move the new point to the end of the raw buffer
glob.aptRaw[SMOOTHING_BUFFER_LIMIT - 1] = *ppt;
}
// Is there enough data to do smoothing?
if (glob.cptRaw > 2)
{
WORD ipt = glob.cptRaw - 2;
glob.aptRaw[ipt].x = (glob.aptRaw[ipt - 1].x + glob.aptRaw[ipt].x * 2 + glob.aptRaw[ipt + 1].x) >> 2;
glob.aptRaw[ipt].y = (glob.aptRaw[ipt - 1].y + glob.aptRaw[ipt].y * 2 + glob.aptRaw[ipt + 1].y) >> 2;
}
// Advance to the next point
ppt++;
}
// Can we draw something?
if (cptAdd)
{
cptAdd++;
if (cptAdd > glob.cptOut)
cptAdd = glob.cptOut;
ConnectTheDots(&glob.pptOut[glob.cptOut - cptAdd], cptAdd);
}
}
////////////////////////////////////////////////////////////////////////
//
// Windows message handler
//
// =====================================================================
//
// HandleMouseAction
//
// Handling mouse actions
//
// =====================================================================
BOOL HandleMouseAction(HWND hwnd, UINT iMsg, POINT *ppt)
{
switch (iMsg)
{
case WM_LBUTTONDOWN:
{
int iBox = ComputeBoxKey(ppt);
// If we're not in a box or on a key, exit
if (iBox < 0)
return FALSE;
// Grab ownership of the mouse
SetCapture(hwnd);
// If this is a key press, deal with it
if (iBox > BOX_COUNT)
{
viDown = iBox;
viWant = iBox;
vbPush = TRUE;
InvalidateRect(hwnd, &varc[viDown - IDC_BACKSP], FALSE);
return TRUE;
}
if (hdcMouse == NULL)
{
ASSERT(glob.iCurrBox == -1);
hdcMouse = GetDC(hwnd);
}
// The very, very, first time the pen is touched to a box, erase
// the crosshairs and remove them until next restart.
if (!glob.bDown && !glob.bInked)
{
glob.bInked = TRUE;
EraseRecogInk(hdcMouse, 0);
EraseRecogInk(hdcMouse, 1);
}
glob.bDown = TRUE;
// Pump up our thread priority by 1 level
if (!glob.bHiPri)
{
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
glob.bHiPri = TRUE;
}
if (v_bTimerStarted)
{
KillTimer(hwnd, TIMER_ID_WPAD);
v_bTimerStarted = FALSE;
}
// Start a stroke in the box.
NewStroke(iBox);
// Setup the rcClip and the DC if their not already set up.
if (iBox != glob.iCurrBox)
{
glob.rcClip.left = (iBox * BOX_SIZE + BOX_OFFSET + 2);
glob.rcClip.top = (BOX_OFFSET + 2);
glob.rcClip.right = iBox * BOX_SIZE + BOX_OFFSET + BOX_WRITING_AREA - 2;
glob.rcClip.bottom = BOX_OFFSET + BOX_WRITING_AREA - 2;
// Scale the clip rect to internal coordinates
glob.rcClip.left <<= 2;
glob.rcClip.top <<= 2;
glob.rcClip.right <<= 2;
glob.rcClip.bottom <<= 2;
}
// Convert from display to interal coordinates and clip to the current box
ppt->x <<= 2;
ppt->y <<= 2;
ClipToBox(ppt);
glob.cptRaw = 0;
AddPoints(ppt, 1);
glob.ptClient.x = glob.ptClient.y = 0;
ClientToScreen(hwnd, &glob.ptClient);
// Save away the current and previous box info.
glob.iPrevBox = glob.iCurrBox;
glob.iCurrBox = iBox;
return TRUE;
}
case WM_LBUTTONUP:
{
ReleaseCapture();
// Was a button being pushed?
if (vbPush)
{
// Were we over it when we let go? If so, tell the main window
if (viDown == viWant)
PostMessage(g_hwndMain, WM_COMMAND, viDown, 0);
if (viDown >= IDC_BACKSP)
InvalidateRect(hwnd, &varc[viDown - IDC_BACKSP], FALSE);
viDown = -1;
vbPush = FALSE;
return TRUE;
}
if ( !glob.bDown )
return FALSE;
glob.bDown = FALSE;
// Convert from display to internal coordinates and clip to the current box
ppt->x <<= 2;
ppt->y <<= 2;
ClipToBox(ppt);
AddPoints(ppt, 1);
//
// Terminate saves the stroke away and queries state from the SiPanel
// if it's the first stroke.
//
Terminate();
//
// Erase the old ink, we have a tiny slice of time before the next
// stroke can begin.
//
if ((glob.iCurrBox != glob.iPrevBox) &&
(glob.iPrevBox != -1))
{
EraseRecogInk(hdcMouse, glob.iPrevBox);
glob.iPrevBox = -1;
}
// Now start timer
//
// If timeout value is 0, it means no timeout. Don't
// start timer
if( gbTimeout )
{
SetTimer(hwnd, TIMER_ID_WPAD, gnTimeout, NULL);
v_bTimerStarted = TRUE;
}
return TRUE;
}
case WM_MOUSEMOVE:
if (vbPush)
{
int iNew = ComputeBoxKey(ppt);
if (viWant != iNew)
iNew = -1;
if (viDown != iNew)
{
if (viDown >= IDC_BACKSP)
InvalidateRect(hwnd, &varc[viDown - IDC_BACKSP], FALSE);
viDown = iNew;
if (viDown >= IDC_BACKSP)
InvalidateRect(hwnd, &varc[viDown - IDC_BACKSP], FALSE);
}
return TRUE;
}
if (glob.bDown)
{
#ifdef UNDER_CE
UINT cpt = 128;
POINT apt[128];
if (!GetMouseMovePoints(apt, cpt, &cpt))
{
DEBUGMSG(DBGERROR, (TEXT("GetMouseMovePoints() failed\n")));
}
else
{
// Convert the points from Screen Mouse to Client and then
// clip it to the current box being written in.
POINT *pptEnd, *pptTo;
pptEnd = apt + cpt;
for (pptTo = ppt = apt; ppt < pptEnd; ppt++)
{
pptTo->x = ppt->x - (glob.ptClient.x << 2);
pptTo->y = ppt->y - (glob.ptClient.y << 2);
ClipToBox(pptTo++);
}
AddPoints(apt, cpt);
}
#else
ppt->x <<= 2;
ppt->y <<= 2;
ClipToBox(ppt);
AddPoints(ppt, 1);
#endif
return TRUE;
}
break;
default:
break;
}
return FALSE;
}
// ====================================================================
//
// HandleHWXAction
//
// Handling some HWX specific actions: erase and recognize
//
// ====================================================================
LRESULT HandleHWXAction(HWND hwnd, UINT iMsg)
{
LRESULT lRet = 0;
ASSERT((iMsg == PAD_WM_ERASE) || (iMsg == PAD_WM_DETERMINE));
// We sometimes don't get a WM_LBUTTONUP message due to the system
// design. We need to simulate one here if we think we are in a
// down state or risk odd behaviour. The hwxpad assumes we will
// get one and may leak resources if we don't.
if (glob.bDown)
SendMessage(g_hwndWPad, WM_LBUTTONUP, 0, 0);
// In either case, do the recognition, for erase then send a backspace key through.
if (hdcMouse == NULL)
hdcMouse = GetDC(hwnd);
EraseRecogInk(hdcMouse, glob.iCurrBox);
if(iMsg == PAD_WM_ERASE){
EraseStroke();
PostThreadMessage(v_rThreadID, THRDMSG_CLEAR, 0, 0);
} else {
NewStroke(-1);
}
lRet = 1;
// There's no more ink, init state again.
glob.iCurrBox = -1;
if (glob.bHiPri)
{
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL);
glob.bHiPri = FALSE;
}
return lRet;
}
int ConvertToString(HWXRESULTPRI *pres, WCHAR *pwsz)
{
int ich;
ich = 0;
while (pres)
{
pwsz[ich++] = pres->awchAlts[0];
pres = pres->pNext;
}
pwsz[ich] = L'\0';
return ich;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -