📄 winspec.cpp
字号:
}
return false;
}
bool
WinCopyWMF::oRectangle(int x1, int y1, int x2, int y2, char *name)
{
BOOL RetVal;
RetVal = Rectangle(hdc, x1, y1, x2, y2);
if(RetVal && hgo) return hgo->oRectangle(x1, y1, x2, y2, 0L);
else if (RetVal) return true;
return false;
}
bool
WinCopyWMF::oSolidLine(POINT *p)
{
if(Polyline(hdc, p, 2)) return true;
return false;
}
bool
WinCopyWMF::oTextOut(int x, int y, char *txt, int cb)
{
return com_oTextOut(x, y, txt, cb, &hFont, &hdc, &TxtSet, true, this);
}
bool
WinCopyWMF::oPolygon(POINT *pts, int cp, char *nam)
{
BOOL RetVal;
RetVal = Polygon(hdc, pts, cp);
if(RetVal && hgo) return hgo->oPolygon(pts, cp);
else if (RetVal) return true;
return false;
}
bool
WinCopyWMF::oArc(int x1, int y1, int x2, int y2, int quads)
{
return com_Arc(hdc, x1, y1, x2, y2, quads);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Print
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PrintWin::PrintWin()
{
int i, j;
double pw, ph;
PrintDriver = PrintDevice = PrintPort = 0L;
hPen = 0L;
hBrush = 0L;
hFont = 0L;
hDC = 0L;
hgo = 0L;
units = defs.cUnits;
i = j = 0;
GetProfileString("windows", "device", "", TmpTxt, 4096);
while(TmpTxt[i] && TmpTxt[i] != ',') i++;
TmpTxt[i] = 0;
if (i >2) {
PrintDevice = strdup(TmpTxt);
i++;
j = i;
while(TmpTxt[i] && TmpTxt[i] != ',') i++;
if(i-j > 2) {
TmpTxt[i] = 0;
PrintDriver = strdup(TmpTxt+j);
i++;
j = i;
while(TmpTxt[i] && TmpTxt[i] != ',') i++;
if(i-j > 2) {
TmpTxt[i] = 0;
PrintPort = strdup(TmpTxt+j);
//Get default paper setup
if(hDC = CreateDC(PrintDriver, PrintDevice, PrintPort, 0L)) {
pw = GetDeviceCaps(hDC, PHYSICALWIDTH);
pw /= (double)GetDeviceCaps(hDC, LOGPIXELSX);
ph = GetDeviceCaps(hDC, PHYSICALHEIGHT);
ph /= (double)GetDeviceCaps(hDC, LOGPIXELSY);
switch (defs.cUnits){
case 1: pw *= 2.54; ph *= 2.54; break;
case 2: break;
default: pw *= 25.4; ph *= 25.4; break;
}
FindPaper(pw, ph, 0.01);
DeleteDC(hDC);
}
hDC = 0L;
}
}
}
}
PrintWin::~PrintWin()
{
if(PrintDriver) free(PrintDriver);
if(PrintDevice) free(PrintDevice);
if(PrintPort) free(PrintPort);
if(hPen) DeleteObject(hPen);
if(hBrush) DeleteObject(hBrush);
if(hFont) DeleteObject(hFont);
}
bool
PrintWin::SetLine(LineDEF *lDef)
{
int iw;
HPEN newPen;
if(!hPen || lDef->width != LineWidth || lDef->width != LineWidth ||
lDef->pattern != dPattern || lDef->color != dLineCol) {
LineWidth = lDef->width;
iw = iround(un2ix(lDef->width));
dPattern = lDef->pattern;
RLP.finc = 256.0/un2fix(lDef->patlength*8.0);
RLP.fp = 0.0;
if(iLine == iw && dLineCol == lDef->color && hPen) return true;
iLine = iw;
dLineCol = lDef->color;
newPen = CreatePen(PS_SOLID, iw > 0 ? iw : 1, dLineCol);
SelectObject(hDC, newPen);
if(hPen) DeleteObject(hPen);
hPen = newPen;
}
return true;
}
bool
PrintWin::SetFill(FillDEF *fill)
{
HBRUSH newBrush;
if(!fill) return false;
if((fill->type & 0xff) != FILL_NONE) {
if(!hgo) hgo = new HatchOut(this);
if(hgo) hgo->SetFill(fill);
}
else {
if(hgo) delete hgo;
hgo = NULL;
}
newBrush = CreateSolidBrush(fill->color);
SelectObject(hDC, newBrush);
if(hBrush) DeleteObject(hBrush);
hBrush = newBrush;
dFillCol = fill->color;
dFillCol2 = fill->color2;
return true;
}
bool
PrintWin::SetTextSpec(TextDEF *set)
{
return com_SetTextSpec(set, this, &hFont, &TxtSet, &hDC, isWIN95);
}
bool
PrintWin::StartPage()
{
DOCINFO DocInfo;
bool bRet = false;
if(hDC = CreateDC(PrintDriver, PrintDevice, PrintPort, 0L)) {
hPen = CreatePen(PS_SOLID, 1, dLineCol = 0x00ffffffL);
hBrush = CreateSolidBrush(dFillCol =dBgCol = 0x00ffffffL);
dPattern = 0L;
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
memset(&DocInfo, 0, sizeof(DOCINFO));
DocInfo.lpszDocName = "RLPlot graph";
DocInfo.cbSize = sizeof(DOCINFO);
DeskRect.left = DeskRect.top = 0;
DeskRect.right = GetDeviceCaps(hDC, HORZRES);
DeskRect.bottom = GetDeviceCaps(hDC, VERTRES);
hres = (double)GetDeviceCaps(hDC, LOGPIXELSX);
vres = (double)GetDeviceCaps(hDC, LOGPIXELSY);
if(StartDoc(hDC, &DocInfo) >= 0) {
if(::StartPage(hDC)>0) bRet = true;
}
}
return bRet;
}
bool
PrintWin::EndPage()
{
if(hDC) {
::EndPage(hDC); EndDoc(hDC); DeleteDC(hDC);
}
hDC = 0L;
return true;
}
bool
PrintWin::Eject()
{
if(hDC) {
::EndPage(hDC); ::StartPage(hDC); return true;
}
return false;
}
bool
PrintWin::oCircle(int x1, int y1, int x2, int y2, char* nam)
{
BOOL RetVal;
RetVal = Ellipse(hDC, x1, y1, x2, y2);
if(RetVal && hgo) return hgo->oCircle(x1, y1, x2, y2);
else if(RetVal) return true;
return false;
}
bool
PrintWin::oPolyline(POINT * pts, int cp, char *nam)
{
int i;
if(cp < 1) return FALSE;
if (dPattern) {
for (i = 1; i < cp; i++) PatLine(pts[i-1], pts[i]);
return true;
}
else {
if(Polyline(hDC, pts, cp))return true;
else return false;
}
}
bool
PrintWin::oRectangle(int x1, int y1, int x2, int y2, char *name)
{
BOOL RetVal;
RetVal = Rectangle(hDC, x1, y1, x2, y2);
if(RetVal && hgo) return hgo->oRectangle(x1, y1, x2, y2, 0L);
else if (RetVal) return true;
return false;
}
bool
PrintWin::oSolidLine(POINT *p)
{
if(Polyline(hDC, p, 2)) return true;
return false;
}
bool
PrintWin::oTextOut(int x, int y, char *txt, int cb)
{
return com_oTextOut(x, y, txt, cb, &hFont, &hDC, &TxtSet, isWIN95, this);
}
bool
PrintWin::oPolygon(POINT *pts, int cp, char *nam)
{
BOOL RetVal;
RetVal = Polygon(hDC, pts, cp);
if(RetVal && hgo) return hgo->oPolygon(pts, cp);
else if (RetVal) return true;
return false;
}
bool
PrintWin::oArc(int x1, int y1, int x2, int y2, int quads)
{
return com_Arc(hDC, x1, y1, x2, y2, quads);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Find a suitable www browser
void FindBrowser()
{
char text[600];
long size = 599;
HDC dc;
HKEY hdl;
HWND hwnd;
int i;
//find the default browser
if(ERROR_SUCCESS == RegQueryValue(HKEY_CLASSES_ROOT, "http\\shell\\open\\command",
text, &size) && size > 7) {
if(text[0] == '"') {
for(i = size-2; i >3; i--) {
if(text[i+1] == '"') {
text[i+1] = 0;
break;
}
else text[i+1] = 0;
}
WWWbrowser = strdup(text+1);
}
else {
for(i = size-1; i >5; i--) {
if(0 == stricmp(text+i-3, ".exe")) break;
else text[i] = 0;
}
WWWbrowser = strdup(text);
}
}
//find user default data directory
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Environment", NULL,
KEY_READ, &hdl)) {
text[0] = 0; size=599;
RegQueryValueEx(hdl, "HOMEDRIVE", 0, 0, (unsigned char*)text, (unsigned long*)&size);
size= 599;
RegQueryValueEx(hdl, "HOMEPATH", 0, 0, (unsigned char*)(text+strlen(text)),
(unsigned long*)&size);
defs.currPath = strdup(text);
}
//find user application data directory
if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", NULL,
KEY_READ, &hdl)) {
text[0] = 0; size=599;
RegQueryValueEx(hdl, "AppData", 0, 0, (unsigned char*)text, (unsigned long*)&size);
strcat(text, "\\RLPlot");
defs.IniFile = strdup(text);
}
//find country specific information
// its not a perfect place to do it, but a good one
GetProfileString("intl", "sDecimal", ".", text, 2);
if(text[0]) defs.DecPoint[0] = text[0];
GetProfileString("intl", "sList", ".", text, 2);
if(text[0]) defs.ColSep[0] = text[0];
if(GetProfileInt("intl", "iMeasure", 0)) defs.dUnits = defs.cUnits = 2;
//test if windows95
dc = GetDC(hwnd = GetDesktopWindow());
isWIN95 = (0 == SetGraphicsMode(dc, GM_ADVANCED));
SetGraphicsMode(dc, GM_COMPATIBLE);
ReleaseDC(hwnd, dc);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Windos entry point
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASS wndclass;
MSG msg;
DefsRW *drw;
//OS dependent initialization
dlgtxtheight = 16;
if(lpCmdLine && lpCmdLine[0] && FileExist(lpCmdLine)) LoadFile = strdup(lpCmdLine);
else if(lpCmdLine) { //probably Unicode
sprintf(TmpTxt, "%s", lpCmdLine);
if(TmpTxt[0] == '"'){
strcpy(TmpTxt, TmpTxt+1);
if(TmpTxt[0]) TmpTxt[strlen(TmpTxt)-1] = 0;
}
if(TmpTxt[0]) LoadFile= strdup(TmpTxt);
}
hInstance = hInst;
wndclass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(GraphObj*);
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_EVAL));
wndclass.hCursor = 0L;
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = 0L;
wndclass.lpszClassName = name;
RegisterClass(&wndclass);
ShowBanner(true);
InitTextCursor(true);
Printer = new PrintWin();
accel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ACCELERATORS_1));
while(GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
TranslateAccelerator(msg.hwnd, accel, &msg);
DispatchMessage(&msg);
}
if(defs.IniFile) {
if(drw = new DefsRW()){
drw->FileIO(FILE_WRITE); delete drw;
}
}
if(WWWbrowser) free(WWWbrowser);
if(LoadFile) free(LoadFile);
SpreadMain(false);
if(Printer) delete Printer;
InitTextCursor(false);
UnregisterClass(name, hInstance);
return msg.wParam;
}
void CopyData(GraphObj *g, unsigned int cf)
{
HGLOBAL hmem;
long cb;
unsigned char *dt = 0L;
unsigned char *buf;
if(!g || g->Id != GO_SPREADDATA) return;
switch(cf) {
case CF_TEXT:
if(!g->Command(CMD_COPY_TSV, &dt, 0L))return;
break;
case CF_SYLK:
if(!g->Command(CMD_COPY_SYLK, &dt, 0L))return;
break;
default:
if(cf == cf_rlpxml && g->Command(CMD_COPY_XML, &dt, 0L)) break;
else return;
}
cb = strlen((char*)dt);
if(hmem = GlobalAlloc(GMEM_MOVEABLE, cb+2)) {
if(buf = (unsigned char *)GlobalLock(hmem)) {
memcpy(buf, dt, cb+1);
GlobalUnlock(hmem);
SetClipboardData(cf, hmem);
}
}
}
void CopyGraph(GraphObj *g, unsigned int cf)
{
HGLOBAL hmem;
char *dt, *buf;
long cb;
if(!(dt = GraphToMem(g, &cb)))return;
if(hmem = GlobalAlloc(GMEM_MOVEABLE, cb+1)) {
if(buf = (char *)GlobalLock(hmem)) {
memcpy(buf, dt, cb);
buf[cb] = 0;
GlobalUnlock(hmem);
SetClipboardData(cf, hmem);
}
}
free(dt);
}
void ScrollEvent(bool bVert, HWND hwnd, UINT type, GraphObj *g, OutputWin *w)
{
SCROLLINFO si;
int LineStep, cmd, pos;
if(hwnd && g && w) {
cmd = bVert ? CMD_SETVPOS : CMD_SETHPOS;
LineStep = g->Id == GO_GRAPH ? 8 : 1;
si.fMask = SIF_ALL;
si.cbSize = sizeof(SCROLLINFO);
if(!(GetScrollInfo(hwnd, bVert ? SB_VERT : SB_HORZ, &si)))return;
switch(type){
case SB_LINEUP:
pos = si.nPos - LineStep;
break;
case SB_LINEDOWN:
pos = si.nPos + LineStep;
break;
case SB_PAGEUP:
if(g->Id == GO_SPREADDATA) {
g->Command(CMD_PAGEUP, 0L, w);
return;
}
pos = (si.nPos - (int)si.nPage) >= si.nMin ? (si.nPos - si.nPage) : si.nMin;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -