📄 imewin.c
字号:
/* Copyright (C) 2004-2005 Li Yudong*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include "../include/common.h"#include "../include/bmp.h"#include "../include/regclass.h"#include "../include/hdc.h"#include "../include/hdcbitblt.h"#include "../include/imewin.h"#include "../include/gdi.h"#include "../include/rect.h"#include "../include/message.h"#include "../include/blockheap.h"#include "../include/invalidregion.h"#include "../include/clipregion.h"#include "../include/caret.h"#include "../include/winnc.h"#include "../include/winbase.h"#include "../include/window.h"#include "../include/text.h"#include "../include/lguiapp.h"#include "../include/pinyin.h"#include "../include/imewin.h"#include "../include/keyboard_pro.h"#include "../include/skbwin.h"#include "../include/taskbar.h"extern int _lGUI_iBytesDataType;extern PWindowsTree _lGUI_pTaskBarWindow;//[|----4 ----||------4------|][|-----4-----||----4----|][|----4----||----4----|][|----4----||----4----|]//[|in method-||-L/R pressed-|][|-sdc/dbc -||----4----|][|----4----||----4----|][|----4----||----4----|]PWindowsTree _lGUI_pImeWindow;extern PWindowsTree _lGUI_pWindowsTree;extern PWindowsTree _lGUI_pSkbWindow;//create installable input method//create an ime link table represent ime which currently installed.ImeDataTable imeDataTable;static PLGUIIme pImeLinkTable = NULL;extern LGUIIme pinyinIme;static BOOLInstallOneIme( PLGUIIme pLGUIIME);static BOOLInstallLGUIIme();static voidUnInstallLGUIIme();static PLGUIImeGetImePointerByIndex( int iIndex);static int GetCurrentIme();static void SetCurrentIme( int iIme);static BOOLLGUIInitIme();static void LGUIDestroyIme();static void LGUIResetIme();static BOOLLGUICharArrived( char ch);static voidLGUIFillBackwardSelection();static voidLGUIFillForwardSelection();static BOOLIsChineseIme( int iIme);static BOOL ReadImeBmp( HWND hWnd);static void FreeImeBmp( HWND hWnd);static void RefreshListArea( HDC hDC);static void RefreshInputArea( HDC hDC);static void InvertLeftKey( HDC hDC);static void InvertRightKey( HDC hDC);static void SetLeftKeyPressed( HWND hWnd);static void SetRightKeyPressed( HWND hWnd);static void SetNoKeyPressed( HWND hWnd);static BOOL IsLeftKeyPressed( HWND hWnd);static BOOL IsRightKeyPressed( HWND hWnd);static int IsDbcOrSbc( HWND hWnd);static char* Sbc2Dbc( char c);static void RefreshListDisplay( HWND hWnd);static void RefreshInputDisplay( HWND hWnd);void MoveUpImeWindow();void MoveDownImeWindow();voidShowImeWindow();void HideImeWindow();void CreateImeWindow( LPRECT lpRect){ if(_lGUI_pImeWindow) DestroyImeWindow(); CreateWindow("imewindow",NULL,WS_IMEWIN | WS_BORDER,lpRect->left,lpRect->top, (lpRect->right - lpRect->left + 1),(lpRect->bottom - lpRect->top + 1), _lGUI_pWindowsTree,NULL,NULL,NULL); //attention imewindow is invisible when create.}void DestroyImeWindow(){ DestroyWindow((HWND)_lGUI_pImeWindow);}BOOL RegisterImeWindow(){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = 0; wcex.lpfnWndProc = (WNDPROC)ImeWindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = 0; wcex.hIcon = 0; wcex.hCursor = 0; wcex.hbrBackground = CreateSolidBrush(RGB(198,239,229)); wcex.lpszMenuName = NULL; wcex.lpszClassName = "imewindow"; wcex.hIconSm = 0; RegisterClass(&wcex); return true;}LRESULT ImeWindowProc( HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam){ HDC hDC; PAINTSTRUCT ps; PWindowsTree pWin; int iCurIme; RECT rcList,rcLeftKey,rcRightKey; void* pSrcData; void* pDestData; char pString[16]; char* pEnvStr; char pPathString[256]; char c; HBRUSH hBrush; COLORREF crColor; PWNDCLASSEX pWndClass; LRESULT res; pWin=(PWindowsTree)hWnd; switch(iMsg) { case LMSG_CREATE: if(!ReadImeBmp(hWnd)) return false; InstallLGUIIme(); break; case LMSG_RESETIME: LGUIResetIme(); break; case LMSG_ERASEBKGND: pWndClass=GetRegClass(pWin->lpszClassName); if(!pWndClass) return (LRESULT)NULL; hBrush=pWndClass->hbrBackground; crColor=((BRUSH*)hBrush)->crBrushColor; ((BRUSH*)hBrush)->crBrushColor=RGB_WHITE; res=DefWindowProc(hWnd, iMsg, wParam, lParam); ((BRUSH*)hBrush)->crBrushColor=crColor; return res; case LMSG_IME_LEFTKEY_PRESSED: LGUIFillBackwardSelection(); RefreshListDisplay(hWnd); break; case LMSG_IME_RIGHTKEY_PRESSED: LGUIFillForwardSelection(); RefreshListDisplay(hWnd); break; case LMSG_IME_LIST_PRESSED: break; case LMSG_CHAR: { int iIme; char* pRetString=NULL; char pString[4]; c = (char)wParam; if(IsDbcOrSbc(hWnd) == IME_STATUS_DBC){ pRetString = Sbc2Dbc(c); } if(pRetString) SendString2Client(pRetString); else{ iIme = GetCurrentIme(hWnd); if(IsChineseIme(iIme)){ LGUICharArrived(c); RefreshListDisplay(hWnd); RefreshInputDisplay(hWnd); } else{ pString[0]= c; pString[1]='\0'; if(c == 8) SendKeyDown2Client(SCANCODE_BACKSPACE); else SendString2Client(pString); break; } } break; } case LMSG_PENDOWN: CaptureMouse(hWnd,BYCLIENT); SetRect(&rcLeftKey, pWin->rect.right - 2 * IMEWIN_BORDER - 2 * IMEWIN_BUTTON_WIDTH, pWin->rect.top + IMEWIN_BORDER, pWin->rect.right - 2 * IMEWIN_BORDER - IMEWIN_BUTTON_WIDTH, pWin->rect.bottom - IMEWIN_BORDER); SetRect(&rcRightKey, pWin->rect.right - IMEWIN_BORDER - IMEWIN_BUTTON_WIDTH, pWin->rect.top + IMEWIN_BORDER, pWin->rect.right - IMEWIN_BORDER, pWin->rect.bottom - IMEWIN_BORDER); if(PtInRect(&rcLeftKey,(int)wParam,(int)lParam)){ SetLeftKeyPressed(hWnd); SendMessage(hWnd,LMSG_IME_LEFTKEY_PRESSED,wParam,lParam); scrInvalidateRect(hWnd,&rcLeftKey,true); } else if(PtInRect(&rcRightKey,(int)wParam,(int)lParam)){ SetRightKeyPressed(hWnd); SendMessage(hWnd,LMSG_IME_RIGHTKEY_PRESSED,wParam,lParam); scrInvalidateRect(hWnd,&rcRightKey,true); } break; case LMSG_PENUP: if(IsLeftKeyPressed(hWnd)){ SetRect(&rcLeftKey, pWin->rect.right - 2 * IMEWIN_BORDER - 2 * IMEWIN_BUTTON_WIDTH, pWin->rect.top + IMEWIN_BORDER, pWin->rect.right - 2 * IMEWIN_BORDER - IMEWIN_BUTTON_WIDTH, pWin->rect.bottom - IMEWIN_BORDER); SetNoKeyPressed(hWnd); scrInvalidateRect(hWnd,&rcLeftKey,true); } else if(IsRightKeyPressed(hWnd)){ SetRect(&rcRightKey, pWin->rect.right - IMEWIN_BORDER - IMEWIN_BUTTON_WIDTH, pWin->rect.top + IMEWIN_BORDER, pWin->rect.right - IMEWIN_BORDER, pWin->rect.bottom - IMEWIN_BORDER); SetNoKeyPressed(hWnd); scrInvalidateRect(hWnd,&rcRightKey,true); } DisCaptureMouse(); break; case LMSG_PENMOVE: break; case LMSG_PAINT: ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } pDestData = hDC->pData; pSrcData = (void*)pWin->dwAddData; memcpy(pDestData,pSrcData,IMEWIN_WIDTH * IMEWIN_HEIGHT* _lGUI_iBytesDataType); if(IsLeftKeyPressed(hWnd)) InvertLeftKey(hDC); if(IsRightKeyPressed(hWnd)) InvertRightKey(hDC); EndPaint(hWnd, &ps); break; case LMSG_DESTROY: FreeImeBmp(hWnd); UnInstallLGUIIme(); break; case LMSG_COMMAND: break; default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } return true;}//Install a new ime to lgui systemstatic BOOLInstallOneIme( PLGUIIme pLGUIIME){ int iSize; void* pData; PTaskBar pTaskBar; PTaskBarItem pItemIme; PLGUIIme pIme; FILE* fp; char *pEnv; char pPathStr[256]; pEnv = getenv("LGUI_HOME"); if(!pEnv) return false; if(!pLGUIIME) return false; if(!pImeLinkTable){ pImeLinkTable = pLGUIIME; } else{ pIme = pImeLinkTable; while(pIme->pNext) pIme = pIme->pNext; pIme->pNext = pLGUIIME; } //update taskbar data pTaskBar = (PTaskBar)(_lGUI_pTaskBarWindow->dwAddData); if(!pTaskBar) return false; pItemIme = pTaskBar->pItemIme; if(!pItemIme) return false; pItemIme->iTotalPictureNumber += 1; //pData; iSize = TASKBAR_BUTTONS_HEIGHT * TASKBAR_IMESWITCH_WIDTH * _lGUI_iBytesDataType; pData = malloc(pItemIme->iTotalPictureNumber * iSize); if(!pData) return false; memcpy(pData, pItemIme->pData, (pItemIme->iTotalPictureNumber - 1) * iSize); strcpy(pPathStr, pEnv); strcat(pPathStr, pLGUIIME->pTaskBarIconPath); fp = fopen(pPathStr, "rb"); if(!fp) return false; ReadBmpToBuf(fp, TASKBAR_IMESWITCH_WIDTH,TASKBAR_BUTTONS_HEIGHT, pData + (pItemIme->iTotalPictureNumber - 1) * iSize); fclose(fp); free(pItemIme->pData); pItemIme->pData = pData; return true;}static BOOLInstallLGUIIme(){ if(!InstallOneIme(&pinyinIme)) return false;// if(!InstallOneIme(&wubiIme))// return false; return true;}static voidUnInstallLGUIIme(){ PLGUIIme pIme, pNext; pIme = pImeLinkTable; while(pIme){ pIme->DestroyIme(); pNext = pIme->pNext; free(pIme); pIme = pNext; }}static PLGUIImeGetImePointerByIndex( int iIndex){ PLGUIIme pIme; pIme = pImeLinkTable; while(pIme){ if(pIme->iIndex == iIndex) return pIme; pIme = pIme->pNext; } return NULL;}static int GetCurrentIme()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -