Skip to content

Instantly share code, notes, and snippets.

@nocd5
Last active December 28, 2015 23:29
Show Gist options
  • Save nocd5/7579548 to your computer and use it in GitHub Desktop.
Save nocd5/7579548 to your computer and use it in GitHub Desktop.
gui_w32.c.001.diff : win32版gVimのタブでD&Dによる並び変えの機能 gui_w32.c.002.diff : win32版gVimのタブでミドルクリックによるタブを閉じる機能
*** src/gui_w32.c Sun Aug 4 23:15:37 2013
--- src/gui_w32.c.mod Thu Nov 21 19:35:01 2013
***************
*** 4223,4228 ****
--- 4223,4257 ----
#endif
#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
+ static LONG DefTabControlProc;
+ static tabpage_T *s_tp = NULL;
+ static HCURSOR s_hCursor = NULL;
+ static POINT s_pt = {0, 0};
+
+ /*
+ * Get tabpage_T from POINT
+ */
+ static tabpage_T *
+ GetTabFromPoint(
+ HWND hWnd,
+ POINT pt)
+ {
+ tabpage_T *ptp = NULL;
+ if (gui_mch_showing_tabline())
+ {
+ TCHITTESTINFO htinfo;
+ htinfo.pt = pt;
+ /* ignore if a window under cusor is not tabcontrol. */
+ if (s_tabhwnd == hWnd)
+ {
+ int idx = TabCtrl_HitTest(s_tabhwnd, &htinfo);
+ if (idx != -1)
+ ptp = find_tabpage(idx + 1);
+ }
+ }
+ return ptp;
+ }
+
static void
initialise_tabline(void)
{
***************
*** 4248,4253 ****
--- 4277,4347 ----
WPARAM wParam,
LPARAM lParam)
{
+ POINT pt;
+ tabpage_T *tp;
+ int nDragXth = GetSystemMetrics(SM_CXDRAG);
+ RECT rect;
+ int nCenter;
+ int idx0;
+ int idx1;
+ switch (uMsg)
+ {
+ case WM_LBUTTONDOWN:
+ {
+ s_pt.x = GET_X_LPARAM(lParam);
+ s_pt.y = GET_Y_LPARAM(lParam);
+ s_tp = GetTabFromPoint(hwnd, s_pt);
+ if (s_tp != NULL)
+ {
+ SetCapture(hwnd);
+ s_hCursor = GetCursor(); /* backup default cursor */
+ }
+ break;
+ }
+ case WM_MOUSEMOVE:
+ if (GetCapture() == hwnd
+ && (0 != (wParam & MK_LBUTTON)))
+ {
+ pt.x = GET_X_LPARAM(lParam);
+ pt.y = s_pt.y;
+ tp = GetTabFromPoint(hwnd, pt);
+ if ( abs(pt.x - s_pt.x) > nDragXth )
+ {
+ SetCursor(LoadCursor(0, IDC_SIZEWE));
+
+ if (s_tp != NULL && tp != NULL
+ && tp != s_tp) /* ignore if the same tabpage */
+ {
+ idx0 = tabpage_index(s_tp) - 1;
+
+ idx1 = tabpage_index(tp) - 1;
+ TabCtrl_GetItemRect(hwnd, idx1, &rect);
+ nCenter = rect.left + (rect.right - rect.left) / 2;
+
+ if ( ((idx0 < idx1) && (nCenter < pt.x)) /* move rightward & over the center */
+ || (idx1 < idx0) && (pt.x < nCenter)) /* move leftward & over the center */
+ {
+ tabpage_move(idx1);
+ update_screen(0);
+ }
+ }
+ }
+ }
+ break;
+ case WM_LBUTTONUP:
+ {
+ if (GetCapture() == hwnd)
+ {
+ SetCursor(s_hCursor);
+ ReleaseCapture();
+ s_tp = NULL;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
HandleMouseHide(uMsg, lParam);
return CallWindowProc(s_tabline_wndproc, hwnd, uMsg, wParam, lParam);
}
*** src/gui_w32.c Thu Nov 21 19:38:09 2013
--- src/gui_w32.c.mod Thu Nov 21 19:37:34 2013
***************
*** 4338,4343 ****
--- 4338,4384 ----
}
break;
}
+ case WM_MBUTTONDOWN:
+ {
+ pt.x = GET_X_LPARAM(lParam);
+ pt.y = GET_Y_LPARAM(lParam);
+ s_tp = GetTabFromPoint(hwnd, pt);
+ if (s_tp != NULL)
+ SetCapture(hwnd);
+ break;
+ }
+ case WM_MBUTTONUP:
+ {
+ if (GetCapture() == hwnd)
+ {
+ ReleaseCapture();
+ /* when the mouse events was executed on the same tab */
+ pt.x = GET_X_LPARAM(lParam);
+ pt.y = GET_Y_LPARAM(lParam);
+ if (GetTabFromPoint(hwnd, pt) == s_tp)
+ {
+ BOOL bResult = FALSE;
+ if (s_tp == curtab)
+ {
+ if (first_tabpage->tp_next != NULL)
+ {
+ tabpage_close(FALSE);
+ bResult = TRUE;
+ }
+ }
+ else if (s_tp != NULL)
+ {
+ tabpage_close_other(s_tp, FALSE);
+ bResult = TRUE;
+ }
+
+ if (bResult == TRUE)
+ update_screen(0);
+ }
+ s_tp = NULL;
+ }
+ break;
+ }
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment