| 1 |
/* motifEmulator.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1993-2026 Paul Boersma |
| 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 <stdio.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#include <stdarg.h> |
| 22 |
#include <string.h> |
| 23 |
#include <ctype.h> |
| 24 |
#include <time.h> |
| 25 |
#include "melder.h" |
| 26 |
#include "GuiP.h" |
| 27 |
#include "machine.h" |
| 28 |
|
| 29 |
static void (*theQuitApplicationCallback) (); |
| 30 |
|
| 31 |
void Gui_setQuitApplicationCallback (void (*quitApplicationCallback) ()) { |
| 32 |
theQuitApplicationCallback = quitApplicationCallback; |
| 33 |
} |
| 34 |
void Gui_runQuitApplicationCallback () { |
| 35 |
theQuitApplicationCallback (); |
| 36 |
} |
| 37 |
|
| 38 |
#if defined (_WIN32) |
| 39 |
#define TRY_BARLESS 0 |
| 40 |
|
| 41 |
/* The Motif emulator for Windows. */ |
| 42 |
|
| 43 |
#define PRAAT_WINDOW_CLASS_NUMBER 1 |
| 44 |
|
| 45 |
/* |
| 46 |
* The MEMBER macros only work if klas1 etc are no macros themselves. |
| 47 |
* Therefore, we undefine those who are: |
| 48 |
*/ |
| 49 |
#undef MessageBox |
| 50 |
|
| 51 |
#define _motif_SHIFT_MASK 1 |
| 52 |
#define _motif_COMMAND_MASK 2 |
| 53 |
#define _motif_OPTION_MASK 4 |
| 54 |
|
| 55 |
#define CELL_HEIGHT 15 |
| 56 |
#define MESSAGE_BOX_BUTTON_WIDTH 100 |
| 57 |
|
| 58 |
static void _motif_update (GuiObject me, void *event); |
| 59 |
|
| 60 |
/********** Resource names. **********/ |
| 61 |
|
| 62 |
#define motif_RESOURCE(xxx) #xxx, |
| 63 |
static const char *motif_resourceNames [] = { |
| 64 |
"XmNnull", |
| 65 |
#include "motifEmulator_resources.h" |
| 66 |
"XmNend" |
| 67 |
}; |
| 68 |
#undef motif_RESOURCE |
| 69 |
|
| 70 |
/* Modes. */ |
| 71 |
|
| 72 |
struct Gui theGui; // global variable |
| 73 |
|
| 74 |
/********** XWindows routines. **********/ |
| 75 |
|
| 76 |
void XMapRaised (int displayDummy, Window window) { |
| 77 |
(void) displayDummy; |
| 78 |
ShowWindow ((HWND) window, SW_SHOW); |
| 79 |
SetForegroundWindow ((HWND) window); |
| 80 |
} |
| 81 |
|
| 82 |
int WidthOfScreen (int screen) { |
| 83 |
(void) screen; |
| 84 |
return GetSystemMetrics (SM_CXMAXIMIZED); |
| 85 |
} |
| 86 |
int HeightOfScreen (int screen) { |
| 87 |
(void) screen; |
| 88 |
return GetSystemMetrics (SM_CYMAXIMIZED); |
| 89 |
} |
| 90 |
|
| 91 |
/********** X Toolkit **********/ |
| 92 |
|
| 93 |
void _Gui_callCallbacks (GuiObject w, XtCallbackList *callbacks, XtPointer call) { |
| 94 |
for (int i = 0; i < MAXNUM_CALLBACKS; i ++) |
| 95 |
if (callbacks -> pairs [i]. proc) |
| 96 |
callbacks -> pairs [i]. proc (w, callbacks -> pairs [i]. closure, call); |
| 97 |
} |
| 98 |
|
| 99 |
#define MAXIMUM_NUMBER_OF_MENUS 4000 |
| 100 |
static GuiObject theMenus [1+MAXIMUM_NUMBER_OF_MENUS]; // we can freely use and reuse these menu ids |
| 101 |
static char32 theWindowClassName [100], theDrawingAreaClassName [100], theApplicationClassName [100]; |
| 102 |
char32 * _GuiWin_getDrawingAreaClassName () { return theDrawingAreaClassName; } |
| 103 |
static int (*theUserMessageCallback) (); |
| 104 |
#define MINIMUM_MENU_ITEM_ID (MAXIMUM_NUMBER_OF_MENUS + 1) |
| 105 |
#define MAXIMUM_MENU_ITEM_ID 32767 |
| 106 |
static short theMenuItems [1+MAXIMUM_MENU_ITEM_ID]; // we can freely use and reuse the item ids 4001..32767 |
| 107 |
|
| 108 |
static GuiObject theApplicationShell; // for global menus |
| 109 |
static int theBackground = False; // set by suspend and resume events; used by Motif-style activation methods |
| 110 |
static int theDialogHint = False; // should the shell that is currently being created, have dialog or document looks? |
| 111 |
integer numberOfWidgets = 0; |
| 112 |
integer Gui_getNumberOfMotifWidgets () { return numberOfWidgets; } |
| 113 |
|
| 114 |
/* AppContext level */ |
| 115 |
|
| 116 |
static int theNumberOfWorkProcs; |
| 117 |
static XtWorkProc theWorkProcs [10]; |
| 118 |
static XtPointer theWorkProcClosures [10]; |
| 119 |
|
| 120 |
static int theNumberOfTimeOuts; |
| 121 |
static XtTimerCallbackProc theTimeOutProcs [10]; |
| 122 |
static XtPointer theTimeOutClosures [10]; |
| 123 |
static double theTimeOutStarts [10]; |
| 124 |
static double theTimeOutIntervals [10]; |
| 125 |
|
| 126 |
static void Native_move (GuiObject w, int dx, int dy); // forward |
| 127 |
|
| 128 |
static void cb_scroll (GuiObject scrollBar, XtPointer closure, XtPointer call) { |
| 129 |
GuiObject scrolledWindow = (GuiObject) closure; |
| 130 |
GuiObject workWindow = scrolledWindow -> motiff.scrolledWindow.workWindow; |
| 131 |
int previousShift, newShift, distance; |
| 132 |
bool horizontal = ( scrolledWindow -> motiff.scrolledWindow.horizontalBar == scrollBar ); |
| 133 |
(void) call; |
| 134 |
if (! workWindow) |
| 135 |
return; |
| 136 |
Melder_assert (scrolledWindow -> motiff.scrolledWindow.clipWindow); |
| 137 |
previousShift = horizontal ? |
| 138 |
scrolledWindow -> motiff.scrolledWindow.clipWindow -> x - workWindow -> x : |
| 139 |
scrolledWindow -> motiff.scrolledWindow.clipWindow -> y - workWindow -> y; |
| 140 |
newShift = scrollBar -> value; |
| 141 |
distance = previousShift - newShift; |
| 142 |
if (horizontal) { |
| 143 |
workWindow -> x += distance; |
| 144 |
Native_move (workWindow, distance, 0); |
| 145 |
} else { |
| 146 |
workWindow -> y += distance; |
| 147 |
Native_move (workWindow, 0, distance); |
| 148 |
} |
| 149 |
GdiFlush (); // for dragging |
| 150 |
} |
| 151 |
|
| 152 |
/* These are like the toolkit's query_geometry methods: */ |
| 153 |
|
| 154 |
static int Native_titleWidth (GuiObject me) { |
| 155 |
if (my parent -> window) { |
| 156 |
HDC dc = GetDC (my parent -> window); |
| 157 |
SIZE size; |
| 158 |
SelectFont (dc, theWinGuiNormalLabelFont ()); // possible BUG |
| 159 |
conststringW nameW = Melder_peek32toW (my name.get()); |
| 160 |
GetTextExtentPoint32 (dc, nameW, wcslen (nameW), & size); |
| 161 |
ReleaseDC (my parent -> window, dc); |
| 162 |
return size. cx; |
| 163 |
} else { |
| 164 |
return 7 * Melder_length (my name.get()); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
static int NativeLabel_preferredWidth (GuiObject me) { |
| 169 |
return Native_titleWidth (me) + 10; |
| 170 |
} |
| 171 |
|
| 172 |
static int NativeButton_preferredWidth (GuiObject me) { |
| 173 |
int width = Native_titleWidth (me) + 10; |
| 174 |
return width < 41 ? 41 : width; |
| 175 |
} |
| 176 |
|
| 177 |
static int NativeToggleButton_preferredWidth (GuiObject me) { |
| 178 |
return Native_titleWidth (me) + 25; |
| 179 |
} |
| 180 |
|
| 181 |
static int NativeButton_preferredHeight (GuiObject me) { |
| 182 |
(void) me; |
| 183 |
return 22; |
| 184 |
} |
| 185 |
|
| 186 |
/***** WIDGET *****/ |
| 187 |
|
| 188 |
GuiObject _Gui_initializeWidget (int widgetClass, GuiObject parent, conststring32 name) { |
| 189 |
GuiObject me = Melder_calloc_f (struct structGuiObject, 1); |
| 190 |
if (Melder_debug == 34) |
| 191 |
Melder_casual (U"from _Gui_initializeWidget\t", Melder_pointer (me), U"\t1\t", sizeof (struct structGuiObject)); |
| 192 |
my magicNumber = 15111959; |
| 193 |
numberOfWidgets ++; |
| 194 |
my widgetClass = widgetClass; |
| 195 |
my parent = parent; |
| 196 |
my inMenu = parent && MEMBER (parent, PulldownMenu); |
| 197 |
my name = Melder_dup_f (name); |
| 198 |
|
| 199 |
/* |
| 200 |
Install me into my parent's list of children. |
| 201 |
*/ |
| 202 |
if (! parent) { |
| 203 |
; |
| 204 |
} else if (! parent -> firstChild) { |
| 205 |
parent -> firstChild = me; |
| 206 |
} else { |
| 207 |
GuiObject lastChild = parent -> firstChild; |
| 208 |
while (lastChild -> nextSibling) |
| 209 |
lastChild = lastChild -> nextSibling; |
| 210 |
lastChild -> nextSibling = me; |
| 211 |
my previousSibling = lastChild; |
| 212 |
} |
| 213 |
|
| 214 |
/* |
| 215 |
I am in the same shell as my parent, so I inherit my parent's "shell" attribute. |
| 216 |
*/ |
| 217 |
if (MEMBER (me, Shell)) |
| 218 |
my shell = me; |
| 219 |
else |
| 220 |
my shell = ( parent ? parent -> shell : nullptr ); |
| 221 |
|
| 222 |
/* |
| 223 |
* The remainder of initialization is about positioning, sizes, attachments, and the contents of a scrolled window. |
| 224 |
* All of that is irrelevant to menu items. |
| 225 |
*/ |
| 226 |
if (my inMenu) |
| 227 |
return me; |
| 228 |
|
| 229 |
/* Initial defaults: mainly positioning and sizes. */ |
| 230 |
|
| 231 |
switch (my widgetClass) { |
| 232 |
case xmDrawingAreaWidgetClass: { |
| 233 |
my x = 2; |
| 234 |
my y = 2; |
| 235 |
my width = 100; |
| 236 |
my height = 100; |
| 237 |
} break; case xmShellWidgetClass: { |
| 238 |
my x = 20; |
| 239 |
my y = 3; |
| 240 |
my width = 30; |
| 241 |
my height = 50; |
| 242 |
my deleteResponse = XmDESTROY; |
| 243 |
} break; case xmTextWidgetClass: { |
| 244 |
my x = 2; |
| 245 |
my y = 2; |
| 246 |
my width = 102; |
| 247 |
my height = Gui_TEXTFIELD_HEIGHT; |
| 248 |
} break; case xmPushButtonWidgetClass: { |
| 249 |
my x = 2; |
| 250 |
my y = 2; |
| 251 |
my width = NativeButton_preferredWidth (me); |
| 252 |
my height = Gui_PUSHBUTTON_HEIGHT; |
| 253 |
} break; case xmLabelWidgetClass: { |
| 254 |
my x = 2; |
| 255 |
my y = 2; |
| 256 |
my width = NativeLabel_preferredWidth (me); |
| 257 |
my height = Gui_LABEL_HEIGHT; |
| 258 |
} break; case xmCascadeButtonWidgetClass: { |
| 259 |
if (my parent -> rowColumnType == XmMENU_BAR) { |
| 260 |
my x = 2; |
| 261 |
my y = 2; |
| 262 |
my width = NativeButton_preferredWidth (me); |
| 263 |
my height = NativeButton_preferredHeight (me) + 4; // BUG: menu bar should be large enough |
| 264 |
} else { |
| 265 |
my motiff.cascadeButton.inBar = true; |
| 266 |
} |
| 267 |
} break; case xmToggleButtonWidgetClass: { |
| 268 |
my x = 2; |
| 269 |
my y = 2; |
| 270 |
my width = NativeToggleButton_preferredWidth (me); |
| 271 |
my height = Gui_CHECKBUTTON_HEIGHT; |
| 272 |
} break; case xmSeparatorWidgetClass: { |
| 273 |
my width = parent -> width; |
| 274 |
my height = 10; |
| 275 |
} break; case xmScrollBarWidgetClass: { |
| 276 |
my width = 16; |
| 277 |
my height = 100; |
| 278 |
} break; case xmMenuBarWidgetClass: { |
| 279 |
my width = 10; |
| 280 |
my height = 10; |
| 281 |
} break; case xmRowColumnWidgetClass: { |
| 282 |
my width = 10; |
| 283 |
my height = 10; |
| 284 |
my orientation = XmVERTICAL; |
| 285 |
} break; case xmScaleWidgetClass: { |
| 286 |
my width = 300; |
| 287 |
my height = 25; |
| 288 |
} break; case xmFormWidgetClass: { |
| 289 |
if (MEMBER (parent, Shell)) { |
| 290 |
/* |
| 291 |
* The following trick is necessary for forms that contain scroll bars. |
| 292 |
*/ |
| 293 |
my width = parent -> width; |
| 294 |
my height = parent -> height; |
| 295 |
} else { |
| 296 |
/* |
| 297 |
* EXPERIMENT: |
| 298 |
* this relies on a certain sequence in building up a window: from top to bottom. |
| 299 |
* If the form is inside a RowColumn of a certain width established by a widget |
| 300 |
* closer to the top, this width will be copied. The height, of course, should not be copied. |
| 301 |
* See Praat's SoundRecorder for an example. |
| 302 |
*/ |
| 303 |
my width = parent -> width; |
| 304 |
my height = 10; |
| 305 |
} |
| 306 |
} break; default: { |
| 307 |
my width = parent ? parent -> width : 0; |
| 308 |
my height = parent ? parent -> height : 0; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
/* Some positions depend on parent. */ |
| 313 |
|
| 314 |
if (parent) switch (parent -> widgetClass) { |
| 315 |
case xmFrameWidgetClass: { |
| 316 |
my x = 1; |
| 317 |
my y = 1; |
| 318 |
my width = parent -> width - 2; |
| 319 |
my height = parent -> height - 2; |
| 320 |
} break; case xmScrolledWindowWidgetClass: { |
| 321 |
my x = 1; |
| 322 |
my y = 1; |
| 323 |
my width = parent -> width - 17; // exact fit: scroll bar (16) plus border (1) |
| 324 |
my height = parent -> height - 17; |
| 325 |
if (my widgetClass == xmTextWidgetClass) { |
| 326 |
my width = 3000; |
| 327 |
my height = 30000; |
| 328 |
} // BUG: either put in GuiText or erase |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
if (my width < 0) |
| 333 |
my width = 0; |
| 334 |
if (my height < 0) |
| 335 |
my height = 0; |
| 336 |
|
| 337 |
/* Automatic attachment of dialog to parent shell. */ |
| 338 |
|
| 339 |
if (MEMBER2 (me, BulletinBoard, Form) && MEMBER (my parent, Shell)) |
| 340 |
my leftAttachment = my rightAttachment = my topAttachment = my bottomAttachment = XmATTACH_FORM; |
| 341 |
|
| 342 |
if (MEMBER (me, CascadeButton) && str32equ (name, U"Help")) |
| 343 |
my rightAttachment = XmATTACH_FORM; /* !!!!!! */ |
| 344 |
|
| 345 |
/* A child of a scrolled window will be installed as the workWindow of that scrolled window, |
| 346 |
* except if it is a scroll bar or if the clipWindow does not exist yet. |
| 347 |
* This is because the creations of the scroll bars and the clip window will also arrive here. |
| 348 |
* Our XmScrolledWindow creation method always creates two scroll bars and a clip window, |
| 349 |
* before you can create any other children. |
| 350 |
*/ |
| 351 |
|
| 352 |
if (my parent && MEMBER (my parent, ScrolledWindow) && |
| 353 |
! MEMBER (me, ScrollBar) && // 'me' is one of the two scroll bars, or a new one |
| 354 |
my parent -> motiff.scrolledWindow.clipWindow // 'me' is probably the clip window now |
| 355 |
) |
| 356 |
my parent -> motiff.scrolledWindow.workWindow = me; // install |
| 357 |
return me; |
| 358 |
} |
| 359 |
|
| 360 |
/***** NATIVE *****/ |
| 361 |
|
| 362 |
void _GuiNativeControl_check (GuiObject me, Boolean value) { |
| 363 |
Button_SetCheck (my window, value ? BST_CHECKED : BST_UNCHECKED); |
| 364 |
} |
| 365 |
|
| 366 |
void _GuiNativeControl_destroy (GuiObject me) { |
| 367 |
DestroyWindow (my window); |
| 368 |
} |
| 369 |
|
| 370 |
void _GuiNativeControl_show (GuiObject me) { |
| 371 |
ShowWindow (my window, SW_SHOW); |
| 372 |
} |
| 373 |
|
| 374 |
void _GuiNativeControl_hide (GuiObject me) { |
| 375 |
ShowWindow (my window, SW_HIDE); |
| 376 |
} |
| 377 |
|
| 378 |
void _GuiNativeControl_setSensitive (GuiObject me) { |
| 379 |
EnableWindow (my window, ! my insensitive); |
| 380 |
} |
| 381 |
|
| 382 |
char32 * _GuiWin_expandAmpersands (conststring32 title) { |
| 383 |
static char32 buffer [300]; |
| 384 |
const char32 *from = & title [0]; |
| 385 |
char32 *to = & buffer [0]; |
| 386 |
while (*from) { if (*from == U'&') * to ++ = U'&'; * to ++ = * from ++; } * to = U'\0'; |
| 387 |
return buffer; |
| 388 |
} |
| 389 |
|
| 390 |
void _GuiNativeControl_setTitle (GuiObject me) { |
| 391 |
HDC dc = GetDC (my window); |
| 392 |
SelectPen (dc, GetStockPen (NULL_PEN)); |
| 393 |
SelectBrush (dc, theWinGuiBackgroundBrush ()); |
| 394 |
Rectangle (dc, 0, 0, my width, my height); |
| 395 |
ReleaseDC (my window, dc); |
| 396 |
SetWindowTextW (my window, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get()))); |
| 397 |
} |
| 398 |
|
| 399 |
static int _XmScrollBar_check (GuiObject me) { |
| 400 |
if (my maximum < my minimum) |
| 401 |
Melder_warning (U"XmScrollBar: maximum (", my maximum, U") less than minimum (", my minimum, U")."); |
| 402 |
else if (my sliderSize > my maximum - my minimum) |
| 403 |
Melder_warning (U"XmScrollBar: slider size (", my sliderSize, U") greater than maximum (", |
| 404 |
my maximum, U") minus minimum (", my minimum, U")."); |
| 405 |
else if (my value < my minimum) |
| 406 |
Melder_warning (U"XmScrollBar: value (", my value, U") less than minimum (", my minimum, U")."); |
| 407 |
else if (my value > my maximum - my sliderSize) |
| 408 |
Melder_warning (U"XmScrollBar: value (", my value, U") greater than maximum (", |
| 409 |
my maximum, U") minus slider size (", my sliderSize, U")."); |
| 410 |
else |
| 411 |
return 1; |
| 412 |
return 0; |
| 413 |
} |
| 414 |
|
| 415 |
static void NativeScrollBar_set (GuiObject me) { |
| 416 |
if (! _XmScrollBar_check (me)) |
| 417 |
return; |
| 418 |
SCROLLINFO scrollInfo; |
| 419 |
scrollInfo. cbSize = sizeof (SCROLLINFO); |
| 420 |
scrollInfo. fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_DISABLENOSCROLL; |
| 421 |
if (my maximum == my minimum + my sliderSize) { |
| 422 |
scrollInfo. nMin = 0; |
| 423 |
scrollInfo. nMax = 0; |
| 424 |
scrollInfo. nPage = 1; |
| 425 |
scrollInfo. nPos = 0; |
| 426 |
} else { |
| 427 |
scrollInfo. nMin = 0; |
| 428 |
scrollInfo. nMax = 32767; |
| 429 |
scrollInfo. nPage = (32767.0 * my sliderSize) / (my maximum - my minimum); |
| 430 |
scrollInfo. nPos = ((32767.0 - scrollInfo. nPage) * (my value - my minimum)) / (my maximum - my minimum - my sliderSize); |
| 431 |
} |
| 432 |
if (my window) |
| 433 |
SetScrollInfo (my window, SB_CTL, & scrollInfo, true); |
| 434 |
} |
| 435 |
|
| 436 |
static void NativeMenuItem_delete (GuiObject me) { |
| 437 |
RemoveMenu (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND); |
| 438 |
} |
| 439 |
|
| 440 |
static int NativeMenuItem_getPosition (GuiObject me) { |
| 441 |
int position = 1; |
| 442 |
/* |
| 443 |
* The following routine could also be used for Mac. |
| 444 |
*/ |
| 445 |
GuiObject sibling; |
| 446 |
for (sibling = my parent -> firstChild; sibling; sibling = sibling -> nextSibling) { |
| 447 |
if (sibling == me) |
| 448 |
break; |
| 449 |
if (sibling -> managed && ! MEMBER (sibling, PulldownMenu)) |
| 450 |
position += 1; |
| 451 |
} |
| 452 |
/* |
| 453 |
* Bill Gates counts like 0, 1, 2... |
| 454 |
*/ |
| 455 |
position -= 1; |
| 456 |
return position; |
| 457 |
} |
| 458 |
|
| 459 |
static void NativeMenuItem_check (GuiObject me, Boolean value) { |
| 460 |
if (! my managed) |
| 461 |
return; |
| 462 |
CheckMenuItem (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND | ( value ? MF_CHECKED : MF_UNCHECKED )); |
| 463 |
} |
| 464 |
|
| 465 |
static void NativeMenuItem_setSensitive (GuiObject me) { |
| 466 |
//if (! my managed) |
| 467 |
// return; |
| 468 |
if (my widgetClass == xmPulldownMenuWidgetClass) { |
| 469 |
Melder_assert (MEMBER (my parent, MenuBar)); |
| 470 |
EnableMenuItem (my parent -> nat.menu.handle, my nat.menu.id, MF_BYCOMMAND | ( my insensitive ? MF_GRAYED : MF_ENABLED )); |
| 471 |
} else { |
| 472 |
EnableMenuItem (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND | ( my insensitive ? MF_GRAYED : MF_ENABLED )); |
| 473 |
} |
| 474 |
//DrawMenuBar (my shell -> window); |
| 475 |
} |
| 476 |
|
| 477 |
/********** **********/ |
| 478 |
|
| 479 |
/* |
| 480 |
* We now create the native objects associated with this widget, |
| 481 |
* but do not show them on the screen yet (ideally). |
| 482 |
* A reference must be made from widget to native object and back, |
| 483 |
* with SetWindowLongPtr (window, GWLP_USERDATA, (LONG_PTR) widget). |
| 484 |
*/ |
| 485 |
|
| 486 |
static void _GuiNativizeWidget (GuiObject me) { |
| 487 |
if (my nativized) |
| 488 |
return; |
| 489 |
if (my inMenu) { |
| 490 |
if (MEMBER (me, PulldownMenu)) { |
| 491 |
int id; |
| 492 |
for (id = 1; id <= MAXIMUM_NUMBER_OF_MENUS; id ++) |
| 493 |
if (! theMenus [id]) |
| 494 |
break; |
| 495 |
my nat.menu.id = id; |
| 496 |
theMenus [my nat.menu.id] = me; // instead of UserData fields |
| 497 |
/* |
| 498 |
* This will be a hierarchical menu. |
| 499 |
*/ |
| 500 |
my nat.menu.handle = CreatePopupMenu (); |
| 501 |
} else { |
| 502 |
/* |
| 503 |
* Any menu item (push button, toggle button, or cascade button) shall contain its native parent menu handle. |
| 504 |
*/ |
| 505 |
my nat.entry.handle = my parent -> nat.menu.handle; |
| 506 |
{ |
| 507 |
/* |
| 508 |
* A Windows menu item shall have a shell-unique ID, |
| 509 |
* which we can use to make changes and |
| 510 |
* which will be sent to us by the WM_COMMAND message. |
| 511 |
* This ID should be higher than 4000, in order to be different from the menu IDs. |
| 512 |
* In our implementation, item IDs are application-unique. |
| 513 |
*/ |
| 514 |
int id; |
| 515 |
for (id = MINIMUM_MENU_ITEM_ID; id <= MAXIMUM_MENU_ITEM_ID; id ++) |
| 516 |
if (! theMenuItems [id]) |
| 517 |
break; |
| 518 |
my nat.entry.id = id; // install unique ID |
| 519 |
theMenuItems [id] = true; |
| 520 |
} |
| 521 |
} |
| 522 |
} else switch (my widgetClass) { |
| 523 |
case xmBulletinBoardWidgetClass: { |
| 524 |
my window = CreateWindowEx (0, Melder_peek32toW (theWindowClassName), L"bulletinBoard", WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS, |
| 525 |
my x, my y, my width, my height, my parent -> window, NULL, theGui.instance, NULL); |
| 526 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 527 |
} break; |
| 528 |
case xmDrawingAreaWidgetClass: Melder_crash (U"Should be implemented in GuiDrawingArea."); break; |
| 529 |
case xmFormWidgetClass: { |
| 530 |
my window = CreateWindowEx (0, Melder_peek32toW (theWindowClassName), L"form", WS_CHILD | WS_CLIPSIBLINGS, |
| 531 |
my x, my y, my width, my height, my parent -> window, NULL, theGui.instance, NULL); |
| 532 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 533 |
} break; |
| 534 |
case xmRowColumnWidgetClass: { |
| 535 |
my window = CreateWindowEx (0, Melder_peek32toW (theWindowClassName), L"rowColumn", WS_CHILD | WS_CLIPSIBLINGS, |
| 536 |
my x, my y, my width, my height, my parent -> window, NULL, theGui.instance, NULL); |
| 537 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 538 |
//TRACE |
| 539 |
trace (U"Created window ", Melder_pointer (my window), U" for original RowColumn ", Melder_pointer (me)); |
| 540 |
} break; |
| 541 |
case xmListWidgetClass: Melder_crash (U"Should be implemented in GuiList."); break; |
| 542 |
case xmMenuBarWidgetClass: { |
| 543 |
if (! my shell -> motiff.shell.isDialog && my shell -> nat.shell.menuBar == NULL && my parent -> widgetClass != xmRowColumnWidgetClass) { |
| 544 |
HMENU bar = CreateMenu (); |
| 545 |
SetMenu (my shell -> window, bar); |
| 546 |
my nat.menu.handle = bar; |
| 547 |
my shell -> nat.shell.menuBar = me; // does this have to be? |
| 548 |
} else { |
| 549 |
my widgetClass = xmRowColumnWidgetClass; // !!!!!!!!!!!!! |
| 550 |
my orientation = XmHORIZONTAL; |
| 551 |
my rowColumnType = XmMENU_BAR; |
| 552 |
#if TRY_BARLESS |
| 553 |
my window = my parent -> window; |
| 554 |
#else |
| 555 |
my window = CreateWindowEx (0, Melder_peek32toW (theWindowClassName), L"rowColumn", WS_CHILD, |
| 556 |
my x, my y, my width, my height, my parent -> window, NULL, theGui.instance, NULL); |
| 557 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 558 |
#endif |
| 559 |
//TRACE |
| 560 |
trace (U"Created window ", Melder_pointer (my window), U" for MenuBar-derived RowColumn ", Melder_pointer (me)); |
| 561 |
} |
| 562 |
} break; |
| 563 |
case xmPulldownMenuWidgetClass: { |
| 564 |
int id; |
| 565 |
for (id = 1; id <= MAXIMUM_NUMBER_OF_MENUS; id ++) |
| 566 |
if (! theMenus [id]) |
| 567 |
break; |
| 568 |
my nat.menu.id = id; |
| 569 |
theMenus [my nat.menu.id] = me; // instead of UserData fields |
| 570 |
if (MEMBER (my parent, MenuBar)) { |
| 571 |
GuiObject menu; |
| 572 |
UINT beforeID = -1; |
| 573 |
my nat.menu.handle = CreatePopupMenu (); |
| 574 |
/* |
| 575 |
* Insert the menu before the Help menu, if that exists; otherwise, at the end. |
| 576 |
*/ |
| 577 |
for (menu = my parent -> firstChild; menu; menu = menu -> nextSibling) { |
| 578 |
if (MEMBER (menu, PulldownMenu) && str32equ (menu -> name.get(), U"Help") && menu != me) { |
| 579 |
beforeID = (UINT) menu -> nat.menu./*handle*/id; |
| 580 |
break; |
| 581 |
} |
| 582 |
} |
| 583 |
{ |
| 584 |
MENUITEMINFO info; |
| 585 |
info. cbSize = sizeof (MENUITEMINFO); |
| 586 |
info. fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_ID; |
| 587 |
info. fType = MFT_STRING | ( str32equ (my name.get(), U"Help") ? MFT_RIGHTJUSTIFY : 0 ); |
| 588 |
info. dwTypeData = (mutablestringW) Melder_peek32toW (my name.get()); |
| 589 |
info. hSubMenu = my nat.menu.handle; |
| 590 |
info. wID = (UINT) my nat.menu./*handle*/id; |
| 591 |
InsertMenuItem (my parent -> nat.menu.handle, beforeID, 0, & info); |
| 592 |
} /*else if (beforeID >= 0) |
| 593 |
InsertMenu (my parent -> nat.menu.handle, beforeID, MF_STRING | MF_POPUP | MF_BYCOMMAND, |
| 594 |
(UINT) my nat.menu.handle, my name); |
| 595 |
else |
| 596 |
AppendMenu (my parent -> nat.menu.handle, MF_STRING | MF_POPUP, (UINT) my nat.menu.handle, my name);*/ |
| 597 |
DrawMenuBar (my shell -> window); |
| 598 |
} else if (MEMBER (my parent, RowColumn) && my parent -> rowColumnType == XmMENU_BAR) { |
| 599 |
my nat.menu.handle = CreatePopupMenu (); |
| 600 |
} |
| 601 |
} break; |
| 602 |
case xmLabelWidgetClass: Melder_crash (U"Should be implemented in GuiLabel."); break; |
| 603 |
case xmCascadeButtonWidgetClass: { |
| 604 |
if (my motiff.cascadeButton.inBar) { |
| 605 |
my nat.entry.handle = my parent -> nat.menu.handle; // TODO: superfluous? |
| 606 |
} else { |
| 607 |
my window = CreateWindow (L"button", Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())), |
| 608 |
WS_CHILD | BS_PUSHBUTTON | WS_CLIPSIBLINGS, |
| 609 |
my x, my y, my width, my height, my parent -> window, (HMENU) 1, theGui.instance, NULL); |
| 610 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 611 |
SetWindowFont (my window, theWinGuiNormalLabelFont (), false); |
| 612 |
} |
| 613 |
} break; |
| 614 |
case xmPushButtonWidgetClass: Melder_crash (U"Should be implemented in GuiButton."); break; |
| 615 |
case xmTextWidgetClass: Melder_crash (U"Should be implemented in GuiText."); break; |
| 616 |
case xmToggleButtonWidgetClass: Melder_crash (U"Should be implemented in GuiCheckButton and GuiRadioButton."); break; |
| 617 |
case xmScaleWidgetClass: { |
| 618 |
my window = CreateWindow (PROGRESS_CLASS, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())), WS_CHILD | WS_CLIPSIBLINGS, |
| 619 |
my x, my y, my width, my height, my parent -> window, (HMENU) 1, theGui.instance, NULL); |
| 620 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 621 |
SendMessage (my window, PBM_SETRANGE, (WPARAM) 0, (LPARAM) MAKELONG (0, 10000)); |
| 622 |
} break; |
| 623 |
case xmScrollBarWidgetClass: { |
| 624 |
my window = CreateWindow (L"scrollbar", Melder_peek32toW (my name.get()), WS_CHILD | |
| 625 |
( str32equ (my name.get(), U"verticalScrollBar") ? SBS_VERT : SBS_HORZ ) | WS_CLIPSIBLINGS, |
| 626 |
my x, my y, my width, my height, my parent -> window, (HMENU) 1, theGui.instance, NULL); |
| 627 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 628 |
NativeScrollBar_set (me); |
| 629 |
my minimum = 0; |
| 630 |
my maximum = 100; |
| 631 |
my value = 0; |
| 632 |
my sliderSize = 100; |
| 633 |
} break; |
| 634 |
case xmScrolledWindowWidgetClass: { |
| 635 |
/* |
| 636 |
* The space of the scrolled window is completely filled by three of its children: |
| 637 |
* the two scroll bars and the clip window. The first child you create yourself will be the |
| 638 |
* work window: this work window can grow larger than the clip window. |
| 639 |
* While normally every widget is only clipped to the rects of its ancestors, |
| 640 |
* for a scrolled window the clip window will be inserted into this chain. |
| 641 |
* Example: if the widget hierarchy is |
| 642 |
* shell.form.scrolledWindow.column.row.pushButton, |
| 643 |
* the clipping hierarchy will be |
| 644 |
* (shell.)form.(scrolledWindow.)clipWindow.column.row.pushButton |
| 645 |
*/ |
| 646 |
my window = CreateWindowEx (0, Melder_peek32toW (theWindowClassName), L"scrolledWindow", WS_CHILD | WS_CLIPSIBLINGS, |
| 647 |
my x, my y, my width, my height, my parent -> window, NULL, theGui.instance, NULL); |
| 648 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 649 |
my motiff.scrolledWindow.horizontalBar = XmCreateScrollBar (me, "horizontalScrollBar", NULL, 0); |
| 650 |
my motiff.scrolledWindow.verticalBar = XmCreateScrollBar (me, "verticalScrollBar", NULL, 0); |
| 651 |
XtVaSetValues (my motiff.scrolledWindow.horizontalBar, XmNorientation, XmHORIZONTAL, |
| 652 |
XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, |
| 653 |
XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 15, XmNheight, 16, |
| 654 |
XmNminimum, 0, XmNmaximum, 100, XmNsliderSize, 100, |
| 655 |
XmNincrement, CELL_HEIGHT, XmNpageIncrement, 101 - CELL_HEIGHT, NULL); |
| 656 |
XtVaSetValues (my motiff.scrolledWindow.verticalBar, XmNorientation, XmVERTICAL, |
| 657 |
XmNtopAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, |
| 658 |
XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 15, XmNwidth, 16, |
| 659 |
XmNminimum, 0, XmNmaximum, 100, XmNsliderSize, 100, |
| 660 |
XmNincrement, CELL_HEIGHT, XmNpageIncrement, 101 - CELL_HEIGHT, NULL); |
| 661 |
my motiff.scrolledWindow.clipWindow = XmCreateBulletinBoard (me, "clipWindow", NULL, 0); |
| 662 |
XtVaSetValues (my motiff.scrolledWindow.clipWindow, |
| 663 |
XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 1, // for border |
| 664 |
XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 16, // for scroll bar |
| 665 |
XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 1, // for border |
| 666 |
XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 16, NULL); // for scroll bar |
| 667 |
XtAddCallback (my motiff.scrolledWindow.verticalBar, XmNvalueChangedCallback, cb_scroll, (XtPointer) me); |
| 668 |
XtAddCallback (my motiff.scrolledWindow.verticalBar, XmNdragCallback, cb_scroll, (XtPointer) me); |
| 669 |
XtAddCallback (my motiff.scrolledWindow.horizontalBar, XmNvalueChangedCallback, cb_scroll, (XtPointer) me); |
| 670 |
XtAddCallback (my motiff.scrolledWindow.horizontalBar, XmNdragCallback, cb_scroll, (XtPointer) me); |
| 671 |
} break; |
| 672 |
case xmShellWidgetClass: { |
| 673 |
static char32 *className { theApplicationClassName }; // only for first window |
| 674 |
my window = CreateWindowEx (theDialogHint ? WS_EX_DLGMODALFRAME /* | WS_EX_TOPMOST */ : 0, |
| 675 |
Melder_peek32toW (className), Melder_peek32toW (className), |
| 676 |
theDialogHint ? WS_CAPTION | WS_SYSMENU : WS_OVERLAPPEDWINDOW, |
| 677 |
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, my parent ? my parent -> window : NULL, NULL, theGui.instance, NULL); |
| 678 |
className = theWindowClassName; // all later windows |
| 679 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 680 |
my motiff.shell.isDialog = theDialogHint; // so we can maintain a single Shell class instead of two different |
| 681 |
} break; |
| 682 |
default: break; |
| 683 |
} |
| 684 |
my nativized = True; |
| 685 |
} |
| 686 |
|
| 687 |
static GuiObject createWidget (int widgetClass, GuiObject parent, const char *name) { |
| 688 |
GuiObject me = _Gui_initializeWidget (widgetClass, parent, Melder_peek8to32_u (name)); |
| 689 |
_GuiNativizeWidget (me); |
| 690 |
//TRACE |
| 691 |
trace (U"Created widget ", Melder_pointer (me)); |
| 692 |
return me; |
| 693 |
} |
| 694 |
|
| 695 |
void _Gui_invalidateWidget (GuiObject me) { |
| 696 |
if (! my managed) // should be: visible |
| 697 |
return; |
| 698 |
if (MEMBER (me, Shell) /*|| |
| 699 |
my widgetClass == xmRowColumnWidgetClass || |
| 700 |
my widgetClass == xmFormWidgetClass*/) return; // composites are not invalidated !!!!! ???? |
| 701 |
} |
| 702 |
|
| 703 |
void _Gui_validateWidget (GuiObject me) { |
| 704 |
if (! my managed) // should be: visible |
| 705 |
return; |
| 706 |
if (MEMBER (me, Shell)) |
| 707 |
return; |
| 708 |
} |
| 709 |
|
| 710 |
static void Native_move (GuiObject me, int dx, int dy) { |
| 711 |
/* Native_move () changes the native attributes and visual position of the widget: |
| 712 |
* No Motif attributes (such as 'x' and 'y') are changed. |
| 713 |
* Usage: |
| 714 |
* Native_move () is normally called immediately after changing the 'x' or 'y' attribute. |
| 715 |
* It can be seen as the 'realization' of a Motif move. |
| 716 |
*/ |
| 717 |
(void) dx; |
| 718 |
(void) dy; |
| 719 |
if (! my window) |
| 720 |
return; // ignore menu items |
| 721 |
if (MEMBER (me, Shell)) { |
| 722 |
my nat.shell.duringMoveWindow = True; |
| 723 |
if (my motiff.shell.isDialog) { |
| 724 |
#ifndef __clang__ |
| 725 |
/* |
| 726 |
In a Windows app, both following system frame measurements should be 8: |
| 727 |
*/ |
| 728 |
const int cxFixedFrame = GetSystemMetrics (SM_CXFIXEDFRAME); |
| 729 |
const int cyFixedFrame = GetSystemMetrics (SM_CYFIXEDFRAME); |
| 730 |
#else |
| 731 |
/* |
| 732 |
However, CLANG under MSYS2 thinks it's in a console app, |
| 733 |
so that these two values are 4 instead of 8, |
| 734 |
which causes text fields and caption to run off the right edge of the window. |
| 735 |
Repair. |
| 736 |
*/ |
| 737 |
const int cxFixedFrame = 8; |
| 738 |
const int cyFixedFrame = 8; |
| 739 |
#endif |
| 740 |
MoveWindow (my window, my x, my y, |
| 741 |
my width + 2 * cxFixedFrame, |
| 742 |
my height + 2 * cyFixedFrame + GetSystemMetrics (SM_CYCAPTION), |
| 743 |
true |
| 744 |
); |
| 745 |
} else { |
| 746 |
#ifndef __clang__ |
| 747 |
/* |
| 748 |
In a Windows app, both following system frame measurements should be 8: |
| 749 |
*/ |
| 750 |
const int cxSizeFrame = GetSystemMetrics (SM_CXSIZEFRAME); |
| 751 |
const int cySizeFrame = GetSystemMetrics (SM_CYSIZEFRAME); |
| 752 |
#else |
| 753 |
/* |
| 754 |
However, CLANG under MSYS2 thinks it's in a console app, |
| 755 |
so that these two values are 4 instead of 8, |
| 756 |
which causes the scroll bars to be cut off. |
| 757 |
Repair. |
| 758 |
*/ |
| 759 |
const int cxSizeFrame = 8; |
| 760 |
const int cySizeFrame = 8; |
| 761 |
#endif |
| 762 |
MoveWindow (my window, my x, my y, |
| 763 |
my width + 2 * cxSizeFrame, |
| 764 |
my height + 2 * cySizeFrame + GetSystemMetrics (SM_CYCAPTION) + |
| 765 |
( my nat.shell.menuBar ? GetSystemMetrics (SM_CYMENU) : 0 ), |
| 766 |
true |
| 767 |
); |
| 768 |
} |
| 769 |
} else |
| 770 |
MoveWindow (my window, my x, my y, my width, my height, True); |
| 771 |
} |
| 772 |
|
| 773 |
static void shellResizeWidget (GuiObject me, int dx, int dy, int dw, int dh) { |
| 774 |
GuiObject child; |
| 775 |
Melder_assert (! my shell || ! my shell -> nat.shell.duringMoveWindow); |
| 776 |
if (my window && ! MEMBER (me, Shell)) { |
| 777 |
/*RECT rect, client; |
| 778 |
GetWindowRect (my window, & rect); |
| 779 |
GetClientRect (my window, & client); |
| 780 |
ScreenToClient (my parent -> window, (LPPOINT) & rect.left); |
| 781 |
ScreenToClient (my parent -> window, (LPPOINT) & rect.right); |
| 782 |
if (rect.left!=my x||rect.right!=my x + my width||rect.top !=my y||rect.bottom!=my y +my height) |
| 783 |
Melder_warning ("class %d x %d left %d y %d top %d width %d right %d height %d bottom %d", |
| 784 |
my widgetClass, my x, rect.left, my y, rect.top, my width, rect.right, my height, rect.bottom);*/ |
| 785 |
MoveWindow (my window, my x, my y, my width, my height, true); |
| 786 |
if (MEMBER (me, DrawingArea)) |
| 787 |
_GuiWinDrawingArea_shellResize (me); |
| 788 |
} |
| 789 |
for (child = my firstChild; child; child = child -> nextSibling) { |
| 790 |
int cdx = 0, cdy = 0, cdw = 0, cdh = 0; |
| 791 |
if (MEMBER (child, Shell)) |
| 792 |
continue; |
| 793 |
if (child -> rightAttachment == XmATTACH_FORM) { |
| 794 |
if (child -> leftAttachment == XmATTACH_FORM) |
| 795 |
cdw = dw; |
| 796 |
else |
| 797 |
cdx = dw; |
| 798 |
} |
| 799 |
if (child -> leftAttachment == XmATTACH_POSITION && child -> rightAttachment == XmATTACH_POSITION) { |
| 800 |
int xLeft = my width * (child -> leftPosition / 100.0); |
| 801 |
int xRight = my width * (child -> rightPosition / 100.0); |
| 802 |
cdx = xLeft - child -> x; |
| 803 |
cdw = (xRight - xLeft) - child -> width; |
| 804 |
} |
| 805 |
if (child -> bottomAttachment == XmATTACH_FORM) { |
| 806 |
if (child -> topAttachment == XmATTACH_FORM) |
| 807 |
cdh = dh; |
| 808 |
else |
| 809 |
cdy = dh; |
| 810 |
} |
| 811 |
if (child -> topAttachment == XmATTACH_POSITION && child -> bottomAttachment == XmATTACH_POSITION) { |
| 812 |
int yTop = my height * (child -> topPosition / 100.0); |
| 813 |
int yBottom = my height * (child -> bottomPosition / 100.0); |
| 814 |
cdy = yTop - child -> y; |
| 815 |
cdh = (yBottom - yTop) - child -> height; |
| 816 |
} |
| 817 |
child -> x += cdx; |
| 818 |
child -> y += cdy; |
| 819 |
child -> width += cdw; |
| 820 |
child -> height += cdh; |
| 821 |
shellResizeWidget (child, dx + cdx, dy + cdy, cdw, cdh); |
| 822 |
} |
| 823 |
if (MEMBER (me, ScrolledWindow)) |
| 824 |
_Gui_manageScrolledWindow (me); |
| 825 |
} |
| 826 |
|
| 827 |
static void resizeWidget (GuiObject me, int dw, int dh) { |
| 828 |
GuiObject child; |
| 829 |
if (my window && ! MEMBER (me, Shell)) { |
| 830 |
MoveWindow (my window, my x, my y, my width, my height, true); |
| 831 |
if (MEMBER (me, DrawingArea)) |
| 832 |
_GuiWinDrawingArea_shellResize (me); |
| 833 |
} |
| 834 |
if (MEMBER2 (me, Form, ScrolledWindow)) |
| 835 |
for (child = my firstChild; child; child = child -> nextSibling) { |
| 836 |
int cdx = 0, cdy = 0, cdw = 0, cdh = 0; |
| 837 |
if (child -> widgetClass == xmShellWidgetClass) continue; |
| 838 |
if (child -> rightAttachment == XmATTACH_FORM) { |
| 839 |
if (child -> leftAttachment == XmATTACH_FORM) |
| 840 |
cdw = dw; |
| 841 |
else |
| 842 |
cdx = dw; |
| 843 |
} |
| 844 |
if (child -> leftAttachment == XmATTACH_POSITION && child -> rightAttachment == XmATTACH_POSITION) { |
| 845 |
int xLeft = my width * (child -> leftPosition / 100.0); |
| 846 |
int xRight = my width * (child -> rightPosition / 100.0); |
| 847 |
cdx = xLeft - child -> x; |
| 848 |
cdw = (xRight - xLeft) - child -> width; |
| 849 |
} |
| 850 |
if (child -> bottomAttachment == XmATTACH_FORM) { |
| 851 |
if (child -> topAttachment == XmATTACH_FORM) |
| 852 |
cdh = dh; |
| 853 |
else |
| 854 |
cdy = dh; |
| 855 |
} |
| 856 |
if (child -> topAttachment == XmATTACH_POSITION && child -> bottomAttachment == XmATTACH_POSITION) { |
| 857 |
int yTop = my height * (child -> topPosition / 100.0); |
| 858 |
int yBottom = my height * (child -> bottomPosition / 100.0); |
| 859 |
cdy = yTop - child -> y; |
| 860 |
cdh = (yBottom - yTop) - child -> height; |
| 861 |
} |
| 862 |
if (cdx || cdy) { |
| 863 |
child -> x += cdx; |
| 864 |
child -> y += cdy; |
| 865 |
Native_move (child, cdx, cdy); |
| 866 |
} |
| 867 |
if (cdw || cdh) { |
| 868 |
child -> width += cdw; |
| 869 |
child -> height += cdh; |
| 870 |
resizeWidget (child, cdw, cdh); |
| 871 |
} |
| 872 |
} |
| 873 |
if (MEMBER (me, Shell)) { |
| 874 |
int right = 1000, bottom = 500; |
| 875 |
for (child = my firstChild; child; child = child -> nextSibling) |
| 876 |
if (MEMBER2 (child, Form, ScrolledWindow)) { |
| 877 |
child -> width += dw; |
| 878 |
child -> height += dh; |
| 879 |
resizeWidget (child, dw, dh); |
| 880 |
} |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
static void _motif_setValues (GuiObject me, va_list arg) { |
| 885 |
int resource; |
| 886 |
Boolean move = False, resize = False, attach = False, scrollset = False; |
| 887 |
char *text; |
| 888 |
int oldX = my x, oldY = my y, oldWidth = my width, oldHeight = my height; |
| 889 |
while (resource = va_arg (arg, int), resource != 0) switch (resource) { |
| 890 |
case XmNautoUnmanage: |
| 891 |
my autoUnmanage = va_arg (arg, int); |
| 892 |
break; |
| 893 |
case XmNbottomAttachment: |
| 894 |
my bottomAttachment = va_arg (arg, int); |
| 895 |
attach = True; |
| 896 |
break; |
| 897 |
case XmNbottomOffset: |
| 898 |
my bottomOffset = va_arg (arg, int); |
| 899 |
attach = True; |
| 900 |
break; |
| 901 |
case XmNbottomPosition: |
| 902 |
my bottomPosition = va_arg (arg, int); |
| 903 |
attach = True; |
| 904 |
break; |
| 905 |
case XmNcolumns: { |
| 906 |
int columns = va_arg (arg, int); |
| 907 |
Melder_assert (MEMBER (me, Text)); |
| 908 |
my width = columns * 9 + 4; |
| 909 |
resize = True; |
| 910 |
} break; |
| 911 |
case XmNdeleteResponse: |
| 912 |
Melder_assert (MEMBER (me, Shell)); |
| 913 |
my deleteResponse = va_arg (arg, int); |
| 914 |
if (my deleteResponse == XmDO_NOTHING && ! my motiff.shell.goAwayCallback) { |
| 915 |
// change window attributes |
| 916 |
} |
| 917 |
break; |
| 918 |
case XmNdialogStyle: |
| 919 |
Melder_assert (MEMBER2 (me, Form, BulletinBoard)); |
| 920 |
my shell -> dialogStyle = my dialogStyle = va_arg (arg, int); |
| 921 |
break; |
| 922 |
case XmNdialogTitle: |
| 923 |
Melder_assert (MEMBER2 (me, Form, BulletinBoard)); |
| 924 |
text = va_arg (arg, char *); |
| 925 |
SetWindowTextW (my shell -> window, Melder_peek32toW (Melder_peek8to32_u (text))); |
| 926 |
break; |
| 927 |
case XmNheight: |
| 928 |
my height = va_arg (arg, int); |
| 929 |
if (MEMBER (me, Shell)) { |
| 930 |
int maximumHeight = |
| 931 |
GetSystemMetrics (SM_CYMAXIMIZED) - GetSystemMetrics (SM_CYCAPTION) - |
| 932 |
GetSystemMetrics (SM_CYSIZEFRAME) - GetSystemMetrics (SM_CYMENU) - 15; |
| 933 |
if (my height > maximumHeight) |
| 934 |
my height = maximumHeight; |
| 935 |
} |
| 936 |
resize = True; |
| 937 |
break; |
| 938 |
case XmNhorizontalScrollBar: { |
| 939 |
/* Have to kill my own bar first. */ |
| 940 |
XtDestroyWidget (my motiff.scrolledWindow.horizontalBar); |
| 941 |
/* Then replace by new bar. */ |
| 942 |
my motiff.scrolledWindow.horizontalBar = va_arg (arg, GuiObject); |
| 943 |
/* Make sure it is in the right position. */ |
| 944 |
XtVaSetValues (my motiff.scrolledWindow.horizontalBar, XmNorientation, XmHORIZONTAL, |
| 945 |
XmNleftAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, |
| 946 |
XmNrightAttachment, XmATTACH_FORM, XmNrightOffset, 15, XmNheight, 16, NULL); |
| 947 |
/* |
| 948 |
* Note that we may now have a horizontal bar with application-defined scrolling policy, |
| 949 |
* and a vertical bar with automatic scrolling policy. |
| 950 |
* This is more flexible than X Motif, but may be simulated in X Motif with the following strategy, |
| 951 |
* which is compatible with MotifEmulator: |
| 952 |
* - set the scrolling policy to XmAUTOMATIC: two scroll bars will be created; |
| 953 |
* - ask for the horizontal scroll bar with XtVaGetValues; |
| 954 |
* - remove all the callbacks from the horizontal scroll bar with XtRemoveAllCallbacks; |
| 955 |
* - add your application-defined callback with XtAddCallback. |
| 956 |
* We just hope now that X Motif does not look into the XmNscrollingPolicy resource after this... |
| 957 |
*/ |
| 958 |
} break; |
| 959 |
case XmNincrement: |
| 960 |
Melder_assert (MEMBER (me, ScrollBar)); |
| 961 |
my increment = va_arg (arg, int); |
| 962 |
break; |
| 963 |
case XmNlabelString: |
| 964 |
Melder_assert (MEMBER2 (me, CascadeButton, PushButton)); |
| 965 |
text = va_arg (arg, char *); |
| 966 |
my name = Melder_8to32_e (text); // BUG throwable |
| 967 |
if (my inMenu) { |
| 968 |
_GuiWinMenuItem_setText (me); |
| 969 |
} else if (MEMBER (me, CascadeButton) && my motiff.cascadeButton.inBar) { |
| 970 |
/* BUG: menu title change not implemented */ |
| 971 |
} else { |
| 972 |
_GuiNativeControl_setTitle (me); |
| 973 |
} |
| 974 |
break; |
| 975 |
case XmNleftAttachment: |
| 976 |
my leftAttachment = va_arg (arg, int); |
| 977 |
attach = True; |
| 978 |
break; |
| 979 |
case XmNleftOffset: |
| 980 |
my leftOffset = va_arg (arg, int); |
| 981 |
attach = True; |
| 982 |
break; |
| 983 |
case XmNleftPosition: |
| 984 |
my leftPosition = va_arg (arg, int); |
| 985 |
attach = True; |
| 986 |
break; |
| 987 |
case XmNmaximum: |
| 988 |
my maximum = va_arg (arg, int); |
| 989 |
if (MEMBER (me, ScrollBar)) |
| 990 |
scrollset = True; |
| 991 |
else if (MEMBER (me, Scale)) |
| 992 |
_Gui_invalidateWidget (me); |
| 993 |
break; |
| 994 |
case XmNmenuHelpWidget: |
| 995 |
(void) va_arg (arg, GuiObject); |
| 996 |
break; |
| 997 |
case XmNminimum: |
| 998 |
my minimum = va_arg (arg, int); |
| 999 |
if (MEMBER (me, ScrollBar)) |
| 1000 |
scrollset = True; |
| 1001 |
else if (MEMBER (me, Scale)) |
| 1002 |
_Gui_invalidateWidget (me); |
| 1003 |
break; |
| 1004 |
case XmNorientation: |
| 1005 |
Melder_assert (MEMBER3 (me, RowColumn, ScrollBar, Scale)); |
| 1006 |
my orientation = va_arg (arg, int); |
| 1007 |
break; |
| 1008 |
case XmNpageIncrement: |
| 1009 |
Melder_assert (MEMBER (me, ScrollBar)); |
| 1010 |
my pageIncrement = va_arg (arg, int); |
| 1011 |
break; |
| 1012 |
case XmNradioBehavior: |
| 1013 |
Melder_assert (MEMBER (me, RowColumn)); |
| 1014 |
my radioBehavior = va_arg (arg, int); |
| 1015 |
break; |
| 1016 |
case XmNrightAttachment: |
| 1017 |
my rightAttachment = va_arg (arg, int); |
| 1018 |
attach = True; |
| 1019 |
break; |
| 1020 |
case XmNrightOffset: |
| 1021 |
my rightOffset = va_arg (arg, int); |
| 1022 |
attach = True; |
| 1023 |
break; |
| 1024 |
case XmNrightPosition: |
| 1025 |
my rightPosition = va_arg (arg, int); |
| 1026 |
attach = True; |
| 1027 |
break; |
| 1028 |
case XmNrowColumnType: |
| 1029 |
Melder_assert (MEMBER (me, RowColumn)); |
| 1030 |
my rowColumnType = va_arg (arg, int); |
| 1031 |
break; |
| 1032 |
case XmNrows: |
| 1033 |
(void) va_arg (arg, int); |
| 1034 |
break; |
| 1035 |
case XmNscaleHeight: |
| 1036 |
Melder_assert (MEMBER (me, Scale)); |
| 1037 |
my height = va_arg (arg, int); |
| 1038 |
resize = True; |
| 1039 |
break; |
| 1040 |
case XmNscaleWidth: |
| 1041 |
Melder_assert (MEMBER (me, Scale)); |
| 1042 |
my width = va_arg (arg, int); |
| 1043 |
resize = True; |
| 1044 |
break; |
| 1045 |
case XmNscrollingPolicy: |
| 1046 |
(void) va_arg (arg, int); |
| 1047 |
break; |
| 1048 |
case XmNsliderSize: |
| 1049 |
Melder_assert (MEMBER (me, ScrollBar)); |
| 1050 |
my sliderSize = va_arg (arg, int); |
| 1051 |
scrollset = True; |
| 1052 |
break; |
| 1053 |
case XmNspacing: |
| 1054 |
(void) va_arg (arg, int); |
| 1055 |
break; |
| 1056 |
case XmNsubMenuId: |
| 1057 |
Melder_assert (MEMBER (me, CascadeButton)); |
| 1058 |
my subMenuId = va_arg (arg, GuiObject); |
| 1059 |
my subMenuId -> popUpButton = me; |
| 1060 |
break; |
| 1061 |
case XmNtitle: |
| 1062 |
Melder_assert (MEMBER (me, Shell)); |
| 1063 |
text = va_arg (arg, char *); |
| 1064 |
SetWindowTextW (my window, Melder_peek32toW (Melder_peek8to32_u (text))); |
| 1065 |
break; |
| 1066 |
case XmNtitleString: |
| 1067 |
Melder_assert (MEMBER (me, Scale)); |
| 1068 |
text = va_arg (arg, char *); |
| 1069 |
my name = Melder_8to32_e (text); // BUG throwable |
| 1070 |
_Gui_invalidateWidget (me); |
| 1071 |
break; |
| 1072 |
case XmNtopAttachment: |
| 1073 |
my topAttachment = va_arg (arg, int); |
| 1074 |
attach = True; |
| 1075 |
break; |
| 1076 |
case XmNtopOffset: |
| 1077 |
my topOffset = va_arg (arg, int); |
| 1078 |
attach = True; |
| 1079 |
break; |
| 1080 |
case XmNtopPosition: |
| 1081 |
my topPosition = va_arg (arg, int); |
| 1082 |
attach = True; |
| 1083 |
break; |
| 1084 |
case XmNuserData: |
| 1085 |
my userData = va_arg (arg, void *); |
| 1086 |
break; |
| 1087 |
case XmNvalue: |
| 1088 |
my value = va_arg (arg, int); |
| 1089 |
if (MEMBER (me, ScrollBar)) |
| 1090 |
scrollset = True; |
| 1091 |
else if (MEMBER (me, Scale)) |
| 1092 |
SendMessage (my window, PBM_SETPOS, (WPARAM) my value, 0); |
| 1093 |
break; |
| 1094 |
case XmNverticalScrollBar: { |
| 1095 |
/* Have to kill my own bar first. */ |
| 1096 |
XtDestroyWidget (my motiff.scrolledWindow.verticalBar); |
| 1097 |
/* Then replace by new bar. */ |
| 1098 |
my motiff.scrolledWindow.verticalBar = va_arg (arg, GuiObject); |
| 1099 |
/* Make sure it is in the right position. */ |
| 1100 |
XtVaSetValues (my motiff.scrolledWindow.verticalBar, XmNorientation, XmVERTICAL, |
| 1101 |
XmNtopAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, |
| 1102 |
XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 15, XmNwidth, 16, NULL); |
| 1103 |
} break; |
| 1104 |
case XmNwidth: |
| 1105 |
my width = va_arg (arg, int); |
| 1106 |
resize = True; |
| 1107 |
break; |
| 1108 |
case XmNx: |
| 1109 |
my x = va_arg (arg, int); |
| 1110 |
move = True; |
| 1111 |
break; |
| 1112 |
case XmNy: |
| 1113 |
my y = va_arg (arg, int); |
| 1114 |
move = True; |
| 1115 |
break; |
| 1116 |
default: { |
| 1117 |
if (resource < 0 || resource >= sizeof motif_resourceNames / sizeof (char *)) |
| 1118 |
Melder_flushError (U"(XtVaSetValues:) Resource out of range (", resource, U")."); |
| 1119 |
else |
| 1120 |
Melder_flushError (U"(XtVaSetValues:) Unknown resource \"", Melder_peek8to32_u (motif_resourceNames [resource]), U"\"."); |
| 1121 |
return; // because we do not know how to skip this unknown resource |
| 1122 |
} |
| 1123 |
} |
| 1124 |
|
| 1125 |
if (attach) { |
| 1126 |
Melder_assert (MEMBER2 (my parent, Form, ScrolledWindow)); |
| 1127 |
if (my leftAttachment == XmATTACH_FORM) { |
| 1128 |
my x = my leftOffset; |
| 1129 |
move = True; |
| 1130 |
if (my rightAttachment == XmATTACH_FORM) { |
| 1131 |
my width = my parent -> width - my leftOffset - my rightOffset; |
| 1132 |
resize = True; |
| 1133 |
} |
| 1134 |
} else if (my rightAttachment == XmATTACH_FORM) { |
| 1135 |
my x = my parent -> width - my width - my rightOffset; |
| 1136 |
move = True; |
| 1137 |
} |
| 1138 |
if (my leftAttachment == XmATTACH_POSITION && my rightAttachment == XmATTACH_POSITION) { |
| 1139 |
my x = my parent -> width * (my leftPosition / 100.0); |
| 1140 |
int xRight = my parent -> width * (my rightPosition / 100.0); |
| 1141 |
my width = xRight - my x; |
| 1142 |
resize = True; |
| 1143 |
} |
| 1144 |
if (my topAttachment == XmATTACH_FORM) { |
| 1145 |
my y = my topOffset; |
| 1146 |
move = True; |
| 1147 |
if (my bottomAttachment == XmATTACH_FORM) { |
| 1148 |
my height = my parent -> height - my topOffset - my bottomOffset; |
| 1149 |
resize = True; |
| 1150 |
} |
| 1151 |
} else if (my bottomAttachment == XmATTACH_FORM) { |
| 1152 |
my y = my parent -> height - my height - my bottomOffset; |
| 1153 |
move = True; |
| 1154 |
} |
| 1155 |
if (my topAttachment == XmATTACH_POSITION && my bottomAttachment == XmATTACH_POSITION) { |
| 1156 |
my y = my parent -> height * (my topPosition / 100.0); |
| 1157 |
int yBottom = my parent -> height * (my bottomPosition / 100.0); |
| 1158 |
my height = yBottom - my y; |
| 1159 |
resize = True; |
| 1160 |
} |
| 1161 |
} |
| 1162 |
if (move) |
| 1163 |
Native_move (me, 0, 0); |
| 1164 |
if (resize) |
| 1165 |
resizeWidget (me, my width - oldWidth, my height - oldHeight); |
| 1166 |
if (scrollset) |
| 1167 |
NativeScrollBar_set (me); |
| 1168 |
} |
| 1169 |
|
| 1170 |
void _Gui_manageScrolledWindow (GuiObject me) { |
| 1171 |
int workWidth, workHeight, horzAutomatic, vertAutomatic; |
| 1172 |
GuiObject clipWindow, workWindow, horzBar = my motiff.scrolledWindow.horizontalBar, vertBar = my motiff.scrolledWindow.verticalBar; |
| 1173 |
Melder_assert (my widgetClass == xmScrolledWindowWidgetClass); |
| 1174 |
clipWindow = my motiff.scrolledWindow.clipWindow; |
| 1175 |
workWindow = my motiff.scrolledWindow.workWindow; |
| 1176 |
if (clipWindow == NULL || horzBar == NULL || vertBar == NULL) |
| 1177 |
return; // apparently during destruction of scrolled window |
| 1178 |
/* |
| 1179 |
* We must find out if the scrolling policy of each bar is automatic. |
| 1180 |
* Otherwise, we must not change them automatically. |
| 1181 |
*/ |
| 1182 |
horzAutomatic = horzBar -> motiff.scrollBar.valueChangedCallbacks.pairs [0].proc == cb_scroll; |
| 1183 |
vertAutomatic = vertBar -> motiff.scrollBar.valueChangedCallbacks.pairs [0].proc == cb_scroll; |
| 1184 |
/* |
| 1185 |
* If the work window has been unmanaged or destroyed, the automatic scroll bars should be empty and insensitive. |
| 1186 |
*/ |
| 1187 |
if (workWindow == NULL || ! workWindow -> managed) { |
| 1188 |
if (horzAutomatic) |
| 1189 |
XtVaSetValues (horzBar, XmNmaximum, 100, XmNsliderSize, 100, XmNvalue, 0, XmNpageIncrement, 1, NULL); |
| 1190 |
if (vertAutomatic) |
| 1191 |
XtVaSetValues (vertBar, XmNmaximum, 100, XmNsliderSize, 100, XmNvalue, 0, XmNpageIncrement, 1, NULL); |
| 1192 |
return; |
| 1193 |
} |
| 1194 |
workWidth = workWindow -> width > 10 ? workWindow -> width : 10; |
| 1195 |
workHeight = workWindow -> height > 10 ? workWindow -> height : 10; |
| 1196 |
/* |
| 1197 |
* If the scroll bar is automatic, the slider width is set to the visible height of the work window, |
| 1198 |
* and the maximum is set to the entire height of the work window. |
| 1199 |
* If the value becomes greater than the maximum minus the slider size, |
| 1200 |
* the value is reduced and the work window is scrolled up (i.e. moved down). |
| 1201 |
*/ |
| 1202 |
if (horzAutomatic) { |
| 1203 |
int maximum = workWidth; |
| 1204 |
int sliderSize = workWidth < clipWindow -> width ? workWidth : clipWindow -> width; |
| 1205 |
int value = horzBar -> value; |
| 1206 |
if (value > maximum - sliderSize) { |
| 1207 |
value = maximum - sliderSize; |
| 1208 |
workWindow -> x += horzBar -> value - value; |
| 1209 |
Native_move (workWindow, horzBar -> value - value, 0); |
| 1210 |
} |
| 1211 |
XtVaSetValues (horzBar, XmNmaximum, maximum, XmNsliderSize, sliderSize, XmNvalue, value, |
| 1212 |
XmNpageIncrement, clipWindow -> width - (CELL_HEIGHT - 1), NULL); |
| 1213 |
} |
| 1214 |
if (vertAutomatic) { /* Automatic? */ |
| 1215 |
int maximum = workHeight; |
| 1216 |
int sliderSize = workHeight < clipWindow -> height ? workHeight : clipWindow -> height; |
| 1217 |
int value = vertBar -> value; |
| 1218 |
if (value > maximum - sliderSize) { |
| 1219 |
value = maximum - sliderSize; |
| 1220 |
workWindow -> y += vertBar -> value - value; |
| 1221 |
Native_move (workWindow, 0, vertBar -> value - value); |
| 1222 |
} |
| 1223 |
XtVaSetValues (vertBar, XmNmaximum, maximum, XmNsliderSize, sliderSize, XmNvalue, value, |
| 1224 |
XmNpageIncrement, clipWindow -> height - (CELL_HEIGHT - 1), NULL); |
| 1225 |
} |
| 1226 |
} |
| 1227 |
|
| 1228 |
static void _motif_manage (GuiObject me) { |
| 1229 |
GuiObject child; |
| 1230 |
int x = 2, y = 2; |
| 1231 |
int width = 0, height = 0, dw = 0, dh = 0; |
| 1232 |
/*if (my widgetClass == xmScrolledWindowWidgetClass) return; /* Ignore. */ |
| 1233 |
|
| 1234 |
/* |
| 1235 |
* My geometry follows the layout of my children. |
| 1236 |
* If I am a RowColumn, I am growing while my children move. |
| 1237 |
* Because these moves may involve drawing, which needs clipping to my rect, |
| 1238 |
* I have to grow with every managed child separately, |
| 1239 |
* not just after managing all of them. |
| 1240 |
*/ |
| 1241 |
|
| 1242 |
for (child = my firstChild; child; child = child -> nextSibling) { |
| 1243 |
if (child -> managed && ! MEMBER (child, Shell)) { |
| 1244 |
int dx = 0, dy = 0; // by default, the child does not move |
| 1245 |
if (MEMBER (me, RowColumn)) { |
| 1246 |
{ |
| 1247 |
if (x > child -> x) |
| 1248 |
dx = x - child -> x; |
| 1249 |
if (y > child -> y) |
| 1250 |
dy = y - child -> y; |
| 1251 |
child -> x += dx; x = child -> x; |
| 1252 |
child -> y += dy; y = child -> y; |
| 1253 |
if (my orientation != XmHORIZONTAL) |
| 1254 |
y += child -> height + 1; |
| 1255 |
else |
| 1256 |
x += child -> width + 3; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
if (child -> x + child -> width > width) |
| 1260 |
width = child -> x + child -> width; |
| 1261 |
if (child -> y + child -> height > height) |
| 1262 |
height = child -> y + child -> height; |
| 1263 |
if (MEMBER3 (me, Shell, Form, BulletinBoard)) { |
| 1264 |
/* |
| 1265 |
These widgets grow with their children. |
| 1266 |
*/ |
| 1267 |
dw = Melder_clippedLeft (0, width - my width); |
| 1268 |
dh = Melder_clippedLeft (0, height - my height); |
| 1269 |
} else if (MEMBER (me, RowColumn)) { |
| 1270 |
/* |
| 1271 |
A RowColumn shrinks and grows with its children. |
| 1272 |
*/ |
| 1273 |
dw = width - my width + 2; |
| 1274 |
dh = height - my height + 2; |
| 1275 |
} else { /* ? */ |
| 1276 |
dw = width - my width; |
| 1277 |
dh = height - my height; |
| 1278 |
} |
| 1279 |
my width += dw; |
| 1280 |
my height += dh; |
| 1281 |
|
| 1282 |
/* |
| 1283 |
Now that I have grown, there is room for my child to move. |
| 1284 |
*/ |
| 1285 |
if (MEMBER (me, RowColumn)) |
| 1286 |
Native_move (child, dx, dy); |
| 1287 |
|
| 1288 |
/* |
| 1289 |
Resize my attached other children. |
| 1290 |
*/ |
| 1291 |
#if 0 |
| 1292 |
if (MEMBER3 (me, RowColumn, Form, ScrolledWindow)) { |
| 1293 |
GuiObject child2; |
| 1294 |
for (child2 = my firstChild; child2; child2 = child2 -> nextSibling) if (child2 != child && child2 -> managed) { |
| 1295 |
int cdx = 0, cdy = 0, cdw = 0, cdh = 0; |
| 1296 |
if (child2 -> widgetClass == xmShellWidgetClass) |
| 1297 |
continue; |
| 1298 |
if (child2 -> rightAttachment == XmATTACH_FORM) |
| 1299 |
if (child2 -> leftAttachment == XmATTACH_FORM) |
| 1300 |
cdw = dw; |
| 1301 |
else |
| 1302 |
cdx = dw; |
| 1303 |
if (child2 -> bottomAttachment == XmATTACH_FORM) |
| 1304 |
if (child2 -> topAttachment == XmATTACH_FORM) |
| 1305 |
cdh = dh; |
| 1306 |
else |
| 1307 |
cdy = dh; |
| 1308 |
if (cdx || cdy) { |
| 1309 |
child2 -> x += cdx; |
| 1310 |
child2 -> y += cdy; |
| 1311 |
Native_move (child2, cdx, cdy); |
| 1312 |
} |
| 1313 |
if (cdw || cdh) { |
| 1314 |
child2 -> width += cdw; |
| 1315 |
child2 -> height += cdh; |
| 1316 |
resizeWidget (child2, cdw, cdh); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
} |
| 1320 |
#endif |
| 1321 |
} |
| 1322 |
} |
| 1323 |
|
| 1324 |
if (my window) Native_move (me, 0, 0); |
| 1325 |
|
| 1326 |
/* |
| 1327 |
If I have grown, I have to notify my parent. |
| 1328 |
*/ |
| 1329 |
if (! MEMBER (me, Shell)) { |
| 1330 |
//if (MEMBER4 (my parent, RowColumn, Form, BulletinBoard, Shell)) _motif_manage (my parent); |
| 1331 |
if (MEMBER (my parent, ScrolledWindow)) |
| 1332 |
_Gui_manageScrolledWindow (my parent); |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
/***** X TOOLKIT *****/ |
| 1337 |
|
| 1338 |
static void xt_addCallback (XtCallbackList *callbacks, XtCallbackProc proc, XtPointer closure) { |
| 1339 |
int i; |
| 1340 |
for (i = 0; i < MAXNUM_CALLBACKS; i ++) { |
| 1341 |
if (! callbacks -> pairs [i]. proc) { |
| 1342 |
callbacks -> pairs [i]. proc = proc; |
| 1343 |
callbacks -> pairs [i]. closure = closure; |
| 1344 |
return; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
Melder_assert (i < MAXNUM_CALLBACKS); // will always fail if we arrive here |
| 1348 |
} |
| 1349 |
|
| 1350 |
void XtAddCallback (GuiObject me, int kind, XtCallbackProc proc, XtPointer closure) { |
| 1351 |
switch (kind) { |
| 1352 |
case XmNactivateCallback: |
| 1353 |
my activateCallback = proc; my activateClosure = closure; |
| 1354 |
break; |
| 1355 |
case XmNdestroyCallback: |
| 1356 |
my destroyCallback = proc; my destroyClosure = closure; |
| 1357 |
break; |
| 1358 |
case XmNdragCallback: |
| 1359 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 1360 |
xt_addCallback (& my motiff.scrollBar.dragCallbacks, proc, closure); |
| 1361 |
break; |
| 1362 |
case XmNvalueChangedCallback: |
| 1363 |
if (my widgetClass == xmScrollBarWidgetClass) |
| 1364 |
xt_addCallback (& my motiff.scrollBar.valueChangedCallbacks, proc, closure); |
| 1365 |
else if (my widgetClass == xmToggleButtonWidgetClass) |
| 1366 |
xt_addCallback (& my motiff.toggleButton.valueChangedCallbacks, proc, closure); |
| 1367 |
else |
| 1368 |
Melder_assert (False); |
| 1369 |
break; |
| 1370 |
default: |
| 1371 |
if (kind < 0 || kind >= sizeof motif_resourceNames / sizeof (char *)) |
| 1372 |
Melder_flushError (U"(XtAddCallback:) Callback name out of range (", kind, U")."); |
| 1373 |
else |
| 1374 |
Melder_flushError (U"(XtAddCallback:) Unknown callback \"", Melder_peek8to32_u (motif_resourceNames [kind]), U"\"."); |
| 1375 |
} |
| 1376 |
} |
| 1377 |
|
| 1378 |
XtWorkProcId XtAddWorkProc (XtWorkProc workProc, XtPointer closure) { |
| 1379 |
int i = 1; |
| 1380 |
while (i < 10 && theWorkProcs [i]) |
| 1381 |
i ++; |
| 1382 |
Melder_assert (i < 10); |
| 1383 |
theWorkProcs [i] = workProc; |
| 1384 |
theWorkProcClosures [i] = closure; |
| 1385 |
theNumberOfWorkProcs ++; |
| 1386 |
return i; |
| 1387 |
} |
| 1388 |
|
| 1389 |
void XtRemoveWorkProc (XtWorkProcId id) { |
| 1390 |
theWorkProcs [id] = NULL; |
| 1391 |
theNumberOfWorkProcs --; |
| 1392 |
} |
| 1393 |
|
| 1394 |
XtIntervalId XtAddTimeOut (double interval, XtTimerCallbackProc proc, XtPointer closure) { |
| 1395 |
integer i = 1; |
| 1396 |
while (i < 10 && theTimeOutProcs [i]) |
| 1397 |
i ++; |
| 1398 |
Melder_assert (i < 10); |
| 1399 |
theTimeOutProcs [i] = proc; |
| 1400 |
theTimeOutStarts [i] = Melder_clock (); |
| 1401 |
theTimeOutIntervals [i] = interval; |
| 1402 |
theTimeOutClosures [i] = closure; |
| 1403 |
theNumberOfTimeOuts ++; |
| 1404 |
return i; |
| 1405 |
} |
| 1406 |
|
| 1407 |
void XtRemoveTimeOut (XtIntervalId id) { |
| 1408 |
theTimeOutProcs [id] = NULL; |
| 1409 |
theNumberOfTimeOuts --; |
| 1410 |
} |
| 1411 |
|
| 1412 |
void XtDestroyWidget (GuiObject me) { |
| 1413 |
//TRACE |
| 1414 |
trace (U"Destroying widget ", Melder_pointer (me)); |
| 1415 |
GuiObject subview = my firstChild; |
| 1416 |
/* |
| 1417 |
* Prevent subsequent messages. |
| 1418 |
*/ |
| 1419 |
HWND natWindow; |
| 1420 |
if (my window) |
| 1421 |
SetWindowLongPtr (my window, GWLP_USERDATA, 0); |
| 1422 |
if (my widgetClass == xmShellWidgetClass) { |
| 1423 |
XtUnmanageChild (me); |
| 1424 |
natWindow = my window; // save for destroy |
| 1425 |
my window = NULL; |
| 1426 |
} |
| 1427 |
if (MEMBER2 (me, Form, BulletinBoard) && MEMBER (my parent, Shell) && |
| 1428 |
my parent -> window |
| 1429 |
) { |
| 1430 |
XtDestroyWidget (my parent); |
| 1431 |
return; |
| 1432 |
} |
| 1433 |
while (subview) { |
| 1434 |
GuiObject nextSibling = subview -> nextSibling; // save... |
| 1435 |
//if (subview -> widgetClass != xmShellWidgetClass) /* FIX instead of Xm's being_destroyed mark. */ // removed 20090105 |
| 1436 |
XtDestroyWidget (subview); |
| 1437 |
subview = nextSibling; // ...because we can't dereference dead subview |
| 1438 |
} |
| 1439 |
if (my destroyCallback) |
| 1440 |
my destroyCallback (me, my destroyClosure, NULL); |
| 1441 |
switch (my widgetClass) { |
| 1442 |
case xmLabelWidgetClass: { |
| 1443 |
_GuiWinLabel_destroy (me); |
| 1444 |
} break; |
| 1445 |
case xmCascadeButtonWidgetClass: { |
| 1446 |
if (! my inMenu && ! MEMBER (my parent, MenuBar)) |
| 1447 |
_GuiNativeControl_destroy (me); |
| 1448 |
} break; |
| 1449 |
case xmScaleWidgetClass: { |
| 1450 |
_GuiWinScale_destroy (me); |
| 1451 |
} break; |
| 1452 |
case xmShellWidgetClass: { |
| 1453 |
DestroyWindow (natWindow); |
| 1454 |
} break; |
| 1455 |
case xmListWidgetClass: { |
| 1456 |
_GuiWinList_destroy (me); |
| 1457 |
} break; |
| 1458 |
case xmDrawingAreaWidgetClass: { |
| 1459 |
_GuiWinDrawingArea_destroy (me); |
| 1460 |
} break; |
| 1461 |
case xmRowColumnWidgetClass: { |
| 1462 |
//TRACE |
| 1463 |
trace (U"Destroying window ", Melder_pointer (my window), U" for RowColumn ", Melder_pointer (me)); |
| 1464 |
#if TRY_BARLESS |
| 1465 |
if (my rowColumnType == XmMENU_BAR) |
| 1466 |
; // my window is my parent's window |
| 1467 |
else |
| 1468 |
DestroyWindow (my window); |
| 1469 |
#else |
| 1470 |
DestroyWindow (my window); |
| 1471 |
#endif |
| 1472 |
} break; |
| 1473 |
case xmFormWidgetClass: |
| 1474 |
case xmBulletinBoardWidgetClass: { |
| 1475 |
DestroyWindow (my window); |
| 1476 |
} break; |
| 1477 |
case xmTextWidgetClass: { |
| 1478 |
_GuiWinText_destroy (me); |
| 1479 |
} break; |
| 1480 |
case xmPushButtonWidgetClass: { |
| 1481 |
if (my inMenu) { |
| 1482 |
if (my nat.entry.id) |
| 1483 |
theMenuItems [my nat.entry.id] = false; |
| 1484 |
} else { |
| 1485 |
_GuiWinButton_destroy (me); |
| 1486 |
} |
| 1487 |
} break; |
| 1488 |
case xmToggleButtonWidgetClass: { |
| 1489 |
if (my inMenu) { |
| 1490 |
if (my nat.entry.id) |
| 1491 |
theMenuItems [my nat.entry.id] = false; |
| 1492 |
} else { |
| 1493 |
if (my isRadioButton) |
| 1494 |
_GuiWinRadioButton_destroy (me); |
| 1495 |
else |
| 1496 |
_GuiWinCheckButton_destroy (me); |
| 1497 |
} |
| 1498 |
} break; |
| 1499 |
case xmScrollBarWidgetClass: { |
| 1500 |
_GuiWinScrollBar_destroy (me); |
| 1501 |
} break; |
| 1502 |
case xmScrolledWindowWidgetClass: { |
| 1503 |
/* The scroll bars will be destroyed automatically because they are my children. */ |
| 1504 |
_GuiWinScrolledWindow_destroy (me); |
| 1505 |
} break; |
| 1506 |
case xmSeparatorWidgetClass: { |
| 1507 |
if (my inMenu) { |
| 1508 |
if (my nat.entry.id) |
| 1509 |
theMenuItems [my nat.entry.id] = false; |
| 1510 |
} |
| 1511 |
} break; |
| 1512 |
case xmPulldownMenuWidgetClass: { |
| 1513 |
if (MEMBER (my parent, MenuBar)) |
| 1514 |
RemoveMenu (my parent -> nat.menu.handle, (UINT) my nat.menu./*handle*/id, MF_BYCOMMAND); |
| 1515 |
DestroyMenu (my nat.menu.handle); |
| 1516 |
theMenus [my nat.menu.id] = NULL; |
| 1517 |
} break; |
| 1518 |
} |
| 1519 |
my name. reset(); // not automatic |
| 1520 |
if (my parent && me == my parent -> firstChild) // remove dangling reference |
| 1521 |
my parent -> firstChild = my nextSibling; |
| 1522 |
if (my previousSibling) // remove dangling reference |
| 1523 |
my previousSibling -> nextSibling = my nextSibling; |
| 1524 |
if (my nextSibling) // remove dangling reference: two-way linked list |
| 1525 |
my nextSibling -> previousSibling = my previousSibling; |
| 1526 |
if (my parent && MEMBER (my parent, ScrolledWindow)) { |
| 1527 |
if (me == my parent -> motiff.scrolledWindow.workWindow) { |
| 1528 |
my parent -> motiff.scrolledWindow.workWindow = NULL; |
| 1529 |
_Gui_manageScrolledWindow (my parent); |
| 1530 |
} else if (me == my parent -> motiff.scrolledWindow.horizontalBar) { |
| 1531 |
my parent -> motiff.scrolledWindow.horizontalBar = NULL; |
| 1532 |
} else if (me == my parent -> motiff.scrolledWindow.verticalBar) { |
| 1533 |
my parent -> motiff.scrolledWindow.verticalBar = NULL; |
| 1534 |
} else if (me == my parent -> motiff.scrolledWindow.clipWindow) { |
| 1535 |
my parent -> motiff.scrolledWindow.clipWindow = NULL; |
| 1536 |
} |
| 1537 |
} |
| 1538 |
Melder_free (me); |
| 1539 |
numberOfWidgets --; |
| 1540 |
} |
| 1541 |
|
| 1542 |
Boolean XtIsManaged (GuiObject me) { return my managed; } |
| 1543 |
|
| 1544 |
Boolean XtIsShell (GuiObject me) { |
| 1545 |
return my widgetClass == xmShellWidgetClass; |
| 1546 |
} |
| 1547 |
|
| 1548 |
void XtMapWidget (GuiObject me) { |
| 1549 |
switch (my widgetClass) { |
| 1550 |
case xmShellWidgetClass: |
| 1551 |
ShowWindow (my window, theGui.commandShow); |
| 1552 |
//UpdateWindow (my window); |
| 1553 |
break; |
| 1554 |
default: |
| 1555 |
break; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
|
| 1559 |
static void mapWidget (GuiObject me) { |
| 1560 |
GuiObject child; |
| 1561 |
Melder_assert (my widgetClass != xmPulldownMenuWidgetClass); |
| 1562 |
if (my inMenu) { |
| 1563 |
trace (U"showing a menu item"); |
| 1564 |
int position = NativeMenuItem_getPosition (me); |
| 1565 |
switch (my widgetClass) { |
| 1566 |
case xmPushButtonWidgetClass: { |
| 1567 |
InsertMenu (my nat.entry.handle, position, |
| 1568 |
MF_STRING | MF_BYPOSITION | ( my insensitive ? MF_GRAYED : MF_ENABLED ), |
| 1569 |
my nat.entry.id, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())) |
| 1570 |
); |
| 1571 |
} break; |
| 1572 |
case xmToggleButtonWidgetClass: { |
| 1573 |
InsertMenu (my nat.entry.handle, position, |
| 1574 |
MF_STRING | MF_UNCHECKED | MF_BYPOSITION | ( my insensitive ? MF_GRAYED : MF_ENABLED ), |
| 1575 |
my nat.entry.id, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())) |
| 1576 |
); |
| 1577 |
} break; |
| 1578 |
case xmCascadeButtonWidgetClass: { |
| 1579 |
my nat.entry.id = (ULONG_PTR) my subMenuId -> nat.menu.handle; |
| 1580 |
InsertMenu (my nat.entry.handle, position, |
| 1581 |
MF_POPUP | MF_BYPOSITION | ( my insensitive ? MF_GRAYED : MF_ENABLED ), |
| 1582 |
my nat.entry.id, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())) |
| 1583 |
); |
| 1584 |
} break; |
| 1585 |
case xmSeparatorWidgetClass: { |
| 1586 |
InsertMenu (my nat.entry.handle, position, |
| 1587 |
MF_SEPARATOR | MF_BYPOSITION, |
| 1588 |
my nat.entry.id, Melder_peek32toW (_GuiWin_expandAmpersands (my name.get())) |
| 1589 |
); |
| 1590 |
} break; |
| 1591 |
} |
| 1592 |
} else switch (my widgetClass) { |
| 1593 |
case xmBulletinBoardWidgetClass: |
| 1594 |
case xmDrawingAreaWidgetClass: |
| 1595 |
case xmScrolledWindowWidgetClass: |
| 1596 |
case xmFormWidgetClass: { |
| 1597 |
ShowWindow (my window, SW_SHOW); |
| 1598 |
} break; |
| 1599 |
case xmRowColumnWidgetClass: { |
| 1600 |
ShowWindow (my window, SW_SHOW); |
| 1601 |
} break; |
| 1602 |
case xmShellWidgetClass: { |
| 1603 |
ShowWindow (my window, theGui.commandShow); |
| 1604 |
if (my dialogStyle == XmDIALOG_FULL_APPLICATION_MODAL) |
| 1605 |
; |
| 1606 |
} break; |
| 1607 |
case xmMenuBarWidgetClass: { |
| 1608 |
DrawMenuBar (my shell -> window); // every window has its own menu bar |
| 1609 |
} break; |
| 1610 |
case xmPushButtonWidgetClass: _GuiNativeControl_show (me); break; |
| 1611 |
case xmToggleButtonWidgetClass: _GuiNativeControl_show (me); break; |
| 1612 |
case xmScrollBarWidgetClass: { |
| 1613 |
if (! my window) { |
| 1614 |
my window = CreateWindow (L"scrollbar", |
| 1615 |
Melder_peek32toW (my name.get()), |
| 1616 |
WS_CHILD | ( my orientation == XmHORIZONTAL ? SBS_HORZ : SBS_VERT) | WS_CLIPSIBLINGS, |
| 1617 |
my x, my y, my width, my height, |
| 1618 |
my parent -> window, |
| 1619 |
(HMENU) 1, |
| 1620 |
theGui.instance, |
| 1621 |
NULL |
| 1622 |
); |
| 1623 |
SetWindowLongPtr (my window, GWLP_USERDATA, (LONG_PTR) me); |
| 1624 |
NativeScrollBar_set (me); |
| 1625 |
} |
| 1626 |
_GuiNativeControl_show (me); |
| 1627 |
} break; |
| 1628 |
case xmLabelWidgetClass: { |
| 1629 |
_GuiNativeControl_show (me); |
| 1630 |
} break; |
| 1631 |
case xmCascadeButtonWidgetClass: { |
| 1632 |
if (! MEMBER (my parent, MenuBar)) |
| 1633 |
_GuiNativeControl_show (me); |
| 1634 |
} break; |
| 1635 |
case xmScaleWidgetClass: { |
| 1636 |
_GuiNativeControl_show (me); |
| 1637 |
} break; |
| 1638 |
case xmTextWidgetClass: { |
| 1639 |
_GuiWinText_map (me); |
| 1640 |
} break; |
| 1641 |
case xmListWidgetClass: { |
| 1642 |
_GuiWinList_map (me); |
| 1643 |
} break; |
| 1644 |
default: |
| 1645 |
break; |
| 1646 |
} |
| 1647 |
for (child = my firstChild; child != NULL; child = child -> nextSibling) |
| 1648 |
if (child -> managed) mapWidget (child); |
| 1649 |
} |
| 1650 |
|
| 1651 |
void XtManageChild (GuiObject me) { |
| 1652 |
if (my managed) |
| 1653 |
return; |
| 1654 |
|
| 1655 |
if (MEMBER (me, ScrolledWindow)) { |
| 1656 |
XtManageChild (my motiff.scrolledWindow.horizontalBar); |
| 1657 |
XtManageChild (my motiff.scrolledWindow.verticalBar); |
| 1658 |
/*XtManageChild (my motiff.scrolledWindow.clipWindow);*/ |
| 1659 |
} |
| 1660 |
|
| 1661 |
my managed = 1; |
| 1662 |
|
| 1663 |
/* Geometry management if my parent is a manager. */ |
| 1664 |
|
| 1665 |
if (! MEMBER (me, Shell)) { |
| 1666 |
if (MEMBER4 (my parent, RowColumn, Form, BulletinBoard, Shell)) |
| 1667 |
_motif_manage (my parent); |
| 1668 |
if (MEMBER (me, ScrolledWindow)) |
| 1669 |
_Gui_manageScrolledWindow (me); |
| 1670 |
if (MEMBER (my parent, ScrolledWindow)) |
| 1671 |
_Gui_manageScrolledWindow (my parent); |
| 1672 |
} |
| 1673 |
|
| 1674 |
/* Map to the screen (suppose that mapped_when_managed is true). */ |
| 1675 |
/* Condition: the entire up chain has been managed. */ |
| 1676 |
/* Shells or their immediate manager children can be mapped directly. */ |
| 1677 |
|
| 1678 |
if (my parent && MEMBER (my parent, Shell) && MEMBER2 (me, Form, BulletinBoard)) { |
| 1679 |
my parent -> managed = 1; |
| 1680 |
mapWidget (my parent); |
| 1681 |
} else if (my inMenu) { |
| 1682 |
mapWidget (me); |
| 1683 |
} else { |
| 1684 |
int visible = True; |
| 1685 |
GuiObject widget; |
| 1686 |
for (widget = me; widget != NULL; widget = widget -> parent) { |
| 1687 |
if (! widget -> managed && // if a parent is invisible, so are its children |
| 1688 |
! MEMBER (widget, PulldownMenu)) // the exception: "shown" even if not popped up |
| 1689 |
{ visible = False; break; } |
| 1690 |
if (MEMBER (widget, Shell)) |
| 1691 |
break; // root: end of chain |
| 1692 |
} |
| 1693 |
if (visible) mapWidget (me); |
| 1694 |
} |
| 1695 |
|
| 1696 |
/* I may have been created by XmCreateScrolledText or XmCreateScrolledList. */ |
| 1697 |
/* In that case, my parent should be managed. */ |
| 1698 |
|
| 1699 |
if (MEMBER2 (me, Text, List) && MEMBER (my parent, ScrolledWindow)) |
| 1700 |
XtManageChild (my parent); |
| 1701 |
} |
| 1702 |
|
| 1703 |
void XtManageChildren (GuiObjectList children, Cardinal num_children) { |
| 1704 |
for (Cardinal i = 0; i < num_children; i ++) |
| 1705 |
XtManageChild (children [i]); |
| 1706 |
} |
| 1707 |
|
| 1708 |
void XtSetSensitive (GuiObject me, Boolean value) { |
| 1709 |
//TRACE |
| 1710 |
if (my insensitive != value) |
| 1711 |
return; |
| 1712 |
my insensitive = ! value; |
| 1713 |
if (! my parent) |
| 1714 |
return; |
| 1715 |
switch (my widgetClass) { |
| 1716 |
case xmPushButtonWidgetClass: |
| 1717 |
case xmToggleButtonWidgetClass: { |
| 1718 |
if (my inMenu) |
| 1719 |
NativeMenuItem_setSensitive (me); |
| 1720 |
else |
| 1721 |
_GuiNativeControl_setSensitive (me); |
| 1722 |
} break; |
| 1723 |
case xmScrollBarWidgetClass: _GuiNativeControl_setSensitive (me); break; |
| 1724 |
case xmLabelWidgetClass: _GuiNativeControl_setSensitive (me); break; |
| 1725 |
case xmCascadeButtonWidgetClass: { |
| 1726 |
trace (U"setting the sensitivity of a cascade button to ", value); |
| 1727 |
if (my inMenu || my motiff.cascadeButton.inBar) { |
| 1728 |
trace (U"in the menu bar"); |
| 1729 |
if (my subMenuId) { |
| 1730 |
trace (U"submenu ID ", Melder_pointer (my subMenuId)); |
| 1731 |
my subMenuId -> insensitive = my insensitive; |
| 1732 |
NativeMenuItem_setSensitive (my subMenuId); |
| 1733 |
//NativeMenuItem_setSensitive (me); |
| 1734 |
DrawMenuBar (my shell -> window); |
| 1735 |
} |
| 1736 |
} else { |
| 1737 |
trace (U"outside the menu bar"); |
| 1738 |
_GuiNativeControl_setSensitive (me); |
| 1739 |
} |
| 1740 |
} break; |
| 1741 |
case xmPulldownMenuWidgetClass: { |
| 1742 |
trace (U"setting the sensitivity of a menu title to ", value); |
| 1743 |
if (my popUpButton) |
| 1744 |
XtSetSensitive (my popUpButton, value); |
| 1745 |
} break; |
| 1746 |
default: |
| 1747 |
break; |
| 1748 |
} |
| 1749 |
} |
| 1750 |
|
| 1751 |
void XtUnmanageChild (GuiObject me) { |
| 1752 |
if (! my managed) |
| 1753 |
return; |
| 1754 |
if (my inMenu) { |
| 1755 |
if (! MEMBER (me, PulldownMenu)) |
| 1756 |
NativeMenuItem_delete (me); |
| 1757 |
} else switch (my widgetClass) { |
| 1758 |
case xmShellWidgetClass: |
| 1759 |
_GuiText_handleFocusLoss (my textFocus); |
| 1760 |
ShowWindow (my window, SW_HIDE); |
| 1761 |
if (my firstChild && MEMBER2 (my firstChild, Form, BulletinBoard)) |
| 1762 |
my firstChild -> managed = 0; |
| 1763 |
break; |
| 1764 |
case xmPushButtonWidgetClass: |
| 1765 |
_GuiNativeControl_hide (me); |
| 1766 |
break; |
| 1767 |
case xmToggleButtonWidgetClass: |
| 1768 |
_GuiNativeControl_hide (me); |
| 1769 |
break; |
| 1770 |
case xmLabelWidgetClass: |
| 1771 |
_GuiNativeControl_hide (me); |
| 1772 |
break; |
| 1773 |
case xmCascadeButtonWidgetClass: |
| 1774 |
if (! MEMBER (my parent, MenuBar)) |
| 1775 |
_GuiNativeControl_hide (me); |
| 1776 |
break; |
| 1777 |
case xmScrollBarWidgetClass: |
| 1778 |
_GuiNativeControl_hide (me); |
| 1779 |
break; |
| 1780 |
case xmFormWidgetClass: |
| 1781 |
case xmBulletinBoardWidgetClass: |
| 1782 |
if (MEMBER (my parent, Shell)) |
| 1783 |
XtUnmanageChild (my parent); |
| 1784 |
break; |
| 1785 |
case xmTextWidgetClass: |
| 1786 |
_GuiText_unmanage (me); |
| 1787 |
break; |
| 1788 |
default: |
| 1789 |
_Gui_invalidateWidget (me); |
| 1790 |
break; |
| 1791 |
} |
| 1792 |
|
| 1793 |
my managed = 0; |
| 1794 |
|
| 1795 |
if (! MEMBER (me, Shell)) { |
| 1796 |
if (MEMBER4 (my parent, RowColumn, Form, BulletinBoard, Shell)) |
| 1797 |
_motif_manage (my parent); |
| 1798 |
else if (MEMBER (my parent, ScrolledWindow)) |
| 1799 |
_Gui_manageScrolledWindow (my parent); |
| 1800 |
} |
| 1801 |
} |
| 1802 |
|
| 1803 |
void XtUnmanageChildren (GuiObjectList children, Cardinal num_children) { |
| 1804 |
for (Cardinal i = 0; i < num_children; i ++) |
| 1805 |
XtUnmanageChild (children [i]); |
| 1806 |
} |
| 1807 |
|
| 1808 |
static LRESULT CALLBACK windowProc (HWND window, UINT message, WPARAM wParam, LPARAM lParam); |
| 1809 |
|
| 1810 |
void * GuiWin_initialize1 (conststring32 name) |
| 1811 |
{ |
| 1812 |
Melder_sprint (theApplicationClassName,100, U"PraatShell", PRAAT_WINDOW_CLASS_NUMBER, U" ", name); |
| 1813 |
Melder_sprint (theWindowClassName,100, U"PraatChildWindow", PRAAT_WINDOW_CLASS_NUMBER, U" ", name); |
| 1814 |
trace (U"Window class name <<", theWindowClassName, U">>"); |
| 1815 |
Melder_sprint (theDrawingAreaClassName,100, U"PraatDrawingArea", PRAAT_WINDOW_CLASS_NUMBER, U" ", name); |
| 1816 |
HWND window = FindWindow (Melder_peek32toW (theWindowClassName), NULL); // or theApplicationClassName? |
| 1817 |
return window; |
| 1818 |
} |
| 1819 |
void GuiWin_initialize2 (unsigned int argc, char **argv) |
| 1820 |
{ |
| 1821 |
WNDCLASSEX windowClass; |
| 1822 |
windowClass. cbSize = sizeof (WNDCLASSEX); |
| 1823 |
windowClass. style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | |
| 1824 |
CS_OWNDC // crucial: see GraphicsScreen_init () |
| 1825 |
; |
| 1826 |
windowClass. lpfnWndProc = windowProc; |
| 1827 |
windowClass. cbClsExtra = 0; |
| 1828 |
windowClass. cbWndExtra = 0; |
| 1829 |
windowClass. hInstance = theGui.instance; |
| 1830 |
windowClass. hIcon = NULL; |
| 1831 |
windowClass. hCursor = LoadCursor (NULL, IDC_ARROW); |
| 1832 |
windowClass. hbrBackground = theWinGuiBackgroundBrush (); |
| 1833 |
windowClass. lpszMenuName = NULL; |
| 1834 |
windowClass. lpszClassName = Melder_32toW (theWindowClassName).transfer(); |
| 1835 |
windowClass. hIconSm = NULL; |
| 1836 |
RegisterClassEx (& windowClass); |
| 1837 |
windowClass. hbrBackground = theWinGuiBackgroundBrush (); |
| 1838 |
windowClass. lpszClassName = Melder_32toW (theDrawingAreaClassName).transfer(); |
| 1839 |
RegisterClassEx (& windowClass); |
| 1840 |
windowClass. lpszClassName = Melder_32toW (theApplicationClassName).transfer(); |
| 1841 |
RegisterClassEx (& windowClass); |
| 1842 |
InitCommonControls (); |
| 1843 |
#ifdef _WIN64 |
| 1844 |
EnableMouseInPointer (TRUE); // from Windows 8 on |
| 1845 |
#endif |
| 1846 |
} |
| 1847 |
|
| 1848 |
void GuiApp_setApplicationShell (GuiObject shell) { |
| 1849 |
theApplicationShell = shell; |
| 1850 |
} |
| 1851 |
|
| 1852 |
GuiObject XtVaCreateManagedWidget (const char *name, int widgetClass, GuiObject parent, ...) { |
| 1853 |
GuiObject me; |
| 1854 |
va_list arg; |
| 1855 |
va_start (arg, parent); |
| 1856 |
me = createWidget (widgetClass, parent, name); |
| 1857 |
_motif_setValues (me, arg); |
| 1858 |
va_end (arg); |
| 1859 |
XtManageChild (me); |
| 1860 |
return me; |
| 1861 |
} |
| 1862 |
|
| 1863 |
GuiObject XtVaCreateWidget (const char *name, int widgetClass, GuiObject parent, ...) { |
| 1864 |
GuiObject me; |
| 1865 |
va_list arg; |
| 1866 |
va_start (arg, parent); |
| 1867 |
me = createWidget (widgetClass, parent, name); |
| 1868 |
_motif_setValues (me, arg); |
| 1869 |
va_end (arg); |
| 1870 |
return me; |
| 1871 |
} |
| 1872 |
|
| 1873 |
void XtVaGetValues (GuiObject me, ...) { |
| 1874 |
char *text; |
| 1875 |
unsigned int resource; |
| 1876 |
va_list arg; |
| 1877 |
va_start (arg, me); |
| 1878 |
while ((resource = va_arg (arg, int)) != 0) switch (resource) { |
| 1879 |
case XmNx: *va_arg (arg, int *) = my x; break; |
| 1880 |
case XmNy: *va_arg (arg, int *) = my y; break; |
| 1881 |
case XmNwidth: *va_arg (arg, int *) = my width; break; |
| 1882 |
case XmNheight: *va_arg (arg, int *) = my height; break; |
| 1883 |
case XmNuserData: *va_arg (arg, void **) = my userData; break; |
| 1884 |
case XmNtitle: |
| 1885 |
Melder_assert (my widgetClass == xmShellWidgetClass); |
| 1886 |
*va_arg (arg, char **) = NULL; |
| 1887 |
break; |
| 1888 |
case XmNlabelString: |
| 1889 |
case XmNtitleString: |
| 1890 |
Melder_assert (my widgetClass == xmCascadeButtonWidgetClass || my widgetClass == xmScaleWidgetClass); |
| 1891 |
text = Melder_32to8 (my name.get()).transfer(); // BUG throwable |
| 1892 |
*va_arg (arg, char **) = text; |
| 1893 |
break; |
| 1894 |
case XmNdialogTitle: |
| 1895 |
Melder_assert (my widgetClass == xmFormWidgetClass || my widgetClass == xmBulletinBoardWidgetClass); |
| 1896 |
*va_arg (arg, char **) = NULL; // NYI |
| 1897 |
break; |
| 1898 |
case XmNradioBehavior: |
| 1899 |
Melder_assert (my widgetClass == xmRowColumnWidgetClass); |
| 1900 |
*va_arg (arg, int *) = my radioBehavior; |
| 1901 |
break; |
| 1902 |
case XmNautoUnmanage: |
| 1903 |
*va_arg (arg, int *) = my autoUnmanage; |
| 1904 |
break; |
| 1905 |
case XmNorientation: |
| 1906 |
Melder_assert (my widgetClass == xmRowColumnWidgetClass || |
| 1907 |
my widgetClass == xmScrollBarWidgetClass); |
| 1908 |
*va_arg (arg, int *) = my orientation; |
| 1909 |
break; |
| 1910 |
case XmNrowColumnType: |
| 1911 |
Melder_assert (my widgetClass == xmRowColumnWidgetClass); |
| 1912 |
*va_arg (arg, int *) = my rowColumnType; |
| 1913 |
break; |
| 1914 |
case XmNsubMenuId: |
| 1915 |
Melder_assert (my widgetClass == xmCascadeButtonWidgetClass); |
| 1916 |
*va_arg (arg, GuiObject *) = my subMenuId; |
| 1917 |
break; |
| 1918 |
case XmNdialogStyle: |
| 1919 |
Melder_assert (my widgetClass == xmFormWidgetClass || |
| 1920 |
my widgetClass == xmBulletinBoardWidgetClass); |
| 1921 |
*va_arg (arg, int *) = my dialogStyle; |
| 1922 |
break; |
| 1923 |
case XmNleftAttachment: |
| 1924 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1925 |
*va_arg (arg, int *) = my leftAttachment; |
| 1926 |
break; |
| 1927 |
case XmNrightAttachment: |
| 1928 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1929 |
*va_arg (arg, int *) = my rightAttachment; |
| 1930 |
break; |
| 1931 |
case XmNtopAttachment: |
| 1932 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1933 |
*va_arg (arg, int *) = my topAttachment; |
| 1934 |
break; |
| 1935 |
case XmNbottomAttachment: |
| 1936 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1937 |
*va_arg (arg, int *) = my bottomAttachment; |
| 1938 |
break; |
| 1939 |
case XmNleftOffset: |
| 1940 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1941 |
*va_arg (arg, int *) = my leftOffset; |
| 1942 |
break; |
| 1943 |
case XmNrightOffset: |
| 1944 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1945 |
*va_arg (arg, int *) = my rightOffset; |
| 1946 |
break; |
| 1947 |
case XmNtopOffset: |
| 1948 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1949 |
*va_arg (arg, int *) = my topOffset; |
| 1950 |
break; |
| 1951 |
case XmNbottomOffset: |
| 1952 |
Melder_assert (my parent -> widgetClass == xmFormWidgetClass); |
| 1953 |
*va_arg (arg, int *) = my bottomOffset; |
| 1954 |
break; |
| 1955 |
case XmNminimum: *va_arg (arg, int *) = my minimum; break; |
| 1956 |
case XmNmaximum: *va_arg (arg, int *) = my maximum; break; |
| 1957 |
case XmNvalue: *va_arg (arg, int *) = my value; break; |
| 1958 |
case XmNincrement: |
| 1959 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 1960 |
*va_arg (arg, int *) = my increment; |
| 1961 |
break; |
| 1962 |
case XmNpageIncrement: |
| 1963 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 1964 |
*va_arg (arg, int *) = my pageIncrement; |
| 1965 |
break; |
| 1966 |
case XmNsliderSize: |
| 1967 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 1968 |
*va_arg (arg, int *) = my sliderSize; |
| 1969 |
break; |
| 1970 |
case XmNdeleteResponse: |
| 1971 |
Melder_assert (my widgetClass == xmShellWidgetClass); |
| 1972 |
*va_arg (arg, int *) = my deleteResponse; |
| 1973 |
break; |
| 1974 |
case XmNcolumns: *va_arg (arg, int *) = 40; break; |
| 1975 |
case XmNhorizontalScrollBar: *va_arg (arg, GuiObject *) = my motiff.scrolledWindow.horizontalBar; break; |
| 1976 |
case XmNverticalScrollBar: *va_arg (arg, GuiObject *) = my motiff.scrolledWindow.verticalBar; break; |
| 1977 |
default: { |
| 1978 |
if (resource < 0 || resource >= sizeof motif_resourceNames / sizeof (char *)) |
| 1979 |
Melder_flushError (U"(XtVaGetValues:) Resource out of range (", resource, U")."); |
| 1980 |
else |
| 1981 |
Melder_flushError (U"(XtVaGetValues:) Unknown resource \"", Melder_peek8to32_u (motif_resourceNames [resource]), U"\"."); |
| 1982 |
return; |
| 1983 |
} |
| 1984 |
} |
| 1985 |
va_end (arg); |
| 1986 |
} |
| 1987 |
|
| 1988 |
void XtVaSetValues (GuiObject me, ...) { |
| 1989 |
va_list arg; |
| 1990 |
va_start (arg, me); |
| 1991 |
_motif_setValues (me, arg); |
| 1992 |
va_end (arg); |
| 1993 |
} |
| 1994 |
|
| 1995 |
Window XtWindow (GuiObject me) { |
| 1996 |
return (Window) my window; |
| 1997 |
} |
| 1998 |
|
| 1999 |
/***** MOTIF *****/ |
| 2000 |
|
| 2001 |
void XmAddWMProtocolCallback (GuiObject me, Atom protocol, XtCallbackProc callback, char *closure) { |
| 2002 |
if (protocol == 'delw') { |
| 2003 |
my motiff.shell.goAwayCallback = callback; |
| 2004 |
my motiff.shell.goAwayClosure = closure; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
|
| 2008 |
GuiObject XmCreateBulletinBoard (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2009 |
(void) dum1; |
| 2010 |
(void) dum2; |
| 2011 |
return createWidget (xmBulletinBoardWidgetClass, parent, name); |
| 2012 |
} |
| 2013 |
|
| 2014 |
GuiObject XmCreateBulletinBoardDialog (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2015 |
GuiObject shell = XmCreateDialogShell (parent, name, dum1, dum2); |
| 2016 |
return XmCreateBulletinBoard (shell, name, dum1, dum2); |
| 2017 |
} |
| 2018 |
|
| 2019 |
GuiObject XmCreateCascadeButton (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2020 |
(void) dum1; |
| 2021 |
(void) dum2; |
| 2022 |
return createWidget (xmCascadeButtonWidgetClass, parent, name); |
| 2023 |
} |
| 2024 |
|
| 2025 |
GuiObject XmCreateCascadeButtonGadget (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2026 |
(void) dum1; |
| 2027 |
(void) dum2; |
| 2028 |
return createWidget (xmCascadeButtonGadgetClass, parent, name); |
| 2029 |
} |
| 2030 |
|
| 2031 |
GuiObject XmCreateDialogShell (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2032 |
GuiObject shell; |
| 2033 |
theDialogHint = True; |
| 2034 |
shell = XmCreateShell (parent, name, dum1, dum2); |
| 2035 |
theDialogHint = False; |
| 2036 |
return shell; |
| 2037 |
} |
| 2038 |
|
| 2039 |
GuiObject XmCreateForm (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2040 |
(void) dum1; |
| 2041 |
(void) dum2; |
| 2042 |
return createWidget (xmFormWidgetClass, parent, name); |
| 2043 |
} |
| 2044 |
|
| 2045 |
GuiObject XmCreateFormDialog (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2046 |
GuiObject shell = XmCreateDialogShell (parent, name, dum1, dum2); |
| 2047 |
return XmCreateForm (shell, name, dum1, dum2); |
| 2048 |
} |
| 2049 |
|
| 2050 |
GuiObject XmCreateMenuBar (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2051 |
(void) dum1; |
| 2052 |
(void) dum2; |
| 2053 |
return createWidget (xmMenuBarWidgetClass, parent, name); |
| 2054 |
} |
| 2055 |
|
| 2056 |
GuiObject XmCreatePulldownMenu (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2057 |
(void) dum1; |
| 2058 |
(void) dum2; |
| 2059 |
return createWidget (xmPulldownMenuWidgetClass, parent, name); |
| 2060 |
} |
| 2061 |
|
| 2062 |
GuiObject XmCreateRadioBox (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2063 |
GuiObject result = createWidget (xmRowColumnWidgetClass, parent, name); |
| 2064 |
(void) dum1; |
| 2065 |
(void) dum2; |
| 2066 |
XtVaSetValues (result, XmNradioBehavior, True, NULL); |
| 2067 |
return result; |
| 2068 |
} |
| 2069 |
|
| 2070 |
GuiObject XmCreateRowColumn (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2071 |
(void) dum1; |
| 2072 |
(void) dum2; |
| 2073 |
return createWidget (xmRowColumnWidgetClass, parent, name); |
| 2074 |
} |
| 2075 |
|
| 2076 |
GuiObject XmCreateScale (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2077 |
(void) dum1; |
| 2078 |
(void) dum2; |
| 2079 |
return createWidget (xmScaleWidgetClass, parent, name); |
| 2080 |
} |
| 2081 |
|
| 2082 |
GuiObject XmCreateScrollBar (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2083 |
(void) dum1; |
| 2084 |
(void) dum2; |
| 2085 |
return createWidget (xmScrollBarWidgetClass, parent, name); |
| 2086 |
} |
| 2087 |
|
| 2088 |
GuiObject XmCreateScrolledWindow (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2089 |
(void) dum1; |
| 2090 |
(void) dum2; |
| 2091 |
return createWidget (xmScrolledWindowWidgetClass, parent, name); |
| 2092 |
} |
| 2093 |
|
| 2094 |
GuiObject XmCreateSeparator (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2095 |
(void) dum1; |
| 2096 |
(void) dum2; |
| 2097 |
return createWidget (xmSeparatorWidgetClass, parent, name); |
| 2098 |
} |
| 2099 |
|
| 2100 |
GuiObject XmCreateSeparatorGadget (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2101 |
(void) dum1; |
| 2102 |
(void) dum2; |
| 2103 |
return createWidget (xmSeparatorWidgetClass, parent, name); |
| 2104 |
} |
| 2105 |
|
| 2106 |
GuiObject XmCreateShell (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2107 |
GuiObject me = createWidget (xmShellWidgetClass, parent, name); |
| 2108 |
(void) dum1; |
| 2109 |
(void) dum2; |
| 2110 |
return me; |
| 2111 |
} |
| 2112 |
|
| 2113 |
GuiObject XmCreateToggleButtonGadget (GuiObject parent, const char *name, ArgList dum1, int dum2) { |
| 2114 |
(void) dum1; |
| 2115 |
(void) dum2; |
| 2116 |
return createWidget (xmToggleButtonWidgetClass, parent, name); |
| 2117 |
} |
| 2118 |
|
| 2119 |
void XmScaleGetValue (GuiObject me, int *value_return) { |
| 2120 |
Melder_assert (my widgetClass == xmScaleWidgetClass); |
| 2121 |
*value_return = my value; |
| 2122 |
} |
| 2123 |
|
| 2124 |
void XmScaleSetValue (GuiObject me, int value) { |
| 2125 |
Melder_assert (my widgetClass == xmScaleWidgetClass); |
| 2126 |
my value = value; |
| 2127 |
SendMessage (my window, PBM_SETPOS, (WPARAM) value, 0); |
| 2128 |
_motif_update (me, 0); |
| 2129 |
} |
| 2130 |
|
| 2131 |
void XmScrollBarGetValues (GuiObject me, int *value, int *sliderSize, |
| 2132 |
int *increment, int *pageIncrement) |
| 2133 |
{ |
| 2134 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 2135 |
*value = my value; |
| 2136 |
*sliderSize = my sliderSize; |
| 2137 |
*increment = my increment; |
| 2138 |
*pageIncrement = my pageIncrement; |
| 2139 |
} |
| 2140 |
|
| 2141 |
void XmScrollBarSetValues (GuiObject me, int value, int sliderSize, |
| 2142 |
int increment, int pageIncrement, Boolean notify) |
| 2143 |
{ |
| 2144 |
Melder_assert (my widgetClass == xmScrollBarWidgetClass); |
| 2145 |
my value = value; |
| 2146 |
my sliderSize = sliderSize; |
| 2147 |
my increment = increment; |
| 2148 |
my pageIncrement = pageIncrement; |
| 2149 |
NativeScrollBar_set (me); |
| 2150 |
if (notify) |
| 2151 |
_Gui_callCallbacks (me, & my motiff.scrollBar.valueChangedCallbacks, NULL); |
| 2152 |
} |
| 2153 |
|
| 2154 |
Boolean XmToggleButtonGadgetGetState (GuiObject me) { |
| 2155 |
Melder_assert (MEMBER (me, ToggleButton)); |
| 2156 |
Melder_assert (my inMenu); |
| 2157 |
return GetMenuState (my nat.entry.handle, my nat.entry.id, MF_BYCOMMAND) & MF_CHECKED ? True : False; |
| 2158 |
} |
| 2159 |
|
| 2160 |
void XmToggleButtonGadgetSetState (GuiObject me, Boolean value, Boolean notify) { |
| 2161 |
Melder_assert (MEMBER (me, ToggleButton)); |
| 2162 |
Melder_assert (my inMenu); |
| 2163 |
NativeMenuItem_check (me, value); |
| 2164 |
if (notify) |
| 2165 |
_Gui_callCallbacks (me, & my motiff.toggleButton.valueChangedCallbacks, NULL); |
| 2166 |
} |
| 2167 |
|
| 2168 |
static void _motif_update (GuiObject me, void *event) { (void) me; (void) event; } |
| 2169 |
|
| 2170 |
/***** EVENT *****/ |
| 2171 |
|
| 2172 |
static void _motif_inspectTextWidgets (GuiObject me, GuiObject text, |
| 2173 |
integer *p_numberOfTextWidgets, integer *p_textWidgetLocation) |
| 2174 |
{ |
| 2175 |
for (GuiObject sub = my firstChild; sub != NULL; sub = sub -> nextSibling) { |
| 2176 |
if (MEMBER (sub, Shell)) |
| 2177 |
continue; |
| 2178 |
if (MEMBER (sub, Text)) { |
| 2179 |
(*p_numberOfTextWidgets) ++; |
| 2180 |
if (sub == text) |
| 2181 |
*p_textWidgetLocation = *p_numberOfTextWidgets; |
| 2182 |
} else { |
| 2183 |
_motif_inspectTextWidgets (sub, text, p_numberOfTextWidgets, p_textWidgetLocation); |
| 2184 |
} |
| 2185 |
} |
| 2186 |
} |
| 2187 |
static GuiObject _motif_getLocatedTextWidget (GuiObject me, |
| 2188 |
integer *p_itextWidget, integer textWidgetLocation) |
| 2189 |
{ |
| 2190 |
for (GuiObject sub = my firstChild; sub != NULL; sub = sub -> nextSibling) { |
| 2191 |
if (MEMBER (sub, Shell)) |
| 2192 |
continue; |
| 2193 |
if (MEMBER (sub, Text)) { |
| 2194 |
(*p_itextWidget) ++; |
| 2195 |
if (*p_itextWidget == textWidgetLocation) |
| 2196 |
return sub; |
| 2197 |
} else { |
| 2198 |
GuiObject locatedTextWidget = _motif_getLocatedTextWidget (sub, p_itextWidget, textWidgetLocation); |
| 2199 |
if (locatedTextWidget) return locatedTextWidget; |
| 2200 |
} |
| 2201 |
} |
| 2202 |
return NULL; |
| 2203 |
} |
| 2204 |
static GuiObject _motif_getNextTextWidget (GuiObject shell, GuiObject text, bool backward) { |
| 2205 |
integer numberOfTextWidgets = 0, textWidgetLocation = 0; |
| 2206 |
_motif_inspectTextWidgets (shell, text, & numberOfTextWidgets, & textWidgetLocation); |
| 2207 |
trace (U"Found ", numberOfTextWidgets, U" text widgets."); |
| 2208 |
if (numberOfTextWidgets == 0) |
| 2209 |
return nullptr; // no tab navigation if there is no text widget (shouldn't normally occur) |
| 2210 |
Melder_assert (textWidgetLocation >= 1); |
| 2211 |
Melder_assert (textWidgetLocation <= numberOfTextWidgets); |
| 2212 |
if (numberOfTextWidgets == 1) return NULL; // no tab navigation if there is only one text widget |
| 2213 |
if (backward) { |
| 2214 |
textWidgetLocation --; // tab to previous text widget |
| 2215 |
if (textWidgetLocation < 1) |
| 2216 |
textWidgetLocation = numberOfTextWidgets; // if at beginning, then tab around to last text widget |
| 2217 |
} else { |
| 2218 |
textWidgetLocation ++; // tab to next text widget |
| 2219 |
if (textWidgetLocation > numberOfTextWidgets) |
| 2220 |
textWidgetLocation = 1; // if at end, then tab around to first text widget |
| 2221 |
} |
| 2222 |
integer itextWidget = 0; |
| 2223 |
return _motif_getLocatedTextWidget (shell, & itextWidget, textWidgetLocation); |
| 2224 |
} |
| 2225 |
|
| 2226 |
static void on_scroll (GuiObject me, UINT part, int pos) { |
| 2227 |
if (my maximum == my minimum) |
| 2228 |
return; |
| 2229 |
switch (part) { |
| 2230 |
case SB_LINEUP: |
| 2231 |
my value -= my increment; |
| 2232 |
break; |
| 2233 |
case SB_LINEDOWN: |
| 2234 |
my value += my increment; |
| 2235 |
break; |
| 2236 |
case SB_PAGEUP: |
| 2237 |
my value -= my pageIncrement; |
| 2238 |
break; |
| 2239 |
case SB_PAGEDOWN: |
| 2240 |
my value += my pageIncrement; |
| 2241 |
break; |
| 2242 |
case SB_THUMBTRACK: |
| 2243 |
case SB_THUMBPOSITION: |
| 2244 |
my value = my minimum + pos * ((my maximum - my minimum - my sliderSize) / (32767.0 - (32767.0 * my sliderSize) / (my maximum - my minimum))); |
| 2245 |
break; |
| 2246 |
default: |
| 2247 |
break; |
| 2248 |
} |
| 2249 |
Melder_clip (my minimum, & my value, my maximum - my sliderSize); |
| 2250 |
NativeScrollBar_set (me); |
| 2251 |
if (part == SB_THUMBTRACK || part == SB_THUMBPOSITION) |
| 2252 |
_Gui_callCallbacks (me, & my motiff.scrollBar.dragCallbacks, (XtPointer) (ULONG_PTR) part); |
| 2253 |
else |
| 2254 |
_Gui_callCallbacks (me, & my motiff.scrollBar.valueChangedCallbacks, (XtPointer) (ULONG_PTR) part); |
| 2255 |
} |
| 2256 |
|
| 2257 |
void XtNextEvent (XEvent *xevent) { |
| 2258 |
GetMessage (xevent, NULL, 0, 0); |
| 2259 |
} |
| 2260 |
|
| 2261 |
static void processWorkProcsAndTimeOuts () { |
| 2262 |
if (theNumberOfWorkProcs != 0) |
| 2263 |
for (integer i = 9; i >= 1; i --) |
| 2264 |
if (theWorkProcs [i]) |
| 2265 |
if (theWorkProcs [i] (theWorkProcClosures [i])) |
| 2266 |
XtRemoveWorkProc (i); |
| 2267 |
if (theNumberOfTimeOuts != 0) { |
| 2268 |
const double now = Melder_clock (); |
| 2269 |
for (integer i = 1; i < 10; i ++) if (theTimeOutProcs [i]) { |
| 2270 |
static volatile double timeElapsed; |
| 2271 |
timeElapsed = now - theTimeOutStarts [i]; |
| 2272 |
if (timeElapsed > theTimeOutIntervals [i]) { |
| 2273 |
theTimeOutProcs [i] (theTimeOutClosures [i], & i); |
| 2274 |
XtRemoveTimeOut (i); |
| 2275 |
} |
| 2276 |
} |
| 2277 |
} |
| 2278 |
} |
| 2279 |
|
| 2280 |
void GuiNextEvent (XEvent *xevent) { |
| 2281 |
if (theNumberOfWorkProcs != 0 || theNumberOfTimeOuts != 0) { |
| 2282 |
if (PeekMessage (xevent, 0, 0, 0, PM_REMOVE)) { // Message available? |
| 2283 |
; // Hand message to XtDispatchEvent. |
| 2284 |
} else { |
| 2285 |
processWorkProcsAndTimeOuts (); // Handle chores during idle time. |
| 2286 |
xevent -> message = 0; // Hand null message to XtDispatchEvent. |
| 2287 |
} |
| 2288 |
} else GetMessage (xevent, NULL, 0, 0); // be neighbour-friendly: do not hand null events |
| 2289 |
} |
| 2290 |
|
| 2291 |
static GuiObject _motif_findDrawingArea (GuiObject me) { |
| 2292 |
if (my widgetClass == xmDrawingAreaWidgetClass) |
| 2293 |
return me; |
| 2294 |
for (GuiObject sub = my firstChild; sub != NULL; sub = sub -> nextSibling) |
| 2295 |
if (! MEMBER (sub, Shell)) { // only in same top window |
| 2296 |
GuiObject drawingArea = _motif_findDrawingArea (sub); |
| 2297 |
if (drawingArea) |
| 2298 |
return drawingArea; |
| 2299 |
} |
| 2300 |
return NULL; // no DrawingArea found |
| 2301 |
} |
| 2302 |
|
| 2303 |
static int win_shell_processKeyboardEquivalent (GuiObject me, int kar, int modifiers) { |
| 2304 |
//TRACE |
| 2305 |
for (int imenu = 1; imenu <= MAXIMUM_NUMBER_OF_MENUS; imenu ++) if (theMenus [imenu] && theMenus [imenu] -> shell == me) { |
| 2306 |
for (GuiObject child = theMenus [imenu] -> firstChild; child != NULL; child = child -> nextSibling) { |
| 2307 |
if ((child -> widgetClass == xmPushButtonWidgetClass || child -> widgetClass == xmToggleButtonWidgetClass) && |
| 2308 |
child -> motiff.pushButton.acceleratorChar == kar && |
| 2309 |
child -> motiff.pushButton.acceleratorModifiers == modifiers) { |
| 2310 |
if (child -> activateCallback && ! child -> insensitive) { |
| 2311 |
child -> activateCallback (child, child -> activateClosure, 0); |
| 2312 |
return 1; |
| 2313 |
} else if (child -> widgetClass == xmToggleButtonWidgetClass) { |
| 2314 |
XmToggleButtonGadgetSetState (child, 1 - XmToggleButtonGadgetGetState (child), False); |
| 2315 |
_Gui_callCallbacks (child, & child -> motiff.toggleButton.valueChangedCallbacks, 0); |
| 2316 |
return 1; |
| 2317 |
} |
| 2318 |
} |
| 2319 |
} |
| 2320 |
} |
| 2321 |
if (me && my shell) { |
| 2322 |
GuiObject drawingArea = _motif_findDrawingArea (my shell); |
| 2323 |
if (drawingArea) { |
| 2324 |
trace (U"kar5 ", kar); |
| 2325 |
if ((modifiers & _motif_COMMAND_MASK) && kar >= 'A' && kar <= 'Z' && ! (modifiers & _motif_SHIFT_MASK)) |
| 2326 |
kar += 'a' - 'A'; |
| 2327 |
if (kar == VK_RETURN) kar = 10; |
| 2328 |
if (kar == VK_LEFT) kar = 0x2190; |
| 2329 |
if (kar == VK_RIGHT) kar = 0x2192; |
| 2330 |
if (kar == VK_UP) kar = 0x2191; |
| 2331 |
if (kar == VK_DOWN) kar = 0x2193; |
| 2332 |
if (kar == VK_OEM_7) kar = '\''; |
| 2333 |
_GuiWinDrawingArea_handleKey (drawingArea, kar); // TODO: event -> key? |
| 2334 |
return 1; |
| 2335 |
} |
| 2336 |
} |
| 2337 |
return 0; |
| 2338 |
} |
| 2339 |
|
| 2340 |
static int win_processKeyboardEquivalent (GuiObject me, int kar, int modifiers) { |
| 2341 |
/* |
| 2342 |
* First try to send the key command to the active shell. |
| 2343 |
* If that fails, try to send the key command to the application shell. |
| 2344 |
*/ |
| 2345 |
if (win_shell_processKeyboardEquivalent (me, kar, modifiers)) |
| 2346 |
return 1; |
| 2347 |
if (win_shell_processKeyboardEquivalent (theApplicationShell, kar, modifiers)) |
| 2348 |
return 1; |
| 2349 |
return 0; |
| 2350 |
} |
| 2351 |
|
| 2352 |
void XtDispatchEvent (XEvent *xevent) { |
| 2353 |
//TRACE |
| 2354 |
MSG *message = (MSG *) xevent; |
| 2355 |
if (message -> message == 0) |
| 2356 |
return; // null message from PeekMessage during work proc or time out. |
| 2357 |
if (message -> message == WM_APP_WORK_PROC) { |
| 2358 |
auto *container = reinterpret_cast <GuiWinWorkProcWrapper_base *> (message -> lParam); |
| 2359 |
try { |
| 2360 |
container -> run (); |
| 2361 |
} catch (MelderError) { |
| 2362 |
Melder_flushError (); // no error message should leave the event loop |
| 2363 |
} |
| 2364 |
delete container; // called even if there was an exception |
| 2365 |
return; |
| 2366 |
} |
| 2367 |
/*if (message -> message == WM_KEYDOWN || message -> message == WM_SYSKEYDOWN) |
| 2368 |
{ |
| 2369 |
int kar = LOWORD (message -> wParam); |
| 2370 |
int modifiers = 0; |
| 2371 |
GuiObject me = (GuiObject) GetWindowLongPtr (message -> hwnd, GWLP_USERDATA); |
| 2372 |
if (GetKeyState (VK_CONTROL) < 0) modifiers |= _motif_COMMAND_MASK; |
| 2373 |
if (GetKeyState (VK_MENU) < 0) modifiers |= _motif_OPTION_MASK; |
| 2374 |
if (GetKeyState (VK_SHIFT) < 0) modifiers |= _motif_SHIFT_MASK; |
| 2375 |
if(kar>=48)Melder_flushError ("modifiers:%s%s%s\nmessage: %s\nkar: %d", |
| 2376 |
modifiers & _motif_COMMAND_MASK ? " control" : "", |
| 2377 |
modifiers & _motif_OPTION_MASK ? " alt" : "", |
| 2378 |
modifiers & _motif_SHIFT_MASK ? " shift" : "", message -> message == WM_KEYDOWN ? "keydown" : "syskeydown", kar); |
| 2379 |
}*/ |
| 2380 |
/* |
| 2381 |
* Intercept accelerators, which may be function keys or Command combinations. |
| 2382 |
* Some Alt-GR combinations denote special characters (e.g. backslash) on some (e.g. German) keyboards; |
| 2383 |
* in such a case, the message is WM_KEYDOWN, and the reported modifier keys are Control (!) and Alt |
| 2384 |
* (on a German keyboard, the backslash can be generated by Ctrl-Alt-ringel-s as well); |
| 2385 |
* otherwise Alt keys give WM_SYSKEYDOWN messages. |
| 2386 |
*/ |
| 2387 |
if (message -> message == WM_KEYDOWN && (GetKeyState (VK_CONTROL) < 0 || ! (message -> lParam & (1<<29))) || |
| 2388 |
message -> message == WM_SYSKEYDOWN && GetKeyState (VK_MENU) < 0 |
| 2389 |
&& (message -> lParam & (1<<29)) || // R&N 413: Alt key is pressed |
| 2390 |
message -> message == WM_SYSKEYDOWN && GetKeyState (VK_CONTROL) < 0) |
| 2391 |
{ |
| 2392 |
int kar = LOWORD (message -> wParam); |
| 2393 |
trace (U"kar1 ", kar); |
| 2394 |
GuiObject me = (GuiObject) GetWindowLongPtr (message -> hwnd, GWLP_USERDATA); |
| 2395 |
int modifiers = 0; |
| 2396 |
if (GetKeyState (VK_CONTROL) < 0) |
| 2397 |
modifiers |= _motif_COMMAND_MASK; |
| 2398 |
if (GetKeyState (VK_MENU) < 0) |
| 2399 |
modifiers |= _motif_OPTION_MASK; |
| 2400 |
if (GetKeyState (VK_SHIFT) < 0) |
| 2401 |
modifiers |= _motif_SHIFT_MASK; |
| 2402 |
/*if(kar>=48)Melder_casual ("modifiers:%s%s%s\nmessage: %s\nkar: %d", |
| 2403 |
modifiers & _motif_COMMAND_MASK ? " control" : "", |
| 2404 |
modifiers & _motif_OPTION_MASK ? " alt" : "", |
| 2405 |
modifiers & _motif_SHIFT_MASK ? " shift" : "", message -> message == WM_KEYDOWN ? "keydown" : "syskeydown", kar);*/ |
| 2406 |
if (me && my shell) { |
| 2407 |
uint32 acc = my shell -> motiff.shell.lowAccelerators [modifiers]; |
| 2408 |
//if (kar != VK_CONTROL) Melder_casual ("%d %d", acc, kar); |
| 2409 |
if (kar < 48) { |
| 2410 |
if (kar == VK_BACK) { // shortcut or text |
| 2411 |
if (acc & 1 << GuiMenu_BACKSPACE) { win_processKeyboardEquivalent (my shell, GuiMenu_BACKSPACE, modifiers); return; } |
| 2412 |
} else if (kar == VK_TAB) { // shortcut or text |
| 2413 |
if (acc & 1 << GuiMenu_TAB) { win_processKeyboardEquivalent (my shell, GuiMenu_TAB, modifiers); return; } |
| 2414 |
} else if (kar == VK_RETURN) { // shortcut, default button, or text |
| 2415 |
//Melder_information (U"RETURN ", acc, U" def ", Melder_pointer (my shell -> defaultButton)); |
| 2416 |
if (acc & 1 << GuiMenu_ENTER) { win_processKeyboardEquivalent (my shell, GuiMenu_ENTER, modifiers); return; } |
| 2417 |
else { |
| 2418 |
if (my shell -> defaultButton && _GuiWinButton_tryToHandleShortcutKey (my shell -> defaultButton)) return; |
| 2419 |
} |
| 2420 |
} else if (kar == VK_ESCAPE) { // shortcut or cancel button (and from 2024-04-06:) or text |
| 2421 |
if (acc & 1 << GuiMenu_ESCAPE) { win_processKeyboardEquivalent (my shell, GuiMenu_ESCAPE, modifiers); return; } |
| 2422 |
else { |
| 2423 |
if (my shell -> cancelButton && _GuiWinButton_tryToHandleShortcutKey (my shell -> cancelButton)) return; |
| 2424 |
} |
| 2425 |
//return; // this return has been here from before 2002; don't know why an Escape cannot be text (Demo wants it) |
| 2426 |
} else if (kar == VK_PRIOR) { // shortcut or text |
| 2427 |
if (acc & 1 << GuiMenu_PAGE_UP) { win_processKeyboardEquivalent (my shell, GuiMenu_PAGE_UP, modifiers); return; } |
| 2428 |
} else if (kar == VK_NEXT) { // shortcut or text |
| 2429 |
if (acc & 1 << GuiMenu_PAGE_DOWN) { win_processKeyboardEquivalent (my shell, GuiMenu_PAGE_DOWN, modifiers); return; } |
| 2430 |
} else if (kar == VK_HOME) { // shortcut or text |
| 2431 |
if (acc & 1 << GuiMenu_HOME) { win_processKeyboardEquivalent (my shell, GuiMenu_HOME, modifiers); return; } |
| 2432 |
} else if (kar == VK_END) { // shortcut or text |
| 2433 |
if (acc & 1 << GuiMenu_END) { win_processKeyboardEquivalent (my shell, GuiMenu_END, modifiers); return; } |
| 2434 |
} else if (kar == VK_LEFT) { // shortcut or text |
| 2435 |
if (acc & 1 << GuiMenu_LEFT_ARROW) { win_processKeyboardEquivalent (my shell, GuiMenu_LEFT_ARROW, modifiers); return; } |
| 2436 |
} else if (kar == VK_RIGHT) { // shortcut or text |
| 2437 |
if (acc & 1 << GuiMenu_RIGHT_ARROW) { win_processKeyboardEquivalent (my shell, GuiMenu_RIGHT_ARROW, modifiers); return; } |
| 2438 |
} else if (kar == VK_UP) { // shortcut or text |
| 2439 |
if (acc & 1 << GuiMenu_UP_ARROW) { win_processKeyboardEquivalent (my shell, GuiMenu_UP_ARROW, modifiers); return; } |
| 2440 |
} else if (kar == VK_DOWN) { // shortcut or text |
| 2441 |
if (acc & 1 << GuiMenu_DOWN_ARROW) { win_processKeyboardEquivalent (my shell, GuiMenu_DOWN_ARROW, modifiers); return; } |
| 2442 |
} else if (kar == VK_INSERT) { // shortcut |
| 2443 |
win_processKeyboardEquivalent (my shell, GuiMenu_INSERT, modifiers); |
| 2444 |
return; |
| 2445 |
} else if (kar == VK_DELETE) { // shortcut or text |
| 2446 |
if (acc & 1 << GuiMenu_DELETE) { win_processKeyboardEquivalent (my shell, GuiMenu_DELETE, modifiers); return; } |
| 2447 |
} else if (kar == VK_HELP) { // simulate Command-? |
| 2448 |
win_processKeyboardEquivalent (my shell, '?', modifiers | _motif_SHIFT_MASK); |
| 2449 |
return; |
| 2450 |
} |
| 2451 |
} else if (kar >= VK_F1 && kar <= VK_F12) { /* 112...123 */ |
| 2452 |
/* |
| 2453 |
* She has pressed one of the F keys. |
| 2454 |
*/ |
| 2455 |
if (win_processKeyboardEquivalent (my shell, kar - VK_F1 + GuiMenu_F1, modifiers)) return; |
| 2456 |
/* Let windowProc handle Alt-F4 etc. */ |
| 2457 |
/* |
| 2458 |
* If the Command key is pressed with a printable character, this is often a menu shortcut. |
| 2459 |
*/ |
| 2460 |
} else if ((modifiers & _motif_COMMAND_MASK) && ! (modifiers & _motif_OPTION_MASK)) { |
| 2461 |
if (MEMBER (me, Text) && (kar == 'X' || kar == 'C' || kar == 'V' || kar == 'Z')) { |
| 2462 |
; // let window proc handle text editing |
| 2463 |
} else if (kar >= 186) { |
| 2464 |
const int shift = modifiers & _motif_SHIFT_MASK; |
| 2465 |
/* |
| 2466 |
* BUG: The following is not internationally correct. |
| 2467 |
*/ |
| 2468 |
if (kar == 186 && win_processKeyboardEquivalent (my shell, shift ? ':' : ';', modifiers) || |
| 2469 |
kar == 187 && win_processKeyboardEquivalent (my shell, shift ? '+' : '=', modifiers) || |
| 2470 |
kar == 188 && win_processKeyboardEquivalent (my shell, shift ? '<' : ',', modifiers) || |
| 2471 |
kar == 189 && win_processKeyboardEquivalent (my shell, shift ? '_' : '-', modifiers) || |
| 2472 |
kar == 190 && win_processKeyboardEquivalent (my shell, shift ? '>' : '.', modifiers) || |
| 2473 |
kar == 191 && win_processKeyboardEquivalent (my shell, shift ? '?' : '/', modifiers) || |
| 2474 |
kar == 192 && win_processKeyboardEquivalent (my shell, shift ? '~' : '`', modifiers) || |
| 2475 |
kar == 219 && win_processKeyboardEquivalent (my shell, shift ? '{' : '[', modifiers) || // Alt-GR-ringel-s is here |
| 2476 |
kar == 220 && win_processKeyboardEquivalent (my shell, shift ? '|' : '\\', modifiers) || |
| 2477 |
kar == 221 && win_processKeyboardEquivalent (my shell, shift ? '}' : ']', modifiers) || |
| 2478 |
kar == 222 && win_processKeyboardEquivalent (my shell, shift ? '\"' : '\'', modifiers)) |
| 2479 |
{ |
| 2480 |
return; |
| 2481 |
} |
| 2482 |
} else { |
| 2483 |
if (win_processKeyboardEquivalent (my shell, kar, modifiers)) |
| 2484 |
return; // handle shortcuts like Ctrl-T (but not Ctrl-Alt-T, because of Alt_GR on some keyboards) |
| 2485 |
/* Let window proc handle international Alt-GR (= Ctrl-Alt) sequences, which are plain characters. */ |
| 2486 |
} |
| 2487 |
} |
| 2488 |
/* Other characters: to text. */ |
| 2489 |
} |
| 2490 |
/* Not me or not my shell: let windowProc handle. */ |
| 2491 |
} else if (message -> message == WM_CHAR) { |
| 2492 |
int kar = LOWORD (message -> wParam); |
| 2493 |
/* |
| 2494 |
* Catch character messages to push buttons and toggle buttons: |
| 2495 |
* divert them to a drawing area, if possible. |
| 2496 |
*/ |
| 2497 |
GuiObject me = (GuiObject) GetWindowLongPtr (message -> hwnd, GWLP_USERDATA); |
| 2498 |
if (me && MEMBER2 (me, PushButton, ToggleButton)) { |
| 2499 |
GuiObject drawingArea = _motif_findDrawingArea (my shell); |
| 2500 |
if (drawingArea) { |
| 2501 |
trace (U"kar2 ", kar); |
| 2502 |
if (kar == VK_RETURN) kar = 10; |
| 2503 |
if (kar == VK_LEFT) kar = 0x2190; |
| 2504 |
if (kar == VK_RIGHT) kar = 0x2192; |
| 2505 |
if (kar == VK_UP) kar = 0x2191; |
| 2506 |
if (kar == VK_DOWN) kar = 0x2193; |
| 2507 |
if (kar == VK_OEM_7) kar = '\''; |
| 2508 |
_GuiWinDrawingArea_handleKey (drawingArea, kar); // TODO: event -> key? |
| 2509 |
return; |
| 2510 |
} |
| 2511 |
} |
| 2512 |
/* |
| 2513 |
* Next, try tab navigation. |
| 2514 |
*/ |
| 2515 |
if (me && MEMBER (me, Text) && kar == 9) { |
| 2516 |
trace (U"Tab navigation with shell ", Melder_pointer (my shell), U" and from text widget ", Melder_pointer (me)); |
| 2517 |
GuiObject nextTextWidget = _motif_getNextTextWidget (my shell, me, GetKeyState (VK_SHIFT) < 0); |
| 2518 |
trace (U"Tab navigation to text widget ", Melder_pointer (nextTextWidget)); |
| 2519 |
if (nextTextWidget != NULL) { |
| 2520 |
_GuiText_setTheTextFocus (nextTextWidget); |
| 2521 |
GuiText_setSelection ((GuiText) nextTextWidget -> userData, 0, 10000000); |
| 2522 |
return; |
| 2523 |
} |
| 2524 |
} |
| 2525 |
} else if (message -> message == WM_LBUTTONDOWN) { |
| 2526 |
/* |
| 2527 |
* Catch mouse-down messages to cascade buttons: |
| 2528 |
* post the associated menu, if any. |
| 2529 |
*/ |
| 2530 |
GuiObject me = (GuiObject) GetWindowLongPtr (message -> hwnd, GWLP_USERDATA); |
| 2531 |
//Melder_information (Melder_pointer (me), U" -- ", Melder_pointer (my subMenuId)); |
| 2532 |
if (me && MEMBER (me, CascadeButton) && my subMenuId) { |
| 2533 |
RECT rect; |
| 2534 |
GetWindowRect (my window, & rect); |
| 2535 |
TrackPopupMenu (my subMenuId -> nat.menu.handle, TPM_LEFTBUTTON | |
| 2536 |
TPM_LEFTALIGN | TPM_TOPALIGN, rect.left, rect.bottom - 3, 0, my parent -> window, NULL); |
| 2537 |
return; |
| 2538 |
} |
| 2539 |
} |
| 2540 |
TranslateMessage (xevent); // Generate WM_CHAR messages. |
| 2541 |
DispatchMessage (xevent); |
| 2542 |
} |
| 2543 |
|
| 2544 |
void GuiMainLoop () { |
| 2545 |
for (;;) { |
| 2546 |
XEvent event; |
| 2547 |
GuiNextEvent (& event); |
| 2548 |
XtDispatchEvent (& event); |
| 2549 |
} |
| 2550 |
} |
| 2551 |
|
| 2552 |
#define main wingwmain |
| 2553 |
extern int main (int argc, char *argv []); |
| 2554 |
int APIENTRY WinMain (HINSTANCE instance, HINSTANCE /*previousInstance*/, LPSTR commandLine, int commandShow) { |
| 2555 |
trace (U"Entering WinMain"); |
| 2556 |
theGui.instance = instance; |
| 2557 |
theGui.commandShow = commandShow; |
| 2558 |
int argc; |
| 2559 |
WCHAR** argvW = CommandLineToArgvW (GetCommandLineW (), & argc); |
| 2560 |
char** argv = Melder_malloc (char*, argc); |
| 2561 |
for (int iarg = 0; iarg < argc; iarg ++) |
| 2562 |
argv [iarg] = Melder_32to8 (Melder_peekWto32 (argvW [iarg])).transfer(); |
| 2563 |
/* |
| 2564 |
It cannot hurt to establish the current thread as the GUI thread, |
| 2565 |
by calling one event-loop function (without further side effects). |
| 2566 |
Perhaps this will help later calls to PostMessage(). |
| 2567 |
*/ |
| 2568 |
{ |
| 2569 |
MSG dummy; |
| 2570 |
PeekMessage (& dummy, nullptr, 0, 0, PM_NOREMOVE); |
| 2571 |
} |
| 2572 |
return main (argc, argv); |
| 2573 |
} |
| 2574 |
|
| 2575 |
static void on_close (HWND window) { |
| 2576 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2577 |
if (me) { |
| 2578 |
if (my widgetClass == xmShellWidgetClass) { |
| 2579 |
int deleteResponse = my deleteResponse; // save this, in case the callback should kill the widget (XmDO_NOTHING) |
| 2580 |
GuiObject parent = my parent; |
| 2581 |
if (my motiff.shell.goAwayCallback) |
| 2582 |
my motiff.shell.goAwayCallback (me, my motiff.shell.goAwayClosure, NULL); |
| 2583 |
if (deleteResponse == XmDESTROY) { |
| 2584 |
XtDestroyWidget (me); |
| 2585 |
} else if (deleteResponse == XmUNMAP) { |
| 2586 |
/* |
| 2587 |
Unmapping is not the same as unmanaging. |
| 2588 |
One of the oldest bugs in Praat was that in the Windows edition |
| 2589 |
the Picture window could not be closed a second time, |
| 2590 |
and that after it had been closed and opened the scroll bars did not move when |
| 2591 |
the user resized the window. |
| 2592 |
The solution was to use only some of the code from XtUnmanageChild here, |
| 2593 |
without clearing the 'managed' attribute. |
| 2594 |
*/ |
| 2595 |
_GuiText_handleFocusLoss (my textFocus); |
| 2596 |
ShowWindow (my window, SW_HIDE); |
| 2597 |
} |
| 2598 |
return; |
| 2599 |
} else FORWARD_WM_CLOSE (window, DefWindowProc); |
| 2600 |
} else FORWARD_WM_CLOSE (window, DefWindowProc); |
| 2601 |
} |
| 2602 |
static GuiObject findItem (GuiObject menu, int id) { |
| 2603 |
GuiObject child = menu -> firstChild; |
| 2604 |
for (child = menu -> firstChild; child != NULL; child = child -> nextSibling) { |
| 2605 |
if (child -> widgetClass == xmPulldownMenuWidgetClass) { |
| 2606 |
GuiObject result = findItem (child, id); |
| 2607 |
if (result) |
| 2608 |
return result; |
| 2609 |
} else { |
| 2610 |
Melder_assert (MEMBER4 (child, PushButton, ToggleButton, CascadeButton, Separator)); |
| 2611 |
if (child -> nat.entry.id == id) |
| 2612 |
return child; |
| 2613 |
} |
| 2614 |
} |
| 2615 |
return NULL; |
| 2616 |
} |
| 2617 |
static void on_command (HWND window, int id, HWND controlWindow, UINT codeNotify) { |
| 2618 |
GuiObject parent = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2619 |
if (parent) { |
| 2620 |
if (controlWindow) { |
| 2621 |
GuiObject control = (GuiObject) GetWindowLongPtr (controlWindow, GWLP_USERDATA); |
| 2622 |
if (control) { |
| 2623 |
switch (control -> widgetClass) { |
| 2624 |
/* |
| 2625 |
* Clicking on a button takes away the focus from a text widget. |
| 2626 |
* We have already been notified of that by EN_KILLFOCUS. |
| 2627 |
* We have to put the focus back (see GuiText.c, parenthesized discussion 1.4); |
| 2628 |
* this has to be done before calling the callbacks, because these may destroy or hide the text widget. |
| 2629 |
*/ |
| 2630 |
case xmPushButtonWidgetClass: |
| 2631 |
/* |
| 2632 |
* If EN_KILLFOCUS had not cleared the global text focus, |
| 2633 |
* the following message would not actually do SetFocus! |
| 2634 |
*/ |
| 2635 |
_GuiText_setTheTextFocus (control -> shell -> textFocus); |
| 2636 |
_GuiWinButton_handleClick (control); |
| 2637 |
break; |
| 2638 |
case xmToggleButtonWidgetClass: |
| 2639 |
_GuiText_setTheTextFocus (control -> shell -> textFocus); |
| 2640 |
if (control -> isRadioButton) |
| 2641 |
_GuiWinRadioButton_handleClick (control); |
| 2642 |
else |
| 2643 |
_GuiWinCheckButton_handleClick (control); |
| 2644 |
break; |
| 2645 |
case xmListWidgetClass: |
| 2646 |
if (codeNotify == LBN_SELCHANGE) { |
| 2647 |
_GuiWinList_handleClick (control); |
| 2648 |
} else FORWARD_WM_COMMAND (window, id, controlWindow, codeNotify, DefWindowProc); |
| 2649 |
break; |
| 2650 |
case xmTextWidgetClass: |
| 2651 |
if (codeNotify == EN_CHANGE) |
| 2652 |
_GuiText_handleValueChanged (control); |
| 2653 |
else if (codeNotify == EN_SETFOCUS) |
| 2654 |
_GuiText_handleFocusReception (control); |
| 2655 |
else if (codeNotify == EN_KILLFOCUS) |
| 2656 |
_GuiText_handleFocusLoss (control); // for button clicks (see above) |
| 2657 |
break; |
| 2658 |
default: |
| 2659 |
break; |
| 2660 |
} |
| 2661 |
} else FORWARD_WM_COMMAND (window, id, controlWindow, codeNotify, DefWindowProc); |
| 2662 |
} else { // menu choice |
| 2663 |
GuiObject menuBar = NULL; |
| 2664 |
if (MEMBER (parent, Shell)) |
| 2665 |
menuBar = parent -> nat.shell.menuBar; |
| 2666 |
else if (MEMBER (parent, RowColumn)) |
| 2667 |
menuBar = parent; |
| 2668 |
if (menuBar) { |
| 2669 |
GuiObject item = findItem (menuBar, id); |
| 2670 |
if (item) { |
| 2671 |
if (item -> widgetClass == xmPushButtonWidgetClass) { |
| 2672 |
if (item -> activateCallback) |
| 2673 |
item -> activateCallback (item, item -> activateClosure, 0); |
| 2674 |
} else if (item -> widgetClass == xmToggleButtonWidgetClass) { |
| 2675 |
XmToggleButtonGadgetSetState (item, 1 - XmToggleButtonGadgetGetState (item), False); |
| 2676 |
_Gui_callCallbacks (item, & item -> motiff.toggleButton.valueChangedCallbacks, 0); |
| 2677 |
} |
| 2678 |
} |
| 2679 |
} |
| 2680 |
} |
| 2681 |
} else FORWARD_WM_COMMAND (window, id, controlWindow, codeNotify, DefWindowProc); |
| 2682 |
} |
| 2683 |
static void on_destroy (HWND window) { |
| 2684 |
(void) window; |
| 2685 |
} |
| 2686 |
static void on_lbuttonDown (HWND window, BOOL doubleClick, int x, int y, UINT flags) { |
| 2687 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2688 |
if (me) { |
| 2689 |
if (MEMBER (me, DrawingArea)) { |
| 2690 |
SetCapture (window); |
| 2691 |
_GuiWinDrawingArea_handleMouse (me, structGuiDrawingArea_MouseEvent::Phase::CLICK, x, y); |
| 2692 |
} else FORWARD_WM_LBUTTONDOWN (window, doubleClick, x, y, flags, DefWindowProc); |
| 2693 |
} else FORWARD_WM_LBUTTONDOWN (window, doubleClick, x, y, flags, DefWindowProc); |
| 2694 |
} |
| 2695 |
static void on_mouseMove (HWND window, int x, int y, UINT flags) { |
| 2696 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2697 |
if (me) { |
| 2698 |
if (MEMBER (me, DrawingArea) && (flags & MK_LBUTTON)) { |
| 2699 |
_GuiWinDrawingArea_handleMouse (me, structGuiDrawingArea_MouseEvent::Phase::DRAG, x, y); |
| 2700 |
} else FORWARD_WM_MOUSEMOVE (window, x, y, flags, DefWindowProc); |
| 2701 |
} else FORWARD_WM_MOUSEMOVE (window, x, y, flags, DefWindowProc); |
| 2702 |
} |
| 2703 |
static void on_lbuttonUp (HWND window, int x, int y, UINT flags) { |
| 2704 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2705 |
if (me) { |
| 2706 |
if (MEMBER (me, DrawingArea)) { |
| 2707 |
ReleaseCapture (); |
| 2708 |
_GuiWinDrawingArea_handleMouse (me, structGuiDrawingArea_MouseEvent::Phase::DROP, x, y); |
| 2709 |
} else FORWARD_WM_LBUTTONUP (window, x, y, flags, DefWindowProc); |
| 2710 |
} else FORWARD_WM_LBUTTONUP (window, x, y, flags, DefWindowProc); |
| 2711 |
} |
| 2712 |
static void on_paint (HWND window) { |
| 2713 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2714 |
if (me) { |
| 2715 |
if (my widgetClass == xmDrawingAreaWidgetClass) { |
| 2716 |
_GuiWinDrawingArea_update (me); |
| 2717 |
} else FORWARD_WM_PAINT (window, DefWindowProc); |
| 2718 |
} else FORWARD_WM_PAINT (window, DefWindowProc); |
| 2719 |
} |
| 2720 |
static void on_hscroll (HWND window, HWND controlWindow, UINT code, int pos) { |
| 2721 |
GuiObject parent = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2722 |
if (parent) { |
| 2723 |
GuiObject control = (GuiObject) GetWindowLongPtr (controlWindow, GWLP_USERDATA); |
| 2724 |
if (control) { |
| 2725 |
on_scroll (control, code, pos); |
| 2726 |
} else FORWARD_WM_HSCROLL (window, controlWindow, code, pos, DefWindowProc); |
| 2727 |
} else FORWARD_WM_HSCROLL (window, controlWindow, code, pos, DefWindowProc); |
| 2728 |
} |
| 2729 |
static void on_vscroll (HWND window, HWND controlWindow, UINT code, int pos) { |
| 2730 |
GuiObject parent = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2731 |
if (parent) { |
| 2732 |
GuiObject control = (GuiObject) GetWindowLongPtr (controlWindow, GWLP_USERDATA); |
| 2733 |
if (control) { |
| 2734 |
on_scroll (control, code, pos); |
| 2735 |
} else FORWARD_WM_VSCROLL (window, controlWindow, code, pos, DefWindowProc); |
| 2736 |
} else FORWARD_WM_VSCROLL (window, controlWindow, code, pos, DefWindowProc); |
| 2737 |
} |
| 2738 |
#undef FORWARD_WM_MOUSEWHEEL // bug in our windowsx.h |
| 2739 |
#define FORWARD_WM_MOUSEWHEEL(hwnd,xPos,yPos,zDelta,fwKeys,fn) \ |
| 2740 |
(void)(fn)((hwnd),WM_MOUSEWHEEL,MAKEWPARAM((fwKeys),(zDelta)),MAKELPARAM((xPos),(yPos))) |
| 2741 |
//#define HANDLE_WM_MOUSEWHEEL(hwnd,wParam,lParam,fn) \ |
| 2742 |
((fn)((hwnd),(int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),(int)(short)HIWORD(wParam),(UINT)(short)LOWORD(wParam)),(LRESULT)0) |
| 2743 |
static void on_mouseWheel (HWND window, int xPos, int yPos, int zDelta, int fwKeys) { |
| 2744 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2745 |
if (me) { |
| 2746 |
if (my widgetClass == xmDrawingAreaWidgetClass) { |
| 2747 |
const bool isHorizontal = ( fwKeys & MK_SHIFT ); |
| 2748 |
const int direction = ( isHorizontal ? ( zDelta < 0 ? SB_LINELEFT : SB_LINERIGHT ) : ( zDelta < 0 ? SB_LINEDOWN : SB_LINEUP ) ); |
| 2749 |
const bool controlKeyPressed = ( fwKeys & MK_CONTROL ); |
| 2750 |
if (controlKeyPressed) { |
| 2751 |
_GuiWinDrawingArea_handleZoom (me, double (zDelta) / 10.0); |
| 2752 |
} else if (my parent -> widgetClass == xmScrolledWindowWidgetClass) { |
| 2753 |
on_scroll (isHorizontal ? my parent -> motiff.scrolledWindow.horizontalBar : my parent -> motiff.scrolledWindow.verticalBar, direction, 0); |
| 2754 |
} else if (isHorizontal) { |
| 2755 |
for (GuiObject child = my parent -> firstChild; child; child = child -> nextSibling) |
| 2756 |
if (child -> widgetClass == xmScrollBarWidgetClass && child -> orientation == XmHORIZONTAL) |
| 2757 |
on_scroll (child, direction, 0); |
| 2758 |
} else { |
| 2759 |
for (GuiObject child = my parent -> firstChild; child; child = child -> nextSibling) |
| 2760 |
if (child -> widgetClass == xmScrollBarWidgetClass && child -> orientation == XmVERTICAL) |
| 2761 |
on_scroll (child, direction, 0); |
| 2762 |
} |
| 2763 |
} else FORWARD_WM_MOUSEWHEEL (window, xPos, yPos, zDelta, fwKeys, DefWindowProc); |
| 2764 |
} else FORWARD_WM_MOUSEWHEEL (window, xPos, yPos, zDelta, fwKeys, DefWindowProc); |
| 2765 |
} |
| 2766 |
static void on_size (HWND window, UINT state, int cx, int cy) { |
| 2767 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2768 |
if (me && MEMBER (me, Shell) && (state == SIZE_RESTORED || state == SIZE_MAXIMIZED)) { |
| 2769 |
const int oldWidth = my width, oldHeight = my height; |
| 2770 |
const int newWidth = cx; |
| 2771 |
const int newHeight = cy; |
| 2772 |
my width = newWidth; |
| 2773 |
my height = newHeight; |
| 2774 |
FORWARD_WM_SIZE (window, state, cx, cy, DefWindowProc); |
| 2775 |
if (! my managed) { |
| 2776 |
} else if (my nat.shell.duringMoveWindow) // Yeah, a BUG fix. Only react to user actions. |
| 2777 |
my nat.shell.duringMoveWindow = False; |
| 2778 |
else if (newWidth != oldWidth || newHeight != oldHeight) { |
| 2779 |
shellResizeWidget (me, 0, 0, newWidth - oldWidth, newHeight - oldHeight); |
| 2780 |
} |
| 2781 |
} else FORWARD_WM_SIZE (window, state, cx, cy, DefWindowProc); |
| 2782 |
} |
| 2783 |
static void on_key (HWND window, UINT key, BOOL down, int repeat, UINT flags) { |
| 2784 |
//TRACE |
| 2785 |
trace (U"KEY ", key); |
| 2786 |
Melder_assert (down == true); |
| 2787 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2788 |
if (me && key >= VK_LEFT && key <= VK_DOWN) { |
| 2789 |
//Melder_warning (U"Widget type ", my widgetClass); |
| 2790 |
if (MEMBER (me, Shell) || my widgetClass == xmDrawingAreaWidgetClass) { // any change in this condition should be mirrored in `on_char` |
| 2791 |
GuiObject drawingArea = _motif_findDrawingArea (me); |
| 2792 |
if (drawingArea) { |
| 2793 |
GuiObject textFocus = drawingArea -> shell -> textFocus; // BUG: ignore? |
| 2794 |
trace (U"kar3 ", key); |
| 2795 |
if (key == VK_RETURN) key = 10; |
| 2796 |
if (key == VK_LEFT) key = 0x2190; |
| 2797 |
if (key == VK_RIGHT) key = 0x2192; |
| 2798 |
if (key == VK_UP) key = 0x2191; |
| 2799 |
if (key == VK_DOWN) key = 0x2193; |
| 2800 |
if (key == VK_OEM_7) key = '\''; |
| 2801 |
_GuiWinDrawingArea_handleKey (drawingArea, key); |
| 2802 |
} else { |
| 2803 |
FORWARD_WM_KEYDOWN (window, key, repeat, flags, DefWindowProc); |
| 2804 |
} |
| 2805 |
} else FORWARD_WM_KEYDOWN (window, key, repeat, flags, DefWindowProc); |
| 2806 |
} else { |
| 2807 |
FORWARD_WM_KEYDOWN (window, key, repeat, flags, DefWindowProc); |
| 2808 |
} |
| 2809 |
} |
| 2810 |
static void on_char (HWND window, TCHAR kar, int repeat) { |
| 2811 |
//TRACE |
| 2812 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2813 |
if (me) { |
| 2814 |
if (MEMBER (me, Shell) || my widgetClass == xmDrawingAreaWidgetClass) { // any change in this condition should be mirrored in `on_key` |
| 2815 |
GuiObject drawingArea = _motif_findDrawingArea (me); |
| 2816 |
if (drawingArea) { |
| 2817 |
GuiObject textFocus = drawingArea -> shell -> textFocus; // BUG: ignore? |
| 2818 |
trace (U"kar4 ", kar); |
| 2819 |
_GuiWinDrawingArea_handleKey (drawingArea, kar); |
| 2820 |
} else { |
| 2821 |
FORWARD_WM_CHAR (window, kar, repeat, DefWindowProc); |
| 2822 |
} |
| 2823 |
} else FORWARD_WM_CHAR (window, kar, repeat, DefWindowProc); |
| 2824 |
} else { |
| 2825 |
FORWARD_WM_CHAR (window, kar, repeat, DefWindowProc); |
| 2826 |
} |
| 2827 |
} |
| 2828 |
static void on_move (HWND window, int x, int y) { |
| 2829 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2830 |
/*if (me && MEMBER (me, Shell)) { |
| 2831 |
my x = x - ( my motiff.shell.isDialog ? GetSystemMetrics (SM_CXFIXEDFRAME) : GetSystemMetrics (SM_CXSIZEFRAME) ); |
| 2832 |
my y = y - GetSystemMetrics (SM_CYCAPTION) - ( my motiff.shell.isDialog ? GetSystemMetrics (SM_CYFIXEDFRAME) : |
| 2833 |
GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYMENU) ); |
| 2834 |
}*/ |
| 2835 |
FORWARD_WM_MOVE (window, x, y, DefWindowProc); |
| 2836 |
} |
| 2837 |
static HBRUSH on_ctlColorStatic (HWND window, HDC hdc, HWND controlWindow, int type) { |
| 2838 |
GuiObject parent = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2839 |
(void) type; |
| 2840 |
if (parent) { |
| 2841 |
GuiObject control = (GuiObject) GetWindowLongPtr (controlWindow, GWLP_USERDATA); |
| 2842 |
if (control) { |
| 2843 |
SetBkMode (hdc, TRANSPARENT); |
| 2844 |
return theWinGuiBackgroundBrush (); |
| 2845 |
} |
| 2846 |
} |
| 2847 |
return FORWARD_WM_CTLCOLORSTATIC (window, hdc, controlWindow, DefWindowProc); |
| 2848 |
} |
| 2849 |
static HBRUSH on_ctlColorBtn (HWND window, HDC hdc, HWND controlWindow, int type) { |
| 2850 |
GuiObject parent = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2851 |
(void) type; |
| 2852 |
if (parent) { |
| 2853 |
GuiObject control = (GuiObject) GetWindowLongPtr (controlWindow, GWLP_USERDATA); |
| 2854 |
if (control) { |
| 2855 |
SetBkMode (hdc, TRANSPARENT); |
| 2856 |
return theWinGuiBackgroundBrush (); |
| 2857 |
} |
| 2858 |
} |
| 2859 |
return FORWARD_WM_CTLCOLORBTN (window, hdc, controlWindow, DefWindowProc); |
| 2860 |
} |
| 2861 |
static void on_activate (HWND window, UINT state, HWND hActive, BOOL minimized) { |
| 2862 |
GuiObject me = (GuiObject) GetWindowLongPtr (window, GWLP_USERDATA); |
| 2863 |
if (me && my widgetClass == xmShellWidgetClass) { |
| 2864 |
if (state == WA_INACTIVE || minimized) { |
| 2865 |
_GuiText_handleFocusLoss (my textFocus); |
| 2866 |
} else { |
| 2867 |
_GuiText_setTheTextFocus (my textFocus); |
| 2868 |
} |
| 2869 |
return; |
| 2870 |
} else FORWARD_WM_ACTIVATE (window, state, hActive, minimized, DefWindowProc); |
| 2871 |
} |
| 2872 |
static LRESULT CALLBACK windowProc (HWND window, UINT message, WPARAM wParam, LPARAM lParam) { |
| 2873 |
switch (message) { |
| 2874 |
HANDLE_MSG (window, WM_CLOSE, on_close); |
| 2875 |
HANDLE_MSG (window, WM_COMMAND, on_command); |
| 2876 |
HANDLE_MSG (window, WM_DESTROY, on_destroy); |
| 2877 |
HANDLE_MSG (window, WM_LBUTTONDOWN, on_lbuttonDown); |
| 2878 |
HANDLE_MSG (window, WM_LBUTTONDBLCLK, on_lbuttonDown); // double-click counts as two clicks |
| 2879 |
HANDLE_MSG (window, WM_LBUTTONUP, on_lbuttonUp); |
| 2880 |
HANDLE_MSG (window, WM_MOUSEMOVE, on_mouseMove); |
| 2881 |
HANDLE_MSG (window, WM_PAINT, on_paint); |
| 2882 |
HANDLE_MSG (window, WM_HSCROLL, on_hscroll); |
| 2883 |
HANDLE_MSG (window, WM_VSCROLL, on_vscroll); |
| 2884 |
HANDLE_MSG (window, WM_MOUSEWHEEL, on_mouseWheel); |
| 2885 |
HANDLE_MSG (window, WM_SIZE, on_size); |
| 2886 |
HANDLE_MSG (window, WM_KEYDOWN, on_key); |
| 2887 |
HANDLE_MSG (window, WM_CHAR, on_char); |
| 2888 |
HANDLE_MSG (window, WM_MOVE, on_move); |
| 2889 |
HANDLE_MSG (window, WM_CTLCOLORBTN, on_ctlColorBtn); |
| 2890 |
HANDLE_MSG (window, WM_CTLCOLORSTATIC, on_ctlColorStatic); |
| 2891 |
HANDLE_MSG (window, WM_ACTIVATE, on_activate); |
| 2892 |
#ifdef _WIN64 |
| 2893 |
case WM_POINTERWHEEL: { // from Windows 8 on |
| 2894 |
int zDelta = GET_WHEEL_DELTA_WPARAM (wParam); |
| 2895 |
int fwKeys = GET_KEYSTATE_WPARAM (wParam); |
| 2896 |
if (GetKeyState (VK_SHIFT) < 0) |
| 2897 |
fwKeys |= MK_SHIFT; |
| 2898 |
if (GetKeyState (VK_CONTROL) < 0) |
| 2899 |
fwKeys |= MK_CONTROL; |
| 2900 |
POINT point = { GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam) }; |
| 2901 |
ScreenToClient (window, & point); |
| 2902 |
on_mouseWheel (window, point.x, point.y, zDelta, fwKeys); |
| 2903 |
return 0; |
| 2904 |
} |
| 2905 |
case WM_POINTERHWHEEL: { // from Windows 8 on |
| 2906 |
int zDelta = GET_WHEEL_DELTA_WPARAM (wParam); |
| 2907 |
int fwKeys = GET_KEYSTATE_WPARAM (wParam) | MK_SHIFT; |
| 2908 |
POINT point = { GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam) }; |
| 2909 |
ScreenToClient (window, & point); |
| 2910 |
on_mouseWheel (window, point.x, point.y, zDelta, fwKeys); |
| 2911 |
return 0; |
| 2912 |
} |
| 2913 |
#endif |
| 2914 |
case WM_USER: // TODO: remove once Elan's sendpraat is updated to using WM_APP instead of WM_USER |
| 2915 |
case WM_APP: |
| 2916 |
{ |
| 2917 |
/*if (IsIconic (window)) ShowWindow (window, SW_RESTORE); |
| 2918 |
SetForegroundWindow (window);*/ |
| 2919 |
//TRACE |
| 2920 |
trace (U"app message ", message); |
| 2921 |
return theUserMessageCallback ? theUserMessageCallback () : 1; |
| 2922 |
} |
| 2923 |
default: return DefWindowProc (window, message, wParam, lParam); |
| 2924 |
} |
| 2925 |
} |
| 2926 |
void motif_win_setUserMessageCallback (int (*userMessageCallback) (void)) { |
| 2927 |
theUserMessageCallback = userMessageCallback; |
| 2928 |
} |
| 2929 |
|
| 2930 |
#endif // defined (_WIN32) |
| 2931 |
|
| 2932 |
/* End of file motifEmulator.cpp */ |