scrap.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include <Python.h>
  18. /* Handle clipboard text and data in arbitrary formats */
  19. /**
  20. * Predefined supported pygame scrap types.
  21. */
  22. #define PYGAME_SCRAP_TEXT "text/plain"
  23. #define PYGAME_SCRAP_BMP "image/bmp"
  24. #define PYGAME_SCRAP_PPM "image/ppm"
  25. #define PYGAME_SCRAP_PBM "image/pbm"
  26. /**
  27. * The supported scrap clipboard types.
  28. *
  29. * This is only relevant in a X11 environment, which supports mouse
  30. * selections as well. For Win32 and MacOS environments the default
  31. * clipboard is used, no matter what value is passed.
  32. */
  33. typedef enum
  34. {
  35. SCRAP_CLIPBOARD,
  36. SCRAP_SELECTION /* only supported in X11 environments. */
  37. } ScrapClipType;
  38. /**
  39. * Macro for initialization checks.
  40. */
  41. #define PYGAME_SCRAP_INIT_CHECK() \
  42. if(!pygame_scrap_initialized()) \
  43. return (PyErr_SetString (PyExc_SDLError, \
  44. "scrap system not initialized."), NULL)
  45. /**
  46. * \brief Checks, whether the pygame scrap module was initialized.
  47. *
  48. * \return 1 if the modules was initialized, 0 otherwise.
  49. */
  50. extern int
  51. pygame_scrap_initialized (void);
  52. /**
  53. * \brief Initializes the pygame scrap module internals. Call this before any
  54. * other method.
  55. *
  56. * \return 1 on successful initialization, 0 otherwise.
  57. */
  58. extern int
  59. pygame_scrap_init (void);
  60. /**
  61. * \brief Checks, whether the pygame window lost the clipboard focus or not.
  62. *
  63. * \return 1 if the window lost the focus, 0 otherwise.
  64. */
  65. extern int
  66. pygame_scrap_lost (void);
  67. /**
  68. * \brief Places content of a specific type into the clipboard.
  69. *
  70. * \note For X11 the following notes are important: The following types
  71. * are reserved for internal usage and thus will throw an error on
  72. * setting them: "TIMESTAMP", "TARGETS", "SDL_SELECTION".
  73. * Setting PYGAME_SCRAP_TEXT ("text/plain") will also automatically
  74. * set the X11 types "STRING" (XA_STRING), "TEXT" and "UTF8_STRING".
  75. *
  76. * For Win32 the following notes are important: Setting
  77. * PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
  78. * the Win32 type "TEXT" (CF_TEXT).
  79. *
  80. * For QNX the following notes are important: Setting
  81. * PYGAME_SCRAP_TEXT ("text/plain") will also automatically set
  82. * the QNX type "TEXT" (Ph_CL_TEXT).
  83. *
  84. * \param type The type of the content.
  85. * \param srclen The length of the content.
  86. * \param src The NULL terminated content.
  87. * \return 1, if the content could be successfully pasted into the clipboard,
  88. * 0 otherwise.
  89. */
  90. extern int
  91. pygame_scrap_put (char *type, int srclen, char *src);
  92. /**
  93. * \brief Gets the current content from the clipboard.
  94. *
  95. * \note The received content does not need to be the content previously
  96. * placed in the clipboard using pygame_put_scrap(). See the
  97. * pygame_put_scrap() notes for more details.
  98. *
  99. * \param type The type of the content to receive.
  100. * \param count The size of the returned content.
  101. * \return The content or NULL in case of an error or if no content of the
  102. * specified type was available.
  103. */
  104. extern char*
  105. pygame_scrap_get (char *type, unsigned long *count);
  106. /**
  107. * \brief Gets the currently available content types from the clipboard.
  108. *
  109. * \return The different available content types or NULL in case of an
  110. * error or if no content type is available.
  111. */
  112. extern char**
  113. pygame_scrap_get_types (void);
  114. /**
  115. * \brief Checks whether content for the specified scrap type is currently
  116. * available in the clipboard.
  117. *
  118. * \param type The type to check for.
  119. * \return 1, if there is content and 0 otherwise.
  120. */
  121. extern int
  122. pygame_scrap_contains (char *type);