Ignore:
Timestamp:
Nov 2, 1999, 10:44:04 PM (26 years ago)
Author:
achimha
Message:

comctl32 merged with WINE 991031

File:
1 edited

Legend:

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

    r1431 r1565  
    3434 *   LISTVIEW_GetISearchString : not implemented
    3535 *   LISTVIEW_GetBkImage : not implemented
    36  *   LISTVIEW_EditLabel : REPORT (need to implement a timer)
    3736 *   LISTVIEW_GetColumnOrderArray : not implemented
    3837 *   LISTVIEW_SetColumnOrderArray : not implemented
     
    4443 */
    4544
    46 /* WINE 990923 level */
     45/* WINE 991031 level */
    4746
    4847#include <string.h>
     
    8079/* default column width for items in list display mode */
    8180#define DEFAULT_COLUMN_WIDTH 96
     81
     82/* Increment size of the horizontal scroll bar */
     83#define REPORT_HSCROLL_INC_SIZE 10
    8284
    8385/*
     
    9193/* retrieve the number of items in the listview */
    9294#define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
     95
     96/* Some definitions for inline edit control */   
     97typedef BOOL (*EditlblCallback)(HWND, LPSTR, DWORD);
     98
     99HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y,
     100        INT width, INT height, HWND parent, HINSTANCE hinst,
     101        EditlblCallback EditLblCb, DWORD param);
     102 
     103typedef struct tagEDITLABEL_ITEM
     104{
     105    WNDPROC EditWndProc;
     106    DWORD param;
     107    EditlblCallback EditLblCb;
     108} EDITLABEL_ITEM;
    93109
    94110/*
     
    129145static BOOL LISTVIEW_ToggleSelection(HWND, INT);
    130146static VOID LISTVIEW_UnsupportedStyles(LONG lStyle);
    131 
    132 /***
    133  * DESCRIPTION:
    134  * Update the scrollbars. This functions should be called whenever
     147static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem);
     148static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem);
     149static LRESULT LISTVIEW_Command(HWND hwnd, WPARAM wParam, LPARAM lParam);
     150
     151/*************************************************************************
     152 * LISTVIEW_UpdateHeaderSize [Internal]
     153 *
     154 * Function to resize the header control
     155 *
     156 * PARAMS
     157 *     hwnd             [I] handle to a window
     158 *     nNewScrollPos    [I] Scroll Pos to Set
     159 *     nOldScrollPos    [I] Previous Scroll Pos
     160 *
     161 * RETURNS
     162 *     nothing
     163 *
     164 * NOTES
     165 */
     166static VOID LISTVIEW_UpdateHeaderSize(HWND hwnd, INT nNewScrollPos, INT nOldScrollPos)
     167{
     168    LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     169    INT nDiff = nOldScrollPos-nNewScrollPos;
     170    RECT winRect;
     171    POINT point[2];
     172
     173    GetWindowRect(infoPtr->hwndHeader, &winRect);
     174    point[0].x = winRect.left;
     175    point[0].y = winRect.top;
     176    point[1].x = winRect.right;
     177    point[1].y = winRect.bottom;
     178
     179    MapWindowPoints(HWND_DESKTOP, hwnd, point, 2);
     180    point[0].x += (nDiff * REPORT_HSCROLL_INC_SIZE );
     181    point[1].x -= point[0].x;
     182
     183    SetWindowPos(infoPtr->hwndHeader,0,
     184        point[0].x,point[0].y,point[1].x,point[1].y,
     185        SWP_NOZORDER | SWP_NOACTIVATE);
     186}
     187
     188/***
     189 * DESCRIPTION:
     190 * Update the scrollbars. This functions should be called whenever
    135191 * the content, size or view changes.
    136  *
     192 * 
    137193 * PARAMETER(S):
    138194 * [I] HWND : window handle
     
    143199static VOID LISTVIEW_UpdateScroll(HWND hwnd)
    144200{
    145   LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     201  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); 
    146202  LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
    147203  UINT uView =  lStyle & LVS_TYPEMASK;
     
    160216    {
    161217      /* calculate new scrollbar range */
    162       INT nHiddenItemCount = GETITEMCOUNT(infoPtr) - nCountPerPage;
    163       if (nHiddenItemCount % nCountPerColumn == 0)
    164       {
    165         scrollInfo.nMax = nHiddenItemCount / nCountPerColumn;
     218      if((GETITEMCOUNT(infoPtr) % nCountPerPage) == 0)
     219      {
     220          scrollInfo.nMax = GETITEMCOUNT(infoPtr) / nCountPerPage * LISTVIEW_GetCountPerRow(hwnd)-1;
    166221      }
    167222      else
    168223      {
    169         scrollInfo.nMax = nHiddenItemCount / nCountPerColumn + 1;
    170       }
    171 
     224          scrollInfo.nMax = (GETITEMCOUNT(infoPtr) / nCountPerPage)* LISTVIEW_GetCountPerRow(hwnd);
     225      }
     226     
    172227      scrollInfo.nPos = ListView_GetTopIndex(hwnd) / nCountPerColumn;
    173       /*scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd);*/
    174       scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     228      scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd);
     229      scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
    175230      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
    176231    }
     
    180235      if (lStyle & WS_HSCROLL)
    181236      {
    182         ShowScrollBar(hwnd, SB_HORZ, FALSE);
     237        ShowScrollBar(hwnd, SB_HORZ, FALSE);
    183238      }
    184239    }
     
    186241  else if (uView == LVS_REPORT)
    187242  {
     243    RECT clientRect;
    188244    /* update vertical scrollbar */
    189245    scrollInfo.nMin = 0;
    190     scrollInfo.nMax = GETITEMCOUNT(infoPtr) - LISTVIEW_GetCountPerColumn(hwnd);
     246    scrollInfo.nMax = GETITEMCOUNT(infoPtr) - 1;
    191247    scrollInfo.nPos = ListView_GetTopIndex(hwnd);
    192     /*scrollInfo.nPage = nCountPerColumn;*/
    193     scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     248    scrollInfo.nPage = LISTVIEW_GetCountPerColumn(hwnd);
     249    scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
    194250    SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
    195251
    196252    /* update horizontal scrollbar */
    197 /*     if (infoPtr->nItemWidth > nListWidth) */
    198 /*     { */
    199 /*       scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; */
    200 /*       SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); */
    201 /*     } */
    202 
    203     /* horizontal scrolling has not been implemented yet! I experienced some
    204        problems when performing child window scrolling. */
     253    infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     254    GetClientRect(hwnd, &clientRect);
     255
     256    if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE)
     257    {
     258      scrollInfo.nPos = 0;
     259    }
     260    scrollInfo.nMin = 0;
     261    scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE  ;
     262    scrollInfo.nPage = (clientRect.right - clientRect.left) / REPORT_HSCROLL_INC_SIZE;
     263    scrollInfo.nMax = infoPtr->nItemWidth;
     264
     265    /* Check to see if we need the scroll bar */
     266    if(scrollInfo.nMax < 0)
     267    {
     268      scrollInfo.nMax = 0;
     269    }
     270    else
     271    {
     272      /* Even up the max */
     273      scrollInfo.nMax -= (scrollInfo.nMax % REPORT_HSCROLL_INC_SIZE);
     274      scrollInfo.nMax = (scrollInfo.nMax / REPORT_HSCROLL_INC_SIZE)-1;
     275    }
     276    /* Set the scroll pos to the max if the current scroll pos is greater */
     277    if((scrollInfo.nPos+scrollInfo.nPage) > scrollInfo.nMax
     278        && scrollInfo.nMax > scrollInfo.nPage)
     279    {
     280      UINT nOldScrollPos = scrollInfo.nPos;
     281      scrollInfo.nPos = scrollInfo.nMax;
     282      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     283      GetScrollInfo(hwnd, SB_HORZ, &scrollInfo);
     284      LISTVIEW_UpdateHeaderSize(hwnd, scrollInfo.nPos, nOldScrollPos);
     285    }
     286    else
     287    {
     288        SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
     289    }
    205290  }
    206291  else
     
    233318          scrollInfo.nPos = 0;
    234319        }
    235 
     320 
    236321        if (nHiddenWidth % nScrollPosWidth == 0)
    237322        {
    238           scrollInfo.nMax = nHiddenWidth / nScrollPosWidth;
     323          scrollInfo.nMax = nHiddenWidth / nScrollPosWidth; 
    239324        }
    240325        else
    241326        {
    242           scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1;
    243         }
    244 
     327          scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1; 
     328        }
     329         
    245330        scrollInfo.nMin = 0;
    246         /*scrollInfo.nPage = 10;*/
    247         scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     331        scrollInfo.nPage = 10;
     332        scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
    248333        SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
    249334      }
     
    279364        if (nHiddenHeight % nScrollPosHeight == 0)
    280365        {
    281           scrollInfo.nMax = nHiddenHeight / nScrollPosHeight;
     366          scrollInfo.nMax = nHiddenHeight / nScrollPosHeight; 
    282367        }
    283368        else
    284369        {
    285           scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1;
     370          scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1; 
    286371        }
    287372
    288373        scrollInfo.nMin = 0;
    289         /*scrollInfo.nPage = 10;*/
    290         scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
     374        scrollInfo.nPage = 10;
     375        scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
    291376        SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
    292377      }
     
    17751860  }
    17761861
     1862  /* Don't bother painting item being edited */
     1863  if (infoPtr->lpeditItem && lvItem.state & LVIS_FOCUSED)
     1864      return;
     1865
    17771866  if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE))
    17781867  {
     
    19222011 * DESCRIPTION:
    19232012 * Draws listview items when in report display mode.
    1924  *
    1925  * PARAMETER(S):
    1926  * [I] HWND : window handle
    1927  * [I] HDC : device context handle
     2013 * 
     2014 * PARAMETER(S):
     2015 * [I] HWND : window handle
     2016 * [I] HDC : device context handle 
    19282017 *
    19292018 * RETURN:
     
    19332022{
    19342023  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
     2024  SCROLLINFO scrollInfo;
    19352025  INT nDrawPosY = infoPtr->rcList.top;
    19362026  INT nColumnCount;
     
    19402030  INT nLast;
    19412031
     2032  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
     2033  scrollInfo.cbSize = sizeof(SCROLLINFO);
     2034  scrollInfo.fMask = SIF_POS;
     2035
    19422036  nItem = ListView_GetTopIndex(hwnd);
    19432037
     
    19552049      rcItem.top = nDrawPosY;
    19562050      rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
     2051
     2052      /* Offset the Scroll Bar Pos */
     2053      if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
     2054      {
     2055        rcItem.left -= (scrollInfo.nPos * REPORT_HSCROLL_INC_SIZE);
     2056        rcItem.right -= (scrollInfo.nPos * REPORT_HSCROLL_INC_SIZE);
     2057      }
     2058
    19572059      if (j == 0)
    19582060      {
    1959         LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
    1960       }
    1961       else
     2061        LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem); 
     2062      }
     2063      else 
    19622064      {
    19632065        LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem);
    19642066      }
    19652067    }
    1966 
     2068   
    19672069    nDrawPosY += infoPtr->nItemHeight;
    19682070  }
     
    20702172 * DESCRIPTION:
    20712173 * Draws listview items when in list display mode.
    2072  *
    2073  * PARAMETER(S):
    2074  * [I] HWND : window handle
    2075  * [I] HDC : device context handle
     2174 * 
     2175 * PARAMETER(S):
     2176 * [I] HWND : window handle
     2177 * [I] HDC : device context handle 
    20762178 *
    20772179 * RETURN:
     
    20862188  INT nColumnCount;
    20872189  INT nCountPerColumn;
    2088 
     2190  INT nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     2191  INT nItemHeight = LISTVIEW_GetItemHeight(hwnd);
     2192 
    20892193  /* get number of fully visible columns */
    20902194  nColumnCount = LISTVIEW_GetColumnCount(hwnd);
     
    20992203        return;
    21002204
    2101       rcItem.top = j * infoPtr->nItemHeight;
    2102       rcItem.left = i * infoPtr->nItemWidth;
    2103       rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
    2104       rcItem.right = rcItem.left + infoPtr->nItemWidth;
     2205      rcItem.top = j * nItemHeight;
     2206      rcItem.left = i * nItemWidth;
     2207      rcItem.bottom = rcItem.top + nItemHeight;
     2208      rcItem.right = rcItem.left + nItemWidth;
    21052209      LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
    21062210    }
     
    24592563 * DESCRIPTION:
    24602564 * Removes a column from the listview control.
    2461  *
     2565 * 
    24622566 * PARAMETER(S):
    24632567 * [I] HWND : window handle
     
    24732577  UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    24742578  BOOL bResult = FALSE;
    2475 
     2579 
    24762580  if (Header_DeleteItem(infoPtr->hwndHeader, nColumn) != FALSE)
    24772581  {
    24782582    bResult = LISTVIEW_RemoveColumn(infoPtr->hdpaItems, nColumn);
     2583
     2584    /* Need to reset the item width when deleting a column */
     2585    infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
    24792586
    24802587    /* reset scroll parameters */
     
    25922699}
    25932700
    2594 /* LISTVIEW_EditLabel */
     2701/***
     2702 * DESCRIPTION:
     2703 * Return edit control handle of current edit label
     2704 *
     2705 * PARAMETER(S):
     2706 * [I] HWND : window handle
     2707 *
     2708 * RETURN:
     2709 *   SUCCESS : HWND
     2710 *   FAILURE : 0
     2711 */
     2712static LRESULT LISTVIEW_GetEditControl(hwnd)
     2713{
     2714  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2715  return infoPtr->hwndEdit;
     2716}
     2717
     2718
     2719/***
     2720 * DESCRIPTION:
     2721 * Callback implementation for editlabel control
     2722 *
     2723 * PARAMETER(S):
     2724 * [I] HWND : window handle
     2725 * [I] LPSTR : modified text
     2726 * [I] DWORD : item index
     2727 *
     2728 * RETURN:
     2729 *   SUCCESS : TRUE
     2730 *   FAILURE : FALSE
     2731 */
     2732
     2733static BOOL LISTVIEW_EndEditLabel(HWND hwnd, LPSTR pszText, DWORD nItem)
     2734{
     2735  NMLVDISPINFOA dispInfo;
     2736  LISTVIEW_ITEM *lpItem;
     2737  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     2738  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2739  HDPA hdpaSubItems;
     2740 
     2741  ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
     2742
     2743  if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
     2744          return FALSE;
     2745
     2746  if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
     2747          return FALSE;
     2748
     2749  dispInfo.hdr.hwndFrom = hwnd;
     2750  dispInfo.hdr.idFrom = nCtrlId;
     2751  dispInfo.hdr.code = LVN_ENDLABELEDITA;
     2752  dispInfo.item.mask = 0;
     2753  dispInfo.item.iItem = nItem;
     2754  dispInfo.item.state = lpItem->state;
     2755  dispInfo.item.stateMask = 0;
     2756  dispInfo.item.pszText = pszText;
     2757  dispInfo.item.cchTextMax = pszText ? strlen(pszText) : 0;
     2758  dispInfo.item.iImage = lpItem->iImage;
     2759  dispInfo.item.lParam = lpItem->lParam;
     2760
     2761  ListView_Notify(GetParent(hwnd), nCtrlId, &dispInfo);
     2762  infoPtr->hwndEdit = 0;
     2763  infoPtr->lpeditItem = NULL;
     2764
     2765  return TRUE;
     2766}
     2767
     2768/***
     2769 * DESCRIPTION:
     2770 * Begin in place editing of specified list view item
     2771 *
     2772 * PARAMETER(S):
     2773 * [I] HWND : window handle
     2774 * [I] INT : item index
     2775 *
     2776 * RETURN:
     2777 *   SUCCESS : TRUE
     2778 *   FAILURE : FALSE
     2779 */
     2780
     2781static HWND LISTVIEW_EditLabelA(HWND hwnd, INT nItem)
     2782{
     2783  NMLVDISPINFOA dispInfo;
     2784  RECT rect;
     2785  LISTVIEW_ITEM *lpItem;
     2786  HWND hedit;
     2787  HINSTANCE hinst = GetWindowLongA(hwnd, GWL_HINSTANCE);
     2788  INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
     2789  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     2790  HDPA hdpaSubItems;
     2791 
     2792  if (~GetWindowLongA(hwnd, GWL_STYLE) & LVS_EDITLABELS)
     2793      return FALSE;
     2794
     2795  ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
     2796  if (NULL == (hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem)))
     2797          return 0;
     2798
     2799  if (NULL == (lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0)))
     2800          return 0;
     2801
     2802  dispInfo.hdr.hwndFrom = hwnd;
     2803  dispInfo.hdr.idFrom = nCtrlId;
     2804  dispInfo.hdr.code = LVN_BEGINLABELEDITA;
     2805  dispInfo.item.mask = 0;
     2806  dispInfo.item.iItem = nItem;
     2807  dispInfo.item.state = lpItem->state;
     2808  dispInfo.item.stateMask = 0;
     2809  dispInfo.item.pszText = lpItem->pszText;
     2810  dispInfo.item.cchTextMax = strlen(lpItem->pszText);
     2811  dispInfo.item.iImage = lpItem->iImage;
     2812  dispInfo.item.lParam = lpItem->lParam;
     2813
     2814  if (ListView_LVNotify(GetParent(hwnd), nCtrlId, &dispInfo))
     2815          return 0;
     2816
     2817  rect.left = LVIR_LABEL;
     2818  if (!LISTVIEW_GetItemRect(hwnd, nItem, &rect))
     2819          return 0;
     2820 
     2821 if (!(hedit = CreateEditLabel(dispInfo.item.pszText , WS_VISIBLE,
     2822                 rect.left, rect.top, rect.right - rect.left + 15,
     2823                 rect.bottom - rect.top,
     2824                 hwnd, hinst, LISTVIEW_EndEditLabel, nItem)))
     2825         return 0;
     2826
     2827  infoPtr->hwndEdit = hedit;
     2828  infoPtr->lpeditItem = lpItem;
     2829  SetFocus(hedit);
     2830  SendMessageA(hedit, EM_SETSEL, 0, -1);
     2831
     2832  return hedit;
     2833}
    25952834
    25962835/***
     
    33233562                Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
    33243563              }
    3325               lpLVItem->pszText = dispInfo.item.pszText;
     3564              strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax);
    33263565            }
    33273566            else if (lpLVItem->mask & LVIF_TEXT)
    33283567            {
    3329               lpLVItem->pszText = lpItem->pszText;
     3568              strncpy(lpLVItem->pszText, lpItem->pszText, lpLVItem->cchTextMax);
    33303569            }
    33313570
     
    34183657                   Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
    34193658              }
    3420               lpLVItem->pszText = dispInfo.item.pszText;
     3659              strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax);
    34213660            }
    34223661            else if (lpLVItem->mask & LVIF_TEXT)
    34233662            {
    3424               lpLVItem->pszText = lpSubItem->pszText;
     3663              strncpy(lpLVItem->pszText, lpSubItem->pszText, lpLVItem->cchTextMax);
    34253664            }
    34263665          }
     
    45364775                             (WPARAM)nColumn, (LPARAM)&hdi);
    45374776
     4777    /* Need to reset the item width when inserting a new column */
     4778    infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
     4779
    45384780    LISTVIEW_UpdateScroll(hwnd);
    45394781    InvalidateRect(hwnd, NULL, FALSE);
     
    54585700  infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING);
    54595701  ZeroMemory(&infoPtr->rcList, sizeof(RECT));
     5702  infoPtr->hwndEdit = 0;
     5703  infoPtr->lpeditItem = NULL;
    54605704
    54615705  /* get default font (icon title) */
     
    55645808 * DESCRIPTION:
    55655809 * Performs vertical scrolling.
    5566  *
     5810 * 
    55675811 * PARAMETER(S):
    55685812 * [I] HWND : window handle
    55695813 * [I] INT : scroll code
    5570  * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
     5814 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 
    55715815 *             or SB_THUMBTRACK.
    55725816 * [I] HWND : scrollbar control window handle
     
    55785822                                HWND hScrollWnd)
    55795823{
    5580   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    55815824  SCROLLINFO scrollInfo;
    55825825
    55835826  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
    55845827  scrollInfo.cbSize = sizeof(SCROLLINFO);
    5585   scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
    5586 
     5828  scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
     5829 
    55875830  if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
    55885831  {
     
    55965839      }
    55975840    break;
    5598 
     5841   
    55995842    case SB_LINEDOWN:
    56005843      if (scrollInfo.nPos < scrollInfo.nMax)
     
    56035846      }
    56045847      break;
    5605 
     5848     
    56065849    case SB_PAGEUP:
    56075850      if (scrollInfo.nPos > scrollInfo.nMin)
    56085851      {
    5609         INT nPage = 0;
    5610 
    5611         if (uView == LVS_REPORT)
    5612         {
    5613           nPage = LISTVIEW_GetCountPerColumn(hwnd);
    5614         }
    5615         else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    5616         {
    5617           nPage = 10;
    5618         }
    5619 
    5620         if (scrollInfo.nPos >= nPage)
    5621         {
    5622           scrollInfo.nPos -= nPage;
     5852
     5853        if (scrollInfo.nPos >= scrollInfo.nPage)
     5854        {
     5855          scrollInfo.nPos -= scrollInfo.nPage;
    56235856        }
    56245857        else
     
    56285861      }
    56295862      break;
    5630 
     5863     
    56315864    case SB_PAGEDOWN:
    56325865      if (scrollInfo.nPos < scrollInfo.nMax)
    56335866      {
    5634         INT nPage = 0;
    5635 
    5636         if (uView == LVS_REPORT)
    5637         {
    5638           nPage = LISTVIEW_GetCountPerColumn(hwnd);
    5639         }
    5640         else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    5641         {
    5642           nPage = 10;
    5643         }
    5644 
    5645         if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
    5646         {
    5647           scrollInfo.nPos += nPage;
     5867        if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage)
     5868        {
     5869          scrollInfo.nPos += scrollInfo.nPage;
    56485870        }
    56495871        else
     
    56545876      break;
    56555877
    5656     case SB_THUMBPOSITION:
     5878    case SB_THUMBTRACK:
     5879        scrollInfo.nPos = nCurrentPos;
    56575880      break;
    56585881    }
     
    56625885      scrollInfo.fMask = SIF_POS;
    56635886      SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
    5664       InvalidateRect(hwnd, NULL, FALSE);
    5665     }
    5666   }
    5667 
     5887      InvalidateRect(hwnd, NULL, TRUE);
     5888    }
     5889  }
     5890   
    56685891  return 0;
    56695892}
     
    56725895 * DESCRIPTION:
    56735896 * Performs horizontal scrolling.
    5674  *
     5897 * 
    56755898 * PARAMETER(S):
    56765899 * [I] HWND : window handle
    56775900 * [I] INT : scroll code
    5678  * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
     5901 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION 
    56795902 *             or SB_THUMBTRACK.
    56805903 * [I] HWND : scrollbar control window handle
     
    56865909                                HWND hScrollWnd)
    56875910{
    5688   UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    56895911  SCROLLINFO scrollInfo;
    56905912
    56915913  ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
    56925914  scrollInfo.cbSize = sizeof(SCROLLINFO);
    5693   scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
    5694 
     5915  scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
     5916 
    56955917  if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
    56965918  {
     
    57055927      }
    57065928      break;
    5707 
     5929   
    57085930    case SB_LINERIGHT:
    57095931      if (scrollInfo.nPos < scrollInfo.nMax)
     
    57125934      }
    57135935      break;
    5714 
     5936     
    57155937    case SB_PAGELEFT:
    57165938      if (scrollInfo.nPos > scrollInfo.nMin)
    57175939      {
    5718         INT nPage = 0;
    5719 
    5720         if (uView == LVS_LIST)
    5721         {
    5722           nPage = LISTVIEW_GetCountPerRow(hwnd);
    5723         }
    5724         else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    5725         {
    5726           nPage = 10;
    5727         }
    5728 
    5729         if (scrollInfo.nPos >= nPage)
    5730         {
    5731           scrollInfo.nPos -= nPage;
     5940        if (scrollInfo.nPos >= scrollInfo.nPage)
     5941        {
     5942          scrollInfo.nPos -= scrollInfo.nPage;
    57325943        }
    57335944        else
     
    57375948      }
    57385949      break;
    5739 
     5950     
    57405951    case SB_PAGERIGHT:
    57415952      if (scrollInfo.nPos < scrollInfo.nMax)
    57425953      {
    5743         INT nPage = 0;
    5744 
    5745         if (uView == LVS_LIST)
    5746         {
    5747           nPage = LISTVIEW_GetCountPerRow(hwnd);
    5748         }
    5749         else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
    5750         {
    5751           nPage = 10;
    5752         }
    5753 
    5754         if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
    5755         {
    5756           scrollInfo.nPos += nPage;
     5954        if (scrollInfo.nPos <= scrollInfo.nMax - scrollInfo.nPage)
     5955        {
     5956          scrollInfo.nPos += scrollInfo.nPage;
    57575957        }
    57585958        else
     
    57635963      break;
    57645964
    5765     case SB_THUMBPOSITION:
     5965    case SB_THUMBTRACK:
     5966        scrollInfo.nPos = nCurrentPos;
    57665967      break;
    57675968    }
     
    57695970    if (nOldScrollPos != scrollInfo.nPos)
    57705971    {
     5972      UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
    57715973      scrollInfo.fMask = SIF_POS;
    57725974      SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
    5773       InvalidateRect(hwnd, NULL, FALSE);
    5774     }
    5775   }
    5776 
     5975      scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
     5976      GetScrollInfo(hwnd, SB_HORZ, &scrollInfo);
     5977      if(uView == LVS_REPORT)
     5978      {
     5979          LISTVIEW_UpdateHeaderSize(hwnd, scrollInfo.nPos, nOldScrollPos);
     5980      }
     5981      InvalidateRect(hwnd, NULL, TRUE);
     5982    }
     5983  }
     5984   
    57775985  return 0;
    57785986}
     
    61466354 * DESCRIPTION:
    61476355 * Handles notifications from children.
    6148  *
     6356 * 
    61496357 * PARAMETER(S):
    61506358 * [I] HWND : window handle
    61516359 * [I] INT : control identifier
    61526360 * [I] LPNMHDR : notification information
    6153  *
     6361 * 
    61546362 * RETURN:
    61556363 * Zero
     
    61586366{
    61596367  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    6160 
    6161   if (lpnmh->hwndFrom == infoPtr->hwndHeader)
     6368 
     6369  if (lpnmh->hwndFrom == infoPtr->hwndHeader) 
    61626370  {
    61636371    /* handle notification from header control */
     
    61656373    {
    61666374      infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
    6167       InvalidateRect(hwnd, NULL, FALSE);
    6168     }
     6375      InvalidateRect(hwnd, NULL, TRUE);
     6376    }
     6377    else if(lpnmh->code ==  HDN_ITEMCLICKA)
     6378    {
     6379        /* Handle sorting by Header Column */
     6380        NMLISTVIEW nmlv;
     6381        LPNMHEADERA pnmHeader = (LPNMHEADERA) lpnmh;
     6382        LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
     6383
     6384        ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
     6385        nmlv.hdr.hwndFrom = hwnd;
     6386        nmlv.hdr.idFrom = lCtrlId;
     6387        nmlv.hdr.code = LVN_COLUMNCLICK;
     6388        nmlv.iItem = -1;
     6389        nmlv.iSubItem = pnmHeader->iItem;
     6390       
     6391        ListView_LVNotify(GetParent(hwnd),lCtrlId, &nmlv);
     6392
     6393    }
     6394    else if(lpnmh->code == NM_RELEASEDCAPTURE)
     6395    {
     6396      /* Idealy this should be done in HDN_ENDTRACKA
     6397       * but since SetItemBounds in Header.c is called after
     6398       * the notification is sent, it is neccessary to handle the
     6399       * update of the scroll bar here (Header.c works fine as it is,
     6400       * no need to disturb it)
     6401       */
     6402      LISTVIEW_UpdateScroll(hwnd);
     6403      InvalidateRect(hwnd, NULL, TRUE);
     6404    }
     6405
    61696406  }
    61706407
     
    66736910    return LISTVIEW_DeleteItem(hwnd, (INT)wParam);
    66746911
    6675 /*      case LVM_EDITLABEL: */
     6912  case LVM_EDITLABELW:
     6913  case LVM_EDITLABELA:
     6914    return LISTVIEW_EditLabelA(hwnd, (INT)wParam);
    66766915
    66776916  case LVM_ENSUREVISIBLE:
     
    67056944    return LISTVIEW_GetCountPerPage(hwnd);
    67066945
    6707 /*      case LVM_GETEDITCONTROL: */
     6946  case LVM_GETEDITCONTROL:
     6947    return LISTVIEW_GetEditControl(hwnd);
     6948
    67086949  case LVM_GETEXTENDEDLISTVIEWSTYLE:
    67096950    return LISTVIEW_GetExtendedListViewStyle(hwnd);
     
    68897130
    68907131/*      case WM_CHAR: */
    6891 /*      case WM_COMMAND: */
     7132  case WM_COMMAND:
     7133    return LISTVIEW_Command(hwnd, wParam, lParam);
    68927134
    68937135  case WM_CREATE:
     
    70387280}
    70397281
     7282/***
     7283 * DESCRIPTION:
     7284 * Handle any WM_COMMAND messages
     7285 *
     7286 * PARAMETER(S):
     7287 *
     7288 * RETURN:
     7289 */
     7290static LRESULT LISTVIEW_Command(HWND hwnd, WPARAM wParam, LPARAM lParam)
     7291{
     7292    switch (HIWORD(wParam))
     7293    {
     7294        case EN_UPDATE:
     7295        {
     7296            /*
     7297             * Adjust the edit window size
     7298             */
     7299            char buffer[1024];
     7300            LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     7301            HDC           hdc      = GetDC(infoPtr->hwndEdit);
     7302            RECT          rect;
     7303            SIZE          sz;
     7304
     7305            GetWindowTextA(infoPtr->hwndEdit, buffer, 1024);
     7306            GetWindowRect(infoPtr->hwndEdit, &rect);
     7307            if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
     7308            {
     7309                    SetWindowPos (
     7310                infoPtr->hwndEdit,
     7311                HWND_TOP,
     7312                0,
     7313                0,
     7314                sz.cx + 15,
     7315                rect.bottom - rect.top,
     7316                SWP_DRAWFRAME|SWP_NOMOVE);
     7317            }
     7318            ReleaseDC(hwnd, hdc);
     7319
     7320            break;
     7321        }
     7322
     7323        default:
     7324          return SendMessageA (GetParent (hwnd), WM_COMMAND, wParam, lParam);
     7325    }
     7326
     7327    return 0;
     7328}
     7329
     7330
     7331/***
     7332 * DESCRIPTION:
     7333 * Subclassed edit control windproc function
     7334 *
     7335 * PARAMETER(S):
     7336 *
     7337 * RETURN:
     7338 */
     7339LRESULT CALLBACK EditLblWndProc(HWND hwnd, UINT uMsg,
     7340        WPARAM wParam, LPARAM lParam)
     7341{
     7342    BOOL cancel = TRUE;
     7343    EDITLABEL_ITEM *einfo =
     7344    (EDITLABEL_ITEM *) GetWindowLongA(hwnd, GWL_USERDATA);
     7345
     7346    switch (uMsg)
     7347    {
     7348        case WM_KILLFOCUS:
     7349            break;
     7350
     7351        case WM_CHAR:
     7352            if (VK_RETURN == (INT)wParam)
     7353            {
     7354                cancel = FALSE;
     7355                break;
     7356            }
     7357            else if (VK_ESCAPE == (INT)wParam)
     7358                break;
     7359
     7360        default:
     7361            return CallWindowProcA(einfo->EditWndProc, hwnd,
     7362                        uMsg, wParam, lParam);
     7363    }
     7364
     7365    SetWindowLongA(hwnd, GWL_WNDPROC, (LONG)einfo->EditWndProc);
     7366    if (einfo->EditLblCb)
     7367    {
     7368        char *buffer  = NULL;
     7369
     7370        if (!cancel)
     7371        {
     7372            int len = 1 + GetWindowTextLengthA(hwnd);
     7373
     7374            if (len > 1)
     7375            {
     7376                if (NULL != (buffer = (char *)COMCTL32_Alloc(len*sizeof(char))))
     7377                {
     7378                    GetWindowTextA(hwnd, buffer, len);
     7379                }
     7380            }
     7381        }
     7382           
     7383        einfo->EditLblCb(GetParent(hwnd), buffer, einfo->param);
     7384
     7385        if (buffer)
     7386            COMCTL32_Free(buffer);
     7387    }
     7388
     7389    COMCTL32_Free(einfo);
     7390    PostMessageA(hwnd, WM_CLOSE, 0, 0);
     7391    return TRUE;
     7392}
     7393
     7394
     7395/***
     7396 * DESCRIPTION:
     7397 * Creates a subclassed edit cotrol
     7398 *
     7399 * PARAMETER(S):
     7400 *
     7401 * RETURN:
     7402 */
     7403HWND CreateEditLabel(LPCSTR text, DWORD style, INT x, INT y,
     7404        INT width, INT height, HWND parent, HINSTANCE hinst,
     7405        EditlblCallback EditLblCb, DWORD param)
     7406{
     7407    HWND hedit;
     7408    EDITLABEL_ITEM *einfo;
     7409 
     7410    if (NULL == (einfo = COMCTL32_Alloc(sizeof(EDITLABEL_ITEM))))
     7411        return 0;
     7412
     7413    style |= WS_CHILDWINDOW|WS_CLIPSIBLINGS|ES_LEFT|WS_BORDER;
     7414    if (!(hedit = CreateWindowA("Edit", text, style, x, y, width, height,
     7415                    parent, 0, hinst, 0)))
     7416    {
     7417        COMCTL32_Free(einfo);
     7418        return 0;
     7419    }
     7420
     7421    einfo->param = param;
     7422    einfo->EditLblCb = EditLblCb;
     7423    einfo->EditWndProc = (WNDPROC)SetWindowLongA(hedit,
     7424          GWL_WNDPROC, (LONG) EditLblWndProc);
     7425
     7426    SetWindowLongA(hedit, GWL_USERDATA, (LONG)einfo);
     7427
     7428    return hedit;
     7429}
Note: See TracChangeset for help on using the changeset viewer.