Debian Codegraph @

sys/GuiControl.cpp

raw symbols SCIP
1 /* GuiControl.cpp
2 *
3 * Copyright (C) 1993-2012,2013,2015,2017,2020,2021,2023 Paul Boersma,
4 * 2008 Stefan de Koninck, 2010 Franz Brausse, 2013 Tom Naughton
5 *
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This code is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this work. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/
21 #include "machine.h"cxx . . $ `<file>/sys/machine.h`/
22
23 void structGuiControlcxx . . $ structGuiControl# :: v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (GuiObjectcxx . . $ GuiObject# widget, int left, int right, int top, int bottom, GuiFormcxx . . $ GuiForm# parent) {
24 #if gtkcxx . . $ `sys/Gui.h:33:10`!
25 /*
26 * Remember the location settings for resizing.
27 */
28 d_leftcxx . . $ structGuiControl#d_left. = left;
29 d_rightcxx . . $ structGuiControl#d_right. = right;
30 d_topcxx . . $ structGuiControl#d_top. = top;
31 d_bottomcxx . . $ structGuiControl#d_bottom. = bottom;
32 /*
33 */
34 if (! parent)
35 return;
36 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (parent -> d_widget);
37 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (GTK_IS_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:41:9`! (parent -> d_widget));
38 gint parentWidth, parentHeight;
39 gtk_widget_get_size_request (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (parent -> d_widget), & parentWidth, & parentHeight);
40 //parentWidth = gtk_widget_get_allocated_width (GTK_WIDGET (parent -> d_widget));
41 //parentHeight = gtk_widget_get_allocated_height (GTK_WIDGET (parent -> d_widget));
42 //parentWidth = parent -> d_right;
43 //parentHeight = parent -> d_top;
44 if (left < 0) left += parentWidth;
45 if (right <= 0) right += parentWidth;
46 if (top < 0) top += parentHeight;
47 if (bottom <= 0) bottom += parentHeight;
48 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"fixed: parent width ", parentWidth, U" height ", parentHeight);
49 gtk_widget_set_size_request (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget), right - left, bottom - top);
50 gtk_fixed_put (GTK_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:39:9`! (parent -> d_widget), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget), left, top);
51 #elif motif
52 (void) parent;
53 if (left >= 0) {
54 if (right > 0) {
55 XtVaSetValues (widget, XmNx, left, XmNwidth, right - left, nullptr);
56 } else {
57 XtVaSetValues (widget, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, left, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, - right, nullptr);
58 }
59 } else {
60 Melder_assert (right <= 0);
61 trace (U"parent width ", parent -> d_widget -> width);
62 XtVaSetValues (widget, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, - right, XmNwidth, right - left, nullptr);
63 trace (U"parent width ", parent -> d_widget -> width);
64 }
65 if (top >= 0) {
66 if (bottom > 0) {
67 XtVaSetValues (widget, XmNy, top, XmNheight, bottom - top, nullptr);
68 } else {
69 XtVaSetValues (widget, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, top, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, - bottom, nullptr);
70 }
71 } else {
72 Melder_assert (bottom <= 0);
73 XtVaSetValues (widget, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, - bottom, XmNheight, bottom - top, nullptr);
74 }
75 #elif cocoa
76 NSView *superView = (NSView *) parent -> d_widget;
77 NSView *widgetView = (NSView *) widget;
78 NSRect parentRect = [superView frame];
79 int parentWidth = parentRect.size.width;
80 int parentHeight = parentRect.size.height;
81
82 NSUInteger horizMask = 0;
83 if (left >= 0) {
84 if (right <= 0)
85 horizMask = NSViewWidthSizable;
86 } else {
87 horizMask = NSViewMinXMargin;
88 }
89
90 NSUInteger vertMask = 0;
91 if (top >= 0) {
92 vertMask = NSViewMinYMargin;
93 if (bottom <= 0)
94 vertMask = NSViewHeightSizable;
95 }
96
97 if (left < 0) left += parentWidth;
98 if (right <= 0) right += parentWidth;
99 if (top < 0) top += parentHeight;
100 if (bottom <= 0) bottom += parentHeight;
101 top = parentHeight - top; // flip
102 bottom = parentHeight - bottom; // flip
103 int width = right - left;
104 int height = top - bottom;
105 if ([widgetView isKindOfClass: [NSButton class]]) {
106 if (! [widgetView isKindOfClass: [NSPopUpButton class]]) {
107 /*
108 On Cocoa, NSButton views show up 12 pixels less wide and 5 pixels less high than their frame.
109 Compensate for this (undocumented?) Cocoa phenomenon.
110 */
111 if (Melder_systemVersion < 260000) {
112 left -= 6;
113 width += 12;
114 bottom -= 5;
115 height += 5;
116 } else {
117 left -= 2;
118 width += 4;
119 bottom -= 2;
120 height += 4;
121 }
122 }
123 }
124 NSRect rect = NSMakeRect (left, bottom, width, height);
125 [widgetView setAutoresizingMask: horizMask | vertMask];
126 [superView addSubview: widgetView]; // parent will retain the subview...
127 [widgetView setFrame: rect];
128 [widgetView setClipsToBounds: true]; // 20231019: seems to be needed from SDK 14.0
129 [widgetView release]; // ... so we can release the item already
130 #endif
131 }
132
133 void structGuiControlcxx . . $ structGuiControl# :: v_positionInScrolledWindowcxx . . $ structGuiControl#v_positionInScrolledWindow(bd0f8bf0b668f63a). (GuiObjectcxx . . $ GuiObject# widget, int width, int height, GuiScrolledWindowcxx . . $ GuiScrolledWindow# parent) {
134 #if gtkcxx . . $ `sys/Gui.h:33:10`!
135 if (! parent)
136 return;
137 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (GTK_IS_SCROLLED_WINDOWcxx . . $ `<external>/15242555379300173687/gtkscrolledwindow.h:40:9`! (parent -> d_widget));
138 gtk_widget_set_size_request (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget), width, height);
139 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOWcxx . . $ `<external>/15242555379300173687/gtkscrolledwindow.h:38:9`! (parent -> d_widget), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget));
140 #elif motif
141 (void) parent;
142 XtVaSetValues (widget, XmNwidth, width, XmNheight, height, nullptr);
143 #elif cocoa
144 GuiCocoaScrolledWindow *scrolledWindow = (GuiCocoaScrolledWindow *) parent -> d_widget;
145 NSView *widgetView = (NSView *) widget;
146 NSRect rect = NSMakeRect (0, 0, width, height);
147 [widgetView initWithFrame: rect];
148 [widgetView setBounds: rect];
149 [scrolledWindow setDocumentView: widgetView];
150 [widgetView release]; // ... so we can release the item already
151 #endif
152 }
153
154 int GuiControl_getXcxx . . $ GuiControl_getX(1227891e76fac374). (GuiControlcxx . . $ GuiControl# me) {
155 #if gtkcxx . . $ `sys/Gui.h:33:10`!
156 //return GTK_WIDGET (my d_widget) -> allocation.x;
157 GtkAllocation allocation;
158 gtk_widget_get_allocation (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & allocation);
159 return allocation.x;
160 #elif motif
161 return my d_widget -> x;
162 #elif cocoa
163 return [(NSView *) my d_widget frame]. origin. x;
164 #else
165 return 0;
166 #endif
167 }
168
169 int GuiControl_getYcxx . . $ GuiControl_getY(1227891e76fac374). (GuiControlcxx . . $ GuiControl# me) {
170 #if gtkcxx . . $ `sys/Gui.h:33:10`!
171 //return GTK_WIDGET (my d_widget) -> allocation.y;
172 GtkAllocation allocation;
173 gtk_widget_get_allocation (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & allocation);
174 return allocation.y;
175 #elif motif
176 return my d_widget -> y;
177 #elif cocoa
178 return [(NSView *) my d_widget frame]. origin. y;
179 #else
180 return 0;
181 #endif
182 }
183
184 int GuiControl_getWidthcxx . . $ GuiControl_getWidth(1227891e76fac374). (GuiControlcxx . . $ GuiControl# me) {
185 #if gtkcxx . . $ `sys/Gui.h:33:10`!
186 //return GTK_WIDGET (my d_widget) -> allocation.width;
187 GtkAllocation allocation;
188 gtk_widget_get_allocation (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & allocation);
189 return allocation.width;
190 #elif motif
191 return my d_widget -> width;
192 #elif cocoa
193 return [(NSView *) my d_widget frame]. size. width;
194 #else
195 return 0;
196 #endif
197 }
198
199 int GuiControl_getHeightcxx . . $ GuiControl_getHeight(1227891e76fac374). (GuiControlcxx . . $ GuiControl# me) {
200 #if gtkcxx . . $ `sys/Gui.h:33:10`!
201 //return GTK_WIDGET (my d_widget) -> allocation.height;
202 GtkAllocation allocation;
203 gtk_widget_get_allocation (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & allocation);
204 return allocation.height;
205 #elif motif
206 return my d_widget -> height;
207 #elif cocoa
208 return [(NSView *) my d_widget frame]. size. height;
209 #else
210 return 0;
211 #endif
212 }
213
214 void GuiControl_movecxx . . $ GuiControl_move(8866d61c560ae333). (GuiControlcxx . . $ GuiControl# me, int x, int y) {
215 #if gtkcxx . . $ `sys/Gui.h:33:10`!
216 GuiObjectcxx . . $ GuiObject# parent = gtk_widget_get_parent (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
217 if (GTK_IS_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:41:9`! (parent)) {
218 gtk_fixed_move (GTK_FIXEDcxx . . $ `<external>/4105621574481455997/gtkfixed.h:39:9`! (parent), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), x, y);
219 }
220 #elif motif
221 XtVaSetValues (my d_widget, XmNx, (Position) x, XmNy, (Position) y, nullptr); // 64-bit-compatible
222 #elif cocoa
223 #endif
224 }
225
226 void GuiControl_setSizecxx . . $ GuiControl_setSize(8866d61c560ae333). (GuiControlcxx . . $ GuiControl# me, int width, int height) {
227 #if gtkcxx . . $ `sys/Gui.h:33:10`!
228 gtk_widget_set_size_request (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), width, height);
229 #elif motif
230 XtVaSetValues (my d_widget, XmNwidth, (Dimension) width, XmNheight, (Dimension) height, nullptr); // 64-bit-compatible
231 #elif cocoa
232 #endif
233 }
234
235 /* End of file GuiControl.cpp */