WORD gr_slidebox(LONG tree, WORD parent, WORD obj, WORD isvert) { GRECT t, c; WORD divnd, divis; ob_actxywh(tree, parent, &c); ob_relxywh(tree, obj, &t); gr_dragbox(t.g_w, t.g_h, t.g_x + c.g_x, t.g_y + c.g_y, &c, &t.g_x, &t.g_y); if ( isvert ) { divnd = t.g_y - c.g_y; divis = c.g_h - t.g_h; } else { divnd = t.g_x - c.g_x; divis = c.g_w - t.g_w; } if (divis) return( mul_div( divnd, 1000, divis) ); else return(0); }
VOID slid_trees(VOID) { WORD v_size; v_size = min(1000, (WORD) umul_div(fit_vtrees(), 1000, need_vtrees())); set_slsize(rcs_view, 1000, v_size); v_size = max(1, fit_htrees() * (need_vtrees() - fit_vtrees())); v_size = mul_div(rcs_trpan, 1000, v_size); set_slpos(rcs_view, 0, v_size); }
/* * Routine to take the filenames that will appear in the window, * based on the current scrolled position, and point at them * with the sub-tree of G_STRINGs that makes up the window box. */ static void fs_format(LONG tree, WORD currtop, WORD count) { register WORD i, cnt; register WORD y, h, th; BYTE *p, name[LEN_FSNAME]; OBJECT *obj, *treeptr = (OBJECT *)tree; /* build in real text */ /* strings */ cnt = min(NM_NAMES, count - currtop); for(i=0, obj=treeptr+NAME_OFFSET; i<NM_NAMES; i++, obj++) { if (i < cnt) { p = ad_fsnames + g_fslist[currtop+i]; fmt_str(p+1, name+1); /* format file/folder name */ name[0] = p[0]; /* copy file/folder indicator */ } else { name[0] = ' '; name[1] = '\0'; } inf_sset(tree, NAME_OFFSET+i, name); obj->ob_type = G_FBOXTEXT; obj->ob_state = NORMAL; } /* size and position the*/ /* elevator */ y = 0; obj = treeptr + FSVSLID; th = h = obj->ob_height; if ( count > NM_NAMES) { h = mul_div(NM_NAMES, h, count); h = max(gl_hbox/2, h); /* min size elevator */ y = mul_div(currtop, th-h, count-NM_NAMES); } obj = treeptr + FSVELEV; obj->ob_y = y; obj->ob_height = h; }
void w_barcalc(WORD isvert, WORD space, WORD sl_value, WORD sl_size, WORD min_sld, GRECT *ptv, GRECT *pth) { if (sl_size == -1) sl_size = min_sld; else sl_size = max(min_sld, mul_div(sl_size, space, 1000) ); sl_value = mul_div(space - sl_size, sl_value, 1000); #if 0 /* anemic slidebars */ if (isvert) r_set(ptv, 3, sl_value, gl_wbox-6, sl_size); else r_set(pth, sl_value, 2, sl_size, gl_hbox-4); #else if (isvert) r_set(ptv, 0, sl_value, gl_wbox, sl_size); else r_set(pth, sl_value, 0, sl_size, gl_hbox); #endif }
VOID insa_elev(LONG tree, WORD nicon, WORD numics) { WORD y, h, th; LONG lp; y = 0; th = h = LWGET(OB_HEIGHT(APFSVSLI)); if ( numics > 1) { #if M68000 h = h / numics; #else h = mul_div(1, h, numics); #endif h = max((gl_hbox/2)+2, h); /* min size elevator */ #if M68000 y = (WORD)((LONG)nicon * (LONG)(th-h) / (LONG)(numics-1)); #else y = mul_div(nicon, th-h, numics-1); #endif } LWSET(OB_Y(APFSVELE), y); LWSET(OB_HEIGHT(APFSVELE), h); strcpy(&G.g_1text[0], ini_str(STAPPL)); insa_icon(tree, APF1NAME, IA_GENERIC+nicon, &gl_aib, &G.g_1text[0]); strcpy(&G.g_2text[0], ini_str(STDOCU)); insa_icon(tree, APF2NAME, ID_GENERIC+nicon, &gl_dib, &G.g_2text[0]); #if ALCYON lp = G.a_datastart + *((BYTE **)(G.a_datastart + gl_pstart + (nicon * sizeof(BYTE *)) ) ); #else lp = G.a_datastart + LWGET(G.a_datastart + gl_pstart + (nicon * sizeof(BYTE *)) ); #endif LSTCPY(lp, ADDR(&gl_lngstr[0])); inf_sset(tree, APFTITLE, &gl_lngstr[0] ); } /* insa_elev */
/* * Routine to change the current virtual row being viewed * in the upper left corner based on a new slide amount */ void win_slide(WORD wh, WORD sl_value) { WNODE *pw; WORD newcv; WORD vn, pn, i, sls, sl_size; pw = win_find(wh); if (!pw) return; vn = pw->w_vnrow; pn = pw->w_pnrow; sls = WF_VSLSIZ; wind_get(wh, sls, &sl_size, &i, &i, &i); newcv = mul_div(sl_value, vn - pn, 1000); win_blt(pw, newcv); }
WORD insa_dial(LONG tree, WORD nicon, WORD numics) { WORD firstslot, nstate, ystate, i; WORD touchob, oicon, value; WORD mx, my, kret, bret, cont; BYTE *pstr, doctype[4]; GRECT pt; /* draw the form */ show_hide(FMD_START, tree); /* init for while loop by forcing initial fs_newdir call */ cont = TRUE; while ( cont ) { firstslot = 6; for (i = 0; i < firstslot; i++) { pstr = &doctype[0]; inf_sget(tree, APDFTYPE+i, pstr); if (*pstr == '\0') firstslot = i; } touchob = form_do((OBJECT FAR *)tree, APDFTYPE+firstslot); graf_mkstate(&mx, &my, &kret, &bret); value = nstate = ystate = 0; touchob &= 0x7fff; switch ( touchob ) { case APINST: case APREMV: case APCNCL: cont = FALSE; break; case APFUPARO: value = -1; break; case APFDNARO: value = 1; break; case APGEM: nstate = SELECTED; ystate = DISABLED; break; case APDOS: case APPARMS: nstate = LWGET(OB_STATE(APNMEM)); ystate = LWGET(OB_STATE(APYMEM)); if ( ystate == DISABLED ) { nstate = SELECTED; ystate = NORMAL; } break; case APFSVSLI: ob_actxywh(tree, APFSVELE, &pt); pt.g_x -= 3; pt.g_w += 6; if ( rc_inside(&pt, mx, my) ) goto dofelev; value = (my <= pt.g_y) ? -1 : 1; break; case APFSVELE: dofelev: wind_update(3); ob_relxywh(tree, APFSVSLI, &pt); pt.g_x += 3; pt.g_w -= 6; LWSET(OB_X(APFSVSLI), pt.g_x); LWSET(OB_WIDTH(APFSVSLI), pt.g_w); value = graf_slidebox((OBJECT FAR *)tree, APFSVSLI, APFSVELE, TRUE); pt.g_x -= 3; pt.g_w += 6; LWSET(OB_X(APFSVSLI), pt.g_x); LWSET(OB_WIDTH(APFSVSLI), pt.g_w); wind_update(2); #if M68000 value = (WORD)((LONG)value * (LONG)(numics-1) / 1000) - nicon; #else value = mul_div(value, numics-1, 1000) - nicon; #endif break; } if (nstate != ystate) { LWSET(OB_STATE(APNMEM), nstate); LWSET(OB_STATE(APYMEM), ystate); draw_fld(tree, APMEMBOX); } if (value) { oicon = nicon; nicon += value; if (nicon < 0) nicon = 0; if (nicon >= numics) nicon = numics - 1; if (oicon != nicon) { insa_elev(tree, nicon, numics); draw_fld(tree, APFTITLE); draw_fld(tree, APFSVSLI); draw_fld(tree, APFILEBO); } } } /* undraw the form */ show_hide(FMD_FINISH, tree); return(nicon); }
/* * 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 ); }
/* * Build an object tree of the list of files that are currently * viewable in a window. Next adjust root of tree to take into * account the current view of the window. */ void win_bldview(WNODE *pwin, WORD x, WORD y, WORD w, WORD h) { FNODE *pstart; WORD obid; WORD r_cnt, c_cnt; WORD o_wfit, o_hfit; /* object grid */ WORD i_index; WORD xoff, yoff, wh, sl_size, sl_value; /* free all this window's kids and set size */ obj_wfree(pwin->w_root, x, y, w, h); /* make pstart point at 1st file in current view */ win_ocalc(pwin, w/G.g_iwspc, h/G.g_ihspc, &pstart); o_wfit = pwin->w_pncol; o_hfit = min(pwin->w_pnrow + 1, pwin->w_vnrow - pwin->w_cvrow); r_cnt = c_cnt = 0; while ((c_cnt < o_wfit) && (r_cnt < o_hfit) && pstart) { OBJECT *obj; SCREENINFO *si; USERBLK *ub; ICONBLK *ib; /* calc offset */ yoff = r_cnt * G.g_ihspc; xoff = c_cnt * G.g_iwspc; /* allocate object */ obid = obj_ialloc(pwin->w_root, xoff + G.g_iwint, yoff + G.g_ihint, G.g_iwext, G.g_ihext); if (!obid) /* can't allocate item object */ { KDEBUG(("win_bldview(): can't create window item object\n")); break; } /* remember it */ pstart->f_obid = obid; /* build object */ obj = &G.g_screen[obid]; obj->ob_state = WHITEBAK /*| DRAW3D*/; obj->ob_flags = 0x00; si = &G.g_screeninfo[obid]; switch(G.g_iview) { case V_TEXT: ub = &si->udef; obj->ob_type = G_USERDEF; obj->ob_spec = (LONG)ub; ub->ub_code = &dr_code; ub->ub_parm = (LONG)&pstart->f_junk; win_icalc(pstart, pwin); break; case V_ICON: ib = &si->icon.block; obj->ob_type = G_ICON; win_icalc(pstart, pwin); i_index = (pstart->f_isap) ? pstart->f_pa->a_aicon : pstart->f_pa->a_dicon; si->icon.index = i_index; obj->ob_spec = (LONG)ib; memcpy(ib, &G.g_iblist[i_index], sizeof(ICONBLK)); ib->ib_ptext = pstart->f_name; ib->ib_char |= pstart->f_pa->a_letter; break; } pstart = pstart->f_next; c_cnt++; if (c_cnt == o_wfit) { /* next row so skip next file in virt grid */ r_cnt++; c_cnt = 0; } } /* set slider size & position */ wh = pwin->w_id; wind_set(wh, WF_HSLSIZ, 1000, 0, 0, 0); sl_size = mul_div(pwin->w_pnrow, 1000, pwin->w_vnrow); wind_set(wh, WF_VSLSIZ, sl_size, 0, 0, 0); if (pwin->w_vnrow > pwin->w_pnrow) sl_value = mul_div(pwin->w_cvrow, 1000, pwin->w_vnrow-pwin->w_pnrow); else sl_value = 0; wind_set(wh, WF_VSLIDE, sl_value, 0, 0, 0); }