Пример #1
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 );
}
Пример #2
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);
}
Пример #3
0
static int _GWidget_TopLevel_Key(GWindow top, GWindow ew, GEvent *event) {
    GTopLevelD *topd = (GTopLevelD *) (top->widget_data);
    int handled=0;
    GEvent sub;

    if ( !top->is_popup )
	last_input_window = top;

    /* If the palette has the focus, and it usually will under kde, then */
    /*  give the event to the main window if the cursor is outside of the palette */
    if ( topd->ispalette ) {
	if ( event->u.chr.x<-2 || event->u.chr.x>top->pos.width+2 ||
		event->u.chr.y<-2 || event->u.chr.y>top->pos.height+2 ) {
	    GPoint p;
	    topd = topd->owner;
	    p.x = event->u.chr.x; p.y = event->u.chr.y;
	    GDrawTranslateCoordinates(ew,topd->w,&p);
	    event->u.chr.x = p.x; event->u.chr.y = p.y;
	    ew = top = topd->w;
	    event->w = top;
	}
    }
    /* Check for mnemonics and shortcuts */
    if ( event->type == et_char && !GKeysymIsModifier(event->u.chr.keysym) ) {
	handled = GMenuPopupCheckKey(event);
	if ( topd->ispalette ) {
	    if ( !(handled = GMenuBarCheckKey(top,topd->owner->gmenubar,event)) )
		handled = GWidgetCheckMn((GContainerD *) topd->owner,event);
	}
	if ( !handled )
	    if ( !(handled = GMenuBarCheckKey(top,topd->gmenubar,event)) )
		handled = GWidgetCheckMn((GContainerD *) topd,event);
    }
    if ( handled )
	/* No op */;
    else if ( topd->popupowner!=NULL ) {
	/* When we've got an active popup (menu, list, etc.) all key events */
	/*  go to the popups owner (which, presumably sends them to the popup)*/
	if ( topd->popupowner->funcs->handle_key !=NULL )
	    handled = (topd->popupowner->funcs->handle_key)(topd->popupowner,event);
    } else if ( topd->gfocus!=NULL && topd->gfocus->funcs->handle_key )
	handled = (topd->gfocus->funcs->handle_key)(topd->gfocus,event);
    else if ( topd->wfocus!=NULL ) {
	if ( topd->wfocus->widget_data==NULL ) {
	    if ( topd->wfocus->eh!=NULL )
		handled = (topd->wfocus->eh)(topd->wfocus,event);
	} else if ( topd->wfocus->widget_data->e_h!=NULL )
	    handled = (topd->wfocus->widget_data->e_h)(topd->wfocus,event);
    }
    if ( !handled ) {
	if ( ew->widget_data==NULL ) {
	    if ( ew->eh!=NULL )
		handled = (ew->eh)(ew,event);
	} else if ( ew->widget_data->e_h!=NULL )
	    handled = (ew->widget_data->e_h)(ew,event);
    }

    if ( event->type==et_charup )
return( handled );
    /* If no one wanted it then try keyboard navigation */
    /* Tab or back tab cycles the focus through our widgets/gadgets */
    if ( !handled && (event->u.chr.keysym==GK_Tab || event->u.chr.keysym==GK_BackTab )) {
	if ( event->u.chr.keysym==GK_BackTab || (event->u.chr.state&ksm_shift) )
	    GWidgetPrevFocus(ew);
	else
	    GWidgetNextFocus(ew);
	handled = true;
    }
    /* Return activates the default button (if there is one) */
    else if ( !handled && (event->u.chr.keysym==GK_Return || event->u.chr.keysym==GK_KP_Enter) &&
	    topd->gdef!=NULL ) {
	sub.type = et_controlevent;
	sub.w = topd->gdef->base;
	sub.u.control.subtype = et_buttonactivate;
	sub.u.control.g = topd->gdef;
	sub.u.control.u.button.clicks = 0;
	if ( topd->gdef->handle_controlevent != NULL )
	    (topd->gdef->handle_controlevent)(topd->gdef,&sub);
	else
	    GDrawPostEvent(&sub);
    }
    /* Escape activates the cancel button (if there is one) */
    /*  (On the mac, Command-. has that meaning) */
    else if ( !handled && topd->gcancel!=NULL &&
	    (event->u.chr.keysym==GK_Escape ||
	     ((GMenuMask()&ksm_cmdmacosx) &&
	      (event->u.chr.state&GMenuMask())==ksm_cmdmacosx &&
	      event->u.chr.keysym=='.'))) {
	sub.type = et_controlevent;
	sub.w = topd->gcancel->base;
	sub.u.control.subtype = et_buttonactivate;
	sub.u.control.g = topd->gcancel;
	sub.u.control.u.button.clicks = 0;
	if ( topd->gcancel->handle_controlevent != NULL )
	    (topd->gcancel->handle_controlevent)(topd->gcancel,&sub);
	else
	    GDrawPostEvent(&sub);
    }
return( handled );
}
Пример #4
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);
}