Debian Codegraph @

sys/GuiWindow.cpp

raw symbols SCIP
1 /* GuiWindow.cpp
2 *
3 * Copyright (C) 1993-2018,2020,2021,2024,2025 Paul Boersma, 2013 Tom Naughton
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"cxx . . $ `<file>/sys/GuiP.h`/
20 #include "../kar/UnicodeData.h"cxx . . $ `<file>/kar/UnicodeData.h`/
21 #include "machine.h"cxx . . $ `<file>/sys/machine.h`/
22 #include <locale.h>
23
24 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiWindow, GuiShell, 0);
25
26 #undef iamcxx . . $ `melder/melder.h:50:9`!
27 #define iamcxx . . $ `sys/GuiWindow.cpp:27:9`!(x) x me = (x) void_me
28
29 #if gtkcxx . . $ `sys/Gui.h:33:10`!
30 static gboolean _GuiWindow_destroyCallbackcxx . . $ _GuiWindow_destroyCallback(2d2a8f722e23ecc4). (GuiObjectcxx . . $ GuiObject# widget, GdkEvent *event, gpointer void_me) {
31 (void) widget;
32 iamcxx . . $ `sys/GuiWindow.cpp:27:9`! (GuiWindow);
33 forgetcxx . . $ `sys/Thing.h:158:9`! (me);
34 return true;
35 }
36 static gboolean _GuiWindow_goAwayCallbackcxx . . $ _GuiWindow_goAwayCallback(2d2a8f722e23ecc4). (GuiObjectcxx . . $ GuiObject# widget, GdkEvent *event, gpointer void_me) {
37 (void) widget;
38 iamcxx . . $ `sys/GuiWindow.cpp:27:9`! (GuiWindow);
39 if (mycxx . . $ `melder/melder.h:44:9`! d_goAwayCallbackcxx . . $ structGuiShell#d_goAwayCallback.) {
40 mycxx . . $ `melder/melder.h:44:9`! d_goAwayCallbackcxx . . $ structGuiShell#d_goAwayCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).mycxx . . $ `melder/melder.h:44:9`! d_goAwayBosscxx . . $ structGuiShell#d_goAwayBoss.);
41 }
42 return true;
43 }
44 static void _GuiWindow_child_resizeCallbackcxx . . $ _GuiWindow_child_resizeCallback(c2a8b32df5332c4b). (GtkWidget *childWidget, gpointer data) {
45 GtkAllocation *parentAllocation = (GtkAllocation *) data;
46 GtkWidget *parentWidget = gtk_widget_get_parent (childWidget);
47 Thing_castcxx . . $ `sys/Thing.h:246:9`! (GuiThing, child, _GuiObject_getUserData (childWidget));
48 if (child) {
49 GuiControlcxx . . $ GuiControl# control = nullptr;
50 if (Thing_isacxx . . $ Thing_isa(8cbb12e93d03b2a1). (child, classGuiWindowcxx . . $ classGuiWindow.)) {
51 control = static_cast <GuiWindowcxx . . $ GuiWindow#> (child);
52 //Melder_casual (U"menu bar");
53 } else if (Thing_isacxx . . $ Thing_isa(8cbb12e93d03b2a1). (child, classGuiControlcxx . . $ classGuiControl.)) {
54 control = static_cast <GuiControlcxx . . $ GuiControl#> (child);
55 //Melder_casual (U"control");
56 } else if (Thing_isacxx . . $ Thing_isa(8cbb12e93d03b2a1). (child, classGuiMenucxx . . $ classGuiMenu.)) {
57 Thing_castcxx . . $ `sys/Thing.h:246:9`! (GuiMenu, menu, child);
58 control = menu -> d_cascadeButtoncxx . . $ structGuiMenu#d_cascadeButton..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
59 //Melder_casual (U"menu");
60 }
61 if (control) {
62 /*
63 Move and resize.
64 */
65 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"moving child of class ", Thing_className (control));
66 int left = control -> d_leftcxx . . $ structGuiControl#d_left., right = control -> d_rightcxx . . $ structGuiControl#d_right., top = control -> d_topcxx . . $ structGuiControl#d_top., bottom = control -> d_bottomcxx . . $ structGuiControl#d_bottom.;
67 if (left < 0) left += parentAllocation -> width; // this replicates structGuiControl :: v_positionInForm ()
68 if (right <= 0) right += parentAllocation -> width;
69 if (top < 0) top += parentAllocation -> height;
70 if (bottom <= 0) bottom += parentAllocation -> height;
71 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"moving child to (", left, U",", top, U") with size ", right - left, U" x ", bottom - top, U".");
72 GtkAllocation childAllocation { parentAllocation -> x + left, parentAllocation -> y + top, right - left, bottom - top };
73 gtk_widget_size_allocate (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (childWidget), & childAllocation);
74 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"moved child of class ", Thing_className (control));
75 }
76 }
77 }
78 static void _GuiWindow_resizeCallbackcxx . . $ _GuiWindow_resizeCallback(f92a4b2dd5db7c1d). (GuiObjectcxx . . $ GuiObject# widget, GtkAllocation *allocation, gpointer void_me) {
79 (void) widget;
80 iamcxx . . $ `sys/GuiWindow.cpp:27:9`! (GuiWindow);
81 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"fixed received size allocation: (", allocation -> x, U", ", allocation -> y,
82 U"), ", allocation -> width, U" x ", allocation -> height, U".");
83 /*
84 Apparently, GTK sends the size allocation message both to the shell and to its fixed-container child.
85 we could capture the message either from the shell or from the fixed; we choose to do it from the fixed.
86 */
87 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (GTK_IS_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:41:9`! (widget));
88 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (GTK_IS_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:41:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
89 /*
90 We move and resize all the children of the fixed.
91 */
92 #if defined (chrome)
93 {
94 GtkAllocation surrogateShellTitleLabelWidgetAllocation { allocation -> x, allocation -> y, allocation -> width, 31 };
95 gtk_widget_size_allocate (GTK_WIDGET (my chrome_surrogateShellTitleLabelWidget), & surrogateShellTitleLabelWidgetAllocation);
96 }
97 #endif
98 gtk_container_foreach (GTK_CONTAINERcxx . . $ `<external>/462093496598485868/gtkcontainer.h:38:9`! (widget), _GuiWindow_child_resizeCallbackcxx . . $ _GuiWindow_child_resizeCallback(c2a8b32df5332c4b)., allocation);
99 //gtk_container_foreach (GTK_CONTAINER (my d_widget), _GuiWindow_child_resizeCallback, allocation);
100 mycxx . . $ `melder/melder.h:44:9`! d_widthcxx . . $ structGuiShell#d_width. = allocation -> width;
101 mycxx . . $ `melder/melder.h:44:9`! d_heightcxx . . $ structGuiShell#d_height. = allocation -> height;
102 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"end");
103 }
104 #elif motif
105 static void _GuiMotifWindow_destroyCallback (GuiObject widget, XtPointer void_me, XtPointer call) {
106 (void) widget; (void) call;
107 iam (GuiWindow);
108 if (my d_xmMenuBar) {
109 }
110 trace (U"destroying window widget");
111 forget (me);
112 }
113 static void _GuiMotifWindow_goAwayCallback (GuiObject widget, XtPointer void_me, XtPointer call) {
114 (void) widget; (void) call;
115 iam (GuiWindow);
116 if (my d_goAwayCallback) {
117 //Melder_casual (U"_GuiMotifWindow_goAwayCallback: before");
118 my d_goAwayCallback (my d_goAwayBoss);
119 //Melder_casual (U"_GuiMotifWindow_goAwayCallback: after");
120 }
121 }
122 #endif
123
124 GuiWindowcxx . . $ GuiWindow# GuiWindow_createcxx . . $ GuiWindow_create(f24bfc1968593561). (int x, int y, int width, int height, int minimumWidth, int minimumHeight,
125 conststring32cxx . . $ conststring32# title /* cattable */, GuiShell_GoAwayCallbackcxx . . $ GuiShell_GoAwayCallback# goAwayCallback, Thingcxx . . $ Thing# goAwayBoss, uint32cxx . . $ uint32# flags)
126 {
127 autoGuiWindowcxx . . $ autoGuiWindow# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiWindow);
128 if (Melder_debugcxx . . $ Melder_debug. == 55)
129 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"\t", Thing_messageNameAndAddresscxx . . $ Thing_messageNameAndAddress(fbb3dc34e3ef688d). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()), U" init");
130 mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = nullptr;
131 mycxx . . $ `melder/melder.h:44:9`! d_goAwayCallbackcxx . . $ structGuiShell#d_goAwayCallback. =cxx . . $ MelderCallback#`operator=`(56fcffe4febc5261). goAwayCallback;
132 mycxx . . $ `melder/melder.h:44:9`! d_goAwayBosscxx . . $ structGuiShell#d_goAwayBoss. = goAwayBoss;
133 #if gtkcxx . . $ `sys/Gui.h:33:10`!
134 (void) flags;
135 GuiGtk_initializecxx . . $ GuiGtk_initialize(49f6e7a06ebc5aa8). ();
136 mycxx . . $ `melder/melder.h:44:9`! d_gtkWindowcxx . . $ structGuiShell#d_gtkWindow. = (GtkWindow *) gtk_window_new (GTK_WINDOW_TOPLEVEL);
137 #if 0
138 static const GdkRGBA backgroundColour { 0.92, 0.92, 0.92, 1.0 };
139 gtk_widget_override_background_color (GTK_WIDGET (my d_gtkWindow), GTK_STATE_FLAG_NORMAL, & backgroundColour);
140 #endif
141 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), "delete-event", goAwayCallback ? G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiWindow_goAwayCallback) : G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (gtk_widget_hide_on_delete), me.get());
142 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), "destroy-event", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiWindow_destroyCallback), me.get());
143
144 gtk_window_set_default_size (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), width, height);
145 gtk_window_set_resizable (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), true);
146
147 mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_fixed_new ();
148 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
149 gtk_widget_set_size_request (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), minimumWidth, minimumHeight);
150 gtk_container_add (GTK_CONTAINERcxx . . $ `<external>/462093496598485868/gtkcontainer.h:38:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
151 GdkGeometry geometry = { minimumWidth, minimumHeight, 0, 0, 0, 0, 0, 0, 0, 0, GDK_GRAVITY_NORTH_WEST };
152 gtk_window_set_geometry_hints (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindowcxx . . $ structGuiShell#d_gtkWindow., GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & geometry, GDK_HINT_MIN_SIZE);
153 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "size-allocate", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiWindow_resizeCallback), me.get());
154 //g_signal_connect (G_OBJECT (my d_gtkWindow), "size-allocate", G_CALLBACK (_GuiWindow_resizeCallback), me.get());
155 #if defined (chrome)
156 my chrome_surrogateShellTitleLabelWidget = gtk_label_new (Melder_peek32to8 (title));
157 gtk_label_set_use_markup (GTK_LABEL (my chrome_surrogateShellTitleLabelWidget), true);
158 gtk_widget_set_size_request (GTK_WIDGET (my chrome_surrogateShellTitleLabelWidget), minimumWidth, 31 /*Machine_getTextHeight()*/);
159 gtk_misc_set_alignment (GTK_MISC (my chrome_surrogateShellTitleLabelWidget), 0.5, 0.0);
160 gtk_fixed_put (GTK_FIXED (my d_widget), GTK_WIDGET (my chrome_surrogateShellTitleLabelWidget), 8, 0);
161 gtk_widget_show (GTK_WIDGET (my chrome_surrogateShellTitleLabelWidget));
162 #endif
163 GuiShell_setTitlecxx . . $ GuiShell_setTitle(3a9df304850abc11). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), title);
164 gint rootX, rootY;
165 gtk_window_get_position (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindowcxx . . $ structGuiShell#d_gtkWindow., & rootX, & rootY);
166 tracecxx . . $ `melder/melder_debug.h:60:10`! (rootX, U" root ", rootY);
167 #elif motif
168 my d_xmShell = XmCreateShell (nullptr, flags & GuiWindow_FULLSCREEN ? "Praatwulgfullscreen" : "Praatwulg", nullptr, 0);
169 XtVaSetValues (my d_xmShell, XmNdeleteResponse, goAwayCallback ? XmDO_NOTHING : XmUNMAP, nullptr);
170 XtVaSetValues (my d_xmShell, XmNx, x, XmNy, y, XmNwidth, (Dimension) width, XmNheight, (Dimension) height, nullptr);
171 if (goAwayCallback)
172 XmAddWMProtocolCallback (my d_xmShell, 'delw', _GuiMotifWindow_goAwayCallback, (char *) me.get());
173 GuiShell_setTitle (me.get(), title);
174 my d_widget = XmCreateForm (my d_xmShell, "dialog", nullptr, 0);
175 _GuiObject_setUserData (my d_widget, me.get());
176 XtAddCallback (my d_widget, XmNdestroyCallback, _GuiMotifWindow_destroyCallback, me.get());
177 XtVaSetValues (my d_widget, XmNdialogStyle, XmDIALOG_MODELESS, XmNautoUnmanage, False, nullptr);
178 #elif cocoa
179 (void) flags;
180 NSRect rect = { { static_cast<CGFloat>(x), static_cast<CGFloat>(y) }, { static_cast<CGFloat>(width), static_cast<CGFloat>(height) } };
181 my d_cocoaShell = [[GuiCocoaShell alloc]
182 initWithContentRect: rect
183 styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
184 backing: NSBackingStoreBuffered
185 defer: false];
186 //GuiCocoaShellDelegate *delegate = [[GuiCocoaShellDelegate alloc] init];
187 //my d_cocoaShell. delegate = delegate;
188 if (Melder_debug == 55)
189 Melder_casual (U"\t\tGuiCocoaShell-", Melder_pointer (my d_cocoaShell), U" init in ", Thing_messageNameAndAddress (me.get()));
190 [my d_cocoaShell setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
191 [my d_cocoaShell setMinSize: NSMakeSize (minimumWidth, minimumHeight)];
192 GuiShell_setTitle (me.get(), title);
193 [my d_cocoaShell makeKeyAndOrderFront: nil];
194 [my d_cocoaShell layoutIfNeeded];
195 [my d_cocoaShell setDistinctiveBackGround];
196 my d_widget = (GuiObject) [my d_cocoaShell contentView]; // BUG: this d_widget doesn't have the GuiCocoaAny protocol
197 _GuiObject_setUserData (my d_cocoaShell, me.get());
198 //if (! theGuiCocoaWindowDelegate) {
199 // theGuiCocoaWindowDelegate = [[GuiCocoaWindowDelegate alloc] init];
200 //}
201 //[my d_cocoaWindow setDelegate: theGuiCocoaWindowDelegate];
202 #endif
203 mycxx . . $ `melder/melder.h:44:9`! d_widthcxx . . $ structGuiShell#d_width. = width;
204 mycxx . . $ `melder/melder.h:44:9`! d_heightcxx . . $ structGuiShell#d_height. = height;
205 mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
206 return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).();
207 }
208
209 uintegercxx . . $ uinteger# theGuiTopLowAcceleratorscxx . . $ theGuiTopLowAccelerators. [8];
210
211 void GuiWindow_addMenuBarcxx . . $ GuiWindow_addMenuBar(20efc9fbfef198b1). (GuiWindowcxx . . $ GuiWindow# me) {
212 #if gtkcxx . . $ `sys/Gui.h:33:10`!
213 mycxx . . $ `melder/melder.h:44:9`! d_gtkMenuBarcxx . . $ structGuiWindow#d_gtkMenuBar. = (GtkMenuBar *) gtk_menu_bar_new ();
214 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_gtkMenuBarcxx . . $ structGuiWindow#d_gtkMenuBar., me);
215 mycxx . . $ `melder/melder.h:44:9`! v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (mycxx . . $ `melder/melder.h:44:9`! d_gtkMenuBarcxx . . $ structGuiWindow#d_gtkMenuBar., 0, 0, Machine_getMenuBarTopcxx . . $ Machine_getMenuBarTop(b126dc7c1de90089). (), Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). (), me); // BUG?
216
217 // we need an accelerator group for each window we're creating accelerated menus on
218 GuiObjectcxx . . $ GuiObject# topwin = gtk_widget_get_toplevel (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
219 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (topwin == mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow);
220 GtkAccelGroup *ag = gtk_accel_group_new ();
221 gtk_window_add_accel_group (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (topwin), ag);
222 // unfortunately, menu-bars don't fiddle with accel-groups, so we need a way
223 // to pass it to the sub-menus created upon this bar for their items to have
224 // access to the accel-group
225 g_object_set_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkMenuBar), "accel-group", ag);
226 gtk_widget_show (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkMenuBar));
227 #elif motif
228 my d_xmMenuBar = XmCreateMenuBar (my d_widget, "menuBar", nullptr, 0);
229 XtVaSetValues (my d_xmMenuBar, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, nullptr);
230 XtManageChild (my d_xmMenuBar);
231 #elif cocoa
232 (void) me; // this is handled elsewhere
233 #endif
234 }
235
236 bool GuiWindow_setDirtycxx . . $ GuiWindow_setDirty(aed7644c12df6ab). (GuiWindowcxx . . $ GuiWindow# me, bool dirty) {
237 #if gtkcxx . . $ `sys/Gui.h:33:10`!
238 (void) dirty;
239 return false;
240 #elif motif
241 (void) dirty;
242 return false;
243 #elif cocoa
244 [my d_cocoaShell setDocumentEdited: dirty];
245 return true;
246 #else
247 (void) dirty;
248 return false;
249 #endif
250 }
251
252 /* End of file GuiWindow.cpp */