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); }
/* * Routine to handle scrolling the directory window a certain number * of file names. */ static WORD fs_nscroll(LONG tree, WORD *psel, WORD curr, WORD count, WORD touchob, WORD n) { register WORD i, newcurr, diffcurr; WORD sy, dy, neg; GRECT r[2]; /* single scroll n times*/ newcurr = curr; for (i=0; i<n; i++) newcurr = fs_1scroll(newcurr, count, touchob); /* if things changed */ /* then redraw */ diffcurr = newcurr - curr; if (diffcurr) { curr = newcurr; fs_sel(*psel, NORMAL); *psel = 0; fs_format(tree, curr, count); gsx_gclip(&r[1]); ob_actxywh(tree, F1NAME, &r[0]); if (( neg = (diffcurr < 0)) != 0 ) diffcurr = -diffcurr; if (diffcurr < NM_NAMES) { sy = r[0].g_y + (r[0].g_h * diffcurr); dy = r[0].g_y; if (neg) { dy = sy; sy = r[0].g_y; } bb_screen(S_ONLY, r[0].g_x, sy, r[0].g_x, dy, r[0].g_w, r[0].g_h * (NM_NAMES - diffcurr) ); if ( !neg ) r[0].g_y += r[0].g_h * (NM_NAMES - diffcurr); } else diffcurr = NM_NAMES; r[0].g_h *= diffcurr; for(i=0; i<2; i++) { gsx_sclip(&r[i]); ob_draw(tree, ((i) ? FSVSLID : FILEBOX), MAX_DEPTH); } } return(curr); }
WORD gr_watchbox(LONG tree, WORD obj, WORD instate, WORD outstate) { register WORD out; register WORD state; GRECT t; gsx_sclip(&gl_rscreen); ob_actxywh(tree, obj, &t); out = FALSE; do { state = (out) ? outstate : instate; ob_change(tree, obj, state, TRUE); out = !out; } while( gr_stilldn(out, t.g_x, t.g_y, t.g_w, t.g_h) ); return( out ); }
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 ); }
static void hctl_window(WORD w_handle, WORD mx, WORD my) { GRECT t, f, pt; WINDOW *pwin = &D.w_win[w_handle]; WORD x, y, w, h; WORD wm, hm; WORD kind; WORD cpt, message; LONG tree; message = 0; x = y = w = h = 0; if ( (w_handle == gl_wtop) || ( (pwin->w_flags & VF_SUBWIN) && (D.w_win[gl_wtop].w_flags & VF_SUBWIN) ) ) { /* * went down on active window so handle control points */ w_bldactive(w_handle); tree = gl_awind; cpt = ob_find(gl_awind, 0, 10, mx, my); w_getsize(WS_CURR, w_handle, &t); r_get(&t, &x, &y, &w, &h); kind = pwin->w_kind; switch(cpt) { case W_CLOSER: if ( kind & HOTCLOSE ) { message = WM_CLOSED; break; } /* else fall thru */ case W_FULLER: if ( gr_watchbox(gl_awind, cpt, SELECTED, NORMAL) ) { message = (cpt == W_CLOSER) ? WM_CLOSED : WM_FULLED; ob_change(gl_awind, cpt, NORMAL, TRUE); } break; case W_NAME: if ( kind & MOVER ) { /* prevent the mover gadget from being moved completely offscreen */ r_set(&f, 0, gl_hbox, gl_rscreen.g_w + w - gl_wbox - 6, MAX_COORDINATE); gr_dragbox(w, h, x, y, &f, &x, &y); message = WM_MOVED; } break; case W_SIZER: if (kind & SIZER) { w_getsize(WS_WORK, w_handle, &t); t.g_x -= x; t.g_y -= y; t.g_w -= w; t.g_h -= h; wm = gl_wchar; hm = gl_hchar; if (kind & (LFARROW | RTARROW | HSLIDE)) wm = gl_wbox * 7; if (kind & (UPARROW | DNARROW | VSLIDE)) hm = gl_hbox * 7; gr_rubwind(x, y, wm, hm, &t, &w, &h); message = WM_SIZED; } break; case W_HSLIDE: case W_VSLIDE: ob_actxywh(tree, cpt + 1, &pt); if (inside(mx, my, &pt)) { cpt = (cpt==W_HSLIDE) ? W_HELEV : W_VELEV; goto doelev; } /* fix up cpt for index into gl_wa[] */ if (cpt == W_HSLIDE) { if ( !(mx < pt.g_x) ) cpt += 1; } else { if ( !(my < pt.g_y) ) cpt += 1; } /* fall thru */ case W_UPARROW: case W_DNARROW: case W_LFARROW: case W_RTARROW: message = WM_ARROWED; x = gl_wa[cpt - W_UPARROW]; break; case W_HELEV: case W_VELEV: doelev: message = (cpt == W_HELEV) ? WM_HSLID : WM_VSLID; x = gr_slidebox(gl_awind, cpt - 1, cpt, (cpt == W_VELEV)); /* slide is 1 less than elev */ break; } } else { perform_untop(gl_wtop); /* * went down on inactive window so tell ap. to bring it to top */ message = WM_TOPPED; } ct_msgup(message, pwin->w_owner, w_handle, x, y, w, h); }