4 * This file contains most of the X calls called by Tk. Many of
5 * these calls are just stubs and either don't make sense on the
6 * Macintosh or thier implamentation just doesn't do anything. Other
7 * calls will eventually be moved into other files.
9 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
27 #include <QDOffscreen.h>
28 #include <ToolUtils.h>
33 * Because this file is still under major development Debugger statements are
34 * used through out this file. The define TCL_DEBUG will decide whether
35 * the debugger statements actually call the debugger or not.
45 * Declarations of static variables used in this file.
48 static TkDisplay *gMacDisplay = NULL; /* Macintosh display. */
49 static char *macScreenName = ":0";
50 /* Default name of macintosh display. */
53 * Forward declarations of procedures used in this file.
56 static XID MacXIdAlloc _ANSI_ARGS_((Display *display));
57 static int DefaultErrorHandler _ANSI_ARGS_((Display* display,
58 XErrorEvent* err_evt));
64 int TkMacXDestroyImage _ANSI_ARGS_((XImage *image));
65 unsigned long TkMacXGetPixel _ANSI_ARGS_((XImage *image, int x, int y));
66 int TkMacXPutPixel _ANSI_ARGS_((XImage *image, int x, int y,
67 unsigned long pixel));
68 XImage *TkMacXSubImage _ANSI_ARGS_((XImage *image, int x, int y,
69 unsigned int width, unsigned int height));
70 int TkMacXAddPixel _ANSI_ARGS_((XImage *image, long value));
71 int _XInitImageFuncPtrs _ANSI_ARGS_((XImage *image));
74 *----------------------------------------------------------------------
78 * Create the Display structure and fill it with device
79 * specific information.
82 * Returns a Display structure on success or NULL on failure.
85 * Allocates a new Display structure.
87 *----------------------------------------------------------------------
96 GDHandle graphicsDevice;
98 if (gMacDisplay != NULL) {
99 if (strcmp(gMacDisplay->display->display_name, display_name) == 0) {
106 graphicsDevice = GetMainDevice();
107 display = (Display *) ckalloc(sizeof(Display));
108 display->resource_alloc = MacXIdAlloc;
109 screen = (Screen *) ckalloc(sizeof(Screen) * 2);
110 display->default_screen = 0;
111 display->request = 0;
112 display->nscreens = 1;
113 display->screens = screen;
114 display->display_name = macScreenName;
117 screen->root = ROOT_ID;
118 screen->display = display;
119 screen->root_depth = (*(*graphicsDevice)->gdPMap)->cmpSize *
120 (*(*graphicsDevice)->gdPMap)->cmpCount;
121 screen->height = (*graphicsDevice)->gdRect.bottom -
122 (*graphicsDevice)->gdRect.top;
123 screen->width = (*graphicsDevice)->gdRect.right -
124 (*graphicsDevice)->gdRect.left;
126 screen->mwidth = (screen->width * 254 + 360) / 720;
127 screen->mheight = (screen->height * 254 + 360) / 720;
128 screen->black_pixel = 0x00000000;
129 screen->white_pixel = 0x00FFFFFF;
130 screen->root_visual = (Visual *) ckalloc(sizeof(Visual));
131 screen->root_visual->visualid = 0;
132 screen->root_visual->class = TrueColor;
133 screen->root_visual->red_mask = 0x00FF0000;
134 screen->root_visual->green_mask = 0x0000FF00;
135 screen->root_visual->blue_mask = 0x000000FF;
136 screen->root_visual->bits_per_rgb = 24;
137 screen->root_visual->map_entries = 2 ^ 8;
139 gMacDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
140 gMacDisplay->display = display;
145 *----------------------------------------------------------------------
149 * Deallocates a display structure created by TkpOpenDisplay.
157 *----------------------------------------------------------------------
162 TkDisplay *displayPtr)
164 Display *display = displayPtr->display;
165 if (gMacDisplay != displayPtr) {
166 panic("TkpCloseDisplay: tried to call TkpCloseDisplay on bad display");
170 * Make sure that the local scrap is transfered to the global
174 TkSuspendClipboard();
177 if (display->screens != (Screen *) NULL) {
178 if (display->screens->root_visual != (Visual *) NULL) {
179 ckfree((char *) display->screens->root_visual);
181 ckfree((char *) display->screens);
183 ckfree((char *) display);
184 ckfree((char *) displayPtr);
188 *----------------------------------------------------------------------
192 * This procedure is invoked by Xlib as the resource allocator
196 * The return value is an X resource identifier that isn't currently
200 * The identifier is removed from the stack of free identifiers,
201 * if it was previously on the stack.
203 *----------------------------------------------------------------------
208 Display *display) /* Display for which to allocate. */
210 static long int cur_id = 100;
212 * Some special XIds are reserved
213 * - this is why we start at 100
220 *----------------------------------------------------------------------
222 * TkpWindowWasRecentlyDeleted --
224 * Tries to determine whether the given window was recently deleted.
225 * Called from the generic code error handler to attempt to deal with
226 * async BadWindow errors under some circumstances.
229 * Always 0, we do not keep this information on the Mac, so we do not
230 * know whether the window was destroyed.
235 *----------------------------------------------------------------------
239 TkpWindowWasRecentlyDeleted(
247 *----------------------------------------------------------------------
249 * DefaultErrorHandler --
251 * This procedure is the default X error handler. Tk uses it's
252 * own error handler so this call should never be called.
258 * This function will call panic and exit.
260 *----------------------------------------------------------------------
266 XErrorEvent* err_evt)
269 * This call should never be called. Tk replaces
270 * it with its own error handler.
272 panic("Warning hit bogus error handler!");
287 _XInitImageFuncPtrs(XImage *image)
294 XErrorHandler handler)
296 return DefaultErrorHandler;
300 XRootWindow(Display *display, int screen_number)
307 XGetImage(display, d, x, y, width, height, plane_mask, format)
314 unsigned long plane_mask;
322 XGetGeometry(display, d, root_return, x_return, y_return, width_return,
323 height_return, border_width_return, depth_return)
329 unsigned int* width_return;
330 unsigned int* height_return;
331 unsigned int* border_width_return;
332 unsigned int* depth_return;
334 /* Used in tkCanvPs.c & wm code */
347 _Xconst unsigned char* data,
377 * Do nothing. Shouldn't even be called.
385 * Always return NULL. Tk code checks to see if NULL
386 * is returned & does nothing if it is.
408 ximage = (XImage *) ckalloc(sizeof(XImage));
410 ximage->height = height;
411 ximage->width = width;
412 ximage->depth = depth;
413 ximage->xoffset = offset;
414 ximage->format = format;
416 ximage->bitmap_pad = bitmap_pad;
417 if (bytes_per_line == 0) {
418 ximage->bytes_per_line = width * 4; /* assuming 32 bits per pixel */
420 ximage->bytes_per_line = bytes_per_line;
423 if (format == ZPixmap) {
424 ximage->bits_per_pixel = 32;
425 ximage->bitmap_unit = 32;
427 ximage->bits_per_pixel = 1;
428 ximage->bitmap_unit = 8;
430 ximage->byte_order = LSBFirst;
431 ximage->bitmap_bit_order = LSBFirst;
432 ximage->red_mask = 0x00FF0000;
433 ximage->green_mask = 0x0000FF00;
434 ximage->blue_mask = 0x000000FF;
436 ximage->f.destroy_image = TkMacXDestroyImage;
437 ximage->f.get_pixel = TkMacXGetPixel;
438 ximage->f.put_pixel = TkMacXPutPixel;
439 ximage->f.sub_image = TkMacXSubImage;
440 ximage->f.add_pixel = TkMacXAddPixel;
449 /* TODO - currently a no-op */
474 Atom *actual_type_return,
475 int *actual_format_return,
476 unsigned long *nitems_return,
477 unsigned long *bytes_after_return,
478 unsigned char ** prop_return)
481 *actual_type_return = None;
482 *actual_format_return = *bytes_after_return = 0;
488 XRefreshKeyboardMapping()
490 /* used by tkXEvent.c */
498 const char *icon_name)
501 * This is a no-op, no icon name for Macs.
512 * This function is just a no-op. It is defined to
513 * reset the screen saver. However, there is no real
514 * way to do this on a Mac. Let me know if there is!
520 *----------------------------------------------------------------------
524 * Given a window, this procedure returns information about
525 * the window server for that window. This procedure provides
526 * the guts of the "winfo server" command.
534 *----------------------------------------------------------------------
539 Tcl_Interp *interp, /* The server information is returned in
540 * this interpreter's result. */
541 Tk_Window tkwin) /* Token for window; this selects a
542 * particular display and server. */
544 char buffer[50], buffer2[50];
546 sprintf(buffer, "X%dR%d ", ProtocolVersion(Tk_Display(tkwin)),
547 ProtocolRevision(Tk_Display(tkwin)));
548 sprintf(buffer2, " %d", VendorRelease(Tk_Display(tkwin)));
549 Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)),
550 buffer2, (char *) NULL);
607 *----------------------------------------------------------------------
609 * XChangeWindowAttributes, XSetWindowBackground,
610 * XSetWindowBackgroundPixmap, XSetWindowBorder, XSetWindowBorderPixmap,
611 * XSetWindowBorderWidth, XSetWindowColormap
613 * These functions are all no-ops. They all have equivilent
614 * Tk calls that should always be used instead.
622 *----------------------------------------------------------------------
626 XChangeWindowAttributes(
629 unsigned long value_mask,
630 XSetWindowAttributes* attributes)
635 XSetWindowBackground(
643 XSetWindowBackgroundPixmap(
646 Pixmap background_pixmap)
654 unsigned long border_pixel)
659 XSetWindowBorderPixmap(
662 Pixmap border_pixmap)
667 XSetWindowBorderWidth(
684 *----------------------------------------------------------------------
686 * TkGetDefaultScreenName --
688 * Returns the name of the screen that Tk should use during
692 * Returns a statically allocated string.
697 *----------------------------------------------------------------------
701 TkGetDefaultScreenName(
702 Tcl_Interp *interp, /* Not used. */
703 char *screenName) /* If NULL, use default string. */
705 if ((screenName == NULL) || (screenName[0] == '\0')) {
706 screenName = macScreenName;