Ignore:
Timestamp:
Mar 17, 2000, 6:12:08 PM (25 years ago)
Author:
cbratschi
Message:

fixed setwindowpos bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/listbox.cpp

    r3117 r3144  
    1 /* $Id: listbox.cpp,v 1.22 2000-03-14 18:27:25 cbratschi Exp $ */
     1/* $Id: listbox.cpp,v 1.23 2000-03-17 17:12:07 cbratschi Exp $ */
    22/*
    33 * Listbox controls
     
    88 * Corel version: 20000212
    99 * WINE version: 991212
     10 *
     11 * Status: ???
     12 * Version: ???
    1013 */
    1114
     
    2427
    2528/* Unimplemented yet:
    26  * - LBS_NOSEL
    27  * - LBS_USETABSTOPS
    28  * - Unicode
    29  * - Locale handling
     29 - LBS_NOSEL
     30 - LBS_USETABSTOPS
     31 - Locale handling
     32 - OS/2 default font bug: Odin about dialog -> LISTBOX_UpdateSize
     33 - WS_EX_NOPARENTNOTIFY
     34 - VK_LINEDOWN -> bottom most item not always visible
     35 - performance not optimized
    3036 */
    3137
     
    459465
    460466/***********************************************************************
    461  *           LISTBOX_PaintItem
    462  *
    463  * Paint an item.
    464  */
    465 static void LISTBOX_PaintItem( HWND hwnd, LB_DESCR *descr, HDC hdc,
     467 *           LISTBOX_DrawItem
     468 *
     469 * Draw an item.
     470 */
     471static void LISTBOX_DrawItem( HWND hwnd, LB_DESCR *descr, HDC hdc,
    466472                               const RECT *rect, INT index, UINT action )
    467473{
     
    557563 * Change the redraw flag.
    558564 */
    559 static void LISTBOX_SetRedraw( HWND hwnd, LB_DESCR *descr, BOOL on )
     565static LRESULT LISTBOX_SetRedraw( HWND hwnd, LB_DESCR *descr, BOOL on )
    560566{
    561567    if (on)
    562568    {
    563         if (!(descr->style & LBS_NOREDRAW)) return;
     569        if (!(descr->style & LBS_NOREDRAW)) return 0;
    564570        descr->style &= ~LBS_NOREDRAW;
    565571        LISTBOX_UpdateScroll( hwnd, descr );
    566572    }
    567573    else descr->style |= LBS_NOREDRAW;
     574
     575    return 0;
    568576}
    569577
     
    595603        SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) );
    596604    SetWindowOrgEx( hdc, descr->horz_pos, 0, NULL );
    597     LISTBOX_PaintItem( hwnd, descr, hdc, &rect, index, action );
     605    LISTBOX_DrawItem( hwnd, descr, hdc, &rect, index, action );
    598606    if (oldFont) SelectObject( hdc, oldFont );
    599607    if (oldBrush) SelectObject( hdc, oldBrush );
     
    865873
    866874/***********************************************************************
    867  *           LISTBOX_Paint
    868  */
    869 static LRESULT LISTBOX_Paint( HWND hwnd, LB_DESCR *descr, HDC hdc )
     875 *           LISTBOX_Draw
     876 */
     877static LRESULT LISTBOX_Draw( HWND hwnd, LB_DESCR *descr, HDC hdc )
    870878{
    871879    INT i, col_pos = descr->page_size - 1;
     
    897905        /* Special case for empty listbox: paint focus rect */
    898906        rect.bottom = rect.top + descr->item_height;
    899         LISTBOX_PaintItem( hwnd, descr, hdc, &rect, descr->focus_item,
     907        LISTBOX_DrawItem( hwnd, descr, hdc, &rect, descr->focus_item,
    900908                           ODA_FOCUS );
    901909        rect.top = rect.bottom;
     
    909917            rect.bottom = rect.top + descr->items[i].height;
    910918
    911         LISTBOX_PaintItem( hwnd, descr, hdc, &rect, i, ODA_DRAWENTIRE );
     919        LISTBOX_DrawItem( hwnd, descr, hdc, &rect, i, ODA_DRAWENTIRE );
    912920        rect.top = rect.bottom;
    913921
     
    11001108 * Returns the item height.
    11011109 */
    1102 static INT LISTBOX_SetFont( HWND hwnd, LB_DESCR *descr, HFONT font )
     1110static LRESULT LISTBOX_SetFont(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
    11031111{
    11041112    HDC hdc;
     
    11061114    TEXTMETRICA tm;
    11071115
    1108     descr->font = font;
     1116    descr->font = (HFONT)wParam;
    11091117
    11101118    if (!(hdc = GetDCEx( hwnd, 0, DCX_CACHE )))
    11111119    {
    1112         //ERR("unable to get DC.\n" );
    1113         return 16;
    1114     }
    1115     if (font) oldFont = SelectObject( hdc, font );
     1120      //ERR("unable to get DC.\n" );
     1121      descr->item_height =  16;
     1122      return 0;
     1123    }
     1124    if (descr->font) oldFont = SelectObject(hdc,descr->font);
    11161125    GetTextMetricsA( hdc, &tm );
    11171126    if (oldFont) SelectObject( hdc, oldFont );
     
    11191128    if (!IS_OWNERDRAW(descr))
    11201129        LISTBOX_SetItemHeight( hwnd, descr, 0, tm.tmHeight );
    1121     return tm.tmHeight ;
     1130
     1131    descr->item_height =  tm.tmHeight;
     1132
     1133    if (lParam) InvalidateRect( hwnd, 0, TRUE );
     1134
     1135    return 0;
    11221136}
    11231137
     
    12451259    {
    12461260        INT oldsel = descr->selected_item;
    1247         //SvL: Why was this commented out??? (enabled in latest wine code)
     1261        //SvL: Why was this commented out??? (enabled in latest wine code)
    12481262        if (index == oldsel) return LB_OKAY;
    12491263
     
    14031417}
    14041418
     1419static LRESULT LISTBOX_AddString(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     1420{
     1421  wParam = LISTBOX_FindStringPos( hwnd, descr, (LPCSTR)lParam, FALSE );
     1422  return LISTBOX_InsertString( hwnd, descr, wParam, (LPCSTR)lParam );
     1423}
     1424
     1425static LRESULT LISTBOX_AddFile(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     1426{
     1427  wParam = LISTBOX_FindFileStrPos( hwnd, descr, (LPCSTR)lParam );
     1428  return LISTBOX_InsertString( hwnd, descr, wParam, (LPCSTR)lParam );
     1429}
    14051430
    14061431/***********************************************************************
     
    14981523}
    14991524
     1525static LRESULT LISTBOX_DeleteString(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     1526{
     1527  if (LISTBOX_RemoveItem( hwnd, descr, wParam) != LB_ERR)
     1528    return descr->nb_items;
     1529  else
     1530    return LB_ERR;
     1531}
    15001532
    15011533/***********************************************************************
    15021534 *           LISTBOX_ResetContent
    15031535 */
    1504 static void LISTBOX_ResetContent( HWND hwnd, LB_DESCR *descr )
     1536static LRESULT LISTBOX_ResetContent( HWND hwnd, LB_DESCR *descr,BOOL refresh)
    15051537{
    15061538    INT i;
     
    15141546    descr->anchor_item   = -1;
    15151547    descr->items         = NULL;
    1516     LISTBOX_UpdateScroll( hwnd, descr );
    1517     InvalidateRect( hwnd, NULL, TRUE );
     1548    if (refresh)
     1549    {
     1550      LISTBOX_UpdateScroll( hwnd, descr );
     1551      InvalidateRect( hwnd, NULL, TRUE );
     1552    }
     1553
     1554    return 0;
    15181555}
    15191556
     
    15251562{
    15261563    LRESULT ret;
     1564    INT oldcount = descr->nb_items;
    15271565
    15281566    if (HAS_STRINGS(descr) || !HAS_NODATA(descr)) return LB_ERR;
     
    15811619    LISTBOX_UpdateScroll( hwnd, descr );
    15821620    InvalidateRect(hwnd,NULL,TRUE);
     1621
     1622    /* Move selection and focused item */
     1623    /* If listbox was empty, set focus to the first item */
     1624    if (oldcount == 0)
     1625      LISTBOX_SetCaretIndex( hwnd, descr, 0, FALSE );
    15831626
    15841627    return LB_OKAY;
     
    17891832    UINT pulScrollLines = 3;
    17901833
     1834    if (wParam & (MK_SHIFT | MK_CONTROL))
     1835      return DefWindowProcA(hwnd,WM_MOUSEWHEEL,wParam,lParam);
     1836
    17911837    SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
    17921838
     
    20392085 * WM_MOUSEMOVE handler.
    20402086 */
    2041 static void LISTBOX_HandleMouseMove( HWND hwnd, LB_DESCR *descr,
     2087static LRESULT LISTBOX_HandleMouseMove( HWND hwnd, LB_DESCR *descr,
    20422088                                     INT x, INT y )
    20432089{
     
    20452091    TIMER_DIRECTION dir;
    20462092
    2047     if (!descr->captured) return;
     2093    if (GetCapture() != hwnd) return 0;
     2094    if (!descr->captured) return 0;
    20482095
    20492096    if (descr->style & LBS_MULTICOLUMN)
     
    20842131
    20852132    LISTBOX_Timer = dir;
     2133
     2134    return 0;
    20862135}
    20872136
     
    22302279 *           LISTBOX_Create
    22312280 */
    2232 static BOOL LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc )
     2281static LRESULT LISTBOX_Create( HWND hwnd, LPHEADCOMBO lphc )
    22332282{
    22342283    LB_DESCR *descr;
     
    22372286
    22382287    if (!(descr = (LB_DESCR*)HeapAlloc( GetProcessHeap(), 0, sizeof(*descr) )))
    2239         return FALSE;
     2288        return -1;
    22402289    if (!(descr->heap = HeapCreate( 0, 0x10000, 0 )))
    22412290    {
    22422291        HeapFree( GetProcessHeap(), 0, descr );
    2243         return FALSE;
     2292        return -1;
    22442293    }
    22452294    GetClientRect( hwnd, &rect );
     
    22822331    if (descr->style & LBS_MULTICOLUMN) descr->style &= ~LBS_OWNERDRAWVARIABLE;
    22832332    if (descr->style & LBS_OWNERDRAWVARIABLE) descr->style |= LBS_NOINTEGRALHEIGHT;
    2284     descr->item_height = LISTBOX_SetFont( hwnd, descr, 0 );
     2333    LISTBOX_SetFont(hwnd,descr,0,(LPARAM)FALSE);
    22852334
    22862335    if (descr->style & LBS_OWNERDRAWFIXED)
     
    23062355    }
    23072356
    2308     return TRUE;
    2309 }
    2310 
     2357    return 0;
     2358}
     2359
     2360static LRESULT LISTBOX_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
     2361{
     2362  DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
     2363
     2364  /*
     2365   * When a listbox is not in a combobox and the look
     2366   * is win95,  the WS_BORDER style is replaced with
     2367   * the WS_EX_CLIENTEDGE style.
     2368   */
     2369  if (dwStyle & WS_BORDER)
     2370  {
     2371    SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE);
     2372    SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE)  & ~ WS_BORDER);
     2373  }
     2374
     2375  return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
     2376}
    23112377
    23122378/***********************************************************************
     
    23152381static BOOL LISTBOX_Destroy( HWND hwnd, LB_DESCR *descr )
    23162382{
    2317     LISTBOX_ResetContent( hwnd, descr );
     2383    LISTBOX_ResetContent(hwnd,descr,FALSE);
    23182384    HeapDestroy( descr->heap );
    23192385    HeapFree( GetProcessHeap(), 0, descr );
     
    23222388}
    23232389
     2390static LRESULT LISTBOX_GetItemData(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2391{
     2392  if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
     2393    return LB_ERR;
     2394  return descr->items[wParam].data;
     2395}
     2396
     2397static LRESULT LISTBOX_SetItemData(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2398{
     2399  if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
     2400    return LB_ERR;
     2401  descr->items[wParam].data = (DWORD)lParam;
     2402  return LB_OKAY;
     2403}
     2404
     2405static LRESULT LISTBOX_GetCount(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2406{
     2407  return descr->nb_items;
     2408}
     2409
     2410static LRESULT LISTBOX_GetTextLen(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2411{
     2412  if (wParam >= descr->nb_items)
     2413    return LB_ERR;
     2414  return (HAS_STRINGS(descr) ? strlen(descr->items[wParam].str)
     2415                               : sizeof(DWORD));
     2416}
     2417
     2418static LRESULT LISTBOX_GetCurSel(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2419{
     2420  if (descr->nb_items==0)
     2421    return LB_ERR;
     2422  if (!IS_MULTISELECT(descr))
     2423    return descr->selected_item;
     2424  /* else */
     2425  if (descr->selected_item!=-1)
     2426    return descr->selected_item;
     2427  /* else */
     2428  return descr->focus_item;
     2429  /* otherwise, if the user tries to move the selection with the    */
     2430  /* arrow keys, we will give the application something to choke on */
     2431}
     2432
     2433static LRESULT LISTBOX_GetTopIndex(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2434{
     2435  return descr->top_item;
     2436}
     2437
     2438static LRESULT LISTBOX_ItemFromPoint(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2439{
     2440  POINT pt;
     2441  RECT rect;
     2442
     2443  pt.x = LOWORD(lParam);
     2444  pt.y = HIWORD(lParam);
     2445  rect.left = 0;
     2446  rect.top = 0;
     2447  rect.right = descr->width;
     2448  rect.bottom = descr->height;
     2449
     2450  return MAKELONG( LISTBOX_GetItemFromPoint(hwnd, descr, pt.x, pt.y),
     2451                   !PtInRect( &rect, pt ) );
     2452}
     2453
     2454static LRESULT LISTBOX_HandleSetCaretIndex(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2455{
     2456  if ((!IS_MULTISELECT(descr)) && (descr->selected_item != -1)) return LB_ERR;
     2457  if (LISTBOX_SetCaretIndex( hwnd, descr, wParam, !lParam ) == LB_ERR)
     2458    return LB_ERR;
     2459  else
     2460    return LB_OKAY;
     2461}
     2462
     2463static LRESULT LISTBOX_GetCaretIndex(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2464{
     2465  return descr->focus_item;
     2466}
     2467
     2468static LRESULT LISTBOX_SelectString(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2469{
     2470  INT index = LISTBOX_FindString( hwnd, descr, wParam,
     2471                                 (LPCSTR)lParam, FALSE );
     2472  if (index == LB_ERR)
     2473    return LB_ERR;
     2474  LISTBOX_SetSelection( hwnd, descr, index, TRUE, FALSE );
     2475  return index;
     2476}
     2477
     2478static LRESULT LISTBOX_GetSel(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2479{
     2480  if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
     2481    return LB_ERR;
     2482  return descr->items[wParam].selected;
     2483}
     2484
     2485static LRESULT LISTBOX_SetCurSel(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2486{
     2487  if (IS_MULTISELECT(descr)) return LB_ERR;
     2488  LISTBOX_SetCaretIndex( hwnd, descr, wParam, TRUE );
     2489  return LISTBOX_SetSelection( hwnd, descr, wParam, TRUE, FALSE );
     2490}
     2491
     2492static LRESULT LISTBOX_SelItemRange(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2493{
     2494  if (LOWORD(lParam) <= HIWORD(lParam))
     2495    return LISTBOX_SelectItemRange( hwnd, descr, LOWORD(lParam),
     2496                                    HIWORD(lParam), wParam );
     2497  else
     2498    return LISTBOX_SelectItemRange( hwnd, descr, HIWORD(lParam),
     2499                                    LOWORD(lParam), wParam );
     2500}
     2501
     2502static LRESULT LISTBOX_SelItemRangeEx(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2503{
     2504  if ((INT)lParam >= (INT)wParam)
     2505    return LISTBOX_SelectItemRange( hwnd, descr, wParam, lParam, TRUE );
     2506  else
     2507    return LISTBOX_SelectItemRange( hwnd, descr, lParam, wParam, FALSE);
     2508}
     2509
     2510static LRESULT LISTBOX_GetHorizontalExtent(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2511{
     2512  return descr->horz_extent;
     2513}
     2514
     2515static LRESULT LISTBOX_GetAnchorIndex(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2516{
     2517  return descr->anchor_item;
     2518}
     2519
     2520static LRESULT LISTBOX_SetAnchorIndex(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2521{
     2522  if (((INT)wParam < -1) || ((INT)wParam >= descr->nb_items))
     2523    return LB_ERR;
     2524  descr->anchor_item = (INT)wParam;
     2525  return LB_OKAY;
     2526}
     2527
     2528static LRESULT LISTBOX_GetLocale(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2529{
     2530  return descr->locale;
     2531}
     2532
     2533static LRESULT LISTBOX_SetLocale(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2534{
     2535  descr->locale = (LCID)wParam;  /* FIXME: should check for valid lcid */
     2536  return LB_OKAY;
     2537}
     2538
     2539static LRESULT LISTBOX_CaretOn(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2540{
     2541  if (descr->caret_on)
     2542    return LB_OKAY;
     2543  descr->caret_on = TRUE;
     2544  if ((descr->focus_item != -1) && (descr->in_focus))
     2545    LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
     2546  return LB_OKAY;
     2547}
     2548
     2549static LRESULT LISTBOX_CaretOff(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2550{
     2551  if (!descr->caret_on)
     2552    return LB_OKAY;
     2553  descr->caret_on = FALSE;
     2554  if ((descr->focus_item != -1) && (descr->in_focus))
     2555    LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
     2556  return LB_OKAY;
     2557}
     2558
     2559static LRESULT LISTBOX_Enable(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2560{
     2561  InvalidateRect( hwnd, NULL, TRUE );
     2562  return 0;
     2563}
     2564
     2565static LRESULT LISTBOX_GetDlgCode(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2566{
     2567  return DLGC_WANTARROWS | DLGC_WANTCHARS;
     2568}
     2569
     2570static LRESULT LISTBOX_Paint(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2571{
     2572  PAINTSTRUCT ps;
     2573  HDC hdc = ( wParam ) ? ((HDC)wParam) :  BeginPaint( hwnd, &ps );
     2574  LRESULT ret;
     2575
     2576  ret = LISTBOX_Draw( hwnd, descr, hdc );
     2577  if( !wParam ) EndPaint( hwnd, &ps );
     2578
     2579  return ret;
     2580}
     2581
     2582static LRESULT LISTBOX_Size(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2583{
     2584  LISTBOX_UpdateSize( hwnd, descr );
     2585  return 0;
     2586}
     2587
     2588static LRESULT LISTBOX_GetFont(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2589{
     2590  return descr->font;
     2591}
     2592
     2593static LRESULT LISTBOX_SetFocus(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2594{
     2595  descr->in_focus = TRUE;
     2596  descr->caret_on = TRUE;
     2597  if (descr->focus_item != -1)
     2598    LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
     2599  SEND_NOTIFICATION( hwnd, descr, LBN_SETFOCUS );
     2600  return 0;
     2601}
     2602
     2603static LRESULT LISTBOX_KillFocus(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2604{
     2605  descr->in_focus = FALSE;
     2606  if ((descr->focus_item != -1) && descr->caret_on)
     2607    LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
     2608  SEND_NOTIFICATION( hwnd, descr, LBN_KILLFOCUS );
     2609  return 0;
     2610}
     2611
     2612static LRESULT LISTBOX_MouseActivate(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2613{
     2614  return MA_NOACTIVATE;
     2615}
     2616
     2617static LRESULT LISTBOX_LButtonDblClk(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2618{
     2619  if (descr->style & LBS_NOTIFY)
     2620    SEND_NOTIFICATION( hwnd, descr, LBN_DBLCLK );
     2621  return 0;
     2622}
     2623
     2624static LRESULT LISTBOX_EraseBackground(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2625{
     2626  if (IS_OWNERDRAW(descr))
     2627  {
     2628    RECT rect;
     2629    HBRUSH hbrush = SendMessageA( descr->owner, WM_CTLCOLORLISTBOX, wParam, (LPARAM)hwnd );
     2630
     2631    GetClientRect(hwnd, &rect);
     2632    if (hbrush) FillRect( (HDC)wParam, &rect, hbrush );
     2633  }
     2634
     2635  return 1;
     2636}
     2637
     2638static LRESULT LISTBOX_DropFiles(HWND hwnd,LB_DESCR *descr,WPARAM wParam,LPARAM lParam)
     2639{
     2640  if ( !descr->lphc )
     2641    return SendMessageA( descr->owner, WM_DROPFILES, wParam, lParam );
     2642
     2643  return 0;
     2644}
     2645
     2646static LRESULT LISTBOX_HandleDragDrop(HWND hwnd,LB_DESCR *descr,UINT msg,WPARAM wParam,LPARAM lParam)
     2647{
     2648  if( !descr->lphc )
     2649  {
     2650    LPDRAGINFO dragInfo = (LPDRAGINFO)lParam;
     2651
     2652    dragInfo->l = LISTBOX_GetItemFromPoint( hwnd, descr, dragInfo->pt.x,
     2653                                                dragInfo->pt.y );
     2654    return SendMessageA( descr->owner, msg, wParam, lParam );
     2655  }
     2656
     2657  return 0;
     2658}
    23242659
    23252660/***********************************************************************
     
    23292664                                      WPARAM wParam, LPARAM lParam )
    23302665{
    2331     LRESULT ret;
    23322666    LB_DESCR *descr;
    23332667
    23342668    if (!(descr = (LB_DESCR*)GetInfoPtr(hwnd)))
    23352669    {
    2336         switch (msg)
    2337         {
    2338             case WM_CREATE:
    2339             {
    2340                 if (!LISTBOX_Create( hwnd, NULL ))
    2341                      return -1;
    2342                 //TRACE("creating wnd=%04x descr=%p\n",
    2343                 //      hwnd, *(LB_DESCR **)wnd->wExtra );
    2344                 return 0;
    2345             }
    2346             case WM_NCCREATE:
    2347             {
    2348                 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
    2349 
    2350                 /*
    2351                  * When a listbox is not in a combobox and the look
    2352                  * is win95,  the WS_BORDER style is replaced with
    2353                  * the WS_EX_CLIENTEDGE style.
    2354                  */
    2355                 if (dwStyle & WS_BORDER)
    2356                 {
    2357                     SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE);
    2358                     SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE)  & ~ WS_BORDER);
    2359                 }
    2360             }
    2361         }
    2362         /* Ignore all other messages before we get a WM_CREATE */
    2363         return DefWindowProcA( hwnd, msg, wParam, lParam );
    2364     }
    2365 
    2366     //TRACE("[%04x]: msg %s wp %08x lp %08lx\n",
    2367     //             wnd->hwndSelf, SPY_GetMsgName(msg), wParam, lParam );
     2670      switch (msg)
     2671      {
     2672        case WM_CREATE:
     2673          return LISTBOX_Create(hwnd,NULL);
     2674
     2675        case WM_NCCREATE:
     2676          return LISTBOX_NCCreate(hwnd,wParam,lParam);
     2677      }
     2678      /* Ignore all other messages before we get a WM_CREATE */
     2679      return DefWindowProcA( hwnd, msg, wParam, lParam );
     2680    }
     2681
    23682682    switch(msg)
    23692683    {
    2370     case LB_RESETCONTENT:
    2371         LISTBOX_ResetContent( hwnd, descr );
    2372         return 0;
    2373 
    2374     case LB_ADDSTRING:
    2375         wParam = LISTBOX_FindStringPos( hwnd, descr, (LPCSTR)lParam, FALSE );
     2684      case LB_RESETCONTENT:
     2685        return LISTBOX_ResetContent(hwnd,descr,TRUE);
     2686
     2687      case LB_ADDSTRING:
     2688        return LISTBOX_AddString(hwnd,descr,wParam,lParam);
     2689
     2690      case LB_INSERTSTRING:
    23762691        return LISTBOX_InsertString( hwnd, descr, wParam, (LPCSTR)lParam );
    23772692
    2378     case LB_INSERTSTRING:
    2379         return LISTBOX_InsertString( hwnd, descr, wParam, (LPCSTR)lParam );
    2380 
    2381     case LB_ADDFILE:
    2382         wParam = LISTBOX_FindFileStrPos( hwnd, descr, (LPCSTR)lParam );
    2383         return LISTBOX_InsertString( hwnd, descr, wParam, (LPCSTR)lParam );
    2384 
    2385     case LB_DELETESTRING:
    2386         if (LISTBOX_RemoveItem( hwnd, descr, wParam) != LB_ERR)
    2387            return descr->nb_items;
    2388         else
    2389            return LB_ERR;
    2390 
    2391     case LB_GETITEMDATA:
    2392         if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
    2393             return LB_ERR;
    2394         return descr->items[wParam].data;
    2395 
    2396     case LB_SETITEMDATA:
    2397         if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
    2398             return LB_ERR;
    2399         descr->items[wParam].data = (DWORD)lParam;
    2400         return LB_OKAY;
    2401 
    2402     case LB_GETCOUNT:
    2403         return descr->nb_items;
    2404 
    2405     case LB_GETTEXT:
     2693      case LB_ADDFILE:
     2694        return LISTBOX_AddFile(hwnd,descr,wParam,lParam);
     2695
     2696      case LB_DELETESTRING:
     2697        return LISTBOX_DeleteString(hwnd,descr,wParam,lParam);
     2698
     2699      case LB_GETITEMDATA:
     2700        return LISTBOX_GetItemData(hwnd,descr,wParam,lParam);
     2701
     2702      case LB_SETITEMDATA:
     2703        return LISTBOX_SetItemData(hwnd,descr,wParam,lParam);
     2704
     2705      case LB_GETCOUNT:
     2706        return LISTBOX_GetCount(hwnd,descr,wParam,lParam);
     2707
     2708      case LB_GETTEXT:
    24062709        return LISTBOX_GetText( hwnd, descr, wParam, (LPSTR)lParam );
    24072710
    2408     case LB_GETTEXTLEN:
    2409         if (wParam >= descr->nb_items)
    2410             return LB_ERR;
    2411         return (HAS_STRINGS(descr) ? strlen(descr->items[wParam].str)
    2412                                    : sizeof(DWORD));
    2413 
    2414     case LB_GETCURSEL:
    2415         if (descr->nb_items==0)
    2416           return LB_ERR;
    2417         if (!IS_MULTISELECT(descr))
    2418           return descr->selected_item;
    2419         /* else */
    2420         if (descr->selected_item!=-1)
    2421           return descr->selected_item;
    2422         /* else */
    2423         return descr->focus_item;
    2424         /* otherwise, if the user tries to move the selection with the    */
    2425         /* arrow keys, we will give the application something to choke on */
    2426     case LB_GETTOPINDEX:
    2427         return descr->top_item;
    2428 
    2429     case LB_GETITEMHEIGHT:
     2711      case LB_GETTEXTLEN:
     2712        return LISTBOX_GetTextLen(hwnd,descr,wParam,lParam);
     2713
     2714      case LB_GETCURSEL:
     2715        return LISTBOX_GetCurSel(hwnd,descr,wParam,lParam);
     2716
     2717      case LB_GETTOPINDEX:
     2718        return LISTBOX_GetTopIndex(hwnd,descr,wParam,lParam);
     2719
     2720      case LB_GETITEMHEIGHT:
    24302721        return LISTBOX_GetItemHeight( hwnd, descr, wParam );
    24312722
    2432     case LB_SETITEMHEIGHT:
     2723      case LB_SETITEMHEIGHT:
    24332724        return LISTBOX_SetItemHeight( hwnd, descr, wParam, lParam );
    24342725
    2435     case LB_ITEMFROMPOINT:
    2436         {
    2437             POINT pt;
    2438             RECT rect;
    2439 
    2440             pt.x = LOWORD(lParam);
    2441             pt.y = HIWORD(lParam);
    2442             rect.left = 0;
    2443             rect.top = 0;
    2444             rect.right = descr->width;
    2445             rect.bottom = descr->height;
    2446 
    2447             return MAKELONG( LISTBOX_GetItemFromPoint(hwnd, descr, pt.x, pt.y),
    2448                              !PtInRect( &rect, pt ) );
    2449         }
    2450 
    2451     case LB_SETCARETINDEX:
    2452         if ((!IS_MULTISELECT(descr)) && (descr->selected_item != -1)) return LB_ERR;
    2453         if (LISTBOX_SetCaretIndex( hwnd, descr, wParam, !lParam ) == LB_ERR)
    2454             return LB_ERR;
    2455         else
    2456              return LB_OKAY;
    2457 
    2458     case LB_GETCARETINDEX:
    2459         return descr->focus_item;
    2460 
    2461     case LB_SETTOPINDEX:
     2726      case LB_ITEMFROMPOINT:
     2727        return LISTBOX_ItemFromPoint(hwnd,descr,wParam,lParam);
     2728
     2729      case LB_SETCARETINDEX:
     2730        return LISTBOX_HandleSetCaretIndex(hwnd,descr,wParam,lParam);
     2731
     2732      case LB_GETCARETINDEX:
     2733        return LISTBOX_GetCaretIndex(hwnd,descr,wParam,lParam);
     2734
     2735      case LB_SETTOPINDEX:
    24622736        return LISTBOX_SetTopItem( hwnd, descr, wParam, TRUE );
    24632737
    2464     case LB_SETCOLUMNWIDTH:
     2738      case LB_SETCOLUMNWIDTH:
    24652739        return LISTBOX_SetColumnWidth( hwnd, descr, wParam );
    24662740
    2467     case LB_GETITEMRECT:
     2741      case LB_GETITEMRECT:
    24682742        return LISTBOX_GetItemRect( hwnd, descr, wParam, (RECT *)lParam );
    24692743
    2470     case LB_FINDSTRING:
     2744      case LB_FINDSTRING:
    24712745        return LISTBOX_FindString( hwnd, descr, wParam, (LPCSTR)lParam, FALSE );
    24722746
    2473     case LB_FINDSTRINGEXACT:
     2747      case LB_FINDSTRINGEXACT:
    24742748        return LISTBOX_FindString( hwnd, descr, wParam, (LPCSTR)lParam, TRUE );
    24752749
    2476     case LB_SELECTSTRING:
    2477         {
    2478             INT index = LISTBOX_FindString( hwnd, descr, wParam,
    2479                                               (LPCSTR)lParam, FALSE );
    2480             if (index == LB_ERR)
    2481                 return LB_ERR;
    2482             LISTBOX_SetSelection( hwnd, descr, index, TRUE, FALSE );
    2483             return index;
    2484         }
    2485 
    2486     case LB_GETSEL:
    2487         if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items))
    2488             return LB_ERR;
    2489         return descr->items[wParam].selected;
    2490 
    2491     case LB_SETSEL:
     2750      case LB_SELECTSTRING:
     2751        return LISTBOX_SelectString(hwnd,descr,wParam,lParam);
     2752
     2753      case LB_GETSEL:
     2754        return LISTBOX_GetSel(hwnd,descr,wParam,lParam);
     2755
     2756      case LB_SETSEL:
    24922757        return LISTBOX_SetSelection( hwnd, descr, lParam, wParam, FALSE );
    24932758
    2494     case LB_SETCURSEL:
    2495         if (IS_MULTISELECT(descr)) return LB_ERR;
    2496         LISTBOX_SetCaretIndex( hwnd, descr, wParam, TRUE );
    2497         return LISTBOX_SetSelection( hwnd, descr, wParam, TRUE, FALSE );
    2498 
    2499     case LB_GETSELCOUNT:
     2759      case LB_SETCURSEL:
     2760        return LISTBOX_SetCurSel(hwnd,descr,wParam,lParam);
     2761
     2762      case LB_GETSELCOUNT:
    25002763        return LISTBOX_GetSelCount( hwnd, descr );
    25012764
    2502     case LB_GETSELITEMS:
     2765      case LB_GETSELITEMS:
    25032766        return LISTBOX_GetSelItems( hwnd, descr, wParam, (LPINT)lParam );
    25042767
    2505     case LB_SELITEMRANGE:
    2506         if (LOWORD(lParam) <= HIWORD(lParam))
    2507             return LISTBOX_SelectItemRange( hwnd, descr, LOWORD(lParam),
    2508                                             HIWORD(lParam), wParam );
    2509         else
    2510             return LISTBOX_SelectItemRange( hwnd, descr, HIWORD(lParam),
    2511                                             LOWORD(lParam), wParam );
    2512 
    2513     case LB_SELITEMRANGEEX:
    2514         if ((INT)lParam >= (INT)wParam)
    2515             return LISTBOX_SelectItemRange( hwnd, descr, wParam, lParam, TRUE );
    2516         else
    2517             return LISTBOX_SelectItemRange( hwnd, descr, lParam, wParam, FALSE);
    2518 
    2519     case LB_GETHORIZONTALEXTENT:
    2520         return descr->horz_extent;
    2521 
    2522     case LB_SETHORIZONTALEXTENT:
     2768      case LB_SELITEMRANGE:
     2769        return LISTBOX_SelItemRange(hwnd,descr,wParam,lParam);
     2770
     2771      case LB_SELITEMRANGEEX:
     2772        return LISTBOX_SelItemRangeEx(hwnd,descr,wParam,lParam);
     2773
     2774      case LB_GETHORIZONTALEXTENT:
     2775        return LISTBOX_GetHorizontalExtent(hwnd,descr,wParam,lParam);
     2776
     2777      case LB_SETHORIZONTALEXTENT:
    25232778        return LISTBOX_SetHorizontalExtent( hwnd, descr, wParam );
    25242779
    2525     case LB_GETANCHORINDEX:
    2526         return descr->anchor_item;
    2527 
    2528     case LB_SETANCHORINDEX:
    2529         if (((INT)wParam < -1) || ((INT)wParam >= descr->nb_items))
    2530             return LB_ERR;
    2531         descr->anchor_item = (INT)wParam;
    2532         return LB_OKAY;
    2533 
    2534     case LB_DIR:
     2780      case LB_GETANCHORINDEX:
     2781        return LISTBOX_GetAnchorIndex(hwnd,descr,wParam,lParam);
     2782
     2783      case LB_SETANCHORINDEX:
     2784        return LISTBOX_SetAnchorIndex(hwnd,descr,wParam,lParam);
     2785
     2786      case LB_DIR:
    25352787        return LISTBOX_Directory( hwnd, descr, wParam, (LPCSTR)lParam, TRUE );
    25362788
    2537     case LB_GETLOCALE:
    2538         return descr->locale;
    2539 
    2540     case LB_SETLOCALE:
    2541         descr->locale = (LCID)wParam;  /* FIXME: should check for valid lcid */
    2542         return LB_OKAY;
    2543 
    2544     case LB_INITSTORAGE:
     2789      case LB_GETLOCALE:
     2790        return LISTBOX_GetLocale(hwnd,descr,wParam,lParam);
     2791
     2792      case LB_SETLOCALE:
     2793        return LISTBOX_SetLocale(hwnd,descr,wParam,lParam);
     2794
     2795      case LB_INITSTORAGE:
    25452796        return LISTBOX_InitStorage( hwnd, descr, wParam, (DWORD)lParam );
    25462797
    2547     case LB_SETCOUNT:
     2798      case LB_SETCOUNT:
    25482799        return LISTBOX_SetCount( hwnd, descr, (INT)wParam );
    25492800
    2550     case LB_SETTABSTOPS:
     2801      case LB_SETTABSTOPS:
    25512802        return LISTBOX_SetTabStops( hwnd, descr, wParam, (LPINT)lParam, FALSE );
    25522803
    2553     case LB_CARETON:
    2554         if (descr->caret_on)
    2555             return LB_OKAY;
    2556         descr->caret_on = TRUE;
    2557         if ((descr->focus_item != -1) && (descr->in_focus))
    2558             LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
    2559         return LB_OKAY;
    2560 
    2561     case LB_CARETOFF:
    2562         if (!descr->caret_on)
    2563             return LB_OKAY;
    2564         descr->caret_on = FALSE;
    2565         if ((descr->focus_item != -1) && (descr->in_focus))
    2566             LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
    2567         return LB_OKAY;
    2568 
    2569     case WM_DESTROY:
     2804      case LB_CARETON:
     2805        return LISTBOX_CaretOn(hwnd,descr,wParam,lParam);
     2806
     2807      case LB_CARETOFF:
     2808        return LISTBOX_CaretOff(hwnd,descr,wParam,lParam);
     2809
     2810      case WM_DESTROY:
    25702811        return LISTBOX_Destroy( hwnd, descr );
    25712812
    2572     case WM_ENABLE:
    2573         InvalidateRect( hwnd, NULL, TRUE );
    2574         return 0;
    2575 
    2576     case WM_SETREDRAW:
    2577         LISTBOX_SetRedraw( hwnd, descr, wParam != 0 );
    2578         return 0;
    2579 
    2580     case WM_GETDLGCODE:
    2581         return DLGC_WANTARROWS | DLGC_WANTCHARS;
    2582 
    2583     case WM_PAINT:
    2584         {
    2585             PAINTSTRUCT ps;
    2586             HDC hdc = ( wParam ) ? ((HDC)wParam)
    2587                                    :  BeginPaint( hwnd, &ps );
    2588             ret = LISTBOX_Paint( hwnd, descr, hdc );
    2589             if( !wParam ) EndPaint( hwnd, &ps );
    2590         }
    2591         return ret;
    2592     case WM_SIZE:
    2593         LISTBOX_UpdateSize( hwnd, descr );
    2594         return 0;
    2595     case WM_GETFONT:
    2596         return descr->font;
    2597     case WM_SETFONT:
    2598         LISTBOX_SetFont( hwnd, descr, (HFONT)wParam );
    2599         if (lParam) InvalidateRect( hwnd, 0, TRUE );
    2600         return 0;
    2601     case WM_SETFOCUS:
    2602         descr->in_focus = TRUE;
    2603         descr->caret_on = TRUE;
    2604         if (descr->focus_item != -1)
    2605             LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
    2606         SEND_NOTIFICATION( hwnd, descr, LBN_SETFOCUS );
    2607         return 0;
    2608     case WM_KILLFOCUS:
    2609         descr->in_focus = FALSE;
    2610         if ((descr->focus_item != -1) && descr->caret_on)
    2611             LISTBOX_RepaintItem( hwnd, descr, descr->focus_item, ODA_FOCUS );
    2612         SEND_NOTIFICATION( hwnd, descr, LBN_KILLFOCUS );
    2613         return 0;
    2614     case WM_HSCROLL:
     2813      case WM_ENABLE:
     2814        return LISTBOX_Enable(hwnd,descr,wParam,lParam);
     2815
     2816      case WM_SETREDRAW:
     2817        return LISTBOX_SetRedraw( hwnd, descr, wParam != 0 );
     2818
     2819      case WM_GETDLGCODE:
     2820        return LISTBOX_GetDlgCode(hwnd,descr,wParam,lParam);
     2821
     2822      case WM_PAINT:
     2823        return LISTBOX_Paint(hwnd,descr,wParam,lParam);
     2824
     2825      case WM_SIZE:
     2826        return LISTBOX_Size(hwnd,descr,wParam,lParam);
     2827
     2828      case WM_GETFONT:
     2829        return LISTBOX_GetFont(hwnd,descr,wParam,lParam);
     2830
     2831      case WM_SETFONT:
     2832        return LISTBOX_SetFont(hwnd,descr,wParam,lParam);
     2833
     2834      case WM_SETFOCUS:
     2835        return LISTBOX_SetFocus(hwnd,descr,wParam,lParam);
     2836
     2837      case WM_KILLFOCUS:
     2838        return LISTBOX_KillFocus(hwnd,descr,wParam,lParam);
     2839
     2840      case WM_HSCROLL:
    26152841        return LISTBOX_HandleHScroll( hwnd, descr, wParam, lParam );
    2616     case WM_VSCROLL:
     2842
     2843      case WM_VSCROLL:
    26172844        return LISTBOX_HandleVScroll( hwnd, descr, wParam, lParam );
    2618     case WM_MOUSEACTIVATE:
    2619         return MA_NOACTIVATE;
    2620     case WM_MOUSEWHEEL:
    2621         if (wParam & (MK_SHIFT | MK_CONTROL))
    2622             return DefWindowProcA( hwnd, msg, wParam, lParam );
     2845
     2846      case WM_MOUSEACTIVATE:
     2847        return LISTBOX_MouseActivate(hwnd,descr,wParam,lParam);
     2848
     2849      case WM_MOUSEWHEEL:
    26232850        return LISTBOX_HandleMouseWheel( hwnd, descr, wParam, lParam );
    2624     case WM_LBUTTONDOWN:
     2851
     2852      case WM_LBUTTONDOWN:
    26252853        return LISTBOX_HandleLButtonDown( hwnd, descr, wParam,
    26262854                                          (INT16)LOWORD(lParam),
    26272855                                          (INT16)HIWORD(lParam) );
    2628     case WM_LBUTTONDBLCLK:
    2629         if (descr->style & LBS_NOTIFY)
    2630             SEND_NOTIFICATION( hwnd, descr, LBN_DBLCLK );
    2631         return 0;
    2632     case WM_MOUSEMOVE:
    2633         if (GetCapture() == hwnd)
    2634             LISTBOX_HandleMouseMove( hwnd, descr, (INT16)LOWORD(lParam),
    2635                                      (INT16)HIWORD(lParam) );
    2636         return 0;
    2637 
    2638     case WM_LBUTTONUP:
     2856      case WM_LBUTTONDBLCLK:
     2857        return LISTBOX_LButtonDblClk(hwnd,descr,wParam,lParam);
     2858
     2859      case WM_MOUSEMOVE:
     2860        return LISTBOX_HandleMouseMove( hwnd, descr, (INT16)LOWORD(lParam),
     2861                                        (INT16)HIWORD(lParam) );
     2862
     2863      case WM_LBUTTONUP:
    26392864        return LISTBOX_HandleLButtonUp( hwnd, descr );
    2640     case WM_KEYDOWN:
     2865
     2866      case WM_KEYDOWN:
    26412867        return LISTBOX_HandleKeyDown( hwnd, descr, wParam );
    2642     case WM_CHAR:
     2868
     2869      case WM_CHAR:
    26432870        return LISTBOX_HandleChar( hwnd, descr, wParam );
    2644     case WM_SYSTIMER:
     2871
     2872      case WM_SYSTIMER:
    26452873        return LISTBOX_HandleSystemTimer( hwnd, descr );
    2646     case WM_ERASEBKGND:
    2647         if (IS_OWNERDRAW(descr))
    2648         {
    2649             RECT rect;
    2650             HBRUSH hbrush = SendMessageA( descr->owner, WM_CTLCOLORLISTBOX,
    2651                                               wParam, (LPARAM)hwnd );
    2652             GetClientRect(hwnd, &rect);
    2653             if (hbrush) FillRect( (HDC)wParam, &rect, hbrush );
    2654         }
    2655         return 1;
    2656     case WM_DROPFILES:
    2657         if( !descr->lphc )
    2658             return SendMessageA( descr->owner, msg, wParam, lParam );
    2659         break;
    2660 
    2661     case WM_DROPOBJECT:
    2662     case WM_QUERYDROPOBJECT:
    2663     case WM_DRAGSELECT:
    2664     case WM_DRAGMOVE:
    2665         if( !descr->lphc )
    2666         {
    2667             LPDRAGINFO dragInfo = (LPDRAGINFO)lParam;
    2668             dragInfo->l = LISTBOX_GetItemFromPoint( hwnd, descr, dragInfo->pt.x,
    2669                                                 dragInfo->pt.y );
    2670             return SendMessageA( descr->owner, msg, wParam, lParam );
    2671         }
    2672         break;
     2874
     2875      case WM_ERASEBKGND:
     2876        return LISTBOX_EraseBackground(hwnd,descr,wParam,lParam);
     2877
     2878      case WM_DROPFILES:
     2879        return LISTBOX_DropFiles(hwnd,descr,wParam,lParam);
     2880
     2881      case WM_DROPOBJECT:
     2882      case WM_QUERYDROPOBJECT:
     2883      case WM_DRAGSELECT:
     2884      case WM_DRAGMOVE:
     2885        return LISTBOX_HandleDragDrop(hwnd,descr,msg,wParam,lParam);
    26732886
    26742887    default:
Note: See TracChangeset for help on using the changeset viewer.