home *** CD-ROM | disk | FTP | other *** search
- #ifdef MSW
-
- /* This started out as simple font management for the .ini file, but
- * it turned out I felt like keeping other display info-type things in the
- * .ini file, so you'll notice other non-font things in this file. I
- * should've created a new file, but I wanted to keep the .ini file in
- * once place and didn't want to spend the time to generalize the access.
- * Yes, I know - bad karma. (JAM)
- */
- #include "stdlib.h"
- #include "jam.h"
- #include "def.h"
- #include "stdio.h"
- #include "ttydef.h"
- #include "chrdef.h"
- #include "commdlg.h"
-
- /* user picks the font
- */
- static CHOOSEFONT *newfont;
- static LOGFONT *emaxfont;
- static TEXTMETRIC *textmetric;
-
- static void LoadTheFont(void);
-
- static COLORREF ttfore, ttback, tthigh;
- static BOOL newuser = TRUE;
-
- /* saveall settings
- */
- static char profile[NFILEN];
-
- static char NEAR *textcolor = "text";
- static char NEAR *highcolor = "touched";
- static char NEAR *windowcolor = "window";
- static char NEAR *newuserstr = "newuser";
- static char NEAR *weight = "weight";
- static char NEAR *height = "height";
- static char NEAR *name = "name";
- static char NEAR *pitch = "pitch";
- static char NEAR *slant = "slant";
- static char NEAR *defname = "terminal";
- static char NEAR *rows = "rows";
- static char NEAR *cols = "cols";
- static char NEAR *xpos = "x";
- static char NEAR *ypos = "y";
- static char NEAR *format = "%d";
- static char NEAR *lformat = "%lu";
-
- #define Weight (FF_MODERN | FW_NORMAL)
-
- /* resource string, default value
- */
- #define SaveStringResource(r, v)\
- WritePrivateProfileString(g_APPNAME, r, v, profile)
-
- /* resource string, default value
- */
- #define LoadIntResource(r, v)\
- (int)GetPrivateProfileInt(g_APPNAME, r, v, profile)
-
- /* resource string, default value, buffer, sizeof(buffer)
- */
- #define LoadStringResource(r, v, b, sz)\
- GetPrivateProfileString(g_APPNAME, r, v, b, sz, profile)
-
- /* save settings - fonts, pos/size, color, whatever
- */
- void SaveAllSettings(void)
- {
- char buf[100];
- RECT rect;
-
- /* fonts
- */
- SaveStringResource(name, emaxfont->lfFaceName); /* family name */
- sprintf(buf, format, emaxfont->lfWeight);
- SaveStringResource(weight, buf); /* weight */
- sprintf(buf, format, emaxfont->lfHeight);
- SaveStringResource(height, buf); /* height */
- sprintf(buf, format, emaxfont->lfPitchAndFamily);
- SaveStringResource(pitch, buf); /* pitch & family */
- sprintf(buf, format, emaxfont->lfItalic);
- SaveStringResource(slant, buf); /* italic or not */
-
- /* colors
- */
- sprintf(buf, lformat, ttfore);
- SaveStringResource(textcolor, buf);
- sprintf(buf, lformat, ttback);
- SaveStringResource(windowcolor, buf);
- sprintf(buf, lformat, tthigh);
- SaveStringResource(highcolor, buf);
-
- /* pos, rows, cols
- */
- if (!IsIconic(g_hWnd) && !IsZoomed(g_hWnd))
- {
- GetWindowRect(g_hWnd, &rect);
- sprintf(buf, format, rect.left);
- SaveStringResource(xpos, buf);
- sprintf(buf, format, rect.top);
- SaveStringResource(ypos, buf);
-
- sprintf(buf, format, nrow);
- SaveStringResource(rows, buf);
- sprintf(buf, format, ncol);
- SaveStringResource(cols, buf);
- WindowMessage("Current font & window settings saved", FALSE);
- }
- else
- WindowMessage("Current font & colors saved.", FALSE);
- }
-
- /* set the requested font size
- *
- * NOTE: this routine must be called before code which
- * restores settings, etc since it allocates data and computes
- * ini file name. (is called by WinMain in w3win)
- */
- void WindowInitFont(int fontsize)
- {
- if (!profile[0])
- {
- strcpy(profile, g_APPNAME);
- strcat(profile, ".ini");
- }
-
- /* set font, see if resources saved
- */
- if (!(emaxfont = (LOGFONT *)calloc(1, sizeof(LOGFONT))))
- WindowMessage("Unable to get LOGFONT", TRUE);
- if (!(textmetric = (TEXTMETRIC *)calloc(1, sizeof(TEXTMETRIC))))
- WindowMessage("Unable to get TEXTMETRIC", TRUE);
-
- LoadStringResource(name, defname, emaxfont->lfFaceName, LF_FACESIZE);
- emaxfont->lfWeight = LoadIntResource(weight, Weight);
- emaxfont->lfHeight = LoadIntResource(height, fontsize);
- emaxfont->lfPitchAndFamily = (BYTE)LoadIntResource(pitch, FIXED_PITCH);
- emaxfont->lfItalic = (BYTE)LoadIntResource(slant, 0);
-
- newuser = LoadIntResource(newuserstr, TRUE);
-
- /* create the font, then refetch the attributes
- * of the resulting match
- */
- LoadTheFont();
- GetObject(g_hfont, sizeof(LOGFONT), emaxfont);
- }
-
- /* work routine to create and set a LOGFONT into g_hDC
- */
- static void LoadTheFont()
- {
- /* delete any previous font created
- */
- if (g_oldFont)
- {
- SelectObject(g_hDC, g_oldFont);
- DeleteObject(g_hfont);
- }
-
- /* create new requested font
- */
- g_hfont = CreateFontIndirect(emaxfont);
- g_oldFont = SelectObject(g_hDC, g_hfont);
- GetTextMetrics(g_hDC, textmetric);
- g_nLineHeight = textmetric->tmExternalLeading + textmetric->tmHeight;
- g_nCharWidth = textmetric->tmMaxCharWidth + textmetric->tmOverhang;
- }
-
- /* dialogbox for new font
- */
- void WindowNewFont(void)
- {
- /* Before bringing up the dialog, kill the current
- * cursor (size defined by current font). WM_KILLFOCUS msg
- * triggers a cursor delete, WM_SETFOCUS recreates it
- * and thus it comes back the (new) right size.
- */
- SendMessage(g_hWnd, WM_KILLFOCUS, 0, 0L); /* bye bye cursor */
-
- /* Init the structure and do dialog
- */
- if (!(newfont = ( CHOOSEFONT *)calloc(1, sizeof(LOGFONT))))
- WindowMessage("Unable to get CHOOSEFONT", TRUE);
- newfont->lStructSize = sizeof(CHOOSEFONT);
- newfont->hwndOwner = g_hWnd;
- newfont->lpLogFont = emaxfont;
- newfont->nFontType = SCREEN_FONTTYPE;
- newfont->Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT;
- ChooseFont(newfont);
- LoadTheFont();
- free((void *)newfont);
-
- /* Send redraw/resize instruction (new # rows/cols based on
- * new font size) and recreate the cursor reflecting font cell size.
- */
- ExtendedFunction(function_name(myrefresh));
- SendMessage(g_hWnd, WM_SETFOCUS, 0, 0L);
- }
-
- /* Size the window based on current font and resources
- * for cols, lines, and colors
- */
- void InitWindow(int numcols, int numlines)
- {
- char fore[100], back[100], high[100];
- int oldcols = LoadIntResource(cols, numcols);
- int oldlines = LoadIntResource(rows, numlines);
- int x = LoadIntResource(xpos, 0);
- int y = LoadIntResource(ypos, 0);
-
- SizeWindow(x, y, oldcols, oldlines);
-
- /* Colors.
- */
- ttfore = GetSysColor(COLOR_WINDOWTEXT);
- tthigh = GetSysColor(COLOR_ACTIVECAPTION); /* ughly choice.. */
- ttback = GetSysColor(COLOR_WINDOW);
- fore[0] = high[0] = back[0] = '\0';
- LoadStringResource(textcolor, NULL, fore, sizeof(fore));
- LoadStringResource(highcolor, NULL, high, sizeof(high));
- LoadStringResource(windowcolor, NULL, back, sizeof(back));
-
- if (fore[0])
- sscanf(fore, lformat, &ttfore);
- if (back[0])
- sscanf(back, lformat, &ttback);
- if (high[0])
- sscanf(high, lformat, &tthigh);
- }
-
- /* tty access to colors for refresh
- */
- COLORREF GetForeColor()
- {
- return (ttfore);
- }
- COLORREF GetHighColor()
- {
- return (tthigh);
- }
- COLORREF GetBackColor()
- {
- return(ttback);
- }
-
- /* Access to saveable preferences, called from w3win
- * as a result of system menu choices for TEXT COLOR and WINDOW COLOR
- */
- void SetForeColor(color)
- COLORREF color;
- {
- ttfore = color;
- }
- void SetBackColor(color)
- COLORREF color;
- {
- ttback = color;
- }
- void SetHighColor(color)
- COLORREF color;
- {
- tthigh = color;
- }
-
- /* One time greeting box; same dialog as seen from ABOUT menu.
- * If no .ini file is found on startup, greet the user.
- */
- BOOL newUser()
- {
- char buf[128];
- BOOL was = newuser;
-
- /* user type
- */
- if (was)
- {
- sprintf(buf, format, newuser = FALSE);
- SaveStringResource(newuserstr, buf);
- }
-
- return (was);
- }
-
- #endif /* MSW */
-