📄 findword.c
字号:
#include <windows.h>
#include "srhword.h"
#include "findword.h"
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "..\pub3216.h"
#include <malloc.h>
#ifdef _DEBUG
#include "DbgFunc.h"
#endif //_DEBUG
extern int g_nCurrWindowVer;
extern char g_szTotalWord[BUFFERLENGTH];
extern RECT g_TotalWordRect;
extern int g_CharType;
extern int g_nCurCaretPlaceInTotalWord;
extern int g_bMouseInTotalWord;
//Added by XGL,Sep 29th,1998
extern RECT g_rcFirstWordRect;
//Adding ends.
extern char g_szCurWord[BUFFERLENGTH];
extern RECT g_CurWordRect;
extern int g_nCurCaretPlace;
extern char szMemDCWordBuff[BUFFERLENGTH];
extern int pnMemDCCharLeft[BUFFERLENGTH];
extern int pnMemDCCharRight[BUFFERLENGTH];
extern WORDPARA WordBuffer[MEMDC_MAXNUM];
extern int nWordNum;
extern BOOL g_bAllowGetCurWord;
extern POINT g_CurMousePos;
extern HWND g_hNotifyWnd;
extern UINT g_nTextAlign;
extern DWORD g_dwDCOrg;
extern int g_nExtra;
extern POINT g_CurPos;
extern TEXTMETRIC g_tm;
///////////////////////////////////////////////////////////////////////////
// Modify by Yan/Gang 1997/11/18
// 用於修改在计算 TA_CENTER 情况的失误。
extern BOOL bRecAllRect;
extern RECT g_rcTotalRect;
// End Modify
///////////////////////////////////////////////////////////////////////////
#define RIGHT 1
#define LEFT -1
#ifdef _DICTING_
///////////////////////////////////////////////////////////////////////////
// Add by Yan/Gang 11/13/1997
// 用於向查字助理通知取得所需要的单词·
extern UINT BL_HASSTRING;
// Add end.
///////////////////////////////////////////////////////////////////////////
#endif
#ifdef _DICTING_
/////////////////////////////////////////////////////////////////////////////////
// Modify by Yan/Gang 1997/11/19
// 主要解决通配符的问题。
extern int g_nGetWordStyle;
// End Add.
/////////////////////////////////////////////////////////////////////////////////
//Added by XGL Sep 17th, 1998
extern int g_nWordsInPhrase ;
extern BOOL g_bPhraseNeeded ;
extern int g_nPhraseCharType ;
//Adding ends
/////////////////////////////////////////////////////////////////////////////////
#endif
//////////////////////////////////////////////////////////////////////////////////
// TODO: Return a char type.
__inline int GetCharType(char ch)
{
BYTE chitem = ch;
if (ch < 0)
return CHAR_TYPE_HZ;
if (((ch >= 'a')&&(ch <= 'z'))||
((ch >= 'A')&&(ch <= 'Z')))
{
return CHAR_TYPE_ASCII;
}
return CHAR_TYPE_OTHER;
}
#ifdef _DICTING_
/////////////////////////////////////////////////////////////////////////////////
// Modify by Yan/Gang 1997/11/19
// 主要解决通配符的问题。
__inline int FindAWord(LPCSTR lpString, int nFromPlace, int nLength)
{
return FindTWWord(lpString, nFromPlace, nLength);
}
__inline int FindDWord(LPCSTR lpString, int nFromPlace, int nLength)
{
int i = nFromPlace;
while (i < nLength)
{
if (GetCharType(lpString[i]) == CHAR_TYPE_ASCII)
{
i++;
}
else
{
return i-1;
}
}
return nLength - 1;
}
__inline int FindTWWord(LPCSTR lpString, int nFromPlace, int nLength)
{
int i = nFromPlace;
// int j;
while (i < nLength)
{
if (lpString[i] == CHAR_LINK)
{
if (IsASCIIWord(lpString, nFromPlace, nLength, i + 1))
{
i++;
}
else
{
return i-1;
}
}
else
{
// 用於处理 '-' 的几种情况·
if (IsASCIIWord(lpString, nFromPlace, nLength, i))
{
i++;
}
else
{
return i-1;
}
}
}
return nLength - 1;
}
__inline BOOL IsASCIIWord(LPCSTR lpString, int nFromPlace, int nLength, int nCurCharNum)
{
if (GetCharType(lpString[nCurCharNum]) == CHAR_TYPE_ASCII)
{
return TRUE;
}
return FALSE;
}
// End Add.
/////////////////////////////////////////////////////////////////////////////////
#else
__inline int FindAWord(LPCSTR lpString, int nFromPlace, int nLength)
{
int i = nFromPlace;
while (i < nLength)
{
if (lpString[i] == CHAR_LINK)
{
if (IsASCIIWord(lpString, nFromPlace, nLength, i + 1))
{
i++;
}
else
{
return i-1;
}
}
else
{
// 用於处理 '-' 的几种情况·
if (IsASCIIWord(lpString, nFromPlace, nLength, i))
{
i++;
}
else
{
return i-1;
}
}
}
return nLength - 1;
}
#define CHAR_WILDCHAR1 '*'
#define CHAR_WILDCHAR2 '?'
__inline BOOL IsASCIIWord(LPCSTR lpString, int nFromPlace, int nLength, int nCurCharNum)
{
if (GetCharType(lpString[nCurCharNum]) == CHAR_TYPE_ASCII)
{
return TRUE;
}
return FALSE;
}
#endif
__inline int FindHZWord(LPCSTR lpString, int nFromPlace, int nLength)
{
int i = nFromPlace;
if ((BYTE)(lpString[nFromPlace]) >= 0xa1
&& (BYTE)(lpString[nFromPlace]) <= 0xa9)
{
return nFromPlace + 1 ;
}
while (i < nLength)
{
if (GetCharType(lpString[i]) == CHAR_TYPE_HZ)
{
//Added by XGL, Nov 13th, 1998
//We have to filter out Chinese punctuation marks,
//which is diffent as it is in ASCII.
if ((BYTE)(lpString[i]) >= 0xa1
&& (BYTE)(lpString[i]) <= 0xa9)
{
return i - 1 ;
}
//Adding ends. XGL, Nov 13th, 1998
i = i + 2;
}
else
{
return i - 1;
}
}
return nLength - 1;
}
__inline int FindNextWordBegin(LPCSTR lpString, int nFromPlace, int nLength)
{
int i = nFromPlace;
while (i < nLength)
{
if (GetCharType(lpString[i]) == CHAR_TYPE_OTHER)
{
i++;
}
else
{
return i-1;
}
}
return i - 1;
}
__inline int GetCurWordEnd(LPCSTR lpString, int nFromPlace, int nLength, int nCharType)
{
switch (nCharType)
{
case CHAR_TYPE_ASCII:
return FindAWord(lpString, nFromPlace, nLength);
break;
case CHAR_TYPE_HZ:
return FindHZWord(lpString, nFromPlace, nLength);
break;
case CHAR_TYPE_OTHER:
return FindNextWordBegin(lpString, nFromPlace, nLength);
break;
}
return FindAWord(lpString, nFromPlace, nLength);
}
__inline void CopyWord(LPSTR lpWord, LPCSTR lpString, int nBegin, int nEnd)
{
int i;
for ( i = nBegin; i <= nEnd; i++)
{
lpWord[i - nBegin] = lpString[i];
}
lpWord[nEnd - nBegin + 1] = '\0';
}
__inline void GetStringTopBottom(HDC hDC, int y, RECT* lpStringRect)
{
POINT WndPos;
WndPos.y = HIWORD(g_dwDCOrg);
if (TA_UPDATECP & g_nTextAlign)
{
y = g_CurPos.y;
}
switch ((TA_TOP | TA_BOTTOM)&g_nTextAlign)
{
case TA_BOTTOM:
lpStringRect->top = y - g_tm.tmHeight + g_tm.tmInternalLeading;
lpStringRect->bottom = y;
break;
case TA_BASELINE:
lpStringRect->top = y - g_tm.tmAscent;
lpStringRect->bottom = y + g_tm.tmDescent;
break;
case TA_TOP:
default:
lpStringRect->top = y;
lpStringRect->bottom = y + g_tm.tmHeight + g_tm.tmInternalLeading;
break;
}
LPtoDP(hDC, (LPPOINT)lpStringRect, 2);
lpStringRect->top = lpStringRect->top + WndPos.y;
lpStringRect->bottom = lpStringRect->bottom + WndPos.y;
}
__inline void GetStringLeftRight(HDC hDC, LPSTR szBuff, int cbLen, int x, RECT* lpStringRect, int FAR* lpDx)
{
SIZE StringSize;
POINT WndPos;
int i;
if (cbLen < 0)
{
lpStringRect->top = 0;
lpStringRect->bottom = 0;
lpStringRect->left = 0;
lpStringRect->right = 0;
return;
}
GetTextExtentPoint(hDC, szBuff, cbLen, &StringSize);
WndPos.x = LOWORD(g_dwDCOrg);
if (lpDx != NULL)
{
StringSize.cx = 0;
for (i = 0; i < cbLen; i++)
{
StringSize.cx += lpDx[i];
}
}
if (TA_UPDATECP & g_nTextAlign)
{
x = g_CurPos.x;
}
switch ((TA_LEFT | TA_CENTER | TA_RIGHT)&g_nTextAlign)
{
case TA_RIGHT:
if (!bRecAllRect)
{
lpStringRect->right = x;
lpStringRect->left = x - StringSize.cx;
}
else
{
lpStringRect->left = g_rcTotalRect.left;
lpStringRect->right= g_rcTotalRect.left + StringSize.cx;
}
break;
case TA_CENTER:
if (!bRecAllRect)
{
lpStringRect->right = x + StringSize.cx / 2;
lpStringRect->left = x - StringSize.cx / 2;
}
else
{
lpStringRect->left = g_rcTotalRect.left;
lpStringRect->right= g_rcTotalRect.left + StringSize.cx;
}
break;
case TA_LEFT:
default:
lpStringRect->left = x ;
lpStringRect->right = x + StringSize.cx;
break;
}
LPtoDP(hDC, (LPPOINT)lpStringRect, 2);
lpStringRect->left = lpStringRect->left + WndPos.x;
lpStringRect->right = lpStringRect->right + WndPos.x;
}
//#define _TEST
void GetStringRect(HDC hDC, LPSTR szBuff, int cbLen, int x, int y, RECT* lpStringRect, int FAR* lpDx)
{
SIZE StringSize;
POINT WndPos;
int i;
if (cbLen < 0)
{
lpStringRect->top = 0;
lpStringRect->bottom = 0;
lpStringRect->left = 0;
lpStringRect->right = 0;
return;
}
GetTextExtentPoint(hDC, szBuff, cbLen, &StringSize);
WndPos.x = LOWORD(g_dwDCOrg);
WndPos.y = HIWORD(g_dwDCOrg);
if (lpDx != NULL)
{
StringSize.cx = 0;
for (i = 0; i < cbLen; i++)
{
StringSize.cx += lpDx[i];
}
}
if (TA_UPDATECP & g_nTextAlign)
{
x = g_CurPos.x;
y = g_CurPos.y;
}
switch ((TA_LEFT | TA_CENTER | TA_RIGHT)&g_nTextAlign)
{
case TA_RIGHT:
if (bRecAllRect == FALSE)
{
lpStringRect->right = x;
lpStringRect->left = x - StringSize.cx;
}
else
{
lpStringRect->left = g_rcTotalRect.left;
lpStringRect->right= g_rcTotalRect.left + StringSize.cx;
}
break;
case TA_CENTER:
if (bRecAllRect == FALSE)
{
lpStringRect->right = x + StringSize.cx / 2;
lpStringRect->left = x - StringSize.cx / 2;
}
else
{
lpStringRect->left = g_rcTotalRect.left;
lpStringRect->right= g_rcTotalRect.left + StringSize.cx;
}
break;
case TA_LEFT:
default:
lpStringRect->left = x ;
lpStringRect->right = x + StringSize.cx;
break;
}
switch ((TA_TOP | TA_BOTTOM | TA_BASELINE)&g_nTextAlign)
{
case TA_BOTTOM:
lpStringRect->top = y - StringSize.cy;
lpStringRect->bottom = y;
break;
case TA_BASELINE:
lpStringRect->top = y - g_tm.tmAscent;
lpStringRect->bottom = y + g_tm.tmDescent;
break;
case TA_TOP:
default:
lpStringRect->top = y;
lpStringRect->bottom = y + StringSize.cy;
break;
}
LPtoDP(hDC, (LPPOINT)lpStringRect, 2);
lpStringRect->top = lpStringRect->top + WndPos.y;
lpStringRect->bottom = lpStringRect->bottom + WndPos.y;
lpStringRect->left = lpStringRect->left + WndPos.x;
lpStringRect->right = lpStringRect->right + WndPos.x;
}
DWORD GetCurMousePosWord(HDC hDC,
LPSTR szBuff,
int cbLen,
int x,
int y,
int FAR* lpDx)
{
int nCurrentWord, nPrevWord;
RECT StringRect;
int CharType;
int nLeft;
DWORD dwReturn;
GetStringTopBottom(hDC, y, &StringRect);
if ((StringRect.top > g_CurMousePos.y) || (StringRect.bottom < g_CurMousePos.y))
{
return NO_CURMOUSEWORD;
}
GetStringRect(hDC, szBuff, cbLen, x, y, &StringRect, lpDx);
nLeft = StringRect.left;
// nLeft = 0;
nPrevWord = nCurrentWord = -1;
while (nCurrentWord < cbLen)
{
CharType = GetCharType(szBuff[nCurrentWord + 1]);
nPrevWord = nCurrentWord;
nCurrentWord = GetCurWordEnd(szBuff, nPrevWord + 1, cbLen, CharType);
dwReturn = CheckMouseInCurWord(hDC, szBuff, cbLen, x, y, lpDx, &nLeft, nPrevWord + 1, nCurrentWord, CharType);
#ifdef _DICTING_
if (dwReturn == HAS_CURMOUSEWORD)
{
if (CharType == CHAR_TYPE_OTHER)
{
PostMessage(g_hNotifyWnd, BL_HASSTRING, 0, 0l);
}
else
{
}
}
else
{
if (g_bMouseInTotalWord)
{
PostMessage(g_hNotifyWnd, BL_HASSTRING, 0, 0l);
}
}
#else
if (dwReturn == HAS_CURMOUSEWORD)
return HAS_CURMOUSEWORD;
#endif
if (nCurrentWord >= cbLen - 1)
return NO_CURMOUSEWORD;
}
return NO_CURMOUSEWORD;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -