|
|
1.1 root 1: #define NOVIRTUALKEYCODES
2:
3: #include "windows.h"
4: #include <windowsx.h>
5: #include "fontedit.h"
6: #include "fcntl.h"
7: #include <stdlib.h> // Causes redefinition warnings.
8: #include <string.h>
9:
10: /****************************************************************************/
11: /* Shared Variables (Home base) */
12: /****************************************************************************/
13:
14: FARPROC lpHeaderProc; /* Pointer to Dialog Box Procedure */
15: FARPROC lpReSizeProc; /* Pointer to Dialog Box Procedure */
16: FARPROC lpWidthProc; /* Pointer to Dialog Box Procedure */
17:
18: FontHeaderType font; /* Structure of Font File Header */
19: LONG lSizeOfOldFontHeader = 0; /* Old packed header size. */
20: LONG lSizeOfOldFontHeader30 = 0; /* Old 3.0 packed header size. */
21: LONG lSizeOfOldGlyph20 = 0; /* Old packed 2.0 glyph info size. */
22: LONG lSizeOfOldGlyph30 = 0; /* Old packed 3.0 glyph info size. */
23: extern CHAR szFontFile[]; /* Name of Font File */
24: extern CHAR szFontFileFull[]; /* Name of Font File */
25: extern CHAR szNewFile[]; /* Temporary Name */
26: extern BOOL NewFile; /* flag indicating if file was opened
27: by selecting NEW menu item */
28: HCURSOR hCross; /* handle to a "+" shaped cursor */
29: HANDLE hInst; /* Handle to Window Instance */
30: HANDLE hgPrev;
31: INT swH = 0; /* Position in Show Window 0-100 */
32: BYTE iChar = 65; /* Character being edited */
33: BYTE jChar = 65; /* Last Char. of edit block */
34: CHAR szFaceName[szNamesMax] = {""}; /* Face Name of Font */
35: DWORD offsets[257]; /* Offsets Table */
36: CHAR *vrgsz[CSTRINGS]; /* string table */
37:
38: BOOL fChanged = FALSE; /* Note if we did anything */
39: BOOL fLoaded = FALSE; /* Set if a font is loaded */
40: BOOL fEdited = FALSE; /* Character was edited */
41: INT iFontFormat; /* Set to id of current font format */
42: INT iFontFormatPrev; /* Set to id of prev. font format */
43: BOOL fReadOnly;
44:
45: HWND hBox = NULL; /* Handle to Edit Window */
46: HWND hFont = NULL; /* Handle to Show window */
47: HDC hMemDC = NULL; /* Handle to Memory Display Context */
48: HBITMAP hBitmap = NULL; /* Handle to our work bit map */
49:
50: CHAR matBox [wBoxLim] [kBoxLim]; /* array to hold Box */
51: WORD wBox = 10; /* Width of Character(s) */
52: WORD kBox = 16; /* Height of Characters */
53: DWORD kStuff; /* Height of font window caption etc. */
54:
55: OFSTRUCT ofstrFile; /* holds info of file - filled in by dlgopen/save */
56: //WORD fp = NULL; /* global fp of current file - " " " " " " */
57:
58: /*** string arrays for using stringtable ***/
59: CHAR szAppName[MAX_STR_LEN];
60: CHAR szIFN[MAX_STR_LEN]; /* illegal filename */
61: CHAR szFNF[MAX_STR_LEN]; /* file not found */
62: CHAR szREF[MAX_STR_LEN]; /* replace existing file */
63: CHAR szSCC[MAX_STR_LEN]; /* save current changes */
64: CHAR szEOF[MAX_STR_LEN]; /* error opening file */
65: CHAR szECF[MAX_STR_LEN]; /* error creating file */
66: CHAR szFRO[MAX_STR_LEN]; /* error creating file */
67: CHAR szExt[MAX_STR_LEN]; /* .FNT */
68: CHAR szExtDesc[MAX_STR_LEN]; /* Font Files(.FNT) */
69: CHAR szNEWFONT[MAX_STR_LEN]; /* Font Files(.FNT) */
70: CHAR szFilter[MAX_STR_LEN]; /* Font Files(.FNT) */
71:
72:
73: /* size of system font */
74: INT cSysWidth;
75: INT cSysHeight;
76:
77: /****************************************************************************/
78: /* Local Variables */
79: /****************************************************************************/
80:
81: BYTE FindMouse(); /* Find where mouse is */
82:
83: HBRUSH hbrWhite;
84: HBRUSH hbrBlack;
85: HBRUSH hbrGray;
86: HBRUSH hbrDkGray;
87: HBRUSH hbrBackGround;
88:
89: BYTE downChar; /* Where mouse was pressed */
90: BYTE lastChar; /* Where mouse was last */
91: WORD wBoxOld; /* So we can catch any changes */
92: RECT rectWin; /* Client Rectangle */
93: LONG origin; /* Position in Show Window pixels */
94: BOOL fFirstShow = TRUE; /* first time Show Window displayed? */
95:
96: /****************************************************************************/
97: /* Local Functions */
98: /****************************************************************************/
99:
100: VOID InvertFont(HDC, BYTE, BYTE);
101: BOOL FontEditInit(HANDLE);
102: VOID InitSizes(VOID);
103:
104: /*****************************************************************************
105: * FontShowHorzScroll(hFont, code, posNew)
106: *
107: * purpose: intepret scroll message for tiny window and call scroll funtion
108: * accordingly
109: *
110: * params: HWND hFont : handle to tiny window
111: * int code : scroll message
112: * int posNew : thumb position
113: * returns: none
114: *
115: * side effects: scroll position variable altered
116: *
117: ****************************************************************************/
118: VOID
119: FontShowHorzScroll(
120: HWND hFont,
121: INT code,
122: INT posNew
123: )
124: {
125: WORD wChar;
126: RECT rect;
127:
128: /* Get dimensions */
129: GetClientRect(hFont, (LPRECT)&rect);
130:
131: /* Make a fair guess as to how many characters are in the window */
132: /* Convert sorta to hex too. */
133: wChar=(WORD)(11*(rect.right-rect.left)/(font.AvgWidth*16));
134:
135: switch (code)
136: {
137: case SB_LINEUP: /* line left */
138: swH -= 1;
139: break;
140: case SB_LINEDOWN: /* line right */
141: swH += 1;
142: break;
143: case SB_PAGEUP: /* page left */
144: swH -= wChar;
145: break;
146: case SB_PAGEDOWN: /* page right */
147: swH += wChar;
148: break;
149: case SB_THUMBPOSITION:
150: swH = posNew;
151: break;
152: case SB_THUMBTRACK:
153: return;
154: }
155: ScrollFont();
156: }
157:
158: /*****************************************************************************
159: * FontShowPaint(hDC)
160: *
161: * purpose: repaint the little window at the bottom
162: *
163: * params: HDC hDC : handle to display context.
164: *
165: * returns: none
166: *
167: * side effects: some scroll globals altered.
168: *
169: ****************************************************************************/
170:
171: VOID
172: FontShowPaint(
173: HDC hDC
174: )
175: {
176: DWORD range, nBits;
177: INT nx;
178:
179: nx=GetSystemMetrics(SM_CXBORDER);
180: /* 320 --> 300 */
181: nBits = min(300, rectWin.right - rectWin.left-nx-nx) - 24;
182: /* Window width (pixels) */
183: /* 320 --> 300 */
184: range = max(0, (font.WidthBytes << 3) - min(300, nBits));
185: origin = (swH * range) / 100; /* Global variable */
186: BitBlt(hDC, 12, 2, nBits, font.PixHeight,
187: hMemDC, origin, 0, NOTSRCCOPY);
188: /* Now highlight the current value of iChar */
189: InvertFont(hDC, iChar, jChar);
190: }
191:
192:
193: /*****************************************************************************
194: * MouseInFont(ptMouse)
195: *
196: * purpose: Select new char in tiny Show window by inverting current char
197: * and un-inverting last one
198: *
199: * params: POINT ptMouse : mouse coordinates
200: *
201: * returns: none
202: *
203: * side effects: pixels inverted(uninverted) in bitmap.
204: *
205: ****************************************************************************/
206: VOID
207: MouseInFont(
208: POINT ptMouse /* .. to get new iChar */
209: )
210: {
211: HDC hDC;
212:
213: BoxToChar(iChar); /* Replace edited character in Box if changed */
214: hDC = GetDC(hFont);
215: /* UnInvert present inverted region */
216: InvertFont(hDC, iChar, jChar);
217: /* Find where mouse is */
218: lastChar = downChar = iChar = jChar = FindMouse(ptMouse);
219: /* Invert Character touched */
220: InvertFont(hDC, iChar, jChar);
221: ReleaseDC(hFont, hDC);
222: }
223:
224:
225: /*****************************************************************************
226: *
227: * purpose:
228: *
229: * params:
230: *
231: * returns:
232: *
233: * side effects:
234: *
235: ****************************************************************************/
236: VOID
237: MouseMoveFont(
238: POINT ptMouse
239: )
240: /* Mouse raised in font */
241: /* .. to get new jChar */
242: {
243: UNREFERENCED_PARAMETER(ptMouse);
244: return; /********* NOT YET IN USE !! ********/
245:
246: #if 0
247: BYTE newChar;
248: HDC hDC;
249:
250: newChar = FindMouse(ptMouse); /* Find where mouse is */
251: if (newChar == lastChar) /* Did we move ? */
252: return; /* No: return */
253: lastChar = newChar;
254: hDC = GetDC(hFont);
255: if (newChar > jChar)
256: {
257: InvertFont(hDC, jChar + 1, newChar); /* extend jChar */
258: jChar = newChar;
259: }
260: else if (newChar < iChar) /* iChar & jChar switch */
261: {
262: InvertFont(hDC, newChar, iChar - 1);
263: iChar = newChar;
264: }
265: else
266: {
267: if (newChar >= downChar) /* width reduced on right */
268: {
269: InvertFont(hDC, newChar + 1, jChar);
270: jChar = newChar;
271: }
272: if (newChar <= downChar) /* width reduced on left */
273: {
274: InvertFont(hDC, iChar, newChar - 1);
275: iChar = newChar;
276: }
277: }
278: ReleaseDC(hFont, hDC);
279: #endif
280: }
281:
282:
283: /*****************************************************************************
284: * InvertFont(hDC, iChar, jChar)
285: *
286: * purpose: inverts color on selected chars (iChar thro' jChar) in the Show
287: * Window
288: *
289: * params: HDC hDC : handle to display context
290: * char iChar : start char
291: * char jChar : end char
292: *
293: * returns: none
294: *
295: * side effects: changes pixel values in bitmap
296: *
297: ****************************************************************************/
298: VOID
299: InvertFont(
300: HDC hDC,
301: BYTE iChar,
302: BYTE jChar
303: )
304: {
305: PatBlt(hDC, /* Use Blt to Invert it */
306: 12 + offsets[iChar] - origin, /* X: Position */
307: 2, /* Y: Allow for top band */
308: offsets[jChar + 1] - offsets[iChar], /* dx: Compute width */
309: font.PixHeight, /* dy: Look up the Height */
310: DSTINVERT); /* Z: Tell it to invert it */
311: }
312:
313:
314: /*****************************************************************************
315: * MouseOutFont(ptMouse)
316: *
317: * purpose: brings selected char to edit box and sets up tiny window for
318: * repainting
319: *
320: * params: POINT ptMouse : mouse location
321: *
322: * returns: none
323: *
324: * side effects: changes matBox(2-d array containing ready pixel info. on
325: * char being edited)
326: *
327: ****************************************************************************/
328: VOID
329: MouseOutFont(
330: POINT ptMouse
331: )
332: /* Mouse raised in font */
333: /* .. to get new jChar */
334: {
335: MouseMoveFont(ptMouse); /* Check on iChar and jChar */
336: CharToBox(iChar);
337: InvalidateRect(hFont, (LPRECT)NULL, TRUE); /* Cause repaint */
338: }
339:
340:
341: /*****************************************************************************
342: * BYTE FindMouse(ptMouse)
343: *
344: * purpose: Locate number of character(in tiny window at bottom) under mouse
345: *
346: * params: POINT ptMouse : mouse location
347: *
348: * returns: number of character
349: *
350: * side effects: alters scroll position variable
351: *
352: ****************************************************************************/
353:
354: BYTE
355: FindMouse(
356: POINT ptMouse
357: )
358: {
359: int iChar;
360: LONG x;
361:
362:
363: x = ptMouse.x + origin - 12; /* Horizontal position of mouse */
364: if (x < 0)
365: iChar = font.FirstChar;
366: else
367: {
368: iChar = x / font.AvgWidth + font.FirstChar;
369: /* Right if Fixed Pitch -- Best Guess if variable width */
370: if (!font.PixWidth) /* Scan for new iChar */
371: {
372: if (iChar > (int)font.LastChar)
373: iChar = (int)font.LastChar; /* Don't overshoot */
374:
375: while (iChar < (int)font.LastChar && offsets[iChar] < (DWORD)x)
376: iChar++;
377: while (iChar > (int)font.FirstChar && offsets[iChar] > (DWORD)x)
378: iChar--;
379: }
380: }
381:
382: /* Bug fix: prevent nil character from showing if mouse is pressed way
383: over on right side of font scroll with narrow fixed fonts. */
384: if (iChar > (int)font.LastChar)
385: iChar = (int)font.LastChar; /* Don't overshoot */
386:
387: if (iChar < (int)font.FirstChar)
388: iChar = (int)font.FirstChar; /* Don't undershoot */
389:
390: if (ptMouse.x <= 12L)
391: {
392: swH -= 1;
393: ScrollFont();
394: }
395: if (ptMouse.x > 308L)
396: {
397: swH += 1;
398: ScrollFont();
399: }
400: return (BYTE)iChar;
401: }
402:
403:
404: /*****************************************************************************
405: * ScrollFont()
406: *
407: * purpose: scrolls tiny window at bottom
408: *
409: * params: none
410: *
411: * returns: none
412: *
413: * side effects: alters scroll position variable
414: *
415: ****************************************************************************/
416: VOID
417: ScrollFont(
418: VOID
419: )
420: {
421: HDC hDC;
422:
423: swH = max(0, swH);
424: swH = min(100, swH); /* maintain 0 - 100 range */
425: SetScrollPos(hFont, SB_HORZ, swH, TRUE); /* Move thumb */
426: hDC = GetDC(hFont);
427: FontShowPaint(hDC);
428: ReleaseDC(hFont, hDC);
429: }
430:
431:
432: /*****************************************************************************
433: * BoxToChar(iChar)
434: *
435: * purpose: sets pixels in bitmap according to matBox(2-d array containing
436: * ready pixel info. on char being edited)
437: *
438: * params: BYTE iChar : index of char in bitmap offset array(offsets)
439: *
440: * returns: none
441: *
442: * side effects: changes font bitmap
443: *
444: ****************************************************************************/
445: VOID
446: BoxToChar(
447: BYTE iChar
448: )
449: {
450: DWORD x, y, offset;
451:
452: if (!fEdited)
453: return;
454:
455: if (wBox != wBoxOld) /* I.e if width has changed */
456: CharWidth(iChar, wBox); /* .. go fix it */
457:
458: offset = offsets[iChar];
459: for (x = 0; x < wBox; x++)
460: {
461: for (y = 0; y < kBox; y++)
462: SetPixel(hMemDC, offset + x, y,
463: matBox[x] [y] == TRUE ? WHITE : BLACK);
464: }
465: fEdited = FALSE;
466: }
467:
468:
469: /*****************************************************************************
470: * CharToBox(iChar)
471: *
472: * purpose: assigns matBox(2-d array containing ready pixel info. on char being
473: * edited) according to pixels in portion of bitmap corresp. to char.
474: *
475: * params: BYTE iChar : index of char in bitmap offset array(offsets)
476: *
477: * returns: none
478: *
479: * side effects: changes matBox
480: *
481: ****************************************************************************/
482: VOID
483: CharToBox(
484: BYTE iChar
485: )
486: {
487: DWORD x, y, offset;
488: HMENU hMenu;
489:
490: ClearBox();
491: offset = offsets[iChar];
492: wBox = wBoxOld = (WORD) (offsets[iChar + 1] - offset); /* Edit Box width */
493: kBox = font.PixHeight; /* Edit Box Height */
494: for (x = 0; x < wBox; x++)
495: for (y = 0; y < kBox; y++)
496: matBox[x][y] = (BYTE) (GetPixel(hMemDC, offset + x, y) ? 1 : 0);
497: InvalidateRect(hBox, (LPRECT)NULL, TRUE);
498: fEdited = FALSE; /* Not Changed Yet */
499: hMenu = GetMenu(hBox);
500: EnableMenuItem(hMenu, BOX_UNDO, MF_GRAYED);
501: EnableMenuItem(hMenu, BOX_REFRESH, MF_GRAYED);
502: }
503:
504:
505: /*****************************************************************************/
506: /* WinMain and Friends */
507: /*****************************************************************************/
508:
509:
510: /* Procedure called every time a new instance of the application
511: ** is created */
512:
513: INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT cmdShow)
514: {
515: MSG msg;
516: WORD message;
517: INT nx;
518: HANDLE hAccel;
519:
520: hInst = hInstance;
521: hgPrev=hPrevInstance;
522:
523:
524: if (!FontEditInit( hInstance ))
525: return FALSE;
526:
527:
528:
529: LoadString(hInstance, IDS_APPNAME, szAppName, MAX_STR_LEN);
530: LoadString(hInstance, IDS_IFN, szIFN, MAX_STR_LEN); /* illegal filename */
531: LoadString(hInstance, IDS_FNF, szFNF, MAX_STR_LEN); /* file not found */
532: LoadString(hInstance, IDS_REF, szREF, MAX_STR_LEN);
533: /* replace existing file */
534: LoadString(hInstance, IDS_SCC, szSCC, MAX_STR_LEN);
535: /* save current changes */
536: LoadString(hInstance, IDS_EOF, szEOF, MAX_STR_LEN); /* error opening file */
537: LoadString(hInstance, IDS_ECF, szECF, MAX_STR_LEN);
538: // File is read only.
539: LoadString(hInstance, IDS_FRO, szFRO, MAX_STR_LEN);
540: /* error creating file */
541: LoadString(hInstance, IDS_EXT, szExt, MAX_STR_LEN); /* default file ext. */
542:
543: // File extension description for common dialog.
544: LoadString(hInstance, IDS_EXTDESC, szExtDesc, MAX_STR_LEN);
545: // Message for new font warning box.
546: LoadString(hInstance, IDS_NEW_FONT, szNEWFONT, MAX_STR_LEN);
547: memset(szFilter, 0, MAX_STR_LEN);
548: LoadString(hInstance, IDS_EXTDESC, szFilter, MAX_STR_LEN);
549: LoadString(hInstance, IDS_STARDOTFNT, szFilter+strlen(szFilter)+1,
550: MAX_STR_LEN-(strlen(szFilter)+1));
551:
552:
553: ClearBox();
554:
555: /* Create a window instance of class "FontEdit" */
556:
557: hBox = CreateWindow((LPSTR) vszFontEdit,
558: (LPSTR)szAppName,
559: WS_TILEDWINDOW,
560: 56,34,
561: GetSystemMetrics(SM_CXFULLSCREEN)/2,
562: GetSystemMetrics(SM_CYFULLSCREEN)/2,
563: (HWND)NULL, /* no parent */
564: (HMENU)NULL, /* use class menu */
565: (HANDLE)hInstance, /* handle to window instance */
566: (LPSTR)NULL /* no params to pass on */
567: );
568:
569: ShowWindow(hBox, cmdShow);
570: UpdateWindow(hBox);
571: InitSizes(); /* 11/21/86 - linsh - get system char width & height */
572:
573:
574: GetWindowRect(hBox, (LPRECT)&rectWin);
575: nx=GetSystemMetrics(SM_CXBORDER);
576: hFont = CreateWindow((LPSTR) vszFontShow,
577: (LPSTR) "",
578: WS_BORDER|WS_HSCROLL|WS_CAPTION,
579: rectWin.left,
580: rectWin.bottom-56,
581: min(300, rectWin.right - rectWin.left-nx-nx),
582: 50 - GetSystemMetrics(SM_CYBORDER),
583: (HWND)hBox,
584: (HMENU)NULL,
585: (HANDLE)hInstance,
586: (LPSTR)NULL
587: );
588:
589:
590: /* Get address of Dialog Box procedure */
591: lpHeaderProc = MakeProcInstance((FARPROC)HeaderProc, hInstance);
592: lpReSizeProc = MakeProcInstance((FARPROC)ReSizeProc, hInstance);
593: lpWidthProc = MakeProcInstance((FARPROC)WidthProc, hInstance);
594:
595: /* Start it loading if it's not iconic */
596: if (!IsIconic(hBox))
597: {
598: if (lpszCmdLine[0]) /* If we have a font name use it */
599: {
600: BOOL fDot;
601: INT i;
602:
603: /* Copy the specified file and make it upper case */
604: lstrcpy((LPSTR)szFontFile, CharUpper((LPSTR)lpszCmdLine));
605:
606: fDot = FALSE;
607: nx=lstrlen((LPSTR)szFontFile);
608:
609: for (i = 0; i < nx; i++)
610: {
611: if (szFontFile[i] == '.') /* Add .FNT if none */
612: fDot = TRUE;
613:
614: if (szFontFile[i] == ' ')
615: szFontFile[i]=0;
616: }
617:
618: if (!fDot)
619: lstrcat((LPSTR)szFontFile, (LPSTR)vszDotFNT);
620:
621: lstrcpy((LPSTR)szNewFile, (LPSTR)szFontFile);
622:
623: /* Do this thing that someone forgot. THe dialog open does it
624: and affects the Save As initialization. */
625: (HFILE)OpenFile((LPSTR)szNewFile, &ofstrFile, OF_READ);
626:
627: message = FONT_START;
628: }
629: else /* Start by doing a regular file load */
630: message = FONT_LOAD;
631:
632: SetFocus(hBox);
633: PostMessage(hBox, WM_COMMAND, message, (LONG)0);
634: }
635:
636: if (!fLoaded)
637: ShowWindow(hFont, SW_HIDE);
638:
639: hAccel=LoadAccelerators(hInstance, "FE");
640:
641: /* Quit message will terminate application */
642: while (GetMessage((LPMSG)&msg, NULL, 0, 0))
643: {
644: if (!TranslateAccelerator (hBox, hAccel, &msg))
645: {
646: TranslateMessage((LPMSG)&msg);
647: DispatchMessage((LPMSG)&msg);
648: }
649: }
650:
651: return msg.wParam;
652: }
653:
654: /*****************************************************************************
655: * int FontEditInit( hInstance )
656: *
657: * purpose: Initialises a whole lot of stuff
658: *
659: * params: HANDLE hInstance : handle to instance of application
660: *
661: * returns: TRUE : if everything goes off well
662: * FALSE : error in initialisation
663: *
664: * side effects: a whole lot
665: *
666: ****************************************************************************/
667:
668: /* Procedure called when the application is loaded */
669: BOOL
670: FontEditInit(
671: HANDLE hInstance
672: )
673: {
674: INT cch; /* all variables used to load srings from .RC file */
675: INT cchRemaining;
676: CHAR *pch;
677: HANDLE hStrings;
678: INT i;
679: CHAR ColorStr[CCHCOLORSTRING]; /* background color inf. fronm win.ini */
680: BYTE bR, bG, bB; /* the three primary color values ret. from win.ini */
681: // CHAR cDummy; /* dummy char to hold the " " char */
682: PWNDCLASS pFontEditClass; /* Edit Box window class */
683: PWNDCLASS pFontShowClass; /* Show Font window class */
684:
685: //
686: // Initialize the conversion routines to read in the old font structure
687: // off of disk.
688: //
689:
690: if (fConvStructInit () == FALSE) {
691:
692: return FALSE;
693: }
694:
695: /* load strings from resource file */
696: if (!(pch = (CHAR *)(hStrings =
697: LocalAlloc (LPTR, cchRemaining = CCHSTRINGSMAX))))
698: return FALSE; /* unable to alloc. Try increasing initial
699: heapsize in .DEf file */
700: for (i=0; i< CSTRINGS; i++){
701: cch = 1+LoadString (hInstance, (WORD) i, (LPTSTR)pch, cchRemaining);
702: if (cch < 2){
703: return FALSE;
704: }
705: vrgsz[i] = pch;
706: pch += cch;
707: if ((cchRemaining -= cch ) <= 0)
708: return FALSE;
709: }
710:
711: /* Allocate class structure in local heap */
712: pFontEditClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
713: if (pFontEditClass == NULL)
714: return FALSE;
715:
716: /* set up some default brushes */
717: hbrWhite = GetStockObject( WHITE_BRUSH );
718: hbrBlack = GetStockObject( BLACK_BRUSH );
719: hbrGray = GetStockObject( GRAY_BRUSH );
720: hbrDkGray = GetStockObject( DKGRAY_BRUSH );
721:
722: /* get App. Workspace color from win.ini - LR */
723: if (GetProfileString(vszcolors, vszAppWorkspace, "",ColorStr,
724: CCHCOLORSTRING)){
725: bR = (BYTE)atoi((const char *)strtok (ColorStr, " "));
726: bG = (BYTE)atoi((const char *)strtok (NULL, " "));
727: bB = (BYTE)atoi((const char *)strtok (NULL, "\n"));
728: hbrBackGround = CreateSolidBrush(RGB(bR, bG, bB));
729: }
730: else /* set to lt. blue background */
731: hbrBackGround = CreateSolidBrush((LONG)0x00FF8000);
732:
733: /* get necessary resources */
734: pFontEditClass->hCursor = LoadCursor( NULL, IDC_ARROW);
735: pFontEditClass->hIcon = LoadIcon( hInstance,(LPSTR)vszFontEdit);
736: pFontEditClass->lpszMenuName = (LPSTR)vszFontEdit;
737: pFontEditClass->lpszClassName = (LPSTR)vszFontEdit;
738: pFontEditClass->hbrBackground = hbrBackGround;
739: pFontEditClass->hInstance = hInstance;
740:
741: pFontEditClass->style = CS_VREDRAW | CS_HREDRAW;
742:
743: /* Register our Window Proc */
744: pFontEditClass->lpfnWndProc = (WNDPROC)FontEditWndProc;
745:
746: /* register this new class with WINDOWS */
747: if (!hgPrev)
748: if (!RegisterClass( (LPWNDCLASS)pFontEditClass ) )
749: return FALSE; /* Initialization failed */
750:
751: /* Now repeat the performance for the Show window */
752:
753: pFontShowClass = pFontEditClass;
754: /* get necessary resources */
755: pFontShowClass->hCursor = LoadCursor(NULL,IDC_ARROW);
756: pFontShowClass->hIcon = (HICON)NULL;
757: pFontShowClass->lpszMenuName = (HMENU)NULL;
758: pFontShowClass->lpszClassName = (LPSTR)vszFontShow;
759: pFontShowClass->hbrBackground = hbrGray;
760: pFontShowClass->hInstance = hInstance;
761: pFontShowClass->style = CS_VREDRAW | CS_HREDRAW;
762:
763: /* Register our Window Proc */
764: pFontShowClass->lpfnWndProc = (WNDPROC)FontShowWndProc;
765:
766: /* register this new class with WINDOWS */
767: if (!hgPrev)
768: if (!RegisterClass( (LPWNDCLASS)pFontShowClass ) )
769: return FALSE; /* Initialization failed */
770:
771: LocalFree( (HANDLE)pFontShowClass );
772:
773: return TRUE; /* Initialization succeeded */
774: }
775:
776: /*****************************************************************************
777: * InitSizes()
778: *
779: * purpose: gets system char width and height
780: *
781: * params: none
782: *
783: * returns: none
784: *
785: * side effects: sets width and height globals
786: *
787: ****************************************************************************/
788: VOID
789: InitSizes(
790: VOID
791: )
792: {
793: HDC hDC;
794: TEXTMETRIC tm;
795:
796: hDC = GetDC(hFont);
797: GetTextMetrics(hDC, (LPTEXTMETRIC) &tm);
798: cSysHeight = tm.tmHeight + tm.tmExternalLeading;;
799: cSysWidth = tm.tmAveCharWidth;
800: ReleaseDC(hFont, hDC);
801: }
802:
803:
804: /*****************************************************************************
805: * long APIENTRY FontShowWndProc(hFont, message, wParam, lParam)
806: *
807: * purpose: Window function for tiny window at the bottom (showing font chars)
808: * Independently processes paint, scroll, keyboard and mouse
809: * messages for the window
810: *
811: * params: as for window functions
812: *
813: * side effects: lots
814: *
815: ****************************************************************************/
816:
817: /* Procedures which make up the window class. */
818: LONG APIENTRY
819: FontShowWndProc(
820: HWND hFont,
821: WORD message,
822: WPARAM wParam,
823: LPARAM lParam
824: )
825: {
826: PAINTSTRUCT ps;
827: // RECT rectWin;
828: POINT pt;
829:
830: ((pt).x = ((*((POINTS *)&(lParam)))).x, (pt).y = ((*((POINTS *)&(lParam)))).y);
831:
832: switch (message)
833: {
834:
835: case WM_SIZE :
836: switch (wParam){
837: /* if main window is iconised, hide the child window */
838: case SIZEICONIC :
839: ShowWindow(hFont, SW_HIDE);
840: break;
841: default:
842: return(DefWindowProc(hFont, message, wParam, lParam));
843: break;
844: }
845: break;
846:
847:
848: case WM_PAINT:
849: /* Time for the window to draw itself. */
850: BeginPaint(hFont, (LPPAINTSTRUCT)&ps);
851: FontShowPaint(ps.hdc);
852: EndPaint(hFont, (LPPAINTSTRUCT)&ps);
853: break;
854:
855: /* For each of following mouse window messages, wParam contains
856: ** bits indicating whether or not various virtual keys are down,
857: ** and lParam is a POINT containing the mouse coordinates. The
858: ** keydown bits of wParam are: MK_LBUTTON (set if Left Button is
859: ** down); MK_RBUTTON (set if Right Button is down); MK_SHIFT (set
860: ** if Shift Key is down); MK_ALTERNATE (set if Alt Key is down);
861: ** and MK_CONTROL (set if Control Key is down). */
862:
863: case WM_LBUTTONDOWN:
864: MouseInFont(pt); /* .. set iChar */
865: break;
866: case WM_LBUTTONUP:
867: MouseOutFont(pt); /* .. set jChar */
868: break;
869: case WM_RBUTTONDOWN:
870: case WM_RBUTTONUP:
871: case WM_MOUSEMOVE: /* If mouse is down */
872: if (wParam & MK_LBUTTON)
873: MouseMoveFont(pt); /* .. set jChar */
874: break;
875: case WM_LBUTTONDBLCLK:
876: case WM_RBUTTONDBLCLK:
877: break;
878:
879: case WM_HSCROLL:
880: /* wParam contains the scroll code.
881: ** For the thumb movement codes, the low
882: ** word of lParam contain the new scroll position.
883: ** Possible values for wParam are: SB_LINEUP, SB_LINEDOWN,
884: ** SB_PAGEUP, SB_PAGEDOWN, SB_THUMBPOSITION, SB_THUMBTRACK */
885: /* Horizontal scroll bar input. Parameters same as for
886: ** WM_HSCROLL. UP and DOWN should be interpreted as LEFT
887: ** and RIGHT, respectively. */
888: FontShowHorzScroll(hFont, LOWORD(wParam),
889: HIWORD(wParam));
890: break;
891: case WM_CLOSE:
892: break; /* don't allow this window to be closed before
893: bigger one */
894:
895: default:
896:
897: /* Everything else comes here. This call MUST exist
898: ** in your window proc. */
899:
900: return(DefWindowProc(hFont, message, wParam, lParam));
901: break;
902:
903: }
904:
905: /* A window proc should always return something */
906: return(0L);
907: }
908:
909:
910: VOID
911: FontRename(
912: CHAR * szError
913: )
914: {
915: CHAR *szTitle[MAX_STR_LEN+MAX_FNAME_LEN];
916:
917: if (szError[0])
918: ErrorBox(hBox, szError);
919: else
920: {
921: lstrcpy((LPSTR)szFontFileFull, (LPSTR)szNewFile);
922: lstrcpy((LPSTR)szTitle, (LPSTR)szAppName);
923: lstrcat((LPSTR)szTitle, (LPSTR)vszBlankDashBlank);
924: lstrcat((LPSTR)szTitle, (LPSTR)szFontFile);
925: SetWindowText(hBox, (LPSTR)szTitle);
926: }
927: }
928:
929:
930: /*****************************************************************************
931: * ResizeShow()
932: *
933: * purpose: resize tiny window at bottom (showing font chars) in proportion
934: * to large window
935: *
936: * params: none
937: *
938: * returns: none
939: *
940: * side effects:
941: *
942: ****************************************************************************/
943:
944: VOID
945: ResizeShow(
946: VOID
947: )
948: {
949: INT height;
950: INT nx;
951:
952: /* size message for hbox goes thru before hfont created. 06-Jul-1987. */
953: if (!hFont)
954: return;
955:
956: GetWindowRect(hBox, (LPRECT)&rectWin);
957: kStuff = GetkStuff(); /* For check on second pass */
958:
959: #if 0
960: height = font.PixHeight + kStuff + 20; /* 4 Height we want box */
961: #else
962: height = font.PixHeight + GetSystemMetrics(SM_CYHSCROLL)
963: + GetSystemMetrics(SM_CYCAPTION)
964: + 4*GetSystemMetrics(SM_CYBORDER)/*20*/; /* 4*/
965: #endif
966:
967: nx=GetSystemMetrics(SM_CXBORDER);
968: MoveWindow(hFont,
969: rectWin.left +nx+4,
970: rectWin.bottom - (height + GetSystemMetrics(SM_CYBORDER)+2),
971: min(300, rectWin.right - rectWin.left-nx-nx),
972: height,
973: TRUE);
974: if (!IsWindowVisible(hFont) && fLoaded)
975: ShowWindow(hFont, SW_SHOW);
976: }
977:
978:
979: DWORD
980: GetkStuff(
981: VOID
982: ) /* Get size of menu, scrollbar etc. */
983: {
984: RECT rect, rectWin;
985:
986: /* size message for hbox goes thru before hfont created. 06-Jul-1987. */
987: if (!hFont)
988: return 0;
989:
990: GetClientRect(hFont, (LPRECT)&rect); /* How much do WE get? */
991: GetWindowRect(hFont, (LPRECT)&rectWin);
992: return (DWORD) (rectWin.bottom - rectWin.top) - (rect.bottom - rect.top);
993: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.