|
|
1.1 root 1: /*
2: * OBJFDBK.C
3: *
4: * Miscellaneous API's to generate UI feedback effects for OLE objects. This
5: * is part of the OLE 2.0 User Interface Support Library.
6: * The following feedback effects are supported:
7: * 1. Object selection handles (OleUIDrawHandles)
8: * 2. Open Object window shading (OleUIDrawShading)
9: *
10: * Copyright (c)1992 Microsoft Corporation, All Right Reserved
11: */
12:
13: #define STRICT 1
14: #include "ole2ui.h"
15:
16: static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw);
17:
18: /*
19: * OleUIDrawHandles
20: *
21: * Purpose:
22: * Draw handles or/and boundary around Container Object when selected
23: *
24: * Parameters:
25: * lpRect Dimensions of Container Object
26: * hdc HDC of Container Object (MM_TEXT mapping mode)
27: * dwFlags-
28: * Exclusive flags
29: * OLEUI_HANDLES_INSIDE Draw handles on inside of rect
30: * OLEUI_HANDLES_OUTSIDE Draw handles on outside of rect
31: * Optional flags
32: * OLEUI_HANDLES_NOBORDER Draw handles only, no rect
33: * OLEUI_HANDLES_USEINVERSE
34: * use invert for handles and rect, o.t. use COLOR_WINDOWTEXT
35: * cSize size of handle box
36: * fDraw Draw if TRUE, erase if FALSE
37: *
38: * Return Value: null
39: *
40: */
41: STDAPI_(void) OleUIDrawHandles(
42: LPRECT lpRect,
43: HDC hdc,
44: DWORD dwFlags,
45: UINT cSize,
46: BOOL fDraw
47: )
48: {
49: HBRUSH hbr;
50: RECT rc;
51: int bkmodeOld;
52: BOOL bInvert = (BOOL) (dwFlags & OLEUI_HANDLES_USEINVERSE);
53:
54: CopyRect((LPRECT)&rc, lpRect);
55:
56: bkmodeOld = SetBkMode(hdc, TRANSPARENT);
57:
58: if (dwFlags & OLEUI_HANDLES_OUTSIDE)
59: InflateRect((LPRECT)&rc, cSize - 1, cSize - 1);
60:
61: // Draw the handles inside the rectangle boundary
62: DrawHandle(hdc, rc.left, rc.top, cSize, bInvert, fDraw);
63: DrawHandle(hdc, rc.left, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
64: DrawHandle(hdc, rc.left, rc.bottom-cSize, cSize, bInvert, fDraw);
65: DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.top, cSize, bInvert, fDraw);
66: DrawHandle(hdc, rc.left+(rc.right-rc.left-cSize)/2, rc.bottom-cSize, cSize, bInvert, fDraw);
67: DrawHandle(hdc, rc.right-cSize, rc.top, cSize, bInvert, fDraw);
68: DrawHandle(hdc, rc.right-cSize, rc.top+(rc.bottom-rc.top-cSize)/2, cSize, bInvert, fDraw);
69: DrawHandle(hdc, rc.right-cSize, rc.bottom-cSize, cSize, bInvert, fDraw);
70:
71: if (!(dwFlags & OLEUI_HANDLES_NOBORDER)) {
72: if (fDraw)
73: hbr = GetStockObject(BLACK_BRUSH);
74: else
75: hbr = GetStockObject(WHITE_BRUSH);
76:
77: FrameRect(hdc, lpRect, hbr);
78: }
79:
80: SetBkMode(hdc, bkmodeOld);
81: }
82:
83:
84:
85: /*
86: * DrawHandle
87: *
88: * Purpose:
89: * Draw a handle box at the specified coordinate
90: *
91: * Parameters:
92: * hdc HDC to be drawn into
93: * x, y upper left corner coordinate of the handle box
94: * cSize size of handle box
95: * bInvert use InvertRect() if TRUE, otherwise use Rectangle()
96: * fDraw Draw if TRUE, erase if FALSE, ignored if bInvert is TRUE
97: *
98: * Return Value: null
99: *
100: */
101: static void DrawHandle(HDC hdc, int x, int y, UINT cSize, BOOL bInvert, BOOL fDraw)
102: {
103: HBRUSH hbr;
104: HBRUSH hbrOld;
105: HPEN hpen;
106: HPEN hpenOld;
107: RECT rc;
108:
109:
110: if (!bInvert) {
111: if (fDraw) {
112: hpen = GetStockObject(BLACK_PEN);
113: hbr = GetStockObject(BLACK_BRUSH);
114: } else {
115: hpen = GetStockObject(WHITE_PEN);
116: hbr = GetStockObject(WHITE_PEN);
117: }
118:
119: hpenOld = SelectObject(hdc, hpen);
120: hbrOld = SelectObject(hdc, hbr);
121: Rectangle(hdc, x, y, x+cSize, y+cSize);
122: SelectObject(hdc, hpenOld);
123: SelectObject(hdc, hbrOld);
124: }
125: else {
126: rc.left = x;
127: rc.top = y;
128: rc.right = x + cSize;
129: rc.bottom = y + cSize;
130: InvertRect(hdc, (LPRECT)&rc);
131: }
132: }
133:
134:
135: /*
136: * OleUIDrawShading
137: *
138: * Purpose:
139: * Shade the object when it is in in-place editing. Borders are drawn
140: * on the Object rectangle. The right and bottom edge of the rectangle
141: * are excluded in the drawing.
142: *
143: * Parameters:
144: * lpRect Dimensions of Container Object
145: * hdc HDC for drawing
146: * dwFlags-
147: * Exclusive flags
148: * OLEUI_SHADE_FULLRECT Shade the whole rectangle
149: * OLEUI_SHADE_BORDERIN Shade cWidth pixels inside rect
150: * OLEUI_SHADE_BORDEROUT Shade cWidth pixels outside rect
151: * Optional flags
152: * OLEUI_SHADE_USEINVERSE
153: * use PATINVERT instead of the hex value
154: * cWidth width of border in pixel
155: *
156: * Return Value: null
157: *
158: */
159: STDAPI_(void) OleUIDrawShading(LPRECT lpRect, HDC hdc, DWORD dwFlags, UINT cWidth)
160: {
161: HBRUSH hbr;
162: HBRUSH hbrOld;
163: HBITMAP hbm;
164: RECT rc;
165: WORD wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
166: COLORREF cvText;
167: COLORREF cvBk;
168:
169: hbm = CreateBitmap(8, 8, 1, 1, wHatchBmp);
170: hbr = CreatePatternBrush(hbm);
171: hbrOld = SelectObject(hdc, hbr);
172:
173: rc = *lpRect;
174:
175: if (dwFlags == OLEUI_SHADE_FULLRECT) {
176: cvText = SetTextColor(hdc, RGB(255, 255, 255));
177: cvBk = SetBkColor(hdc, RGB(0, 0, 0));
178: PatBlt(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
179: 0x00A000C9L /* DPa */ );
180:
181: } else { // either inside or outside rect
182:
183: if (dwFlags == OLEUI_SHADE_BORDEROUT)
184: InflateRect((LPRECT)&rc, cWidth - 1, cWidth - 1);
185:
186: cvText = SetTextColor(hdc, RGB(255, 255, 255));
187: cvBk = SetBkColor(hdc, RGB(0, 0, 0));
188: PatBlt(hdc, rc.left, rc.top, rc.right - rc.left,
189: cWidth, 0x00A000C9L /* DPa */);
190: PatBlt(hdc, rc.left, rc.top, cWidth, rc.bottom - rc.top,
191: 0x00A000C9L /* DPa */);
192: PatBlt(hdc, rc.right - cWidth, rc.top, cWidth,
193: rc.bottom - rc.top, 0x00A000C9L /* DPa */);
194: PatBlt(hdc, rc.left, rc.bottom - cWidth, rc.right-rc.left,
195: cWidth, 0x00A000C9L /* DPa */);
196: }
197:
198: SetTextColor(hdc, cvText);
199: SetBkColor(hdc, cvBk);
200: SelectObject(hdc, hbrOld);
201: DeleteObject(hbr);
202: DeleteObject(hbm);
203: }
204:
205:
206: /*
207: * OleUIShowObject
208: *
209: * Purpose:
210: * Draw the ShowObject effect around the object
211: *
212: * Parameters:
213: * lprc rectangle for drawing
214: * hdc HDC for drawing
215: * fIsLink linked object (TRUE) or embedding object (FALSE)
216: *
217: * Return Value: null
218: *
219: */
220: STDAPI_(void) OleUIShowObject(LPCRECT lprc, HDC hdc, BOOL fIsLink)
221: {
222: HPEN hpen;
223: HPEN hpenOld;
224: HBRUSH hbrOld;
225:
226: if (!lprc || !hdc)
227: return;
228:
229: hpen = fIsLink ? CreatePen(PS_DASH, 1, RGB(0,0,0)) :
230: GetStockObject(BLACK_PEN);
231:
232: if (!hpen)
233: return;
234:
235: hpenOld = SelectObject(hdc, hpen);
236: hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH));
237:
238: Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
239:
240: SelectObject(hdc, hpenOld);
241: SelectObject(hdc, hbrOld);
242:
243: if (fIsLink)
244: DeleteObject(hpen);
245:
246: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.