|
|
1.1 ! root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org ! 2: This product uses components written by Paul Le Roux <[email protected]> */ ! 3: ! 4: #include "TCdefs.h" ! 5: #include "combo.h" ! 6: ! 7: #include <time.h> ! 8: ! 9: #define SIZEOF_MRU_LIST 8 ! 10: ! 11: void ! 12: AddComboItem (HWND hComboBox, char *lpszFileName) ! 13: { ! 14: LPARAM nIndex; ! 15: ! 16: nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, ! 17: (LPARAM) & lpszFileName[0]); ! 18: ! 19: if (nIndex == CB_ERR && *lpszFileName) ! 20: { ! 21: long lTime = time (NULL); ! 22: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & lpszFileName[0]); ! 23: if (nIndex != CB_ERR) ! 24: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) lTime); ! 25: } ! 26: ! 27: if (nIndex != CB_ERR && *lpszFileName) ! 28: nIndex = SendMessage (hComboBox, CB_SETCURSEL, nIndex, 0); ! 29: ! 30: if (*lpszFileName == 0) ! 31: { ! 32: SendMessage (hComboBox, CB_SETCURSEL, (WPARAM) - 1, 0); ! 33: } ! 34: } ! 35: ! 36: ! 37: LPARAM ! 38: MoveEditToCombo (HWND hComboBox) ! 39: { ! 40: char szTmp[256] = ! 41: {0}; ! 42: ! 43: GetWindowText (hComboBox, szTmp, sizeof (szTmp)); ! 44: ! 45: if (strlen (szTmp) > 0) ! 46: { ! 47: LPARAM nIndex = SendMessage (hComboBox, CB_FINDSTRINGEXACT, (WPARAM) - 1, ! 48: (LPARAM) & szTmp[0]); ! 49: if (nIndex == CB_ERR) ! 50: { ! 51: long lTime = time (NULL); ! 52: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) & szTmp[0]); ! 53: if (nIndex != CB_ERR) ! 54: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime); ! 55: } ! 56: else ! 57: { ! 58: long lTime = time (NULL); ! 59: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (DWORD) lTime); ! 60: } ! 61: ! 62: return nIndex; ! 63: } ! 64: ! 65: return SendMessage (hComboBox, CB_GETCURSEL, 0, 0); ! 66: } ! 67: ! 68: int ! 69: GetOrderComboIdx (HWND hComboBox, int *nIdxList, int nElems) ! 70: { ! 71: int x = (int) SendMessage (hComboBox, CB_GETCOUNT, 0, 0); ! 72: if (x != CB_ERR) ! 73: { ! 74: int i, nHighIdx = CB_ERR; ! 75: long lHighTime = -1; ! 76: ! 77: for (i = 0; i < x; i++) ! 78: { ! 79: long lTime = SendMessage (hComboBox, CB_GETITEMDATA, (WPARAM) i, 0); ! 80: if (lTime > lHighTime) ! 81: { ! 82: int n; ! 83: for (n = 0; n < nElems; n++) ! 84: if (nIdxList[n] == i) ! 85: break; ! 86: if (n == nElems) ! 87: { ! 88: lHighTime = lTime; ! 89: nHighIdx = i; ! 90: } ! 91: } ! 92: } ! 93: ! 94: return nHighIdx; ! 95: } ! 96: ! 97: return CB_ERR; ! 98: } ! 99: ! 100: LPARAM ! 101: UpdateComboOrder (HWND hComboBox) ! 102: { ! 103: LPARAM nIndex; ! 104: ! 105: nIndex = SendMessage (hComboBox, CB_GETCURSEL, 0, 0); ! 106: ! 107: if (nIndex != CB_ERR) ! 108: { ! 109: long lTime = time (NULL); ! 110: nIndex = SendMessage (hComboBox, CB_SETITEMDATA, (WPARAM) nIndex, ! 111: (LPARAM) lTime); ! 112: } ! 113: ! 114: return nIndex; ! 115: } ! 116: ! 117: void ! 118: LoadCombo (HWND hComboBox, char *lpszKey) ! 119: { ! 120: int i; ! 121: ! 122: for (i = 0; i < SIZEOF_MRU_LIST; i++) ! 123: { ! 124: char szTmp[256], szKey[32], szTmp2[32]; ! 125: ! 126: *szTmp = 0; ! 127: ! 128: sprintf (szTmp2, "%s%s", lpszKey, "%d"); ! 129: sprintf (szKey, szTmp2, i); ! 130: ReadRegistryString (szKey, "", szTmp, sizeof (szTmp)); ! 131: ! 132: AddComboItem (hComboBox, szTmp); ! 133: } ! 134: ! 135: SendMessage (hComboBox, CB_SETCURSEL, 0, 0); ! 136: ! 137: } ! 138: ! 139: void ! 140: DumpCombo (HWND hComboBox, char *lpszKey, int bClear) ! 141: { ! 142: int i, nComboIdx[SIZEOF_MRU_LIST]; ! 143: ! 144: /* combo list part:- get mru items */ ! 145: for (i = 0; i < SIZEOF_MRU_LIST; i++) ! 146: nComboIdx[i] = bClear ? CB_ERR : GetOrderComboIdx (hComboBox, &nComboIdx[0], i); ! 147: ! 148: /* combo list part:- write out mru items */ ! 149: for (i = 0; i < SIZEOF_MRU_LIST; i++) ! 150: { ! 151: char szTmp[256], szKey[32], szTmp2[32]; ! 152: ! 153: *szTmp = 0; ! 154: ! 155: if (nComboIdx[i] != CB_ERR) ! 156: SendMessage (hComboBox, CB_GETLBTEXT, nComboIdx[i], (LPARAM) & szTmp[0]); ! 157: ! 158: sprintf (szTmp2, "%s%s", lpszKey, "%d"); ! 159: sprintf (szKey, szTmp2, i); ! 160: ! 161: WriteRegistryString (szKey, szTmp); ! 162: } ! 163: } ! 164: ! 165: void ! 166: ClearCombo (HWND hComboBox) ! 167: { ! 168: int i; ! 169: for (i = 0; i < SIZEOF_MRU_LIST; i++) ! 170: { ! 171: SendMessage (hComboBox, CB_DELETESTRING, 0, 0); ! 172: } ! 173: } ! 174: ! 175: int ! 176: IsComboEmpty (HWND hComboBox) ! 177: { ! 178: return SendMessage (hComboBox, CB_GETCOUNT, 0, 0) < 1; ! 179: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.