Annotation of pmsdk/samples/newcard/cfpaint.c, revision 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: /* This file contains all of cardfile's painting procedures, as well as */
        !            19: /* the size proc. */
        !            20: 
        !            21: /*********************************************************************/
        !            22: /* CardfileEraseBkGnd -                                              */
        !            23: /*    Handles the EraseBkGnd message.  Most applications pass the    */
        !            24: /* message through to DefWindowProc, but Cardfile paints the         */
        !            25: /* background blue in Cardfile mode.                                 */
        !            26: /*                                                                   */
        !            27: /* Slightly different in PM and Windows.                             */
        !            28: /*********************************************************************/
        !            29: 
        !            30: void CardfileEraseBkGnd(hWnd, hDC)
        !            31: HWND hWnd;
        !            32: HDC  hDC;
        !            33:     {
        !            34:     HBRUSH  hbr;            /* brush used to paint background */
        !            35:     HBRUSH  hbrOld;         /* to save brush which was in DC */
        !            36:     RECT    rect;           /* filled with the window's rect */
        !            37:     POINT   pt;             /* used for aligning brush */
        !            38: 
        !            39:     GetClientRect(hWnd, (LPRECT)&rect);
        !            40: 
        !            41:     /* Get the right brush */
        !            42:     if (CardPhone == IDM_PHONEBOOK)
        !            43: 
        !            44:         /* Last minute changes in the way in which colors operate force */
        !            45:         /*  the next two statements - for the PM version, assume that   */
        !            46:         /*  the phonebook background color is white */       
        !            47: 
        !            48: #ifdef   IN_WINDOWS
        !            49:         hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
        !            50: #else
        !            51:         hbr = WHITE_COLOR;
        !            52: #endif
        !            53:     else
        !            54:         hbr = hbrBack;
        !            55: 
        !            56:     if (hbr)
        !            57:         {
        !            58:         /* Unless you unrealize the brush, and set its origin, patterns */
        !            59:         /* may not line up correctly on the screen.  For example, two */
        !            60:         /* gray brushes that weren't lined up could create a line. */
        !            61: 
        !            62:         /* Don't worry about this for PM; right now patterns aren't */
        !            63:         /* used for brushes anyway   */
        !            64:    
        !            65: #ifdef   IN_WINDOWS
        !            66:         UnrealizeObject(hbr);
        !            67:         pt.x = 0;
        !            68:         pt.y = 0;
        !            69:         ClientToScreen(hWnd, (LPPOINT)&pt);
        !            70:         SetBrushOrg( hDC, pt.x, pt.y);
        !            71:         hbrOld = SelectObject(hDC, hbr);
        !            72: #endif
        !            73: 
        !            74:         FillRect(hDC, (LPRECT)&rect, hbr);
        !            75: 
        !            76:         /* Deleting old brush.  Don't do in PM version */
        !            77: 
        !            78: #ifdef   IN_WINDOWS
        !            79:         /* We may delete the brush, so select in the old one.  (You can't */
        !            80:         /* delete a locked object.) */
        !            81:         SelectObject(hDC, hbrOld);
        !            82: 
        !            83:         if (CardPhone == IDM_PHONEBOOK)
        !            84:             DeleteObject(hbr);
        !            85: #endif
        !            86:         }
        !            87:     }
        !            88: 
        !            89: 
        !            90: 
        !            91: /*********************************************************************/
        !            92: /* CardfilePaint -                                                   */
        !            93: /*    Main paint procedure for Cardfile when in the card mode.  For  */
        !            94: /* an explanation of the variables used to draw cards, look in       */
        !            95: /* cfdata.c.                                                         */
        !            96: /*                                                                   */
        !            97: /* Same in Windows and PM.                                           */
        !            98: /*********************************************************************/
        !            99: 
        !           100: void CardfilePaint(hWindow, hDC)
        !           101: HWND hWindow;
        !           102: HDC  hDC;
        !           103:     {
        !           104:     RECT rect;
        !           105:     LPCARDHEADER lpCards;   /* far pointer to first card */
        !           106:     LPCARDHEADER lpTCards;  /* far pointer to any card in file */
        !           107:     int xCur, yCur;         /* coordinates of card being painted */
        !           108:     int vcCards;            /* count of cards that will fit vertically */
        !           109:     int hcCards;            /* count of cards that will fit horizontally */
        !           110:     int width;              /* width of the window minus the margins */
        !           111:     int height;             /* height of the window minus the margins */
        !           112:     int idCard;             /* index of the card being painted */
        !           113:     int i;                  /* loop variable */
        !           114: 
        !           115: 
        !           116:     /* always have a left margin, and if there's room for a right margin, */
        !           117:     /* subtract that too. */
        !           118:     width = cxMainWindow - LEFTMARGIN;
        !           119:     if (width - RIGHTMARGIN > CardWidth)
        !           120:         width -= RIGHTMARGIN;
        !           121: 
        !           122:     /* always have a top margin, and if there's room for a bottom margin, */
        !           123:     /* subtract that too. */
        !           124:     height = cyMainWindow;
        !           125:     if (cyMainWindow - BOTTOMMARGIN > CardHeight)
        !           126:         height -= BOTTOMMARGIN;
        !           127: 
        !           128:     /* always have at least one card */
        !           129:     hcCards = 1;
        !           130:     cFSHeads = cScreenHeads = 1;
        !           131: 
        !           132:     /* see how many full or partial headers will appear in vertical space */
        !           133:     if (yFirstCard < height)
        !           134:         {
        !           135:         cScreenHeads += (yFirstCard+ySpacing-1) / ySpacing;
        !           136:         cFSHeads += (yFirstCard / ySpacing);
        !           137:         }
        !           138: 
        !           139:     /* limit header counts to number of cards in file */
        !           140:     if (cScreenHeads > cCards)
        !           141:         cScreenHeads = cCards;
        !           142: 
        !           143:     if (cFSHeads > cCards)
        !           144:         cFSHeads = cCards;
        !           145: 
        !           146:     /* see how many cards will fit horizontally */
        !           147:     if (width - CardWidth > 0)
        !           148:         hcCards += ((width - CardWidth) / (2 * CharFixWidth));
        !           149: 
        !           150:     /* see how many cards will fit vertically */
        !           151:     vcCards = height / ySpacing;
        !           152: 
        !           153:     /* the actual count should be the greater of the vertical and horizontal */
        !           154:     cScreenCards = hcCards > vcCards ? hcCards : vcCards;
        !           155: 
        !           156:     /* limit the count to the number of cards in the file */
        !           157:     cScreenCards = cCards < cScreenCards ? cCards : cScreenCards;
        !           158: 
        !           159:     /* get pointer to first card */
        !           160:     lpCards = (LPCARDHEADER) GlobalLock(hCards);
        !           161: 
        !           162:     /* calculate the coordinates of the first card to be painted */
        !           163:     yCur = yFirstCard - (cScreenCards - 1)*ySpacing;
        !           164:     xCur = xFirstCard + (cScreenCards - 1)* (2 * CharFixWidth);
        !           165: 
        !           166:     /* figure out which card will be painted first.  Cards are painted from */
        !           167:     /* the back right to the front left, i.e. from the end of the file */
        !           168:     /* to the front of the file */
        !           169:     idCard = (iFirstCard + cScreenCards-1) % cCards;
        !           170:     lpTCards = lpCards + idCard;
        !           171: 
        !           172:     /* Turn on PM coord transformations by specifying the height of the */
        !           173:     /*  main window */
        !           174:     TRANSLATE_COORDS( cyMainWindow );
        !           175: 
        !           176:     for (i = 0; i < cScreenCards; ++i)
        !           177:         {
        !           178:         /* draw the card */
        !           179:         SetRect((LPRECT)&rect, xCur, yCur, xCur+CardWidth, yCur+CardHeight);
        !           180:         TRANSLATE_RECT( rect );
        !           181:         FrameRect(hDC, (LPRECT)&rect, hbrBlack);
        !           182:         InflateRect((LPRECT)&rect, -1, -1);
        !           183:         FillRect(hDC, (LPRECT)&rect, hbrWhite);
        !           184:         SetBkMode(hDC, TRANSPARENT);
        !           185:         TextOut(hDC, xCur+1, yCur+1+(ExtLeading / 2), 
        !           186:                 lpTCards->line, Mylstrlen(lpTCards->line));
        !           187: 
        !           188:         /* calculate coordinates for next card */
        !           189:         xCur -= (2*CharFixWidth);
        !           190:         yCur += ySpacing;
        !           191: 
        !           192:         /* get next card */
        !           193:         lpTCards--;
        !           194:         idCard--;
        !           195: 
        !           196:         /* if past beginning of file */
        !           197:         if (idCard < 0)
        !           198:             {
        !           199:             /* get to last card */
        !           200:             idCard = cCards - 1;
        !           201:             lpTCards = lpCards+idCard;
        !           202:             }
        !           203:         }
        !           204:     /* draw the red line on the front card */
        !           205:     SetRect((LPRECT)&rect, xFirstCard, yFirstCard+1+CharFixHeight, 
        !           206:             xFirstCard+CardWidth, yFirstCard+2+CharFixHeight);
        !           207:     TRANSLATE_RECT( rect );
        !           208:     FillRect(hDC, (LPRECT)&rect, hbrLine);
        !           209: 
        !           210:     SetRect((LPRECT)&rect, xFirstCard, yFirstCard+3+CharFixHeight, xFirstCard+CardWidth, yFirstCard+4+CharFixHeight);
        !           211:     TRANSLATE_RECT( rect );
        !           212:     FillRect(hDC, (LPRECT)&rect, hbrLine);
        !           213: 
        !           214:     /* Reset the transformation unit to 0 to insure in the future */
        !           215:     /*  that no unwanted transformation will occur in other routines */
        !           216:     TRANSLATE_COORDS( 0 );
        !           217: 
        !           218:     /* done with cards */
        !           219:     GlobalUnlock(hCards);
        !           220:     }
        !           221: 
        !           222: 
        !           223: /*********************************************************************/
        !           224: /* PhonePaint - 
        !           225: /*    Paints the main window when in phone book mode.  Simpler than 
        !           226: /* painting in Card mode because all that needs to be done in phone
        !           227: /* book mode is to display list of strings.
        !           228: /*
        !           229: /* Slightly different in Windows and PM.
        !           230: /*********************************************************************/
        !           231: 
        !           232: void PhonePaint(hWindow, hDC)
        !           233: HWND hWindow;
        !           234: HDC  hDC;
        !           235:     {
        !           236:     RECT rect;               /* the window's rectangle */
        !           237:     LPCARDHEADER lpCards;    /* far pointer to card being painted */
        !           238:     int y;                   /* y coordinate of header being painted */
        !           239:     int i;
        !           240:     int cScrCards;           /* count partially visible headers */
        !           241: 
        !           242:     /* figure out how many headers are at least partially visible.  This */
        !           243:     /* is basically just the count of how many lines of text will fit in */
        !           244:     /* the window. */
        !           245:     cScrCards = (cyMainWindow + CharFixHeight - 1) / CharFixHeight;
        !           246:     
        !           247:     /* get to the header which is currently at the top of the window */
        !           248:     lpCards = (LPCARDHEADER) GlobalLock(hCards);
        !           249:     lpCards += iTopCard;
        !           250: 
        !           251:     /* set the default text color, and put it in transparent mode */
        !           252: 
        !           253:     /* Don't perform this in PM for the time being, just use default */
        !           254:     /* text color. */
        !           255: #ifdef   IN_WINDOWS
        !           256:     SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
        !           257: #endif
        !           258:     SetBkMode(hDC, TRANSPARENT);
        !           259: 
        !           260:     /* always start at the top of the screen */
        !           261:     y = 0;
        !           262: 
        !           263:     TRANSLATE_COORDS( cyMainWindow );
        !           264: 
        !           265:     for (i = 0; i < cScrCards; ++i)
        !           266:         {
        !           267:         /* if it's going to paint a non-existant card, break */
        !           268:         if (i + iTopCard >= cCards)
        !           269:             break;
        !           270: 
        !           271:         /* paint it */
        !           272:         TextOut(hDC, CharFixWidth, y, lpCards->line, 
        !           273:                 Mylstrlen(lpCards->line));
        !           274: 
        !           275:         /* get to next header */
        !           276:         y += CharFixHeight;
        !           277:         lpCards++;
        !           278:         }
        !           279: 
        !           280:     /* done with cards */
        !           281:     GlobalUnlock(hCards);
        !           282: 
        !           283:     /* if have the focus, highlight the current card */
        !           284:     if (GetFocus() == hCardfileWnd)
        !           285:         {
        !           286:         y = (iFirstCard - iTopCard) * CharFixHeight;
        !           287: 
        !           288:         SetRect((LPRECT)&rect, 0, y, (LINELENGTH+2)*CharFixWidth, 
        !           289:                 y+CharFixHeight);
        !           290:         TRANSLATE_RECT( rect );
        !           291: 
        !           292:         InvertRect(hDC, (LPRECT)&rect);
        !           293:         }
        !           294: 
        !           295:     TRANSLATE_COORDS( 0 );  
        !           296:     }
        !           297: 
        !           298: 
        !           299: 
        !           300: /*********************************************************************/
        !           301: /* PaintNewHeaders - 
        !           302: /*    Called when a new card is brought to the front.  Overwrites 
        !           303: /* information in headers.  This routine is only called in card mode.
        !           304: /*
        !           305: /* Smae in Windows and PM.
        !           306: /*********************************************************************/
        !           307: 
        !           308: void PaintNewHeaders()
        !           309:     {
        !           310:     HDC hDC;                    /* the DC */
        !           311:     int idCard;                 /* id of the card being painted */
        !           312:     LPCARDHEADER lpCards;       /* far pointer to first card */
        !           313:     LPCARDHEADER lpTCards;      /* far pointer to card being painted */
        !           314:     int xCur, yCur;             /* coordinates of card being painted */
        !           315:     int i;
        !           316:     RECT rect;
        !           317: 
        !           318:     /* cards are painted from back to front, calculate first coordinates */
        !           319:     yCur = yFirstCard - (cScreenHeads - 1)*ySpacing;
        !           320:     xCur = xFirstCard + (cScreenHeads - 1)* (2 * CharFixWidth);
        !           321: 
        !           322:     /* get to the first card to be painted */
        !           323:     idCard = (iFirstCard + cScreenHeads-1) % cCards;
        !           324:     lpCards = (LPCARDHEADER) GlobalLock(hCards);
        !           325:     lpTCards = lpCards + idCard;
        !           326: 
        !           327:     /* get a dc */
        !           328:     hDC = GetDC(hCardfileWnd);
        !           329:     SetBkMode(hDC, TRANSPARENT);
        !           330: 
        !           331:     TRANSLATE_COORDS( cyMainWindow );  
        !           332: 
        !           333:     /* for all cards with headers showing */
        !           334:     for (i = 0; i < cScreenHeads; ++i)
        !           335:         {
        !           336:         /* clear out the old header */
        !           337:         SetRect((LPRECT)&rect, xCur+1, yCur+1, xCur+CardWidth-1, 
        !           338:                 yCur+CharFixHeight+1);
        !           339:         TRANSLATE_RECT( rect ); 
        !           340:       
        !           341:         FillRect(hDC, (LPRECT)&rect, hbrWhite);
        !           342: 
        !           343:         /* draw the new header */
        !           344:         TextOut(hDC, xCur+1, yCur+1+(ExtLeading/2), lpTCards->line, 
        !           345:                 Mylstrlen(lpTCards->line));
        !           346: 
        !           347:         /* calculate next coordinates */
        !           348:         xCur -= (2*CharFixWidth);
        !           349:         yCur += ySpacing;
        !           350: 
        !           351:         /* get to next card */
        !           352:         lpTCards--;
        !           353:         idCard--;
        !           354:         /* if past beginning of file, get to end of file */
        !           355:         if (idCard < 0)
        !           356:             {
        !           357:             idCard = cCards - 1;
        !           358:             lpTCards = lpCards+idCard;
        !           359:             }
        !           360:         }
        !           361: 
        !           362:     TRANSLATE_COORDS( 0 );
        !           363: 
        !           364:     /* done with both dc and cards */
        !           365:     ReleaseDC(hCardfileWnd, hDC);
        !           366:     GlobalUnlock(hCards);
        !           367:     }
        !           368: 
        !           369: 
        !           370: 
        !           371: /*********************************************************************/
        !           372: /* CardfileSize - 
        !           373: /*    Process size message.  Repositions child edit window if in 
        !           374: /* Card mode; saves size in global variables.
        !           375: /*
        !           376: /* Same in Windows and PM.
        !           377: /*********************************************************************/
        !           378: 
        !           379: void CardfileSize(hWindow, newWidth, newHeight)
        !           380: HWND    hWindow;
        !           381: int newWidth;
        !           382: int newHeight;
        !           383:     {
        !           384:     int yCard;
        !           385: 
        !           386:     /* save width and height */
        !           387:     cxMainWindow = newWidth;
        !           388:     cyMainWindow = newHeight;
        !           389: 
        !           390:     /* calculate coordinates of bottom left card */
        !           391:     yFirstCard = (newHeight - BOTTOMMARGIN) - CardHeight;
        !           392: 
        !           393:     if ((CharFixHeight / 2) > yFirstCard)
        !           394:         yFirstCard = CharFixHeight / 2;
        !           395: 
        !           396:     /* figure out where edit control should go */
        !           397:     yCard = yFirstCard + 1 + CharFixHeight + 1 + 2;
        !           398: 
        !           399:     xFirstCard = LEFTMARGIN;
        !           400: 
        !           401:     /* if edit control exists, move it to new location */
        !           402:     TRANSLATE_COORDS( cyMainWindow );
        !           403: 
        !           404:     if (hCardWnd)
        !           405:         MoveWindow(hCardWnd, xFirstCard+1, yCard, 
        !           406:                    (LINELENGTH*CharFixWidth)+1, CARDLINES*CharFixHeight, 
        !           407:                    FALSE);
        !           408: 
        !           409:     TRANSLATE_COORDS( 0 );
        !           410:     if (CardPhone == IDM_PHONEBOOK)
        !           411:         SetScrRangeAndPos();
        !           412:     }
        !           413: 

unix.superglobalmegacorp.com

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