scrap.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. pygame - Python Game Library
  3. Copyright (C) 2006, 2007 Rene Dudfield, Marcus von Appen
  4. Originally put in the public domain by Sam Lantinga.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /* This is unconditionally defined in Python.h */
  18. #if defined(_POSIX_C_SOURCE)
  19. #undef _POSIX_C_SOURCE
  20. #endif
  21. #include <Python.h>
  22. /* Handle clipboard text and data in arbitrary formats */
  23. /**
  24. * Predefined supported pygame scrap types.
  25. */
  26. #define PYGAME_SCRAP_TEXT "text/plain"
  27. #define PYGAME_SCRAP_BMP "image/bmp"
  28. #define PYGAME_SCRAP_PPM "image/ppm"
  29. #define PYGAME_SCRAP_PBM "image/pbm"
  30. /**
  31. * The supported scrap clipboard types.
  32. *
  33. * This is only relevant in a X11 environment, which supports mouse
  34. * selections as well. For Win32 and MacOS environments the default
  35. * clipboard is used, no matter what value is passed.
  36. */
  37. typedef enum
  38. {
  39. SCRAP_CLIPBOARD,
  40. SCRAP_SELECTION /* only supported in X11 environments. */
  41. } ScrapClipType;
  42. /**
  43. * Macro for initialization checks.
  44. */
  45. #define PYGAME_SCRAP_INIT_CHECK() \
  46. if(!pygame_scrap_initialized()) \
  47. return (PyErr_SetString (pgExc_SDLError, \
  48. "scrap system not initialized."), NULL)
  49. /**
  50. * \brief Checks, whether the pygame scrap module was initialized.
  51. *
  52. * \return 1 if the modules was initialized, 0 otherwise.
  53. */
  54. extern int
  55. pygame_scrap_initialized (void);
  56. /**
  57. * \brief Initializes the pygame scrap module internals. Call this before any
  58. * other method.
  59. *
  60. * \return 1 on successful initialization, 0 otherwise.
  61. */
  62. extern int
  63. pygame_scrap_init (void);
  64. /**
  65. * \brief Checks, whether the pygame window lost the clipboard focus or not.
  66. *
  67. * \return 1 if the window lost the focus, 0 otherwise.
  68. */
  69. extern int
  70. pygame_scrap_lost (void);
  71. /**
  72. * \brief Places content of a specific type into the clipboard.
  73. *
  74. * \note For X11 the following notes are important: The following types
  75. * are reserved for internal usage and thus will throw an error on
  76. * setting them: "TIMESTAMP", "TARGETS", "SDL_SELECTION".
  77. * Setting PYGAME_SCRAP_TEXT ("text/plain") will also automatically
  78. * set the X11 types "STRING" (XA_STRING), "TEXT" and "UTF8_STRING".
  79. *
  80. * For Win32 the following notes are important: Setting
  81. * PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
  82. * the Win32 type "TEXT" (CF_TEXT).
  83. *
  84. * For QNX the following notes are important: Setting
  85. * PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
  86. * the QNX type "TEXT" (Ph_CL_TEXT).
  87. *
  88. * \param type The type of the content.
  89. * \param srclen The length of the content.
  90. * \param src The NULL terminated content.
  91. * \return 1, if the content could be successfully pasted into the clipboard,
  92. * 0 otherwise.
  93. */
  94. extern int
  95. pygame_scrap_put (char *type, int srclen, char *src);
  96. /**
  97. * \brief Gets the current content from the clipboard.
  98. *
  99. * \note The received content does not need to be the content previously
  100. * placed in the clipboard using pygame_put_scrap(). See the
  101. * pygame_put_scrap() notes for more details.
  102. *
  103. * \param type The type of the content to receive.
  104. * \param count The size of the returned content.
  105. * \return The content or NULL in case of an error or if no content of the
  106. * specified type was available.
  107. */
  108. extern char*
  109. pygame_scrap_get (char *type, unsigned long *count);
  110. /**
  111. * \brief Gets the currently available content types from the clipboard.
  112. *
  113. * \return The different available content types or NULL in case of an
  114. * error or if no content type is available.
  115. */
  116. extern char**
  117. pygame_scrap_get_types (void);
  118. /**
  119. * \brief Checks whether content for the specified scrap type is currently
  120. * available in the clipboard.
  121. *
  122. * \param type The type to check for.
  123. * \return 1, if there is content and 0 otherwise.
  124. */
  125. extern int
  126. pygame_scrap_contains (char *type);