Beispiel #1
0
static void CacheArgs(
    ArgList	    args,
    Cardinal	    num_args,
    XtTypedArgList  typed_args,
    Cardinal	    num_typed_args,
    XrmQuarkList    quark_cache,
    Cardinal	    num_quarks,
    XrmQuarkList    *pQuarks)       /* RETURN */
{
    register XrmQuarkList   quarks;
    register Cardinal       i;
    register Cardinal       count;

    count = (args != NULL) ? num_args : num_typed_args;

    if (num_quarks < count) {
	quarks = (XrmQuarkList) __XtMalloc(count * sizeof(XrmQuark));
    } else {
	quarks = quark_cache;
    }
    *pQuarks = quarks;

    if (args != NULL) {
	for (i = count; i; i--)
	    *quarks++ = StringToQuark((args++)->name);
    }
    else {
	for (i = count; i; i--)
	    *quarks++ = StringToQuark((typed_args++)->name);
    }
}
Beispiel #2
0
static void
InitAppLock(XtAppContext app)
{
    int ii;
    LockPtr app_lock;

    app->lock = AppLock;
    app->unlock = AppUnlock;
    app->yield_lock = YieldAppLock;
    app->restore_lock = RestoreAppLock;
    app->free_lock = FreeAppLock;

    app_lock = app->lock_info = XtNew(LockRec);
    app_lock->mutex = xmutex_malloc();
    xmutex_init(app_lock->mutex);
    app_lock->level = 0;
#ifndef _XMUTEX_NESTS
    app_lock->cond = xcondition_malloc();
    xcondition_init(app_lock->cond);
    xthread_clear_id(app_lock->holder);
#endif
    app_lock->stack.size = STACK_INCR;
    app_lock->stack.sp = -1;
    app_lock->stack.st =
	(struct _Tstack *)__XtMalloc(sizeof(struct _Tstack)*STACK_INCR);
    for (ii = 0; ii < STACK_INCR; ii++) {
	app_lock->stack.st[ii].c = xcondition_malloc();
	xcondition_init(app_lock->stack.st[ii].c);
    }
}
Beispiel #3
0
void _XtAddCallback(
    InternalCallbackList*   callbacks,
    XtCallbackProc	    callback,
    XtPointer		    closure)
{
    register InternalCallbackList icl;
    register XtCallbackList cl;
    register int count;

    icl = *callbacks;
    count = icl ? icl->count : 0;

    if (icl && icl->call_state) {
	icl->call_state |= _XtCBFreeAfterCalling;
	icl = (InternalCallbackList)
	    __XtMalloc(sizeof(InternalCallbackRec) +
		     sizeof(XtCallbackRec) * (count + 1));
	(void) memmove((char *)ToList(icl), (char *)ToList(*callbacks),
		       sizeof(XtCallbackRec) * count);
    } else {
	icl = (InternalCallbackList)
	    XtRealloc((char *) icl, sizeof(InternalCallbackRec) +
		      sizeof(XtCallbackRec) * (count + 1));
    }
    *callbacks = icl;
    icl->count = count + 1;
    icl->is_padded = 0;
    icl->call_state = 0;
    cl = ToList(icl) + count;
    cl->callback = callback;
    cl->closure = closure;
} /* _XtAddCallback */
Beispiel #4
0
/* ARGSUSED */
static void AddCallbacks(
    Widget		    widget,
    InternalCallbackList   *callbacks,
    XtCallbackList	    newcallbacks)
{
    register InternalCallbackList icl;
    register int i, j;
    register XtCallbackList cl;

    icl = *callbacks;
    i = icl ? icl->count : 0;
    for (j=0, cl = newcallbacks; cl->callback; cl++, j++);
    if (icl && icl->call_state) {
	icl->call_state |= _XtCBFreeAfterCalling;
	icl = (InternalCallbackList) __XtMalloc(sizeof(InternalCallbackRec) +
					      sizeof(XtCallbackRec) * (i+j));
	(void) memmove((char *)ToList(*callbacks), (char *)ToList(icl),
		       sizeof(XtCallbackRec) * i);
    } else {
	icl = (InternalCallbackList) XtRealloc((char *) icl,
					       sizeof(InternalCallbackRec) +
					       sizeof(XtCallbackRec) * (i+j));
    }
    *callbacks = icl;
    icl->count = i+j;
    icl->is_padded = 0;
    icl->call_state = 0;
    for (cl = ToList(icl) + i; --j >= 0; )
	*cl++ = *newcallbacks++;
} /* AddCallbacks */
Beispiel #5
0
static void FillInLangSubs(
    Substitution subs,
    XtPerDisplay pd)
{
    int len;
    char *string, *p1, *p2, *p3;
    char **rest;
    char *ch;

    if (pd->language == NULL ||
            (pd->language != NULL && pd->language[0] == '\0')) {
        subs[0].substitution = subs[1].substitution =
                                   subs[2].substitution = subs[3].substitution = NULL;
        return;
    }

    string = ExtractLocaleName(pd->language);

    if (string == NULL ||
            (string != NULL && string[0] == '\0')) {
        subs[0].substitution = subs[1].substitution =
                                   subs[2].substitution = subs[3].substitution = NULL;
        return;
    }

    len = strlen(string) + 1;
    subs[0].substitution = string;
    p1 = subs[1].substitution = __XtMalloc((Cardinal) 3*len);
    p2 = subs[2].substitution = subs[1].substitution + len;
    p3 = subs[3].substitution = subs[2].substitution + len;

    /* Everything up to the first "_" goes into p1.  From "_" to "." in
       p2.  The rest in p3.  If no delimiters, all goes into p1.  We
       assume p1, p2, and p3 are large enough. */

    *p1 = *p2 = *p3 = '\0';

    ch = strchr(string, '_');
    if (ch != NULL) {
        len = ch - string;
        (void) strncpy(p1, string, len);
        p1[len] = '\0';
        string = ch + 1;
        rest = &p2;
    } else rest = &p1;

    /* Rest points to where we put the first part */

    ch = strchr(string, '.');
    if (ch != NULL) {
        len = ch - string;
        strncpy(*rest, string, len);
        (*rest)[len] = '\0';
        (void) strcpy(p3, ch+1);
    } else (void) strcpy(*rest, string);
}
Beispiel #6
0
void _XtRemoveCallback (
    InternalCallbackList   *callbacks,
    XtCallbackProc	    callback,
    XtPointer		    closure)
{
    register InternalCallbackList icl;
    register int i, j;
    register XtCallbackList cl, ncl, ocl;

    icl = *callbacks;
    if (!icl) return;

    cl = ToList(icl);
    for (i=icl->count; --i >= 0; cl++) {
	if (cl->callback == callback && cl->closure == closure) {
	    if (icl->call_state) {
		icl->call_state |= _XtCBFreeAfterCalling;
		if (icl->count == 1) {
		    *callbacks = NULL;
		} else {
		    j = icl->count - i - 1;
		    ocl = ToList(icl);
		    icl = (InternalCallbackList)
			__XtMalloc(sizeof(InternalCallbackRec) +
				 sizeof(XtCallbackRec) * (i + j));
		    icl->count = i + j;
		    icl->is_padded = 0;
		    icl->call_state = 0;
		    ncl = ToList(icl);
		    while (--j >= 0)
			*ncl++ = *ocl++;
		    while (--i >= 0)
			*ncl++ = *++cl;
		    *callbacks = icl;
		}
	    } else {
		if (--icl->count) {
		    ncl = cl + 1;
		    while (--i >= 0)
			*cl++ = *ncl++;
		    icl = (InternalCallbackList)
			XtRealloc((char *) icl, sizeof(InternalCallbackRec)
				  + sizeof(XtCallbackRec) * icl->count);
		    icl->is_padded = 0;
		    *callbacks = icl;
		} else {
		    XtFree((char *) icl);
		    *callbacks = NULL;
		}
	    }
	    return;
	}
    }
} /* _XtRemoveCallback */
Beispiel #7
0
XrmResourceList* _XtCreateIndirectionTable (
    XtResourceList  resources,
    Cardinal	    num_resources)
{
    register Cardinal idx;
    XrmResourceList* table;

    table = (XrmResourceList*)__XtMalloc(num_resources * sizeof(XrmResourceList));
    for (idx = 0; idx < num_resources; idx++)
        table[idx] = (XrmResourceList)(&(resources[idx]));
    return table;
}
Beispiel #8
0
static void DeleteDetailFromMask(
    Mask **ppDetailMask,
    unsigned short detail)
{
    Mask *pDetailMask = *ppDetailMask;

    if (!pDetailMask) {
	int i;
	pDetailMask = (Mask *)__XtMalloc(sizeof(Mask) * MasksPerDetailMask);
	for (i = MasksPerDetailMask; --i >= 0; )
	    pDetailMask[i] = ~0;
	*ppDetailMask = pDetailMask;
    }
    BITCLEAR((pDetailMask), detail);
}
Beispiel #9
0
void XtGetResourceList(
	WidgetClass widget_class,
	XtResourceList *resources,
	Cardinal *num_resources)
{
	int size;
	register Cardinal i, dest = 0;
	register XtResourceList *list, dlist;

	LOCK_PROCESS;
	size = widget_class->core_class.num_resources * sizeof(XtResource);
	*resources = (XtResourceList) __XtMalloc((unsigned) size);

	if (!widget_class->core_class.class_inited) {
	    /* Easy case */

	    (void) memmove((char *) *resources,
			   (char *)widget_class->core_class.resources, size);
	    *num_resources = widget_class->core_class.num_resources;
	    UNLOCK_PROCESS;
	    return;
	}

	/* Nope, it's the hard case */

	list = (XtResourceList *) widget_class->core_class.resources;
	dlist = *resources;
	for (i = 0; i < widget_class->core_class.num_resources; i++) {
	    if (list[i] != NULL) {
		dlist[dest].resource_name = (String)
			XrmQuarkToString(TOXRMQUARK(list[i]->resource_name));
		dlist[dest].resource_class = (String)
			XrmQuarkToString(TOXRMQUARK(list[i]->resource_class));
		dlist[dest].resource_type = (String)
			XrmQuarkToString(TOXRMQUARK(list[i]->resource_type));
		dlist[dest].resource_size = list[i]->resource_size;
		/* trust that resource_offset isn't that big */
		dlist[dest].resource_offset = (Cardinal)
			-((int)(list[i]->resource_offset + 1));
		dlist[dest].default_type = (String)
			XrmQuarkToString(TOXRMQUARK(list[i]->default_type));
		dlist[dest].default_addr = list[i]->default_addr;
		dest++;
	    }
	}
	*num_resources = dest;
	UNLOCK_PROCESS;
}
Beispiel #10
0
static Mask *CopyDetailMask(
    Mask *pOriginalDetailMask)
{
    Mask *pTempMask;
    int i;

    if (!pOriginalDetailMask)
	return NULL;

    pTempMask = (Mask *)__XtMalloc(sizeof(Mask) * MasksPerDetailMask);

    for ( i = 0; i < MasksPerDetailMask; i++)
      pTempMask[i]= pOriginalDetailMask[i];

    return pTempMask;
}
Beispiel #11
0
InternalCallbackList _XtCompileCallbackList(
    XtCallbackList xtcallbacks)
{
    register int n;
    register XtCallbackList xtcl, cl;
    register InternalCallbackList callbacks;

    for (n=0, xtcl=xtcallbacks; xtcl->callback; n++, xtcl++) {};
    if (n == 0) return (InternalCallbackList) NULL;

    callbacks = (InternalCallbackList) __XtMalloc(sizeof(InternalCallbackRec) +
						sizeof(XtCallbackRec) * n);
    callbacks->count = n;
    callbacks->is_padded = 0;
    callbacks->call_state = 0;
    cl = ToList(callbacks);
    while (--n >= 0)
	*cl++ = *xtcallbacks++;
    return(callbacks);
} /* _XtCompileCallbackList */
Beispiel #12
0
static XtServerGrabPtr CreateGrab(
    Widget	widget,
    Boolean	ownerEvents,
    Modifiers	modifiers,
    KeyCode 	keybut,
    int		pointer_mode,
    int		keyboard_mode,
    Mask	event_mask,
    Window 	confine_to,
    Cursor 	cursor,
    Boolean	need_ext)
{
    XtServerGrabPtr grab;

    if (confine_to || cursor)
	need_ext = True;
    grab = (XtServerGrabPtr)__XtMalloc(sizeof(XtServerGrabRec) +
				     (need_ext ? sizeof(XtServerGrabExtRec)
				      : 0));
    grab->next = NULL;
    grab->widget = widget;
    grab->ownerEvents = ownerEvents;
    grab->pointerMode = pointer_mode;
    grab->keyboardMode = keyboard_mode;
    grab->eventMask = event_mask;
    grab->hasExt = need_ext;
    grab->confineToIsWidgetWin = (XtWindow (widget) == confine_to);
    grab->modifiers = modifiers;
    grab->keybut = keybut;
    if (need_ext) {
	XtServerGrabExtPtr ext = GRABEXT(grab);
	ext->pModifiersMask = NULL;
	ext->pKeyButMask = NULL;
	ext->confineTo = confine_to;
	ext->cursor = cursor;
    }
    return grab;
}
Beispiel #13
0
XtCallbackList _XtGetCallbackList(
    InternalCallbackList *callbacks)
{
    register int i;
    register InternalCallbackList icl;
    register XtCallbackList cl, ocl;

    icl = *callbacks;
    if (!icl) {
	static XtCallbackRec emptyList[1] = { {NULL, NULL} };
	return (XtCallbackList)emptyList;
    }
    if (icl->is_padded)
	return ToList(icl);
    i = icl->count;
    if (icl->call_state) {
	icl->call_state |= _XtCBFreeAfterCalling;
	ocl = ToList(icl);
	icl = (InternalCallbackList) __XtMalloc(sizeof(InternalCallbackRec) +
					      sizeof(XtCallbackRec) * (i+1));
	icl->count = i;
	icl->call_state = 0;
	cl = ToList(icl);
	while (--i >= 0)
	    *cl++ = *ocl++;
    } else {
	icl = (InternalCallbackList) XtRealloc((char *)icl,
					       sizeof(InternalCallbackRec) +
					       sizeof(XtCallbackRec) * (i+1));
	cl = ToList(icl) + i;
    }
    icl->is_padded = 1;
    cl->callback = (XtCallbackProc) NULL;
    cl->closure = NULL;
    *callbacks = icl;
    return ToList(icl);
}
Beispiel #14
0
void
XtSetWMColormapWindows(
    Widget widget,
    Widget *list,
    Cardinal count)
{
    Window *data;
    Widget *checked, *top, *temp, hookobj;
    Cardinal i, j, checked_count;
    Boolean match;
    Atom xa_wm_colormap_windows;
    WIDGET_TO_APPCON(widget);

    LOCK_APP(app);
    if ( !XtIsRealized(widget) || (count == 0) ) {
	UNLOCK_APP(app);
	return;
    }

    top = checked = (Widget *) __XtMalloc( (Cardinal) sizeof(Widget) * count);


/*
 * The specification calls for only adding the windows that have unique
 * colormaps to the property to this function, so we will make a pass through
 * the widget list removing all the widgets with non-unique colormaps.
 *
 * We will also remove any unrealized widgets from the list at this time.
 */

    for (checked_count = 0, i = 0; i < count; i++) {
	if (!XtIsRealized(list[i])) continue;

	*checked = list[i];
	match = FALSE;

/*
 * Don't check first element for matching colormap since there is nothing
 * to check it against.
 */

	if (checked != top)
	    for (j = 0, temp = top; j < checked_count ; j++, temp++)
		if ( (*temp)->core.colormap == (*checked)->core.colormap) {
		    match = TRUE;
		    break;
		}

/*
 * If no colormap was found to match then add this widget to the linked list.
 */

	if (!match) {
	    checked++;
	    checked_count++;
	}
    }

/*
 * Now that we have the list of widgets we need to convert it to a list of
 * windows and set the property.
 */

    data = (Window *) __XtMalloc( (Cardinal) sizeof(Window) * checked_count);

    for ( i = 0 ; i < checked_count ; i++)
	data[i] = XtWindow(top[i]);

    xa_wm_colormap_windows = XInternAtom(XtDisplay(widget),
					 "WM_COLORMAP_WINDOWS", FALSE);

    XChangeProperty(XtDisplay(widget), XtWindow(widget),
		    xa_wm_colormap_windows, XA_WINDOW, 32,
		    PropModeReplace, (unsigned char *) data, (int) i);

    hookobj = XtHooksOfDisplay(XtDisplay(widget));
    if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
	XtChangeHookDataRec call_data;

	call_data.type = XtHsetWMColormapWindows;
	call_data.widget = widget;
	call_data.event_data = (XtPointer) list;
	call_data.num_event_data = count;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.changehook_callbacks,
		(XtPointer)&call_data);
    }

    XtFree( (char *) data);
    XtFree( (char *) top);
    UNLOCK_APP(app);
}
Beispiel #15
0
static void ManageChildren(
    WidgetList  children,
    Cardinal    num_children,
    Widget	parent,
    Boolean	call_change_managed,
    String	caller_func)
{
#define MAXCHILDREN 100
    Widget		child;
    Cardinal		num_unique_children, i;
    XtWidgetProc	change_managed = NULL;
    WidgetList		unique_children;
    Widget		cache[MAXCHILDREN];
    Bool		parent_realized = False;

    if (XtIsComposite((Widget) parent)) {
	LOCK_PROCESS;
        change_managed = ((CompositeWidgetClass) parent->core.widget_class)
		    ->composite_class.change_managed;
	UNLOCK_PROCESS;
	parent_realized = XtIsRealized((Widget)parent);
    } else {
	XtAppErrorMsg(XtWidgetToApplicationContext((Widget)parent),
		"invalidParent",caller_func, XtCXtToolkitError,
	    "Attempt to manage a child when parent is not Composite",
	    (String *) NULL, (Cardinal *) NULL);
    }

    /* Construct new list of children that really need to be operated upon. */
    if (num_children <= MAXCHILDREN) {
	unique_children = cache;
    } else {
	unique_children = (WidgetList) __XtMalloc(num_children * sizeof(Widget));
    }
    num_unique_children = 0;
    for (i = 0; i < num_children; i++) {
	child = children[i];
	if (child == NULL) {
	    XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
		XtNinvalidChild,caller_func,XtCXtToolkitError,
		"null child passed to ManageChildren",
		(String *)NULL, (Cardinal *)NULL);
	    if (unique_children != cache) XtFree((char *) unique_children);
	    return;
	}
#ifdef DEBUG
	if (!XtIsRectObj(child)) {
	    String params[2];
	    Cardinal num_params = 2;
	    params[0] = XtName(child);
	    params[1] = child->core.widget_class->core_class.class_name;
	    XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
			    "notRectObj",caller_func,XtCXtToolkitError,
			    "child \"%s\", class %s is not a RectObj",
			    params, &num_params);
	    continue;
	}
#endif /*DEBUG*/
        if (child->core.parent != parent) {
	    XtAppWarningMsg(XtWidgetToApplicationContext((Widget)parent),
		    "ambiguousParent",caller_func,XtCXtToolkitError,
		"Not all children have same parent in XtManageChildren",
		(String *)NULL, (Cardinal *)NULL);
	} else if (! child->core.managed && !child->core.being_destroyed) {
	    unique_children[num_unique_children++] = child;
	    CALLGEOTAT(_XtGeoTrace(child,
			   "Child \"%s\"[%d,%d] is marked managed\n",
			   XtName(child),
			   child->core.width,child->core.height));
	    child->core.managed = TRUE;
	}
    }

    if ((call_change_managed || num_unique_children != 0) && parent_realized) {
	/* Compute geometry of new managed set of children. */
	if (change_managed != NULL) {
	    CALLGEOTAT(_XtGeoTrace((Widget)parent,
			   "Call parent: \"%s\"[%d,%d]'s changemanaged\n",
			   XtName((Widget)parent),
			   parent->core.width,parent->core.height));
	    (*change_managed) ((Widget)parent);
	}

	/* Realize each child if necessary, then map if necessary */
	for (i = 0; i < num_unique_children; i++) {
	    child = unique_children[i];
	    if (XtIsWidget(child)) {
		if (! XtIsRealized(child)) XtRealizeWidget(child);
		if (child->core.mapped_when_managed) XtMapWidget(child);
	    } else { /* RectObj child */
		Widget pw = child->core.parent;
		RectObj r = (RectObj) child;
		while ((pw!=NULL) && (!XtIsWidget(pw)))
		    pw = pw->core.parent;
		if (pw != NULL)
		    XClearArea (XtDisplay (pw), XtWindow (pw),
		    r->rectangle.x, r->rectangle.y,
		    r->rectangle.width + (r->rectangle.border_width << 1),
		    r->rectangle.height + (r->rectangle.border_width << 1),
		    TRUE);
            }
        }
    }

    if (unique_children != cache) XtFree((char *) unique_children);
} /* ManageChildren */
Beispiel #16
0
void XtRemoveCallbacks (
    Widget	    widget,
    _Xconst char*   name,
    XtCallbackList  xtcallbacks)
{
    InternalCallbackList *callbacks;
    Widget hookobj;
    int i;
    InternalCallbackList icl;
    XtCallbackList cl, ccl, rcl;
    XtAppContext app = XtWidgetToApplicationContext(widget);

    LOCK_APP(app);
    callbacks = FetchInternalList(widget, name);
    if (!callbacks) {
	XtAppWarningMsg(app,
	       XtNinvalidCallbackList,XtNxtRemoveCallback,XtCXtToolkitError,
              "Cannot find callback list in XtRemoveCallbacks",
	      (String *)NULL, (Cardinal *)NULL);
	UNLOCK_APP(app);
	return;
    }

    icl = *callbacks;
    if (!icl) {
	UNLOCK_APP(app);
	return;
    }

    i = icl->count;
    cl = ToList(icl);
    if (icl->call_state) {
	icl->call_state |= _XtCBFreeAfterCalling;
	icl = (InternalCallbackList)__XtMalloc(sizeof(InternalCallbackRec) +
					     sizeof(XtCallbackRec) * i);
	icl->count = i;
	icl->call_state = 0;
    }
    ccl = ToList(icl);
    while (--i >= 0) {
	*ccl++ = *cl;
	for (rcl=xtcallbacks; rcl->callback; rcl++) {
	    if (cl->callback == rcl->callback && cl->closure == rcl->closure) {
		ccl--;
		icl->count--;
		break;
	    }
	}
	cl++;
    }
    if (icl->count) {
	icl = (InternalCallbackList)
	    XtRealloc((char *)icl, (sizeof(InternalCallbackRec) +
				    sizeof(XtCallbackRec) * icl->count));
	icl->is_padded = 0;
	*callbacks = icl;
    } else {
	XtFree((char *)icl);
	*callbacks = NULL;
    }
    hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget));
    if (XtHasCallbacks(hookobj, XtNchangeHook) == XtCallbackHasSome) {
	XtChangeHookDataRec call_data;

	call_data.type = XtHremoveCallbacks;
	call_data.widget = widget;
	call_data.event_data = (XtPointer) name;
	XtCallCallbackList(hookobj,
		((HookObject)hookobj)->hooks.changehook_callbacks,
		(XtPointer)&call_data);
    }
    UNLOCK_APP(app);
} /* XtRemoveCallbacks */
Beispiel #17
0
/*
 * Create a new resource list, with the class resources following the
 * superclass's resources.  If a resource in the class list overrides
 * a superclass resource, then just replace the superclass entry in place.
 *
 * At the same time, add a level of indirection to the XtResourceList to
 * create and XrmResourceList.
 */
void _XtDependencies(
    XtResourceList  *class_resp,	/* VAR */
    Cardinal	    *class_num_resp,    /* VAR */
    XrmResourceList *super_res,
    Cardinal	    super_num_res,
    Cardinal	    super_widget_size)
{
    register XrmResourceList *new_res;
	     Cardinal	     new_num_res;
	     XrmResourceList class_res = (XrmResourceList) *class_resp;
	     Cardinal        class_num_res = *class_num_resp;
    register Cardinal	     i, j;
	     Cardinal        new_next;

    if (class_num_res == 0) {
	/* Just point to superclass resource list */
	*class_resp = (XtResourceList) super_res;
	*class_num_resp = super_num_res;
	return;
    }

    /* Allocate and initialize new_res with superclass resource pointers */
    new_num_res = super_num_res + class_num_res;
    new_res = (XrmResourceList *) __XtMalloc(new_num_res*sizeof(XrmResourceList));
    if (super_num_res > 0)
	XtMemmove(new_res, super_res, super_num_res * sizeof(XrmResourceList));
    
    /* Put pointers to class resource entries into new_res */
    new_next = super_num_res;
    for (i = 0; i < class_num_res; i++) {
	if ((Cardinal)(-class_res[i].xrm_offset-1) < super_widget_size) {
	    /* Probably an override of superclass resources--look for overlap */
	    for (j = 0; j < super_num_res; j++) {
		if (class_res[i].xrm_offset == new_res[j]->xrm_offset) {
		    /* Spec is silent on what fields subclass can override.
		     * The only two of real concern are type & size.
		     * Although allowing type to be over-ridden introduces
		     * the possibility of errors, it's at present the only
		     * reasonable way to allow a subclass to force a private
		     * converter to be invoked for a subset of fields.
		     */
		    /* We do insist that size be identical to superclass */
		    if (class_res[i].xrm_size != new_res[j]->xrm_size) {
			BadSize(class_res[i].xrm_size,
				(XrmQuark) class_res[i].xrm_name);
			class_res[i].xrm_size = new_res[j]->xrm_size;
		    }
		    new_res[j] = &(class_res[i]);
		    new_num_res--;
		    goto NextResource;
		}
	    } /* for j */
	}
	/* Not an overlap, add an entry to new_res */
	new_res[new_next++] = &(class_res[i]);
NextResource:;
    } /* for i */

    /* Okay, stuff new resources back into class record */
    *class_resp = (XtResourceList) new_res;
    *class_num_resp = new_num_res;
} /* _XtDependencies */
Beispiel #18
0
static XtCacheRef *GetResources(
    Widget	    widget,	    /* Widget resources are associated with */
    char*	    base,	    /* Base address of memory to write to   */
    XrmNameList     names,	    /* Full inheritance name of widget      */
    XrmClassList    classes,	    /* Full inheritance class of widget     */
    XrmResourceList*  table,	    /* The list of resources required.      */
    unsigned	    num_resources,  /* number of items in resource list     */
    XrmQuarkList    quark_args,     /* Arg names quarkified		    */
    ArgList	    args,	    /* ArgList to override resources	    */
    unsigned	    num_args,       /* number of items in arg list	    */
    XtTypedArgList  typed_args,	    /* Typed arg list to override resources */
    Cardinal*	    pNumTypedArgs,  /* number of items in typed arg list    */
    Boolean	    tm_hack)	    /* do baseTranslations		    */
{
/*
 * assert: *pNumTypedArgs == 0 if num_args > 0
 * assert: num_args == 0 if *pNumTypedArgs > 0
 */
#define SEARCHLISTLEN 100
#define MAXRESOURCES  400

    XrmValue	    value;
    XrmQuark	    rawType;
    XrmValue	    convValue;
    XrmHashTable    stackSearchList[SEARCHLISTLEN];
    XrmHashTable    *searchList = stackSearchList;
    unsigned int    searchListSize = SEARCHLISTLEN;
    Boolean	    found[MAXRESOURCES];
    int		    typed[MAXRESOURCES];
    XtCacheRef	    cache_ref[MAXRESOURCES];
    XtCacheRef      *cache_ptr, *cache_base;
    Boolean	    persistent_resources = True;
    Boolean	    found_persistence = False;
    int		    num_typed_args = *pNumTypedArgs;
    XrmDatabase     db;
    Boolean	    do_tm_hack = False;

    if ((args == NULL) && (num_args != 0)) {
    	XtAppWarningMsg(XtWidgetToApplicationContext(widget),
		"invalidArgCount","getResources",XtCXtToolkitError,
                 "argument count > 0 on NULL argument list",
                   (String *)NULL, (Cardinal *)NULL);
	num_args = 0;
    }
    if (num_resources == 0) {
	return NULL;
    } else if (num_resources >= MAXRESOURCES) {
    	XtAppWarningMsg(XtWidgetToApplicationContext(widget),
		"invalidResourceCount","getResources",XtCXtToolkitError,
              "too many resources",
	      (String *)NULL, (Cardinal *)NULL);
	return NULL;
    } else if (table == NULL) {
    	XtAppWarningMsg(XtWidgetToApplicationContext(widget),
		"invalidResourceCount","getResources",XtCXtToolkitError,
              "resource count > 0 on NULL resource list",
	      (String *)NULL, (Cardinal *)NULL);
	return NULL;
    }

    /* Mark each resource as not found on arg list */
    bzero((char *) found, (int) (num_resources * sizeof(Boolean)));
    bzero((char *) typed, (int) (num_resources * sizeof(int)));

    /* Copy the args into the resources, mark each as found */
    {
	register ArgList	    arg;
	register XtTypedArgList	    typed_arg;
	register XrmName	    argName;
	register Cardinal	    j;
	register int	    i;
	register XrmResourceList rx;
	register XrmResourceList *res;
	for (arg = args, i = 0; (Cardinal)i < num_args; i++, arg++) {
	    argName = quark_args[i];
	    if (argName == QinitialResourcesPersistent) {
		persistent_resources = (Boolean)arg->value;
		found_persistence = True;
		continue;
	    }
	    for (j = 0, res = table; j < num_resources; j++, res++) {
		rx = *res;
		if (argName == rx->xrm_name) {
		    _XtCopyFromArg(
			arg->value,
			base - rx->xrm_offset - 1,
			rx->xrm_size);
		    found[j] = TRUE;
		    break;
		}
	    }
	}
	for (typed_arg = typed_args, i = 0; i < num_typed_args;
	     i++, typed_arg++) {
	    register XrmRepresentation argType;
	    argName = quark_args[i];
	    argType = (typed_arg->type == NULL) ? NULLQUARK 
		: XrmStringToRepresentation(typed_arg->type);
	    if (argName == QinitialResourcesPersistent) {
		persistent_resources = (Boolean)typed_arg->value;
		found_persistence = True;   
		break;
	    }
	    for (j = 0, res = table; j < num_resources; j++, res++) {
		rx = *res;
		if (argName == rx->xrm_name) {
		    if (argType != NULLQUARK && argType != rx->xrm_type) {
			typed[j] = i + 1;
		    } else {
			_XtCopyFromArg(
				       typed_arg->value,
				       base - rx->xrm_offset - 1,
				       rx->xrm_size);
		    }
		    found[j] = TRUE;
		    break;
		}   
	    }
	}
    }

    /* Ask resource manager for a list of database levels that we can
       do a single-level search on each resource */

    db = XtScreenDatabase(XtScreenOfObject(widget));
    while (!XrmQGetSearchList(db, names, classes,
			      searchList, searchListSize)) {
	if (searchList == stackSearchList)
	    searchList = NULL;
	searchList = (XrmHashTable*)XtRealloc((char*)searchList,
					      sizeof(XrmHashTable) *
					      (searchListSize *= 2));
    }
    
    if (persistent_resources)
	cache_base = NULL;
    else
	cache_base = cache_ref;
    /* geez, this is an ugly mess */
    if (XtIsShell(widget)) {
	register XrmResourceList  *res;
	register Cardinal	  j;
	Screen *oldscreen = widget->core.screen;

	/* look up screen resource first, since real rdb depends on it */
	for (res = table, j = 0; j < num_resources; j++, res++) {
	    if ((*res)->xrm_name != Qscreen)
		continue;
	    if (typed[j]) {
		register XtTypedArg* arg = typed_args + typed[j] - 1;
		XrmQuark from_type;
		XrmValue from_val, to_val;

		from_type = StringToQuark(arg->type);
		from_val.size = arg->size;
		if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal)))
		    from_val.addr = (XPointer)arg->value;
		else
		    from_val.addr = (XPointer)&arg->value;
		to_val.size = sizeof(Screen*);
		to_val.addr = (XPointer)&widget->core.screen;
		found[j] = _XtConvert(widget, from_type, &from_val,
				      QScreen, &to_val, cache_base);
		if (cache_base && *cache_base)
		    cache_base++;
	    }
	    if (!found[j]) {
		if (XrmQGetSearchResource(searchList, Qscreen, QScreen,
				      &rawType, &value)) {
		    if (rawType != QScreen) {
			convValue.size = sizeof(Screen*);
			convValue.addr = (XPointer)&widget->core.screen;
			(void)_XtConvert(widget, rawType, &value,
					 QScreen, &convValue, cache_base);
			if (cache_base && *cache_base)
			    cache_base++;
		    } else {
			widget->core.screen = *((Screen **)value.addr);
		    }
		}
	    }
	    break;
	}
	/* now get the database to use for the rest of the resources */
	if (widget->core.screen != oldscreen) {
	    db = XtScreenDatabase(widget->core.screen);
	    while (!XrmQGetSearchList(db, names, classes,
				      searchList, searchListSize)) {
		if (searchList == stackSearchList)
		    searchList = NULL;
		searchList = (XrmHashTable*)XtRealloc((char*)searchList,
						      sizeof(XrmHashTable) *
						      (searchListSize *= 2));
	    }
	}
    }

    /* go to the resource manager for those resources not found yet */
    /* if it's not in the resource database use the default value   */

    {
	register XrmResourceList  rx;
	register XrmResourceList  *res;
	register Cardinal	  j;
	register XrmRepresentation xrm_type;
	register XrmRepresentation xrm_default_type;
	char	char_val;
	short	short_val;
	int	int_val;
	long	long_val;
	char*	char_ptr;

	if (!found_persistence) {
	    if (XrmQGetSearchResource(searchList, QinitialResourcesPersistent,
			QInitialResourcesPersistent, &rawType, &value)) {
		if (rawType != QBoolean) {
		    convValue.size = sizeof(Boolean);
		    convValue.addr = (XPointer)&persistent_resources;
		    (void)_XtConvert(widget, rawType, &value, QBoolean,
				     &convValue, NULL);
		}
		else
		    persistent_resources = *(Boolean*)value.addr;
	    }
	}
	if (persistent_resources)
	    cache_ptr = NULL;
	else if (cache_base)
	    cache_ptr = cache_base;
	else
	    cache_ptr = cache_ref;

	for (res = table, j = 0; j < num_resources; j++, res++) {
	    rx = *res;
	    xrm_type = rx->xrm_type;
	    if (typed[j]) {
		register XtTypedArg* arg = typed_args + typed[j] - 1;

		/*
                 * This resource value has been specified as a typed arg and 
		 * has to be converted. Typed arg conversions are done here 
		 * to correctly interpose them with normal resource conversions.
                 */
		XrmQuark	    from_type;
		XrmValue            from_val, to_val;
		Boolean		    converted;
                 
		from_type = StringToQuark(arg->type);
    		from_val.size = arg->size;
		if ((from_type == QString) || ((unsigned) arg->size > sizeof(XtArgVal)))
        	    from_val.addr = (XPointer)arg->value;
	        else
            	    from_val.addr = (XPointer)&arg->value;
		to_val.size = rx->xrm_size;
		to_val.addr = base - rx->xrm_offset - 1;
		converted = _XtConvert(widget, from_type, &from_val,
				       xrm_type, &to_val, cache_ptr);
		if (converted) {

		    /* Copy the converted value back into the typed argument.
		     * normally the data should be <= sizeof(XtArgVal) and
		     * is stored directly into the 'value' field .... BUT
		     * if the resource size is greater than sizeof(XtArgVal)
		     * then we dynamically alloc a block of store to hold the
		     * data and zap a copy in there !!! .... freeing it later
		     * the size field in the typed arg is negated to indicate
		     * that the store pointed to by the value field is
		     * dynamic .......
		     * "freeing" happens in the case of _XtCreate after the
		     * CallInitialize ..... other clients of GetResources
		     * using typed args should be aware of the need to free
		     * this store .....
		     */

		    if(rx->xrm_size > sizeof(XtArgVal)) {
			arg->value = (XtArgVal) __XtMalloc(rx->xrm_size);
			arg->size = -(arg->size);
		    } else { /* will fit - copy directly into value field */
			arg->value = (XtArgVal) NULL;
		    }
		    CopyToArg((char *)(base - rx->xrm_offset - 1),
				 &arg->value, rx->xrm_size);

		} else {
		   /* Conversion failed. Get default value. */
		   found[j] = False;
		}

		if (cache_ptr && *cache_ptr)
		    cache_ptr++;
	    }

	    if (!found[j]) {
		Boolean	already_copied = False;
		Boolean have_value = False;

		if (XrmQGetSearchResource(searchList,
			rx->xrm_name, rx->xrm_class, &rawType, &value)) {
		    if (rawType != xrm_type) {
			convValue.size = rx->xrm_size;
			convValue.addr = (XPointer)(base - rx->xrm_offset - 1);
			already_copied = have_value =
			    _XtConvert(widget, rawType, &value,
				       xrm_type, &convValue, cache_ptr);
			if (cache_ptr && *cache_ptr)
			    cache_ptr++;
		    } else have_value = True;
		    if (have_value && rx->xrm_name == Qtranslations)
			do_tm_hack = True;
		}
		LOCK_PROCESS;
		if (!have_value
		    && ((rx->xrm_default_type == QImmediate)
			|| (rx->xrm_default_type == xrm_type)
			|| (rx->xrm_default_addr != NULL))) {
		    /* Convert default value to proper type */
		    xrm_default_type = rx->xrm_default_type;
		    if (xrm_default_type == QCallProc) {
#ifdef CRAY
 			if ( (int) Cjumpp != (int) Cjump)
 			    (*(XtResourceDefaultProc)
			      (((int)(rx->xrm_default_addr))<<2))(
 				 widget,-(rx->xrm_offset+1), &value);
			else
#endif
			(*(XtResourceDefaultProc)(rx->xrm_default_addr))(
			      widget,-(rx->xrm_offset+1), &value);

		    } else if (xrm_default_type == QImmediate) {
			/* XtRImmediate == XtRString for type XtRString */
			if (xrm_type == QString) {
			    value.addr = rx->xrm_default_addr;
			} else if (rx->xrm_size == sizeof(int)) {
			    int_val = (int)(long)rx->xrm_default_addr;
			    value.addr = (XPointer) &int_val;
			} else if (rx->xrm_size == sizeof(short)) {
			    short_val = (short)(long)rx->xrm_default_addr;
			    value.addr = (XPointer) &short_val;
			} else if (rx->xrm_size == sizeof(char)) {
			    char_val = (char)(long)rx->xrm_default_addr;
			    value.addr = (XPointer) &char_val;
			} else if (rx->xrm_size == sizeof(long)) {
			    long_val = (long)rx->xrm_default_addr;
			    value.addr = (XPointer) &long_val;
			} else if (rx->xrm_size == sizeof(char*)) {
			    char_ptr = (char*)rx->xrm_default_addr;
			    value.addr = (XPointer) &char_ptr;
			} else {
			    value.addr = (XPointer) &(rx->xrm_default_addr);
			}
		    } else if (xrm_default_type == xrm_type) {
			value.addr = rx->xrm_default_addr;
		    } else {
			value.addr = rx->xrm_default_addr;
			if (xrm_default_type == QString) {
			    value.size = strlen((char *)value.addr) + 1;
			} else {
			    value.size = sizeof(XtPointer);
			}
			convValue.size = rx->xrm_size;
			convValue.addr = (XPointer)(base - rx->xrm_offset - 1);
			already_copied =
			    _XtConvert(widget, xrm_default_type, &value,
				       xrm_type, &convValue, cache_ptr);
			if (!already_copied)
			    value.addr = NULL;
			if (cache_ptr && *cache_ptr)
			    cache_ptr++;
		    }
		}
		if (!already_copied) {
		    if (xrm_type == QString) {
			*((String*)(base - rx->xrm_offset - 1)) = value.addr;
		    } else {
			if (value.addr != NULL) {
			    XtMemmove(base - rx->xrm_offset - 1,
				      value.addr, rx->xrm_size);
			} else {
			    /* didn't get value, initialize to NULL... */
			    XtBZero(base - rx->xrm_offset - 1, rx->xrm_size);
			}
		    }
		}
		UNLOCK_PROCESS;

		if (typed[j]) {
		    /*
		     * This resource value was specified as a typed arg.
		     * However, the default value is being used here since
		     * type type conversion failed, so we compress the list.
		     */
		    register XtTypedArg* arg = typed_args + typed[j] - 1;
		    register int i;

		    for (i = num_typed_args - typed[j]; i > 0; i--, arg++) {
			*arg = *(arg+1);
		    }
		    num_typed_args--;
		}
	    } 
	}
	if (tm_hack)
	    widget->core.tm.current_state = NULL;
	if (tm_hack &&
	    (!widget->core.tm.translations ||
	     (do_tm_hack &&
	      widget->core.tm.translations->operation != XtTableReplace)) &&
	    XrmQGetSearchResource(searchList, QbaseTranslations,
				  QTranslations, &rawType, &value)) {
	    if (rawType != QTranslationTable) {
		convValue.size = sizeof(XtTranslations);
		convValue.addr = (XPointer)&widget->core.tm.current_state;
		(void)_XtConvert(widget, rawType, &value,
				 QTranslationTable, &convValue, cache_ptr);
		if (cache_ptr && *cache_ptr)
		    cache_ptr++;
	    } else {
		/* value.addr can be NULL see: !already_copied */
		if (value.addr)
		    *((XtTranslations *)&widget->core.tm.current_state) =
			*((XtTranslations *)value.addr);
	    }
	}
    }
    if ((Cardinal)num_typed_args != *pNumTypedArgs) *pNumTypedArgs = num_typed_args;
    if (searchList != stackSearchList) XtFree((char*)searchList);
    if (!cache_ptr)
	cache_ptr = cache_base;
    if (cache_ptr && cache_ptr != cache_ref) {
	int cache_ref_size = cache_ptr - cache_ref;
	XtCacheRef *refs = (XtCacheRef*)
	    __XtMalloc((unsigned)sizeof(XtCacheRef)*(cache_ref_size + 1));
	(void) memmove(refs, cache_ref, sizeof(XtCacheRef)*cache_ref_size );
	refs[cache_ref_size] = NULL;
	return refs;
    }
    return (XtCacheRef*)NULL;
}
Beispiel #19
0
String XtFindFile(
    _Xconst char* path,
    Substitution substitutions,
    Cardinal num_substitutions,
    XtFilePredicate predicate)
{
    char *buf, *buf1, *buf2, *colon;
    int len;
    Boolean firstTime = TRUE;

    buf = buf1 = __XtMalloc((unsigned)PATH_MAX);
    buf2 = __XtMalloc((unsigned)PATH_MAX);

    if (predicate == NULL) predicate = TestFile;

    while (1) {
        colon = (String)path;
        /* skip leading colons */
        while (*colon) {
            if (*colon != ':') break;
            colon++;
            path++;
        }
        /* now look for an un-escaped colon */
        for ( ; *colon ; colon++) {
            if (*colon == '%' && *(path+1)) {
                colon++;	/* bump it an extra time to skip %. */
                continue;
            }
            if (*colon == ':')
#ifdef __UNIXOS2__
                if (colon > (path+1))
#endif
                    break;
        }
        len = colon - path;
        if (Resolve(path, len, substitutions, num_substitutions,
                    buf, '/')) {
            if (firstTime || strcmp(buf1,buf2) != 0) {
#ifdef __UNIXOS2__
                {
                    char *bufx = (char*)__XOS2RedirRoot(buf);
                    strcpy(buf,bufx);
                }
#endif
#ifdef XNL_DEBUG
                printf("Testing file %s\n", buf);
#endif /* XNL_DEBUG */
                /* Check out the file */
                if ((*predicate) (buf)) {
                    /* We've found it, return it */
#ifdef XNL_DEBUG
                    printf("File found.\n");
#endif /* XNL_DEBUG */
                    if (buf == buf1) XtFree(buf2);
                    else XtFree(buf1);
                    return buf;
                }
                if (buf == buf1)
                    buf = buf2;
                else
                    buf = buf1;
                firstTime = FALSE;
            }
        }

        /* Nope...any more paths? */

        if (*colon == '\0') break;
        path = colon+1;
    }

    /* No file found */

    XtFree(buf1);
    XtFree(buf2);
    return NULL;
}
Beispiel #20
0
static void
AddEventHandler(
    Widget widget,
    XtPointer select_data,
    int type,
    Boolean         has_type_specifier,
    Boolean         other,
    XtEventHandler  proc,
    XtPointer	closure,
    XtListPosition  position,
    Boolean         force_new_position,
    Boolean         raw)
{
    register XtEventRec *p, **pp;
    EventMask oldMask = 0, eventMask = 0;

    if (!has_type_specifier) {
	eventMask = *(EventMask*)select_data & ~NonMaskableMask;
	if (other) eventMask |= NonMaskableMask;
	if (!eventMask) return;
    } else if (!type) return;

    if (XtIsRealized(widget) && !raw) oldMask = XtBuildEventMask(widget);

    if (raw) raw = 1;
    pp = &widget->core.event_table;
    while ((p = *pp) &&
	   (p->proc != proc || p->closure != closure || p->select == raw ||
	    has_type_specifier != p->has_type_specifier ||
	    (has_type_specifier && EXT_TYPE(p) != type)))
	pp = &p->next;

    if (!p) {		                /* New proc to add to list */
	if (has_type_specifier) {
	    p = (XtEventRec*) __XtMalloc(sizeof(XtEventRec) +
				       sizeof(XtEventRecExt));
	    EXT_TYPE(p) = type;
	    EXT_SELECT_DATA(p,0) = select_data;
	    p->mask = 1;
	    p->has_type_specifier = True;
	} else {
	    p = (XtEventRec*) __XtMalloc(sizeof(XtEventRec));
	    p->mask = eventMask;
	    p->has_type_specifier = False;
	}
	p->proc = proc;
	p->closure = closure;
	p->select = ! raw;

	if (position == XtListHead) {
	    p->next = widget->core.event_table;
	    widget->core.event_table = p;
	    pp = &widget->core.event_table;
	} else {
	    *pp = p;
	    p->next = NULL;
	}
    }
    else {
	if (force_new_position) {
	    *pp = p->next;

	    if (position == XtListHead) {
		p->next = widget->core.event_table;
		widget->core.event_table = p;
	    } else {
	       	/*
		 * Find the last element in the list.
		 */
		while (*pp)
		    pp = &(*pp)->next;
		*pp = p;
		p->next = NULL;
	    }
	}

	if (!has_type_specifier)
	    p->mask |= eventMask;
	else {
	    Cardinal i;
	    /* p->mask specifies count of EXT_SELECT_DATA(p,i) */
	    for (i = 0; i < p->mask && select_data != EXT_SELECT_DATA(p,i); )
		i++;
	    if (i == p->mask) {
		p = (XtEventRec*) XtRealloc((char*)p,
					    sizeof(XtEventRec) +
					    sizeof(XtEventRecExt) +
					    p->mask * sizeof(XtPointer));
		EXT_SELECT_DATA(p,i) = select_data;
		p->mask++;
		*pp = p;
	    }
	}
    }

    if (XtIsRealized(widget) && !raw) {
	EventMask mask = XtBuildEventMask(widget);
	Display* dpy = XtDisplay (widget);

	if (oldMask != mask)
	    XSelectInput(dpy, XtWindow(widget), mask);

	if (has_type_specifier) {
	    XtPerDisplay pd = _XtGetPerDisplay (dpy);
	    int i;
	    for (i = 0; i < pd->ext_select_count; i++) {
		if (type >= pd->ext_select_list[i].min &&
		    type <= pd->ext_select_list[i].max) {
		    CallExtensionSelector(widget, pd->ext_select_list+i, FALSE);
		    break;
		}
		if (type < pd->ext_select_list[i].min) break;
	    }
	}
    }
}
static void _MergeOptionTables(
    const XrmOptionDescRec *src1,
    Cardinal num_src1,
    const XrmOptionDescRec *src2,
    Cardinal num_src2,
    XrmOptionDescRec **dst,
    Cardinal *num_dst)
{
    XrmOptionDescRec *table, *endP;
    register XrmOptionDescRec *opt1, *whereP, *dstP;
    register const XrmOptionDescRec *opt2;
    int i1;
    Cardinal i2;
    int dst_len, order;
    Boolean found;
    enum {Check, NotSorted, IsSorted} sort_order = Check;

    *dst = table = (XrmOptionDescRec*)
	__XtMalloc( sizeof(XrmOptionDescRec) * (num_src1 + num_src2) );

    (void) memmove(table, src1, sizeof(XrmOptionDescRec) * num_src1 );
    if (num_src2 == 0) {
	*num_dst = num_src1;
	return;
    }
    endP = &table[dst_len = num_src1];
    for (opt2 = src2, i2= 0; i2 < num_src2; opt2++, i2++) {
	found = False;
	whereP = endP-1;	/* assume new option goes at the end */
	for (opt1 = table, i1 = 0; i1 < dst_len; opt1++, i1++) {
	    /* have to walk the entire new table so new list is ordered
	       (if src1 was ordered) */
	    if (sort_order == Check && i1 > 0
		&& strcmp(opt1->option, (opt1-1)->option) < 0)
		sort_order = NotSorted;
	    if ((order = strcmp(opt1->option, opt2->option)) == 0) {
		/* same option names; just overwrite opt1 with opt2 */
		*opt1 = *opt2;
		found = True;
		break;
		}
	    /* else */
	    if (sort_order == IsSorted && order > 0) {
		/* insert before opt1 to preserve order */
		/* shift rest of table forward to make room for new entry */
		for (dstP = endP++; dstP > opt1; dstP--)
		    *dstP = *(dstP-1);
		*opt1 = *opt2;
		dst_len++;
		found = True;
		break;
	    }
	    /* else */
	    if (order < 0)
		/* opt2 sorts after opt1, so remember this position */
		whereP = opt1;
	}
	if (sort_order == Check && i1 == dst_len)
	    sort_order = IsSorted;
	if (!found) {
	   /* when we get here, whereP points to the last entry in the
	      destination that sorts before "opt2".  Shift rest of table
	      forward and insert "opt2" after whereP. */
	    whereP++;
	    for (dstP = endP++; dstP > whereP; dstP--)
		*dstP = *(dstP-1);
	    *whereP = *opt2;
	    dst_len++;
	}
    }
    *num_dst = dst_len;
}
Beispiel #22
0
static void RealizeWidget(
    Widget			widget)
{
    XtValueMask			value_mask;
    XSetWindowAttributes	values;
    XtRealizeProc		realize;
    Window			window;
    Display*			display;
    String			class_name;
    Widget			hookobj;

    if (!XtIsWidget(widget) || XtIsRealized(widget)) return;
    display = XtDisplay(widget);
    _XtInstallTranslations(widget);

    ComputeWindowAttributes (widget, &value_mask, &values);
    LOCK_PROCESS;
    realize = widget->core.widget_class->core_class.realize;
    class_name = widget->core.widget_class->core_class.class_name;
    UNLOCK_PROCESS;
    if (realize == NULL)
        XtAppErrorMsg(XtWidgetToApplicationContext(widget),
                      "invalidProcedure","realizeProc",XtCXtToolkitError,
                      "No realize class procedure defined",
                      (String *)NULL, (Cardinal *)NULL);
    else {
        CALLGEOTAT(_XtGeoTrace(widget,"Call \"%s\"[%d,%d]'s realize proc\n",
                               XtName(widget),
                               widget->core.width, widget->core.height));
        (*realize) (widget, &value_mask, &values);
    }
    window = XtWindow(widget);
    hookobj = XtHooksOfDisplay(XtDisplayOfObject(widget));
    if (XtHasCallbacks(hookobj,XtNchangeHook) == XtCallbackHasSome) {
        XtChangeHookDataRec call_data;

        call_data.type = XtHrealizeWidget;
        call_data.widget = widget;
        XtCallCallbackList(hookobj,
                           ((HookObject)hookobj)->hooks.changehook_callbacks,
                           (XtPointer)&call_data);
    }
#ifndef NO_IDENTIFY_WINDOWS
    if (_XtGetPerDisplay(display)->appContext->identify_windows) {
        int len_nm, len_cl;
        char *s;

        len_nm = widget->core.name ? strlen(widget->core.name) : 0;
        len_cl = strlen(class_name);
        s = __XtMalloc((unsigned) (len_nm + len_cl + 2));
        s[0] = '\0';
        if (len_nm)
            strcpy(s, widget->core.name);
        strcpy(s + len_nm + 1, class_name);
        XChangeProperty(display, window,
                        XInternAtom(display, "_MIT_OBJ_CLASS",
                                    False),
                        XA_STRING, 8, PropModeReplace, (unsigned char *) s,
                        len_nm + len_cl + 2);
        XtFree(s);
    }
#endif
#ifdef notdef
    _XtRegisterAsyncHandlers(widget);
#endif
    /* (re)register any grabs extant in the translations */
    _XtRegisterGrabs(widget);
    /* reregister any grabs added with XtGrab{Button,Key} */
    _XtRegisterPassiveGrabs(widget);
    XtRegisterDrawable (display, window, widget);
    _XtExtensionSelect(widget);

    if (XtIsComposite (widget)) {
        Cardinal		i;
        CompositePart *cwp = &(((CompositeWidget)widget)->composite);
        WidgetList children = cwp->children;
        /* Realize all children */
        for (i = cwp->num_children; i != 0; --i) {
            RealizeWidget (children[i-1]);
        }
        /* Map children that are managed and mapped_when_managed */

        if (cwp->num_children != 0) {
            if (ShouldMapAllChildren(cwp)) {
                XMapSubwindows (display, window);
            } else {
                MapChildren(cwp);
            }
        }
    }

    /* If this is the application's popup shell, map it */
    if (widget->core.parent == NULL && widget->core.mapped_when_managed) {
        XtMapWidget (widget);
    }
} /* RealizeWidget */