flu_file_chooser.cpp

来自「ncbi源码」· C++ 代码 · 共 2,471 行 · 第 1/5 页

CPP
2,471
字号
/* * =========================================================================== * PRODUCTION $Log: Flu_File_Chooser.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 21:05:46  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * PRODUCTION * =========================================================================== *//* * These files were imported into NCBI's CVS directly from FLU version 2.9.1. * Modifications to the source are listed below. * * ========================================================================== * $Log: Flu_File_Chooser.cpp,v $ * Revision 1000.1  2004/06/01 21:05:46  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3 * * Revision 1.3  2004/05/21 22:27:51  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.2  2004/03/11 14:10:10  dicuccio * Fixes for 64-bit compilation.  Cast away const from strchr() where needed * * Revision 1.1  2004/03/11 13:51:39  dicuccio * Imported FLU version 2.9.1.  Altered export specifiers to match NCBI layout. * Altered include paths to match NCBI toolkit layout. * * ========================================================================== */// $Id: Flu_File_Chooser.cpp,v 1000.1 2004/06/01 21:05:46 gouriano Exp $/*************************************************************** *                FLU - FLTK Utility Widgets  *  Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University * * This file and its content is protected by a software license. * You should have received a copy of this license with this file. * If not, please contact the Ohio Supercomputer Center immediately: * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212 *  ***************************************************************/#include <ncbi_pch.hpp>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#ifdef WIN32#include <windows.h>#include <shellapi.h>#include <lmcons.h>#endif#if defined WIN32 && !defined CYGWIN#include <direct.h>#else#include <unistd.h>#endif#include <FL/Fl.H>#include <FL/fl_draw.H>#include <FL/fl_ask.H>#include <FL/math.h>#include <FL/filename.H>#include <FL/Fl_Pixmap.H>#include <FL/Fl_Scroll.H>#include <FL/Fl_Shared_Image.H>#include <gui/widgets/FLU/flu_pixmaps.h>#include <gui/widgets/FLU/Flu_Label.h>#include <gui/widgets/FLU/Flu_Tree_Browser.h>#include <gui/widgets/FLU/Flu_Separator.h>#include <gui/widgets/FLU/Flu_Enumerations.h>#include <gui/widgets/FLU/Flu_File_Chooser.h>#include <gui/widgets/FLU/flu_file_chooser_pixmaps.h>#include <gui/widgets/FLU/flu_pixmaps.h>// just a string that no file could probably ever be called#define FAVORITES_UNIQUE_STRING   "\t!@#$%^&*(Favorites)-=+"#define DEFAULT_ENTRY_WIDTH 235Fl_Pixmap up_folder_img( (char*const*)big_folder_up_xpm ),  trash( (char*const*)trash_xpm ),  new_folder( (char*const*)big_folder_new_xpm ),  reload( (char*const*)reload_xpm ),  preview_img( (char*const*)monalisa_xpm ),  file_list_img( (char*const*)filelist_xpm ),  file_listwide_img( (char*const*)filelistwide_xpm ),  fileDetails( (char*const*)filedetails_xpm ),  add_to_favorite_folder( (char*const*)folder_favorite_xpm ),  home( (char*const*)bighome_xpm ),  favorites( (char*const*)bigfavorites_xpm ),  desktop( (char*const*)desktop_xpm ),  folder_closed( (char*const*)folder_closed_xpm ),  default_file( (char*const*)textdoc_xpm ),  my_computer( (char*const*)my_computer_xpm ),  computer( (char*const*)computer_xpm ),  disk_drive( (char*const*)disk_drive_xpm ),  cd_drive( (char*const*)cd_drive_xpm ),  floppy_drive( (char*const*)floppy_drive_xpm ),  removable_drive( (char*const*)removable_drive_xpm ),  ram_drive( (char*const*)ram_drive_xpm ),  network_drive( (char*const*)network_drive_xpm ),  documents( (char*const*)filled_folder_xpm ),  littlehome( (char*const*)home_xpm ),  little_favorites( (char*const*)mini_folder_favorites_xpm ),  little_desktop( (char*const*)mini_desktop_xpm ),  bigdocuments( (char*const*)bigdocuments_xpm ),  bigtemporary( (char*const*)bigtemporary_xpm );#define streq(a,b) (strcmp(a,b)==0)Flu_File_Chooser::FileTypeInfo* Flu_File_Chooser::types = NULL;int Flu_File_Chooser::numTypes = 0;int Flu_File_Chooser::typeArraySize = 0;Flu_File_Chooser::ContextHandlerVector Flu_File_Chooser::contextHandlers;Flu_File_Chooser::PreviewHandlerVector Flu_File_Chooser::previewHandlers;Flu_File_Chooser::ImgTxtPreview* Flu_File_Chooser::imgTxtPreview = 0;int (*Flu_File_Chooser::customSort)(const char*,const char*) = 0;// taken explicitly from fltk/src/filename_match.cxx// and changed to support case-sensitive matchingstatic int flu_filename_match(const char *s, const char *p){  int matched;  for (;;) {    switch(*p++) {    case '?' :	// match any single character      if (!*s++) return 0;      break;    case '*' :	// match 0-n of any characters      if (!*p) return 1; // do trailing * quickly      while (!flu_filename_match(s, p)) if (!*s++) return 0;      return 1;    case '[': {	// match one character in set of form [abc-d] or [^a-b]      if (!*s) return 0;      int reverse = (*p=='^' || *p=='!'); if (reverse) p++;      matched = 0;      char last = 0;      while (*p) {	if (*p=='-' && last) {	  if (*s <= *++p && *s >= last ) matched = 1;	  last = 0;	} else {	  if (*s == *p) matched = 1;	}	last = *p++;	if (*p==']') break;      }      if (matched == reverse) return 0;      s++; p++;}    break;    case '{' : // {pattern1|pattern2|pattern3}    NEXTCASE:    if (flu_filename_match(s,p)) return 1;    for (matched = 0;;) {      switch (*p++) {      case '\\': if (*p) p++; break;      case '{': matched++; break;      case '}': if (!matched--) return 0; break;      case '|': case ',': if (matched==0) goto NEXTCASE;      case 0: return 0;      }    }    case '|':	// skip rest of |pattern|pattern} when called recursively    case ',':      for (matched = 0; *p && matched >= 0;) {	switch (*p++) {	case '\\': if (*p) p++; break;	case '{': matched++; break;	case '}': matched--; break;	}      }      break;    case '}':      break;    case 0:	// end of pattern      return !*s;    case '\\':	// quote next character      if (*p) p++;    default:      //if (tolower(*s) != tolower(*(p-1))) return 0;      if( *s != *(p-1) ) return 0;      s++;      break;    }  }}void Flu_File_Chooser :: add_context_handler( int type, const char *ext, const char *name,					      void (*cb)(const char*,int,void*), void *cbd ){  if( cb == NULL )    return;  ContextHandler h;  h.ext = ext ? ext : "";  h.ext.downcase();  h.type = type;  h.name = name;  h.callback = cb;  h.callbackData = cbd;  Flu_File_Chooser::contextHandlers.add( h );}void Flu_File_Chooser :: add_preview_handler( PreviewWidgetBase *w ){  if( w == NULL )    return;  Flu_File_Chooser::previewHandlers.add( w );}// extensions == NULL implies directoriesvoid Flu_File_Chooser :: add_type( const char *extensions, const char *short_description, Fl_Image *icon ){  FluSimpleString ext;  if( extensions )    ext = extensions;  else    ext = "\t"; // indicates a directory  ext.upcase();  // are we overwriting an existing type?  for( int i = 0; i < numTypes; i++ )    {      if( types[i].extensions == ext )	{	  types[i].icon = icon;	  types[i].type = short_description;	  return;	}    }  if( numTypes == typeArraySize )    {      int newSize = ( typeArraySize == 0 ) ? 1 : typeArraySize*2; // double the size of the old list (same behavior as STL vector)      // allocate the new list      FileTypeInfo* newTypes = new FileTypeInfo[ newSize ];      // copy the old list to the new list      for( int i = 0; i < numTypes; i++ )	{	  newTypes[i].icon = types[i].icon;	  newTypes[i].extensions = types[i].extensions;	  newTypes[i].type = types[i].type;	}      // delete the old list and replace it with the new list      delete[] types;      types = newTypes;      typeArraySize = newSize;    }  types[numTypes].icon = icon;  types[numTypes].extensions = ext;  types[numTypes].type = short_description;  numTypes++;}Flu_File_Chooser::FileTypeInfo* Flu_File_Chooser :: find_type( const char *extension ){  FluSimpleString ext;  if( extension )    ext = extension;  else    ext = "\t"; // indicates a directory  ext.upcase();  // lookup the type based on the extension  for( int i = 0; i < numTypes; i++ )    {      // check extension against every token      FluSimpleString e = types[i].extensions;      char *tok = strtok( (char*)e.c_str(), " ," );      while( tok )	{	  if( ext == tok )	    return &(types[i]);	  tok = strtok( NULL, " ," );	}    }  return NULL;}Flu_File_Chooser :: Flu_File_Chooser( const char *pathname, const char *pat, int type, const char *title )  : Fl_Double_Window( 600, 400, title ),    filename( 70, h()-60, w()-70-85-10, 25, "Filename:", this ),    ok( w()-90, h()-60, 85, 25, "Ok" ),    cancel( w()-90, h()-30, 85, 25, "Cancel" ),    entryPopup( 0, 0, 0, 0 ){  Fl_Double_Window::size_range( 600, 400 );  Fl_Group *g;  add_type( NULL, "Directory", &folder_closed );  history = currentHist = NULL;  walkingHistory = false;  fileEditing = true;#ifdef WIN32  refreshDrives = true;  caseSort = false;#else  caseSort = true;#endif  int oldNormalSize = FL_NORMAL_SIZE;  FL_NORMAL_SIZE = 12;  selectionType = type;  filenameEnterCallback = filenameTabCallback = false;  sortMethod = SORT_NAME;  lastSelected = NULL;  filename.labelsize( 12 );  filename.when( FL_WHEN_ENTER_KEY_ALWAYS );  filename.callback( _filenameCB, this );  filename.value( "" );  Fl_Group *quickIcons = new Fl_Group( 5, 5, 100, h()-10-60 );  quickIcons->box( FL_DOWN_BOX );  quickIcons->color( FL_DARK3 );  Flu_Button *desktopBtn = new Flu_Button( 30, 18, 50, 48 );  desktopBtn->box( FL_FLAT_BOX );  desktopBtn->image( desktop );  desktopBtn->enter_box( FL_THIN_UP_BOX );  desktopBtn->color( FL_DARK3 );  desktopBtn->callback( _desktopCB, this );  {     Flu_Label *l = new Flu_Label( 5, 62, 100, 20, "Desktop" );    l->labelcolor( FL_WHITE );    l->align( FL_ALIGN_CENTER );  }  Flu_Button *homeBtn = new Flu_Button( 30, 98, 50, 48 );  homeBtn->box( FL_FLAT_BOX );  homeBtn->enter_box( FL_THIN_UP_BOX );  homeBtn->color( FL_DARK3 );  homeBtn->callback( _homeCB, this );  {#ifdef WIN32    Flu_Label *l = new Flu_Label( 5, 142, 100, 20, "My Computer" );    homeBtn->image( my_computer );#else    Flu_Label *l = new Flu_Label( 5, 142, 100, 20, "Home" );    homeBtn->image( home );#endif    l->labelcolor( FL_WHITE );    l->align( FL_ALIGN_CENTER );  }  Flu_Button *documentsBtn = new Flu_Button( 30, 178, 50, 48 );  documentsBtn->box( FL_FLAT_BOX );  documentsBtn->enter_box( FL_THIN_UP_BOX );  documentsBtn->labelcolor( FL_WHITE );  documentsBtn->color( FL_DARK3 );  documentsBtn->callback( _documentsCB, this );  { #ifdef WIN32    Flu_Label *l = new Flu_Label( 5, 222, 100, 20, "My Documents" );    documentsBtn->image( &bigdocuments );#else    Flu_Label *l = new Flu_Label( 5, 222, 100, 20, "Temporary" );    documentsBtn->image( &bigtemporary );#endif    l->labelcolor( FL_WHITE );    l->align( FL_ALIGN_CENTER );  }  Flu_Button *favoritesBtn = new Flu_Button( 30, 258, 50, 48 );  favoritesBtn->box( FL_FLAT_BOX );  favoritesBtn->image( favorites );  favoritesBtn->enter_box( FL_THIN_UP_BOX );  favoritesBtn->color( FL_DARK3 );  favoritesBtn->callback( _favoritesCB, this );  {     Flu_Label *l = new Flu_Label( 5, 302, 100, 20, "Favorites" );    l->labelcolor( FL_WHITE );    l->align( FL_ALIGN_CENTER );  }  favoritesList = new Fl_Browser( 0, 0, 0, 0 );  favoritesList->hide();  {    Fl_Group* dummy = new Fl_Group( 5, h()-10-61, 100, 1 );    quickIcons->resizable( dummy );  }  quickIcons->end();  Fl_Group *dummy = new Fl_Group( 110, 0, w()-110, 60 );  filesystems = new Flu_Combo_Tree( 166, 5, w()-171, 22, "Location:" );  filesystems->editable( false );  filesystems->pop_height( 200 );  filesystems->tree.all_branches_always_open( true );#ifdef WIN32  filesystems->tree.show_root( false );#endif  filesystems->tree.show_connectors( false );  filesystems->tree.horizontal_gap( -10 );  filesystems->tree.show_leaves( false );  filesystems->callback( _filesystemsCB, this );  ////////////////////////////////////////////////////////////////  g = new Fl_Group( 110, 30, w()-110, 30 ); // group enclosing all the buttons at top  backBtn = new Flu_Button( 285, 33, 25, 25, "@<-" );  backBtn->labelcolor( fl_rgb_color( 80, 180, 200 ) );  backBtn->labelsize( 16 );  backBtn->box( FL_FLAT_BOX );  backBtn->enter_box( FL_THIN_UP_BOX );  backBtn->callback( _backCB, this );  backBtn->tooltip( "Go back one directory in the history" );  forwardBtn = new Flu_Button( 310, 33, 25, 25, "@->" );  forwardBtn->labelcolor( fl_rgb_color( 80, 180, 200 ) );  forwardBtn->labelsize( 16 );  forwardBtn->box( FL_FLAT_BOX );  forwardBtn->enter_box( FL_THIN_UP_BOX );  forwardBtn->callback( _forwardCB, this );  forwardBtn->tooltip( "Go forward one directory in the history" );  upDirBtn = new Flu_Button( 335, 33, 25, 25 );  upDirBtn->image( up_folder_img );  upDirBtn->box( FL_FLAT_BOX );  upDirBtn->enter_box( FL_THIN_UP_BOX );  upDirBtn->callback( upDirCB, this );  upDirBtn->tooltip( "Go to the parent directory" );  reloadBtn = new Flu_Button( 360, 33, 25, 25 );  reloadBtn->image( reload );  reloadBtn->box( FL_FLAT_BOX );  reloadBtn->enter_box( FL_THIN_UP_BOX );  reloadBtn->callback( reloadCB, this );  reloadBtn->tooltip( "Refresh this directory" );  {    Flu_Separator *sep = new Flu_Separator( 385, 32, 10, 28 );    sep->type( Flu_Separator::VERTICAL );    sep->box( FL_ENGRAVED_BOX );  }  trashBtn = new Flu_Button( 395, 33, 25, 25 );  trashBtn->image( trash );  trashBtn->box( FL_FLAT_BOX );  trashBtn->enter_box( FL_THIN_UP_BOX );  trashBtn->callback( _trashCB, this );  trashBtn->tooltip( "Delete file(s)" );  newDirBtn = new Flu_Button( 420, 33, 25, 25 );  newDirBtn->image( new_folder );  newDirBtn->box( FL_FLAT_BOX );  newDirBtn->enter_box( FL_THIN_UP_BOX );  newDirBtn->callback( _newFolderCB, this );  newDirBtn->tooltip( "Create new directory" );  addFavoriteBtn = new Flu_Button( 445, 33, 25, 25 );  addFavoriteBtn->image( add_to_favorite_folder );  addFavoriteBtn->box( FL_FLAT_BOX );  addFavoriteBtn->enter_box( FL_THIN_UP_BOX );  addFavoriteBtn->callback( _addToFavoritesCB, this );  addFavoriteBtn->tooltip( "Add this directory to my favorites" );  {    Flu_Separator *sep = new Flu_Separator( 470, 32, 10, 28 );    sep->type( Flu_Separator::VERTICAL );    sep->box( FL_ENGRAVED_BOX );  }  previewBtn = new Flu_Button( 482, 33, 23, 25 );  previewBtn->type( FL_TOGGLE_BUTTON );  previewBtn->image( preview_img );  previewBtn->callback( _previewCB, this );  previewBtn->tooltip( "Preview files" );  {    Fl_Group *g = new Fl_Group( 511, 33, 81, 25 );

⌨️ 快捷键说明

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