Changeset 31
- Timestamp:
- 04/06/07 07:20:40 (2 years ago)
- Files:
-
- trunk/src/ui.c (modified) (48 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ui.c
r30 r31 7 7 * incorporate modifications in all Angband variants as defined in the 8 8 * Angband variants FAQ. See rec.games.roguelike.angband for FAQ. 9 */ 9 */ 10 10 11 11 /* … … 48 48 /* forward declarations */ 49 49 static void display_menu_row(menu_type *menu, int pos, int top, 50 bool cursor, int row, int col, int width);50 bool cursor, int row, int col, int width); 51 51 52 52 /* =================== GEOMETRY ================= */ … … 57 57 int w = loc->width; 58 58 int h = loc->page_rows; 59 if(loc->width <= 0 || loc->page_rows <= 0) { 59 60 if (loc->width <= 0 || loc->page_rows <= 0) 61 { 60 62 Term_get_size(&w, &h); 61 if (loc->width <= 0) w -= loc->width;62 if (loc->page_rows <= 0) h -= loc->page_rows;63 } 64 for(i = 0; i < h; i++) { 65 Term_erase(loc->col, loc->row+i, w);66 }63 if (loc->width <= 0) w -= loc->width; 64 if (loc->page_rows <= 0) h -= loc->page_rows; 65 } 66 67 for (i = 0; i < h; i++) 68 Term_erase(loc->col, loc->row + i, w); 67 69 } 68 70 69 71 bool region_inside(const region *loc, const key_event *key) 70 72 { 71 if ((loc->col > key->mousex) || (loc->col + loc->width <= key->mousex))73 if ((loc->col > key->mousex) || (loc->col + loc->width <= key->mousex)) 72 74 return FALSE; 73 if((loc->row > key->mousey) || (loc->row + loc->page_rows <= key->mousey)) 75 76 if ((loc->row > key->mousey) || (loc->row + loc->page_rows <= key->mousey)) 74 77 return FALSE; 78 75 79 return TRUE; 76 80 } … … 89 93 { 90 94 key_event stop = { EVT_STOP }; 95 91 96 /* Stop right away! */ 92 97 Term_event_push(&stop); … … 105 110 * The first unhandled event - forever is false. 106 111 */ 107 key_event run_event_loop(event_target * target, bool forever, const key_event *start)112 key_event run_event_loop(event_target * target, bool forever, const key_event *start) 108 113 { 109 114 key_event ke; 110 115 bool handled = TRUE; 111 while (forever || handled) { 116 117 while (forever || handled) 118 { 112 119 listener_list *list = target->observers; 113 120 handled = FALSE; 114 if(start) ke = *start; 121 122 if (start) ke = *start; 115 123 else ke = inkey_ex(); 116 if(ke.type == EVT_STOP) 124 125 if (ke.type == EVT_STOP) 117 126 break; 118 127 119 if (ke.type & target->self.events.evt_flags)128 if (ke.type & target->self.events.evt_flags) 120 129 handled = target->self.handler(target->self.object, &ke); 121 130 122 if(!target->is_modal) { 123 while(list && !handled) { 124 if(ke.type & list->listener->events.evt_flags) { 131 if (!target->is_modal) 132 { 133 while (list && !handled) 134 { 135 if (ke.type & list->listener->events.evt_flags) 125 136 handled = list->listener->handler(list->listener->object, &ke); 126 } 137 127 138 list = list->next; 128 139 } 129 140 } 130 if(handled) start = NULL; 131 } 132 if(start) { 141 142 if (handled) start = NULL; 143 } 144 145 if (start) 146 { 133 147 ke.type = EVT_AGAIN; 134 148 ke.key = '\xff'; 135 149 } 150 136 151 return ke; 137 152 } 138 153 139 void add_listener(event_target * target, event_listener *observer)154 void add_listener(event_target * target, event_listener * observer) 140 155 { 141 156 listener_list *link; 157 142 158 MAKE(link, listener_list); 143 159 link->listener = observer; … … 146 162 } 147 163 148 void remove_listener(event_target * target, event_listener *observer)164 void remove_listener(event_target * target, event_listener * observer) 149 165 { 150 166 listener_list *cur = target->observers; 151 167 listener_list **prev = &target->observers; 152 while(cur) { 153 if(cur->listener == observer) { 168 169 while (cur) 170 { 171 if (cur->listener == observer) 172 { 154 173 *prev = cur->next; 155 174 FREE(cur); … … 157 176 } 158 177 } 178 159 179 bell("remove_listener: no such observer"); 160 180 } … … 165 185 166 186 /* Display an event, with possible preference overrides */ 167 static void display_event_aux(event_action *event, int menuID, byte color, 168 int row, int col, int wid) 187 static void display_event_aux(event_action *event, int menuID, byte color, int row, int col, int wid) 169 188 { 170 189 /* TODO: add preference support */ 171 190 /* TODO: wizard mode should show more data */ 172 191 Term_erase(col, row, wid); 173 if(event->name) { 192 193 if (event->name) 174 194 Term_putstr(col, row, wid, color, event->name); 175 } 176 } 177 178 static void display_event(menu_type *menu, int oid, bool cursor, 179 int row, int col, int width) 180 { 181 event_action *evts = (event_action*)menu->menu_data; 195 } 196 197 static void display_event(menu_type *menu, int oid, bool cursor, int row, int col, int width) 198 { 199 event_action *evts = (event_action *)menu->menu_data; 182 200 byte color = curs_attrs[CURS_KNOWN][0 != cursor]; 183 display_event_aux(&evts[oid], menu->target.self.object_id, color, row, col, width); 201 202 display_event_aux(&evts[oid], menu->target.self.object_id, color, row, col, 203 width); 184 204 } 185 205 … … 188 208 static bool handle_menu_item_event(char cmd, void *db, int oid) 189 209 { 190 event_action *evt = &((event_action*)db)[oid]; 191 if(cmd == '\xff' && evt->action) { 210 event_action *evt = &((event_action *)db)[oid]; 211 212 if (cmd == '\xff' && evt->action) 213 { 192 214 evt->action(evt->data, evt->name); 193 215 return TRUE; 194 216 } 195 else if(cmd == '\xff') 217 else if (cmd == '\xff') 218 { 196 219 return TRUE; 220 } 221 197 222 return FALSE; 198 223 } … … 200 225 static int valid_menu_event(menu_type *menu, int oid) 201 226 { 202 event_action *evts = (event_action *) menu->menu_data;227 event_action *evts = (event_action *)menu->menu_data; 203 228 return (NULL != evts[oid].name); 204 229 } 205 230 206 231 /* Virtual function table for action_events */ 207 static const menu_iter menu_iter_event = { 232 static const menu_iter menu_iter_event = 233 { 208 234 MN_EVT, 209 235 0, … … 218 244 static char tag_menu_item(menu_type *menu, int oid) 219 245 { 220 menu_item *items = (menu_item *) menu->menu_data;246 menu_item *items = (menu_item *)menu->menu_data; 221 247 return items[oid].sel; 222 248 } 223 249 224 static void display_menu_item(menu_type *menu, int oid, bool cursor, 225 int row, int col, int width) 226 { 227 menu_item *items = (menu_item *) menu->menu_data; 228 229 byte color = 230 curs_attrs[!(items[oid].flags & (MN_GRAYED))][0 != cursor]; 231 display_event_aux(&items[oid].evt, menu->target.self.object_id, color, row, col, width); 250 static void display_menu_item(menu_type *menu, int oid, bool cursor, int row, int col, int width) 251 { 252 menu_item *items = (menu_item *)menu->menu_data; 253 byte color = curs_attrs[!(items[oid].flags & (MN_GRAYED))][0 != cursor]; 254 255 display_event_aux(&items[oid].evt, menu->target.self.object_id, color, row, 256 col, width); 232 257 } 233 258 … … 235 260 static bool handle_menu_item(char cmd, void *db, int oid) 236 261 { 237 if(cmd == '\xff') 238 { 239 menu_item *item = &((menu_item*)db)[oid]; 240 if(item->flags & MN_DISABLED) return TRUE; 241 if(item->evt.action) 262 if (cmd == '\xff') 263 { 264 menu_item *item = &((menu_item *)db)[oid]; 265 266 if (item->flags & MN_DISABLED) 267 return TRUE; 268 if (item->evt.action) 242 269 item->evt.action(item->evt.data, item->evt.name); 243 if (item->flags & MN_SELECTABLE) {270 if (item->flags & MN_SELECTABLE) 244 271 item->flags ^= MN_SELECTED; 245 } 272 246 273 return TRUE; 247 274 } 275 248 276 return FALSE; 249 277 } … … 251 279 static int valid_menu_item(menu_type *menu, int oid) 252 280 { 253 menu_item *items = (menu_item *) menu->menu_data; 254 if(items[oid].flags & MN_HIDDEN) return 2; 281 menu_item *items = (menu_item *)menu->menu_data; 282 283 if (items[oid].flags & MN_HIDDEN) 284 return 2; 285 255 286 return (NULL != items[oid].evt.name); 256 287 } 257 288 258 289 /* Virtual function table for menu items */ 259 static const menu_iter menu_iter_item = { 290 static const menu_iter menu_iter_item = 291 { 260 292 MN_ACT, 261 293 tag_menu_item, … … 268 300 269 301 static void display_string(menu_type *menu, int oid, bool cursor, 270 int row, int col, int width)271 { 272 const char **items = (const char **) menu->menu_data;302 int row, int col, int width) 303 { 304 const char **items = (const char **)menu->menu_data; 273 305 byte color = curs_attrs[CURS_KNOWN][0 != cursor]; 274 306 Term_putstr(col, row, width, color, items[oid]); … … 276 308 277 309 /* Virtual function table for displaying arrays of strings */ 278 static const menu_iter menu_iter_string = { MN_STRING, 0, 0, display_string, 0 }; 310 static const menu_iter menu_iter_string = 311 { MN_STRING, 0, 0, display_string, 0 }; 279 312 280 313 … … 289 322 { 290 323 int cursor = row - loc->row + top; 291 if (cursor >= n) cursor = n-1;324 if (cursor >= n) cursor = n - 1; 292 325 293 326 return cursor; … … 296 329 297 330 /* Display current view of a skin */ 298 static void display_scrolling (menu_type *menu, int cursor, int *top, region *loc) 331 static void 332 display_scrolling(menu_type *menu, int cursor, int *top, region *loc) 299 333 { 300 334 int col = loc->col; … … 304 338 int i; 305 339 306 if (cursor <= *top && *top > 0)340 if ((cursor <= *top) && (*top > 0)) 307 341 *top = cursor - jumpscroll - 1; 308 if(cursor >= *top + (rows_per_page-1)) 309 *top = cursor - (rows_per_page-1) + 1 + jumpscroll; 310 if(*top > n - rows_per_page) *top = n - rows_per_page; 311 if(*top < 0) *top = 0; 312 313 for(i = 0; i < rows_per_page && i < n; i++) 342 if (cursor >= *top + (rows_per_page - 1)) 343 *top = cursor - (rows_per_page - 1) + 1 + jumpscroll; 344 if (*top > n - rows_per_page) 345 *top = n - rows_per_page; 346 if (*top < 0) 347 *top = 0; 348 349 for (i = 0; i < rows_per_page && i < n; i++) 314 350 { 315 351 bool is_curs = (i == cursor - *top); 316 display_menu_row(menu, i+*top, *top, is_curs, row+i, col, loc->width); 317 } 318 if(cursor >= 0) { 319 Term_gotoxy(col, row + cursor-*top); 320 } 352 display_menu_row(menu, i + *top, *top, is_curs, row + i, col, 353 loc->width); 354 } 355 356 if (cursor >= 0) 357 Term_gotoxy(col, row + cursor - *top); 321 358 } 322 359 … … 327 364 328 365 /* Virtual function table for scrollable menu skin */ 329 static const menu_skin scroll_skin = { 366 static const menu_skin scroll_skin = 367 { 330 368 MN_SCROLL, 331 369 scrolling_get_cursor, … … 340 378 { 341 379 int rows_per_page = loc->page_rows; 342 int colw = loc->width / (n + rows_per_page -1)/rows_per_page;343 int cursor = row + rows_per_page * (col - loc->col) /colw;344 345 if (cursor < 0) cursor = 0;/* assert: This should never happen */346 if (cursor >= n) cursor = n-1;380 int colw = loc->width / (n + rows_per_page - 1) / rows_per_page; 381 int cursor = row + rows_per_page * (col - loc->col) / colw; 382 383 if (cursor < 0) cursor = 0; /* assert: This should never happen */ 384 if (cursor >= n) cursor = n - 1; 347 385 348 386 return cursor; 349 387 } 350 388 351 void display_columns (menu_type *menu, int cursor, int *top, region *loc)389 void display_columns(menu_type *menu, int cursor, int *top, region *loc) 352 390 { 353 391 int c, r; … … 357 395 int row = loc->row; 358 396 int rows_per_page = loc->page_rows; 359 int cols = (n + rows_per_page - 1) / rows_per_page;397 int cols = (n + rows_per_page - 1) / rows_per_page; 360 398 int colw = menu_width; 399 361 400 Term_get_size(&w, &h); 362 if(colw * cols > w - col) 363 colw = (w-col) /cols; 364 365 for(c = 0; c < cols; c++) { 366 for(r = 0; r < rows_per_page; r++) { 367 int pos = c*rows_per_page + r; 401 402 if ((colw * cols) > (w - col)) 403 colw = (w - col) / cols; 404 405 for (c = 0; c < cols; c++) 406 { 407 for (r = 0; r < rows_per_page; r++) 408 { 409 int pos = c * rows_per_page + r; 368 410 bool is_cursor = (pos == cursor); 369 display_menu_row(menu, pos, 0, is_cursor, row+r, col+c*colw, colw); 411 display_menu_row(menu, pos, 0, is_cursor, row + r, col + c * colw, 412 colw); 370 413 } 371 414 } … … 378 421 379 422 /* Virtual function table for multi-column menu skin */ 380 static const menu_skin column_skin = { 423 static const menu_skin column_skin = 424 { 381 425 MN_COLUMNS, 382 426 columns_get_cursor, … … 387 431 /* ================== IMPLICIT MENU FOR KEY SELECTION ================== */ 388 432 389 static void display_nothing (menu_type *menu, int cursor, int *top, region *loc)433 static void display_nothing(menu_type *menu, int cursor, int *top, region *loc) 390 434 { 391 435 } … … 396 440 } 397 441 398 static const menu_skin key_select_skin = { 442 static const menu_skin key_select_skin = 443 { 399 444 MN_KEY_ONLY, 400 445 no_cursor, … … 408 453 { 409 454 int oid = cursor; 410 if(cursor < 0 || cursor >= menu->filter_count) return FALSE; 411 if(menu->object_list) { 412 oid = menu->object_list[cursor]; 413 } 414 if(!menu->row_funcs->valid_row) return TRUE; 455 456 if (cursor < 0 || cursor >= menu->filter_count) 457 return FALSE; 458 459 if (menu->object_list) 460 oid = menu->object_list[cursor]; 461 462 if (!menu->row_funcs->valid_row) 463 return TRUE; 464 415 465 return menu->row_funcs->valid_row(menu, oid); 416 466 } … … 420 470 int i; 421 471 int n = menu->filter_count; 422 if(menu->flags & MN_NO_TAGS) return -1; 423 else if(menu->flags & MN_REL_TAGS) { 424 for(i = 0; i < n; i++) { 472 473 if (menu->flags & MN_NO_TAGS) 474 { 475 return -1; 476 } 477 else if (menu->flags & MN_REL_TAGS) 478 { 479 for (i = 0; i < n; i++) 480 { 425 481 char c = menu->skin->get_tag(menu, i); 426 if (c && c == key)482 if (c && c == key) 427 483 return i + menu->top; 428 484 } 429 485 } 430 else if(!(menu->flags & MN_PVT_TAGS) && menu->selections) { 431 for(i = 0; menu->selections[i] ; i++) 432 if(menu->selections[i] == key) return i; 433 } 434 else if(menu->row_funcs->get_tag) { 435 for(i = 0; i < n; i++) { 486 else if (!(menu->flags & MN_PVT_TAGS) && menu->selections) 487 { 488 for (i = 0; menu->selections[i]; i++) 489 { 490 if (menu->selections[i] == key) 491 return i; 492 } 493 } 494 else if (menu->row_funcs->get_tag) 495 { 496 for (i = 0; i < n; i++) 497 { 436 498 int oid = menu->object_list ? menu->object_list[i] : i; 437 499 char c = menu->row_funcs->get_tag(menu, oid); 438 if (c && c == key)500 if (c && c == key) 439 501 return i; 440 502 } 441 503 } 504 442 505 return -1; 443 506 } … … 450 513 { 451 514 int oid = cursor; 452 if(menu->object_list) oid = menu->object_list[cursor];453 515 int flags = menu->flags; 454 if(flags & MN_NO_ACT) return FALSE; 455 456 if(isspace(cmd) && (flags & MN_PAGE)) return FALSE; 457 458 if(cmd == ESCAPE) return FALSE; 459 if(!cmd == '\xff' && (!menu->cmd_keys || !strchr(menu->cmd_keys, cmd))) 460 return FALSE; 461 462 if(menu->row_funcs->row_handler && 463 menu->row_funcs->row_handler(cmd, (void*) menu->menu_data, oid)) { 516 517 if (menu->object_list) oid = menu->object_list[cursor]; 518 if (flags & MN_NO_ACT) return FALSE; 519 520 if (isspace(cmd) && (flags & MN_PAGE)) return FALSE; 521 522 if (cmd == ESCAPE) return FALSE; 523 if (!cmd == '\xff' && (!menu->cmd_keys || !strchr(menu->cmd_keys, cmd))) 524 return FALSE; 525 526 if (menu->row_funcs->row_handler && 527 menu->row_funcs->row_handler(cmd, (void *)menu->menu_data, oid)) 528 { 464 529 key_event ke; 465 530 ke.type = EVT_SELECT; … … 469 534 return TRUE; 470 535 } 536 471 537 return FALSE; 472 538 } 473 539 474 540 /* Modal display of menu */ 475 static void display_menu_row(menu_type *menu, int pos, int top, 476 bool cursor, int row, int col, int width) 541 static void 542 display_menu_row(menu_type *menu, int pos, int top, 543 bool cursor, int row, int col, int width) 477 544 { 478 545 int flags = menu->flags; 479 546 char sel = 0; 480 547 int oid = pos; 481 if(menu->object_list) oid = menu->object_list[oid]; 482 if(menu->row_funcs->valid_row && menu->row_funcs->valid_row(menu, oid) == 2) 548 549 if (menu->object_list) 550 oid = menu->object_list[oid]; 551 552 if (menu->row_funcs->valid_row && menu->row_funcs->valid_row(menu, oid) == 2) 483 553 return; 484 if(!(flags & MN_NO_TAGS)) { 485 if(flags & MN_REL_TAGS) { 554 555 if (!(flags & MN_NO_TAGS)) 556 { 557 if (flags & MN_REL_TAGS) 486 558 sel = menu->skin->get_tag(menu, pos); 487 } 488 else if(menu->selections && !(flags & MN_PVT_TAGS)) { 559 else if (menu->selections && !(flags & MN_PVT_TAGS)) 489 560 sel = menu->selections[pos]; 490 } 491 else if(menu->row_funcs->get_tag) { 561 else if (menu->row_funcs->get_tag) 492 562 sel = menu->row_funcs->get_tag(menu, oid); 493 } 494 } 495 if(sel) { 563 } 564 565 if (sel) 566 { 496 567 /* TODO: CHECK FOR VALID */ 497 568 byte color = curs_attrs[CURS_KNOWN][0 != (cursor)]; … … 500 571 width -= 3; 501 572 } 573 502 574 menu->row_funcs->display_row(menu, oid, cursor, row, col, width); 503 575 } … … 507 579 region *loc = &menu->boundary; 508 580 int oid = menu->cursor; 509 if (menu->object_list && menu->cursor >= 0)581 if (menu->object_list && menu->cursor >= 0) 510 582 oid = menu->object_list[oid]; 511 583 512 513 584 region_erase(&menu->boundary); 514 585 515 if (menu->title)586 if (menu->title) 516 587 Term_putstr(loc->col, loc->row, loc->width, TERM_WHITE, menu->title); 517 if(menu->prompt) 518 Term_putstr(loc->col, loc->row+loc->page_rows-1, loc->width, TERM_WHITE, menu->prompt); 588 if (menu->prompt) 589 Term_putstr(loc->col, loc->row + loc->page_rows - 1, loc->width, 590 TERM_WHITE, menu->prompt); 519 591 520 592 menu->skin->display_list(menu, menu->cursor, &menu->top, &menu->active); 521 if(menu->browse_hook && oid >= 0) { 593 594 if (menu->browse_hook && oid >= 0) 522 595 menu->browse_hook(oid, menu->menu_data, loc); 523 }524 596 } 525 597 … … 530 602 int *cursor = &menu->cursor; 531 603 key_event out; 604 532 605 out.key = '\xff'; 533 if(menu->target.observers) { 606 607 if (menu->target.observers) 608 { 534 609 /* TODO: need a panel dispatcher here, not a generic target */ 535 event_target t = { {0, 0, 0, 0}, FALSE, menu->target.observers};610 event_target t = { { 0, 0, 0, 0 }, FALSE, menu->target.observers }; 536 611 out = run_event_loop(&t, FALSE, in); 537 if(out.type != EVT_AGAIN) { 538 if(out.type == EVT_SELECT) { 612 613 if (out.type != EVT_AGAIN) 614 { 615 if (out.type == EVT_SELECT) 616 { 539 617 /* HACK: can't return selection event from submenu (no ID) */ 540 618 out.type = EVT_REFRESH; 541 619 Term_event_push(&out); 542 620 } 621 543 622 return TRUE; 544 623 } 545 624 } 546 625 547 switch (in->type)626 switch (in->type) 548 627 { 549 628 case EVT_MOUSE: 550 629 { 551 630 int m_curs; 552 if(!region_inside(&menu->active, in)) { 553 if(!region_inside(&menu->boundary, in)) { 631 632 if (!region_inside(&menu->active, in)) 633 { 634 if (!region_inside(&menu->boundary, in)) 635 { 554 636 return FALSE; 555 637 } 556 638 557 639 /* used for heirarchical menus */ 558 if(in->mousex < menu->active.col) { 640 if (in->mousex < menu->active.col) 641 { 559 642 out.type = EVT_BACK; 560 643 break; 561 644 } 645 562 646 return FALSE; 563 647 } 564 565 566 m_curs = menu->skin->get_cursor(in->mousey,in->mousex, 567 menu->filter_count, menu->top, &menu->active); 648 649 m_curs = menu->skin->get_cursor(in->mousey, in->mousex, 650 menu->filter_count, menu->top, 651 &menu->active); 652 568 653 /* Ignore this event - retry */ 569 if (!is_valid_row(menu, m_curs))654 if (!is_valid_row(menu, m_curs)) 570 655 return TRUE; 571 656 572 657 out.index = m_curs; 573 if(*cursor == m_curs || !(menu->flags & MN_DBL_TAP)) { 658 659 if (*cursor == m_curs || !(menu->flags & MN_DBL_TAP)) 574 660 out.type = EVT_SELECT; 575 } 576 else { 661 else 577 662 out.type = EVT_MOVE; 578 } 663 579 664 *cursor = m_curs; 665 580 666 break; 581 667 } … … 586 672 587 673 /* could install handle_menu_key as a handler */ 588 if((menu->cmd_keys && strchr(menu->cmd_keys, in->key)) 589 || in->key == ESCAPE) 590 { 591 if(menu->flags & MN_NO_ACT) return FALSE; 592 else return handle_menu_key(in->key, menu, *cursor); 593 } 594 595 if(!(menu->flags & MN_NO_TAGS)) 674 if ((menu->cmd_keys && strchr(menu->cmd_keys, in->key)) 675 || in->key == ESCAPE) 676 { 677 if (menu->flags & MN_NO_ACT) 678 return FALSE; 679 else 680 return handle_menu_key(in->key, menu, *cursor); 681 } 682 683 if (!(menu->flags & MN_NO_TAGS)) 596 684 { 597 685 int c = get_cursor_key(menu, menu->top, in->key); 686 598 687 /* retry! */ 599 if(c > 0 && !is_valid_row(menu, c)) 688 if (c > 0 && !is_valid_row(menu, c)) 689 { 600 690 return FALSE; 601 else if(c >= 0) { 691 } 692 else if (c >= 0) 693 { 602 694 menu->cursor = c; 603 695 out.type = EVT_SELECT; … … 606 698 } 607 699 } 700 608 701 /* Not handled */ 609 if (menu->flags & MN_NO_CURSOR)702 if (menu->flags & MN_NO_CURSOR) 610 703 return FALSE; 611 704 612 705 /* cursor movement */ 613 706 dir = target_dir(in->key); 614 if(ddx[dir] && ddy[dir]) return FALSE; /* Reject diagonals */ 615 else if(ddx[dir]) { 707 708 /* Reject diagonals */ 709 if (ddx[dir] && ddy[dir]) 710 { 711 return FALSE; 712 } 713 else if (ddx[dir]) 714 { 616 715 out.type = ddx[dir] < 0 ? EVT_BACK : EVT_SELECT; 617 716 out.key = '\xff'; 618 717 out.index = *cursor; 619 718 } 620 else if(ddy[dir]) { /* Move up or down to the next valid & visible row */ 719 /* Move up or down to the next valid & visible row */ 720 else if (ddy[dir]) 721 { 621 722 int ind; 622 723 int dy = ddy[dir]; 724 623 725 out.type = EVT_MOVE; 624 for (ind = *cursor + dy; ind < n && ind >= 0625 && (TRUE != is_valid_row(menu, ind)); ind += dy) ;726 for (ind = *cursor + dy; ind < n && ind >= 0 727 && (TRUE != is_valid_row(menu, ind)); ind += dy) ; 626 728 out.index = ind; 627 if(ind < n && ind >= 0) *cursor = ind; 628 } 629 else return FALSE; 729 if (ind < n && ind >= 0) *cursor = ind; 730 } 731 else 732 { 733 return FALSE; 734 } 735 630 736 break; 631 737 } 632 738 633 case EVT_REFRESH: { 739 case EVT_REFRESH: 740 { 634 741 menu_refresh(menu); 635 742 return FALSE; 636 743 } 744 637 745 default: 746 { 638 747 return FALSE; 639 }640 641 if(out.type == EVT_SELECT && handle_menu_key('\xff', menu, *cursor)) 642 {748 } 749 } 750 751 if (out.type == EVT_SELECT && handle_menu_key('\xff', menu, *cursor)) 643 752 return TRUE; 644 } 645 646 if(out.type == EVT_MOVE)menu_refresh(menu);753 754 if (out.type == EVT_MOVE) 755 menu_refresh(menu); 647 756 648 757 Term_event_push(&out); 758 649 759 return TRUE; 650 760 } … … 652 762 653 763 /* VTAB for menus */ 654 static const panel_type menu_target = { 655 { { 0, /* listener.object_id */ 656 (handler_f)menu_handle_event, /* listener.handler */ 657 (release_f)menu_destroy, /* listener.release */ 658 0, /* listener.object */ 659 {EVT_KBRD | EVT_MOUSE | EVT_REFRESH} /* listener.events */ 764 static const panel_type menu_target = 765 { 766 { 767 {0, /* listener.object_id */ 768 (handler_f) menu_handle_event, /* listener.handler */ 769 (release_f) menu_destroy, /* listener.release */ 770 0, /* listener.object */ 771 {EVT_KBRD | EVT_MOUSE | EVT_REFRESH} /* listener.events */ 660 772 }, 661 TRUE,/* target.is_modal */662 },663 menu_refresh, /* refresh() */664 {0, 0, 0, 0} /* boundary */773 TRUE, /* target.is_modal */ 774 }, 775 menu_refresh, /* refresh() */ 776 {0, 0, 0, 0} /* boundary */ 665 777 }; 666 778 … … 685 797 * EVT_KBRD - An unhandled keyboard event 686 798 */ 687 688 799 key_event menu_select(menu_type *menu, int *cursor, int no_handle) 689 800 { 801 key_event ke; 690 802 691 803 menu->cursor = *cursor; 804 692 805 /* Menu shall not handle these */ 693 no_handle |= (EVT_SELECT |EVT_BACK|EVT_ESCAPE|EVT_STOP);806 no_handle |= (EVT_SELECT | EVT_BACK | EVT_ESCAPE | EVT_STOP); 694 807 no_handle &= ~(EVT_REFRESH); 695 808 696 if (!menu->object_list)809 if (!menu->object_list) 697 810 menu->filter_count = menu->count; 698 811 699 key_event ke;700 812 ke.type = EVT_REFRESH; 701 (void) run_event_loop(&menu->target, FALSE, &ke);813 (void)run_event_loop(&menu->target, FALSE, &ke); 702 814 703 815 /* Stop on first unhandled event. */ 704 while (!(ke.type & no_handle))816 while (!(ke.type & no_handle)) 705 817 { 706 818 ke = run_event_loop(&menu->target, FALSE, 0); 707 switch(ke.type) 819 820 switch (ke.type) 708 821 { 709 822 /* menu always returns these */ 710 823 case EVT_SELECT: 711 if(*cursor != ke.index) { 824 { 825  
