Ticket #2199: mc-4.7.0.5-buttonbar-click-locations.patch
File mc-4.7.0.5-buttonbar-click-locations.patch, 4.2 KB (added by egmont, 15 years ago) |
---|
-
src/widget.c
diff -ur mc-4.7.0.5.orig/src/widget.c mc-4.7.0.5/src/widget.c
old new 2663 2663 return ret; 2664 2664 } 2665 2665 2666 /* calculate width of one button, width is never lesser than 7 */ 2666 /* calculate positions of buttons; width is never less than 7 */ 2667 static void 2668 buttonbar_init_button_positions (WButtonBar *bb) 2669 { 2670 int i; 2671 int pos = 0; 2672 int div, mod; 2673 if (COLS < BUTTONBAR_LABELS_NUM * 7) { 2674 for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) { 2675 if (pos + 7 <= COLS) { 2676 pos += 7; 2677 } 2678 bb->labels[i].end_coord = pos; 2679 } 2680 } else { 2681 /* Distribute the extra width in a way that the middle vertical line 2682 (between F5 and F6) aligns with the two panels. The extra width 2683 is distributed in this order: F10, F5, F9, F4, ..., F6, F1. */ 2684 div = COLS / BUTTONBAR_LABELS_NUM; 2685 mod = COLS % BUTTONBAR_LABELS_NUM; 2686 for (i = 0; i < BUTTONBAR_LABELS_NUM / 2; i++) { 2687 pos += div; 2688 if (BUTTONBAR_LABELS_NUM / 2 - 1 - i < mod / 2) { 2689 pos++; 2690 } 2691 bb->labels[i].end_coord = pos; 2692 } 2693 for (; i < BUTTONBAR_LABELS_NUM; i++) { 2694 pos += div; 2695 if (BUTTONBAR_LABELS_NUM - 1 - i < (mod + 1) / 2) { 2696 pos++; 2697 } 2698 bb->labels[i].end_coord = pos; 2699 } 2700 } 2701 } 2702 2703 /* return width of one button */ 2667 2704 static int 2668 buttonba t_get_button_width (void)2705 buttonbar_get_button_width (const WButtonBar *bb, int i) 2669 2706 { 2670 int result = COLS / BUTTONBAR_LABELS_NUM; 2671 return (result >= 7) ? result : 7; 2707 if (i == 0) { 2708 return bb->labels[0].end_coord; 2709 } 2710 return bb->labels[i].end_coord - bb->labels[i - 1].end_coord; 2711 } 2712 2713 static int 2714 buttonbar_get_button_by_x_coord (const WButtonBar *bb, int x) 2715 { 2716 int i; 2717 for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) { 2718 if (bb->labels[i].end_coord > x) { 2719 return i; 2720 } 2721 } 2722 return -1; 2672 2723 } 2673 2724 2674 2725 static cb_ret_t … … 2690 2741 2691 2742 case WIDGET_DRAW: 2692 2743 if (bb->visible) { 2693 int offset = 0; 2694 int count_free_positions; 2744 int width; 2695 2745 2746 buttonbar_init_button_positions (bb); 2696 2747 widget_move (&bb->widget, 0, 0); 2697 2748 tty_setcolor (DEFAULT_COLOR); 2698 bb->btn_width = buttonbat_get_button_width ();2699 2749 tty_printf ("%-*s", bb->widget.cols, ""); 2700 count_free_positions = COLS - bb->btn_width * BUTTONBAR_LABELS_NUM;2750 widget_move (&bb->widget, 0, 0); 2701 2751 2702 for (i = 0; i < COLS / bb->btn_width && i < BUTTONBAR_LABELS_NUM; i++) { 2703 widget_move (&bb->widget, 0, (i * bb->btn_width) + offset); 2752 for (i = 0; i < BUTTONBAR_LABELS_NUM && (width = buttonbar_get_button_width(bb, i)) > 0; i++) { 2704 2753 tty_setcolor (BUTTONBAR_HOTKEY_COLOR); 2705 2754 tty_printf ("%2d", i + 1); 2706 2755 tty_setcolor (BUTTONBAR_BUTTON_COLOR); 2707 2756 text = (bb->labels[i].text != NULL) ? bb->labels[i].text : ""; 2708 2757 tty_print_string (str_fit_to_term ( 2709 2758 text, 2710 bb->btn_width - 2 + (int)(offset < count_free_positions),2759 width - 2, 2711 2760 J_LEFT_FIT)); 2712 2713 if (count_free_positions != 0 && offset < count_free_positions)2714 offset++;2715 2761 } 2716 2762 } 2717 2763 return MSG_HANDLED; … … 2736 2782 return MOU_NORMAL; 2737 2783 if (event->y == 2) 2738 2784 return MOU_NORMAL; 2739 button = (event->x - 1) * BUTTONBAR_LABELS_NUM / COLS;2740 if (button < BUTTONBAR_LABELS_NUM)2785 button = buttonbar_get_button_by_x_coord (bb, event->x - 1); 2786 if (button >= 0) 2741 2787 buttonbar_call (bb, button); 2742 2788 return MOU_NORMAL; 2743 2789 } … … 2755 2801 bb->visible = visible; 2756 2802 widget_want_hotkey (bb->widget, 1); 2757 2803 widget_want_cursor (bb->widget, 0); 2758 bb->btn_width = buttonbat_get_button_width ();2759 2804 2760 2805 return bb; 2761 2806 } -
src/widget.h
diff -ur mc-4.7.0.5.orig/src/widget.h mc-4.7.0.5/src/widget.h
old new 165 165 typedef struct WButtonBar { 166 166 Widget widget; 167 167 gboolean visible; /* Is it visible? */ 168 int btn_width; /* width of one button */169 168 struct { 170 169 char *text; 171 170 unsigned long command; 172 171 Widget *receiver; 172 int end_coord; /* cumulative width of buttons so far */ 173 173 } labels [BUTTONBAR_LABELS_NUM]; 174 174 } WButtonBar; 175 175