Пример #1
0
/*
*       File Selector input routine that takes control of the mouse
*       and keyboard, searchs and sort the directory, draws the file 
*       selector, interacts with the user to determine a selection
*       or change of path, and returns to the application with
*       the selected path, filename, and exit button.
*/
WORD fs_input(BYTE *pipath, BYTE *pisel, WORD *pbutton, BYTE *pilabel)
{
        register WORD   touchob, value, fnum;
        WORD            curr, count, sel;
        WORD            mx, my;
        LONG            tree;
        ULONG           bitmask;
        BYTE            *ad_fpath, *ad_fname, *ad_ftitle;
        WORD            drive; 
        WORD            dclkret, cont, newlist, newsel, newdrive;
        register BYTE   *pstr;
        GRECT           pt;
        BYTE            locstr[LEN_ZPATH+1], mask[LEN_ZFNAME+1], selname[LEN_FSNAME];
        OBJECT          *obj;
        TEDINFO         *tedinfo;

        curr = 0;
        count = 0;
                                        /* get out quick if path is     */
                                        /*   nullptr or if pts to null. */
        if (pipath == NULL)
          return(FALSE);
                                        /* if path string is empty, */
                                        /*   set reasonable default */
        if (*pipath == '\0') {
          strcpy(pipath,"A:\\*.*");
          *pipath += dos_gdrv();
        }
                                        /* get memory for the filename buffer */
                                        /*  & the array that points to it     */
        for (nm_files = MAX_NM_FILES; nm_files >= MIN_NM_FILES; nm_files /= 2)
        {
          ad_fsnames = (BYTE *)dos_alloc(nm_files*(LEN_FSNAME+sizeof(BYTE *)));
          if (ad_fsnames)
            break;
        }
        if (!ad_fsnames)
          return(FALSE);
        g_fslist = (LONG *)(ad_fsnames+nm_files*LEN_FSNAME);

        strcpy(locstr, pipath);

        tree = ad_fstree;
                                                /* init strings in form */
        obj = ((OBJECT *)tree) + FTITLE;
        tedinfo = (TEDINFO *)obj->ob_spec;
        ad_ftitle = (BYTE *)tedinfo->te_ptext;
        set_mask(mask, locstr);                 /* save caller's mask */
        strcpy(ad_ftitle, mask);                /*  & copy to title line */

        obj = ((OBJECT *)tree) + FSDIRECT;
        tedinfo = (TEDINFO *)obj->ob_spec;
        ad_fpath = (BYTE *)tedinfo->te_ptext;
        inf_sset(tree, FSDIRECT, locstr);

        obj = ((OBJECT *)tree) + FSSELECT;
        tedinfo = (TEDINFO *)obj->ob_spec;
        ad_fname = (BYTE *)tedinfo->te_ptext;
        fmt_str(pisel, selname);                /* selname[] is without dot */
        inf_sset(tree, FSSELECT, selname);

        obj = ((OBJECT *)tree) + FSTITLE;
        obj->ob_spec = pilabel ? (LONG)pilabel : (LONG)rs_str(ITEMSLCT);

                                                /* set drive buttons */
        obj = ((OBJECT *)tree) + DRIVE_OFFSET;
        for (drive = 0, bitmask = 1; drive < NM_DRIVES; drive++, bitmask <<= 1, obj++)
        {
          if (drvbits & bitmask)
            obj->ob_state &= ~DISABLED;
          else
            obj->ob_state |= DISABLED;
        }
        select_drive(tree,locstr[0]-'A',0);
                                                /* set clip and start   */
                                                /*   form fill-in by    */
                                                /*   drawing the form   */
        gsx_sclip(&gl_rfs);     
        fm_dial(FMD_START, &gl_rfs);
        ob_draw(tree, ROOT, 2);
                                                /* init for while loop  */
                                                /*   by forcing initial */
                                                /*   fs_newdir call     */
        sel = 0;
        newsel = FALSE;
        cont = newlist = TRUE;
        while( cont )
        {
          touchob = (newlist) ? 0x0 : fm_do(tree, FSSELECT);
          gsx_mxmy(&mx, &my);
        
          if ( newlist )
          {
            fs_sel(sel, NORMAL);
            if ( (touchob == FSOK) ||
                 (touchob == FSCANCEL) )
              ob_change(tree, touchob, NORMAL, TRUE);
            inf_sset(tree, FSDIRECT, locstr);
            pstr = fs_pspec(locstr, NULL);        
            strcpy(pstr, mask);
            fs_newdir(locstr, mask, tree, &count);
            curr = 0;
            sel = touchob = 0;
            newlist = FALSE;
          }

          value = 0;
          dclkret = ((touchob & 0x8000) != 0);
          switch( (touchob &= 0x7fff) )
          {
            case FSOK:
            case FSCANCEL:
                cont = FALSE;
                break;
            case FUPAROW:
            case FDNAROW:
                value = 1;
                break;
            case FSVSLID:
                ob_actxywh(tree, FSVELEV, &pt);
                /* anemic slidebars
                  pt.g_x -= 3;
                  pt.g_w += 6;
                */
                if ( !inside(mx, my, &pt) )
                  {
                  touchob = (my <= pt.g_y) ? FUPAROW : FDNAROW;
                  value = NM_NAMES;
                  break;
                  }
                /* drop through */
            case FSVELEV:
                fm_own(TRUE);
                value = gr_slidebox(tree, FSVSLID, FSVELEV, TRUE);
                fm_own(FALSE);
                value = curr - mul_div(value, count-NM_NAMES, 1000);
                if (value >= 0)
                  touchob = FUPAROW;
                else
                {
                  touchob = FDNAROW;
                  value = -value;
                }
                break;
            case F1NAME:
            case F2NAME:
            case F3NAME:
            case F4NAME:
            case F5NAME:
            case F6NAME:
            case F7NAME:
            case F8NAME:
            case F9NAME:
                fnum = touchob - F1NAME + 1;
                if ( fnum > count )
                  break;
                if ( (sel) && (sel != fnum) )
                  fs_sel(sel, NORMAL);
                if ( sel != fnum)
                {
                  sel = fnum;
                  fs_sel(sel, SELECTED);
                }
                                                /* get string and see   */
                                                /*   if file or folder  */
                inf_sget(tree, touchob, selname);
                if (selname[0] == ' ')          /* a file was selected  */
                {                               /* copy to selection    */
                  newsel = TRUE;
                  if (dclkret)
                    cont = FALSE;
                }
                else                            /* a folder was selected:  */
                {                               /* insert name before mask */
                  pstr = fs_pspec(locstr, NULL);
                  unfmt_str(selname+1, pstr);
                  pstr += strlen(pstr);
                  *pstr++ = '\\';
                  strcpy(pstr, mask);
                  newlist = TRUE;
                }
                break;
            case FCLSBOX:
                pstr = fs_back(locstr, NULL);
                if (*pstr-- != '\\')    /* ignore strange path string */
                  break;
                if (*pstr != ':')       /* not at root of drive, so back up */
                {
                  pstr = fs_back(locstr, pstr);
                  if (*pstr == '\\')    /* we must have at least X:\ */
                    strcpy(pstr+1, mask);
                }
                newlist = TRUE;
                break;
            default:
                drive = touchob - DRIVE_OFFSET;
                if ((drive < 0) || (drive >= NM_DRIVES))/* not for us */
                  break;
                if (drive == locstr[0] - 'A')           /* no change */
                  break;
                obj = ((OBJECT *)tree) + touchob;
                if (obj->ob_state & DISABLED)           /* non-existent drive */
                  break;
                strcpy(locstr, "A:\\*.*");
                locstr[0] += drive;
                newdrive = TRUE;
                break;
          }
          if (!newlist && !newdrive
           && path_changed(locstr))                     /* path changed manually */
          {
            if (ad_fpath[0] != locstr[0])               /* drive has changed */
              newdrive = TRUE;
            else
              newlist = TRUE;
            strcpy(locstr, ad_fpath);
          }
          if (newdrive)
          {
            select_drive(tree, touchob-DRIVE_OFFSET,1);
            newdrive = FALSE;
            newlist = TRUE;
          }
          if (newlist)
          {
            inf_sset(tree, FSDIRECT, locstr);
            set_mask(mask, locstr);                 /* set mask         */
            selname[1] = '\0';                      /* selected is empty */
            newsel = TRUE;
          }
          if (newsel)
          {
            strcpy(ad_fname, selname + 1);
            ob_draw(tree, FSSELECT, MAX_DEPTH);
            if (!cont)
              ob_change(tree, FSOK, SELECTED, TRUE);
            newsel = FALSE;
          }
          if (value)
            curr = fs_nscroll(tree, &sel, curr, count, touchob, value);
        }
                                                /* return path and      */
                                                /*   file name to app   */
        strcpy(pipath, locstr);
        unfmt_str(ad_fname, selname);
        strcpy(pisel, selname);
                                                /* start the redraw     */
        fm_dial(FMD_FINISH, &gl_rfs);
                                                /* return exit button   */
        *pbutton = inf_what(tree, FSOK, FSCANCEL);
        dos_free((LONG)ad_fsnames);

        return( TRUE );
}
Пример #2
0
desk_pref()
{
	REG OBJECT		*obj;
	REG WORD	cyes, i, flag;
	    WORD	overwrite,font;

	obj = get_tree( ADSETPRE );
	cyes = cdele_save;
	obj[SPCDYES].ob_state = cyes;
	obj[SPCDNO].ob_state = !cyes;

	cyes = write_save;
	obj[YWRITE].ob_state = !cyes;
	obj[NWRITE].ob_state = cyes;

	cyes = ccopy_save;
	obj[SPCCYES].ob_state = cyes;
	obj[SPCCNO].ob_state = !cyes;

	for ( i = SPLOW; i <= SPEXT3; i++ )	/* hopefully they are in order	*/
	  obj[i].ob_state = NORMAL;

						/* set the resolution button */
	for ( i = 0,flag = SPLOW; i < 6; i++, flag++ )		
	{
	  if ( !restable[i] )
	    obj[flag].ob_state = DISABLED;
	}

	if ( m_st )
	{
	  for( i = SPEXT1; i <= SPEXT3; i++ )
	    obj[i].ob_flags |= HIDETREE;
	}

	if ( restable[4] )		/* TT high res	*/		
	  cyes = font_save;

	/* gl_restype is set according to followings:
					vdi handle
	1 = LOW RES	320 x 200	0, 2, 5, 7
	2 = MEDIUM RES	640 x 200	3		
	3 = HIGH RES	640 x 400	4
	4 = EXT1	640 x 480	6
	5 = EXT2	1280 x 960	8
	6 = EXT3 	320 x 480	9

	*/

	switch( gl_restype )
	{
	   case 1:
	     flag = SPLOW;
	     break;
		   
	   case 2:
	     flag = SPMEDIUM;
	     break;

	   case 3:
	     flag = SPHIGH;
	     break;
	
	   case 4:
	     flag = SPEXT1;
	     break;
		
	   case 5:
	     flag = SPEXT2;
	     break;

	   case 6:
	     flag = SPEXT3;
	     break;		

	}

	obj[flag].ob_state = SELECTED;

	if ( fmdodraw( ADSETPRE, 0 ) == SPOK )
	{
	  cdele_save = inf_what( obj, SPCDYES, SPCDNO );
	  ccopy_save = inf_what( obj, SPCCYES, SPCCNO );
	  write_save = !inf_what( obj, YWRITE, NWRITE );

	  flag = inf_gindex( obj, SPLOW, 6 ) + 1;

	  if ( app_reschange( flag ) )
	    d_exit = L_CHGRES;
	}

} /* inf_pref */
Пример #3
0
/*
 *  Routine that creates a new directory in the specified window/path
 */
WORD fun_mkdir(WNODE *pw_node)
{
    PNODE *pp_node;
    OBJECT *tree;
    WORD  i, len, err;
    BYTE  fnew_name[LEN_ZFNAME], unew_name[LEN_ZFNAME], *ptmp;
    BYTE  path[MAXPATHLEN];

    tree = G.a_trees[ADMKDBOX];
    pp_node = pw_node->w_path;
    ptmp = path;
    strcpy(ptmp, pp_node->p_spec);

    i = 0;
    while (*ptmp++)
    {
        if (*ptmp == '\\')
            i++;
    }

    if (i > MAX_LEVEL)
    {
        fun_alert(1, STFO8DEE);
        return FALSE;
    }

    while(1)
    {
        fnew_name[0] = '\0';
        inf_sset(tree, MKNAME, fnew_name);
        show_hide(FMD_START, tree);
        form_do(tree, 0);
        if (inf_what(tree, MKOK, MKCNCL) == 0)
            break;

        inf_sget(tree, MKNAME, fnew_name);
        unfmt_str(fnew_name, unew_name);

        if (unew_name[0] == '\0')
            break;

        ptmp = add_fname(path, unew_name);
        err = dos_mkdir(path);
        if (err == 0)       /* mkdir succeeded */
        {
            fun_rebld(pw_node);
            break;
        }

        /*
         * if we're getting a BIOS (rather than GEMDOS) error, the
         * critical error handler has already issued a message, so
         * just quit
         */
        if (IS_BIOS_ERROR(err))
            break;

        len = strlen(path); /* before we restore old path */
        restore_path(ptmp); /* restore original path */
        if (len >= LEN_ZPATH-3)
        {
            fun_alert(1,STDEEPPA);
            break;
        }

        /*
         * mkdir failed with a recoverable error:
         * prompt for Cancel or Retry
         */
        if (fun_alert(2,STFOFAIL) == 1)     /* Cancel */
            break;
    }

    show_hide(FMD_FINISH, tree);
    return TRUE;
}