glue.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Copyright (c) 2018-2020 Bruce A Henderson
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "libclipboard.h"
  20. #include "brl.mod/blitz.mod/blitz.h"
  21. clipboard_c * bmx_clipboard_new_win32(int maxRetries, int retryDelay) {
  22. clipboard_opts opts = {0};
  23. opts.win32.max_retries = maxRetries;
  24. opts.win32.retry_delay = retryDelay;
  25. return clipboard_new(&opts);
  26. }
  27. clipboard_c * bmx_clipboard_new_x11(int actionTimeout, int transferSize, BBString * displayName) {
  28. clipboard_opts opts = {0};
  29. opts.x11.action_timeout = actionTimeout;
  30. opts.x11.transfer_size = transferSize;
  31. if (displayName != &bbEmptyString) {
  32. opts.x11.display_name = bbStringToUTF8String(displayName);
  33. }
  34. clipboard_c * clipboard = clipboard_new(&opts);
  35. bbMemFree(opts.x11.display_name);
  36. return clipboard;
  37. }
  38. clipboard_c * bmx_clipboard_new() {
  39. return clipboard_new(NULL);
  40. }
  41. void bmx_clipboard_free(clipboard_c * clipboard) {
  42. clipboard_free(clipboard);
  43. }
  44. void bmx_clipboard_clear(clipboard_c * clipboard, int clipboardMode) {
  45. clipboard_clear(clipboard, clipboardMode);
  46. }
  47. int bmx_clipboard_has_ownership(clipboard_c * clipboard, int clipboardMode) {
  48. return clipboard_has_ownership(clipboard, clipboardMode);
  49. }
  50. BBString * bmx_clipboard_text(clipboard_c * clipboard) {
  51. char * text = clipboard_text(clipboard);
  52. if (text) {
  53. BBString * ret = bbStringFromUTF8String(text);
  54. free(text);
  55. return ret;
  56. }
  57. return &bbEmptyString;
  58. }
  59. BBString * bmx_clipboard_text_ex(clipboard_c * clipboard, int * length, int clipboardMode) {
  60. char * text = clipboard_text_ex(clipboard, length, clipboardMode);
  61. if (text) {
  62. BBString * ret = bbStringFromUTF8String(text);
  63. free(text);
  64. return ret;
  65. }
  66. return &bbEmptyString;
  67. }
  68. int bmx_clipboard_set_text(clipboard_c * clipboard, BBString * src) {
  69. if (src == &bbEmptyString) {
  70. return 0;
  71. }
  72. char * s = bbStringToUTF8String(src);
  73. int ret = clipboard_set_text(clipboard, s);
  74. bbMemFree(s);
  75. return ret;
  76. }
  77. int bmx_clipboard_set_text_ex(clipboard_c * clipboard, BBString * src, int clipboardMode) {
  78. if (src == &bbEmptyString) {
  79. return 0;
  80. }
  81. char * s = bbStringToUTF8String(src);
  82. int ret = clipboard_set_text_ex(clipboard, s, strlen(s), clipboardMode);
  83. bbMemFree(s);
  84. return ret;
  85. }