Changeset 1170 for trunk/src


Ignore:
Timestamp:
Oct 7, 1999, 5:46:30 PM (26 years ago)
Author:
cbratschi
Message:

Drag&drop support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/header.c

    r1156 r1170  
    1 /* $Id: header.c,v 1.15 1999-10-06 15:41:10 cbratschi Exp $ */
     1/* $Id: header.c,v 1.16 1999-10-07 15:46:30 cbratschi Exp $ */
    22/*
    33 *  Header control
     
    1111 *   - Control specific cursors (over dividers).
    1212 *   - Custom draw support (including Notifications).
    13  *   - Drag and Drop support (including Notifications).
    1413 *   - HDS_FILTERBAR
    1514 *
     
    379378    rect.right = x+1;
    380379    InvertRect(hdc,&rect);
    381 /* //CB: Odin bug!!! This code doesn't work:
    382     hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
    383     oldRop = SetROP2 (hdc, R2_XORPEN);
    384     MoveToEx (hdc, x, rect.top, NULL);
    385     LineTo (hdc, x, rect.bottom);
    386     SetROP2 (hdc, oldRop);
    387     SelectObject (hdc, hOldPen);
    388 */
    389380}
    390381
     
    432423
    433424    if (infoPtr->bCaptured && infoPtr->bTracking && !(dwStyle & HDS_FULLDRAG)) HEADER_DrawTrackLine(hwnd,hdc,infoPtr->xOldTrack);
     425
     426    if (infoPtr->bDragDrop)
     427    {
     428      if (infoPtr->iDragItem != infoPtr->iMoveItem && infoPtr->iDragItem != infoPtr->iMoveItem+1 && infoPtr->iDragItem != -1)
     429      {
     430        INT x,y,width;
     431        HPEN hPen = CreatePen(PS_DOT,0,GetSysColor(COLOR_HIGHLIGHT)),hOldPen;
     432        INT oldBkMode = SetBkMode(hdc,TRANSPARENT);
     433
     434        hOldPen = SelectObject(hdc,hPen);
     435        if (infoPtr->iDragItem == infoPtr->uNumItem)
     436        {
     437          x = infoPtr->items[infoPtr->uNumItem-1].rect.right-1;
     438          width = 2;
     439        } else if (infoPtr->iDragItem == 0)
     440        {
     441          x = infoPtr->items[0].rect.left;
     442          width = 1;
     443        } else
     444        {
     445          x = infoPtr->items[infoPtr->iDragItem].rect.left-2;
     446          width = 3;
     447        }
     448
     449        for (y = 0;y < width;y++)
     450        {
     451          MoveToEx(hdc,x,0,NULL);
     452          LineTo(hdc,x,rect.bottom);
     453          x++;
     454        }
     455        SetBkMode(hdc,oldBkMode);
     456        SelectObject(hdc,hOldPen);
     457        DeleteObject(hPen);
     458      }
     459      ImageList_Draw(infoPtr->dragImage,0,hdc,infoPtr->items[infoPtr->iMoveItem].rect.left+infoPtr->dragPos.x-infoPtr->dragStart.x,0,ILD_NORMAL);
     460    }
    434461}
    435462
     
    865892{
    866893  HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
    867 
    868   //CB:todo
    869   //HDN_FILTERCHANGE
    870 
    871   return 0;
     894  INT iItem = (INT)lParam;
     895
     896  if (iItem == -1)
     897  {
     898    INT x;
     899
     900    for (x = 0;x < infoPtr->uNumItem;x++)
     901    {
     902      //CB:todo
     903    }
     904  } else
     905  {
     906    if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem)) return iItem;
     907
     908    //CB:todo
     909  }
     910
     911  HEADER_SendFilterChange(hwnd,-1);
     912
     913  return iItem;
    872914}
    873915
     
    879921
    880922  if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem)) return 0;
     923
     924  if (!lParam)
     925  {
     926    //CB: save changes
     927
     928    HEADER_SendFilterChange(hwnd,iItem);
     929  }
    881930
    882931  //CB: todo
     
    899948  INT iItem = (INT)wParam;
    900949  HEADER_ITEM *phdi;
    901   HICON hicon;
     950  RECT oldRect;
     951  HDC hdc,hdcBmp;
     952  HBITMAP bmp,mask,oldbmp;
     953  HBRUSH hbr;
     954  HFONT hFont,hOldFont;
    902955  HIMAGELIST himl;
    903956
    904   if (!infoPtr->himl || (iItem < 0) || (iItem >= (INT)infoPtr->uNumItem)) return 0;
     957  if (iItem < 0 || iItem >= (INT)infoPtr->uNumItem) return 0;
     958
    905959  phdi = &infoPtr->items[iItem];
    906 /*
    907   hicon = ImageList_GetIcon(infoPtr->himl,phdi->iImage,ILD_BLEND | ILD_TRANSPARENT);
    908   if (!hicon) return 0;
    909 
    910   himl = ImageList_Create();
    911 */
    912   //CB: create and return new imagelist
    913 
    914   return 0;
     960  oldRect = phdi->rect;
     961  phdi->rect.right -= phdi->rect.left;
     962  phdi->rect.left = 0;
     963
     964  hdc = GetDC(hwnd);
     965  hFont = infoPtr->hFont ? infoPtr->hFont:GetStockObject(SYSTEM_FONT);
     966  hOldFont = SelectObject(hdc,hFont);
     967  hdcBmp = CreateCompatibleDC(hdc);
     968  bmp = CreateCompatibleBitmap(hdc,phdi->rect.right,phdi->rect.bottom);
     969  mask = CreateCompatibleBitmap(hdc,phdi->rect.right,phdi->rect.bottom);
     970  oldbmp = SelectObject(hdcBmp,bmp);
     971  HEADER_DrawItem(hwnd,hdcBmp,iItem,FALSE,TRUE);
     972  SelectObject(hdcBmp,mask);
     973  hbr = CreateSolidBrush(RGB(255,255,255));
     974  FillRect(hdcBmp,&phdi->rect,hbr);
     975  DeleteObject(hbr);
     976  hbr = CreateHatchBrush(HS_DIAGCROSS,RGB(0,0,0));
     977  FillRect(hdcBmp,&phdi->rect,hbr);
     978  DeleteObject(hbr);
     979  SelectObject(hdcBmp,oldbmp);
     980
     981  himl = ImageList_Create(phdi->rect.right,phdi->rect.bottom,ILC_COLOR | ILC_MASK,1,0);
     982  ImageList_Add(himl,bmp,mask);
     983
     984  DeleteObject(bmp);
     985  DeleteObject(mask);
     986  SelectObject(hdc,hOldFont);
     987  DeleteDC(hdcBmp);
     988  ReleaseDC(hwnd,hdc);
     989  phdi->rect = oldRect;
     990
     991  return (LRESULT)himl;
    915992}
    916993
     
    918995HEADER_SetHotDivider(HWND hwnd,WPARAM wParam,LPARAM lParam)
    919996{
    920   //CB:todo
     997  if (wParam)
     998  {
     999    //CB:todo
     1000  } else
     1001  {
     1002    //CB:todo
     1003  }
    9211004
    9221005  return 0;
     
    11311214HEADER_GetOrderArray(HWND hwnd,WPARAM wParam,LPARAM lParam)
    11321215{
     1216  HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
     1217  LPINT lpiArray = (LPINT)lParam;
     1218
     1219  if (wParam != infoPtr->uNumItem || !lpiArray) return FALSE;
     1220
    11331221  //CB: todo
    11341222
    1135   return 0;
     1223  return TRUE;
    11361224}
    11371225
     
    11391227HEADER_SetOrderArray(HWND hwnd,WPARAM wParam,LPARAM lParam)
    11401228{
     1229  HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
     1230  LPINT lpiArray = (LPINT)lParam;
     1231
     1232  if (wParam != infoPtr->uNumItem || !lpiArray) return FALSE;
     1233
    11411234  //CB: todo
    11421235  HEADER_SetItemBounds(hwnd,0);
    11431236  HEADER_Refresh(hwnd);
    11441237
    1145   return 0;
     1238  return TRUE;
    11461239}
    11471240
     
    11491242HEADER_OrderToIndex(HWND hwnd,WPARAM wParam,LPARAM lParam)
    11501243{
    1151   //CB:todo
    1152 
    1153   return 0;
     1244  HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
     1245  INT iOrder = (INT)wParam;
     1246  INT x;
     1247
     1248  for (x = 0;x < infoPtr->uNumItem;x++)
     1249  {
     1250//CB:todo
     1251  }
     1252
     1253  return iOrder;
    11541254}
    11551255
     
    16681768        infoPtr->bPressed  = TRUE;
    16691769        infoPtr->iMoveItem = nItem;
     1770        infoPtr->dragStart = pt;
     1771        infoPtr->iDragItem = nItem;
    16701772
    16711773        infoPtr->items[nItem].bDown = TRUE;
     
    17211823    if (infoPtr->bPressed)
    17221824    {
    1723         if (PtInRect(&infoPtr->items[infoPtr->iMoveItem].rect,pt))
    1724         {
    1725             infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
    1726             hdc = GetDC(hwnd);
    1727             HEADER_RefreshItem(hwnd,hdc,infoPtr->iMoveItem);
    1728             ReleaseDC(hwnd,hdc);
    1729 
    1730             HEADER_SendItemClick(hwnd,infoPtr->iMoveItem,0);
     1825      if (infoPtr->bDragDrop)
     1826      {
     1827        infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
     1828        infoPtr->bDragDrop = FALSE;
     1829        ImageList_Destroy(infoPtr->dragImage);
     1830        infoPtr->dragImage = NULL;
     1831
     1832        if (!HEADER_SendDragNotify(hwnd,HDN_ENDDRAG,infoPtr->iMoveItem,0) && infoPtr->iDragItem != infoPtr->iMoveItem && infoPtr->iDragItem != infoPtr->iMoveItem+1 && infoPtr->iDragItem != -1)
     1833        {
     1834          HEADER_ITEM tmpItem = infoPtr->items[infoPtr->iMoveItem];;
     1835
     1836          //CB: notificatons??
     1837
     1838          if (infoPtr->iDragItem > infoPtr->iMoveItem)
     1839          {
     1840            INT x ;
     1841
     1842            for (x = infoPtr->iMoveItem;x < infoPtr->iDragItem-1;x++)
     1843              memcpy(&infoPtr->items[x],&infoPtr->items[x+1],sizeof(HEADER_ITEM));
     1844
     1845            infoPtr->items[infoPtr->iDragItem-1] = tmpItem;
     1846          } else
     1847          {
     1848            INT x;
     1849
     1850            for (x = infoPtr->iMoveItem;x > infoPtr->iDragItem;x--)
     1851              memcpy(&infoPtr->items[x],&infoPtr->items[x-1],sizeof(HEADER_ITEM));
     1852
     1853            infoPtr->items[infoPtr->iDragItem] = tmpItem;
     1854          }
     1855
     1856          HEADER_SetItemBounds(hwnd,0);
    17311857        }
     1858        HEADER_Refresh(hwnd);
     1859      } else if (PtInRect(&infoPtr->items[infoPtr->iMoveItem].rect,pt))
     1860      {
     1861        infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
     1862        hdc = GetDC(hwnd);
     1863        HEADER_RefreshItem(hwnd,hdc,infoPtr->iMoveItem);
     1864        ReleaseDC(hwnd,hdc);
     1865
     1866        HEADER_SendItemClick(hwnd,infoPtr->iMoveItem,0);
     1867      }
    17321868//      TRACE (header, "Released item %d!\n", infoPtr->iMoveItem);
    1733         infoPtr->bPressed = FALSE;
     1869      infoPtr->bPressed = FALSE;
    17341870    } else if (infoPtr->bTracking)
    17351871    {
    17361872//      TRACE (header, "End tracking item %d!\n", infoPtr->iMoveItem);
    1737         infoPtr->bTracking = FALSE;
    1738 
    1739         HEADER_SendEndTrack(hwnd,infoPtr->iMoveItem,0);
    1740 
    1741         if (!(dwStyle & HDS_FULLDRAG))
    1742         {
    1743             hdc = GetDC (hwnd);
    1744             HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
    1745             ReleaseDC (hwnd, hdc);
    1746             if (HEADER_SendItemChanging(hwnd,infoPtr->iMoveItem))
    1747                 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
    1748             else
    1749             {
    1750                 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
    1751                 if (nWidth < MIN_ITEMWIDTH) nWidth = MIN_ITEMWIDTH;
    1752 
    1753                 if (infoPtr->nOldWidth != nWidth)
    1754                 {
    1755                   infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
    1756                   HEADER_SendItemChanged(hwnd,infoPtr->iMoveItem);
    1757 
    1758                   HEADER_SetItemBounds (hwnd,infoPtr->iMoveItem);
    1759 
    1760                   HEADER_Refresh(hwnd);
    1761                 }
    1762             }
     1873      infoPtr->bTracking = FALSE;
     1874
     1875      HEADER_SendEndTrack(hwnd,infoPtr->iMoveItem,0);
     1876
     1877      if (!(dwStyle & HDS_FULLDRAG))
     1878      {
     1879        hdc = GetDC (hwnd);
     1880        HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
     1881        ReleaseDC (hwnd, hdc);
     1882        if (HEADER_SendItemChanging(hwnd,infoPtr->iMoveItem))
     1883          infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
     1884        else
     1885        {
     1886          nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
     1887          if (nWidth < MIN_ITEMWIDTH) nWidth = MIN_ITEMWIDTH;
     1888
     1889          if (infoPtr->nOldWidth != nWidth)
     1890          {
     1891            infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
     1892            HEADER_SendItemChanged(hwnd,infoPtr->iMoveItem);
     1893
     1894            HEADER_SetItemBounds (hwnd,infoPtr->iMoveItem);
     1895
     1896            HEADER_Refresh(hwnd);
     1897          }
    17631898        }
     1899      }
    17641900    }
    17651901
     
    17741910}
    17751911
     1912static INT
     1913HEADER_DragHitTest(HWND hwnd,HEADER_INFO* infoPtr,POINT pt)
     1914{
     1915  RECT rect;
     1916  INT x,xDrag;
     1917
     1918  GetClientRect(hwnd,&rect);
     1919  if (pt.y < rect.top || pt.y > rect.bottom) return -1;
     1920
     1921  xDrag = infoPtr->items[infoPtr->iMoveItem].rect.left+pt.x-infoPtr->dragStart.x;
     1922
     1923  if (xDrag < infoPtr->items[0].rect.left) return 0;
     1924
     1925  for (x = 0;x < infoPtr->uNumItem;x++)
     1926  {
     1927    if (xDrag >= infoPtr->items[x].rect.left && xDrag <= infoPtr->items[x].rect.right) return x;
     1928  }
     1929
     1930  return infoPtr->uNumItem;
     1931}
    17761932
    17771933static LRESULT
     
    17891945    HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
    17901946
    1791     if (dwStyle & HDS_BUTTONS && dwStyle & HDS_HOTTRACK) //CB: check with no buttons
     1947    if (dwStyle & HDS_BUTTONS && dwStyle & HDS_HOTTRACK)
    17921948    {
    17931949        INT newItem;
     
    18221978      if (infoPtr->bPressed)
    18231979      {
    1824         if (dwStyle & HDS_DRAGDROP && (infoPtr->bDragDrop || !HEADER_SendDragNotify(hwnd,HDN_BEGINDRAG,infoPtr->iMoveItem,0)))
     1980        if (dwStyle & HDS_DRAGDROP && infoPtr->uNumItem > 1 && (infoPtr->bDragDrop || !HEADER_SendDragNotify(hwnd,HDN_BEGINDRAG,infoPtr->iMoveItem,0)))
    18251981        {
    18261982          if (!infoPtr->bDragDrop)
    18271983          {
    18281984            infoPtr->bDragDrop = TRUE;
    1829             infoPtr->dragImage = (HIMAGELIST)HEADER_CreateDragImage(hwnd,0,0);
     1985            infoPtr->dragImage = (HIMAGELIST)HEADER_CreateDragImage(hwnd,infoPtr->iMoveItem,0);
    18301986          }
    1831           //CB:todo
     1987          infoPtr->dragPos   = pt;
     1988          infoPtr->iDragItem = HEADER_DragHitTest(hwnd,infoPtr,pt);
     1989          HEADER_Refresh(hwnd);
    18321990        } else
    18331991        {
     
    19272085  HDC hdc;
    19282086
    1929   if (wParam == VK_ESCAPE && infoPtr->bCaptured && infoPtr->bTracking)
     2087  if (wParam == VK_ESCAPE && infoPtr->bCaptured)
    19302088  {
    1931     infoPtr->bTracking = FALSE;
    1932 
    1933     HEADER_SendEndTrack(hwnd,infoPtr->iMoveItem,0);
    1934     hdc = GetDC(hwnd);
    1935     HEADER_DrawTrackLine(hwnd,hdc,infoPtr->xOldTrack);
    1936     ReleaseDC(hwnd,hdc);
    1937     if (dwStyle & HDS_FULLDRAG)
    1938     {
    1939       infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
     2089    if (infoPtr->bPressed && infoPtr->bDragDrop)
     2090    {
     2091      infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
     2092      infoPtr->bPressed = FALSE;
     2093      infoPtr->bDragDrop = FALSE;
     2094      ImageList_Destroy(infoPtr->dragImage);
     2095      infoPtr->dragImage = NULL;
     2096
     2097      HEADER_SendDragNotify(hwnd,HDN_ENDDRAG,infoPtr->iMoveItem,0);
    19402098      HEADER_Refresh(hwnd);
     2099
     2100    } else if (infoPtr->bTracking)
     2101    {
     2102      infoPtr->bTracking = FALSE;
     2103
     2104      HEADER_SendEndTrack(hwnd,infoPtr->iMoveItem,0);
     2105
     2106      if (dwStyle & HDS_FULLDRAG)
     2107      {
     2108        infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
     2109        HEADER_Refresh(hwnd);
     2110      } else
     2111      {
     2112        hdc = GetDC(hwnd);
     2113        HEADER_DrawTrackLine(hwnd,hdc,infoPtr->xOldTrack);
     2114        ReleaseDC(hwnd,hdc);
     2115      }
    19412116    }
    19422117
     
    19582133  HDC hdc;
    19592134
    1960   if (infoPtr->bCaptured && infoPtr->bTracking)
     2135  if (infoPtr->bCaptured && infoPtr->bPressed)
     2136  {
     2137    infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
     2138    infoPtr->bPressed  = FALSE;
     2139    if (infoPtr->bDragDrop)
     2140    {
     2141      infoPtr->bDragDrop = FALSE;
     2142      ImageList_Destroy(infoPtr->dragImage);
     2143      infoPtr->dragImage = NULL;
     2144
     2145      HEADER_SendDragNotify(hwnd,HDN_ENDDRAG,infoPtr->iMoveItem,0);
     2146      HEADER_Refresh(hwnd);
     2147    } else
     2148    {
     2149      hdc = GetDC(hwnd);
     2150      HEADER_RefreshItem(hwnd,hdc,infoPtr->iMoveItem);
     2151      ReleaseDC(hwnd,hdc);
     2152    }
     2153  } else if (infoPtr->bCaptured && infoPtr->bTracking)
    19612154  {
    19622155    infoPtr->bTracking = FALSE;
    19632156
    19642157    HEADER_SendEndTrack(hwnd,infoPtr->iMoveItem,0);
    1965     hdc = GetDC(hwnd);
    1966     HEADER_DrawTrackLine(hwnd,hdc,infoPtr->xOldTrack);
    1967     ReleaseDC(hwnd,hdc);
     2158
    19682159    if (dwStyle & HDS_FULLDRAG)
    19692160    {
    19702161      infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
    19712162      HEADER_Refresh(hwnd);
     2163    } else
     2164    {
     2165      hdc = GetDC(hwnd);
     2166      HEADER_DrawTrackLine(hwnd,hdc,infoPtr->xOldTrack);
     2167      ReleaseDC(hwnd,hdc);
    19722168    }
    19732169  }
     2170
     2171  infoPtr->bCaptured = FALSE;
    19742172
    19752173  return 0;
     
    19942192HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
    19952193{
    1996     return HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
     2194  HEADER_SendSimpleNotify(hwnd,NM_RCLICK);
     2195
     2196  return DefWindowProcA(hwnd,WM_RBUTTONUP,wParam,lParam);
    19972197}
    19982198
Note: See TracChangeset for help on using the changeset viewer.