COMCTL32: treectrl test - or why my mIRC patch *is* correct

Krzysztof Foltman wdev at foltman.com
Sun Jun 12 15:10:54 CDT 2005


... and that patch is not:

http://winehq.org/hypermail/wine-patches/2005/01/0190.html

There's a chance that both me and Crestez Leonard are right - and that 
there are some cases when the notification is sent when I assume it 
isn't. Or that it is sent, just not in XP where I tested it.

But, as the test is meant to prove, in the presented (trivial) cases, 
calling TreeView_SelectItem with the currently selected item doesn't 
cause any notifications to be sent. This does, as the author reported, 
conflict with MSDN, but it reflects the original Windows behaviour.

This is my first regression test for Wine, so please read it ten times 
and report any problems.

Krzysztof
-------------- next part --------------
#include <windows.h>
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include "wine/test.h"
 
#define _WIN32_IE 0x400

#include <commctrl.h>

HWND hTree;
HTREEITEM hRoot, hChild;

int pos = 0;
static char sequence[256];

void Clear()
{
    pos = 0;
    sequence[0] = '\0';
}

void AddItem(char ch)
{
    sequence[pos++] = ch;
    sequence[pos] = '\0';
}

void IdentifyItem(HTREEITEM hItem)
{
    if (hItem == hRoot) {
        AddItem('R');
        return;
    }
    if (hItem == hChild) {
        AddItem('C');
        return;
    }
    if (hItem == NULL) {
        AddItem('n');
        return;
    }
    AddItem('?');
}

void FillRoot()
{
    TVINSERTSTRUCT ins;

    Clear();
    AddItem('A');    
    ins.hParent = TVI_ROOT;
    ins.hInsertAfter = TVI_ROOT;
    ins.item.mask = TVIF_TEXT;
    ins.item.pszText = "Root";
    hRoot = TreeView_InsertItem(hTree, &ins);
    assert(hRoot);
  
    AddItem('B');
    ins.hParent = hRoot;
    ins.hInsertAfter = TVI_FIRST;
    ins.item.mask = TVIF_TEXT;
    ins.item.pszText = "Child";
    hChild = TreeView_InsertItem(hTree, &ins);
    assert(hChild);
    AddItem('.');
    
    ok(!strcmp(sequence, "AB."), "Item creation");
}

void DoTest1()
{
    TreeView_SelectItem(hTree, NULL);
    Clear();
    AddItem('1');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('2');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('3');
    TreeView_SelectItem(hTree, NULL);
    AddItem('4');
    TreeView_SelectItem(hTree, NULL);
    AddItem('5');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('.');
    ok(!strcmp(sequence, "1(nR)nR23(Rn)Rn45(nR)nR."), "root-none select test");
}

void DoTest2()
{
    TreeView_SelectItem(hTree, NULL);
    Clear();
    AddItem('1');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('2');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('3');
    TreeView_SelectItem(hTree, hChild);
    AddItem('4');
    TreeView_SelectItem(hTree, hChild);
    AddItem('5');
    TreeView_SelectItem(hTree, hRoot);
    AddItem('.');
    ok(!strcmp(sequence, "1(nR)nR23(RC)RC45(CR)CR."), "root-child select test");
}

LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg) {
                  
    case WM_CREATE:
    {
        hTree = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL, WS_CHILD|WS_VISIBLE|
            TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS, 
            0, 0, 300, 50, hWnd, (HMENU)100, GetModuleHandle(0), 0);
    
        SetFocus(hTree);
        return 0;
    }
    case WM_NOTIFY:
    {
        NMHDR *pHdr = (NMHDR *)lParam;
    
        if (pHdr->idFrom == 100) {
            NMTREEVIEW *pTreeView = (LPNMTREEVIEW) lParam;
            switch(pHdr->code) {
            case TVN_SELCHANGING:
                AddItem('(');
                IdentifyItem(pTreeView->itemOld.hItem);
                IdentifyItem(pTreeView->itemNew.hItem);
                return 0;
            case TVN_SELCHANGED:
                AddItem(')');
                IdentifyItem(pTreeView->itemOld.hItem);
                IdentifyItem(pTreeView->itemNew.hItem);
                return 0;
            }
        }
        return 0;
    }
  
    case WM_SIZE:
        MoveWindow(hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
        break;
      
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
  
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0L;
}

HWND hMainWnd;

void func_treeview()
{
    WNDCLASS wc;
    MSG msg;
    INITCOMMONCONTROLSEX icex;
    RECT rc;
  
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC   = ICC_TREEVIEW_CLASSES;
    InitCommonControlsEx(&icex);
  
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = GetModuleHandle(NULL);
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
    wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "MyTestWnd";
    wc.lpfnWndProc = MyWndProc;
    RegisterClass(&wc);
    
    hMainWnd = CreateWindowEx(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW, 
      CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandle(NULL), 0);
    GetClientRect(hMainWnd, &rc);
    FillRoot();
    DoTest1();
    DoTest2();
    PostMessage(hMainWnd, WM_CLOSE, 0, 0);
    while(GetMessage(&msg,0,0,0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}


More information about the wine-patches mailing list