Annotation of pmsdk/samples/newcard/cfscroll.c, revision 1.1.1.1

1.1       root        1: #include "cardfile.h"
                      2: 
                      3: /*********************************************************************/
                      4: /*  Windows/PM Cardfile Shared Code                                  */
                      5: /*                                                                   */
                      6: /*  (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved    */
                      7: /*********************************************************************/
                      8: 
                      9: /*********************************************************************/
                     10: /*    The following shared code was developed from the original      */
                     11: /* Cardfile application.  This code can be compiled to run under     */
                     12: /* either the Windows or the PM manager environment.  All            */
                     13: /* functionality associated with bitmaps or printing has been        */
                     14: /* deleted.  Some comments refering to these functions may still be  */
                     15: /* present in the code and should be disregarded. jw.                */
                     16: /*********************************************************************/
                     17: 
                     18: 
                     19: 
                     20: /*********************************************************************/
                     21: /* CardfileScroll -                                                  */
                     22: /*    Handles all scroll messages in card mode.                      */
                     23: /*                                                                   */
                     24: /* Same in PM and Windows.                                           */
                     25: /*********************************************************************/
                     26: 
                     27: BOOL CardfileScroll(hWindow, cmd, pos)
                     28: HWND hWindow;
                     29: int cmd;
                     30: int pos;
                     31:     {
                     32:     int OldFirst = iFirstCard;
                     33:     RECT rect;
                     34:     int result = TRUE;
                     35:     HDC  hDC;
                     36: 
                     37:     /* if less that 2 cards, scrolling is a waste */
                     38:     if (cCards < 2)
                     39:         return(result);
                     40: 
                     41:     /* if just started scrolling, save starting position */
                     42:     if (!fScrolling)
                     43:         iCardStartScroll = iFirstCard;
                     44: 
                     45:     /* we're definitely scrolling now */
                     46:     fScrolling = TRUE;
                     47:     switch (cmd)
                     48:         {
                     49:         case SB_LINEUP:
                     50:             /* go back one card, with a possible wrap */
                     51:             iFirstCard--;
                     52:             if (iFirstCard < 0)
                     53:                 iFirstCard = cCards-1;
                     54:             break;
                     55: 
                     56:         case SB_LINEDOWN:
                     57:             /* move ahead one card */
                     58:             iFirstCard++;
                     59:             if (iFirstCard == cCards)
                     60:                 iFirstCard = 0;
                     61:             break;
                     62: 
                     63:         case SB_PAGEUP:
                     64:             /* move back one page (of fully visible cards) */
                     65:             if (cFSHeads == cCards)
                     66:                 return(result);
                     67: 
                     68:             iFirstCard -= cFSHeads;
                     69: 
                     70:             if (iFirstCard < 0)
                     71:                 iFirstCard += cCards; /* a negative number */
                     72: 
                     73:             break;
                     74: 
                     75:         case SB_PAGEDOWN:
                     76:             /* move forward one page */
                     77:             if (cFSHeads == cCards)
                     78:                 return(result);
                     79: 
                     80:             iFirstCard += cFSHeads;
                     81: 
                     82:             if (iFirstCard >= cCards)
                     83:                 iFirstCard -= cCards;
                     84: 
                     85:             break;
                     86: 
                     87:         case SB_THUMBPOSITION:
                     88:         case SB_ENDSCROLL:
                     89:             /* if we finish on a different card than at start */
                     90:             if (iFirstCard != iCardStartScroll)
                     91:                 {
                     92:                 /* save info, and read it back */
                     93:                 if (SaveCurrentCard(iCardStartScroll))
                     94:                     SetCurCard(iFirstCard);
                     95:                 else
                     96:                     {
                     97:                     /* otherwise we won't do anything */
                     98:                     iFirstCard = iCardStartScroll;
                     99:                     result = FALSE;
                    100:                     }
                    101:                 }
                    102: 
                    103:             /* set new position */
                    104:             SetScrollPos(hWindow, SB_HORZ, iFirstCard, TRUE);
                    105:             InvalidateRect(hCardWnd, (LPRECT)NULL, TRUE);
                    106:             fCardCleared = FALSE;
                    107:             fScrolling = FALSE;
                    108:             return(result);
                    109: 
                    110:         case SB_THUMBTRACK:
                    111:             /* follow thumb position */
                    112:             iFirstCard = pos;
                    113:             break;
                    114: 
                    115:         default:
                    116:             return(result);
                    117:         }
                    118:     /* only gets here on lineup-down, pageup-down, and thumbtrack */
                    119:     /* if we're on a different card than at start */
                    120:     if (iFirstCard != OldFirst)
                    121:         {
                    122:         /* and it hasn't been whited out */
                    123:         if (!fCardCleared)
                    124:             {
                    125:             /* clear it */
                    126:             hDC = GetDC(hCardWnd);
                    127: 
                    128:             GetClientRect(hCardWnd, (LPRECT)&rect);
                    129:             FillRect(hDC, (LPRECT)&rect, hbrWhite);
                    130:             ReleaseDC(hCardWnd, hDC);
                    131: 
                    132:             fCardCleared = TRUE;
                    133:             }
                    134: 
                    135:         /* set new position, if not conflicting with scroll bar */
                    136:         if (cmd != SB_THUMBTRACK)
                    137:             SetScrollPos(hWindow, SB_HORZ, iFirstCard, TRUE);
                    138: 
                    139:         /* paint the new headers */
                    140:         PaintNewHeaders();
                    141:         }
                    142:     return(result);
                    143:     }
                    144: 
                    145: 
                    146: /*********************************************************************/
                    147: /* PhoneScroll -                                                     */
                    148: /*    Handle scroll commands coming through in phone book mode.      */
                    149: /*                                                                   */
                    150: /* Same in Windows and PM.                                           */
                    151: /*********************************************************************/
                    152: 
                    153: void PhoneScroll(hWindow, cmd, pos)
                    154: HWND hWindow;
                    155: int cmd;
                    156: int pos;
                    157:     {
                    158:     int OldTop = iTopCard;
                    159:     int cLines;
                    160:     int dCards;
                    161: 
                    162:     cLines = cyMainWindow / CharFixHeight;
                    163: 
                    164:     dCards = 0;
                    165:     switch (cmd)
                    166:         {
                    167:         case SB_LINEUP:
                    168:             dCards = -1;
                    169:             break;
                    170: 
                    171:         case SB_LINEDOWN:
                    172:             dCards = 1;
                    173:             break;
                    174: 
                    175:         case SB_PAGEUP:
                    176:             dCards = -cLines;
                    177:             break;
                    178: 
                    179:         case SB_PAGEDOWN:
                    180:             dCards = cLines;
                    181:             break;
                    182: 
                    183:         case SB_THUMBTRACK:
                    184:             dCards = pos - iTopCard;
                    185:             break;
                    186: 
                    187:         case SB_THUMBPOSITION:
                    188:             SetScrollPos(hWindow, SB_VERT, pos, TRUE);
                    189:             return;
                    190:         }
                    191:     iTopCard += dCards;
                    192: 
                    193:     if (iTopCard > cCards - cLines)
                    194:         iTopCard = cCards - cLines;
                    195:     else if (iTopCard < 0)
                    196:         iTopCard = 0;
                    197: 
                    198:     dCards = OldTop - iTopCard;
                    199: 
                    200:     if (dCards)
                    201:         {
                    202:         if (cmd != SB_THUMBTRACK)
                    203:             SetScrollPos(hWindow, SB_VERT, iTopCard, TRUE);
                    204: 
                    205:         ScrollWindow(hWindow, 0, dCards * CharFixHeight, 
                    206:                      (LPRECT)NULL, (LPRECT)NULL);
                    207:         UpdateWindow(hWindow);
                    208:         }
                    209:     }
                    210: 
                    211: 
                    212: /*********************************************************************/
                    213: /* SetScrRangeAndPos -                                               */
                    214: /*    Resets the range and position of the scroll bars, depending    */
                    215: /* on the number of cards in the file and the current card.          */
                    216: /*                                                                   */
                    217: /* Same in Windows and PM.                                           */
                    218: /*********************************************************************/
                    219: 
                    220: void SetScrRangeAndPos()
                    221:     {
                    222:     int range;
                    223:     int cLines;
                    224: 
                    225:     if (CardPhone == IDM_PHONEBOOK)
                    226:         {
                    227:         if ((cLines = cyMainWindow / CharFixHeight) >= cCards)
                    228:             range = 0;
                    229:         else
                    230:             {
                    231:             if (!cLines)
                    232:                 cLines = 1;
                    233:             range = cCards - cLines;
                    234:             }
                    235:         }
                    236:     else
                    237:         range = cCards-1;
                    238: 
                    239: 
                    240:     if (CardPhone == IDM_PHONEBOOK) {
                    241:        SCROLL_RANGE( hCardfileWnd, SB_VERT, iTopCard, 0, range );
                    242:     }
                    243:     else
                    244:        SCROLL_RANGE( hCardfileWnd, SB_HORZ, iFirstCard, 0, range );
                    245:     }
                    246: 

unix.superglobalmegacorp.com

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