/************************************************* * dconvdlg.c * * * * Copyright (C) 1995-1999 Microsoft Inc. * * * *************************************************/ #include "prop.h" #include "upimeres.h" #include /***************************************************************************** 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. ****************************************************************************/ BOOL CALLBACK ConvDialogProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam) { LPNMHDR lpnmhdr; static DWORD dwDesOffset,dwDesLen; static DWORD dwRuleOffset,dwRuleLen; static char szMbName[MAX_PATH]; static char szSrcName[MAX_PATH]; static char _szStr[MAX_PATH]; static char Ext[]=".mb"; static BOOL bModify; LPRULE lpRule; int i; static DESCRIPTION Descript; switch (uMessage) { case WM_INITDIALOG: { LPENCODEAREA lpEncode; InstallConvSubClass(GetDlgItem(hdlg,IDC_LIST)); SendDlgItemMessage(hdlg,IDC_IMENAME,EM_LIMITTEXT,24,0L); SendDlgItemMessage(hdlg,IDC_USEDCODE,EM_LIMITTEXT,MAXUSEDCODES-1,0L); SetConvDisable(hdlg); PropSheet_CancelToClose(GetParent(hdlg)); 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); lpEncode = (LPENCODEAREA) GlobalLock(hEncode); ConvInitEncode(lpEncode); GlobalUnlock(hEncode); break; } case WM_NOTIFY: lpnmhdr = (NMHDR FAR *)lparam; switch (lpnmhdr->code) { case PSN_SETACTIVE: break; case PSN_APPLY: if(bModify) { LoadString(NULL, IDS_FILEMODIFY, _szStr, sizeof(_szStr)); wsprintf(szMbName,"创建输入法页面中\n\'%s\'\n%s",szSrcName,_szStr); if(ErrMessage(hdlg,szMbName)) { SendMessage(hdlg,WM_COMMAND,IDC_SAVE,0L); } } break; case PSN_RESET: break; case PSN_QUERYCANCEL: break; case PSN_HELP: break; default: break; } break; case WM_COMMAND: switch (LOWORD(wparam)) { case ID_FILEOPEN: if(bModify) { char errString[MAX_PATH]; LoadString(NULL, IDS_FILEMODIFY, _szStr, sizeof(_szStr)); wsprintf(errString,"\'%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; _szStr[0] = 0; SetDlgItemText(hdlg,IDC_EDITBOX,_szStr); SendDlgItemMessage(hdlg,IDC_LIST,LB_RESETCONTENT,0,0L); { LPSTR lpString; if((lpString = strrchr(szSrcName,'\\'))!=NULL) SetDlgItemText(hdlg,IDC_SRCNAME, lpString+1); lstrcpy(szMbName, szSrcName); lstrcpy(_szStr, szSrcName); if((lpString = strrchr(szMbName,'.'))!=NULL) *lpString = 0; lstrcat(szMbName,Ext); } 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)); 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)); 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; } { char WildChar; WildChar=_szStr[0]; if(WildChar != Descript.cWildChar) { EnableWindow(GetDlgItem(hdlg,IDC_SAVE),TRUE); bModify = TRUE; } GetDlgItemText(hdlg,IDC_USEDCODE,_szStr,sizeof(_szStr)); if(strchr(_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 = SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCURSEL,0,0L); 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 = SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCURSEL,0,0L); if(nSelect != LB_ERR) { SendDlgItemMessage(hdlg,IDC_LIST,LB_DELETESTRING,nSelect,0L); 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=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCURSEL,0,0L))==LB_ERR) { nSelect=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0L); SendDlgItemMessage(hdlg,IDC_LIST,LB_SETCURSEL,nSelect-1,0L); } } 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; char _szStr[20]; GetDlgItemText(hDlg,IDC_IMENAME,lpDescript->szName,NAMESIZE); GetDlgItemText(hDlg,IDC_USEDCODE,lpDescript->szUsedCode,MAXUSEDCODES); GetDlgItemText(hDlg,IDC_WILDCHAR,_szStr,sizeof(_szStr)); DelSpace(_szStr); if(_szStr[0]==0) _szStr[0]='?'; 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; char _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)); DelSpace(lpImeRes->Version); if(lstrlen(lpImeRes->Version) == 0) { ProcessError(ERR_VERSION, hDlg, WARNING); return FALSE; } GetDlgItemText(hDlg, IDC_GROUP, lpImeRes->Depart, sizeof(lpImeRes->Depart)); DelSpace(lpImeRes->Depart); if(lstrlen(lpImeRes->Depart) == 0) { ProcessError(ERR_GROUP, hDlg, WARNING); return FALSE; } GetDlgItemText(hDlg, IDC_BMP, lpImeRes->BmpName, sizeof(lpImeRes->BmpName)); GetDlgItemText(hDlg, IDC_ICO, lpImeRes->IcoName, sizeof(lpImeRes->IcoName)); GetValue(hDlg, &(lpImeRes->Value)); return TRUE; }