File: GuiObject.cpp

package info (click to toggle)
praat 5.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,728 kB
  • sloc: cpp: 333,759; ansic: 237,947; makefile: 731; python: 340
file content (312 lines) | stat: -rw-r--r-- 8,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* GuiObject.cpp
 *
 * Copyright (C) 1993-2011,2012 Paul Boersma
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * pb 2007/12/26 abstraction from motif
 * pb 2007/12/28 _GuiObject_position: allow the combination of fixed height and automatic position
 * sdk 2008/03/24 GTK
 * sdk 2008/07/01 GTK get sizes
 * fb 2010/02/23 GTK
 * pb 2010/11/28 removed Motif
 * pb 2011/04/06 C++
 */

#include "GuiP.h"
#include "machine.h"

static int _Gui_defaultHeight (GuiObject me) {
	#if win || mac && useCarbon
		WidgetClass klas = XtClass (me);
		if (klas == xmLabelWidgetClass) return Gui_LABEL_HEIGHT;
		if (klas == xmPushButtonWidgetClass) return Gui_PUSHBUTTON_HEIGHT;
		if (klas == xmTextWidgetClass) return Gui_TEXTFIELD_HEIGHT;
		if (klas == xmToggleButtonWidgetClass) return
			#ifdef UNIX
				Gui_CHECKBUTTON_HEIGHT;   // BUG
			#else
				my isRadioButton ? Gui_RADIOBUTTON_HEIGHT : Gui_CHECKBUTTON_HEIGHT;
			#endif
	#endif
	return 100;
}

void _GuiObject_position (GuiObject me, int left, int right, int top, int bottom) {
	#if gtk
		// TODO: ...nog even te creatief
	#elif win || mac && useCarbon
		if (left >= 0) {
			if (right > 0) {
				XtVaSetValues (me, XmNx, left, XmNwidth, right - left, NULL);
			} else if (right == Gui_AUTOMATIC) {
				XtVaSetValues (me, XmNx, left, NULL);
			} else {
				XtVaSetValues (me, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, left,
					XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, - right, NULL);
			}
		} else if (left == Gui_AUTOMATIC) {
			Melder_assert (right <= 0);
			if (right > Gui_AUTOMATIC + 3000)
				XtVaSetValues (me, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, - right, NULL);
			else if (right != Gui_AUTOMATIC)
				XtVaSetValues (me, XmNwidth, right - Gui_AUTOMATIC, NULL);
		} else {
			Melder_assert (right <= 0);
			XtVaSetValues (me, XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, - right, XmNwidth, right - left, NULL);
		}
		if (top >= 0) {
			if (bottom > 0) {
				XtVaSetValues (me, XmNy, top, XmNheight, bottom - top, NULL);
			} else if (bottom == Gui_AUTOMATIC) {
				XtVaSetValues (me, XmNy, top, XmNheight, _Gui_defaultHeight (me), NULL);
			} else {
				XtVaSetValues (me, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, top,
					XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, - bottom, NULL);
			}
		} else if (top == Gui_AUTOMATIC) {
			Melder_assert (bottom <= 0);
			if (bottom > Gui_AUTOMATIC + 3000)
				XtVaSetValues (me, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, - bottom, XmNheight, _Gui_defaultHeight (me), NULL);
			else if (bottom != Gui_AUTOMATIC)
				XtVaSetValues (me, XmNheight, bottom - Gui_AUTOMATIC, NULL);
		} else {
			Melder_assert (bottom <= 0);
			XtVaSetValues (me, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, - bottom, XmNheight, bottom - top, NULL);
		}
	#endif
}

void * _GuiObject_getUserData (GuiObject me) {
	void *userData = NULL;
	#if gtk
		userData = (void *) g_object_get_data (G_OBJECT (me), "praat");
	#elif win
		XtVaGetValues (me, XmNuserData, & userData, NULL);
	#elif mac
		#if useCarbon
			XtVaGetValues (me, XmNuserData, & userData, NULL);
		#else
		#endif
	#endif
	return userData;
}

void _GuiObject_setUserData (GuiObject me, void *userData) {
	#if gtk
		g_object_set_data (G_OBJECT (me), "praat", userData);
	#elif win
		XtVaSetValues (me, XmNuserData, userData, NULL);
	#elif mac
		#if useCarbon
			XtVaSetValues (me, XmNuserData, userData, NULL);
		#else
		#endif
	#endif
}

void GuiObject_destroy (GuiObject me) {
	#if gtk
		gtk_widget_destroy (GTK_WIDGET (me));
	#elif win
		XtDestroyWidget (me);
	#elif mac
		#if useCarbon
			XtDestroyWidget (me);
		#else
		#endif
	#endif
}

long GuiObject_getHeight (GuiObject me) {
	long height = 0;
	#if gtk
		height = GTK_WIDGET (me) -> allocation.height;
	#elif win
		height = my height;
	#elif mac
		#if useCarbon
			height = my height;
		#else
		#endif
	#endif
	return height;
}

long GuiObject_getWidth (GuiObject me) {
	long width = 0;
	#if gtk
		width = GTK_WIDGET (me) -> allocation.width;
	#elif win
		width = my width;
	#elif mac
		#if useCarbon
			width = my width;
		#else
		#endif
	#endif
	return width;
}

long GuiObject_getX (GuiObject me) {
	long x = 0;
	#if gtk
		x = GTK_WIDGET (me) -> allocation.x;
	#elif win
		x = my x;
	#elif mac
		#if useCarbon
			x = my x;
		#else
		#endif
	#endif
	return x;
}

long GuiObject_getY (GuiObject me) {
	long y = 0;
	#if gtk
		y = GTK_WIDGET (me) -> allocation.y;
	#elif win
		y = my y;
	#elif mac
		#if useCarbon
			y = my y;
		#else
		#endif
	#endif
	return y;
}

void GuiObject_move (GuiObject me, long x, long y) {
	#if gtk
	#elif win || mac && useCarbon
		if (x != Gui_AUTOMATIC) {
			if (y != Gui_AUTOMATIC) {
				XtVaSetValues (me, XmNx, (Position) x, XmNy, (Position) y, NULL);   // 64-bit-compatible
			} else {
				XtVaSetValues (me, XmNx, (Position) x, NULL);   // 64-bit-compatible
			}
		} else if (y != Gui_AUTOMATIC) {
			XtVaSetValues (me, XmNy, (Position) y, NULL);   // 64-bit-compatible
		}
	#endif
}

void GuiObject_hide (GuiObject me) {
	#if gtk
		GuiObject parent = gtk_widget_get_parent (GTK_WIDGET (me));
		if (parent != NULL && GTK_IS_DIALOG (parent)) {   // I am the top vbox of a dialog
			gtk_widget_hide (GTK_WIDGET (parent));
		} else {
			gtk_widget_hide (GTK_WIDGET (me));
		}
	#elif win
		XtUnmanageChild (me);
		// nothing, because the scrolled window is not a widget
	#elif mac
		#if useCarbon
			XtUnmanageChild (me);
			if (my widgetClass == xmListWidgetClass) {
				XtUnmanageChild (my parent);   // the containing scrolled window; BUG if created with XmScrolledList?
			}
		#else
		#endif
	#endif
}

GuiObject GuiObject_parent (GuiObject me) {
	#if gtk
		return gtk_widget_get_parent (GTK_WIDGET (me));
	#elif win
		return my parent;
	#elif mac
		#if useCarbon
			return my parent;
		#else
			return NULL;   // TODO
		#endif
	#endif
}

void GuiObject_setSensitive (GuiObject me, bool sensitive) {
	#if gtk
		gtk_widget_set_sensitive (GTK_WIDGET (me), sensitive);
	#elif win
		XtSetSensitive (me, sensitive);
	#elif mac
		#if useCarbon
			XtSetSensitive (me, sensitive);
		#else
		#endif
	#endif
}

void GuiObject_show (GuiObject me) {
	#if gtk
		GuiObject parent = gtk_widget_get_parent (GTK_WIDGET (me));
		if (GTK_IS_WINDOW (parent)) {
			// I am a window's vbox
			gtk_widget_show (GTK_WIDGET (me));
			gtk_window_present (GTK_WINDOW (parent));
		} else if (GTK_IS_DIALOG (parent)) {
			// I am a dialog's vbox, and therefore automatically shown
			gtk_window_present (GTK_WINDOW (parent));
		} else {
			gtk_widget_show (GTK_WIDGET (me));
		}
	#elif win
		XtManageChild (me);
		GuiObject parent = my parent;
		if (parent -> widgetClass == xmShellWidgetClass) {
			XMapRaised (XtDisplay (parent), XtWindow (parent));
		} else if (mac && my widgetClass == xmListWidgetClass) {
			XtManageChild (parent);   // the containing scrolled window; BUG if created with XmScrolledList?
		}
	#elif mac
		#if useCarbon
			XtManageChild (me);
			GuiObject parent = my parent;
			if (parent -> widgetClass == xmShellWidgetClass) {
				XMapRaised (XtDisplay (parent), XtWindow (parent));
			} else if (mac && my widgetClass == xmListWidgetClass) {
				XtManageChild (parent);   // the containing scrolled window; BUG if created with XmScrolledList?
			}
		#else
		#endif
	#endif
}

void GuiObject_size (GuiObject me, long width, long height) {
	#if gtk
		if (width == Gui_AUTOMATIC || width <= 0) width = -1;
		if (height == Gui_AUTOMATIC || height <= 0) height = -1;
		gtk_widget_set_size_request (GTK_WIDGET (me), width, height);
	#elif win || mac && useCarbon
		if (width != Gui_AUTOMATIC) {
			if (height != Gui_AUTOMATIC) {
				XtVaSetValues (me, XmNwidth, (Dimension) width, XmNheight, (Dimension) height, NULL);   // 64-bit-compatible
			} else {
				XtVaSetValues (me, XmNwidth, (Dimension) width, NULL);   // 64-bit-compatible
			}
		} else if (height != Gui_AUTOMATIC) {
			XtVaSetValues (me, XmNheight, (Dimension) height, NULL);   // 64-bit-compatible
		}
	#endif
}

/* End of file GuiObject.cpp */