void draw_box(char *title, int _x, int _y, int _w, int _h, int shadow) { int x, y; hi_vid(); goto1(_x, _y); pch(TL_CHAR); pch(TOP_CHAR); x=2; if (title) { mywrite(title); x += strlen(title); } while (x<_w-1) { pch(TOP_CHAR); x++; } pch(TR_CHAR); for (y=1; y<_h-1; y++) { goto1(_x, _y+y); pch(SIDE_CHAR); for (x=1; x<_w-1; x++) pch(' '); pch(SIDE_CHAR); } goto1(_x, _y+_h-1); pch(BL_CHAR); for (x=1; x<_w-1; x++) pch(BOTTOM_CHAR); pch(BR_CHAR); if (shadow) { tattr(((config.hi_col >> 4) == 8) ? 0 : 128); for (y=1; y<_h; y++) { goto1(_x+_w, _y+y); pch(' '); } goto1(_x+1, _y+_h); for (x=0; x<_w; x++) pch(' '); } n_vid(); }
int main(){ CRASHREPORTER_init(); //getc(stdin); //CRASHREPORTER_close(); //CRASHREPORTER_report_crash("Gakk!!!\n1\n2\n3\n"); goto1(); }
int select_file(char *prompt, char *fname) { int ret; static char p[256] = ""; filebox.h = screen_h - 10; filebox.height = screen_h - 14; filebox.w = MAX(screen_w - 16, 32); filebox.slen = filebox.w - 8; draw_box(prompt, 7, 2, filebox.w, 5, TRUE); draw_listbox(&filebox); hi_vid(); goto1(7,6); pch(LJOIN_CHAR); goto1(filebox.w+6,6); pch(RJOIN_CHAR); if (!fname[0]) { if (p[0]) strcpy(fname, p); else getcwd(fname, 256); cleanup_filename(fname); append_backslash(fname); } fill_filelist(fname); goto1(12, 4); ret = do_input_text(fname, 255, 54, is_filechar, fsel_proc, TRUE, fsel_mouse); if (ret != ESC) { strcpy(p, fname); *get_fname(p) = 0; } n_vid(); empty_filelist(); dirty_everything(); return ret; }
void draw_askbox(LISTBOX *l) { draw_box(l->title, l->x, l->y, l->w, l->h, TRUE); draw_contents(l); hi_vid(); goto1(l->x+4, l->y+2); mywrite((char *)l->parent); pch('?'); n_vid(); }
char *prepare_popup(char *t, int *_x, int *_y, int *_w) { char *b; if (*_w > screen_w - 4) *_w = screen_w - 4; *_x = (screen_w - *_w) / 2 - 1; *_y = (screen_h - 5) / 2; b = save_screen(*_x, *_y, *_w, 5); draw_box(t, *_x, *_y, *_w, 5, TRUE); goto1(*_x+5, *_y+2); hi_vid(); return b; }
int do_input_text(char *buf, int size, int width, int (*valid)(char), int (*proc)(int, char *, int *, int *), int mouse_flag, int (*mouse_proc)(int x, int y, char *buf, int *oldlen)) { KEYPRESS k; int key; int askey; int ret; int x, y, len, cpos; int oldlen, c; int gap; int sel = TRUE; x = x_pos; y = y_pos; len = oldlen = cpos = strlen(buf); n_vid(); do { goto1(x, y); if ((width > 0) && (len > width)) { gap = len - width; pch('.'); pch('.'); pch('.'); pch(' '); mywrite(buf+gap+4); } else { gap = 0; mywrite(buf); } hi_vid(); for (c=len-gap; c < ((width > 0) ? width : oldlen); c++) pch(' '); oldlen = len; if (cpos-gap > 0) goto2(x+cpos-gap, y); else goto2(x, y); show_c(); if (mouse_flag) { display_mouse(); while (m_b) poll_mouse(); while (TRUE) { if (input_waiting()) { k = input_char(); key = k.key; if ((ascii(key) == CR) && (k.flags & KF_CTRL)) key = LF; if (key) break; } poll_mouse(); if ((m_b) && (mouse_proc)) { hide_c(); key = (*mouse_proc)(x, y, buf, &oldlen); len = cpos = strlen(buf); sel = FALSE; show_c(); if (key > 0) break; } } hide_mouse(); } else { while (m_b) poll_mouse(); while ((!input_waiting()) && (!m_b)) poll_mouse(); if (m_b) { if (m_b & 2) key = ESC; else key = CR; } else { k = input_char(); key = k.key; if ((ascii(key) == CR) && (k.flags & KF_CTRL)) key = LF; } } if ((!proc) || (!(*proc)(key, buf, &len, &cpos))) { if ((key==CTRL_G) || (key==CTRL_C)) askey=ESC; else askey=ascii((char)key); if ((askey==ESC) || (askey==CR) || (askey==LF)) { ret = askey; break; } if (key==LEFT_ARROW) { if (cpos > 0) cpos--; } else if (key==RIGHT_ARROW) { if (cpos < len) cpos++; } else if (key==K_HOME) { cpos = 0; } else if (key==K_END) { cpos = MAX(len, 0); } else { if ((sel) && ((key==K_DELETE) || (askey==BACKSPACE) || ((*valid)(askey)))) { len = cpos = 0; buf[0] = 0; } if (key==K_DELETE) { if (cpos < len) { for (c=cpos; c<len; c++) buf[c] = buf[c+1]; len--; } } else if (askey==BACKSPACE) { if (cpos > 0) { cpos--; for (c=cpos; c<len; c++) buf[c] = buf[c+1]; len--; } } else { if ((len<size) && ((*valid)(askey))) { len++; for (c=len; c>cpos; c--) buf[c] = buf[c-1]; buf[cpos++]=askey; } } } if (proc) (*proc)(-1, buf, &len, &cpos); } sel = FALSE; } while (TRUE); n_vid(); return ret; }
int fsel_mouse(int x, int y, char *s, int *len) { int c, gap; int selitem; int first = TRUE; int changed; int d; #ifdef TARGET_CURSES int count = 0; #endif if ((m_x < filebox.x) || (m_x >= filebox.x + filebox.w) || (m_y < filebox.y) || (m_y >= filebox.y + filebox.h) || (m_b & 2)) return ESC; if (filebox.count <= 0) return 0; do { delay(10); selitem = -1; changed = d = FALSE; if (mouse_inside_list(&filebox)) { filebox.current = get_mouse_item(&filebox); if (filebox.current >= filebox.count) filebox.current = filebox.count - 1; else selitem = filebox.current; changed = TRUE; } else { if ((m_y < filebox.y + filebox.yoff) && (filebox.scroll > 0)) { filebox.scroll--; filebox.current = filebox.scroll; changed = d = TRUE; } else if ((m_y >= filebox.y + filebox.yoff + filebox.height) && (filebox.scroll < filebox.count - filebox.height)) { filebox.scroll++; filebox.current = filebox.scroll + filebox.height - 1; if (filebox.current >= filebox.count) filebox.current = filebox.count-1; changed = d = TRUE; } } if (changed) { hide_mouse(); draw_contents(&filebox); strcpy(s, filebox.data[filebox.current].text); goto1(x, y); hi_vid(); if (strlen(s) > 54) { gap = strlen(s) - 54; pch('.'); pch('.'); pch('.'); pch(' '); mywrite(s+gap+4); } else { gap = 0; mywrite(s); } for (c=strlen(s)-gap; c<54; c++) pch(' '); goto2(x+strlen(s+gap), y); *len = strlen(s); display_mouse(); } if (d) delay(20); if ((first) && (selitem >= 0)) if (!mouse_dclick(FALSE)) if (mouse_dclick(TRUE)) return CR; first = FALSE; refresh_screen(); #ifdef TARGET_CURSES if (d) { if (count++ >= 10) m_b = 0; } else while (m_b) #endif poll_mouse(); } while(m_b); clear_keybuf(); return 0; }
void fill_filelist(char *path) { char b[256]; int c; FILENODE *node; int redraw = FALSE; int old; strcpy(b, path); #if (defined TARGET_DJGPP) || (defined TARGET_WIN) strcpy(get_fname(b), "*.*"); #else strcpy(get_fname(b), "*"); #endif cleanup_filename(b); if (stricmp(b, filepath) != 0) { empty_filelist(); do_for_each_file(b, add_to_filelist, 0); do_for_each_directory(b, add_to_filelist, 0); if (filebox.count > 0) { filebox.data = malloc(sizeof(LISTITEM)*filebox.count); if (filebox.data) { node = filenode; for (c=0; c<filebox.count; c++) { filebox.data[c].text = node->name; filebox.data[c].data = -1; filebox.data[c].click_proc = NULL; filebox.data[c].draw_proc = NULL; filebox.data[c].comment = NULL; node = node->next; } } else errno = ENOMEM; } redraw = TRUE; strcpy(filepath, b); } old = filebox.current; filebox.current = -1; if (path[0]) { char *p = get_fname(path); int len = strlen(p); if (p[0]) { for (c=0; c<filebox.count; c++) { if (strnicmp(p, get_fname(filebox.data[c].text), len)==0) { filebox.current = c; break; } } } } if (filebox.current != old) { if (filebox.current != -1) { while (filebox.current < filebox.scroll) filebox.scroll--; while (filebox.current >= filebox.scroll+filebox.height) filebox.scroll++; } redraw = TRUE; } if (redraw) { if (errno==0) draw_contents(&filebox); else { filebox.current = -1; filebox.count = -1; draw_contents(&filebox); hi_vid(); goto1(filebox.x+filebox.xoff+1, filebox.y+filebox.yoff); mywrite("Error: "); mywrite(err()); } } }
void draw_contents(LISTBOX *l) { int x, y; int c, c2; int len; char *p; hi_vid(); if (l->flags & LISTBOX_SCROLL) { goto1(l->x+l->xoff+3, l->y+1); for (c=0; c<4; c++) { if (l->scroll > 0) pch(UP_CHAR); else pch(' '); pch(' '); pch(' '); } goto1(l->x+l->xoff+3, l->y+l->h-2); for (c=0; c<4; c++) { if (l->scroll + l->width*l->height < l->count) pch(DOWN_CHAR); else pch(' '); pch(' '); pch(' '); } } for (y=0; y<l->height; y++) { for (x=0; x<l->width; x++) { goto1(l->x+l->xoff+(l->slen+2)*x, l->y+l->yoff+y); c = l->scroll + y*l->width + x; if (c==l->current) n_vid(); pch(' '); if (c < l->count) { if (l->data[c].draw_proc) { (*l->data[c].draw_proc)(l->slen+1, l, l->data+c); } else { p = l->data[c].text; len = l->slen; if (strlen(p) > len) { pch('.'); pch('.'); pch('.'); pch(' '); len -= 4; p += (strlen(p) - len); } for (c2=0; p[c2]; c2++) pch(p[c2]); while (c2++ <= len) pch(' '); } } else for (c2=0; c2<l->slen+1; c2++) pch(' '); if (c==l->current) { if ((config.comments) && (l->data[c].comment)) { strcpy(message, l->data[c].comment); display_message(0); hide_c(); } hi_vid(); } } } n_vid(); }