[CALC] Fix input bug when display is in error. (#5988)
[reactos.git] / base / applications / regedit / listview.c
index 04eb4c1..346ed78 100644 (file)
 
 #include "regedit.h"
 
-
-#define CX_ICON    16
-#define CY_ICON    16
-#define NUM_ICONS   2
+#define CX_ICON            16
+#define CY_ICON            16
+#define LISTVIEW_NUM_ICONS 2
 
 int Image_String = 0;
 int Image_Bin = 0;
@@ -50,10 +49,10 @@ typedef struct tagSORT_INFO
 static INT g_iSortedColumn = 0;
 
 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
-static const int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
+static const int default_column_widths[MAX_LIST_COLUMNS] = { 35, 25, 40 };  /* in percents */
 static const int column_alignment[MAX_LIST_COLUMNS] = { LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT };
 
-LPCWSTR GetValueName(HWND hwndLV, int iStartAt)
+WCHAR *GetValueName(HWND hwndLV, int iStartAt)
 {
     int item;
     LVITEMW LVItem;
@@ -92,7 +91,7 @@ VOID SetValueName(HWND hwndLV, LPCWSTR pszValueName)
     {
         ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED);
     }
-    if (pszValueName == NULL)
+    if (pszValueName == NULL || pszValueName[0] == 0)
         i = 0;
     else
     {
@@ -102,6 +101,7 @@ VOID SetValueName(HWND hwndLV, LPCWSTR pszValueName)
     }
     ListView_SetItemState(hwndLV, i, LVIS_FOCUSED | LVIS_SELECTED,
                           LVIS_FOCUSED | LVIS_SELECTED);
+    ListView_EnsureVisible(hwndLV, i, FALSE);
     iListViewSelect = i;
 }
 
@@ -182,7 +182,7 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
             {
                 WCHAR buffer[255];
                 /* load (value not set) string */
-                LoadStringW(hInst, IDS_VALUE_NOT_SET, buffer, COUNT_OF(buffer));
+                LoadStringW(hInst, IDS_VALUE_NOT_SET, buffer, ARRAY_SIZE(buffer));
                 ListView_SetItemText(hwndLV, index, 2, buffer);
             }
             break;
@@ -214,6 +214,7 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
         }
         break;
         case REG_DWORD:
+        case REG_NONE:
         {
             WCHAR buf[200];
             if(dwCount == sizeof(DWORD))
@@ -222,7 +223,7 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
             }
             else
             {
-                LoadStringW(hInst, IDS_INVALID_DWORD, buf, COUNT_OF(buf));
+                LoadStringW(hInst, IDS_INVALID_DWORD, buf, ARRAY_SIZE(buf));
             }
             ListView_SetItemText(hwndLV, index, 2, buf);
         }
@@ -247,7 +248,7 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
             else
             {
                 WCHAR szText[128];
-                LoadStringW(hInst, IDS_BINARY_EMPTY, szText, COUNT_OF(szText));
+                LoadStringW(hInst, IDS_BINARY_EMPTY, szText, ARRAY_SIZE(szText));
                 ListView_SetItemText(hwndLV, index, 2, szText);
             }
         }
@@ -256,7 +257,7 @@ static void AddEntryToList(HWND hwndLV, LPWSTR Name, DWORD dwValType, void* ValB
     }
 }
 
-static BOOL CreateListColumns(HWND hWndListView)
+static BOOL CreateListColumns(HWND hWndListView, INT cxTotal)
 {
     WCHAR szText[50];
     int index;
@@ -270,9 +271,9 @@ static BOOL CreateListColumns(HWND hWndListView)
     for (index = 0; index < MAX_LIST_COLUMNS; index++)
     {
         lvC.iSubItem = index;
-        lvC.cx = default_column_widths[index];
+        lvC.cx = (cxTotal * default_column_widths[index]) / 100;
         lvC.fmt = column_alignment[index];
-        LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, COUNT_OF(szText));
+        LoadStringW(hInst, IDS_LIST_COLUMN_FIRST + index, szText, ARRAY_SIZE(szText));
         if (ListView_InsertColumn(hWndListView, index, &lvC) == -1) return FALSE;
     }
     return TRUE;
@@ -285,7 +286,7 @@ static BOOL InitListViewImageLists(HWND hwndLV)
 
     /* Create the image list.  */
     if ((himl = ImageList_Create(CX_ICON, CY_ICON,
-                                 ILC_MASK, 0, NUM_ICONS)) == NULL)
+                                 ILC_MASK, 0, LISTVIEW_NUM_ICONS)) == NULL)
     {
         return FALSE;
     }
@@ -297,7 +298,7 @@ static BOOL InitListViewImageLists(HWND hwndLV)
     Image_String = ImageList_AddIcon(himl, hico);
 
     /* Fail if not all of the images were added.  */
-    if (ImageList_GetImageCount(himl) < NUM_ICONS)
+    if (ImageList_GetImageCount(himl) < LISTVIEW_NUM_ICONS)
     {
         return FALSE;
     }
@@ -320,7 +321,7 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi)
     switch (plvdi->item.iSubItem)
     {
     case 0:
-        LoadStringW(hInst, IDS_DEFAULT_VALUE_NAME, buffer, COUNT_OF(buffer));
+        LoadStringW(hInst, IDS_DEFAULT_VALUE_NAME, buffer, ARRAY_SIZE(buffer));
         plvdi->item.pszText = buffer;
         break;
     case 1:
@@ -365,7 +366,7 @@ static void OnGetDispInfo(NMLVDISPINFO* plvdi)
             default:
             {
                 WCHAR buf2[200];
-                LoadStringW(hInst, IDS_UNKNOWN_TYPE, buf2, COUNT_OF(buf2));
+                LoadStringW(hInst, IDS_UNKNOWN_TYPE, buf2, ARRAY_SIZE(buf2));
                 wsprintf(buffer, buf2, ((LINE_INFO*)plvdi->item.lParam)->dwValType);
                 plvdi->item.pszText = buffer;
                 break;
@@ -439,7 +440,7 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor
                     return ((int)dw2 - (int)dw1);
             }
 
-            case REG_QWORD:
+            case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */
             {
                 qw1 = *(DWORDLONG*)l->val;
                 qw2 = *(DWORDLONG*)r->val;
@@ -479,7 +480,7 @@ static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSor
 
 static BOOL ListView_Sort(HWND hListView, int iSortingColumn, int iSortedColumn)
 {
-    if ( (GetWindowLongPtr(hListView, GWL_STYLE) & ~LVS_NOSORTHEADER) &&
+    if (!(GetWindowLongPtr(hListView, GWL_STYLE) & LVS_NOSORTHEADER) &&
          (iSortingColumn >= 0) )
     {
         BOOL bSortAscending;
@@ -564,7 +565,7 @@ BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
     }
     return TRUE;
     case NM_SETFOCUS:
-        g_pChildWnd->nFocusPanel = 0;
+        g_pChildWnd->nFocusPanel = 1;
         break;
     case LVN_BEGINLABELEDIT:
         Info = (NMLVDISPINFO*)lParam;
@@ -598,8 +599,8 @@ BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
                 {
                     WCHAR msg[128], caption[128];
 
-                    LoadStringW(hInst, IDS_ERR_RENVAL_TOEMPTY, msg, COUNT_OF(msg));
-                    LoadStringW(hInst, IDS_ERR_RENVAL_CAPTION, caption, COUNT_OF(caption));
+                    LoadStringW(hInst, IDS_ERR_RENVAL_TOEMPTY, msg, ARRAY_SIZE(msg));
+                    LoadStringW(hInst, IDS_ERR_RENVAL_CAPTION, caption, ARRAY_SIZE(caption));
                     MessageBoxW(0, msg, caption, 0);
                     *Result = TRUE;
                 }
@@ -628,7 +629,7 @@ BOOL ListWndNotifyProc(HWND hWnd, WPARAM wParam, LPARAM lParam, BOOL *Result)
     return FALSE;
 }
 
-HWND CreateListView(HWND hwndParent, HMENU id)
+HWND CreateListView(HWND hwndParent, HMENU id, INT cx)
 {
     RECT rcClient;
     HWND hwndLV;
@@ -642,7 +643,7 @@ HWND CreateListView(HWND hwndParent, HMENU id)
     if (!hwndLV) return NULL;
 
     /* Initialize the image list, and add items to the control. */
-    if (!CreateListColumns(hwndLV)) goto fail;
+    if (!CreateListColumns(hwndLV, cx)) goto fail;
     if (!InitListViewImageLists(hwndLV)) goto fail;
 
     return hwndLV;
@@ -668,7 +669,7 @@ void DestroyListView(HWND hwndLV)
 
 }
 
-BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCWSTR keyPath)
+BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCWSTR keyPath, BOOL bSelectNone)
 {
     DWORD max_sub_key_len;
     DWORD max_val_name_len;
@@ -738,6 +739,9 @@ BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCWSTR keyPath)
     {
         ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED);
     }
+
+    if (bSelectNone)
+        iListViewSelect = -1;
     ListView_SetItemState(hwndLV, iListViewSelect,
                           LVIS_FOCUSED | LVIS_SELECTED,
                           LVIS_FOCUSED | LVIS_SELECTED);