/*++ Copyright (c) 1999 Microsoft Corporation Module Name: ConstraintsPage.cpp Abstract: Functions for "Constraints" page of the wizard. Author: Sergey Kuzin (a-skuzin@microsoft.com) 09-August-1999 Environment: Revision History: --*/ #include "tsverui.h" #include "resource.h" void AddSelectedItemsToControl(HWND hwndDlg,int iCtrl); void AddOneSelectedItemToControl(HWND hwndDlg,int iCtrl); void AddSelectedRangeToControl(HWND hwndDlg); void AssembleContraints(HWND hwndDlg,LPSHAREDWIZDATA pdata); void InitConstraintsPage(HWND hwndDlg); void AddToControl(HWND hwndDlg, int iCtrl,int &i, TCHAR *szConstraints); void AddOneToControl(HWND hwndDlg, int iCtrl,int &i, TCHAR *szConstraints); void AddRangeToControl(HWND hwndDlg, int &i, TCHAR *szConstraints); BOOL CheckSyntax(HWND hwndDlg, WORD wCtrlId); BOOL CheckRangeSyntax(HWND hwndDlg); /*++ Routine Description : dialog box procedure for the "Constraints" page. Arguments : IN HWND hwndDlg - handle to dialog box. IN UINT uMsg - message to be acted upon. IN WPARAM wParam - value specific to wMsg. IN LPARAM lParam - value specific to wMsg. Return Value : TRUE if it processed the message FALSE if it did not. --*/ INT_PTR CALLBACK ConstraintsPageProc ( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { //Retrieve the shared user data from GWL_USERDATA LPSHAREDWIZDATA pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (uMsg) { case WM_INITDIALOG : { //Get the shared data from PROPSHEETPAGE lParam value //and load it into GWL_USERDATA pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR) pdata); InitConstraintsPage(hwndDlg); break; } case WM_NOTIFY : { LPNMHDR lpnm = (LPNMHDR) lParam; switch (lpnm->code) { case PSN_SETACTIVE : //Enable the Back and Next buttons PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT); if(pdata->pszConstraints){ delete pdata->pszConstraints; pdata->pszConstraints=NULL; } break; case PSN_WIZNEXT : //Handle a Next button click here if(!CheckSyntax(hwndDlg,IDC_ALLOW)|| !CheckSyntax(hwndDlg,IDC_DISALLOW)|| !CheckSyntax(hwndDlg,IDC_HIGHER)|| !CheckSyntax(hwndDlg,IDC_LOWER)|| !CheckRangeSyntax(hwndDlg)){ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1); return TRUE; } AssembleContraints(hwndDlg,pdata); break; case PSN_RESET : //Handle a Cancel button click, if necessary break; default : break; } } break; case WM_COMMAND: switch ( LOWORD(wParam) ) { case ID_ALLOW: AddSelectedItemsToControl(hwndDlg,IDC_ALLOW); break; case ID_DISALLOW: AddSelectedItemsToControl(hwndDlg,IDC_DISALLOW); break; case ID_HIGHER: AddOneSelectedItemToControl(hwndDlg,IDC_HIGHER); break; case ID_LOWER: AddOneSelectedItemToControl(hwndDlg,IDC_LOWER); break; case ID_RANGE: AddSelectedRangeToControl(hwndDlg); break; default: break; } break; default: break; } return FALSE; } /*++ Routine Description : Checks validity of entered values Arguments : IN HWND hwndDlg - Page handle. IN int wCtrlId - edit box ID. Return Value : FALSE if some invalid values found. --*/ BOOL CheckSyntax( HWND hwndDlg, WORD wCtrlId ) { HWND hwndCtrl=GetDlgItem(hwndDlg,wCtrlId); TCHAR szBuf[MAX_LEN+1]; TCHAR szTemplate[MAX_LEN-100+1]; TCHAR szCtrlName[100+1]; TCHAR szMsg[MAX_LEN+1]; int size=GetDlgItemText(hwndDlg,wCtrlId,szBuf,MAX_LEN); if(!size){ return TRUE; } do{ size--; if(!_istdigit(szBuf[size])&&szBuf[size]!=' '){ switch(wCtrlId){ case IDC_HIGHER: case IDC_LOWER: LoadString(g_hInst,IDS_INVALID_VALUE,szTemplate,MAX_LEN-100); LoadString(g_hInst,wCtrlId,szCtrlName,100); wsprintf(szMsg,szTemplate,szCtrlName); MessageBox(hwndDlg,szMsg,NULL,MB_OK); return FALSE; case IDC_ALLOW: case IDC_DISALLOW: if(szBuf[size]!=','){ LoadString(g_hInst,IDS_INVALID_VALUE,szTemplate,MAX_LEN-100); LoadString(g_hInst,wCtrlId,szCtrlName,100); wsprintf(szMsg,szTemplate,szCtrlName); MessageBox(hwndDlg,szMsg,NULL,MB_OK); return FALSE; }else{ break; } default: break; } } }while(size); return TRUE; } /*++ Routine Description : Checks validity of entered values for IDC_RANGE edit box Arguments : IN HWND hwndDlg - Page handle. Return Value : FALSE if some invalid values found. --*/ BOOL CheckRangeSyntax( HWND hwndDlg) { HWND hwndCtrl=GetDlgItem(hwndDlg,IDC_RANGE); TCHAR szBuf[MAX_LEN+1]; TCHAR szTemplate[MAX_LEN-100+1]; TCHAR szCtrlName[100+1]; TCHAR szMsg[MAX_LEN+1]; int size=GetDlgItemText(hwndDlg,IDC_RANGE,szBuf,MAX_LEN); if(!size){ return TRUE; } BOOL bBracket=FALSE; BOOL bColon=FALSE; BOOL bDigit=FALSE; do{ size--; if(!bBracket)//outside of brackets { if(szBuf[size]!=';' && szBuf[size]!=')' && szBuf[size]!=' '){ //illegal symbol LoadString(g_hInst,IDS_INVALID_VALUE,szTemplate,MAX_LEN-100); LoadString(g_hInst,IDC_RANGE,szCtrlName,100); wsprintf(szMsg,szTemplate,szCtrlName); MessageBox(hwndDlg,szMsg,NULL,MB_OK); return FALSE; } } else {//inside of brackets if((!_istdigit(szBuf[size]) && szBuf[size]!=':' && szBuf[size]!='(' && szBuf[size]!=' ')|| //illegal symbol (szBuf[size]==':' && bColon)|| // two conons inside brackets (szBuf[size]=='(' && !bColon)|| // no colons inside brackets (szBuf[size]==':' && !bDigit)|| // no number after colon '(123:)' (szBuf[size]=='(' && !bDigit)){ // no number after bracket '(:123)' LoadString(g_hInst,IDS_INVALID_VALUE,szTemplate,MAX_LEN-100); LoadString(g_hInst,IDC_RANGE,szCtrlName,100); wsprintf(szMsg,szTemplate,szCtrlName); MessageBox(hwndDlg,szMsg,NULL,MB_OK); return FALSE; } } if(szBuf[size]==')'){ bBracket=TRUE; bColon=FALSE; bDigit=FALSE; continue; } if(szBuf[size]=='('){ bBracket=FALSE; bColon=FALSE; bDigit=FALSE; continue; } if(szBuf[size]==':'){ bColon=TRUE; bDigit=FALSE; continue; } if(_istdigit(szBuf[size])){ bDigit=TRUE; continue; } }while(size); return TRUE; } /*++ Routine Description : Get IDs of selected listbox items Arguments : IN HWND hwndList - handle to list box. OUT int **ppItems - pointer to pointer to array of IDs of selected items Return Value : number of selected items. --*/ // int GetSelectedItems( HWND hwndList, int **ppItems) { *ppItems=NULL; int nItems=(int)SendMessage(hwndList,LB_GETSELCOUNT,(WPARAM)0,(LPARAM)0); if(nItems){ *ppItems=new int[nItems]; if(*ppItems) { SendMessage(hwndList,LB_GETSELITEMS,(WPARAM)nItems,(LPARAM)*ppItems); } else { return 0; } } return nItems; } /*++ Routine Description : Adds selected items from list to IDC_ALLOW or IDC_DISALLOW edit box Arguments : IN HWND hwndDlg - Page handle. IN int iCtrl - edit box ID. Return Value : none --*/ void AddSelectedItemsToControl( HWND hwndDlg, int iCtrl) { static HWND hwndList=NULL; if(!hwndList){ hwndList=GetDlgItem(hwndDlg,IDC_VERSION_LIST); } int *pItemIDs; int nItems=GetSelectedItems(hwndList,&pItemIDs); if(nItems){ _TCHAR szNumber[11];//assume that list contains only numbers _TCHAR szCtrlText[MAX_LEN+1]; for(int i=0;i': AddOneToControl(hwndDlg, IDC_HIGHER,i, pBuffer); break; case '!': i++; // increment past the = sign AddToControl(hwndDlg, IDC_DISALLOW,i, pBuffer); break; case '(': AddRangeToControl(hwndDlg, i, pBuffer); break; default: break; } } delete pBuffer; pBuffer=NULL; } //-------------------------------------------------------------------------- //END "Parse constraint string" } /*++ Routine Description : Adds values from constraint string to IDC_ALLOW or IDC_DISALLOW edit box Arguments : IN HWND hwndDlg - Page handle. IN int iCtrl - edit box ID. IN,OUT int &i - reference to current position in string IN TCHAR *szConstraints - constraint string Return Value : none --*/ void AddToControl( HWND hwndDlg, int iCtrl, int &i, TCHAR *szConstraints) { int index; TCHAR szNumber[11];//max 10 digits + '\0' TCHAR szItemText[MAX_LEN+1]; // parse a number out of the registry string index = 0; i++; //pass '=' or '>' or '<' or ',' symbol while ( ( _istdigit(szConstraints[i]) || szConstraints[i] == ' ' ) && index < 10 ) { if(szConstraints[i] != ' '){ szNumber[index] = szConstraints[i]; index++; } i++; } szNumber[index] = '\0'; GetDlgItemText(hwndDlg,iCtrl,szItemText,MAX_LEN); if(_tcslen(szItemText)<=(MAX_LEN-11)){//10 digits+',' if(_tcslen(szItemText)){ _tcscat(szItemText,TEXT(",")); } _tcscat(szItemText,szNumber); SetDlgItemText(hwndDlg,iCtrl,szItemText); } if(szConstraints[i]==','){ AddToControl(hwndDlg, iCtrl, i, szConstraints); } } /*++ Routine Description : Adds values from constraint string to IDC_HIGHER or IDC_LOWER edit box Arguments : IN HWND hwndDlg - Page handle. IN int iCtrl - edit box ID. IN,OUT int &i - reference to current position in string IN TCHAR *szConstraints - constraint string Return Value : none --*/ void AddOneToControl( HWND hwndDlg, int iCtrl, int &i, TCHAR *szConstraints) { int index; TCHAR szNumber[11];//max 10 digits + '\0' // parse a number out of the registry string index = 0; i++; //pass '=' or '>' or '<' or ',' symbol while ( ( _istdigit(szConstraints[i]) || szConstraints[i] == ' ' ) && index < 10 ) { if(szConstraints[i] != ' '){ szNumber[index] = szConstraints[i]; index++; } i++; } szNumber[index] = '\0'; SetDlgItemText(hwndDlg,iCtrl,szNumber); } /*++ Routine Description : Adds values from constraint string to IDC_RANGE edit box Arguments : IN HWND hwndDlg - Page handle. IN,OUT int &i - reference to current position in string IN TCHAR *szConstraints - constraint string Return Value : none --*/ void AddRangeToControl( HWND hwndDlg, int &i, TCHAR *szConstraints) { int index; TCHAR szRange[24];//10+10+'('+':'+')'+'\0' index = 0; while (szConstraints[i] != ')' && index < 22 ){ if(szConstraints[i]!=' '){//delete all spaces szRange[index] = szConstraints[i]; index++; } i++; } szRange[index]=')';//index max - 22 index++; szRange[index] = '\0';//index max - 23 TCHAR szItemText[MAX_LEN+1]; GetDlgItemText(hwndDlg,IDC_RANGE,szItemText,MAX_LEN); if(_tcslen(szItemText)<(MAX_LEN-24)){//23+',' do not count '\0' if(_tcslen(szItemText)){ _tcscat(szItemText,TEXT(";")); } _tcscat(szItemText,szRange); SetDlgItemText(hwndDlg,IDC_RANGE,szItemText); } } /*++ Routine Description : Assembles constraint string from values in edit boxes and writes it in data structure. Arguments : IN HWND hwndDlg - Page handle. LPSHAREDWIZDATA pdata - pointer to data structure Return Value : none --*/ void AssembleContraints(HWND hwndDlg,LPSHAREDWIZDATA pdata) { TCHAR szAllow[MAX_LEN+1]; TCHAR szDisallow[MAX_LEN+1]; TCHAR szHigher[MAX_LEN+1]; TCHAR szLower[MAX_LEN+1]; TCHAR szRange[MAX_LEN+1]; GetDlgItemText(hwndDlg,IDC_ALLOW,szAllow,MAX_LEN); GetDlgItemText(hwndDlg,IDC_DISALLOW,szDisallow,MAX_LEN); GetDlgItemText(hwndDlg,IDC_HIGHER,szHigher,MAX_LEN); GetDlgItemText(hwndDlg,IDC_LOWER,szLower,MAX_LEN); GetDlgItemText(hwndDlg,IDC_RANGE,szRange,MAX_LEN); int Size=_tcslen(szAllow)+_tcslen(szDisallow)+_tcslen(szHigher)+ _tcslen(szLower)+_tcslen(szRange)+10;//'='+'!='+'<'+'>'+4*';'+'\0'=10 pdata->pszConstraints=new TCHAR[Size]; if(pdata->pszConstraints != NULL) { pdata->pszConstraints[0]=0; } else { return; } if(_tcslen(szAllow)){ _tcscpy(pdata->pszConstraints,TEXT("=")); _tcscat(pdata->pszConstraints,szAllow); } if(_tcslen(szDisallow)){ if(_tcslen(pdata->pszConstraints)){ _tcscat(pdata->pszConstraints,TEXT(";!=")); }else{ _tcscat(pdata->pszConstraints,TEXT("!=")); } _tcscat(pdata->pszConstraints,szDisallow); } if(_tcslen(szHigher)){ if(_tcslen(pdata->pszConstraints)){ _tcscat(pdata->pszConstraints,TEXT(";>")); }else{ _tcscat(pdata->pszConstraints,TEXT(">")); } _tcscat(pdata->pszConstraints,szHigher); } if(_tcslen(szLower)){ if(_tcslen(pdata->pszConstraints)){ _tcscat(pdata->pszConstraints,TEXT(";<")); }else{ _tcscat(pdata->pszConstraints,TEXT("<")); } _tcscat(pdata->pszConstraints,szLower); } if(_tcslen(szRange)){ if(_tcslen(pdata->pszConstraints)){ _tcscat(pdata->pszConstraints,TEXT(";")); } _tcscat(pdata->pszConstraints,szRange); } }