int XSetSelectionOwner( Display *display, Atom selection, Window owner, Time time) { HWND hwnd = owner ? TkWinGetHWND(owner) : NULL; Tk_Window tkwin; /* * This is a gross hack because the Tk_InternAtom interface is broken. It * expects a Tk_Window, even though it only needs a Tk_Display. */ tkwin = (Tk_Window) TkGetMainInfoList()->winPtr; if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) { /* * Only claim and empty the clipboard if we aren't already the owner * of the clipboard. */ if (GetClipboardOwner() != hwnd) { UpdateClipboard(hwnd); } } return Success; }
void TkSelUpdateClipboard( TkWindow *winPtr, TkClipboardTarget *targetPtr) { HWND hwnd = TkWinGetHWND(winPtr->window); UpdateClipboard(hwnd); }
void TkWinReleaseDrawableDC( Drawable d, HDC dc, TkWinDCState *state) { TkWinDrawable *twdPtr = (TkWinDrawable *)d; SetBkMode(dc, state->bkmode); SelectPalette(dc, state->palette, TRUE); RealizePalette(dc); if (twdPtr->type == TWD_WINDOW) { ReleaseDC(TkWinGetHWND(d), dc); } else if (twdPtr->type == TWD_BITMAP) { DeleteDC(dc); } }
int TkScrollWindow( Tk_Window tkwin, /* The window to be scrolled. */ GC gc, /* GC for window to be scrolled. */ int x, int y, int width, int height, /* Position rectangle to be scrolled. */ int dx, int dy, /* Distance rectangle should be moved. */ TkRegion damageRgn) /* Region to accumulate damage in. */ { HWND hwnd = TkWinGetHWND(Tk_WindowId(tkwin)); RECT scrollRect; scrollRect.left = x; scrollRect.top = y; scrollRect.right = x + width; scrollRect.bottom = y + height; return (ScrollWindowEx(hwnd, dx, dy, &scrollRect, NULL, (HRGN) damageRgn, NULL, 0) == NULLREGION) ? 0 : 1; }
HGLRC OpenGLGetContext(Tcl_Interp* interp,char* name) #endif { Tcl_CmdInfo info; OpenGLClientData* OpenGLPtr; #ifdef _WIN32 HWND hWnd; #endif if(!Tcl_GetCommandInfo(interp, name, &info)) return 0; OpenGLPtr=(OpenGLClientData*)info.clientData; if (OpenGLPtr->tkwin != Tk_NameToWindow(interp, name, Tk_MainWindow(interp))) return 0; if (OpenGLPtr->display != Tk_Display(OpenGLPtr->tkwin)) return 0; if (OpenGLPtr->display) XSync(OpenGLPtr->display, False); if (!OpenGLPtr->x11_win) { Tk_MakeWindowExist(OpenGLPtr->tkwin); XSync(OpenGLPtr->display, False); OpenGLPtr->x11_win = Tk_WindowId(OpenGLPtr->tkwin); } if (!OpenGLPtr->x11_win) return 0; #ifndef _WIN32 OpenGLPtr->glx_win = OpenGLPtr->x11_win; if (!OpenGLPtr->cx) { OpenGLPtr->cx = glXCreateContext(OpenGLPtr->display, OpenGLPtr->vi, first_context, OpenGLPtr->direct); if (!first_context) { first_context = OpenGLPtr->cx; } } if (!OpenGLPtr->cx) { Tcl_AppendResult(interp, "Error making GL context", (char*)NULL); return 0; } if (!OpenGLPtr->glx_win) return 0; #else hWnd = TkWinGetHWND(Tk_WindowId(OpenGLPtr->tkwin)); OpenGLPtr->hDC = GetDC(hWnd); if (!OpenGLPtr->cx) { OpenGLPtr->cx = wglCreateContext(OpenGLPtr->hDC); wglShareLists(first_context,OpenGLPtr->cx); if (!first_context) first_context = OpenGLPtr->cx; } if (!OpenGLPtr->cx) { Tcl_AppendResult(interp, "Error making GL context", (char*)NULL); printf("wglCreateContext() returned NULL; Error code: %d\n", (int)GetLastError()); return 0; } #endif return OpenGLPtr->cx; }
SCISHARE int OpenGLCmd(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char **argv) { Tk_Window mainwin = (Tk_Window) clientData; OpenGLClientData *OpenGLPtr; Colormap cmap; Tk_Window tkwin; XVisualInfo temp_vi; int tempid; int n; #ifndef _WIN32 int attributes[50]; int idx = 0; #endif if (argc < 2) { Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " pathName ?options?\"", (char *) NULL); return TCL_ERROR; } tkwin = Tk_CreateWindowFromPath(interp, mainwin, argv[1], (char *) NULL); if (tkwin == NULL) { return TCL_ERROR; } Tk_SetClass(tkwin, "OpenGL"); /* Allocate and initialize the widget record. */ OpenGLPtr = (OpenGLClientData *) ckalloc(sizeof(OpenGLClientData)); OpenGLPtr->geometry = 0; OpenGLPtr->cursor = 0; OpenGLPtr->interp = interp; OpenGLPtr->tkwin = tkwin; OpenGLPtr->display = Tk_Display(tkwin); OpenGLPtr->x11_win=0; OpenGLPtr->screen_number = Tk_ScreenNumber(tkwin); #ifndef _WIN32 OpenGLPtr->glx_win=0; OpenGLPtr->fb_configs=glXGetFBConfigs(OpenGLPtr->display, OpenGLPtr->screen_number, &(OpenGLPtr->num_fb)); #else OpenGLPtr->hDC = 0; #endif OpenGLPtr->vi=0; OpenGLPtr->cx=0; Tk_CreateEventHandler(OpenGLPtr->tkwin, StructureNotifyMask, OpenGLEventProc, (ClientData) OpenGLPtr); Tcl_CreateCommand(interp, Tk_PathName(OpenGLPtr->tkwin), OpenGLWidgetCmd, (ClientData) OpenGLPtr, (Tcl_CmdDeleteProc *)0); if (OpenGLConfigure(interp, OpenGLPtr, argc-2, argv+2, 0) != TCL_OK) { return TCL_ERROR; } tempid = OpenGLPtr->visualid; if (OpenGLPtr->visualid) { temp_vi.visualid = OpenGLPtr->visualid; OpenGLPtr->vi = XGetVisualInfo(OpenGLPtr->display, VisualIDMask, &temp_vi, &n); if(!OpenGLPtr->vi || n!=1) { Tcl_AppendResult(interp, "Error finding visual", NULL); return TCL_ERROR; } } else { /* * Pick the right visual... */ #ifndef _WIN32 attributes[idx++]=GLX_BUFFER_SIZE; attributes[idx++]=OpenGLPtr->buffersize; attributes[idx++]=GLX_LEVEL; attributes[idx++]=OpenGLPtr->level; if(OpenGLPtr->rgba) attributes[idx++]=GLX_RGBA; if(OpenGLPtr->doublebuffer) attributes[idx++]=GLX_DOUBLEBUFFER; if(OpenGLPtr->stereo) attributes[idx++]=GLX_STEREO; attributes[idx++]=GLX_AUX_BUFFERS; attributes[idx++]=OpenGLPtr->auxbuffers; attributes[idx++]=GLX_RED_SIZE; attributes[idx++]=OpenGLPtr->redsize; attributes[idx++]=GLX_GREEN_SIZE; attributes[idx++]=OpenGLPtr->greensize; attributes[idx++]=GLX_BLUE_SIZE; attributes[idx++]=OpenGLPtr->bluesize; attributes[idx++]=GLX_ALPHA_SIZE; attributes[idx++]=OpenGLPtr->alphasize; attributes[idx++]=GLX_DEPTH_SIZE; attributes[idx++]=OpenGLPtr->depthsize; attributes[idx++]=GLX_STENCIL_SIZE; attributes[idx++]=OpenGLPtr->stencilsize; attributes[idx++]=GLX_ACCUM_RED_SIZE; attributes[idx++]=OpenGLPtr->accumredsize; attributes[idx++]=GLX_ACCUM_GREEN_SIZE; attributes[idx++]=OpenGLPtr->accumgreensize; attributes[idx++]=GLX_ACCUM_BLUE_SIZE; attributes[idx++]=OpenGLPtr->accumbluesize; attributes[idx++]=GLX_ACCUM_ALPHA_SIZE; attributes[idx++]=OpenGLPtr->accumalphasize; attributes[idx++]=None; OpenGLPtr->vi = glXChooseVisual(OpenGLPtr->display, OpenGLPtr->screen_number, attributes); OpenGLPtr->visualid=tempid; #else // WIN32 // I am using the *PixelFormat commands from win32 because according // to the Windows page, we should prefer this to wgl*PixelFormatARB. // Unfortunately, this means that the Windows code will differ // substantially from that of other platforms. However, it has the // advantage that we don't have to use the wglGetProc to get // the procedure address, or test to see if the applicable extension // is supported. WM:VI HWND hWnd = TkWinGetHWND(Tk_WindowId(OpenGLPtr->tkwin)); // a little ugly, but we need this to be defined before pfd, and // we need to follow C initialization rules DWORD dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | (OpenGLPtr->doublebuffer ? PFD_DOUBLEBUFFER : 0) | (OpenGLPtr->stereo ? PFD_STEREO : 0); int iPixelFormat; XVisualInfo xvi; int n_ret; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number dwFlags, PFD_TYPE_RGBA, // RGBA type OpenGLPtr->buffersize, // color depth OpenGLPtr->redsize, 0, OpenGLPtr->greensize, 0, OpenGLPtr->bluesize, 0, // color bits OpenGLPtr->alphasize,0, // alpha buffer OpenGLPtr->accumredsize+ OpenGLPtr->accumgreensize+ OpenGLPtr->accumbluesize,// accumulation buffer OpenGLPtr->accumredsize, OpenGLPtr->accumgreensize, OpenGLPtr->accumbluesize, OpenGLPtr->accumalphasize,// accum bits OpenGLPtr->depthsize, // 32-bit z-buffer OpenGLPtr->stencilsize,// no stencil buffer OpenGLPtr->auxbuffers, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; iPixelFormat = ChoosePixelFormat(OpenGLPtr->hDC, &pfd); SetPixelFormat(OpenGLPtr->hDC, iPixelFormat, &pfd); OpenGLPtr->visualid = iPixelFormat; OpenGLPtr->hDC = GetDC(hWnd); xvi.screen = OpenGLPtr->screen_number; n_ret=0; OpenGLPtr->vi = XGetVisualInfo(OpenGLPtr->display, VisualScreenMask, &xvi, &n_ret); #endif if (!OpenGLPtr->vi) { Tcl_AppendResult(interp, "Error selecting visual", (char*)NULL); return TCL_ERROR; } } cmap = XCreateColormap(OpenGLPtr->display, Tk_WindowId(Tk_MainWindow(OpenGLPtr->interp)), OpenGLPtr->vi->visual, AllocNone); if(Tk_SetWindowVisual(OpenGLPtr->tkwin, OpenGLPtr->vi->visual, OpenGLPtr->vi->depth, cmap) != 1) { Tcl_AppendResult(interp, "Error setting visual for window", (char*)NULL); return TCL_ERROR; } XSync(OpenGLPtr->display, False); Tcl_SetResult(interp,Tk_PathName(OpenGLPtr->tkwin),TCL_STATIC); return TCL_OK; }