Browse Source

winmain.c, etc, whitespace cleanup

pre-master-46
rlar 9 years ago
parent
commit
90a205d36d
  1. 358
      src/frontend/wdisp/windisp.c
  2. 79
      src/include/ngspice/wstdio.h
  3. 624
      src/winmain.c
  4. 94
      src/winmain.h

358
src/frontend/wdisp/windisp.c

@ -40,21 +40,24 @@ typedef struct { /* Extra window data */
int PaintFlag; /* 1 with WM_PAINT */
int FirstFlag; /* 1 before first update */
} tWindowData;
typedef tWindowData * tpWindowData; /* pointer to it */
typedef tWindowData *tpWindowData; /* pointer to it */
#define pWindowData(g) ((tpWindowData)(g->devdep))
/* forwards */
LRESULT CALLBACK PlotWindowProc( HWND hwnd, /* window procedure */
UINT uMsg, WPARAM wParam, LPARAM lParam);
void WPRINT_PrintInit( HWND hwnd); /* Windows printer init */
LRESULT CALLBACK PlotWindowProc(HWND hwnd, /* window procedure */
UINT uMsg, WPARAM wParam, LPARAM lParam);
void WPRINT_PrintInit(HWND hwnd); /* Windows printer init */
void WaitForIdle(void); /* wait until no more events */
static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy);
static LRESULT HcpyPlot( HWND hwnd);
static LRESULT HcpyPlotBW( HWND hwnd);
static LRESULT PrintPlot( HWND hwnd);
static LRESULT PrintInit( HWND hwnd);
static LRESULT HcpyPlot(HWND hwnd);
static LRESULT HcpyPlotBW(HWND hwnd);
static LRESULT PrintPlot(HWND hwnd);
static LRESULT PrintInit(HWND hwnd);
//static void RealClose(void);
/* externals */
extern HINSTANCE hInst; /* application instance */
extern int WinLineWidth; /* width of text window */
extern HWND swString; /* string input window of main window */
@ -65,6 +68,7 @@ extern void com_hardcopy(wordlist *wl);
/* defines */
#define RAD_TO_DEG (180.0 / M_PI)
#ifndef M_LN10
#define M_LN10 2.30258509299404568402
#endif
@ -75,7 +79,7 @@ extern void com_hardcopy(wordlist *wl);
static int IsRegistered = 0; /* 1 if window class is registered */
#define NumWinColors 23 /* predefined colors */
static COLORREF ColorTable[NumWinColors]; /* color memory */
static char * WindowName = "Spice Plot"; /* window name */
static char *WindowName = "Spice Plot"; /* window name */
static WNDCLASS TheWndClass; /* Plot-window class */
static HFONT PlotFont; /* which font */
#define ID_DRUCKEN 0xEFF0 /* System Menue: print */
@ -84,10 +88,10 @@ static HFONT PlotFont; /* which font */
#define ID_HARDCOPY_BW 0xEFB0 /* System Menue: hardcopy b&w*/
#define ID_MASK 0xFFF0; /* System-Menue: mask */
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 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 bool isblack = TRUE; /* background color of plot is black */
static bool isblackold = TRUE;
static int linewidth = 0; /* linewidth of grid and plot */
@ -110,8 +114,8 @@ int WIN_Init(void)
char colorstring[BSIZE_SP];
/* Initialization of display descriptor */
dispdev->width = GetSystemMetrics( SM_CXSCREEN);
dispdev->height = GetSystemMetrics( SM_CYSCREEN);
dispdev->width = GetSystemMetrics(SM_CXSCREEN);
dispdev->height = GetSystemMetrics(SM_CYSCREEN);
dispdev->numlinestyles = 5; /* see implications in WinPrint! */
dispdev->numcolors = NumWinColors;
@ -122,6 +126,7 @@ int WIN_Init(void)
if (cieq(colorstring, "white")) isblack = FALSE;
else isblack = TRUE;
}
/* get linewidth information from spinit */
if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
linewidth = 0;
@ -140,41 +145,43 @@ int WIN_Init(void)
/* Initialize colors */
if (isblack) {
ColorTable[0] = RGB( 0, 0, 0); /* black = background */
ColorTable[1] = RGB(255,255,255); /* white = text and grid */
ColorTable[1] = RGB(255, 255, 255); /* white = text and grid */
}
else {
ColorTable[0] = RGB(255,255,255); /* white = background */
ColorTable[0] = RGB(255, 255, 255); /* white = background */
ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */
}
ColorTable[2] = RGB( 0,255, 0); /* green = first line */
ColorTable[2] = RGB( 0, 255, 0); /* green = first line */
ColorTable[3] = RGB(255, 0, 0); /* red */
ColorTable[4] = RGB( 0, 0,255); /* blue */
ColorTable[5] = RGB(255,255, 0); /* yellow */
ColorTable[6] = RGB(255, 0,255); /* violett */
ColorTable[7] = RGB( 0,255,255); /* azur */
ColorTable[8] = RGB(255,128, 0); /* orange */
ColorTable[4] = RGB( 0, 0, 255); /* blue */
ColorTable[5] = RGB(255, 255, 0); /* yellow */
ColorTable[6] = RGB(255, 0, 255); /* violett */
ColorTable[7] = RGB( 0, 255, 255); /* azur */
ColorTable[8] = RGB(255, 128, 0); /* orange */
ColorTable[9] = RGB(128, 64, 0); /* brown */
ColorTable[10]= RGB(128, 0,255); /* light violett */
ColorTable[11]= RGB(255,128,128); /* pink */
ColorTable[10] = RGB(128, 0, 255); /* light violett */
ColorTable[11] = RGB(255, 128, 128); /* pink */
/* 2. color bank (with different line style */
if (isblack)
ColorTable[12]= RGB(255,255,255); /* white */
ColorTable[12] = RGB(255, 255, 255); /* white */
else
ColorTable[12]= RGB( 0, 0, 0); /* black */
ColorTable[13]= RGB( 0,255, 0); /* green */
ColorTable[14]= RGB(255, 0, 0); /* red */
ColorTable[15]= RGB( 0, 0,255); /* blue */
ColorTable[16]= RGB(255,255, 0); /* yellow */
ColorTable[17]= RGB(255, 0,255); /* violett */
ColorTable[18]= RGB( 0,255,255); /* azur */
ColorTable[19]= RGB(255,128, 0); /* orange */
ColorTable[20]= RGB(128, 64, 0); /* brown */
ColorTable[21]= RGB(128, 0,255); /* light violett */
ColorTable[22]= RGB(255,128,128); /* pink */
ColorTable[12] = RGB( 0, 0, 0); /* black */
ColorTable[13] = RGB( 0, 255, 0); /* green */
ColorTable[14] = RGB(255, 0, 0); /* red */
ColorTable[15] = RGB( 0, 0, 255); /* blue */
ColorTable[16] = RGB(255, 255, 0); /* yellow */
ColorTable[17] = RGB(255, 0, 255); /* violett */
ColorTable[18] = RGB( 0, 255, 255); /* azur */
ColorTable[19] = RGB(255, 128, 0); /* orange */
ColorTable[20] = RGB(128, 64, 0); /* brown */
ColorTable[21] = RGB(128, 0, 255); /* light violett */
ColorTable[22] = RGB(255, 128, 128); /* pink */
/* Ansii fixed font */
PlotFont = GetStockFont( ANSI_FIXED_FONT);
PlotFont = GetStockFont(ANSI_FIXED_FONT);
/* register window class */
TheWndClass.lpszClassName = WindowName;
@ -183,31 +190,34 @@ int WIN_Init(void)
TheWndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
TheWndClass.lpszMenuName = NULL;
TheWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
if (isblack)
TheWndClass.hbrBackground = GetStockObject( BLACK_BRUSH);
TheWndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
else
TheWndClass.hbrBackground = GetStockObject( WHITE_BRUSH);
TheWndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
TheWndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(2));
TheWndClass.cbClsExtra = 0;
TheWndClass.cbWndExtra = sizeof(GRAPH *);
if (!RegisterClass(&TheWndClass)) return 1;
}
/* not first time */
else if (isblackold != isblack) {
if (isblack) {
ColorTable[0] = RGB( 0, 0, 0); /* black = background */
ColorTable[1] = RGB(255,255,255); /* white = text and grid */
ColorTable[1] = RGB(255, 255, 255); /* white = text and grid */
}
else {
ColorTable[0] = RGB(255,255,255); /* white = background */
ColorTable[0] = RGB(255, 255, 255); /* white = background */
ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */
}
if (isblack)
ColorTable[12]= RGB(255,255,255); /* white */
ColorTable[12] = RGB(255, 255, 255); /* white */
else
ColorTable[12]= RGB( 0, 0, 0); /* black */
ColorTable[12] = RGB( 0, 0, 0); /* black */
isblackold=isblack;
isblackold = isblack;
}
IsRegistered = 1;
@ -215,15 +225,17 @@ int WIN_Init(void)
return (0);
}
/* get pointer to graph */
/* (attach to window) */
static GRAPH * pGraph( HWND hwnd)
static GRAPH *pGraph(HWND hwnd)
{
return (GRAPH *) GetWindowLongPtr( hwnd, 0);
return (GRAPH *) GetWindowLongPtr(hwnd, 0);
}
/* return line style for plotting */
static int LType( int ColorIndex)
static int LType(int ColorIndex)
{
if (ColorIndex >= 12)
return PS_DOT;
@ -231,9 +243,10 @@ static int LType( int ColorIndex)
return PS_SOLID;
}
/* postscript hardcopy from a plot window */
/* postscript hardcopy from a plot window */
/* called by SystemMenue / Postscript hardcopy */
static LRESULT HcpyPlot( HWND hwnd)
static LRESULT HcpyPlot(HWND hwnd)
{
int colorval = isblack? 0 : 1;
NG_IGNORE(hwnd);
@ -242,7 +255,8 @@ static LRESULT HcpyPlot( HWND hwnd)
return 0;
}
static LRESULT HcpyPlotBW( HWND hwnd)
static LRESULT HcpyPlotBW(HWND hwnd)
{
int bgcolor;
NG_IGNORE(hwnd);
@ -255,13 +269,13 @@ static LRESULT HcpyPlotBW( HWND hwnd)
/* print a plot window */
/* called by SystemMenue / Print */
static LRESULT PrintPlot( HWND hwnd)
static LRESULT PrintPlot(HWND hwnd)
{
GRAPH * graph;
GRAPH * temp;
GRAPH *graph;
GRAPH *temp;
/* get pointer to graph */
graph = pGraph( hwnd);
graph = pGraph(hwnd);
if (!graph) return 0;
/* switch to printer */
@ -269,7 +283,7 @@ static LRESULT PrintPlot( HWND hwnd)
if (DevSwitch("WinPrint")) return 0;
/* Cursor = wait */
SetCursor( LoadCursor( NULL, IDC_WAIT));
SetCursor(LoadCursor(NULL, IDC_WAIT));
/* copy graph */
temp = CopyGraph(graph);
@ -285,35 +299,37 @@ static LRESULT PrintPlot( HWND hwnd)
/* print the graph */
gr_resize(temp);
PrintEND2:
PrintEND2:
/* delete temporary graph */
DestroyGraph(temp->graphid);
PrintEND:
PrintEND:
/* switch back to screen */
DevSwitch(NULL);
/* Cursor = normal */
SetCursor( LoadCursor( NULL, IDC_ARROW));
SetCursor(LoadCursor(NULL, IDC_ARROW));
return 0;
}
/* initialze printer */
static LRESULT PrintInit( HWND hwnd)
static LRESULT PrintInit(HWND hwnd)
{
/* hand over to printer module */
WPRINT_PrintInit(hwnd);
return 0;
}
/* window procedure */
LRESULT CALLBACK PlotWindowProc( HWND hwnd,
LRESULT CALLBACK PlotWindowProc(HWND hwnd,
UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static int x0,y0,xep,yep;
static int x0, y0, xep, yep;
int xe, ye, prevmix;
static double fx0,fy0;
static double fx0, fy0;
double fxe, fye;
double angle;
char buf[BSIZE_SP];
@ -329,17 +345,17 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
/* test command */
WPARAM cmd = wParam & ID_MASK;
switch(cmd) {
case ID_DRUCKEN: return PrintPlot( hwnd);
case ID_DRUCKEINR: return PrintInit( hwnd);
case ID_HARDCOPY: return HcpyPlot( hwnd);
case ID_HARDCOPY_BW: return HcpyPlotBW( hwnd);
case ID_DRUCKEN: return PrintPlot(hwnd);
case ID_DRUCKEINR: return PrintInit(hwnd);
case ID_HARDCOPY: return HcpyPlot(hwnd);
case ID_HARDCOPY_BW: return HcpyPlotBW(hwnd);
}
}
goto WIN_DEFAULT;
case WM_LBUTTONDOWN:
{
GRAPH * gr = pGraph( hwnd);
GRAPH *gr = pGraph(hwnd);
xep = x0 = LOWORD (lParam);
yep = y0 = HIWORD (lParam);
/* generate x,y data from grid coordinates */
@ -351,64 +367,64 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
/* left mouse button: connect coordinate pair by dashed pair of x, y lines */
if (wParam & MK_LBUTTON)
{
hdc = GetDC (hwnd) ;
hdc = GetDC(hwnd);
if (isblack)
prevmix = SetROP2(hdc, R2_XORPEN);
else
prevmix = SetROP2(hdc, R2_NOTXORPEN);
/* Create white dashed pen */
NewPen = CreatePen( LType(12), 0, ColorTable[1] );
NewPen = CreatePen(LType(12), 0, ColorTable[1]);
OldPen = SelectObject(hdc, NewPen);
/* draw lines with previous coodinates -> delete old line because of XOR */
MoveToEx (hdc, x0, y0, NULL) ;
LineTo (hdc, x0, yep) ;
MoveToEx (hdc, x0, y0, NULL);
LineTo (hdc, x0, yep);
LineTo (hdc, xep, yep);
/* get new end point */
xe = LOWORD (lParam);
ye = HIWORD (lParam);
/* draw new lines */
MoveToEx (hdc, x0, y0, NULL) ;
LineTo (hdc, x0, ye) ;
MoveToEx (hdc, x0, y0, NULL);
LineTo (hdc, x0, ye);
LineTo (hdc, xe, ye);
/* restore standard color mix */
SetROP2(hdc, prevmix);
OldPen = SelectObject(hdc, OldPen);
DeleteObject( NewPen);
ReleaseDC (hwnd, hdc) ;
DeleteObject(NewPen);
ReleaseDC (hwnd, hdc);
/* restore new to previous coordinates */
yep = ye;
xep = xe;
}
/* right mouse button: create white (black) dashed box */
else if (wParam & MK_RBUTTON){
hdc = GetDC (hwnd) ;
else if (wParam & MK_RBUTTON) {
hdc = GetDC (hwnd);
if (isblack)
prevmix = SetROP2(hdc, R2_XORPEN);
else
prevmix = SetROP2(hdc, R2_NOTXORPEN);
/* Create white (black) dashed pen */
NewPen = CreatePen( LType(12), 0, ColorTable[1] );
NewPen = CreatePen(LType(12), 0, ColorTable[1]);
OldPen = SelectObject(hdc, NewPen);
/* draw box with previous coodinates -> delete old lines because of XOR */
MoveToEx (hdc, x0, y0, NULL) ;
LineTo (hdc, x0, yep) ;
MoveToEx (hdc, x0, y0, NULL);
LineTo (hdc, x0, yep);
LineTo (hdc, xep, yep);
LineTo (hdc, xep, y0) ;
LineTo (hdc, xep, y0);
LineTo (hdc, x0, y0);
/* get new end point */
xe = LOWORD (lParam);
ye = HIWORD (lParam);
/* draw new box */
MoveToEx (hdc, x0, y0, NULL) ;
LineTo (hdc, x0, ye) ;
MoveToEx (hdc, x0, y0, NULL);
LineTo (hdc, x0, ye);
LineTo (hdc, xe, ye);
LineTo (hdc, xe, y0) ;
LineTo (hdc, xe, y0);
LineTo (hdc, x0, y0);
/* restore standard color mix */
SetROP2(hdc, prevmix);
OldPen = SelectObject(hdc, OldPen);
DeleteObject( NewPen);
ReleaseDC (hwnd, hdc) ;
DeleteObject(NewPen);
ReleaseDC (hwnd, hdc);
/* restore new to previous coordinates */
yep = ye;
xep = xe;
@ -419,8 +435,8 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
/* calculate and print out the data */
case WM_LBUTTONUP:
{
GRAPH * gr = pGraph( hwnd);
InvalidateRect (hwnd, NULL, TRUE) ;
GRAPH *gr = pGraph(hwnd);
InvalidateRect (hwnd, NULL, TRUE);
xe = LOWORD (lParam);
ye = HIWORD (lParam);
WIN_ScreentoData(gr, xe, ye, &fxe, &fye);
@ -432,10 +448,10 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
|| gr->grid.gridtype == GRID_SMITH
|| gr->grid.gridtype == GRID_SMITHGRID)
{
angle = RAD_TO_DEG * atan2( fy0, fx0 );
angle = RAD_TO_DEG * atan2(fy0, fx0);
fprintf(stdout, "r0 = %g, a0 = %g\n",
hypot(fx0, fy0),
(angle>0)?angle:360.0+angle);
(angle > 0) ? angle : 360.0 + angle);
}
} else {
/* need to print info about two points */
@ -448,34 +464,35 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
/* which is uninteresting */
fprintf(stdout, "dy/dx = %g dx/dy = %g\n",
(fye-fy0)/(fxe-fx0), (fxe-fx0)/(fye-fy0));
(fye - fy0) / (fxe - fx0), (fxe - fx0) / (fye - fy0));
}
}
SetFocus( swString);
SetFocus(swString);
}
goto WIN_DEFAULT;
/* get starting coordinates upon right mouse button down */
case WM_RBUTTONDOWN:
{
GRAPH * gr = pGraph( hwnd);
GRAPH *gr = pGraph(hwnd);
x0 = xep = LOWORD (lParam);
y0 = yep = HIWORD (lParam);
WIN_ScreentoData(gr, x0, y0, &fx0, &fy0);
}
goto WIN_DEFAULT;
/* get final coordinates upon right mouse button up */
/* copy xlimit, ylimit command into buf */
/* start plot loop with argument buf */
case WM_RBUTTONUP:
{
GRAPH * gr = pGraph( hwnd);
InvalidateRect (hwnd, NULL, TRUE) ;
GRAPH *gr = pGraph(hwnd);
InvalidateRect (hwnd, NULL, TRUE);
xe = LOWORD (lParam);
ye = HIWORD (lParam);
/* do nothing if mouse curser is not moved in both x and y */
if ((xe == x0) || (ye == y0)) {
SetFocus( swString);
SetFocus(swString);
goto WIN_DEFAULT;
}
WIN_ScreentoData(gr, xe, ye, &fxe, &fye);
@ -495,13 +512,13 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
}
(void) cp_evloop(buf);
SetFocus( swString);
SetFocus(swString);
}
goto WIN_DEFAULT;
case WM_CLOSE: /* close window */
{
GRAPH * g = pGraph( hwnd);
GRAPH *g = pGraph(hwnd);
if (g) {
/* if g equals currentgraph, reset currentgraph. */
@ -515,14 +532,14 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
case WM_PAINT: /* replot window (e.g. after Resize) */
{
PAINTSTRUCT ps;
GRAPH * g;
GRAPH *g;
tpWindowData wd;
HDC saveDC; /* the DC from BeginPaint is different... */
HDC newDC;
/* has to happen */
newDC = BeginPaint( hwnd, &ps);
g = pGraph( hwnd);
newDC = BeginPaint(hwnd, &ps);
g = pGraph(hwnd);
if (g) {
wd = pWindowData(g);
if (wd) {
@ -530,7 +547,7 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
/* avoid recursive call */
wd->PaintFlag = 1;
/* get window sizes */
GetClientRect( hwnd, &(wd->Area));
GetClientRect(hwnd, &(wd->Area));
g->absolute.width = wd->Area.right;
g->absolute.height = wd->Area.bottom;
/* switch DC */
@ -553,13 +570,13 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
}
}
/* finish */
EndPaint( hwnd, &ps);
EndPaint(hwnd, &ps);
}
return 0;
default:
WIN_DEFAULT:
return DefWindowProc( hwnd, uMsg, wParam, lParam);
WIN_DEFAULT:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
@ -571,7 +588,7 @@ WIN_DEFAULT:
******************************************************************************/
int WIN_NewViewport( GRAPH * graph)
int WIN_NewViewport(GRAPH *graph)
{
int i;
HWND window;
@ -592,11 +609,12 @@ int WIN_NewViewport( GRAPH * graph)
/* allocate device dependency info */
wd = calloc(1, sizeof(tWindowData));
if (!wd) return 1;
graph->devdep = wd;
/* Create the window */
i = GetSystemMetrics( SM_CYSCREEN) / 3;
window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
i = GetSystemMetrics(SM_CYSCREEN) / 3;
window = CreateWindow(WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
if (!window) return 1;
@ -612,13 +630,13 @@ int WIN_NewViewport( GRAPH * graph)
SetWindowLongPtr(window, 0, (LONG_PTR)graph);
/* show window */
ShowWindow( window, SW_SHOWNORMAL);
ShowWindow(window, SW_SHOWNORMAL);
/* get the mask */
GetClientRect( window, &(wd->Area));
GetClientRect(window, &(wd->Area));
/* get the DC */
dc = GetDC( window);
dc = GetDC(window);
wd->hDC = dc;
/* set the Color Index */
@ -629,22 +647,22 @@ int WIN_NewViewport( GRAPH * graph)
wd->FirstFlag = 1;
/* modify system menue */
sysmenu = GetSystemMenu( window, FALSE);
AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR);
AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY);
AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW);
sysmenu = GetSystemMenu(window, FALSE);
AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL);
AppendMenu(sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN);
AppendMenu(sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR);
AppendMenu(sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY);
AppendMenu(sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW);
/* set default parameters of DC */
SetBkColor( dc, ColorTable[0]);
SetBkMode( dc, TRANSPARENT );
SetBkColor(dc, ColorTable[0]);
SetBkMode(dc, TRANSPARENT );
/* set font */
SelectObject( dc, PlotFont);
SelectObject(dc, PlotFont);
/* query the font parameters */
if (GetTextMetrics( dc, &tm)) {
if (GetTextMetrics(dc, &tm)) {
graph->fontheight = tm.tmHeight;
graph->fontwidth = tm.tmAveCharWidth;
}
@ -666,6 +684,7 @@ int WIN_NewViewport( GRAPH * graph)
return(0);
}
/******************************************************************************
WIN_Close is essentially the counterpart to WIN_Init. unfortunately it might
happen, that WIN_Close is called during plotting, because one wants to switch
@ -677,30 +696,36 @@ int WIN_Close(void)
{
return (0);
}
/*
static void RealClose(void)
{
// delete window class
if (IsRegistered) {
if (TheWndClass.hIcon) {
DestroyIcon( TheWndClass.hIcon);
DestroyIcon(TheWndClass.hIcon);
TheWndClass.hIcon = NULL;
}
UnregisterClass( WindowName, hInst);
UnregisterClass(WindowName, hInst);
IsRegistered = FALSE;
}
}
*/
*/
int WIN_Clear(void)
{
tpWindowData wd;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
/* this is done by the window itself */
if (!wd->PaintFlag) /* not necessary with WM_PAINT */
SendMessage( wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0);
SendMessage(wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0);
return 0;
}
@ -713,22 +738,23 @@ int WIN_DrawLine(int x1, int y1, int x2, int y2)
HPEN NewPen;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
MoveToEx(wd->hDC, x1, wd->Area.bottom - y1, NULL);
NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] );
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);
DeleteObject( NewPen);
DeleteObject(NewPen);
return (0);
}
int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
/*
/*
* Notes:
* Draws an arc of <radius> and center at (x0,y0) beginning at
* angle theta (in rad) and ending at theta + delta_theta
@ -746,6 +772,7 @@ int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
double dy0;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
@ -755,7 +782,7 @@ int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
delta_theta = - delta_theta;
direction = AD_CLOCKWISE;
}
SetArcDirection( wd->hDC, direction);
SetArcDirection(wd->hDC, direction);
/* some geometric considerations in advance */
yb = wd->Area.bottom;
@ -773,30 +800,35 @@ int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
ye = (int)(dy0 + (r * sin(theta + delta_theta)));
/* plot */
NewPen = CreatePen( LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex] );
NewPen = CreatePen(LType(wd->ColorIndex), linewidth, ColorTable[wd->ColorIndex]);
OldPen = SelectObject(wd->hDC, NewPen);
Arc( wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);
Arc(wd->hDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);
OldPen = SelectObject(wd->hDC, OldPen);
DeleteObject( NewPen);
DeleteObject(NewPen);
return 0;
}
/*
int WIN_Text_old( char * text, int x, int y, int degrees)
int WIN_Text_old(char * text, int x, int y, int degrees)
{
tpWindowData wd;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
SetTextColor( wd->hDC, ColorTable[wd->ColorIndex]);
TextOut( wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, strlen(text));
SetTextColor(wd->hDC, ColorTable[wd->ColorIndex]);
TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, strlen(text));
return (0);
}
*/
int WIN_Text( char * text, int x, int y)
int WIN_Text(char * text, int x, int y)
{
tpWindowData wd;
HFONT hfont;
@ -805,38 +837,40 @@ int WIN_Text( char * text, int x, int y)
int CentiDegrees = 0;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
lf.lfHeight = (int) (1.1 * currentgraph->fontheight) ;
lf.lfWidth = 0 ;
lf.lfEscapement = CentiDegrees ;
lf.lfOrientation = CentiDegrees ;
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 ;
lf.lfHeight = (int) (1.1 * currentgraph->fontheight);
lf.lfWidth = 0;
lf.lfEscapement = CentiDegrees;
lf.lfOrientation = CentiDegrees;
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 = (int) (1.1 * currentgraph->fontheight) ;
lf.lfHeight = (int) (1.1 * currentgraph->fontheight);
}
// lstrcpy (lf.lfFaceName, "Courier"/*"Times New Roman"*/) ;
// lstrcpy (lf.lfFaceName, "Courier"/*"Times New Roman"*/);
hfont = CreateFontIndirect (&lf);
SelectObject(wd->hDC, hfont);
SetTextColor( wd->hDC, ColorTable[wd->ColorIndex]);
TextOut( wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text));
SetTextColor(wd->hDC, ColorTable[wd->ColorIndex]);
TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text));
DeleteObject(SelectObject(wd->hDC, GetStockObject(SYSTEM_FONT)));
@ -854,6 +888,7 @@ int WIN_DefineColor(int colorid, double red, double green, double blue)
return (0);
}
int WIN_DefineLinestyle(int num, int mask)
{
/* nothing */
@ -862,6 +897,7 @@ int WIN_DefineLinestyle(int num, int mask)
return (0);
}
int WIN_SetLinestyle(int style)
{
/* nothing */
@ -869,10 +905,13 @@ int WIN_SetLinestyle(int style)
return (0);
}
int WIN_SetColor( int color)
int WIN_SetColor(int color)
{
tpWindowData wd;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
@ -881,10 +920,13 @@ int WIN_SetColor( int color)
return (0);
}
int WIN_Update(void)
{
tpWindowData wd;
if (!currentgraph) return 0;
wd = pWindowData(currentgraph);
if (!wd) return 0;
@ -894,20 +936,26 @@ int WIN_Update(void)
wd->FirstFlag = 0;
return 0;
}
/*
int WIN_DiagramReady(void)
{
return 0;
}
*/
void RemoveWindow(GRAPH* dgraph)
{
tpWindowData wd;
wd = pWindowData(dgraph);
if (wd)
SendMessage(wd->wnd, WM_CLOSE, (WPARAM) wd->hDC, 0);
}
/* Function borrowed from x11.c */
static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy)
{

79
src/include/ngspice/wstdio.h

@ -1,10 +1,11 @@
/* I/O Redirection for Spice 3F4 under Win32s
Autor: Wolfgang Muees
Stand: 21.05.95
*/
*/
#ifndef ngspice_WSTDIO_H
#define ngspice_WSTDIO_H
#include <stdio.h> /* original definitions */
#undef getc /* old macros removed */
@ -15,53 +16,55 @@
#undef feof
#undef ferror
/* -------------------------------<forwards>----------------------------------*/
/* -------------------------------<forwards>---------------------------------- */
int win_x_fclose(FILE *stream);
int win_x_fflush(FILE *stream);
int win_x_fgetc(FILE *stream);
int win_x_fgetpos(FILE *stream, fpos_t *pos);
char *win_x_fgets(char *s, int n, FILE *stream);
int win_x_fprintf(FILE *stream, const char *format, ...);
int win_x_fputc(int c, FILE *stream);
int win_x_fputs(const char *s, FILE *stream);
size_t win_x_fread(void *ptr, size_t size, size_t n, FILE *stream);
FILE *win_x_freopen(const char *path, const char *mode, FILE *stream);
int win_x_fscanf(FILE *stream, const char *format, ...);
int win_x_fseek(FILE *stream, long offset, int whence);
int win_x_fsetpos(FILE *stream, const fpos_t*pos);
long win_x_ftell(FILE *stream);
size_t win_x_fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
char *win_x_gets(char *s);
void win_x_perror(const char *s);
int win_x_printf(const char *format, ...);
int win_x_puts(const char *s);
int win_x_scanf(const char *format, ...);
int win_x_ungetc(int c, FILE *stream);
int win_x_vfprintf(FILE *stream, const char *format, void *arglist);
/* int win_x_vfscanf(FILE *stream, const char *format, void *arglist); */
int win_x_vprintf(const char *format, void *arglist);
/* int win_x_vscanf(const char *format, void *arglist); */
int win_x_fclose( FILE * stream);
int win_x_fflush( FILE * stream);
int win_x_fgetc( FILE * stream);
int win_x_fgetpos( FILE * stream, fpos_t * pos);
char * win_x_fgets(char * s, int n, FILE * stream);
int win_x_fprintf(FILE * stream, const char * format, ...);
int win_x_fputc(int c, FILE * stream);
int win_x_fputs(const char * s, FILE * stream);
size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream);
FILE * win_x_freopen(const char * path, const char * mode, FILE * stream);
int win_x_fscanf(FILE * stream, const char * format, ...);
int win_x_fseek(FILE * stream, long offset, int whence);
int win_x_fsetpos(FILE * stream, const fpos_t*pos);
long win_x_ftell(FILE * stream);
size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream);
char * win_x_gets(char * s);
void win_x_perror(const char * s);
int win_x_printf(const char * format, ...);
int win_x_puts(const char * s);
int win_x_scanf(const char * format, ...);
int win_x_ungetc(int c, FILE * stream);
int win_x_vfprintf(FILE * stream, const char * format, void * arglist);
/*int win_x_vfscanf(FILE * stream, const char * format, void * arglist);*/
int win_x_vprintf(const char * format, void * arglist);
/*int win_x_vscanf(const char * format, void * arglist); */
#ifdef _MSC_VER
#if _MSC_VER < 1500
/* VC++ 6.0, VC++ 2005 */
_CRTIMP int __cdecl read(int fd, void * buf, unsigned int n);
_CRTIMP int __cdecl read(int fd, void *buf, unsigned int n);
#else
/* VC++ 2008 */
_CRTIMP int __cdecl read(int fd, _Out_bytecap_(_MaxCharCount) void * buf, _In_ unsigned int n);
_CRTIMP int __cdecl read(int fd, _Out_bytecap_(_MaxCharCount) void *buf, _In_ unsigned int n);
#endif
#else
int win_x_read(int fd, char * buf, int n);
int win_x_read(int fd, char *buf, int n);
#endif
int win_x_getc(FILE * fp);
int win_x_getc(FILE *fp);
int win_x_getchar(void);
int win_x_putchar(const int c);
int win_x_putc(const int c, FILE * fp);
int win_x_feof(FILE * fp);
int win_x_ferror(FILE * fp);
int win_x_putc(const int c, FILE *fp);
int win_x_feof(FILE *fp);
int win_x_ferror(FILE *fp);
int win_x_fputchar(int c);
/* ------------------------------<New macros>---------------------------------*/
/* ------------------------------<New macros>--------------------------------- */
#define fclose win_x_fclose
#define fflush win_x_fflush
@ -85,9 +88,9 @@ int win_x_fputchar(int c);
#define scanf win_x_scanf
#define ungetc win_x_ungetc
#define vfprintf win_x_vfprintf
/*#define vfscanf win_x_vfscanf*/
/* #define vfscanf win_x_vfscanf */
#define vprintf win_x_vprintf
/*#define vscanf win_x_vscanf*/
/* #define vscanf win_x_vscanf */
#define read win_x_read
#define getc win_x_getc
#define getchar win_x_getchar
@ -97,8 +100,6 @@ int win_x_fputchar(int c);
#define ferror win_x_ferror
#define fputchar win_x_fputchar
/*----------------------------------------------------------------------------*/
#endif

624
src/winmain.c
File diff suppressed because it is too large
View File

94
src/winmain.h

@ -3,71 +3,73 @@
*/
/* Forward definition of main() */
int xmain( int argc, char * argv[]);
int xmain(int argc, char *argv[]);
/* forward of Update function */
#ifdef __CYGWIN__
static char* rlead(char*);
#endif
void winmessage(char*);
static void HistoryInit(void);
static void HistoryScroll(void);
static void HistoryEnter( char * newLine);
static char * HistoryGetPrev(void);
static char * HistoryGetNext(void);
static void HistoryEnter(char *newLine);
static char *HistoryGetPrev(void);
static char *HistoryGetNext(void);
void WaitForIdle(void);
static void WaitForMessage(void);
static void ClearInput(void);
void SetSource( char * Name);
void SetAnalyse(char *, int );
void SetSource(char *Name);
void SetAnalyse(char *, int);
static void AdjustScroller(void);
static void _DeleteFirstLine(void);
static void AppendChar( char c);
static void AppendString( const char * Line);
static void DisplayText( void);
static void AppendChar(char c);
static void AppendString(const char *Line);
static void DisplayText(void);
static int w_getch(void);
static int w_putch( int c);
static int w_putch(int c);
static void Main_OnSize(HWND hwnd, UINT state, int cx, int cy);
static void PostSpiceCommand( const char * const cmd);
static LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK StringWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK TextWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void PostSpiceCommand(const char *const cmd);
static LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK StringWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK TextWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void Element_OnPaint(HWND hwnd);
static LRESULT CALLBACK ElementWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static int MakeArgcArgv(char *cmdline,int *argc,char ***argv);
static LRESULT CALLBACK ElementWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static int MakeArgcArgv(char *cmdline, int *argc, char ***argv);
int win_x_fclose( FILE * stream);
int win_x_fflush( FILE * stream);
int win_x_fgetc( FILE * stream);
int win_x_fgetpos( FILE * stream, fpos_t * pos);
char * win_x_fgets(char * s, int n, FILE * stream);
int win_x_fprintf(FILE * stream, const char * format, ...);
int win_x_fputc(int c, FILE * stream);
int win_x_fputs(const char * s, FILE * stream);
size_t win_x_fread(void * ptr, size_t size, size_t n, FILE * stream);
FILE * win_x_freopen(const char * path, const char * mode, FILE * stream);
int win_x_fscanf(FILE * stream, const char * format, ...);
int win_x_fseek(FILE * stream, long offset, int whence);
int win_x_fsetpos(FILE * stream, const fpos_t*pos);
long win_x_ftell(FILE * stream);
size_t win_x_fwrite(const void * ptr, size_t size, size_t n, FILE * stream);
char * win_x_gets(char * s);
void win_x_perror(const char * s);
int win_x_printf(const char * format, ...);
int win_x_puts(const char * s);
int win_x_scanf(const char * format, ...);
int win_x_ungetc(int c, FILE * stream);
int win_x_vfprintf(FILE * stream, const char * format, void * arglist);
/*int win_x_vfscanf(FILE * stream, const char * format, void * arglist);*/
int win_x_vprintf(const char * format, void * arglist);
/*int win_x_vscanf(const char * format, void * arglist); */
int win_x_read(int fd, char * buf, int n);
int win_x_getc(FILE * fp);
int win_x_fclose(FILE *stream);
int win_x_fflush(FILE *stream);
int win_x_fgetc(FILE *stream);
int win_x_fgetpos(FILE *stream, fpos_t *pos);
char *win_x_fgets(char *s, int n, FILE *stream);
int win_x_fprintf(FILE *stream, const char *format, ...);
int win_x_fputc(int c, FILE *stream);
int win_x_fputs(const char *s, FILE *stream);
size_t win_x_fread(void *ptr, size_t size, size_t n, FILE *stream);
FILE *win_x_freopen(const char *path, const char *mode, FILE *stream);
int win_x_fscanf(FILE *stream, const char *format, ...);
int win_x_fseek(FILE *stream, long offset, int whence);
int win_x_fsetpos(FILE *stream, const fpos_t*pos);
long win_x_ftell(FILE *stream);
size_t win_x_fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
char *win_x_gets(char *s);
void win_x_perror(const char *s);
int win_x_printf(const char *format, ...);
int win_x_puts(const char *s);
int win_x_scanf(const char *format, ...);
int win_x_ungetc(int c, FILE *stream);
int win_x_vfprintf(FILE *stream, const char *format, void *arglist);
/* int win_x_vfscanf(FILE *stream, const char *format, void *arglist); */
int win_x_vprintf(const char *format, void *arglist);
/* int win_x_vscanf(const char *format, void *arglist); */
int win_x_read(int fd, char *buf, int n);
int win_x_getc(FILE *fp);
int win_x_getchar(void);
int win_x_putchar(const int c);
int win_x_putc(const int c, FILE * fp);
int win_x_feof(FILE * fp);
int win_x_ferror(FILE * fp);
int win_x_putc(const int c, FILE *fp);
int win_x_feof(FILE *fp);
int win_x_ferror(FILE *fp);
int win_x_fputchar(int c);
Loading…
Cancel
Save