treeview: Scrolling does not cause label being edited to lose focus.

This commit is contained in:
Duane Clark 2007-02-09 17:45:30 -08:00 committed by Alexandre Julliard
parent 909425d99d
commit 5bc1a8de87
2 changed files with 46 additions and 15 deletions

View File

@ -32,7 +32,7 @@
static HWND hMainWnd; static HWND hMainWnd;
static HWND hTree; static HWND hTree, hEdit;
static HTREEITEM hRoot, hChild; static HTREEITEM hRoot, hChild;
static int pos = 0; static int pos = 0;
@ -140,6 +140,37 @@ static void DoTest2(void)
ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n"); ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test\n");
} }
static void DoFocusTest(void)
{
TVINSERTSTRUCTA ins;
static CHAR child1[] = "Edit",
child2[] = "A really long string";
HTREEITEM hChild1, hChild2;
/* This test verifies that when a label is being edited, scrolling
* the treeview does not cause the label to lose focus. To test
* this, first some additional entries are added to generate
* scrollbars.
*/
ins.hParent = hRoot;
ins.hInsertAfter = hChild;
U(ins).item.mask = TVIF_TEXT;
U(ins).item.pszText = child1;
hChild1 = TreeView_InsertItem(hTree, &ins);
assert(hChild1);
ins.hInsertAfter = hChild1;
U(ins).item.mask = TVIF_TEXT;
U(ins).item.pszText = child2;
hChild2 = TreeView_InsertItem(hTree, &ins);
assert(hChild2);
ShowWindow(hMainWnd,SW_SHOW);
SendMessageW(hTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hChild);
hEdit = TreeView_EditLabel(hTree, hChild);
ScrollWindowEx(hTree, -10, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN);
ok(GetFocus() == hEdit, "Edit control should have focus\n");
}
static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
switch(msg) { switch(msg) {
@ -147,8 +178,8 @@ static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa
case WM_CREATE: case WM_CREATE:
{ {
hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE| hTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL, WS_CHILD|WS_VISIBLE|
TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS, TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS|TVS_EDITLABELS,
0, 0, 300, 50, hWnd, (HMENU)100, GetModuleHandleA(0), 0); 0, 0, 120, 100, hWnd, (HMENU)100, GetModuleHandleA(0), 0);
SetFocus(hTree); SetFocus(hTree);
return 0; return 0;
@ -214,12 +245,13 @@ START_TEST(treeview)
hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW, hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0); CW_USEDEFAULT, CW_USEDEFAULT, 130, 105, NULL, NULL, GetModuleHandleA(NULL), 0);
GetClientRect(hMainWnd, &rc); GetClientRect(hMainWnd, &rc);
FillRoot(); FillRoot();
DoTest1(); DoTest1();
DoTest2(); DoTest2();
DoFocusTest();
PostMessageA(hMainWnd, WM_CLOSE, 0, 0); PostMessageA(hMainWnd, WM_CLOSE, 0, 0);
while(GetMessageA(&msg,0,0,0)) { while(GetMessageA(&msg,0,0,0)) {

View File

@ -4654,9 +4654,6 @@ TREEVIEW_VScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
if (!(infoPtr->uInternalStatus & TV_VSCROLL)) if (!(infoPtr->uInternalStatus & TV_VSCROLL))
return 0; return 0;
if (infoPtr->hwndEdit)
SetFocus(infoPtr->hwnd);
if (!oldFirstVisible) if (!oldFirstVisible)
{ {
assert(infoPtr->root->firstChild == NULL); assert(infoPtr->root->firstChild == NULL);
@ -4727,9 +4724,6 @@ TREEVIEW_HScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
if (!(infoPtr->uInternalStatus & TV_HSCROLL)) if (!(infoPtr->uInternalStatus & TV_HSCROLL))
return FALSE; return FALSE;
if (infoPtr->hwndEdit)
SetFocus(infoPtr->hwnd);
maxWidth = infoPtr->treeWidth - infoPtr->clientWidth; maxWidth = infoPtr->treeWidth - infoPtr->clientWidth;
/* shall never occur */ /* shall never occur */
if (maxWidth <= 0) if (maxWidth <= 0)
@ -5619,6 +5613,11 @@ TREEVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
else else
return 0; return 0;
case WM_NCLBUTTONDOWN:
if (infoPtr->hwndEdit)
SetFocus(infoPtr->hwnd);
goto def;
case WM_NCPAINT: case WM_NCPAINT:
if (nc_paint (infoPtr, (HRGN)wParam)) if (nc_paint (infoPtr, (HRGN)wParam))
return 0; return 0;