|
|
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: imaglink.c
11: *
12: * Contains routines for managing the linked list of images.
13: *
14: * History:
15: *
16: ****************************************************************************/
17:
18: #include "imagedit.h"
19:
20:
21:
22: /************************************************************************
23: * ImageLinkAlloc
24: *
25: * Allocates an image link. This is a node in the linked list of
26: * images for the current file. This link will be added to the
27: * current linked list of images.
28: *
29: * Arguments:
30: * PDEVICE pDevice - Pointer to the device structure.
31: * INT cx - Width of the image.
32: * INT cy - Height of the image.
33: * INT xHotSpot - X location of the hotspot (cursors only).
34: * INT yHotSpot - Y location of the hotspot (cursors only).
35: * INT nColors - Number of colors (2 or 16).
36: *
37: * History:
38: *
39: ************************************************************************/
40:
41: PIMAGEINFO ImageLinkAlloc(
42: PDEVICE pDevice,
43: INT cx,
44: INT cy,
45: INT xHotSpot,
46: INT yHotSpot,
47: INT nColors)
48: {
49: PIMAGEINFO pImage;
50: PIMAGEINFO pImageT;
51:
52: if (!(pImage = (PIMAGEINFO)MyAlloc(sizeof(IMAGEINFO))))
53: return NULL;
54:
55: pImage->pDevice = pDevice;
56: pImage->cx = cx;
57: pImage->cy = cy;
58: pImage->iHotspotX = xHotSpot;
59: pImage->iHotspotY = yHotSpot;
60: pImage->nColors = nColors;
61: pImage->DIBSize = 0;
62: pImage->DIBhandle = NULL;
63: pImage->DIBPtr = NULL;
64: pImage->pImageNext = NULL;
65:
66: /*
67: * Insert the link in the list.
68: */
69: if (!gpImageHead) {
70: /*
71: * This is the first one. Start the list.
72: */
73: gpImageHead = pImage;
74: }
75: else {
76: /*
77: * Find the end of the list and tack on the new link.
78: */
79: for (pImageT = gpImageHead; pImageT->pImageNext;
80: pImageT = pImageT->pImageNext)
81: ;
82:
83: pImageT->pImageNext = pImage;
84: }
85:
86: return pImage;
87: }
88:
89:
90:
91: /************************************************************************
92: * ImageLinkFree
93: *
94: * Free's the specified image link and closes up the hole
95: * in the linked list.
96: *
97: * Arguments:
98: * PIMAGEINFO pImageFree - The image link to free.
99: *
100: * History:
101: *
102: ************************************************************************/
103:
104: VOID ImageLinkFree(
105: PIMAGEINFO pImageFree)
106: {
107: PIMAGEINFO pImage;
108: PIMAGEINFO pImagePrev;
109:
110: /*
111: * Find the existing link and get it's previous link.
112: */
113: for (pImage = gpImageHead, pImagePrev = NULL;
114: pImage && pImage != pImageFree;
115: pImagePrev = pImage, pImage = pImage->pImageNext)
116: ;
117:
118: /*
119: * Was the image link found?
120: */
121: if (pImage) {
122: /*
123: * Close up the linked list.
124: */
125: if (pImagePrev)
126: pImagePrev->pImageNext = pImageFree->pImageNext;
127: else
128: gpImageHead = pImageFree->pImageNext;
129:
130: /*
131: * Unlock and free the allocated DIB image.
132: */
133: if (pImageFree->DIBhandle) {
134: GlobalUnlock(pImageFree->DIBhandle);
135: GlobalFree(pImageFree->DIBhandle);
136: }
137:
138: /*
139: * Free the link itself.
140: */
141: MyFree(pImageFree);
142: }
143: }
144:
145:
146:
147: /************************************************************************
148: * ImageLinkFreeList
149: *
150: * Free's all the nodes in the current image list (if there is one).
151: *
152: * Arguments:
153: *
154: * History:
155: *
156: ************************************************************************/
157:
158: VOID ImageLinkFreeList(VOID)
159: {
160: while (gpImageHead)
161: ImageLinkFree(gpImageHead);
162: }
163:
164:
165:
166: /************************************************************************
167: * ImageDelete
168: *
169: * Deletes the current image (for icons/cursors). If there are other images,
170: * the first one is opened. If the last image was just deleted, the
171: * entire editor will be reset (if the file was untitled) or if there
172: * is currently a file opened, some other things will happen, such as
173: * hiding the workspace and view windows, etc.
174: *
175: * History:
176: *
177: ************************************************************************/
178:
179: VOID ImageDelete(VOID)
180: {
181: PIMAGEINFO pImage;
182:
183: ImageDCDelete();
184: ImageLinkFree(gpImageCur);
185: gpImageCur = NULL;
186: fFileDirty = TRUE;
187: fImageDirty = FALSE;
188: gnImages--;
189:
190: /*
191: * Look for the first remaining image that has a valid device
192: * (which means it is editable).
193: */
194: for (pImage = gpImageHead; pImage && !pImage->pDevice;
195: pImage = pImage->pImageNext)
196: ;
197:
198: /*
199: * If there are other editable images, open the first one.
200: * Otherwise, clear out some more things.
201: */
202: if (pImage) {
203: ImageOpen2(pImage);
204: }
205: else {
206: /*
207: * Is this a file off of disk?
208: */
209: if (gpszFileName) {
210: /*
211: * Hide the Workspace and View windows.
212: */
213: ShowWindow(ghwndWork, SW_HIDE);
214: ViewShow(FALSE);
215:
216: /*
217: * Update the properties bar (refill the images combo).
218: */
219: PropBarUpdate();
220: }
221: else {
222: /*
223: * Since this file was opened new and they deleted the
224: * last image present in it, just reset everything.
225: */
226: ClearResource();
227: }
228: }
229: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.