/************************************************* * convdlg.c * * * * Copyright (C) 1995-1999 Microsoft Inc. * * * *************************************************/ #include #include "prop.h" #include "upimeres.h" #include #include #ifdef UNICODE extern TCHAR Title[]; extern TCHAR szVer[]; #else extern BYTE Title[]; extern BYTE szVer[]; #endif /***************************************************************************** FUNCTION: ConvDialogProc(HWND, UINT, WPARAM, LPARAM) PURPOSE: Processes messages for "conv" property sheet. PARAMETERS: hdlg - window handle of the property sheet wMessage - type of message wparam - message-specific information lparam - message-specific information RETURN VALUE: TRUE - message handled FALSE - message not handled HISTORY: 04-18-95 Yehfew Tie Created. ****************************************************************************/ INT_PTR CALLBACK ConvDialogProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam) { LPNMHDR lpnmhdr; static DWORD dwDesOffset,dwDesLen; static DWORD dwRuleOffset,dwRuleLen; static TCHAR szMbName[MAX_PATH]; static TCHAR szSrcName[MAX_PATH]; static TCHAR _szStr[MAX_PATH]; static BOOL bModify; LPRULE lpRule; int i; static DESCRIPTION Descript; switch (uMessage) { case WM_INITDIALOG: { //install conv sub class lpConvProc = (FARPROC)SetWindowLongPtr(GetDlgItem(hdlg,IDC_LIST), GWLP_WNDPROC,(LONG_PTR)ConvEditProc); SendDlgItemMessage(hdlg,IDC_IMENAME,EM_LIMITTEXT,24,0L); SendDlgItemMessage(hdlg,IDC_USEDCODE,EM_LIMITTEXT,MAXUSEDCODES,0L); SetConvDisable(hdlg); PropSheet_CancelToClose(GetParent(hdlg)); break; } case WM_DESTROY: if(hRule) GlobalFree(hRule); if(hEncode) GlobalFree(hEncode); break; case WM_NOTIFY: lpnmhdr = (NMHDR FAR *)lparam; switch (lpnmhdr->code) { case PSN_SETACTIVE: hRule = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, sizeof(RULE)*MAXCODELEN); hEncode = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT, NUMENCODEAREA*sizeof(ENCODEAREA)); if(!hRule || !hEncode) ProcessError(ERR_OUTOFMEMORY,hdlg,ERR); if ( hEncode ) ConvInitEncode(hEncode); break; case PSN_APPLY: if(bModify) { LoadString(NULL, IDS_FILEMODIFY, _szStr, sizeof(_szStr)/sizeof(TCHAR)); #ifdef UNICODE { TCHAR UniTmp[] = {0x521B, 0x5EFA, 0x8F93, 0x5165, 0x6CD5, 0x9875, 0x9762, 0x4E2D, 0x005C, 0x006E, 0x005C, 0x0027, 0x0025, 0x0077, 0x0073, 0x005C, 0x0027, 0x005C, 0x006E, 0x0025, 0x0077, 0x0073, 0x0000}; wsprintf(szMbName,UniTmp,szSrcName,_szStr); } #else wsprintf(szMbName,"创建输入法页面中\n\'%s\'\n%s",szSrcName,_szStr); #endif if(ErrMessage(hdlg,szMbName)) { SendMessage(hdlg,WM_COMMAND,IDC_SAVE,0L); } } break; case PSN_RESET: break; case PSN_QUERYCANCEL: break; case PSN_HELP: break; case PSN_KILLACTIVE: break; default: break; } break; case WM_COMMAND: switch (LOWORD(wparam)) { case IDC_BROWSE: if(bModify) { TCHAR errString[MAX_PATH]; LoadString(NULL, IDS_FILEMODIFY, _szStr, sizeof(_szStr)/sizeof(TCHAR)); wsprintf(errString,TEXT("\'%s\'%s"),szSrcName,_szStr); if(ErrMessage(hdlg,errString)) SendMessage(hdlg,WM_COMMAND,IDC_SAVE,0L); } SetDlgItemText(hdlg,IDC_MBNAME,szMbName); { #ifdef UNICODE static TCHAR szTitle[] = {0x6253, 0x5F00, 0x0000}; #else TCHAR szTitle[MAX_PATH]; strcpy(szTitle,"打开"); #endif if(!TxtFileOpenDlg(hdlg,_szStr,szTitle)) break; } lstrcpy(szSrcName,_szStr); bModify = FALSE; memset(_szStr, 0, MAX_PATH); SetDlgItemText(hdlg,IDC_EDITBOX,_szStr); SendDlgItemMessage(hdlg,IDC_LIST,LB_RESETCONTENT,0,0L); { LPTSTR lpString; if((lpString = _tcsrchr(szSrcName,TEXT('\\')))!=NULL) SetDlgItemText(hdlg,IDC_SRCNAME, lpString+1); lstrcpy(szMbName, szSrcName); lstrcpy(_szStr, szSrcName); if((lpString = _tcsrchr(szMbName,TEXT('.')))!=NULL) *lpString = 0; lstrcat(szMbName,TEXT(MbExt)); } SetDlgItemText(hdlg,IDC_MBNAME,szMbName); { int nRetValue; nRetValue = ConvGetDescript(hdlg, szSrcName, &dwDesOffset, &dwDesLen, &Descript, FALSE); if(nRetValue ==(-ERR_FILENOTOPEN)) { szSrcName[0]=0; lstrcpy(szMbName, szSrcName); SetDlgItemText(hdlg,IDC_SRCNAME,szSrcName); SetDlgItemText(hdlg,IDC_MBNAME,szMbName); MessageBeep((UINT)-1); break; } } if(!(lpRule = GlobalLock(hRule)) ) { ProcessError(ERR_GLOBALLOCK,hdlg,ERR); break; } if(ConvGetRule(hdlg, szSrcName, &dwRuleOffset, &dwRuleLen, lpRule, &Descript)==(-ERR_FILENOTOPEN)) { szSrcName[0]=0; lstrcpy(szMbName,szSrcName); SetDlgItemText(hdlg,IDC_SRCNAME,szSrcName); SetDlgItemText(hdlg,IDC_MBNAME,szMbName); GlobalUnlock(hRule); MessageBeep((UINT)-1); EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); break; } SetDlgDescript(hdlg,&Descript); SetDlgRuleStr(hdlg,Descript.wNumRules,lpRule); SetDlgItemText(hdlg,IDC_MBNAME,szMbName); GlobalUnlock(hRule); SetConvEnable(hdlg); EnableWindow(GetDlgItem(hdlg,IDC_SAVE),FALSE); SendMessage(GetDlgItem(hdlg,ID_FILEOPEN),BM_SETSTYLE,BS_PUSHBUTTON,0L); SendMessage(GetDlgItem(hdlg,IDC_CONV),BM_SETSTYLE,BS_DEFPUSHBUTTON,TRUE); SetFocus(GetDlgItem(hdlg,IDC_CONV)); break; case IDC_MBNAME: GetDlgItemText(hdlg,IDC_MBNAME,szMbName,256); if(lstrlen(szMbName) == 0) { EnableWindow(GetDlgItem(hdlg,IDC_CONV),FALSE); break; } else { GetDlgItemText(hdlg,IDC_IMENAME,_szStr,32); if(lstrlen(_szStr) != 0 && Descript.wMaxCodes != 0) EnableWindow(GetDlgItem(hdlg,IDC_CONV),TRUE); else EnableWindow(GetDlgItem(hdlg,IDC_CONV),FALSE); } break; case IDC_IMENAME: GetDlgItemText(hdlg,IDC_IMENAME,_szStr,128); _szStr[128]=0; if(lstrlen(_szStr) == 0) { EnableWindow(GetDlgItem(hdlg,IDC_CONV),FALSE); break; } else { GetDlgItemText(hdlg,IDC_MBNAME,szMbName,256); if(lstrlen(szMbName) != 0 && Descript.wMaxCodes != 0) EnableWindow(GetDlgItem(hdlg,IDC_CONV),TRUE); else EnableWindow(GetDlgItem(hdlg,IDC_CONV),FALSE); } if(lstrcmpi(Descript.szName,_szStr)==0) break; bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); break; case IDC_MAXCODES: { int nMaxCodes; nMaxCodes = GetDlgItemInt (hdlg,IDC_MAXCODES,NULL,FALSE); if(nMaxCodes > MAXCODELEN) { MessageBeep((UINT)-1); SetDlgItemInt (hdlg,IDC_MAXCODES,MAXCODELEN,FALSE); Descript.wMaxCodes = MAXCODELEN; } if(Descript.wMaxCodes != nMaxCodes) { bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); } break; } case IDC_USEDCODE: GetDlgItemText(hdlg,IDC_USEDCODE,_szStr,sizeof(_szStr)/sizeof(TCHAR)); if(lstrlen(_szStr) == 0) EnableWindow(GetDlgItem(hdlg,IDC_CONV),FALSE); if(lstrcmpi(Descript.szUsedCode,_szStr)==0) break; bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); break; case IDC_WILDCHAR: GetDlgItemText(hdlg,IDC_WILDCHAR,_szStr,sizeof(_szStr)/sizeof(TCHAR)); if(lstrlen(_szStr)==0 ) { if( Descript.cWildChar!=0) { bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); } break; } if(lstrlen(_szStr)>1) { MessageBeep((UINT)-1); _szStr[0]=0; SetDlgItemText(hdlg,IDC_WILDCHAR,_szStr); break; } { TCHAR WildChar; WildChar=_szStr[0]; if(WildChar != Descript.cWildChar) { EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); bModify = TRUE; } GetDlgItemText(hdlg,IDC_USEDCODE,_szStr,sizeof(_szStr)/sizeof(TCHAR)); if(_tcschr(_szStr,WildChar) != NULL) { _szStr[0]=0; SetDlgItemText(hdlg,IDC_WILDCHAR,_szStr); MessageBeep((UINT)-1); break; } } break; case IDC_SINGLEELEMENT: case IDC_MULTIELEMENT: if(Descript.byMaxElement == (BYTE)(IsDlgButtonChecked(hdlg,IDC_MULTIELEMENT)?2:1)) break; Descript.byMaxElement = 1 + Descript.byMaxElement%2; bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); break; case IDC_ADD: { FARPROC lpProcInfo; szRuleStr[0] = 0; if(Descript.wNumRules >= MAXCODELEN) { ProcessError(ERR_RULENUM,hdlg,WARNING); break; } lpProcInfo = MakeProcInstance((FARPROC)AddRuleDlg, hInst); DialogBox(hInst, MAKEINTRESOURCE(IDD_ADDRULE), hdlg, (DLGPROC)AddRuleDlg); FreeProcInstance(lpProcInfo); bModify = TRUE; break; } case IDC_MODIFY: { FARPROC lpProcInfo; int nSelect; nSelect = (INT)SendDlgItemMessage(hdlg, IDC_LIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0); if(nSelect == LB_ERR) { MessageBeep((UINT)-1); break; } SendDlgItemMessage(hdlg,IDC_LIST,LB_GETTEXT,nSelect,(LPARAM)szRuleStr); lpProcInfo = MakeProcInstance((FARPROC)ModiRuleDlg, hInst); DialogBox(hInst, MAKEINTRESOURCE(IDD_EDITRULE), hdlg, (DLGPROC)ModiRuleDlg); FreeProcInstance(lpProcInfo); break; } case IDC_DEL: { int nSelect; nSelect = (INT)SendDlgItemMessage(hdlg, IDC_LIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0); if(nSelect != LB_ERR) { SendDlgItemMessage(hdlg,IDC_LIST,LB_DELETESTRING, nSelect,(LPARAM)0); if(!(lpRule = GlobalLock(hRule)) ) { ProcessError(ERR_GLOBALLOCK,hdlg,ERR); break; } DelSelRule(Descript.wNumRules,(WORD)nSelect,lpRule); Descript.wNumRules--; GlobalUnlock(hRule); bModify = TRUE; EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); SetFocus(GetDlgItem(hdlg,IDC_LIST)); SendDlgItemMessage(hdlg,IDC_LIST,LB_SETCURSEL,nSelect,0L); if((nSelect=(INT)SendDlgItemMessage(hdlg,IDC_LIST, LB_GETCURSEL,0,0L))==LB_ERR) { nSelect=(INT)SendDlgItemMessage(hdlg, IDC_LIST, LB_GETCOUNT, (WPARAM)0, (LPARAM)0); SendDlgItemMessage(hdlg, IDC_LIST, LB_SETCURSEL, (WPARAM)(nSelect-1), (LPARAM)0); } } else MessageBeep((UINT)-1); break; } case IDC_ADDRULE: if(!(lpRule = GlobalLock(hRule)) ) { ProcessError(ERR_GLOBALLOCK,hdlg,ERR); szRuleStr[0] = 0; break; } if(RuleParse(hdlg,szRuleStr,0,lpRule,Descript.wMaxCodes)) { int nCnt; nCnt =(WORD)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0L); if(nCnt != 0) { for(i=0; ibyMaxElement==1)?IDC_SINGLEELEMENT:IDC_MULTIELEMENT; SetDlgItemText(hDlg,IDC_IMENAME,lpDescript->szName); SetDlgItemText(hDlg,IDC_USEDCODE,lpDescript->szUsedCode); _szStr[0]=lpDescript->cWildChar; _szStr[1]=0; SetDlgItemText(hDlg,IDC_WILDCHAR,_szStr); SetDlgItemInt (hDlg,IDC_MAXCODES,lpDescript->wMaxCodes,FALSE); CheckRadioButton(hDlg,IDC_SINGLEELEMENT,IDC_MULTIELEMENT,nElement); } void GetDlgDescript(HWND hDlg,LPDESCRIPTION lpDescript) { BOOL bTrans; TCHAR _szStr[20]; GetDlgItemText(hDlg,IDC_IMENAME,lpDescript->szName,NAMESIZE); GetDlgItemText(hDlg,IDC_USEDCODE,lpDescript->szUsedCode,MAXUSEDCODES); GetDlgItemText(hDlg,IDC_WILDCHAR,_szStr,sizeof(_szStr)/sizeof(TCHAR)); DelSpace(_szStr); if(_szStr[0]==0) _szStr[0]=TEXT('?'); lpDescript->cWildChar=_szStr[0]; lpDescript->wMaxCodes=(WORD)GetDlgItemInt (hDlg,IDC_MAXCODES,&bTrans,FALSE); lpDescript->wNumCodes=(WORD)lstrlen(lpDescript->szUsedCode); lpDescript->byMaxElement=(BYTE)(IsDlgButtonChecked(hDlg,IDC_MULTIELEMENT)?2:1); lpDescript->wNumRules=(WORD)SendDlgItemMessage(hDlg,IDC_LIST,LB_GETCOUNT,0,0L); } void SetDlgRuleStr(HWND hDlg,WORD NumRules,LPRULE lpRule) { WORD i; TCHAR _szStr[MAX_PATH]; SendDlgItemMessage(hDlg,IDC_LIST,LB_RESETCONTENT,0,0L); if(NumRules==0) return; for(i=0; i=MAXCODELEN) return; for(i=wSelect;iVersion, sizeof(lpImeRes->Version)/sizeof(TCHAR)); if(lstrlen(lpImeRes->Version) == 0) { ProcessError(ERR_VERSION, hDlg, WARNING); return FALSE; } GetDlgItemText(hDlg, IDC_GROUP, lpImeRes->Depart, sizeof(lpImeRes->Depart)/sizeof(TCHAR)); if(lstrlen(lpImeRes->Depart) == 0) { ProcessError(ERR_GROUP, hDlg, WARNING); return FALSE; } GetDlgItemText(hDlg, IDC_BMP, lpImeRes->BmpName, sizeof(lpImeRes->BmpName)/sizeof(TCHAR)); GetDlgItemText(hDlg, IDC_ICO, lpImeRes->IcoName, sizeof(lpImeRes->IcoName)/sizeof(TCHAR)); GetValue(hDlg, &(lpImeRes->Value)); return TRUE; }