Mercurial > vim
comparison src/popupwin.c @ 17119:b439e096a011 v8.1.1559
patch 8.1.1559: popup window title property not implemented yet
commit https://github.com/vim/vim/commit/eb2310d47d83764a61d63cd5c2788870d7f6eddf
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 16 20:09:10 2019 +0200
patch 8.1.1559: popup window title property not implemented yet
Problem: Popup window title property not implemented yet.
Solution: Implement the title property.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Jun 2019 20:15:05 +0200 |
parents | 7ef5283ace3c |
children | 808ea76535a9 |
comparison
equal
deleted
inserted
replaced
17118:27642fa6eeee | 17119:b439e096a011 |
---|---|
291 // Option values resulting in setting an option. | 291 // Option values resulting in setting an option. |
292 str = dict_get_string(dict, (char_u *)"highlight", FALSE); | 292 str = dict_get_string(dict, (char_u *)"highlight", FALSE); |
293 if (str != NULL) | 293 if (str != NULL) |
294 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, | 294 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
295 str, OPT_FREE|OPT_LOCAL, 0); | 295 str, OPT_FREE|OPT_LOCAL, 0); |
296 | |
297 str = dict_get_string(dict, (char_u *)"title", FALSE); | |
298 if (str != NULL) | |
299 { | |
300 vim_free(wp->w_popup_title); | |
301 wp->w_popup_title = vim_strsave(str); | |
302 } | |
296 | 303 |
297 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); | 304 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
298 if (wp->w_firstline < 1) | 305 if (wp->w_firstline < 1) |
299 wp->w_firstline = 1; | 306 wp->w_firstline = 1; |
300 | 307 |
530 + wp->w_popup_padding[3] + wp->w_popup_border[3] | 537 + wp->w_popup_padding[3] + wp->w_popup_border[3] |
531 + wp->w_popup_padding[1] + wp->w_popup_border[1]; | 538 + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
532 } | 539 } |
533 | 540 |
534 /* | 541 /* |
542 * Get the padding plus border at the top, adjusted to 1 if there is a title. | |
543 */ | |
544 static int | |
545 popup_top_extra(win_T *wp) | |
546 { | |
547 int extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; | |
548 | |
549 if (extra == 0 && wp->w_popup_title != NULL && *wp->w_popup_title != NUL) | |
550 return 1; | |
551 return extra; | |
552 } | |
553 | |
554 /* | |
535 * Adjust the position and size of the popup to fit on the screen. | 555 * Adjust the position and size of the popup to fit on the screen. |
536 */ | 556 */ |
537 void | 557 void |
538 popup_adjust_position(win_T *wp) | 558 popup_adjust_position(win_T *wp) |
539 { | 559 { |
541 int wrapped = 0; | 561 int wrapped = 0; |
542 int maxwidth; | 562 int maxwidth; |
543 int center_vert = FALSE; | 563 int center_vert = FALSE; |
544 int center_hor = FALSE; | 564 int center_hor = FALSE; |
545 int allow_adjust_left = !wp->w_popup_fixed; | 565 int allow_adjust_left = !wp->w_popup_fixed; |
546 int top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; | 566 int top_extra = popup_top_extra(wp); |
547 int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; | 567 int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; |
548 int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; | 568 int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; |
549 int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; | 569 int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
550 int extra_height = top_extra + bot_extra; | 570 int extra_height = top_extra + bot_extra; |
551 int extra_width = left_extra + right_extra; | 571 int extra_width = left_extra + right_extra; |
552 int org_winrow = wp->w_winrow; | 572 int org_winrow = wp->w_winrow; |
553 int org_wincol = wp->w_wincol; | 573 int org_wincol = wp->w_wincol; |
554 int org_width = wp->w_width; | 574 int org_width = wp->w_width; |
555 int org_height = wp->w_height; | 575 int org_height = wp->w_height; |
576 int minwidth; | |
556 | 577 |
557 wp->w_winrow = 0; | 578 wp->w_winrow = 0; |
558 wp->w_wincol = 0; | 579 wp->w_wincol = 0; |
559 if (wp->w_popup_pos == POPPOS_CENTER) | 580 if (wp->w_popup_pos == POPPOS_CENTER) |
560 { | 581 { |
644 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count | 665 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count |
645 - wp->w_topline + 1 + wrapped > wp->w_maxheight) | 666 - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
646 break; | 667 break; |
647 } | 668 } |
648 | 669 |
649 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth) | 670 minwidth = wp->w_minwidth; |
650 wp->w_width = wp->w_minwidth; | 671 if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
672 { | |
673 int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; | |
674 | |
675 if (minwidth < title_len) | |
676 minwidth = title_len; | |
677 } | |
678 | |
679 if (minwidth > 0 && wp->w_width < minwidth) | |
680 wp->w_width = minwidth; | |
651 if (wp->w_width > maxwidth) | 681 if (wp->w_width > maxwidth) |
652 wp->w_width = maxwidth; | 682 wp->w_width = maxwidth; |
653 if (center_hor) | 683 if (center_hor) |
654 { | 684 { |
655 wp->w_wincol = (Columns - wp->w_width - extra_width) / 2; | 685 wp->w_wincol = (Columns - wp->w_width - extra_width) / 2; |
1382 | 1412 |
1383 if (rettv_dict_alloc(rettv) == OK) | 1413 if (rettv_dict_alloc(rettv) == OK) |
1384 { | 1414 { |
1385 if (wp == NULL) | 1415 if (wp == NULL) |
1386 return; // invalid {id} | 1416 return; // invalid {id} |
1387 top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; | 1417 top_extra = popup_top_extra(wp); |
1388 left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; | 1418 left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
1389 | 1419 |
1390 dict = rettv->vval.v_dict; | 1420 dict = rettv->vval.v_dict; |
1391 | 1421 |
1392 dict_add_number(dict, "line", wp->w_winrow + 1); | 1422 dict_add_number(dict, "line", wp->w_winrow + 1); |
1748 win_T *wp; | 1778 win_T *wp; |
1749 int top_off; | 1779 int top_off; |
1750 int left_off; | 1780 int left_off; |
1751 int total_width; | 1781 int total_width; |
1752 int total_height; | 1782 int total_height; |
1783 int top_padding; | |
1753 int popup_attr; | 1784 int popup_attr; |
1754 int border_attr[4]; | 1785 int border_attr[4]; |
1755 int border_char[8]; | 1786 int border_char[8]; |
1756 char_u buf[MB_MAXBYTES]; | 1787 char_u buf[MB_MAXBYTES]; |
1757 int row; | 1788 int row; |
1768 // zindex is on top of the character. | 1799 // zindex is on top of the character. |
1769 screen_zindex = wp->w_zindex; | 1800 screen_zindex = wp->w_zindex; |
1770 | 1801 |
1771 // adjust w_winrow and w_wincol for border and padding, since | 1802 // adjust w_winrow and w_wincol for border and padding, since |
1772 // win_update() doesn't handle them. | 1803 // win_update() doesn't handle them. |
1773 top_off = wp->w_popup_padding[0] + wp->w_popup_border[0]; | 1804 top_off = popup_top_extra(wp); |
1774 left_off = wp->w_popup_padding[3] + wp->w_popup_border[3]; | 1805 left_off = wp->w_popup_padding[3] + wp->w_popup_border[3]; |
1775 wp->w_winrow += top_off; | 1806 wp->w_winrow += top_off; |
1776 wp->w_wincol += left_off; | 1807 wp->w_wincol += left_off; |
1777 | 1808 |
1778 // Draw the popup text. | 1809 // Draw the popup text. |
1781 wp->w_winrow -= top_off; | 1812 wp->w_winrow -= top_off; |
1782 wp->w_wincol -= left_off; | 1813 wp->w_wincol -= left_off; |
1783 | 1814 |
1784 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] | 1815 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] |
1785 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1]; | 1816 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
1786 total_height = wp->w_popup_border[0] + wp->w_popup_padding[0] | 1817 total_height = popup_top_extra(wp) |
1787 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; | 1818 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
1788 popup_attr = get_wcr_attr(wp); | 1819 popup_attr = get_wcr_attr(wp); |
1789 | 1820 |
1790 // We can only use these line drawing characters when 'encoding' is | 1821 // We can only use these line drawing characters when 'encoding' is |
1791 // "utf-8" and 'ambiwidth' is "single". | 1822 // "utf-8" and 'ambiwidth' is "single". |
1814 border_attr[i] = popup_attr; | 1845 border_attr[i] = popup_attr; |
1815 if (wp->w_border_highlight[i] != NULL) | 1846 if (wp->w_border_highlight[i] != NULL) |
1816 border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); | 1847 border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); |
1817 } | 1848 } |
1818 | 1849 |
1850 top_padding = wp->w_popup_padding[0]; | |
1819 if (wp->w_popup_border[0] > 0) | 1851 if (wp->w_popup_border[0] > 0) |
1820 { | 1852 { |
1821 // top border | 1853 // top border |
1822 screen_fill(wp->w_winrow, wp->w_winrow + 1, | 1854 screen_fill(wp->w_winrow, wp->w_winrow + 1, |
1823 wp->w_wincol, | 1855 wp->w_wincol, |
1830 buf[mb_char2bytes(border_char[5], buf)] = NUL; | 1862 buf[mb_char2bytes(border_char[5], buf)] = NUL; |
1831 screen_puts(buf, wp->w_winrow, | 1863 screen_puts(buf, wp->w_winrow, |
1832 wp->w_wincol + total_width - 1, border_attr[1]); | 1864 wp->w_wincol + total_width - 1, border_attr[1]); |
1833 } | 1865 } |
1834 } | 1866 } |
1835 | 1867 else if (wp->w_popup_padding[0] == 0 && popup_top_extra(wp) > 0) |
1836 if (wp->w_popup_padding[0] > 0) | 1868 top_padding = 1; |
1869 | |
1870 if (top_padding > 0) | |
1837 { | 1871 { |
1838 // top padding | 1872 // top padding |
1839 row = wp->w_winrow + wp->w_popup_border[0]; | 1873 row = wp->w_winrow + wp->w_popup_border[0]; |
1840 screen_fill(row, row + wp->w_popup_padding[0], | 1874 screen_fill(row, row + top_padding, |
1841 wp->w_wincol + wp->w_popup_border[3], | 1875 wp->w_wincol + wp->w_popup_border[3], |
1842 wp->w_wincol + total_width - wp->w_popup_border[1], | 1876 wp->w_wincol + total_width - wp->w_popup_border[1], |
1843 ' ', ' ', popup_attr); | 1877 ' ', ' ', popup_attr); |
1844 } | 1878 } |
1879 | |
1880 // Title goes on top of border or padding. | |
1881 if (wp->w_popup_title != NULL) | |
1882 screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, | |
1883 wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); | |
1845 | 1884 |
1846 for (row = wp->w_winrow + wp->w_popup_border[0]; | 1885 for (row = wp->w_winrow + wp->w_popup_border[0]; |
1847 row < wp->w_winrow + total_height - wp->w_popup_border[2]; | 1886 row < wp->w_winrow + total_height - wp->w_popup_border[2]; |
1848 ++row) | 1887 ++row) |
1849 { | 1888 { |