Exemple #1
0
void x_create_colormap( char *name, unsigned char r[256], unsigned char g[256], unsigned char b[256] )
{
        Colormap        orig_colormap, new_colormap;
        Display         *display;
        int             i, status=0, enabled;
        XColor          *color;
        unsigned long   plane_masks[1], pixels[1];
        Cmaplist        *cmaplist, *cml;
        static int      first_time_through = FALSE;
	char		sl_cmap_name[1020];
	Stringlist	*sl;

	/*
	printf( "----------------------\n" );
	printf( "in x_create_colormap, here is state stringlist:\n" );
	stringlist_dump( read_in_state );
	printf( "----------------------\n" );
	*/

        display = XtDisplay( topLevel );

        if( colormap_list == NULL )
                first_time_through = TRUE;
        else
                first_time_through = FALSE;

        /* Make a new Cmaplist structure, and link it into the list */
        new_cmaplist( &cmaplist );
        cmaplist->name = (char *)malloc( (strlen(name)+1)*sizeof(char) );
        strcpy( cmaplist->name, name );

	/* Figure out if, according to our saved state, this colormap
	 * should be enabled or not. If we don't find this colormap 
	 * in the list, default to 'Enabled' 
	 */
	if( strlen(name) > 1000 ) {
		fprintf( stderr, "Error, colormap name is too long: %s\n", name );
		exit(-1);
		}
	snprintf( sl_cmap_name, 1018, "CMAP_%s", name );
	sl = stringlist_match_string_exact( read_in_state, sl_cmap_name );
	if( sl == NULL ) {
		/* People seem to find this message confusing
		printf( "did not find color map %s in state file: enabling by default\n", sl_cmap_name );
		*/
	 	cmaplist->enabled = 1;
		}
	else
		{
		if( sl->sltype != SLTYPE_INT ) {
			fprintf( stderr, "Error, saved TYPE for colormap %s is not an int\n", sl_cmap_name );
			enabled = 1;
			}
		else
			enabled = *((int *)(sl->aux));
		cmaplist->enabled = enabled;
		}

        if( first_time_through )
                colormap_list = cmaplist;
        else
                {
                cml = colormap_list;
                while( cml->next != NULL )
                        cml = cml->next;
                cml->next      = cmaplist;
                cmaplist->prev = cml;
                }

        if( first_time_through ) {

                /* First time through, allocate the read/write entries in the colormap.
                 * We always do ten more than the number of colors requested so that
                 * black can indicate 'fill_value' entries, and the other color entries
                 * (which are the window elements) can be colored as desired.
                 */
                current_colormap_list = cmaplist;

                /* TrueColor device */
                if( options.display_type == TrueColor ) {
                        for( i=0; i<(options.n_colors+options.n_extra_colors); i++ ) {
                                (cmaplist->color_list+i)->pixel = (long)i;
                                *(cmaplist->pixel_transform+i)  = (ncv_pixel)i;
                                }
                        }

                /* Shared colormap, PseudoColor device */
                if( (!options.private_colormap) && (options.display_type == PseudoColor) ) {
                        /* Try the standard colormap, and see if
                         * it has enough available colorcells.
                         */
                        orig_colormap    = DefaultColormap( display, 0 );
                        current_colormap = orig_colormap;
                        i      = 0;
                        status = 1;
                        while( (i < (options.n_colors+options.n_extra_colors)) && (status != 0) ) {
                                status = XAllocColorCells( display, orig_colormap, True,
                                        plane_masks, 0, pixels, 1 );
                                (cmaplist->color_list+i)->pixel = *pixels;
                                *(cmaplist->pixel_transform+i)   = (ncv_pixel)*pixels;
                                i++;
                                }
                        }

                /* standard colormap failed for PseudoColor, allocate a private colormap */
                if( (options.display_type == PseudoColor) &&
                                ((status == 0) || (options.private_colormap)) ) {
                        printf( "Using private colormap...\n" );
                        new_colormap  = XCreateColormap(
                                display,
                                RootWindow( display, DefaultScreen( display ) ),
                                XDefaultVisualOfScreen( XtScreen( topLevel ) ),
                                AllocNone );
                        current_colormap = new_colormap;
                        for( i=0; i<(options.n_colors+options.n_extra_colors); i++ )
                                {
                                status = XAllocColorCells( display, new_colormap,
                                                True, plane_masks,
                                                0, pixels, 1 );
                                if( status == 0 ) {
                                        fprintf( stderr, "ncview: x_create_colormap: couldn't allocate \n" );
                                        fprintf( stderr, "requested number of colorcells in a private colormap\n" );
                                        fprintf( stderr, "Try requesting fewer colors with the -nc option\n" );
                                        exit( -1 );
                                        }
                                (cmaplist->color_list+i)->pixel = *pixels;
                                *(cmaplist->pixel_transform+i)  = (ncv_pixel)*pixels;
                                }
                        }
                pixel_transform = cmaplist->pixel_transform;
                }
        else
                {
                /* if NOT the first time through, just set the pixel values */
                for( i=0; i<options.n_colors+options.n_extra_colors; i++ ) {
                        (cmaplist->color_list+i)->pixel =
                                (current_colormap_list->color_list+i)->pixel;
                        *(cmaplist->pixel_transform+i)   =
                                (ncv_pixel)(current_colormap_list->color_list+i)->pixel;
                        }
                }

        /* Set the first ten colors including black, the color used for "Fill_Value" entries */
        for( i=0; i<options.n_extra_colors; i++ ) {
                color        = cmaplist->color_list+i;
                color->flags = DoRed | DoGreen | DoBlue;
                color->red   = 256*(unsigned int)255;
                color->green = 256*(unsigned int)255;
                color->blue  = 256*(unsigned int)255;
                }
        color        = cmaplist->color_list+1;
        color->flags = DoRed | DoGreen | DoBlue;
        color->red   = 256*(unsigned int)0;
        color->green = 256*(unsigned int)0;
        color->blue  = 256*(unsigned int)0;

        for( i=options.n_extra_colors; i<options.n_colors+options.n_extra_colors; i++ )
                {
                color        = cmaplist->color_list+i;
                color->flags = DoRed | DoGreen | DoBlue;
                color->red   = (unsigned int)
                                (256*interp( i-options.n_extra_colors, options.n_colors, r, 256 ));
                color->green = (unsigned int)
                                (256*interp( i-options.n_extra_colors, options.n_colors, g, 256 ));
                color->blue  = (unsigned int)
                                (256*interp( i-options.n_extra_colors, options.n_colors, b, 256 ));
                }

        if( (options.display_type == PseudoColor) && first_time_through )
                XStoreColors( XtDisplay(topLevel), current_colormap, current_colormap_list->color_list,
                        options.n_colors+options.n_extra_colors );
}
Exemple #2
0
/*********************************************************************
 * Function: CreateDA
 *
 *    CreateDA creates a Text Graphic area with the appropriate scroll bars.
 *
 *********************************************************************/
static XtPointer
HelpCreateDA(
    Widget	 parent,
    char	*name,
    short	 vert_flag,
    short	 horz_flag,
    Boolean	 traversal_flag,
    _DtCvValue   honor_size,
    _DtCvRenderType render_type,
    int          rows,
    int          columns,
    unsigned short media_resolution,
    void	(*hyperTextCB)(),
    void	(*resizeCB)(),
    int		(*exec_ok_routine)(),
    XtPointer	 client_data,
    XmFontList	 default_list )
{
    DtHelpDispAreaStruct *pDAS;
    DAArgs DA_args;
    Arg args[20];
    int n;
    int maxFontAscent;
    int maxFontDescent;
    int maxFontCharWidth;
  
    short margin_width;
    short margin_height;
    short shadowThick, highThick;
    Dimension hBarHeight = 0;
    Dimension vBarWidth  = 0;
    Dimension width;
    Boolean   value;

    Widget form;
    Display *dpy = XtDisplay(parent);
    Screen      *retScr = XtScreen(parent);
    int          screen = XScreenNumberOfScreen(retScr);

    Colormap colormap;

    Pixmap		 tile;
    XGCValues		 gcValues;
    unsigned long	 gcMask;

    unsigned long char_width;

    Atom xa_ave_width;

    XFontStruct *tmpFont = NULL;
    XtPointer	 default_font = NULL;
    XRectangle   rectangle[1];

    XmFontContext	fontContext;
    XmFontListEntry	fontEntry;
    XmFontType		fontType;

    /* Allocate the Display Area. */
    pDAS = (DtHelpDispAreaStruct *) XtMalloc(sizeof(DtHelpDispAreaStruct));

   /*
     * get the resources
     */
    XtGetSubresources(parent, &DA_args, name, "XmDrawnButton",
		    Resources, XtNumber(Resources), NULL, 0);

    if (rows <= 0)
	rows = 1;
    if (columns <= 0)
	columns = 1;

    /*
     * initialize the structure variables.
     */
    pDAS->text_selected = False;
    pDAS->primary       = False;
    pDAS->select_state  = _DtHelpNothingDoing;
    pDAS->toc_y         = 0;
    pDAS->toc_base      = 0;
    pDAS->toc_flag      = 0;
    if (traversal_flag)
        pDAS->toc_flag  = _DT_HELP_SHADOW_TRAVERSAL | _DT_HELP_NOT_INITIALIZED;

    pDAS->max_spc       = 0;
    pDAS->cur_spc       = 0;
    pDAS->maxX          = 0;
    pDAS->virtualX      = 0;
    pDAS->firstVisible  = 0;
    pDAS->visibleCount  = rows;
    pDAS->maxYpos       = 0;
    pDAS->neededFlags   = 0;
    pDAS->vert_init_scr = DA_args.initialDelay;
    pDAS->vert_rep_scr  = DA_args.repeatDelay;
    pDAS->horz_init_scr = DA_args.initialDelay;
    pDAS->horz_rep_scr  = DA_args.repeatDelay;
    pDAS->moveThreshold = DA_args.moveThreshold;
    pDAS->marginWidth   = DA_args.marginWidth;
    pDAS->marginHeight  = DA_args.marginHeight;
    pDAS->searchColor   = DA_args.search_color;
    pDAS->depth		= 0;
    pDAS->spc_chars     = NULL;
    pDAS->scr_timer_id  = 0;
    pDAS->def_pix       = 0;
    pDAS->context       = NULL;
    pDAS->vertIsMapped  = False;
    pDAS->horzIsMapped  = False;
    pDAS->lst_topic     = NULL;
    pDAS->nextNonVisible = 0;
    pDAS->media_resolution = media_resolution;
    pDAS->honor_size = honor_size;
    pDAS->render_type = render_type;
    pDAS->dtinfo = 0;
    pDAS->stipple = None;

    /*
     * locale dependant information
     */
    pDAS->nl_to_space      = 1;
    pDAS->cant_begin_chars = NULL;
    pDAS->cant_end_chars   = NULL;
    if (1 < MB_CUR_MAX)
	_DtHelpLoadMultiInfo (&(pDAS->cant_begin_chars),
				&(pDAS->cant_end_chars), &(pDAS->nl_to_space));

    /*
     * initialize the hypertext callback pointer
     */
    pDAS->exec_filter = exec_ok_routine;
    pDAS->hyperCall   = hyperTextCB;
    pDAS->resizeCall  = resizeCB;
    pDAS->clientData  = client_data;

    /*
     * zero out other callback fields
     */
    pDAS->vScrollNotify = NULL ;
    pDAS->armCallback = NULL ;

    /*
     * create the atoms needed
     */
    xa_ave_width = XmInternAtom(dpy, "AVERAGE_WIDTH"     , False);

    /*
     * Malloc for the default font.
     */
    (void) XmeRenderTableGetDefaultFont(DA_args.userFont, &tmpFont);
    if (default_list != NULL &&
		XmFontListInitFontContext (&fontContext, default_list))
      {
	fontEntry = XmFontListNextEntry (fontContext);
	if (fontEntry != NULL)
	    default_font = XmFontListEntryGetFont (fontEntry, &fontType);

	XmFontListFreeFontContext (fontContext);
      }

    /*
     * fake out the next call by using the parent as the display widget
     */
    pDAS->dispWid = parent;
    __DtHelpFontDatabaseInit (pDAS, default_font, fontType, tmpFont);

    /*
     * Get the base font meterics.
     */
    __DtHelpFontMetrics (pDAS->font_info, __DtHelpDefaultFontIndexGet(pDAS),
			&maxFontAscent, &maxFontDescent, &maxFontCharWidth,
			NULL, NULL);

    pDAS->leading    = DA_args.leading;
    pDAS->fontAscent = maxFontAscent;
    pDAS->lineHeight = maxFontAscent + maxFontDescent + pDAS->leading + 1;

    n = __DtHelpDefaultFontIndexGet(pDAS);
    if (n < 0)
        value = get_fontsetproperty(__DtHelpFontSetGet(pDAS->font_info, n),
			xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));
    else
	value = XGetFontProperty(__DtHelpFontStructGet(pDAS->font_info, n),
			xa_ave_width, ((unsigned long *) &(pDAS->charWidth)));

    if (False == value || 0 == pDAS->charWidth)
      {
	int len = maxFontCharWidth;

	if (n < 0)
	    len += XmbTextEscapement(
				__DtHelpFontSetGet(pDAS->font_info,n),"1",1);
	else
	    len += XTextWidth(__DtHelpFontStructGet(pDAS->font_info, n),"1",1);

        pDAS->charWidth = 10 * len / 2;
      }

    /*
     * Create the form to manage the window and scroll bars.
     */
    n = 0;
    XtSetArg(args[n], XmNresizePolicy      , XmRESIZE_ANY);		++n;
    XtSetArg(args[n], XmNshadowType	, XmSHADOW_OUT);		++n;
    form = XmCreateForm(parent, "DisplayAreaForm", args, n);
    XtManageChild(form);

    /*
     * force the shadowThickness to zero. The XmManager will try to set
     * this to one.
     */
    n = 0;
    XtSetArg(args[n], XmNshadowThickness   , 0);			++n;
    XtSetArg(args[n], XmNhighlightThickness, 0);			++n;
    XtSetValues (form, args, n);

    /*
     * get the colors and margin widths and heights
     */
    n = 0;
    XtSetArg (args[n], XmNmarginWidth , &margin_width);		++n;
    XtSetArg (args[n], XmNmarginHeight, &margin_height);	++n;
    XtSetArg (args[n], XmNcolormap    , &colormap);		++n;
    XtGetValues(form, args, n);

    /* Create the vertical scrollbar. */
    pDAS->vertScrollWid = NULL;
    if (vert_flag != _DtHelpNONE)
      {
	if (vert_flag == _DtHelpSTATIC)
	    pDAS->vertIsMapped = True;

	n = 0;
	XtSetArg(args[n], XmNtopAttachment     , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNtopOffset         , 0);			++n;
	XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNbottomOffset      , margin_height);	++n;
	XtSetArg(args[n], XmNrightAttachment   , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNrightOffset       , 0);			++n;
	XtSetArg(args[n], XmNorientation       , XmVERTICAL);		++n;
	XtSetArg(args[n], XmNtraversalOn       , True);			++n;
	XtSetArg(args[n], XmNhighlightThickness, 1);			++n;
	XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);		++n;
	XtSetArg(args[n], XmNvalue             , 0);			++n;
	XtSetArg(args[n], XmNminimum           , 0);			++n;
	/* fake out the scrollbar manager, who will init dims to 100 */
	XtSetArg(args[n], XmNheight            , 1);			++n;
	XtSetArg(args[n], XmNmaximum           , 1);			++n;
	XtSetArg(args[n], XmNincrement         , 1);			++n;
	XtSetArg(args[n], XmNpageIncrement     , 1);			++n;
	XtSetArg(args[n], XmNsliderSize        , 1);			++n;
	XtSetArg(args[n], XtNmappedWhenManaged , pDAS->vertIsMapped);	++n;
	pDAS->vertScrollWid = XmCreateScrollBar(form,
					"DisplayDtHelpVertScrollBar", args, n);

	XtManageChild(pDAS->vertScrollWid);
	if (vert_flag != _DtHelpSTATIC)
	    pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
						_DtHelpVERTICAL_SCROLLBAR);
  
	XtAddCallback(pDAS->vertScrollWid, XmNdragCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNincrementCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNdecrementCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNpageIncrementCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNpageDecrementCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNtoBottomCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNtoTopCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->vertScrollWid, XmNvalueChangedCallback,
					_DtHelpVertScrollCB, (XtPointer) pDAS);

	XtAddEventHandler (pDAS->vertScrollWid, ButtonPressMask, True,
			(XtEventHandler)_DtHelpMoveBtnFocusCB,(XtPointer) pDAS);

      }

    /* Create the horizontal scrollbar. */
    pDAS->horzScrollWid = NULL;
    if (horz_flag != _DtHelpNONE)
      {
	if (horz_flag == _DtHelpSTATIC)
	    pDAS->horzIsMapped = True;

	n = 0;
	XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNbottomOffset      , 0);			++n;
	XtSetArg(args[n], XmNrightAttachment   , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNrightOffset       , margin_width);		++n;
	XtSetArg(args[n], XmNleftAttachment    , XmATTACH_FORM);	++n;
	XtSetArg(args[n], XmNleftOffset        , 0);			++n;
	XtSetArg(args[n], XmNorientation       , XmHORIZONTAL);		++n;
	XtSetArg(args[n], XmNtraversalOn       , True);			++n;
	XtSetArg(args[n], XmNhighlightThickness, 1);			++n;
	XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);		++n;
	XtSetArg(args[n], XmNvalue             , 0);			++n;
	XtSetArg(args[n], XmNminimum           , 0);			++n;
	XtSetArg(args[n], XmNmaximum           , (pDAS->charWidth/10));	++n;
	/* fake out the scrollbar manager, who will init dims to 100 */
	XtSetArg(args[n], XmNwidth             , 1);			++n;
	XtSetArg(args[n], XmNincrement         , (pDAS->charWidth/10));	++n;
	XtSetArg(args[n], XmNpageIncrement     , (pDAS->charWidth/10));	++n;
	XtSetArg(args[n], XmNsliderSize        , (pDAS->charWidth/10));	++n;
	XtSetArg(args[n], XtNmappedWhenManaged , pDAS->horzIsMapped);	++n;
	pDAS->horzScrollWid = XmCreateScrollBar(form,
					"DisplayHorzScrollBar", args, n);
	XtManageChild(pDAS->horzScrollWid);
	if (horz_flag != _DtHelpSTATIC)
	    pDAS->neededFlags = _DtHelpSET_AS_NEEDED (pDAS->neededFlags,
						_DtHelpHORIZONTAL_SCROLLBAR);
  
	XtAddCallback(pDAS->horzScrollWid, XmNdragCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNincrementCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNdecrementCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNpageIncrementCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNpageDecrementCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNtoBottomCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNtoTopCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
	XtAddCallback(pDAS->horzScrollWid, XmNvalueChangedCallback,
					_DtHelpHorzScrollCB, (XtPointer) pDAS);
      }

    /*
     * check for the horizontal attachments
     */
    n = 0;
    if (horz_flag == _DtHelpSTATIC)
      {
	XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_WIDGET);	++n;
	XtSetArg(args[n], XmNbottomWidget      , pDAS->horzScrollWid);	++n;
      }
    else
      {
	XtSetArg(args[n], XmNbottomAttachment  , XmATTACH_FORM);	++n;
      }

    /*
     * check for the vertical attachments
     */
    if (vert_flag == _DtHelpSTATIC)
      {
	XtSetArg(args[n], XmNrightAttachment   , XmATTACH_WIDGET);	++n;
	XtSetArg(args[n], XmNrightWidget       , pDAS->vertScrollWid);	++n;
      }
    else
      {
	XtSetArg(args[n], XmNrightAttachment  , XmATTACH_FORM);		++n;
      }

    /*
     * do the rest of the arguments
     */
    XtSetArg(args[n], XmNbottomOffset      , margin_height);		++n;
    XtSetArg(args[n], XmNrightOffset       , margin_width);		++n;
    XtSetArg(args[n], XmNtopAttachment     , XmATTACH_FORM);		++n;
    XtSetArg(args[n], XmNtopOffset	   , 0);			++n;
    XtSetArg(args[n], XmNleftAttachment    , XmATTACH_FORM);		++n;
    XtSetArg(args[n], XmNleftOffset	   , 0);			++n;
    XtSetArg(args[n], XmNrecomputeSize     , False);			++n;
    XtSetArg(args[n], XmNpushButtonEnabled , False);			++n;
    XtSetArg(args[n], XmNtraversalOn       , True);			++n;
    XtSetArg(args[n], XmNhighlightThickness, 1);			++n;
    XtSetArg(args[n], XmNshadowType        , XmSHADOW_IN);		++n;
    XtSetArg(args[n], XmNmultiClick	   , XmMULTICLICK_DISCARD);	++n;
    XtSetArg(args[n], XmNuserData  	   , pDAS);			++n;
    pDAS->dispWid = XmCreateDrawnButton(form, name, args, n);
    XtManageChild(pDAS->dispWid);
  
    XtAddCallback(pDAS->dispWid, XmNexposeCallback, _DtHelpExposeCB,
						(XtPointer) pDAS);
    XtAddCallback(pDAS->dispWid, XmNresizeCallback, _DtHelpResizeCB,
						(XtPointer) pDAS);
    XtAddCallback(pDAS->dispWid, XmNarmCallback, _DtHelpClickOrSelectCB,
						(XtPointer) pDAS);
    XtAddCallback(pDAS->dispWid, XmNdisarmCallback, _DtHelpEndSelectionCB,
						(XtPointer) pDAS);

    XtAddEventHandler (pDAS->dispWid, Button1MotionMask, True,
			(XtEventHandler)_DtHelpMouseMoveCB, (XtPointer) pDAS);

    /*
     * add my actions
     * parse the translations.
     */
    _DtHelpProcessLock();
    if (DrawnBTrans == NULL)
        DrawnBTrans = XtParseTranslationTable(DrawnBTransTable);

     /*
     * override the translations
    XtSetArg(args[n], XmNtranslations	   , DrawnBTrans);		++n;
     */
    if (DrawnBTrans != NULL)
	XtOverrideTranslations(pDAS->dispWid, DrawnBTrans);
    _DtHelpProcessUnlock();
  
    if (_XmGetFocusPolicy(parent) == XmPOINTER)
      {
	XtAddEventHandler (pDAS->dispWid, EnterWindowMask, True,
			(XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
	XtAddEventHandler (pDAS->dispWid, LeaveWindowMask, True,
			(XtEventHandler)_DtHelpEnterLeaveCB, (XtPointer) pDAS);
      }
    else
	XtAddEventHandler (pDAS->dispWid, FocusChangeMask, True,
			(XtEventHandler)_DtHelpFocusCB, (XtPointer) pDAS);

    XtAddEventHandler (pDAS->dispWid, VisibilityChangeMask, True,
			(XtEventHandler)_DtHelpVisibilityCB, (XtPointer) pDAS);
  

    /* Add a destroy callback so that the display area can clean up prior to
     * the help widget getting destroyed (e.g. display area's parent) 
     */
    XtAddCallback(pDAS->dispWid, XmNdestroyCallback,
				_DtHelpDisplayAreaDestroyCB, (XtPointer) pDAS);
  
    n = 0;
    XtSetArg(args[n], XmNshadowThickness   , &shadowThick);	++n;
    XtSetArg(args[n], XmNhighlightThickness, &highThick);	++n;
    XtSetArg(args[n], XmNforeground    , &(pDAS->foregroundColor)); ++n;
    XtSetArg(args[n], XmNbackground    , &(pDAS->backgroundColor)); ++n;
    XtSetArg(args[n], XmNhighlightColor, &(pDAS->traversalColor) ); ++n;
    XtSetArg(args[n], XmNdepth         , &(pDAS->depth)          ); ++n;
    XtGetValues(pDAS->dispWid, args, n);
    pDAS->decorThickness = shadowThick + highThick;

    /*
     * Get the underline information
     */
    GetUnderLineInfo (dpy, pDAS, &(pDAS->lineThickness));

    /*
     * get the tiling pattern.
     */
    tile = XmGetPixmap (XtScreen(pDAS->dispWid), "50_foreground",
				pDAS->foregroundColor, pDAS->backgroundColor);

    /*
     * Get the data for the graphics contexts and create the GC's.
     */
    gcMask = (GCFunction   | GCPlaneMask   | GCForeground  |
		GCBackground  | GCLineWidth   | GCLineStyle   |
		GCClipXOrigin | GCClipYOrigin | GCClipMask);

    gcValues.function      = GXcopy;
    gcValues.plane_mask    = AllPlanes;
    gcValues.foreground    = pDAS->foregroundColor;
    gcValues.background    = pDAS->backgroundColor;
    gcValues.line_style    = LineSolid;
    gcValues.line_width    = pDAS->lineThickness;
    gcValues.clip_x_origin = 0;
    gcValues.clip_y_origin = 0;
    gcValues.clip_mask     = None;
    if (tile)
      {
	gcMask |= GCTile;
	gcValues.tile = tile;
      }
 
    pDAS->normalGC = XCreateGC(dpy,
		RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);

    gcMask &= (~GCTile);
    pDAS->pixmapGC = XCreateGC(dpy,
		RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
  
    gcValues.foreground = pDAS->backgroundColor;
    gcValues.background = pDAS->foregroundColor;
    pDAS->invertGC = XCreateGC(dpy,
		RootWindowOfScreen(XtScreen(pDAS->dispWid)), gcMask, &gcValues);
  
    /*
     * Set the size of the text view area to the requested
     * number of columns and lines.
     */
    char_width          = pDAS->charWidth * columns;

    /*
     * Make sure the margins include enough room for a traversal line
     */
    if (((int) pDAS->marginWidth) < pDAS->lineThickness)
	pDAS->marginWidth = pDAS->lineThickness;
    if (((int) pDAS->marginHeight) < pDAS->lineThickness)
	pDAS->marginHeight = pDAS->lineThickness;
    if (pDAS->leading < pDAS->lineThickness)
	pDAS->leading = pDAS->lineThickness;

    /*
     * get the scrollbar widths.
     */
    if (NULL != pDAS->horzScrollWid)
      {
	n = 0;
	XtSetArg(args[n], XmNheight      , &hBarHeight); n++;
	XtSetArg(args[n], XmNinitialDelay, &(pDAS->horz_init_scr)); n++;
	XtSetArg(args[n], XmNrepeatDelay , &(pDAS->horz_rep_scr));  n++;
	XtGetValues(pDAS->horzScrollWid, args, n);
      }

    if (NULL != pDAS->vertScrollWid)
      {
	n = 0;
	XtSetArg(args[n], XmNwidth       , &vBarWidth);             n++;
	XtSetArg(args[n], XmNinitialDelay, &(pDAS->vert_init_scr)); n++;
	XtSetArg(args[n], XmNrepeatDelay , &(pDAS->vert_rep_scr));  n++;
	XtGetValues(pDAS->vertScrollWid, args, n);
      }

    /*
     * calculate the display area height/width
     */
    pDAS->dispUseWidth  = ((int) (char_width / 10 + (char_width % 10 ? 1 : 0)))
					      + 2 * pDAS->marginWidth;
    if (vert_flag != _DtHelpSTATIC && pDAS->dispUseWidth < vBarWidth)
	pDAS->dispUseWidth = vBarWidth;
    pDAS->dispWidth     = pDAS->dispUseWidth  + 2 * pDAS->decorThickness;

    pDAS->dispUseHeight = pDAS->lineHeight * rows;
    if (horz_flag != _DtHelpSTATIC && pDAS->dispUseHeight < hBarHeight)
	pDAS->dispUseHeight = hBarHeight;
    pDAS->dispHeight    = pDAS->dispUseHeight + 2 * pDAS->decorThickness;

    /*
     * Truncate the width and height to the size of the display.
     * This will prevent an X protocal error when it is asked for
     * a too large size. Besides, any decent window manager will
     * force the overall size to the height and width of the display.
     * This simply refines the size down to a closer (but not perfect)
     * fit.
     */
    if (((int) pDAS->dispWidth) > XDisplayWidth (dpy, screen)) {
	pDAS->dispWidth = XDisplayWidth (dpy, screen);
    }
    if (((int) pDAS->dispHeight) > XDisplayHeight (dpy, screen)) {
	pDAS->dispHeight = XDisplayHeight (dpy, screen);
    }

    n = 0;
    pDAS->formWidth  = 0;
    pDAS->formHeight = 0;
    XtSetArg(args[n], XmNwidth, pDAS->dispWidth);		++n;
    XtSetArg(args[n], XmNheight, pDAS->dispHeight);		++n;
    XtSetValues(pDAS->dispWid, args, n);

    /*
     * set the scroll bar values
     */
    if (pDAS->vertScrollWid != NULL)
      {
        n = 0;
        XtSetArg(args[n], XmNmaximum           , pDAS->dispUseHeight);	++n;
        XtSetArg(args[n], XmNincrement         , pDAS->lineHeight);	++n;
        XtSetArg(args[n], XmNpageIncrement     , pDAS->lineHeight);	++n;
        XtSetArg(args[n], XmNsliderSize        , pDAS->dispUseHeight);	++n;
        XtSetValues(pDAS->vertScrollWid, args, n);
      }
  
    if (pDAS->resizeCall)
	(*(pDAS->resizeCall)) (pDAS->clientData);

    /*
     * calculate the offset for the right edge of the
     * horizontal scrollbar.
     */
    if (vert_flag == _DtHelpSTATIC && pDAS->horzScrollWid)
      {
	width = vBarWidth + margin_width;

	XtSetArg(args[0], XmNrightOffset , width);
	XtSetValues(pDAS->horzScrollWid, args, 1);
      }

    /*
     * calculate the offset for the bottom end of the
     * vertical scrollbar.
     */
    if (horz_flag == _DtHelpSTATIC && pDAS->vertScrollWid)
      {
	width = hBarHeight + margin_height;

	XtSetArg(args[0], XmNbottomOffset , width);
	XtSetValues(pDAS->vertScrollWid, args, 1);
      }

    rectangle[0].x      = pDAS->decorThickness;
    rectangle[0].y      = pDAS->decorThickness;
    rectangle[0].width  = pDAS->dispUseWidth;
    rectangle[0].height = pDAS->dispUseHeight;
    XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->normalGC, 0, 0,
						rectangle, 1, Unsorted);
    XSetClipRectangles(XtDisplay(pDAS->dispWid), pDAS->invertGC, 0, 0,
						rectangle, 1, Unsorted);

    /*
     * get the colormap and the visual
     */
    if (!XtIsShell(parent) && XtParent(parent) != NULL)
	parent = XtParent(parent);

    pDAS->visual = NULL;

    n = 0;
    XtSetArg (args[n], XmNcolormap, &(pDAS->colormap)); n++;
    XtSetArg (args[n], XmNvisual  , &(pDAS->visual  )); n++;
    XtGetValues (parent, args, n);

    if (pDAS->visual == NULL)
	pDAS->visual = XDefaultVisualOfScreen(XtScreen(pDAS->dispWid));

    /*
     * set up the canvas
     */
    _DtHelpProcessLock();
    DefVirtFunctions.exec_cmd_filter = exec_ok_routine;

    pDAS->canvas = _DtCanvasCreate (DefVirtFunctions, (_DtCvPointer) pDAS);
    _DtHelpProcessUnlock();

    return (XtPointer) pDAS;

}  /* End _DtHelpCreateDA */
/*--------------------------------------------------------*/
void open_gwindow_( )
{
/*
 * create new graphics window on first entry....
 */
  int                          font,black,white;
  int                          scr_width,scr_height;
  int                          j;
  unsigned long                valuemask;
  static int                   depth;    /* number of planes  */
  static Visual               *visual;   /*VISUAL TYPE       */
  static XSizeHints            win_position;   /*position and size for
                                            window manager.*/

/*
 * initialize display id and screen id....
 */
      disp_id = XOpenDisplay(0);
      if (!disp_id) {
         printf("Display not opened!\n");
         exit(-1);
      }
/*
 * next instruction for debugging only....
 */
/*      XSynchronize(disp_id, 1); */
  
  screen_id  =  XDefaultScreenOfDisplay(disp_id);
  root_win_id = XRootWindowOfScreen(screen_id);
  black =       XBlackPixelOfScreen(screen_id);
  white =       XWhitePixelOfScreen(screen_id);
  scr_width =   XWidthOfScreen(screen_id);
  scr_height =  XHeightOfScreen(screen_id);
  depth  =      XDefaultDepthOfScreen(screen_id);
  visual =      XDefaultVisualOfScreen(screen_id);


/*
 * set up backing store....
 */
      valuemask = CWBitGravity | CWBackingStore | CWBackPixel;
      setwinattr.bit_gravity = SouthWestGravity;
      setwinattr.backing_store = Always;
      setwinattr.background_pixel = white;
/*
 * create the window....
 */
      win_id  = XCreateWindow(disp_id,
			      root_win_id,
			      scr_width - win_width - 15,
			      scr_height - win_height - 35,
			      win_width, 
			      win_height, 
			      10,
			      depth,
			      InputOutput,
			      visual,
			      valuemask,
			      &setwinattr);
/* WMHints structure */
  win_position.x = scr_width - win_width - 15;
  win_position.y = scr_height - win_height - 35;
  win_position.width = win_width;
  win_position.height = win_height;
  win_position.flags=USPosition|USSize;
  
  XSetWMNormalHints(disp_id, win_id, &win_position); 

      XStoreName(disp_id, win_id, WINDNAME);
/*
 * get named color values....
 */

      color[1]   = define_color_("BLUE");
      color[2]   = define_color_("DEEP SKY BLUE");
      color[3]   = define_color_("LIGHT SKY BLUE");

      color[4]   = define_color_("SEA GREEN");
      color[5]  = define_color_("MEDIUM SEA GREEN");
      color[6]  = define_color_("GREEN");

      color[7]  = define_color_("BROWN");
      color[8]  = define_color_("CHOCOLATE");
      color[9]  = define_color_("SANDY BROWN");

      color[10]   = define_color_("RED");
      color[11]   = define_color_("CORAL");
      color[12]   = define_color_("ORANGE");

      color[13]  = define_color_("YELLOW3");
      color[14]  = define_color_("YELLOW2");
      color[15]  = define_color_("YELLOW");

      color[16]  = define_color_("PEACH PUFF");
      color[17]  = define_color_("PAPAYA WHIP");
      color[18]  = define_color_("OLD LACE");

      color[19]   = white;
      color[20]   = black;
      color[21]   = black;


/*
 * create graphics context....
 */
      xgcvl.background = color[19];
      xgcvl.foreground = color[20];
      gc_id = XCreateGC(disp_id, win_id, GCForeground | GCBackground, &xgcvl);
      xgcvl.function = GXinvert;
      gc_comp_id = XCreateGC(disp_id, win_id, GCFunction, &xgcvl);
/*
 * load the font for text writing....
 */
      font = XLoadFont(disp_id, FONTNAME);
      XSetFont(disp_id, gc_id, font);

  /* Map the window.... */
  XSelectInput(disp_id,win_id,ExposureMask|VisibilityChangeMask);
  XMapRaised(disp_id,win_id);

  /*
   * Wait for the window to be raised. Some X servers do not 
   * generate an initial expose event, so also check the visibility
   * event.
   */
  XMaskEvent(disp_id,ExposureMask|VisibilityChangeMask,&event);
  XSelectInput(disp_id,win_id,0);
  XSync(disp_id,1);
}
Exemple #4
0
int initsystem(void)  /* retourne 1 si initialisation reussie */
{
    int i;
    int windowW;
    int windowH;
    XSetWindowAttributes xswa;
    XGCValues xgcv;
    XSizeHints xsh;

    windowW=WIDTH*RATIO;
    windowH=HEIGHT*RATIO;
    display=XOpenDisplay(0);

    if (!display) return(0);
    else
    {
        mousek=0;
        XAutoRepeatOff(display);
        timestart=last=systime();
        screen=XDefaultScreenOfDisplay(display);
        rdepth=sdepth=XDefaultDepthOfScreen(screen);
        if (emulmono) sdepth=1;
        XSynchronize(display,0);

        black=XBlackPixelOfScreen(screen);
        white=XWhitePixelOfScreen(screen);
        colormap=XDefaultColormapOfScreen(screen);
        visual=XDefaultVisualOfScreen(screen);

        xswa.event_mask=VisibilityChangeMask;
        xswa.background_pixel=black;
        xswa.border_pixel=white;
        xswa.override_redirect=0;
        xswa.backing_store=Always;
        xswa.bit_gravity=StaticGravity;
        xswa.win_gravity=CenterGravity;
        window=XCreateWindow(display,XRootWindowOfScreen(screen),
                             randval(50),randval(100),windowW,windowH,0,
                             XDefaultDepthOfScreen(screen),InputOutput,
                             XDefaultVisualOfScreen(screen),
                             CWWinGravity|CWBitGravity|CWBackingStore|CWEventMask|
                             CWBackPixel|CWOverrideRedirect|CWBorderPixel,&xswa);

        if (sdepth!=1)
            xcolormap=XCreateColormap(display,window,
                                      visual,AllocAll);

        xgcv.foreground = white;
        xgcv.background = black;
        gc=XCreateGC(display,window,GCForeground | GCBackground,&xgcv);

        XSetGraphicsExposures(display,gc,False);
        /* CAPITAL!!! : evite d'accumuler sans cesse des expose events */

        xsh.x=0;
        xsh.y=0;
        xsh.width=windowW;
        xsh.height=windowH;
        xsh.min_width=windowW;
        xsh.max_width=windowW;
        xsh.min_height=windowH;
        xsh.max_height=windowH;
        xsh.flags=PPosition|PSize|PMinSize|PMaxSize;

        XSetNormalHints(display, window, &xsh);
        XStoreName(display,window,"");
        XMapWindow(display, window);
        XSelectInput(display,window,PointerMotionMask|ButtonPressMask|
                     ButtonReleaseMask|KeyPressMask|KeyReleaseMask);
        XFlush(display);
        XSync(display,0);

        for (i=0; i<(NBCOLORS+2); i++)
        {
            if (i&1) pixels[i]=white;
            else pixels[i]=black;
            if (i==NBCOLORS) pixels[i]=0;
            if (i==(NBCOLORS+1)) pixels[i]=(1<<rdepth)-1;
            xgcv.foreground=pixels[i];
            xgcv.background=black;
            gctab[i]=XCreateGC(display,window,
                               GCForeground|GCBackground,&xgcv);
            XSetFunction(display,gctab[i],GXcopy);
            XSetFillStyle(display,gctab[i],FillSolid);
        }

        ecran[0]=XCreatePixmap(display,window,windowW,windowH,rdepth);
        ecran[1]=XCreatePixmap(display,window,windowW,windowH,rdepth);

        for(i=0; i<9; i++)
            graypixmap[i]=XCreatePixmapFromBitmapData(display,window,
                          &graypat[i][0],8,8,white,black,rdepth);

        setpalette(egapal);

        cls();
        swap();
        cls();

        empty();
        waitdelay(500);

        return(1);
    }
}
Exemple #5
0
void
SplashInitPlatform(Splash * splash) {
    int shapeVersionMajor, shapeVersionMinor;

    // This setting enables the synchronous Xlib mode!
    // Don't use it == 1 in production builds!
#if (defined DEBUG)
    _Xdebug = 1;
#endif

    pthread_mutex_init(&splash->lock, NULL);

    // We should not ignore any errors.
    //XSetErrorHandler(HandleError);
//    XSetIOErrorHandler(HandleIOError);
    XSetIOErrorHandler(NULL);
    splash->display = XOpenDisplay(NULL);
    if (!splash->display) {
        splash->isVisible = -1;
        return;
    }

    shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase,
            &shapeErrorBase);
    if (shapeSupported) {
        XShapeQueryVersion(splash->display, &shapeVersionMajor,
                &shapeVersionMinor);
    }

    splash->screen = XDefaultScreenOfDisplay(splash->display);
    splash->visual = XDefaultVisualOfScreen(splash->screen);
    switch (splash->visual->class) {
    case TrueColor: {
            int depth = XDefaultDepthOfScreen(splash->screen);

            splash->byteAlignment = 1;
            splash->maskRequired = shapeSupported;
            initFormat(&splash->screenFormat, splash->visual->red_mask,
                    splash->visual->green_mask, splash->visual->blue_mask, 0);
            splash->screenFormat.byteOrder =
                (XImageByteOrder(splash->display) == LSBFirst ?
                 BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST);
            splash->screenFormat.depthBytes = (depth + 7) / 8;
            // TrueColor depth probably can't be less
            // than 8 bits, and it's always byte padded
            break;
        }
    case PseudoColor: {
            int availableColors;
            int numColors;
            int numComponents[3];
            unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
            XColor xColors[SPLASH_COLOR_MAP_SIZE];
            int i;
            int depth = XDefaultDepthOfScreen(splash->screen);
            int scale = 65535 / MAX_COLOR_VALUE;

            availableColors = GetNumAvailableColors(splash->display, splash->screen,
                    splash->visual->map_entries);
            numColors = quantizeColors(availableColors, numComponents);
            if (numColors > availableColors) {
                // Could not allocate the color cells. Most probably
                // the pool got exhausted. Disable the splash screen.
                XCloseDisplay(splash->display);
                splash->isVisible = -1;
                splash->display = NULL;
                splash->screen = NULL;
                splash->visual = NULL;
                fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
                return;
            }
            splash->cmap = AllocColors(splash->display, splash->screen,
                    numColors, colorIndex);
            for (i = 0; i < numColors; i++) {
                splash->colorIndex[i] = colorIndex[i];
            }
            initColorCube(numComponents, splash->colorMap, splash->dithers,
                    splash->colorIndex);
            for (i = 0; i < numColors; i++) {
                xColors[i].pixel = colorIndex[i];
                xColors[i].red = (unsigned short)
                    QUAD_RED(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].green = (unsigned short)
                    QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].blue = (unsigned short)
                    QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale;
                xColors[i].flags = DoRed | DoGreen | DoBlue;
            }
            XStoreColors(splash->display, splash->cmap, xColors, numColors);
            initFormat(&splash->screenFormat, 0, 0, 0, 0);
            splash->screenFormat.colorIndex = splash->colorIndex;
            splash->screenFormat.depthBytes = (depth + 7) / 8;  // or always 8?
            splash->screenFormat.colorMap = splash->colorMap;
            splash->screenFormat.dithers = splash->dithers;
            splash->screenFormat.numColors = numColors;
            splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE;
            break;
        }
    default:
        ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */
    }
}