From 2b566481a1b8874e3b19dc63c68629274cde637a Mon Sep 17 00:00:00 2001 From: William Joye Date: Thu, 23 Mar 2017 12:34:59 -0400 Subject: translate from carbon to cocoa --- tkmacosx/macosxlib.mm | 38 +-------------------- tkmacosx/tkmacosx.h | 16 ++++----- tkmacosx/tkmacosx.mm | 92 +++++++++++++++++++++++++++------------------------ 3 files changed, 56 insertions(+), 90 deletions(-) diff --git a/tkmacosx/macosxlib.mm b/tkmacosx/macosxlib.mm index 0c9034d..65e51a8 100644 --- a/tkmacosx/macosxlib.mm +++ b/tkmacosx/macosxlib.mm @@ -2,28 +2,23 @@ // Smithsonian Astrophysical Observatory, Cambridge, MA, USA // For conditions of distribution and use, see copyright notice in "copyright" -//#include "tkmacosx.h" +#include "tkmacosx.h" #include "macosxlib.h" void macosxBegin() { -/* if (tkmacosx) tkmacosx->begin(); -*/ } void macosxEnd() { -/* if (tkmacosx) tkmacosx->end(); -*/ } void macosxColor(XColor* clr) { -/* if (clr) { float red = clr->red/float(USHRT_MAX); float green = clr->green/float(USHRT_MAX); @@ -32,85 +27,67 @@ void macosxColor(XColor* clr) if (tkmacosx) tkmacosx->color(red,green,blue); } -*/ } void macosxWidth(float ww) { -/* if (tkmacosx) tkmacosx->width(ww); -*/ } void macosxDash(float* d, int n) { -/* if (tkmacosx) tkmacosx->dash(d,n); -*/ } void macosxFont(const char* f, float s) { -/* if (tkmacosx) tkmacosx->font(f,s); -*/ } void macosxClip(Vector v, Vector s) { -/* if (tkmacosx) { Vector vv1 = v*tkmacosx->getCanvasToPage(); Vector vv2 = (v+s)*tkmacosx->getCanvasToPage(); Vector ss = vv2-vv1; tkmacosx->clip(vv1[0],vv1[1],ss[0],ss[1]); } -*/ } void macosxNewPath() { -/* if (tkmacosx) { tkmacosx->newpath(); } -*/ } void macosxStroke() { -/* if (tkmacosx) { tkmacosx->stroke(); } -*/ } void macosxFill() { -/* if (tkmacosx) { tkmacosx->fill(); } -*/ } void macosxArc(Vector v, float rad, float ang1, float ang2) { -/* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->arc(vv[0], vv[1], rad, ang1, ang2); } -*/ } void macosxCurve(Vector v0, Vector t0, Vector t1, Vector v1) { -/* if (tkmacosx) { Vector vv0 = v0*tkmacosx->getCanvasToPage(); Vector tt0 = t0*tkmacosx->getCanvasToPage(); @@ -120,22 +97,18 @@ void macosxCurve(Vector v0, Vector t0, Vector t1, Vector v1) tkmacosx->curve(vv0[0], vv0[1], tt0[0], tt0[1], tt1[0], tt1[1], vv1[0], vv1[1]); } -*/ } void macosxDrawText(Vector v, float ang, const char* text) { -/* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->drawText(vv[0], vv[1], ang, text); } -*/ } void macosxDrawLine(Vector v0, Vector v1) { -/* if (tkmacosx) { Vector vv0 = v0*tkmacosx->getCanvasToPage(); Vector vv1 = v1*tkmacosx->getCanvasToPage(); @@ -151,12 +124,10 @@ void macosxDrawLine(Vector v0, Vector v1) tkmacosx->drawLines(x,y,n); } -*/ } void macosxDrawLines(Vector* v, int n) { -/* if (tkmacosx) { float xx[n]; float yy[n]; @@ -170,12 +141,10 @@ void macosxDrawLines(Vector* v, int n) tkmacosx->drawLines(xx,yy,n); } -*/ } void macosxFillPolygon(Vector* v, int n) { -/* if (tkmacosx) { float xx[n]; float yy[n]; @@ -189,28 +158,23 @@ void macosxFillPolygon(Vector* v, int n) tkmacosx->fillPolygon(xx,yy,n); } -*/ } void macosxDrawArc(Vector v, float rad, float ang1, float ang2) { -/* if (tkmacosx) { Vector vv = v*tkmacosx->getCanvasToPage(); tkmacosx->drawArc(vv[0], vv[1], rad, ang1, ang2); } -*/ } void macosxBitmapCreate(void* img, int width, int height, const Vector& v, const Vector& s) { -/* if (tkmacosx) { Vector vv1 = v*tkmacosx->getCanvasToPage(); Vector vv2 = (v+s)*tkmacosx->getCanvasToPage(); Vector ss = vv2-vv1; tkmacosx->bitmapCreate(img, width, height, vv1[0], vv1[1], ss[0], ss[1]); } -*/ } diff --git a/tkmacosx/tkmacosx.h b/tkmacosx/tkmacosx.h index 83810dd..3c4d6a2 100644 --- a/tkmacosx/tkmacosx.h +++ b/tkmacosx/tkmacosx.h @@ -5,7 +5,7 @@ #ifndef __tkmacosx_h__ #define __tkmacosx_h__ -#include +#include #include @@ -13,13 +13,12 @@ class TkMacosx { private: Tcl_Interp* interp; - /* int showDialog; - - CGContextRef context; Matrix canvasToPage; + CGContextRef context; OSStatus status; + PMPageFormat pageFormat; PMPrintSettings printSettings; PMPrintSession printSession; @@ -29,19 +28,19 @@ class TkMacosx { int pmPrintEnd(); int pmPrintText(int, const char**); int pmPageSetup(); - */ + public: TkMacosx(Tcl_Interp*); ~TkMacosx(); - // int pm(int, const char**); + int pm(int, const char**); int locale(int, const char**); - /* + const Matrix& getCanvasToPage() {return canvasToPage;} void begin(); void end(); - + void color(float,float,float); void width(float); void dash(float*,int); @@ -60,7 +59,6 @@ class TkMacosx { void drawArc(float, float, float, float, float); void bitmapCreate(void*, int, int, float, float, float, float); - */ }; extern TkMacosx* tkmacosx; diff --git a/tkmacosx/tkmacosx.mm b/tkmacosx/tkmacosx.mm index f6fa8d2..5f44984 100644 --- a/tkmacosx/tkmacosx.mm +++ b/tkmacosx/tkmacosx.mm @@ -8,8 +8,6 @@ using namespace std; #include -#include - #include "tkmacosx.h" extern "C" { @@ -42,10 +40,9 @@ int Tkmacosx_Init(Tcl_Interp* interp) { int TkmacosxCmd(ClientData data,Tcl_Interp *interp,int argc,const char* argv[]) { if (argc>=2) { -/* if (!strncmp(argv[1], "pm", 2)) return tkmacosx->pm(argc, argv); -*/ + if (!strncmp(argv[1], "locale", 2)) return tkmacosx->locale(argc, argv); else { @@ -65,7 +62,6 @@ TkMacosx::TkMacosx(Tcl_Interp* intp) { interp = intp; -/* showDialog = 0; status = noErr; @@ -73,17 +69,14 @@ TkMacosx::TkMacosx(Tcl_Interp* intp) printSettings = kPMNoPrintSettings; printSession = NULL; context = NULL; -*/ } TkMacosx::~TkMacosx() { -/* if (pageFormat != kPMNoPageFormat) PMRelease(pageFormat); if (printSettings != kPMNoPrintSettings) PMRelease(printSettings); -*/ } // Locale @@ -113,7 +106,6 @@ int TkMacosx::locale(int argc, const char* argv[]) return TCL_OK; } -/* // Image Print Mangager int TkMacosx::pm(int argc, const char* argv[]) { @@ -243,8 +235,8 @@ int TkMacosx::pmPrintBegin(int argc, const char* argv[]) // dialog if (showDialog) { - Boolean rr; - status = PMSessionPrintDialog(printSession, printSettings, pageFormat, &rr); + Boolean rr =0; +// status = PMSessionPrintDialog(printSession, printSettings, pageFormat, &rr); if (status != noErr) goto error; @@ -284,11 +276,11 @@ int TkMacosx::pmPrintBegin(int argc, const char* argv[]) goto error; } - status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat); +// status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat); if (status != noErr) goto error; - status = PMSessionBeginPage(printSession, pageFormat, NULL); +// status = PMSessionBeginPage(printSession, pageFormat, NULL); if (status != noErr) goto error; @@ -361,10 +353,10 @@ int TkMacosx::pmPrintBegin(int argc, const char* argv[]) int TkMacosx::pmPrintEnd() { - status = PMSessionEndPage(printSession); +// status = PMSessionEndPage(printSession); if (status != noErr) goto error; - status = PMSessionEndDocument(printSession); +// status = PMSessionEndDocument(printSession); if (status != noErr) goto error; @@ -372,7 +364,6 @@ int TkMacosx::pmPrintEnd() if (status != noErr) goto error; - done: PMRelease(printSession); printSession = NULL; return TCL_OK; @@ -406,8 +397,8 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) char* ss; char* st; - char* sstr; - char* estr; + char* sstr =NULL; + char* estr =NULL; // text if (argc >= 5) @@ -519,8 +510,8 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) // dialog { - Boolean rr; - status = PMSessionPrintDialog(printSession, printSettings, pageFormat, &rr); + Boolean rr =0; +// status = PMSessionPrintDialog(printSession, printSettings, pageFormat, &rr); if (status != noErr) goto error; @@ -533,8 +524,8 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) // job name { - CFStringRef jobName = CFSTR("SAOImage DS9"); - status = PMSetJobNameCFString(printSettings, jobName); +// CFStringRef jobName = CFSTR("SAOImage DS9"); +// status = PMSetJobNameCFString(printSettings, jobName); if (status != noErr) goto error; } @@ -567,7 +558,7 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) goto error; // start - status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat); + //status = PMSessionBeginCGDocument(printSession, printSettings, pageFormat); if (status != noErr) goto error; @@ -578,7 +569,7 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) st = sstr; while (currentPage <= lastPage) { - status = PMSessionBeginPage(printSession, pageFormat, NULL); +// status = PMSessionBeginPage(printSession, pageFormat, NULL); if (status != noErr) goto error; @@ -587,7 +578,7 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) goto error; // set context - CGContextSelectFont(context, "Courier", fontSize, kCGEncodingMacRoman); +// CGContextSelectFont(context, "Courier", fontSize, kCGEncodingMacRoman); CGContextSetRGBFillColor(context,0,0,0,1); CGContextSetTextDrawingMode (context, kCGTextFill); @@ -601,8 +592,9 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) // line by line while (ss < estr) { - Vector vv = Vector(xx,yy) * mm; - CGContextShowTextAtPoint (context, vv[0], vv[1], ss, strlen(ss)); + Vector vv = Vector(xx,yy) * mm; + vv = Vector(); // remove waj + // CGContextShowTextAtPoint (context, vv[0], vv[1], ss, strlen(ss)); while (*st++); ss = st; @@ -614,14 +606,14 @@ int TkMacosx::pmPrintText(int argc, const char* argv[]) } } - status = PMSessionEndPage(printSession); + // status = PMSessionEndPage(printSession); if (status != noErr) goto error; currentPage++; } - status = PMSessionEndDocument(printSession); +// status = PMSessionEndDocument(printSession); if (status != noErr) goto error; @@ -677,12 +669,11 @@ int TkMacosx::pmPageSetup() goto error; } - Boolean rr; - status = PMSessionPageSetupDialog(printSession, pageFormat, &rr); + //Boolean rr =0; + //status = PMSessionPageSetupDialog(printSession, pageFormat, &rr); if (status != noErr) goto error; - done: PMRelease(printSession); printSession = NULL; return TCL_OK; @@ -698,108 +689,121 @@ int TkMacosx::pmPageSetup() void TkMacosx::begin() { - CGContextSaveGState(context); +// CGContextSaveGState(context); } void TkMacosx::end() { - CGContextRestoreGState(context); +// CGContextRestoreGState(context); } void TkMacosx::color(float red, float green, float blue) { - CGContextSetRGBStrokeColor(context,red,green,blue,1); - CGContextSetRGBFillColor(context,red,green,blue,1); +// CGContextSetRGBStrokeColor(context,red,green,blue,1); +// CGContextSetRGBFillColor(context,red,green,blue,1); } void TkMacosx::width(float ww) { - CGContextSetLineWidth(context,ww); +// CGContextSetLineWidth(context,ww); } void TkMacosx::dash(float* dd, int nn) { - CGContextSetLineDash(context,0,(CGFloat*)dd,nn); +// CGContextSetLineDash(context,0,(CGFloat*)dd,nn); } void TkMacosx::font(const char* font, float size) { - CGContextSelectFont(context, font, size, kCGEncodingMacRoman); +// CGContextSelectFont(context, font, size, kCGEncodingMacRoman); } void TkMacosx::clip(float x, float y, float w, float h) { +/* CGContextBeginPath(context); CGContextAddRect(context, CGRectMake(x,y,w,h)); CGContextClosePath(context); CGContextClip(context); +*/ } void TkMacosx::newpath() { - CGContextBeginPath(context); +// CGContextBeginPath(context); } void TkMacosx::stroke() { - CGContextStrokePath(context); +// CGContextStrokePath(context); } void TkMacosx::fill() { - CGContextEOFillPath(context); +// CGContextEOFillPath(context); } void TkMacosx::arc(float x, float y, float rad, float ang1, float ang2) { - CGContextAddArc(context, x, y, rad, ang1, ang2, 0); +// CGContextAddArc(context, x, y, rad, ang1, ang2, 0); } void TkMacosx::curve(float x0, float y0, float u0, float v0, float u1, float v1, float x1, float y1) { +/* CGContextMoveToPoint(context, x0, y0); CGContextAddCurveToPoint(context, u0, v0, u1, v1, x1, y1); +*/ } void TkMacosx::drawText(float x, float y, float angle, const char* text) { +/* CGAffineTransform mm = CGAffineTransformMakeRotation(angle); CGContextSetTextMatrix(context, mm); CGContextSetTextDrawingMode (context, kCGTextFill); CGContextShowTextAtPoint (context, x, y, text, strlen(text)); +*/ } void TkMacosx::drawLines(float* x, float* y, int n) { +/* CGContextBeginPath(context); CGContextMoveToPoint(context, x[0], y[0]); for (int ii=1; ii