changes from Alessandro Scotti from 20051231
[xboard.git] / winboard / wgamelist.c
index 34339d4..5fa191c 100644 (file)
@@ -20,7 +20,6 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
  * ------------------------------------------------------------------------\r
  */\r
-\r
 #include "config.h"\r
 \r
 #include <windows.h> /* required for all Windows applications */\r
@@ -37,6 +36,8 @@
 #include "frontend.h"\r
 #include "backend.h"\r
 \r
+#include "wsnap.h"
+
 /* Module globals */\r
 HWND gameListDialog = NULL;\r
 BOOLEAN gameListUp = FALSE;\r
@@ -206,6 +207,7 @@ GameListDialog(HWND hDlg, UINT message,     WPARAM wParam, LPARAM lParam)
   static BOOL filterHasFocus = FALSE;
   int count;
   struct GameListStats stats;
+  static SnapData sd;
 \r
   switch (message) {\r
   case WM_INITDIALOG: \r
@@ -269,6 +271,18 @@ GameListDialog(HWND hDlg, UINT message,    WPARAM wParam, LPARAM lParam)
     sizeY = newSizeY;\r
     break;\r
 \r
+  case WM_ENTERSIZEMOVE:
+    return OnEnterSizeMove( &sd, hDlg, wParam, lParam );
+
+  case WM_SIZING:
+    return OnSizing( &sd, hDlg, wParam, lParam );
+
+  case WM_MOVING:
+    return OnMoving( &sd, hDlg, wParam, lParam );
+
+  case WM_EXITSIZEMOVE:
+    return OnExitSizeMove( &sd, hDlg, wParam, lParam );
+
   case WM_GETMINMAXINFO:\r
     /* Prevent resizing window too small */\r
     mmi = (MINMAXINFO *) lParam;\r
@@ -469,3 +483,56 @@ VOID ShowGameListProc()
     }\r
   }\r
 }\r
+
+HGLOBAL ExportGameListAsText()
+{
+    HGLOBAL result = NULL;
+    LPVOID lpMem = NULL;
+    ListGame * lg = (ListGame *) gameList.head;
+    int nItem;
+    DWORD dwLen = 0;
+
+    if( ! gameFileName || ((ListGame *) gameList.tailPred)->number <= 0 ) {
+        DisplayError("Game list not loaded or empty", 0);
+        return NULL;
+    }
+
+    /* Get list size */
+    for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){
+        char * st = GameListLineFull(lg->number, &lg->gameInfo);
+
+        dwLen += strlen(st) + 2; /* Add extra characters for "\r\n" */
+
+        free(st);
+        lg = (ListGame *) lg->node.succ;
+    }
+
+    /* Allocate memory for the list */
+    result = GlobalAlloc(GHND, dwLen+1 );
+
+    if( result != NULL ) {
+        lpMem = GlobalLock(result);
+    }
+
+    /* Copy the list into the global memory block */
+    if( lpMem != NULL ) {
+        char * dst = (char *) lpMem;
+        size_t len;
+
+        lg = (ListGame *) gameList.head;
+
+        for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){
+            char * st = GameListLineFull(lg->number, &lg->gameInfo);
+
+            len = sprintf( dst, "%s\r\n", st );
+            dst += len;
+
+            free(st);
+            lg = (ListGame *) lg->node.succ;
+        }
+
+        GlobalUnlock( result );
+    }
+
+    return result;
+}