Ejemplo n.º 1
0
static void RulerPlace(CharView *cv, GEvent *event) {
    unichar_t ubuf[80];
    int width, x, y;
    GRect size;
    GPoint pt;
    int i,h,w;
    GWindowAttrs wattrs;
    GRect pos;
    FontRequest rq;
    int as, ds, ld;

    if ( cv->ruler_w==NULL ) {
	memset(&wattrs,0,sizeof(wattrs));
	wattrs.mask = wam_events|wam_cursor|wam_positioned|wam_nodecor|wam_backcol|wam_bordwidth;
	wattrs.event_masks = (1<<et_expose)|(1<<et_resize)|(1<<et_mousedown);
	wattrs.cursor = ct_mypointer;
	wattrs.background_color = 0xe0e0c0;
	wattrs.nodecoration = 1;
	wattrs.border_width = 1;
	pos.x = pos.y = 0; pos.width=pos.height = 20;
	cv->ruler_w = GWidgetCreateTopWindow(NULL,&pos,ruler_e_h,cv,&wattrs);

	if ( rvfont==NULL ) {
	    memset(&rq,0,sizeof(rq));
	    rq.utf8_family_name = FIXED_UI_FAMILIES;
	    rq.point_size = -12;
	    rq.weight = 400;
	    rvfont = GDrawInstanciateFont(GDrawGetDisplayOfWindow(cv->ruler_w),&rq);
	    rvfont = GResourceFindFont("CharView.Measure.Font",rvfont);
	}
	cv->rfont = rvfont;
	GDrawFontMetrics(cv->rfont,&as,&ds,&ld);
	cv->rfh = as+ds; cv->ras = as;
    } else
	GDrawRaise(cv->ruler_w);

    GDrawSetFont(cv->ruler_w,cv->rfont);
    width = h = 0;
    for ( i=0; RulerText(cv,ubuf,i); ++i ) {
	w = GDrawGetBiTextWidth(cv->ruler_w,ubuf,-1,-1,NULL);
	if ( w>width ) width = w;
	h += cv->rfh;
    }
    GDrawGetSize(GDrawGetRoot(NULL),&size);
    pt.x = event->u.mouse.x; pt.y = event->u.mouse.y;
    GDrawTranslateCoordinates(cv->v,GDrawGetRoot(NULL),&pt);
    x = pt.x + infowindowdistance;
    if ( x+width > size.width )
	x = pt.x - width-infowindowdistance;
    y = pt.y -cv->ras-2;
    if ( y+h > size.height )
	y = pt.y - h - cv->ras -10;
    GDrawMoveResize(cv->ruler_w,x,y,width+4,h+4);
}
Ejemplo n.º 2
0
/*  Palettes go invisible when the owner loses focus, and become visible when it gains focus */
GWindow GWidgetCreatePalette(GWindow w, GRect *pos, int (*eh)(GWindow,GEvent *), void *user_data, GWindowAttrs *wattrs) {
    GWindow gw;
    GPoint pt, base;
    GRect newpos, ownerpos, screensize;
    struct gtopleveldata *gd, *od;
    GWindow root;

    if ( !w->is_toplevel )
return( false );

    pt.x = pos->x; pt.y = pos->y;
    root = GDrawGetRoot(w->display);
    GDrawGetSize(w,&ownerpos);
    GDrawGetSize(root,&screensize);
    GDrawTranslateCoordinates(w,root,&pt);
    base.x = base.y = 0;
    GDrawTranslateCoordinates(w,root,&base);
    if ( pt.x<0 ) {
	if ( base.x+ownerpos.width+20+pos->width+20 > screensize.width )
	    pt.x=0;
	else
	    pt.x = base.x+ownerpos.width+20;
    }
    if ( pt.y<0 ) pt.y=0;
    if ( pt.x+pos->width>root->pos.width )
	pt.x = root->pos.width-pos->width;
    if ( pt.y+pos->height>root->pos.height )
	pt.y = root->pos.height-pos->height;

    newpos.x = pt.x; newpos.y = pt.y; newpos.width = pos->width; newpos.height = pos->height;
    wattrs->event_masks |= (1<<et_visibility);
    if ( !(wattrs->mask&wam_transient)) {
	wattrs->mask |= wam_transient;
	wattrs->transient = GWidgetGetTopWidget(w);
    }
    if ( broken_palettes ) {
	wattrs->mask |= wam_positioned;
	wattrs->positioned = true;
    }
    gw = GDrawCreateTopWindow(w->display,&newpos,eh,user_data,wattrs);
    MakeContainerWidget(gw);
    if ( w->widget_data==NULL )
	MakeContainerWidget(w);
    od = (struct gtopleveldata *) (w->widget_data);
    gd = (struct gtopleveldata *) (gw->widget_data);
    gd->nextp = od->palettes;
    gd->owner = od;
    od->palettes = gd;
    gd->ispalette = true;
    gd->owner_off_x = pos->x; gd->owner_off_y = pos->y;
return( gw );
}
Ejemplo n.º 3
0
static void CreateErrorWindow(void) {
    GWindowAttrs wattrs;
    FontRequest rq;
    GRect pos,size;
    int as, ds, ld;
    GWindow gw;
    GGadgetData gd;
    extern int _GScrollBar_Width;

    GDrawGetSize(GDrawGetRoot(NULL),&size);

    memset(&wattrs,0,sizeof(wattrs));
    wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_isdlg|wam_positioned;
    wattrs.event_masks = ~(1<<et_charup);
    wattrs.is_dlg = true;
    wattrs.cursor = ct_pointer;
    wattrs.positioned = true;
    wattrs.utf8_window_title = _("Warnings");
    pos.width = GDrawPointsToPixels(NULL,GGadgetScale(400));
    pos.height = GDrawPointsToPixels(NULL,GGadgetScale(100));
    pos.x = size.width - pos.width - 10;
    pos.y = size.height - pos.height - 30;
    errdata.gw = gw = GDrawCreateTopWindow(NULL,&pos,warnings_e_h,&errdata,&wattrs);

    memset(&rq,0,sizeof(rq));
    rq.utf8_family_name = SANS_UI_FAMILIES;
    rq.point_size = 10;
    rq.weight = 400;
    errdata.font = GDrawInstanciateFont(NULL,&rq);
    errdata.font = GResourceFindFont("Warnings.Font",errdata.font);
    GDrawWindowFontMetrics(errdata.gw,errdata.font,&as,&ds,&ld);
    errdata.as = as;
    errdata.fh = as+ds;

    memset(&gd,0,sizeof(gd));
    gd.pos.y = 0;
    gd.pos.height = pos.height;
    gd.pos.width = GDrawPointsToPixels(gw,_GScrollBar_Width);
    gd.pos.x = pos.width-gd.pos.width;
    gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels|gg_sb_vert;
    errdata.vsb = GScrollBarCreate(gw,&gd,&errdata);

    pos.width -= gd.pos.width;
    pos.x = pos.y = 0;
    wattrs.mask = wam_events|wam_cursor;
    errdata.v = GWidgetCreateSubWindow(gw,&pos,warningsv_e_h,&errdata,&wattrs);
    GDrawSetVisible(errdata.v,true);

    errdata.linecnt = pos.height/errdata.fh;
    errdata.start_l = errdata.end_l = -1;
}
Ejemplo n.º 4
0
FontInstance *GDrawInstanciateFont(GWindow gw, FontRequest *rq) {
    struct font_instance *fi;

    if (gw == NULL)
	gw = GDrawGetRoot(NULL);

    if ( rq->point_size<0 )	/* It's in pixels, not points, convert to points */
	rq->point_size = PixelToPoint(-rq->point_size, ((GXWindow) gw)->display->res);

    fi = xcalloc(1,sizeof(struct font_instance));
    fi->rq = *rq;
    fi->rq.family_name = x_u32_strdup_or_null( fi->rq.family_name );
    fi->rq.utf8_family_name = xstrdup_or_null( fi->rq.utf8_family_name );

return( fi );
}
Ejemplo n.º 5
0
static int _GWidget_TopLevel_eh(GWindow gw, GEvent *event) {
    GTopLevelD *td;
    int ret;

    if ( !GDrawNativeWindowExists(NULL,event->native_window) )
return( true );

    td = (GTopLevelD *) (gw->widget_data);
    if ( td==NULL )		/* Dying */
return( true );

    GGadgetPopupExternalEvent(event);
    if ( event->type==et_focus ) {
	
	if ( event->u.focus.gained_focus ) {
	    if ( gw->is_toplevel && !gw->is_popup && !gw->is_dying ) {
		if ( last_input_window!=gw )
		    previous_focus_window = last_input_window;
		current_focus_window = gw;
	    }
	} else if ( current_focus_window==gw ) {
	    current_focus_window = NULL;
	}
	if ( !td->ispalette && gw->is_visible && event->u.focus.gained_focus && !gw->is_dying ) {
	    GWindow dlg = GDrawGetRedirectWindow(NULL);
	    if ( dlg==NULL || dlg==gw ) {
		/* If top level window loses the focus all its palettes go invisible */
		/* if it gains focus then all palettes that are supposed to be vis */
		/*  become visible */
		/* But not if we've got an active dialog */
		GTopLevelD *palette;
		if ( last_paletted_focus_window!=NULL && !last_paletted_focus_window->is_dying ) {
		    GTopLevelD *lpfw_td = (GTopLevelD *) (last_paletted_focus_window->widget_data);
		    for ( palette=lpfw_td->palettes; palette!=NULL; palette = palette->nextp ) {
			if ( !palette->w->is_visible && palette->w->visible_request ) {
			    GDrawSetVisible(palette->w,false);
			    palette->w->visible_request = true;
			}
		    }
		}
		for ( palette=td->palettes; palette!=NULL; palette = palette->nextp ) {
		    if ( !palette->w->is_visible && palette->w->visible_request )
			GDrawSetVisible(palette->w,true);
		}
		last_paletted_focus_window = gw;
	    }
	}
	if ( !gw->is_dying && td->gfocus!=NULL && td->gfocus->funcs->handle_focus!=NULL ) {
 { oldtd = td; oldgfocus = td->gfocus; }	/* Debug!!!! */
	    (td->gfocus->funcs->handle_focus)(td->gfocus,event);
	} else if ( !gw->is_dying && td->wfocus!=NULL ) {
	    if ( td->wfocus->widget_data!=NULL ) {
		if ( td->wfocus->widget_data->e_h!=NULL )
		    (td->wfocus->widget_data->e_h)(td->wfocus,event);
	    } else if ( td->wfocus->eh!=NULL )
		(td->wfocus->eh)(td->wfocus,event);
	}
	if ( !gw->is_dying && td->e_h!=NULL )
	    (td->e_h)(gw,event);
return( true );
    } else if ( !gw->is_dying && event->type == et_crossing ) {
	GiveToAll((GContainerD *) td,event);
return( true );
    } else if ( event->type == et_char || event->type == et_charup ) {
return( _GWidget_TopLevel_Key(gw,gw,event));
    } else if ( !gw->is_dying && event->type == et_resize ) {
	GRect r;
	if ( td->gmenubar!=NULL ) {
	    GGadgetGetSize(td->gmenubar,&r);
	    GGadgetResize(td->gmenubar,event->u.resize.size.width,r.height);
	    GGadgetRedraw(td->gmenubar);
	} /* status line, toolbar, etc. */
	if ( td->palettes!=NULL && event->u.resize.moved ) {
	    GTopLevelD *palette;
	    for ( palette=td->palettes; palette!=NULL; palette = palette->nextp ) {
		if ( !broken_palettes || !palette->positioned_yet ) {
		    int x = gw->pos.x + palette->owner_off_x,
			y = gw->pos.y + palette->owner_off_y;
		    if ( x<0 ) x=0;
		    if ( y<0 ) y=0;
		    if ( x+palette->w->pos.width>GDrawGetRoot(NULL)->pos.width )
			x = GDrawGetRoot(NULL)->pos.width-palette->w->pos.width;
		    if ( y+palette->w->pos.height>GDrawGetRoot(NULL)->pos.height )
			y = GDrawGetRoot(NULL)->pos.height-palette->w->pos.height;
		    ++palette->programmove;
		    if ( gw->is_visible )
			GDrawTrueMove(palette->w, x, y);
		    else
			GDrawMove(palette->w, x, y);
		    palette->positioned_yet = true;
		}
	    }
	}
	if ( td->ispalette ) {
	    if ( td->programmove>0 )
		--td->programmove;
	    else {
		td->owner_off_x = gw->pos.x - td->owner->w->pos.x;
		td->owner_off_y = gw->pos.y - td->owner->w->pos.y;
	    }
	}
    } else if ( event->type == et_close && td->ispalette ) {
	GDrawSetVisible(gw,false);
return( true );
    } else if ( !gw->is_dying && event->type == et_visibility ) {
	if ( broken_palettes )
	    /* Do Nothing */;
	else if ( td->ispalette && event->u.visibility.state!=vs_unobscured ) {
	    if ( !GDrawIsAbove(gw,td->owner->w))
		GDrawRaiseAbove(gw,td->owner->w);
	}
    } else if ( !gw->is_dying && event->type == et_map && !td->ispalette ) {
	/* If top level window goes invisible all its palettes follow */
	/* if it goes visible then all palettes that are supposed to be vis */
	/*  follow */
	ManagePalettesVis(td, event->u.map.is_visible );
    }
    if ( event->type == et_destroy ) {
	if ( td->palettes!=NULL ) {
	    struct gtopleveldata *palettes, *next;
	    for ( palettes=td->palettes; palettes!=NULL; palettes = next ) {
		next = palettes->nextp;
		GDrawDestroyWindow(palettes->w);
	    }
	    /* Palettes must die before our widget data are freed */
	    GDrawSync(GDrawGetDisplayOfWindow(gw));
	    GDrawProcessPendingEvents(GDrawGetDisplayOfWindow(gw));
	}
    }
    ret = _GWidget_Container_eh(gw,event);
    if ( event->type == et_destroy ) {
	if ( gw==current_focus_window )
	    current_focus_window = NULL;
	if ( gw==previous_focus_window )
	    previous_focus_window = NULL;
	if ( gw==last_input_window )
	    last_input_window = NULL;
	if ( gw==last_paletted_focus_window )
	    last_paletted_focus_window = NULL;
	ret = true;
    }
return( ret );
}
Ejemplo n.º 6
0
void AnchorControl(SplineChar *sc,AnchorPoint *ap,int layer) {
    GRect pos;
    GWindowAttrs wattrs;
    AnchorDlg a;
    GWindow gw;
    GGadgetCreateData gcd[15], buttonbox, maingcd[3], *hvarray[60], *buttonarray[8];
    GGadgetCreateData glyphbox, *glypharray[5];
    GTextInfo label[16];
    int k, hv;
    extern int _GScrollBar_Width;
    char buffer[20], xbuf[20], ybuf[20];
    GRect boxsize;

    memset(&a,0,sizeof(a));
    a.sc = sc;
    a.ap = ap;
    a.apos = ap->me;
    a.pixelsize = aa_pixelsize;
    a.magfactor = 1;
    a.layer = layer;
    if ( ap->xadjust.corrections!=NULL ) {
	int len = ap->xadjust.last_pixel_size-ap->xadjust.first_pixel_size+1;
	a.xadjust = ap->xadjust;
	a.xadjust.corrections = malloc(len);
	memcpy(a.xadjust.corrections,ap->xadjust.corrections,len);
    }
    if ( ap->yadjust.corrections!=NULL ) {
	int len = ap->yadjust.last_pixel_size-ap->yadjust.first_pixel_size+1;
	a.yadjust = ap->yadjust;
	a.yadjust.corrections = malloc(len);
	memcpy(a.yadjust.corrections,ap->yadjust.corrections,len);
    }

    memset(&wattrs,0,sizeof(wattrs));

    wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_isdlg|wam_restrict;
    wattrs.event_masks = ~(1<<et_charup);
    wattrs.restrict_input_to_me = true;
    wattrs.undercursor = 1;
    wattrs.cursor = ct_pointer;
    wattrs.utf8_window_title = _("Anchor Control...");
    wattrs.is_dlg = true;
    GDrawGetSize(GDrawGetRoot(NULL),&pos);
    pos.x = pos.y = 0;
    pos.height = GDrawPointsToPixels(NULL,210);
    if ( pos.height<aa_pixelsize+40+25 )
	pos.height = aa_pixelsize+40+25;
    pos.width -= 50;
    a.gw = gw = GDrawCreateTopWindow(NULL,&pos,anchord_e_h,&a,&wattrs);

    a.ctl_len = GDrawPointsToPixels(gw,140);
    a.sb_height = GDrawPointsToPixels(gw,_GScrollBar_Width);
    a.sb_base = pos.height - a.sb_height;

    memset(maingcd,0,sizeof(maingcd));
    memset(&buttonbox,0,sizeof(buttonbox));
    memset(&glyphbox,0,sizeof(glyphbox));
    memset(gcd,0,sizeof(gcd));
    memset(label,0,sizeof(label));
    k = hv = 0;

    gcd[k].gd.flags = gg_visible|gg_enabled ;
    gcd[k].gd.cid = CID_Glyph;
    gcd[k].gd.handle_controlevent = AnchorD_GlyphChanged;
    gcd[k++].creator = GListButtonCreate;

    glypharray[0] = GCD_Glue; glypharray[1] = &gcd[k-1]; glypharray[2] = GCD_Glue; glypharray[3] = NULL;

    glyphbox.gd.flags = gg_enabled|gg_visible;
    glyphbox.gd.u.boxelements = glypharray;
    glyphbox.creator = GHBoxCreate;

    hvarray[hv++] = &glyphbox; hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_ColSpan;
    hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

    label[k].text = (unichar_t *) _("_Size:");
    label[k].text_is_1byte = true;
    label[k].text_in_resource = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = 9;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup;
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    sprintf( buffer, "%d", a.pixelsize );
    label[k].text = (unichar_t *) buffer;
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 40; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.pos.width = 60;
    gcd[k].gd.flags = gg_visible|gg_enabled | gg_utf8_popup ;
    gcd[k].gd.cid = CID_DisplaySize;
    gcd[k].gd.handle_controlevent = AnchorD_DisplaySizeChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("The size at which the current glyph is rasterized.\nFor small pixelsize you may want to use the magnification\nfactor below to get a clearer view.\n\nThe pulldown list contains the pixelsizes at which there\nare device table corrections.");
    gcd[k++].creator = GListFieldCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

/* GT: Short for: Magnification */
    label[k].text = (unichar_t *) _("Mag:");
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-2].gd.pos.y+26;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = GCD_HPad10; hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    gcd[k].gd.pos.x = 45; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k].gd.cid = CID_Mag;
    gcd[k].gd.u.list = magnifications;
    gcd[k].gd.handle_controlevent = AnchorD_MagnificationChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("The glyph is rasterized at the size above, but it\nmay be difficult to see the alignment errors\nthat can happen at small pixelsizes. This allows\nyou to expand each pixel to show potential problems\nbetter.");
    gcd[k++].creator = GListButtonCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

    label[k].text = (unichar_t *) _("_X");
    label[k].text_is_1byte = true;
    label[k].text_in_resource = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    sprintf( xbuf, "%d", (int) rint(ap->me.x) );
    label[k].text = (unichar_t *) xbuf;
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 40; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.pos.width = 60;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k].gd.cid = CID_X;
    gcd[k].gd.handle_controlevent = AnchorD_PositionChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("The X coordinate of the anchor point in this glyph");
    gcd[k++].creator = GNumericFieldCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

/* GT: Short for Correction */
    label[k].text = (unichar_t *) _("Cor:");
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30;
    gcd[k].gd.flags = gg_visible|gg_enabled | gg_utf8_popup ;
    gcd[k].gd.popup_msg = (unichar_t *) _("Correction in pixels to the horizontal positioning of this anchor point\nwhen rasterizing at the given pixelsize.\n(Lives in a Device Table)");
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = GCD_HPad10; hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    label[k].text = (unichar_t *) "0";
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 45; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.pos.width = 60;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k].gd.cid = CID_XCor;
    gcd[k].gd.handle_controlevent = AnchorD_CorrectionChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("This is the number of pixels by which the anchor\nshould be moved horizontally when the glyph is\nrasterized at the above size.  This information\nis part of the device table for this anchor.\nDevice tables are particularly important at small\npixelsizes where rounding errors will have a\nproportionally greater effect.");
    gcd[k++].creator = GNumericFieldCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

    label[k].text = (unichar_t *) _("_Y");
    label[k].text_is_1byte = true;
    label[k].text_in_resource = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    sprintf( ybuf, "%d", (int) rint(ap->me.y) );
    label[k].text = (unichar_t *) ybuf;
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 40; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.pos.width = 60;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k].gd.cid = CID_Y;
    gcd[k].gd.handle_controlevent = AnchorD_PositionChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("The Y coordinate of the anchor point in this glyph");
    gcd[k++].creator = GNumericFieldCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

/* GT: Short for Correction */
    label[k].text = (unichar_t *) _("Cor:");
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 10; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+30;
    gcd[k].gd.flags = gg_visible|gg_enabled | gg_utf8_popup ;
    gcd[k].gd.popup_msg = (unichar_t *) _("Correction in pixels to the horizontal positioning of this anchor point\nwhen rasterizing at the given pixelsize.\n(Lives in a Device Table)");
    gcd[k++].creator = GLabelCreate;
    hvarray[hv++] = GCD_HPad10; hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_ColSpan;

    label[k].text = (unichar_t *) "0";
    label[k].text_is_1byte = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 45; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y-4;
    gcd[k].gd.pos.width = 60;
    gcd[k].gd.flags = gg_visible|gg_enabled  | gg_utf8_popup ;
    gcd[k].gd.cid = CID_YCor;
    gcd[k].gd.handle_controlevent = AnchorD_CorrectionChanged;
    gcd[k].gd.popup_msg = gcd[k-1].gd.popup_msg = (unichar_t *)
	    _("This is the number of pixels by which the anchor\nshould be moved vertically when the glyph is\nrasterized at the above size.  This information\nis part of the device table for this anchor.\nDevice tables are particularly important at small\npixelsizes where rounding errors will have a\nproportionally greater effect.");
    gcd[k++].creator = GNumericFieldCreate;
    hvarray[hv++] = &gcd[k-1]; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

    hvarray[hv++] = GCD_Glue; hvarray[hv++] = GCD_Glue; hvarray[hv++] = GCD_Glue;
    hvarray[hv++] = GCD_Glue; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;

    label[k].text = (unichar_t *) _("_OK");
    label[k].text_is_1byte = true;
    label[k].text_in_resource = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 5; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+40;
    gcd[k].gd.pos.width = -1;
    gcd[k].gd.flags = gg_visible|gg_enabled|gg_but_default;
    gcd[k].gd.handle_controlevent = AnchorD_OK;
    gcd[k++].creator = GButtonCreate;
    buttonarray[0] = GCD_Glue; buttonarray[1] = &gcd[k-1]; buttonarray[2] = GCD_Glue;

    label[k].text = (unichar_t *) _("_Cancel");
    label[k].text_is_1byte = true;
    label[k].text_in_resource = true;
    gcd[k].gd.label = &label[k];
    gcd[k].gd.pos.x = 80; gcd[k].gd.pos.y = gcd[k-1].gd.pos.y+3;
    gcd[k].gd.pos.width = -1;
    gcd[k].gd.flags = gg_visible|gg_enabled|gg_but_cancel;
    gcd[k].gd.handle_controlevent = AnchorD_Cancel;
    gcd[k++].creator = GButtonCreate;
    buttonarray[3] = GCD_Glue; buttonarray[4] = &gcd[k-1]; buttonarray[5] = GCD_Glue;
    buttonarray[6] = NULL;

    buttonbox.gd.flags = gg_enabled|gg_visible;
    buttonbox.gd.u.boxelements = buttonarray;
    buttonbox.creator = GHBoxCreate;

    hvarray[hv++] = &buttonbox; hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_ColSpan;
    hvarray[hv++] = GCD_ColSpan; hvarray[hv++] = GCD_Glue; hvarray[hv++] = NULL;
    hvarray[hv++] = NULL;

    maingcd[0].gd.pos.x = maingcd[0].gd.pos.y = 5;
    maingcd[0].gd.pos.height = pos.height - 10;
/*    maingcd[0].gd.pos.width = a.ctl_len - 10; */
    maingcd[0].gd.flags = gg_enabled|gg_visible|gg_pos_in_pixels;
    maingcd[0].gd.u.boxelements = hvarray;
    maingcd[0].creator = GHVBoxCreate;

    maingcd[1].gd.pos.x = 300;
    maingcd[1].gd.pos.y = pos.height-a.sb_height;
    maingcd[1].gd.pos.height = a.sb_height;
    maingcd[1].gd.pos.width = pos.width-300;
    maingcd[1].gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels;
    maingcd[1].creator = GScrollBarCreate;

    GGadgetsCreate(a.gw,maingcd);
    GGadgetSetList(gcd[0].ret,AnchorD_GlyphsInClass(&a),false);
    GTextInfoListFree(gcd[0].gd.u.list);

    GHVBoxSetExpandableRow(maingcd[0].ret,gb_expandglue);
    GHVBoxSetExpandableCol(maingcd[0].ret,4);
    GHVBoxSetExpandableCol(buttonbox.ret,gb_expandgluesame);
    GHVBoxSetExpandableCol(glyphbox.ret,gb_expandglue);
    GGadgetGetDesiredSize(maingcd[0].ret,&boxsize,NULL);
    a.ctl_len = boxsize.width + 10;
    
    a.hsb = maingcd[1].ret;

    AnchorD_FindComplements(&a);
    AnchorD_SetDevTabs(&a);
    AnchorD_ChangeSize(&a);
    AnchorD_SetTitle(&a);

    GDrawSetVisible(a.gw,true);
    while ( !a.done )
	GDrawProcessOneEvent(NULL);
    GDrawDestroyWindow(a.gw);
    AnchorD_FreeAll(&a);
}
Ejemplo n.º 7
0
static void CpInfoPlace(CharView *cv, GEvent *event) {
    char buf[100];
    int line, which;
    int width, x, y;
    GRect size;
    GPoint pt, pt2;
    int h,w;
    GWindowAttrs wattrs;
    GRect pos;
    FontRequest rq;
    int as, ds, ld;
    SplinePoint *sp;

    if ( cv->ruler_w==NULL ) {
	memset(&wattrs,0,sizeof(wattrs));
	wattrs.mask = wam_events|wam_cursor|wam_positioned|wam_nodecor|wam_backcol|wam_bordwidth;
	wattrs.event_masks = (1<<et_expose)|(1<<et_resize)|(1<<et_mousedown);
	wattrs.cursor = ct_mypointer;
	wattrs.background_color = 0xe0e0c0;
	wattrs.nodecoration = 1;
	wattrs.border_width = 1;
	pos.x = pos.y = 0; pos.width=pos.height = 20;
	cv->ruler_w = GWidgetCreateTopWindow(NULL,&pos,cpinfo_e_h,cv,&wattrs);

	if ( rvfont==NULL ) {
	    memset(&rq,0,sizeof(rq));
	    rq.utf8_family_name = FIXED_UI_FAMILIES;
	    rq.point_size = -12;
	    rq.weight = 400;
	    rvfont = GDrawInstanciateFont(GDrawGetDisplayOfWindow(cv->ruler_w),&rq);
	    rvfont = GResourceFindFont("CharView.Measure.Font",rvfont);
	}
	cv->rfont = rvfont;
	GDrawFontMetrics(cv->rfont,&as,&ds,&ld);
	cv->rfh = as+ds; cv->ras = as;
    } else
	GDrawRaise(cv->ruler_w);

    GDrawSetFont(cv->ruler_w,cv->rfont);
    h = 0; width = 0;
    for ( which = 0; which<2; ++which ) {
	for ( line=0; PtInfoText(cv,line,which,buf,sizeof(buf))!=NULL; ++line ) {
	    w = GDrawGetBiText8Width(cv->ruler_w,buf,-1,-1,NULL);
	    if ( w>width ) width = w;
	    h += cv->rfh+1;
	}
	h += 4;
    }
    if ( PtInfoText(cv,0,-1,buf,sizeof(buf))!=NULL ) {
	w = GDrawGetBiText8Width(cv->ruler_w,buf,-1,-1,NULL);
	if ( w>width ) width = w;
	h += cv->rfh+1;
    }
    
    GDrawGetSize(GDrawGetRoot(NULL),&size);
    pt.x = event->u.mouse.x; pt.y = event->u.mouse.y;	/* Address of cp */
    GDrawTranslateCoordinates(cv->v,GDrawGetRoot(NULL),&pt);

    sp = cv->p.sp;
    if ( !cv->p.prevcp && !cv->p.nextcp )
	sp = cv->active_sp;
    if ( sp!=NULL ) {
	x =  cv->xoff + rint(sp->me.x*cv->scale);
	y = -cv->yoff + cv->height - rint(sp->me.y*cv->scale);
	if ( x>=0 && y>=0 && x<cv->width && y<cv->height ) {
	    pt2.x = x; pt2.y = y;
	    GDrawTranslateCoordinates(cv->v,GDrawGetRoot(NULL),&pt2);
	} else
	    sp = NULL;
    }

    x = pt.x + infowindowdistance;
    y = pt.y - cv->ras-2;
    if ( sp!=NULL && x<=pt2.x-4 && x+width>=pt2.x+4 && y<=pt2.y-4 && y+h>=pt2.y+4 )
	x = pt2.x + 4;
    if ( x+width > size.width ) {
	x = pt.x - width-30;
	if ( sp!=NULL && x<=pt2.x-4 && x+width>=pt2.x+4 && y<=pt2.y-4 && y+h>=pt2.y+4 )
	    x = pt2.x - width - 4;
	if ( x<0 ) {
	    x = pt.x + 10;
	    y = pt.y - h - infowindowdistance;
	    if ( sp!=NULL && x<=pt2.x-4 && x+width>=pt2.x+4 && y<=pt2.y-4 && y+h>=pt2.y+4 )
		y = pt2.y - h - 4;
	    if ( y<0 )
		y = pt.y+infowindowdistance;	/* If this doesn't work we have nowhere else to */
				/* try so don't check */
	}
    }
    if ( y+h > size.height )
	y = pt.y - h - cv->ras - 10;
    GDrawMoveResize(cv->ruler_w,x,y,width+4,h+4);
}