[RAPPS] Use FTP in passive mode
[reactos.git] / base / applications / rapps / gui.cpp
index cae703f..ed2c3b8 100644 (file)
@@ -388,14 +388,17 @@ class CAppsListView :
     };
 
     BOOL bHasAllChecked;
-    BOOL bAscending;
+    BOOL bIsAscending;
     BOOL bHasCheckboxes;
 
+    INT nLastHeaderID;
+
 public:
     CAppsListView() :
         bHasAllChecked(FALSE),
-        bAscending(TRUE),
-        bHasCheckboxes(FALSE)
+        bIsAscending(TRUE),
+        bHasCheckboxes(FALSE),
+        nLastHeaderID(-1)
     {
     }
 
@@ -415,11 +418,40 @@ public:
 
     VOID ColumnClick(LPNMLISTVIEW pnmv)
     {
-        SortContext ctx = {this, pnmv->iSubItem};
+        HWND hHeader;
+        HDITEMW hColumn;
+        INT nHeaderID = pnmv->iSubItem;
+
+        if ((GetWindowLongPtr(GWL_STYLE) & ~LVS_NOSORTHEADER) == 0)
+            return;
+
+        hHeader = (HWND) SendMessage(LVM_GETHEADER, 0, 0);
+        ZeroMemory(&hColumn, sizeof(hColumn));
+
+        /* If the sorting column changed, remove the sorting style from the old column */
+        if ((nLastHeaderID != -1) && (nLastHeaderID != nHeaderID))
+        {
+            hColumn.mask = HDI_FORMAT;
+            Header_GetItem(hHeader, nLastHeaderID, &hColumn);
+            hColumn.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
+            Header_SetItem(hHeader, nLastHeaderID, &hColumn);
+        }
+
+        /* Set the sorting style to the new column */
+        hColumn.mask = HDI_FORMAT;
+        Header_GetItem(hHeader, nHeaderID, &hColumn);
+
+        hColumn.fmt &= (bIsAscending ? ~HDF_SORTDOWN : ~HDF_SORTUP);
+        hColumn.fmt |= (bIsAscending ? HDF_SORTUP : HDF_SORTDOWN);
+        Header_SetItem(hHeader, nHeaderID, &hColumn);
 
+        /* Sort the list, using the current values of nHeaderID and bIsAscending */
+        SortContext ctx = {this, nHeaderID};
         SortItems(s_CompareFunc, &ctx);
 
-        bAscending = !bAscending;
+        /* Save new values */
+        nLastHeaderID = nHeaderID;
+        bIsAscending = !bIsAscending;
     }
 
     PVOID GetLParam(INT Index)
@@ -507,12 +539,7 @@ public:
         GetItemText(Index, iSubItem, Item2.GetBuffer(MAX_STR_LEN), MAX_STR_LEN);
         Item2.ReleaseBuffer();
 
-        if (bAscending)
-            return Item2 == Item1;
-        else
-            return Item1 == Item2;
-
-        return 0;
+        return bIsAscending ? Item1.Compare(Item2) : Item2.Compare(Item1);
     }
 
     HWND Create(HWND hwndParent)
@@ -668,7 +695,7 @@ public:
     const INT m_Width;
     const INT m_Height;
 
-    CSearchBar() : m_Width(200), m_Height(22) 
+    CSearchBar() : m_Width(200), m_Height(22)
     {
     }
 
@@ -939,6 +966,8 @@ private:
 
     VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
     {
+        if (wParam == SIZE_MINIMIZED)
+            return;
 
         /* Size status bar */
         m_StatusBar->SendMessage(WM_SIZE, 0, 0);
@@ -1613,7 +1642,7 @@ private:
 
         m_ListView->DeleteAllItems();
 
-        // Create new ImageList 
+        // Create new ImageList
         hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE,
                                           LISTVIEW_ICON_SIZE,
                                           GetSystemColorDepth() | ILC_MASK,