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

📄 iodlg.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:

         if ( i )
         do {

            if ( ((p_listbox_item)i->rec)->sel == sel ) {

                 p_filelistbox_item t = ((p_filelistbox_item)i->rec);

                 if ( io_isfilename(t->info.filename) ) /* if it's ok file name */

                     list->insert(list, new_tfile(t->info.path, t->info.filename,
                                        t->info.attrib, t->info.time,
                                        t->info.date, t->info.size));

            };

            i = i->next;

         } while ( i != l );

      };

  };

  return list;

};



/*

   - get data from filelistbox, data are stored in rec->data pointer and

     this function set to this pointer list of DAT_TFILEs

     ( t_file structure ).
*/

l_bool     filelistbox_get_data ( p_object o, t_data *rec )
{
  if ( rec && o->is_state(o, OB_SF_FOCUSED) ) { /* i'm focused */

     p_filelistbox_item i = (p_filelistbox_item)LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

     rec->info_obj = o;
     l_tag_cpy(rec->id, DAT_LIST);
     rec->data = NULL;

     if ( i )

     switch ( rec->style ) { /* some item exist */

       case DS_SELECTED : {

          p_list p = LISTBOX(o)->get_selected_items(LISTBOX(o), true);

          if ( !p ) return false;

          if ( !p->last ) { /* not item is select */

             if ( !io_isfilename(i->info.filename) ) { /* current item is not ok file/directory = "..", ".", ... */

                 l_tag_cpy(rec->id, DAT_NONE);

                 return false;

             } else { /* current item is ok file/directory != "..", "." , ... */

                 /* make new pointer to t_file structure and add to the list */

                 p->insert(p, new_tfile(i->info.path, i->info.filename,
                                  i->info.attrib, i->info.time,
                                  i->info.date, i->info.size));

             };

          };

          rec->data = (void*)p; /* set rec->data to list of t_file structure */

          l_tag_cpy(rec->id, DAT_LIST); /* set (id) to LIST */

          return true;

       }; break;

       case DS_ALL : {

          rec->style = DS_SELECTED;

          o->select_data(o, DS_ALL, true);

          return o->get_data(o, rec);

       }; break;

       case DS_WHATEVER : {

          rec->style = DS_SELECTED;

          return o->get_data(o, rec);

       }; break;

     };

     l_tag_cpy(rec->id, DAT_NONE);

  };

  return false;

};


l_bool     filelistbox_set_data ( p_object o, t_data *rec )
{
  #define  retr(t) do { _free(path); return t; } while (0)

  l_bool   ok = false;
  l_dword  indicator = 0; /* number of files that were in process */
  l_text   path = _strdup(FILELISTBOX(o)->path);

  p_filelistbox_item i = (p_filelistbox_item)LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

  if ( rec && l_tag_cmp(o->data_type, rec->id) && i ) {

     if ( rec->style & DS_DELETE ) {

       if ( o->is_state(o, OB_SF_FOCUSED) ) { /* delete only if focused */

           if ( rec->style & DS_ALL ) {

               retr(false);

           } else { /* delete DS_SELECTED or DS_WHATEVER, so only select item */

               p_list p = LISTBOX(o)->get_selected_items(LISTBOX(o), true);

               if ( !p ) retr(false);

               if ( !p->last ) { /* not item is select */

                  if ( !io_isfilename(i->info.filename) ) { /* current item is not ok file/directory = "..", ".", ... */

                      retr(false); /* no delete */

                  } else { /* current item is ok file/directory != "..", "." , ... */

                      /* make new pointer to t_file structure and add to the list */

                      p->insert(p, new_tfile(i->info.path, i->info.filename,
                                   i->info.attrib, i->info.time,
                                   i->info.date, i->info.size));

                  };

               };

               /* delete files in t_list (p) */

               if ( msgbox(MW_QUESTION, MB_YES|MB_NO, "%s %s ?", TXT_AREYOUSUREYOUWANTTODELETE, strlwr(TXT_THESEFILES)) == MSG_YES ) {

                  l_text nicefile = set_format_text_nice(NULL, -29, FILELISTBOX(o)->path);
                  l_text from = set_format_text(NULL, "%s %s", TXT_DELETINGFILESFROM, nicefile);

                  p_object proc; /* window that control process */

                  l_dword allfiles = 0;

                  /* get number of files in all directories */

                  p->for_each_item(p, NULL, &io_numberfile, &allfiles);

                  /* show process window */

                  proc = show_process(TXT_DELETINGFILES, from, allfiles, &indicator);

                  /* removing process */

                  p->for_each_item(p, proc, &io_removefile, &indicator);

                  /* hide process window */

                  hide_process(proc);

                  ok = true;

                  _free(from);
                  _free(nicefile);

               } else ok = false;

           };

       };

     } else /* data are pasted into the object */

     if ( l_tag_cmp(rec->id, DAT_LIST) && rec->data &&  /* rec->data is DAT_LIST = ptr to t_list structure */
         l_tag_cmp(((p_list)rec->data)->tag, DAT_TFILE) ) { /* t_list items->rec contains ptr to DAT_TFILE item = t_file structure see ( _iods.h  )*/

         l_text fn = io_realpath(i->info.path, i->info.filename);
         l_text file = NULL;
         l_text nicelink = fn; /* if file is link, it make io_nicelink */

         /* ask for where to copy */
         l_dword msg = menu_file_copy_where(nicelink);

         switch ( msg ) {

            case MSG_COPYTODIR: file = i->info.path; break; /* copy files to dir, where current file (item) is placed  */
            case MSG_COPYTOFILE: file = fn; break; /* copy files to current file (item) */

         };


         if ( !file ) {

            _free(fn);

            retr(false); /* menu was canceled */

         };

         nicelink = io_nicelink(file);

         /* copy files from t_list (p) into current item */

         if ( msgbox(MW_QUESTION, MB_YES|MB_NO, "%s %s %s %s?", TXT_AREYOUSUREYOUWANTTOCOPY, strlwr(TXT_THESEFILES), strlwr(TXT_INTO), file) == MSG_YES ) {

             l_text nicefile = set_format_text_nice(NULL, -29, file);
             l_text to = set_format_text(NULL, "%s %s", TXT_COPYINGFILESTO, nicefile);
             t_file inf;

             p_object proc; /* window that control process */

             l_dword allfiles = 0;

             /* get number of files in all directories */

             ((p_list)(rec->data))->for_each_item(((p_list)(rec->data)), NULL, &io_numberfile, &allfiles);

             /* show process window */

             proc = show_process(TXT_COPYINGFILES, to, allfiles, &indicator);

             /* copying process */

             inf = i->info; /* copy current info of file item to copying info */

             path = _strdup(inf.path);

             inf.path = io_path(file);
             inf.filename = io_filename(file);

             ((p_list)(rec->data))->for_each_item_to_item((p_list)(rec->data), proc, &inf, i->set_data, &indicator);

             _free(inf.path);
             _free(inf.filename);

             /* hide process window */

             hide_process(proc);

             ok = true;

             _free(to);
             _free(nicefile);

         } else ok = false;

         _free(fn);

     };

     /* reload and redraw listbox */

     if ( ok )

        /* retype path */

        RETYPE_FILES_IN_PATH(path);


  };

  retr(ok);


};



/*
   drag_where function redraw [mouse under]-item, when some t_data are under

   this object.

*/
l_bool  filelistbox_drag_where ( p_view o, p_data rec, t_point where )
{

   if ( view_drag_where(o, rec, where) ) { /* is mouse under view */

       l_dword mpos = LISTBOX(o)->get_pos_from_xy(LISTBOX(o), where);

       /*
          it must call only listbox rewrite_item, because filelistbox rewrite_item
          function make some changes
       */

       listbox_rewrite_item(LISTBOX(o), mpos);

       return true;

   } else /* mouse is not under view or end */

   if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {

       if ( rec ) /* mouse is not under view */
          ;


       else /* end of dragging - give things to right place */
         ;

   } else { /* mouse is not under view or end but in non-focused view */


   };

   return false;
};


/*

   translate_event function

   get info about pressed item and set o->file ( t_filelistbox ) and
   o->path ( t_filelistbox ) to current file values. If file item was
   pressed ( by doubleclick ), it call MSG_OK same as in OK button.

   If file was pressed, then not clear event, but if directory or file is
   kind of extension, it clear event and reload list. ( see MSG_OK message )

   If file is pressed (by right mouse button) it call menu ( file_menu )
   for selected file. If filemenu return MSG_PROPERTIES it run properties
   function ( t_filelistbox_item ) for selected file, if MSG_COPY,
   then run get_data function, if MSG_CUT, MSG_PASTE, it run set_data
   function for selected file item.

*/

void  filelistbox_translate_event ( p_object o, p_event event )
{

  RETVIEW(o, event);

  /* info text */

  if ( VIEW(o)->is_mouse_in_view(VIEW(o)) && LISTBOX(o)->list &&
       OBJECT(keyb)->state & KB_SF_KEYDOWN && KEYCTRL(KB_F1) )  { /* show info text */

         l_long  mpos = LISTBOX(o)->get_pos_from_xy(LISTBOX(o), VIEW(o)->get_local_point(VIEW(o), mouse->where));
         void   *rec  = LISTBOX(o)->list->at(LISTBOX(o)->list, mpos);

         l_text  item_text = rec?((p_filelistbox_item)rec)->info.filename:NULL;

         l_dword item_size = rec?((p_filelistbox_item)rec)->info.size:NULL;

         set_format_text(&(VIEW(o)->info_text), "'%s'\n %s: %i (bytes)", item_text, TXT_SIZE, item_size);

         VIEW(o)->show_info_board(VIEW(o));

         clear_event(event);

  };

  if ( event->type & EV_MOUSE &&
       OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) { /* mouse event */

       /* test for doubleclick */
       if ( OBJECT(mouse)->state & MO_SF_MOUSELDOUBLE ) {

            clear_event(event);

            set_event(event, EV_MESSAGE, MSG_OK, o);

       };

  };


  listbox_translate_event(o, event); /* old translate event */



  /* keyboard event */

  if ( event->type & EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN &&

       OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {

       if ( keyb->code == TO_KEY(KB_ENTER) ) { /* enter was pressed */

          clear_event(event);

          set_event(event, EV_MESSAGE, MSG_OK, o); /* call MSG_OK2 */

       };

  };


  if ( event->type & EV_MOUSE ) { /* mouse event */

      if ( OBJECT(mouse)->state & MO_SF_MOUSERPRESS && o->owner &&
           o->owner->is_state(o->owner, OB_SF_FOCUSED) ) { /* right button pressed */

          if ( OBJECT(mouse)->state & MO_SF_MOUSERDOWN &&
               !o->is_state(o, OB_SF_FOCUSED) )  /* object is not focused */

               o->select(o);

          clear_event(event);


          if ( o->is_state(o, OB_SF_FOCUSED) )  /* object is focused */

              /* set current item to pointer */

              LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->get_pos_from_xy(LISTBOX(o), VIEW(o)->get_local_point(VIEW(o), mouse->where)));

      };

      /* make menu */
      if ( o->is_state(o, OB_SF_FOCUSED) ) {

         if ( OBJECT(mouse)->state & MO_SF_MOUSERUP ) { /* right button un-pressed */

            l_dword msg = 0;

            clear_event(event);

                         /* make menu over the file/directory */
            msg = FILELISTBOX(o)->file_menu(FILELISTBOX(o));

            if ( msg ) {

               clear_event(event);

               set_event(event, EV_MESSAGE, msg, o);

            };
         };
      };

  };



  if ( event->type & EV_RETYPE ) { /* retype event */

     switch ( event->message ) {

         case MSG_RETYPEPATH : { /* this redraw filelistbox if event->info is same to o->path */

             /* ! not clear event, it must be send further !*/

             if ( event->info && FILELISTBOX(o)->path && /* if same path as retyped path */
                  io_issame(event->info, FILELISTBOX(o)->path) ) {

                    /* make new list */
                     FILELISTBOX(o)->load_list(FILELISTBOX(o), FILELISTBOX(o)->path, FILELISTBOX(o)->file);

             };

         }; break;

     };

  };


⌨️ 快捷键说明

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