Changeset 3117 for trunk/src


Ignore:
Timestamp:
Mar 14, 2000, 7:27:25 PM (25 years ago)
Author:
cbratschi
Message:

faster LB_SETCOUNT

File:
1 edited

Legend:

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

    r3108 r3117  
    1 /* $Id: listbox.cpp,v 1.21 2000-03-14 15:00:59 sandervl Exp $ */
     1/* $Id: listbox.cpp,v 1.22 2000-03-14 18:27:25 cbratschi Exp $ */
    22/*
    33 * Listbox controls
     
    1818#include "combo.h"
    1919#include <misc.h>
     20#include "heapstring.h"
    2021
    2122#define DBG_LOCALLOG    DBG_listbox
     
    5354typedef struct
    5455{
    55     LPSTR     str;       /* Item text */
     56    LPSTR   str;       /* Item text */
    5657    BOOL    selected;  /* Is item selected? */
    5758    UINT    height;    /* Item height (only for OWNERDRAWVARIABLE) */
    58     DWORD     data;      /* User data */
     59    DWORD   data;      /* User data */
    5960} LB_ITEMDATA;
    6061
     
    8485    BOOL        in_focus;
    8586    HFONT       font;           /* Current font */
    86     LCID          locale;         /* Current locale for string comparisons */
    87     LPHEADCOMBO   lphc;           /* ComboLBox */
     87    LCID        locale;         /* Current locale for string comparisons */
     88    LPHEADCOMBO lphc;           /* ComboLBox */
    8889} LB_DESCR;
    8990
     
    9495#define HAS_STRINGS(descr) \
    9596    (!IS_OWNERDRAW(descr) || ((descr)->style & LBS_HASSTRINGS))
     97
     98#define HAS_NODATA(descr) \
     99    ((descr)->style & LBS_NODATA)
    96100
    97101#define IS_MULTISELECT(descr) \
     
    13661370}
    13671371
    1368 //CB: helper from wine/memory/heap.c
    1369 
    1370 LPSTR HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
    1371 {
    1372     LPSTR p = (LPSTR)HeapAlloc(heap,flags,strlen(str)+1);
    1373 
    1374     strcpy(p,str);
    1375     return p;
    1376 }
    1377 
    1378 
    13791372/***********************************************************************
    13801373 *           LISTBOX_InsertString
     
    15331526    LRESULT ret;
    15341527
    1535     if (HAS_STRINGS(descr)) return LB_ERR;
    1536     /* FIXME: this is far from optimal... */
     1528    if (HAS_STRINGS(descr) || !HAS_NODATA(descr)) return LB_ERR;
     1529
    15371530    if (count > descr->nb_items)
    15381531    {
    1539         while (count > descr->nb_items)
    1540             if ((ret = LISTBOX_InsertString( hwnd, descr, -1, 0 )) < 0)
    1541                 return ret;
    1542     }
    1543     else if (count < descr->nb_items)
    1544     {
    1545         while (count < descr->nb_items)
    1546             if ((ret = LISTBOX_RemoveItem( hwnd, descr, -1 )) < 0)
    1547                 return ret;
    1548     }
     1532      LB_ITEMDATA *item;
     1533      INT max_items,index;
     1534      UINT id = (descr->lphc) ? ID_CB_LISTBOX:GetWindowLongA(hwnd,GWL_ID);
     1535
     1536      max_items = count+LB_ARRAY_GRANULARITY-(count % LB_ARRAY_GRANULARITY);
     1537      if (!(item = (LB_ITEMDATA*)HeapReAlloc(descr->heap,0,descr->items,max_items*sizeof(LB_ITEMDATA))))
     1538      {
     1539        SEND_NOTIFICATION( hwnd, descr, LBN_ERRSPACE );
     1540        return LB_ERRSPACE;
     1541      }
     1542      descr->items = item;
     1543
     1544      /* Insert the item structure */
     1545
     1546      index = descr->nb_items-1;
     1547      while (count > descr->nb_items)
     1548      {
     1549        index++;
     1550        item = &descr->items[index];
     1551
     1552        item->str      = "";
     1553        item->data     = 0;
     1554        item->height   = 0;
     1555        item->selected = FALSE;
     1556        descr->nb_items++;
     1557
     1558        /* Get item height */
     1559
     1560        if (descr->style & LBS_OWNERDRAWVARIABLE)
     1561        {
     1562          MEASUREITEMSTRUCT mis;
     1563
     1564          mis.CtlType    = ODT_LISTBOX;
     1565          mis.CtlID      = id;
     1566          mis.itemID     = index;
     1567          mis.itemData   = descr->items[index].data;
     1568          mis.itemHeight = descr->item_height;
     1569          SendMessageA( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis );
     1570          item->height = mis.itemHeight ? mis.itemHeight : 1;
     1571        }
     1572      }
     1573    } else if (count < descr->nb_items)
     1574    {
     1575      descr->nb_items = count;
     1576      if (descr->selected_item >= count) descr->selected_item = count-1;
     1577      if (descr->focus_item >= count) descr-> focus_item = count-1;
     1578    }
     1579    /* Repaint the items */
     1580
     1581    LISTBOX_UpdateScroll( hwnd, descr );
     1582    InvalidateRect(hwnd,NULL,TRUE);
     1583
    15491584    return LB_OKAY;
    15501585}
Note: See TracChangeset for help on using the changeset viewer.