Annotation of mstools/samples/sdktools/imagedit/devinfo.c, revision 1.1

1.1     ! root        1: /****************************************************************************/
        !             2: /*                                                                          */
        !             3: /*                         Microsoft Confidential                           */
        !             4: /*                                                                          */
        !             5: /*                 Copyright (c) Microsoft Corp.  1987, 1991                */
        !             6: /*                           All Rights Reserved                            */
        !             7: /*                                                                          */
        !             8: /****************************************************************************/
        !             9: /****************************** Module Header *******************************
        !            10: * Module Name: devinfo.c
        !            11: *
        !            12: * Contains routines for manipulating the linked list of known target
        !            13: * devices for icons and cursors.
        !            14: *
        !            15: * History:
        !            16: *
        !            17: ****************************************************************************/
        !            18: 
        !            19: #include "imagedit.h"
        !            20: 
        !            21: #include <stdio.h>
        !            22: #include <stdlib.h>
        !            23: #include <string.h>
        !            24: 
        !            25: 
        !            26: STATICFN VOID ProcessDeviceSection(INT iType);
        !            27: STATICFN BOOL ParseDeviceLine(PSTR pszLine, PINT pnColors, PINT pcx,
        !            28:     PINT pcy);
        !            29: 
        !            30: 
        !            31: 
        !            32: /************************************************************************
        !            33: * InitDeviceList
        !            34: *
        !            35: *
        !            36: *
        !            37: * Arguments:
        !            38: *
        !            39: * History:
        !            40: *
        !            41: ************************************************************************/
        !            42: 
        !            43: VOID InitDeviceList(VOID)
        !            44: {
        !            45:     /*
        !            46:      * Allocate the standard icon devices.
        !            47:      */
        !            48:     DeviceLinkAlloc(FT_ICON, ids(IDS_ICONDEVNAMEEGAVGA), 16, 32, 32);
        !            49:     DeviceLinkAlloc(FT_ICON, ids(IDS_ICONDEVNAMEMONO), 2, 32, 32);
        !            50:     DeviceLinkAlloc(FT_ICON, ids(IDS_ICONDEVNAMECGA), 2, 32, 16);
        !            51: 
        !            52:     ProcessDeviceSection(FT_ICON);
        !            53: 
        !            54:     /*
        !            55:      * Allocate the standard cursor devices.
        !            56:      */
        !            57:     DeviceLinkAlloc(FT_CURSOR, ids(IDS_CURDEVNAMEVGAMONO), 2, 32, 32);
        !            58:     DeviceLinkAlloc(FT_CURSOR, ids(IDS_CURDEVNAMEVGACOLOR), 16, 32, 32);
        !            59: 
        !            60:     ProcessDeviceSection(FT_CURSOR);
        !            61: }
        !            62: 
        !            63: 
        !            64: 
        !            65: /************************************************************************
        !            66: * ProcessDeviceSection
        !            67: *
        !            68: *
        !            69: *
        !            70: * Arguments:
        !            71: *
        !            72: * History:
        !            73: *
        !            74: ************************************************************************/
        !            75: 
        !            76: STATICFN VOID ProcessDeviceSection(
        !            77:     INT iType)
        !            78: {
        !            79:     PSTR pszSectionName;
        !            80:     CHAR szValueBuf[CCHTEXTMAX];
        !            81:     CHAR szKeyNameBuf[CCHTEXTMAX];
        !            82:     PSTR pszKeyName;
        !            83:     INT nColors;
        !            84:     INT cx;
        !            85:     INT cy;
        !            86: 
        !            87:     if (iType == FT_ICON) {
        !            88:         pszSectionName = ids(IDS_ICONINISECTION);
        !            89:     }
        !            90:     else {
        !            91:         pszSectionName = ids(IDS_CURSORINISECTION);
        !            92:     }
        !            93: 
        !            94:     if (!GetPrivateProfileString(pszSectionName, NULL, "",
        !            95:             szKeyNameBuf, sizeof(szKeyNameBuf), ids(IDS_IMAGEDITINI)))
        !            96:         return;
        !            97: 
        !            98:     pszKeyName = szKeyNameBuf;
        !            99:     while (*pszKeyName) {
        !           100:         if (GetPrivateProfileString(pszSectionName, pszKeyName, "",
        !           101:                 szValueBuf, sizeof(szValueBuf), ids(IDS_IMAGEDITINI))) {
        !           102:             if (ParseDeviceLine(szValueBuf, &nColors, &cx, &cy))
        !           103:                 DeviceLinkAlloc(iType, pszKeyName, nColors, cx, cy);
        !           104:         }
        !           105: 
        !           106:         pszKeyName += strlen(pszKeyName) + 1;
        !           107:     }
        !           108: }
        !           109: 
        !           110: 
        !           111: 
        !           112: /************************************************************************
        !           113: * ParseDeviceLine
        !           114: *
        !           115: *
        !           116: *
        !           117: * Arguments:
        !           118: *
        !           119: * History:
        !           120: *
        !           121: ************************************************************************/
        !           122: 
        !           123: STATICFN BOOL ParseDeviceLine(
        !           124:     PSTR pszLine,
        !           125:     PINT pnColors,
        !           126:     PINT pcx,
        !           127:     PINT pcy)
        !           128: {
        !           129:     static CHAR szSep[] = " ,";
        !           130:     PSTR pstr;
        !           131: 
        !           132:     if (!(pstr = strtok(pszLine, szSep)))
        !           133:         return FALSE;
        !           134: 
        !           135:     *pnColors = atoi(pstr);
        !           136: 
        !           137:     if (!(pstr = strtok(NULL, szSep)))
        !           138:         return FALSE;
        !           139: 
        !           140:     *pcx = atoi(pstr);
        !           141: 
        !           142:     if (!(pstr = strtok(NULL, szSep)))
        !           143:         return FALSE;
        !           144: 
        !           145:     *pcy = atoi(pstr);
        !           146: 
        !           147:     return TRUE;
        !           148: }
        !           149: 
        !           150: 
        !           151: 
        !           152: /************************************************************************
        !           153: * DeviceLinkAlloc
        !           154: *
        !           155: * Allocates a DEVICE structure, initializes it with the given values
        !           156: * and adds it to the appropriate linked list.  Because these are
        !           157: * specified only at init time, there is no need to ever free them.
        !           158: *
        !           159: * There is a special case if the image type is FT_BITMAP.  Because
        !           160: * there is only one type of bitmap image device at any one time,
        !           161: * this routine does not really allocate a link for these.  Instead,
        !           162: * it uses a static structure for bitmaps.  It will be set to the
        !           163: * given values and a pointer to it will be returned.  This means
        !           164: * that for bitmaps, this function must be called every time that
        !           165: * the current bitmap image changes to set up the proper values in
        !           166: * the structure.
        !           167: *
        !           168: * Arguments:
        !           169: *   INT iType    - Type of image.  FT_* constant.
        !           170: *   PSTR pszName - Device name ("VGA", for example).
        !           171: *   INT nColors  - Number of colors.
        !           172: *   INT cx       - Width of image.
        !           173: *   INT cy       - Height of image.
        !           174: *
        !           175: * History:
        !           176: *
        !           177: ************************************************************************/
        !           178: 
        !           179: PDEVICE DeviceLinkAlloc(
        !           180:     INT iType,
        !           181:     PSTR pszName,
        !           182:     INT nColors,
        !           183:     INT cx,
        !           184:     INT cy)
        !           185: {
        !           186:     static DEVICE DeviceBitmap;     // Device structure for bitmaps.
        !           187:     PDEVICE pDevice;
        !           188:     PDEVICE pDeviceT;
        !           189:     PDEVICE *ppDeviceHead;
        !           190: 
        !           191:     /*
        !           192:      * Currently we only support 1 and 4 plane devices.
        !           193:      */
        !           194:     if (nColors != 2 && nColors != 16) {
        !           195:         Message(MSG_BADDEVICECOLORS);
        !           196:         return NULL;
        !           197:     }
        !           198: 
        !           199:     /*
        !           200:      * There is a limit to the size of image we will edit.  For icons
        !           201:      * and cursors, the field that carries the dimensions is a byte,
        !           202:      * so the size cannot be greater than 256.  This is also what
        !           203:      * we limit bitmaps to.
        !           204:      */
        !           205:     if (cx < 1 || cx > MAXIMAGEDIM || cy < 1 || cy > MAXIMAGEDIM) {
        !           206:         Message(MSG_BADDEVICESIZE, MAXIMAGEDIM);
        !           207:         return NULL;
        !           208:     }
        !           209: 
        !           210:     /*
        !           211:      * For bitmaps, don't really allocate a link, just reuse the
        !           212:      * static DEVICE structure used for bitmaps.
        !           213:      */
        !           214:     if (iType == FT_BITMAP) {
        !           215:         pDevice = &DeviceBitmap;
        !           216:     }
        !           217:     else {
        !           218:         if (!(pDevice = (PDEVICE)MyAlloc(sizeof(DEVICE))))
        !           219:             return NULL;
        !           220: 
        !           221:         switch (iType) {
        !           222:             case FT_ICON:
        !           223:                 ppDeviceHead = &gpIconDeviceHead;
        !           224:                 gnIconDevices++;
        !           225:                 break;
        !           226: 
        !           227:             case FT_CURSOR:
        !           228:                 ppDeviceHead = &gpCursorDeviceHead;
        !           229:                 gnCursorDevices++;
        !           230:                 break;
        !           231:         }
        !           232:     }
        !           233: 
        !           234:     pDevice->pDeviceNext = NULL;
        !           235:     pDevice->iType = iType;
        !           236:     pDevice->nColors = nColors;
        !           237:     pDevice->cx = cx;
        !           238:     pDevice->cy = cy;
        !           239: 
        !           240:     if (pszName) {
        !           241:         strcpy(pDevice->szName, pszName);
        !           242:         wsprintf(pDevice->szDesc, "%s %d-Color %dx%d",  //   hardcoded strings!
        !           243:                 (LPSTR)pszName, nColors, cx, cy);
        !           244:     }
        !           245:     else {
        !           246:         *pDevice->szName = '\0';
        !           247:         wsprintf(pDevice->szDesc, "%d-Color %dx%d", nColors, cx, cy);
        !           248:     }
        !           249: 
        !           250:     /*
        !           251:      * Because there is only one bitmap link, there is no need
        !           252:      * for a list for these, only icons and cursors.
        !           253:      */
        !           254:     if (iType != FT_BITMAP) {
        !           255:         /*
        !           256:          * Insert the link in the specified list.
        !           257:          */
        !           258:         if (!(*ppDeviceHead)) {
        !           259:             /*
        !           260:              * This is the first one.  Start the list.
        !           261:              */
        !           262:             *ppDeviceHead = pDevice;
        !           263:         }
        !           264:         else {
        !           265:             /*
        !           266:              * Find the end of the list and tack on the new link.
        !           267:              */
        !           268:             for (pDeviceT = *ppDeviceHead; pDeviceT->pDeviceNext;
        !           269:                     pDeviceT = pDeviceT->pDeviceNext)
        !           270:                 ;
        !           271: 
        !           272:             pDeviceT->pDeviceNext = pDevice;
        !           273:         }
        !           274:     }
        !           275: 
        !           276:     return pDevice;
        !           277: }
        !           278: 
        !           279: 
        !           280: 
        !           281: /************************************************************************
        !           282: * DeviceLinkFind
        !           283: *
        !           284: *
        !           285: *
        !           286: * Arguments:
        !           287: *
        !           288: * History:
        !           289: *
        !           290: ************************************************************************/
        !           291: 
        !           292: PDEVICE DeviceLinkFind(
        !           293:     PDEVICE pDeviceHead,
        !           294:     INT nColors,
        !           295:     INT cx,
        !           296:     INT cy)
        !           297: {
        !           298:     PDEVICE pDevice;
        !           299: 
        !           300:     /*
        !           301:      * Search the specified list.
        !           302:      */
        !           303:     for (pDevice = pDeviceHead; pDevice; pDevice = pDevice->pDeviceNext) {
        !           304:         /*
        !           305:          * Is this a match?
        !           306:          */
        !           307:         if (pDevice->nColors == nColors && pDevice->cx == cx &&
        !           308:                 pDevice->cy == cy)
        !           309:             break;
        !           310:     }
        !           311: 
        !           312:     return pDevice;
        !           313: }
        !           314: 
        !           315: 
        !           316: 
        !           317: /************************************************************************
        !           318: * DeviceLinkUsed
        !           319: *
        !           320: * This function returns TRUE if the specified device is used in
        !           321: * the current image list.
        !           322: *
        !           323: * Arguments:
        !           324: *   PDEVICE pDevice - Device to look for.
        !           325: *
        !           326: * History:
        !           327: *
        !           328: ************************************************************************/
        !           329: 
        !           330: BOOL DeviceLinkUsed(
        !           331:     PDEVICE pDevice)
        !           332: {
        !           333:     PIMAGEINFO pImage;
        !           334: 
        !           335:     for (pImage = gpImageHead; pImage; pImage = pImage->pImageNext) {
        !           336:         if (pImage->pDevice == pDevice)
        !           337:             return TRUE;
        !           338:     }
        !           339: 
        !           340:     return FALSE;
        !           341: }

unix.superglobalmegacorp.com

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