Ejemplo n.º 1
0
void ppu::reg_write(const unsigned int addr,const unsigned char val, const unsigned int cycle) {
    //cout<<"!! "<<phases[phase(cycle)]<<" Write address: 0x"<<hex<<addr<<" Value: 0x"<<int(val)<<dec<<" Cycle: "<<cycle<<endl;
    ppu_phase curphase = phase(cycle);
    if(curphase == RENDER) ++s.writes_during_render;
    switch(addr) {
        case 0x2000:
        {
            int bg_table = control0.bg_table;
            int spr_table = control0.sprite_table;
            control0.reg = val;
            vram_ptr_reset.fields.page_y = (control0.base_addr & 2)/2;
            vram_ptr_reset.fields.page_x = (control0.base_addr & 1);

            int xscroll = (control0.base_addr%2) * 32 + vram_ptr_reset.fields.tile_x;
            int yscroll = (control0.base_addr/2) * 30 + vram_ptr_reset.fields.tile_y;
            if(curphase != RENDER && curphase != POST_RENDER) { //keeps track of where the screen will start
                set_scroll(xscroll*8+fine_x, yscroll*8+vram_ptr_reset.fields.fine_y);
                cart.ppu_change(cycle, BG_CHANGE_ADDR, control0.bg_table);
                cart.ppu_change(cycle, SPR_CHANGE_ADDR, control0.sprite_table);
                //if(control0.bg_table != bg_table) cout<<"Changed the bg table (to "<<control0.bg_table<<"), cycle: "<<cycle<<endl;
                //if(control0.sprite_table != spr_table) cout<<"Changed the sprite table (to "<<control0.sprite_table<<"), cycle: "<<cycle<<endl;
            } else { //keeps track of when (during rendering) the reset shifts, but only worry about the X reset
                set_scroll(xscroll*8+fine_x, yscroll*8+vram_ptr_reset.fields.fine_y, cycle%CLK_PER_LINE, cycle/CLK_PER_LINE);
                if(control0.bg_table != bg_table) {
                    //cout<<"Changed the bg table mid-frame! (to "<<control0.bg_table<<"), cycle: "<<cycle<<endl;
                    cart.ppu_change(cycle, BG_CHANGE_ADDR, 1 - control0.bg_table);
                }
                if(control0.sprite_table != spr_table) {
                    //cout<<"Changed the sprite table mid-frame! (to "<<control0.sprite_table<<"), cycle: "<<cycle<<endl;
                    cart.ppu_change(cycle, SPR_CHANGE_ADDR, 1 - control0.sprite_table);
                }
            }
        }
            break;
        case 0x2001:
            /*
            cout<<"Wrote "<<hex<<val<<dec<<" to 2001 (Color disabled: "<<control1.bits.color_disabled
                <<" show left bg: "<<control1.bits.show_left_bg<<" show left sprites: "<<control1.bits.show_left_sprites
                <<" show bg: "<<control1.bits.show_bg<<" show sprites: "<<control1.bits.show_sprites<<endl;
            */
            control1.reg = val;
            break;
        case 0x2003:
            spraddr = val;
            break;
        case 0x2004:
            if(spraddr/4 == 0) recalc_s0 = true;
            recalc_overflow = true;
            sprites[spraddr/4].val[spraddr%4] = val;
            spraddr++;
            break;
        case 0x2005:
            if(!scroll_latch) {
                vram_ptr_reset.fields.tile_x = (val & 0xf8)>>(3) ;
                fine_x = (val & 0x7);
                //cout<<"Set X reset to ("<<(control0.base_addr&1)*256+vram_ptr_reset.fields.tile_x*8+fine_x<<", "
                //    <<(control0.base_addr&2)*120+vram_ptr_reset.fields.tile_y*8+vram_ptr_reset.fields.fine_y<<") at cycle "
                //    <<cycle<<" ("<<cycle/CLK_PER_LINE<<", "<<cycle%CLK_PER_LINE<<") ("<<phases[curphase]<<")"<<endl;
            }
            else {
Ejemplo n.º 2
0
static void handle_file( LWControl *ectl, void *edata )
{
   char a[ 24 ];
   struct stat s;
   time_t timestamp;

   GET_STR( ectl, filename, sizeof( filename ));
   if ( filename[ 0 ] == 0 ) return;

   if ( fp ) fclose( fp );
   if ( !( fp = fopen( filename, "rb" ))) {
      msgf->error( "Couldn't open", filename );
      return;
   }

   stat( filename, &s );
   filesize = s.st_size;
   timestamp = s.st_mtime;

   pos = 0;
   set_scroll();

   SET_STR( ctl[ 11 ], itoa( filesize, a, 10 ), sizeof( a ));
   strftime( a, sizeof( a ), "%d %b %y %X", localtime( &timestamp ));
   SET_STR( ctl[ 2 ], a, strlen( a ));

   ctl[ 0 ]->draw( ctl[ 0 ], DR_REFRESH );
}
Ejemplo n.º 3
0
/* <crt_quit>:
 * On exit, clear the path-mark line, to set the cursor there.  We also
 * reset the scrolling margins to their default value (without keeping this
 * in our state) so that if this is called from a FLIST-SPAWN command, then
 * we can use 'crt_reset' to restore our scrolling margins.
 *
 * The 'erase' option causes the last line of the screen to be cleared.
 * If the last input was a newline, then VMS will echo this (scrolling up
 * one line on exit).  If not (e.g., CTRL/Z), then the program will exit
 * without scrolling.
 */
void	crt_quit(int erase)
{
	putraw ("\033>");		/* Exit alternate keypad mode */
	scr$set_scroll (1, lpp);
	if (erase)			/* Make a clean exit to command line */
		crt__ED (lpp, 1);
}
Ejemplo n.º 4
0
/* <crt_margin>:
 * If this is an ANSI terminal, we may set scrolling margins.  Both FLIST
 * and BROWSE use the special case of a status line at the end of the page.
 */
void	crt_margin (int lo, int hi)
{
	if (crt_ansi())
		scr$set_scroll (top_margin = lo, end_margin = hi);
	else
		top_margin = 1, end_margin = lpp;
}
Ejemplo n.º 5
0
static void change_pos( int b, int n )
{
   if ( !fp ) return;

   pos = b + n;
   if ( pos > filesize - 1 ) pos = filesize - 1;
   if ( pos < 0 ) pos = 0;
   set_scroll();
   drawcb_text( ctl[ 0 ], NULL, 0 );
}
Ejemplo n.º 6
0
void NesMain(void) {
    unsigned char bgy = 0;
    const char palettebg[] = {
        0x0f, 0x11, 0x21, 0x30,
        0x0f, 0x11, 0x21, 0x30,
        0x0f, 0x11, 0x21, 0x30,
        0x0f, 0x11, 0x21, 0x30
    };

    const char palettespr[] = {
        0x0f, 0x00, 0x10, 0x21,
        0x0f, 0x0f, 0x10, 0x21,
        0x0f, 0x09, 0x19, 0x21,
        0x0f, 0x15, 0x27, 0x30
    };

    init_ppu();

    set_palette((char *)palettebg, 0);
    set_palette((char *)palettespr, 1);

    set_background(0x21, 0xc9, "HELLO, WORLD!", 13);

    set_scroll(0, 0);
    set_ppu(0x08, 0x1e);

    while (1) {
        vblank();

        bgy++;

        if (bgy == 240) {
            bgy == 0;
        }
        set_scroll(0, bgy);
        frame++;
    }
}
Ejemplo n.º 7
0
void Level::update()
{
  if (m_look_time > 0) {
    double t = exp_ramp(m_look_time, LOOK_AT_DURATION);
    set_scroll(m_look_from + (m_look_to - m_look_from) * t);
    if (GAME_T - m_look_time > LOOK_AT_DURATION) {
      m_look_time = 0;
      set_scroll(m_look_to);
    }
  }

  if (m_angels_to_generate > 0) {
    if (m_last_angel_time == 0) {
      m_last_angel_time = GAME_T;
      m_angels_to_generate--;

      GAMEPLAY->add_angel(new Angel(get_random_pos_for_angel()));
    }
    else if (GAME_T - m_last_angel_time > m_level_angel_interval * BPS) {
      m_last_angel_time = 0;
    }
  }
}
Ejemplo n.º 8
0
Level::Level(int num)
{
  int w, h;

  switch (num) {
    case 1:
      w = 40;
      h = 30;
      m_angels_to_generate = 10;
      m_level_angel_interval = 2.0;
      m_max_dist_to_abduct = 3.0;
      m_min_angel_energy = 4.0;
      m_max_angel_energy = 10.0;
      break;
    case 2:
      w = 50;
      h = 20;
      m_angels_to_generate = 15;
      m_level_angel_interval = 1.5;
      m_max_dist_to_abduct = 5.0;
      m_min_angel_energy = 8.0;
      m_max_angel_energy = 20.0;
      break;
    case 3:
      w = 60;
      h = 15;
      m_angels_to_generate = 20;
      m_level_angel_interval = 1.0;
      m_max_dist_to_abduct = 10.0;
      m_min_angel_energy = 15.0;
      m_max_angel_energy = 40.0;
      break;
  }

  m_is_old = false;
  m_num = num;
  m_last_angel_time = 0;
  m_look_time = 0;

  set_tiles_size(w, h);
//   set_scroll(get_start_pos() - vector2d(GFX_CX, GFX_CY));
  set_scroll(get_start_pos() + vector2d(-GFX_CX, GFX_CY));

  for (int y=0; y<m_h; ++y)
    for (int x=0; x<m_w; ++x) {
      m_tiles_bg[y*m_w+x] = TILE_NOTHING;
      m_tiles_fg[y*m_w+x] = (y == m_h-1) ? TILE_FLOOR_EXTERN:
					   TILE_NOTHING;
    }
}
Ejemplo n.º 9
0
bool App::event_keydown(WPARAM wParam){
	if(wParam==VK_ESCAPE){
        if(Config::geti()->fullscreen_on){ //wyjœcie z fullscreena
            fullscreen_set(false);
        }else{
            Controls::geti()->set_focus("editor");
        }
	}else if(wParam==VK_F1){
		set_scroll(0);
	}else if(wParam==VK_F2){
		change_scroll(-35);
	}else if(wParam==VK_F3){
		change_scroll(+35);
	}else if(wParam==VK_F5){
		autoscroll_nowait(+Config::geti()->autoscroll_interval*0.25);
	}else if(wParam==VK_F6){
		autoscroll_nowait(-Config::geti()->autoscroll_interval*0.2);
	}else if(wParam==VK_F7){
		autoscroll_switch();
	}else if(wParam==VK_F8){
		if(Config::geti()->autoscroll){
			autoscroll_off();
			IO::geti()->echo("Autoscroll wy³¹czony");
		}else{
			autoscroll_nowait();
		}
	}else if(wParam==VK_F9){
		toolbar_switch();
	}else if(wParam==VK_F10 || wParam==VK_F11){
        fullscreen_toggle();
	}
    //ctrl
	if(is_control_pressed()){
		if(wParam=='S'){
			save_chords_file();
		}else if(wParam=='F'){
            if(!Config::geti()->toolbar_show){
                toolbar_switch(1);
            }
			Controls::geti()->set_focus("find_edit");
		}else if(wParam=='N'){
            new_file();
        }else if(wParam=='B'){
            chordsbase_start();
        }else if(wParam==VK_ADD){
			change_font_size(+1);
		}else if(wParam==VK_SUBTRACT){
			change_font_size(-1);
		}else if(wParam==VK_OEM_3){ // znaczek `
            cmd_switch();
            if(Config::geti()->cmd_show){
                Controls::geti()->set_focus("cmd");
                Controls::geti()->select_all("cmd");
            }else{
                Controls::geti()->set_focus("editor");
            }
		}else if(wParam==VK_LEFT){
			transpose(-1);
		}else if(wParam==VK_RIGHT){
			transpose(+1);
		}else if(wParam=='0'||wParam==VK_NUMPAD0){
			transpose(-Config::geti()->transposed);
		}
	}
    return true; //przechwycenie
}
Ejemplo n.º 10
0
void App::event_button(WPARAM wParam){
    string name = "";
    if(wParam>=1 && wParam<=Controls::geti()->controls.size()){
        name = Controls::geti()->get_button_name(wParam);
    }else{
        name = Controls::geti()->get_menu_name(wParam);
    }
    if(name.length()==0) return;
	if(name == "new"){ //nowy
		new_file();
	}else if(name == "load"){ //wczytaj
        if(!Config::geti()->toolbar_show){
            toolbar_switch(1);
        }
        string str2 = Controls::geti()->get_text("filename_edit");
		if(str2.length()==0){
			IO::geti()->echo("Podaj nazwê pliku.");
		}else{
			open_chords_file(str2);
		}
	}else if(name == "save"){ //zapisz
		save_chords_file();
	}else if(name == "analyze"){ //analizuj
		analyze();
	}else if(name == "replace"){ //zamieñ
        if(!Config::geti()->toolbar_show){
            toolbar_switch(1);
            return;
        }
		zamien();
	}else if(name == "find"){ //znajdŸ
        if(!Config::geti()->toolbar_show){
            toolbar_switch(1);
            return;
        }
		znajdz();
	}else if(name == "undo"){
        undo->revert();
	}else if(name == "base"){ //baza akordów
        chordsbase_start();
	}else if(name == "autoscroll"){ //autoscroll
		autoscroll_switch();
	}else if(name == "reload"){
        open_chords_file(Config::geti()->opened_file);
    }else if(name == "config"){
        ShellExecute(0,"open",Config::geti()->config_filename.c_str(),"",0,SW_SHOW);
    }else if(name == "quick_replace"){
        quick_replace();
    }else if(name == "remove_chords"){
        usun_akordy();
    }else if(name == "remove_alt"){
        usun_wersje();
    }else if(name == "add_chord"){
        dodaj_nawias();
    }else if(name == "font++"){
        change_font_size(+1);
    }else if(name == "font--"){
        change_font_size(-1);
    }else if(name == "format_text"){
        refresh_text();
    }else if(name == "fullscreen"){
        fullscreen_toggle();
    }else if(name == "autoscroll_wait"){
        autoscroll_on();
    }else if(name == "autoscroll_nowait"){
        autoscroll_nowait();
    }else if(name == "autoscroll_off"){
        autoscroll_off();
        IO::geti()->echo("Autoscroll wy³¹czony");
    }else if(name == "autoscroll_slower"){
        autoscroll_nowait(+Config::geti()->autoscroll_interval*0.25);
    }else if(name == "autoscroll_faster"){
        autoscroll_nowait(-Config::geti()->autoscroll_interval*0.2);
    }else if(name == "transpose+5"){
        transpose(+5);
    }else if(name == "transpose++"){
        transpose(+1);
    }else if(name == "transpose--"){
        transpose(-1);
    }else if(name == "transpose-5"){
        transpose(-5);
    }else if(name == "transpose0"){
        transpose(-Config::geti()->transposed);
    }else if(name == "alt"){
        dodaj_alternatywne();
    }else if(name == "log"){
        ShellExecute(0, "open", Config::geti()->log_filename.c_str(), "", 0, SW_SHOW);
    }else if(name == "associate_files"){
        associate_files();
    }else if(name == "help"){
        show_help();
    }else if(name == "info"){
        stringstream ss;
        ss<<Config::geti()->program_name<<endl;
        ss<<"wersja "<<version<<endl;
        IO::geti()->message_box("O programie",ss.str());
    }else if(name == "cmd_toggle"){
        cmd_switch();
    }else if(name == "toolbar_toggle"){
        toolbar_switch();
    }else if(name == "scroll_to_begin"){
        set_scroll(0);
    }else if(name == "scroll_to_end"){
        SendMessage(Controls::geti()->find("editor"), WM_VSCROLL, SB_BOTTOM, 0);
    }else if(name == "save_pattern"){
        save_pattern();
    }else if(name == "insert_pattern"){
        insert_pattern();
    }else if(name == "exit"){
        DestroyWindow(main_window);
    }else{
        IO::geti()->error("Zdarzenie nie zosta³o obs³u¿one: "+name);
    }
}
Ejemplo n.º 11
0
void GUI_TextBox::on_mouse_wheel(MouseEventArgs const& e)
{
//#warning FIXME Что за магическое 30?
	set_scroll(e.value / 30);
}
Ejemplo n.º 12
0
			void reset_scroll() { set_scroll(vtx::spos(0)); }
Ejemplo n.º 13
0
Archivo: gvccmd.c Proyecto: 131/gsview
/* gsview menu commands */
int
gsview_command(int command)
{
    switch (command) {
    case IDM_NEXTHOME:
    case IDM_NEXT:
    case IDM_NEXTSKIP:
    case IDM_REDISPLAY:
    case IDM_PREVHOME:
    case IDM_PREVSKIP:
    case IDM_PREV:
    case IDM_GOBACK:
    case IDM_GOFWD:
    case IDM_MAGPLUS:
    case IDM_MAGMINUS:
    case IDM_FITWIN:
    case IDM_ZOOM:
    case IDM_FULLSCREEN:
        /* These don't close the full screen window */
        break;
    default:
        gsview_fullscreen_end();
    }
    switch (command) {
    case IDM_FULLSCREEN:
        gsview_fullscreen();
        return 0;
    case IDM_OPEN:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        gsview_display();
        return 0;
    case IDM_LASTFILE1:
    case IDM_LASTFILE2:
    case IDM_LASTFILE3:
    case IDM_LASTFILE4:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        make_cwd(last_files[command-IDM_LASTFILE1]);
        gsview_displayfile(last_files[command-IDM_LASTFILE1]);
        return 0;
    case IDM_CLOSE:
        /* doesn't unload DLL */
        /* close file */
        if (gsdll.open && (gsdll.state != GS_UNINIT)) {
            PSFILE *tpsfile;
            if (pending.psfile) {
                play_sound(SOUND_BUSY);
                return 0;
            }
            tpsfile = (PSFILE *)malloc(sizeof(PSFILE));
            if (tpsfile == NULL)
                return 0;
            memset((char *)tpsfile, 0, sizeof(PSFILE));
            pending.psfile = tpsfile;
            pending.now = TRUE;
            if (psfile.name[0] && psfile.dsc==(CDSC *)NULL)
                pending.abort = TRUE;
        }
        else {
            /* DLL isn't loaded */
            if (psfile.file)
                dfclose();	/* just to make sure */
            psfile_free(&psfile);
            post_img_message(WM_GSTITLE, 0);
            info_wait(IDS_NOWAIT);
        }
        return 0;
    case IDM_CLOSE_DONE:
        if (selectname[0] != '\0') {
            /* pending IDM_SELECT */
            PSFILE *tpsfile;
            tpsfile = gsview_openfile(selectname);
            if (tpsfile) {
                psfile = *tpsfile;
                free(tpsfile);
            }
            selectname[0] = '\0';
            post_img_message(WM_GSTITLE, 0);
            info_wait(IDS_NOWAIT);
        }
        return 0;
    case IDM_NEXTHOME:
#ifdef UNIX
        set_scroll(-1, 0);
#else
#ifdef _Windows
        PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L);
#else
        WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP));
#endif
#endif
    /* fall thru */
    case IDM_NEXT:
        if (not_open())
            return 0;
        gs_page_skip(1);
        return 0;
    case IDM_NEXTSKIP:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(page_skip);
        return 0;
    case IDM_REDISPLAY:
        if (dfchanged()) {
            PSFILE *tpsfile;
            if (dfchanged() < 0) {
                gs_addmess("File has been deleted\n");
                gsview_command(IDM_CLOSE);
                pending.unload = TRUE;
                pending.now = FALSE;
                return 0;
            }
            if (pending.psfile)
                tpsfile = pending.psfile;	/* new file, old file deleted */
            else
                tpsfile = gsview_openfile(psfile.name);
            if (tpsfile) {
                tpsfile->pagenum = psfile.pagenum;
                request_mutex();
                pending.psfile = tpsfile;
                if ( gsdll.hmodule &&  (psfile.dsc==(CDSC *)NULL) &&
                        (gsdll.state != GS_IDLE) )
                    /* don't know where we are so close and reopen */
                    pending.abort = TRUE;
                pending.now = TRUE;
                release_mutex();
            }
        }

        if (not_open())
            return 0;
        if (psfile.dsc==(CDSC *)NULL) {
            /* don't know where we are so close and reopen */
            if (gsdll.state != GS_IDLE) {
                if (!pending.psfile) {
                    pending.psfile = (PSFILE *)malloc(sizeof(PSFILE));
                    if (pending.psfile)
                        *pending.psfile = psfile;
                }
                pending.psfile->pagenum = pending.pagenum = 1;
                pending.abort = TRUE;
                pending.now = TRUE;
            }
        }
        else {
            pending.pagenum = -1;  /* default page number is current page */
            if (psfile.dsc->page_order == CDSC_SPECIAL)
                pending.pagenum = 1;	/* restart */
        }
        gsview_unzoom();
        pending.now = TRUE;
        return 0;
    case IDM_PREVHOME:
#ifdef UNIX
        set_scroll(-1, 0);
#else
#ifdef _Windows
        PostMessage(hwnd_image ,WM_VSCROLL,SB_TOP,0L);
#else
        WinPostMsg(hwnd_frame, WM_VSCROLL, MPFROMLONG(0), MPFROM2SHORT(0, SB_TOP));
#endif
#endif
    /* fall thru */
    case IDM_PREV:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(-1);
        return 0;
    case IDM_PREVSKIP:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        gs_page_skip(-page_skip);
        return 0;
    case IDM_GOTO:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        if (psfile.dsc->page_count == 0) {
            gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
            return 0;
        }
        nHelpTopic = IDS_TOPICGOTO;
        {   int pagenum;
            pagenum = psfile.pagenum;
            if (get_page(&pagenum, FALSE, FALSE)) {
                gsview_goto_page(pagenum);
            }
        }
        return 0;
    case IDM_GOBACK:
        if (not_dsc())
            return 0;
        if (order_is_special())
            return 0;
        history_back();
        return 0;
    case IDM_GOFWD:
        if (not_open())
            return 0;
        if (psfile.dsc == (CDSC *)NULL)
            gsview_command(IDM_NEXT);
        else
            history_forward();
        return 0;
    case IDM_INFO:
        show_info();
        return 0;
    case IDM_SELECT:
        if (pending.psfile) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        gsview_select();
        return 0;
#ifndef VIEWONLY
    case IDM_PRINT:
    case IDM_PRINTTOFILE:
    case IDM_CONVERTFILE:
        if (psfile.name[0] == '\0')
            gsview_select();
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (dfreopen() != 0)
            return 0;
        if (command == IDM_PRINTTOFILE)
            option.print_to_file = TRUE;
        if (psfile.name[0] != '\0')
            gsview_print(command == IDM_CONVERTFILE);
        dfclose();
        return 0;
    case IDM_SPOOL:
        gsview_spool((char *)NULL, (char *)NULL);
        return 0;
    case IDM_SAVEAS:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        if (psfile.name[0] != '\0')
            gsview_saveas();
        return 0;
    case IDM_EXTRACT:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        if (order_is_special())
            return 0;
        if (psfile.name[0] != '\0')
            gsview_extract();
        return 0;
    case IDM_PSTOEDIT:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        if (psfile.name[0] == '\0')
            gsview_select();
        (void)order_is_special();    /* warn, but allow it anyway */
        if (dfreopen() != 0)
            return 0;
        if (psfile.name[0] != '\0')
            gsview_pstoedit();
        dfclose();
        return 0;
    case IDM_TEXTEXTRACT:
        if (psfile.name[0] == '\0')
            gsview_select();
        if (psfile.name[0] != '\0')
            gsview_text_extract();
        return 0;
    case IDM_TEXTEXTRACT_SLOW:
        gsview_text_extract_slow();
        return 0;
    case IDM_TEXTFIND:
        gsview_text_find();
        return 0;
    case IDM_TEXTFINDNEXT:
        gsview_text_findnext();
        return 0;
    case IDM_COPYCLIP:
        copy_clipboard();
        return 0;
    case IDM_PASTETO:
        paste_to_file();
        return 0;
    case IDM_CONVERT:
        clip_convert();
        return 0;
    case IDM_MEASURE:
        if (gsdll.state == GS_BUSY) {
            play_sound(SOUND_BUSY);
            return 0;
        }
        measure_show();
        return 0;
#endif /* !VIEWONLY */
    case IDM_GSMESS:
        gs_showmess();	/* show messages from Ghostscript */
        return 0;
    case IDM_EXIT:
        if (print_count) {
            /* Still busy printing.  Warn user. */
            TCHAR buf[MAXSTR];
            load_string(IDS_BUSYPRINTING, buf,
                        sizeof(buf)/sizeof(TCHAR)-1);
            if (message_box(buf, MB_OKCANCEL) != IDOK)
                return 0;
        }
        post_img_message(WM_CLOSE, 0);
        return 0;
    case IDM_CFG:	/* Easy configure */
        config_wizard(TRUE);
        return 0;
    case IDM_GSCOMMAND:	/* Advanced configure */
        if (install_gsdll() && gsdll.open)
            pending.unload = TRUE;
        return 0;
    case IDM_UNITPT:
    case IDM_UNITMM:
    case IDM_UNITINCH:
        gsview_unit(command);
        return 0;
    case IDM_UNITFINE:
        option.unitfine = !option.unitfine;
        check_menu_item(IDM_UNITMENU, IDM_UNITFINE, option.unitfine);
        return 0;
    case IDM_LANGMENU+1:
    case IDM_LANGMENU+2:
    case IDM_LANGMENU+3:
    case IDM_LANGMENU+4:
    case IDM_LANGMENU+5:
    case IDM_LANGMENU+6:
    case IDM_LANGMENU+7:
    case IDM_LANGMENU+8:
    case IDM_LANGMENU+9:
    case IDM_LANGMENU+10:
    case IDM_LANGMENU+11:
    case IDM_LANGMENU+12:
    case IDM_LANGMENU+13:
    case IDM_LANGMENU+14:
    case IDM_LANGMENU+15:
    case IDM_LANGMENU+16:
    case IDM_LANGMENU+17:
    case IDM_LANGMENU+18:
    case IDM_LANGMENU+19:
        gsview_language(command);
        return 0;
    case IDM_SAFER:
        option.safer = !option.safer;
        check_menu_item(IDM_OPTIONMENU, IDM_SAFER, option.safer);
        return 0;
    case IDM_SAVEDIR:
        option.save_dir = !option.save_dir;
        check_menu_item(IDM_OPTIONMENU, IDM_SAVEDIR, option.save_dir);
        return 0;
    case IDM_BUTTONSHOW:
        option.button_show = !option.button_show;
        check_menu_item(IDM_OPTIONMENU, IDM_BUTTONSHOW, option.button_show);
        show_buttons();
        return 0;
    case IDM_FITPAGE:
        option.fit_page = !option.fit_page;
        check_menu_item(IDM_OPTIONMENU, IDM_FITPAGE, option.fit_page);
        /* should cause WM_SIZE message to be sent */
        return 0;
    case IDM_PSTOTEXTDIS:
    case IDM_PSTOTEXTNORM:
    case IDM_PSTOTEXTCORK:
        check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, FALSE);
        option.pstotext = command - IDM_PSTOTEXTMENU - 1;
        check_menu_item(IDM_PSTOTEXTMENU, option.pstotext + IDM_PSTOTEXTMENU + 1, TRUE);
        return 0;
    case IDM_AUTOREDISPLAY:
        option.redisplay = !option.redisplay;
        check_menu_item(IDM_OPTIONMENU, IDM_AUTOREDISPLAY, option.redisplay);
        return 0;
    case IDM_EPSFCLIP:
        option.epsf_clip = !option.epsf_clip;
        check_menu_item(IDM_OPTIONMENU, IDM_EPSFCLIP, option.epsf_clip);
        gs_resize();
        return 0;
    case IDM_EPSFWARN:
        option.epsf_warn = !option.epsf_warn;
        check_menu_item(IDM_OPTIONMENU, IDM_EPSFWARN, option.epsf_warn);
        return 0;
    case IDM_IGNOREDSC:
        option.ignore_dsc = !option.ignore_dsc;
        check_menu_item(IDM_OPTIONMENU, IDM_IGNOREDSC, option.ignore_dsc);
        if (psfile.name[0]) {
            if (option.redisplay)
                gsview_displayfile(psfile.name);
            else
                gsview_selectfile(psfile.name);
        }
        return 0;
    case IDM_SHOWBBOX:
        option.show_bbox = !option.show_bbox;
        check_menu_item(IDM_OPTIONMENU, IDM_SHOWBBOX, option.show_bbox);
#ifdef UNIX
        gtk_widget_draw(img, NULL);
#else
#ifdef _Windows
        PostMessage(hwndimg, WM_GSSYNC, 0, 0L);
#else
        if (!WinInvalidateRect(hwnd_bmp, (PRECTL)NULL, TRUE))
            error_message("error invalidating rect");
        if (!WinUpdateWindow(hwnd_bmp))
            error_message("error updating window");
#endif
#endif
        return 0;
#ifndef VIEWONLY
    case IDM_PSTOEPS:
        if (not_open())
            return 0;
        if (psfile.name[0] != '\0') {
            if (dfreopen() != 0)
                return 0;
            ps_to_eps();
            dfclose();
        }
        return 0;
    case IDM_MAKEEPSI:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_interchange(FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPST4:
    case IDM_MAKEEPST6U:
    case IDM_MAKEEPST6P:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_tiff(command, FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPSW:
        if ( (option.orientation == IDM_PORTRAIT) ||
                (option.auto_orientation == TRUE) ) {
            char epsname[MAXSTR];
            epsname[0] = '\0';
            if (dfreopen() != 0)
                return 0;
            if (!get_filename(epsname, TRUE, FILTER_EPS, 0,
                              IDS_TOPICPREVIEW)) {
                dfclose();
                return 0;
            }
            image_lock(view.img);
            make_eps_metafile(FALSE, epsname);
            image_unlock(view.img);
            dfclose();
        }
        else
            gserror(IDS_MUSTUSEPORTRAIT, 0, MB_ICONEXCLAMATION, 0);
        return 0;
    case IDM_MAKEEPSU:
        if (dfreopen() != 0)
            return 0;
        make_eps_user();
        dfclose();
        return 0;
    case IDM_EXTRACTPS:
    case IDM_EXTRACTPRE:
        if (dfreopen() != 0)
            return 0;
        extract_doseps(command);
        dfclose();
        return 0;
#endif
    case IDM_SETTINGS:
        write_profile();
        return 0;
    case IDM_SAVESETTINGS:
        option.settings = !option.settings;
        check_menu_item(IDM_OPTIONMENU, IDM_SAVESETTINGS, option.settings);
        {   char buf[MAXSTR];
            PROFILE *prf = profile_open(szIniFile);
            sprintf(buf, "%d", (int)option.settings);
            profile_write_string(prf, INISECTION, "SaveSettings", buf);
            profile_close(prf);
        }
        return 0;
    case IDM_SOUNDS:
        change_sounds();
        return 0;
    case IDM_AUTOORIENT:
    case IDM_PORTRAIT:
    case IDM_LANDSCAPE:
    case IDM_UPSIDEDOWN:
    case IDM_SEASCAPE:
    case IDM_SWAPLANDSCAPE:
        gsview_orientation(command);
        return 0;
    case IDM_DSC_OFF:
    case IDM_DSC_ERROR:
    case IDM_DSC_WARN:
    case IDM_DSC_INFO:
        check_menu_item(IDM_DSCMENU, option.dsc_warn, FALSE);
        option.dsc_warn = command;
        check_menu_item(IDM_DSCMENU, option.dsc_warn, TRUE);
        return 0;
    case IDM_ZOOM:		/* called indirectly from Right Mouse Button */
        if (not_dsc()) {
            zoom = FALSE;
            return 0;
        }
        if (order_is_special()) {
            zoom = FALSE;
            return 0;
        }
        if (! ((gsdll.state == GS_PAGE) || (gsdll.state == GS_IDLE)) ) {
            zoom = FALSE;
            gserror(IDS_NOZOOM, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
            return 0;
        }
        gs_resize();
        pending.pagenum = -1;  /* default page number is current page */
        pending.now = TRUE;
        return 0;
    case IDM_MAGPLUS:
        gs_magnify((float)1.2);
        return 0;
    case IDM_MAGMINUS:
        gs_magnify((float)0.8333);
        return 0;
    case IDM_FITWIN:
        /* fit media to size of current window */
        gsview_fitwin();
        return 0;
    case IDM_DISPLAYSETTINGS:
        display_settings();
        return 0;
    case IDM_MEDIAROTATE:
        option.media_rotate = !option.media_rotate;
        check_menu_item(IDM_MEDIAMENU, IDM_MEDIAROTATE,
                        option.media_rotate);
        zoom = FALSE;
        gs_resize();
        return 0;
    case IDM_11x17:
    case IDM_A3:
    case IDM_A4:
    case IDM_A5:
    case IDM_B4:
    case IDM_B5:
    case IDM_LEDGER:
    case IDM_LEGAL:
    case IDM_LETTER:
    case IDM_NOTE:
    case IDM_USERSIZE:
    case IDM_USERSIZE1:
    case IDM_USERSIZE2:
    case IDM_USERSIZE3:
    case IDM_USERSIZE4:
    case IDM_USERSIZE5:
    case IDM_USERSIZE6:
    case IDM_USERSIZE7:
    case IDM_USERSIZE8:
    case IDM_USERSIZE9:
    case IDM_USERSIZE10:
    case IDM_USERSIZE11:
    case IDM_USERSIZE12:
    case IDM_USERSIZE13:
        if (command == IDM_USERSIZE)
            if (!gsview_usersize())
                return 0;
        gsview_media(command);
        return 0;
    case IDM_HELPCONTENT:
#ifdef UNIX
        nHelpTopic = IDS_TOPICROOT;
        get_help();
#else
#ifdef _Windows
#ifdef USE_HTMLHELP
        nHelpTopic = IDS_TOPICROOT;
        get_help();
#else
        WinHelp(hwndimg,szHelpName,HELP_CONTENTS,(DWORD)NULL);
#endif
#else
        WinSendMsg(hwnd_help, HM_HELP_CONTENTS, 0L, 0L);
#endif
#endif
        return 0;
    case IDM_HELPSEARCH:
#ifdef UNIX
        gs_addmess("IDM_HELPSEARCH: not implemented\n");
#else
#ifdef _Windows
#ifdef USE_HTMLHELP
        HtmlHelp(hwndimg,szHelpName,HH_DISPLAY_INDEX, (DWORD)TEXT(""));
        gs_addmessf("HtmlHelp: %s HH_DISPLAY_INDEX\n", szHelpName);
#else
        WinHelp(hwndimg,szHelpName,HELP_PARTIALKEY,(DWORD)"");
#endif
#else
        WinSendMsg(hwnd_help, HM_HELP_INDEX, 0L, 0L);
#endif
#endif
        return 0;
    case IDM_HELPKEYS:
        nHelpTopic = IDS_TOPICKEYS;
        get_help();
        return 0;
    case IDM_ABOUT:
        show_about();
        return 0;
    case IDM_REGISTER:
        registration_nag();
        return 0;
    }
    return 0;
}