/*\r
* wclipbrd.c -- Clipboard routines for WinBoard\r
- * $Id$\r
+ * $Id: wclipbrd.c,v 2.1 2003/10/27 19:21:02 mann Exp $\r
*\r
- * Copyright 2000 Free Software Foundation, Inc.\r
+ * Copyright 2000,2009 Free Software Foundation, Inc.\r
*\r
* ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * your option) any later version.\r
*\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
*\r
* You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- * ------------------------------------------------------------------------\r
- */\r
+ * along with this program. If not, see http://www.gnu.org/licenses/. *\r
+ *\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history. */\r
\r
#include "config.h"\r
\r
{\r
char *fen = NULL;\r
\r
- fen = PositionToFEN(currentMove);\r
+ fen = PositionToFEN(currentMove,1);\r
if (!fen) {\r
DisplayError("Unable to convert position to FEN.", 0);\r
return;\r
free(fen);\r
}\r
\r
+/* [AS] */\r
+HGLOBAL ExportGameListAsText();\r
+\r
+VOID CopyGameListToClipboard()\r
+{\r
+ HGLOBAL hMem = ExportGameListAsText();\r
+ \r
+ if( hMem != NULL ) {\r
+ /* Assign memory block to clipboard */\r
+ BOOL ok = OpenClipboard( hwndMain );\r
+\r
+ if( ok ) {\r
+ ok = EmptyClipboard();\r
+\r
+ if( ok ) {\r
+ if( hMem != SetClipboardData( CF_TEXT, hMem ) ) {\r
+ ok = FALSE;\r
+ }\r
+ }\r
+\r
+ CloseClipboard();\r
+\r
+ if( ! ok ) {\r
+ GlobalFree( hMem );\r
+ }\r
+ }\r
+\r
+ if( ! ok ) {\r
+ DisplayError( "Cannot copy list to clipboard.", 0 );\r
+ }\r
+ }\r
+}\r
\r
VOID\r
CopyGameToClipboard()\r
locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED));\r
if (appData.debugMode) {\r
fprintf(debugFP, \r
- "CopyTextToClipboard(): err %d locked %d\n", err, locked);\r
+ "CopyTextToClipboard(): err %d locked %d\n", (int)err, locked);\r
}\r
}\r
if (locked) {\r
return TRUE;\r
}\r
\r
+/* [AS] Reworked paste functions so they can work with strings too */\r
+\r
+VOID PasteFENFromString( char * fen )\r
+{\r
+ if (appData.debugMode) {\r
+ fprintf(debugFP, "PasteFenFromString(): fen '%s'\n", fen);\r
+ }\r
+ EditPositionPasteFEN(fen); /* call into backend */\r
+ free(fen);\r
+}\r
\r
\r
VOID\r
DisplayError("Unable to paste FEN from clipboard.", 0);\r
return;\r
}\r
- if (appData.debugMode) {\r
- fprintf(debugFP, "PasteFenFromClipboard(): fen '%s'\n", fen);\r
- }\r
- EditPositionPasteFEN(fen); /* call into backend */\r
- free(fen);\r
+ PasteFENFromString( fen );\r
}\r
\r
-\r
-VOID\r
-PasteGameFromClipboard()\r
+VOID PasteGameFromString( char * buf )\r
{\r
- /* Write the clipboard to a temp file, then let LoadGameFromFile()\r
- * do all the work. */\r
- char *buf;\r
FILE *f;\r
size_t len;\r
- if (!PasteTextFromClipboard(&buf)) {\r
- return;\r
- }\r
if (!pasteTemp) {\r
pasteTemp = tempnam(NULL, "wbpt");\r
}\r
f = fopen(pasteTemp, "w");\r
if (!f) {\r
DisplayError("Unable to create temporary file.", 0);\r
+ free(buf); /* [AS] */\r
return;\r
}\r
len = fwrite(buf, sizeof(char), strlen(buf), f);\r
fclose(f);\r
if (len != strlen(buf)) {\r
DisplayError("Error writing to temporary file.", 0);\r
+ free(buf); /* [AS] */\r
return;\r
}\r
LoadGameFromFile(pasteTemp, 0, "Clipboard", TRUE);\r
+ free( buf ); /* [AS] */\r
+}\r
+\r
+\r
+VOID\r
+PasteGameFromClipboard()\r
+{\r
+ /* Write the clipboard to a temp file, then let LoadGameFromFile()\r
+ * do all the work. */\r
+ char *buf;\r
+ if (!PasteTextFromClipboard(&buf)) {\r
+ return;\r
+ }\r
+ PasteGameFromString( buf );\r
}\r
\r
+/* [AS] Try to detect whether the clipboard contains FEN or PGN data */\r
+VOID PasteGameOrFENFromClipboard()\r
+{\r
+ char *buf;\r
+ char *tmp;\r
+\r
+ if (!PasteTextFromClipboard(&buf)) {\r
+ return;\r
+ }\r
+\r
+ tmp = buf;\r
+ while( *tmp == ' ' || *tmp == '\t' || *tmp == '\r' || *tmp == '\n' ) {\r
+ tmp++;\r
+ }\r
+\r
+ if( *tmp == '[' ) {\r
+ PasteGameFromString( buf );\r
+ }\r
+ else {\r
+ PasteFENFromString( buf );\r
+ }\r
+}\r
\r
int \r
PasteTextFromClipboard(char **text)\r
locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED));\r
if (appData.debugMode) {\r
fprintf(debugFP, \r
- "PasteTextFromClipboard(): err %d locked %d\n", err, locked);\r
+ "PasteTextFromClipboard(): err %d locked %d\n", (int)err, locked);\r
}\r
}\r
if (locked) \r