501 |
501 |
502 if (y < 0) |
502 if (y < 0) |
503 return - 1; |
503 return - 1; |
504 |
504 |
505 item = y / 10; |
505 item = y / 10; |
506 if (item >= WP(w,dropdown_d).num_items || (HasBit(WP(w,dropdown_d).disabled_state, item) && !HasBit(WP(w,dropdown_d).hidden_state, item)) || WP(w,dropdown_d).items[item] == 0) |
506 if (item >= WP(w, dropdown_d).num_items || (HasBit(WP(w,dropdown_d).disabled_state, item) && !HasBit(WP(w,dropdown_d).hidden_state, item)) || WP(w,dropdown_d).items[item] == 0) |
507 return - 1; |
507 return - 1; |
508 |
508 |
509 /* Skip hidden items -- +1 for each hidden item before the clicked item. */ |
509 /* Skip hidden items -- +1 for each hidden item before the clicked item. */ |
510 for (counter = 0; item >= counter; ++counter) |
510 for (counter = 0; item >= counter; ++counter) |
511 if (HasBit(WP(w,dropdown_d).hidden_state, counter)) item++; |
511 if (HasBit(WP(w, dropdown_d).hidden_state, counter)) item++; |
512 |
512 |
513 return item; |
513 return item; |
514 } |
514 } |
515 |
515 |
516 static void DropdownMenuWndProc(Window *w, WindowEvent *e) |
516 static void DropdownMenuWndProc(Window *w, WindowEvent *e) |
525 DrawWindowWidgets(w); |
525 DrawWindowWidgets(w); |
526 |
526 |
527 x = 1; |
527 x = 1; |
528 y = 2 - w->vscroll.pos * 10; |
528 y = 2 - w->vscroll.pos * 10; |
529 |
529 |
530 sel = WP(w,dropdown_d).selected_index; |
530 sel = WP(w, dropdown_d).selected_index; |
531 width = w->widget[0].right - 3; |
531 width = w->widget[0].right - 3; |
532 height = w->widget[0].bottom - 3; |
532 height = w->widget[0].bottom - 3; |
533 |
533 |
534 for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) { |
534 for (i = 0; WP(w, dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) { |
535 if (HasBit(WP(w,dropdown_d).hidden_state, i)) continue; |
535 if (HasBit(WP(w, dropdown_d).hidden_state, i)) continue; |
536 |
536 |
537 if (y >= 0 && y <= height) { |
537 if (y >= 0 && y <= height) { |
538 if (WP(w,dropdown_d).items[i] != STR_NULL) { |
538 if (WP(w, dropdown_d).items[i] != STR_NULL) { |
539 if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0); |
539 if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0); |
540 DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? TC_WHITE : TC_BLACK, x + width); |
540 DrawStringTruncated(x + 2, y, WP(w, dropdown_d).items[i], sel == 0 ? TC_WHITE : TC_BLACK, x + width); |
541 |
541 |
542 if (HasBit(WP(w,dropdown_d).disabled_state, i)) { |
542 if (HasBit(WP(w, dropdown_d).disabled_state, i)) { |
543 GfxFillRect(x, y, x + width, y + 9, |
543 GfxFillRect(x, y, x + width, y + 9, |
544 (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5] |
544 (1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5] |
545 ); |
545 ); |
546 } |
546 } |
547 } else { |
547 } else { |
558 |
558 |
559 case WE_CLICK: { |
559 case WE_CLICK: { |
560 if (e->we.click.widget != 0) break; |
560 if (e->we.click.widget != 0) break; |
561 item = GetDropdownItem(w); |
561 item = GetDropdownItem(w); |
562 if (item >= 0) { |
562 if (item >= 0) { |
563 WP(w,dropdown_d).click_delay = 4; |
563 WP(w, dropdown_d).click_delay = 4; |
564 WP(w,dropdown_d).selected_index = item; |
564 WP(w, dropdown_d).selected_index = item; |
565 SetWindowDirty(w); |
565 SetWindowDirty(w); |
566 } |
566 } |
567 } break; |
567 } break; |
568 |
568 |
569 case WE_MOUSELOOP: { |
569 case WE_MOUSELOOP: { |
570 Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
570 Window *w2 = FindWindowById(WP(w, dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
571 if (w2 == NULL) { |
571 if (w2 == NULL) { |
572 DeleteWindow(w); |
572 DeleteWindow(w); |
573 return; |
573 return; |
574 } |
574 } |
575 |
575 |
576 if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) { |
576 if (WP(w, dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) { |
577 WindowEvent e; |
577 WindowEvent e; |
578 e.event = WE_DROPDOWN_SELECT; |
578 e.event = WE_DROPDOWN_SELECT; |
579 e.we.dropdown.button = WP(w,dropdown_d).parent_button; |
579 e.we.dropdown.button = WP(w, dropdown_d).parent_button; |
580 e.we.dropdown.index = WP(w,dropdown_d).selected_index; |
580 e.we.dropdown.index = WP(w, dropdown_d).selected_index; |
581 w2->wndproc(w2, &e); |
581 w2->wndproc(w2, &e); |
582 DeleteWindow(w); |
582 DeleteWindow(w); |
583 return; |
583 return; |
584 } |
584 } |
585 |
585 |
586 if (WP(w,dropdown_d).drag_mode) { |
586 if (WP(w, dropdown_d).drag_mode) { |
587 item = GetDropdownItem(w); |
587 item = GetDropdownItem(w); |
588 |
588 |
589 if (!_left_button_clicked) { |
589 if (!_left_button_clicked) { |
590 WP(w,dropdown_d).drag_mode = false; |
590 WP(w, dropdown_d).drag_mode = false; |
591 if (item < 0) return; |
591 if (item < 0) return; |
592 WP(w,dropdown_d).click_delay = 2; |
592 WP(w, dropdown_d).click_delay = 2; |
593 } else { |
593 } else { |
594 if (item < 0) return; |
594 if (item < 0) return; |
595 } |
595 } |
596 |
596 |
597 WP(w,dropdown_d).selected_index = item; |
597 WP(w, dropdown_d).selected_index = item; |
598 SetWindowDirty(w); |
598 SetWindowDirty(w); |
599 } |
599 } |
600 } break; |
600 } break; |
601 |
601 |
602 case WE_DESTROY: { |
602 case WE_DESTROY: { |
603 Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
603 Window *w2 = FindWindowById(WP(w, dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num); |
604 if (w2 != NULL) { |
604 if (w2 != NULL) { |
605 w2->RaiseWidget(WP(w,dropdown_d).parent_button); |
605 w2->RaiseWidget(WP(w, dropdown_d).parent_button); |
606 w2->InvalidateWidget(WP(w,dropdown_d).parent_button); |
606 w2->InvalidateWidget(WP(w, dropdown_d).parent_button); |
607 } |
607 } |
608 } break; |
608 } break; |
609 } |
609 } |
610 } |
610 } |
611 |
611 |
694 } |
694 } |
695 |
695 |
696 w2->desc_flags = WDF_DEF_WIDGET; |
696 w2->desc_flags = WDF_DEF_WIDGET; |
697 w2->flags4 &= ~WF_WHITE_BORDER_MASK; |
697 w2->flags4 &= ~WF_WHITE_BORDER_MASK; |
698 |
698 |
699 WP(w2,dropdown_d).disabled_state = disabled_mask; |
699 WP(w2, dropdown_d).disabled_state = disabled_mask; |
700 WP(w2,dropdown_d).hidden_state = hidden_mask; |
700 WP(w2, dropdown_d).hidden_state = hidden_mask; |
701 |
701 |
702 WP(w2,dropdown_d).parent_wnd_class = w->window_class; |
702 WP(w2, dropdown_d).parent_wnd_class = w->window_class; |
703 WP(w2,dropdown_d).parent_wnd_num = w->window_number; |
703 WP(w2, dropdown_d).parent_wnd_num = w->window_number; |
704 WP(w2,dropdown_d).parent_button = button; |
704 WP(w2, dropdown_d).parent_button = button; |
705 |
705 |
706 WP(w2,dropdown_d).num_items = i; |
706 WP(w2, dropdown_d).num_items = i; |
707 WP(w2,dropdown_d).selected_index = selected; |
707 WP(w2, dropdown_d).selected_index = selected; |
708 WP(w2,dropdown_d).items = strings; |
708 WP(w2, dropdown_d).items = strings; |
709 |
709 |
710 WP(w2,dropdown_d).click_delay = 0; |
710 WP(w2, dropdown_d).click_delay = 0; |
711 WP(w2,dropdown_d).drag_mode = true; |
711 WP(w2, dropdown_d).drag_mode = true; |
712 } |
712 } |
713 |
713 |
714 |
714 |
715 static void ResizeWidgets(Window *w, byte a, byte b) |
715 static void ResizeWidgets(Window *w, byte a, byte b) |
716 { |
716 { |