static void GList_destroy(GGadget *g) { GDList *gl = (GDList *) g; if ( gl==NULL ) return; GDrawCancelTimer(gl->enduser); GDrawCancelTimer(gl->pressed); if ( gl->freeti ) GTextInfoArrayFree(gl->ti); free(gl->sofar); if ( gl->vsb!=NULL ) (gl->vsb->g.funcs->destroy)(&gl->vsb->g); _ggadget_destroy(g); }
static void GRowCol_destroy(GGadget *g) { GRowCol *grc = (GRowCol *) g; if ( grc==NULL ) return; GDrawCancelTimer(grc->enduser); GDrawCancelTimer(grc->pressed); if ( grc->freeti ) GTextInfoArrayFree(grc->ti); free(grc->sofar); if ( grc->vsb!=NULL ) (grc->vsb->g.funcs->destroy)(&grc->vsb->g); _ggadget_destroy(g); }
static void gscrollbar_destroy(GGadget *g) { GScrollBar *gsb = (GScrollBar *) g; if ( gsb==NULL ) return; GDrawCancelTimer(gsb->pressed); _ggadget_destroy(g); }
static void DoDelayedEvents(GEvent *event) { GTimer *t = event->u.timer.timer; struct delayed_event *info = (struct delayed_event *) (event->u.timer.userdata); if ( info!=NULL ) (info->func)(info->data); GDrawCancelTimer(t); }
void ShowAboutScreen(void) { static int first=1; if ( first ) { GDrawResize(splashw,splashimage.u.image->width,splashimage.u.image->height+linecnt*fh); first = false; } if ( splasht!=NULL ) GDrawCancelTimer(splasht); splasht=NULL; GDrawSetVisible(splashw,true); }
static void SendNextArg(struct argsstruct *args) { int i; char *msg; static GTimer *timeout; if ( timeout!=NULL ) { GDrawCancelTimer(timeout); timeout = NULL; } for ( i=args->next; i<args->argc; ++i ) { if ( *args->argv[i]!='-' || strcmp(args->argv[i],"-quit")==0 || strcmp(args->argv[i],"--quit")==0 || strcmp(args->argv[i],"-new")==0 || strcmp(args->argv[i],"--new")==0 ) break; } if ( i>=args->argc ) { if ( args->any ) exit(0); /* Sent everything */ msg = "-open"; } else msg = args->argv[i]; args->next = i+1; args->any = true; GDrawGrabSelection(splashw,sn_user1); GDrawAddSelectionType(splashw,sn_user1,"STRING", copy(msg),strlen(msg),1, NULL,NULL); /* If we just sent the other fontforge a request to die, it will never*/ /* take the selection back. So we should just die quietly */ /* But we can't die instantly, or it will never get our death threat */ /* (it won't have a chance to ask us for the selection if we're dead)*/ timeout = GDrawRequestTimer(splashw,1000,0,NULL); }
static int growcol_key(GGadget *g, GEvent *event) { GRowCol *grc = (GRowCol *) g; uint16 keysym = event->u.chr.keysym; int sofar_pos = grc->sofar_pos; int loff, xoff, sel=-1; int refresh = false; if ( event->type == et_charup ) return( false ); if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused )) return(false ); if ( grc->ispopup && event->u.chr.keysym == GK_Return ) { GRowColDoubleClick(grc); return( true ); } if ( event->u.chr.keysym == GK_Return || event->u.chr.keysym == GK_Tab || event->u.chr.keysym == GK_BackTab || event->u.chr.keysym == GK_Escape ) return( false ); GDrawCancelTimer(grc->enduser); grc->enduser = NULL; grc->sofar_pos = 0; loff = 0x80000000; xoff = 0x80000000; sel = -1; if ( keysym == GK_Home || keysym == GK_KP_Home || keysym == GK_Begin || keysym == GK_KP_Begin ) { loff = -grc->loff; xoff = -grc->xoff; sel = 0; } else if ( keysym == GK_End || keysym == GK_KP_End ) { loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff; xoff = -grc->xoff; sel = grc->ltot-1; } else if ( keysym == GK_Up || keysym == GK_KP_Up ) { if (( sel = GRowColGetFirstSelPos(&grc->g)-1 )<0 ) { /*if ( grc->loff!=0 ) loff = -1; else loff = 0;*/ sel = 0; } } else if ( keysym == GK_Down || keysym == GK_KP_Down ) { if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) ++sel; else /*if ( grc->loff + GRowColLinesInWindow(grc,grc->loff)<grc->ltot ) loff = 1; else loff = 0;*/ sel = 0; } else if ( keysym == GK_Left || keysym == GK_KP_Left ) { xoff = -GDrawPointsToPixels(grc->g.base,6); } else if ( keysym == GK_Right || keysym == GK_KP_Right ) { xoff = GDrawPointsToPixels(grc->g.base,6); } else if ( keysym == GK_Page_Up || keysym == GK_KP_Page_Up ) { loff = GRowColTopInWindow(grc,grc->loff); if ( loff == grc->loff ) /* Normally we leave one line in window from before, except if only one line fits */ loff = GRowColTopInWindow(grc,grc->loff-1); loff -= grc->loff; if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) { if (( sel += loff )<0 ) sel = 0; } } else if ( keysym == GK_Page_Down || keysym == GK_KP_Page_Down ) { loff = GRowColLinesInWindow(grc,grc->loff)-1; if ( loff<=0 ) loff = 1; if ( loff + grc->loff >= grc->ltot ) loff = GRowColTopInWindow(grc,grc->ltot-1)-grc->loff; if (( sel = GRowColGetFirstSelPos(&grc->g))!= -1 ) { if (( sel += loff )>=grc->ltot ) sel = grc->ltot-1; } } else if ( keysym == GK_BackSpace && grc->orderer ) { /* ordered lists may be reversed by typing backspace */ grc->backwards = !grc->backwards; GRowColOrderIt(grc); sel = GRowColGetFirstSelPos(&grc->g); if ( sel!=-1 ) { int top = GRowColTopInWindow(grc,grc->ltot-1); grc->loff = sel-1; if ( grc->loff > top ) grc->loff = top; if ( sel-1<0 ) grc->loff = 0; } GScrollBarSetPos(&grc->vsb->g,grc->loff); _ggadget_redraw(&grc->g); return( true ); } else if ( event->u.chr.chars[0]!='\0' && grc->orderer ) { int len = u_strlen(event->u.chr.chars); if ( sofar_pos+len >= grc->sofar_max ) { if ( grc->sofar_max == 0 ) grc->sofar = galloc((grc->sofar_max = len+10) * sizeof(unichar_t)); else grc->sofar = grealloc(grc->sofar,(grc->sofar_max = sofar_pos+len+10)*sizeof(unichar_t)); } u_strcpy(grc->sofar+sofar_pos,event->u.chr.chars); grc->sofar_pos = sofar_pos + len; sel = GRowColFindPosition(grc,grc->sofar); grc->enduser = GDrawRequestTimer(grc->g.base,GRowColTypeTime,0,NULL); } if ( loff==0x80000000 && sel>=0 ) { if ( sel>=grc->ltot ) sel = grc->ltot-1; if ( sel<grc->loff ) loff = sel-grc->loff; else if ( sel>=grc->loff+GRowColLinesInWindow(grc,grc->loff) ) loff = sel-(grc->loff+GRowColLinesInWindow(grc,grc->loff)-1); } else sel = -1; if ( sel!=-1 ) { int wassel = grc->ti[sel]->selected; refresh = GRowColAnyOtherSels(grc,sel) || !wassel; GRowColSelectOne(&grc->g,sel); if ( refresh ) GRowColSelected(grc); } if ( loff!=0x80000000 || xoff!=0x80000000 ) { if ( loff==0x80000000 ) loff = 0; if ( xoff==0x80000000 ) xoff = 0; GRowColScrollBy(grc,loff,xoff); } if ( refresh ) _ggadget_redraw(g); if ( loff!=0x80000000 || xoff!=0x80000000 || sel!=-1 ) return( true ); return( false ); }
static int growcol_mouse(GGadget *g, GEvent *event) { GRowCol *grc = (GRowCol *) g; int pos; if ( !g->takes_input || (g->state!=gs_active && g->state!=gs_enabled && g->state!=gs_focused)) return( false ); if ( event->type == et_crossing ) return( false ); if ( event->type==et_mousemove && !grc->pressed && !grc->parentpressed ) { if ( GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y) && g->popup_msg ) GGadgetPreparePopup(g->base,g->popup_msg); return( true ); } else if ( event->type==et_mouseup && grc->parentpressed && !GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y)) { grc->parentpressed = false; GDrawPointerUngrab(GDrawGetDisplayOfWindow(grc->g.base)); } else if ( event->type==et_mousemove && grc->parentpressed && GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y)) { if ( grc->pressed == NULL ) grc->pressed = GDrawRequestTimer(g->base,GRowColScrollTime,GRowColScrollTime,NULL); GDrawPointerUngrab(GDrawGetDisplayOfWindow(grc->g.base)); grc->parentpressed = false; growcol_scroll_selbymouse(grc,event); return( true ); } else if ( event->type==et_mousemove && grc->pressed ) { growcol_scroll_selbymouse(grc,event); return( true ); } else if ( event->type==et_mousedown ) { if ( grc->pressed == NULL ) grc->pressed = GDrawRequestTimer(g->base,GRowColScrollTime,GRowColScrollTime,NULL); pos = GRowColIndexFromPos(grc,event->u.mouse.y); if ( pos==-1 ) return( true ); /* Do Nothing, nothing selectable */ else if ( !grc->exactly_one && grc->ti[pos]->selected && (event->u.mouse.state&(ksm_control|ksm_shift))) { grc->ti[pos]->selected = false; } else if ( !grc->multiple_sel || !(event->u.mouse.state&(ksm_control|ksm_shift))) { GRowColClearSel(grc); grc->ti[pos]->selected = true; grc->start = grc->end = pos; } else if ( event->u.mouse.state&ksm_control ) { grc->ti[pos]->selected = !grc->ti[pos]->selected; grc->start = grc->end = pos; } else if ( event->u.mouse.state&ksm_shift ) { GRowColExpandSelection(grc,pos); } _ggadget_redraw(&grc->g); } else if ( event->type==et_mouseup && grc->pressed ) { GDrawCancelTimer(grc->pressed); grc->pressed = NULL; if ( GGadgetInnerWithin(&grc->g,event->u.mouse.x,event->u.mouse.y) ) { growcol_scroll_selbymouse(grc,event); if ( event->u.mouse.clicks==2 ) GRowColDoubleClick(grc); else GRowColSelected(grc); } } else return( false ); return( true ); }
static int splash_e_h(GWindow gw, GEvent *event) { static int splash_cnt; GRect old; int i, y, x; static char *foolishness[] = { /* GT: These strings are for fun. If they are offensive or incomprehensible */ /* GT: simply translate them as something dull like: "FontForge" */ /* GT: This is a spoof of political slogans, designed to point out how foolish they are */ N_("A free press discriminates\nagainst the illiterate."), N_("A free press discriminates\nagainst the illiterate."), /* GT: This is a pun on the old latin drinking song "Gaudeamus igature!" */ N_("Gaudeamus Ligature!"), N_("Gaudeamus Ligature!"), /* GT: Spoof on the bible */ N_("In the beginning was the letter..."), /* GT: Some wit at MIT came up with this ("ontology recapitulates phylogony" is the original) */ N_("fontology recapitulates file-ogeny") }; switch ( event->type ) { case et_create: GDrawGrabSelection(gw,sn_user1); break; case et_expose: GDrawPushClip(gw,&event->u.expose.rect,&old); GDrawDrawImage(gw,&splashimage,NULL,0,0); GDrawSetFont(gw,splash_font); y = splashimage.u.image->height + as + fh/2; for ( i=1; i<linecnt; ++i ) { if ( is>=lines[i-1]+1 && is<lines[i] ) { x = 8+GDrawDrawText(gw,8,y,lines[i-1]+1,is-lines[i-1]-1,0x000000); GDrawSetFont(gw,splash_italic); GDrawDrawText(gw,x,y,is,lines[i]-is,0x000000); } else if ( ie>=lines[i-1]+1 && ie<lines[i] ) { x = 8+GDrawDrawText(gw,8,y,lines[i-1]+1,ie-lines[i-1]-1,0x000000); GDrawSetFont(gw,splash_font); GDrawDrawText(gw,x,y,ie,lines[i]-ie,0x000000); } else GDrawDrawText(gw,8,y,lines[i-1]+1,lines[i]-lines[i-1]-1,0x000000); y += fh; } GDrawPopClip(gw,&old); break; case et_map: splash_cnt = 0; break; case et_timer: if ( event->u.timer.timer==autosave_timer ) { DoAutoSaves(); } else if ( event->u.timer.timer==splasht ) { if ( ++splash_cnt==1 ) GDrawResize(gw,splashimage.u.image->width,splashimage.u.image->height-30); else if ( splash_cnt==2 ) GDrawResize(gw,splashimage.u.image->width,splashimage.u.image->height); else if ( splash_cnt>=7 ) { GGadgetEndPopup(); GDrawSetVisible(gw,false); GDrawCancelTimer(splasht); splasht = NULL; } } else { DoDelayedEvents(event); } break; case et_char: case et_mousedown: case et_close: GGadgetEndPopup(); GDrawSetVisible(gw,false); break; case et_mousemove: GGadgetPreparePopup8(gw,_(foolishness[rand()%(sizeof(foolishness)/sizeof(foolishness[0]))]) ); break; case et_selclear: /* If this happens, it means someone wants to send us a message with a*/ /* filename to open. So we need to ask for it, process it, and then */ /* take the selection back again */ if ( event->u.selclear.sel == sn_user1 ) { int len; char *arg; arg = GDrawRequestSelection(splashw,sn_user1,"STRING",&len); if ( arg==NULL ) return( true ); if ( strcmp(arg,"-new")==0 || strcmp(arg,"--new")==0 ) FontNew(); else if ( strcmp(arg,"-open")==0 || strcmp(arg,"--open")==0 ) _FVMenuOpen(NULL); else if ( strcmp(arg,"-quit")==0 || strcmp(arg,"--quit")==0 ) MenuExit(NULL,NULL,NULL); else ViewPostScriptFont(arg,0); free(arg); GDrawGrabSelection(splashw,sn_user1); } break; case et_destroy: IError("Who killed the splash screen?"); break; } return( true ); }
static int glist_mouse(GGadget *g, GEvent *event) { GDList *gl = (GDList *) g; int pos; if ( !g->takes_input || (g->state!=gs_active && g->state!=gs_enabled && g->state!=gs_focused)) return( false ); if ( event->type == et_crossing ) return( false ); if (( event->type==et_mouseup || event->type==et_mousedown ) && (event->u.mouse.button>=4 && event->u.mouse.button<=7)) { if ( gl->vsb!=NULL ) return( GGadgetDispatchEvent(&gl->vsb->g,event)); else return( true ); } if ( event->type==et_mousemove && !gl->pressed && !gl->parentpressed ) { if ( GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y) ) { if ( gl->popup_callback!=NULL ) (gl->popup_callback)(g,GListIndexFromPos(gl,event->u.mouse.y)); else if ( g->popup_msg ) GGadgetPreparePopup(g->base,g->popup_msg); } return( true ); } else if ( event->type==et_mouseup && gl->parentpressed /* && !GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y)*/ ) { gl->parentpressed = false; GDrawPointerUngrab(GDrawGetDisplayOfWindow(gl->g.base)); } else if ( event->type==et_mousemove && gl->parentpressed && GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y)) { if ( gl->pressed == NULL ) gl->pressed = GDrawRequestTimer(g->base,GListScrollTime,GListScrollTime,NULL); GDrawPointerUngrab(GDrawGetDisplayOfWindow(gl->g.base)); gl->parentpressed = false; glist_scroll_selbymouse(gl,event); return( true ); } else if ( event->type==et_mousemove && gl->pressed ) { glist_scroll_selbymouse(gl,event); return( true ); } else if ( event->type==et_mousedown ) { if ( gl->pressed == NULL ) gl->pressed = GDrawRequestTimer(g->base,GListScrollTime,GListScrollTime,NULL); pos = GListIndexFromPos(gl,event->u.mouse.y); if ( pos==-1 ) return( true ); /* Do Nothing, nothing selectable */ else if ( !gl->exactly_one && gl->ti[pos]->selected && (event->u.mouse.state&(ksm_control|ksm_shift))) { gl->ti[pos]->selected = false; gl->start = gl->end = 0xffff; } else if ( !gl->multiple_sel || (!gl->ti[pos]->selected && !(event->u.mouse.state&(ksm_control|ksm_shift)))) { GListClearSel(gl); gl->ti[pos]->selected = true; gl->start = gl->end = pos; } else if ( event->u.mouse.state&ksm_control || ((event->u.mouse.state&ksm_shift) && gl->ti[pos]->selected)) { gl->ti[pos]->selected = !gl->ti[pos]->selected; gl->start = gl->end = pos; } else if ( event->u.mouse.state&ksm_shift ) { GListExpandSelection(gl,pos); } else { gl->ti[pos]->selected = true; gl->start = gl->end = pos; } _ggadget_redraw(&gl->g); } else if ( event->type==et_mouseup && gl->pressed ) { GDrawCancelTimer(gl->pressed); gl->pressed = NULL; if ( GGadgetInnerWithin(&gl->g,event->u.mouse.x,event->u.mouse.y) ) { pos = GListIndexFromPos(gl,event->u.mouse.y); if ( !(event->u.mouse.state&(ksm_control|ksm_shift)) || gl->start!=0xffff ) glist_scroll_selbymouse(gl,event); if ( event->u.mouse.clicks==2 ) GListDoubleClick(gl,true,pos); else GListSelected(gl,true,pos); } } else return( false ); return( true ); }
static int gscrollbar_mouse(GGadget *g, GEvent *event) { GScrollBar *gsb = (GScrollBar *) g; int active_pos, active_len; if ( !g->takes_input || (g->state!=gs_enabled && g->state!=gs_active && g->state!=gs_focused )) return( false ); if ( event->type == et_crossing ) return( false ); if ( gsb->g.vert ) { active_pos = event->u.mouse.y-g->inner.y; active_len = g->inner.height; } else { active_pos = event->u.mouse.x-g->inner.x; active_len = g->inner.width; } if ( (event->type==et_mouseup || event->type==et_mousedown) && (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) { /* X treats scroll wheels as though they send events from buttons 4 and 5 */ /* Badly configured wacom mice send "p5 r5 p4 r4" or "p4 r4 p5 r5" */ /* properly configured mice just send "p4 r4" or "p5 r5" */ /* And apple's mouse with a scrollwheel sends buttons 6&7 for horizontal*/ /* scrolling */ /* Convention is that shift-vertical scroll=horizontal scroll */ /* control-vertical scroll=minimize/maximize */ if ( event->type==et_mousedown ) { GDrawCancelTimer(gsb->pressed); gsb->pressed = NULL; int isv = event->u.mouse.button<=5; if ( event->u.mouse.state&ksm_shift ) isv = !isv; if ( isv != g->vert ) return( false ); /* Only respond to scrolling events in our direction */ else if ( event->u.mouse.state&ksm_control ) return( false ); if ( event->u.mouse.button==5 || event->u.mouse.button==7 ) { GScrollBarChanged(gsb,et_sb_down,0); } else if ( event->u.mouse.button==4 || event->u.mouse.button==6 ) { GScrollBarChanged(gsb,et_sb_up,0); } } return( true ); } if ( event->type == et_mousedown && GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y)) { GDrawCancelTimer(gsb->pressed); gsb->pressed = NULL; if ( event->u.mouse.button!=1 ) { gsb->thumbpressed = true; gsb->thumboff = 0; active_pos = event->u.mouse.y-g->inner.y; GScrollBarChanged(gsb,et_sb_thumb,active_pos); } else if ( active_pos >= gsb->thumbpos && active_pos < gsb->thumbpos+gsb->thumbsize ) { gsb->thumbpressed = true; gsb->thumboff = active_pos-gsb->thumbpos; } else if ( active_pos < gsb->thumbpos && (event->u.mouse.state&(ksm_control|ksm_meta)) ) { gsb->thumbpressed = true; gsb->thumboff = active_pos; GScrollBarChanged(gsb,et_sb_top,0); } else if ( active_pos >= gsb->thumbpos+gsb->thumbsize && (event->u.mouse.state&(ksm_control|ksm_meta)) ) { gsb->thumbpressed = true; gsb->thumboff = active_pos-active_len+gsb->thumbsize; GScrollBarChanged(gsb,et_sb_bottom,0); } else { if ( active_pos<0 ) gsb->repeatcmd = et_sb_up; else if ( active_pos >= active_len ) gsb->repeatcmd = et_sb_down; else if ( active_pos < gsb->thumbpos ) gsb->repeatcmd = et_sb_uppage; else /* if ( active_pos > gsb->thumbpos+gsb->thumbsize )*/ gsb->repeatcmd = et_sb_downpage; GScrollBarChanged(gsb,gsb->repeatcmd,0); gsb->pressed = GDrawRequestTimer(g->base,_GScrollBar_StartTime,_GScrollBar_RepeatTime,NULL); } } else if ( event->type == et_mousemove && gsb->thumbpressed ) { GDrawSkipMouseMoveEvents(gsb->g.base,event); if ( gsb->g.vert ) { active_pos = event->u.mouse.y-g->inner.y; } else { active_pos = event->u.mouse.x-g->inner.x; } GScrollBarChanged(gsb,et_sb_thumb,active_pos); } else if ( event->type == et_mouseup && (gsb->thumbpressed || gsb->pressed)) { if ( gsb->thumbpressed ) GScrollBarChanged(gsb,et_sb_thumbrelease,active_pos); GDrawCancelTimer(gsb->pressed); gsb->pressed = NULL; gsb->thumbpressed = false; } else if ( event->type == et_mousemove && !gsb->pressed && g->popup_msg!=NULL && GGadgetWithin(g,event->u.mouse.x,event->u.mouse.y)) { GGadgetPreparePopup(g->base,g->popup_msg); return( true ); } else return( false ); return( true ); }