Annotation of mstools/ole20/samples/ole2ui/hatch.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * HATCH.C
        !             3:  *
        !             4:  * Miscellaneous API's to generate hatch window for in-place active
        !             5:  * objects. This is part of the OLE 2.0 User Interface Support Library.
        !             6:  *
        !             7:  * Copyright (c)1993 Microsoft Corporation, All Right Reserved
        !             8:  */
        !             9: 
        !            10: #define STRICT  1
        !            11: #include "ole2ui.h"
        !            12: 
        !            13: // offsets in the extra bytes stored with the hatch window
        !            14: #define EB_HATCHWIDTH       0
        !            15: #define EB_HATCHRECT_LEFT   2
        !            16: #define EB_HATCHRECT_TOP    4
        !            17: #define EB_HATCHRECT_RIGHT  6
        !            18: #define EB_HATCHRECT_BOTTOM 8
        !            19: 
        !            20: // class name of hatch window
        !            21: #define CLASS_HATCH     "Hatch Window"
        !            22: 
        !            23: // local function prototypes
        !            24: LRESULT FAR PASCAL EXPORT HatchWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
        !            25: 
        !            26: 
        !            27: /* 
        !            28:  * HatchRegisterClass
        !            29:  *
        !            30:  * Purpose:
        !            31:  *  Register the hatch window
        !            32:  *
        !            33:  * Parameters:
        !            34:  *  hInst           Process instance
        !            35:  *
        !            36:  * Return Value:
        !            37:  *  TRUE            if successful
        !            38:  *  FALSE           if failed
        !            39:  * 
        !            40:  */
        !            41: STDAPI_(BOOL) RegisterHatchWindowClass(HINSTANCE hInst)
        !            42: {
        !            43:     WNDCLASS wc;
        !            44:     
        !            45:     // Register Hatch Window Class
        !            46:     wc.style = CS_BYTEALIGNWINDOW;
        !            47:     wc.lpfnWndProc = HatchWndProc;
        !            48:     wc.cbClsExtra = 0;
        !            49:     wc.cbWndExtra = 5 * sizeof(int);    // extra bytes stores
        !            50:                                         //     uHatchWidth 
        !            51:                                         //     rcHatchRect
        !            52:     wc.hInstance = hInst;
        !            53:     wc.hIcon = NULL;
        !            54:     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        !            55:     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        !            56:     wc.lpszMenuName = NULL;
        !            57:     wc.lpszClassName = CLASS_HATCH;
        !            58: 
        !            59:     if (!RegisterClass(&wc))
        !            60:         return FALSE;
        !            61:     else
        !            62:         return TRUE;
        !            63: }
        !            64: 
        !            65: 
        !            66: /* 
        !            67:  * CreateHatchWindow
        !            68:  *
        !            69:  * Purpose:
        !            70:  *  Create the hatch window
        !            71:  *
        !            72:  * Parameters:
        !            73:  *  hWndParent          parent of hatch window
        !            74:  *  hInst               instance handle
        !            75:  *
        !            76:  * Return Value:
        !            77:  *  pointer to hatch window         if successful
        !            78:  *  NULL                            if failed
        !            79:  * 
        !            80:  */
        !            81: STDAPI_(HWND) CreateHatchWindow(HWND hWndParent, HINSTANCE hInst)
        !            82: {
        !            83:     HWND         hWnd;
        !            84:     
        !            85:     if (!hWndParent || !hInst)
        !            86:         return NULL;
        !            87: 
        !            88:     hWnd = CreateWindow(
        !            89:         CLASS_HATCH,
        !            90:         "Hatch Window",
        !            91:         WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
        !            92:         0, 0, 0, 0,
        !            93:         hWndParent,
        !            94:         (HMENU)NULL,
        !            95:         hInst,
        !            96:         0L
        !            97:     );
        !            98: 
        !            99:     if (!hWnd)
        !           100:         return NULL;
        !           101:          
        !           102:     return hWnd;
        !           103: }
        !           104: 
        !           105: /* 
        !           106:  *  GetHatchWidth
        !           107:  *
        !           108:  *  Purpose:
        !           109:  *      Get width of hatch border
        !           110:  *
        !           111:  *  Parameters:
        !           112:  *      hWndHatch       hatch window handle
        !           113:  *
        !           114:  *  Return Value:
        !           115:  *      width of the hatch border
        !           116:  */
        !           117: STDAPI_(UINT) GetHatchWidth(HWND hWndHatch)
        !           118: {
        !           119:     if (!IsWindow(hWndHatch))
        !           120:         return 0;
        !           121: 
        !           122:     return (UINT)GetWindowWord(hWndHatch, EB_HATCHWIDTH);
        !           123: }
        !           124: 
        !           125: /* 
        !           126:  *  GetHatchRect
        !           127:  *
        !           128:  *  Purpose:
        !           129:  *      Get hatch rect. this is the size of the hatch window if it were 
        !           130:  *      not clipped by the ClipRect.
        !           131:  *
        !           132:  *  Parameters:
        !           133:  *      hWndHatch       hatch window handle
        !           134:  *      lprcHatchRect   hatch rect
        !           135:  *
        !           136:  *  Return Value:
        !           137:  *      none
        !           138:  */
        !           139: STDAPI_(void) GetHatchRect(HWND hWndHatch, LPRECT lprcHatchRect)
        !           140: {
        !           141:     if (!IsWindow(hWndHatch)) {
        !           142:         SetRect(lprcHatchRect, 0, 0, 0, 0);
        !           143:         return;
        !           144:     }
        !           145: 
        !           146:     lprcHatchRect->left = GetWindowWord(hWndHatch, EB_HATCHRECT_LEFT);
        !           147:     lprcHatchRect->top = GetWindowWord(hWndHatch, EB_HATCHRECT_TOP);
        !           148:     lprcHatchRect->right = GetWindowWord(hWndHatch, EB_HATCHRECT_RIGHT);
        !           149:     lprcHatchRect->bottom = GetWindowWord(hWndHatch, EB_HATCHRECT_BOTTOM);
        !           150: }
        !           151: 
        !           152: 
        !           153: /* SetHatchRect
        !           154:  *
        !           155:  *
        !           156:  *  Purpose:
        !           157:  *      Store hatch rect with HatchRect window. 
        !           158:  *      this rect is the size of the hatch window if it were 
        !           159:  *      not clipped by the ClipRect.
        !           160:  *
        !           161:  *  Parameters:
        !           162:  *      hWndHatch       hatch window handle
        !           163:  *      lprcHatchRect   hatch rect
        !           164:  *
        !           165:  *  Return Value:
        !           166:  *      none
        !           167:  */
        !           168: STDAPI_(void) SetHatchRect(HWND hWndHatch, LPRECT lprcHatchRect)
        !           169: {
        !           170:     if (!IsWindow(hWndHatch))
        !           171:         return;
        !           172:     
        !           173:     SetWindowWord(hWndHatch, EB_HATCHRECT_LEFT,  (WORD)lprcHatchRect->left);
        !           174:     SetWindowWord(hWndHatch, EB_HATCHRECT_TOP,   (WORD)lprcHatchRect->top);
        !           175:     SetWindowWord(hWndHatch, EB_HATCHRECT_RIGHT, (WORD)lprcHatchRect->right);
        !           176:     SetWindowWord(hWndHatch, EB_HATCHRECT_BOTTOM,(WORD)lprcHatchRect->bottom);
        !           177: }
        !           178: 
        !           179: 
        !           180: /* SetHatchWindowSize
        !           181:  *
        !           182:  *
        !           183:  *  Purpose:
        !           184:  *      Move/size the HatchWindow correctly given the rect required by the
        !           185:  *      in-place server object window and the lprcClipRect imposed by the 
        !           186:  *      in-place container. both rect's are expressed in the client coord.
        !           187:  *      of the in-place container's window (which is the parent of the 
        !           188:  *      HatchWindow).
        !           189:  *
        !           190:  *      OLE2NOTE: the in-place server must honor the lprcClipRect specified 
        !           191:  *      by its in-place container. it must NOT draw outside of the ClipRect.
        !           192:  *      in order to achieve this, the hatch window is sized to be
        !           193:  *      exactly the size that should be visible (rcVisRect). the
        !           194:  *      rcVisRect is defined as the intersection of the full size of
        !           195:  *      the HatchRect window and the lprcClipRect.
        !           196:  *      the ClipRect could infact clip the HatchRect on the
        !           197:  *      right/bottom and/or on the top/left. if it is clipped on the
        !           198:  *      right/bottom then it is sufficient to simply resize the hatch
        !           199:  *      window. but if the HatchRect is clipped on the top/left then
        !           200:  *      in-place server document window (child of HatchWindow) must be moved 
        !           201:  *      by the delta that was clipped. the window origin of the
        !           202:  *      in-place server window will then have negative coordinates relative
        !           203:  *      to its parent HatchWindow.
        !           204:  *
        !           205:  *  Parameters:
        !           206:  *      hWndHatch       hatch window handle
        !           207:  *      lprcIPObjRect   full size of in-place server object window
        !           208:  *      lprcClipRect    clipping rect imposed by in-place container
        !           209:  *      lpptOffset      offset required to position in-place server object
        !           210:  *                      window properly. caller should call:
        !           211:  *                          OffsetRect(&rcObjRect,lpptOffset->x,lpptOffset->y)
        !           212:  *
        !           213:  *  Return Value:
        !           214:  *      none
        !           215:  */
        !           216: STDAPI_(void) SetHatchWindowSize(
        !           217:         HWND        hWndHatch, 
        !           218:         LPRECT      lprcIPObjRect, 
        !           219:         LPRECT      lprcClipRect,
        !           220:         LPPOINT       lpptOffset
        !           221: )
        !           222: {
        !           223:     RECT        rcHatchRect;
        !           224:     RECT        rcVisRect;
        !           225:     UINT        uHatchWidth;
        !           226:     POINT       ptOffset;
        !           227: 
        !           228:     if (!IsWindow(hWndHatch))
        !           229:         return;
        !           230:     
        !           231:     rcHatchRect = *lprcIPObjRect;
        !           232:     uHatchWidth = GetHatchWidth(hWndHatch);
        !           233:     InflateRect((LPRECT)&rcHatchRect, uHatchWidth + 1, uHatchWidth + 1);
        !           234: 
        !           235:     IntersectRect((LPRECT)&rcVisRect, (LPRECT)&rcHatchRect, lprcClipRect);
        !           236:     MoveWindow(
        !           237:             hWndHatch, 
        !           238:             rcVisRect.left, 
        !           239:             rcVisRect.top, 
        !           240:             rcVisRect.right-rcVisRect.left, 
        !           241:             rcVisRect.bottom-rcVisRect.top,
        !           242:             TRUE    /* fRepaint */
        !           243:     );
        !           244:     InvalidateRect(hWndHatch, NULL, TRUE);
        !           245: 
        !           246:     ptOffset.x = -rcHatchRect.left + (rcHatchRect.left - rcVisRect.left);
        !           247:     ptOffset.y = -rcHatchRect.top + (rcHatchRect.top - rcVisRect.top);
        !           248: 
        !           249:     /* convert the rcHatchRect into the client coordinate system of the
        !           250:     **    HatchWindow itself 
        !           251:     */
        !           252:     OffsetRect((LPRECT)&rcHatchRect, ptOffset.x, ptOffset.y);
        !           253: 
        !           254:     SetHatchRect(hWndHatch, (LPRECT)&rcHatchRect);
        !           255:     
        !           256:     // calculate offset required to position in-place server doc window
        !           257:     lpptOffset->x = ptOffset.x;
        !           258:     lpptOffset->y = ptOffset.y;
        !           259: }
        !           260: 
        !           261: 
        !           262: /* 
        !           263:  *  HatchWndProc
        !           264:  *
        !           265:  *  Purpose:
        !           266:  *      WndProc for hatch window
        !           267:  *
        !           268:  *  Parameters:
        !           269:  *      hWnd
        !           270:  *      Message
        !           271:  *      wParam
        !           272:  *      lParam
        !           273:  *
        !           274:  *  Return Value:
        !           275:  *      message dependent
        !           276:  */
        !           277: LRESULT FAR PASCAL EXPORT HatchWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
        !           278: {
        !           279:     int nBorderWidth;
        !           280:     
        !           281:     switch (Message) {
        !           282: 
        !           283:         case WM_CREATE:
        !           284:             nBorderWidth = GetProfileInt(
        !           285:                 "windows",
        !           286:                 "oleinplaceborderwidth",
        !           287:                 DEFAULT_HATCHBORDER_WIDTH
        !           288:             );
        !           289:             SetWindowWord(hWnd, EB_HATCHWIDTH, (WORD)nBorderWidth);
        !           290:             break;
        !           291:                     
        !           292:         case WM_PAINT: 
        !           293:         {
        !           294:             HDC hDC;
        !           295:             PAINTSTRUCT ps;
        !           296:             RECT rcHatchRect;
        !           297:             
        !           298:             nBorderWidth = GetHatchWidth(hWnd);
        !           299:             hDC = BeginPaint(hWnd, &ps);
        !           300:             GetHatchRect(hWnd, (LPRECT)&rcHatchRect);
        !           301:             OleUIDrawShading(&rcHatchRect, hDC, OLEUI_SHADE_BORDERIN, 
        !           302:                     nBorderWidth);
        !           303:             InflateRect((LPRECT)&rcHatchRect, -nBorderWidth, -nBorderWidth);
        !           304:             OleUIDrawHandles(&rcHatchRect, hDC, OLEUI_HANDLES_OUTSIDE, 
        !           305:                     nBorderWidth+1, TRUE);
        !           306:             EndPaint(hWnd, &ps);
        !           307:             break;
        !           308:         }   
        !           309: 
        !           310:         default:
        !           311:             return DefWindowProc(hWnd, Message, wParam, lParam);
        !           312:     }
        !           313:     
        !           314:     return 0L;
        !           315: }

unix.superglobalmegacorp.com

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