⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reader.cxx

📁 一个小的非常好用的电子书阅读器源码
💻 CXX
📖 第 1 页 / 共 4 页
字号:
  }  static void bunindent_cb(Fl_Widget* o, void* _data)  {    ((reader_ui*)_data)->bunindent = !(((reader_ui*)_data)->bunindent);    ((reader_ui*)_data)->setfilter();  }  static void brepara_cb(Fl_Widget* o, void* _data)  {    ((reader_ui*)_data)->brepara = !(((reader_ui*)_data)->brepara);    ((reader_ui*)_data)->setfilter();  }  static void bindenterp_cb(Fl_Widget* o, void* _data)  {    ((reader_ui*)_data)->bindenter += 2;    ((reader_ui*)_data)->setfilter();  }  static void bindenterm_cb(Fl_Widget* o, void* _data)  {    if (((reader_ui*)_data)->bindenter < 2)      ((reader_ui*)_data)->bindenter = 0;    else      ((reader_ui*)_data)->bindenter -= 2;    ((reader_ui*)_data)->setfilter();  }  static void bdblspce_cb(Fl_Widget* o, void* _data)  {    ((reader_ui*)_data)->bdblspce = !(((reader_ui*)_data)->bdblspce);    ((reader_ui*)_data)->setfilter();  }  static void info_cb(Fl_Widget* o, void* _data)  {    static Fl_Window* infowin = NULL;    static Fl_Output* filename;    static Fl_Output* filesize;    static Fl_Output* textsize;    static CBar* comprat;    static Fl_Output* posn;    static CBar* frcn;    static Fl_Multiline_Output* about;    if (infowin == NULL)      {	infowin = new Fl_Window(160,240);	//infowin = new_cwindow(160,240);	//infowin->border(0);	//infowin->box(FL_UP_BOX);	filename = new Fl_Output(45,5,110,14,"Filename");	filename->textsize(10);	filename->labelsize(10);	filesize = new Fl_Output(45,25,110,14,"Filesize");	filesize->textsize(10);	filesize->labelsize(10);	textsize = new Fl_Output(45,45,110,14,"Textsize");	textsize->textsize(10);	textsize->labelsize(10);	comprat = new CBar(45,65,110,14,"Ratio %");	comprat->labelsize(10);	posn = new Fl_Output(45,85,110,14,"Location");	posn->textsize(10);	posn->labelsize(10);	frcn = new CBar(45,105,110,14,"% Read");	frcn->labelsize(10);	about = new Fl_Multiline_Output(5,125,150,90);	about->textsize(10);	about->value("TWReader - $Name: V1_1 $\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");	Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");	jump_accept->labelsize(10);	jump_accept->callback(Cancel_cb,_data);	infowin->end();	infowin->set_modal();      }    unsigned long fs,ts;    char sz[20];    ((reader_ui *)_data)->input->sizes(fs,ts);    unsigned long pl = ((reader_ui *)_data)->input->locate();    filename->value(((reader_ui *)_data)->g_filename);    sprintf(sz,"%u",fs);    filesize->value(sz);    sprintf(sz,"%u",ts);    textsize->value(sz);    comprat->value(100-(100*fs + (ts >> 1))/ts);    sprintf(sz,"%u",pl);    posn->value(sz);    frcn->value((100*pl + (ts >> 1))/ts);    infowin->show();  }  reader_ui() : bstripcr(false), bunindent(false), brepara(false), bindenter(0), bdblspce(false), btight(false)  {    g_filename[0] = '\0';#ifdef AGENDA    window = Widget_Factory::new_window("TWReader");    input = new myoutput(0, 0, Fl_Group::current()->w(), Fl_Group::current()->h());    input->textfont(FL_HELVETICA);    input->textsize(8);    Fl_Group::current()->resizable(input);    getprefs();    input->tight = btight;    int boolflag = FL_MENU_TOGGLE | ((bold) ? FL_MENU_VALUE : 0);    int stripflag = FL_MENU_TOGGLE | ((bstripcr) ? FL_MENU_VALUE : 0);    int unindentflag = FL_MENU_TOGGLE | ((bunindent) ? FL_MENU_VALUE : 0);    int paraflag = FL_MENU_TOGGLE | ((brepara) ? FL_MENU_VALUE : 0);    int dblflag = FL_MENU_TOGGLE | ((bdblspce) ? FL_MENU_VALUE : 0);    int tightflag = FL_MENU_TOGGLE | ((btight) ? FL_MENU_VALUE : 0);    Fl_Dockable_Window* toolbar = Widget_Factory::new_toolbar();      Fl_Button *done_button = Widget_Factory::new_button("Done", quit_cb, this);      Fl_Menu_Button* menubar = Widget_Factory::new_menu_button("File");      menubar->add("Open",0,open_cb,this);      menubar->add("Info",0,info_cb,this);      menubar->add("Find",0,find_cb,this);      menubar->add("Find Again",0,find2_cb,this);      menubar->add("Jump",0,jump_cb,this);#ifdef USEBKMKS      menubar = Widget_Factory::new_menu_button("Marks");      menubar->add("Mark",0,save_cb,this);      menubar->add("Goto",0,getbkmk_cb,this);      menubar->add("Delete",0,delbkmk_cb,this);      menubar->add("Autogen",0,autogenbkmk_cb,this);      menubar->add("Clear",0,clrbkmk_cb,this);      menubar->add("Tidy",0,tidybkmk_cb,this);#endif      menubar = Widget_Factory::new_menu_button("View");      menubar->add("Magnify",0,mag_cb,this);      menubar->add("Reduce",0,red_cb,this);      menubar->add("Font",0,fnt_cb,this);      menubar->add("Bold",0,bld_cb,this,boolflag);      menubar->add("Tight",0,tight_cb,this,tightflag);      menubar = Widget_Factory::new_menu_button("Format");      menubar->add("StripCR",0,bstripcr_cb,this,stripflag);      menubar->add("Unindent",0,bunindent_cb,this,unindentflag);      menubar->add("Repara",0,brepara_cb,this,paraflag);      menubar->add("Indent+",0,bindenterp_cb,this,0);      menubar->add("Indent-",0,bindenterm_cb,this,0);      menubar->add("DblSpace",0,bdblspce_cb,this,dblflag);    toolbar->end();    window->add_dockable(toolbar,1);    window->end();#else    window = new Fl_Window(Fl::w()/2,Fl::h()/2,"TWReader");#ifdef WS    input = new myoutput(0, 20, window->w(), window->h()-20);#else    input = new myoutput(0, 12, window->w(), window->h()-12);#endif    input->textfont(FL_HELVETICA);    input->textsize(12);    window->resizable(input);    getprefs();    input->tight = btight;    int boolflag = FL_MENU_TOGGLE | ((bold) ? FL_MENU_VALUE : 0);    int stripflag = FL_MENU_TOGGLE | ((bstripcr) ? FL_MENU_VALUE : 0);    int unindentflag = FL_MENU_TOGGLE | ((bunindent) ? FL_MENU_VALUE : 0);    int paraflag = FL_MENU_TOGGLE | ((brepara) ? FL_MENU_VALUE : 0);    int dblflag = FL_MENU_TOGGLE | ((bdblspce) ? FL_MENU_VALUE : 0);    int tightflag = FL_MENU_TOGGLE | ((btight) ? FL_MENU_VALUE : 0);    static Fl_Menu_Item menuitems[] =      {	{ "File", 0, 0, 0, FL_SUBMENU },	{ "&Open", FL_ALT+'o', open_cb, this },	{ "&Quit", FL_ALT+'q', quit_cb, this},	{ "&Info", FL_ALT+'i', info_cb,this},	{ 0 },	{ "Search", 0, 0, 0, FL_SUBMENU },	{ "&Find",FL_ALT+'f',find_cb,this},	{"Find A&gain",FL_ALT+'g',find2_cb,this},	{"&Jump",FL_ALT+'j',jump_cb,this},#ifdef USEBKMKS	{ "&Mark Current", FL_ALT+'m', save_cb,this},	{"Goto mar&k",FL_ALT+'k',getbkmk_cb,this},	{ "More Bookmarks", 0, 0, 0, FL_SUBMENU },	{ "De&lete Mark", FL_ALT+'l', delbkmk_cb, this},	{"&Autogen",FL_ALT+'a',autogenbkmk_cb,this},	{"&Clear",FL_ALT+'c',clrbkmk_cb,this},	{"&Tidy",FL_ALT+'t',tidybkmk_cb,this},	{0},#endif	{0},	{"View",0,0,0,FL_SUBMENU},	{"&Zoom in",FL_ALT+'z',mag_cb,this},	{"&Zoom out",FL_ALT+'Z',red_cb,this},	{"Fo&nt",FL_ALT+'n',fnt_cb,this},	{"Bold",FL_ALT+'b',bld_cb,this,boolflag},	{"Tight",FL_ALT+'w',tight_cb,this,tightflag},	{0},	{"Format",0,0,0,FL_SUBMENU},	{"StripCR",0,bstripcr_cb,this,stripflag},	{"Unindent",0,bunindent_cb,this,unindentflag},	{"Repara",0,brepara_cb,this,paraflag},	{"Indent+",0,bindenterp_cb,this,0},	{"Indent-",0,bindenterm_cb,this,0},	{"DblSpace",0,bdblspce_cb,this,dblflag},	{0},	{0}      };#ifdef WS    Fl_Menu_Bar *menubar= new Fl_Menu_Bar(0,0,window->w(),20);#else    Fl_Menu_Bar *menubar= new Fl_Menu_Bar(0,0,window->w(),12);    menubar->textsize(8);#endif    menubar->menu(menuitems);    window->end();#endif    //    input = new myoutput(0, 0, Fl_Group::current()->w(), Fl_Group::current()->h(),toolbar);    //    //    Fl_Group::current()->resizable(input);    //    input->callback((Fl_Callback *)changed_cb);    //    input->when(FL_WHEN_CHANGED);#ifdef USEBKMKS    setupbkmks();#endif    //  window->callback((Fl_Callback *)quit_cb);    setfilter();    window->show();  }  void load_file(char *newfile) {#ifdef USEBKMKS    save_current(NULL,this);#endif    strcpy(g_filename,newfile);#ifdef USEBKMKS    input->load_file(newfile,initlocation(newfile));#else    input->load_file(newfile,0);#endif  }  void locate(unsigned int lcn) { input->locate(lcn); }  void getprefs()  {    prefs_t prefs;#ifdef USEBKMKS    DBT key, data;    memset(&key,0,sizeof(key));    memset(&data,0,sizeof(data));    char buffer[] = PREFRNCE;    key.data = buffer;    key.size = strlen(buffer);    int ret = bkmks->get(bkmks, &key, &data, 0);    if (ret != 0 || data.size != sizeof(prefs))      {	//	fl_alert("Incompatible or missing preferences");      }    else      {	memcpy(&prefs,data.data,data.size);	//printf("%d:%d:%d\n",prefs.textsize,prefs.textfont,prefs.bold);	input->textsize(prefs.textsize);	input->textfont(prefs.textfont);	if (prefs.bold)	  {	    bold = true;	  }	bstripcr = prefs.bstripcr;	bunindent = prefs.bunindent;	brepara = prefs.brepara;	bdblspce = prefs.bdblspce;	btight = prefs.btight;	bindenter = prefs.bindenter;      }#else    FILE *f = fopen(".twr-bkmks","rb");    if (f != NULL)      {	size_t n = fread(&prefs,sizeof(prefs),1,f);	if (n == 1)	  {	    input->textsize(prefs.textsize);	    input->textfont(prefs.textfont);	    if (prefs.bold)	      {		bold = true;	      }	    bstripcr = prefs.bstripcr;	    bunindent = prefs.bunindent;	    brepara = prefs.brepara;	    bdblspce = prefs.bdblspce;	    btight = prefs.btight;	    bindenter = prefs.bindenter;	    size_t lcn;	    n = fread(&lcn,sizeof(lcn),1,f);	    if (n == 1)	      {		char filename[1024];		memset(filename,0,1024);		n = fread(filename,sizeof(char),1023,f);		strcpy(g_filename,filename);		if (n > 0)		  {		    setfilter();		    input->load_file(filename,lcn);		  }	      }	  }	fclose(f);      }#endif  }  void setprefs()  {    prefs_t prefs;    prefs.textsize = input->textsize();    prefs.textfont = input->textfont();    prefs.bold = bold;    prefs.bstripcr = bstripcr;    prefs.bunindent = bunindent;    prefs.brepara = brepara;    prefs.bdblspce = bdblspce;    prefs.btight = btight;    prefs.bindenter = bindenter;    //printf("%d:%d:%d\n",prefs.textsize,prefs.textfont,prefs.bold);#ifdef USEBKMKS    DBT key, data;    memset(&key,0,sizeof(key));    memset(&data,0,sizeof(data));    char buffer[] = PREFRNCE;    key.data = buffer;    key.size = strlen(buffer);    //printf("%d:%d:%d\n",prefs.textsize,prefs.textfont,prefs.bold);    data.data = &prefs;    data.size = sizeof(prefs);    int ret = bkmks->put(bkmks, &key, &data, 0);#else    FILE *f = fopen(".twr-bkmks","wb");    fwrite(&prefs,sizeof(prefs),1,f);    size_t lcn = input->pagelocate();    if (g_filename[0] != '\0')      {	fwrite(&lcn,sizeof(lcn),1,f);	fwrite(g_filename,1,strlen(g_filename),f);      }    fclose(f);#endif  }};#ifdef USEBKMKSunsigned int reader_ui::initlocation(char *file) {  DBT key, data;  memset(&key,0,sizeof(key));  memset(&data,0,sizeof(data));  key.data = file;  key.size = strlen(file);  getdefaultbkmk(file,&key);  int ret = bkmks->get(bkmks, &key, &data, 0);  if (ret == 0)    {      unsigned long lcn;      memcpy(&lcn,data.data,sizeof(lcn));      return lcn;    }  else    {      return 0;    }}#endifint main(int argc, char **argv) {#ifdef USEBKMKS  bkmks = dbopen(".twr-bkmks", O_RDWR|O_CREAT, S_IRWXU, DB_BTREE, NULL);  //  fl_message_font(FL_HELVETICA,8);  if (bkmks == NULL)    {      fl_alert("ERROR: can't open bookmarks - the file may be corrupt.");      return 10;    }#endif  reader_ui reader;  filename[0] = '\0';  search[0] = '\0';  if (argc > 1) {    unsigned int lcn = 0;    if (argc > 2) lcn = atoi(argv[2]);    reader.load_file(argv[1]);        if (argc > 2) reader.locate(lcn);      }  else    {#ifdef USEBKMKS      DBT key, data;      memset(&key,0,sizeof(key));      memset(&data,0,sizeof(data));      char newfile[1024];      char buffer[1024];      strcpy(buffer,LASTFILE);      key.data = buffer;      key.size = strlen(buffer);      int ret = bkmks->get(bkmks, &key, &data, 0);      if (ret == 0)	{	  memcpy(newfile,data.data,data.size);	  newfile[data.size] = '\0';	  reader.load_file(newfile);	}#endif    }  fl_message_font(FL_HELVETICA,8);  return Fl::run();}//// End of "$Id: reader.cxx,v 1.36 2001/10/10 19:55:20 agenda Exp $".//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -