Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387/* * PROJECT: ReactOS Console Configuration DLL * LICENSE: GPL - See COPYING in the top level directory * FILE: dll/cpl/console/options.c * PURPOSE: Options dialog * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org) * Hermes Belusca-Maito (hermes.belusca@sfr.fr) */
#include "console.h"
#define NDEBUG#include <debug.h>
#define MAX_VALUE_NAME 16383
static INTList_GetCount(IN PLIST_CTL ListCtl){ return (INT)SendMessageW(ListCtl->hWndList, CB_GETCOUNT, 0, 0);}
static ULONG_PTRList_GetData(IN PLIST_CTL ListCtl, IN INT Index){ return (ULONG_PTR)SendMessageW(ListCtl->hWndList, CB_GETITEMDATA, (WPARAM)Index, 0);}
static VOIDAddCodePage( IN PLIST_CTL ListCtl, IN UINT CodePage){ UINT iItem, iDupItem; CPINFOEXW CPInfo;
/* * Add only valid code pages, that is: * - If the CodePage is one of the reserved (alias) values: * CP_ACP == 0 ; CP_OEMCP == 1 ; CP_MACCP == 2 ; CP_THREAD_ACP == 3 ; * or the deprecated CP_SYMBOL == 42 (see http://archives.miloush.net/michkap/archive/2005/11/08/490495.html) * it is considered invalid. * - If IsValidCodePage() fails because the code page is listed but * not installed on the system, it is also considered invalid. */ if (CodePage == CP_ACP || CodePage == CP_OEMCP || CodePage == CP_MACCP || CodePage == CP_THREAD_ACP || CodePage == CP_SYMBOL || !IsValidCodePage(CodePage)) { return; }
/* Retrieve the code page display name */ if (!GetCPInfoExW(CodePage, 0, &CPInfo)) { /* We failed, just use the code page value as its name */ // _ultow(CodePage, CPInfo.CodePageName, 10); StringCchPrintfW(CPInfo.CodePageName, ARRAYSIZE(CPInfo.CodePageName), L"%lu", CodePage); }
/* Add the code page into the list, sorted by code page value. Avoid any duplicates. */ iDupItem = CB_ERR; iItem = BisectListSortedByValue(ListCtl, CodePage, &iDupItem, TRUE); if (iItem == CB_ERR) iItem = 0; if (iDupItem != CB_ERR) return; iItem = (UINT)SendMessageW(ListCtl->hWndList, CB_INSERTSTRING, iItem, (LPARAM)CPInfo.CodePageName); if (iItem != CB_ERR && iItem != CB_ERRSPACE) iItem = SendMessageW(ListCtl->hWndList, CB_SETITEMDATA, iItem, CodePage);}
static VOIDBuildCodePageList( IN HWND hDlg, IN UINT CurrentCodePage){ LIST_CTL ListCtl; LRESULT lResult; HKEY hKey; DWORD dwIndex, dwType; DWORD cchValueName; UINT CodePage;
/* Valid code page value names are string representations * of their corresponding decimal values, that are not larger * than MAXUSHORT == 65535. */ WCHAR szValueName[sizeof("65535")];
/* Open the Nls\CodePage key */ // #define REGSTR_PATH_CODEPAGE TEXT("System\\CurrentControlSet\\Control\\Nls\\CodePage") if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Nls\\CodePage", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { return; }
ListCtl.hWndList = GetDlgItem(hDlg, IDL_CODEPAGE); ListCtl.GetCount = List_GetCount; ListCtl.GetData = List_GetData;
/* Enumerate all the available code pages on the system */ for (dwIndex = 0, cchValueName = ARRAYSIZE(szValueName); (lResult = RegEnumValueW(hKey, dwIndex, szValueName, &cchValueName, NULL, &dwType, NULL, NULL)) != ERROR_NO_MORE_ITEMS; ++dwIndex, cchValueName = ARRAYSIZE(szValueName)) { /* Ignore if we failed for another reason, e.g. because * the value name is too long (and thus, invalid). */ if (lResult != ERROR_SUCCESS) continue;
/* Validate the value name (exclude the unnamed value) */ if (!cchValueName || (*szValueName == UNICODE_NULL)) continue; /* Too large value names have already been handled with ERROR_MORE_DATA */ ASSERT((cchValueName < ARRAYSIZE(szValueName)) && (szValueName[cchValueName] == UNICODE_NULL));
/* Validate the value type */ if (dwType != REG_SZ) continue;
/* * Add the code page into the list. * If _wtol fails and returns 0, the code page is considered invalid * (and indeed this value corresponds to the CP_ACP alias too). */ CodePage = (UINT)_wtol(szValueName); if (CodePage == 0) continue; AddCodePage(&ListCtl, CodePage); }
RegCloseKey(hKey);
/* Add the special UTF-7 (CP_UTF7 65000) and UTF-8 (CP_UTF8 65001) code pages */ AddCodePage(&ListCtl, CP_UTF7); AddCodePage(&ListCtl, CP_UTF8);
/* Find and select the current code page in the sorted list */ if (BisectListSortedByValue(&ListCtl, CurrentCodePage, &CodePage, FALSE) == CB_ERR || CodePage == CB_ERR) { /* Not found, select the first element */ CodePage = 0; } SendMessageW(ListCtl.hWndList, CB_SETCURSEL, (WPARAM)CodePage, 0);}
static VOIDUpdateDialogElements( IN HWND hDlg, IN PCONSOLE_STATE_INFO pConInfo){ /* Update the cursor size */ if (pConInfo->CursorSize <= 25) { /* Small cursor */ CheckRadioButton(hDlg, IDC_RADIO_SMALL_CURSOR, IDC_RADIO_LARGE_CURSOR, IDC_RADIO_SMALL_CURSOR); // CheckDlgButton(hDlg, IDC_RADIO_SMALL_CURSOR , BST_CHECKED); // CheckDlgButton(hDlg, IDC_RADIO_MEDIUM_CURSOR, BST_UNCHECKED); // CheckDlgButton(hDlg, IDC_RADIO_LARGE_CURSOR , BST_UNCHECKED); } else if (pConInfo->CursorSize <= 50) { /* Medium cursor */ CheckRadioButton(hDlg, IDC_RADIO_SMALL_CURSOR, IDC_RADIO_LARGE_CURSOR, IDC_RADIO_MEDIUM_CURSOR); // CheckDlgButton(hDlg, IDC_RADIO_SMALL_CURSOR , BST_UNCHECKED); // CheckDlgButton(hDlg, IDC_RADIO_MEDIUM_CURSOR, BST_CHECKED); // CheckDlgButton(hDlg, IDC_RADIO_LARGE_CURSOR , BST_UNCHECKED); } else /* if (pConInfo->CursorSize <= 100) */ { /* Large cursor */ CheckRadioButton(hDlg, IDC_RADIO_SMALL_CURSOR, IDC_RADIO_LARGE_CURSOR, IDC_RADIO_LARGE_CURSOR); // CheckDlgButton(hDlg, IDC_RADIO_SMALL_CURSOR , BST_UNCHECKED); // CheckDlgButton(hDlg, IDC_RADIO_MEDIUM_CURSOR, BST_UNCHECKED); // CheckDlgButton(hDlg, IDC_RADIO_LARGE_CURSOR , BST_CHECKED); }
/* Update the number of history buffers */ SendDlgItemMessageW(hDlg, IDC_UPDOWN_NUM_BUFFER, UDM_SETRANGE, 0, MAKELONG(999, 1)); SetDlgItemInt(hDlg, IDC_EDIT_NUM_BUFFER, pConInfo->NumberOfHistoryBuffers, FALSE);
/* Update the history buffer size */ SendDlgItemMessageW(hDlg, IDC_UPDOWN_BUFFER_SIZE, UDM_SETRANGE, 0, MAKELONG(999, 1)); SetDlgItemInt(hDlg, IDC_EDIT_BUFFER_SIZE, pConInfo->HistoryBufferSize, FALSE);
/* Update discard duplicates */ CheckDlgButton(hDlg, IDC_CHECK_DISCARD_DUPLICATES, pConInfo->HistoryNoDup ? BST_CHECKED : BST_UNCHECKED);
/* Update full/window screen state */ if (pConInfo->FullScreen) { CheckRadioButton(hDlg, IDC_RADIO_DISPLAY_WINDOW, IDC_RADIO_DISPLAY_FULL, IDC_RADIO_DISPLAY_FULL); // CheckDlgButton(hDlg, IDC_RADIO_DISPLAY_WINDOW, BST_UNCHECKED); // CheckDlgButton(hDlg, IDC_RADIO_DISPLAY_FULL , BST_CHECKED); } else { CheckRadioButton(hDlg, IDC_RADIO_DISPLAY_WINDOW, IDC_RADIO_DISPLAY_FULL, IDC_RADIO_DISPLAY_WINDOW); // CheckDlgButton(hDlg, IDC_RADIO_DISPLAY_WINDOW, BST_CHECKED); // CheckDlgButton(hDlg, IDC_RADIO_DISPLAY_FULL , BST_UNCHECKED); }
/* Update "Quick-edit" state */ CheckDlgButton(hDlg, IDC_CHECK_QUICK_EDIT, pConInfo->QuickEdit ? BST_CHECKED : BST_UNCHECKED);
/* Update "Insert mode" state */ CheckDlgButton(hDlg, IDC_CHECK_INSERT_MODE, pConInfo->InsertMode ? BST_CHECKED : BST_UNCHECKED);}
INT_PTRCALLBACKOptionsProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg) { case WM_INITDIALOG: { BuildCodePageList(hDlg, ConInfo->CodePage); UpdateDialogElements(hDlg, ConInfo); return TRUE; }
case WM_NOTIFY: { LPPSHNOTIFY lppsn = (LPPSHNOTIFY)lParam;
if (lppsn->hdr.code == UDN_DELTAPOS) { LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
if (lppsn->hdr.idFrom == IDC_UPDOWN_BUFFER_SIZE) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 1), 999); ConInfo->HistoryBufferSize = lpnmud->iPos; PropSheet_Changed(GetParent(hDlg), hDlg); } else if (lppsn->hdr.idFrom == IDC_UPDOWN_NUM_BUFFER) { lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 1), 999); ConInfo->NumberOfHistoryBuffers = lpnmud->iPos; PropSheet_Changed(GetParent(hDlg), hDlg); } } else if (lppsn->hdr.code == PSN_APPLY) { ApplyConsoleInfo(hDlg); return TRUE; } break; }
case WM_COMMAND: { if (HIWORD(wParam) == BN_CLICKED) { switch (LOWORD(wParam)) { case IDC_RADIO_SMALL_CURSOR: { ConInfo->CursorSize = 25; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_RADIO_MEDIUM_CURSOR: { ConInfo->CursorSize = 50; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_RADIO_LARGE_CURSOR: { ConInfo->CursorSize = 100; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_RADIO_DISPLAY_WINDOW: { ConInfo->FullScreen = FALSE; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_RADIO_DISPLAY_FULL: { ConInfo->FullScreen = TRUE; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_CHECK_QUICK_EDIT: { ConInfo->QuickEdit = (IsDlgButtonChecked(hDlg, IDC_CHECK_QUICK_EDIT) == BST_CHECKED); // BST_UNCHECKED or BST_INDETERMINATE => FALSE PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_CHECK_INSERT_MODE: { ConInfo->InsertMode = (IsDlgButtonChecked(hDlg, IDC_CHECK_INSERT_MODE) == BST_CHECKED); // BST_UNCHECKED or BST_INDETERMINATE => FALSE PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_CHECK_DISCARD_DUPLICATES: { ConInfo->HistoryNoDup = (IsDlgButtonChecked(hDlg, IDC_CHECK_DISCARD_DUPLICATES) == BST_CHECKED); // BST_UNCHECKED or BST_INDETERMINATE => FALSE PropSheet_Changed(GetParent(hDlg), hDlg); break; } } } else if (HIWORD(wParam) == EN_KILLFOCUS) { switch (LOWORD(wParam)) { case IDC_EDIT_BUFFER_SIZE: { DWORD sizeBuff;
sizeBuff = GetDlgItemInt(hDlg, IDC_EDIT_BUFFER_SIZE, NULL, FALSE); sizeBuff = min(max(sizeBuff, 1), 999);
ConInfo->HistoryBufferSize = sizeBuff; PropSheet_Changed(GetParent(hDlg), hDlg); break; } case IDC_EDIT_NUM_BUFFER: { DWORD numBuff;
numBuff = GetDlgItemInt(hDlg, IDC_EDIT_NUM_BUFFER, NULL, FALSE); numBuff = min(max(numBuff, 1), 999);
ConInfo->NumberOfHistoryBuffers = numBuff; PropSheet_Changed(GetParent(hDlg), hDlg); break; } } } else // (HIWORD(wParam) == CBN_KILLFOCUS) if ((HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_SELENDOK) && (LOWORD(wParam) == IDL_CODEPAGE)) { HWND hWndList = GetDlgItem(hDlg, IDL_CODEPAGE); INT iItem; UINT CodePage;
iItem = (INT)SendMessageW(hWndList, CB_GETCURSEL, 0, 0); if (iItem == CB_ERR) break;
CodePage = (UINT)SendMessageW(hWndList, CB_GETITEMDATA, iItem, 0); if (CodePage == CB_ERR) break;
/* If the user has selected a different code page... */ if ((HIWORD(wParam) == CBN_SELENDOK) && (CodePage != ConInfo->CodePage)) { /* ... update the code page and change the property sheet state */ ConInfo->CodePage = CodePage; ResetFontPreview(&FontPreview); PropSheet_Changed(GetParent(hDlg), hDlg); } }
break; }
default: break; }
return FALSE;}