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

📄 iodlg.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************
 * SEAL 2.0                                                       *
 * Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved.  *
 *                                                                *
 * Web site: http://sealsystem.sourceforge.net/                   *
 * E-mail (current maintainer): orudge@users.sourceforge.net      *
 ******************************************************************/

/*
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <seal.h>
#include <iodlg.h>
#include <dir.h>
#include <dos.h>
#include <unistd.h>


////////////////////////////////////////////////////////////////////////////////

#define io_nicelink(x) _strdup(x)


////////////////////////////////////////////////////////////////////////////////


p_filelistbox  (*filelistbox_init) ( p_filelistbox o, t_rect r, l_int cols, l_int flags, l_text path, l_text file, l_int attrib, void (*file_sel)() ) = &_filelistbox_init;
p_filehistory  (*filehistory_init) ( p_filehistory o, t_rect r, p_list list, l_int limit, l_int flags, p_filelistbox filebox ) = &_filehistory_init;
p_filetextline (*filetextline_init) ( p_filetextline o, t_rect r, l_int limit, l_int flags, p_filelistbox filebox, p_filehistory filehistory ) = &_filetextline_init;
p_filelistctrl (*filelistctrl_init) ( p_filelistctrl o, t_rect r, p_filelistbox filebox ) = &_filelistctrl_init;

l_text  (*file_dialog) ( l_text caption, l_text bname, l_text path, l_text file, p_list hislist, l_int attrib, l_int flags, void (*file_sel)() ) = &_file_dialog;

#define ParentDirIcon IMG_PARDIRBT
/* t_filelistbox_item functions */


/*

  menu_copy_where

  - menu that ask for copying, where we want to copy our data

  - 1. to file
  - 2. to directory, where file is placed

*/

l_dword  menu_file_copy_where ( l_text filename )
{

   l_text of = io_filename(filename);
   l_text df = io_path(filename);
   l_text copytofile = set_format_text_nice(NULL, -39, "%s %s", TXT_COPYTOFILE, of);
   l_text copytodir  = set_format_text_nice(NULL, -39, "%s %s", TXT_COPYTODIRECTORY, df);
   l_text copytofileinfo = set_format_text_nice(NULL, -39, "%s %s", TXT_INFOCOPYTOFILE, of);
   l_text copytodirinfo  = set_format_text_nice(NULL, -39, "%s %s", TXT_INFOCOPYTODIRECTORY, df);

   p_menu p = new_menu(

                 new_menu_item_ex(copytofile, NULL, 0, MSG_COPYTOFILE, true,
                                  copytofileinfo, MIF_NONE, font_system, NULL, NULL, 0,
                 new_menu_line(
                 new_menu_item_ex(copytodir, NULL, 0, MSG_COPYTODIR, true,
                                  copytodirinfo, MIF_NONE, font_system, NULL, NULL, 0,
                NULL)))
             );

   _free(of);
   _free(df);
   _free(copytodir);
   _free(copytofile);
   _free(copytodirinfo);
   _free(copytofileinfo);

   if ( p ) {

         t_rect   r = rect_assign(mouse->where.x-5, mouse->where.y-5, 0, 0);

         p_object menu = OBJECT(menuview_init(
                                _malloc(sizeof(t_menuview)),
                                r,
                                p)
                         );

         return desktop->execute_view(desktop, VIEW(menu));

      };

  return MSG_CANCEL;
};



/*
  properties functions

  - linkdir
  - file
  - directory
  - these functions are part of t_filelistbox_item

  - return true if something was changed, otherwise return false
*/


/*
  - show file properties from filename = real path to file
*/
l_bool  file_properties ( l_text filename )
{

   struct  ftime t;
   l_word  attrib = 0;
   l_dword size   = 0;
   FILE   *f      = fopen(filename, "rb");


   if ( f ) { /* file exist */

      l_text file = io_getfilename(filename);
      l_text path = stridup(filename, strsize(filename, file));

      _dos_getfileattr(filename, &attrib);

      getftime(fileno(f), &t);

      size = filelength(fileno(f));

      fclose(f);

      msgboxsize(400, MW_INFO, MB_OK, "%s: %s\n\n%s: %s\n\n%s: %i (bytes) = %.2f (kbytes)\n\n%s: %i.%i.%i\n\n%s: %ih:%imin:%isecs",
                 TXT_FILENAME, file,
                 TXT_PATH, path,
                 TXT_SIZE, size, ((double)size/(double)1024),
                 TXT_DATE, t.ft_day, t.ft_month, 1980+t.ft_year,
                 TXT_TIME, t.ft_hour, t.ft_min, (double)t.ft_tsec,
                 TXT_ATTRIB, NULL);

      _free(path);

   };

   return false;

};


/*
  - show directory properties from directory = real path to dir

*/
l_bool  dir_properties ( l_text filename )
{

  l_text  dir = io_getfilename(filename);
  l_text  path = stridup(filename, strsize(filename, dir));
  l_word  attrib = 0;

  struct  ftime t;

  p_object i = show_info(0, MW_INFO, "%s...", TXT_PLEASEWAIT); /* show info "Please wait..." */

  t_dirinfo dinfo = io_foreach_file(filename, DIF_SIZE, i, NULL); /* count files */

  l_text    whatbytes = "bytes";
  double    size = (double)dinfo.size;
  l_text    status = (dinfo.flags & DIF_HALT) ? TXT_HALTED : TXT_DONE;

  hide_info(i); /* hide info "Please wait... " */

  if ( dinfo.size > (l_dword)1024*100 ) { /* Kb */

      whatbytes = "Kb";
      size = size/(double)1024;

  };

  if ( dinfo.size > (l_dword)1024*1000 ) { /* Mb */

      whatbytes = "Mb";
      size = size/1024;

  };

  msgboxsize(400, MW_INFO, MB_OK, "%s: %s\n\n%s: %s\n\n%s: %i\n\n%s: %i\n\n%s: %.2f (%s)\n\n%s: (%s)",
                  TXT_DIRNAME, dir,
                  TXT_PATH, path,
                  TXT_NUMBEROFFILES, dinfo.files,
                  TXT_NUMBEROFDIRECTORIES, dinfo.dirs,
                  TXT_SIZE, size, whatbytes,
                  TXT_PROCESSSTATUS, strlwr(status),
                  TXT_ATTRIB, NULL);

  _free(path);

  return false;

};

/*
  set data function for
  - linkdir
  - linkfile
  - file
  - directory
  - these functions are part of t_filelistbox_item
*/


/*
  set data for file = run file (dst) by argument (src)

  - dst    destination directory
  - src    source file/directory
  - ind    indicator of process, this value contains at the end number of files
  - o      object that control process
*/
l_int file_set_data ( p_object o, t_file *dst, t_file *src, l_dword *ind )
{
  return io_copyfile(o, dst, src, ind);
};


/*
  set data for dir = copy files from src ( file/dir ) to dst ( dir ),

  - dst    destination directory
  - src    source file/directory
  - ind    indicator of process, this value contains at the end number of files
  - o      object that control process
*/
l_int dir_set_data ( p_object o, t_file *dst, t_file *src, l_dword *ind )
{

  return io_copyfile(o, dst, src, ind);

};

/*

   get file items from directory, return list of p_filelistbox_item(s)

   path   - real path to directory
   files  - type of files that must be displayed ( *.bmp, *.exe, hello.*, ... )
   attrib - atributes of files/directory that must be displayed

            may contain following:

            FA_DIREC     - directory
            FA_ARCH      - archive files
            FA_HIDDEN    - hidden files/directory
            FA_RDONLY    - read-only files
*/


p_list get_listbox_item_dirfiles ( l_text path, l_text files, l_int attrib, l_int isize )
{
  p_list p = list_init(_malloc(sizeof(t_list)), &free_filelistbox_item, 0);
  p_item l = NULL;
  l_text fi = NULL;
  BITMAP *icon = NULL;

  if ( p ) {

     struct t_ffblk f;

     l_int done = 0;

     /* directories */
     if ( attrib & FA_DIREC ) {

         fi = io_realpath(path, "*.*"); /* insert string "path"/*.* to fi */

         done = io_findfirst(fi, &f, FA_DIREC); /* looking for directories */

         _free(fi);


         while ( !done ) { /* file found */

            l_int mem = 0;

            fi = io_realpath(path, f.ff_filename); /* insert string "path"/"found file" to fi */

            /* get icon for file, this function is defined in exedlx.h */


            if ( f.ff_filename && *(f.ff_filename) && f.info.ff_attrib & FA_DIREC && stricmp(f.ff_filename, ".")
                 && stricmp(f.ff_filename, "..") )  { /* OK it found direcory */

                   p_filelistbox_item diritem;

                   icon = get_icon_for_file_ex(fi, f.info.ff_attrib, &mem, isize);

                   /* make new t_filelistbox_item */
                   diritem = new_filelistbox_item_ex(f.info.ff_name, icon,
                                 false, mem ? LIF_MEMORY : LIF_NONE,
                                 f.info.ff_attrib, f.info.ff_fdate,
                                 f.info.ff_ftime, f.info.ff_fsize,
                                 path, f.ff_filename,
                                 &dir_properties, &dir_set_data
                             );

                   p->insert(p, diritem); /* insert t_filelistbox_item (direcotry) to the list */

            };

            _free(fi);

            done = io_findnext(&f);  /* looking for next directory */

         };

         collect_by_name(p, LISTBOX_ITEM_NAME); /* collect list by the name */

         l = p->last;

     };

     attrib &= ~FA_DIREC;

     /* files finding */
     if ( attrib ) {

         fi = io_realpath(path, files);

         done = io_findfirst(fi, &f, attrib); /* looking for files */

         _free(fi);

         while ( !done ) {

            p_filelistbox_item fileitem;

            l_int mem = 0;

            fi = io_realpath(path, f.ff_filename);  /* insert string "path"/"file found" to fi */

                /* get icon for file, this function is defined in exedlx.h */

           icon = get_icon_for_file_ex(fi, f.info.ff_attrib, &mem, isize);

            /* make new filelistbox item */
            fileitem = new_filelistbox_item_ex(strlwr(f.info.ff_name), icon,
                           false, mem ? LIF_MEMORY : LIF_NONE,
                           f.info.ff_attrib, f.info.ff_fdate, f.info.ff_ftime,
                           f.info.ff_fsize,
                           path, f.ff_filename,
                           &file_properties, &file_set_data
                       );

            p->insert(p, fileitem); /* insert file item into the list */

            done = io_findnext(&f); /* looking for next file */

            _free(fi);

         };

         p->collect_by_name_from(p, l, LISTBOX_ITEM_NAME);  /* collect list from last link directory by the name */

     };

  };
  return p;
};


/* filelistbox item functions */

/*
   make new file item,

   name  - name that will be displayed at list
   icon  - icon of item
   sel   - if item is selected
   flags - if LIF_MEMORY, than context of the icon will be free automatically

   filename - real name of file/directory
   path     - real path to file/directory
   attrib   - attrib of file/directory
   date     - date of file/directory
   time     - time of file/directory
   size     - size of file, directory = 0

   properties - function that displayed info about file/directory
   set_data   - function that set data to file/directory

*/

p_filelistbox_item   new_filelistbox_item_ex ( l_text name, BITMAP *icon, l_bool sel, l_int flags, l_int attrib, l_word date, l_word time, l_dword size, l_text path, l_text filename, l_bool (*properties)(l_text filename), l_int (*set_data)(p_object o, t_file *dst, t_file *src, l_dword *ind ) )
{

  p_filelistbox_item i = (p_filelistbox_item)_malloc(sizeof(t_filelistbox_item));

  if ( i ) {

     i->obclass.name  = _strdup(name);
     i->obclass.icon  = icon;
     i->obclass.sel   = sel;
     i->obclass.flags = flags;

     i->info.filename      = _strdup(filename);
     i->info.path          = _strdup(path);
     i->info.attrib        = attrib;

     i->info.date          = date;
     i->info.time          = time;
     i->info.size          = size;

     /* functions */
     i->properties    = properties;
     i->set_data      = set_data;

  };

  return i;

};


/* free file item */

void  free_filelistbox_item ( void *o )
{
   if ( o ) {

      if ( ((p_filelistbox_item)o)->info.filename
           && *(((p_filelistbox_item)o)->info.filename) ) _free(((p_filelistbox_item)o)->info.filename);
      if ( ((p_filelistbox_item)o)->info.path
           && *(((p_filelistbox_item)o)->info.path) )     _free(((p_filelistbox_item)o)->info.path);

   };

   free_listbox_item(o);
};




/* t_filelistbox functions */

void  filelistbox_setup ( p_object o )
{

  scroller_setup(o);

  FILELISTBOX(o)->load_list(FILELISTBOX(o), FILELISTBOX(o)->path, FILELISTBOX(o)->file);

};


/*

  return list of selected items.

  list is in t_ffblk file type.

*/

p_list filelistbox_get_selected_items ( p_listbox o, l_bool sel )
{

  p_list list = NULL;

  if ( o->list && o->get_max(o) >= 0 ) {

      list = list_init(_malloc(sizeof(t_list)), &free_tfile, DAT_TFILE);

      if ( list ) {

         p_item i = o->list->last;
         p_item l = i;

⌨️ 快捷键说明

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