GuiObject.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* GuiObject.cpp
  2. *
  3. * Copyright (C) 1993-2012,2013,2017 Paul Boersma, 2008 Stefan de Konink, 2010 Franz Brausse
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "GuiP.h"
  19. #include "machine.h"
  20. #if cocoa
  21. @interface GuiCocoaView : NSView
  22. - (GuiThing) getUserData;
  23. - (void) setUserData: (GuiThing) userData;
  24. @end
  25. #endif
  26. void * _GuiObject_getUserData (GuiObject widget) {
  27. void *userData = nullptr;
  28. #if gtk
  29. userData = (void *) g_object_get_data (G_OBJECT (widget), "praat");
  30. #elif motif
  31. XtVaGetValues (widget, XmNuserData, & userData, nullptr);
  32. #elif cocoa
  33. userData = [(GuiCocoaView *) widget getUserData];
  34. #endif
  35. return userData;
  36. }
  37. void _GuiObject_setUserData (GuiObject widget, void *userData) {
  38. #if gtk
  39. g_object_set_data (G_OBJECT (widget), "praat", userData);
  40. #elif motif
  41. XtVaSetValues (widget, XmNuserData, userData, nullptr);
  42. #elif cocoa
  43. [(GuiCocoaView *) widget setUserData: (GuiThing) userData];
  44. #endif
  45. }
  46. void GuiObject_destroy (GuiObject widget) {
  47. #if gtk
  48. gtk_widget_destroy (GTK_WIDGET (widget));
  49. #elif motif
  50. XtDestroyWidget (widget);
  51. #elif cocoa
  52. if ([widget isKindOfClass: [NSMenuItem class]]) {
  53. NSMenuItem *cocoaMenuItem = (NSMenuItem *) widget;
  54. [[cocoaMenuItem menu] removeItem: cocoaMenuItem]; // this also releases the item
  55. } else {
  56. Melder_assert ([widget isKindOfClass: [NSView class]]);
  57. NSView *cocoaView = (NSView *) widget;
  58. if (cocoaView == [[cocoaView window] contentView]) {
  59. [[cocoaView window] orderOut: nil];
  60. [[cocoaView window] close];
  61. [[cocoaView window] release];
  62. } else {
  63. [cocoaView removeFromSuperview]; // this also releases the view
  64. }
  65. }
  66. #endif
  67. }
  68. /* End of file GuiObject.cpp */