Changeset 2635 for trunk/src


Ignore:
Timestamp:
Feb 4, 2000, 6:02:09 PM (26 years ago)
Author:
cbratschi
Message:

merged with WINE20000130

Location:
trunk/src/comctl32
Files:
8 edited

Legend:

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

    r2523 r2635  
    1 /* $Id: comctl32.c,v 1.12 2000-01-26 18:04:29 cbratschi Exp $ */
     1/* $Id: comctl32.c,v 1.13 2000-02-04 17:02:06 cbratschi Exp $ */
    22/*
    33 * Win32 common controls implementation
     
    1212 */
    1313
    14 /* WINE 990923 level (commctrl.c) */
     14/* WINE 20000130 level (commctrl.c) */
    1515
    1616#include "comctl32.h"
     
    837837}
    838838
     839static int iTrackMax = 0;
     840static HWND TrackingList[10];
     841static UINT timer;
     842
     843static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT idEvent, DWORD dwTime) {
     844        int i = 0;
     845        POINT pos;
     846        HWND hwnd;
     847        BOOL keepTracking = FALSE;
     848        GetCursorPos(&pos);
     849        hwnd = WindowFromPoint(pos);
     850        /* Loop through the list of windows waiting on mouse exit */
     851        while (i < iTrackMax) {
     852                if (TrackingList[i] != hwnd)
     853                        PostMessageA(TrackingList[i], WM_MOUSELEAVE, 0, 0);
     854                else
     855                        keepTracking = TRUE;
     856
     857
     858                i++;
     859        }
     860
     861        if (keepTracking) {
     862                iTrackMax = 1;
     863                TrackingList[0] = hwnd;
     864        }
     865        else
     866                KillTimer(0, timer);
     867}
     868
     869/***********************************************************************
     870 * _TrackMouseEvent [COMCTL32.25]
     871 *
     872 * Requests notification of mouse events
     873 *
     874 * PARAMS
     875 *     ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
     876 *
     877 * RETURNS
     878 *     Success: non-zero
     879 *     Failure: zero
     880 *
     881 */
     882
     883BOOL WINAPI
     884_TrackMouseEvent (TRACKMOUSEEVENT *ptme)
     885{
     886    DWORD flags = 0;
     887        int i;
     888        BOOL cancel = 0, hover = 0, leave = 0, query = 0;
     889        if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
     890        //WARN("wrong TRACKMOUSEEVENT size from app");
     891        return E_INVALIDARG;
     892    }
     893
     894    //TRACE("%lx, %lx, %x, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
     895
     896        flags = ptme->dwFlags;
     897    if ( flags & TME_CANCEL ) {
     898                cancel = 1;
     899                flags &= ~ TME_CANCEL;
     900        }
     901    if ( flags & TME_HOVER  ) {
     902                hover = 1;
     903                flags &= ~ TME_HOVER;
     904                //FIXME("TME_HOVER unimplemented\n" );
     905        }
     906    if ( flags & TME_LEAVE ) {
     907                leave = 1;
     908                flags &= ~ TME_LEAVE;
     909        }
     910    if ( flags & TME_QUERY ) {
     911                query = 1;
     912                flags &= ~ TME_QUERY;
     913                //FIXME("TME_QUERY unimplemented\n" );
     914        }
     915
     916        //if ( flags )
     917        //      FIXME("Unknown flag(s) %ld\n", flags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_QUERY) );
     918
     919        if (leave) {
     920                if (cancel) {
     921                        for (i = 0; i < iTrackMax; i++)
     922                                if (TrackingList[i] == ptme->hwndTrack)
     923                                        TrackingList[i] = TrackingList[--iTrackMax];
     924                }
     925                else {
     926                        if (iTrackMax == sizeof (TrackingList) / sizeof *TrackingList)
     927                                return FALSE;
     928
     929                        /* Add hwndTrack to the track list */
     930                        TrackingList[iTrackMax++] = ptme->hwndTrack;
     931                        if (!timer)
     932                                timer = SetTimer(0, 0, 50, TrackMouseEventProc);
     933                }
     934        }
     935
     936        return TRUE;
     937}
     938
     939
  • trunk/src/comctl32/comctl32undoc.c

    r2126 r2635  
    1 /* $Id: comctl32undoc.c,v 1.16 1999-12-18 20:56:58 achimha Exp $ */
     1/* $Id: comctl32undoc.c,v 1.17 2000-02-04 17:02:06 cbratschi Exp $ */
    22/*
    33 * Undocumented functions from COMCTL32.DLL
     
    1212 */
    1313
    14 /* WINE 991212 level */
     14/* WINE 20000130 level */
    1515
    1616/* CB: todo
     
    2525#include <stdlib.h>
    2626#include <ctype.h>
     27#include <wchar.h>
     28#include <wcstr.h>
     29#include <wctype.h>
    2730
    2831extern HANDLE COMCTL32_hHeap; /* handle to the private heap */
     
    295298HANDLE WINAPI
    296299CreateMRUListLazyA (LPCREATEMRULIST lpcml, DWORD dwParam2,
    297                     DWORD dwParam3, DWORD dwParam4);
     300                    DWORD dwParam3, DWORD dwParam4);
    298301
    299302
     
    323326FreeMRUListA (HANDLE hMRUList)
    324327{
    325     FIXME("(%08x) empty stub!\n", hMRUList);
     328    //FIXME("(%08x) empty stub!\n", hMRUList);
    326329
    327330#if 0
    328331    if (!(hmru->dwParam1 & 1001)) {
    329         RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
    330                           hmru->lpszMRUString,
    331                           lstrlenA (hmru->lpszMRUString));
     332        RegSetValueExA (hmru->hKeyMRU, "MRUList", 0, REG_SZ,
     333                          hmru->lpszMRUString,
     334                          lstrlenA (hmru->lpszMRUString));
    332335    }
    333336
     
    343346/**************************************************************************
    344347 *              AddMRUData [COMCTL32.167]
    345  * 
     348 *
    346349 * Add item to MRU binary list.  If item already exists in list them it is
    347350 * simply moved up to the top of the list and not added again.  If list is
     
    360363AddMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData)
    361364{
    362     FIXME("(%08x, %p, %ld) empty stub!\n", hList, lpData, cbData);
     365    //FIXME("(%08x, %p, %ld) empty stub!\n", hList, lpData, cbData);
    363366
    364367    return 0;
     
    367370/**************************************************************************
    368371 *              AddMRUStringA [COMCTL32.153]
    369  * 
     372 *
    370373 * Add item to MRU string list.  If item already exists in list them it is
    371374 * simply moved up to the top of the list and not added again.  If list is
     
    383386AddMRUStringA(HANDLE hList, LPCSTR lpszString)
    384387{
    385     FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
     388    //FIXME("(%08x, %s) empty stub!\n", hList, debugstr_a(lpszString));
    386389
    387390    return 0;
     
    403406DelMRUString(HANDLE hList, INT nItemPos)
    404407{
    405     FIXME("(%08x, %d): stub\n", hList, nItemPos);
     408    //FIXME("(%08x, %d): stub\n", hList, nItemPos);
    406409    return TRUE;
    407410}
     
    409412/**************************************************************************
    410413 *                  FindMRUData [COMCTL32.169]
    411  * 
     414 *
    412415 * Searches binary list for item that matches lpData of length cbData.
    413416 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
     
    426429FindMRUData (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum)
    427430{
    428     FIXME("(%08x, %p, %ld, %p) empty stub!\n",
    429            hList, lpData, cbData, lpRegNum);
     431    //FIXME("(%08x, %p, %ld, %p) empty stub!\n",
     432    //       hList, lpData, cbData, lpRegNum);
    430433
    431434    return 0;
     
    434437/**************************************************************************
    435438 *                  FindMRUStringA [COMCTL32.155]
    436  * 
     439 *
    437440 * Searches string list for item that matches lpszString.
    438441 * Returns position in list order 0 -> MRU and if lpRegNum != NULL then value
     
    450453FindMRUStringA (HANDLE hList, LPCSTR lpszString, LPINT lpRegNum)
    451454{
    452     FIXME("(%08x, %s, %p) empty stub!\n", hList, debugstr_a(lpszString),
    453           lpRegNum);
     455    //FIXME("(%08x, %s, %p) empty stub!\n", hList, debugstr_a(lpszString),
     456    //      lpRegNum);
    454457
    455458    return 0;
     
    471474    LPVOID ptr;
    472475
    473     FIXME("(%p) empty stub!\n", lpcml);
     476    //FIXME("(%p) empty stub!\n", lpcml);
    474477
    475478    if (lpcml == NULL)
    476         return 0;
     479        return 0;
    477480
    478481    if (lpcml->cbSize < sizeof(CREATEMRULIST))
    479         return 0;
    480 
    481     FIXME("(%lu %lu %lx %lx \"%s\" %p)\n",
    482           lpcml->cbSize, lpcml->nMaxItems, lpcml->dwFlags,
    483           (DWORD)lpcml->hKey, lpcml->lpszSubKey, lpcml->lpfnCompare);
     482        return 0;
     483
     484    //FIXME("(%lu %lu %lx %lx \"%s\" %p)\n",
     485    //      lpcml->cbSize, lpcml->nMaxItems, lpcml->dwFlags,
     486    //      (DWORD)lpcml->hKey, lpcml->lpszSubKey, lpcml->lpfnCompare);
    484487
    485488    /* dummy pointer creation */
    486489    ptr = COMCTL32_Alloc (32);
    487490
    488     FIXME("-- ret = %p\n", ptr);
     491    //FIXME("-- ret = %p\n", ptr);
    489492
    490493    return (HANDLE)ptr;
     
    493496/**************************************************************************
    494497 *                EnumMRUListA [COMCTL32.154]
    495  * 
     498 *
    496499 * Enumerate item in a list
    497500 *
     
    507510 *    of list returns -1.
    508511 *    If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
    509  *    the list. 
     512 *    the list.
    510513 */
    511514INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer,
    512515DWORD nBufferSize)
    513516{
    514     FIXME("(%08x, %d, %p, %ld): stub\n", hList, nItemPos, lpBuffer,
    515           nBufferSize);
     517    //FIXME("(%08x, %d, %p, %ld): stub\n", hList, nItemPos, lpBuffer,
     518    //      nBufferSize);
    516519    return 0;
    517520}
     
    832835            /* resize the block of memory */
    833836            nNewItems =
    834                 hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
     837                hdsa->nGrow * ((INT)(((nIndex + 1) - 1) / hdsa->nGrow) + 1);
    835838            nSize = hdsa->nItemSize * nNewItems;
    836839
     
    13381341            /* resize the block of memory */
    13391342            INT nNewItems =
    1340                 hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
     1343                hdpa->nGrow * ((INT)(((i+1) - 1) / hdpa->nGrow) + 1);
    13411344            INT nSize = nNewItems * sizeof(LPVOID);
    13421345
     
    14771480    v = lpPtrs[(int)(l+r)/2];
    14781481    do {
    1479         while ((pfnCompare)(lpPtrs[i], v, lParam) < 0) i++;
    1480         while ((pfnCompare)(lpPtrs[j], v, lParam) > 0) j--;
     1482        while ((pfnCompare)(lpPtrs[i], v, lParam) < 0) i++;
     1483        while ((pfnCompare)(lpPtrs[j], v, lParam) > 0) j--;
    14811484        if (i <= j)
    14821485        {
     
    20172020
    20182021/***********************************************************************
    2019  *           ChrCmpA   
     2022 *           ChrCmpA
    20202023 * This fuction returns FALSE if both words match, TRUE otherwise...
    20212024 */
     
    20392042  if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
    20402043
    2041   for(; lpStart < lpEnd; lpStart = CharNextA(lpStart)) 
    2042     if (!ChrCmpA( GET_WORD(lpStart), wMatch)) 
     2044  for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
     2045    if (!ChrCmpA( GET_WORD(lpStart), wMatch))
    20432046      lpGotIt = lpStart;
    2044    
     2047
    20452048  return ((LPSTR)lpGotIt);
    20462049
     
    20492052
    20502053/***********************************************************************
    2051  *           ChrCmpW   
     2054 *           ChrCmpW
    20522055 * This fuction returns FALSE if both words match, TRUE otherwise...
    20532056 */
     
    20672070  if (!lpEnd) lpEnd = lpStart + lstrlenW(lpStart);
    20682071
    2069   for(; lpStart < lpEnd; lpStart = CharNextW(lpStart)) 
    2070     if (!ChrCmpW( GET_WORD(lpStart), wMatch)) 
     2072  for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
     2073    if (!ChrCmpW( GET_WORD(lpStart), wMatch))
    20712074      lpGotIt = lpStart;
    2072    
     2075
    20732076  return (LPWSTR)lpGotIt;
    20742077}
     
    21192122BOOL WINAPI comctl32_410( HWND hw, DWORD b, DWORD c, DWORD d) {
    21202123
    2121    FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
     2124   //FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
    21222125
    21232126   return TRUE;
     
    21332136BOOL WINAPI comctl32_411( HWND hw, DWORD b, DWORD c) {
    21342137
    2135    FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
     2138   //FIXME("(%x, %lx, %lx): stub!\n", hw, b, c);
    21362139
    21372140   return TRUE;
     
    21472150BOOL WINAPI comctl32_412( HWND hwnd, DWORD b, DWORD c)
    21482151{
    2149     FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
     2152    //FIXME("(%x, %lx, %lx): stub!\n", hwnd, b, c);
    21502153
    21512154    if (IsWindow (hwnd) == FALSE)
    2152         return FALSE;
     2155        return FALSE;
    21532156
    21542157    if (b == 0)
    2155         return FALSE;
     2158        return FALSE;
    21562159
    21572160
     
    21682171BOOL WINAPI comctl32_413( HWND hw, DWORD b, DWORD c, DWORD d) {
    21692172
    2170    FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
     2173   //FIXME("(%x, %lx, %lx, %lx): stub!\n", hw, b, c, d);
    21712174
    21722175   return TRUE;
     
    21822185BOOL WINAPI InitMUILanguage( LANGID uiLang) {
    21832186
    2184    FIXME("(%04x): stub!\n", uiLang);
     2187   //FIXME("(%04x): stub!\n", uiLang);
    21852188
    21862189   return TRUE;
  • trunk/src/comctl32/datetime.c

    r2126 r2635  
    1 /* $Id: datetime.c,v 1.6 1999-12-18 20:56:58 achimha Exp $ */
     1/* $Id: datetime.c,v 1.7 2000-02-04 17:02:07 cbratschi Exp $ */
    22/*
    33 * Date and time picker control
     
    1515 */
    1616
    17 /* WINE 991212 level */
     17/* WINE 20000130 level */
    1818
    1919#include "winbase.h"
  • trunk/src/comctl32/imagelist.c

    r2126 r2635  
    1 /* $Id: imagelist.c,v 1.10 1999-12-18 20:56:58 achimha Exp $ */
     1/* $Id: imagelist.c,v 1.11 2000-02-04 17:02:07 cbratschi Exp $ */
    22/*
    33 *  ImageList implementation
    44 *
    55 *  Copyright 1998 Eric Kohl
    6  * Copyright 1999 Achim Hasenmueller
     6 *  Copyright 1999 Achim Hasenmueller
     7 *  Copyright 2000 Christoph Bratschi
    78 *
    89 *  TODO:
     
    1011 *    - Fix ImageList_GetIcon.
    1112 *    - Fix drag functions.
    12  *    - Fix ImageList_Read and ImageList_Write.
     13 *    - Fix ImageList_Write.
    1314 *    - Fix ImageList_SetFilter (undocumented).
    1415 *      BTW does anybody know anything about this function???
     
    2627
    2728/* CB: todo
    28   - ImageList_Read
    2929  - ImageList_Write
    3030*/
    3131
    32 /* WINE 991212 level */
     32/* WINE 20000130 level */
    3333
    3434/* This must be defined because the HIMAGELIST type is just a pointer
     
    3838 */
    3939#define __WINE_IMAGELIST_C
     40
     41#include "wine/obj_base.h"
     42#include "wine/obj_storage.h"
    4043
    4144#include "imagelist.h"
     
    169172    HDC hImageDC;
    170173    HBITMAP hOldBitmap;
     174
    171175    hImageDC = CreateCompatibleDC(0);
    172176    hOldBitmap = SelectObject(hImageDC, pimldp->himl->hbmImage);
     
    223227    */
    224228    if( bUseCustomBackground && (pimldp->fStyle == ILD_NORMAL
    225           || pimldp->fStyle & ILD_IMAGE
     229          || (pimldp->fStyle & ILD_IMAGE)
    226230          || bBlendFlag))
    227231    {
     
    238242    */
    239243    if(pimldp->fStyle == ILD_NORMAL
    240         || pimldp->fStyle & ILD_TRANSPARENT
     244        || (pimldp->fStyle & ILD_TRANSPARENT)
    241245        || ((pimldp->fStyle & ILD_IMAGE) && bUseCustomBackground)
    242246        || bBlendFlag)
     
    265269    /* Draw the image when no Background is specified
    266270    */
    267     else if(pimldp->fStyle & ILD_IMAGE && !bUseCustomBackground)
     271    else if((pimldp->fStyle & ILD_IMAGE) && !bUseCustomBackground)
    268272    {
    269273        BitBlt(pimldp->hdcDst,
     
    13391343        DeleteDC (hdcDst);
    13401344        DeleteDC (hdcSrc);
     1345
     1346        himlDst->cCurImage = himlSrc->cCurImage;
     1347        himlDst->cMaxImage = himlSrc->cMaxImage;
    13411348    }
    13421349
     
    18881895
    18891896
     1897/* helper for _read_bitmap currently unused */
     1898static int may_use_dibsection(HDC hdc) {
     1899    int bitspixel = GetDeviceCaps(hdc,BITSPIXEL)*GetDeviceCaps(hdc,PLANES);
     1900    if (bitspixel>8)
     1901        return TRUE;
     1902    if (bitspixel<=4)
     1903        return FALSE;
     1904    return GetDeviceCaps(hdc,94) & 0x10;
     1905}
     1906
     1907/* helper for ImageList_Read, see comments below */
     1908static HBITMAP _read_bitmap(LPSTREAM pstm,int ilcFlag,int cx,int cy) {
     1909    HDC                 xdc = 0;
     1910    BITMAPFILEHEADER    bmfh;
     1911    BITMAPINFOHEADER    bmih;
     1912    int                 bitsperpixel,palspace,longsperline,width,height;
     1913    LPBITMAPINFOHEADER  bmihc = NULL;
     1914    int                 result = 0;
     1915    HBITMAP             hbitmap = 0;
     1916    LPBYTE              bits = NULL,nbits = NULL;
     1917    int                 nbytesperline,bytesperline;
     1918
     1919    if (!SUCCEEDED(IStream_Read ( pstm, &bmfh, sizeof(bmfh), NULL))     ||
     1920        (bmfh.bfType != (('M'<<8)|'B'))                                 ||
     1921        !SUCCEEDED(IStream_Read ( pstm, &bmih, sizeof(bmih), NULL))     ||
     1922        (bmih.biSize != sizeof(bmih))
     1923    )
     1924        return 0;
     1925
     1926    bitsperpixel = bmih.biPlanes * bmih.biBitCount;
     1927    if (bitsperpixel<=8)
     1928        palspace = (1<<bitsperpixel)*sizeof(RGBQUAD);
     1929    else
     1930        palspace = 0;
     1931    width = bmih.biWidth;
     1932    height = bmih.biHeight;
     1933    bmihc = (LPBITMAPINFOHEADER)LocalAlloc(LMEM_ZEROINIT,sizeof(bmih)+palspace);
     1934    memcpy(bmihc,&bmih,sizeof(bmih));
     1935    longsperline        = ((width*bitsperpixel+31)&~0x1f)>>5;
     1936    bmihc->biSizeImage  = (longsperline*height)<<2;
     1937
     1938    /* read the palette right after the end of the bitmapinfoheader */
     1939    if (palspace)
     1940        if (!SUCCEEDED(IStream_Read ( pstm, bmihc+1, palspace, NULL)))
     1941            goto ret1;
     1942
     1943    xdc = GetDC(0);
     1944#if 0 /* Magic for NxM -> 1x(N*M) not implemented for DIB Sections */
     1945    if ((bitsperpixel>1) &&
     1946        ((ilcFlag!=ILC_COLORDDB) && (!ilcFlag || may_use_dibsection(xdc)))
     1947     ) {
     1948        hbitmap = CreateDIBSection(xdc,(BITMAPINFO*)bmihc,0,(LPVOID*)&bits,0,0);
     1949        if (!hbitmap)
     1950            goto ret1;
     1951        if (!SUCCEEDED(IStream_Read( pstm, bits, bmihc->biSizeImage, NULL)))
     1952            goto ret1;
     1953        result = 1;
     1954    } else
     1955#endif
     1956    {
     1957        int i,nwidth,nheight;
     1958
     1959        nwidth  = width*(height/cy);
     1960        nheight = cy;
     1961
     1962        if (bitsperpixel==1)
     1963            hbitmap = CreateBitmap(nwidth,nheight,1,1,NULL);
     1964        else
     1965            hbitmap = CreateCompatibleBitmap(xdc,nwidth,nheight);
     1966
     1967        /* Might be a bit excessive memory use here */
     1968        bits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
     1969        nbits = (LPBYTE)LocalAlloc(LMEM_ZEROINIT,bmihc->biSizeImage);
     1970        if (!SUCCEEDED(IStream_Read ( pstm, bits, bmihc->biSizeImage, NULL)))
     1971                goto ret1;
     1972
     1973        /* Copy the NxM bitmap into a 1x(N*M) bitmap we need, linewise */
     1974        /* Do not forget that windows bitmaps are bottom->top */
     1975        bytesperline    = longsperline*4;
     1976        nbytesperline   = (height/cy)*bytesperline;
     1977        for (i=0;i<height;i++) {
     1978            memcpy(
     1979                nbits+((height-i)%cy)*nbytesperline+(i/cy)*bytesperline,
     1980                bits+bytesperline*(height-i),
     1981                bytesperline
     1982            );
     1983        }
     1984        bmihc->biWidth  = nwidth;
     1985        bmihc->biHeight = nheight;
     1986        if (!SetDIBits(xdc,hbitmap,0,nheight,nbits,(BITMAPINFO*)bmihc,0))
     1987                goto ret1;
     1988        LocalFree((HLOCAL)nbits);
     1989        LocalFree((HLOCAL)bits);
     1990        result = 1;
     1991    }
     1992ret1:
     1993    if (xdc)    ReleaseDC(0,xdc);
     1994    if (bmihc)  LocalFree((HLOCAL)bmihc);
     1995    if (!result) {
     1996        if (hbitmap) {
     1997            DeleteObject(hbitmap);
     1998            hbitmap = 0;
     1999        }
     2000    }
     2001    return hbitmap;
     2002}
     2003
    18902004/*************************************************************************
    18912005 * ImageList_Read [COMCTL32.66]
     
    19002014 *     Failure: NULL
    19012015 *
    1902  * NOTES
    1903  *     This function can not be implemented yet, because
    1904  *     IStream32::Read is not implemented yet.
    1905  *
    1906  * BUGS
    1907  *     empty stub.
    1908  */
    1909 
    1910 //HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
    1911 HIMAGELIST WINAPI ImageList_Read (PVOID pstm)
    1912 {
    1913 //    HRESULT errCode;
    1914 //    ULONG ulRead;
    1915 //    ILHEAD ilHead;
    1916 //    HIMAGELIST himl;
    1917 
    1918 
    1919     dprintf(("ImageList_Read empty stub!\n"));
    1920 
    1921 //    errCode = IStream_Read (pstm, &ilHead, sizeof(ILHEAD), &ulRead);
    1922 //    if (errCode != S_OK)
    1923 //    return NULL;
    1924 
    1925     FIXME("Magic: 0x%x\n", ilHead.usMagic);
    1926 
    1927 //    himl = ImageList_Create (32, 32, ILD_NORMAL, 2, 2);
    1928 
    1929 //    return himl;
    1930   return 0;
     2016 * The format is like this:
     2017 *      ILHEAD                  ilheadstruct;
     2018 *
     2019 * for the color image part:
     2020 *      BITMAPFILEHEADER        bmfh;
     2021 *      BITMAPINFOHEADER        bmih;
     2022 * only if it has a palette:
     2023 *      RGBQUAD         rgbs[nr_of_paletted_colors];
     2024 *
     2025 *      BYTE                    colorbits[imagesize];
     2026 *
     2027 * the following only if the ILC_MASK bit is set in ILHEAD.ilFlags:
     2028 *      BITMAPFILEHEADER        bmfh_mask;
     2029 *      BITMAPINFOHEADER        bmih_mask;
     2030 * only if it has a palette (it usually does not):
     2031 *      RGBQUAD         rgbs[nr_of_paletted_colors];
     2032 *
     2033 *      BYTE                    maskbits[imagesize];
     2034 *
     2035 * CAVEAT: Those images are within a NxM bitmap, not the 1xN we expect.
     2036 *         _read_bitmap needs to convert them.
     2037 */
     2038HIMAGELIST WINAPI ImageList_Read (LPSTREAM pstm)
     2039{
     2040    ILHEAD      ilHead;
     2041    HIMAGELIST  himl;
     2042    HBITMAP     hbmColor=0,hbmMask=0;
     2043    int         i;
     2044
     2045    if (!SUCCEEDED(IStream_Read (pstm, &ilHead, sizeof(ILHEAD), NULL)))
     2046        return NULL;
     2047    if (ilHead.usMagic != (('L' << 8) | 'I'))
     2048        return NULL;
     2049    if (ilHead.usVersion != 0x101) /* probably version? */
     2050        return NULL;
     2051
     2052#if 0
     2053    FIXME("     ilHead.cCurImage = %d\n",ilHead.cCurImage);
     2054    FIXME("     ilHead.cMaxImage = %d\n",ilHead.cMaxImage);
     2055    FIXME("     ilHead.cGrow = %d\n",ilHead.cGrow);
     2056    FIXME("     ilHead.cx = %d\n",ilHead.cx);
     2057    FIXME("     ilHead.cy = %d\n",ilHead.cy);
     2058    FIXME("     ilHead.flags = %x\n",ilHead.flags);
     2059    FIXME("     ilHead.ovls[0] = %d\n",ilHead.ovls[0]);
     2060    FIXME("     ilHead.ovls[1] = %d\n",ilHead.ovls[1]);
     2061    FIXME("     ilHead.ovls[2] = %d\n",ilHead.ovls[2]);
     2062    FIXME("     ilHead.ovls[3] = %d\n",ilHead.ovls[3]);
     2063#endif
     2064
     2065    hbmColor = _read_bitmap(pstm,ilHead.flags & ~ILC_MASK,ilHead.cx,ilHead.cy);
     2066    if (!hbmColor)
     2067        return NULL;
     2068    if (ilHead.flags & ILC_MASK) {
     2069        hbmMask = _read_bitmap(pstm,0,ilHead.cx,ilHead.cy);
     2070        if (!hbmMask) {
     2071            DeleteObject(hbmColor);
     2072            return NULL;
     2073        }
     2074    }
     2075
     2076    himl = ImageList_Create (
     2077                    ilHead.cx,
     2078                    ilHead.cy,
     2079                    ilHead.flags,
     2080                    1,          /* initial */
     2081                    ilHead.cGrow
     2082    );
     2083    if (!himl) {
     2084        DeleteObject(hbmColor);
     2085        DeleteObject(hbmMask);
     2086        return NULL;
     2087    }
     2088    himl->hbmImage = hbmColor;
     2089    himl->hbmMask = hbmMask;
     2090    himl->cCurImage = ilHead.cCurImage;
     2091    himl->cMaxImage = ilHead.cMaxImage;
     2092
     2093    ImageList_SetBkColor(himl,ilHead.bkcolor);
     2094    for (i=0;i<4;i++)
     2095        ImageList_SetOverlayImage(himl,ilHead.ovls[i],i+1);
     2096    return himl;
    19312097}
    19322098
     
    24842650    if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE))
    24852651        return FALSE;
    2486     if ((iImage < 0) || (iImage > himl->cCurImage))
    2487         return FALSE;
    2488 
     2652    if ((iImage != -1) && ((iImage < 0) || (iImage > himl->cCurImage)))
     2653        return FALSE;
    24892654    himl->nOvlIdx[iOverlay - 1] = iImage;
    24902655    return TRUE;
  • trunk/src/comctl32/listview.c

    r2205 r2635  
    1 /*$Id: listview.c,v 1.20 1999-12-26 17:32:12 cbratschi Exp $*/
     1/*$Id: listview.c,v 1.21 2000-02-04 17:02:07 cbratschi Exp $*/
    22/*
    33 * Listview control
     
    4545 */
    4646
    47 /* WINE 991212 level */
     47/* WINE 20000130 level */
    4848
    4949#include <string.h>
     
    5959
    6060/* maximum size of a label */
    61 #define DISP_TEXT_SIZE 128
     61#define DISP_TEXT_SIZE 512
    6262
    6363/* padding for items in list and small icon display modes */
     
    105105 * forward declarations
    106106 */
     107static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem, BOOL internal);
    107108static INT LISTVIEW_HitTestItem(HWND, LPLVHITTESTINFO);
    108109static INT LISTVIEW_GetCountPerRow(HWND);
     
    17831784  lvItem.cchTextMax = DISP_TEXT_SIZE;
    17841785  lvItem.pszText = szDispText;
    1785   ListView_GetItemA(hwnd, &lvItem);
     1786  LISTVIEW_GetItemA(hwnd,&lvItem,TRUE);
    17861787
    17871788  /* set item colors */
     
    18271828  lvItem.cchTextMax = DISP_TEXT_SIZE;
    18281829  lvItem.pszText = szDispText;
    1829   ListView_GetItemA(hwnd, &lvItem);
     1830  LISTVIEW_GetItemA(hwnd,&lvItem,TRUE);
    18301831
    18311832  /* state icons */
     
    19481949  lvItem.cchTextMax = DISP_TEXT_SIZE;
    19491950  lvItem.pszText = szDispText;
    1950   ListView_GetItemA(hwnd, &lvItem);
     1951  LISTVIEW_GetItemA(hwnd, &lvItem,TRUE);
    19511952
    19521953  if (lvItem.state & LVIS_SELECTED)
     
    27402741 *   FAILURE : 0
    27412742 */
    2742 static LRESULT LISTVIEW_GetEditControl(hwnd)
     2743static LRESULT LISTVIEW_GetEditControl(HWND hwnd)
    27432744{
    27442745  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
     
    31583159        lvItem.iItem = nItem;
    31593160        lvItem.iSubItem = 0;
    3160         if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
     3161        if (LISTVIEW_GetItemA(hwnd, &lvItem,TRUE) != FALSE)
    31613162        {
    31623163          if (lvItem.mask & LVIF_TEXT)
     
    35293530 * [I] HWND : window handle
    35303531 * [IO] LPLVITEMA : item info
     3532 * [I] internal : if true then we will use tricks that avoid copies
     3533 *               but are not compatible with the regular interface
    35313534 *
    35323535 * RETURN:
     
    35343537 *   FAILURE : FALSE
    35353538 */
    3536 static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem)
     3539static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem, BOOL internal)
    35373540{
    35383541  LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
    35393542  LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
    3540   BOOL bResult = FALSE;
    35413543  NMLVDISPINFOA dispInfo;
    35423544  LISTVIEW_SUBITEM *lpSubItem;
    35433545  LISTVIEW_ITEM *lpItem;
     3546  INT* piImage;
     3547  LPSTR* ppszText;
    35443548  HDPA hdpaSubItems;
    35453549
    3546 //  TRACE("(hwnd=%x, lpLVItem=%p)\n", hwnd, lpLVItem);
    3547 
    3548   if (lpLVItem != NULL)
    3549   {
    3550     if ((lpLVItem->iItem >= 0) && (lpLVItem->iItem < GETITEMCOUNT(infoPtr)))
    3551     {
    3552       ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
    3553       hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
    3554       if (hdpaSubItems != NULL)
    3555       {
    3556         lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
    3557         if (lpItem != NULL)
    3558         {
    3559           bResult = TRUE;
    3560           if (lpLVItem->iSubItem == 0)
    3561           {
    3562             if ((lpItem->iImage == I_IMAGECALLBACK) &&
    3563                 (lpLVItem->mask & LVIF_IMAGE))
    3564             {
    3565               dispInfo.item.mask |= LVIF_IMAGE;
    3566             }
    3567 
    3568             if ((lpItem->pszText == LPSTR_TEXTCALLBACKA) &&
    3569                 (lpLVItem->mask & LVIF_TEXT))
    3570             {
    3571               dispInfo.item.mask |= LVIF_TEXT;
    3572               ZeroMemory(lpLVItem->pszText, sizeof(CHAR)*lpLVItem->cchTextMax);
    3573               dispInfo.item.pszText = lpLVItem->pszText;
    3574               dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
    3575             }
    3576 
    3577             if ((infoPtr->uCallbackMask != 0) && (lpLVItem->mask & LVIF_STATE))
    3578             {
    3579               dispInfo.item.mask |= LVIF_STATE;
    3580               dispInfo.item.stateMask = infoPtr->uCallbackMask;
    3581             }
    3582 
    3583             if (dispInfo.item.mask != 0)
    3584             {
    3585               dispInfo.hdr.hwndFrom = hwnd;
    3586               dispInfo.hdr.idFrom = lCtrlId;
    3587               dispInfo.hdr.code = LVN_GETDISPINFOA;
    3588               dispInfo.item.iItem = lpLVItem->iItem;
    3589               dispInfo.item.iSubItem = 0;
    3590               dispInfo.item.lParam = lpItem->lParam;
    3591               ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    3592             }
    3593 
    3594             if (dispInfo.item.mask & LVIF_IMAGE)
    3595             {
    3596               lpLVItem->iImage = dispInfo.item.iImage;
    3597             }
    3598             else if (lpLVItem->mask & LVIF_IMAGE)
    3599             {
    3600               lpLVItem->iImage = lpItem->iImage;
    3601             }
    3602 
    3603             if (dispInfo.item.mask & LVIF_TEXT)
    3604             {
    3605               if (dispInfo.item.mask & LVIF_DI_SETITEM)
    3606               {
    3607                 Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
    3608               }
    3609               strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax);
    3610               lpLVItem->pszText[lpLVItem->cchTextMax-1]='\0';
    3611             }
    3612             else if (lpLVItem->mask & LVIF_TEXT)
    3613             {
    3614               strncpy(lpLVItem->pszText, lpItem->pszText, lpLVItem->cchTextMax);
    3615               lpLVItem->pszText[lpLVItem->cchTextMax-1]='\0';
    3616             }
    3617 
    3618             if (dispInfo.item.mask & LVIF_STATE)
    3619             {
    3620               lpLVItem->state = lpItem->state;
    3621               lpLVItem->state &= ~dispInfo.item.stateMask;
    3622               lpLVItem->state |= (dispInfo.item.state &
    3623                                   dispInfo.item.stateMask);
    3624             }
    3625             else if (lpLVItem->mask & LVIF_STATE)
    3626             {
    3627               lpLVItem->state = lpItem->state & lpLVItem->stateMask;
    3628             }
    3629 
    3630             if (lpLVItem->mask & LVIF_PARAM)
    3631             {
    3632               lpLVItem->lParam = lpItem->lParam;
    3633             }
    3634 
    3635             if (lpLVItem->mask & LVIF_INDENT)
    3636             {
    3637               lpLVItem->iIndent = lpItem->iIndent;
    3638             }
    3639           }
    3640           else
    3641           {
    3642             lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems,
    3643                                                lpLVItem->iSubItem);
    3644             if (lpSubItem != NULL)
    3645             {
    3646               if ((lpSubItem->iImage == I_IMAGECALLBACK) &&
    3647                   (lpLVItem->mask & LVIF_IMAGE))
    3648               {
    3649                 dispInfo.item.mask |= LVIF_IMAGE;
    3650               }
    3651 
    3652               if ((lpSubItem->pszText == LPSTR_TEXTCALLBACKA) &&
    3653                   (lpLVItem->mask & LVIF_TEXT))
    3654               {
    3655                 dispInfo.item.mask |= LVIF_TEXT;
    3656                 ZeroMemory(lpLVItem->pszText,
    3657                            sizeof(CHAR)*lpLVItem->cchTextMax);
    3658                 dispInfo.item.pszText = lpLVItem->pszText;
    3659                 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
    3660               }
    3661             }
    3662             else
    3663             {
    3664               if (lpLVItem->mask & LVIF_IMAGE)
    3665               {
    3666                 dispInfo.item.mask |= LVIF_IMAGE;
    3667               }
    3668 
    3669               if (lpLVItem->mask & LVIF_TEXT)
    3670               {
    3671                 dispInfo.item.mask |= LVIF_TEXT;
    3672                 ZeroMemory(lpLVItem->pszText,
    3673                            sizeof(CHAR)*lpLVItem->cchTextMax);
    3674                 dispInfo.item.pszText = lpLVItem->pszText;
    3675                 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
    3676               }
    3677             }
    3678 
    3679             if (dispInfo.item.mask != 0)
    3680             {
    3681               dispInfo.hdr.hwndFrom = hwnd;
    3682               dispInfo.hdr.idFrom = lCtrlId;
    3683               dispInfo.hdr.code = LVN_GETDISPINFOA;
    3684               dispInfo.item.iItem = lpLVItem->iItem;
    3685               dispInfo.item.iSubItem = lpLVItem->iSubItem;
    3686               dispInfo.item.lParam = lpItem->lParam;
    3687               ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
    3688             }
    3689 
    3690             if (dispInfo.item.mask & LVIF_IMAGE)
    3691             {
    3692               lpLVItem->iImage = dispInfo.item.iImage;
    3693             }
    3694             else if (lpLVItem->mask & LVIF_IMAGE)
    3695             {
    3696               lpLVItem->iImage = lpItem->iImage;
    3697             }
    3698 
    3699             if (dispInfo.item.mask & LVIF_TEXT)
    3700             {
    3701               if (dispInfo.item.mask & LVIF_DI_SETITEM)
    3702               {
    3703                 if (lpSubItem)
    3704                    Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
    3705               }
    3706               strncpy(lpLVItem->pszText, dispInfo.item.pszText, lpLVItem->cchTextMax);
    3707               lpLVItem->pszText[lpLVItem->cchTextMax-1]='\0';
    3708             }
    3709             else if (lpLVItem->mask & LVIF_TEXT)
    3710             {
    3711               strncpy(lpLVItem->pszText, lpSubItem->pszText, lpLVItem->cchTextMax);
    3712               lpLVItem->pszText[lpLVItem->cchTextMax-1]='\0';
    3713             }
    3714           }
    3715         }
    3716       }
    3717     }
    3718   }
    3719 
    3720   return bResult;
     3550  /* In the following:
     3551   * lpLVItem describes the information requested by the user
     3552   * lpItem/lpSubItem is what we have
     3553   * dispInfo is a structure we use to request the missing
     3554   *     information from the application
     3555   */
     3556
     3557  //TRACE("(hwnd=%x, lpLVItem=%p)\n", hwnd, lpLVItem);
     3558  if ((lpLVItem == NULL) ||
     3559      (lpLVItem->iItem < 0) ||
     3560      (lpLVItem->iItem >= GETITEMCOUNT(infoPtr))
     3561     )
     3562    return FALSE;
     3563  hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
     3564  if (hdpaSubItems == NULL)
     3565    return FALSE;
     3566  lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
     3567  if (lpItem == NULL)
     3568    return FALSE;
     3569  ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
     3570  if (lpLVItem->iSubItem == 0)
     3571  {
     3572    piImage=&lpItem->iImage;
     3573    ppszText=&lpItem->pszText;
     3574    if ((infoPtr->uCallbackMask != 0) && (lpLVItem->mask & LVIF_STATE))
     3575    {
     3576      dispInfo.item.mask |= LVIF_STATE;
     3577      dispInfo.item.stateMask = infoPtr->uCallbackMask;
     3578    }
     3579  }
     3580  else
     3581  {
     3582    lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems, lpLVItem->iSubItem);
     3583    if (lpSubItem != NULL)
     3584    {
     3585      piImage=&lpItem->iImage;
     3586      ppszText=&lpItem->pszText;
     3587    }
     3588    else
     3589    {
     3590      piImage=NULL;
     3591      ppszText=NULL;
     3592    }
     3593  }
     3594  if ((lpLVItem->mask & LVIF_IMAGE) &&
     3595      ((piImage==NULL) || (*piImage == I_IMAGECALLBACK)))
     3596  {
     3597    dispInfo.item.mask |= LVIF_IMAGE;
     3598  }
     3599  if ((lpLVItem->mask & LVIF_TEXT) &&
     3600      ((ppszText==NULL) || (*ppszText == LPSTR_TEXTCALLBACKA)))
     3601  {
     3602    dispInfo.item.mask |= LVIF_TEXT;
     3603    dispInfo.item.pszText = lpLVItem->pszText;
     3604    dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
     3605  }
     3606  if (dispInfo.item.mask != 0)
     3607  {
     3608    /* We don't have all the requested info, query the application */
     3609    dispInfo.hdr.hwndFrom = hwnd;
     3610    dispInfo.hdr.idFrom = lCtrlId;
     3611    dispInfo.hdr.code = LVN_GETDISPINFOA;
     3612    dispInfo.item.iItem = lpLVItem->iItem;
     3613    dispInfo.item.iSubItem = lpLVItem->iSubItem;
     3614    dispInfo.item.lParam = lpItem->lParam;
     3615    ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
     3616  }
     3617  if (dispInfo.item.mask & LVIF_IMAGE)
     3618  {
     3619    lpLVItem->iImage = dispInfo.item.iImage;
     3620  }
     3621  else if (lpLVItem->mask & LVIF_IMAGE)
     3622  {
     3623    lpLVItem->iImage = *piImage;
     3624  }
     3625  if (dispInfo.item.mask & LVIF_TEXT)
     3626  {
     3627    if ((dispInfo.item.mask & LVIF_DI_SETITEM) && (ppszText != NULL))
     3628    {
     3629      Str_SetPtrA(ppszText, dispInfo.item.pszText);
     3630    }
     3631    /* Here lpLVItem->pszText==dispInfo.item.pszText so a copy is unnecessary */
     3632  }
     3633  else if (lpLVItem->mask & LVIF_TEXT)
     3634  {
     3635    if (internal==TRUE)
     3636    {
     3637      lpLVItem->pszText=*ppszText;
     3638    } else {
     3639      lstrcpynA(lpLVItem->pszText, *ppszText, lpLVItem->cchTextMax);
     3640    }
     3641  }
     3642  if (lpLVItem->iSubItem == 0)
     3643  {
     3644    if (dispInfo.item.mask & LVIF_STATE)
     3645    {
     3646      lpLVItem->state = lpItem->state;
     3647      lpLVItem->state &= ~dispInfo.item.stateMask;
     3648      lpLVItem->state |= (dispInfo.item.state & dispInfo.item.stateMask);
     3649    }
     3650    else if (lpLVItem->mask & LVIF_STATE)
     3651    {
     3652      lpLVItem->state = lpItem->state & lpLVItem->stateMask;
     3653    }
     3654    if (lpLVItem->mask & LVIF_PARAM)
     3655    {
     3656      lpLVItem->lParam = lpItem->lParam;
     3657    }
     3658    if (lpLVItem->mask & LVIF_INDENT)
     3659    {
     3660      lpLVItem->iIndent = lpItem->iIndent;
     3661    }
     3662  }
     3663  return TRUE;
    37213664}
    37223665
     
    41954138  lvItem.cchTextMax = DISP_TEXT_SIZE;
    41964139  lvItem.pszText = szDispText;
    4197   if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
     4140  if (LISTVIEW_GetItemA(hwnd, &lvItem,TRUE) != FALSE)
    41984141  {
    41994142    nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
     
    42564199    lvItem.stateMask = uMask;
    42574200    lvItem.mask = LVIF_STATE;
    4258     if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
     4201    if (LISTVIEW_GetItemA(hwnd, &lvItem,TRUE) != FALSE)
    42594202    {
    42604203      uState = lvItem.state;
     
    42894232      lpLVItem->mask = LVIF_TEXT;
    42904233      lpLVItem->iItem = nItem;
    4291       if (ListView_GetItemA(hwnd, lpLVItem) != FALSE)
     4234      if (LISTVIEW_GetItemA(hwnd, lpLVItem,FALSE) != FALSE)
    42924235      {
    42934236        nLength = lstrlenA(lpLVItem->pszText);
     
    70647007
    70657008  case LVM_GETITEMA:
    7066     return LISTVIEW_GetItemA(hwnd, (LPLVITEMA)lParam);
     7009    return LISTVIEW_GetItemA(hwnd, (LPLVITEMA)lParam,FALSE);
    70677010
    70687011/*      case LVM_GETITEMW: */
  • trunk/src/comctl32/monthcal.c

    r1762 r2635  
    1 /* $Id: monthcal.c,v 1.6 1999-11-17 17:06:22 cbratschi Exp $ */
     1/* $Id: */
    22/* Month calendar control
    3 
    4 
    53 *
    64 * Copyright 1998, 1999 Eric Kohl (ekohl@abo.rhein-zeitung.de)
    7  * Copyright 1999  Alex Priem (alexp@sci.kun.nl)
    8  * Copyright 1999 Christoph Bratschi
     5 * Copyright 1999 Alex Priem (alexp@sci.kun.nl)
     6 * Copyright 1999 Chris Morgan <cmorgan@wpi.edu> and
     7 *                James Abbatiello <abbeyj@wpi.edu>
     8 * Copyright 2000 Christoph Bratschi
    99 *
    1010 * TODO:
     
    1313 *
    1414 *  FIXME: refresh should ask for rect of required length. (?)
    15  *  FIXME: we refresh to often; especially in LButtonDown/MouseMove.
    1615 *  FIXME: handle resources better (doesn't work now); also take care
    1716           of internationalization.
    1817 *  FIXME: keyboard handling.
    1918 */
     19
     20/* WINE 20000130 level */
    2021
    2122#include "winbase.h"
     
    3536 * defined here */
    3637
    37 #define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongA (hwnd, 0))
    38 
    39 /* helper functions
    40  * MONTHCAL_ValidateTime: is time a valid date/time combo?
    41  */
    42 
    43 int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
    44 
    45 int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    46 
    47 static char *daytxt[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
    48 
    49 static char *monthtxt[] = {"January", "February", "March", "April", "May",
    50                            "June", "July", "August", "September", "October",
    51                            "November", "December"};
    52 
    53 /* CHECKME: all these validations OK? */
    54 
    55 static int MONTHCAL_ValidateTime (SYSTEMTIME time)
    56 
    57 {
    58  if (time.wMonth > 12) return FALSE;
    59  if (time.wDayOfWeek > 6) return FALSE;
    60  if (time.wDay > mdays[time.wMonth]) return FALSE;
    61  if (time.wMonth > 23) return FALSE;
    62  if (time.wMinute > 60) return FALSE;
    63  if (time.wSecond > 60) return FALSE;
    64  if (time.wMilliseconds > 100) return FALSE;
    65  return TRUE;
    66 }
    67 
    68 void MONTHCAL_CopyTime (const SYSTEMTIME *from, SYSTEMTIME *to)
    69 
    70 {
    71  to->wYear=from->wYear;
    72  to->wMonth=from->wMonth;
    73  to->wDayOfWeek=from->wDayOfWeek;
    74  to->wDay=from->wDay;
    75  to->wHour=from->wHour;
    76  to->wMinute=from->wMinute;
    77  to->wSecond=from->wSecond;
    78  to->wMilliseconds=from->wMilliseconds;
     38static const int mdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
     39
     40const char * const monthtxt[] = {"January", "February", "March", "April", "May",
     41                      "June", "July", "August", "September", "October",
     42                      "November", "December"};
     43const char * const daytxt[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
     44static const int DayOfWeekTable[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
     45
     46
     47#define MONTHCAL_GetInfoPtr(hwnd) ((MONTHCAL_INFO *)GetWindowLongA(hwnd, 0))
     48
     49/* helper functions  */
     50
     51/* returns the number of days in any given month */
     52/* january is 1, december is 12 */
     53static int MONTHCAL_MonthLength(int month, int year)
     54{
     55  /* if we have a leap year add 1 day to February */
     56  /* a leap year is a year either divisible by 400 */
     57  /* or divisible by 4 and not by 100 */
     58  if(month == 2) { /* February */
     59    return mdays[month - 1] + ((year%400 == 0) ? 1 : ((year%100 != 0) &&
     60     (year%4 == 0)) ? 1 : 0);
     61  }
     62  else {
     63    return mdays[month - 1];
     64  }
     65}
     66
     67
     68/* make sure that time is valid */
     69static int MONTHCAL_ValidateTime(SYSTEMTIME time)
     70{
     71  if(time.wMonth > 12) return FALSE;
     72  if(time.wDayOfWeek > 6) return FALSE;
     73  if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
     74          return FALSE;
     75  if(time.wHour > 23) return FALSE;
     76  if(time.wMinute > 59) return FALSE;
     77  if(time.wSecond > 59) return FALSE;
     78  if(time.wMilliseconds > 999) return FALSE;
     79
     80  return TRUE;
     81}
     82
     83
     84void MONTHCAL_CopyTime(const SYSTEMTIME *from, SYSTEMTIME *to)
     85{
     86  to->wYear = from->wYear;
     87  to->wMonth = from->wMonth;
     88  to->wDayOfWeek = from->wDayOfWeek;
     89  to->wDay = from->wDay;
     90  to->wHour = from->wHour;
     91  to->wMinute = from->wMinute;
     92  to->wSecond = from->wSecond;
     93  to->wMilliseconds = from->wMilliseconds;
    7994}
    8095
     
    8398   Need to find out if we're on a DST place & adjust the clock accordingly.
    8499   Above function assumes we have a valid data.
    85    Valid for year>1752;  d <= 1 <= 31, 1 <= m <= 12.
    86    0=Monday.
     100   Valid for year>1752;  1 <= d <= 31, 1 <= m <= 12.
     101   0 = Monday.
    87102*/
    88103
    89 
    90 int MONTHCAL_CalculateDayOfWeek (DWORD day, DWORD month, DWORD year)
    91 
    92 {
    93  year -= month < 3;
    94  return (year + year/4 - year/100 + year/400 +
    95          DayOfWeekTable[month-1] + day - 1 ) % 7;
    96 }
    97 
    98 
    99 static int MONTHCAL_CalcDayFromPos (MONTHCAL_INFO *infoPtr, int x, int y)
    100 
    101 {
    102     int daypos,weekpos,retval,firstDay;
    103 
    104     daypos=(x - infoPtr->prevmonth.left) / infoPtr->textWidth ;
    105     weekpos=(y - infoPtr->days.bottom - infoPtr->rcClient.top) /
    106                      (infoPtr->textHeight*1.25);
    107         firstDay=MONTHCAL_CalculateDayOfWeek (1,infoPtr->currentMonth,infoPtr->currentYear);
    108     retval=daypos + 7*weekpos - firstDay;
    109         //TRACE ("%d %d %d\n",daypos,weekpos,retval);
    110         return retval;
    111 }
    112 
    113 
    114 static void MONTHCAL_CalcDayXY (MONTHCAL_INFO *infoPtr, int day, int month,
     104/* returns the day in the week(0 == sunday, 6 == saturday) */
     105/* day(1 == 1st, 2 == 2nd... etc), year is the  year value */
     106int MONTHCAL_CalculateDayOfWeek(DWORD day, DWORD month, DWORD year)
     107{
     108  year-=(month < 3);
     109
     110  return((year + year/4 - year/100 + year/400 +
     111         DayOfWeekTable[month-1] + day - 1 ) % 7);
     112}
     113
     114
     115static int MONTHCAL_CalcDayFromPos(MONTHCAL_INFO *infoPtr, int x, int y)
     116{
     117  int daypos, weekpos, retval, firstDay;
     118
     119  /* if the point is outside the x bounds of the window put
     120  it at the boundry */
     121  if(x > (infoPtr->width_increment * 7.0)) {
     122    x = infoPtr->rcClient.right - infoPtr->rcClient.left - infoPtr->left_offset;
     123  }
     124
     125  daypos = (x -(infoPtr->prevmonth.left + infoPtr->left_offset)) / infoPtr->width_increment;
     126  weekpos = (y - infoPtr->days.bottom - infoPtr->rcClient.top) / infoPtr->height_increment;
     127
     128  firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
     129  retval = daypos + (7 * weekpos) - firstDay;
     130  //TRACE("%d %d %d\n", daypos, weekpos, retval);
     131  return retval;
     132}
     133
     134/* day is the day of the month, 1 == 1st day of the month */
     135/* sets x and y to be the position of the day */
     136/* x == day, y == week where(0,0) == sunday, 1st week */
     137static void MONTHCAL_CalcDayXY(MONTHCAL_INFO *infoPtr, int day, int month,
    115138                                 int *x, int *y)
    116 
    117 {
    118   int firstDay,prevMonth;
    119 
    120   firstDay=MONTHCAL_CalculateDayOfWeek (1,infoPtr->currentMonth,infoPtr->currentYear);
    121 
    122   if (month==infoPtr->currentMonth) {
    123         *x=(day+firstDay) & 7;
    124         *y=(day+firstDay-*x) / 7;
    125                 return;
    126         }
    127   if (month < infoPtr->currentMonth) {
    128                 prevMonth=month - 1;
    129                 if (prevMonth==0) prevMonth=11;
    130         *x=(mdays[prevMonth]-firstDay) & 7;
    131                 *y=0;
    132         }
    133 
    134   *y=mdays[month] / 7;
    135   *x=(day+firstDay+mdays[month]) & 7;
    136 }
    137 
    138 
    139 static void MONTHCAL_CalcDayRect (MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
    140 {
    141   r->left   = infoPtr->prevmonth.left + x * infoPtr->textWidth;
    142   r->right  = r->left + infoPtr->textWidth;
    143   r->top    = infoPtr->rcClient.top + y * 1.25 * infoPtr->textHeight
    144                                    + infoPtr->days.bottom;
     139{
     140  int firstDay, prevMonth;
     141
     142  firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
     143
     144  if(month==infoPtr->currentMonth) {
     145    *x = (day + firstDay) % 7;
     146    *y = (day + firstDay - *x) / 7;
     147    return;
     148  }
     149  if(month < infoPtr->currentMonth) {
     150    prevMonth = month - 1;
     151    if(prevMonth==0)
     152       prevMonth = 12;
     153
     154    *x = (MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay) % 7;
     155    *y = 0;
     156    return;
     157  }
     158
     159  *y = MONTHCAL_MonthLength(month, infoPtr->currentYear - 1) / 7;
     160  *x = (day + firstDay + MONTHCAL_MonthLength(month,
     161       infoPtr->currentYear)) % 7;
     162}
     163
     164
     165/* x: column(day), y: row(week) */
     166static void MONTHCAL_CalcDayRect(MONTHCAL_INFO *infoPtr, RECT *r, int x, int y)
     167{
     168  r->left = infoPtr->prevmonth.left + x * infoPtr->width_increment + infoPtr->left_offset;
     169  r->right = r->left + infoPtr->width_increment;
     170  r->top = infoPtr->height_increment * y  + infoPtr->days.bottom + infoPtr->top_offset;
    145171  r->bottom = r->top + infoPtr->textHeight;
    146 
    147 }
    148 
    149 static void MONTHCAL_CalcPosFromDay (MONTHCAL_INFO *infoPtr,
    150                                             int day, int month, RECT *r)
    151 
    152 {
    153   int x,y;
    154 
    155   MONTHCAL_CalcDayXY (infoPtr, day, month, &x, &y);
    156   MONTHCAL_CalcDayRect (infoPtr, r, x, y);
    157 }
    158 
    159 
    160 
    161 
    162 static void MONTHCAL_CircleDay (HDC hdc, MONTHCAL_INFO *infoPtr, int i, int j)
    163 
    164 {
    165         HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB (255,0,0) );
    166     HPEN hOldPen2 = SelectObject( hdc, hRedPen );
    167         POINT points[7];
    168         int x,y;
     172}
     173
     174
     175/* sets the RECT struct r to the rectangle around the day and month */
     176/* day is the day value of the month(1 == 1st), month is the month */
     177/* value(january == 1, december == 12) */
     178static void MONTHCAL_CalcPosFromDay(MONTHCAL_INFO *infoPtr,
     179                                    int day, int month, RECT *r)
     180{
     181  int x, y;
     182
     183  MONTHCAL_CalcDayXY(infoPtr, day, month, &x, &y);
     184  MONTHCAL_CalcDayRect(infoPtr, r, x, y);
     185}
     186
     187
     188/* day is the day in the month(1 == 1st of the month) */
     189/* month is the month value(1 == january, 12 == december) */
     190static void MONTHCAL_CircleDay(HDC hdc, MONTHCAL_INFO *infoPtr, int day,
     191int month)
     192{
     193  HPEN hRedPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
     194  HPEN hOldPen2 = SelectObject(hdc, hRedPen);
     195  POINT points[13];
     196  int x, y;
     197  RECT day_rect;
    169198
    170199 /* use prevmonth to calculate position because it contains the extra width
     
    172201  */
    173202
    174         x=infoPtr->prevmonth.left + (i+0.5)*infoPtr->textWidth;
    175         y=infoPtr->rcClient.top + 1.25*(j+0.5)*infoPtr->textHeight + infoPtr->days.bottom;
    176         points[0].x = x;
    177         points[0].y = y-0.25*infoPtr->textHeight;
    178         points[1].x = x-1.0*infoPtr->textWidth;
    179         points[1].y = y;
    180         points[2].x = x;
    181         points[2].y = y+0.6*infoPtr->textHeight;
    182         points[3].x = x+0.5*infoPtr->textWidth;
    183         points[3].y = y;
    184         points[4].x = x+0.3*infoPtr->textWidth;
    185         points[4].y = y-0.5*infoPtr->textHeight;
    186         points[5].x = x-0.25*infoPtr->textWidth;
    187         points[5].y = y-0.5*infoPtr->textHeight;
    188         points[6].x = x-0.5*infoPtr->textWidth;
    189         points[6].y = y-0.45*infoPtr->textHeight;
    190 
    191         PolyBezier (hdc,points,4);
    192         PolyBezier (hdc,points+3,4);
    193     DeleteObject (hRedPen);
    194         SelectObject (hdc, hOldPen2);
    195 }
    196 
    197 
    198 
    199 
    200 
    201 static void MONTHCAL_DrawDay (HDC hdc, MONTHCAL_INFO *infoPtr,
     203  MONTHCAL_CalcPosFromDay(infoPtr, day, month, &day_rect);
     204
     205  x = day_rect.left;
     206  y = day_rect.top;
     207
     208  points[0].x = x;
     209  points[0].y = y - 1;
     210  points[1].x = x + 0.8 * infoPtr->width_increment;
     211  points[1].y = y - 1;
     212  points[2].x = x + 0.9 * infoPtr->width_increment;
     213  points[2].y = y;
     214  points[3].x = x + infoPtr->width_increment;
     215  points[3].y = y + 0.5 * infoPtr->textHeight;
     216
     217  points[4].x = x + infoPtr->width_increment;
     218  points[4].y = y + 0.9 * infoPtr->textHeight;
     219  points[5].x = x + 0.6 * infoPtr->width_increment;
     220  points[5].y = y + 0.9 * infoPtr->textHeight;
     221  points[6].x = x + 0.5 * infoPtr->width_increment;
     222  points[6].y = y + 0.9 * infoPtr->textHeight; /* bring the bottom up just
     223                                a hair to fit inside the day rectangle */
     224
     225  points[7].x = x + 0.2 * infoPtr->width_increment;
     226  points[7].y = y + 0.8 * infoPtr->textHeight;
     227  points[8].x = x + 0.1 * infoPtr->width_increment;
     228  points[8].y = y + 0.8 * infoPtr->textHeight;
     229  points[9].x = x;
     230  points[9].y = y + 0.5 * infoPtr->textHeight;
     231
     232  points[10].x = x + 0.1 * infoPtr->width_increment;
     233  points[10].y = y + 0.2 * infoPtr->textHeight;
     234  points[11].x = x + 0.2 * infoPtr->width_increment;
     235  points[11].y = y + 0.3 * infoPtr->textHeight;
     236  points[12].x = x + 0.5 * infoPtr->width_increment;
     237  points[12].y = y + 0.3 * infoPtr->textHeight;
     238
     239  PolyBezier(hdc, points, 13);
     240  DeleteObject(hRedPen);
     241  SelectObject(hdc, hOldPen2);
     242}
     243
     244
     245static void MONTHCAL_DrawDay(HDC hdc, MONTHCAL_INFO *infoPtr,
    202246                                                        int day, int month, int x, int y, int bold)
    203 
    204247{
    205248  char buf[10];
    206249  RECT r;
    207   static int haveBoldFont,haveSelectedDay=FALSE;
     250  static int haveBoldFont, haveSelectedDay = FALSE;
    208251  HBRUSH hbr;
    209   COLORREF oldCol,oldBk;
    210 
    211   sprintf (buf,"%d",day);
    212 
    213 
     252  HPEN hNewPen, hOldPen = 0;
     253  COLORREF oldCol = 0;
     254  COLORREF oldBk = 0;
     255
     256  sprintf(buf, "%d", day);
    214257
    215258/* No need to check styles: when selection is not valid, it is set to zero.
     
    217260 */
    218261
    219   MONTHCAL_CalcDayRect (infoPtr, &r, x, y);
    220 
    221   if ((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
    222       && (month==infoPtr->currentMonth)) {
    223                 HRGN hrgn;
    224                 RECT r2;
    225 
    226                 //TRACE ("%d %d %d\n",day,infoPtr->minSel.wDay,infoPtr->maxSel.wDay);
    227                 //TRACE ("%d %d %d %d\n", r.left, r.top, r.right, r.bottom);
    228                 oldCol=SetTextColor (hdc, infoPtr->monthbk);
    229                 oldBk=SetBkColor (hdc,infoPtr->trailingtxt);
    230                 hbr= GetSysColorBrush (COLOR_GRAYTEXT);
    231                 hrgn=CreateEllipticRgn (r.left,r.top, r.right,r.bottom);
    232                 FillRgn (hdc,hrgn,hbr);
    233 
    234                 r2.left   = r.left-0.25*infoPtr->textWidth;
    235                 r2.top    = r.top;
    236                 r2.right  = r.left+0.5*infoPtr->textWidth;
    237                 r2.bottom = r.bottom;
    238                 if (haveSelectedDay) FillRect (hdc,&r2,hbr);
    239                 haveSelectedDay=TRUE;
    240         } else {
    241                 haveSelectedDay=FALSE;
    242         }
    243 
    244 
    245 
    246 /* need to add some code for multiple selections */
    247 
    248   if ((bold) && (!haveBoldFont)) {
    249         SelectObject (hdc, infoPtr->hBoldFont);
    250                 haveBoldFont=TRUE;
    251         }
    252   if ((!bold) && (haveBoldFont)) {
    253         SelectObject (hdc, infoPtr->hFont);
    254                 haveBoldFont=FALSE;
    255         }
    256 
    257 
    258 
    259   DrawTextA ( hdc, buf, lstrlenA(buf), &r,
     262  MONTHCAL_CalcDayRect(infoPtr, &r, x, y);
     263
     264  if((day>=infoPtr->minSel.wDay) && (day<=infoPtr->maxSel.wDay)
     265       && (month==infoPtr->currentMonth)) {
     266    HRGN hrgn;
     267    RECT r2;
     268
     269    //TRACE("%d %d %d\n",day, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
     270    //TRACE("%d %d %d %d\n", r.left, r.top, r.right, r.bottom);
     271    oldCol = SetTextColor(hdc, infoPtr->monthbk);
     272    oldBk = SetBkColor(hdc, infoPtr->trailingtxt);
     273    hbr = GetSysColorBrush(COLOR_GRAYTEXT);
     274    hrgn = CreateEllipticRgn(r.left, r.top, r.right, r.bottom);
     275    FillRgn(hdc, hrgn, hbr);
     276
     277    /* FIXME: this may need to be changed now b/c of the other
     278        drawing changes 11/3/99 CMM */
     279    r2.left   = r.left - 0.25 * infoPtr->textWidth;
     280    r2.top    = r.top;
     281    r2.right  = r.left + 0.5 * infoPtr->textWidth;
     282    r2.bottom = r.bottom;
     283    if(haveSelectedDay) FillRect(hdc, &r2, hbr);
     284      haveSelectedDay = TRUE;
     285  } else {
     286    haveSelectedDay = FALSE;
     287  }
     288
     289  /* need to add some code for multiple selections */
     290
     291  if((bold) &&(!haveBoldFont)) {
     292    SelectObject(hdc, infoPtr->hBoldFont);
     293    haveBoldFont = TRUE;
     294  }
     295  if((!bold) &&(haveBoldFont)) {
     296    SelectObject(hdc, infoPtr->hFont);
     297    haveBoldFont = FALSE;
     298  }
     299
     300  if(haveSelectedDay) {
     301    SetTextColor(hdc, oldCol);
     302    SetBkColor(hdc, oldBk);
     303  }
     304
     305  DrawTextA(hdc, buf, lstrlenA(buf), &r,
    260306                         DT_CENTER | DT_VCENTER | DT_SINGLELINE );
    261   if (haveSelectedDay) {
    262                 SetTextColor(hdc, oldCol);
    263                 SetBkColor (hdc, oldBk);
    264         }
    265 
    266   if ((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth)) {
    267                 HPEN hNewPen, hOldPen;
    268 
    269                 hNewPen = CreatePen(PS_DOT, 0, GetSysColor(COLOR_WINDOWTEXT) );
    270                 hbr= GetSysColorBrush (COLOR_WINDOWTEXT);
    271                 hOldPen = SelectObject( hdc, hNewPen );
    272                 r.left+=2;
    273                 r.right-=2;
    274                 r.top-=1;
    275                 r.bottom+=1;
    276                 FrameRect (hdc, &r, hbr);
    277                 SelectObject( hdc, hOldPen );
     307
     308  /* draw a rectangle around the currently selected days text */
     309  if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth)) {
     310    hNewPen = CreatePen(PS_DOT, 0, GetSysColor(COLOR_WINDOWTEXT) );
     311    hbr = GetSysColorBrush(COLOR_WINDOWTEXT);
     312    FrameRect(hdc, &r, hbr);
     313    SelectObject(hdc, hOldPen);
    278314  }
    279315}
     
    281317
    282318/* CHECKME: For `todays date', do we need to check the locale?*/
    283 /* CHECKME: For `todays date', how do is Y2K handled?*/
    284 /* FIXME:  todays date circle */
    285 
    286 static void MONTHCAL_Refresh (HWND hwnd, HDC hdc)
    287 
    288 {
    289     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    290         RECT *rcClient=&infoPtr->rcClient;
    291         RECT *title=&infoPtr->title;
    292         RECT *prev=&infoPtr->titlebtnprev;
    293         RECT *next=&infoPtr->titlebtnnext;
    294         RECT *titlemonth=&infoPtr->titlemonth;
    295         RECT *titleyear=&infoPtr->titleyear;
    296         RECT *prevmonth=&infoPtr->prevmonth;
    297         RECT *nextmonth=&infoPtr->nextmonth;
    298         RECT *days=&infoPtr->days;
    299         RECT *weeknums=&infoPtr->weeknums;
    300         RECT *rtoday=&infoPtr->today;
    301     int i,j,m,mask,day,firstDay, weeknum,prevMonth;
    302     int textHeight,textWidth;
    303         SIZE size;
    304         HBRUSH hbr;
    305     HFONT currentFont;
    306         TEXTMETRICA tm;
    307 /*    LOGFONTA logFont; */
    308         char buf[20],*thisMonthtxt;
    309     COLORREF oldTextColor,oldBkColor;
    310     DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    311         BOOL prssed;
    312 
    313 
    314     oldTextColor = SetTextColor(hdc, GetSysColor( COLOR_WINDOWTEXT));
    315 
    316     currentFont = SelectObject (hdc, infoPtr->hFont);
    317 
    318         /* FIXME: need a way to determine current font, without setting it */
    319 /*
    320         if (infoPtr->hFont!=currentFont) {
    321         SelectObject (hdc, currentFont);
    322                 infoPtr->hFont=currentFont;
    323                 GetObjectA (currentFont, sizeof (LOGFONTA), &logFont);
    324         logFont.lfWeight=FW_BOLD;
    325         infoPtr->hBoldFont = CreateFontIndirectA (&logFont);
    326         }
    327 */
    328 
    329         GetTextMetricsA (hdc, &tm);
    330         infoPtr->textHeight=textHeight=tm.tmHeight + tm.tmExternalLeading;
    331     GetTextExtentPoint32A (hdc, "Sun",3, &size);
    332         infoPtr->textWidth=textWidth=size.cx+2;
    333 
    334     GetClientRect (hwnd, rcClient);
    335     hbr =  CreateSolidBrush (RGB(255,255,255));
    336     DrawEdge (hdc, rcClient, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
    337     FillRect (hdc, rcClient, hbr);
    338     DeleteObject (hbr);
    339 
    340 /* calculate whole client area & title area */
    341 
    342         infoPtr->rcClient.right=7*infoPtr->textWidth;
    343         if (dwStyle & MCS_WEEKNUMBERS)
    344           infoPtr->rcClient.right+=infoPtr->textWidth;
    345 
    346         title->top    = rcClient->top + 1;
    347         title->bottom = title->top + 2*textHeight + 4;
    348         title->left   = rcClient->left + 1;
    349         title->right  = rcClient->right - 1;
    350         infoPtr->rcClient.bottom=title->bottom + 6*textHeight;
    351 
    352 
    353 /* draw header */
    354 
    355     hbr =  CreateSolidBrush (infoPtr->titlebk);
    356     FillRect (hdc, title, hbr);
    357 
    358         prev->top                 = next->top        = title->top + 6;
    359         prev->bottom      = next->bottom     = title->top + 2*textHeight - 3;
    360         prev->right       = title->left  + 28;
    361         prev->left        = title->left  + 4;
    362         next->left        = title->right - 28;
    363         next->right       = title->right - 4;
    364         titlemonth->bottom= titleyear->bottom = prev->top + 2*textHeight - 3;
    365         titlemonth->top   = titleyear->top    = title->top + 6;
    366         titlemonth->left  = title->left;
    367         titlemonth->right = title->right;
    368         prssed=FALSE;
    369 
    370         if (!(infoPtr->status & MC_PREVPRESSED))
    371            DrawFrameControl(hdc, prev, DFC_SCROLL,
    372                         DFCS_SCROLLLEFT | (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
    373 
    374         if (!(infoPtr->status & MC_NEXTPRESSED))
    375         DrawFrameControl(hdc, next, DFC_SCROLL,
    376                 DFCS_SCROLLRIGHT | (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
    377 
    378     oldBkColor=SetBkColor (hdc,infoPtr->titlebk);
    379     SetTextColor(hdc, infoPtr->titletxt);
    380         SelectObject (hdc, infoPtr->hBoldFont);
    381 
    382         thisMonthtxt=monthtxt[infoPtr->currentMonth - 1];
    383         sprintf (buf,"%s %ld",thisMonthtxt,infoPtr->currentYear);
    384     DrawTextA ( hdc, buf, strlen(buf), titlemonth,
    385                         DT_CENTER | DT_VCENTER | DT_SINGLELINE );
    386         SelectObject (hdc, infoPtr->hFont);
    387 
    388  /* titlemonth left/right contained rect for whole titletxt ('June  1999')
     319static void MONTHCAL_Refresh(HWND hwnd, HDC hdc)
     320{
     321  MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
     322  RECT *rcClient=&infoPtr->rcClient;
     323  RECT *rcDraw=&infoPtr->rcDraw;
     324  RECT *title=&infoPtr->title;
     325  RECT *prev=&infoPtr->titlebtnprev;
     326  RECT *next=&infoPtr->titlebtnnext;
     327  RECT *titlemonth=&infoPtr->titlemonth;
     328  RECT *titleyear=&infoPtr->titleyear;
     329  RECT *prevmonth=&infoPtr->prevmonth;
     330  RECT *nextmonth=&infoPtr->nextmonth;
     331  RECT dayrect;
     332  RECT *days=&dayrect;
     333  RECT *weeknums=&infoPtr->weeknums;
     334  RECT *rtoday=&infoPtr->today;
     335  int i, j, m, mask, day, firstDay, weeknum, prevMonth;
     336  int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
     337  SIZE size;
     338  HBRUSH hbr;
     339  HFONT currentFont;
     340  /* LOGFONTA logFont; */
     341  char buf[20];
     342  const char *thisMonthtxt;
     343  COLORREF oldTextColor, oldBkColor;
     344  DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     345  BOOL prssed;
     346
     347  oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
     348
     349  /* draw control edge */
     350  hbr =  CreateSolidBrush(RGB(255, 255, 255));
     351  FillRect(hdc, rcClient, hbr);
     352  DrawEdge(hdc, rcClient, EDGE_SUNKEN, BF_RECT);
     353  DeleteObject(hbr);
     354  prssed = FALSE;
     355
     356  /* draw header */
     357  hbr =  CreateSolidBrush(infoPtr->titlebk);
     358  FillRect(hdc, title, hbr);
     359
     360  /* if the previous button is pressed draw it depressed */
     361  if((infoPtr->status & MC_PREVPRESSED))
     362      DrawFrameControl(hdc, prev, DFC_SCROLL,
     363           DFCS_SCROLLLEFT | DFCS_PUSHED |
     364        (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
     365  else /* if the previous button is pressed draw it depressed */
     366    DrawFrameControl(hdc, prev, DFC_SCROLL,
     367           DFCS_SCROLLLEFT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
     368
     369  /* if next button is depressed draw it depressed */
     370  if((infoPtr->status & MC_NEXTPRESSED))
     371    DrawFrameControl(hdc, next, DFC_SCROLL,
     372           DFCS_SCROLLRIGHT | DFCS_PUSHED |
     373        (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
     374  else /* if the next button is pressed draw it depressed */
     375    DrawFrameControl(hdc, next, DFC_SCROLL,
     376           DFCS_SCROLLRIGHT |(dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0));
     377
     378  oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
     379  SetTextColor(hdc, infoPtr->titletxt);
     380  currentFont = SelectObject(hdc, infoPtr->hBoldFont);
     381
     382  /* titlemonth->left and right are set in MONTHCAL_UpdateSize */
     383  titlemonth->left   = title->left;
     384  titlemonth->right  = title->right;
     385
     386  thisMonthtxt = monthtxt[infoPtr->currentMonth - 1];
     387  sprintf(buf, "%s %ld", thisMonthtxt, infoPtr->currentYear);
     388  DrawTextA(hdc, buf, strlen(buf), titlemonth,
     389                        DT_CENTER | DT_VCENTER | DT_SINGLELINE);
     390  SelectObject(hdc, infoPtr->hFont);
     391
     392/* titlemonth left/right contained rect for whole titletxt('June  1999')
    389393  * MCM_HitTestInfo wants month & year rects, so prepare these now.
    390   * (no, we can't draw them separately; the whole text is centered)
     394  *(no, we can't draw them separately; the whole text is centered)
    391395  */
    392 
    393     GetTextExtentPoint32A (hdc, buf,lstrlenA (buf), &size);
    394         titlemonth->left = title->right/2 - size.cx/2;
    395         titleyear->right = title->right/2 + size.cx/2;
    396     GetTextExtentPoint32A (hdc, thisMonthtxt,lstrlenA (thisMonthtxt), &size);
    397     titlemonth->right= titlemonth->left+size.cx;
    398     titleyear->right = titlemonth->right;
     396  GetTextExtentPoint32A(hdc, buf, lstrlenA(buf), &size);
     397  titlemonth->left = title->right / 2 - size.cx / 2;
     398  titleyear->right = title->right / 2 + size.cx / 2;
     399  GetTextExtentPoint32A(hdc, thisMonthtxt, lstrlenA(thisMonthtxt), &size);
     400  titlemonth->right = titlemonth->left + size.cx;
     401  titleyear->right = titlemonth->right;
     402
    399403
    400404/* draw line under day abbreviatons */
    401405
    402          if (dwStyle & MCS_WEEKNUMBERS)
    403                 MoveToEx (hdc, rcClient->left+textWidth+3,
    404                        title->bottom + textHeight + 2, NULL);
    405          else
    406                 MoveToEx (hdc, rcClient->left+3, title->bottom + textHeight + 2, NULL);
    407      LineTo   (hdc, rcClient->right-3, title->bottom + textHeight + 2);
     406   if(dwStyle & MCS_WEEKNUMBERS)
     407     MoveToEx(hdc, rcDraw->left + textWidth + 3, title->bottom + textHeight + 2, NULL);
     408   else
     409     MoveToEx(hdc, rcDraw->left + 3, title->bottom + textHeight + 2, NULL);
     410
     411  LineTo(hdc, rcDraw->right - 3, title->bottom + textHeight + 2);
    408412
    409413/* draw day abbreviations */
    410414
    411     SetBkColor (hdc, infoPtr->monthbk);
    412     SetTextColor(hdc, infoPtr->trailingtxt);
    413 
    414         days->left   = rcClient->left;
    415         if (dwStyle & MCS_WEEKNUMBERS) days->left+=textWidth;
    416     days->right  = days->left + textWidth;
    417     days->top    = title->bottom + 2;
    418     days->bottom = title->bottom + textHeight + 2;
    419         i=infoPtr->firstDay;
    420 
    421         for (j=0; j<7; j++) {
    422             DrawTextA ( hdc, daytxt[i], strlen(daytxt[i]), days,
     415  SetBkColor(hdc, infoPtr->monthbk);
     416  SetTextColor(hdc, infoPtr->trailingtxt);
     417
     418  /* copy this rect so we can change the values without changing */
     419  /* the original version */
     420  days->left = infoPtr->days.left;
     421  days->right = infoPtr->days.right;
     422  days->top = infoPtr->days.top;
     423  days->bottom = infoPtr->days.bottom;
     424
     425  i = infoPtr->firstDay;
     426
     427  for(j=0; j<7; j++) {
     428    DrawTextA(hdc, daytxt[i], strlen(daytxt[i]), days,
    423429                         DT_CENTER | DT_VCENTER | DT_SINGLELINE );
    424                         i++;
    425                         if (i>7) i-=7;
    426                         days->left+=textWidth;
    427                         days->right+=textWidth;
    428         }
    429 
    430         days->left   = rcClient->left + j;
    431         if (dwStyle & MCS_WEEKNUMBERS) days->left+=textWidth;
    432     days->right  = rcClient->left + (j+1)*textWidth-2;
     430    i = (i + 1) % 7;
     431    days->left+=infoPtr->width_increment;
     432    days->right+=infoPtr->width_increment;
     433  }
     434
     435  days->left = rcDraw->left + j;
     436  if(dwStyle & MCS_WEEKNUMBERS) days->left+=textWidth;
     437  /* FIXME: this may need to be changed now 11/10/99 CMM */
     438  days->right = rcDraw->left + (j+1) * textWidth - 2;
    433439
    434440/* draw day numbers; first, the previous month */
    435441
    436         prevmonth->left=0;
    437         if (dwStyle & MCS_WEEKNUMBERS) prevmonth->left=textWidth;
    438 
    439         firstDay=MONTHCAL_CalculateDayOfWeek (1,infoPtr->currentMonth,infoPtr->currentYear);
    440         prevMonth=infoPtr->currentMonth-1;
    441         if (prevMonth==0) prevMonth=11;
    442         day=mdays[prevMonth]-firstDay;
    443         mask=1<<(day-1);
    444 
    445         i=0;
    446         m=0;
    447         while (day<=mdays[prevMonth]) {
    448                         MONTHCAL_DrawDay (hdc, infoPtr, day, prevMonth, i, 0,
    449                                                 infoPtr->monthdayState[m] & mask);
    450                         mask<<=1;
    451                         day++;
    452                         i++;
    453         }
    454 
    455         prevmonth->right = prevmonth->left+i*textWidth;
    456         prevmonth->top   = days->bottom;
    457         prevmonth->bottom= prevmonth->top + textHeight;
     442  firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
     443
     444  prevMonth = infoPtr->currentMonth - 1;
     445  if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
     446    prevMonth = 12;    /* december(12) of the previous year */
     447
     448  day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) - firstDay;
     449  mask = 1<<(day-1);
     450
     451  i = 0;
     452  m = 0;
     453  while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
     454    MONTHCAL_DrawDay(hdc, infoPtr, day, prevMonth, i, 0,
     455          infoPtr->monthdayState[m] & mask);
     456    mask<<=1;
     457    day++;
     458    i++;
     459  }
     460
     461  prevmonth->left = 0;
     462  if(dwStyle & MCS_WEEKNUMBERS) prevmonth->left = textWidth;
     463  prevmonth->right  = prevmonth->left + i * textWidth;
     464  prevmonth->top    = days->bottom;
     465  prevmonth->bottom = prevmonth->top + textHeight;
    458466
    459467/* draw `current' month  */
    460468
    461         day=1;
    462         infoPtr->firstDayplace=i;
    463     SetTextColor(hdc, infoPtr->txt);
    464         m++;
    465         mask=1;
    466         while (i<7) {
    467                         MONTHCAL_DrawDay (hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
    468                                                 infoPtr->monthdayState[m] & mask);
    469                         if ((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
    470                 (day==infoPtr->todaysDate.wDay))
    471                                         MONTHCAL_CircleDay (hdc, infoPtr, i,j);
    472                         mask<<=1;
    473                         day++;
    474                         i++;
    475                 }
    476 
    477         j=1;
    478         i=0;
    479         while (day<=mdays[infoPtr->currentMonth]) {
    480                         MONTHCAL_DrawDay (hdc, infoPtr, day, infoPtr->currentMonth, i, j,
    481                                                 infoPtr->monthdayState[m] & mask);
    482                         if ((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
    483                 (day==infoPtr->todaysDate.wDay))
    484                                         MONTHCAL_CircleDay (hdc, infoPtr, i,j);
    485                         mask<<=1;
    486                         day++;
    487                         i++;
    488                         if (i>6) {
    489                                 i=0;
    490                                 j++;
    491                         }
    492         }
     469  day = 1; /* start at the beginning of the current month */
     470
     471  infoPtr->firstDayplace = i;
     472  SetTextColor(hdc, infoPtr->txt);
     473  m++;
     474  mask = 1;
     475
     476  /* draw the first week of the current month */
     477  while(i<7) {
     478    MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, 0,
     479        infoPtr->monthdayState[m] & mask);
     480
     481    if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
     482        (day==infoPtr->todaysDate.wDay) &&
     483        (infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
     484      MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
     485    }
     486
     487    mask<<=1;
     488    day++;
     489    i++;
     490  }
     491
     492  j = 1; /* move to the 2nd week of the current month */
     493  i = 0; /* move back to sunday */
     494  while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
     495    MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth, i, j,
     496          infoPtr->monthdayState[m] & mask);
     497
     498    if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
     499    (day==infoPtr->todaysDate.wDay) &&
     500    (infoPtr->currentYear == infoPtr->todaysDate.wYear))
     501      MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth);
     502
     503    mask<<=1;
     504    day++;
     505    i++;
     506    if(i>6) { /* past saturday, goto the next weeks sunday */
     507      i = 0;
     508      j++;
     509    }
     510  }
    493511
    494512/*  draw `next' month */
     
    499517 * this rect -- HitTest knows about this.*/
    500518
    501 
    502 
    503         nextmonth->left   = prevmonth->left+i*textWidth;
    504         nextmonth->right  = rcClient->right;
    505         nextmonth->top    = days->bottom+(j+1)*textHeight;
    506         nextmonth->bottom = nextmonth->top + textHeight;
    507 
    508         day=1;
    509         m++;
    510         mask=1;
    511     SetTextColor(hdc, infoPtr->trailingtxt);
    512         while ((i<7) && (j<6)) {
    513                         MONTHCAL_DrawDay (hdc, infoPtr, day, infoPtr->currentMonth+1, i, j,
    514                                                 infoPtr->monthdayState[m] & mask);
    515                         mask<<=1;
    516                         day++;
    517                         i++;
    518                         if (i==7) {
    519                                 i=0;
    520                                 j++;
    521                         }
    522         }
    523     SetTextColor(hdc, infoPtr->txt);
    524 
     519  nextmonth->left   = prevmonth->left + i * textWidth;
     520  nextmonth->right  = rcDraw->right;
     521  nextmonth->top    = days->bottom + (j+1) * textHeight;
     522  nextmonth->bottom = nextmonth->top + textHeight;
     523
     524  day = 1; /* start at the first day of the next month */
     525  m++;
     526  mask = 1;
     527
     528  SetTextColor(hdc, infoPtr->trailingtxt);
     529  while((i<7) &&(j<6)) {
     530    MONTHCAL_DrawDay(hdc, infoPtr, day, infoPtr->currentMonth + 1, i, j,
     531                infoPtr->monthdayState[m] & mask);
     532
     533    mask<<=1;
     534    day++;
     535    i++;
     536    if(i==7) { /* past saturday, go to next week's sunday */
     537      i = 0;
     538      j++;
     539    }
     540  }
     541  SetTextColor(hdc, infoPtr->txt);
    525542
    526543
    527544/* draw `today' date if style allows it, and draw a circle before today's
    528  * date if necessairy */
    529 
    530         if (!( dwStyle & MCS_NOTODAY))  {
    531         int offset=0;
    532         if (!( dwStyle & MCS_NOTODAYCIRCLE))  {
    533                         MONTHCAL_CircleDay (hdc, infoPtr, 0, 6);
    534                         offset+=textWidth;
    535                 }
    536 
    537                 MONTHCAL_CalcDayRect (infoPtr, rtoday, offset==textWidth, 6);
    538                 sprintf (buf,"Today: %d/%d/%d",infoPtr->todaysDate.wMonth,
    539                         infoPtr->todaysDate.wDay, infoPtr->todaysDate.wYear-1900);
    540                 rtoday->right  = rcClient->right;
    541         SelectObject (hdc, infoPtr->hBoldFont);
    542             DrawTextA ( hdc, buf, lstrlenA(buf), rtoday,
    543                          DT_LEFT | DT_VCENTER | DT_SINGLELINE );
    544         SelectObject (hdc, infoPtr->hFont);
    545         }
    546 
    547         if (dwStyle & MCS_WEEKNUMBERS)  {
    548                         /* display weeknumbers*/
    549 
    550                 weeknums->left   = 0;
    551                 weeknums->right  = textWidth;
    552                 weeknums->top    = days->bottom + 2;
    553                 weeknums->bottom = days->bottom + 2 + textHeight;
    554 
    555                 weeknum=0;
    556                 for (i=0; i<infoPtr->currentMonth-1; i++)
    557                         weeknum+=mdays[i];
    558 
    559                 weeknum/=7;
    560                 for (i=0; i<6; i++) {
    561                         sprintf (buf,"%d",weeknum+i);
    562                 DrawTextA ( hdc, buf, lstrlenA(buf), weeknums,
     545 * date if necessary */
     546
     547  if(!(dwStyle & MCS_NOTODAY))  {
     548    int offset = 0;
     549    if(!(dwStyle & MCS_NOTODAYCIRCLE))  {
     550      MONTHCAL_CircleDay(hdc, infoPtr, day, infoPtr->currentMonth + 1);
     551      offset+=textWidth;
     552    }
     553    MONTHCAL_CalcDayRect(infoPtr, rtoday, offset==textWidth, 6);
     554    sprintf(buf, "Today: %d/%d/%d", infoPtr->todaysDate.wMonth,
     555             infoPtr->todaysDate.wDay, infoPtr->todaysDate.wYear % 100);
     556    rtoday->right = rcDraw->right;
     557    SelectObject(hdc, infoPtr->hBoldFont);
     558    DrawTextA(hdc, buf, lstrlenA(buf), rtoday,
     559                         DT_LEFT | DT_VCENTER | DT_SINGLELINE);
     560    SelectObject(hdc, infoPtr->hFont);
     561  }
     562
     563  if(dwStyle & MCS_WEEKNUMBERS)  {
     564    /* display weeknumbers*/
     565    weeknums->left   = 0;
     566    weeknums->right  = textWidth;
     567    weeknums->top    = days->bottom + 2;
     568    weeknums->bottom = days->bottom + 2 + textHeight;
     569
     570    weeknum = 0;
     571    for(i=0; i<infoPtr->currentMonth-1; i++)
     572      weeknum+=MONTHCAL_MonthLength(i, infoPtr->currentYear);
     573
     574    weeknum/=7;
     575    for(i=0; i<6; i++) {
     576      sprintf(buf, "%d", weeknum + i);
     577      DrawTextA(hdc, buf, lstrlenA(buf), weeknums,
    563578                         DT_CENTER | DT_BOTTOM | DT_SINGLELINE );
    564                         weeknums->top+=textHeight*1.25;
    565                         weeknums->bottom+=textHeight*1.25;
    566                 }
    567 
    568             MoveToEx (hdc, weeknums->right, days->bottom+5 , NULL);
    569         LineTo   (hdc, weeknums->right, weeknums->bottom-1.25*textHeight-5);
    570 
    571         }
    572 
    573                                  /* currentFont was font at entering Refresh */
    574 
    575     SetBkColor (hdc, oldBkColor);
    576     SelectObject (hdc, currentFont);
    577     SetTextColor (hdc, oldTextColor);
    578 }
    579 
    580 
    581 static LRESULT
    582 MONTHCAL_GetMinReqRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
    583 
    584 {
    585     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    586         LPRECT lpRect=(LPRECT) lParam;
    587         //TRACE ("%x %lx\n",wParam,lParam);
     579      weeknums->top+=textHeight * 1.25;
     580      weeknums->bottom+=textHeight * 1.25;
     581    }
     582
     583    MoveToEx(hdc, weeknums->right, days->bottom + 5 , NULL);
     584    LineTo(hdc, weeknums->right, weeknums->bottom - 1.25 * textHeight - 5);
     585
     586  }
     587
     588  /* currentFont was font at entering Refresh */
     589
     590  SetBkColor(hdc, oldBkColor);
     591  SelectObject(hdc, currentFont);
     592  SetTextColor(hdc, oldTextColor);
     593}
     594
     595
     596static LRESULT
     597MONTHCAL_GetMinReqRect(HWND hwnd, WPARAM wParam, LPARAM lParam)
     598{
     599  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     600  LPRECT lpRect = (LPRECT) lParam;
     601  //TRACE("%x %lx\n", wParam, lParam);
    588602
    589603  /* validate parameters */
    590604
    591     if ( (infoPtr==NULL) || (lpRect == NULL) ) return FALSE;
    592 
    593         lpRect->left=infoPtr->rcClient.left;
    594         lpRect->right=infoPtr->rcClient.right;
    595         lpRect->top=infoPtr->rcClient.top;
    596         lpRect->bottom=infoPtr->rcClient.bottom;
    597         return TRUE;
    598 }
    599 
    600 static LRESULT
    601 MONTHCAL_GetColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
    602 
    603 {
    604     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    605 
    606         //TRACE ("%x %lx\n",wParam,lParam);
    607 
    608         switch ((int)wParam) {
    609                 case MCSC_BACKGROUND:
    610                         return infoPtr->bk;
    611                 case MCSC_TEXT:
    612                         return infoPtr->txt;
    613                 case MCSC_TITLEBK:
    614                         return infoPtr->titlebk;
    615                 case MCSC_TITLETEXT:
    616                         return infoPtr->titletxt;
    617                 case MCSC_MONTHBK:
    618                         return infoPtr->monthbk;
    619                 case MCSC_TRAILINGTEXT:
    620                         return infoPtr->trailingtxt;
    621         }
    622 
    623  return -1;
    624 }
    625 
    626 static LRESULT
    627 MONTHCAL_SetColor (HWND hwnd, WPARAM wParam, LPARAM lParam)
    628 
    629 {
    630     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    631         int prev=-1;
    632 
    633         //TRACE ("%x %lx\n",wParam,lParam);
    634 
    635         switch ((int)wParam) {
    636                 case MCSC_BACKGROUND:
    637                         prev=infoPtr->bk;
    638                         infoPtr->bk=(COLORREF) lParam;
    639                         break;
    640                 case MCSC_TEXT:
    641                         prev=infoPtr->txt;
    642                         infoPtr->txt=(COLORREF) lParam;
    643                         break;
    644                 case MCSC_TITLEBK:
    645                         prev=infoPtr->titlebk;
    646                         infoPtr->titlebk=(COLORREF) lParam;
    647                         break;
    648                 case MCSC_TITLETEXT:
    649                         prev=infoPtr->titletxt;
    650                         infoPtr->titletxt=(COLORREF) lParam;
    651                         break;
    652                 case MCSC_MONTHBK:
    653                         prev=infoPtr->monthbk;
    654                         infoPtr->monthbk=(COLORREF) lParam;
    655                         break;
    656                 case MCSC_TRAILINGTEXT:
    657                         prev=infoPtr->trailingtxt;
    658                         infoPtr->trailingtxt=(COLORREF) lParam;
    659                         break;
    660         }
    661 
    662  return prev;
    663 }
    664 
    665 static LRESULT
    666 MONTHCAL_GetMonthDelta (HWND hwnd, WPARAM wParam, LPARAM lParam)
    667 
    668 {
    669     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    670 
    671         //TRACE ("%x %lx\n",wParam,lParam);
    672 
    673         if (infoPtr->delta) return infoPtr->delta;
    674         else return infoPtr->visible;
    675 }
    676 
    677 static LRESULT
    678 MONTHCAL_SetMonthDelta (HWND hwnd, WPARAM wParam, LPARAM lParam)
    679 
    680 {
    681     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    682     int prev=infoPtr->delta;
    683 
    684         //TRACE ("%x %lx\n",wParam,lParam);
    685 
    686         infoPtr->delta=(int) wParam;
    687         return prev;
    688 }
    689 
    690 
    691 
    692 static LRESULT
    693 MONTHCAL_GetFirstDayOfWeek (HWND hwnd, WPARAM wParam, LPARAM lParam)
    694 {
    695     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    696 
    697         return infoPtr->firstDay;
    698 }
    699 
     605  if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
     606
     607  lpRect->left = infoPtr->rcClient.left;
     608  lpRect->right = infoPtr->rcClient.right;
     609  lpRect->top = infoPtr->rcClient.top;
     610  lpRect->bottom = infoPtr->rcClient.bottom;
     611  return TRUE;
     612}
     613
     614static LRESULT
     615MONTHCAL_GetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
     616{
     617  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     618
     619  //TRACE("%x %lx\n", wParam, lParam);
     620
     621  switch((int)wParam) {
     622    case MCSC_BACKGROUND:
     623      return infoPtr->bk;
     624    case MCSC_TEXT:
     625      return infoPtr->txt;
     626    case MCSC_TITLEBK:
     627      return infoPtr->titlebk;
     628    case MCSC_TITLETEXT:
     629      return infoPtr->titletxt;
     630    case MCSC_MONTHBK:
     631      return infoPtr->monthbk;
     632    case MCSC_TRAILINGTEXT:
     633      return infoPtr->trailingtxt;
     634  }
     635
     636  return -1;
     637}
     638
     639static LRESULT
     640MONTHCAL_SetColor(HWND hwnd, WPARAM wParam, LPARAM lParam)
     641{
     642  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     643  int prev = -1;
     644
     645  //TRACE("%x %lx\n", wParam, lParam);
     646
     647  switch((int)wParam) {
     648    case MCSC_BACKGROUND:
     649      prev = infoPtr->bk;
     650      infoPtr->bk = (COLORREF)lParam;
     651      break;
     652    case MCSC_TEXT:
     653      prev = infoPtr->txt;
     654      infoPtr->txt = (COLORREF)lParam;
     655      break;
     656    case MCSC_TITLEBK:
     657      prev = infoPtr->titlebk;
     658      infoPtr->titlebk = (COLORREF)lParam;
     659      break;
     660    case MCSC_TITLETEXT:
     661      prev=infoPtr->titletxt;
     662      infoPtr->titletxt = (COLORREF)lParam;
     663      break;
     664    case MCSC_MONTHBK:
     665      prev = infoPtr->monthbk;
     666      infoPtr->monthbk = (COLORREF)lParam;
     667      break;
     668    case MCSC_TRAILINGTEXT:
     669      prev = infoPtr->trailingtxt;
     670      infoPtr->trailingtxt = (COLORREF)lParam;
     671      break;
     672  }
     673
     674  return prev;
     675}
     676
     677static LRESULT
     678MONTHCAL_GetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
     679{
     680  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     681
     682  //TRACE("%x %lx\n", wParam, lParam);
     683
     684  if(infoPtr->delta)
     685    return infoPtr->delta;
     686  else
     687    return infoPtr->visible;
     688}
     689
     690static LRESULT
     691MONTHCAL_SetMonthDelta(HWND hwnd, WPARAM wParam, LPARAM lParam)
     692{
     693  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     694  int prev = infoPtr->delta;
     695
     696  //TRACE("%x %lx\n", wParam, lParam);
     697
     698  infoPtr->delta = (int)wParam;
     699  return prev;
     700}
     701
     702
     703static LRESULT
     704MONTHCAL_GetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
     705{
     706  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     707
     708  return infoPtr->firstDay;
     709}
     710
     711
     712/* sets the first day of the week that will appear in the control */
     713/* 0 == Monday, 6 == Sunday */
     714/* FIXME: this needs to be implemented properly in MONTHCAL_Refresh() */
    700715/* FIXME: we need more error checking here */
    701 
    702 static LRESULT
    703 MONTHCAL_SetFirstDayOfWeek (HWND hwnd, WPARAM wParam, LPARAM lParam)
    704 
    705 {
    706     MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    707     int prev=infoPtr->firstDay;
    708         char buf[40];
    709         int day;
    710 
    711         //TRACE ("%x %lx\n",wParam,lParam);
    712 
    713         if ((lParam>=0) && (lParam<7)) {
    714                         infoPtr->firstDay=(int) lParam;
    715                         GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
     716static LRESULT
     717MONTHCAL_SetFirstDayOfWeek(HWND hwnd, WPARAM wParam, LPARAM lParam)
     718{
     719  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     720  int prev = infoPtr->firstDay;
     721  char buf[40];
     722  int day;
     723
     724  //TRACE("%x %lx\n", wParam, lParam);
     725
     726  if((lParam >= 0) && (lParam < 7)) {
     727    infoPtr->firstDay = (int)lParam;
     728    GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
    716729                buf, sizeof(buf));
    717                 //TRACE ("%s %d\n",buf,strlen(buf));
    718             if ((sscanf(buf,"%d",&day)==1) && (infoPtr->firstDay!=day))
    719                                 infoPtr->firstDay|=HIWORD(TRUE);
    720 
    721         }
    722     return prev;
    723 }
    724 
     730    //TRACE("%s %d\n", buf, strlen(buf));
     731    if((sscanf(buf, "%d", &day) == 1) &&(infoPtr->firstDay != day))
     732      infoPtr->firstDay = day;
     733  }
     734  return prev;
     735}
    725736
    726737
    727738/* FIXME: fill this in */
    728 
    729 static LRESULT
    730 MONTHCAL_GetMonthRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    731 {
    732   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    733 
    734   //TRACE ("%x %lx\n",wParam,lParam);
     739static LRESULT
     740MONTHCAL_GetMonthRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
     741{
     742  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     743
     744  //TRACE("%x %lx\n", wParam, lParam);
     745  //FIXME("stub\n");
    735746
    736747  return infoPtr->monthRange;
    737748}
    738749
    739 static LRESULT
    740 MONTHCAL_GetMaxTodayWidth (HWND hwnd)
    741 
    742 {
    743  MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    744 
    745  return (infoPtr->today.right-infoPtr->today.left);
    746 }
     750
     751static LRESULT
     752MONTHCAL_GetMaxTodayWidth(HWND hwnd)
     753{
     754  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     755
     756  return(infoPtr->today.right - infoPtr->today.left);
     757}
     758
    747759
    748760/* FIXME: are validated times taken from current date/time or simply
     
    753765
    754766static LRESULT
    755 MONTHCAL_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    756 {
    757   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
     767MONTHCAL_SetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
     768{
     769  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
    758770  SYSTEMTIME lprgSysTimeArray[1];
    759771  int prev;
    760772
    761   //TRACE ("%x %lx\n",wParam,lParam);
    762 
    763   if (wParam & GDTR_MAX) {
    764                 if (MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
    765                         MONTHCAL_CopyTime (&lprgSysTimeArray[1],&infoPtr->maxDate);
    766                         infoPtr->rangeValid|=GDTR_MAX;
    767                 } else  {
    768                         GetSystemTime (&infoPtr->todaysDate);
    769                         MONTHCAL_CopyTime (&infoPtr->todaysDate,&infoPtr->maxDate);
    770                         }
    771                 }
    772   if (wParam & GDTR_MIN) {
    773                 if (MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
    774                         MONTHCAL_CopyTime (&lprgSysTimeArray[0],&infoPtr->maxDate);
    775                         infoPtr->rangeValid|=GDTR_MIN;
    776                 } else {
    777                         GetSystemTime (&infoPtr->todaysDate);
    778                         MONTHCAL_CopyTime (&infoPtr->todaysDate,&infoPtr->maxDate);
    779                         }
    780             }
    781 
    782   prev=infoPtr->monthRange;
    783   infoPtr->monthRange=infoPtr->maxDate.wMonth-infoPtr->minDate.wMonth;
    784   if (infoPtr->monthRange!=prev)
    785         COMCTL32_ReAlloc (infoPtr->monthdayState,
    786                 infoPtr->monthRange*sizeof(MONTHDAYSTATE));
     773  //TRACE("%x %lx\n", wParam, lParam);
     774
     775  if(wParam & GDTR_MAX) {
     776    if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
     777      MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
     778      infoPtr->rangeValid|=GDTR_MAX;
     779    } else  {
     780      GetSystemTime(&infoPtr->todaysDate);
     781      MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
     782    }
     783  }
     784  if(wParam & GDTR_MIN) {
     785    if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
     786      MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->maxDate);
     787      infoPtr->rangeValid|=GDTR_MIN;
     788    } else {
     789      GetSystemTime(&infoPtr->todaysDate);
     790      MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
     791    }
     792  }
     793
     794  prev = infoPtr->monthRange;
     795  infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;
     796
     797  if(infoPtr->monthRange!=prev) {
     798        COMCTL32_ReAlloc(infoPtr->monthdayState,
     799                infoPtr->monthRange * sizeof(MONTHDAYSTATE));
     800  }
    787801
    788802  return 1;
     
    796810
    797811static LRESULT
    798 MONTHCAL_GetRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    799 {
    800   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    801   SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam;
     812MONTHCAL_GetRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
     813{
     814  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     815  SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *)lParam;
    802816
    803817  /* validate parameters */
    804818
    805   if ( (infoPtr==NULL) || (lprgSysTimeArray==NULL) ) return FALSE;
    806 
    807   MONTHCAL_CopyTime (&infoPtr->maxDate,&lprgSysTimeArray[1]);
    808   MONTHCAL_CopyTime (&infoPtr->minDate,&lprgSysTimeArray[0]);
     819  if((infoPtr==NULL) || (lprgSysTimeArray==NULL)) return FALSE;
     820
     821  MONTHCAL_CopyTime(&infoPtr->maxDate, &lprgSysTimeArray[1]);
     822  MONTHCAL_CopyTime(&infoPtr->minDate, &lprgSysTimeArray[0]);
    809823
    810824  return infoPtr->rangeValid;
    811825}
    812826
    813 static LRESULT
    814 MONTHCAL_SetDayState (HWND hwnd, WPARAM wParam, LPARAM lParam)
    815 
    816 {
    817   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    818   int i,iMonths=(int) wParam;
    819   MONTHDAYSTATE *dayStates=(LPMONTHDAYSTATE) lParam;
    820 
    821   //TRACE ("%x %lx\n",wParam,lParam);
    822   if (iMonths!=infoPtr->monthRange) return 0;
    823 
    824   for (i=0; i<iMonths; i++)
    825                 infoPtr->monthdayState[i]=dayStates[i];
     827
     828static LRESULT
     829MONTHCAL_SetDayState(HWND hwnd, WPARAM wParam, LPARAM lParam)
     830
     831{
     832  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     833  int i, iMonths = (int)wParam;
     834  MONTHDAYSTATE *dayStates = (LPMONTHDAYSTATE)lParam;
     835
     836  //TRACE("%x %lx\n", wParam, lParam);
     837  if(iMonths!=infoPtr->monthRange) return 0;
     838
     839  for(i=0; i<iMonths; i++)
     840    infoPtr->monthdayState[i] = dayStates[i];
    826841  return 1;
    827842}
    828843
    829 static LRESULT
    830 MONTHCAL_GetCurSel (HWND hwnd, WPARAM wParam, LPARAM lParam)
    831 {
    832   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    833   SYSTEMTIME *lpSel=(SYSTEMTIME *) lParam;
    834 
    835   //TRACE ("%x %lx\n",wParam,lParam);
    836   if ( (infoPtr==NULL) || (lpSel==NULL) ) return FALSE;
    837   if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
    838 
    839   MONTHCAL_CopyTime (&infoPtr->minSel,lpSel);
     844
     845static LRESULT
     846MONTHCAL_GetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
     847{
     848  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     849  SYSTEMTIME *lpSel = (SYSTEMTIME *) lParam;
     850
     851  //TRACE("%x %lx\n", wParam, lParam);
     852  if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
     853  if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
     854
     855  MONTHCAL_CopyTime(&infoPtr->minSel, lpSel);
    840856  return TRUE;
    841857}
     
    844860/* FIXME: if the specified date is not visible, make it visible */
    845861/* FIXME: redraw? */
    846 
    847 static LRESULT
    848 MONTHCAL_SetCurSel (HWND hwnd, WPARAM wParam, LPARAM lParam)
    849 {
    850   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    851   SYSTEMTIME *lpSel=(SYSTEMTIME *) lParam;
    852 
    853   //TRACE ("%x %lx\n",wParam,lParam);
    854   if ( (infoPtr==NULL) || (lpSel==NULL) ) return FALSE;
    855   if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
    856 
    857   //TRACE ("%d %d\n",lpSel->wMonth,lpSel->wDay);
    858 
    859   MONTHCAL_CopyTime (lpSel,&infoPtr->minSel);
    860   MONTHCAL_CopyTime (lpSel,&infoPtr->maxSel);
     862static LRESULT
     863MONTHCAL_SetCurSel(HWND hwnd, WPARAM wParam, LPARAM lParam)
     864{
     865  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     866  SYSTEMTIME *lpSel = (SYSTEMTIME *)lParam;
     867
     868  //TRACE("%x %lx\n", wParam, lParam);
     869  if((infoPtr==NULL) ||(lpSel==NULL)) return FALSE;
     870  if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT) return FALSE;
     871
     872  //TRACE("%d %d\n", lpSel->wMonth, lpSel->wDay);
     873
     874  MONTHCAL_CopyTime(lpSel, &infoPtr->minSel);
     875  MONTHCAL_CopyTime(lpSel, &infoPtr->maxSel);
    861876
    862877  return TRUE;
    863878}
    864879
    865 static LRESULT
    866 MONTHCAL_GetMaxSelCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
    867 {
    868   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    869 
    870   //TRACE ("%x %lx\n",wParam,lParam);
     880
     881static LRESULT
     882MONTHCAL_GetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
     883{
     884  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     885
     886  //TRACE("%x %lx\n", wParam, lParam);
    871887  return infoPtr->maxSelCount;
    872888}
    873889
    874 static LRESULT
    875 MONTHCAL_SetMaxSelCount (HWND hwnd, WPARAM wParam, LPARAM lParam)
    876 {
    877   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    878 
    879   //TRACE ("%x %lx\n",wParam,lParam);
    880   if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
    881                 infoPtr->maxSelCount=wParam;
     890
     891static LRESULT
     892MONTHCAL_SetMaxSelCount(HWND hwnd, WPARAM wParam, LPARAM lParam)
     893{
     894  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     895
     896  //TRACE("%x %lx\n", wParam, lParam);
     897  if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
     898    infoPtr->maxSelCount = wParam;
    882899  }
    883900
     
    887904
    888905static LRESULT
    889 MONTHCAL_GetSelRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    890 {
    891   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    892   SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam;
    893 
    894   //TRACE ("%x %lx\n",wParam,lParam);
     906MONTHCAL_GetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
     907{
     908  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     909  SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
     910
     911  //TRACE("%x %lx\n", wParam, lParam);
    895912
    896913  /* validate parameters */
    897914
    898   if ( (infoPtr==NULL) || (lprgSysTimeArray==NULL) ) return FALSE;
    899 
    900   if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
    901                 MONTHCAL_CopyTime (&infoPtr->maxSel,&lprgSysTimeArray[1]);
    902         MONTHCAL_CopyTime (&infoPtr->minSel,&lprgSysTimeArray[0]);
    903                 //TRACE ("[min,max]=[%d %d]\n",infoPtr->minSel.wDay,infoPtr->maxSel.wDay);
    904         return TRUE;
     915  if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
     916
     917  if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)
     918  {
     919    MONTHCAL_CopyTime(&infoPtr->maxSel, &lprgSysTimeArray[1]);
     920    MONTHCAL_CopyTime(&infoPtr->minSel, &lprgSysTimeArray[0]);
     921    //TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
     922    return TRUE;
    905923  }
    906924
     
    908926}
    909927
    910 static LRESULT
    911 MONTHCAL_SetSelRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    912 {
    913   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    914   SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *) lParam;
    915 
    916   //TRACE ("%x %lx\n",wParam,lParam);
     928
     929static LRESULT
     930MONTHCAL_SetSelRange(HWND hwnd, WPARAM wParam, LPARAM lParam)
     931{
     932  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     933  SYSTEMTIME *lprgSysTimeArray = (SYSTEMTIME *) lParam;
     934
     935  //TRACE("%x %lx\n", wParam, lParam);
    917936
    918937  /* validate parameters */
    919938
    920   if ( (infoPtr==NULL) || (lprgSysTimeArray==NULL) ) return FALSE;
    921 
    922   if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
    923                 MONTHCAL_CopyTime (&lprgSysTimeArray[1],&infoPtr->maxSel);
    924         MONTHCAL_CopyTime (&lprgSysTimeArray[0],&infoPtr->minSel);
    925                 //TRACE ("[min,max]=[%d %d]\n",infoPtr->minSel.wDay,infoPtr->maxSel.wDay);
    926         return TRUE;
     939  if((infoPtr==NULL) ||(lprgSysTimeArray==NULL)) return FALSE;
     940
     941  if(GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)
     942  {
     943    MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxSel);
     944    MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minSel);
     945    //TRACE("[min,max]=[%d %d]\n", infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
     946    return TRUE;
    927947  }
    928948
     
    931951
    932952
    933 
    934 
    935 static LRESULT
    936 MONTHCAL_GetToday (HWND hwnd, WPARAM wParam, LPARAM lParam)
    937 {
    938   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    939   SYSTEMTIME *lpToday=(SYSTEMTIME *) lParam;
    940 
    941   //TRACE ("%x %lx\n",wParam,lParam);
     953static LRESULT
     954MONTHCAL_GetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
     955{
     956  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     957  SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
     958
     959  //TRACE("%x %lx\n", wParam, lParam);
    942960
    943961  /* validate parameters */
    944962
    945   if ( (infoPtr==NULL) || (lpToday==NULL) ) return FALSE;
    946   MONTHCAL_CopyTime (&infoPtr->todaysDate,lpToday);
     963  if((infoPtr==NULL) || (lpToday==NULL)) return FALSE;
     964  MONTHCAL_CopyTime(&infoPtr->todaysDate, lpToday);
    947965  return TRUE;
    948966}
     
    950968
    951969static LRESULT
    952 MONTHCAL_SetToday (HWND hwnd, WPARAM wParam, LPARAM lParam)
    953 {
    954   MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    955   SYSTEMTIME *lpToday=(SYSTEMTIME *) lParam;
    956 
    957   //TRACE ("%x %lx\n",wParam,lParam);
     970MONTHCAL_SetToday(HWND hwnd, WPARAM wParam, LPARAM lParam)
     971{
     972  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     973  SYSTEMTIME *lpToday = (SYSTEMTIME *) lParam;
     974
     975  //TRACE("%x %lx\n", wParam, lParam);
    958976
    959977  /* validate parameters */
    960978
    961   if ( (infoPtr==NULL) || (lpToday==NULL) ) return FALSE;
    962   MONTHCAL_CopyTime (lpToday, &infoPtr->todaysDate);
     979  if((infoPtr==NULL) ||(lpToday==NULL)) return FALSE;
     980  MONTHCAL_CopyTime(lpToday, &infoPtr->todaysDate);
    963981  return TRUE;
    964982}
    965983
    966984
    967 
    968 
    969 static LRESULT
    970 MONTHCAL_HitTest (HWND hwnd, LPARAM lParam)
    971 {
    972  MONTHCAL_INFO *infoPtr=MONTHCAL_GetInfoPtr(hwnd);
    973  PMCHITTESTINFO lpht=(PMCHITTESTINFO) lParam;
     985static LRESULT
     986MONTHCAL_HitTest(HWND hwnd, LPARAM lParam)
     987{
     988 MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     989 PMCHITTESTINFO lpht = (PMCHITTESTINFO)lParam;
    974990 UINT x,y;
    975991 DWORD retval;
    976992
    977  x=lpht->pt.x;
    978  y=lpht->pt.y;
    979  retval=MCHT_NOWHERE;
    980 
    981 
    982         /* are we in the header? */
    983 
    984  if (PtInRect (&infoPtr->title, lpht->pt)) {
    985 
    986                 if (PtInRect (&infoPtr->titlebtnprev, lpht->pt)) {
    987                         retval=MCHT_TITLEBTNPREV;
    988                         goto done;
    989                 }
    990                 if (PtInRect (&infoPtr->titlebtnnext, lpht->pt)) {
    991                         retval=MCHT_TITLEBTNNEXT;
    992                         goto done;
    993                 }
    994                 if (PtInRect (&infoPtr->titlemonth, lpht->pt)) {
    995                         retval=MCHT_TITLEMONTH;
    996                         goto done;
    997                 }
    998                 if (PtInRect (&infoPtr->titleyear, lpht->pt)) {
    999                         retval=MCHT_TITLEYEAR;
    1000                         goto done;
    1001                 }
    1002                 retval=MCHT_TITLE;
    1003                 goto done;
    1004         }
    1005 
    1006  if (PtInRect (&infoPtr->days, lpht->pt)) {
    1007                 retval=MCHT_CALENDARDAY;  /* FIXME: find out which day we're on */
    1008                 goto done;
    1009         }
    1010  if (PtInRect (&infoPtr->weeknums, lpht->pt)) {
    1011                 retval=MCHT_CALENDARWEEKNUM;/* FIXME: find out which day we're on */
    1012                 goto done;
    1013         }
    1014  if (PtInRect (&infoPtr->prevmonth, lpht->pt)) {
    1015                 retval=MCHT_CALENDARDATEPREV;
    1016                 goto done;
    1017         }
    1018  if (PtInRect (&infoPtr->nextmonth, lpht->pt) ||
    1019     ((x>infoPtr->nextmonth.left) && (x<infoPtr->nextmonth.right) &&
    1020      (y>infoPtr->nextmonth.bottom) && (y<infoPtr->today.top ))) {
    1021                 retval=MCHT_CALENDARDATENEXT;
    1022                 goto done;
    1023         }
    1024 
    1025 
    1026  if (PtInRect (&infoPtr->today, lpht->pt)) {
    1027                 retval=MCHT_TODAYLINK;
    1028                 goto done;
    1029         }
     993 x = lpht->pt.x;
     994 y = lpht->pt.y;
     995 retval = MCHT_NOWHERE;
     996
     997
     998  /* are we in the header? */
     999
     1000  if(PtInRect(&infoPtr->title, lpht->pt)) {
     1001    if(PtInRect(&infoPtr->titlebtnprev, lpht->pt)) {
     1002      retval = MCHT_TITLEBTNPREV;
     1003      goto done;
     1004    }
     1005    if(PtInRect(&infoPtr->titlebtnnext, lpht->pt)) {
     1006      retval = MCHT_TITLEBTNNEXT;
     1007      goto done;
     1008    }
     1009    if(PtInRect(&infoPtr->titlemonth, lpht->pt)) {
     1010      retval = MCHT_TITLEMONTH;
     1011      goto done;
     1012    }
     1013    if(PtInRect(&infoPtr->titleyear, lpht->pt)) {
     1014      retval = MCHT_TITLEYEAR;
     1015      goto done;
     1016    }
     1017
     1018    retval = MCHT_TITLE;
     1019    goto done;
     1020  }
     1021
     1022  if(PtInRect(&infoPtr->days, lpht->pt)) {
     1023    retval = MCHT_CALENDARDAY;  /* FIXME: find out which day we're on */
     1024    goto done;
     1025  }
     1026  if(PtInRect(&infoPtr->weeknums, lpht->pt)) {
     1027    retval = MCHT_CALENDARWEEKNUM; /* FIXME: find out which day we're on */
     1028    goto done;
     1029  }
     1030  if(PtInRect(&infoPtr->prevmonth, lpht->pt)) {
     1031    retval = MCHT_CALENDARDATEPREV;
     1032    goto done;
     1033  }
     1034
     1035  if(PtInRect(&infoPtr->nextmonth, lpht->pt) ||
     1036 ((x>infoPtr->nextmonth.left) &&(x<infoPtr->nextmonth.right) &&
     1037  (y>infoPtr->nextmonth.bottom) &&(y<infoPtr->today.top ))) {
     1038    retval = MCHT_CALENDARDATENEXT;
     1039    goto done;
     1040  }
     1041
     1042  if(PtInRect(&infoPtr->today, lpht->pt)) {
     1043    retval = MCHT_TODAYLINK;
     1044    goto done;
     1045  }
    10301046
    10311047/* MCHT_CALENDARDATE determination: since the next & previous month have
    1032  * been handled already (MCHT_CALENDARDATEPREV/NEXT), we only have to check
     1048 * been handled already(MCHT_CALENDARDATEPREV/NEXT), we only have to check
    10331049 * whether we're in the calendar area. infoPtr->prevMonth.left handles the
    10341050 * MCS_WEEKNUMBERS style nicely.
     
    10361052
    10371053
    1038  //TRACE ("%d %d [%d %d %d %d] [%d %d %d %d]\n",x,y,
     1054 //TRACE("%d %d [%d %d %d %d] [%d %d %d %d]\n", x, y,
    10391055 //       infoPtr->prevmonth.left, infoPtr->prevmonth.right,
    10401056 //       infoPtr->prevmonth.top, infoPtr->prevmonth.bottom,
    10411057 //       infoPtr->nextmonth.left, infoPtr->nextmonth.right,
    10421058 //       infoPtr->nextmonth.top, infoPtr->nextmonth.bottom);
    1043 
    1044  if ((x>infoPtr->prevmonth.left) && (x<infoPtr->nextmonth.right) &&
    1045          (y>infoPtr->prevmonth.top) && (y<infoPtr->nextmonth.bottom))  {
    1046                 lpht->st.wYear=infoPtr->currentYear;
    1047                 lpht->st.wMonth=infoPtr->currentMonth;
    1048 
    1049                 lpht->st.wDay=MONTHCAL_CalcDayFromPos (infoPtr,x,y);
    1050 
    1051                 //TRACE ("day hit: %d\n",lpht->st.wDay);
    1052                 retval=MCHT_CALENDARDATE;
    1053                 goto done;
    1054 
    1055         }
    1056 
    1057         /* Hit nothing special? What's left must be background :-) */
    1058 
    1059   retval=MCHT_CALENDARBK;
     1059  if((x>infoPtr->prevmonth.left) &&(x<infoPtr->nextmonth.right) &&
     1060   (y>infoPtr->prevmonth.top) &&(y<infoPtr->nextmonth.bottom))  {
     1061    lpht->st.wYear = infoPtr->currentYear;
     1062    lpht->st.wMonth = infoPtr->currentMonth;
     1063
     1064    lpht->st.wDay = MONTHCAL_CalcDayFromPos(infoPtr, x, y);
     1065
     1066    //TRACE("day hit: %d\n", lpht->st.wDay);
     1067    retval = MCHT_CALENDARDATE;
     1068    goto done;
     1069
     1070  }
     1071
     1072  /* Hit nothing special? What's left must be background :-) */
     1073
     1074  retval = MCHT_CALENDARBK;
    10601075 done:
    1061   lpht->uHit=retval;
     1076  lpht->uHit = retval;
    10621077  return retval;
    10631078}
    10641079
    10651080
    1066 
    1067 static void MONTHCAL_GoToNextMonth (HWND hwnd,  MONTHCAL_INFO *infoPtr)
    1068 {
    1069     DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    1070 
    1071         //TRACE ("\n");
    1072 
    1073         infoPtr->currentMonth++;
    1074         if (infoPtr->currentMonth>12) {
    1075                 infoPtr->currentYear++;
    1076                 infoPtr->currentMonth=1;
    1077         }
    1078 
    1079         if (dwStyle & MCS_DAYSTATE) {
    1080                 NMDAYSTATE nmds;
    1081                 int i;
    1082 
    1083         nmds.nmhdr.hwndFrom = hwnd;
    1084                 nmds.nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
    1085                 nmds.nmhdr.code     = MCN_GETDAYSTATE;
    1086                 nmds.cDayState          = infoPtr->monthRange;
    1087                 nmds.prgDayState        = COMCTL32_Alloc
    1088                                  (infoPtr->monthRange*sizeof(MONTHDAYSTATE));
    1089 
    1090                 SendMessageA (GetParent (hwnd), WM_NOTIFY,
    1091                                   (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
    1092                 for (i=0; i<infoPtr->monthRange; i++)
    1093                 infoPtr->monthdayState[i]=nmds.prgDayState[i];
    1094         }
    1095 
    1096 }
    1097 
    1098 
    1099 static void MONTHCAL_GoToPrevMonth (HWND hwnd,  MONTHCAL_INFO *infoPtr)
    1100 {
    1101     DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    1102 
    1103         //TRACE ("\n");
    1104 
    1105         infoPtr->currentMonth--;
    1106         if (infoPtr->currentMonth<1) {
    1107                 infoPtr->currentYear--;
    1108                 infoPtr->currentMonth=12;
    1109         }
    1110 
    1111         if (dwStyle & MCS_DAYSTATE) {
    1112                 NMDAYSTATE nmds;
    1113                 int i;
    1114 
    1115         nmds.nmhdr.hwndFrom = hwnd;
    1116                 nmds.nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
    1117                 nmds.nmhdr.code     = MCN_GETDAYSTATE;
    1118                 nmds.cDayState          = infoPtr->monthRange;
    1119                 nmds.prgDayState        = COMCTL32_Alloc
    1120                                  (infoPtr->monthRange*sizeof(MONTHDAYSTATE));
    1121 
    1122                 SendMessageA (GetParent (hwnd), WM_NOTIFY,
    1123                                  (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
    1124                 for (i=0; i<infoPtr->monthRange; i++)
    1125                 infoPtr->monthdayState[i]=nmds.prgDayState[i];
    1126         }
    1127 }
    1128 
    1129 
    1130 static LRESULT
    1131 MONTHCAL_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1132 
    1133 {
    1134     MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr (hwnd);
    1135         MCHITTESTINFO ht;
    1136         HDC hdc;
    1137         DWORD hit;
    1138         HMENU hMenu;
    1139         HWND retval;
    1140 
    1141 
    1142         //TRACE ("%x %lx\n",wParam,lParam);
    1143 
    1144     ht.pt.x = (INT)LOWORD(lParam);
    1145     ht.pt.y = (INT)HIWORD(lParam);
    1146     hit=MONTHCAL_HitTest (hwnd, (LPARAM) &ht);
    1147 
    1148     hdc=GetDC (hwnd);
    1149 
    1150         if (hit & MCHT_NEXT){
    1151                 MONTHCAL_GoToNextMonth (hwnd, infoPtr);
    1152                 infoPtr->status=MC_NEXTPRESSED;
    1153                 SetTimer (hwnd, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY,0);
    1154         }
    1155         if (hit & MCHT_PREV) {
    1156                 MONTHCAL_GoToPrevMonth (hwnd, infoPtr);
    1157                 infoPtr->status=MC_PREVPRESSED;
    1158                 SetTimer (hwnd, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY,0);
    1159         }
    1160 
    1161         if (hit == MCHT_TITLEMONTH) {
     1081static void MONTHCAL_GoToNextMonth(HWND hwnd, MONTHCAL_INFO *infoPtr)
     1082{
     1083  DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     1084
     1085  //TRACE("MONTHCAL_GoToNextMonth\n");
     1086
     1087  infoPtr->currentMonth++;
     1088  if(infoPtr->currentMonth > 12) {
     1089    infoPtr->currentYear++;
     1090    infoPtr->currentMonth = 1;
     1091  }
     1092
     1093  if(dwStyle & MCS_DAYSTATE) {
     1094    NMDAYSTATE nmds;
     1095    int i;
     1096
     1097    nmds.nmhdr.hwndFrom = hwnd;
     1098    nmds.nmhdr.idFrom   = GetWindowLongA(hwnd, GWL_ID);
     1099    nmds.nmhdr.code     = MCN_GETDAYSTATE;
     1100    nmds.cDayState      = infoPtr->monthRange;
     1101    nmds.prgDayState    = COMCTL32_Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
     1102
     1103    SendMessageA(GetParent(hwnd), WM_NOTIFY,
     1104    (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
     1105    for(i=0; i<infoPtr->monthRange; i++)
     1106      infoPtr->monthdayState[i] = nmds.prgDayState[i];
     1107  }
     1108}
     1109
     1110
     1111static void MONTHCAL_GoToPrevMonth(HWND hwnd,  MONTHCAL_INFO *infoPtr)
     1112{
     1113  DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     1114
     1115  //TRACE("MONTHCAL_GoToPrevMonth\n");
     1116
     1117  infoPtr->currentMonth--;
     1118  if(infoPtr->currentMonth < 1) {
     1119    infoPtr->currentYear--;
     1120    infoPtr->currentMonth = 12;
     1121  }
     1122
     1123  if(dwStyle & MCS_DAYSTATE) {
     1124    NMDAYSTATE nmds;
     1125    int i;
     1126
     1127    nmds.nmhdr.hwndFrom = hwnd;
     1128    nmds.nmhdr.idFrom   = GetWindowLongA(hwnd, GWL_ID);
     1129    nmds.nmhdr.code     = MCN_GETDAYSTATE;
     1130    nmds.cDayState      = infoPtr->monthRange;
     1131    nmds.prgDayState    = COMCTL32_Alloc
     1132                        (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
     1133
     1134    SendMessageA(GetParent(hwnd), WM_NOTIFY,
     1135        (WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
     1136    for(i=0; i<infoPtr->monthRange; i++)
     1137       infoPtr->monthdayState[i] = nmds.prgDayState[i];
     1138  }
     1139}
     1140
     1141
     1142static LRESULT
     1143MONTHCAL_LButtonDown(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1144{
     1145  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1146  MCHITTESTINFO ht;
     1147  HDC hdc;
     1148  DWORD hit;
     1149  HMENU hMenu;
     1150  HWND retval;
     1151  BOOL redraw = FALSE;
     1152
     1153
     1154  //TRACE("%x %lx\n", wParam, lParam);
     1155
     1156  ht.pt.x = (INT)LOWORD(lParam);
     1157  ht.pt.y = (INT)HIWORD(lParam);
     1158  hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
     1159
     1160  /* FIXME: these flags should be checked by */
     1161  /*((hit & MCHT_XXX) == MCHT_XXX) b/c some of the flags are */
     1162  /* multi-bit */
     1163  if(hit & MCHT_NEXT) {
     1164    redraw = TRUE;
     1165    MONTHCAL_GoToNextMonth(hwnd, infoPtr);
     1166    infoPtr->status = MC_NEXTPRESSED;
     1167    SetTimer(hwnd, MC_NEXTMONTHTIMER, MC_NEXTMONTHDELAY, 0);
     1168  }
     1169  if(hit & MCHT_PREV) {
     1170    redraw = TRUE;
     1171    MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
     1172    infoPtr->status = MC_PREVPRESSED;
     1173    SetTimer(hwnd, MC_PREVMONTHTIMER, MC_NEXTMONTHDELAY, 0);
     1174  }
     1175
     1176  if(hit == MCHT_TITLEMONTH) {
    11621177/*
    1163                 HRSRC hrsrc = FindResourceA( COMCTL32_hModule, MAKEINTRESOURCEA(IDD_MCMONTHMENU), RT_MENUA );
    1164         if (!hrsrc) {
    1165                         TRACE ("returning zero\n");
    1166                         return 0;
    1167                 }
    1168                 TRACE ("resource is:%x\n",hrsrc);
    1169         hMenu=LoadMenuIndirectA( (LPCVOID)LoadResource( COMCTL32_hModule, hrsrc ));
    1170 
    1171                 TRACE ("menu is:%x\n",hMenu);
     1178    HRSRC hrsrc = FindResourceA( COMCTL32_hModule, MAKEINTRESOURCEA(IDD_MCMONTHMENU), RT_MENUA );
     1179    if(!hrsrc) {
     1180      TRACE("returning zero\n");
     1181      return 0;
     1182    }
     1183    TRACE("resource is:%x\n",hrsrc);
     1184    hMenu = LoadMenuIndirectA((LPCVOID)LoadResource( COMCTL32_hModule, hrsrc ));
     1185
     1186    TRACE("menu is:%x\n",hMenu);
    11721187*/
    11731188
    1174                 hMenu=CreateMenu ();
    1175         AppendMenuA (hMenu,MF_STRING,IDM_JAN,"January");
    1176         AppendMenuA (hMenu,MF_STRING,IDM_FEB,"February");
    1177         AppendMenuA (hMenu,MF_STRING,IDM_MAR,"March");
    1178 
    1179                 retval=CreateWindowA (POPUPMENU_CLASS_ATOM, NULL,
    1180                         WS_CHILD | WS_VISIBLE,
    1181                         0,0,100,220,
    1182                         hwnd, hMenu, GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
    1183                 //TRACE ("hwnd returned:%x\n",retval);
    1184 
    1185         }
    1186         if (hit == MCHT_TITLEYEAR) {
    1187                         //FIXME ("create updown for yearselection\n");
    1188         }
    1189         if (hit == MCHT_TODAYLINK) {
    1190                         //FIXME ("set currentday\n");
    1191         }
    1192         if (hit == MCHT_CALENDARDATE) {
    1193                         SYSTEMTIME selArray[2];
    1194                         NMSELCHANGE nmsc;
    1195 
    1196                         //TRACE ("\n");
    1197                     nmsc.nmhdr.hwndFrom = hwnd;
    1198                 nmsc.nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
    1199                 nmsc.nmhdr.code     = MCN_SELCHANGE;
    1200                         MONTHCAL_CopyTime (&nmsc.stSelStart, &infoPtr->minSel);
    1201                         MONTHCAL_CopyTime (&nmsc.stSelEnd, &infoPtr->maxSel);
    1202 
    1203                 SendMessageA (GetParent (hwnd), WM_NOTIFY,
    1204                                    (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
    1205 
    1206                         MONTHCAL_CopyTime (&ht.st, &selArray[0]);
    1207                         MONTHCAL_CopyTime (&ht.st, &selArray[1]);
    1208                         MONTHCAL_SetSelRange (hwnd,0,(LPARAM) &selArray);
    1209 
    1210                         infoPtr->firstSelDay=ht.st.wDay;
    1211                         infoPtr->curSelDay=ht.st.wDay;
    1212                         infoPtr->status=MC_SEL_LBUTDOWN;
    1213         }
    1214 
    1215         MONTHCAL_Refresh (hwnd,hdc);
    1216         ReleaseDC (hwnd,hdc);
    1217         return 0;
    1218 }
    1219 
    1220 static LRESULT
    1221 MONTHCAL_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1222 
    1223 {
    1224     MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr (hwnd);
    1225         NMSELCHANGE nmsc;
    1226     NMHDR nmhdr;
    1227         HDC hdc;
    1228 
    1229         //TRACE ("\n");
    1230 
    1231         if (infoPtr->status & MC_NEXTPRESSED)
    1232                         KillTimer (hwnd, MC_NEXTMONTHTIMER);
    1233         if (infoPtr->status & MC_PREVPRESSED)
    1234                         KillTimer (hwnd, MC_PREVMONTHTIMER);
    1235         infoPtr->status=MC_SEL_LBUTUP;
    1236         infoPtr->curSelDay=0;
    1237 
    1238     nmhdr.hwndFrom = hwnd;
    1239     nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
    1240     nmhdr.code     = NM_RELEASEDCAPTURE;
    1241         //TRACE ("Sent notification from %x to %x\n", hwnd, GetParent (hwnd));
    1242 
    1243     SendMessageA (GetParent (hwnd), WM_NOTIFY,
    1244                                    (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
    1245 
     1189    hMenu = CreateMenu();
     1190    AppendMenuA(hMenu, MF_STRING,IDM_JAN, "January");
     1191    AppendMenuA(hMenu, MF_STRING,IDM_FEB, "February");
     1192    AppendMenuA(hMenu, MF_STRING,IDM_MAR, "March");
     1193
     1194    retval = CreateWindowA(POPUPMENU_CLASS_ATOM, NULL,
     1195              WS_CHILD | WS_VISIBLE, 0, 0 ,100 , 220,
     1196              hwnd, hMenu, GetWindowLongA(hwnd, GWL_HINSTANCE), NULL);
     1197    //TRACE("hwnd returned:%x\n", retval);
     1198
     1199  }
     1200  if(hit == MCHT_TITLEYEAR) {
     1201    //FIXME("create updown for yearselection\n");
     1202  }
     1203  if(hit == MCHT_TODAYLINK) {
     1204    //FIXME("set currentday\n");
     1205  }
     1206  if(hit == MCHT_CALENDARDATE) {
     1207    SYSTEMTIME selArray[2];
     1208    NMSELCHANGE nmsc;
     1209
     1210    //TRACE("\n");
    12461211    nmsc.nmhdr.hwndFrom = hwnd;
    1247     nmsc.nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
    1248     nmsc.nmhdr.code     = MCN_SELECT;
    1249         MONTHCAL_CopyTime (&nmsc.stSelStart, &infoPtr->minSel);
    1250         MONTHCAL_CopyTime (&nmsc.stSelEnd, &infoPtr->maxSel);
    1251 
    1252     SendMessageA (GetParent (hwnd), WM_NOTIFY,
    1253                                    (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
    1254 
    1255     hdc=GetDC (hwnd);
    1256     MONTHCAL_Refresh (hwnd,hdc);
    1257     ReleaseDC (hwnd,hdc);
    1258 
    1259         return 0;
    1260 }
    1261 
    1262 static LRESULT
    1263 MONTHCAL_Timer (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1264 
    1265 {
    1266     MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr (hwnd);
    1267     HDC hdc;
    1268 
    1269     //TRACE(" %d\n",wParam);
    1270     if (!infoPtr) return FALSE;
    1271 
    1272     hdc=GetDC (hwnd);
    1273     switch (wParam) {
    1274         case MC_NEXTMONTHTIMER:
    1275                 MONTHCAL_GoToNextMonth (hwnd, infoPtr);
    1276                 break;
    1277         case MC_PREVMONTHTIMER:
    1278                 MONTHCAL_GoToPrevMonth (hwnd, infoPtr);
    1279                 break;
    1280     //default:
    1281         //ERR("got unknown timer\n");
    1282         }
    1283 
    1284     MONTHCAL_Refresh (hwnd,hdc);
    1285     ReleaseDC (hwnd,hdc);
     1212    nmsc.nmhdr.idFrom   = GetWindowLongA(hwnd, GWL_ID);
     1213    nmsc.nmhdr.code     = MCN_SELCHANGE;
     1214    MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
     1215    MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
     1216
     1217    SendMessageA(GetParent(hwnd), WM_NOTIFY,
     1218           (WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
     1219
     1220    MONTHCAL_CopyTime(&ht.st, &selArray[0]);
     1221    MONTHCAL_CopyTime(&ht.st, &selArray[1]);
     1222    MONTHCAL_SetSelRange(hwnd,0,(LPARAM) &selArray);
     1223
     1224    /* redraw if the selected day changed */
     1225    if(infoPtr->curSelDay != ht.st.wDay) {
     1226      redraw = TRUE;
     1227    }
     1228
     1229    infoPtr->firstSelDay = ht.st.wDay;
     1230    infoPtr->curSelDay = ht.st.wDay;
     1231    infoPtr->status = MC_SEL_LBUTDOWN;
     1232  }
     1233
     1234  /* redraw only if the control changed */
     1235  if(redraw) {
     1236    hdc = GetDC(hwnd);
     1237          MONTHCAL_Refresh(hwnd, hdc);
     1238    ReleaseDC(hwnd, hdc);
     1239  }
     1240
     1241  return 0;
     1242}
     1243
     1244
     1245static LRESULT
     1246MONTHCAL_LButtonUp(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1247{
     1248  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1249  NMSELCHANGE nmsc;
     1250  NMHDR nmhdr;
     1251  HDC hdc;
     1252  BOOL redraw = FALSE;
     1253
     1254  //TRACE("\n");
     1255
     1256  if(infoPtr->status & MC_NEXTPRESSED) {
     1257    KillTimer(hwnd, MC_NEXTMONTHTIMER);
     1258    redraw = TRUE;
     1259  }
     1260  if(infoPtr->status & MC_PREVPRESSED) {
     1261    KillTimer(hwnd, MC_PREVMONTHTIMER);
     1262    redraw = TRUE;
     1263  }
     1264
     1265  infoPtr->status = MC_SEL_LBUTUP;
     1266
     1267  nmhdr.hwndFrom = hwnd;
     1268  nmhdr.idFrom   = GetWindowLongA( hwnd, GWL_ID);
     1269  nmhdr.code     = NM_RELEASEDCAPTURE;
     1270  //TRACE("Sent notification from %x to %x\n", hwnd, GetParent(hwnd));
     1271
     1272  SendMessageA(GetParent(hwnd), WM_NOTIFY,
     1273                                (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
     1274
     1275  nmsc.nmhdr.hwndFrom = hwnd;
     1276  nmsc.nmhdr.idFrom   = GetWindowLongA(hwnd, GWL_ID);
     1277  nmsc.nmhdr.code     = MCN_SELECT;
     1278  MONTHCAL_CopyTime(&nmsc.stSelStart, &infoPtr->minSel);
     1279  MONTHCAL_CopyTime(&nmsc.stSelEnd, &infoPtr->maxSel);
     1280
     1281  SendMessageA(GetParent(hwnd), WM_NOTIFY,
     1282           (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
     1283
     1284  /* redraw if necessary */
     1285  if(redraw) {
     1286    hdc = GetDC(hwnd);
     1287    MONTHCAL_Refresh(hwnd, hdc);
     1288    ReleaseDC(hwnd, hdc);
     1289  }
     1290
     1291  return 0;
     1292}
     1293
     1294
     1295static LRESULT
     1296MONTHCAL_Timer(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1297{
     1298  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1299  HDC hdc;
     1300  BOOL redraw = FALSE;
     1301
     1302  //TRACE(" %d\n", wParam);
     1303  if(!infoPtr) return 0;
     1304
     1305  switch(wParam) {
     1306  case MC_NEXTMONTHTIMER:
     1307    redraw = TRUE;
     1308    MONTHCAL_GoToNextMonth(hwnd, infoPtr);
     1309    break;
     1310  case MC_PREVMONTHTIMER:
     1311    redraw = TRUE;
     1312    MONTHCAL_GoToPrevMonth(hwnd, infoPtr);
     1313    break;
     1314  //default:
     1315  //  ERR("got unknown timer\n");
     1316  }
     1317
     1318  /* redraw only if necessary */
     1319  if(redraw) {
     1320    hdc = GetDC(hwnd);
     1321    MONTHCAL_Refresh(hwnd, hdc);
     1322    ReleaseDC(hwnd, hdc);
     1323  }
     1324
     1325  return 0;
     1326}
     1327
     1328
     1329static LRESULT
     1330MONTHCAL_MouseMove(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1331{
     1332  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1333  MCHITTESTINFO ht;
     1334  HDC hdc;
     1335  int oldselday, selday, hit;
     1336  RECT r;
     1337
     1338  if(!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
     1339
     1340  ht.pt.x = LOWORD(lParam);
     1341  ht.pt.y = HIWORD(lParam);
     1342
     1343  hit = MONTHCAL_HitTest(hwnd, (LPARAM)&ht);
     1344
     1345  /* not on the calendar date numbers? bail out */
     1346  //TRACE("hit:%x\n",hit);
     1347  if((hit & MCHT_CALENDARDATE) != MCHT_CALENDARDATE) return 0;
     1348
     1349  selday = ht.st.wDay;
     1350  oldselday = infoPtr->curSelDay;
     1351  infoPtr->curSelDay = selday;
     1352  MONTHCAL_CalcPosFromDay(infoPtr, selday, ht.st. wMonth, &r);
     1353
     1354  if(GetWindowLongA(hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
     1355    SYSTEMTIME selArray[2];
     1356    int i;
     1357
     1358    MONTHCAL_GetSelRange(hwnd, 0, (LPARAM)&selArray);
     1359    i = 0;
     1360    if(infoPtr->firstSelDay==selArray[0].wDay) i=1;
     1361    //TRACE("oldRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
     1362    if(infoPtr->firstSelDay==selArray[1].wDay) {
     1363      /* 1st time we get here: selArray[0]=selArray[1])  */
     1364      /* if we're still at the first selected date, return */
     1365      if(infoPtr->firstSelDay==selday) goto done;
     1366      if(selday<infoPtr->firstSelDay) i = 0;
     1367    }
     1368
     1369    if(abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
     1370      if(selday>infoPtr->firstSelDay)
     1371        selday = infoPtr->firstSelDay + infoPtr->maxSelCount;
     1372      else
     1373        selday = infoPtr->firstSelDay - infoPtr->maxSelCount;
     1374    }
     1375
     1376    if(selArray[i].wDay!=selday) {
     1377      //TRACE("newRange:%d %d %d %d\n", infoPtr->firstSelDay, selArray[0].wDay, selArray[1].wDay, i);
     1378
     1379      selArray[i].wDay = selday;
     1380
     1381      if(selArray[0].wDay>selArray[1].wDay) {
     1382        DWORD tempday;
     1383        tempday = selArray[1].wDay;
     1384        selArray[1].wDay = selArray[0].wDay;
     1385        selArray[0].wDay = tempday;
     1386      }
     1387
     1388      MONTHCAL_SetSelRange(hwnd, 0, (LPARAM)&selArray);
     1389    }
     1390  }
     1391
     1392done:
     1393
     1394  /* only redraw if the currently selected day changed */
     1395  if(oldselday != infoPtr->curSelDay) {
     1396    hdc = GetDC(hwnd);
     1397    MONTHCAL_Refresh(hwnd, hdc);
     1398    ReleaseDC(hwnd, hdc);
     1399  }
     1400
     1401  return 0;
     1402}
     1403
     1404
     1405static LRESULT
     1406MONTHCAL_Paint(HWND hwnd, WPARAM wParam)
     1407{
     1408  HDC hdc;
     1409  PAINTSTRUCT ps;
     1410
     1411  hdc = (wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam);
     1412  MONTHCAL_Refresh(hwnd, hdc);
     1413  if(!wParam) EndPaint(hwnd, &ps);
     1414  return 0;
     1415}
     1416
     1417
     1418static LRESULT
     1419MONTHCAL_KillFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1420{
     1421  HDC hdc;
     1422
     1423  //TRACE("\n");
     1424
     1425  hdc = GetDC(hwnd);
     1426  MONTHCAL_Refresh(hwnd, hdc);
     1427  ReleaseDC(hwnd, hdc);
     1428  InvalidateRect(hwnd, NULL, TRUE);
     1429
     1430  return 0;
     1431}
     1432
     1433
     1434static LRESULT
     1435MONTHCAL_SetFocus(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1436{
     1437  HDC hdc;
     1438
     1439  //TRACE("\n");
     1440
     1441  hdc = GetDC(hwnd);
     1442  MONTHCAL_Refresh(hwnd, hdc);
     1443  ReleaseDC(hwnd, hdc);
     1444
     1445  return 0;
     1446}
     1447
     1448/* sets the size information */
     1449static void MONTHCAL_UpdateSize(HWND hwnd)
     1450{
     1451  HDC hdc = GetDC(hwnd);
     1452  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1453  RECT *rcClient=&infoPtr->rcClient;
     1454  RECT *rcDraw=&infoPtr->rcDraw;
     1455  RECT *title=&infoPtr->title;
     1456  RECT *prev=&infoPtr->titlebtnprev;
     1457  RECT *next=&infoPtr->titlebtnnext;
     1458  RECT *titlemonth=&infoPtr->titlemonth;
     1459  RECT *titleyear=&infoPtr->titleyear;
     1460  RECT *days=&infoPtr->days;
     1461  SIZE size;
     1462  TEXTMETRICA tm;
     1463  DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
     1464  HFONT currentFont;
     1465
     1466  currentFont = SelectObject(hdc, infoPtr->hFont);
     1467
     1468  /* FIXME: need a way to determine current font, without setting it */
     1469  /*
     1470  if(infoPtr->hFont!=currentFont) {
     1471    SelectObject(hdc, currentFont);
     1472    infoPtr->hFont=currentFont;
     1473    GetObjectA(currentFont, sizeof(LOGFONTA), &logFont);
     1474    logFont.lfWeight=FW_BOLD;
     1475    infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
     1476  }
     1477  */
     1478
     1479  /* get the height and width of each day's text */
     1480  GetTextMetricsA(hdc, &tm);
     1481  infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading;
     1482  GetTextExtentPoint32A(hdc, "Sun", 3, &size);
     1483  infoPtr->textWidth = size.cx + 2;
     1484
     1485  /* retrieve the controls client rectangle info infoPtr->rcClient */
     1486  GetClientRect(hwnd, rcClient);
     1487
     1488  if(dwStyle & MCS_WEEKNUMBERS)
     1489    infoPtr->rcClient.right+=infoPtr->textWidth;
     1490
     1491  /* rcDraw is the rectangle the control is drawn in */
     1492  rcDraw->left = rcClient->left;
     1493  rcDraw->right = rcClient->right;
     1494  rcDraw->top = rcClient->top;
     1495  rcDraw->bottom = rcClient->bottom;
     1496
     1497  /* use DrawEdge to adjust the size of rcClient such that we */
     1498  /* do not overwrite the border when drawing the control */
     1499  DrawEdge((HDC)NULL, rcDraw, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
     1500
     1501
     1502  /* this is correct, the control does NOT expand vertically */
     1503  /* like it does horizontally */
     1504  /* make sure we don't move the controls bottom out of the client */
     1505  /* area */
     1506  if((rcDraw->top + 8 * infoPtr->textHeight + 5) < rcDraw->bottom) {
     1507    rcDraw->bottom = rcDraw->top + 8 * infoPtr->textHeight + 5;
     1508  }
     1509
     1510  /* calculate title area */
     1511  title->top    = rcClient->top + 1;
     1512  title->bottom = title->top + 2 * infoPtr->textHeight + 4;
     1513  title->left   = rcClient->left + 1;
     1514  title->right  = rcClient->right - 1;
     1515
     1516  /* recalculate the height and width increments and offsets */
     1517  infoPtr->width_increment = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) / 7.0;
     1518  infoPtr->height_increment = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) / 7.0;
     1519  infoPtr->left_offset = (infoPtr->rcDraw.right - infoPtr->rcDraw.left) - (infoPtr->width_increment * 7.0);
     1520  infoPtr->top_offset = (infoPtr->rcDraw.bottom - infoPtr->rcDraw.top) - (infoPtr->height_increment * 7.0);
     1521
     1522  /* set the dimensions of the next and previous buttons and center */
     1523  /* the month text vertically */
     1524  prev->top        = next->top    = title->top + 6;
     1525  prev->bottom = next->bottom = title->top + 2 * infoPtr->textHeight - 3;
     1526  prev->right  = title->left  + 28;
     1527  prev->left   = title->left  + 4;
     1528  next->left   = title->right - 28;
     1529  next->right  = title->right - 4;
     1530
     1531  /* titlemonth->left and right change based upon the current month */
     1532  /* and are recalculated in refresh as the current month may change */
     1533  /* without the control being resized */
     1534  titlemonth->bottom = titleyear->bottom = prev->top + 2 * infoPtr->textHeight - 3;
     1535  titlemonth->top    = titleyear->top    = title->top;
     1536
     1537  /* setup the dimensions of the rectangle we draw the names of the */
     1538  /* days of the week in */
     1539  days->left = infoPtr->left_offset;
     1540  if(dwStyle & MCS_WEEKNUMBERS) days->left+=infoPtr->textWidth;
     1541  days->right  = days->left + infoPtr->width_increment;
     1542  days->top    = title->bottom + 2;
     1543  days->bottom = title->bottom + infoPtr->textHeight + 2;
     1544
     1545  /* restore the originally selected font */
     1546  SelectObject(hdc, currentFont);
     1547
     1548  ReleaseDC(hwnd, hdc);
     1549}
     1550
     1551static LRESULT MONTHCAL_Size(HWND hwnd, int Width, int Height)
     1552{
     1553  //TRACE("(hwnd=%x, width=%d, height=%d)\n", hwnd, Width, Height);
     1554
     1555  MONTHCAL_UpdateSize(hwnd);
     1556
     1557  /* invalidate client area and erase background */
     1558  InvalidateRect(hwnd, NULL, TRUE);
     1559
     1560  return 0;
     1561}
     1562
     1563/* FIXME: check whether dateMin/dateMax need to be adjusted. */
     1564static LRESULT
     1565MONTHCAL_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1566{
     1567  MONTHCAL_INFO *infoPtr;
     1568  LOGFONTA      logFont;
     1569
     1570  /* allocate memory for info structure */
     1571  infoPtr =(MONTHCAL_INFO*)COMCTL32_Alloc(sizeof(MONTHCAL_INFO));
     1572  SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
     1573
     1574  if(infoPtr == NULL) {
     1575    //ERR( "could not allocate info memory!\n");
    12861576    return 0;
    1287 }
    1288 
    1289 
    1290 
    1291 static LRESULT
    1292 MONTHCAL_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1293 {
    1294     MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr (hwnd);
    1295         MCHITTESTINFO ht;
    1296         HDC hdc;
    1297         int selday,hit;
    1298         RECT r;
    1299 
    1300         if (!(infoPtr->status & MC_SEL_LBUTDOWN)) return 0;
    1301 
    1302         ht.pt.x=LOWORD(lParam);
    1303         ht.pt.y=HIWORD(lParam);
    1304 
    1305         hit=MONTHCAL_HitTest (hwnd, (LPARAM) &ht);
    1306 
    1307         /* not on the calendar date numbers? bail out */
    1308         //TRACE ("hit:%x\n",hit);
    1309         if ((hit & MCHT_CALENDARDATE) !=MCHT_CALENDARDATE) return 0;
    1310 
    1311         selday=ht.st.wDay;
    1312         infoPtr->curSelDay=selday;
    1313         MONTHCAL_CalcPosFromDay (infoPtr,selday,ht.st.wMonth,&r);
    1314 
    1315         if ( GetWindowLongA( hwnd, GWL_STYLE) & MCS_MULTISELECT)  {
    1316                 SYSTEMTIME selArray[2];
    1317                 int i;
    1318 
    1319         MONTHCAL_GetSelRange (hwnd,0,(LPARAM) &selArray);
    1320                 i=0;
    1321                 if (infoPtr->firstSelDay==selArray[0].wDay) i=1;
    1322                 //TRACE ("oldRange:%d %d %d %d\n",infoPtr->firstSelDay,selArray[0].wDay,selArray[1].wDay,i);
    1323                 if (infoPtr->firstSelDay==selArray[1].wDay) {
    1324                                 /* 1st time we get here: selArray[0]=selArray[1])  */
    1325                                 /* if we're still at the first selected date, return */
    1326                         if (infoPtr->firstSelDay==selday) goto done;
    1327 
    1328                         if (selday<infoPtr->firstSelDay) i=0;
    1329                 }
    1330 
    1331                 if (abs(infoPtr->firstSelDay - selday) >= infoPtr->maxSelCount) {
    1332                         if (selday>infoPtr->firstSelDay)
    1333                                 selday=infoPtr->firstSelDay+infoPtr->maxSelCount;
    1334                         else
    1335                                 selday=infoPtr->firstSelDay-infoPtr->maxSelCount;
    1336                 }
    1337 
    1338                 if (selArray[i].wDay!=selday) {
    1339 
    1340                 //TRACE ("newRange:%d %d %d %d\n",infoPtr->firstSelDay,selArray[0].wDay,selArray[1].wDay,i);
    1341 
    1342                         selArray[i].wDay=selday;
    1343 
    1344 
    1345                         if (selArray[0].wDay>selArray[1].wDay) {
    1346                                 DWORD tempday;
    1347                                 tempday=selArray[1].wDay;
    1348                                 selArray[1].wDay=selArray[0].wDay;
    1349                                 selArray[0].wDay=tempday;
    1350                         }
    1351 
    1352                 MONTHCAL_SetSelRange (hwnd,0,(LPARAM) &selArray);
    1353                 }
    1354         }
    1355 
    1356 done:
    1357 
    1358         hdc=GetDC (hwnd);
    1359         MONTHCAL_Refresh (hwnd, hdc);
    1360         ReleaseDC (hwnd, hdc);
    1361 
    1362         return 0;
    1363 }
    1364 
    1365 static LRESULT
    1366 MONTHCAL_Paint (HWND hwnd, WPARAM wParam)
    1367 {
    1368     HDC hdc;
    1369     PAINTSTRUCT ps;
    1370 
    1371     hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
    1372     MONTHCAL_Refresh (hwnd, hdc);
    1373     if(!wParam)
    1374     EndPaint (hwnd, &ps);
     1577  }
     1578  if((MONTHCAL_INFO*)GetWindowLongA(hwnd, 0) != infoPtr) {
     1579    //ERR( "pointer assignment error!\n");
    13751580    return 0;
    1376 }
    1377 
    1378 static LRESULT
    1379 MONTHCAL_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1380 {
    1381     HDC hdc;
    1382 
    1383     //TRACE ("\n");
    1384 
    1385     hdc = GetDC (hwnd);
    1386     MONTHCAL_Refresh (hwnd, hdc);
    1387     ReleaseDC (hwnd, hdc);
    1388     InvalidateRect (hwnd, NULL, TRUE);
    1389 
    1390     return 0;
    1391 }
    1392 
    1393 
    1394 static LRESULT
    1395 MONTHCAL_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1396 {
    1397     HDC hdc;
    1398 
    1399     //TRACE ("\n");
    1400 
    1401     hdc = GetDC (hwnd);
    1402     MONTHCAL_Refresh (hwnd, hdc);
    1403     ReleaseDC (hwnd, hdc);
    1404 
    1405     return 0;
    1406 }
    1407 
    1408 
    1409 /* FIXME: check whether dateMin/dateMax need to be adjusted. */
    1410 
    1411 
    1412 static LRESULT
    1413 MONTHCAL_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1414 {
    1415     MONTHCAL_INFO *infoPtr;
    1416         LOGFONTA        logFont;
    1417 
    1418     /* allocate memory for info structure */
    1419     infoPtr = (MONTHCAL_INFO *)COMCTL32_Alloc (sizeof(MONTHCAL_INFO));
    1420     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
    1421 
    1422         if (infoPtr == NULL) {
    1423         //ERR ( "could not allocate info memory!\n");
    1424         return 0;
    1425     }
    1426     if ((MONTHCAL_INFO*) GetWindowLongA( hwnd, 0) != infoPtr) {
    1427         //ERR ( "pointer assignment error!\n");
    1428         return 0;
    1429     }
    1430 
    1431 
    1432     infoPtr->hFont=GetStockObject(DEFAULT_GUI_FONT);
    1433                 GetObjectA (infoPtr->hFont, sizeof (LOGFONTA), &logFont);
    1434         logFont.lfWeight=FW_BOLD;
    1435         infoPtr->hBoldFont = CreateFontIndirectA (&logFont);
    1436 
    1437     /* initialize info structure */
    1438    /* FIXME: calculate systemtime ->> localtime (substract timezoneinfo) */
    1439 
    1440         GetSystemTime (&infoPtr->todaysDate);
    1441         infoPtr->firstDay  = 0;
    1442         infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
    1443         infoPtr->currentYear= infoPtr->todaysDate.wYear;
    1444         MONTHCAL_CopyTime (&infoPtr->todaysDate,&infoPtr->minDate);
    1445         MONTHCAL_CopyTime (&infoPtr->todaysDate,&infoPtr->maxDate);
    1446         infoPtr->maxSelCount=6;
    1447         infoPtr->monthRange=3;
    1448         infoPtr->monthdayState=COMCTL32_Alloc
    1449                            (infoPtr->monthRange*sizeof(MONTHDAYSTATE));
    1450         infoPtr->titlebk     = GetSysColor (COLOR_GRAYTEXT);
    1451         infoPtr->titletxt    = GetSysColor (COLOR_WINDOW);
    1452         infoPtr->monthbk     = GetSysColor (COLOR_WINDOW);
    1453         infoPtr->trailingtxt = GetSysColor (COLOR_GRAYTEXT);
    1454         infoPtr->bk                  = GetSysColor (COLOR_WINDOW);
    1455         infoPtr->txt         = GetSysColor (COLOR_WINDOWTEXT);
    1456 
    1457     return 0;
    1458 }
    1459 
    1460 
    1461 static LRESULT
    1462 MONTHCAL_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1463 {
    1464     MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr (hwnd);
    1465 
    1466     /* free month calendar info data */
    1467     COMCTL32_Free (infoPtr);
    1468 
    1469     return 0;
    1470 }
    1471 
     1581  }
     1582
     1583  infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
     1584  GetObjectA(infoPtr->hFont, sizeof(LOGFONTA), &logFont);
     1585  logFont.lfWeight = FW_BOLD;
     1586  infoPtr->hBoldFont = CreateFontIndirectA(&logFont);
     1587
     1588  /* initialize info structure */
     1589  /* FIXME: calculate systemtime ->> localtime(substract timezoneinfo) */
     1590
     1591  GetSystemTime(&infoPtr->todaysDate);
     1592  infoPtr->firstDay = 0;
     1593  infoPtr->currentMonth = infoPtr->todaysDate.wMonth;
     1594  infoPtr->currentYear = infoPtr->todaysDate.wYear;
     1595  MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
     1596  MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
     1597  infoPtr->maxSelCount  = 6;
     1598  infoPtr->monthRange = 3;
     1599  infoPtr->monthdayState = COMCTL32_Alloc
     1600                         (infoPtr->monthRange * sizeof(MONTHDAYSTATE));
     1601  infoPtr->titlebk     = GetSysColor(COLOR_ACTIVECAPTION);
     1602  infoPtr->titletxt    = GetSysColor(COLOR_WINDOW);
     1603  infoPtr->monthbk     = GetSysColor(COLOR_WINDOW);
     1604  infoPtr->trailingtxt = GetSysColor(COLOR_GRAYTEXT);
     1605  infoPtr->bk          = GetSysColor(COLOR_WINDOW);
     1606  infoPtr->txt         = GetSysColor(COLOR_WINDOWTEXT);
     1607
     1608  /* call MONTHCAL_UpdateSize to set all of the dimensions */
     1609  /* of the control */
     1610  MONTHCAL_UpdateSize(hwnd);
     1611
     1612  return 0;
     1613}
     1614
     1615
     1616static LRESULT
     1617MONTHCAL_Destroy(HWND hwnd, WPARAM wParam, LPARAM lParam)
     1618{
     1619  MONTHCAL_INFO *infoPtr = MONTHCAL_GetInfoPtr(hwnd);
     1620
     1621  /* free month calendar info data */
     1622  COMCTL32_Free(infoPtr);
     1623
     1624  return 0;
     1625}
    14721626
    14731627
    14741628static LRESULT WINAPI
    1475 MONTHCAL_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    1476 {
    1477 
    1478     switch (uMsg)
    1479     {
    1480 
    1481         case MCM_GETCURSEL:
    1482         return MONTHCAL_GetCurSel (hwnd, wParam, lParam);
    1483 
    1484         case MCM_SETCURSEL:
    1485         return MONTHCAL_SetCurSel (hwnd, wParam, lParam);
    1486 
    1487         case MCM_GETMAXSELCOUNT:
    1488         return MONTHCAL_GetMaxSelCount (hwnd, wParam, lParam);
    1489 
    1490         case MCM_SETMAXSELCOUNT:
    1491         return MONTHCAL_SetMaxSelCount (hwnd, wParam, lParam);
    1492 
    1493         case MCM_GETSELRANGE:
    1494         return MONTHCAL_GetSelRange (hwnd, wParam, lParam);
    1495 
    1496         case MCM_SETSELRANGE:
    1497         return MONTHCAL_SetSelRange (hwnd, wParam, lParam);
    1498 
    1499         case MCM_GETMONTHRANGE:
    1500         return MONTHCAL_GetMonthRange (hwnd, wParam, lParam);
    1501 
    1502         case MCM_SETDAYSTATE:
    1503         return MONTHCAL_SetDayState (hwnd, wParam, lParam);
    1504 
    1505         case MCM_GETMINREQRECT:
    1506         return MONTHCAL_GetMinReqRect (hwnd, wParam, lParam);
    1507 
    1508         case MCM_GETCOLOR:
    1509              return MONTHCAL_GetColor (hwnd, wParam, lParam);
    1510 
    1511         case MCM_SETCOLOR:
    1512              return MONTHCAL_SetColor (hwnd, wParam, lParam);
    1513 
    1514         case MCM_GETTODAY:
    1515              return MONTHCAL_GetToday (hwnd, wParam, lParam);
    1516 
    1517         case MCM_SETTODAY:
    1518              return MONTHCAL_SetToday (hwnd, wParam, lParam);
    1519 
    1520         case MCM_HITTEST:
    1521             return MONTHCAL_HitTest (hwnd,lParam);
    1522 
    1523         case MCM_GETFIRSTDAYOFWEEK:
    1524         return MONTHCAL_GetFirstDayOfWeek (hwnd, wParam, lParam);
    1525 
    1526         case MCM_SETFIRSTDAYOFWEEK:
    1527         return MONTHCAL_SetFirstDayOfWeek (hwnd, wParam, lParam);
    1528 
    1529         case MCM_GETRANGE:
    1530              return MONTHCAL_GetRange (hwnd, wParam, lParam);
    1531 
    1532         case MCM_SETRANGE:
    1533              return MONTHCAL_SetRange (hwnd, wParam, lParam);
    1534 
    1535         case MCM_GETMONTHDELTA:
    1536              return MONTHCAL_GetMonthDelta (hwnd, wParam, lParam);
    1537 
    1538         case MCM_SETMONTHDELTA:
    1539              return MONTHCAL_SetMonthDelta (hwnd, wParam, lParam);
    1540 
    1541         case MCM_GETMAXTODAYWIDTH:
    1542              return MONTHCAL_GetMaxTodayWidth (hwnd);
    1543 
    1544         case WM_GETDLGCODE:
    1545         return DLGC_WANTARROWS | DLGC_WANTCHARS;
    1546 
    1547     case WM_KILLFOCUS:
    1548         return MONTHCAL_KillFocus (hwnd, wParam, lParam);
    1549 
    1550     case WM_LBUTTONDOWN:
    1551         return MONTHCAL_LButtonDown (hwnd, wParam, lParam);
    1552 
    1553     case WM_MOUSEMOVE:
    1554         return MONTHCAL_MouseMove (hwnd, wParam, lParam);
    1555 
    1556     case WM_LBUTTONUP:
    1557         return MONTHCAL_LButtonUp (hwnd, wParam, lParam);
    1558 
    1559     case WM_PAINT:
    1560         return MONTHCAL_Paint (hwnd, wParam);
    1561 
    1562     case WM_SETFOCUS:
    1563         return MONTHCAL_SetFocus (hwnd, wParam, lParam);
    1564 
    1565         case WM_CREATE:
    1566             return MONTHCAL_Create (hwnd, wParam, lParam);
    1567 
    1568         case WM_TIMER:
    1569             return MONTHCAL_Timer (hwnd, wParam, lParam);
    1570 
    1571         case WM_DESTROY:
    1572             return MONTHCAL_Destroy (hwnd, wParam, lParam);
    1573 
    1574         default:
    1575             //if (uMsg >= WM_USER)
    1576             //    ERR ( "unknown msg %04x wp=%08x lp=%08lx\n",
    1577             //        uMsg, wParam, lParam);
    1578             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
    1579     }
    1580     return 0;
     1629MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     1630{
     1631  switch(uMsg)
     1632  {
     1633  case MCM_GETCURSEL:
     1634    return MONTHCAL_GetCurSel(hwnd, wParam, lParam);
     1635
     1636  case MCM_SETCURSEL:
     1637    return MONTHCAL_SetCurSel(hwnd, wParam, lParam);
     1638
     1639  case MCM_GETMAXSELCOUNT:
     1640    return MONTHCAL_GetMaxSelCount(hwnd, wParam, lParam);
     1641
     1642  case MCM_SETMAXSELCOUNT:
     1643    return MONTHCAL_SetMaxSelCount(hwnd, wParam, lParam);
     1644
     1645  case MCM_GETSELRANGE:
     1646    return MONTHCAL_GetSelRange(hwnd, wParam, lParam);
     1647
     1648  case MCM_SETSELRANGE:
     1649    return MONTHCAL_SetSelRange(hwnd, wParam, lParam);
     1650
     1651  case MCM_GETMONTHRANGE:
     1652    return MONTHCAL_GetMonthRange(hwnd, wParam, lParam);
     1653
     1654  case MCM_SETDAYSTATE:
     1655    return MONTHCAL_SetDayState(hwnd, wParam, lParam);
     1656
     1657  case MCM_GETMINREQRECT:
     1658    return MONTHCAL_GetMinReqRect(hwnd, wParam, lParam);
     1659
     1660  case MCM_GETCOLOR:
     1661    return MONTHCAL_GetColor(hwnd, wParam, lParam);
     1662
     1663  case MCM_SETCOLOR:
     1664    return MONTHCAL_SetColor(hwnd, wParam, lParam);
     1665
     1666  case MCM_GETTODAY:
     1667    return MONTHCAL_GetToday(hwnd, wParam, lParam);
     1668
     1669  case MCM_SETTODAY:
     1670    return MONTHCAL_SetToday(hwnd, wParam, lParam);
     1671
     1672  case MCM_HITTEST:
     1673    return MONTHCAL_HitTest(hwnd,lParam);
     1674
     1675  case MCM_GETFIRSTDAYOFWEEK:
     1676    return MONTHCAL_GetFirstDayOfWeek(hwnd, wParam, lParam);
     1677
     1678  case MCM_SETFIRSTDAYOFWEEK:
     1679    return MONTHCAL_SetFirstDayOfWeek(hwnd, wParam, lParam);
     1680
     1681  case MCM_GETRANGE:
     1682    return MONTHCAL_GetRange(hwnd, wParam, lParam);
     1683
     1684  case MCM_SETRANGE:
     1685    return MONTHCAL_SetRange(hwnd, wParam, lParam);
     1686
     1687  case MCM_GETMONTHDELTA:
     1688    return MONTHCAL_GetMonthDelta(hwnd, wParam, lParam);
     1689
     1690  case MCM_SETMONTHDELTA:
     1691    return MONTHCAL_SetMonthDelta(hwnd, wParam, lParam);
     1692
     1693  case MCM_GETMAXTODAYWIDTH:
     1694    return MONTHCAL_GetMaxTodayWidth(hwnd);
     1695
     1696  case WM_GETDLGCODE:
     1697    return DLGC_WANTARROWS | DLGC_WANTCHARS;
     1698
     1699  case WM_KILLFOCUS:
     1700    return MONTHCAL_KillFocus(hwnd, wParam, lParam);
     1701
     1702  case WM_LBUTTONDOWN:
     1703    return MONTHCAL_LButtonDown(hwnd, wParam, lParam);
     1704
     1705  case WM_MOUSEMOVE:
     1706    return MONTHCAL_MouseMove(hwnd, wParam, lParam);
     1707
     1708  case WM_LBUTTONUP:
     1709    return MONTHCAL_LButtonUp(hwnd, wParam, lParam);
     1710
     1711  case WM_PAINT:
     1712    return MONTHCAL_Paint(hwnd, wParam);
     1713
     1714  case WM_SETFOCUS:
     1715    return MONTHCAL_SetFocus(hwnd, wParam, lParam);
     1716
     1717  case WM_SIZE:
     1718    return MONTHCAL_Size(hwnd, (int)SLOWORD(lParam), (int)SHIWORD(lParam));
     1719
     1720  case WM_CREATE:
     1721    return MONTHCAL_Create(hwnd, wParam, lParam);
     1722
     1723  case WM_TIMER:
     1724    return MONTHCAL_Timer(hwnd, wParam, lParam);
     1725
     1726  case WM_DESTROY:
     1727    return MONTHCAL_Destroy(hwnd, wParam, lParam);
     1728
     1729  default:
     1730    //if(uMsg >= WM_USER)
     1731    //  ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
     1732    return DefWindowProcA(hwnd, uMsg, wParam, lParam);
     1733  }
     1734  return 0;
    15811735}
    15821736
    15831737
    15841738void
    1585 MONTHCAL_Register (void)
    1586 {
    1587     WNDCLASSA wndClass;
     1739MONTHCAL_Register(void)
     1740{
     1741  WNDCLASSA wndClass;
    15881742
    15891743//SvL: Don't check this now
    1590 //    if (GlobalFindAtomA (MONTHCAL_CLASSA)) return;
    1591 
    1592     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
    1593     wndClass.style         = CS_GLOBALCLASS;
    1594     wndClass.lpfnWndProc   = (WNDPROC)MONTHCAL_WindowProc;
    1595     wndClass.cbClsExtra    = 0;
    1596     wndClass.cbWndExtra    = sizeof(MONTHCAL_INFO *);
    1597     wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
    1598     wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    1599     wndClass.lpszClassName = MONTHCAL_CLASSA;
    1600 
    1601     RegisterClassA (&wndClass);
     1744//  if(GlobalFindAtomA(MONTHCAL_CLASSA)) return;
     1745
     1746  ZeroMemory(&wndClass, sizeof(WNDCLASSA));
     1747  wndClass.style         = CS_GLOBALCLASS;
     1748  wndClass.lpfnWndProc   = (WNDPROC)MONTHCAL_WindowProc;
     1749  wndClass.cbClsExtra    = 0;
     1750  wndClass.cbWndExtra    = sizeof(MONTHCAL_INFO *);
     1751  wndClass.hCursor       = LoadCursorA(0, IDC_ARROWA);
     1752  wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
     1753  wndClass.lpszClassName = MONTHCAL_CLASSA;
     1754
     1755  RegisterClassA(&wndClass);
    16021756}
    16031757
    16041758
    16051759void
    1606 MONTHCAL_Unregister (void)
    1607 {
    1608     if (GlobalFindAtomA (MONTHCAL_CLASSA))
    1609         UnregisterClassA (MONTHCAL_CLASSA, (HINSTANCE)NULL);
    1610 }
    1611 
     1760MONTHCAL_Unregister(void)
     1761{
     1762  if(GlobalFindAtomA(MONTHCAL_CLASSA))
     1763    UnregisterClassA(MONTHCAL_CLASSA, (HINSTANCE)NULL);
     1764}
  • trunk/src/comctl32/tooltips.c

    r2212 r2635  
    1 /* $Id: tooltips.c,v 1.19 1999-12-27 17:13:40 cbratschi Exp $ */
     1/* $Id: tooltips.c,v 1.20 2000-02-04 17:02:09 cbratschi Exp $ */
    22/*
    33 * Tool tip control
     
    1717 */
    1818
    19 /* WINE 991031 level */
     19/* WINE 20000130 level */
    2020
    2121#include <string.h>
  • trunk/src/comctl32/treeview.c

    r2184 r2635  
    1 /* $Id: treeview.c,v 1.21 1999-12-21 17:01:38 cbratschi Exp $ */
     1/* $Id: treeview.c,v 1.22 2000-02-04 17:02:09 cbratschi Exp $ */
    22/* Treeview control
    33 *
     
    8585TREEVIEW_DoSelectItem (HWND hwnd, INT action, HTREEITEM newSelect, INT cause);
    8686static void
    87 TREEVIEW_Refresh (HWND hwnd);
     87TREEVIEW_Refresh (HWND hwnd,HDC hdc);
    8888
    8989static LRESULT CALLBACK
     
    129129  TREEVIEW_INFO *infoPtr,
    130130  TREEVIEW_ITEM *tvItem)
    131 
    132131{
    133132  TREEVIEW_ITEM *wineItem = tvItem;
     
    394393  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    395394
    396 //  TRACE (treeview,"\n");
    397   if (infoPtr==NULL) return 0;
     395  //TRACE (treeview,"\n");
    398396
    399397  if ((INT)wParam == TVSIL_NORMAL)
     
    411409    HIMAGELIST himlTemp;
    412410
    413 //    TRACE (treeview,"\n");
     411    //TRACE (treeview,"\n");
    414412    switch ((INT)wParam) {
    415413        case TVSIL_NORMAL:
     
    485483  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    486484
    487   TRACE("\n");
     485  //TRACE("\n");
    488486  return (LRESULT) infoPtr->clrInsertMark;
    489487}
     
    495493  COLORREF prevColor=infoPtr->clrInsertMark;
    496494
    497   TRACE("%d %ld\n",wParam,lParam);
     495  //TRACE("%d %ld\n",wParam,lParam);
    498496  infoPtr->clrInsertMark=(COLORREF) lParam;
    499497  return (LRESULT) prevColor;
     
    504502{
    505503  TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    506 
    507   FIXME("%d %ld\n",wParam,lParam);
     504  HDC hdc;
     505
     506  //FIXME("%d %ld\n",wParam,lParam);
    508507  if (!TREEVIEW_ValidItem (infoPtr, (HTREEITEM)lParam)) return 0;
    509   FIXME("%d %ld\n",wParam,lParam);
     508  //FIXME("%d %ld\n",wParam,lParam);
    510509
    511510  infoPtr->insertBeforeorAfter=(BOOL) wParam;
    512511  infoPtr->insertMarkItem=(HTREEITEM) lParam;
    513   TREEVIEW_Refresh (hwnd);
     512
     513  hdc = GetDC(hwnd);
     514  TREEVIEW_Refresh(hwnd,hdc);
     515  ReleaseDC(hwnd,hdc);
     516
    514517  return 1;
    515518}
     
    714717        imageIndex=wineItem->state>>12;
    715718        imageIndex++;          /* yeah, right */
    716         TRACE ("imindex:%d\n",imageIndex);
     719        //TRACE ("imindex:%d\n",imageIndex);
    717720    if ((himlp) && (imageIndex))
    718721    {
     
    786789
    787790    if (wineItem->pszText== LPSTR_TEXTCALLBACKA) {
    788       TRACE("LPSTR_TEXTCALLBACK\n");
     791      //TRACE("LPSTR_TEXTCALLBACK\n");
    789792      TREEVIEW_SendDispInfoNotify (hwnd, wineItem, TVN_GETDISPINFO, TVIF_TEXT);
    790793    }
     
    864867  /* Draw insertion mark if necessary */
    865868
    866   if (infoPtr->insertMarkItem)
    867                 TRACE ("item:%d,mark:%d\n", (int)wineItem->hItem,
    868                                (int) infoPtr->insertMarkItem);
     869  //if (infoPtr->insertMarkItem)
     870  //              TRACE ("item:%d,mark:%d\n", (int)wineItem->hItem,
     871  //                             (int) infoPtr->insertMarkItem);
    869872  if (wineItem->hItem==infoPtr->insertMarkItem) {
    870873                HPEN hNewPen, hOldPen;
     
    896899                cditem=TREEVIEW_SendCustomDrawItemNotify
    897900                       (hwnd, hdc, wineItem, CDDS_ITEMPOSTPAINT);
    898                 TRACE("postpaint:cditem-app returns 0x%x\n",cditem);
     901                //TRACE("postpaint:cditem-app returns 0x%x\n",cditem);
    899902        }
    900903
     
    909912  HTREEITEM     *iItem;
    910913  LPRECT        lpRect   = (LPRECT)lParam;
     914  HDC hdc;
    911915
    912916//  TRACE (treeview,"\n");
     
    914918   * validate parameters
    915919   */
    916   if ( (infoPtr==NULL) || (lpRect == NULL) )
     920  if (lpRect == NULL)
    917921    return FALSE;
    918922
    919923  if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
    920                 TREEVIEW_Refresh (hwnd);        /* we want a rect for the current view */
     924  {
     925    hdc = GetDC(hwnd);
     926    TREEVIEW_Refresh(hwnd,hdc);        /* we want a rect for the current view */
     927    ReleaseDC(hwnd,hdc);
     928  }
    921929
    922930  /*
     
    9981006
    9991007  if (tvItem->mask & TVIF_STATE) {
    1000                 TRACE ("prevstate,state,mask:%x,%x,%x\n",wineItem->state,tvItem->state,
    1001 tvItem->stateMask);
     1008                //TRACE ("prevstate,state,mask:%x,%x,%x\n",wineItem->state,tvItem->state,
     1009//tvItem->stateMask);
    10021010        wineItem->state&= ~tvItem->stateMask;
    10031011                wineItem->state|= (tvItem->state & tvItem->stateMask);
     
    10391047
    10401048static void
    1041 TREEVIEW_Refresh (HWND hwnd)
     1049TREEVIEW_Refresh (HWND hwnd,HDC hdc)
    10421050
    10431051{
    10441052    TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
    1045         TEXTMETRICA tm;
    1046         HBRUSH hbrBk;
     1053    TEXTMETRICA tm;
     1054    HBRUSH hbrBk;
    10471055    RECT rect;
    1048         HDC hdc;
    10491056    INT iItem, indent, x, y, cx, height, itemHeight;
    10501057    INT viewtop,viewbottom,viewleft,viewright;
     
    10521059
    10531060    //TRACE("\n");
    1054 
    1055         hdc=GetDC (hwnd);
    10561061
    10571062    if (infoPtr->Timer & TV_REFRESH_TIMER_SET) {
     
    10671072                                                (hwnd, CDDS_PREPAINT, hdc, rect);
    10681073
    1069         if (infoPtr->cdmode==CDRF_SKIPDEFAULT) {
    1070                   ReleaseDC (hwnd, hdc);
    1071                   return;
    1072         }
    1073 
    1074         infoPtr->uVisibleHeight= rect.bottom-rect.top;
    1075         infoPtr->uVisibleWidth= rect.right-rect.left;
     1074    if (infoPtr->cdmode==CDRF_SKIPDEFAULT) return;
     1075
     1076    infoPtr->uVisibleHeight= rect.bottom-rect.top;
     1077    infoPtr->uVisibleWidth= rect.right-rect.left;
    10761078
    10771079    viewtop=infoPtr->cy;
     
    11881190                                                                (hwnd, CDDS_POSTPAINT, hdc, rect);
    11891191
    1190     ReleaseDC (hwnd, hdc);
    11911192    //TRACE("done\n");
    11921193}
     
    11991200
    12001201//  TRACE (treeview, " %d\n",wParam);
    1201   if (!infoPtr) return FALSE;
    12021202
    12031203  switch (wParam) {
     
    13121312  TREEVIEW_ITEM *wineItem, *returnItem;
    13131313  INT iItem, retval, flag;
    1314 
    1315 
    1316   if (!infoPtr) return FALSE;
     1314  HDC hdc;
     1315
    13171316  flag  = (INT) wParam;
    13181317  iItem = (INT) lParam;
     
    13231322        case TVGN_CARET:retval=(INT)infoPtr->selectedItem;
    13241323                                        break;
    1325         case TVGN_FIRSTVISIBLE:
    1326                                 TREEVIEW_Refresh (hwnd);
    1327 /* FIXME:we should only recalculate, not redraw */
    1328                                         retval=(INT)infoPtr->firstVisible;
    1329                                         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;
    13301330        case TVGN_DROPHILITE:
    13311331                                        retval=(INT)infoPtr->dropItem;
     
    19831983   }
    19841984
    1985 
    19861985   TREEVIEW_QueueRefresh (hwnd);
    19871986
     
    20492048
    20502049//  TRACE (treeview,"\n");
    2051   if (!infoPtr) return FALSE;
    20522050
    20532051  if (lParam == (INT)TVI_ROOT) {
     
    22432241
    22442242
    2245 
    22462243static LRESULT
    22472244TREEVIEW_StyleChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
    22482245{
    2249 //  TRACE (treeview,"(%x %lx)\n",wParam,lParam);
    2250 
    2251   TREEVIEW_Refresh(hwnd);
     2246  HDC hdc;
     2247
     2248  //TRACE("(%x %lx)\n",wParam,lParam);
     2249  hdc = GetDC (hwnd);
     2250  TREEVIEW_Refresh (hwnd, hdc);
     2251  ReleaseDC(hwnd,hdc);
    22522252
    22532253  return 0;
    22542254}
     2255
    22552256
    22562257static LRESULT
     
    22632264        HDC hdc;
    22642265
    2265     TRACE("wnd %x, style %lx\n",hwnd,dwStyle);
     2266    //TRACE("wnd %x, style %lx\n",hwnd,dwStyle);
    22662267      /* allocate memory for info structure */
    22672268    infoPtr = (TREEVIEW_INFO *) COMCTL32_Alloc (sizeof(TREEVIEW_INFO));
     
    22702271
    22712272    if (infoPtr == NULL) {
    2272                 ERR("could not allocate info memory!\n");
     2273                //ERR("could not allocate info memory!\n");
    22732274                return 0;
    22742275    }
    22752276
    22762277    if ((TREEVIEW_INFO*) GetWindowLongA( hwnd, 0) != infoPtr) {
    2277                 ERR("pointer assignment error!\n");
     2278                //ERR("pointer assignment error!\n");
    22782279                return 0;
    22792280    }
     
    23082309    infoPtr->pCallBackSort=NULL;
    23092310    infoPtr->uScrollTime = 300;  /* milliseconds */
    2310 
     2311        infoPtr->wpEditOrig = NULL; /* we haven't subclassed anything yet */
    23112312        infoPtr->hwndToolTip=0;
    23122313    if (!(dwStyle & TVS_NOTOOLTIPS)) {   /* Create tooltip control */
     
    23422343        SendMessageA (infoPtr->hwndToolTip, TTM_ADDTOOLA, 0, (LPARAM)&ti);
    23432344    }
    2344 
    2345    // @@@PH 1999/11/05
    2346     infoPtr->wpEditOrig = NULL; /* no subclass */
    23472345
    23482346        infoPtr->hwndEdit = CreateWindowExA (
     
    23702368
    23712369                hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDT_CHECK));
    2372                 TRACE ("%x\n",hbmLoad);
     2370                //TRACE ("%x\n",hbmLoad);
    23732371        nIndex = ImageList_AddMasked (infoPtr->himlState, hbmLoad, CLR_DEFAULT);
    2374                 TRACE ("%d\n",nIndex);
     2372                //TRACE ("%d\n",nIndex);
    23752373                DeleteObject (hbmLoad);
    23762374        }
     
    23892387
    23902388   TREEVIEW_RemoveTree (hwnd);
    2391 
    2392    //@@@PH 1999/11/05 set infoPtr to NULL
    23932389   SetWindowLongA( hwnd, 0, (DWORD)NULL);
    23942390
     
    24122408//    TRACE (treeview,"\n");
    24132409    hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
    2414     TREEVIEW_Refresh (hwnd);
     2410    TREEVIEW_Refresh (hwnd,hdc);
    24152411    if(!wParam)
    24162412        EndPaint (hwnd, &ps);
     
    29192915done:
    29202916  lpht->hItem=wineItem->hItem;
    2921   TRACE ("(%ld,%ld):result %x\n",lpht->pt.x,lpht->pt.y,lpht->flags);
     2917  //TRACE ("(%ld,%ld):result %x\n",lpht->pt.x,lpht->pt.y,lpht->flags);
    29222918
    29232919  return (LRESULT) wineItem->hItem;
     
    30503046  ht.pt.y = (INT)HIWORD(lParam);
    30513047
    3052   TRACE("\n");
     3048  //TRACE("\n");
    30533049
    30543050  /* Return true to cancel default behaviour */
     
    30583054  /* Get the item */
    30593055  iItem = TREEVIEW_HitTest (hwnd, (LPARAM) &ht);
    3060   TRACE ("%d\n",iItem);
     3056  //TRACE ("%d\n",iItem);
    30613057  if (!iItem)
    30623058    return 0;
     
    30853081      }
    30863082
    3087                 TRACE("Edit started for %s.\n", wineItem->pszText);
     3083                //TRACE("Edit started for %s.\n", wineItem->pszText);
    30883084                infoPtr->editItem = wineItem->hItem;
    30893085
     
    31193115                        int state;                                       /* to toggle the current state */
    31203116                        state=1-(wineItem->state>>12);
    3121                         TRACE ("state:%x\n", state);
     3117                        //TRACE ("state:%x\n", state);
    31223118                        wineItem->state&= ~TVIS_STATEIMAGEMASK;
    31233119                        wineItem->state|=state<<12;
    3124                         TRACE ("state:%x\n", wineItem->state);
     3120                        //TRACE ("state:%x\n", wineItem->state);
    31253121                        TREEVIEW_QueueRefresh (hwnd);
    31263122                }
     
    36883684TREEVIEW_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    36893685{
     3686   if (uMsg==WM_CREATE)
     3687                return TREEVIEW_Create (hwnd, wParam, lParam);
     3688
     3689   if (!TREEVIEW_GetInfoPtr(hwnd))
     3690       return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     3691
    36903692    switch (uMsg) {
    36913693        case TVM_INSERTITEMA:
     
    38353837        case WM_COMMAND:
    38363838                return TREEVIEW_Command (hwnd, wParam, lParam);
    3837 
    3838         case WM_CREATE:
    3839                 return TREEVIEW_Create (hwnd, wParam, lParam);
    38403839
    38413840        case WM_DESTROY:
Note: See TracChangeset for help on using the changeset viewer.