Enable utf-8 and UNICODE for string handling.

preprocessor flag EXT_ASC resets handling to old behaviour.
Add utf-16 wide char to all Windows string i/o.
Add translation between utf-8 and utf-16.
Add angle to fcn DevDrawText.
This commit is contained in:
h_vogt 2017-10-04 13:06:19 +02:00 committed by Holger Vogt
parent 28c0fbf397
commit dbd0a5743a
4 changed files with 623 additions and 79 deletions

View File

@ -154,9 +154,16 @@ void ft_gnuplot(double *xlims, double *ylims,
}
/* Set up the file header. */
#if !defined(__MINGW32__) && !defined(_MSC_VER)
#if !defined(__MINGW__) && !defined(_MSC_VER) && !defined(__CYGWIN__)
fprintf(file, "set terminal X11 noenhanced\n");
#elif defined(__CYGWIN__)
#ifndef EXT_ASC
fprintf(file, "set encoding utf8\n");
#endif
#else
#ifndef EXT_ASC
fprintf(file, "set encoding utf8\n");
#endif
fprintf(file, "set termoption noenhanced\n");
#endif
if (title) {

View File

@ -17,10 +17,31 @@ Modified: 2001 AlansFixes
#include <stdlib.h>
#ifdef HAS_WINGUI
#undef BOOLEAN
#include <windows.h>
typedef struct { /* Extra window data */
HWND wnd; /* window */
HDC hDC; /* Device context of window */
RECT Area; /* plot area */
int ColorIndex; /* Index of actual color */
int PaintFlag; /* 1 with WM_PAINT */
int FirstFlag; /* 1 before first update */
} tWindowData;
typedef tWindowData *tpWindowData; /* pointer to it */
#endif
#ifndef X_DISPLAY_MISSING
extern bool old_x11;
extern int X11_GetLenStr(GRAPH *gr, char* instring);
#endif
#define RAD_TO_DEG (180.0 / M_PI)
#define RELPOSXUNIT 0.6 /* old position of the UNIT label */
typedef enum { x_axis, y_axis } Axis;
static int unitshift; /* shift of unit label if x label is too large */
static double *lingrid(GRAPH *graph, double lo, double hi, double delta, int type, Axis axis);
static double *loggrid(GRAPH *graph, double lo, double hi, int type, Axis axis);
@ -105,18 +126,6 @@ gr_fixgrid(GRAPH *graph, double xdelta, double ydelta, int xtype, int ytype)
graph->datawindow.xmin = dd[0];
graph->datawindow.xmax = dd[1];
/* do we really need this? */
/*
SetLinestyle(0);
DevDrawLine(graph->viewportxoff, graph->viewportyoff,
graph->viewport.width + graph->viewportxoff,
graph->viewportyoff);
DevDrawLine(graph->viewportxoff, graph->viewportyoff,
graph->viewportxoff,
graph->viewport.height + graph->viewportyoff);
SetLinestyle(1);
*/
}
@ -128,10 +137,73 @@ gr_redrawgrid(GRAPH *graph)
SetLinestyle(1);
/* draw labels */
if (graph->grid.xlabel) {
#if defined(EXT_ASC) || (!defined HAS_WINGUI && defined X_DISPLAY_MISSING)
DevDrawText(graph->grid.xlabel,
(int) (graph->absolute.width * 0.35),
(int)(graph->absolute.width * 0.35),
graph->fontheight, 0);
#else
if (eq(dispdev->name, "postscript"))
{
DevDrawText(graph->grid.xlabel,
(int)(graph->absolute.width * 0.35),
graph->fontheight, 0);
}
else {
#ifndef X_DISPLAY_MISSING
/* x axis centered to graphics on X11 */
/* utf-8: figure out the real length of the x label */
int wlen = 0, i = 0;
while (graph->grid.xlabel[i]) {
if ((graph->grid.xlabel[i] & 0xc0) != 0x80)
wlen++;
i++;
}
/* string lenth in pixels */
int strsize = X11_GetLenStr(graph, graph->grid.xlabel);
DevDrawText(graph->grid.xlabel,
(int)((graph->absolute.width - strsize) / 2), graph->fontheight, 0);
/* fix the position of the UNIT label */
if (RELPOSXUNIT * graph->absolute.width < ((graph->absolute.width + strsize) / 2 + graph->fontwidth))
unitshift = (int)((graph->absolute.width + strsize) / 2
- RELPOSXUNIT * graph->absolute.width)
+ graph->fontwidth;
else
unitshift = 0; /* reset for next plot window */
}
#endif
#ifdef HAS_WINGUI
/* x axis centered to graphics on Windows */
/* utf-8: figure out the real length of the x label */
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.xlabel) + 1);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1, wtext, 2 * strlen(graph->grid.xlabel) + 1);
if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", graph->grid.xlabel);
}
else {
SIZE sz;
TEXTMETRICW tmw;
tpWindowData wd = graph->devdep;
GetTextMetricsW(wd->hDC, &tmw);
GetTextExtentPoint32W(wd->hDC, wtext, wlen, &sz);
DevDrawText(graph->grid.xlabel,
(int)((graph->absolute.width - sz.cx + tmw.tmOverhang) / 2),
graph->fontheight, 0);
/* fix the position of the UNIT label */
if (RELPOSXUNIT * graph->absolute.width < (graph->absolute.width + sz.cx + tmw.tmOverhang) / 2 + graph->fontwidth)
unitshift = (int)((graph->absolute.width + sz.cx + tmw.tmOverhang) / 2
- RELPOSXUNIT * graph->absolute.width)
+ graph->fontwidth;
else
unitshift = 0; /* reset for next plot window */
}
}
#endif
#endif // EXT_ASC
}
/* y axis: vertical text, centered to graph */
if (graph->grid.ylabel) {
if (graph->grid.gridtype == GRID_POLAR ||
graph->grid.gridtype == GRID_SMITH ||
@ -141,12 +213,57 @@ gr_redrawgrid(GRAPH *graph)
graph->fontwidth,
(graph->absolute.height * 3) / 4, 0);
} else {
if (eq(dispdev->name, "postscript") || eq(dispdev->name, "Windows"))
if (eq(dispdev->name, "postscript"))
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90);
#ifdef EXT_ASC
else if (eq(dispdev->name, "Windows"))
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - (int) strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90);
else /* FIXME: for now excluding X11 and others */
(graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90);
#else
#ifdef HAS_WINGUI
/* Windows and UTF-8: check for string length (in pixels),
place vertical text centered in y with respect to grid */
else if (eq(dispdev->name, "Windows")) {
/* utf-8: figure out the real length of the y label */
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.ylabel) + 1);
int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1, wtext, 2 * strlen(graph->grid.ylabel) + 1);
if (wlen == 0) {
fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", graph->grid.ylabel);
}
else {
SIZE sz;
TEXTMETRICW tmw;
tpWindowData wd = graph->devdep;
GetTextMetricsW(wd->hDC, &tmw);
GetTextExtentPoint32W(wd->hDC, wtext, wlen, &sz);
// printf("length: %d, deviation: %d\n", sz.cx, sz.cx - graph->fontwidth*wlen);
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
/*vertical text, midpoint in y is aligned midpoint of text string */
(graph->absolute.height - (int)(1.2*sz.cx + tmw.tmOverhang)) / 2, 90);
}
}
#endif
#ifndef X_DISPLAY_MISSING
/* new x11 with xft and utf-8 */
else if (!old_x11) {
/* calculate and add offsets in fcn X11_Text in X11.c */
DevDrawText(graph->grid.ylabel,
0,
/*vertical text, y is midpoint of graph height */
(graph->absolute.height) / 2, 90);
}
#endif
#endif
else /* others */
DevDrawText(graph->grid.ylabel,
graph->fontwidth,
graph->absolute.height / 2, 90);
@ -324,7 +441,7 @@ lingrid(GRAPH *graph, double lo, double hi, double delta, int type, Axis axis)
graph->viewportxoff = (digits + 5 + mag - mag3) * graph->fontwidth;
/* add height of the vertical text to offset*/
if (graph->grid.ylabel)
graph->viewportxoff += graph->fontheight;
graph->viewportxoff += (int)(1.6 * graph->fontheight);
margin = graph->viewportyoff;
/*max = graph->viewport.height + graph->viewportyoff;*/
max = graph->absolute.height - graph->viewportyoff;
@ -383,11 +500,10 @@ lingrid(GRAPH *graph, double lo, double hi, double delta, int type, Axis axis)
buf[0] = '\0';
}
s = ft_typabbrev(type);
if (!s)
s = "Units";
strncat(buf, s, sizeof(buf) - strlen(buf) - 1);
if ((s = ft_typabbrev(type)) != NULL)
(void) strncat(buf, s, sizeof(buf) - strlen(buf) - 1);
else
(void) strncat(buf, "Units", sizeof(buf) - strlen(buf) - 1);
if (delta == 0.0) {
int i;
double step;
@ -535,12 +651,12 @@ drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double
if (axis == x_axis)
DevDrawLine(graph->viewportxoff + i,
graph->viewportyoff, graph->viewportxoff + i,
graph->viewport.height + graph->viewportyoff);
graph->viewport.height + graph->viewportyoff, TRUE);
else
DevDrawLine(graph->viewportxoff,
graph->viewportyoff + i,
graph->viewport.width + graph->viewportxoff,
graph->viewportyoff + i);
graph->viewportyoff + i, TRUE);
}
if (j == 0)
SetLinestyle(1);
@ -562,8 +678,7 @@ drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double
j += 1000;
}
if (axis == x_axis)
DevDrawText(units, (int) (graph->absolute.width * 0.6),
graph->fontheight, 0);
DevDrawText(units, (int) (graph->absolute.width * RELPOSXUNIT + unitshift), graph->fontheight, 0);
else
DevDrawText(units, graph->fontwidth,
(int) (graph->absolute.height - 2 * graph->fontheight), 0);
@ -698,13 +813,15 @@ drawloggrid(GRAPH *graph, char *units, int hmt, int lmt, int decsp, int subs, in
graph->viewportyoff,
graph->viewportxoff + i,
graph->viewport.height
+graph->viewportyoff);
+graph->viewportyoff,
TRUE);
else
DevDrawLine(graph->viewportxoff,
graph->viewportyoff + i,
graph->viewport.width
+ graph->viewportxoff,
graph->viewportyoff + i);
graph->viewportyoff + i,
TRUE);
}
if (j == -2)
@ -745,13 +862,15 @@ drawloggrid(GRAPH *graph, char *units, int hmt, int lmt, int decsp, int subs, in
graph->viewportyoff,
graph->viewportxoff + m,
graph->viewport.height
+ graph->viewportyoff);
+ graph->viewportyoff,
TRUE);
else
DevDrawLine(graph->viewportxoff,
graph->viewportyoff + m,
graph->viewport.width
+ graph->viewportxoff,
graph->viewportyoff + m);
graph->viewportyoff + m,
TRUE);
}
}
SetLinestyle(0);
@ -759,7 +878,7 @@ drawloggrid(GRAPH *graph, char *units, int hmt, int lmt, int decsp, int subs, in
}
if (axis == x_axis)
DevDrawText(units, (int) (graph->absolute.width * 0.6),
DevDrawText(units, (int) (graph->absolute.width * RELPOSXUNIT + unitshift),
graph->fontheight, 0);
else
DevDrawText(units, graph->fontwidth,
@ -938,7 +1057,7 @@ drawpolargrid(GRAPH *graph)
graph->grid.yaxis.circular.center,
graph->grid.xaxis.circular.radius))
{
DevDrawLine(x1, y1, x2, y2);
DevDrawLine(x1, y1, x2, y2, TRUE);
/* Add a label here */
/*XXXX*/
adddeglabel(graph, i * 30, x2, y2, x1, y1,
@ -974,7 +1093,7 @@ drawpolargrid(GRAPH *graph)
graph->grid.xaxis.circular.center,
graph->grid.yaxis.circular.center,
graph->grid.xaxis.circular.radius)) {
DevDrawLine(x1, y1, x2, y2);
DevDrawLine(x1, y1, x2, y2, TRUE);
/* Put on the label */
adddeglabel(graph, i, x2, y2, x1, y1,
graph->grid.xaxis.circular.center,
@ -1313,7 +1432,7 @@ drawsmithgrid(GRAPH *graph)
if (zheight < 0)
zheight = - zheight;
DevDrawLine(gr_xcenter - zheight, gr_ycenter + yoff,
gr_xcenter + zheight, gr_ycenter + yoff);
gr_xcenter + zheight, gr_ycenter + yoff, TRUE);
DevDrawText("0", gr_xcenter + zheight + gi_fntwidth, gr_ycenter + yoff -
gi_fntheight / 2, 0);
DevDrawText("o", gr_xcenter + zheight + gi_fntwidth * 2, gr_ycenter + yoff, 0);

View File

@ -3,7 +3,7 @@
* Wolfgang Muees 27.10.97
* Holger Vogt 07.12.01
* Holger Vogt 05.12.07
* Holger Vogt 01.11.18
* Holger Vogt 01.11.18
*/
#include "ngspice/ngspice.h"
@ -73,6 +73,7 @@ extern void com_hardcopy(wordlist *wl);
#endif
#define DEF_FONTW "Arial"
#define DEFW_FONTW L"Arial"
/* local variables */
static int IsRegistered = 0; /* 1 if window class is registered */
@ -80,6 +81,8 @@ static int IsRegistered = 0; /* 1 if window class is regis
static COLORREF ColorTable[NumWinColors]; /* color memory */
static char *WindowName = "Spice Plot"; /* window name */
static WNDCLASS TheWndClass; /* Plot-window class */
static wchar_t * WindowNameW = L"Spice Plot"; /* window name */
static WNDCLASSW TheWndClassW; /* Plot-window class */
static HFONT PlotFont; /* which font */
#define ID_DRUCKEN 0xEFF0 /* System Menue: print */
#define ID_DRUCKEINR 0xEFE0 /* System Menue: printer setup */
@ -91,9 +94,14 @@ static char *STR_DRUCKEN = "Printer..."; /* System menue strings */
static char *STR_DRUCKEINR = "Printer setup...";
static char *STR_HARDCOPY = "Postscript file, color";
static char *STR_HARDCOPY_BW = "Postscript file, b&w";
static wchar_t * STRW_DRUCKEN = L"Printer..."; /* System menue strings */
static wchar_t * STRW_DRUCKEINR = L"Printer setup...";
static wchar_t * STRW_HARDCOPY = L"Postscript file, color";
static wchar_t * STRW_HARDCOPY_BW = L"Postscript file, b&w";
static bool isblack = TRUE; /* background color of plot is black */
static bool isblackold = TRUE;
static int linewidth = 0; /* linewidth of grid and plot */
static int gridlinewidth = 0; /* linewidth of grid */
/******************************************************************************
WIN_Init() makes connection to graphics. We have to determine
@ -110,6 +118,13 @@ WIN_Init() does not yet open a window, this happens only in WIN_NewViewport()
int WIN_Init(void)
{
char colorstring[BSIZE_SP];
char facename[32];
#ifdef EXT_ASC
LOGFONT lf;
#else
LOGFONTW lfw;
#endif
/* Initialization of display descriptor */
dispdev->width = GetSystemMetrics(SM_CXSCREEN);
@ -120,8 +135,10 @@ int WIN_Init(void)
/* always, user may have set color0 to white */
/* get background color information from spinit, only "white"
is recognized as a suitable option! */
if (cp_getvar("color0", CP_STRING, colorstring, sizeof(colorstring)))
isblack = !cieq(colorstring, "white");
if (cp_getvar("color0", CP_STRING, colorstring, sizeof(colorstring))) {
if (cieq(colorstring, "white")) isblack = FALSE;
else isblack = TRUE;
}
/* get linewidth information from spinit */
if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) {
@ -131,18 +148,17 @@ int WIN_Init(void)
linewidth = 0;
}
/* get linewidth for grid from spinit */
if (!cp_getvar("gridwidth", CP_NUM, &gridlinewidth, 0))
gridlinewidth = linewidth;
if (gridlinewidth < 0)
gridlinewidth = 0;
/* only for the first time: */
if (!IsRegistered) {
isblackold = isblack;
/* get linewidth information from spinit
* if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0))
* linewidth = 0;
* if (linewidth < 0)
* linewidth = 0;
*/
/* Initialize colors */
if (isblack) {
ColorTable[0] = RGB( 0, 0, 0); /* black = background */
@ -184,8 +200,8 @@ int WIN_Init(void)
ColorTable[22] = RGB(255, 128, 128); /* pink */
/* Ansii fixed font */
PlotFont = GetStockFont(ANSI_FIXED_FONT);
// PlotFont = GetStockFont(ANSI_FIXED_FONT);
#ifdef EXT_ASC
/* register window class */
TheWndClass.lpszClassName = WindowName;
TheWndClass.hInstance = hInst;
@ -207,7 +223,25 @@ int WIN_Init(void)
if (!RegisterClass(&TheWndClass)) {
return 1;
}
#else
/* register window class */
TheWndClassW.lpszClassName = WindowNameW;
TheWndClassW.hInstance = hInst;
TheWndClassW.lpfnWndProc = PlotWindowProc;
TheWndClassW.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
TheWndClassW.lpszMenuName = NULL;
TheWndClassW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(32512) /*IDC_ARROW*/);
if (isblack)
TheWndClassW.hbrBackground = GetStockObject(BLACK_BRUSH);
else
TheWndClassW.hbrBackground = GetStockObject(WHITE_BRUSH);
TheWndClassW.hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(2));
TheWndClassW.cbClsExtra = 0;
TheWndClassW.cbWndExtra = sizeof(GRAPH *);
if (!RegisterClassW(&TheWndClassW)) return 1;
#endif
}
/* not first time */
else if (isblackold != isblack) {
@ -229,6 +263,55 @@ int WIN_Init(void)
isblackold = isblack;
}
IsRegistered = 1;
#ifdef EXT_ASC
// lf.lfHeight = 18;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 500;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = 0;
lf.lfOutPrecision = 0;
lf.lfClipPrecision = 0;
lf.lfQuality = 0;
lf.lfPitchAndFamily = 0;
/* set up fonts */
if (!cp_getvar("wfont", CP_STRING, lf.lfFaceName)) {
(void)lstrcpy(lf.lfFaceName, DEF_FONTW);
}
if (!cp_getvar("wfont_size", CP_NUM, &(lf.lfHeight))) {
lf.lfHeight = 18;
}
PlotFont = CreateFontIndirect(&lf);
#else
// lfw.lfHeight = 18;
lfw.lfWidth = 0;
lfw.lfEscapement = 0;
lfw.lfOrientation = 0;
lfw.lfWeight = 500;
lfw.lfItalic = 0;
lfw.lfUnderline = 0;
lfw.lfStrikeOut = 0;
lfw.lfCharSet = 0;
lfw.lfOutPrecision = 0;
lfw.lfClipPrecision = 0;
lfw.lfQuality = 0;
lfw.lfPitchAndFamily = 0;
if (!cp_getvar("wfont", CP_STRING, facename, sizeof(facename))) {
(void)lstrcpyW(lfw.lfFaceName, DEFW_FONTW);
}
else {
wchar_t wface[32];
swprintf(wface, 32, L"%S", facename);
(void)lstrcpyW(lfw.lfFaceName, wface);
}
if (!cp_getvar("wfont_size", CP_NUM, &(lfw.lfHeight), 0)) {
lfw.lfHeight = 18;
}
PlotFont = CreateFontIndirectW(&lfw);
#endif
/* ready */
return 0;
@ -239,7 +322,11 @@ int WIN_Init(void)
/* (attach to window) */
static GRAPH *pGraph(HWND hwnd)
{
#ifdef EXT_ASC
return (GRAPH *) GetWindowLongPtr(hwnd, 0);
#else
return (GRAPH *) GetWindowLongPtrW( hwnd, 0);
#endif
}
@ -599,7 +686,11 @@ LRESULT CALLBACK PlotWindowProc(HWND hwnd, UINT uMsg,
default:
WIN_DEFAULT:
#ifdef EXT_ASC
return DefWindowProc(hwnd, uMsg, wParam, lParam);
#else
return DefWindowProcW( hwnd, uMsg, wParam, lParam);
#endif
}
}
@ -616,7 +707,11 @@ int WIN_NewViewport(GRAPH *graph)
int i;
HWND window;
HDC dc;
#ifdef EXT_ASC
TEXTMETRIC tm;
#else
TEXTMETRICW tmw;
#endif
tpWindowData wd;
HMENU sysmenu;
@ -642,9 +737,23 @@ int WIN_NewViewport(GRAPH *graph)
/* Create the window */
i = GetSystemMetrics(SM_CYSCREEN) / 3;
#ifdef EXT_ASC
window = CreateWindow(WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
if (!window) {
#else
/* UTF-8 support */
wchar_t *wtext, *wtext2;
wtext = TMALLOC(wchar_t, 2 * strlen(graph->plotname) + 1);
wtext2 = TMALLOC(wchar_t, 2 * strlen(WindowName) + 1);
/* translate UTF-8 to UTF-16 */
MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, 2 * strlen(graph->plotname) + 1);
MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, 2 * strlen(WindowName) + 1);
window = CreateWindowW(wtext2, wtext, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
tfree(wtext);
tfree(wtext2);
#endif
if (!window)
return 1;
}
@ -695,11 +804,17 @@ int WIN_NewViewport(GRAPH *graph)
SelectObject(dc, PlotFont);
/* query the font parameters */
#ifdef EXT_ASC
if (GetTextMetrics(dc, &tm)) {
graph->fontheight = tm.tmHeight;
graph->fontwidth = tm.tmAveCharWidth;
}
#else
if (GetTextMetricsW(dc, &tmw)) {
graph->fontheight = tmw.tmHeight;
graph->fontwidth = tmw.tmAveCharWidth + 1; /*FIXME relationship between height and width for various fonts*/
}
#endif
/* set viewport parameters */
graph->viewport.height = wd->Area.bottom;
graph->viewport.width = wd->Area.right;
@ -767,7 +882,8 @@ int WIN_Clear(void)
}
int WIN_DrawLine(int x1, int y1, int x2, int y2)
int
WIN_DrawLine(int x1, int y1, int x2, int y2, bool isgrid)
{
tpWindowData wd;
HPEN OldPen;
@ -781,7 +897,10 @@ int WIN_DrawLine(int x1, int y1, int x2, int y2)
return 0;
MoveToEx(wd->hDC, x1, wd->Area.bottom - y1, NULL);
NewPen = CreatePen(LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex]);
if (isgrid)
NewPen = CreatePen(LType(wd->ColorIndex), gridlinewidth, ColorTable[wd->ColorIndex]);
else
NewPen = CreatePen(LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex]);
OldPen = SelectObject(wd->hDC, NewPen);
LineTo(wd->hDC, x2, wd->Area.bottom - y2);
OldPen = SelectObject(wd->hDC, OldPen);
@ -875,7 +994,13 @@ int WIN_Text(char *text, int x, int y, int angle)
{
tpWindowData wd;
HFONT hfont;
#ifdef EXT_ASC
LOGFONT lf;
#else
LOGFONTW lfw;
#endif
if (!currentgraph)
return 0;
@ -884,6 +1009,7 @@ int WIN_Text(char *text, int x, int y, int angle)
if (!wd)
return 0;
#ifdef EXT_ASC
lf.lfHeight = (int) (1.1 * currentgraph->fontheight);
lf.lfWidth = 0;
lf.lfEscapement = angle * 10;
@ -903,15 +1029,60 @@ int WIN_Text(char *text, int x, int y, int angle)
(void) lstrcpy(lf.lfFaceName, DEF_FONTW);
if (!cp_getvar("wfont_size", CP_NUM, &(lf.lfHeight), 0))
lf.lfHeight = (int) (1.3 * currentgraph->fontheight);
lf.lfHeight = 18;
//lf.lfHeight = (int) (1.3 * currentgraph->fontheight);
hfont = CreateFontIndirect (&lf);
#else
char facename[32];
lfw.lfHeight = (int)(1.1 * currentgraph->fontheight);
lfw.lfWidth = 0;
lfw.lfEscapement = angle * 10;
lfw.lfOrientation = angle * 10;
lfw.lfWeight = 500;
lfw.lfItalic = 0;
lfw.lfUnderline = 0;
lfw.lfStrikeOut = 0;
lfw.lfCharSet = 0;
lfw.lfOutPrecision = 0;
lfw.lfClipPrecision = 0;
lfw.lfQuality = 0;
lfw.lfPitchAndFamily = 0;
/* set up fonts */
if (!cp_getvar("wfont", CP_STRING, facename, sizeof(facename))) {
(void)lstrcpyW(lfw.lfFaceName, DEFW_FONTW);
}
else {
wchar_t wface[32];
swprintf(wface, 32, L"%S", facename);
(void)lstrcpyW(lfw.lfFaceName, wface);
}
if (!cp_getvar("wfont_size", CP_NUM, &(lfw.lfHeight), 0)) {
lfw.lfHeight = 18;
}
else {
currentgraph->fontheight = lfw.lfHeight;
currentgraph->fontwidth = (int)(lfw.lfHeight*0.52);
}
hfont = CreateFontIndirectW(&lfw);
#endif
SelectObject(wd->hDC, hfont);
SetTextColor(wd->hDC, ColorTable[wd->ColorIndex]);
#ifdef EXT_ASC
TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text));
DeleteObject(SelectObject(wd->hDC, GetStockObject(SYSTEM_FONT)));
#else
wchar_t *wtext;
wtext = TMALLOC(wchar_t, 2 * strlen(text) + 1);
MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 2 * strlen(text) + 1);
TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, wtext, 2 * (int)strlen(text) + 1);
tfree(wtext);
#endif
DeleteObject(SelectObject(wd->hDC, hfont));
return 0;
}
@ -1018,8 +1189,8 @@ static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy)
{
lmin = log10(graph->datawindow.ymin);
lmax = log10(graph->datawindow.ymax);
*fy = exp(((graph->absolute.height - y - graph->viewportyoff) *
(lmax - lmin) / graph->viewport.height + lmin) * M_LN10);
*fy = exp(((graph->absolute.height - y - graph->viewportxoff) *
(lmax - lmin) / graph->viewport.height + lmin) * M_LN10);
} else {
*fy = ((graph->absolute.height - y) - graph->viewportyoff) *
graph->aspectratioy + graph->datawindow.ymin;

View File

@ -2,6 +2,7 @@
Autor: Wolfgang Muees
Stand: 28.10.97
Copyright: Holger Vogt
Stand: 09.01.2018
Stand: 20.07.2019
Modified BSD license
*/
@ -30,6 +31,7 @@
#include "hist_info.h" /* history management */
#include "ngspice/bool.h" /* bool defined as unsigned char */
#include "misc/misc_time.h" /* timediff */
#include "ngspice/memory.h" /* TMALLOC */
#include "winmain.h"
/* Constants */
@ -76,28 +78,42 @@ HWND hwQuitButton; /* Pause button */
static int nReturnCode = 0; /* WinMain return value */
static int nShowState; /* Display mode of main window */
static WNDCLASS hwMainClass; /* Class definition for the main window */
static WNDCLASSW hwMainClassW; /* Class definition for the main window */
static LPCTSTR hwClassName = "SPICE_TEXT_WND";/* Class name of the main window */
static LPCTSTR hwWindowName = PACKAGE_STRING; /* main window displayed name */
static LPCWSTR hwClassNameW = L"SPICE_TEXT_WND";/* Class name of the main window */
static LPCWSTR hwWindowNameW = L"ngspice 26"; /* main window displayed name */
static WNDCLASS twTextClass; /* Class definition for the text box */
static WNDCLASSW twTextClassW; /* Class definition for the text box */
static LPCTSTR twClassName = "SPICE_TEXT_BOX"; /* Class name for the text box */
static LPCTSTR twWindowName = "TextOut"; /* text box name */
static LPCWSTR twClassNameW = L"SPICE_TEXT_BOX"; /* Class name for the text box */
static LPCWSTR twWindowNameW = L"TextOut"; /* text box name */
static size_t TBufEnd = 0; /* Pointer to \0 */
static char TBuffer[TBufSize + 1]; /* Text buffer */
static SBufLine SBuffer; /* Input buffer */
static WNDCLASS swStringClass; /* Class definition of string window */
static LPCTSTR swClassName = "SPICE_STR_IN"; /* Class name of text input */
static LPCTSTR swWindowName = "StringIn"; /* Window name */
static WNDCLASSW swStringClassW; /* Class definition of string window */
static LPCWSTR swClassNameW = L"SPICE_STR_IN"; /* Class name of text input */
static LPCWSTR swWindowNameW = L"StringIn"; /* Window name */
static char CRLF[] = {CR, LF, SE}; /* CR/LF */
static WNDCLASS hwElementClass; /* Class definition of status displays */
static LPCTSTR hwElementClassName = "ElementClass";
static LPCTSTR hwSourceWindowName = "SourceDisplay";
static LPCTSTR hwAnalyseWindowName = "AnalyseDisplay";
static WNDCLASSW hwElementClassW; /* Class definition of status displays */
static LPCWSTR hwElementClassNameW = L"ElementClass";
static LPCWSTR hwSourceWindowNameW = L"SourceDisplay";
static LPCWSTR hwAnalyseWindowNameW = L"AnalyseDisplay";
static int RowHeight = 16; /* Height of line of text */
static int LineHeight = 25; /* Height of input line */
static int VisibleRows = 10; /* Number of visible lines in text window */
static BOOL DoUpdate = FALSE; /* Update text window */
static WNDPROC swProc = NULL; /* original string window procedure */
static WNDPROC twProc = NULL; /* original text window procedure */
static HFONT sfont; /* Font for source and analysis window */
extern bool ft_ngdebug; /* some additional debug info printed */
extern bool ft_batchmode;
@ -160,9 +176,17 @@ void
SetSource(char *Name)
{
if (hwSource) {
#ifdef EXT_ASC
SetWindowText(hwSource, Name);
#else
wchar_t *NameW;
NameW = TMALLOC(wchar_t, 2 * strlen(Name) + 1);
MultiByteToWideChar(CP_UTF8, 0, Name, -1, NameW, 2 * strlen(Name) + 1);
SetWindowTextW(hwSource, NameW);
tfree(NameW);
#endif
InvalidateRgn(hwSource, NULL, TRUE);
}
}
}
@ -203,9 +227,9 @@ SetAnalyse(char *Analyse, /* in: analysis type */
OldPercent = DecaPercent;
/* output only into hwAnalyse window and if time elapsed is larger than
DELTATIME given value, or if analysis has changed, else return */
if (((diffsec > 0) || (diffmillisec > DELTATIME) || strcmp(OldAn, Analyse))) {
if (hwAnalyse && ((diffsec > 0) || (diffmillisec > DELTATIME) || strcmp(OldAn, Analyse))) {
if (DecaPercent < 0) {
sprintf(s, "--ready--");
sprintf(s, " -- ready --");
sprintf(t, "%s", PACKAGE_STRING);
}
else if (DecaPercent == 0) {
@ -231,8 +255,17 @@ SetAnalyse(char *Analyse, /* in: analysis type */
strncpy(OldAn, Analyse, 127);
}
#ifdef EXT_ASC
SetWindowText(hwAnalyse, s);
SetWindowText(hwMain, t);
#else
wchar_t sw[256];
wchar_t tw[256];
swprintf(sw, 256, L"%S", s);
swprintf(tw, 256, L"%S", t);
SetWindowTextW(hwAnalyse, sw);
SetWindowTextW(hwMain, tw);
#endif
InvalidateRgn(hwAnalyse, NULL, TRUE);
InvalidateRgn(hwMain, NULL, TRUE);
}
@ -359,8 +392,17 @@ AppendString(const char *Line)
static void
DisplayText(void)
{
// Darstellen
// Show text
#ifdef EXT_ASC
Edit_SetText(twText, TBuffer);
#else
wchar_t *TWBuffer;
TWBuffer = TMALLOC(wchar_t, 2 * strlen(TBuffer) + 1);
if (MultiByteToWideChar(CP_UTF8, 0, TBuffer, -1, TWBuffer, 2 * strlen(TBuffer) + 1) == 0)
swprintf(TWBuffer, 2 * strlen(TBuffer), L"UTF-8 to UTF-16 conversion failed with 0x%x\n%hs could not be converted\n", GetLastError(), TBuffer);
SetWindowTextW(twText, TWBuffer);
tfree(TWBuffer);
#endif
// Scroller updaten, neuen Text darstellen
AdjustScroller();
}
@ -454,14 +496,12 @@ Main_OnSize(HWND hwnd, UINT state, int cx, int cy)
MoveWindow(swString, 0, h, cx, LineHeight, TRUE);
/* Expand Status Elements */
h = cy - LineHeight + StatusFrame - 1;
MoveWindow(hwSource, StatusFrame, h, SourceLength, StatusElHeight, TRUE);
MoveWindow(hwAnalyse,
cx - 3 * StatusFrame - QuitButtonLength - AnalyseLength - 20,
h, AnalyseLength, StatusElHeight, TRUE);
MoveWindow(hwQuitButton,
cx - StatusFrame - QuitButtonLength - 20,
h, QuitButtonLength, StatusElHeight, TRUE);
h = cy - LineHeight + StatusFrame - 2;
int statbegin = 3 * StatusFrame + QuitButtonLength + AnalyseLength + 4;
MoveWindow(hwSource, StatusFrame, h, cx - statbegin - BorderSize, StatusElHeight, TRUE);
MoveWindow( hwAnalyse, cx - statbegin, h, AnalyseLength, StatusElHeight, TRUE);
MoveWindow( hwQuitButton, cx - StatusFrame - QuitButtonLength - 1,
h + 1, QuitButtonLength, StatusElHeight, TRUE);
}
@ -504,7 +544,11 @@ MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
default:
DEFAULT_AFTER:
#ifdef EXT_ASC
return DefWindowProc(hwnd, uMsg, wParam, lParam);
#else
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
#endif
}
}
@ -592,7 +636,11 @@ StringWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
} /* end of switch over handled messages */
/* Fowrard to be processed further by swProc */
return CallWindowProc(swProc, hwnd, uMsg, wParam, lParam);
#ifdef EXT_ASC
return CallWindowProc(swProc, hwnd, uMsg, wParam, lParam);
#else
return CallWindowProcW( swProc, hwnd, uMsg, wParam, lParam);
#endif
}
@ -628,7 +676,11 @@ TextWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
default:
DEFAULT_TEXT:
#ifdef EXT_ASC
return CallWindowProc(twProc, hwnd, uMsg, wParam, lParam);
#else
return CallWindowProcW( twProc, hwnd, uMsg, wParam, lParam);
#endif
}
}
@ -640,7 +692,11 @@ Element_OnPaint(HWND hwnd)
RECT r;
RECT s;
HGDIOBJ o;
#ifdef EXT_ASC
char buffer[128];
#else
wchar_t bufferW[256];
#endif
int i;
/* Prepare */
@ -669,6 +725,7 @@ Element_OnPaint(HWND hwnd)
FillRect(hdc, &s, o);
/* Draw contents */
#ifdef EXT_ASC
buffer[0] = '\0';
i = GetWindowText(hwnd, buffer, 127);
s.left = r.left + 1;
@ -679,7 +736,19 @@ Element_OnPaint(HWND hwnd)
FillRect(hdc, &s, o);
SetBkMode(hdc, TRANSPARENT);
ExtTextOut(hdc, s.left + 1, s.top + 1, ETO_CLIPPED, &s, buffer, (unsigned)i, NULL);
#else
bufferW[0] = '\0';
i = GetWindowTextW(hwnd, bufferW, 255);
s.left = r.left + 1;
s.right = r.right - 1;
s.top = r.top + 1;
s.bottom = r.bottom - 1;
o = GetSysColorBrush(COLOR_BTNFACE);
FillRect(hdc, &s, o);
SetBkMode(hdc, TRANSPARENT);
SelectObject(hdc, sfont);
ExtTextOutW(hdc, s.left + 1, s.top + 1, ETO_CLIPPED, &s, bufferW, (unsigned)i, NULL);
#endif
/* End */
EndPaint(hwnd, &ps);
}
@ -696,7 +765,11 @@ ElementWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return 0;
default:
#ifdef EXT_ASC
return DefWindowProc(hwnd, uMsg, wParam, lParam);
#else
return DefWindowProcW( hwnd, uMsg, wParam, lParam);
#endif
}
}
@ -850,9 +923,16 @@ MakeArgcArgv(char *cmdline, int *argc, char ***argv)
/* Main entry point for our Windows application */
#ifdef EXT_ASC
int WINAPI
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpszCmdLine, _In_ int nCmdShow)
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpszCmdLine, _In_ int nCmdShow)
#elif __MINGW32__ /* MINGW bug not knowing wWinMain */
int WINAPI
WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR nolpszCmdLine, _In_ int nCmdShow)
#else
int WINAPI
wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR wlpszCmdLine, _In_ int nCmdShow)
#endif
{
int ix, iy; /* width and height of screen */
int status;
@ -871,6 +951,38 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
NG_IGNORE(hPrevInstance);
#ifndef EXT_ASC
/* convert wchar to utf-8 */
/* MINGW not knowing wWinMain
https://github.com/coderforlife/mingw-unicode-main/blob/master/mingw-unicode-gui.c
*/
#ifdef __MINGW32__
NG_IGNORE(nolpszCmdLine);
char lpszCmdLine[1024];
wchar_t *lpCmdLine = GetCommandLineW();
if (__argc == 1) { // avoids GetCommandLineW bug that does not always quote the program name if no arguments
do { ++lpCmdLine; } while (*lpCmdLine);
}
else {
BOOL quoted = lpCmdLine[0] == L'"';
++lpCmdLine; // skips the " or the first letter (all paths are at least 1 letter)
while (*lpCmdLine) {
if (quoted && lpCmdLine[0] == L'"') { quoted = FALSE; } // found end quote
else if (!quoted && lpCmdLine[0] == L' ') {
// found an unquoted space, now skip all spaces
do { ++lpCmdLine; } while (lpCmdLine[0] == L' ');
break;
}
++lpCmdLine;
}
}
WideCharToMultiByte(CP_UTF8, 0, lpCmdLine, -1, lpszCmdLine, 1023, NULL, NULL);
#else
char lpszCmdLine[1024];
WideCharToMultiByte(CP_UTF8, 0, wlpszCmdLine, -1, lpszCmdLine, 1023, NULL, NULL);
#endif
#endif
/* fill global variables */
hInst = hInstance;
nShowState = nCmdShow;
@ -881,6 +993,7 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
SBuffer[0] = SE;
/* Define main window class */
#ifdef EXT_ASC
hwMainClass.style = CS_HREDRAW | CS_VREDRAW;
hwMainClass.lpfnWndProc = MainWindowProc;
hwMainClass.cbClsExtra = 0;
@ -894,8 +1007,23 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
if (!RegisterClass(&hwMainClass))
goto THE_END;
#else
hwMainClassW.style = CS_HREDRAW | CS_VREDRAW;
hwMainClassW.lpfnWndProc = MainWindowProc;
hwMainClassW.cbClsExtra = 0;
hwMainClassW.cbWndExtra = 0;
hwMainClassW.hInstance = hInst;
hwMainClassW.hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(1));
hwMainClassW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(32512));
hwMainClassW.hbrBackground = GetStockObject(LTGRAY_BRUSH);
hwMainClassW.lpszMenuName = NULL;
hwMainClassW.lpszClassName = hwClassNameW;
if (!RegisterClassW(&hwMainClassW))
goto THE_END;
#endif
/* Define text window class */
#ifdef EXT_ASC
if (!GetClassInfo(NULL, "EDIT", &twTextClass))
goto THE_END;
@ -907,8 +1035,19 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
if (!RegisterClass(&twTextClass))
goto THE_END;
#else
if (!GetClassInfoW(NULL, L"EDIT", &twTextClassW)) goto THE_END;
twProc = twTextClassW.lpfnWndProc;
twTextClassW.lpfnWndProc = TextWindowProc;
twTextClassW.hInstance = hInst;
twTextClassW.lpszMenuName = NULL;
twTextClassW.lpszClassName = twClassNameW;
if (!RegisterClassW(&twTextClassW))
goto THE_END;
#endif
/* Define string window class */
#ifdef EXT_ASC
if (!GetClassInfo(NULL, "EDIT", &swStringClass))
goto THE_END;
@ -920,8 +1059,19 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
if (!RegisterClass(&swStringClass))
goto THE_END;
#else
if (!GetClassInfoW(NULL, L"EDIT", &swStringClassW)) goto THE_END;
swProc = swStringClassW.lpfnWndProc;
swStringClassW.lpfnWndProc = StringWindowProc;
swStringClassW.hInstance = hInst;
swStringClassW.lpszMenuName = NULL;
swStringClassW.lpszClassName = swClassNameW;
if (!RegisterClassW(&swStringClassW))
goto THE_END;
#endif
/* Define status element class */
#ifdef EXT_ASC
hwElementClass.style = CS_HREDRAW | CS_VREDRAW;
hwElementClass.lpfnWndProc = ElementWindowProc;
hwElementClass.cbClsExtra = 0;
@ -935,34 +1085,67 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
if (!RegisterClass(&hwElementClass))
goto THE_END;
#else
hwElementClassW.style = CS_HREDRAW | CS_VREDRAW;
hwElementClassW.lpfnWndProc = ElementWindowProc;
hwElementClassW.cbClsExtra = 0;
hwElementClassW.cbWndExtra = 0;
hwElementClassW.hInstance = hInst;
hwElementClassW.hIcon = NULL;
hwElementClassW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(32512));
hwElementClassW.hbrBackground = GetStockObject(LTGRAY_BRUSH);
hwElementClassW.lpszMenuName = NULL;
hwElementClassW.lpszClassName = hwElementClassNameW;
if (!RegisterClassW(&hwElementClassW))
goto THE_END;
#endif
/*Create main window */
// iy = GetSystemMetrics(SM_CYSCREEN);
// iyt = GetSystemMetrics(SM_CYSCREEN) / 3;
// ix = GetSystemMetrics(SM_CXSCREEN);
/* Font for element status windows (source, analysis) */
sfont = CreateFontW(16, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, L"");
// sfont = CreateFontW(15, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, FIXED_PITCH | FF_MODERN, L"Courier"); /*Create main window */
#ifdef EXT_ASC
SystemParametersInfo(SPI_GETWORKAREA, 0, &wsize, 0);
#else
SystemParametersInfoW(SPI_GETWORKAREA, 0, &wsize, 0);
#endif
iy = wsize.bottom;
ix = wsize.right;
#ifndef BIG_WINDOW_FOR_DEBUGGING
const int iyt = iy / 3; /* height of screen divided by 3 */
#ifdef EXT_ASC
hwMain = CreateWindow(hwClassName, hwWindowName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
0, iyt * 2, ix, iyt, NULL, NULL, hInst, NULL);
#else
hwMain = CreateWindowW(hwClassNameW, hwWindowNameW, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
0, iyt * 2, ix, iyt, NULL, NULL, hInst, NULL);
#endif
#else
#ifdef EXT_ASC
hwMain = CreateWindow(hwClassName, hwWindowName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
0, 0, ix, iy, NULL, NULL, hInst, NULL);
#else
hwMain = CreateWindowW(hwClassName, hwWindowName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
0, 0, ix, iy, NULL, NULL, hInst, NULL);
#endif
#endif
if (!hwMain)
goto THE_END;
/* Create text window */
#ifdef EXT_ASC
twText = CreateWindowEx(WS_EX_NOPARENTNOTIFY, twClassName, twWindowName,
ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_BORDER | WS_VSCROLL,
20, 20, 300, 100, hwMain, NULL, hInst, NULL);
#else
twText = CreateWindowExW(WS_EX_NOPARENTNOTIFY, twClassNameW, twWindowNameW,
ES_LEFT | ES_MULTILINE | ES_READONLY | WS_CHILD | WS_BORDER | WS_VSCROLL,
20,20,300,100, hwMain, NULL, hInst, NULL);
#endif
if (!twText)
goto THE_END;
/* Ansii fixed font */
#ifdef EXT_ASC
{
HDC textDC;
HFONT font;
@ -979,9 +1162,32 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
ReleaseDC(twText, textDC);
}
}
#else
{
HDC textDC;
HFONT font;
TEXTMETRICW tm;
// font = CreateFontW(14, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, FIXED_PITCH | FF_MODERN, L"Lucida Console");
// if(!font)
font = CreateFontW(15, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, FIXED_PITCH | FF_MODERN, L"Courier");
if(!font)
font = GetStockFont(ANSI_FIXED_FONT);
SetWindowFont( twText, font, FALSE);
textDC = GetDC( twText);
if (textDC) {
SelectObject( textDC, font);
if (GetTextMetricsW( textDC, &tm)) {
RowHeight = tm.tmHeight;
WinLineWidth = 90 * tm.tmAveCharWidth;
}
ReleaseDC( twText, textDC);
}
}
#endif
/* Create string window for input. Give a handle to history info to
* the window for saving and retrieving commands */
#ifdef EXT_ASC
swString = CreateWindowEx(WS_EX_NOPARENTNOTIFY, swClassName, swWindowName,
ES_LEFT | WS_CHILD | WS_BORDER |
ES_AUTOHSCROLL, /* Allow text to scroll */
@ -999,29 +1205,70 @@ WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
LineHeight = tm.tmHeight + tm.tmExternalLeading + BorderSize;
ReleaseDC(swString, stringDC);
}
}
}
#else
swString = CreateWindowExW(WS_EX_NOPARENTNOTIFY, swClassNameW, swWindowNameW,
ES_LEFT | WS_CHILD | WS_BORDER, 20, 20, 300, 100, hwMain, NULL, hInst, NULL);
if (!swString)
goto THE_END;
{
HDC stringDC;
TEXTMETRIC tm;
stringDC = GetDC(swString);
if (stringDC) {
if (GetTextMetricsW(stringDC, &tm))
LineHeight = tm.tmHeight + tm.tmExternalLeading + BorderSize;
ReleaseDC(swString, stringDC);
}
}
#endif
/* Create source window */
#ifdef EXT_ASC
hwSource = CreateWindowEx(WS_EX_NOPARENTNOTIFY, hwElementClassName, hwSourceWindowName,
WS_CHILD,
0, 0, SourceLength, StatusElHeight, hwMain, NULL, hInst, NULL);
if (!hwSource)
goto THE_END;
#else
hwSource = CreateWindowExW(WS_EX_NOPARENTNOTIFY, hwElementClassNameW, hwSourceWindowNameW,
WS_CHILD,
0, 0, SourceLength, StatusElHeight, hwMain, NULL, hInst, NULL);
if (!hwSource) goto THE_END;
#endif
/* Create analysis window */
#ifdef EXT_ASC
hwAnalyse = CreateWindowEx(WS_EX_NOPARENTNOTIFY, hwElementClassName, hwAnalyseWindowName,
WS_CHILD,
0, 0, AnalyseLength, StatusElHeight, hwMain, NULL, hInst, NULL);
#else
hwAnalyse = CreateWindowExW(WS_EX_NOPARENTNOTIFY, hwElementClassNameW, hwAnalyseWindowNameW,
WS_CHILD,
0,0, AnalyseLength, StatusElHeight, hwMain, NULL, hInst, NULL);
#endif
if (!hwAnalyse)
goto THE_END;
/* Create "Quit" button */
#ifdef EXT_ASC
hwQuitButton = CreateWindow("BUTTON", "Quit", WS_CHILD | BS_PUSHBUTTON, 0, 0, QuitButtonLength,
StatusElHeight, hwMain, (HMENU)(UINT_PTR)QUIT_BUTTON_ID, hInst, NULL);
#else
hwQuitButton = CreateWindowW(L"BUTTON", L"Quit", WS_CHILD | BS_PUSHBUTTON, 0, 0, QuitButtonLength,
StatusElHeight, hwMain, (HMENU)(UINT_PTR)QUIT_BUTTON_ID, hInst, NULL);
#endif
if (!hwQuitButton)
goto THE_END;
/* Define a minimum width */
int MinWidth = AnalyseLength + SourceLength + QuitButtonLength + 48;
if (WinLineWidth < MinWidth)
WinLineWidth = MinWidth;
/* Make main window and subwindows visible.
Size of windows allows display of 80 character line.