Mercurial > vim
comparison src/popupwin.c @ 17580:d5e5d0fc3fa8 v8.1.1787
patch 8.1.1787: cannot resize a popup window
commit https://github.com/vim/vim/commit/9bcb70c18a740bf9d97a1420df5964618f218a89
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 1 21:11:05 2019 +0200
patch 8.1.1787: cannot resize a popup window
Problem: Cannot resize a popup window.
Solution: Allow for resizing by dragging the lower right corncer.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 01 Aug 2019 21:15:07 +0200 |
parents | 696030820746 |
children | 65a8099fc0e8 |
comparison
equal
deleted
inserted
replaced
17579:8c91fe192c56 | 17580:d5e5d0fc3fa8 |
---|---|
233 // Values set when dragging a popup window starts. | 233 // Values set when dragging a popup window starts. |
234 static int drag_start_row; | 234 static int drag_start_row; |
235 static int drag_start_col; | 235 static int drag_start_col; |
236 static int drag_start_wantline; | 236 static int drag_start_wantline; |
237 static int drag_start_wantcol; | 237 static int drag_start_wantcol; |
238 static int drag_on_resize_handle; | |
238 | 239 |
239 /* | 240 /* |
240 * Mouse down on border of popup window: start dragging it. | 241 * Mouse down on border of popup window: start dragging it. |
241 * Uses mouse_col and mouse_row. | 242 * Uses mouse_col and mouse_row. |
242 */ | 243 */ |
243 void | 244 void |
244 popup_start_drag(win_T *wp) | 245 popup_start_drag(win_T *wp, int row, int col) |
245 { | 246 { |
246 drag_start_row = mouse_row; | 247 drag_start_row = mouse_row; |
247 drag_start_col = mouse_col; | 248 drag_start_col = mouse_col; |
248 // TODO: handle using different corner | 249 // TODO: handle using different corner |
249 if (wp->w_wantline == 0) | 250 if (wp->w_wantline == 0) |
256 drag_start_wantcol = wp->w_wantcol; | 257 drag_start_wantcol = wp->w_wantcol; |
257 | 258 |
258 // Stop centering the popup | 259 // Stop centering the popup |
259 if (wp->w_popup_pos == POPPOS_CENTER) | 260 if (wp->w_popup_pos == POPPOS_CENTER) |
260 wp->w_popup_pos = POPPOS_TOPLEFT; | 261 wp->w_popup_pos = POPPOS_TOPLEFT; |
261 } | 262 |
262 | 263 drag_on_resize_handle = wp->w_popup_border[1] > 0 |
263 /* | 264 && wp->w_popup_border[2] > 0 |
264 * Mouse moved while dragging a popup window: adjust the window popup position. | 265 && row == popup_height(wp) - 1 |
266 && col == popup_width(wp) - 1; | |
267 | |
268 if (wp->w_popup_pos != POPPOS_TOPLEFT && drag_on_resize_handle) | |
269 { | |
270 if (wp->w_popup_pos == POPPOS_TOPRIGHT | |
271 || wp->w_popup_pos == POPPOS_BOTRIGHT) | |
272 wp->w_wantcol = wp->w_wincol + 1; | |
273 if (wp->w_popup_pos == POPPOS_BOTLEFT) | |
274 wp->w_wantline = wp->w_winrow + 1; | |
275 wp->w_popup_pos = POPPOS_TOPLEFT; | |
276 } | |
277 } | |
278 | |
279 /* | |
280 * Mouse moved while dragging a popup window: adjust the window popup position | |
281 * or resize. | |
265 */ | 282 */ |
266 void | 283 void |
267 popup_drag(win_T *wp) | 284 popup_drag(win_T *wp) |
268 { | 285 { |
269 // The popup may be closed before dragging stops. | 286 // The popup may be closed before dragging stops. |
270 if (!win_valid_popup(wp)) | 287 if (!win_valid_popup(wp)) |
271 return; | 288 return; |
272 | 289 |
290 if ((wp->w_popup_flags & POPF_RESIZE) && drag_on_resize_handle) | |
291 { | |
292 int width_inc = mouse_col - drag_start_col; | |
293 int height_inc = mouse_row - drag_start_row; | |
294 | |
295 if (width_inc != 0) | |
296 { | |
297 int width = wp->w_width + width_inc; | |
298 | |
299 if (width < 1) | |
300 width = 1; | |
301 wp->w_minwidth = width; | |
302 wp->w_maxwidth = width; | |
303 drag_start_col = mouse_col; | |
304 } | |
305 | |
306 if (height_inc != 0) | |
307 { | |
308 int height = wp->w_height + height_inc; | |
309 | |
310 if (height < 1) | |
311 height = 1; | |
312 wp->w_minheight = height; | |
313 wp->w_maxheight = height; | |
314 drag_start_row = mouse_row; | |
315 } | |
316 | |
317 popup_adjust_position(wp); | |
318 return; | |
319 } | |
320 | |
321 if (!(wp->w_popup_flags & POPF_DRAG)) | |
322 return; | |
273 wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); | 323 wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); |
274 if (wp->w_wantline < 1) | 324 if (wp->w_wantline < 1) |
275 wp->w_wantline = 1; | 325 wp->w_wantline = 1; |
276 if (wp->w_wantline > Rows) | 326 if (wp->w_wantline > Rows) |
277 wp->w_wantline = Rows; | 327 wp->w_wantline = Rows; |
548 wp->w_p_wrap = nr != 0; | 598 wp->w_p_wrap = nr != 0; |
549 } | 599 } |
550 | 600 |
551 di = dict_find(dict, (char_u *)"drag", -1); | 601 di = dict_find(dict, (char_u *)"drag", -1); |
552 if (di != NULL) | 602 if (di != NULL) |
553 wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); | 603 { |
604 nr = dict_get_number(dict, (char_u *)"drag"); | |
605 if (nr) | |
606 wp->w_popup_flags |= POPF_DRAG; | |
607 else | |
608 wp->w_popup_flags &= ~POPF_DRAG; | |
609 } | |
610 | |
611 di = dict_find(dict, (char_u *)"resize", -1); | |
612 if (di != NULL) | |
613 { | |
614 nr = dict_get_number(dict, (char_u *)"resize"); | |
615 if (nr) | |
616 wp->w_popup_flags |= POPF_RESIZE; | |
617 else | |
618 wp->w_popup_flags &= ~POPF_RESIZE; | |
619 } | |
554 | 620 |
555 di = dict_find(dict, (char_u *)"close", -1); | 621 di = dict_find(dict, (char_u *)"close", -1); |
556 if (di != NULL) | 622 if (di != NULL) |
557 { | 623 { |
558 int ok = TRUE; | 624 int ok = TRUE; |
1475 } | 1541 } |
1476 | 1542 |
1477 wp->w_wantcol = 10; | 1543 wp->w_wantcol = 10; |
1478 wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; | 1544 wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; |
1479 wp->w_minwidth = 20; | 1545 wp->w_minwidth = 20; |
1480 wp->w_popup_drag = 1; | 1546 wp->w_popup_flags |= POPF_DRAG; |
1481 wp->w_popup_close = POPCLOSE_CLICK; | 1547 wp->w_popup_close = POPCLOSE_CLICK; |
1482 for (i = 0; i < 4; ++i) | 1548 for (i = 0; i < 4; ++i) |
1483 wp->w_popup_border[i] = 1; | 1549 wp->w_popup_border[i] = 1; |
1484 wp->w_popup_padding[1] = 1; | 1550 wp->w_popup_padding[1] = 1; |
1485 wp->w_popup_padding[3] = 1; | 1551 wp->w_popup_padding[3] = 1; |
1492 | 1558 |
1493 if (type == TYPE_DIALOG || type == TYPE_MENU) | 1559 if (type == TYPE_DIALOG || type == TYPE_MENU) |
1494 { | 1560 { |
1495 wp->w_popup_pos = POPPOS_CENTER; | 1561 wp->w_popup_pos = POPPOS_CENTER; |
1496 wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; | 1562 wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; |
1497 wp->w_popup_drag = 1; | 1563 wp->w_popup_flags |= POPF_DRAG; |
1498 for (i = 0; i < 4; ++i) | 1564 for (i = 0; i < 4; ++i) |
1499 { | 1565 { |
1500 wp->w_popup_border[i] = 1; | 1566 wp->w_popup_border[i] = 1; |
1501 wp->w_popup_padding[i] = (i & 1) ? 1 : 0; | 1567 wp->w_popup_padding[i] = (i & 1) ? 1 : 0; |
1502 } | 1568 } |
1517 wp->w_popup_flags |= POPF_CURSORLINE; | 1583 wp->w_popup_flags |= POPF_CURSORLINE; |
1518 } | 1584 } |
1519 | 1585 |
1520 if (type == TYPE_PREVIEW) | 1586 if (type == TYPE_PREVIEW) |
1521 { | 1587 { |
1522 wp->w_popup_drag = 1; | 1588 wp->w_popup_flags |= POPF_DRAG | POPF_RESIZE; |
1523 wp->w_popup_close = POPCLOSE_BUTTON; | 1589 wp->w_popup_close = POPCLOSE_BUTTON; |
1524 for (i = 0; i < 4; ++i) | 1590 for (i = 0; i < 4; ++i) |
1525 wp->w_popup_border[i] = 1; | 1591 wp->w_popup_border[i] = 1; |
1526 parse_previewpopup(wp); | 1592 parse_previewpopup(wp); |
1527 popup_set_wantpos(wp, wp->w_minwidth); | 1593 popup_set_wantpos(wp, wp->w_minwidth); |
1705 filter_handle_drag(win_T *wp, int c, typval_T *rettv) | 1771 filter_handle_drag(win_T *wp, int c, typval_T *rettv) |
1706 { | 1772 { |
1707 int row = mouse_row; | 1773 int row = mouse_row; |
1708 int col = mouse_col; | 1774 int col = mouse_col; |
1709 | 1775 |
1710 if (wp->w_popup_drag | 1776 if ((wp->w_popup_flags & POPF_DRAG) |
1711 && is_mouse_key(c) | 1777 && is_mouse_key(c) |
1712 && (wp == popup_dragwin | 1778 && (wp == popup_dragwin |
1713 || wp == mouse_find_win(&row, &col, FIND_POPUP))) | 1779 || wp == mouse_find_win(&row, &col, FIND_POPUP))) |
1714 // do not consume the key, allow for dragging the popup | 1780 // do not consume the key, allow for dragging the popup |
1715 rettv->vval.v_number = 0; | 1781 rettv->vval.v_number = 0; |
2242 dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); | 2308 dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); |
2243 dict_add_number(dict, "zindex", wp->w_zindex); | 2309 dict_add_number(dict, "zindex", wp->w_zindex); |
2244 dict_add_number(dict, "fixed", wp->w_popup_fixed); | 2310 dict_add_number(dict, "fixed", wp->w_popup_fixed); |
2245 dict_add_string(dict, "title", wp->w_popup_title); | 2311 dict_add_string(dict, "title", wp->w_popup_title); |
2246 dict_add_number(dict, "wrap", wp->w_p_wrap); | 2312 dict_add_number(dict, "wrap", wp->w_p_wrap); |
2247 dict_add_number(dict, "drag", wp->w_popup_drag); | 2313 dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); |
2314 dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); | |
2248 dict_add_number(dict, "cursorline", | 2315 dict_add_number(dict, "cursorline", |
2249 (wp->w_popup_flags & POPF_CURSORLINE) != 0); | 2316 (wp->w_popup_flags & POPF_CURSORLINE) != 0); |
2250 dict_add_string(dict, "highlight", wp->w_p_wcr); | 2317 dict_add_string(dict, "highlight", wp->w_p_wcr); |
2251 if (wp->w_scrollbar_highlight != NULL) | 2318 if (wp->w_scrollbar_highlight != NULL) |
2252 dict_add_string(dict, "scrollbarhighlight", | 2319 dict_add_string(dict, "scrollbarhighlight", |
2809 { | 2876 { |
2810 border_char[0] = border_char[2] = 0x2550; | 2877 border_char[0] = border_char[2] = 0x2550; |
2811 border_char[1] = border_char[3] = 0x2551; | 2878 border_char[1] = border_char[3] = 0x2551; |
2812 border_char[4] = 0x2554; | 2879 border_char[4] = 0x2554; |
2813 border_char[5] = 0x2557; | 2880 border_char[5] = 0x2557; |
2814 border_char[6] = 0x255d; | 2881 border_char[6] = (wp->w_popup_flags & POPF_RESIZE) |
2882 ? 0x21f2 : 0x255d; | |
2815 border_char[7] = 0x255a; | 2883 border_char[7] = 0x255a; |
2816 } | 2884 } |
2817 else | 2885 else |
2818 { | 2886 { |
2819 border_char[0] = border_char[2] = '-'; | 2887 border_char[0] = border_char[2] = '-'; |
2820 border_char[1] = border_char[3] = '|'; | 2888 border_char[1] = border_char[3] = '|'; |
2821 for (i = 4; i < 8; ++i) | 2889 for (i = 4; i < 8; ++i) |
2822 border_char[i] = '+'; | 2890 border_char[i] = '+'; |
2891 if (wp->w_popup_flags & POPF_RESIZE) | |
2892 border_char[6] = '@'; | |
2823 } | 2893 } |
2824 for (i = 0; i < 8; ++i) | 2894 for (i = 0; i < 8; ++i) |
2825 if (wp->w_border_char[i] != 0) | 2895 if (wp->w_border_char[i] != 0) |
2826 border_char[i] = wp->w_border_char[i]; | 2896 border_char[i] = wp->w_border_char[i]; |
2827 | 2897 |