Ignore:
Timestamp:
Feb 10, 2000, 7:51:19 PM (26 years ago)
Author:
cbratschi
Message:

added listview style, treeview rewrite started

File:
1 edited

Legend:

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

    r2635 r2740  
    1 /* $Id: treeview.c,v 1.22 2000-02-04 17:02:09 cbratschi Exp $ */
     1/* $Id: treeview.c,v 1.23 2000-02-10 18:51:19 cbratschi Exp $ */
    22/* Treeview control
    33 *
     
    6565  ((TREEVIEW_INFO *) GetWindowLongA( hwnd, 0))
    6666
    67 static BOOL
    68 TREEVIEW_SendSimpleNotify (HWND hwnd, UINT code);
    69 static BOOL
    70 TREEVIEW_SendTreeviewNotify (HWND hwnd, UINT code, UINT action,
    71                         HTREEITEM oldItem, HTREEITEM newItem);
    72 static BOOL
    73 TREEVIEW_SendTreeviewDnDNotify (HWND hwnd, UINT code, HTREEITEM dragItem,
    74                         POINT pt);
    75 static BOOL
    76 TREEVIEW_SendDispInfoNotify (HWND hwnd, TREEVIEW_ITEM *wineItem,
    77                         UINT code, UINT what);
    78 static BOOL
    79 TREEVIEW_SendCustomDrawNotify (HWND hwnd, DWORD dwDrawStage, HDC hdc,
    80                         RECT rc);
    81 static BOOL
    82 TREEVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc,
    83             TREEVIEW_ITEM *tvItem, UINT uItemDrawState);
    84 static LRESULT
    85 TREEVIEW_DoSelectItem (HWND hwnd, INT action, HTREEITEM newSelect, INT cause);
    86 static void
    87 TREEVIEW_Refresh (HWND hwnd,HDC hdc);
    88 
    89 static LRESULT CALLBACK
    90 TREEVIEW_Edit_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam,
    91                                                         LPARAM lParam);
    92 
    93 LRESULT WINAPI
    94 TREEVIEW_EndEditLabelNow (HWND hwnd, WPARAM wParam, LPARAM lParam);
    95 
    96 
    97 
     67static BOOL    TREEVIEW_SendSimpleNotify (HWND hwnd, UINT code);
     68static BOOL    TREEVIEW_SendTreeviewNotify (HWND hwnd, UINT code, UINT action, HTREEITEM oldItem, HTREEITEM newItem);
     69static BOOL    TREEVIEW_SendTreeviewDnDNotify (HWND hwnd, UINT code, HTREEITEM dragItem, POINT pt);
     70static BOOL    TREEVIEW_SendDispInfoNotify (HWND hwnd, TREEVIEW_ITEM *wineItem, UINT code, UINT what);
     71static BOOL    TREEVIEW_SendCustomDrawNotify (HWND hwnd, DWORD dwDrawStage, HDC hdc, RECT rc);
     72static BOOL    TREEVIEW_SendCustomDrawItemNotify (HWND hwnd, HDC hdc, TREEVIEW_ITEM *tvItem, UINT uItemDrawState);
     73static LRESULT TREEVIEW_DoSelectItem (HWND hwnd, INT action, HTREEITEM newSelect, INT cause);
     74static void    TREEVIEW_Refresh(HWND hwnd);
     75static void    TREEVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect);
     76
     77static LRESULT CALLBACK TREEVIEW_Edit_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
     78
     79LRESULT WINAPI TREEVIEW_EndEditLabelNow (HWND hwnd, WPARAM wParam, LPARAM lParam);
    9880
    9981/* helper functions. Work with the assumption that validity of operands
     
    383365
    384366
    385 
    386 
    387 
    388 
    389 
    390367static LRESULT
    391368TREEVIEW_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    502479{
    503480  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    504   HDC hdc;
    505481
    506482  //FIXME("%d %ld\n",wParam,lParam);
     
    511487  infoPtr->insertMarkItem=(HTREEITEM) lParam;
    512488
    513   hdc = GetDC(hwnd);
    514   TREEVIEW_Refresh(hwnd,hdc);
    515   ReleaseDC(hwnd,hdc);
     489  //CB: todo
     490  TREEVIEW_Refresh(hwnd);
    516491
    517492  return 1;
     
    912887  HTREEITEM     *iItem;
    913888  LPRECT        lpRect   = (LPRECT)lParam;
    914   HDC hdc;
    915889
    916890//  TRACE (treeview,"\n");
     
    920894  if (lpRect == NULL)
    921895    return FALSE;
    922 
    923   if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
    924   {
    925     hdc = GetDC(hwnd);
    926     TREEVIEW_Refresh(hwnd,hdc);        /* we want a rect for the current view */
    927     ReleaseDC(hwnd,hdc);
    928   }
    929896
    930897  /*
     
    965932  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    966933
     934  //CB: todo: that's the number of completely visible items
     935
    967936  return (LRESULT) infoPtr->uVisibleHeight / infoPtr->uRealItemHeight;
    968937}
     
    10461015}
    10471016
     1017static void TREEVIEW_RefreshItem(HWND hwnd,TREEVIEW_ITEM *item)
     1018{
     1019  if (item && item->visible)
     1020  {
     1021    //CB: todo: only redraw text and icon
     1022    InvalidateRect(hwnd,&item->rect,TRUE);
     1023  }
     1024}
     1025
     1026static void TREEVIEW_Refresh(HWND hwnd)
     1027{
     1028  InvalidateRect(hwnd,NULL,TRUE);
     1029}
     1030
     1031static void TREEVIEW_CalcItems(HWND hwnd)
     1032{
     1033  //CB: todo: TREEVIEW_Draw should only draw, not calculate!
     1034}
     1035
     1036static void TREEVIEW_SetScrollbars(HWND hwnd)
     1037{
     1038  //CB: todo: dito
     1039}
     1040
     1041static int TREEVIEW_GetFirstVisibleItem(HWND hwnd)
     1042{
     1043  //CB: todo
     1044
     1045  return 0;
     1046}
     1047
    10481048static void
    1049 TREEVIEW_Refresh (HWND hwnd,HDC hdc)
    1050 
     1049TREEVIEW_Draw(HWND hwnd,HDC hdc,RECT *updateRect)
    10511050{
    10521051    TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    10531052    TEXTMETRICA tm;
    10541053    HBRUSH hbrBk;
    1055     RECT rect;
     1054    RECT rect,view;
    10561055    INT iItem, indent, x, y, cx, height, itemHeight;
    1057     INT viewtop,viewbottom,viewleft,viewright;
    10581056    TREEVIEW_ITEM *wineItem, *prevItem;
    10591057
    10601058    //TRACE("\n");
    1061 
    1062     if (infoPtr->Timer & TV_REFRESH_TIMER_SET) {
    1063                 KillTimer (hwnd, TV_REFRESH_TIMER);
    1064                 infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
    1065     }
    1066 
    10671059
    10681060    GetClientRect (hwnd, &rect);
     
    10771069    infoPtr->uVisibleWidth= rect.right-rect.left;
    10781070
    1079     viewtop=infoPtr->cy;
    1080     viewbottom=infoPtr->cy + rect.bottom-rect.top;
    1081     viewleft=infoPtr->cx;
    1082     viewright=infoPtr->cx + rect.right-rect.left;
     1071    view = updateRect ? *updateRect:rect;
     1072    view.left = 0;
     1073    view.right = rect.right;
     1074    OffsetRect(&view,infoPtr->cx,infoPtr->cy);
    10831075
    10841076    /* draw background */
     
    10931085    indent=0;
    10941086    x=y=0;
    1095     //TRACE("[%d %d %d %d]\n",viewtop,viewbottom,viewleft,viewright);
    10961087
    10971088    while (iItem) {
     
    11101101        infoPtr->uRealItemHeight=itemHeight;
    11111102
    1112 
    1113 /* FIXME: remove this in later stage  */
    1114 /*
    1115                 if (wineItem->pszText!=LPSTR_TEXTCALLBACK32A)
    1116                 TRACE (treeview, "%d %d [%d %d %d %d] (%s)\n",y,x,
    1117                         wineItem->rect.top, wineItem->rect.bottom,
    1118                         wineItem->rect.left, wineItem->rect.right,
    1119                         wineItem->pszText);
    1120                 else
    1121                 TRACE (treeview, "%d [%d %d %d %d] (CALLBACK)\n",
    1122                                 wineItem->hItem,
    1123                                 wineItem->rect.top, wineItem->rect.bottom,
    1124                                 wineItem->rect.left, wineItem->rect.right);
    1125 */
    1126 
    11271103                height=itemHeight * wineItem->iIntegral +1;
    1128                 if ((y >= viewtop) && (y <= viewbottom) &&
    1129                 (x >= viewleft  ) && (x <= viewright)) {
     1104                if ((((y >= view.top) && (y <= view.bottom)) || ((y+height >= view.top) && (y+height <= view.bottom))) &&
     1105                    (x >= view.left) && (x <= view.right))
     1106                {
    11301107                                wineItem->visible = TRUE;
    11311108                        wineItem->rect.top = y - infoPtr->cy + rect.top;
     
    11711148
    11721149    infoPtr->uTotalHeight=y;
    1173     if (y >= (viewbottom-viewtop)) {
     1150    if (y >= (view.bottom-view.top)) {
    11741151                if (!(infoPtr->uInternalStatus & TV_VSCROLL))
    11751152                        ShowScrollBar (hwnd, SB_VERT, TRUE);
     
    12021179
    12031180  switch (wParam) {
    1204         case TV_REFRESH_TIMER:
    1205                 KillTimer (hwnd, TV_REFRESH_TIMER);
    1206                 infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
    1207     InvalidateRect(hwnd, NULL, FALSE);
    1208                 return 0;
    12091181        case TV_EDIT_TIMER:
    12101182                KillTimer (hwnd, TV_EDIT_TIMER);
     
    12181190 return 1;
    12191191}
    1220 
    1221 
    1222 static void
    1223 TREEVIEW_QueueRefresh (HWND hwnd)
    1224 
    1225 {
    1226  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    1227 
    1228 // TRACE (treeview,"\n");
    1229  if (infoPtr->Timer & TV_REFRESH_TIMER_SET) {
    1230         KillTimer (hwnd, TV_REFRESH_TIMER);
    1231  }
    1232 
    1233  SetTimer (hwnd, TV_REFRESH_TIMER, TV_REFRESH_DELAY, 0);
    1234  infoPtr->Timer|=TV_REFRESH_TIMER_SET;
    1235 }
    1236 
    1237 
    12381192
    12391193static LRESULT
     
    13121266  TREEVIEW_ITEM *wineItem, *returnItem;
    13131267  INT iItem, retval, flag;
    1314   HDC hdc;
    13151268
    13161269  flag  = (INT) wParam;
     
    13221275        case TVGN_CARET:retval=(INT)infoPtr->selectedItem;
    13231276                                        break;
    1324         case TVGN_FIRSTVISIBLE: /* FIXME:we should only recalculate, not redraw */
    1325                                         hdc = GetDC (hwnd);
    1326                                         TREEVIEW_Refresh (hwnd, hdc);
    1327                                         ReleaseDC(hwnd,hdc);
    1328                                         retval=(INT)infoPtr->firstVisible;
    1329                                         break;
     1277        case TVGN_FIRSTVISIBLE: /* FIXME:we should only recalculate, not redraw */
     1278                                        //CB: todo: remove
     1279                                        TREEVIEW_Refresh(hwnd);
     1280                                        retval=(INT)infoPtr->firstVisible;
     1281                                        break;
    13301282        case TVGN_DROPHILITE:
    13311283                                        retval=(INT)infoPtr->dropItem;
     
    19831935   }
    19841936
    1985    TREEVIEW_QueueRefresh (hwnd);
     1937   //CB: todo: calc
     1938   TREEVIEW_Refresh(hwnd);
    19861939
    19871940   return (LRESULT) iItem;
     
    20592012  }
    20602013
    2061   TREEVIEW_QueueRefresh (hwnd);
     2014  //CB: todo: calc
     2015  TREEVIEW_Refresh(hwnd);
    20622016
    20632017  return TRUE;
     
    22362190  }
    22372191
    2238   TREEVIEW_QueueRefresh (hwnd);
     2192  //CB: todo: calc
     2193  TREEVIEW_Refresh(hwnd);
    22392194  return 0;
    22402195}
     
    22442199TREEVIEW_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
    22452200{
    2246   HDC hdc;
    2247 
    22482201  //TRACE("(%x %lx)\n",wParam,lParam);
    2249   hdc = GetDC (hwnd);
    2250   TREEVIEW_Refresh (hwnd, hdc);
    2251   ReleaseDC(hwnd,hdc);
     2202  //CB: todo: calc
     2203  TREEVIEW_Refresh (hwnd);
    22522204
    22532205  return 0;
     
    23092261    infoPtr->pCallBackSort=NULL;
    23102262    infoPtr->uScrollTime = 300;  /* milliseconds */
    2311         infoPtr->wpEditOrig = NULL; /* we haven't subclassed anything yet */
     2263        infoPtr->wpEditOrig = NULL; /* we haven't subclassed anything yet */
    23122264        infoPtr->hwndToolTip=0;
    23132265    if (!(dwStyle & TVS_NOTOOLTIPS)) {   /* Create tooltip control */
     
    23892341   SetWindowLongA( hwnd, 0, (DWORD)NULL);
    23902342
    2391    if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
    2392         KillTimer (hwnd, TV_REFRESH_TIMER);
    23932343   if (infoPtr->hwndToolTip)
    23942344                DestroyWindow (infoPtr->hwndToolTip);
     
    24082358//    TRACE (treeview,"\n");
    24092359    hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
    2410     TREEVIEW_Refresh (hwnd,hdc);
     2360    TREEVIEW_Draw(hwnd,hdc,&ps.rcPaint);
    24112361    if(!wParam)
    24122362        EndPaint (hwnd, &ps);
     
    24202370{
    24212371   TREEVIEW_SendSimpleNotify (hwnd, NM_SETFOCUS);
    2422    InvalidateRect(hwnd, NULL, FALSE);
     2372
     2373   //CB: todo: focus item
     2374
    24232375   return 0;
    24242376}
     
    24282380{
    24292381   TREEVIEW_SendSimpleNotify (hwnd, NM_KILLFOCUS);
    2430    InvalidateRect(hwnd, NULL, FALSE);
     2382
     2383   //CB: todo: focus item
     2384
    24312385   return 0;
    24322386}
     
    28282782//    wineItem->state);
    28292783
    2830   TREEVIEW_QueueRefresh (hwnd);
     2784  //CB: todo: replace
     2785  TREEVIEW_Refresh(hwnd);
    28312786  return TRUE;
    28322787}
     
    31193074                        wineItem->state|=state<<12;
    31203075                        //TRACE ("state:%x\n", wineItem->state);
    3121                         TREEVIEW_QueueRefresh (hwnd);
     3076                        TREEVIEW_Refresh(hwnd);
    31223077                }
    31233078  }
     
    33003255      infoPtr->selectedItem=(HTREEITEM)newSelect;
    33013256
     3257      TREEVIEW_RefreshItem(hwnd,prevItem);
     3258      TREEVIEW_RefreshItem(hwnd,wineItem);
     3259
    33023260      TREEVIEW_SendTreeviewNotify(
    33033261        hwnd,
     
    33203278        wineItem->state |=TVIS_DROPHILITED;
    33213279
     3280      TREEVIEW_RefreshItem(hwnd,prevItem);
     3281      TREEVIEW_RefreshItem(hwnd,wineItem);
     3282
    33223283      break;
    33233284
     
    33263287      break;
    33273288 }
    3328 
    3329  TREEVIEW_QueueRefresh (hwnd);
    33303289
    33313290//  TRACE (treeview,"Leaving state %d\n", wineItem->state);
     
    33843343 ReleaseDC (0, hdc);
    33853344
     3345 //CB: todo: calc
    33863346 if (lParam)
    3387         TREEVIEW_QueueRefresh (hwnd);
     3347        TREEVIEW_Refresh(hwnd);
    33883348
    33893349 return 0;
     
    33983358  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    33993359  int maxHeight;
     3360  int lastPos = infoPtr->cy;
    34003361
    34013362//  TRACE (treeview,"wp %x, lp %lx\n", wParam, lParam);
     
    34333394  }
    34343395
    3435   TREEVIEW_QueueRefresh (hwnd);
     3396  ScrollWindowEx(hwnd,0,lastPos-infoPtr->cy,NULL,NULL,0,NULL,SW_INVALIDATE);
     3397
    34363398  return TRUE;
    34373399}
     
    34783440  }
    34793441
    3480   TREEVIEW_QueueRefresh (hwnd);
     3442  TREEVIEW_Refresh(hwnd);
     3443
     3444  //CB: todo: use ScrollWindowEx
     3445
    34813446  return TRUE;
    34823447}
     
    36853650{
    36863651   if (uMsg==WM_CREATE)
    3687                 return TREEVIEW_Create (hwnd, wParam, lParam);
     3652                return TREEVIEW_Create (hwnd, wParam, lParam);
    36883653
    36893654   if (!TREEVIEW_GetInfoPtr(hwnd))
     
    39283893
    39293894    ZeroMemory (&wndClass, sizeof(WNDCLASSA));
    3930     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
     3895    wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
    39313896    wndClass.lpfnWndProc   = (WNDPROC)TREEVIEW_WindowProc;
    39323897    wndClass.cbClsExtra    = 0;
Note: See TracChangeset for help on using the changeset viewer.