File:  [OS/2 SDKs] / pmsdk / samples / newcard / cfscroll.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:28:12 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: pmsdk-1988, HEAD
Microsoft OS/2 SDK PM 08-08-1988

#include "cardfile.h"

/*********************************************************************/
/*  Windows/PM Cardfile Shared Code                                  */
/*                                                                   */
/*  (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved    */
/*********************************************************************/

/*********************************************************************/
/*    The following shared code was developed from the original      */
/* Cardfile application.  This code can be compiled to run under     */
/* either the Windows or the PM manager environment.  All            */
/* functionality associated with bitmaps or printing has been        */
/* deleted.  Some comments refering to these functions may still be  */
/* present in the code and should be disregarded. jw.                */
/*********************************************************************/



/*********************************************************************/
/* CardfileScroll -                                                  */
/*    Handles all scroll messages in card mode.                      */
/*                                                                   */
/* Same in PM and Windows.                                           */
/*********************************************************************/

BOOL CardfileScroll(hWindow, cmd, pos)
HWND hWindow;
int cmd;
int pos;
    {
    int OldFirst = iFirstCard;
    RECT rect;
    int result = TRUE;
    HDC  hDC;

    /* if less that 2 cards, scrolling is a waste */
    if (cCards < 2)
        return(result);

    /* if just started scrolling, save starting position */
    if (!fScrolling)
        iCardStartScroll = iFirstCard;

    /* we're definitely scrolling now */
    fScrolling = TRUE;
    switch (cmd)
        {
        case SB_LINEUP:
            /* go back one card, with a possible wrap */
            iFirstCard--;
            if (iFirstCard < 0)
                iFirstCard = cCards-1;
            break;

        case SB_LINEDOWN:
            /* move ahead one card */
            iFirstCard++;
            if (iFirstCard == cCards)
                iFirstCard = 0;
            break;

        case SB_PAGEUP:
            /* move back one page (of fully visible cards) */
            if (cFSHeads == cCards)
                return(result);

            iFirstCard -= cFSHeads;

            if (iFirstCard < 0)
                iFirstCard += cCards; /* a negative number */

            break;

        case SB_PAGEDOWN:
            /* move forward one page */
            if (cFSHeads == cCards)
                return(result);

            iFirstCard += cFSHeads;

            if (iFirstCard >= cCards)
                iFirstCard -= cCards;

            break;

        case SB_THUMBPOSITION:
        case SB_ENDSCROLL:
            /* if we finish on a different card than at start */
            if (iFirstCard != iCardStartScroll)
                {
                /* save info, and read it back */
                if (SaveCurrentCard(iCardStartScroll))
                    SetCurCard(iFirstCard);
                else
                    {
                    /* otherwise we won't do anything */
                    iFirstCard = iCardStartScroll;
                    result = FALSE;
                    }
                }

            /* set new position */
            SetScrollPos(hWindow, SB_HORZ, iFirstCard, TRUE);
            InvalidateRect(hCardWnd, (LPRECT)NULL, TRUE);
            fCardCleared = FALSE;
            fScrolling = FALSE;
            return(result);

        case SB_THUMBTRACK:
            /* follow thumb position */
            iFirstCard = pos;
            break;

        default:
            return(result);
        }
    /* only gets here on lineup-down, pageup-down, and thumbtrack */
    /* if we're on a different card than at start */
    if (iFirstCard != OldFirst)
        {
        /* and it hasn't been whited out */
        if (!fCardCleared)
            {
            /* clear it */
            hDC = GetDC(hCardWnd);

            GetClientRect(hCardWnd, (LPRECT)&rect);
            FillRect(hDC, (LPRECT)&rect, hbrWhite);
            ReleaseDC(hCardWnd, hDC);

            fCardCleared = TRUE;
            }

        /* set new position, if not conflicting with scroll bar */
        if (cmd != SB_THUMBTRACK)
            SetScrollPos(hWindow, SB_HORZ, iFirstCard, TRUE);

        /* paint the new headers */
        PaintNewHeaders();
        }
    return(result);
    }


/*********************************************************************/
/* PhoneScroll -                                                     */
/*    Handle scroll commands coming through in phone book mode.      */
/*                                                                   */
/* Same in Windows and PM.                                           */
/*********************************************************************/

void PhoneScroll(hWindow, cmd, pos)
HWND hWindow;
int cmd;
int pos;
    {
    int OldTop = iTopCard;
    int cLines;
    int dCards;

    cLines = cyMainWindow / CharFixHeight;

    dCards = 0;
    switch (cmd)
        {
        case SB_LINEUP:
            dCards = -1;
            break;

        case SB_LINEDOWN:
            dCards = 1;
            break;

        case SB_PAGEUP:
            dCards = -cLines;
            break;

        case SB_PAGEDOWN:
            dCards = cLines;
            break;

        case SB_THUMBTRACK:
            dCards = pos - iTopCard;
            break;

        case SB_THUMBPOSITION:
            SetScrollPos(hWindow, SB_VERT, pos, TRUE);
            return;
        }
    iTopCard += dCards;

    if (iTopCard > cCards - cLines)
        iTopCard = cCards - cLines;
    else if (iTopCard < 0)
        iTopCard = 0;

    dCards = OldTop - iTopCard;

    if (dCards)
        {
        if (cmd != SB_THUMBTRACK)
            SetScrollPos(hWindow, SB_VERT, iTopCard, TRUE);

        ScrollWindow(hWindow, 0, dCards * CharFixHeight, 
                     (LPRECT)NULL, (LPRECT)NULL);
        UpdateWindow(hWindow);
        }
    }


/*********************************************************************/
/* SetScrRangeAndPos -                                               */
/*    Resets the range and position of the scroll bars, depending    */
/* on the number of cards in the file and the current card.          */
/*                                                                   */
/* Same in Windows and PM.                                           */
/*********************************************************************/

void SetScrRangeAndPos()
    {
    int range;
    int cLines;

    if (CardPhone == IDM_PHONEBOOK)
        {
        if ((cLines = cyMainWindow / CharFixHeight) >= cCards)
            range = 0;
        else
            {
            if (!cLines)
                cLines = 1;
            range = cCards - cLines;
            }
        }
    else
        range = cCards-1;


    if (CardPhone == IDM_PHONEBOOK) {
       SCROLL_RANGE( hCardfileWnd, SB_VERT, iTopCard, 0, range );
    }
    else
       SCROLL_RANGE( hCardfileWnd, SB_HORZ, iFirstCard, 0, range );
    }


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.