diff --git a/graphics/grTCairo1.c b/graphics/grTCairo1.c index 7b4cb312..f9eb1397 100644 --- a/graphics/grTCairo1.c +++ b/graphics/grTCairo1.c @@ -58,8 +58,9 @@ XVisualInfo *grVisualInfo; //TOGL_CURRENT toglCurrent= {(Tk_Font)0, 0, 0, 0, 0, // (Tk_Window)0, (Window)0, (MagWindow *)NULL}; -TCAIRO_CURRENT tcairoCurrent= {(Tk_Font)0, 0, 0, 0, 0, - (Tk_Window)0, (Window)0, (MagWindow *)NULL}; +TCAIRO_CURRENT tcairoCurrent = {(Tk_Font)0, 0, 0, 0, 0, + (Tk_Window)0, (Window)0, (MagWindow *)NULL + }; /* This is kind of a long story, and very kludgy, but the following * things need to be defined as externals because of the way lint @@ -95,52 +96,52 @@ extern void toglSetProjection(); void grtoglSetWMandC (mask, c) - int mask; /* New value for write mask */ - int c; /* New value for current color */ +int mask; /* New value for write mask */ +int c; /* New value for current color */ { - static int oldColor = -1; - static int oldMask = -1; + static int oldColor = -1; + static int oldMask = -1; - int lr, lb, lg; - GLfloat fr, fb, fg; - GLfloat aval; /* Alpha default value was 0.75 */ + int lr, lb, lg; + GLfloat fr, fb, fg; + GLfloat aval; /* Alpha default value was 0.75 */ - if (mask == -65) mask = 127; /* All planes */ - if (mask == oldMask && c == oldColor) return; + if (mask == -65) mask = 127; /* All planes */ + if (mask == oldMask && c == oldColor) return; - GR_TOGL_FLUSH_BATCH(); + GR_TOGL_FLUSH_BATCH(); - GrGetColor(c, &lr, &lb, &lg); + GrGetColor(c, &lr, &lb, &lg); - fr = ((GLfloat)lr / 255); - fg = ((GLfloat)lg / 255); - fb = ((GLfloat)lb / 255); + fr = ((GLfloat)lr / 255); + fg = ((GLfloat)lg / 255); + fb = ((GLfloat)lb / 255); - if (mask == 127) - { - glDisable(GL_BLEND); - aval = 1.0; - } - else - { - /* Calculate a "supercolor", outside of the normal color range, */ - /* but which results in the desired color after a blend with */ - /* the background color. */ + if (mask == 127) + { + glDisable(GL_BLEND); + aval = 1.0; + } + else + { + /* Calculate a "supercolor", outside of the normal color range, */ + /* but which results in the desired color after a blend with */ + /* the background color. */ - fr = fr * 2 - 0.8; - fg = fg * 2 - 0.8; - fb = fb * 2 - 0.8; + fr = fr * 2 - 0.8; + fg = fg * 2 - 0.8; + fb = fb * 2 - 0.8; - aval = (GLfloat)mask / 127.0; /* mask translates to alpha in */ - /* the OpenGL version. */ + aval = (GLfloat)mask / 127.0; /* mask translates to alpha in */ + /* the OpenGL version. */ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - glColor4f(fr, fb, fg, aval); - - oldColor = c; - oldMask = mask; + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + glColor4f(fr, fb, fg, aval); + + oldColor = c; + oldMask = mask; } @@ -158,27 +159,27 @@ grtoglSetWMandC (mask, c) void grtoglSetLineStyle (style) - int style; /* New stipple pattern for lines. */ +int style; /* New stipple pattern for lines. */ { - static int oldStyle = -1; - GLushort glstyle; + static int oldStyle = -1; + GLushort glstyle; - style &= 0xFF; - if (style == oldStyle) return; - oldStyle = style; - GR_TOGL_FLUSH_BATCH(); + style &= 0xFF; + if (style == oldStyle) return; + oldStyle = style; + GR_TOGL_FLUSH_BATCH(); - switch (style) { + switch (style) { case 0xFF: case 0x00: - glDisable(GL_LINE_STIPPLE); - break; + glDisable(GL_LINE_STIPPLE); + break; default: - glstyle = style | (style << 8); - glEnable(GL_LINE_STIPPLE); - glLineStipple(1, glstyle); - break; - } + glstyle = style | (style << 8); + glEnable(GL_LINE_STIPPLE); + glLineStipple(1, glstyle); + break; + } } @@ -196,26 +197,26 @@ grtoglSetLineStyle (style) void grtoglSetSPattern (sttable, numstipples) - int **sttable; /* The table of patterns */ - int numstipples; /* Number of stipples */ +int **sttable; /* The table of patterns */ +int numstipples; /* Number of stipples */ { - int i, j, k, n; - GLubyte *pdata; + int i, j, k, n; + GLubyte *pdata; - grTOGLStipples = (GLubyte **)mallocMagic(numstipples * sizeof(GLubyte *)); - for (k = 0; k < numstipples; k++) - { - pdata = (GLubyte *)mallocMagic(128 * sizeof(GLubyte)); - n = 0; + grTOGLStipples = (GLubyte **)mallocMagic(numstipples * sizeof(GLubyte *)); + for (k = 0; k < numstipples; k++) + { + pdata = (GLubyte *)mallocMagic(128 * sizeof(GLubyte)); + n = 0; - /* expand magic's default 8x8 stipple to OpenGL's 32x32 */ + /* expand magic's default 8x8 stipple to OpenGL's 32x32 */ - for (i = 0; i < 32; i++) - for (j = 0; j < 4; j++) - pdata[n++] = (GLubyte)sttable[k][i % 8]; + for (i = 0; i < 32; i++) + for (j = 0; j < 4; j++) + pdata[n++] = (GLubyte)sttable[k][i % 8]; - grTOGLStipples[k] = pdata; - } + grTOGLStipples[k] = pdata; + } } @@ -233,19 +234,19 @@ grtoglSetSPattern (sttable, numstipples) void grtoglSetStipple (stipple) - int stipple; /* The stipple number to be used. */ +int stipple; /* The stipple number to be used. */ { - static int oldStip = -1; - if (stipple == oldStip) return; - oldStip = stipple; - GR_TOGL_FLUSH_BATCH(); - if (stipple == 0 || stipple > grNumStipples) { - glDisable(GL_POLYGON_STIPPLE); - } else { - if (grTOGLStipples[stipple] == (GLubyte *)NULL) MainExit(1); - glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(grTOGLStipples[stipple]); - } + static int oldStip = -1; + if (stipple == oldStip) return; + oldStip = stipple; + GR_TOGL_FLUSH_BATCH(); + if (stipple == 0 || stipple > grNumStipples) { + glDisable(GL_POLYGON_STIPPLE); + } else { + if (grTOGLStipples[stipple] == (GLubyte *)NULL) MainExit(1); + glEnable(GL_POLYGON_STIPPLE); + glPolygonStipple(grTOGLStipples[stipple]); + } } @@ -258,7 +259,7 @@ grtoglSetStipple (stipple) * * Notes: When 3D rendering is compiled in, we search for a double-buffered * configuration first, because it generates the smoothest graphics, - * and fall back on a single-buffered configuration if necessary. + * and fall back on a single-buffered configuration if necessary. * For normal, 2D-only rendering, we look for a single-buffered * configuration first because we don't use the back buffer, so a * double-buffered configuration just wastes space. @@ -268,73 +269,73 @@ grtoglSetStipple (stipple) bool GrTCairoInit () { - bool rstatus; + bool rstatus; #ifdef THREE_D - static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; + static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; #else - static int attributeList[] = { GLX_RGBA, None, None }; + static int attributeList[] = { GLX_RGBA, None, None }; #endif - tcairoCurrent.window = Tk_MainWindow(magicinterp); - if (tcairoCurrent.window == NULL) - { - TxError("No Top-Level Tk window available. . . is Tk running?\n"); - return FALSE; - } + tcairoCurrent.window = Tk_MainWindow(magicinterp); + if (tcairoCurrent.window == NULL) + { + TxError("No Top-Level Tk window available. . . is Tk running?\n"); + return FALSE; + } - tcairoCurrent.windowid = Tk_WindowId(tcairoCurrent.window); - grXdpy = Tk_Display(tcairoCurrent.window); - tcairoCurrent.depth = Tk_Depth(tcairoCurrent.window); + tcairoCurrent.windowid = Tk_WindowId(tcairoCurrent.window); + grXdpy = Tk_Display(tcairoCurrent.window); + tcairoCurrent.depth = Tk_Depth(tcairoCurrent.window); - grXscrn = DefaultScreen(grXdpy); + grXscrn = DefaultScreen(grXdpy); - grVisualInfo = glXChooseVisual(grXdpy, grXscrn, attributeList); - - if (!grVisualInfo) - { - /* Try for a double-buffered configuration */ -#ifdef THREE_D - attributeList[1] = None; -#else - attributeList[1] = GLX_DOUBLEBUFFER; -#endif grVisualInfo = glXChooseVisual(grXdpy, grXscrn, attributeList); + if (!grVisualInfo) { - TxError("No suitable visual!\n"); - return FALSE; + /* Try for a double-buffered configuration */ +#ifdef THREE_D + attributeList[1] = None; +#else + attributeList[1] = GLX_DOUBLEBUFFER; +#endif + grVisualInfo = glXChooseVisual(grXdpy, grXscrn, attributeList); + if (!grVisualInfo) + { + TxError("No suitable visual!\n"); + return FALSE; + } } - } - grXscrn = grVisualInfo->screen; - tcairoCurrent.depth = grVisualInfo->depth; + grXscrn = grVisualInfo->screen; + tcairoCurrent.depth = grVisualInfo->depth; - /* TRUE = Direct rendering, FALSE = Indirect rendering */ - /* (note that direct rendering may not be able to deal with pixmaps) */ - //grXcontext = glXCreateContext(grXdpy, grVisualInfo, NULL, GL_FALSE); - // should we still use tcairoCurrent? - grCairoSurface = cairo_xlib_surface_create(grXdpy, tcairoCurrent.window, grVisualInfo->visual, Tk_Width(tcairoCurrent.window), Tk_Height(tcairoCurrent.window)); - grCairoContext = cairo_create(grCairoSurface); + /* TRUE = Direct rendering, FALSE = Indirect rendering */ + /* (note that direct rendering may not be able to deal with pixmaps) */ + //grXcontext = glXCreateContext(grXdpy, grVisualInfo, NULL, GL_FALSE); + // should we still use tcairoCurrent? + grCairoSurface = cairo_xlib_surface_create(grXdpy, tcairoCurrent.window, grVisualInfo->visual, Tk_Width(tcairoCurrent.window), Tk_Height(tcairoCurrent.window)); + grCairoContext = cairo_create(grCairoSurface); - /* Basic GL parameters */ - /* - glLineWidth(1.0); - glShadeModel (GL_FLAT); - glPixelStorei(GL_PACK_LSB_FIRST, TRUE); + /* Basic GL parameters */ + /* + glLineWidth(1.0); + glShadeModel (GL_FLAT); + glPixelStorei(GL_PACK_LSB_FIRST, TRUE); */ - cairo_set_line_width(grCairoContext, 1.0); - cairo_set_source_rgb(grCairoContext, 0, 0, 0); + cairo_set_line_width(grCairoContext, 1.0); + cairo_set_source_rgb(grCairoContext, 0, 0, 0); - /* OpenGL sets its own names for colormap and dstyle file types */ - grCMapType = "OpenGL"; - grDStyleType = "OpenGL"; + /* OpenGL sets its own names for colormap and dstyle file types */ + grCMapType = "OpenGL"; + grDStyleType = "OpenGL"; - /* Globally-accessed variables */ - grNumBitPlanes = tcairoCurrent.depth; - grBitPlaneMask = (1 << tcairoCurrent.depth) - 1; + /* Globally-accessed variables */ + grNumBitPlanes = tcairoCurrent.depth; + grBitPlaneMask = (1 << tcairoCurrent.depth) - 1; - HashInit(&grTOGLWindowTable,8,HT_WORDKEYS); + HashInit(&grTOGLWindowTable, 8, HT_WORDKEYS); - return grTkLoadFont(); + return grTkLoadFont(); } /*--------------------------------------------------------- @@ -349,13 +350,13 @@ GrTCairoInit () void GrTOGLClose () { - if (grXdpy == NULL) return; - if (grVisualInfo != NULL) XFree(grVisualInfo); - - grTkFreeFonts(); + if (grXdpy == NULL) return; + if (grVisualInfo != NULL) XFree(grVisualInfo); - /* Pop down Tk window but let Tcl/Tk */ - /* do XCloseDisplay() */ + grTkFreeFonts(); + + /* Pop down Tk window but let Tcl/Tk */ + /* do XCloseDisplay() */ } @@ -375,9 +376,9 @@ GrTOGLClose () void GrTOGLFlush () { - GR_TOGL_FLUSH_BATCH(); - glFlush(); - glFinish(); + GR_TOGL_FLUSH_BATCH(); + glFlush(); + glFinish(); } /* @@ -397,56 +398,57 @@ Pixmap cairopmap = (Pixmap)NULL; void tcairoSetProjection(llx, lly, width, height) - int llx, lly, width, height; +int llx, lly, width, height; { - if (toglCurrent.mw->w_flags & WIND_OFFSCREEN) - { - /* - if (glpmap != None) glXDestroyGLXPixmap(grXdpy, glpmap); - glpmap = glXCreateGLXPixmap(grXdpy, grVisualInfo, - (Pixmap)toglCurrent.windowid); - glXMakeCurrent(grXdpy, (GLXDrawable)glpmap, grXcontext); - */ - cairopmap = XCreatePixmap(grXdpy, grXscrn, width, height, toglCurrent.depth); - cairo_set_source(grCairoContext); - } - else - glXMakeCurrent(grXdpy, (GLXDrawable)toglCurrent.windowid, grXcontext); + if (tcairoCurrent.mw->w_flags & WIND_OFFSCREEN) + { + /* + if (glpmap != None) glXDestroyGLXPixmap(grXdpy, glpmap); + glpmap = glXCreateGLXPixmap(grXdpy, grVisualInfo, + (Pixmap)toglCurrent.windowid); + glXMakeCurrent(grXdpy, (GLXDrawable)glpmap, grXcontext); + */ + cairopmap = XCreatePixmap(grXdpy, grXscrn, width, height, tcairoCurrent.depth); + grCairoSurface = cairo_xlib_surface_create(grXdpy, cairopmap, grVisualInfo->visual, width, height); + //cairo_set_source(grCairoContext); + } + else + glXMakeCurrent(grXdpy, (GLXDrawable)toglCurrent.windowid, grXcontext); #ifndef OGL_SERVER_SIDE_ONLY - /* For batch-processing lines and rectangles */ - glEnableClientState(GL_VERTEX_ARRAY); + /* For batch-processing lines and rectangles */ + glEnableClientState(GL_VERTEX_ARRAY); #endif - /* Because this tends to result in thick lines, it has been moved */ - /* the line drawing routine so it can be enabled for individual */ - /* lines. */ - /* glEnable(GL_LINE_SMOOTH); */ + /* Because this tends to result in thick lines, it has been moved */ + /* the line drawing routine so it can be enabled for individual */ + /* lines. */ + /* glEnable(GL_LINE_SMOOTH); */ - /* Force draw to front buffer (in case of double-buffered config) */ - glDrawBuffer(GL_FRONT); + /* Force draw to front buffer (in case of double-buffered config) */ + glDrawBuffer(GL_FRONT); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - glViewport((GLsizei)llx, (GLsizei)lly, (GLsizei) width, (GLsizei) height); + glViewport((GLsizei)llx, (GLsizei)lly, (GLsizei) width, (GLsizei) height); - /* scale to fit window */ + /* scale to fit window */ #ifdef OGL_INVERT_Y - glScalef(1.0 / (float)(width >> 1), -1.0 / (float)(height >> 1), 1.0); + glScalef(1.0 / (float)(width >> 1), -1.0 / (float)(height >> 1), 1.0); #else - glScalef(1.0 / (float)(width >> 1), 1.0 / (float)(height >> 1), 1.0); + glScalef(1.0 / (float)(width >> 1), 1.0 / (float)(height >> 1), 1.0); #endif - /* magic origin maps to window center; move to window origin */ + /* magic origin maps to window center; move to window origin */ - glTranslated(-(GLsizei)(width >> 1), -(GLsizei)(height >> 1), 0); + glTranslated(-(GLsizei)(width >> 1), -(GLsizei)(height >> 1), 0); - /* Remaining transformations are done on the modelview matrix */ + /* Remaining transformations are done on the modelview matrix */ - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } @@ -468,431 +470,431 @@ tcairoSetProjection(llx, lly, width, height) void TOGLEventProc(clientData, xevent) - ClientData clientData; - XEvent *xevent; +ClientData clientData; +XEvent *xevent; { - TxInputEvent *event; - HashEntry *entry; - Tk_Window tkwind = (Tk_Window)clientData; - Window wind; - MagWindow *mw; - unsigned char LocRedirect = TxInputRedirect; + TxInputEvent *event; + HashEntry *entry; + Tk_Window tkwind = (Tk_Window)clientData; + Window wind; + MagWindow *mw; + unsigned char LocRedirect = TxInputRedirect; - XKeyPressedEvent *KeyPressedEvent = (XKeyPressedEvent *) xevent; - KeySym keysym; - int nbytes; + XKeyPressedEvent *KeyPressedEvent = (XKeyPressedEvent *) xevent; + KeySym keysym; + int nbytes; - /* Keys and Buttons: Determine expansion of macros or redirect - * keys to the terminal or console. - */ + /* Keys and Buttons: Determine expansion of macros or redirect + * keys to the terminal or console. + */ - switch (xevent->type) - { + switch (xevent->type) + { case ButtonPress: - { + { XButtonEvent *ButtonEvent = (XButtonEvent *) xevent; int txbutton; switch (ButtonEvent->button) { case Button1: - txbutton = TX_LEFT_BUTTON; - keysym = XK_Pointer_Button1; - break; + txbutton = TX_LEFT_BUTTON; + keysym = XK_Pointer_Button1; + break; case Button2: - txbutton = TX_MIDDLE_BUTTON; - keysym = XK_Pointer_Button2; - break; + txbutton = TX_MIDDLE_BUTTON; + keysym = XK_Pointer_Button2; + break; case Button3: - txbutton = TX_RIGHT_BUTTON; - keysym = XK_Pointer_Button3; - break; + txbutton = TX_RIGHT_BUTTON; + keysym = XK_Pointer_Button3; + break; case Button4: - txbutton = TX_BUTTON_4; - keysym = XK_Pointer_Button4; - break; + txbutton = TX_BUTTON_4; + keysym = XK_Pointer_Button4; + break; case Button5: - txbutton = TX_BUTTON_5; - keysym = XK_Pointer_Button5; - break; + txbutton = TX_BUTTON_5; + keysym = XK_Pointer_Button5; + break; } nbytes = 0; entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry)?(MagWindow *)HashGetValue(entry):0; + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; if (mw && (mw->w_flags & WIND_SCROLLBARS)) - if (WindButtonInFrame(mw, ButtonEvent->x, - grXtransY(mw, ButtonEvent->y), - txbutton)) - break; + if (WindButtonInFrame(mw, ButtonEvent->x, + grXtransY(mw, ButtonEvent->y), + txbutton)) + break; goto keys_and_buttons; - } - break; + } + break; case KeyPress: - { + { int keywstate, keymod, idx, idxmax; char inChar[10]; Tcl_Channel outChannel = Tcl_GetStdChannel(TCL_STDOUT); nbytes = XLookupString(KeyPressedEvent, inChar, sizeof(inChar), - &keysym, NULL); + &keysym, NULL); if (IsModifierKey(keysym)) break; /* Don't handle modifiers */ entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry)?(MagWindow *)HashGetValue(entry):0; + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; keys_and_buttons: keymod = (LockMask | ControlMask | ShiftMask) - & KeyPressedEvent->state; + & KeyPressedEvent->state; #ifdef __APPLE__ if (KeyPressedEvent->state & (Mod1Mask | Mod2Mask | - Mod3Mask | Mod4Mask | Mod5Mask)) - keymod |= Mod1Mask; + Mod3Mask | Mod4Mask | Mod5Mask)) + keymod |= Mod1Mask; #else keymod |= (Mod1Mask & KeyPressedEvent->state); #endif if (nbytes == 0) /* No ASCII equivalent */ { - keywstate = (keymod << 16) | (keysym & 0xffff); + keywstate = (keymod << 16) | (keysym & 0xffff); } else if (!strncmp(XKeysymToString(keysym), "KP_", 3)) { - /* keypad key (special case---would like to */ - /* differentiate between shift-KP-# and # itself) */ - keymod &= ~ShiftMask; - keywstate = (keymod << 16) | (keysym & 0xffff); - nbytes = 0; + /* keypad key (special case---would like to */ + /* differentiate between shift-KP-# and # itself) */ + keymod &= ~ShiftMask; + keywstate = (keymod << 16) | (keysym & 0xffff); + nbytes = 0; } else /* ASCII-valued character */ { - if (!(keymod & (LockMask | Mod1Mask))) { - if (!(keymod & ControlMask)) - keymod &= ~ShiftMask; - else if (!(keymod & ShiftMask)) - keymod &= ~ControlMask; - } + if (!(keymod & (LockMask | Mod1Mask))) { + if (!(keymod & ControlMask)) + keymod &= ~ShiftMask; + else if (!(keymod & ShiftMask)) + keymod &= ~ControlMask; + } } idxmax = (nbytes == 0) ? 1 : nbytes; for (idx = 0; idx < idxmax; idx++) { - if (inChar[idx] == 3) /* Ctrl-C interrupt */ - { - if (SigInterruptPending) - MainExit(0); /* double Ctrl-C */ - else - sigOnInterrupt(0); /* Set InterruptPending */ - break; - } - else if (nbytes > 0) - { - if ((keymod & ControlMask) && (inChar[idx] < 32)) - inChar[idx] += 'A' - 1; - - keywstate = (keymod << 16) | ((int)inChar[idx] & 0xff); - } - - /* Allow buttons to bypass the console and be */ - /* treated as macros. */ - - if (LocRedirect == TX_INPUT_REDIRECTED) - { - switch (keysym) + if (inChar[idx] == 3) /* Ctrl-C interrupt */ { - case XK_Pointer_Button1: - case XK_Pointer_Button2: - case XK_Pointer_Button3: - case XK_Pointer_Button4: - case XK_Pointer_Button5: - LocRedirect = TX_INPUT_NORMAL;; + if (SigInterruptPending) + MainExit(0); /* double Ctrl-C */ + else + sigOnInterrupt(0); /* Set InterruptPending */ break; } - } + else if (nbytes > 0) + { + if ((keymod & ControlMask) && (inChar[idx] < 32)) + inChar[idx] += 'A' - 1; - if ((LocRedirect == TX_INPUT_REDIRECTED) && TxTkConsole) - { - Tcl_SavedResult state; - static char outstr[] = "::tkcon::Insert .text \"x\" "; + keywstate = (keymod << 16) | ((int)inChar[idx] & 0xff); + } - switch (keysym) - { - case XK_Return: - TxSetPoint(KeyPressedEvent->x, - grXtransY(mw, KeyPressedEvent->y), - mw->w_wid); - TxInputRedirect = TX_INPUT_PROCESSING; - Tcl_EvalEx(consoleinterp, "::tkcon::Eval .text", - 19, 0); - TxInputRedirect = TX_INPUT_NORMAL; - TxSetPrompt('%'); + /* Allow buttons to bypass the console and be */ + /* treated as macros. */ - Tcl_SaveResult(magicinterp, &state); - Tcl_EvalEx(magicinterp, "history event 0", 15, 0); - MacroDefine(mw->w_client, (int)'.', - Tcl_GetStringResult(magicinterp), NULL, - FALSE); - Tcl_RestoreResult(magicinterp, &state); - break; - case XK_Up: - Tcl_EvalEx(consoleinterp, "::tkcon::Event -1", - 17, 0); - break; - case XK_Down: - Tcl_EvalEx(consoleinterp, "::tkcon::Event 1", - 16, 0); - break; - case XK_Left: - Tcl_EvalEx(consoleinterp, ".text mark set insert " - "insert-1c ; .text see insert", 50, 0); - break; - case XK_Right: - Tcl_EvalEx(consoleinterp, ".text mark set insert " - "insert+1c ; .text see insert", 50, 0); - break; - case XK_BackSpace: case XK_Delete: - Tcl_EvalEx(consoleinterp, ".text delete insert-1c ;" - ".text see insert", 40, 0); - break; - case XK_quotedbl: case XK_backslash: case XK_bracketleft: - outstr[23] = '\\'; - outstr[24] = inChar[idx]; - outstr[25] = '\"'; - Tcl_EvalEx(consoleinterp, outstr, 26, 0); - outstr[24] = '\"'; - outstr[25] = '\0'; - default: - outstr[23] = inChar[idx]; - Tcl_EvalEx(consoleinterp, outstr, 25, 0); - break; - } - } - else if (LocRedirect == TX_INPUT_REDIRECTED) { - int tl; - if (TxBuffer == NULL) + if (LocRedirect == TX_INPUT_REDIRECTED) { - TxBuffer = Tcl_Alloc(2); - *TxBuffer = '\0'; - tl = 0; - } - else - { - tl = strlen(TxBuffer); - TxBuffer = Tcl_Realloc(TxBuffer, tl + 2); - } - if (keysym == XK_BackSpace || keysym == XK_Delete) - { - if (tl >= 0) - { - if (tl > 0) + switch (keysym) { - *(TxBuffer + tl - 1) = '\0'; - TxPrintf("\b"); + case XK_Pointer_Button1: + case XK_Pointer_Button2: + case XK_Pointer_Button3: + case XK_Pointer_Button4: + case XK_Pointer_Button5: + LocRedirect = TX_INPUT_NORMAL;; + break; } - TxPrintf(" \b"); - TxFlushOut(); - } - } - else if (keysym == XK_Return) - { - *(TxBuffer + tl) = '\n'; - *(TxBuffer + tl + 1) = '\0'; - if (tl != 0) MacroDefine(mw->w_client, - XK_period, TxBuffer, NULL, FALSE); - TxInputRedirect = TX_INPUT_NORMAL; - TxSetPoint(KeyPressedEvent->x, - grXtransY(mw, KeyPressedEvent->y), - mw->w_wid); - TxPrintf("\n"); - TxFlushOut(); - Tcl_NotifyChannel(Tcl_GetStdChannel(TCL_STDIN), - TCL_READABLE); - } - else - { - *(TxBuffer + tl) = *(inChar + idx); - *(TxBuffer + tl + 1) = '\0'; - TxPrintf("%c", *(inChar + idx)); - TxFlushOut(); - } - } - else - { - bool iMacro; - char *macroDef; - - macroDef = MacroRetrieve(mw->w_client, keywstate, &iMacro); - - /* Special handling: An imacro beginning with ':' */ - /* sets the prompt to ':' and moves to the next char. */ - - if (macroDef != NULL && *macroDef == ':' && iMacro) - { - if (TxTkConsole) - TxSetPrompt(':'); - else - { - TxPrintf("\b\b: "); - TxFlushOut(); - } - memmove(macroDef, macroDef + 1, strlen(macroDef + 1) + 1); } - macroDef = MacroSubstitute(macroDef, "%W", Tk_PathName(tkwind)); - - if (macroDef == NULL) + if ((LocRedirect == TX_INPUT_REDIRECTED) && TxTkConsole) { - if (keysym != XK_Return) - { - char *vis = MacroName(keywstate); - TxError("Unknown macro or short command: '%s'\n", vis); + Tcl_SavedResult state; + static char outstr[] = "::tkcon::Insert .text \"x\" "; - freeMagic(vis); - } - /* Print Carriage Return & Put back Tcl/Tk prompt */ - TxParseString("", NULL, NULL); - } - else - { - int sl = strlen(macroDef); - - if (iMacro) - { - /* Echo macro to interpreter, then redirect keys */ - - if (TxTkConsole) + switch (keysym) { - char *outstring = Tcl_Alloc(sl + 20); - sprintf(outstring, ".text insert end \"%s\"", - macroDef); - Tcl_EvalEx(consoleinterp, outstring, -1, 0); - Tcl_Free(outstring); + case XK_Return: + TxSetPoint(KeyPressedEvent->x, + grXtransY(mw, KeyPressedEvent->y), + mw->w_wid); + TxInputRedirect = TX_INPUT_PROCESSING; + Tcl_EvalEx(consoleinterp, "::tkcon::Eval .text", + 19, 0); + TxInputRedirect = TX_INPUT_NORMAL; + TxSetPrompt('%'); + + Tcl_SaveResult(magicinterp, &state); + Tcl_EvalEx(magicinterp, "history event 0", 15, 0); + MacroDefine(mw->w_client, (int)'.', + Tcl_GetStringResult(magicinterp), NULL, + FALSE); + Tcl_RestoreResult(magicinterp, &state); + break; + case XK_Up: + Tcl_EvalEx(consoleinterp, "::tkcon::Event -1", + 17, 0); + break; + case XK_Down: + Tcl_EvalEx(consoleinterp, "::tkcon::Event 1", + 16, 0); + break; + case XK_Left: + Tcl_EvalEx(consoleinterp, ".text mark set insert " + "insert-1c ; .text see insert", 50, 0); + break; + case XK_Right: + Tcl_EvalEx(consoleinterp, ".text mark set insert " + "insert+1c ; .text see insert", 50, 0); + break; + case XK_BackSpace: case XK_Delete: + Tcl_EvalEx(consoleinterp, ".text delete insert-1c ;" + ".text see insert", 40, 0); + break; + case XK_quotedbl: case XK_backslash: case XK_bracketleft: + outstr[23] = '\\'; + outstr[24] = inChar[idx]; + outstr[25] = '\"'; + Tcl_EvalEx(consoleinterp, outstr, 26, 0); + outstr[24] = '\"'; + outstr[25] = '\0'; + default: + outstr[23] = inChar[idx]; + Tcl_EvalEx(consoleinterp, outstr, 25, 0); + break; + } + } + else if (LocRedirect == TX_INPUT_REDIRECTED) { + int tl; + if (TxBuffer == NULL) + { + TxBuffer = Tcl_Alloc(2); + *TxBuffer = '\0'; + tl = 0; } else { - TxBuffer = Tcl_Alloc(sl + 1); - strcpy(TxBuffer, macroDef); - TxPrintf("%s", macroDef); - TxFlushOut(); + tl = strlen(TxBuffer); + TxBuffer = Tcl_Realloc(TxBuffer, tl + 2); + } + if (keysym == XK_BackSpace || keysym == XK_Delete) + { + if (tl >= 0) + { + if (tl > 0) + { + *(TxBuffer + tl - 1) = '\0'; + TxPrintf("\b"); + } + TxPrintf(" \b"); + TxFlushOut(); + } + } + else if (keysym == XK_Return) + { + *(TxBuffer + tl) = '\n'; + *(TxBuffer + tl + 1) = '\0'; + if (tl != 0) MacroDefine(mw->w_client, + XK_period, TxBuffer, NULL, FALSE); + TxInputRedirect = TX_INPUT_NORMAL; + TxSetPoint(KeyPressedEvent->x, + grXtransY(mw, KeyPressedEvent->y), + mw->w_wid); + TxPrintf("\n"); + TxFlushOut(); + Tcl_NotifyChannel(Tcl_GetStdChannel(TCL_STDIN), + TCL_READABLE); + } + else + { + *(TxBuffer + tl) = *(inChar + idx); + *(TxBuffer + tl + 1) = '\0'; + TxPrintf("%c", *(inChar + idx)); + TxFlushOut(); + } + } + else + { + bool iMacro; + char *macroDef; + + macroDef = MacroRetrieve(mw->w_client, keywstate, &iMacro); + + /* Special handling: An imacro beginning with ':' */ + /* sets the prompt to ':' and moves to the next char. */ + + if (macroDef != NULL && *macroDef == ':' && iMacro) + { + if (TxTkConsole) + TxSetPrompt(':'); + else + { + TxPrintf("\b\b: "); + TxFlushOut(); + } + memmove(macroDef, macroDef + 1, strlen(macroDef + 1) + 1); + } + + macroDef = MacroSubstitute(macroDef, "%W", Tk_PathName(tkwind)); + + if (macroDef == NULL) + { + if (keysym != XK_Return) + { + char *vis = MacroName(keywstate); + TxError("Unknown macro or short command: '%s'\n", vis); + + freeMagic(vis); + } + /* Print Carriage Return & Put back Tcl/Tk prompt */ + TxParseString("", NULL, NULL); + } + else + { + int sl = strlen(macroDef); + + if (iMacro) + { + /* Echo macro to interpreter, then redirect keys */ + + if (TxTkConsole) + { + char *outstring = Tcl_Alloc(sl + 20); + sprintf(outstring, ".text insert end \"%s\"", + macroDef); + Tcl_EvalEx(consoleinterp, outstring, -1, 0); + Tcl_Free(outstring); + } + else + { + TxBuffer = Tcl_Alloc(sl + 1); + strcpy(TxBuffer, macroDef); + TxPrintf("%s", macroDef); + TxFlushOut(); + } + TxInputRedirect = TX_INPUT_REDIRECTED; + } + else + { + /* TxParseString is defined by tcltk/tclmagic.c + * and calls Tcl_Eval() + */ + + TxSetPoint(KeyPressedEvent->x, + grXtransY(mw, KeyPressedEvent->y), + mw->w_wid); + TxParseString(macroDef, NULL, NULL); + } + freeMagic(macroDef); } - TxInputRedirect = TX_INPUT_REDIRECTED; - } - else - { - /* TxParseString is defined by tcltk/tclmagic.c - * and calls Tcl_Eval() - */ - - TxSetPoint(KeyPressedEvent->x, - grXtransY(mw, KeyPressedEvent->y), - mw->w_wid); - TxParseString(macroDef, NULL, NULL); - } - freeMagic(macroDef); } - } } - } - break; + } + break; case ConfigureNotify: - { + { XConfigureEvent *ConfigureEvent = (XConfigureEvent*) xevent; Rect screenRect; int width, height; bool result, need_resize; - + width = ConfigureEvent->width; height = ConfigureEvent->height; entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry)?(MagWindow *)HashGetValue(entry):0; + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; screenRect.r_xbot = ConfigureEvent->x; - screenRect.r_xtop = ConfigureEvent->x + width; - screenRect.r_ytop = glTransYs(ConfigureEvent->y); - screenRect.r_ybot = glTransYs(ConfigureEvent->y + height); + screenRect.r_xtop = ConfigureEvent->x + width; + screenRect.r_ytop = glTransYs(ConfigureEvent->y); + screenRect.r_ybot = glTransYs(ConfigureEvent->y + height); need_resize = (screenRect.r_xbot != mw->w_screenArea.r_xbot || - screenRect.r_xtop != mw->w_screenArea.r_xtop || - screenRect.r_ybot != mw->w_screenArea.r_ybot || - screenRect.r_ytop != mw->w_screenArea.r_ytop); + screenRect.r_xtop != mw->w_screenArea.r_xtop || + screenRect.r_ybot != mw->w_screenArea.r_ybot || + screenRect.r_ytop != mw->w_screenArea.r_ytop); /* Redraw the window */ WindReframe(mw, &screenRect, FALSE, FALSE); WindRedisplay(mw); if (need_resize) (*GrCreateBackingStorePtr)(mw); - } - break; + } + break; case VisibilityNotify: - { + { XVisibilityEvent *VisEvent = (XVisibilityEvent*) xevent; entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry)?(MagWindow *)HashGetValue(entry):0; + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; - switch(VisEvent->state) + switch (VisEvent->state) { - case VisibilityUnobscured: + case VisibilityUnobscured: mw->w_flags &= ~WIND_OBSCURED; if (mw->w_backingStore == (ClientData)NULL) { - (*GrCreateBackingStorePtr)(mw); - if (mw->w_backingStore != (ClientData)NULL) - { - WindAreaChanged(mw, &mw->w_allArea); - WindUpdate(); - } + (*GrCreateBackingStorePtr)(mw); + if (mw->w_backingStore != (ClientData)NULL) + { + WindAreaChanged(mw, &mw->w_allArea); + WindUpdate(); + } } break; - case VisibilityPartiallyObscured: - case VisibilityFullyObscured: + case VisibilityPartiallyObscured: + case VisibilityFullyObscured: mw->w_flags |= WIND_OBSCURED; break; } - } - break; + } + break; case Expose: - { + { XExposeEvent *ExposeEvent = (XExposeEvent*) xevent; Rect screenRect; entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry)?(MagWindow *)HashGetValue(entry):0; + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; screenRect.r_xbot = ExposeEvent->x; - screenRect.r_xtop = ExposeEvent->x+ExposeEvent->width; - screenRect.r_ytop = mw->w_allArea.r_ytop-ExposeEvent->y; - screenRect.r_ybot = mw->w_allArea.r_ytop - - (ExposeEvent->y + ExposeEvent->height); + screenRect.r_xtop = ExposeEvent->x + ExposeEvent->width; + screenRect.r_ytop = mw->w_allArea.r_ytop - ExposeEvent->y; + screenRect.r_ybot = mw->w_allArea.r_ytop - + (ExposeEvent->y + ExposeEvent->height); if (mw->w_backingStore != (ClientData)NULL) { - Rect surface; - (*GrGetBackingStorePtr)(mw, &screenRect); - WindScreenToSurface(mw, &screenRect, &surface); - DBWHLRedrawPrepWindow(mw, &surface); - WindDrawBorder(mw, &screenRect); + Rect surface; + (*GrGetBackingStorePtr)(mw, &screenRect); + WindScreenToSurface(mw, &screenRect, &surface); + DBWHLRedrawPrepWindow(mw, &surface); + WindDrawBorder(mw, &screenRect); } else - WindAreaChanged(mw, &screenRect); + WindAreaChanged(mw, &screenRect); WindUpdate(); - } - break; + } + break; case MapNotify: case UnmapNotify: case DestroyNotify: /* Do nothing */ - break; + break; default: - TxError("Tk Event: Unknown (%d)\n", xevent->type); - TxFlush(); - break; - } + TxError("Tk Event: Unknown (%d)\n", xevent->type); + TxFlush(); + break; + } } @@ -919,100 +921,100 @@ keys_and_buttons: bool oglSetDisplay (dispType, outFileName, mouseFileName) - char *dispType; - char *outFileName; - char *mouseFileName; +char *dispType; +char *outFileName; +char *mouseFileName; { - char *planecount; - char *fullname; - FILE* f; - bool execFailed = FALSE; - int x, y, width, height; + char *planecount; + char *fullname; + FILE* f; + bool execFailed = FALSE; + int x, y, width, height; - WindPackageType = WIND_X_WINDOWS; /* to be changed? */ - TxInputRedirect = TX_INPUT_NORMAL; + WindPackageType = WIND_X_WINDOWS; /* to be changed? */ + TxInputRedirect = TX_INPUT_NORMAL; - grCursorType = "color"; - WindScrollBarWidth = 14; + grCursorType = "color"; + WindScrollBarWidth = 14; - /* Set up the procedure values in the indirection table. */ + /* Set up the procedure values in the indirection table. */ - GrPixelCorrect = 0; + GrPixelCorrect = 0; - GrLockPtr = GrTOGLLock; - GrUnlockPtr = GrTOGLUnlock; - GrInitPtr = GrTOGLInit; - GrClosePtr = GrTOGLClose; - GrSetCMapPtr = GrTOGLSetCMap; + GrLockPtr = GrTOGLLock; + GrUnlockPtr = GrTOGLUnlock; + GrInitPtr = GrTOGLInit; + GrClosePtr = GrTOGLClose; + GrSetCMapPtr = GrTOGLSetCMap; - GrEnableTabletPtr = GrTOGLEnableTablet; - GrDisableTabletPtr = GrTOGLDisableTablet; - GrSetCursorPtr = GrTOGLSetCursor; - GrTextSizePtr = GrTOGLTextSize; - GrDrawGlyphPtr = GrTOGLDrawGlyph; - GrReadPixelPtr = GrTOGLReadPixel; - GrFlushPtr = GrTOGLFlush; + GrEnableTabletPtr = GrTOGLEnableTablet; + GrDisableTabletPtr = GrTOGLDisableTablet; + GrSetCursorPtr = GrTOGLSetCursor; + GrTextSizePtr = GrTOGLTextSize; + GrDrawGlyphPtr = GrTOGLDrawGlyph; + GrReadPixelPtr = GrTOGLReadPixel; + GrFlushPtr = GrTOGLFlush; - GrCreateWindowPtr = GrTOGLCreate; - GrDeleteWindowPtr = GrTOGLDelete; - GrConfigureWindowPtr = GrTOGLConfigure; - GrOverWindowPtr = GrTOGLRaise; - GrUnderWindowPtr = GrTOGLLower; - GrUpdateIconPtr = GrTOGLIconUpdate; - GrEventPendingPtr = GrTOGLEventPending; - GrWindowIdPtr = GrTOGLWindowId; - GrWindowNamePtr = GrTkWindowName; /* from grTkCommon.c */ - GrGetCursorPosPtr = grtoglGetCursorPos; - GrGetCursorRootPosPtr = grtoglGetCursorRootPos; + GrCreateWindowPtr = GrTOGLCreate; + GrDeleteWindowPtr = GrTOGLDelete; + GrConfigureWindowPtr = GrTOGLConfigure; + GrOverWindowPtr = GrTOGLRaise; + GrUnderWindowPtr = GrTOGLLower; + GrUpdateIconPtr = GrTOGLIconUpdate; + GrEventPendingPtr = GrTOGLEventPending; + GrWindowIdPtr = GrTOGLWindowId; + GrWindowNamePtr = GrTkWindowName; /* from grTkCommon.c */ + GrGetCursorPosPtr = grtoglGetCursorPos; + GrGetCursorRootPosPtr = grtoglGetCursorRootPos; - /* local indirections */ - grSetSPatternPtr = grtoglSetSPattern; - grPutTextPtr = grtoglPutText; + /* local indirections */ + grSetSPatternPtr = grtoglSetSPattern; + grPutTextPtr = grtoglPutText; #ifdef VECTOR_FONTS - grFontTextPtr = grtoglFontText; + grFontTextPtr = grtoglFontText; #endif - grDefineCursorPtr = grTkDefineCursor; - grFreeCursorPtr = grTkFreeCursors; - GrBitBltPtr = GrTOGLBitBlt; - grDrawGridPtr = grtoglDrawGrid; - grDrawLinePtr = grtoglDrawLine; - grSetWMandCPtr = grtoglSetWMandC; - grFillRectPtr = grtoglFillRect; - grSetStipplePtr = grtoglSetStipple; - grSetLineStylePtr = grtoglSetLineStyle; - grSetCharSizePtr = grtoglSetCharSize; - grFillPolygonPtr = grtoglFillPolygon; + grDefineCursorPtr = grTkDefineCursor; + grFreeCursorPtr = grTkFreeCursors; + GrBitBltPtr = GrTOGLBitBlt; + grDrawGridPtr = grtoglDrawGrid; + grDrawLinePtr = grtoglDrawLine; + grSetWMandCPtr = grtoglSetWMandC; + grFillRectPtr = grtoglFillRect; + grSetStipplePtr = grtoglSetStipple; + grSetLineStylePtr = grtoglSetLineStyle; + grSetCharSizePtr = grtoglSetCharSize; + grFillPolygonPtr = grtoglFillPolygon; #ifdef X11_BACKING_STORE - GrFreeBackingStorePtr = grtkFreeBackingStore; - GrCreateBackingStorePtr = grtkCreateBackingStore; - GrGetBackingStorePtr = grtkGetBackingStore; - GrPutBackingStorePtr = grtkPutBackingStore; - GrScrollBackingStorePtr = grtkScrollBackingStore; + GrFreeBackingStorePtr = grtkFreeBackingStore; + GrCreateBackingStorePtr = grtkCreateBackingStore; + GrGetBackingStorePtr = grtkGetBackingStore; + GrPutBackingStorePtr = grtkPutBackingStore; + GrScrollBackingStorePtr = grtkScrollBackingStore; #else - GrFreeBackingStorePtr = grtoglFreeBackingStore; - GrCreateBackingStorePtr = grtoglCreateBackingStore; - GrGetBackingStorePtr = grtoglGetBackingStore; - GrPutBackingStorePtr = grtoglPutBackingStore; - GrScrollBackingStorePtr = grtoglScrollBackingStore; + GrFreeBackingStorePtr = grtoglFreeBackingStore; + GrCreateBackingStorePtr = grtoglCreateBackingStore; + GrGetBackingStorePtr = grtoglGetBackingStore; + GrPutBackingStorePtr = grtoglPutBackingStore; + GrScrollBackingStorePtr = grtoglScrollBackingStore; #endif - - if (execFailed) { - TxError("Execution failed!\n"); - return FALSE; - } - if(!GrTOGLInit()){ - return FALSE; - }; + if (execFailed) { + TxError("Execution failed!\n"); + return FALSE; + } - Tk_GetVRootGeometry(Tk_MainWindow(magicinterp), &x, &y, &width, &height); - GrScreenRect.r_xbot = x; - GrScreenRect.r_ybot = y; - GrScreenRect.r_xtop = width + x; - GrScreenRect.r_ytop = height + y; + if (!GrTOGLInit()) { + return FALSE; + }; - return Tk_MainWindow(magicinterp) ? TRUE : FALSE; + Tk_GetVRootGeometry(Tk_MainWindow(magicinterp), &x, &y, &width, &height); + GrScreenRect.r_xbot = x; + GrScreenRect.r_ybot = y; + GrScreenRect.r_xtop = width + x; + GrScreenRect.r_ytop = height + y; + + return Tk_MainWindow(magicinterp) ? TRUE : FALSE; } extern void MakeWindowCommand(); @@ -1035,136 +1037,136 @@ extern void MakeWindowCommand(); bool GrTOGLCreate(w, name) - MagWindow *w; - char *name; +MagWindow *w; +char *name; { - Tk_Window tkwind, tktop; - Window wind; - static int WindowNumber = 0; - HashEntry *entry; - char *windowplace; - char windowname[10]; - int x = w->w_frameArea.r_xbot; - int y = glTransYs(w->w_frameArea.r_ytop); - int width = w->w_frameArea.r_xtop - w->w_frameArea.r_xbot; - int height = w->w_frameArea.r_ytop - w->w_frameArea.r_ybot; - unsigned long attribmask = CWBackPixel | CWBorderPixel | CWColormap; - XSetWindowAttributes grAttributes; + Tk_Window tkwind, tktop; + Window wind; + static int WindowNumber = 0; + HashEntry *entry; + char *windowplace; + char windowname[10]; + int x = w->w_frameArea.r_xbot; + int y = glTransYs(w->w_frameArea.r_ytop); + int width = w->w_frameArea.r_xtop - w->w_frameArea.r_xbot; + int height = w->w_frameArea.r_ytop - w->w_frameArea.r_ybot; + unsigned long attribmask = CWBackPixel | CWBorderPixel | CWColormap; + XSetWindowAttributes grAttributes; - WindSeparateRedisplay(w); + WindSeparateRedisplay(w); - sprintf(windowname, ".magic%d", WindowNumber + 1); - if (windowplace = XGetDefault(grXdpy, "magic", windowname)) - { - XParseGeometry(windowplace,&x,&y, - (unsigned int *)&width,(unsigned int *)&height); - w->w_frameArea.r_xbot = x; - w->w_frameArea.r_xtop = x+width; - w->w_frameArea.r_ytop = glTransYs(y); - w->w_frameArea.r_ybot = glTransYs(y+height); - WindReframe(w,&(w->w_frameArea),FALSE,FALSE); - } - - grAttributes.colormap = XCreateColormap(grXdpy, RootWindow(grXdpy, grXscrn), - grVisualInfo->visual, AllocNone); - grAttributes.background_pixel = WhitePixel(grXdpy,grXscrn); - grAttributes.border_pixel = BlackPixel(grXdpy,grXscrn); - - if (tktop = Tk_MainWindow(magicinterp)) - { - if (!WindowNumber) + sprintf(windowname, ".magic%d", WindowNumber + 1); + if (windowplace = XGetDefault(grXdpy, "magic", windowname)) { - /* To do: deal with grVisualInfo---destroy and recreate top */ - /* frame if necessary */ - - if (Tk_WindowId(tktop) == 0) - { - Tk_SetWindowVisual(tktop, grVisualInfo->visual, - toglCurrent.depth, grAttributes.colormap); - } - else - { - /* The Top-level window has already been mapped. We can't mess */ - /* with it's visual. If the title is "wish", we'll assume that */ - /* nobody else is claiming it, and unmap it. */ - - if (!strcmp(Tk_Name(tktop), "wish")) Tk_UnmapWindow(tktop); - } + XParseGeometry(windowplace, &x, &y, + (unsigned int *)&width, (unsigned int *)&height); + w->w_frameArea.r_xbot = x; + w->w_frameArea.r_xtop = x + width; + w->w_frameArea.r_ytop = glTransYs(y); + w->w_frameArea.r_ybot = glTransYs(y + height); + WindReframe(w, &(w->w_frameArea), FALSE, FALSE); } - } - else - return 0; /* failure */ - /* Last parameter "" indicates a top-level window in the space of */ - /* the parent. */ + grAttributes.colormap = XCreateColormap(grXdpy, RootWindow(grXdpy, grXscrn), + grVisualInfo->visual, AllocNone); + grAttributes.background_pixel = WhitePixel(grXdpy, grXscrn); + grAttributes.border_pixel = BlackPixel(grXdpy, grXscrn); - if (name == NULL) - tkwind = Tk_CreateWindowFromPath(magicinterp, tktop, windowname, ""); - else - tkwind = Tk_CreateWindowFromPath(magicinterp, tktop, name, NULL); + if (tktop = Tk_MainWindow(magicinterp)) + { + if (!WindowNumber) + { + /* To do: deal with grVisualInfo---destroy and recreate top */ + /* frame if necessary */ - /* TxError("Creating window named \"%s\", tkwind = 0x%x\n", + if (Tk_WindowId(tktop) == 0) + { + Tk_SetWindowVisual(tktop, grVisualInfo->visual, + toglCurrent.depth, grAttributes.colormap); + } + else + { + /* The Top-level window has already been mapped. We can't mess */ + /* with it's visual. If the title is "wish", we'll assume that */ + /* nobody else is claiming it, and unmap it. */ + + if (!strcmp(Tk_Name(tktop), "wish")) Tk_UnmapWindow(tktop); + } + } + } + else + return 0; /* failure */ + + /* Last parameter "" indicates a top-level window in the space of */ + /* the parent. */ + + if (name == NULL) + tkwind = Tk_CreateWindowFromPath(magicinterp, tktop, windowname, ""); + else + tkwind = Tk_CreateWindowFromPath(magicinterp, tktop, name, NULL); + + /* TxError("Creating window named \"%s\", tkwind = 0x%x\n", windowname, tkwind); TxFlush(); */ - if (tkwind != 0) - { - bool result; + if (tkwind != 0) + { + bool result; - GrTOGLFlush(); + GrTOGLFlush(); - toglCurrent.window = tkwind; - toglCurrent.mw = w; + toglCurrent.window = tkwind; + toglCurrent.mw = w; - w->w_grdata = (ClientData) tkwind; - - entry = HashFind(&grTOGLWindowTable, (char *)tkwind); - HashSetValue(entry,w); + w->w_grdata = (ClientData) tkwind; - /* ensure that the visual is what we wanted, if possible to change */ + entry = HashFind(&grTOGLWindowTable, (char *)tkwind); + HashSetValue(entry, w); - Tk_SetWindowVisual(tkwind, grVisualInfo->visual, toglCurrent.depth, - grAttributes.colormap); + /* ensure that the visual is what we wanted, if possible to change */ - /* map the window, if necessary */ + Tk_SetWindowVisual(tkwind, grVisualInfo->visual, toglCurrent.depth, + grAttributes.colormap); - Tk_MapWindow(tkwind); + /* map the window, if necessary */ - /* use x, y, width, height to size and position the window */ + Tk_MapWindow(tkwind); - Tk_GeometryRequest(tkwind, width, height); - /* Tk_MoveResizeWindow(tkwind, x, y, width, height); */ + /* use x, y, width, height to size and position the window */ - wind = Tk_WindowId(tkwind); - toglCurrent.windowid = wind; - glXMakeCurrent(grXdpy, (GLXDrawable)wind, grXcontext); + Tk_GeometryRequest(tkwind, width, height); + /* Tk_MoveResizeWindow(tkwind, x, y, width, height); */ - Tk_DefineCursor(tkwind, toglCurrent.cursor); - GrTOGLIconUpdate(w, w->w_caption); + wind = Tk_WindowId(tkwind); + toglCurrent.windowid = wind; + glXMakeCurrent(grXdpy, (GLXDrawable)wind, grXcontext); - WindowNumber++; + Tk_DefineCursor(tkwind, toglCurrent.cursor); + GrTOGLIconUpdate(w, w->w_caption); - /* execute all Tk events up to current */ + WindowNumber++; - while (Tcl_DoOneEvent(TCL_DONT_WAIT) != 0); + /* execute all Tk events up to current */ - /* set up Tk event handler to start processing */ + while (Tcl_DoOneEvent(TCL_DONT_WAIT) != 0); - Tk_CreateEventHandler(tkwind, ExposureMask | StructureNotifyMask - | ButtonPressMask | KeyPressMask | VisibilityChangeMask, - (Tk_EventProc *)TOGLEventProc, (ClientData) tkwind); + /* set up Tk event handler to start processing */ - /* set up commands to be passed expressly to this window */ + Tk_CreateEventHandler(tkwind, ExposureMask | StructureNotifyMask + | ButtonPressMask | KeyPressMask | VisibilityChangeMask, + (Tk_EventProc *)TOGLEventProc, (ClientData) tkwind); - MakeWindowCommand((name == NULL) ? windowname : name, w); + /* set up commands to be passed expressly to this window */ - return (WindowNumber == 1) ? grtoglLoadFont() : 1; - } - else - { - TxError("Could not open new Tk window\n"); - } + MakeWindowCommand((name == NULL) ? windowname : name, w); - return 0; + return (WindowNumber == 1) ? grtoglLoadFont() : 1; + } + else + { + TxError("Could not open new Tk window\n"); + } + + return 0; } /* @@ -1184,17 +1186,17 @@ GrTOGLCreate(w, name) void GrTOGLDelete(w) - MagWindow *w; +MagWindow *w; { - Tk_Window xw; - HashEntry *entry; + Tk_Window xw; + HashEntry *entry; - xw = (Tk_Window) w->w_grdata; - entry = HashLookOnly(&grTOGLWindowTable, (char *)xw); - HashSetValue(entry,NULL); + xw = (Tk_Window) w->w_grdata; + entry = HashLookOnly(&grTOGLWindowTable, (char *)xw); + HashSetValue(entry, NULL); - Tcl_DeleteCommand(magicinterp, Tk_PathName(xw)); - Tk_DestroyWindow(xw); + Tcl_DeleteCommand(magicinterp, Tk_PathName(xw)); + Tk_DestroyWindow(xw); } /* @@ -1214,14 +1216,14 @@ GrTOGLDelete(w) void GrTOGLConfigure(w) - MagWindow *w; +MagWindow *w; { - if (w->w_flags & WIND_OFFSCREEN) return; + if (w->w_flags & WIND_OFFSCREEN) return; - Tk_MoveResizeWindow((Tk_Window)w->w_grdata, - w->w_frameArea.r_xbot, glTransYs(w->w_frameArea.r_ytop), - w->w_frameArea.r_xtop - w->w_frameArea.r_xbot, - w->w_frameArea.r_ytop - w->w_frameArea.r_ybot); + Tk_MoveResizeWindow((Tk_Window)w->w_grdata, + w->w_frameArea.r_xbot, glTransYs(w->w_frameArea.r_ytop), + w->w_frameArea.r_xtop - w->w_frameArea.r_xbot, + w->w_frameArea.r_ytop - w->w_frameArea.r_ybot); } /* @@ -1242,14 +1244,14 @@ GrTOGLConfigure(w) void GrTOGLRaise(w) - MagWindow *w; +MagWindow *w; { - Tk_Window tkwind; + Tk_Window tkwind; - if (w->w_flags & WIND_OFFSCREEN) return; + if (w->w_flags & WIND_OFFSCREEN) return; - tkwind = (Tk_Window)w->w_grdata; - Tk_RestackWindow(tkwind, Above, NULL); + tkwind = (Tk_Window)w->w_grdata; + Tk_RestackWindow(tkwind, Above, NULL); } /* @@ -1270,14 +1272,14 @@ GrTOGLRaise(w) void GrTOGLLower(w) - MagWindow *w; +MagWindow *w; { - Tk_Window tkwind; + Tk_Window tkwind; - if (w->w_flags & WIND_OFFSCREEN) return; + if (w->w_flags & WIND_OFFSCREEN) return; - tkwind = (Tk_Window)w->w_grdata; - Tk_RestackWindow(tkwind, Below, NULL); + tkwind = (Tk_Window)w->w_grdata; + Tk_RestackWindow(tkwind, Below, NULL); } @@ -1299,31 +1301,31 @@ GrTOGLLower(w) void GrTOGLLock(w, flag) - MagWindow *w; - bool flag; +MagWindow *w; +bool flag; { - Window wind; + Window wind; - grSimpleLock(w, flag); - if ( w != GR_LOCK_SCREEN ) - { - toglCurrent.mw = w; - - if (w->w_flags & WIND_OFFSCREEN) + grSimpleLock(w, flag); + if ( w != GR_LOCK_SCREEN ) { - toglCurrent.window = (Tk_Window) NULL; - toglCurrent.windowid = (Pixmap) w->w_grdata; - } - else - { - toglCurrent.window = (Tk_Window) w->w_grdata; - toglCurrent.windowid = Tk_WindowId(toglCurrent.window); - } + toglCurrent.mw = w; - toglSetProjection(w->w_allArea.r_xbot, w->w_allArea.r_ybot, - w->w_allArea.r_xtop - w->w_allArea.r_xbot, - w->w_allArea.r_ytop - w->w_allArea.r_ybot); - } + if (w->w_flags & WIND_OFFSCREEN) + { + toglCurrent.window = (Tk_Window) NULL; + toglCurrent.windowid = (Pixmap) w->w_grdata; + } + else + { + toglCurrent.window = (Tk_Window) w->w_grdata; + toglCurrent.windowid = Tk_WindowId(toglCurrent.window); + } + + toglSetProjection(w->w_allArea.r_xbot, w->w_allArea.r_ybot, + w->w_allArea.r_xtop - w->w_allArea.r_xbot, + w->w_allArea.r_ytop - w->w_allArea.r_ybot); + } } /* @@ -1344,15 +1346,15 @@ GrTOGLLock(w, flag) void GrTOGLUnlock(w) - MagWindow *w; +MagWindow *w; { - /* GR_TOGL_FLUSH_BATCH(); */ - GrTOGLFlush(); /* (?) Adds glFlush and glFinish to the above. */ - grSimpleUnlock(w); + /* GR_TOGL_FLUSH_BATCH(); */ + GrTOGLFlush(); /* (?) Adds glFlush and glFinish to the above. */ + grSimpleUnlock(w); } -/* +/* *------------------------------------------------------------------------- * GrTOGLEventPending -- * check for pending graphics events. @@ -1367,22 +1369,22 @@ GrTOGLUnlock(w) * None, hopefully (put back the event!) * *------------------------------------------------------------------------- - */ - + */ + bool GrTOGLEventPending() -{ - Window wind = toglCurrent.windowid; - XEvent genEvent; - bool retval; +{ + Window wind = toglCurrent.windowid; + XEvent genEvent; + bool retval; - XSync(grXdpy, FALSE); /* Necessary, or it won't catch mouse/key events */ - retval = XCheckWindowEvent(grXdpy, wind, ExposureMask - | StructureNotifyMask | ButtonPressMask - | KeyPressMask, &genEvent); - if (retval) XPutBackEvent(grXdpy, &genEvent); - return retval; -} + XSync(grXdpy, FALSE); /* Necessary, or it won't catch mouse/key events */ + retval = XCheckWindowEvent(grXdpy, wind, ExposureMask + | StructureNotifyMask | ButtonPressMask + | KeyPressMask, &genEvent); + if (retval) XPutBackEvent(grXdpy, &genEvent); + return retval; +} /* *------------------------------------------------------------------------- @@ -1397,44 +1399,44 @@ GrTOGLEventPending() */ void -GrTOGLIconUpdate(w,text) /* See Blt code */ - MagWindow *w; - char *text; +GrTOGLIconUpdate(w, text) /* See Blt code */ +MagWindow *w; +char *text; { - Tk_Window tkwind; - Window wind; - XClassHint class; - char *brack; + Tk_Window tkwind; + Window wind; + XClassHint class; + char *brack; - if (w->w_flags & WIND_OFFSCREEN) return; - - tkwind = (Tk_Window)(w->w_grdata); - if (tkwind == NULL) { - tkwind = Tk_MainWindow(magicinterp); - if (tkwind == NULL) return; - } - wind = Tk_WindowId(tkwind); - if (wind == 0) return; + if (w->w_flags & WIND_OFFSCREEN) return; - class.res_name = "magic"; - class.res_class = "magic"; - - XSetClassHint( grXdpy, wind, &class); - if (text) - { - if (brack = strchr(text,'[')) - { - brack--; - *brack = 0; - XSetIconName(grXdpy,wind,text); - XStoreName(grXdpy,wind,text); - *brack = ' '; - return; + tkwind = (Tk_Window)(w->w_grdata); + if (tkwind == NULL) { + tkwind = Tk_MainWindow(magicinterp); + if (tkwind == NULL) return; + } + wind = Tk_WindowId(tkwind); + if (wind == 0) return; + + class.res_name = "magic"; + class.res_class = "magic"; + + XSetClassHint( grXdpy, wind, &class); + if (text) + { + if (brack = strchr(text, '[')) + { + brack--; + *brack = 0; + XSetIconName(grXdpy, wind, text); + XStoreName(grXdpy, wind, text); + *brack = ' '; + return; + } + if (brack = strrchr(text, ' ')) text = brack + 1; + XSetIconName(grXdpy, wind, text); + XStoreName(grXdpy, wind, text); } - if (brack = strrchr(text,' ')) text = brack+1; - XSetIconName(grXdpy,wind,text); - XStoreName(grXdpy,wind,text); - } } /* @@ -1452,20 +1454,20 @@ GrTOGLIconUpdate(w,text) /* See Blt code */ */ int -GrTOGLWindowId(tkname) - char *tkname; +GrTOGLWindowId(tkname) +char *tkname; { - Tk_Window tkwind; - MagWindow *mw; - HashEntry *entry; - int id = 0; - - tkwind = Tk_NameToWindow(magicinterp, tkname, Tk_MainWindow(magicinterp)); - if (tkwind != NULL) - { - entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); - mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; - if (mw) id = mw->w_wid; - } - return id; -} + Tk_Window tkwind; + MagWindow *mw; + HashEntry *entry; + int id = 0; + + tkwind = Tk_NameToWindow(magicinterp, tkname, Tk_MainWindow(magicinterp)); + if (tkwind != NULL) + { + entry = HashLookOnly(&grTOGLWindowTable, (char *)tkwind); + mw = (entry) ? (MagWindow *)HashGetValue(entry) : 0; + if (mw) id = mw->w_wid; + } + return id; +}