lvsmall.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. // small icon view (positional view, not list)
  2. #include "ctlspriv.h"
  3. #include "listview.h"
  4. int NEAR ListView_SItemHitTest(LV* plv, int x, int y, UINT FAR* pflags, int *piSubItem)
  5. {
  6.     int iHit;
  7.     UINT flags;
  8.     POINT pt;
  9.     RECT rcState;
  10.     RECT rcLabel;
  11.     RECT rcIcon;
  12.     if (piSubItem)
  13.         *piSubItem = 0;
  14.     // Map window-relative coordinates to view-relative coords...
  15.     //
  16.     pt.x = x + plv->ptOrigin.x;
  17.     pt.y = y + plv->ptOrigin.y;
  18.     // If we find an uncomputed item, recompute them all now...
  19.     //
  20.     if (plv->rcView.left == RECOMPUTE)
  21.         ListView_Recompute(plv);
  22.     flags = 0;
  23.     if (ListView_IsOwnerData( plv ))
  24.     {
  25.         int cSlots;
  26.         POINT ptWnd;
  27.         LISTITEM item;
  28.         cSlots = ListView_GetSlotCount( plv, TRUE );
  29.         iHit = ListView_CalcHitSlot( plv, pt, cSlots );
  30.         ListView_SGetRectsOwnerData( plv, iHit, &rcIcon, &rcLabel, &item, FALSE );
  31.         ptWnd.x = x;
  32.         ptWnd.y = y;
  33.         if (PtInRect(&rcIcon, ptWnd))
  34.         {
  35.             flags = LVHT_ONITEMICON;
  36.         }
  37.         else if (PtInRect(&rcLabel, ptWnd))
  38.         {
  39.             flags = LVHT_ONITEMLABEL;
  40.         }
  41.     }
  42.     else
  43.     {
  44.         for (iHit = 0; iHit < ListView_Count(plv); iHit++)
  45.         {
  46.             LISTITEM FAR* pitem = ListView_FastGetZItemPtr(plv, iHit);
  47.             POINT ptItem;
  48.             ptItem.x = pitem->pt.x;
  49.             ptItem.y = pitem->pt.y;
  50.             rcIcon.top    = ptItem.y;
  51.             rcIcon.bottom = ptItem.y + plv->cyItem;
  52.             rcLabel.top    = rcIcon.top;
  53.             rcLabel.bottom = rcIcon.bottom;
  54.             // Quick, easy rejection test...
  55.             //
  56.             if (pt.y < rcIcon.top || pt.y >= rcIcon.bottom)
  57.                 continue;
  58.             rcIcon.left   = ptItem.x;
  59.             rcIcon.right  = ptItem.x + plv->cxSmIcon;
  60.             
  61.             rcState.bottom = rcIcon.bottom;
  62.             rcState.right = rcIcon.left;
  63.             rcState.left = rcState.right - plv->cxState;
  64.             rcState.top = rcState.bottom - plv->cyState;
  65.             rcLabel.left   = rcIcon.right;
  66.             rcLabel.right  = rcLabel.left + pitem->cxSingleLabel;
  67.             if (PtInRect(&rcIcon, pt))
  68.             {
  69.                 flags = LVHT_ONITEMICON;
  70.             } else if (PtInRect(&rcLabel, pt))
  71.             {
  72.                 flags = LVHT_ONITEMLABEL;
  73.             } else if (PtInRect(&rcState, pt)) 
  74.             {
  75.                 flags = LVHT_ONITEMSTATEICON;
  76.             }
  77.             
  78.             if (flags)
  79.                 break;
  80.         }
  81.     }
  82.     if (flags == 0)
  83.     {
  84.         flags = LVHT_NOWHERE;
  85.         iHit = -1;
  86.     }
  87.     else
  88.     {
  89.       if (!ListView_IsOwnerData( plv ))
  90.           iHit = DPA_GetPtrIndex(plv->hdpa, (void FAR*)ListView_FastGetZItemPtr(plv, iHit));
  91.     }
  92.     *pflags = flags;
  93.     return iHit;
  94. }
  95. void NEAR ListView_SGetRectsOwnerData( LV* plv,
  96.         int iItem,
  97.         RECT FAR* prcIcon,
  98.         RECT FAR* prcLabel,
  99.         LISTITEM* pitem,
  100.         BOOL fUsepitem )
  101. {
  102.     RECT rcIcon;
  103.     RECT rcLabel;
  104.     int cSlots;
  105.     // calculate itemx, itemy, itemsSingleLabel from iItem
  106.     cSlots = ListView_GetSlotCount( plv, TRUE );
  107.     pitem->iWorkArea = 0;               // OwnerData doesn't support workareas
  108.     ListView_SetIconPos( plv, pitem, iItem, cSlots );
  109.     // calculate lable sizes
  110.     // Note the rect we return should be the min of the size returned and the slot size...
  111.     ListView_RecomputeLabelSize( plv, pitem, iItem, NULL, fUsepitem );
  112.     rcIcon.left   = pitem->pt.x - plv->ptOrigin.x;
  113.     rcIcon.right  = rcIcon.left + plv->cxSmIcon;
  114.     rcIcon.top    = pitem->pt.y - plv->ptOrigin.y;
  115.     rcIcon.bottom = rcIcon.top + plv->cyItem;
  116.     *prcIcon = rcIcon;
  117.     rcLabel.left   = rcIcon.right;
  118.     if (pitem->cxSingleLabel < (plv->cxItem - plv->cxSmIcon))
  119.         rcLabel.right  = rcLabel.left + pitem->cxSingleLabel;
  120.     else
  121.         rcLabel.right  = rcLabel.left + plv->cxItem - plv->cxSmIcon;
  122.     rcLabel.top    = rcIcon.top;
  123.     rcLabel.bottom = rcIcon.bottom;
  124.     *prcLabel = rcLabel;
  125. }
  126. void NEAR ListView_SGetRects(LV* plv, LISTITEM FAR* pitem, RECT FAR* prcIcon, RECT FAR* prcLabel, LPRECT prcBounds)
  127. {
  128.     ASSERT( !ListView_IsOwnerData( plv ));
  129.     if (pitem->pt.x == RECOMPUTE) {
  130.         ListView_Recompute(plv);
  131.     }
  132.     prcIcon->left   = pitem->pt.x - plv->ptOrigin.x;
  133.     prcIcon->right  = prcIcon->left + plv->cxSmIcon;
  134.     prcIcon->top    = pitem->pt.y - plv->ptOrigin.y;
  135.     prcIcon->bottom = prcIcon->top + plv->cyItem;
  136.     prcLabel->left   = prcIcon->right;
  137.     prcLabel->right  = prcLabel->left + pitem->cxSingleLabel;
  138.     prcLabel->top    = prcIcon->top;
  139.     prcLabel->bottom = prcIcon->bottom;
  140. }
  141. // Return the index of the first item >= *pszLookup.
  142. //
  143. int NEAR ListView_DoLookupString(LV* plv, LPCTSTR pszLookup, UINT flags, int iStart, int j)
  144. {
  145.     int i;
  146.     BOOL fExact;
  147.     int k;
  148.     LISTITEM FAR* pitem;
  149.     LISTITEM FAR* pitemLast = NULL;
  150.     ASSERT( !ListView_IsOwnerData( plv ));
  151.     fExact = FALSE;
  152.     i = iStart;
  153.     while ((i >= iStart) && (i < j))
  154.     {
  155.         int result;
  156.         k = (i + j) / 2;
  157.         pitem = ListView_FastGetItemPtr(plv, k);
  158.         
  159.         if (pitem == pitemLast)
  160.             break;
  161.         pitemLast = pitem;
  162.         
  163.         result = ListView_CompareString(plv, 
  164.                 k, pszLookup, flags, 0);
  165. #ifdef MAINWIN
  166.         // IEUNIX - Mainwin's lstrcmp is not compatable with WIN32.
  167.         if(result < 0)
  168.             result = -1;
  169.         else if(result > 0)
  170.             result = 1;
  171. #endif
  172.         if (plv->ci.style & LVS_SORTDESCENDING)
  173.             result = -result;
  174.         switch (result)
  175.         {
  176.         case 0:
  177.             fExact = TRUE;
  178.             // fall through
  179.         case 1:
  180.             j = k;
  181.             break;
  182.         case -1:
  183.             i = k + 1;
  184.             break;
  185.         }
  186.     }
  187.     // For substrings, return index only if exact match was found.
  188.     //
  189.     if (!(flags & (LVFI_SUBSTRING | LVFI_PARTIAL)) && 
  190.         !fExact)
  191.         return -1;
  192.     if (i < 0)
  193.         i = 0;
  194.     
  195.     if ((!(flags & LVFI_NEARESTXY)) &&
  196.         ListView_CompareString(plv, i, pszLookup, flags, 1)) {
  197.         i = -1;
  198.     }
  199.     return i;
  200. }
  201. int NEAR ListView_LookupString(LV* plv, LPCTSTR pszLookup, UINT flags, int iStart)
  202. {
  203.     int iret;
  204.     
  205.     if (!pszLookup)
  206.         return 0;
  207.     
  208.     iret = ListView_DoLookupString(plv, pszLookup, flags, iStart, ListView_Count(plv));
  209.     if (iret == -1 && (flags & LVFI_WRAP)) {
  210.         iret = ListView_DoLookupString(plv, pszLookup, flags, 0, iStart);
  211.     }
  212.     
  213.     return iret;
  214. }