Annotation of mstools/samples/sdktools/imagedit/propbar.c, revision 1.1.1.1

1.1       root        1: /****************************************************************************/
                      2: /*                                                                          */
                      3: /*                         Microsoft Confidential                           */
                      4: /*                                                                          */
                      5: /*                 Copyright (c) Microsoft Corp.  1987, 1990                */
                      6: /*                           All Rights Reserved                            */
                      7: /*                                                                          */
                      8: /****************************************************************************/
                      9: /****************************** Module Header *******************************
                     10: * Module Name: propbar.c
                     11: *
                     12: * Support for the Properties Bar.
                     13: *
                     14: * History:
                     15: *
                     16: ****************************************************************************/
                     17: 
                     18: #include "imagedit.h"
                     19: #include "dialogs.h"
                     20: 
                     21: 
                     22: #define IMPOSSIBLEVALUE     0x7FFF
                     23: 
                     24: STATICFN VOID NEAR PropBarProcessCommand(HWND hwnd, INT idCtrl,
                     25:     INT NotifyCode);
                     26: 
                     27: /*
                     28:  * Cache variables.  These cache the values of some displayed fields.
                     29:  * The field is updated only if the value changes, which avoids flicker.
                     30:  * They are initialized to a large value so that the first "set" to
                     31:  * any value will always cause the field to be updated.
                     32:  */
                     33: static INT xSave = IMPOSSIBLEVALUE;
                     34: static INT ySave = IMPOSSIBLEVALUE;
                     35: static INT cxSave = IMPOSSIBLEVALUE;
                     36: static INT cySave = IMPOSSIBLEVALUE;
                     37: static INT xHotSpotSave = IMPOSSIBLEVALUE;
                     38: static INT yHotSpotSave = IMPOSSIBLEVALUE;
                     39: 
                     40: 
                     41: 
                     42: /************************************************************************
                     43: * PropBarDlgProc
                     44: *
                     45: * This is the dialog procedure for the PropBar ribbon window.
                     46: *
                     47: * History:
                     48: *
                     49: ************************************************************************/
                     50: 
                     51: DIALOGPROC PropBarDlgProc(
                     52:     HWND hwnd,
                     53:     UINT msg,
                     54:     WPARAM wParam,
                     55:     LPARAM lParam)
                     56: {
                     57:     switch (msg) {
                     58:         case WM_INITDIALOG:
                     59:             /*
                     60:              * Set this global right away.  Other routines that
                     61:              * might be called before CreateDialog returns depend
                     62:              * on this global.
                     63:              */
                     64:             ghwndPropBar = hwnd;
                     65: 
                     66:             PropBarUpdate();
                     67: 
                     68:             /*
                     69:              * Return TRUE so that the dialog manager does NOT
                     70:              * set the focus for me.  This prevents the PropBar
                     71:              * window from initially having the focus when the
                     72:              * editor is started.
                     73:              */
                     74:             return TRUE;
                     75: 
                     76:         case WM_PAINT:
                     77:             {
                     78:                 HDC hdc;
                     79:                 RECT rc;
                     80:                 PAINTSTRUCT ps;
                     81:                 HPEN hpenWindowFrame;
                     82: 
                     83:                 /*
                     84:                  * Draw our border lines.
                     85:                  */
                     86:                 GetClientRect(hwnd, &rc);
                     87:                 hdc = BeginPaint(hwnd, &ps);
                     88: 
                     89:                 SelectObject(hdc, GetStockObject(WHITE_PEN));
                     90:                 MoveToEx(hdc, rc.left, rc.top, NULL);
                     91:                 LineTo(hdc, rc.right, rc.top);
                     92: 
                     93:                 SelectObject(hdc, hpenDarkGray);
                     94:                 MoveToEx(hdc, rc.left, (rc.top + gcyPropBar) - gcyBorder - 1, NULL);
                     95:                 LineTo(hdc, rc.right, (rc.top + gcyPropBar) - gcyBorder - 1);
                     96: 
                     97:                 hpenWindowFrame = CreatePen(PS_SOLID, gcyBorder,
                     98:                         GetSysColor(COLOR_WINDOWFRAME));
                     99:                 SelectObject(hdc, hpenWindowFrame);
                    100:                 MoveToEx(hdc, rc.left, (rc.top + gcyPropBar) - gcyBorder, NULL);
                    101:                 LineTo(hdc, rc.right, (rc.top + gcyPropBar) - gcyBorder);
                    102: 
                    103:                 EndPaint(hwnd, &ps);
                    104:                 DeleteObject(hpenWindowFrame);
                    105:             }
                    106: 
                    107:             break;
                    108: 
                    109:         case 0x0019:
                    110:         case WM_CTLCOLORBTN:
                    111:         case WM_CTLCOLORDLG:
                    112:         case WM_CTLCOLORLISTBOX:
                    113:         case WM_CTLCOLORSTATIC:
                    114:             switch ((WORD)(msg - WM_CTLCOLORMSGBOX)) {
                    115:                 case CTLCOLOR_BTN:
                    116:                 case CTLCOLOR_DLG:
                    117:                 case CTLCOLOR_LISTBOX:
                    118:                     return (BOOL)GetStockObject(LTGRAY_BRUSH);
                    119: 
                    120:                 case CTLCOLOR_STATIC:
                    121:                     SetBkColor((HDC)(wParam),
                    122:                             RGB_LIGHTGRAY);
                    123:                     return (BOOL)GetStockObject(LTGRAY_BRUSH);
                    124:             }
                    125: 
                    126:             return (BOOL)NULL;
                    127: 
                    128:         case WM_COMMAND:
                    129:             PropBarProcessCommand(hwnd,
                    130:                     LOWORD(wParam),
                    131:                     HIWORD(wParam));
                    132:             break;
                    133: 
                    134:         case WM_DESTROY:
                    135:             /*
                    136:              * Null out the global window handle for the prop bar
                    137:              * for safety's sake.
                    138:              */
                    139:             ghwndPropBar = NULL;
                    140: 
                    141:             break;
                    142: 
                    143:         default:
                    144:             return FALSE;
                    145:     }
                    146: 
                    147:     return FALSE;
                    148: }
                    149: 
                    150: 
                    151: 
                    152: /************************************************************************
                    153: * PropBarProcessCommand
                    154: *
                    155: *
                    156: * Arguments:
                    157: *   HWND hwnd        - The window handle.
                    158: *   INT idCtrl       - The id of the control the WM_COMMAND is for.
                    159: *   INT NotifyCode   - The control's notification code.
                    160: *
                    161: * History:
                    162: *
                    163: ************************************************************************/
                    164: 
                    165: STATICFN VOID NEAR PropBarProcessCommand(
                    166:     HWND hwnd,
                    167:     INT idCtrl,
                    168:     INT NotifyCode)
                    169: {
                    170:     INT iSelect;
                    171:     PIMAGEINFO pImage;
                    172: 
                    173:     switch (idCtrl) {
                    174:         case DID_PROPBARIMAGE:
                    175:             if (NotifyCode == CBN_SELCHANGE) {
                    176:                 if ((iSelect = (INT)SendDlgItemMessage(hwnd,
                    177:                         DID_PROPBARIMAGE, CB_GETCURSEL, 0, 0L)) != CB_ERR) {
                    178:                     /*
                    179:                      * Get a pointer to the selected image (stored in the
                    180:                      * listbox items data field).
                    181:                      */
                    182:                     pImage = (PIMAGEINFO)SendDlgItemMessage(hwnd,
                    183:                             DID_PROPBARIMAGE, CB_GETITEMDATA, iSelect, 0L);
                    184: 
                    185:                     /*
                    186:                      * Open the image.  If it fails, be sure to set the
                    187:                      * combobox selection back to the current image.
                    188:                      */
                    189:                     if (!ImageOpen(pImage)) {
                    190:                         PropBarSetImage(gpImageCur);
                    191:                         break;
                    192:                     }
                    193: 
                    194:                     SetFocus(ghwndMain);
                    195:                 }
                    196:             }
                    197: 
                    198:             break;
                    199: 
                    200:         case IDOK:
                    201:         case IDCANCEL:
                    202:             SetFocus(ghwndMain);
                    203:             break;
                    204:     }
                    205: }
                    206: 
                    207: 
                    208: 
                    209: /************************************************************************
                    210: * PropBarUpdate
                    211: *
                    212: * This function updates the Properties Bar for the selection of a
                    213: * new image or file.  It fills the Image combo with the names of
                    214: * the images in the current file and shows/hides the HotSpot display.
                    215: *
                    216: * History:
                    217: *
                    218: ************************************************************************/
                    219: 
                    220: VOID PropBarUpdate(VOID)
                    221: {
                    222:     HWND hwndCombo;
                    223:     PIMAGEINFO pImage;
                    224:     INT idLabel;
                    225:     INT i;
                    226: 
                    227:     if (gpImageCur || gpszFileName) {
                    228:         switch (giType) {
                    229:             case FT_BITMAP:
                    230:                 idLabel = IDS_BITMAPIMAGELABEL;
                    231:                 break;
                    232: 
                    233:             case FT_ICON:
                    234:                 idLabel = IDS_ICONIMAGELABEL;
                    235:                 break;
                    236: 
                    237:             case FT_CURSOR:
                    238:                 idLabel = IDS_CURSORIMAGELABEL;
                    239:                 break;
                    240:         }
                    241:     }
                    242:     else {
                    243:         idLabel = IDS_NULL;
                    244:     }
                    245: 
                    246:     SetDlgItemText(ghwndPropBar, DID_PROPBARIMAGELABEL, ids(idLabel));
                    247: 
                    248:     /*
                    249:      * Get the handle to the combo box and clear out all items.
                    250:      */
                    251:     hwndCombo = GetDlgItem(ghwndPropBar, DID_PROPBARIMAGE);
                    252:     SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
                    253: 
                    254:     /*
                    255:      * Fill the combo box with the images.
                    256:      */
                    257:     for (pImage = gpImageHead; pImage; pImage = pImage->pImageNext) {
                    258:         i = (INT)SendMessage(hwndCombo, CB_INSERTSTRING, (WPARAM)-1,
                    259:                 pImage->pDevice ?
                    260:                 (DWORD)(LPSTR)pImage->pDevice->szDesc :
                    261:                 (DWORD)(LPSTR)ids(IDS_UNKNOWNIMAGEFORMAT));
                    262: 
                    263:         SendMessage(hwndCombo, CB_SETITEMDATA, i, (DWORD)(LPSTR)pImage);
                    264:     }
                    265: 
                    266:     /*
                    267:      * Select the current image.
                    268:      */
                    269:     PropBarSetImage(gpImageCur);
                    270: 
                    271:     /*
                    272:      * Show/Hide the HotSpot info depending on whether this is
                    273:      * a cursor or not.
                    274:      */
                    275:     if (giType == FT_CURSOR) {
                    276:         if (gpImageCur)
                    277:             PropBarSetHotSpot(gpImageCur->iHotspotX, gpImageCur->iHotspotY);
                    278:         else
                    279:             PropBarClearHotSpot();
                    280: 
                    281:         PropBarShowHotSpot(TRUE);
                    282:     }
                    283:     else {
                    284:         PropBarShowHotSpot(FALSE);
                    285:     }
                    286: }
                    287: 
                    288: 
                    289: 
                    290: /************************************************************************
                    291: * PropBarSetImage
                    292: *
                    293: *
                    294: * History:
                    295: *
                    296: ************************************************************************/
                    297: 
                    298: VOID PropBarSetImage(
                    299:     PIMAGEINFO pImage)
                    300: {
                    301:     if (pImage)
                    302:         SendDlgItemMessage(ghwndPropBar, DID_PROPBARIMAGE, CB_SELECTSTRING,
                    303:                 (WPARAM)-1, (DWORD)(LPSTR)pImage->pDevice->szDesc);
                    304:     else
                    305:         SendDlgItemMessage(ghwndPropBar, DID_PROPBARIMAGE, CB_SETCURSEL,
                    306:                 (WPARAM)-1, 0);
                    307: }
                    308: 
                    309: 
                    310: 
                    311: /************************************************************************
                    312: * PropBarSetPos
                    313: *
                    314: *
                    315: * Arguments:
                    316: *
                    317: * History:
                    318: *
                    319: ************************************************************************/
                    320: 
                    321: VOID PropBarSetPos(
                    322:     INT x,
                    323:     INT y)
                    324: {
                    325:     CHAR szBuf[CCHTEXTMAX];
                    326: 
                    327:     if (x != xSave || y != ySave) {
                    328:         wsprintf(szBuf, "%d, %d", x, y);
                    329:         SetDlgItemText(ghwndPropBar, DID_PROPBARPOS, szBuf);
                    330: 
                    331:         /*
                    332:          *  Save them for the next time.
                    333:          */
                    334:         xSave = x;
                    335:         ySave = y;
                    336:     }
                    337: }
                    338: 
                    339: 
                    340: 
                    341: /************************************************************************
                    342: * PropBarClearPos
                    343: *
                    344: *
                    345: * Arguments:
                    346: *
                    347: * History:
                    348: *
                    349: ************************************************************************/
                    350: 
                    351: VOID PropBarClearPos(VOID)
                    352: {
                    353:     SetDlgItemText(ghwndPropBar, DID_PROPBARPOS, "");
                    354: 
                    355:     /*
                    356:      * Reset the cache variables so that the next "set" of
                    357:      * the position is sure to update the display fields.
                    358:      */
                    359:     xSave = IMPOSSIBLEVALUE;
                    360:     ySave = IMPOSSIBLEVALUE;
                    361: }
                    362: 
                    363: 
                    364: 
                    365: /************************************************************************
                    366: * PropBarSetSize
                    367: *
                    368: *
                    369: * Arguments:
                    370: *
                    371: * History:
                    372: *
                    373: ************************************************************************/
                    374: 
                    375: VOID PropBarSetSize(
                    376:     POINT pt1,
                    377:     POINT pt2)
                    378: {
                    379:     CHAR szBuf[CCHTEXTMAX];
                    380:     INT cx;
                    381:     INT cy;
                    382: 
                    383:     NormalizePoints(&pt1, &pt2);
                    384:     cx = ((pt2.x - pt1.x) / gZoomFactor) + 1;
                    385:     cy = ((pt2.y - pt1.y) / gZoomFactor) + 1;
                    386: 
                    387:     if (cx != cxSave || cy != cySave) {
                    388:         wsprintf(szBuf, "%dx%d", cx, cy);
                    389:         SetDlgItemText(ghwndPropBar, DID_PROPBARSIZE, szBuf);
                    390: 
                    391:         /*
                    392:          *  Save them for the next time.
                    393:          */
                    394:         cxSave = cx;
                    395:         cySave = cy;
                    396:     }
                    397: }
                    398: 
                    399: 
                    400: 
                    401: /************************************************************************
                    402: * PropBarClearSize
                    403: *
                    404: *
                    405: * Arguments:
                    406: *
                    407: * History:
                    408: *
                    409: ************************************************************************/
                    410: 
                    411: VOID PropBarClearSize(VOID)
                    412: {
                    413:     SetDlgItemText(ghwndPropBar, DID_PROPBARSIZE, "");
                    414: 
                    415:     /*
                    416:      * Reset the cache variables so that the next "set" of
                    417:      * the position is sure to update the display fields.
                    418:      */
                    419:     cxSave = IMPOSSIBLEVALUE;
                    420:     cySave = IMPOSSIBLEVALUE;
                    421: }
                    422: 
                    423: 
                    424: 
                    425: /************************************************************************
                    426: * PropBarSetHotSpot
                    427: *
                    428: *
                    429: * Arguments:
                    430: *
                    431: * History:
                    432: *
                    433: ************************************************************************/
                    434: 
                    435: VOID PropBarSetHotSpot(
                    436:     INT xHotSpot,
                    437:     INT yHotSpot)
                    438: {
                    439:     CHAR szBuf[CCHTEXTMAX];
                    440: 
                    441:     if (xHotSpot != xHotSpotSave || yHotSpot != yHotSpotSave) {
                    442:         wsprintf(szBuf, "%d, %d", xHotSpot, yHotSpot);
                    443:         SetDlgItemText(ghwndPropBar, DID_PROPBARHOTSPOT, szBuf);
                    444: 
                    445:         /*
                    446:          *  Save them for the next time.
                    447:          */
                    448:         xHotSpotSave = xHotSpot;
                    449:         yHotSpotSave = yHotSpot;
                    450:     }
                    451: }
                    452: 
                    453: 
                    454: 
                    455: /************************************************************************
                    456: * PropBarClearHotSpot
                    457: *
                    458: *
                    459: * Arguments:
                    460: *
                    461: * History:
                    462: *
                    463: ************************************************************************/
                    464: 
                    465: VOID PropBarClearHotSpot(VOID)
                    466: {
                    467:     SetDlgItemText(ghwndPropBar, DID_PROPBARHOTSPOT, "");
                    468: 
                    469:     /*
                    470:      * Reset the cache variables so that the next "set" of
                    471:      * the hotspot is sure to update the display fields.
                    472:      */
                    473:     xHotSpotSave = IMPOSSIBLEVALUE;
                    474:     yHotSpotSave = IMPOSSIBLEVALUE;
                    475: }
                    476: 
                    477: 
                    478: 
                    479: /************************************************************************
                    480: * PropBarShowHotSpot
                    481: *
                    482: *
                    483: * Arguments:
                    484: *
                    485: * History:
                    486: *
                    487: ************************************************************************/
                    488: VOID PropBarShowHotSpot(
                    489:     BOOL fShow)
                    490: {
                    491:     ShowWindow(GetDlgItem(ghwndPropBar, DID_PROPBARHOTSPOTLABEL),
                    492:             fShow ? SW_SHOWNA : SW_HIDE);
                    493:     ShowWindow(GetDlgItem(ghwndPropBar, DID_PROPBARHOTSPOT),
                    494:             fShow ? SW_SHOWNA : SW_HIDE);
                    495: }

unix.superglobalmegacorp.com

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