File:  [OS/2 SDKs] / pmsdk / samples / newcard / cftext.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.                */
/*********************************************************************/



/*********************************************************************/
/* CardKey -                                                         */
/*    Handles all virtual keys passed to cardfile in Card mode.      */
/* Included are PageUp, PageDown, Home, and End.  Each of these keys */
/* brings a new card to the front.                                   */
/*                                                                   */
/* Same in Windows and PM.                                           */
/*********************************************************************/

BOOL CardKey(wParam)
WORD wParam;
    {
    switch(wParam)
        {
        case VK_HOME:
            CardfileScroll(hCardfileWnd, SB_THUMBTRACK, 0);
            goto FinishScroll;

        case VK_END:
            CardfileScroll(hCardfileWnd, SB_THUMBTRACK, cCards-1);
            goto FinishScroll;

        case VK_PRIOR:
            CardfileScroll(hCardfileWnd, SB_LINEUP, 0);
            goto FinishScroll;

        case VK_NEXT:
            CardfileScroll(hCardfileWnd, SB_LINEDOWN, 0);

FinishScroll:
            CardfileScroll(hCardfileWnd, SB_ENDSCROLL, 0);
            return(TRUE);

        default:
            return(FALSE);
        }
    }


/*********************************************************************/
/* CardChar -                                                        */
/*    Looks at chars coming into cardfile and if ctrl-char, searches */
/* for next card beginning with that letter.  If found, card is      */
/* brought to top.  If keystroke is processed, returns TRUE,         */
/* otherwise FALSE.                                                  */
/*                                                                   */
/*    Same in Windows and PM.                                        */
/*********************************************************************/

BOOL CardChar(ch)
int ch;
    {
    LPCARDHEADER lpCards;
    LPCARDHEADER lpTmpCard;
    int i;
    int iCardTmp;
    int y;
    RECT rect;
    HDC hDC;
    MSG  msg;
   
    /* if character is greater than ' ' */
    if (ch >= ' ')
        /* don't want to handle it */
        return(FALSE);

    /* find out the letter of the control character */
    ch += 'A' - 1;

    /* scan all cards for the character, starting at the front one */
    lpCards = (LPCARDHEADER) GlobalLock(hCards);
    iCardTmp = iFirstCard+1;
    lpTmpCard = lpCards + iCardTmp;

    for (i = 0; i < cCards; ++i, lpTmpCard++, iCardTmp++)
        {
        /* if at end */
        if (iCardTmp == cCards)
            {
            /* go back to beginning */
            iCardTmp = 0;
            lpTmpCard = lpCards;
            }

        /* case insensitive */
        if (ANSICHARUP(CHAR_STR(lpTmpCard->line)) == ch)
            break;
        }
    GlobalUnlock(hCards);
    /* if found one, i will be < cCards */
    if (i < cCards)
        {
        /* if card mode */
        if (CardPhone != IDM_PHONEBOOK)
            {
            /* save current front data */
            SaveCurrentCard(iFirstCard);

            /* get new card's data */
            SetCurCard(iCardTmp);
            }
        else
            {
            /* if phonebook, just remove selection */
            y = (iFirstCard - iTopCard) * CharFixHeight;
            TRANSLATE_COORDS( cyMainWindow );

            SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth, 
                    y + CharFixHeight);
            TRANSLATE_RECT( rect );
            TRANSLATE_COORDS( 0 );

            hDC = GetDC(hCardfileWnd);
            InvertRect(hDC, (LPRECT)&rect);
            ReleaseDC(hCardfileWnd, hDC);
            }
        iFirstCard = iCardTmp;

        /* if in card mode, repaint headers and redraw */
        if (CardPhone == IDM_CARDFILE)
            {
            SetScrollPos(hCardfileWnd, SB_HORZ, iFirstCard, TRUE);
            PaintNewHeaders();
            InvalidateRect(hCardWnd, (LPRECT)NULL, TRUE);
            }

        /* otherwise bring new card on screen */
        else
            BringCardOnScreen(iFirstCard);  /* will highlight it too */
        }
    return(TRUE);
    }


/*********************************************************************/
/* BringCardOnScreen -                                               */
/*    Called in phonebook mode to bring a particular card into the   */
/* visible window.                                                   */
/*                                                                   */
/* Same in Windows and PM.                                           */
/*********************************************************************/

void BringCardOnScreen(iCard)
int iCard;
    {
    int dLines;
    int cLines;
    RECT rect;
    HDC hDC;
    int y;

    /* figure out how many lines there are in the window */
    cLines = cyMainWindow / CharFixHeight;

    /* put up new highlight in case it's already partly on the screen */
    TRANSLATE_COORDS( cyMainWindow );
    y = (iCard - iTopCard) * CharFixHeight;

    SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth, 
            y + CharFixHeight);
    TRANSLATE_RECT( rect );

    hDC = GetDC(hCardfileWnd);
    InvertRect(hDC, (LPRECT)&rect);
    ReleaseDC(hCardfileWnd, hDC);
    TRANSLATE_COORDS( 0 );

    /* see if we have to move the list within the window */
    if (iCard < iTopCard || iCard > iTopCard + cLines - 1)
        {
        if (iCard < iTopCard)
            dLines = (iCard - iTopCard);
        else
            dLines = iCard - iTopCard - cLines + 1;
        iTopCard += dLines;

        /* reset everything */
        SetScrollPos(hCardfileWnd, SB_VERT, iTopCard, TRUE);
        ScrollWindow(hCardfileWnd, 0, -dLines * CharFixHeight, 
                     (LPRECT)NULL, (LPRECT)NULL);
        UpdateWindow(hCardfileWnd);
        }
    }



/*********************************************************************/
/* PhoneKey -                                                        */
/*    Handles virtual keys in phonebook mode.                        */
/*                                                                   */
/* Same in Windows and PM.                                           */
/*********************************************************************/

BOOL PhoneKey(hwnd, wParam)
HWND hwnd;
WORD wParam;
    {
    HDC hDC;
    RECT rect;
    int y;
    int tmpCurCard;
    int cLines;

    cLines = cyMainWindow / CharFixHeight;

    switch(wParam)
        {
        case VK_NEXT:
            tmpCurCard = iFirstCard + cLines;
            if (tmpCurCard >= cCards)
                tmpCurCard = cCards - 1;
            goto SelectNewObject;

        case VK_PRIOR:
            tmpCurCard = iFirstCard - cLines;
            if (tmpCurCard >= 0)
                goto SelectNewObject;

        case VK_HOME:
            tmpCurCard = 0;
            goto SelectNewObject;

        case VK_END:
            tmpCurCard = cCards - 1;
            goto SelectNewObject;

        case VK_UP:
            tmpCurCard = iFirstCard - 1;
            goto SelectNewObject;

        case VK_DOWN:
            tmpCurCard = iFirstCard + 1;

SelectNewObject:
            if (tmpCurCard >= 0 && tmpCurCard < cCards && tmpCurCard != iFirstCard)
                {
                TRANSLATE_COORDS( cyMainWindow );
                y = (iFirstCard - iTopCard) * CharFixHeight;
                SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth, y + CharFixHeight);
                TRANSLATE_RECT( rect);

                hDC = GetDC(hwnd);
                InvertRect(hDC, (LPRECT)&rect);
                ReleaseDC(hwnd, hDC);
                TRANSLATE_COORDS( 0 );

                BringCardOnScreen(iFirstCard = tmpCurCard); /* will highlight the right one */
                }
            return(TRUE);

        default:
            return(FALSE);
        }
    }


unix.superglobalmegacorp.com

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