From 2aa4931110c7188d5b3d956b3a85dd633359f14c Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Fri, 5 Feb 2016 02:30:57 +0200
Subject: [PATCH] Ticket #3571: WMenuBar: a few mouse handling fixes.
---
lib/widget/menu.c | 83 +++++++++++++++++++++++++++----------------------------
1 file changed, 40 insertions(+), 43 deletions(-)
diff --git a/lib/widget/menu.c b/lib/widget/menu.c
index 9ca7f29..898d866 100644
a
|
b
|
menubar_mouse_on_menu (const WMenuBar * menubar, int y, int x) |
656 | 656 | menu_t *menu; |
657 | 657 | int left_x, right_x, bottom_y; |
658 | 658 | |
| 659 | if (!menubar->is_dropped) |
| 660 | return FALSE; |
| 661 | |
659 | 662 | menu = MENU (g_list_nth_data (menubar->menu, menubar->selected)); |
660 | 663 | left_x = menu->start_x; |
661 | 664 | right_x = left_x + menu->max_entry_len + 3; |
… |
… |
static void |
696 | 699 | menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
697 | 700 | { |
698 | 701 | WMenuBar *menubar = MENUBAR (w); |
| 702 | gboolean mouse_on_drop; |
| 703 | |
| 704 | mouse_on_drop = menubar_mouse_on_menu (menubar, event->y, event->x); |
699 | 705 | |
700 | 706 | switch (msg) |
701 | 707 | { |
702 | 708 | case MSG_MOUSE_DOWN: |
703 | 709 | if (event->y == 0) |
704 | 710 | { |
| 711 | /* events on menubar */ |
705 | 712 | unsigned int selected; |
706 | 713 | |
707 | 714 | selected = menubar_get_menu_by_x_coord (menubar, event->x); |
… |
… |
menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
711 | 718 | /* menu bar is not active -- activate it */ |
712 | 719 | menubar->previous_widget = dlg_get_current_widget_id (w->owner); |
713 | 720 | menubar->is_active = TRUE; |
714 | | menubar_drop (menubar, selected); |
715 | 721 | dlg_select_widget (w); |
716 | 722 | } |
717 | | else if (selected != menubar->selected) |
718 | | { |
719 | | menubar_remove (menubar); |
720 | | menubar_drop (menubar, selected); |
721 | | } |
| 723 | |
| 724 | menubar_remove (menubar); /* if already shown */ |
| 725 | menubar_drop (menubar, selected); |
722 | 726 | } |
723 | | else |
| 727 | else if (mouse_on_drop) |
724 | 728 | menubar_change_selected_item (menubar, event->y); |
725 | | break; |
726 | | |
727 | | case MSG_MOUSE_CLICK: |
728 | | if (event->y == 0) |
| 729 | else |
729 | 730 | { |
730 | | /* events on menubar */ |
731 | | unsigned int selected; |
732 | | |
733 | | selected = menubar_get_menu_by_x_coord (menubar, event->x); |
| 731 | /* mouse click outside menubar or dropdown -- close menu */ |
| 732 | menubar_finish (menubar); |
734 | 733 | |
735 | | if (selected != menubar->selected) |
736 | | { |
737 | | menubar_remove (menubar); |
738 | | menubar_drop (menubar, selected); |
739 | | } |
740 | | } |
741 | | else if (!menubar->is_dropped) |
742 | | { |
743 | | if (event->y > 0) |
744 | | { |
745 | | /* mouse click below menubar -- close menu */ |
746 | | menubar_finish (menubar); |
747 | | } |
748 | | else |
749 | | { |
750 | | /* show drop-down menu */ |
751 | | menubar_drop (menubar, menubar_get_menu_by_x_coord (menubar, event->x)); |
752 | | } |
| 734 | /* |
| 735 | * @FIXME. |
| 736 | * |
| 737 | * Unless we clear the 'capture' flag, we'll receive MSG_MOUSE_DRAG |
| 738 | * events belonging to this click (in case the user drags the mouse, |
| 739 | * of course). |
| 740 | * |
| 741 | * For the time being, we mark this with FIXME as this flag should |
| 742 | * preferably be regarded as "implementation detail" and not be |
| 743 | * touched by us. We should think of some other way of communicating |
| 744 | * this to the system. |
| 745 | */ |
| 746 | w->Mouse.capture = FALSE; |
753 | 747 | } |
754 | | else if ((event->buttons & GPM_B_MIDDLE) != 0) |
| 748 | break; |
| 749 | |
| 750 | case MSG_MOUSE_CLICK: |
| 751 | if ((event->buttons & GPM_B_MIDDLE) != 0 && event->y > 0 && menubar->is_dropped) |
755 | 752 | { |
756 | 753 | /* middle click -- everywhere */ |
757 | 754 | menubar_execute (menubar); |
758 | 755 | } |
759 | | else if (menubar_mouse_on_menu (menubar, event->y, event->x)) |
| 756 | else if (mouse_on_drop) |
760 | 757 | menubar_execute (menubar); |
761 | | else |
| 758 | else if (event->y > 0) |
| 759 | /* releasing the mouse button outside the menu -- close menu */ |
762 | 760 | menubar_finish (menubar); |
763 | 761 | break; |
764 | 762 | |
… |
… |
menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
768 | 766 | menubar_remove (menubar); |
769 | 767 | menubar_drop (menubar, menubar_get_menu_by_x_coord (menubar, event->x)); |
770 | 768 | } |
771 | | else |
| 769 | else if (mouse_on_drop) |
772 | 770 | menubar_change_selected_item (menubar, event->y); |
773 | 771 | break; |
774 | 772 | |
… |
… |
menubar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
779 | 777 | if (event->y == 0) |
780 | 778 | { |
781 | 779 | /* menubar: left/right */ |
782 | | if (msg == MSG_MOUSE_SCROLL_DOWN) |
| 780 | if (msg == MSG_MOUSE_SCROLL_UP) |
783 | 781 | menubar_left (menubar); |
784 | 782 | else |
785 | 783 | menubar_right (menubar); |
786 | 784 | } |
787 | | else if (menubar_mouse_on_menu (menubar, event->y, event->x)) |
| 785 | else if (mouse_on_drop) |
788 | 786 | { |
789 | 787 | /* drop-down menu: up/down */ |
790 | | /* ignore events below drop-down menu */ |
791 | | if (msg == MSG_MOUSE_SCROLL_DOWN) |
792 | | menubar_down (menubar); |
793 | | else |
| 788 | if (msg == MSG_MOUSE_SCROLL_UP) |
794 | 789 | menubar_up (menubar); |
| 790 | else |
| 791 | menubar_down (menubar); |
795 | 792 | } |
796 | 793 | } |
797 | 794 | break; |