Author: ekohl
Date: Sat Nov 3 18:53:52 2007
New Revision: 30091
URL:
http://svn.reactos.org/svn/reactos?rev=30091&view=rev
Log:
Find the real currently selected list view item. This fixes a bug where a non-selected
item gets edited or deleted.
Modified:
trunk/reactos/dll/cpl/sysdm/environment.c
Modified: trunk/reactos/dll/cpl/sysdm/environment.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/sysdm/environment.…
==============================================================================
--- trunk/reactos/dll/cpl/sysdm/environment.c (original)
+++ trunk/reactos/dll/cpl/sysdm/environment.c Sat Nov 3 18:53:52 2007
@@ -17,6 +17,34 @@
LPTSTR lpRawValue;
LPTSTR lpCookedValue;
} VARIABLE_DATA, *PVARIABLE_DATA;
+
+
+static INT
+GetSelectedListViewItem(HWND hwndListView)
+{
+ INT iCount;
+ INT iItem;
+
+ iCount = SendMessage(hwndListView,
+ LVM_GETITEMCOUNT,
+ 0,
+ 0);
+ if (iCount != LB_ERR)
+ {
+ for (iItem = 0; iItem < iCount; iItem++)
+ {
+ if (SendMessage(hwndListView,
+ LVM_GETITEMSTATE,
+ iItem,
+ (LPARAM) LVIS_SELECTED) == LVIS_SELECTED)
+ {
+ return iItem;
+ }
+ }
+ }
+
+ return -1;
+}
INT_PTR CALLBACK
@@ -311,12 +339,12 @@
VOID
OnNewVariable(HWND hwndDlg,
- int iDlgItem)
+ INT iDlgItem)
{
HWND hwndListView;
PVARIABLE_DATA VarData;
LV_ITEM lvi;
- int iItem;
+ INT iItem;
hwndListView = GetDlgItem(hwndDlg, iDlgItem);
@@ -358,16 +386,16 @@
VOID
OnEditVariable(HWND hwndDlg,
- int iDlgItem)
+ INT iDlgItem)
{
HWND hwndListView;
PVARIABLE_DATA VarData;
LV_ITEM lvi;
- int iItem;
+ INT iItem;
hwndListView = GetDlgItem(hwndDlg, iDlgItem);
- iItem = ListView_GetSelectionMark(hwndListView);
+ iItem = GetSelectedListViewItem(hwndListView);
if (iItem != -1)
{
memset(&lvi, 0x00, sizeof(lvi));
@@ -394,16 +422,16 @@
VOID
OnDeleteVariable(HWND hwndDlg,
- int iDlgItem)
+ INT iDlgItem)
{
HWND hwndListView;
PVARIABLE_DATA VarData;
LV_ITEM lvi;
- int iItem;
+ INT iItem;
hwndListView = GetDlgItem(hwndDlg, iDlgItem);
- iItem = ListView_GetSelectionMark(hwndListView);
+ iItem = GetSelectedListViewItem(hwndListView);
if (iItem != -1)
{
memset(&lvi, 0x00, sizeof(lvi));
@@ -436,13 +464,13 @@
VOID
ReleaseListViewItems(HWND hwndDlg,
- int iDlgItem)
+ INT iDlgItem)
{
HWND hwndListView;
PVARIABLE_DATA VarData;
- int nItemCount;
LV_ITEM lvi;
- int i;
+ INT nItemCount;
+ INT i;
hwndListView = GetDlgItem(hwndDlg, iDlgItem);
@@ -584,7 +612,7 @@
}
/* Loop through all variables */
- while(ListView_GetItem(hwndListView, &lvi))
+ while (ListView_GetItem(hwndListView, &lvi))
{
/* Get the data in each item */
VarData = (PVARIABLE_DATA)lvi.lParam;