Blame tests/Auto/lib/Create/widgets/mvsCreateWid.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
*/ 
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: mvsCreateWid.c /main/10 1995/07/14 11:25:25 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
/***********************************************************************
Packit b099d7
  	@(#)mvsCreateWid.c	1.31.1.1	Date:1/22/91
Packit b099d7
  	Author: TAT
Packit b099d7
	History:
Packit b099d7
	   03/30/90 SJS Add to sccs tree
Packit b099d7
	   04/02/90 SJS Change level of messages
Packit b099d7
	   05/17/90 TAT Add code to allocate widget
Packit b099d7
           06/07/90 TAT Add code to support predefined composite creation
Packit b099d7
           06/25/90 SJS check for convenience function creates
Packit b099d7
           07/17/90 SJS do not try to manage the Shell that is serving as
Packit b099d7
                        our application context.
Packit b099d7
           07/29/90 PSN free arguments at end
Packit b099d7
           08/15/90 SJS try to get the hierarchy of menus correct
Packit b099d7
           09/18/90 SJS add intelligence to determine convenience parent
Packit b099d7
                        class
Packit b099d7
	Calls:
Packit b099d7
Packit b099d7
	Summary:
Packit b099d7
            Creates the specified widget and sets up the widget info record 
Packit b099d7
            associated with it. It returns a pointer to the widget info record.
Packit b099d7
Packit b099d7
            INPUTS
Packit b099d7
                widget_class_info  - Pointer to the mvs widget class info
Packit b099d7
                                     record that you want this widget info
Packit b099d7
                                     record to point to
Packit b099d7
Packit b099d7
                parent_widget_info - Pointer to the parent widget info record
Packit b099d7
Packit b099d7
                use_common         - When set to UseCommonArgs then use the
Packit b099d7
                                     common args found in the widget class
Packit b099d7
                                     record and merge them with those listed
Packit b099d7
                                     in the args parameter following.  When
Packit b099d7
                                     set to DontUseCommonArgs then only use
Packit b099d7
                                     those args listed in the parameter
Packit b099d7
                                     following.
Packit b099d7
Packit b099d7
                args               - The additional arguments that you wish
Packit b099d7
                                     to use.
Packit b099d7
Packit b099d7
                nargs              - The number of args listed in args (above).
Packit b099d7
Packit b099d7
            OUTPUTS
Packit b099d7
                none
Packit b099d7
Packit b099d7
            RETURNS
Packit b099d7
                Pointer to newly alloc'ed widget info record.
Packit b099d7
************************************************************************/
Packit b099d7
Packit b099d7
#include "mvslib.h" 
Packit b099d7
#include "xislib.h" 
Packit b099d7
#include <AutoMessages.h>
Packit b099d7
#include <Xm/DialogS.h>
Packit b099d7
#include <Xm/MenuShell.h>
Packit b099d7
#include <Xm/NotebookP.h>	/* Possible non-portability */
Packit b099d7
Packit b099d7
extern void NormalizePixmap();
Packit b099d7
Packit b099d7
extern Widget Shell1;
Packit b099d7
Packit b099d7
MvsWidgetInfoRecord *mvsCreateManageWidget(widget_class_info, parent_info, name,
Packit b099d7
					use_common, args_in, nargs_in, manage,
Packit b099d7
					xtclass)
Packit b099d7
Packit b099d7
MvsWidgetClassInfo *widget_class_info;
Packit b099d7
MvsWidgetInfoRecord *parent_info;
Packit b099d7
char *name;
Packit b099d7
int use_common, manage;
Packit b099d7
Arg args_in[];
Packit b099d7
Cardinal nargs_in;
Packit b099d7
WidgetClass xtclass;
Packit b099d7
{
Packit b099d7
    MvsWidgetInfoRecord *widget_info, *NB_child;
Packit b099d7
    static MvsWidgetInfoRecord *default_pg_scr_info;
Packit b099d7
    XSetWindowAttributes wattr;
Packit b099d7
    int i, j, n;
Packit b099d7
    Arg args[MAX_RESOURCES];
Packit b099d7
    Cardinal nargs=0;
Packit b099d7
    Arg color_args[50];
Packit b099d7
    Cardinal num_color_args;
Packit b099d7
    MvsResourceInfoRecord *resource_info = widget_class_info->resource_info;
Packit b099d7
    int num_res_colors = widget_class_info->num_res_colors;
Packit b099d7
    short *res_color_ref = widget_class_info->res_color_ref;
Packit b099d7
    short *res_pixmap_ref = widget_class_info->res_pixmap_ref;
Packit b099d7
    Widget tmp_widget;
Packit b099d7
    Widget save_widget;
Packit b099d7
    Widget created_widget;
Packit b099d7
    MvsWidgetInfoRecord *new_info=NULL;
Packit b099d7
    MvsWidgetClassInfo *convenience_class=NULL;
Packit b099d7
    Widget child;
Packit b099d7
    static int created_page_scroller = False;
Packit b099d7
    static int orig_page_scroller_destroyed = False;
Packit b099d7
    unsigned char NBChildType;
Packit b099d7
    XisObjectRecord *PagScr_object, *parent_xis_object, *cur_xis_object;
Packit b099d7
    XisObjectRecord *prev_xis_object;
Packit b099d7
    unsigned char nb_child_type;
Packit b099d7
    Cardinal num_children;
Packit b099d7
Packit b099d7
    msg_trace ("<mvsCreateWidget> Creating Widget.\n");
Packit b099d7
Packit b099d7
    /* Nullify args[] */
Packit b099d7
    for ( i=0 ; i
Packit b099d7
	args[i].value = 0L;
Packit b099d7
	args[i].name = NULL;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    if (parent_info == NULL)
Packit b099d7
        AutoMessage(_AutoMessages[WARNMSG40]);
Packit b099d7
Packit b099d7
    for (i = 0 ; i < nargs_in ; i++) {
Packit b099d7
	args[i].name  = args_in[i].name;
Packit b099d7
	args[i].value = args_in[i].value;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    nargs = nargs_in;
Packit b099d7
Packit b099d7
    /* Allocate and setup widget info record */
Packit b099d7
    widget_info = mvsAllocWidgetInfo(widget_class_info, parent_info, 
Packit b099d7
                                     (Widget)NULL                    );
Packit b099d7
Packit b099d7
    /* Then if in generate mode, append "hard-wired" color settings */
Packit b099d7
    if (mvsGetVisualMode() == VISUAL_MODE_GENERATE_PIXMAPS) {
Packit b099d7
        num_color_args = 0;
Packit b099d7
        for (i=0; i
Packit b099d7
	    if (res_color_ref[i] >= 0) {
Packit b099d7
		XtSetArg(color_args[num_color_args],
Packit b099d7
			 resource_info[res_color_ref[i]].name,
Packit b099d7
			 widget_info->unique_color_ref[i]);
Packit b099d7
Packit b099d7
		num_color_args++;
Packit b099d7
	    }
Packit b099d7
        }
Packit b099d7
Packit b099d7
        mvsCopyReplaceArgs(widget_class_info, args, &nargs, color_args, 
Packit b099d7
			   num_color_args);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /* Create actual widget */
Packit b099d7
    widget_info->widget = (*widget_class_info->proc_CreateWidget)
Packit b099d7
             (parent_info->widget,name,args,nargs,xtclass);
Packit b099d7
Packit b099d7
    if (widget_info->widget == NULL) {
Packit b099d7
        AutoError (_AutoMessages[WARNMSG99]);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    widget_info->window = 0;
Packit b099d7
Packit b099d7
    /* 
Packit b099d7
       Manage widget if it is not a shell, or a child of a MenuShell,
Packit b099d7
       (Pulldown, Popup), also, do not manage if parent is a Dialog
Packit b099d7
       Shell (ErrorDialog, FormDialog...).
Packit b099d7
   */
Packit b099d7
Packit b099d7
    XtRealizeWidget(widget_info->widget);
Packit b099d7
Packit b099d7
    /* Manage widget if it is not a Shell */
Packit b099d7
Packit b099d7
    if((parent_info != mvsRootWidgetInfo) && (manage == TRUE)   &&
Packit b099d7
       (! XmIsMenuShell(widget_info->widget))			&&
Packit b099d7
       (! XmIsMenuShell(XtParent(widget_info->widget)))		&&
Packit b099d7
       (! XmIsDialogShell(XtParent(widget_info->widget))))
Packit b099d7
        XtManageChild (widget_info->widget);
Packit b099d7
Packit b099d7
/* used in 1.1
Packit b099d7
Packit b099d7
    XtRealizeWidget(widget_info->widget);
Packit b099d7
Packit b099d7
*/
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * If the widget being created is a Notebook, we need
Packit b099d7
     * to test if the default PageScroller has been created
Packit b099d7
     */
Packit b099d7
    if ((widget_info->parent->widget != NULL ) && 
Packit b099d7
	(mvsGetClassCode(widget_info->parent->widget) 
Packit b099d7
		== mvsXmNotebookWidgetClass)) {
Packit b099d7
	child = XtNameToWidget(widget_info->parent->widget, "PageScroller");
Packit b099d7
	/*
Packit b099d7
	 * Add the PageScroller to the object hierarchy if it
Packit b099d7
	 * has not already been added
Packit b099d7
	 */
Packit b099d7
	if (created_page_scroller == False) {
Packit b099d7
	    default_pg_scr_info = mvsSetupNewWidgetInfo(widget_info->parent,
Packit b099d7
							child,
Packit b099d7
							iXmSpinBoxWidgetClass);
Packit b099d7
	    mvsCreateChildren(default_pg_scr_info);
Packit b099d7
	    created_page_scroller = True;
Packit b099d7
	}
Packit b099d7
	/*
Packit b099d7
	 * Remove the default PageScroller if a new user defined
Packit b099d7
	 * one is being created.
Packit b099d7
	 */
Packit b099d7
	n = 0;
Packit b099d7
	XtSetArg(args[n], XmNnotebookChildType, &nb_child_type);	n++;
Packit b099d7
	XtGetValues(widget_info->widget, args, n);
Packit b099d7
	if ((nb_child_type == XmPAGE_SCROLLER) && 
Packit b099d7
	    (orig_page_scroller_destroyed == False) &&
Packit b099d7
	    (created_page_scroller == True))  {
Packit b099d7
	    /*
Packit b099d7
	     * Destroy the default PageScroller in the mvs heirarchy
Packit b099d7
	     */
Packit b099d7
	    mvsDestroyWidget(default_pg_scr_info,DontCheckCallbacks);
Packit b099d7
	    orig_page_scroller_destroyed = True;
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /* 
Packit b099d7
	For Pixmap resources do the following:
Packit b099d7
Packit b099d7
	1) Find proper background and foreground pixel values. If
Packit b099d7
	   you are recording this will be the unique color info of
Packit b099d7
	   the widget. If you are playing back, get the forteground
Packit b099d7
	   and background from the parent (if foreground and background
Packit b099d7
	   is not specified in the argument list).
Packit b099d7
Packit b099d7
	2) Find out if a pixmap resource is present.
Packit b099d7
Packit b099d7
	3) If pixmap is present get image and do a XPutPixel
Packit b099d7
	   with first pixel being the background pixel and the
Packit b099d7
	   second pixel being the foreground pixel.
Packit b099d7
Packit b099d7
	This makes the pixmap contain the background and foreground
Packit b099d7
	color of the widget (if you are in playback), or the chosen
Packit b099d7
	color (if you are in record mode).
Packit b099d7
Packit b099d7
    */
Packit b099d7
Packit b099d7
    /* Get the Pixmap resources and see if they need to be normalized.
Packit b099d7
       They can have been set through the resource file, in that case 
Packit b099d7
       add them to the arg list so that we don't reload them when 
Packit b099d7
       loading the default resources */
Packit b099d7
Packit b099d7
    
Packit b099d7
    for (i =0; i< num_res_colors; i++) {
Packit b099d7
	if (res_pixmap_ref[i] >= 0) {
Packit b099d7
	    Arg pixmap_args[1];
Packit b099d7
	    Pixmap value_pixmap;
Packit b099d7
Packit b099d7
	    /* Check if this pixmap needs to be normalized */
Packit b099d7
	    
Packit b099d7
	    XtSetArg(pixmap_args[0],
Packit b099d7
		     resource_info[res_pixmap_ref[i]].name,
Packit b099d7
		     &value_pixmap);
Packit b099d7
	    
Packit b099d7
	    XtGetValues(widget_info->widget, pixmap_args, 1);
Packit b099d7
	    
Packit b099d7
	    if ((value_pixmap != XmUNSPECIFIED_PIXMAP) &&
Packit b099d7
		(value_pixmap != None)) {
Packit b099d7
Packit b099d7
		/* Normalize the pixmap only when in record or compare mode */
Packit b099d7
		
Packit b099d7
		if (mvsGetVisualMode() != VISUAL_MODE_DONT_CHECK)
Packit b099d7
		    NormalizePixmap(widget_info, value_pixmap);
Packit b099d7
		
Packit b099d7
		if (strcmp(resource_info[res_pixmap_ref[i]].name, 
Packit b099d7
			       "backgroundPixmap") == 0) {
Packit b099d7
	           
Packit b099d7
		    Mask    window_mask;
Packit b099d7
		    XSetWindowAttributes attributes;
Packit b099d7
Packit b099d7
		    window_mask = CWBackPixmap;
Packit b099d7
		    attributes.background_pixmap = value_pixmap;
Packit b099d7
						 
Packit b099d7
		    XChangeWindowAttributes(mvsDisplay, 
Packit b099d7
					    XtWindow(widget_info->widget), 
Packit b099d7
					    window_mask, &attributes);
Packit b099d7
		}
Packit b099d7
Packit b099d7
		/* Check if this needs to be added to the list of args */
Packit b099d7
Packit b099d7
		for (j = 0; j < nargs && 
Packit b099d7
		    strcmp(args[j].name,resource_info[res_pixmap_ref[i]].name);
Packit b099d7
		    j++);
Packit b099d7
Packit b099d7
		if (j == nargs) 
Packit b099d7
		    mvsCopyReplace1Arg(widget_class_info, args, &nargs, 
Packit b099d7
				       pixmap_args[0].name, value_pixmap);
Packit b099d7
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
Packit b099d7
    /* Set resources to default values */
Packit b099d7
    mvsSetResourcesToDefaults(widget_info,args,nargs);
Packit b099d7
    mvsSetIntToDefaults(widget_info);
Packit b099d7
Packit b099d7
    /* Store arg values in local copy of resources */
Packit b099d7
    if (nargs > 0) {
Packit b099d7
        if (mvsGetVisualMode() == VISUAL_MODE_GENERATE_PIXMAPS) {
Packit b099d7
            /* Make mvsSetLocalValues store color arguments locally */
Packit b099d7
            mvsSetVisualMode(VISUAL_MODE_DONT_CHECK);
Packit b099d7
            mvsSetLocalValues(widget_info,args,&nargs);
Packit b099d7
            mvsSetVisualMode(VISUAL_MODE_GENERATE_PIXMAPS);
Packit b099d7
        }
Packit b099d7
        else
Packit b099d7
            mvsSetLocalValues(widget_info,args,&nargs);
Packit b099d7
    }
Packit b099d7
Packit b099d7
Packit b099d7
    /* See if this was some sort of Convenience function that creates more   */
Packit b099d7
    /* than just the widget we asked for. If it is, then it is necessary to  */
Packit b099d7
    /* get all the new widgets and their infos into our widget hierarchy.    */
Packit b099d7
    /* See if children were created and alloc their widget_infos and colors. */
Packit b099d7
Packit b099d7
    tmp_widget = XtParent(widget_info->widget);
Packit b099d7
    if( tmp_widget != parent_info->widget) {
Packit b099d7
Packit b099d7
        save_widget = tmp_widget; 
Packit b099d7
        while ( (tmp_widget != NULL) &&
Packit b099d7
              (tmp_widget != parent_info->widget)) {
Packit b099d7
Packit b099d7
            save_widget = tmp_widget; 
Packit b099d7
            tmp_widget = XtParent(tmp_widget);
Packit b099d7
        }
Packit b099d7
        if(tmp_widget == NULL) {
Packit b099d7
            /* The parent we thought we had is nowhere in the ancestor chain
Packit b099d7
               above the parent we got. Look elsewhere for the widget
Packit b099d7
               in the hierarchy. Specifically, popup & pulldown menus
Packit b099d7
               look for the shell above them when they are children of
Packit b099d7
               a popup or pulldown.
Packit b099d7
            */
Packit b099d7
            tmp_widget = XtParent(widget_info->widget);
Packit b099d7
            save_widget = widget_info->widget;
Packit b099d7
            while (tmp_widget != NULL) {
Packit b099d7
                if(mvsWidgetToWidgetInfo(tmp_widget) !=
Packit b099d7
                                                  (MvsWidgetInfoRecord *)NULL) {                    parent_info = mvsWidgetToWidgetInfo(tmp_widget);
Packit b099d7
                    break;
Packit b099d7
                }
Packit b099d7
                save_widget = tmp_widget;
Packit b099d7
                tmp_widget = XtParent(tmp_widget);
Packit b099d7
            }
Packit b099d7
        }
Packit b099d7
        if(tmp_widget == NULL) {
Packit b099d7
        /* FUTURE: ADD IN call to determine class code. Use the return instead
Packit b099d7
           of blindly using iXmDialogShellWidgetClass.
Packit b099d7
        */
Packit b099d7
            AutoMessage(_AutoMessages[WARNMSG41]);
Packit b099d7
            new_info = mvsSetupNewWidgetInfo(mvsRootWidgetInfo,save_widget,
Packit b099d7
                                             iXmDialogShellWidgetClass);
Packit b099d7
        }
Packit b099d7
        else {
Packit b099d7
          /* The widget we are creating is not really created as a child   */
Packit b099d7
          /* of the requested parent. Rather, it has a parent which is the */
Packit b099d7
          /* child of the requested parent. (It is also possible that the  */
Packit b099d7
          /* parent is a widget somewhere else in the widget hierarchy)    */
Packit b099d7
          /* We basically, free the old widget info and construct a new    */
Packit b099d7
          /* one, including the dialog shell above (if a dialog shell is   */
Packit b099d7
          /* created. Popup & Pulldown can share common ancestor shells).  */
Packit b099d7
          /* The most important thing is to make sure that all widgets     */
Packit b099d7
          /* that were created end up in the hierarchy in a location that  */
Packit b099d7
          /* reflects the parent/child relations as seen by the user.      */
Packit b099d7
          /* The real window layout is handled by our object hierarchy.    */
Packit b099d7
Packit b099d7
            created_widget = widget_info->widget;
Packit b099d7
            mvsFreeWidgetInfo(widget_info);
Packit b099d7
Packit b099d7
            /* When the created widget & the saved widget are equal, it    */
Packit b099d7
            /* means that the widget we created was re-parented to         */
Packit b099d7
            /* somewhere else in the hierarchy. Thus, do not treat this    */
Packit b099d7
            /* case as a "Convenience" parent.                             */
Packit b099d7
Packit b099d7
            if(created_widget != save_widget) {
Packit b099d7
                new_info = mvsWidgetToWidgetInfo(save_widget);
Packit b099d7
                if(new_info == (MvsWidgetInfoRecord *)NULL) {
Packit b099d7
                    switch(mvsGetClassCode(save_widget)) {
Packit b099d7
                        case mvsXmDialogShellWidgetClass:
Packit b099d7
                            convenience_class = iXmDialogShellWidgetClass;
Packit b099d7
                            break;
Packit b099d7
                        case mvsXmMenuShellWidgetClass:
Packit b099d7
                            convenience_class = iXmMenuShellWidgetClass;
Packit b099d7
                            break;
Packit b099d7
                        default:
Packit b099d7
                            convenience_class = iXmScrolledWindowWidgetClass;
Packit b099d7
                            break;
Packit b099d7
                    }
Packit b099d7
                    new_info = mvsSetupNewWidgetInfo(parent_info,save_widget,
Packit b099d7
                                                     convenience_class);
Packit b099d7
                }
Packit b099d7
            }
Packit b099d7
            else {
Packit b099d7
                new_info = parent_info;
Packit b099d7
            }
Packit b099d7
Packit b099d7
            /* Allocate and setup widget info record */
Packit b099d7
Packit b099d7
            widget_info = mvsAllocWidgetInfo(widget_class_info, new_info, 
Packit b099d7
                                                 (Widget)NULL);
Packit b099d7
            widget_info->widget = created_widget;
Packit b099d7
            widget_info->window = 0;
Packit b099d7
            if(created_widget != save_widget) {
Packit b099d7
                widget_info->c_parent = True;
Packit b099d7
            }
Packit b099d7
            else {
Packit b099d7
                widget_info->c_parent = False;
Packit b099d7
            }
Packit b099d7
Packit b099d7
	    /* Set resources to default values */
Packit b099d7
Packit b099d7
            mvsSetResourcesToDefaults(widget_info,args,nargs);
Packit b099d7
            mvsSetIntToDefaults(widget_info);
Packit b099d7
Packit b099d7
            /* Store arg values in local copy of resources */
Packit b099d7
Packit b099d7
            if (nargs > 0) {
Packit b099d7
                if (mvsGetVisualMode() == VISUAL_MODE_GENERATE_PIXMAPS) {
Packit b099d7
                    /* Make mvsSetLocalValues store color arguments locally */
Packit b099d7
                    mvsSetVisualMode(VISUAL_MODE_DONT_CHECK);
Packit b099d7
                    mvsSetLocalValues(widget_info,args,&nargs);
Packit b099d7
                    mvsSetVisualMode(VISUAL_MODE_GENERATE_PIXMAPS);
Packit b099d7
                }
Packit b099d7
                else
Packit b099d7
                    mvsSetLocalValues(widget_info,args,&nargs);
Packit b099d7
            }
Packit b099d7
        }
Packit b099d7
    } /* End if(tmp_widget != parent_info->widget) */
Packit b099d7
Packit b099d7
    /* Create all the children of the widget we just created. We are    */
Packit b099d7
    /* *NOT* doing the parents of Convenience created widgets here.     */
Packit b099d7
    /* The reason is that right now we are unsure of the types of the   */
Packit b099d7
    /* chilren involved. This could possibly be improved upon.          */
Packit b099d7
Packit b099d7
    if (widget_info->parent != NULL) {
Packit b099d7
Packit b099d7
        if ((mvsGetClassCode(widget_info->widget) == mvsXmTextWidgetClass ||
Packit b099d7
       	     mvsGetClassCode(widget_info->widget) == mvsXmListWidgetClass) &&
Packit b099d7
	     mvsGetClassCode(XtParent(widget_info->widget)) == 
Packit b099d7
						mvsXmScrolledWindowWidgetClass)
Packit b099d7
    		mvsCreateChildren(widget_info->parent);
Packit b099d7
    }
Packit b099d7
		
Packit b099d7
    mvsCreateChildren(widget_info);
Packit b099d7
    
Packit b099d7
    /* Set up callback checking code if in behavior test set */
Packit b099d7
Packit b099d7
    XSync(mvsDisplay,0);
Packit b099d7
Packit b099d7
    if (widget_info->c_parent)
Packit b099d7
        new_info->window = XtWindowOfObject(new_info->widget);
Packit b099d7
Packit b099d7
    widget_info->window = XtWindowOfObject(widget_info->widget);
Packit b099d7
    xisCreateWidget(widget_info->widget);
Packit b099d7
Packit b099d7
    /* Make sure that window manager recognizes color map of this widget */
Packit b099d7
    wattr.colormap = mvsVisualInfo.colormap_id;
Packit b099d7
    XChangeWindowAttributes(mvsDisplay, XtWindowOfObject(widget_info->widget), 
Packit b099d7
                            CWColormap,&wattr);
Packit b099d7
Packit b099d7
    /* Process all events through expose event */
Packit b099d7
    xisProcessEvents(NULL, 0);
Packit b099d7
    xisUpdateObjectAttributes();
Packit b099d7
Packit b099d7
    /* Return pointer to widget info record */
Packit b099d7
    return(widget_info);
Packit b099d7
Packit b099d7
} /* End mvsCreateWidget() */
Packit b099d7
Packit b099d7

Packit b099d7
/***********************************************************************
Packit b099d7
  	Author: PSN
Packit b099d7
	History:
Packit b099d7
           08/15/90 PSN add manage/unmanage
Packit b099d7
	Summary:
Packit b099d7
		Create & manage widget
Packit b099d7
***********************************************************************/
Packit b099d7
Packit b099d7
MvsWidgetInfoRecord *mvsCreateWidget(widget_class_info, parent_info, name,
Packit b099d7
				     use_common, args_in, nargs_in, xtclass)
Packit b099d7
Packit b099d7
MvsWidgetClassInfo *widget_class_info;
Packit b099d7
MvsWidgetInfoRecord *parent_info;
Packit b099d7
char *name;
Packit b099d7
int use_common;
Packit b099d7
Arg args_in[];
Packit b099d7
Cardinal nargs_in;
Packit b099d7
WidgetClass xtclass;
Packit b099d7
{
Packit b099d7
/**Debug**
Packit b099d7
    return(mvsCreateManageWidget(widget_class_info, parent_info, name,
Packit b099d7
    				 use_common, args_in, nargs_in, TRUE));	
Packit b099d7
**/
Packit b099d7
    return(mvsCreateManageWidget(widget_class_info, parent_info, name,
Packit b099d7
    				 use_common, args_in, nargs_in, TRUE, xtclass));	
Packit b099d7
Packit b099d7
} /* End mvsCreateWidget() */
Packit b099d7
Packit b099d7
/***********************************************************************
Packit b099d7
  	Author: PSN
Packit b099d7
	History:
Packit b099d7
           08/15/90 PSN add manage/unmanage
Packit b099d7
	Summary:
Packit b099d7
		Create but do not manage widget
Packit b099d7
***********************************************************************/
Packit b099d7
Packit b099d7
MvsWidgetInfoRecord *mvsCreateNotManageWidget(widget_class_info, parent_info, 
Packit b099d7
					 name, use_common, args_in, nargs_in,
Packit b099d7
					 xtclass)
Packit b099d7
Packit b099d7
MvsWidgetClassInfo *widget_class_info;
Packit b099d7
MvsWidgetInfoRecord *parent_info;
Packit b099d7
char *name;
Packit b099d7
int use_common;
Packit b099d7
Arg args_in[];
Packit b099d7
Cardinal nargs_in;
Packit b099d7
WidgetClass xtclass;
Packit b099d7
{
Packit b099d7
    return(mvsCreateManageWidget(widget_class_info, parent_info, name,
Packit b099d7
    				 use_common, args_in, nargs_in, FALSE,
Packit b099d7
				 xtclass));
Packit b099d7
Packit b099d7
} /* End mvsCreateNotManageWidget() */
Packit b099d7
Packit b099d7
Packit b099d7
void NormalizePixmap(widget_info, value_pixmap)
Packit b099d7
MvsWidgetInfoRecord *widget_info;
Packit b099d7
Pixmap value_pixmap;
Packit b099d7
{
Packit b099d7
    Arg color_args[10];
Packit b099d7
    Cardinal num_color_args;
Packit b099d7
    Pixel foreground, background;
Packit b099d7
    Window root;
Packit b099d7
    int pix_x, pix_y, x, y;
Packit b099d7
    unsigned int pix_width, pix_height, pix_border, depth;
Packit b099d7
    XImage *pix_image = NULL;
Packit b099d7
    Pixel pixel1, pixel2;
Packit b099d7
    GC gc;
Packit b099d7
    
Packit b099d7
    if (XtParent(widget_info->widget) == NULL) {
Packit b099d7
	printf("mvsCreateWidget: NULL parent in visuals\n");
Packit b099d7
	exit(0);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    num_color_args = 0;
Packit b099d7
    XtSetArg(color_args[num_color_args], XmNbackground, &background); 
Packit b099d7
    num_color_args++;
Packit b099d7
    XtSetArg(color_args[num_color_args], XmNforeground, &foreground); 
Packit b099d7
    num_color_args++;
Packit b099d7
    if (XmIsGadget(widget_info->widget) && 
Packit b099d7
	(mvsGetClassCode(widget_info->widget) != mvsXmIconGadgetClass)) 
Packit b099d7
	if (XtParent(widget_info->widget) != Shell1)
Packit b099d7
	    XtGetValues(XtParent(widget_info->widget), color_args, 
Packit b099d7
			num_color_args);
Packit b099d7
	else
Packit b099d7
	    AutoMessage(_AutoMessages[WARNMSG100]);
Packit b099d7
    else
Packit b099d7
	XtGetValues(widget_info->widget, color_args, num_color_args);
Packit b099d7
Packit b099d7
    if (! XGetGeometry(mvsDisplay, value_pixmap, &root,
Packit b099d7
		       &pix_x, &pix_y, &pix_width, &pix_height,
Packit b099d7
		       &pix_border, &depth)) {
Packit b099d7
	printf("mvsCreateWid: Bad return from XGetGeometry\n");
Packit b099d7
	exit(0);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    pix_image = XGetImage(mvsDisplay, value_pixmap, 0, 0, pix_width,
Packit b099d7
			  pix_height, AllPlanes, ZPixmap);
Packit b099d7
Packit b099d7
    pixel1 = XGetPixel(pix_image,0,0);
Packit b099d7
Packit b099d7
    /* Don't assume pixmaps are only using 2 colors.
Packit b099d7
       Temporary fix, we'll need to improve it for checking real colors.
Packit b099d7
     */
Packit b099d7
Packit b099d7
    for (y=0; y
Packit b099d7
	for (x=0; x
Packit b099d7
	    if (XGetPixel(pix_image,x,y) != pixel1) {
Packit b099d7
		pixel2 = XGetPixel(pix_image,x,y);
Packit b099d7
		break;
Packit b099d7
	    }
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    for (y=0; y
Packit b099d7
	for (x=0; x
Packit b099d7
	    if (XGetPixel(pix_image,x,y) == pixel1) 
Packit b099d7
		XPutPixel(pix_image, x, y, background);
Packit b099d7
	    else
Packit b099d7
		/*  if (XGetPixel(pix_image,x,y) == pixel2)    */
Packit b099d7
		XPutPixel(pix_image, x, y, foreground);
Packit b099d7
	}
Packit b099d7
    }
Packit b099d7
Packit b099d7
    gc = XCreateGC (mvsDisplay, value_pixmap, 0, (XGCValues *)NULL);
Packit b099d7
Packit b099d7
    XPutImage(mvsDisplay, value_pixmap, gc, pix_image,  0, 0,
Packit b099d7
		  0, 0, pix_width, pix_height);
Packit b099d7
Packit b099d7
    XFreeGC(mvsDisplay, gc);
Packit b099d7
Packit b099d7
    XDestroyImage(pix_image);
Packit b099d7
}