1999-01-24 20:12:34 +01:00
|
|
|
/*
|
|
|
|
* Drag List control
|
|
|
|
*
|
|
|
|
* Copyright 1999 Eric Kohl
|
2004-03-10 00:26:44 +01:00
|
|
|
* Copyright 2004 Robert Shearman
|
1999-01-24 20:12:34 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2004-03-11 01:38:44 +01:00
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* This code was audited for completeness against the documented features
|
|
|
|
* of Comctl32.dll version 6.0 on Mar. 10, 2004, by Robert Shearman.
|
|
|
|
*
|
|
|
|
* Unless otherwise noted, we believe this code to be complete, as per
|
|
|
|
* the specification mentioned above.
|
|
|
|
* If you discover missing features or bugs please note them below.
|
|
|
|
*
|
1999-01-24 20:12:34 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winnls.h"
|
1999-01-24 20:12:34 +01:00
|
|
|
#include "commctrl.h"
|
2004-03-10 00:26:44 +01:00
|
|
|
#include "comctl32.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
#define DRAGLIST_SUBCLASSID 0
|
|
|
|
#define DRAGLIST_SCROLLPERIOD 200
|
|
|
|
#define DRAGLIST_TIMERID 666
|
|
|
|
|
|
|
|
/* properties relating to IDI_DRAGICON */
|
|
|
|
#define DRAGICON_HOTSPOT_X 17
|
|
|
|
#define DRAGICON_HOTSPOT_Y 7
|
|
|
|
#define DRAGICON_HEIGHT 32
|
|
|
|
|
|
|
|
/* internal Wine specific data for the drag list control */
|
|
|
|
typedef struct _DRAGLISTDATA
|
|
|
|
{
|
2004-03-11 01:38:44 +01:00
|
|
|
/* are we currently in dragging mode? */
|
|
|
|
BOOL dragging;
|
2004-03-10 00:26:44 +01:00
|
|
|
|
2004-03-11 01:38:44 +01:00
|
|
|
/* cursor to use as determined by DL_DRAGGING notification.
|
2004-03-10 00:26:44 +01:00
|
|
|
* NOTE: as we use LoadCursor we don't have to use DeleteCursor
|
|
|
|
* when we are finished with it */
|
2004-03-11 01:38:44 +01:00
|
|
|
HCURSOR cursor;
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
/* optimisation so that we don't have to load the cursor
|
|
|
|
* all of the time whilst dragging */
|
2004-03-11 01:38:44 +01:00
|
|
|
LRESULT last_dragging_response;
|
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
/* prevents flicker with drawing drag arrow */
|
|
|
|
RECT last_drag_icon_rect;
|
|
|
|
} DRAGLISTDATA;
|
|
|
|
|
2004-09-14 03:06:11 +02:00
|
|
|
UINT uDragListMessage = 0; /* registered window message code */
|
1999-11-24 00:35:12 +01:00
|
|
|
static DWORD dwLastScrollTime = 0;
|
2004-03-10 00:26:44 +01:00
|
|
|
static HICON hDragArrow = NULL;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DragList_Notify (internal)
|
|
|
|
*
|
|
|
|
* Sends notification messages to the parent control. Note that it
|
|
|
|
* does not use WM_NOTIFY like the rest of the controls, but a registered
|
|
|
|
* window message.
|
|
|
|
*/
|
|
|
|
static LRESULT DragList_Notify(HWND hwndLB, UINT uNotification)
|
|
|
|
{
|
|
|
|
DRAGLISTINFO dli;
|
|
|
|
dli.hWnd = hwndLB;
|
|
|
|
dli.uNotification = uNotification;
|
|
|
|
GetCursorPos(&dli.ptCursor);
|
|
|
|
return SendMessageW(GetParent(hwndLB), uDragListMessage, GetDlgCtrlID(hwndLB), (LPARAM)&dli);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleans up after dragging */
|
2005-03-03 14:51:47 +01:00
|
|
|
static void DragList_EndDrag(HWND hwnd, DRAGLISTDATA * data)
|
2004-03-10 00:26:44 +01:00
|
|
|
{
|
|
|
|
KillTimer(hwnd, DRAGLIST_TIMERID);
|
|
|
|
ReleaseCapture();
|
|
|
|
/* clear any drag insert icon present */
|
|
|
|
InvalidateRect(GetParent(hwnd), &data->last_drag_icon_rect, TRUE);
|
2004-09-14 03:06:11 +02:00
|
|
|
/* clear data for next use */
|
|
|
|
memset(data, 0, sizeof(*data));
|
2004-03-10 00:26:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DragList_SubclassWindowProc (internal)
|
|
|
|
*
|
|
|
|
* Handles certain messages to enable dragging for the ListBox and forwards
|
|
|
|
* the rest to the ListBox.
|
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
DragList_SubclassWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
|
|
|
{
|
|
|
|
DRAGLISTDATA * data = (DRAGLISTDATA*)dwRefData;
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
SetFocus(hwnd);
|
|
|
|
data->dragging = DragList_Notify(hwnd, DL_BEGINDRAG);
|
|
|
|
if (data->dragging)
|
|
|
|
{
|
|
|
|
SetCapture(hwnd);
|
|
|
|
SetTimer(hwnd, DRAGLIST_TIMERID, DRAGLIST_SCROLLPERIOD, NULL);
|
|
|
|
}
|
|
|
|
/* note that we don't absorb this message to let the list box
|
|
|
|
* do its thing (normally selecting an item) */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
/* user cancelled drag by either right clicking or
|
|
|
|
* by pressing the escape key */
|
|
|
|
if ((data->dragging) &&
|
|
|
|
((uMsg == WM_RBUTTONDOWN) || (wParam == VK_ESCAPE)))
|
|
|
|
{
|
|
|
|
/* clean up and absorb message */
|
|
|
|
DragList_EndDrag(hwnd, data);
|
|
|
|
DragList_Notify(hwnd, DL_CANCELDRAG);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_TIMER:
|
|
|
|
if (data->dragging)
|
|
|
|
{
|
|
|
|
LRESULT cursor = DragList_Notify(hwnd, DL_DRAGGING);
|
|
|
|
/* optimisation so that we don't have to load the cursor
|
|
|
|
* all of the time whilst dragging */
|
|
|
|
if (data->last_dragging_response != cursor)
|
|
|
|
{
|
|
|
|
switch (cursor)
|
|
|
|
{
|
|
|
|
case DL_STOPCURSOR:
|
|
|
|
data->cursor = LoadCursorW(NULL, (LPCWSTR)IDC_NO);
|
|
|
|
SetCursor(data->cursor);
|
|
|
|
break;
|
|
|
|
case DL_COPYCURSOR:
|
|
|
|
data->cursor = LoadCursorW(COMCTL32_hModule, (LPCWSTR)IDC_COPY);
|
|
|
|
SetCursor(data->cursor);
|
|
|
|
break;
|
|
|
|
case DL_MOVECURSOR:
|
|
|
|
data->cursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
|
|
|
|
SetCursor(data->cursor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
data->last_dragging_response = cursor;
|
|
|
|
}
|
|
|
|
/* don't pass this message on to List Box */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
if (data->dragging)
|
|
|
|
{
|
|
|
|
DragList_EndDrag(hwnd, data);
|
|
|
|
DragList_Notify(hwnd, DL_DROPPED);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_GETDLGCODE:
|
|
|
|
/* tell dialog boxes that we want to receive WM_KEYDOWN events
|
|
|
|
* for keys like VK_ESCAPE */
|
|
|
|
if (data->dragging)
|
|
|
|
return DLGC_WANTALLKEYS;
|
|
|
|
break;
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
RemoveWindowSubclass(hwnd, DragList_SubclassWindowProc, DRAGLIST_SUBCLASSID);
|
|
|
|
Free(data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/***********************************************************************
|
2001-06-19 05:34:07 +02:00
|
|
|
* MakeDragList (COMCTL32.13)
|
2004-02-27 05:40:08 +01:00
|
|
|
*
|
|
|
|
* Makes a normal ListBox into a DragList by subclassing it.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Non-zero
|
|
|
|
* Failure: Zero
|
2000-03-24 21:46:04 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
BOOL WINAPI MakeDragList (HWND hwndLB)
|
1999-01-24 20:12:34 +01:00
|
|
|
{
|
2005-03-03 14:51:47 +01:00
|
|
|
DRAGLISTDATA *data = Alloc(sizeof(DRAGLISTDATA));
|
2004-03-10 00:26:44 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", hwndLB);
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if (!uDragListMessage)
|
2005-03-03 14:51:47 +01:00
|
|
|
uDragListMessage = RegisterWindowMessageW(DRAGLISTMSGSTRINGW);
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
return SetWindowSubclass(hwndLB, DragList_SubclassWindowProc, DRAGLIST_SUBCLASSID, (DWORD_PTR)data);
|
1999-01-24 20:12:34 +01:00
|
|
|
}
|
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/***********************************************************************
|
2001-06-19 05:34:07 +02:00
|
|
|
* DrawInsert (COMCTL32.15)
|
2004-02-27 05:40:08 +01:00
|
|
|
*
|
|
|
|
* Draws insert arrow by the side of the ListBox item in the parent window.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2000-03-24 21:46:04 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
VOID WINAPI DrawInsert (HWND hwndParent, HWND hwndLB, INT nItem)
|
1999-01-24 20:12:34 +01:00
|
|
|
{
|
2004-03-10 00:26:44 +01:00
|
|
|
RECT rcItem, rcListBox, rcDragIcon;
|
|
|
|
HDC hdc;
|
|
|
|
DRAGLISTDATA * data;
|
|
|
|
|
|
|
|
TRACE("(%p %p %d)\n", hwndParent, hwndLB, nItem);
|
|
|
|
|
|
|
|
if (!hDragArrow)
|
|
|
|
hDragArrow = LoadIconW(COMCTL32_hModule, (LPCWSTR)IDI_DRAGARROW);
|
|
|
|
|
|
|
|
if (LB_ERR == SendMessageW(hwndLB, LB_GETITEMRECT, nItem, (LPARAM)&rcItem))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!GetWindowRect(hwndLB, &rcListBox))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* convert item rect to parent co-ordinates */
|
|
|
|
if (!MapWindowPoints(hwndLB, hwndParent, (LPPOINT)&rcItem, 2))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* convert list box rect to parent co-ordinates */
|
|
|
|
if (!MapWindowPoints(HWND_DESKTOP, hwndParent, (LPPOINT)&rcListBox, 2))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rcDragIcon.left = rcListBox.left - DRAGICON_HOTSPOT_X;
|
|
|
|
rcDragIcon.top = rcItem.top - DRAGICON_HOTSPOT_Y;
|
|
|
|
rcDragIcon.right = rcListBox.left;
|
|
|
|
rcDragIcon.bottom = rcDragIcon.top + DRAGICON_HEIGHT;
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if (!GetWindowSubclass(hwndLB, DragList_SubclassWindowProc, DRAGLIST_SUBCLASSID, (DWORD_PTR*)&data))
|
|
|
|
return;
|
1999-01-24 20:12:34 +01:00
|
|
|
|
2004-03-11 01:38:44 +01:00
|
|
|
if (nItem < 0)
|
|
|
|
SetRectEmpty(&rcDragIcon);
|
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
/* prevent flicker by only redrawing when necessary */
|
|
|
|
if (!EqualRect(&rcDragIcon, &data->last_drag_icon_rect))
|
|
|
|
{
|
|
|
|
/* get rid of any previous inserts drawn */
|
|
|
|
RedrawWindow(hwndParent, &data->last_drag_icon_rect, NULL,
|
|
|
|
RDW_INTERNALPAINT | RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
|
|
|
|
|
2016-06-24 13:11:04 +02:00
|
|
|
data->last_drag_icon_rect = rcDragIcon;
|
2004-03-11 01:38:44 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if (nItem >= 0)
|
|
|
|
{
|
|
|
|
hdc = GetDC(hwndParent);
|
|
|
|
|
|
|
|
DrawIcon(hdc, rcDragIcon.left, rcDragIcon.top, hDragArrow);
|
|
|
|
|
|
|
|
ReleaseDC(hwndParent, hdc);
|
|
|
|
}
|
|
|
|
}
|
1999-01-24 20:12:34 +01:00
|
|
|
}
|
|
|
|
|
2000-03-24 21:46:04 +01:00
|
|
|
/***********************************************************************
|
2001-06-19 05:34:07 +02:00
|
|
|
* LBItemFromPt (COMCTL32.14)
|
2004-02-27 05:40:08 +01:00
|
|
|
*
|
|
|
|
* Gets the index of the ListBox item under the specified point,
|
|
|
|
* scrolling if bAutoScroll is TRUE and pt is outside of the ListBox.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The ListBox item ID if pt is over a list item or -1 otherwise.
|
2000-03-24 21:46:04 +01:00
|
|
|
*/
|
1999-02-26 12:11:13 +01:00
|
|
|
INT WINAPI LBItemFromPt (HWND hwndLB, POINT pt, BOOL bAutoScroll)
|
1999-01-24 20:12:34 +01:00
|
|
|
{
|
1999-11-24 00:35:12 +01:00
|
|
|
RECT rcClient;
|
|
|
|
INT nIndex;
|
|
|
|
DWORD dwScrollTime;
|
|
|
|
|
2006-10-13 15:34:21 +02:00
|
|
|
TRACE("(%p %d x %d %s)\n",
|
2004-03-10 00:26:44 +01:00
|
|
|
hwndLB, pt.x, pt.y, bAutoScroll ? "TRUE" : "FALSE");
|
1999-01-24 20:12:34 +01:00
|
|
|
|
1999-11-24 00:35:12 +01:00
|
|
|
ScreenToClient (hwndLB, &pt);
|
|
|
|
GetClientRect (hwndLB, &rcClient);
|
2005-03-03 14:51:47 +01:00
|
|
|
nIndex = (INT)SendMessageW (hwndLB, LB_GETTOPINDEX, 0, 0);
|
1999-11-24 00:35:12 +01:00
|
|
|
|
|
|
|
if (PtInRect (&rcClient, pt))
|
|
|
|
{
|
2004-03-10 00:26:44 +01:00
|
|
|
/* point is inside -- get the item index */
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2005-03-03 14:51:47 +01:00
|
|
|
if (SendMessageW (hwndLB, LB_GETITEMRECT, nIndex, (LPARAM)&rcClient) == LB_ERR)
|
2004-03-10 00:26:44 +01:00
|
|
|
return -1;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if (PtInRect (&rcClient, pt))
|
|
|
|
return nIndex;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
nIndex++;
|
|
|
|
}
|
1999-11-24 00:35:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-10 00:26:44 +01:00
|
|
|
/* point is outside */
|
|
|
|
if (!bAutoScroll)
|
|
|
|
return -1;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if ((pt.x > rcClient.right) || (pt.x < rcClient.left))
|
|
|
|
return -1;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if (pt.y < 0)
|
|
|
|
nIndex--;
|
|
|
|
else
|
|
|
|
nIndex++;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
dwScrollTime = GetTickCount ();
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
if ((dwScrollTime - dwLastScrollTime) < DRAGLIST_SCROLLPERIOD)
|
|
|
|
return -1;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2004-03-10 00:26:44 +01:00
|
|
|
dwLastScrollTime = dwScrollTime;
|
1999-11-24 00:35:12 +01:00
|
|
|
|
2009-12-27 23:51:33 +01:00
|
|
|
SendMessageW (hwndLB, LB_SETTOPINDEX, nIndex, 0);
|
1999-11-24 00:35:12 +01:00
|
|
|
}
|
1999-01-24 20:12:34 +01:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|