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