static widget_handler_status_T kbd_listbox(struct dialog_data *dlg_data, struct widget_data *widget_data) { struct term_event *ev = dlg_data->term_event; /* Not a pure listbox, but you're not supposed to use this outside of * the listbox browser anyway, so what.. */ switch (ev->ev) { case EVENT_KBD: { action_id_T action_id = kbd_action(KEYMAP_MENU, ev, NULL); return do_kbd_listbox_action(action_id, dlg_data, widget_data); } case EVENT_INIT: case EVENT_RESIZE: case EVENT_REDRAW: case EVENT_MOUSE: case EVENT_ABORT: break; } return EVENT_NOT_PROCESSED; }
int main(int argc, char *argv[]) { int i,j,k; char c; int res=0; int x,y; char buttons; struct termios t_new,t_old; FILE *fsc; char buf[100]; progname=argv[0]; screen_gamma=1.5; #ifdef DEBUG log=fopen("/png/view.log","w"); #endif while((c=getopt(argc,argv,"r:g:"))!=-1) { switch(c) { case 'r': res=atoi(optarg); if(res>0) max_screen_colors=256; break; case 'g': screen_gamma=atof(optarg); break; case '?': default: usage(); exit(0); } } switch(res) { case 0: VGLInit(SW_CG640x480); break; case 1: VGLInit(SW_VGA_CG320); break; case 2: VGLInit(SW_VGA_MODEX); break; default: fprintf(stderr,"No such resolution!\n"); usage(); exit(-1); } #ifdef DEBUG fprintf(log,"VGL initialised\n"); #endif VGLSavePalette(); if(argc>optind) { res=png_load(argv[optind]); } else { VGLEnd(); usage(); exit(0); } if(res) { /* Hmm... Script? */ fsc=fopen(argv[optind],"r"); #ifdef DEBUG fprintf(log,"Trying script %s\n",argv[optind]); #endif fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; if(strncmp("VIEW SCRIPT",buf,11)!=NULL) { VGLEnd(); usage(); } if(strlen(buf)>12) { auto_chg=atoi(buf+12); } fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; nimg=atoi(buf); if(nimg==0) { VGLEnd(); usage(); } pres=(char **)calloc(nimg,sizeof(char *)); for(i=0;i<nimg;i++) { fgets(buf,99,fsc); buf[strlen(buf)-1]='\0'; pres[i]=strdup(buf); } fclose(fsc); cur_img=0; #ifdef DEBUG fprintf(log,"Script with %d entries\n",nimg); #endif png_load(pres[cur_img]); } VGLMouseInit(VGL_MOUSEHIDE); /* Prepare the keyboard */ tcgetattr(0,&t_old); memcpy(&t_new,&t_old,sizeof(struct termios)); cfmakeraw(&t_new); tcsetattr(0,TCSAFLUSH,&t_new); fcntl(0,F_SETFL,O_ASYNC); /* XXX VGLClear doesn't work.. :-(( Prepare a blank background */ bkg.Bitmap=(byte *)calloc(VGLDisplay->Xsize*VGLDisplay->Ysize,1); bkg.Xsize=VGLDisplay->Xsize; bkg.Ysize=VGLDisplay->Ysize; bkg.Type=VGLDisplay->Type; signal(SIGIO,kbd_handler); a.zoom=1; a.Xshift=(VGLDisplay->Xsize-pic.Xsize)/2; a.Yshift=(VGLDisplay->Ysize-pic.Ysize)/2; a.rotate=0; quit=0; changed=0; display(&pic,pal_red,pal_green,pal_blue,&a); while(!quit) { if(act) { #ifdef DEBUG fprintf(log,"kbd_action(%c)\n",act); #endif kbd_action(x,y,act); } if(quit) break; if(changed) { #ifdef DEBUG fprintf(log,"changed, redisplaying\n"); #endif display(&pic,pal_red,pal_green,pal_blue,&a); changed=0; } if(auto_chg) { sleep(auto_chg); kbd_action(x,y,'n'); } else { pause(); } VGLMouseStatus(&x,&y,&buttons); if(buttons & MOUSE_BUTTON3DOWN) { #ifdef DEBUG fprintf(log,"pop_up called\n"); #endif pop_up("View",x,y); } } VGLEnd(); #ifdef DEBUG fclose(log); #endif exit(0); }