Mercurial > hg > xemacs-beta
view etc/tests/external-widget/test-ew-xlib.c @ 872:79c6ff3eef26
[xemacs-hg @ 2002-06-20 21:18:01 by ben]
font changes etc.; some 21.4 changes
mule/mule-msw-init-late.el: Specify charset->windows-registry conversion.
mule/mule-x-init.el: Delete extra mule font additions here. Put them in faces.c.
cl-macs.el: Document better.
font-lock.el: Move Lisp function regexp to lisp-mode.el.
lisp-mode.el: Various indentation fixes:
Handle flet functions better.
Handle argument lists in defuns and flets.
Handle quoted lists, e.g. property lists -- don't indent like
function calls. Distinguish between lambdas and other lists.
lisp-mode.el: Handle this form.
faces.el, font-menu.el, font.el, gtk-faces.el, msw-faces.el, msw-font-menu.el, x-faces.el, x-init.el: Major overhaul of face-handling code:
-- Fix lots of bogus code in msw-faces.el, msw-font-menu.el,
font-menu.el that was "truenaming" font specs -- i.e. in the
process of frobbing a particular field in a general user-specified
font spec with wildcarded fields, sticking in particular values
for all the remaining wildcarded fields. This bug was rampant
everywhere except in x-faces.el (the oldest and only correctly
written code). This also means that we need to work with font
names at all times and not font instances, because a font instance
is essentially a truenamed font.
-- Total rewrite of extremely junky code in msw-faces.el. Work
with names as well as font instances, and return names; stop
truenaming when canonicalizing and frobbing; fix handling of the
combined style field, i.e. weight/slant (also fixed in font.el).
-- Totally rewrite the frobbing functions in faces.el. This time,
we frob all the instantiators rather than just computing a single
instance value and working backwards. That way, e.g., `bold' will
work for all charsets that have bold available, rather than only
for whatever charset was part of the computed font instance
(another example of the truename virus). Also fix up code to look
at the fallbacks (all of them) when no global value present, so we
don't need to put something in the global value. Intelligently
handle a request to frob a buffer locale, rather than signalling
an error. When frobbing instantiators, try hard to figure out
what device type is associated with them, and frob each according
to its own proper device type. Correctly handle inheritance
vectors given as instantiators. Preserve existing tags when
putting back frobbed instantiators. Extract out general
specifier-frobbing code into specifier.el. Document everything
cleanly. Do lots of other things better, etc.
-- Don't duplicatively set a global specification for the default
font -- it's already in the fallback and we no longer need a
default global specification present. Delete various code in
x-faces.el and msw-faces.el that duplicated the lists of fonts in
faces.c.
-- init-global-faces was not being called at all under MS Windows!
Major bogosity. That caused device-specific values to get stuck
into all the fonts, making it very hard to change them -- setting
global specs caused nothing to happen.
-- Correct weight names in font.el.
-- Lots more font fixups in objects*.c.
Printer.el: Warning fix.
specifier.el: Add more args to map-specifier.
Add various "heuristic" specifier functions to aid in creation of
specifier-munging code such as in faces.el.
subr.el: New functions.
lwlib.c: Fix warning.
config.inc.samp: Clean up, add args to control fastcall (not yet supported! the
changes needed are in another ws of mine), profile support, vc6
support, union-type.
xemacs.dsp, xemacs.mak: Semi-major overhaul.
Fix bug where dump-id was always getting recomputed, forcing a
redump even when nothing changed.
Add support for fastcall. Support edit-and-continue (on by
default) with vc6. Use incremental linking when doing a debug
compilation. Add support for profiling.
Consolidate the various debug flags.
Partial support for "batch-compiling" -- compiling many files on a
single invocation of the compiler. Doesn't seem to help that much
for me, so it's not finished or enabled by default.
Remove HAVE_MSW_C_DIRED, we always do.
Correct some sloppy use of directories.
s/cygwin32.h: Allow pdump to work under Cygwin (mmap is broken, so need to undefine
HAVE_MMAP).
s/win32-common.h, s/windowsnt.h: Support for fastcall. Add WIN32_ANY for identifying all Win32
variants (Cygwin, native, MinGW). Both of these are properly used
in another ws.
alloc.c, balloon-x.c, buffer.c, bytecode.c, callint.c, cm.c, cmdloop.c, cmds.c, console-gtk.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-stream.h, console-tty.c, console-tty.h, console-x.c, console-x.h, console.c, console.h, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, device.h, devslots.h, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, editfns.c, emacs.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.c, extents.c, extents.h, faces.c, fileio.c, fns.c, frame-gtk.c, frame-msw.c, frame-tty.c, frame-x.c, frame.c, frame.h, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gui-gtk.c, gui-msw.c, gui-x.c, gui.c, gutter.c, input-method-xlib.c, intl-encap-win32.c, intl-win32.c, keymap.c, lisp.h, macros.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, menubar.h, minibuf.c, mule-charset.c, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-msw.h, objects-tty.c, objects-tty.h, objects-x.c, objects-x.h, objects.c, objects.h, postgresql.c, print.c, process.h, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, select-gtk.c, select-msw.c, select-x.c, select.c, signal.c, sound.c, specifier.c, symbols.c, syntax.c, sysdep.c, syssignal.h, syswindows.h, toolbar-common.c, toolbar-gtk.c, toolbar-msw.c, toolbar-x.c, toolbar.c, unicode.c, window.c, window.h: The following are the major changes made:
(1) Separation of various header files into an external and an
internal version, similar to the existing separation of process.h
and procimpl.h. Eventually this should be done for all Lisp
objects. The external version has the same name as currently; the
internal adds -impl. The external file has XFOO() macros for
objects, but the structure is opaque and defined only in the
internal file. It's now reasonable to move all prototypes in
lisp.h into the appropriate external file, and this should be
done. Currently, separation has been done on extents.h,
objects*.h, console.h, device.h, frame.h, and window.h.
For c/d/f/w, the most basic properties are available in the
external header file, with the macros resolving to functions. In
the internal header file, the macros are redefined to directly
access the structure. Also, the global MARK_FOO_CHANGED macros
have been made into functions so that they can be accessed without
needing to include lots of -impl headers -- they are used in
almost exclusively in non-time-critical functions, and take up
enough time that the function overhead will be negligible.
Similarly, the function overhead from making the basic properties
mentioned above into functions is negligible, and code that does
heavy accessing of c/d/f/w structures inevitably ends up needing
the internal header files, anyway.
(2) More face changes.
-- Major rewrite of objects-msw.c. Now handles wildcard specs
properly, rather than "truenaming" (or even worse, signalling an
error, which previously happened with some of the fallbacks if you
tried to use them in make-font-instance!).
-- Split charset matching of fonts into two stages -- one to find
a font specifically designed for a particular charset (by
examining its registry), the second to find a Unicode font that
can support the charset. This needs to proceed as two complete,
separate instantiations in order to work properly (otherwise many
of the fonts in the HELLO page look wrong). This should also make
it easy to support iso10646 (Unicode) fonts under X.
-- All default values for fonts are now completely specified in
the fallbacks. Stuff from mule-x-init.el has all been moved here,
merged with the existing specs, and totally rethought so you get
sensible results. (HELLO now looks much better!).
-- Generalize the "default X/GTK device" stuff into a
per-device-type "default device".
-- Add mswindows-{set-}charset-registry. In time,
charset<->code-page conversion functions will be removed.
-- Wrap protective code around calls to compute device specifier tags,
and do this computation before calling the face initialization code
because the latter may need these tags to be correctly updated.
(3) Other changes.
EmacsFrame.c, glyphs-msw.c, eval.c, gui-x.c, intl-encap-win32.c, search.c, signal.c, toolbar-msw.c, unicode.c: Warning fixes.
config.h.in: #undefs meant to be frobbed by configure *MUST* go inside of
#ifndef WIN32_NO_CONFIGURE, and everything else *MUST* go outside!
eval.c: Let detailed backtraces be detailed.
specifier.c: Don't override user's print-string-length/print-length settings.
glyphs.c: New function image-instance-instantiator.
config.h.in, sysdep.c: Changes for fastcall.
sysdep.c, nt.c: Fix up a previous botched patch that tried to add support for both
EEXIST and EACCES. IF THE BOTCHED PATCH WENT INTO 21.4, THIS FIXUP
NEEDS TO GO IN, TOO.
search.c: Fix *evil* crash due to incorrect synching of syntax-cache code
with 21.1. THIS SHOULD GO INTO 21.4.
author | ben |
---|---|
date | Thu, 20 Jun 2002 21:19:10 +0000 |
parents | ac2d302a0011 |
children | 03ab78e48ef6 |
line wrap: on
line source
/* * Copyright 1989 O'Reilly and Associates, Inc. * See ../Copyright for complete rights and liability information. */ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xos.h> #include <X11/Xatom.h> #include <stdio.h> #define BITMAPDEPTH 1 #define TOO_SMALL 0 #define BIG_ENOUGH 1 /* These are used as arguments to nearly every Xlib routine, so it saves * routine arguments to declare them global. If there were * additional source files, they would be declared extern there. */ Display *display; int screen_num; static char *progname; /* name this program was invoked by */ void main(argc, argv) int argc; char **argv; { Window topwin, win, win2; unsigned int width, height; /* window size */ int x, y; /* window position */ unsigned int border_width = 4; /* four pixels */ unsigned int display_width, display_height; char *window_name = "Basic Window Program"; char *icon_name = "basicwin"; XSizeHints size_hints; int count; XEvent report; GC gc; XFontStruct *font_info; char *display_name = NULL; int window_size = BIG_ENOUGH; /* or TOO_SMALL to display contents */ progname = argv[0]; /* connect to X server */ if ( (display=XOpenDisplay(display_name)) == NULL ) { (void) fprintf( stderr, "%s: cannot connect to X server %s\n", progname, XDisplayName(display_name)); exit( -1 ); } /* get screen size from display structure macro */ screen_num = DefaultScreen(display); display_width = DisplayWidth(display, screen_num); display_height = DisplayHeight(display, screen_num); /* Note that in a real application, x and y would default to 0 * but would be settable from the command line or resource database. */ x = y = 0; /* size window with enough room for text */ width = display_width/2, height = display_height/3; /* ------------------------------------------------------------ */ /* create top-level window */ topwin = XCreateSimpleWindow(display, RootWindow(display,screen_num), x, y, width, 2*height, border_width, BlackPixel(display, screen_num), WhitePixel(display,screen_num)); /* Set size hints for window manager. The window manager may * override these settings. Note that in a real * application if size or position were set by the user * the flags would be UPosition and USize, and these would * override the window manager's preferences for this window. */ /* x, y, width, and height hints are now taken from * the actual settings of the window when mapped. Note * that PPosition and PSize must be specified anyway. */ size_hints.flags = PPosition | PSize | PMinSize; size_hints.min_width = 300; size_hints.min_height = 200; { XWMHints wm_hints; XClassHint class_hints; /* format of the window name and icon name * arguments has changed in R4 */ XTextProperty windowName, iconName; /* These calls store window_name and icon_name into * XTextProperty structures and set their other * fields properly. */ if (XStringListToTextProperty(&window_name, 1, &windowName) == 0) { (void) fprintf( stderr, "%s: structure allocation for windowName failed.\n", progname); exit(-1); } if (XStringListToTextProperty(&icon_name, 1, &iconName) == 0) { (void) fprintf( stderr, "%s: structure allocation for iconName failed.\n", progname); exit(-1); } wm_hints.initial_state = NormalState; wm_hints.input = True; wm_hints.flags = StateHint | InputHint; class_hints.res_name = progname; class_hints.res_class = "Basicwin"; XSetWMProperties(display, topwin, &windowName, &iconName, argv, argc, &size_hints, &wm_hints, &class_hints); } /* ------------------------------------------------------------ */ /* create the window we're in charge of */ win = XCreateSimpleWindow(display, topwin, x, y, width, height, border_width, BlackPixel(display, screen_num), WhitePixel(display,screen_num)); /* Select event types wanted */ XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); load_font(&font_info); /* create GC for text and drawing */ getGC(win, &gc, font_info); /* ------------------------------------------------------------ */ /* create the external-client window */ win2 = XCreateSimpleWindow(display, topwin, x, y+height, width, height, border_width, BlackPixel(display, screen_num), WhitePixel(display,screen_num)); printf("external window: %d\n", win2); ExternalClientInitialize(display, win2); /* ------------------------------------------------------------ */ /* Display windows */ XMapWindow(display, topwin); XMapWindow(display, win); XMapWindow(display, win2); /* get events, use first to display text and graphics */ while (1) { XNextEvent(display, &report); if (report.xany.window == win2) ExternalClientEventHandler(display, win2, &report); else switch (report.type) { case Expose: /* unless this is the last contiguous expose, * don't draw the window */ if (report.xexpose.count != 0) break; /* if window too small to use */ if (window_size == TOO_SMALL) TooSmall(win, gc, font_info); else { /* place text in window */ draw_text(win, gc, font_info, width, height); /* place graphics in window, */ draw_graphics(win, gc, width, height); } break; case ConfigureNotify: /* window has been resized, change width and * height to send to draw_text and draw_graphics * in next Expose */ width = report.xconfigure.width; height = report.xconfigure.height; if ((width < size_hints.min_width) || (height < size_hints.min_height)) window_size = TOO_SMALL; else window_size = BIG_ENOUGH; break; case ButtonPress: /* trickle down into KeyPress (no break) */ case KeyPress: XUnloadFont(display, font_info->fid); XFreeGC(display, gc); XCloseDisplay(display); exit(1); default: /* all events selected by StructureNotifyMask * except ConfigureNotify are thrown away here, * since nothing is done with them */ break; } /* end switch */ } /* end while */ } getGC(win, gc, font_info) Window win; GC *gc; XFontStruct *font_info; { unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */ XGCValues values; unsigned int line_width = 6; int line_style = LineOnOffDash; int cap_style = CapRound; int join_style = JoinRound; int dash_offset = 0; static char dash_list[] = {12, 24}; int list_length = 2; /* Create default Graphics Context */ *gc = XCreateGC(display, win, valuemask, &values); /* specify font */ XSetFont(display, *gc, font_info->fid); /* specify black foreground since default window background is * white and default foreground is undefined. */ XSetForeground(display, *gc, BlackPixel(display,screen_num)); /* set line attributes */ XSetLineAttributes(display, *gc, line_width, line_style, cap_style, join_style); /* set dashes */ XSetDashes(display, *gc, dash_offset, dash_list, list_length); } load_font(font_info) XFontStruct **font_info; { char *fontname = "9x15"; /* Load font and get font information structure. */ if ((*font_info = XLoadQueryFont(display,fontname)) == NULL) { (void) fprintf( stderr, "%s: Cannot open 9x15 font\n", progname); exit( -1 ); } } draw_text(win, gc, font_info, win_width, win_height) Window win; GC gc; XFontStruct *font_info; unsigned int win_width, win_height; { char *string1 = "Hi! I'm a window, who are you?"; char *string2 = "To terminate program; Press any key"; char *string3 = "or button while in this window."; char *string4 = "Screen Dimensions:"; int len1, len2, len3, len4; int width1, width2, width3; char cd_height[50], cd_width[50], cd_depth[50]; int font_height; int initial_y_offset, x_offset; /* need length for both XTextWidth and XDrawString */ len1 = strlen(string1); len2 = strlen(string2); len3 = strlen(string3); /* get string widths for centering */ width1 = XTextWidth(font_info, string1, len1); width2 = XTextWidth(font_info, string2, len2); width3 = XTextWidth(font_info, string3, len3); font_height = font_info->ascent + font_info->descent; /* output text, centered on each line */ XDrawString(display, win, gc, (win_width - width1)/2, font_height, string1, len1); XDrawString(display, win, gc, (win_width - width2)/2, (int)(win_height - (2 * font_height)), string2, len2); XDrawString(display, win, gc, (win_width - width3)/2, (int)(win_height - font_height), string3, len3); /* copy numbers into string variables */ (void) sprintf(cd_height, " Height - %d pixels", DisplayHeight(display,screen_num)); (void) sprintf(cd_width, " Width - %d pixels", DisplayWidth(display,screen_num)); (void) sprintf(cd_depth, " Depth - %d plane(s)", DefaultDepth(display, screen_num)); /* reuse these for same purpose */ len4 = strlen(string4); len1 = strlen(cd_height); len2 = strlen(cd_width); len3 = strlen(cd_depth); /* To center strings vertically, we place the first string * so that the top of it is two font_heights above the center * of the window. Since the baseline of the string is what we * need to locate for XDrawString, and the baseline is one * font_info->ascent below the top of the character, * the final offset of the origin up from the center of the * window is one font_height + one descent. */ initial_y_offset = win_height/2 - font_height - font_info->descent; x_offset = (int) win_width/4; XDrawString(display, win, gc, x_offset, (int) initial_y_offset, string4,len4); XDrawString(display, win, gc, x_offset, (int) initial_y_offset + font_height,cd_height,len1); XDrawString(display, win, gc, x_offset, (int) initial_y_offset + 2 * font_height,cd_width,len2); XDrawString(display, win, gc, x_offset, (int) initial_y_offset + 3 * font_height,cd_depth,len3); } draw_graphics(win, gc, window_width, window_height) Window win; GC gc; unsigned int window_width, window_height; { int x, y; int width, height; height = window_height/2; width = 3 * window_width/4; x = window_width/2 - width/2; /* center */ y = window_height/2 - height/2; XDrawRectangle(display, win, gc, x, y, width, height); } TooSmall(win, gc, font_info) Window win; GC gc; XFontStruct *font_info; { char *string1 = "Too Small"; int y_offset, x_offset; y_offset = font_info->ascent + 2; x_offset = 2; /* output text, centered on each line */ XDrawString(display, win, gc, x_offset, y_offset, string1, strlen(string1)); }