Debian Codegraph @

sys/GuiObject.cpp

raw symbols SCIP
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
19 #include "GuiP.h"
20 #include "machine.h"
21
22 #if cocoa
23 @interface GuiCocoaView : NSView
24 - (GuiThing) getUserData;
25 - (void) setUserData: (GuiThing) userData;
26 @end
27 #endif
28
29 void * _GuiObject_getUserData (GuiObject widget) {
30 void *userData = nullptr;
31 #if gtk
32 userData = (void *) g_object_get_data (G_OBJECT (widget), "praat");
33 #elif motif
34 XtVaGetValues (widget, XmNuserData, & userData, nullptr);
35 #elif cocoa
36 userData = [(GuiCocoaView *) widget getUserData];
37 #endif
38 return userData;
39 }
40
41 void _GuiObject_setUserData (GuiObject widget, void *userData) {
42 #if gtk
43 g_object_set_data (G_OBJECT (widget), "praat", userData);
44 #elif motif
45 XtVaSetValues (widget, XmNuserData, userData, nullptr);
46 #elif cocoa
47 [(GuiCocoaView *) widget setUserData: (GuiThing) userData];
48 #endif
49 }
50
51 void GuiObject_destroy (GuiObject widget) {
52 #if gtk
53 gtk_widget_destroy (GTK_WIDGET (widget));
54 #elif motif
55 XtDestroyWidget (widget);
56 #elif cocoa
57 if ([widget isKindOfClass: [NSMenuItem class]]) {
58 NSMenuItem *cocoaMenuItem = (NSMenuItem *) widget;
59 [[cocoaMenuItem menu] removeItem: cocoaMenuItem]; // this also releases the item
60 } else {
61 Melder_assert ([widget isKindOfClass: [NSView class]]);
62 NSView *cocoaView = (NSView *) widget;
63 if (cocoaView == [[cocoaView window] contentView]) {
64 [[cocoaView window] orderOut: nil];
65 [[cocoaView window] close];
66 [[cocoaView window] release];
67 } else {
68 [cocoaView removeFromSuperview]; // this also releases the view
69 }
70 }
71 #endif
72 }
73
74 /* End of file GuiObject.cpp */