GuiThing.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* GuiThing.cpp
  2. *
  3. * Copyright (C) 1993-2012,2013,2015,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. void structGuiThing :: v_destroy () noexcept {
  21. GuiThing_Parent :: v_destroy ();
  22. }
  23. void structGuiThing :: v_hide () {
  24. #if gtk
  25. GuiObject parent = gtk_widget_get_parent (GTK_WIDGET (d_widget));
  26. if (parent && GTK_IS_DIALOG (parent)) { // I am the top GtkFixed of a dialog
  27. gtk_widget_hide (GTK_WIDGET (parent));
  28. } else if (parent && GTK_IS_DIALOG (gtk_widget_get_parent (GTK_WIDGET (parent)))) {
  29. trace (U"hiding a dialog indirectly");
  30. gtk_widget_hide (GTK_WIDGET (gtk_widget_get_parent (GTK_WIDGET (parent))));
  31. } else {
  32. gtk_widget_hide (GTK_WIDGET (d_widget));
  33. }
  34. #elif motif
  35. XtUnmanageChild (d_widget);
  36. // nothing, because the scrolled window is not a widget
  37. #elif cocoa
  38. if ([(NSObject *) d_widget isKindOfClass: [NSWindow class]]) {
  39. [(NSWindow *) d_widget orderOut: nil];
  40. } else if ([(NSObject *) d_widget isKindOfClass: [NSView class]]) {
  41. if ((NSView *) d_widget == [[(NSView *) d_widget window] contentView]) {
  42. [[(NSView *) d_widget window] orderOut: nil];
  43. } else {
  44. [(NSView *) d_widget setHidden: YES];
  45. }
  46. } else {
  47. [(NSMenuItem *) d_widget setHidden: YES];
  48. }
  49. #endif
  50. }
  51. void structGuiThing :: v_setSensitive (bool sensitive) {
  52. #if gtk
  53. gtk_widget_set_sensitive (GTK_WIDGET (d_widget), sensitive);
  54. #elif motif
  55. XtSetSensitive (d_widget, sensitive);
  56. #elif cocoa
  57. if ([(NSObject *) d_widget isKindOfClass: [NSControl class]]) {
  58. [(NSControl *) d_widget setEnabled: sensitive];
  59. } else if ([(NSObject *) d_widget isKindOfClass: [NSMenuItem class]]) {
  60. [(NSMenuItem *) d_widget setEnabled: sensitive];
  61. }
  62. #endif
  63. }
  64. void structGuiThing :: v_show () {
  65. #if gtk
  66. trace (U"showing widget ", Melder_pointer (d_widget));
  67. GuiObject parent = gtk_widget_get_parent (GTK_WIDGET (d_widget));
  68. trace (U"the parent widget is ", Melder_pointer (parent));
  69. if (GTK_IS_WINDOW (parent)) {
  70. // I am a window's GtkFixed
  71. trace (U"showing a window");
  72. gtk_widget_show (GTK_WIDGET (d_widget));
  73. gtk_window_present (GTK_WINDOW (parent));
  74. } else if (GTK_IS_DIALOG (parent)) {
  75. // I am a dialog's GtkFixed, and therefore automatically shown
  76. trace (U"showing a dialog");
  77. gtk_window_present (GTK_WINDOW (parent));
  78. } else if (GTK_IS_DIALOG (gtk_widget_get_parent (GTK_WIDGET (parent)))) {
  79. // I am a dialog's GtkFixed, and therefore automatically shown
  80. trace (U"showing a dialog (indirectly)");
  81. gtk_window_present (GTK_WINDOW (gtk_widget_get_parent (GTK_WIDGET (parent))));
  82. } else {
  83. trace (U"showing a widget that is not a window or dialog");
  84. gtk_widget_show (GTK_WIDGET (d_widget));
  85. }
  86. #elif motif
  87. XtManageChild (d_widget);
  88. GuiObject parent = d_widget -> parent;
  89. if (parent -> widgetClass == xmShellWidgetClass) {
  90. XMapRaised (XtDisplay (parent), XtWindow (parent));
  91. }
  92. #elif cocoa
  93. if ([(NSObject *) d_widget isKindOfClass: [NSWindow class]]) {
  94. trace (U"trying to show a window");
  95. [(NSWindow *) d_widget makeKeyAndOrderFront: nil];
  96. } else if ([(NSObject *) d_widget isKindOfClass: [NSView class]]) {
  97. if ((NSView *) d_widget == [[(NSView *) d_widget window] contentView]) {
  98. trace (U"trying to show a window through its content view");
  99. [[(NSView *) d_widget window] makeKeyAndOrderFront: nil];
  100. } else {
  101. [(NSView *) d_widget setHidden: NO];
  102. }
  103. } else {
  104. [(NSMenuItem *) d_widget setHidden: NO];
  105. }
  106. #endif
  107. trace (U"end");
  108. }
  109. void GuiThing_hide (GuiThing me) {
  110. my v_hide ();
  111. }
  112. void GuiThing_setSensitive (GuiThing me, bool sensitive) {
  113. my v_setSensitive (sensitive);
  114. }
  115. void GuiThing_show (GuiThing me) {
  116. my v_show ();
  117. }
  118. /* End of file GuiThing.cpp */