Beispiel #1
0
/*ARGSUSED*/
static void 
InitializePrehook(Widget req,	/* unused */
		  Widget new_w,
		  ArgList args,
		  Cardinal *num_args)
{
  XmExtObjectClass ec = (XmExtObjectClass) XtClass(new_w);
  XmBaseClassExt  *wcePtr = _XmGetBaseClassExtPtr(ec, XmQmotif);
  
  if ((*wcePtr)->use_sub_resources)
    {
      /*
       * Get a uncompiled resource list to use with XtGetSubresources.
       * We can't do this in ClassPartInitPosthook because Xt doesn't
       * set class_inited at the right place and thereby mishandles
       * the XtGetResourceList call.
       */
      _XmProcessLock();
      if ((*wcePtr)->ext_resources == NULL)
	{
	  ec->object_class.resources = (*wcePtr)->compiled_ext_resources;
	  ec->object_class.num_resources = (*wcePtr)->num_ext_resources;
	  
	  XtGetResourceList((WidgetClass) ec,
			    &((*wcePtr)->ext_resources),
			    &((*wcePtr)->num_ext_resources));
	}

      XtGetSubresources(XtParent(new_w),
			(XtPointer)new_w,
			NULL, NULL,
			(*wcePtr)->ext_resources,
			(*wcePtr)->num_ext_resources,
			args, *num_args);
      _XmProcessUnlock();
    }
}
Beispiel #2
0
void
XmuWnFetchResources(XmuWidgetNode *node, Widget toplevel,
		    XmuWidgetNode *topnode)
{
    Widget dummy;
    XmuWidgetNode *wn;

    if (node->have_resources) return;

    dummy = XtCreateWidget (node->label, XmuWnClass(node), toplevel,
			    NULL, ZERO);
    if (dummy) XtDestroyWidget (dummy);


    /*
     * walk up tree geting resources; since we've instantiated the widget,
     * we know that all of our superclasses have been initialized
     */
    for (wn = node; wn && !wn->have_resources; wn = wn->superclass) {
	XtGetResourceList (XmuWnClass(wn), &wn->resources, &wn->nresources);
	if (wn->resources) {
	    qsort ((char *) wn->resources, wn->nresources,
		   sizeof(XtResource), compare_resource_entries);
	}
	wn->resourcewn = (XmuWidgetNode **) XtCalloc (wn->nresources,
						  sizeof (XmuWidgetNode *));
	if (!wn->resourcewn) {
	    fprintf (stderr,
		     "%s:  unable to calloc %d %lu byte widget node ptrs\n",
		     "XmuWnFetchResources",wn->nresources,
		     sizeof (XmuWidgetNode *));
	    exit (1);
	}

	XtGetConstraintResourceList (XmuWnClass(wn), &wn->constraints,
				     &wn->nconstraints);
	if (wn->constraints) {
	    qsort ((char *) wn->constraints, wn->nconstraints,
		   sizeof(XtResource), compare_resource_entries);
	}
	wn->constraintwn = (XmuWidgetNode **)
	  XtCalloc (wn->nconstraints, sizeof (XmuWidgetNode *));
	if (!wn->constraintwn) {
	    fprintf (stderr,
		     "%s:  unable to calloc %d %d byte widget node ptrs\n",
		     "XmuWnFetchResources", wn->nconstraints,
		     (int)sizeof (XmuWidgetNode *));
	    exit (1);
	}

	wn->have_resources = True;
	if (wn == topnode) break;
    }


    /*
     * Walk up tree removing all resources that appear in superclass; we can
     * mash the resource list in place since it was copied out of widget.
     */
    for (wn = node; wn; wn = wn->superclass) {
	mark_resource_owner (wn);
	if (wn == topnode) break;
    }

    return;
}
Beispiel #3
0
static void restore_state_from_file(
Widget	topl,
FILE	*fp)
{
    char		buf[512];
    String		t_name = XtName( topl );
    Boolean		resize_topl=False;

    /* read and set resources */
    while( fgets( buf, 512, fp ) != NULL ){

	char		w_name[128], r_name[64];
	Widget		widget;
	XtResourceList	rsc_list;
	Cardinal	num_rsc;
	int		i;

	/* check for empty string or comment line */
	if( strlen(buf) == 0 || buf[0] == '!' )
	    continue;

	/* extract widget name, resource name and value */
	if( sscanf(buf, " %[^,:,\n]: %[^,\n]", w_name, buf) < 2 )
	    continue;
	if( (int) strlen(w_name) < 1 )
	    continue;
	for(i=(int)strlen(w_name)-1; i > 0 && w_name[i] != '.'
	    && w_name[i] != '*'; i--){}
	w_name[i] = '\0';
	strcpy( &r_name[0], &w_name[i+1] );

	/* get the widget - check for topl widget name */
	switch( w_name[0] ){
	case '\0':
	    widget = topl;
	    break;
	case '.':
	case '*':
	    if( strcmp(&(w_name[1]), t_name) == 0 )
		widget = topl;
	    else if( strncmp(&(w_name[1]), t_name, strlen(t_name)) == 0 ){
		String str = (String) &(w_name[strlen(t_name)+1]);
		if( (widget = XtNameToWidget(topl, str)) == NULL )
		    continue;
	    }
	    else if( (widget = XtNameToWidget(topl, w_name)) == NULL )
		continue;
	    break;
	default:
	    if( strcmp(&w_name[0], t_name) == 0 )
		widget = topl;
	    else if( strncmp(&w_name[0], t_name, strlen(t_name)) == 0 ){
		String str = (String) &(w_name[strlen(t_name)]);
		if( (widget = XtNameToWidget(topl, str)) == NULL )
		    continue;
	    }
	    else if( (widget = XtNameToWidget(topl, w_name)) == NULL )
		continue;
	    break;
	}

	/* convert and set the value */
	XtGetResourceList( XtClass(widget), &rsc_list, &num_rsc );
	for(i=0; i < num_rsc; i++){
	    if( strcmp( r_name, rsc_list[i].resource_name ) == 0 ){
		XrmValue	from, to;

		from.size = (int) strlen( buf );
		from.addr = (caddr_t) buf;

		to.addr = NULL;

		/* some string resources are not copied, eg geometry,
		   therefore allocate space for each string. This is
		   probably a small memory leak */
		if( strcmp(rsc_list[i].resource_type, XtRString) == 0 ){
		    String	str = (String) malloc(strlen(buf) + 4);
		    strcpy(str, buf);
		    XtVaSetValues( widget, r_name, str, NULL );
		}
		else if( XtConvertAndStore( widget, XtRString, &from,
					   rsc_list[i].resource_type, &to) ){

		    /* check for resize of top-level widget */
		    if( widget == topl &&
		       (!strcmp(r_name, XmNheight) ||
			!strcmp(r_name, XmNwidth)) )
		    {
			resize_topl = True;
		    }

		    /* set the resource value */
		    switch( rsc_list[i].resource_size ){
		    case 1:
			XtVaSetValues( widget, r_name,
				      *((unsigned char *) to.addr), NULL );
			break;
		    case 2:
			XtVaSetValues( widget, r_name,
				      *((unsigned short *) to.addr), NULL );
			break;
		    case 4:
			XtVaSetValues( widget, r_name,
				      *((unsigned int *) to.addr), NULL );
			break;
		    }
		}
		break;
	    }
	}
	XtFree( (char *)rsc_list );
    }

    /* check top-level */
    if( resize_topl == True ){
	WidgetList	children;
	Cardinal	numChildren;
	XtVaGetValues( topl, XmNchildren, &children,
		      XmNnumChildren, &numChildren, NULL);
	XtUnmanageChildren(children, numChildren);
	XtManageChildren(children, numChildren);
    }
    return;
}