Annotation of truecrypt/common/combo.c, revision 1.1.1.5

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.