home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xtici.zip
/
xtici
/
widgets
/
VShell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-28
|
16KB
|
529 lines
/***********************************************************
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System client which uses the Xcms
* Color Management System. TekColor is a trademark of Tektronix, Inc. The
* TekColor Editor is the subject of U.S. and foreign patents pending. The
* term "TekHVC" designates a particular color space that is the subject of
* U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
* Permission is hereby granted to use, copy, modify, sell, and otherwise
* distribute this software and its documentation for the X Window System
* environment, for any purpose and without fee, provided that:
*
* 1. The code and documentation are only used to implement a
* TekColor Editor in an X Window System environment; and
* 2. This copyright and permission notice is reproduced in all copies
* of the code and in supporting documentation.
*
* Permission is granted to modify this code as required to allow it to
* be compiled on any host computer, provided that the functionality of
* the TekColor Editor is not modified in any way. A description of any
* modifications must be sent to Tektronix, Inc. Contact
* Tektronix Inc., P.O. Box 1000, Mail Station 60-850,
* Network Displays Division Engineering, Wilsonville, OR 97070.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
* NAME
* VShell.c - implementation for visualShell widget
*
* DESCRIPTION
*
* HISTORY
*
* HISTORY END
*/
#ifndef LINT
static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
#ifdef RCS_ID
static char *rcsid= "$Header: VShell.c,v 1.2 91/08/22 11:37:14 adamsc Exp $";
#endif RCS_ID
#endif LINT
#include <X11/Xatom.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "VShellP.h"
/*
* Visual Shell -
* This subclass of an application shell allows a visual to be specified
* for the window of the widget. It is sufficient to subclass a shell,
* because all other widgets CopyFromParent, which is what is desired.
* While we are at it, we might as well correct the R3 bug that ignores
* the colormap resource.
*
* This widget will probably not be necessary in R4, but who knows.
*
* The Shell widget is the model for this widget.
*/
static XtResource resources[] = {
#define offset(field) XtOffset(VisualShellWidget, visual.field)
/* {name, class, type, size, offset, default_type, default_addr}, */
{ XtNvisual, XtCVisual, XtRVisual, sizeof(Visual *),
offset(vis), XtRImmediate, CopyFromParent }
#undef offset
};
/* No new actions for this shell */
static void ClassInit();
static void Realize();
#ifdef LATER
static void Resize();
#endif
VisualShellClassRec visualShellClassRec = {
{ /* core fields */
/* superclass */ (WidgetClass) &applicationShellClassRec,
/* class_name */ "VisualShell",
/* widget_size */ sizeof(VisualShellRec),
/* class_initialize */ ClassInit,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ NULL,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ TRUE,
/* visible_interest */ FALSE,
/* destroy */ NULL,
/* resize */ XtInheritResize /* Resize */,
/* expose */ XtInheritExpose,
/* set_values */ NULL,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{ /* composite fields */
/* geometry_manager */ XtInheritGeometryManager,
/* change_managed */ XtInheritChangeManaged,
/* insert_child */ XtInheritInsertChild,
/* delete_child */ XtInheritDeleteChild,
/* extension */ NULL
},
{ /* shell fields */
/* extension */ NULL
},
{ /* WM shell fields */
/* extension */ NULL
},
{ /* vendor shell fields */
/* extension */ NULL
},
{ /* topLevel shell fields */
/* extension */ NULL
},
{ /* application shell fields */
/* extension */ NULL
},
{ /* visual shell fields */
/* extension */ NULL
}
};
WidgetClass visualShellWidgetClass = (WidgetClass)&visualShellClassRec;
static void SetWindowGroups();
static void SetProperties();
/*
* Override the realize procedure for all shell widgets.
*
* It would be nice to call the superclass realization routine after we
* put in our differences, unfortunately it contains a call to
* XCreateWindow with a hard-coded CopyFromParent visual value.
*
* So this horrendous hack is implemented which allows the rest of the
* shell hierarchy realize procedures to be inherited.
*/
static void ClassInit()
{
WidgetClass super = (WidgetClass)vendorShellWidgetClass;
/*
* All the widget class inheritance has been done by this point,
* so redo realize inheritance. Need to inherit the vendor behavior,
* but override Shell (and WMShell) behavior.
* I told you it was a hack !!!
*/
/* Skip vendor shell */
super = super->core_class.superclass;
while (strcmp(super->core_class.class_name, "Shell")) {
super->core_class.realize = Realize;
super = super->core_class.superclass;
}
/* Replace shell realize proc also */
super->core_class.realize = Realize;
}
/*
* This is pretty much a copy of the code from the Shell widget realize
* procedure, with the exception that colormaps are added to the mask
* and the visual is not hardcoded.
*/
static void Realize(wid, pmask, attr)
ShellWidget wid;
Mask *pmask;
XSetWindowAttributes *attr;
{
VisualShellWidget w = (VisualShellWidget)wid;
Mask mask = *pmask;
Visual *v;
/* attempt to inherit child's pixmap to avoid screen flash */
if (w->core.background_pixmap == XtUnspecifiedPixmap) {
if (w->composite.num_children != 0) {
Widget child;
int i;
for (i = 0; i < w->composite.num_children; i++) {
child = (Widget)w->composite.children[i];
if (XtIsManaged(child))
break;
}
if (child->core.background_pixmap != XtUnspecifiedPixmap) {
mask &= ~CWBackPixel;
mask |= CWBackPixmap;
attr->background_pixmap = child->core.background_pixmap;
} else {
attr->background_pixel = child->core.background_pixel;
}
} else {
mask |= CWBackPixel;
mask &= CWBackPixmap;
attr->background_pixel = w->core.background_pixel;
}
} else {
mask &= ~CWBackPixel;
mask |= CWBackPixmap;
attr->background_pixmap = w->core.background_pixmap;
}
if (w->shell.save_under) {
mask |= CWSaveUnder;
attr->save_under = True;
}
if (w->shell.override_redirect) {
mask |= CWOverrideRedirect;
attr->override_redirect = True;
}
/* I don't particularly like this behaviour, but it what is expected
of a shell widget */
if (w->core.width == 0 || w->core.height == 0) {
Cardinal count = 1;
XtErrorMsg("invalidDimension", "shellRealize", "XtToolkitError",
"Shell widget %s has zero width and/or height",
&w->core.name, &count);
}
/* If we can change the visual, better make sure colormap can change */
/* This should be done by the intrinsics, but is not (R3) */
if (w->core.colormap != CopyFromParent) {
mask |= CWColormap;
attr->colormap = w->core.colormap;
}
if (IsVisualShell((Widget)w))
v = w->visual.vis;
else
v = CopyFromParent;
/* Finally, the one line that justifies existance of this class */
w->core.window = XCreateWindow(XtDisplay(w), w->core.screen->root,
w->core.x, w->core.y, w->core.width, w->core.height,
w->core.border_width, w->core.depth,
InputOutput, v, mask, attr);
if (wid->core.num_popups != 0 && w->core.parent == NULL) {
SetWindowGroups((Widget)w, w->core.window);
}
SetProperties((ApplicationShellWidget)w);
}
#ifdef LATER
static void Resize(widget)
Widget widget;
{
register ShellWidget sw = (ShellWidget)widget;
Widget childwid;
Dimension width, height;
int i;
/*
* you can get into problems if a bw setvalues is done and you're
* still size zero and unrealized |||
*/
if (!XtIsRealized(widget)) return;
width = sw->core.width;
height = sw->core.height;
if (width > ((int) ((XcmsFloat) height * 1.85)))
width = ((XcmsFloat) height) * 1.85;
else
height = ((XcmsFloat) width) / 1.85;
for(i = 0; i < sw->composite.num_children; i++) {
if(sw->composite.children[i]->core.managed) {
childwid = sw->composite.children[i];
XtResizeWidget(childwid, width, height,
childwid->core.border_width);
}
}
}
#endif /* LATER */
static void SetWindowGroups(w, window)
Widget w;
Window window;
{
int i;
Arg arg;
WMShellWidget pop;
XtSetArg(arg, XtNwindowGroup, window);
for (i = 0; i < w->core.num_popups; i++) {
pop = (WMShellWidget)w->core.popup_list[i]; /* may not be WMShell */
if (pop->core.num_popups != 0)
SetWindowGroups((Widget)pop, window);
if (XtIsSubclass((Widget)pop, wmShellWidgetClass) /* check here */
&& pop->wm.wm_hints.window_group == None)
XtSetValues((Widget)pop, &arg, 1);
}
}
#define BIGSIZE ((Dimension) 32123)
#define SMALLSIZE ((Dimension) 1)
static void SetProperties(w)
ApplicationShellWidget w; /* not guaranteed; check class first */
{
Window win = XtWindow(w);
ApplicationShellWidget wid;
Display *dpy = XtDisplay(w);
static unsigned char *hostname;
static Boolean gothost = False;
XWMHints *hintp;
XSizeHints *sizep;
XClassHint classhint;
if (!gothost) {
char hostbuf[1000];
gethostname(hostbuf, sizeof(hostbuf));
hostname = (unsigned char *)XtNewString(hostbuf);
gothost = True;
}
if (XtIsSubclass((Widget)w, wmShellWidgetClass) &&
!w->shell.override_redirect) {
Widget parent = w->core.parent;
if (parent) {
while (parent->core.parent)
parent = parent->core.parent;
}
XStoreName(dpy, win, w->wm.title);
hintp = &w->wm.wm_hints;
hintp->flags |= StateHint | InputHint;
if (hintp->icon_x != -1 || hintp->icon_y != -1)
hintp->flags |= IconPositionHint;
if (hintp->icon_pixmap != NULL)
hintp->flags |= IconPixmapHint;
if (hintp->icon_mask != NULL)
hintp->flags |= IconMaskHint;
if (hintp->icon_window != NULL)
hintp->flags |= IconWindowHint;
if (hintp->window_group == None) {
if (parent) {
hintp->window_group = XtWindow(parent);
hintp->flags |= WindowGroupHint;
}
} else
hintp->flags |= WindowGroupHint;
if (XtIsSubclass((Widget)w, topLevelShellWidgetClass)) {
XSetIconName(dpy, win, w->topLevel.icon_name);
if (w->topLevel.iconic)
hintp->initial_state = IconicState;
}
XSetWMHints(dpy, win, hintp);
sizep = (XSizeHints *)&w->wm.size_hints;
sizep->x = w->core.x;
sizep->y = w->core.y;
sizep->width = w->core.width;
sizep->height = w->core.height;
sizep->flags |= PSize | PPosition;
if (sizep->min_aspect.x != -1 || sizep->min_aspect.y != -1
|| sizep->max_aspect.x != -1 || sizep->max_aspect.y != -1)
sizep->flags |= PAspect;
if (sizep->width_inc != -1 || sizep->height_inc != -1)
sizep->flags |= PResizeInc;
if (sizep->max_width != -1 || sizep->max_height != -1) {
sizep->flags |= PMaxSize;
if (sizep->max_width == -1)
sizep->max_width = BIGSIZE;
if (sizep->max_height == -1)
sizep->max_height = BIGSIZE;
}
if (sizep->min_width != -1 || sizep->min_height != -1) {
sizep->flags |= PMinSize;
if (sizep->min_width == -1)
sizep->min_width = SMALLSIZE;
if (sizep->min_height == -1)
sizep->min_height = SMALLSIZE;
}
XSetNormalHints(dpy, win, sizep);
if (w->wm.transient)
XSetTransientForHint(dpy, win, hintp->window_group);
classhint.res_name = w->core.name;
/* get class from top of widget tree */
if (parent)
wid = (ApplicationShellWidget)parent;
else
wid = w;
if (XtIsSubclass((Widget)wid, applicationShellWidgetClass))
classhint.res_class = wid->application.class;
else
classhint.res_class = XtClass(wid)->core_class.class_name;
XSetClassHint(dpy, win, &classhint);
/* SetHostName(dpy, win, hostname); */
XChangeProperty(dpy, win, XA_WM_CLIENT_MACHINE, XA_STRING, 8,
PropModeReplace, hostname, strlen((char *)hostname));
}
if (XtIsSubclass((Widget)w, applicationShellWidgetClass)
&& w->application.argc != -1)
XSetCommand(dpy, win, w->application.argv, w->application.argc);
}
/****************************************************************************
*
* This routine will attempt to get the visualShell widget associated with
* the widget passed.
*
****************************************************************************/
Widget GetVisualShellWidget (wid)
VisualShellWidget wid;
{
if (!wid || IsVisualShell((Widget)wid))
return ((Widget)wid);
return (GetVisualShellWidget ((VisualShellWidget)XtParent((Widget)wid)));
}
/****************************************************************************
*
* This routine will attempt to get the visual class from the window of a
* widget.
*
* Return -1 on failure and visual class on success.
*
****************************************************************************/
int GetVisualClass(widget)
Widget widget;
{
Display *dpy;
Window win;
XWindowAttributes watt;
if (!widget ||
!(dpy = XtDisplayOfObject(widget)) ||
!(win = XtWindow(widget))) {
return (-1);
}
if (!XGetWindowAttributes(dpy, win, &watt)) {
return (-1);
}
if (watt.visual->class == CopyFromParent) {
return (GetVisualClass (XtParent(widget)));
}
return (watt.visual->class);
}
/****************************************************************************
*
* This routine will determine the maximum number of colors displayable
* on the window of a widget.
*
* Returns -1 on failure or a number greater than or equal to one on success.
*
****************************************************************************/
int GetColormapSize (widget)
Widget widget;
{
Display *dpy;
Window win;
XWindowAttributes watt;
if (!widget ||
!(dpy = XtDisplayOfObject(widget)) ||
!(win = XtWindow(widget))) {
return (-1);
}
if (!XGetWindowAttributes(dpy, win, &watt)) {
return (-1);
}
return (1 << watt.depth);
}