comctl32/listview: Fix hittest flag calculation for negative Y values on report mode.
[wine] / dlls / comctl32 / comboex.c
index f576eee..2156896 100644 (file)
@@ -164,7 +164,7 @@ static void COMBOEX_DumpItem (CBE_ITEMDATA const *item)
 
 static void COMBOEX_DumpInput (COMBOBOXEXITEMW const *input)
 {
-    TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
+    TRACE("input - mask=%08x, iItem=%ld, pszText=%p, cchTM=%d, iImage=%d\n",
           input->mask, input->iItem, input->pszText, input->cchTextMax,
           input->iImage);
     if (input->mask & CBEIF_TEXT)
@@ -356,7 +356,7 @@ static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
 }
 
 
-static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
+static void COMBOEX_CopyItem (const CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
 {
     if (cit->mask & CBEIF_TEXT) {
         /*
@@ -467,7 +467,7 @@ static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
 }
 
 
-static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
+static CBE_ITEMDATA * COMBOEX_FindItem(const COMBOEX_INFO *infoPtr, INT_PTR index)
 {
     CBE_ITEMDATA *item;
     INT i;
@@ -500,7 +500,7 @@ static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO const *infoPtr)
 
 /* ***  CBEM_xxx message support  *** */
 
-static UINT COMBOEX_GetListboxText(COMBOEX_INFO *infoPtr, int n, LPWSTR buf)
+static UINT COMBOEX_GetListboxText(COMBOEX_INFO *infoPtr, INT_PTR n, LPWSTR buf)
 {
     CBE_ITEMDATA *item;
     LPCWSTR str;
@@ -527,9 +527,9 @@ static UINT COMBOEX_GetListboxText(COMBOEX_INFO *infoPtr, int n, LPWSTR buf)
 }
 
 
-static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
+static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT_PTR index)
 {
-    TRACE("(index=%d)\n", index);
+    TRACE("(index=%ld)\n", index);
 
     /* if item number requested does not exist then return failure */
     if ((index >= infoPtr->nb_items) || (index < 0)) return CB_ERR;
@@ -542,9 +542,9 @@ static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
 }
 
 
-static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
+static BOOL COMBOEX_GetItemW (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
 {
-    INT index = cit->iItem;
+    INT_PTR index = cit->iItem;
     CBE_ITEMDATA *item;
 
     TRACE("(...)\n");
@@ -563,7 +563,7 @@ static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
 }
 
 
-static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
+static BOOL COMBOEX_GetItemA (const COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
 {
     COMBOBOXEXITEMW tmpcit;
 
@@ -607,7 +607,7 @@ static inline BOOL COMBOEX_HasEditChanged (COMBOEX_INFO const *infoPtr)
 
 static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW const *cit)
 {
-    INT index;
+    INT_PTR index;
     CBE_ITEMDATA *item;
     NMCOMBOBOXEXW nmcit;
 
@@ -765,7 +765,7 @@ static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
 
 static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
 {
-    INT index = cit->iItem;
+    INT_PTR index = cit->iItem;
     CBE_ITEMDATA *item;
 
     if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
@@ -860,17 +860,19 @@ COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
     /* now search from after starting loc and wrapping back to start */
     for(i=start+1; i<count; i++) {
        CBE_ITEMDATA *item = get_item_data(infoPtr, i);
+       if ((LRESULT)item == CB_ERR) continue;
        if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
     }
     for(i=0; i<=start; i++) {
        CBE_ITEMDATA *item = get_item_data(infoPtr, i);
+       if ((LRESULT)item == CB_ERR) continue;
        if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
     }
     return CB_ERR;
 }
 
 
-static DWORD_PTR COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
+static DWORD_PTR COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT_PTR index)
 {
     CBE_ITEMDATA const *item1;
     CBE_ITEMDATA const *item2;
@@ -893,7 +895,7 @@ static DWORD_PTR COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
 }
 
 
-static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
+static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT_PTR index)
 {
     CBE_ITEMDATA *item;
     INT sel;
@@ -901,7 +903,7 @@ static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
     if (!(item = COMBOEX_FindItem(infoPtr, index)))
        return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
 
-    TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
+    TRACE("selecting item %ld text=%s\n", index, debugstr_txt(item->pszText));
     infoPtr->selected = index;
 
     sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
@@ -910,7 +912,7 @@ static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
 }
 
 
-static DWORD_PTR COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD_PTR data)
+static DWORD_PTR COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT_PTR index, DWORD_PTR data)
 {
     CBE_ITEMDATA *item1;
     CBE_ITEMDATA const *item2;
@@ -1118,13 +1120,14 @@ static LRESULT COMBOEX_Create (HWND hwnd, CREATESTRUCTA const *cs)
 }
 
 
-static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam)
 {
     LRESULT lret;
     INT command = HIWORD(wParam);
     CBE_ITEMDATA *item = 0;
     WCHAR wintext[520];
-    INT cursel, n, oldItem;
+    INT cursel, n;
+    INT_PTR oldItem;
     NMCBEENDEDITW cbeend;
     DWORD oldflags;
     HWND parent = infoPtr->hwndNotify;
@@ -1224,7 +1227,7 @@ static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lPa
         */
        oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
        if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
-           ERR("item %d not found. Problem!\n", oldItem);
+           ERR("item %ld not found. Problem!\n", oldItem);
            break;
        }
        infoPtr->selected = oldItem;
@@ -1534,11 +1537,11 @@ static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT const *di
 
        /* now draw the text */
        if (!IsWindowVisible (infoPtr->hwndEdit)) {
-           nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
-                               COLOR_HIGHLIGHT : COLOR_WINDOW);
+           nbkc = (dis->itemState & ODS_SELECTED) ?
+                   comctl32_color.clrHighlight : comctl32_color.clrWindow;
            bkc = SetBkColor (dis->hDC, nbkc);
-           ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
-                               COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
+           ntxc = (dis->itemState & ODS_SELECTED) ?
+                   comctl32_color.clrHighlightText : comctl32_color.clrWindowText;
            txc = SetTextColor (dis->hDC, ntxc);
            x = xbase + xioff;
            y = dis->rcItem.top +
@@ -1668,6 +1671,14 @@ static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
 }
 
 
+static LRESULT COMBOEX_SetRedraw(COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
+{
+    LRESULT ret = DefWindowProcW( infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam );
+    if (wParam) RedrawWindow( infoPtr->hwndSelf, NULL, 0, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN );
+    return ret;
+}
+
+
 static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
 {
     RECT cbx_wrect, cbx_crect, cb_wrect;
@@ -1741,7 +1752,7 @@ COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
             * The following was determined by traces of the native
             */
             hDC = (HDC) wParam;
-           obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
+           obkc = SetBkColor (hDC, comctl32_color.clrWindow);
             GetClientRect (hwnd, &rect);
             TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
            ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
@@ -1750,7 +1761,7 @@ COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                   hwnd, uMsg, wParam, lParam);
 
        case WM_KEYDOWN: {
-           INT oldItem, selected, step = 1;
+           INT_PTR oldItem, selected, step = 1;
            CBE_ITEMDATA *item;
 
            switch ((INT)wParam)
@@ -1787,7 +1798,7 @@ COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
                InvalidateRect (infoPtr->hwndCombo, 0, 0);
                if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
-                   ERR("item %d not found. Problem!\n", oldItem);
+                   ERR("item %ld not found. Problem!\n", oldItem);
                    break;
                }
                infoPtr->selected = oldItem;
@@ -1829,7 +1840,7 @@ COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                if (selected != -1) {
                     cmp_func_t cmptext = get_cmp_func(infoPtr);
                    item = COMBOEX_FindItem (infoPtr, selected);
-                   TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
+                   TRACE("handling VK_RETURN, selected = %ld, selected_text=%s\n",
                          selected, debugstr_txt(item->pszText));
                    TRACE("handling VK_RETURN, edittext=%s\n",
                          debugstr_w(edit_text));
@@ -1944,7 +1955,7 @@ COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
             * The following was determined by traces of the native
             */
             hDC = (HDC) wParam;
-           obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
+           obkc = SetBkColor (hDC, comctl32_color.clrWindow);
             GetClientRect (hwnd, &rect);
             TRACE("erasing (%s)\n", wine_dbgstr_rect(&rect));
            ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
@@ -2079,8 +2090,8 @@ COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                LPCWSTR lastwrk;
                 cmp_func_t cmptext = get_cmp_func(infoPtr);
 
-               INT selected = SendMessageW (infoPtr->hwndCombo,
-                                            CB_GETCURSEL, 0, 0);
+               INT_PTR selected = SendMessageW (infoPtr->hwndCombo,
+                                                 CB_GETCURSEL, 0, 0);
 
                /* lstrlenW( lastworkingURL ) */
 
@@ -2093,7 +2104,7 @@ COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                    lastwrk = COMBOEX_GetText(infoPtr, item);
                }
 
-               TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
+               TRACE("handling EN_CHANGE, selected = %ld, selected_text=%s\n",
                      selected, debugstr_w(lastwrk));
                TRACE("handling EN_CHANGE, edittext=%s\n",
                      debugstr_w(edit_text));
@@ -2273,7 +2284,7 @@ COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
 /*   Window messages passed to parent */
        case WM_COMMAND:
-           return COMBOEX_Command (infoPtr, wParam, lParam);
+           return COMBOEX_Command (infoPtr, wParam);
 
        case WM_NOTIFY:
            if (infoPtr->NtfUnicode)
@@ -2301,6 +2312,9 @@ COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        case WM_SIZE:
            return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
 
+        case WM_SETREDRAW:
+            return COMBOEX_SetRedraw(infoPtr, wParam, lParam);
+
         case WM_WINDOWPOSCHANGING:
            return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
 
@@ -2308,6 +2322,10 @@ COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
             SetFocus(infoPtr->hwndCombo);
             return 0;
 
+        case WM_SYSCOLORCHANGE:
+            COMCTL32_RefreshSysColors();
+            return 0;
+
        default:
            if ((uMsg >= WM_USER) && (uMsg < WM_APP) && !COMCTL32_IsReflectedMessage(uMsg))
                ERR("unknown msg %04x wp=%08lx lp=%08lx\n",uMsg,wParam,lParam);