2800 |
*/ |
*/ |
2801 |
|
|
2802 |
void |
void |
2803 |
gui_window_split_horiz (t_gui_window *window) |
gui_window_split_horiz (t_gui_window *window, int pourcentage) |
2804 |
{ |
{ |
2805 |
t_gui_window *new_window; |
t_gui_window *new_window; |
2806 |
int height1, height2; |
int height1, height2; |
2808 |
if (!gui_ok) |
if (!gui_ok) |
2809 |
return; |
return; |
2810 |
|
|
2811 |
height1 = window->win_height / 2; |
height1 = (window->win_height * pourcentage) / 100; |
2812 |
height2 = window->win_height - height1; |
height2 = window->win_height - height1; |
2813 |
if ((new_window = gui_window_new (window->win_x, window->win_y, |
|
2814 |
window->win_width, height1))) |
if ((height1 >= WINDOW_MIN_HEIGHT) && (height2 >= WINDOW_MIN_HEIGHT) |
2815 |
|
&& (pourcentage > 0) && (pourcentage <= 100)) |
2816 |
{ |
{ |
2817 |
/* reduce old window height (bottom window) */ |
if ((new_window = gui_window_new (window, |
2818 |
window->win_y = new_window->win_y + new_window->win_height; |
window->win_x, window->win_y, |
2819 |
window->win_height = height2; |
window->win_width, height1, |
2820 |
|
100, pourcentage))) |
2821 |
/* assign same buffer for new window (top window) */ |
{ |
2822 |
new_window->buffer = window->buffer; |
/* reduce old window height (bottom window) */ |
2823 |
new_window->buffer->num_displayed++; |
window->win_y = new_window->win_y + new_window->win_height; |
2824 |
|
window->win_height = height2; |
2825 |
gui_switch_to_buffer (window, window->buffer); |
window->win_height_pct = 100 - pourcentage; |
2826 |
|
|
2827 |
gui_current_window = new_window; |
/* assign same buffer for new window (top window) */ |
2828 |
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
new_window->buffer = window->buffer; |
2829 |
gui_redraw_buffer (gui_current_window->buffer); |
new_window->buffer->num_displayed++; |
2830 |
|
|
2831 |
|
gui_switch_to_buffer (window, window->buffer); |
2832 |
|
|
2833 |
|
gui_current_window = new_window; |
2834 |
|
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
2835 |
|
gui_redraw_buffer (gui_current_window->buffer); |
2836 |
|
} |
2837 |
} |
} |
2838 |
} |
} |
2839 |
|
|
2842 |
*/ |
*/ |
2843 |
|
|
2844 |
void |
void |
2845 |
gui_window_split_vertic (t_gui_window *window) |
gui_window_split_vertic (t_gui_window *window, int pourcentage) |
2846 |
{ |
{ |
2847 |
t_gui_window *new_window; |
t_gui_window *new_window; |
2848 |
int width1, width2; |
int width1, width2; |
2850 |
if (!gui_ok) |
if (!gui_ok) |
2851 |
return; |
return; |
2852 |
|
|
2853 |
width1 = window->win_width / 2; |
width1 = (window->win_width * pourcentage) / 100; |
2854 |
width2 = window->win_width - width1 - 1; |
width2 = window->win_width - width1 - 1; |
|
if ((new_window = gui_window_new (window->win_x + width1 + 1, window->win_y, |
|
|
width2, window->win_height))) |
|
|
{ |
|
|
/* reduce old window height (left window) */ |
|
|
window->win_width = width1; |
|
|
|
|
|
/* assign same buffer for new window (right window) */ |
|
|
new_window->buffer = window->buffer; |
|
|
new_window->buffer->num_displayed++; |
|
|
|
|
|
gui_switch_to_buffer (window, window->buffer); |
|
|
|
|
|
gui_current_window = new_window; |
|
|
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
|
|
gui_redraw_buffer (gui_current_window->buffer); |
|
|
|
|
|
/* create & draw separator */ |
|
|
gui_draw_window_separator (gui_current_window); |
|
|
} |
|
|
} |
|
|
|
|
|
/* |
|
|
* gui_window_merge_down: merge window, direction down |
|
|
*/ |
|
|
|
|
|
int |
|
|
gui_window_merge_down (t_gui_window *window) |
|
|
{ |
|
|
t_gui_window *ptr_win; |
|
2855 |
|
|
2856 |
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
if ((width1 >= WINDOW_MIN_WIDTH) && (width2 >= WINDOW_MIN_WIDTH) |
2857 |
|
&& (pourcentage > 0) && (pourcentage <= 100)) |
2858 |
{ |
{ |
2859 |
if (ptr_win != window) |
if ((new_window = gui_window_new (window, |
2860 |
|
window->win_x + width1 + 1, window->win_y, |
2861 |
|
width2, window->win_height, |
2862 |
|
pourcentage, 100))) |
2863 |
{ |
{ |
2864 |
if ((ptr_win->win_y == window->win_y + window->win_height) |
/* reduce old window height (left window) */ |
2865 |
&& (ptr_win->win_x == window->win_x) |
window->win_width = width1; |
2866 |
&& (ptr_win->win_width == window->win_width)) |
window->win_width_pct = 100 - pourcentage; |
2867 |
{ |
|
2868 |
window->win_height += ptr_win->win_height; |
/* assign same buffer for new window (right window) */ |
2869 |
gui_window_free (ptr_win); |
new_window->buffer = window->buffer; |
2870 |
gui_switch_to_buffer (window, window->buffer); |
new_window->buffer->num_displayed++; |
2871 |
gui_redraw_buffer (window->buffer); |
|
2872 |
return 0; |
gui_switch_to_buffer (window, window->buffer); |
2873 |
} |
|
2874 |
|
gui_current_window = new_window; |
2875 |
|
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
2876 |
|
gui_redraw_buffer (gui_current_window->buffer); |
2877 |
|
|
2878 |
|
/* create & draw separator */ |
2879 |
|
gui_draw_window_separator (gui_current_window); |
2880 |
} |
} |
2881 |
} |
} |
|
|
|
|
/* no window found below current window */ |
|
|
return -1; |
|
2882 |
} |
} |
2883 |
|
|
2884 |
/* |
/* |
2885 |
* gui_window_merge_up: merge window, direction up |
* gui_window_merge: merge window with its sister |
2886 |
*/ |
*/ |
2887 |
|
|
2888 |
int |
int |
2889 |
gui_window_merge_up (t_gui_window *window) |
gui_window_merge (t_gui_window *window) |
2890 |
{ |
{ |
2891 |
t_gui_window *ptr_win; |
t_gui_window_tree *parent, *sister; |
2892 |
|
|
2893 |
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
parent = window->ptr_tree->parent_node; |
2894 |
|
if (parent) |
2895 |
{ |
{ |
2896 |
if (ptr_win != window) |
sister = (parent->child1->window == window) ? |
2897 |
|
parent->child2 : parent->child1; |
2898 |
|
|
2899 |
|
if (!(sister->window)) |
2900 |
|
return 0; |
2901 |
|
|
2902 |
|
if (window->win_y == sister->window->win_y) |
2903 |
{ |
{ |
2904 |
if ((ptr_win->win_y + ptr_win->win_height == window->win_y) |
/* horizontal merge */ |
2905 |
&& (ptr_win->win_x == window->win_x) |
window->win_width += sister->window->win_width + 1; |
2906 |
&& (ptr_win->win_width == window->win_width)) |
window->win_width_pct += sister->window->win_width_pct; |
2907 |
{ |
} |
2908 |
window->win_height += ptr_win->win_height; |
else |
2909 |
window->win_y -= ptr_win->win_height; |
{ |
2910 |
gui_window_free (ptr_win); |
/* vertical merge */ |
2911 |
gui_switch_to_buffer (window, window->buffer); |
window->win_height += sister->window->win_height; |
2912 |
gui_redraw_buffer (window->buffer); |
window->win_height_pct += sister->window->win_height_pct; |
|
return 0; |
|
|
} |
|
2913 |
} |
} |
2914 |
|
if (sister->window->win_x < window->win_x) |
2915 |
|
window->win_x = sister->window->win_x; |
2916 |
|
if (sister->window->win_y < window->win_y) |
2917 |
|
window->win_y = sister->window->win_y; |
2918 |
|
|
2919 |
|
gui_window_free (sister->window); |
2920 |
|
gui_window_tree_node_to_leaf (parent, window); |
2921 |
|
|
2922 |
|
gui_switch_to_buffer (window, window->buffer); |
2923 |
|
gui_redraw_buffer (window->buffer); |
2924 |
|
return 1; |
2925 |
} |
} |
2926 |
|
return 0; |
|
/* no window found above current window */ |
|
|
return -1; |
|
2927 |
} |
} |
2928 |
|
|
2929 |
/* |
/* |
2930 |
* gui_window_merge_left: merge window, direction left |
* gui_window_merge_all: merge all windows into only one |
2931 |
*/ |
*/ |
2932 |
|
|
2933 |
int |
void |
2934 |
gui_window_merge_left (t_gui_window *window) |
gui_window_merge_all (t_gui_window *window) |
2935 |
{ |
{ |
2936 |
t_gui_window *ptr_win; |
while (gui_windows->next_window) |
|
|
|
|
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
|
2937 |
{ |
{ |
2938 |
if (ptr_win != window) |
gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows); |
|
{ |
|
|
if ((ptr_win->win_x + ptr_win->win_width + 1 == window->win_x) |
|
|
&& (ptr_win->win_y == window->win_y) |
|
|
&& (ptr_win->win_height == window->win_height)) |
|
|
{ |
|
|
window->win_width += ptr_win->win_width + 1; |
|
|
window->win_x -= ptr_win->win_width + 1; |
|
|
gui_window_free (ptr_win); |
|
|
gui_switch_to_buffer (window, window->buffer); |
|
|
gui_redraw_buffer (window->buffer); |
|
|
return 0; |
|
|
} |
|
|
} |
|
2939 |
} |
} |
2940 |
|
gui_window_tree_free (&gui_windows_tree); |
2941 |
/* no window found on the left of current window */ |
gui_window_tree_init (window); |
2942 |
return -1; |
window->ptr_tree = gui_windows_tree; |
2943 |
|
window->win_x = 0; |
2944 |
|
window->win_y = 0; |
2945 |
|
window->win_width = COLS; |
2946 |
|
window->win_height = LINES; |
2947 |
|
window->win_width_pct = 100; |
2948 |
|
window->win_height_pct = 100; |
2949 |
|
gui_switch_to_buffer (window, window->buffer); |
2950 |
|
gui_redraw_buffer (window->buffer); |
2951 |
} |
} |
2952 |
|
|
2953 |
/* |
/* |
2954 |
* gui_window_merge_right: merge window, direction right |
* gui_window_auto_resize: auto-resize all windows, according to % of global size |
2955 |
|
* This function is called after a terminal resize. |
2956 |
|
* Returns 0 if ok, -1 if all window should be merged |
2957 |
|
* (not enough space according to windows %) |
2958 |
*/ |
*/ |
2959 |
|
|
2960 |
int |
void |
2961 |
gui_window_merge_right (t_gui_window *window) |
gui_window_auto_resize (t_gui_window_tree *tree, |
2962 |
|
int x, int y, int width, int height) |
2963 |
{ |
{ |
2964 |
t_gui_window *ptr_win; |
int size1, size2; |
2965 |
|
|
2966 |
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
if (tree) |
2967 |
{ |
{ |
2968 |
if (ptr_win != window) |
if (tree->window) |
2969 |
|
{ |
2970 |
|
tree->window->win_x = x; |
2971 |
|
tree->window->win_y = y; |
2972 |
|
tree->window->win_width = width; |
2973 |
|
tree->window->win_height = height; |
2974 |
|
} |
2975 |
|
else |
2976 |
{ |
{ |
2977 |
if ((ptr_win->win_x == window->win_x + window->win_width + 1) |
if (tree->split_horiz) |
2978 |
&& (ptr_win->win_y == window->win_y) |
{ |
2979 |
&& (ptr_win->win_height == window->win_height)) |
size1 = (height * tree->split_pct) / 100; |
2980 |
|
size2 = height - size1; |
2981 |
|
gui_window_auto_resize (tree->child1, x, y + size1, width, size2); |
2982 |
|
gui_window_auto_resize (tree->child2, x, y, width, size1); |
2983 |
|
} |
2984 |
|
else |
2985 |
{ |
{ |
2986 |
window->win_width += ptr_win->win_width + 1; |
size1 = (width * tree->split_pct) / 100; |
2987 |
gui_window_free (ptr_win); |
size2 = width - size1 - 1; |
2988 |
gui_switch_to_buffer (window, window->buffer); |
gui_window_auto_resize (tree->child1, x, y, size1, height); |
2989 |
gui_redraw_buffer (window->buffer); |
gui_window_auto_resize (tree->child2, x + size1 + 1, y, size2, height); |
|
return 0; |
|
2990 |
} |
} |
2991 |
} |
} |
2992 |
} |
} |
|
|
|
|
/* no window found on the right of current window */ |
|
|
return -1; |
|
|
} |
|
|
|
|
|
/* |
|
|
* gui_window_merge: merge a window, direction auto |
|
|
*/ |
|
|
|
|
|
void |
|
|
gui_window_merge_auto (t_gui_window *window) |
|
|
{ |
|
|
if (gui_window_merge_down (window) == 0) |
|
|
return; |
|
|
if (gui_window_merge_up (window) == 0) |
|
|
return; |
|
|
if (gui_window_merge_left (window) == 0) |
|
|
return; |
|
|
if (gui_window_merge_right (window) == 0) |
|
|
return; |
|
|
} |
|
|
|
|
|
/* |
|
|
* gui_window_merge_all: merge all windows |
|
|
*/ |
|
|
|
|
|
void |
|
|
gui_window_merge_all (t_gui_window *window) |
|
|
{ |
|
|
while (gui_windows->next_window) |
|
|
{ |
|
|
gui_window_free ((gui_windows == window) ? gui_windows->next_window : gui_windows); |
|
|
} |
|
|
window->win_x = 0; |
|
|
window->win_y = 0; |
|
|
window->win_width = COLS; |
|
|
window->win_height = LINES; |
|
|
gui_switch_to_buffer (window, window->buffer); |
|
|
gui_redraw_buffer (window->buffer); |
|
2993 |
} |
} |
2994 |
|
|
2995 |
/* |
/* |
3002 |
t_gui_window *ptr_win, *old_current_window; |
t_gui_window *ptr_win, *old_current_window; |
3003 |
int old_width, old_height; |
int old_width, old_height; |
3004 |
int new_width, new_height; |
int new_width, new_height; |
3005 |
int merge_all_windows; |
int merge_all; |
3006 |
|
|
3007 |
getmaxyx (stdscr, old_height, old_width); |
getmaxyx (stdscr, old_height, old_width); |
3008 |
|
|
3013 |
|
|
3014 |
old_current_window = gui_current_window; |
old_current_window = gui_current_window; |
3015 |
|
|
3016 |
gui_ok = ((new_width > 5) && (new_height > 5)); |
gui_ok = ((new_width > WINDOW_MIN_WIDTH) && (new_height > WINDOW_MIN_HEIGHT)); |
3017 |
|
|
3018 |
merge_all_windows = 0; |
if (gui_ok) |
|
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
|
3019 |
{ |
{ |
3020 |
ptr_win->dcc_first = NULL; |
gui_window_auto_resize (gui_windows_tree, 0, 0, COLS, LINES); |
|
ptr_win->dcc_selected = NULL; |
|
3021 |
|
|
3022 |
if (!merge_all_windows) |
merge_all = 0; |
3023 |
|
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
3024 |
{ |
{ |
3025 |
if ((ptr_win->win_x > new_width - 5) |
if ((ptr_win->win_width < WINDOW_MIN_WIDTH) |
3026 |
|| (ptr_win->win_y > new_height - 5)) |
|| (ptr_win->win_height < WINDOW_MIN_HEIGHT)) |
|
merge_all_windows = 1; |
|
|
else |
|
3027 |
{ |
{ |
3028 |
if (ptr_win->win_x + ptr_win->win_width == old_width) |
merge_all = 1; |
3029 |
ptr_win->win_width = new_width - ptr_win->win_x; |
break; |
|
if (ptr_win->win_y + ptr_win->win_height == old_height) |
|
|
ptr_win->win_height = new_height - ptr_win->win_y; |
|
|
if ((ptr_win->win_width < 5) || (ptr_win->win_height < 5)) |
|
|
merge_all_windows = 1; |
|
3030 |
} |
} |
3031 |
} |
} |
3032 |
} |
if (merge_all) |
3033 |
|
gui_window_merge_all (gui_current_window); |
|
if (merge_all_windows) |
|
|
gui_window_merge_all (gui_current_window); |
|
3034 |
|
|
3035 |
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) |
3036 |
{ |
{ |
3037 |
gui_switch_to_buffer (ptr_win, ptr_win->buffer); |
gui_switch_to_buffer (ptr_win, ptr_win->buffer); |
3038 |
gui_redraw_buffer (ptr_win->buffer); |
gui_redraw_buffer (ptr_win->buffer); |
3039 |
gui_draw_window_separator (ptr_win); |
gui_draw_window_separator (ptr_win); |
3040 |
|
} |
3041 |
|
|
3042 |
|
gui_current_window = old_current_window; |
3043 |
|
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
3044 |
|
gui_redraw_buffer (gui_current_window->buffer); |
3045 |
} |
} |
|
|
|
|
gui_current_window = old_current_window; |
|
|
gui_switch_to_buffer (gui_current_window, gui_current_window->buffer); |
|
|
gui_redraw_buffer (gui_current_window->buffer); |
|
3046 |
} |
} |
3047 |
|
|
3048 |
/* |
/* |
3226 |
gui_input_clipboard = NULL; |
gui_input_clipboard = NULL; |
3227 |
|
|
3228 |
/* create new window/buffer */ |
/* create new window/buffer */ |
3229 |
if (gui_window_new (0, 0, COLS, LINES)) |
if (gui_window_new (NULL, 0, 0, COLS, LINES, 100, 100)) |
3230 |
{ |
{ |
3231 |
gui_current_window = gui_windows; |
gui_current_window = gui_windows; |
3232 |
gui_buffer_new (gui_windows, NULL, NULL, 0, 1); |
gui_buffer_new (gui_windows, NULL, NULL, 0, 1); |
3277 |
/* delete all windows */ |
/* delete all windows */ |
3278 |
while (gui_windows) |
while (gui_windows) |
3279 |
gui_window_free (gui_windows); |
gui_window_free (gui_windows); |
3280 |
|
gui_window_tree_free (&gui_windows_tree); |
3281 |
|
|
3282 |
/* delete global history */ |
/* delete global history */ |
3283 |
history_global_free (); |
history_global_free (); |