Skip to content

Commit ca05aa2

Browse files
committed
patch 8.0.1211: cannot reorder tab pages with drag & drop
Problem: Cannot reorder tab pages with drag & drop. Solution: Support drag & drop for GTK and MS-Windows. (Ken Takata, Masamichi Abe)
1 parent f8e8c06 commit ca05aa2

3 files changed

Lines changed: 126 additions & 1 deletion

File tree

src/gui_gtk_x11.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3567,8 +3567,29 @@ on_select_tab(
35673567
gpointer data UNUSED)
35683568
{
35693569
if (!ignore_tabline_evt)
3570-
{
35713570
send_tabline_event(idx + 1);
3571+
}
3572+
3573+
/*
3574+
* Handle reordering the tabs (using D&D).
3575+
*/
3576+
static void
3577+
on_tab_reordered(
3578+
GtkNotebook *notebook UNUSED,
3579+
# if GTK_CHECK_VERSION(3,0,0)
3580+
gpointer *page UNUSED,
3581+
# else
3582+
GtkNotebookPage *page UNUSED,
3583+
# endif
3584+
gint idx,
3585+
gpointer data UNUSED)
3586+
{
3587+
if (!ignore_tabline_evt)
3588+
{
3589+
if ((tabpage_index(curtab) - 1) < idx)
3590+
tabpage_move(idx + 1);
3591+
else
3592+
tabpage_move(idx);
35723593
}
35733594
}
35743595

@@ -3658,6 +3679,9 @@ gui_mch_update_tabline(void)
36583679
page,
36593680
event_box,
36603681
nr++);
3682+
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline),
3683+
page,
3684+
TRUE);
36613685
}
36623686

36633687
event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui.tabline), page);
@@ -4093,14 +4117,19 @@ gui_mch_init(void)
40934117
# endif
40944118
gtk_container_add(GTK_CONTAINER(event_box), label);
40954119
gtk_notebook_set_tab_label(GTK_NOTEBOOK(gui.tabline), page, event_box);
4120+
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(gui.tabline), page, TRUE);
40964121
}
40974122

40984123
# if GTK_CHECK_VERSION(3,0,0)
40994124
g_signal_connect(G_OBJECT(gui.tabline), "switch-page",
41004125
G_CALLBACK(on_select_tab), NULL);
4126+
g_signal_connect(G_OBJECT(gui.tabline), "page-reordered",
4127+
G_CALLBACK(on_tab_reordered), NULL);
41014128
# else
41024129
gtk_signal_connect(GTK_OBJECT(gui.tabline), "switch_page",
41034130
GTK_SIGNAL_FUNC(on_select_tab), NULL);
4131+
gtk_signal_connect(GTK_OBJECT(gui.tabline), "page-reordered",
4132+
GTK_SIGNAL_FUNC(on_tab_reordered), NULL);
41044133
# endif
41054134

41064135
/* Create a popup menu for the tab line and connect it. */

src/gui_w32.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8151,14 +8151,108 @@ initialise_tabline(void)
81518151
# endif
81528152
}
81538153

8154+
/*
8155+
* Get tabpage_T from POINT.
8156+
*/
8157+
static tabpage_T *
8158+
GetTabFromPoint(
8159+
HWND hWnd,
8160+
POINT pt)
8161+
{
8162+
tabpage_T *ptp = NULL;
8163+
8164+
if (gui_mch_showing_tabline())
8165+
{
8166+
TCHITTESTINFO htinfo;
8167+
htinfo.pt = pt;
8168+
/* ignore if a window under cusor is not tabcontrol. */
8169+
if (s_tabhwnd == hWnd)
8170+
{
8171+
int idx = TabCtrl_HitTest(s_tabhwnd, &htinfo);
8172+
if (idx != -1)
8173+
ptp = find_tabpage(idx + 1);
8174+
}
8175+
}
8176+
return ptp;
8177+
}
8178+
8179+
static POINT s_pt = {0, 0};
8180+
static HCURSOR s_hCursor = NULL;
8181+
81548182
static LRESULT CALLBACK
81558183
tabline_wndproc(
81568184
HWND hwnd,
81578185
UINT uMsg,
81588186
WPARAM wParam,
81598187
LPARAM lParam)
81608188
{
8189+
POINT pt;
8190+
tabpage_T *tp;
8191+
RECT rect;
8192+
int nCenter;
8193+
int idx0;
8194+
int idx1;
8195+
81618196
HandleMouseHide(uMsg, lParam);
8197+
8198+
switch (uMsg)
8199+
{
8200+
case WM_LBUTTONDOWN:
8201+
{
8202+
s_pt.x = GET_X_LPARAM(lParam);
8203+
s_pt.y = GET_Y_LPARAM(lParam);
8204+
SetCapture(hwnd);
8205+
s_hCursor = GetCursor(); /* backup default cursor */
8206+
break;
8207+
}
8208+
case WM_MOUSEMOVE:
8209+
if (GetCapture() == hwnd
8210+
&& ((wParam & MK_LBUTTON)) != 0)
8211+
{
8212+
pt.x = GET_X_LPARAM(lParam);
8213+
pt.y = s_pt.y;
8214+
if (abs(pt.x - s_pt.x) > GetSystemMetrics(SM_CXDRAG))
8215+
{
8216+
SetCursor(LoadCursor(NULL, IDC_SIZEWE));
8217+
8218+
tp = GetTabFromPoint(hwnd, pt);
8219+
if (tp != NULL)
8220+
{
8221+
idx0 = tabpage_index(curtab) - 1;
8222+
idx1 = tabpage_index(tp) - 1;
8223+
8224+
TabCtrl_GetItemRect(hwnd, idx1, &rect);
8225+
nCenter = rect.left + (rect.right - rect.left) / 2;
8226+
8227+
/* Check if the mouse cursor goes over the center of
8228+
* the next tab to prevent "flickering". */
8229+
if ((idx0 < idx1) && (nCenter < pt.x))
8230+
{
8231+
tabpage_move(idx1 + 1);
8232+
update_screen(0);
8233+
}
8234+
else if ((idx1 < idx0) && (pt.x < nCenter))
8235+
{
8236+
tabpage_move(idx1);
8237+
update_screen(0);
8238+
}
8239+
}
8240+
}
8241+
}
8242+
break;
8243+
case WM_LBUTTONUP:
8244+
{
8245+
if (GetCapture() == hwnd)
8246+
{
8247+
SetCursor(s_hCursor);
8248+
ReleaseCapture();
8249+
}
8250+
break;
8251+
}
8252+
default:
8253+
break;
8254+
}
8255+
81628256
return CallWindowProc(s_tabline_wndproc, hwnd, uMsg, wParam, lParam);
81638257
}
81648258
#endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1211,
764766
/**/
765767
1210,
766768
/**/

0 commit comments

Comments
 (0)