Browse Source

Prototypes and C comments

pre-master-46
dwarning 19 years ago
parent
commit
8dfa76b756
  1. 247
      src/frontend/wdisp/windisp.c
  2. 128
      src/frontend/wdisp/winprint.c

247
src/frontend/wdisp/windisp.c

@ -12,6 +12,9 @@
#include "graph.h" #include "graph.h"
#include "ftedev.h" #include "ftedev.h"
#include "ftedbgra.h" #include "ftedbgra.h"
#include "fteext.h"
#include "../plotting/graf.h"
#include "../plotting/graphdb.h"
/* /*
* The ngspice.h file included above defines BOOLEAN (via bool.h) and this * The ngspice.h file included above defines BOOLEAN (via bool.h) and this
@ -22,45 +25,45 @@
*/ */
#undef BOOLEAN #undef BOOLEAN
#pragma warn -dup // wegen Redefinition von NUMCOLORS
#pragma warn -dup /* wegen Redefinition von NUMCOLORS */
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#include "suffix.h" #include "suffix.h"
#pragma hdrstop #pragma hdrstop
// Typen
typedef struct { // Extra Fensterdaten
HWND wnd; // Fenster
HDC hDC; // Device context des Fensters
RECT Area; // Zeichenflaeche
int ColorIndex; // Index auf die akt. Farbe
int PaintFlag; // 1 bei WM_PAINT
int FirstFlag; // 1 vor dem ersten Update
/* Typen */
typedef struct { /* Extra Fensterdaten */
HWND wnd; /* Fenster */
HDC hDC; /* Device context des Fensters */
RECT Area; /* Zeichenflaeche */
int ColorIndex; /* Index auf die akt. Farbe */
int PaintFlag; /* 1 bei WM_PAINT */
int FirstFlag; /* 1 vor dem ersten Update */
} tWindowData; } tWindowData;
typedef tWindowData * tpWindowData; // Zeiger darauf
typedef tWindowData * tpWindowData; /* Zeiger darauf */
#define pWindowData(g) ((tpWindowData)(g->devdep)) #define pWindowData(g) ((tpWindowData)(g->devdep))
// Forwards
LRESULT CALLBACK PlotWindowProc( HWND hwnd, // Fensterprozedur
/* Forwards */
LRESULT CALLBACK PlotWindowProc( HWND hwnd, /* Fensterprozedur */
UINT uMsg, WPARAM wParam, LPARAM lParam); UINT uMsg, WPARAM wParam, LPARAM lParam);
// externals
extern HINSTANCE hInst; // Instanz der Applikation
extern int WinLineWidth; // Breite des Textfensters
void WPRINT_PrintInit( HWND hwnd); // Windows Drucker Init
void WaitForIdle(void); // Warte, bis keine Events da
// lokale Variablen
static int IsRegistered = 0; // 1 wenn Fensterkl. reg.
#define NumWinColors 23 // vordef. Farben
static COLORREF ColorTable[NumWinColors]; // Speicher fuer die Farben
static char * WindowName = "Spice Plot"; // Fenstername
static WNDCLASS TheWndClass; // Plot-Fensterklasse
static HFONT PlotFont; // Font-Merker
#define ID_DRUCKEN 0xEFF0 // System-Menu: drucken
#define ID_DRUCKEINR 0xEFE0 // System-Menu: Druckereinrichtung
static const int ID_MASK = 0xFFF0; // System-Menu: Maske
static char * STR_DRUCKEN = "Drucken..."; // System-Menu-Strings
/* externals */
extern HINSTANCE hInst; /* Instanz der Applikation */
extern int WinLineWidth; /* Breite des Textfensters */
void WPRINT_PrintInit( HWND hwnd); /* Windows Drucker Init */
void WaitForIdle(void); /* Warte, bis keine Events da */
/* lokale Variablen */
static int IsRegistered = 0; /* 1 wenn Fensterkl. reg. */
#define NumWinColors 23 /* vordef. Farben */
static COLORREF ColorTable[NumWinColors]; /* Speicher fuer die Farben */
static char * WindowName = "Spice Plot"; /* Fenstername */
static WNDCLASS TheWndClass; /* Plot-Fensterklasse */
static HFONT PlotFont; /* Font-Merker */
#define ID_DRUCKEN 0xEFF0 /* System-Menu: drucken */
#define ID_DRUCKEINR 0xEFE0 /* System-Menu: Druckereinrichtung */
static const int ID_MASK = 0xFFF0; /* System-Menu: Maske */
static char * STR_DRUCKEN = "Drucken..."; /* System-Menu-Strings */
static char * STR_DRUCKEINR = "Druckereinrichtung..."; static char * STR_DRUCKEINR = "Druckereinrichtung...";
/****************************************************************************** /******************************************************************************
@ -78,45 +81,45 @@ WIN_Init() macht noch kein Fenster auf, dies geschieht erst in WIN_NewViewport()
int WIN_Init( ) int WIN_Init( )
{ {
// Initialisierungen des Display-Descriptors
/* Initialisierungen des Display-Descriptors */
dispdev->width = GetSystemMetrics( SM_CXSCREEN); dispdev->width = GetSystemMetrics( SM_CXSCREEN);
dispdev->height = GetSystemMetrics( SM_CYSCREEN); dispdev->height = GetSystemMetrics( SM_CYSCREEN);
dispdev->numlinestyles = 5; // siehe Auswirkungen in WinPrint!
dispdev->numlinestyles = 5; /* siehe Auswirkungen in WinPrint! */
dispdev->numcolors = NumWinColors; dispdev->numcolors = NumWinColors;
// nur beim ersten Mal:
/* nur beim ersten Mal: */
if (!IsRegistered) { if (!IsRegistered) {
// Farben initialisieren
ColorTable[0] = RGB( 0, 0, 0); // Schwarz = Hintergrund
ColorTable[1] = RGB(255,255,255); // Weisz = Beschriftung und Gitter
ColorTable[2] = RGB( 0,255, 0); // Gruen = erste Linie
ColorTable[3] = RGB(255, 0, 0); // Rot
ColorTable[4] = RGB( 0, 0,255); // Blau
ColorTable[5] = RGB(255,255, 0); // Gelb
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); // braun
ColorTable[10]= RGB(128, 0,255); // Hellviolett
ColorTable[11]= RGB(255,128,128); // Rosa
// 2. Farb-Bank (mit anderem Linientyp
ColorTable[12]= RGB(255,255,255); // Weisz
ColorTable[13]= RGB( 0,255, 0); // Gruen
ColorTable[14]= RGB(255, 0, 0); // Rot
ColorTable[15]= RGB( 0, 0,255); // Blau
ColorTable[16]= RGB(255,255, 0); // Gelb
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); // braun
ColorTable[21]= RGB(128, 0,255); // Hellviolett
ColorTable[22]= RGB(255,128,128); // Rosa
// Ansii fixed font
/* Farben initialisieren */
ColorTable[0] = RGB( 0, 0, 0); /* Schwarz = Hintergrund */
ColorTable[1] = RGB(255,255,255); /* Weisz = Beschriftung und Gitter */
ColorTable[2] = RGB( 0,255, 0); /* Gruen = erste Linie */
ColorTable[3] = RGB(255, 0, 0); /* Rot */
ColorTable[4] = RGB( 0, 0,255); /* Blau */
ColorTable[5] = RGB(255,255, 0); /* Gelb */
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); /* braun */
ColorTable[10]= RGB(128, 0,255); /* Hellviolett */
ColorTable[11]= RGB(255,128,128); /* Rosa */
/* 2. Farb-Bank (mit anderem Linientyp */
ColorTable[12]= RGB(255,255,255); /* Weisz */
ColorTable[13]= RGB( 0,255, 0); /* Gruen */
ColorTable[14]= RGB(255, 0, 0); /* Rot */
ColorTable[15]= RGB( 0, 0,255); /* Blau */
ColorTable[16]= RGB(255,255, 0); /* Gelb */
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); /* braun */
ColorTable[21]= RGB(128, 0,255); /* Hellviolett */
ColorTable[22]= RGB(255,128,128); /* Rosa */
/* Ansii fixed font */
PlotFont = GetStockFont( ANSI_FIXED_FONT); PlotFont = GetStockFont( ANSI_FIXED_FONT);
// Fensterklasse registrieren
/* Fensterklasse registrieren */
TheWndClass.lpszClassName = WindowName; TheWndClass.lpszClassName = WindowName;
TheWndClass.hInstance = hInst; TheWndClass.hInstance = hInst;
TheWndClass.lpfnWndProc = PlotWindowProc; TheWndClass.lpfnWndProc = PlotWindowProc;
@ -131,18 +134,18 @@ int WIN_Init( )
} }
IsRegistered = 1; IsRegistered = 1;
// fertig
/* fertig */
return (0); return (0);
} }
// Zeiger auf den Graphen gewinnen
// (wird an das Fenster angehaengt)
/* Zeiger auf den Graphen gewinnen */
/* (wird an das Fenster angehaengt) */
static GRAPH * pGraph( HWND hwnd) static GRAPH * pGraph( HWND hwnd)
{ {
return (GRAPH *) GetWindowLong( hwnd, 0); return (GRAPH *) GetWindowLong( hwnd, 0);
} }
// Linientyp zurueckgeben zum Zeichnen
/* Linientyp zurueckgeben zum Zeichnen */
static int LType( int ColorIndex) static int LType( int ColorIndex)
{ {
if (ColorIndex >= 12) if (ColorIndex >= 12)
@ -151,68 +154,68 @@ static int LType( int ColorIndex)
return PS_SOLID; return PS_SOLID;
} }
// Drucke ein Plotfenster
// Aufruf durch SystemMenue / Drucken
/* Drucke ein Plotfenster */
/* Aufruf durch SystemMenue / Drucken */
LRESULT PrintPlot( HWND hwnd) LRESULT PrintPlot( HWND hwnd)
{ {
GRAPH * graph; GRAPH * graph;
GRAPH * temp; GRAPH * temp;
// Zeiger auf die Grafik holen
/* Zeiger auf die Grafik holen */
graph = pGraph( hwnd); graph = pGraph( hwnd);
if (!graph) return 0; if (!graph) return 0;
// Umschalten auf den Drucker
// (hat WPRINT_Init() zur Folge)
/* Umschalten auf den Drucker */
/* (hat WPRINT_Init() zur Folge) */
if (DevSwitch("WinPrint")) return 0; if (DevSwitch("WinPrint")) return 0;
// Cursor = warten
/* Cursor = warten */
SetCursor( LoadCursor( NULL, IDC_WAIT)); SetCursor( LoadCursor( NULL, IDC_WAIT));
// Graphen kopieren
/* Graphen kopieren */
temp = CopyGraph(graph); temp = CopyGraph(graph);
if (!temp) goto PrintEND; if (!temp) goto PrintEND;
// in die Kopie die neuen Daten des Druckers einspeisen
/* in die Kopie die neuen Daten des Druckers einspeisen */
if (NewViewport(temp)) goto PrintEND2; if (NewViewport(temp)) goto PrintEND2;
// Lage des Gitters korrigieren (Kopie aus gr_init)
/* Lage des Gitters korrigieren (Kopie aus gr_init) */
temp->viewportxoff = temp->fontwidth * 8; temp->viewportxoff = temp->fontwidth * 8;
temp->viewportyoff = temp->fontheight * 4; temp->viewportyoff = temp->fontheight * 4;
// dies druckt den Graphen
/* dies druckt den Graphen */
gr_resize(temp); gr_resize(temp);
PrintEND2: PrintEND2:
// temp. Graphen loeschen
/* temp. Graphen loeschen */
DestroyGraph(temp->graphid); DestroyGraph(temp->graphid);
PrintEND: PrintEND:
// zurueckschalten auf den Bildschirm
/* zurueckschalten auf den Bildschirm */
DevSwitch(NULL); DevSwitch(NULL);
// Cursor = normal
/* Cursor = normal */
SetCursor( LoadCursor( NULL, IDC_ARROW)); SetCursor( LoadCursor( NULL, IDC_ARROW));
return 0; return 0;
} }
// Druckerinitialisierung
/* Druckerinitialisierung */
LRESULT PrintInit( HWND hwnd) LRESULT PrintInit( HWND hwnd)
{ {
// weitergeben an das Drucker-Modul
/* weitergeben an das Drucker-Modul */
WPRINT_PrintInit(hwnd); WPRINT_PrintInit(hwnd);
return 0; return 0;
} }
// Fensterprozedur
/* Fensterprozedur */
LRESULT CALLBACK PlotWindowProc( HWND hwnd, LRESULT CALLBACK PlotWindowProc( HWND hwnd,
UINT uMsg, WPARAM wParam, LPARAM lParam) UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch (uMsg) { switch (uMsg) {
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
{ {
// Kommando testen
/* Kommando testen */
int cmd = wParam & ID_MASK; int cmd = wParam & ID_MASK;
switch(cmd) { switch(cmd) {
case ID_DRUCKEN: return PrintPlot( hwnd); case ID_DRUCKEN: return PrintPlot( hwnd);
@ -221,7 +224,7 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
} }
goto WIN_DEFAULT; goto WIN_DEFAULT;
case WM_CLOSE: // Fenster schlieszen
case WM_CLOSE: /* Fenster schlieszen */
{ {
GRAPH * g = pGraph( hwnd); GRAPH * g = pGraph( hwnd);
if (g) if (g)
@ -229,40 +232,40 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
} }
goto WIN_DEFAULT; goto WIN_DEFAULT;
case WM_PAINT: // Fenster neuzeichnen (z.B. nach Resize)
case WM_PAINT: /* Fenster neuzeichnen (z.B. nach Resize) */
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
GRAPH * g; GRAPH * g;
tpWindowData wd; tpWindowData wd;
HDC saveDC; // der DC aus BeginPaint ist anders...
HDC saveDC; /* der DC aus BeginPaint ist anders... */
HDC newDC; HDC newDC;
// muss passieren
/* muss passieren */
newDC = BeginPaint( hwnd, &ps); newDC = BeginPaint( hwnd, &ps);
g = pGraph( hwnd); g = pGraph( hwnd);
if (g) { if (g) {
wd = pWindowData(g); wd = pWindowData(g);
if (wd) { if (wd) {
if (!wd->PaintFlag && !wd->FirstFlag) { if (!wd->PaintFlag && !wd->FirstFlag) {
// rekursiven Aufruf verhindern
/* rekursiven Aufruf verhindern */
wd->PaintFlag = 1; wd->PaintFlag = 1;
// Fenstermasze holen
/* Fenstermasze holen */
GetClientRect( hwnd, &(wd->Area)); GetClientRect( hwnd, &(wd->Area));
g->absolute.width = wd->Area.right; g->absolute.width = wd->Area.right;
g->absolute.height = wd->Area.bottom; g->absolute.height = wd->Area.bottom;
// DC umschalten
/* DC umschalten */
saveDC = wd->hDC; saveDC = wd->hDC;
wd->hDC = newDC; wd->hDC = newDC;
// neu zeichnen
/* neu zeichnen */
gr_resize(g); gr_resize(g);
// DC umschalten
/* DC umschalten */
wd->hDC = saveDC; wd->hDC = saveDC;
// fertig
/* fertig */
wd->PaintFlag = 0; wd->PaintFlag = 0;
} }
} }
} }
// beenden
/* beenden */
EndPaint( hwnd, &ps); EndPaint( hwnd, &ps);
} }
return 0; return 0;
@ -286,27 +289,27 @@ int WIN_NewViewport( GRAPH * graph)
int i; int i;
HWND window; HWND window;
HDC dc; HDC dc;
HDC textDC;
HFONT font;
/* HDC textDC; */
/* HFONT font; */
TEXTMETRIC tm; TEXTMETRIC tm;
tpWindowData wd; tpWindowData wd;
HMENU sysmenu; HMENU sysmenu;
// Parameter testen
/* Parameter testen */
if (!graph) return 1; if (!graph) return 1;
// Initialisiere, falls noch nicht geschehen
/* Initialisiere, falls noch nicht geschehen */
if (WIN_Init() != 0) { if (WIN_Init() != 0) {
externalerror("Can't initialize GDI."); externalerror("Can't initialize GDI.");
return(1); return(1);
} }
// Device dep. Info allocieren
/* Device dep. Info allocieren */
wd = calloc(1, sizeof(tWindowData)); wd = calloc(1, sizeof(tWindowData));
if (!wd) return 1; if (!wd) return 1;
graph->devdep = (char *)wd; graph->devdep = (char *)wd;
// Create the window
/* Create the window */
i = GetSystemMetrics( SM_CYSCREEN) / 3; i = GetSystemMetrics( SM_CYSCREEN) / 3;
window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW, window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
@ -314,56 +317,56 @@ int WIN_NewViewport( GRAPH * graph)
wd->wnd = window; wd->wnd = window;
SetWindowLong( window, 0, (long)graph); SetWindowLong( window, 0, (long)graph);
// Zeige das Fenster
/* Zeige das Fenster */
ShowWindow( window, SW_SHOWNORMAL); ShowWindow( window, SW_SHOWNORMAL);
// Hole die Masze
/* Hole die Masze */
GetClientRect( window, &(wd->Area)); GetClientRect( window, &(wd->Area));
// Hole den DC
/* Hole den DC */
dc = GetDC( window); dc = GetDC( window);
wd->hDC = dc; wd->hDC = dc;
// Setze den Color-Index
/* Setze den Color-Index */
wd->ColorIndex = 0; wd->ColorIndex = 0;
// noch kein Zeichnen
/* noch kein Zeichnen */
wd->PaintFlag = 0; wd->PaintFlag = 0;
wd->FirstFlag = 1; wd->FirstFlag = 1;
// System-Menu modifizieren
/* System-Menu modifizieren */
sysmenu = GetSystemMenu( window, FALSE); sysmenu = GetSystemMenu( window, FALSE);
AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL); AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN); AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN);
AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR); AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR);
// Default-Parameter des DC setzen
/* Default-Parameter des DC setzen */
SetBkColor( dc, ColorTable[0]); SetBkColor( dc, ColorTable[0]);
SetBkMode( dc, TRANSPARENT ); SetBkMode( dc, TRANSPARENT );
// Font setzen
/* Font setzen */
SelectObject( dc, PlotFont); SelectObject( dc, PlotFont);
// Font-Parameter abfragen
/* Font-Parameter abfragen */
if (GetTextMetrics( dc, &tm)) { if (GetTextMetrics( dc, &tm)) {
graph->fontheight = tm.tmHeight; graph->fontheight = tm.tmHeight;
graph->fontwidth = tm.tmAveCharWidth; graph->fontwidth = tm.tmAveCharWidth;
} }
// Viewport-Parameter setzen
/* Viewport-Parameter setzen */
graph->viewport.height = wd->Area.bottom; graph->viewport.height = wd->Area.bottom;
graph->viewport.width = wd->Area.right; graph->viewport.width = wd->Area.right;
// Absolut-Parameter setzen
/* Absolut-Parameter setzen */
graph->absolute.xpos = 0; graph->absolute.xpos = 0;
graph->absolute.ypos = 0; graph->absolute.ypos = 0;
graph->absolute.width = wd->Area.right; graph->absolute.width = wd->Area.right;
graph->absolute.height = wd->Area.bottom; graph->absolute.height = wd->Area.bottom;
// Warten, bis das Fenster wirklich da ist
/* Warten, bis das Fenster wirklich da ist */
WaitForIdle(); WaitForIdle();
// fertig
/* fertig */
return(0); return(0);
} }
@ -381,7 +384,7 @@ int WIN_Close()
void RealClose(void) void RealClose(void)
{ {
// Fensterklasse loeschen
/* Fensterklasse loeschen */
if (IsRegistered) { if (IsRegistered) {
if (TheWndClass.hIcon) { if (TheWndClass.hIcon) {
DestroyIcon( TheWndClass.hIcon); DestroyIcon( TheWndClass.hIcon);
@ -400,8 +403,8 @@ int WIN_Clear()
wd = pWindowData(currentgraph); wd = pWindowData(currentgraph);
if (!wd) return 0; if (!wd) return 0;
// das macht das Fenster selbst
if (!wd->PaintFlag) // bei WM_PAINT unnoetig
/* das macht das Fenster selbst */
if (!wd->PaintFlag) /* bei WM_PAINT unnoetig */
SendMessage( wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0); SendMessage( wd->wnd, WM_ERASEBKGND, (WPARAM) wd->hDC, 0);
return 0; return 0;
@ -461,7 +464,7 @@ int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2)
} }
SetArcDirection( wd->hDC, direction); SetArcDirection( wd->hDC, direction);
// Geometrische Vorueberlegungen
/* Geometrische Vorueberlegungen */
yb = wd->Area.bottom; yb = wd->Area.bottom;
left = x0 - radius; left = x0 - radius;
right = x0 + radius; right = x0 + radius;
@ -476,7 +479,7 @@ int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2)
xe = (dx0 + (r * cos(theta2))); xe = (dx0 + (r * cos(theta2)));
ye = (dy0 + (r * sin(theta2))); ye = (dy0 + (r * sin(theta2)));
// Zeichnen
/* Zeichnen */
NewPen = CreatePen( LType(wd->ColorIndex), 0, ColorTable[wd->ColorIndex] ); NewPen = CreatePen( LType(wd->ColorIndex), 0, ColorTable[wd->ColorIndex] );
OldPen = SelectObject(wd->hDC, NewPen); 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);
@ -502,19 +505,19 @@ int WIN_Text( char * text, int x, int y, int degrees)
int WIN_DefineColor(int red, int green, int blue, int num) int WIN_DefineColor(int red, int green, int blue, int num)
{ {
// nix
/* nix */
return (0); return (0);
} }
int WIN_DefineLinestyle(int num, int mask) int WIN_DefineLinestyle(int num, int mask)
{ {
// nix
/* nix */
return (0); return (0);
} }
int WIN_SetLinestyle(int style) int WIN_SetLinestyle(int style)
{ {
// nix
/* nix */
return (0); return (0);
} }
@ -537,9 +540,9 @@ int WIN_Update()
wd = pWindowData(currentgraph); wd = pWindowData(currentgraph);
if (!wd) return 0; if (!wd) return 0;
// Nach dem ersten absolvieren von Update() werden durch
// FirstFlag wieder WM_PAINT-Botschaften bearbeitet.
// Dies verhindert doppeltes Zeichnen beim Darstellen des Fensters.
/* Nach dem ersten absolvieren von Update() werden durch */
/* FirstFlag wieder WM_PAINT-Botschaften bearbeitet. */
/* Dies verhindert doppeltes Zeichnen beim Darstellen des Fensters. */
wd->FirstFlag = 0; wd->FirstFlag = 0;
return 0; return 0;
} }

128
src/frontend/wdisp/winprint.c

@ -12,6 +12,7 @@
#include "graph.h" #include "graph.h"
#include "ftedev.h" #include "ftedev.h"
#include "ftedbgra.h" #include "ftedbgra.h"
#include "fteext.h"
/* /*
* The ngspice.h file included above defines BOOLEAN (via bool.h) and this * The ngspice.h file included above defines BOOLEAN (via bool.h) and this
@ -28,24 +29,27 @@
#include "suffix.h" #include "suffix.h"
#pragma hdrstop #pragma hdrstop
// Typen
typedef struct { // Extra Printdaten
int ColorIndex; // Index auf die akt. Farbe
int LineIndex; // Index auf den akt. Linientyp
/* Typen */
typedef struct { /* Extra Printdaten */
int ColorIndex; /* Index auf die akt. Farbe */
int LineIndex; /* Index auf den akt. Linientyp */
} tPrintData; } tPrintData;
typedef tPrintData * tpPrintData; // Zeiger darauf
typedef tPrintData * tpPrintData; /* Zeiger darauf */
#define pPrintData(g) ((tpPrintData)(g->devdep)) #define pPrintData(g) ((tpPrintData)(g->devdep))
// lokale Variablen
static HFONT PlotFont = NULL; // Font-Merker
/* externals */
void WaitForIdle(void); /* Warte, bis keine Events da */
/* lokale Variablen */
static HFONT PlotFont = NULL; /* Font-Merker */
static HFONT OldFont = NULL; static HFONT OldFont = NULL;
#define NumLines 7 // Anzahl der LineStyles
static int LineTable[NumLines]; // Speicher fuer die LineStyles
static HDC PrinterDC = NULL; // Device Context
#define NumPrintColors 2 // vordef. Farben
static COLORREF ColorTable[NumPrintColors];// Speicher fuer die Farben
static int PrinterWidth = 1000; // Breite des Papiers
static int PrinterHeight = 1000; // Hoehe des Papiers
#define NumLines 7 /* Anzahl der LineStyles */
static int LineTable[NumLines]; /* Speicher fuer die LineStyles */
static HDC PrinterDC = NULL; /* Device Context */
#define NumPrintColors 2 /* vordef. Farben */
static COLORREF ColorTable[NumPrintColors];/* Speicher fuer die Farben */
static int PrinterWidth = 1000; /* Breite des Papiers */
static int PrinterHeight = 1000; /* Hoehe des Papiers */
/****************************************************************************** /******************************************************************************
Drucker-Initialisierung Drucker-Initialisierung
@ -53,10 +57,10 @@ static int PrinterHeight = 1000; // Hoehe des Papiers
void WPRINT_PrintInit(HWND hwnd) void WPRINT_PrintInit(HWND hwnd)
{ {
// Parameter-Block
/* Parameter-Block */
PRINTDLG pd; PRINTDLG pd;
// Initialisieren
/* Initialisieren */
pd.lStructSize = sizeof(PRINTDLG); pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd; pd.hwndOwner = hwnd;
pd.hDevMode = NULL; pd.hDevMode = NULL;
@ -77,21 +81,21 @@ void WPRINT_PrintInit(HWND hwnd)
pd.hPrintTemplate = NULL; pd.hPrintTemplate = NULL;
pd.hSetupTemplate = NULL; pd.hSetupTemplate = NULL;
// Default-Drucker initialisieren
/* Default-Drucker initialisieren */
(void) PrintDlg( &pd); (void) PrintDlg( &pd);
// Speicher freigeben
/* Speicher freigeben */
if( pd.hDevMode) GlobalFree( pd.hDevMode); if( pd.hDevMode) GlobalFree( pd.hDevMode);
if( pd.hDevNames) GlobalFree( pd.hDevNames); if( pd.hDevNames) GlobalFree( pd.hDevNames);
} }
// Abort-Procedur zum Drucken
/* Abort-Procedur zum Drucken */
BOOL CALLBACK WPRINT_Abort( HDC hdc, int iError) BOOL CALLBACK WPRINT_Abort( HDC hdc, int iError)
{ {
// Multitasking
/* Multitasking */
WaitForIdle(); WaitForIdle();
// Warten
/* Warten */
return TRUE; return TRUE;
} }
@ -113,13 +117,13 @@ int WPRINT_Init( )
int pWidth; int pWidth;
int pHeight; int pHeight;
// Printer-DC holen
/* Printer-DC holen */
if (!PrinterDC) { if (!PrinterDC) {
// Parameter-Block
/* Parameter-Block */
PRINTDLG pd; PRINTDLG pd;
// Initialisieren
/* Initialisieren */
pd.lStructSize = sizeof(PRINTDLG); pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = NULL; pd.hwndOwner = NULL;
pd.hDevMode = NULL; pd.hDevMode = NULL;
@ -140,71 +144,71 @@ int WPRINT_Init( )
pd.hPrintTemplate = NULL; pd.hPrintTemplate = NULL;
pd.hSetupTemplate = NULL; pd.hSetupTemplate = NULL;
// Default-Drucker initialisieren
/* Default-Drucker initialisieren */
(void) PrintDlg( &pd); (void) PrintDlg( &pd);
// Speicher freigeben
/* Speicher freigeben */
if( pd.hDevMode) GlobalFree( pd.hDevMode); if( pd.hDevMode) GlobalFree( pd.hDevMode);
if( pd.hDevNames) GlobalFree( pd.hDevNames); if( pd.hDevNames) GlobalFree( pd.hDevNames);
// DC holen
/* DC holen */
PrinterDC = pd.hDC; PrinterDC = pd.hDC;
if (!PrinterDC) return 1; if (!PrinterDC) return 1;
// Abmasze bestimmen
/* Abmasze bestimmen */
PrinterWidth = GetDeviceCaps( PrinterDC, HORZRES); PrinterWidth = GetDeviceCaps( PrinterDC, HORZRES);
PrinterHeight = GetDeviceCaps( PrinterDC, VERTRES); PrinterHeight = GetDeviceCaps( PrinterDC, VERTRES);
pWidth = GetDeviceCaps( PrinterDC, HORZSIZE); pWidth = GetDeviceCaps( PrinterDC, HORZSIZE);
pHeight = GetDeviceCaps( PrinterDC, VERTSIZE); pHeight = GetDeviceCaps( PrinterDC, VERTSIZE);
// Mapping Mode setzen (fuer Kreise)
/* Mapping Mode setzen (fuer Kreise) */
if ( pWidth > pHeight) if ( pWidth > pHeight)
// Querformat
/* Querformat */
PrinterWidth = (PrinterHeight * pWidth) / pHeight; PrinterWidth = (PrinterHeight * pWidth) / pHeight;
else else
// Hochformat
/* Hochformat */
PrinterHeight = (PrinterWidth * pHeight) / pWidth; PrinterHeight = (PrinterWidth * pHeight) / pWidth;
SetMapMode( PrinterDC, MM_ISOTROPIC); SetMapMode( PrinterDC, MM_ISOTROPIC);
SetWindowExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL); SetWindowExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL);
SetViewportExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL); SetViewportExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL);
// nicht hoeher als breit zeichnen
/* nicht hoeher als breit zeichnen */
if (pWidth < pHeight) { if (pWidth < pHeight) {
// Papier im Hochformat
/* Papier im Hochformat */
PrinterHeight = PrinterWidth; PrinterHeight = PrinterWidth;
} }
// Initialisierungen des Display-Descriptors
/* Initialisierungen des Display-Descriptors */
dispdev->width = PrinterWidth; dispdev->width = PrinterWidth;
dispdev->height = PrinterHeight; dispdev->height = PrinterHeight;
dispdev->numlinestyles = NumLines; dispdev->numlinestyles = NumLines;
dispdev->numcolors = NumPrintColors; dispdev->numcolors = NumPrintColors;
// Farben initialisieren
ColorTable[0] = RGB(255,255,255); // Weisz
ColorTable[1] = RGB( 0, 0, 0); // Schwarz
/* Farben initialisieren */
ColorTable[0] = RGB(255,255,255); /* Weisz */
ColorTable[1] = RGB( 0, 0, 0); /* Schwarz */
// LineStyles initialisieren
/* LineStyles initialisieren */
LineTable[0] = PS_SOLID; LineTable[0] = PS_SOLID;
LineTable[1] = PS_DOT; // Gitter
LineTable[2] = PS_SOLID; // Erste Linie
LineTable[3] = PS_DOT; // Zweite Linie
LineTable[4] = PS_DASH; // usw
LineTable[1] = PS_DOT; /* Gitter */
LineTable[2] = PS_SOLID; /* Erste Linie */
LineTable[3] = PS_DOT; /* Zweite Linie */
LineTable[4] = PS_DASH; /* usw */
LineTable[5] = PS_DASHDOT; LineTable[5] = PS_DASHDOT;
LineTable[6] = PS_DASHDOTDOT; LineTable[6] = PS_DASHDOTDOT;
// Font
/* Font */
if (!PlotFont) { if (!PlotFont) {
PlotFont = CreateFont( 0,0,0,0, FW_DONTCARE, FALSE, FALSE, FALSE, PlotFont = CreateFont( 0,0,0,0, FW_DONTCARE, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, FIXED_PITCH, NULL); PROOF_QUALITY, FIXED_PITCH, NULL);
} }
// Abort-Prozedur setzen
/* Abort-Prozedur setzen */
SetAbortProc( PrinterDC, WPRINT_Abort); SetAbortProc( PrinterDC, WPRINT_Abort);
} }
// fertig
/* fertig */
return (0); return (0);
} }
@ -222,53 +226,53 @@ int WPRINT_NewViewport( GRAPH * graph)
tpPrintData pd; tpPrintData pd;
DOCINFO di; DOCINFO di;
// Parameter testen
/* Parameter testen */
if (!graph) return 1; if (!graph) return 1;
// Initialisiere, falls noch nicht geschehen
/* Initialisiere, falls noch nicht geschehen */
if (WPRINT_Init() != 0) { if (WPRINT_Init() != 0) {
externalerror("Can't initialize Printer."); externalerror("Can't initialize Printer.");
return(1); return(1);
} }
// Device dep. Info allocieren
/* Device dep. Info allocieren */
pd = calloc(1, sizeof(tPrintData)); pd = calloc(1, sizeof(tPrintData));
if (!pd) return 1; if (!pd) return 1;
graph->devdep = (char *)pd; graph->devdep = (char *)pd;
// Setze den Color-Index
/* Setze den Color-Index */
pd->ColorIndex = 0; pd->ColorIndex = 0;
// Font setzen
/* Font setzen */
OldFont = SelectObject( PrinterDC, PlotFont); OldFont = SelectObject( PrinterDC, PlotFont);
// Font-Parameter abfragen
/* Font-Parameter abfragen */
if (GetTextMetrics( PrinterDC, &tm)) { if (GetTextMetrics( PrinterDC, &tm)) {
graph->fontheight = tm.tmHeight; graph->fontheight = tm.tmHeight;
graph->fontwidth = tm.tmAveCharWidth; graph->fontwidth = tm.tmAveCharWidth;
} }
// Setze den Linien-Index
/* Setze den Linien-Index */
pd->LineIndex = 0; pd->LineIndex = 0;
// Viewport-Parameter setzen
/* Viewport-Parameter setzen */
graph->viewport.height = PrinterHeight; graph->viewport.height = PrinterHeight;
graph->viewport.width = PrinterWidth; graph->viewport.width = PrinterWidth;
// Absolut-Parameter setzen
/* Absolut-Parameter setzen */
graph->absolute.xpos = 0; graph->absolute.xpos = 0;
graph->absolute.ypos = 0; graph->absolute.ypos = 0;
graph->absolute.width = PrinterWidth; graph->absolute.width = PrinterWidth;
graph->absolute.height = PrinterHeight; graph->absolute.height = PrinterHeight;
// Druckauftrag anmelden
/* Druckauftrag anmelden */
di.cbSize = sizeof( DOCINFO); di.cbSize = sizeof( DOCINFO);
di.lpszDocName = graph->plotname; di.lpszDocName = graph->plotname;
di.lpszOutput = NULL; di.lpszOutput = NULL;
if (StartDoc( PrinterDC, &di) <= 0) return 1; if (StartDoc( PrinterDC, &di) <= 0) return 1;
if (StartPage( PrinterDC) <= 0) return 1; if (StartPage( PrinterDC) <= 0) return 1;
// titel drucken
/* titel drucken */
if (graph->plotname) { if (graph->plotname) {
UINT align; UINT align;
align = GetTextAlign( PrinterDC); align = GetTextAlign( PrinterDC);
@ -278,7 +282,7 @@ int WPRINT_NewViewport( GRAPH * graph)
SetTextAlign( PrinterDC, align); SetTextAlign( PrinterDC, align);
} }
// fertig
/* fertig */
return(0); return(0);
} }
@ -316,7 +320,7 @@ int WPRINT_DrawLine(int x1, int y1, int x2, int y2)
pd = pPrintData(currentgraph); pd = pPrintData(currentgraph);
if (!pd) return 0; if (!pd) return 0;
// Farben/Dicke
/* Farben/Dicke */
ColIndex = pd->ColorIndex; ColIndex = pd->ColorIndex;
if (ColIndex > 1) if (ColIndex > 1)
ColIndex = 1; ColIndex = 1;
@ -368,7 +372,7 @@ int WPRINT_Arc(int x0, int y0, int radius, double theta1, double theta2)
} }
SetArcDirection( PrinterDC, direction); SetArcDirection( PrinterDC, direction);
// Geometrische Vorueberlegungen
/* Geometrische Vorueberlegungen */
yb = PrinterHeight; yb = PrinterHeight;
left = x0 - radius; left = x0 - radius;
right = x0 + radius; right = x0 + radius;
@ -383,7 +387,7 @@ int WPRINT_Arc(int x0, int y0, int radius, double theta1, double theta2)
xe = (dx0 + (r * cos(theta2))); xe = (dx0 + (r * cos(theta2)));
ye = (dy0 + (r * sin(theta2))); ye = (dy0 + (r * sin(theta2)));
// Zeichnen
/* Zeichnen */
NewPen = CreatePen( LineTable[pd->LineIndex], 0, ColorTable[ColIndex] ); NewPen = CreatePen( LineTable[pd->LineIndex], 0, ColorTable[ColIndex] );
OldPen = SelectObject(PrinterDC, NewPen); OldPen = SelectObject(PrinterDC, NewPen);
Arc( PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); Arc( PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);
@ -415,13 +419,13 @@ int WPRINT_Text( char * text, int x, int y, int degrees)
int WPRINT_DefineColor(int red, int green, int blue, int num) int WPRINT_DefineColor(int red, int green, int blue, int num)
{ {
// nix
/* nix */
return (0); return (0);
} }
int WPRINT_DefineLinestyle(int num, int mask) int WPRINT_DefineLinestyle(int num, int mask)
{ {
// nix
/* nix */
return (0); return (0);
} }

Loading…
Cancel
Save