/* create_directx_window: * Creates the Allegro window. */ static HWND create_directx_window(void) { static int first = 1; WNDCLASS wnd_class; char fname[1024]; HWND wnd; if (first) { /* setup the window class */ wnd_class.style = CS_HREDRAW | CS_VREDRAW; wnd_class.lpfnWndProc = directx_wnd_proc; wnd_class.cbClsExtra = 0; wnd_class.cbWndExtra = 0; wnd_class.hInstance = allegro_inst; wnd_class.hIcon = LoadIcon(allegro_inst, "allegro_icon"); if (!wnd_class.hIcon) wnd_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd_class.hCursor = LoadCursor(NULL, IDC_ARROW); wnd_class.hbrBackground = NULL; wnd_class.lpszMenuName = NULL; wnd_class.lpszClassName = ALLEGRO_WND_CLASS; RegisterClass(&wnd_class); /* what are we called? */ get_executable_name(fname, sizeof(fname)); ustrlwr(fname); usetc(get_extension(fname), 0); if (ugetat(fname, -1) == '.') usetat(fname, -1, 0); do_uconvert(get_filename(fname), U_CURRENT, wnd_title, U_ASCII, WND_TITLE_SIZE); first = 0; } /* create the window now */ wnd = CreateWindowEx(WS_EX_APPWINDOW, ALLEGRO_WND_CLASS, wnd_title, WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, -100, -100, 0, 0, NULL, NULL, allegro_inst, NULL); if (!wnd) { _TRACE(PREFIX_E "CreateWindowEx() failed (%s)\n", win_err_str(GetLastError())); return NULL; } ShowWindow(wnd, SW_SHOWNORMAL); SetForegroundWindow(wnd); UpdateWindow(wnd); return wnd; }
int eof_string_has_non_ascii(char *str) { unsigned long ctr, length; if(!str) return 0; for(ctr = 0, length = ustrlen(str); ctr < length; ctr++) { //For each character of the string if(ugetat(str, ctr) > 127) { //If the character is not normal ASCII (value 0 through 127) return 1; } } return 0; }
/* fs_dlist_proc: * Dialog procedure for the file selector disk list. */ int fs_dlist_proc(int msg, DIALOG *d, int c) { DIALOG *parent = (DIALOG *)d->dp3; char *s = (char *)parent[FS_EDIT].dp; int ret, i, temp; if(msg == MSG_START) { d->d1 = d->d2 = 0; temp = utoupper(ugetc(s)); if(((temp >= 'A') && (temp <= 'Z')) && (ugetat(s, 1) == DEVICE_SEPARATOR)) { temp -= 'A'; for(i=0; i<temp; i++) if(_al_drive_exists(i)) d->d1++; } } ret = jwin_droplist_proc(msg, d, c); if(ret & D_CLOSE) { temp = 'A' + get_x_drive(d->d1+1); if((temp < 'A') || (temp > 'Z')) temp = 'C'; s += usetc(s, temp); s += usetc(s, DEVICE_SEPARATOR); s += usetc(s, OTHER_PATH_SEPARATOR); usetc(s, 0); object_message(parent +FS_FILES, MSG_START, 0); object_message(parent +FS_FILES, MSG_DRAW, 0); object_message(parent +FS_EDIT, MSG_START, 0); object_message(parent +FS_EDIT, MSG_DRAW, 0); return ret - D_CLOSE + D_O_K; } return ret; }
/* fs_dlist_proc: * Dialog procedure for the file selector disk list. */ static int fs_dlist_proc(int msg, DIALOG *d, int c) { char *s = file_selector[FS_EDIT].dp; int ret, i, temp; if (msg == MSG_START) { d->d1 = d->d2 = 0; temp = utoupper(ugetc(s)); if (((temp >= 'A') && (temp <= 'Z')) && (ugetat(s, 1) == DEVICE_SEPARATOR)) { temp -= 'A'; for (i=0; i<temp; i++) if (drive_exists(i)) d->d1++; } } ret = d_text_list_proc(msg, d, c); if (ret == D_CLOSE) { temp = 'A' + get_x_drive(d->d1+1); if ((temp < 'A') || (temp > 'Z')) temp = 'C'; s += usetc(s, temp); s += usetc(s, DEVICE_SEPARATOR); s += usetc(s, OTHER_PATH_SEPARATOR); usetc(s, 0); scare_mouse(); SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0); SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0); SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0); SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0); unscare_mouse(); return D_O_K; } return ret; }
int d_agtk_edit_proc(int msg, DIALOG *d, int c) { if (msg == MSG_DRAW) { BITMAP *bmp = gui_get_screen(); int l, x, b, f, p, w; int fg = (d->flags & D_DISABLED) ? hshadow : black; char *s = (char *)d->dp; char buf[16]; int fonth; agup_edit_adjust_position (d); fonth = text_height(font); l = ustrlen(s); /* set cursor pos */ if (d->d2 >= l) { d->d2 = l; usetc(buf+usetc(buf, ' '), 0); x = text_length(font, buf) + 2; } else x = 2; b = 0; /* num of chars to be blitted */ /* get the part of the string to be blitted */ for (p = d->d2; p >= 0; p--) { usetc(buf+usetc(buf, ugetat(s, p)), 0); x += text_length(font, buf); b++; if (x > d->w-4) break; } /* see if length of text is too wide */ if (x <= d->w-2) { b = l; p = 0; } else { b--; p = d->d2-b+1; b = d->d2; } if (d->flags & D_GOTFOCUS) gtk_bevel(bmp, d->x, d->y, d->w, fonth+6, 3); else gtk_bevel(bmp, d->x, d->y, d->w, fonth+6, 2); rectfill(bmp, d->x+2, d->y+2, d->x+d->w-3, d->y+fonth+3, white); for (x = 4; p<=b; p++) { f = ugetat(s, p); usetc(buf+usetc(buf, (f) ? f : ' '), 0); w = text_length(font, buf); f = ((p == d->d2) && (d->flags & D_GOTFOCUS)); textout_ex(bmp, font, buf, d->x+x, d->y+4, fg, white); if (f) vline(bmp, d->x+x-1, d->y+3, d->y+fonth+3, black); if ((x += w) + w > d->w - 4) break; } agup_edit_restore_position (d); return D_O_K; } return d_agup_adjusted_edit_proc(msg, d, c); }
/* fs_flist_proc: * Dialog procedure for the file selector list. */ static int fs_flist_proc(int msg, DIALOG *d, int c) { static int recurse_flag = 0; char *s = (char *) file_selector[FS_EDIT].dp; char tmp[32]; /* of s (in bytes) */ int size = (file_selector[FS_EDIT].d1 + 1) * uwidth_max(U_CURRENT); int sel = d->d1; int i, ret; int ch, count; if(msg == MSG_START) { if(!flist) { flist = (FLIST *) zc_malloc(sizeof(FLIST)); if(!flist) { *allegro_errno = ENOMEM; return D_CLOSE; } } else { for(i=0; i<flist->size; i++) if(flist->name[i]) zc_free(flist->name[i]); } flist->size = 0; replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir)); /* The semantics of the attributes passed to file_select_ex() is * different from that of for_each_file_ex() in one case: when * the 'd' attribute is not mentioned in the set of characters, * the other attributes are not taken into account for directories, * i.e the directories are all included. So we can't filter with * for_each_file_ex() in that case. */ if(attrb_state[ATTRB_DIREC] == ATTRB_ABSENT) /* accept all dirs */ for_each_file_ex(flist->dir, 0 , FA_LABEL, fs_flist_putter, (void *)1UL /* check */); else /* don't check */ for_each_file_ex(flist->dir, build_attrb_flag(ATTRB_SET), build_attrb_flag(ATTRB_UNSET) | FA_LABEL, fs_flist_putter, (void *)0UL); usetc(get_filename(flist->dir), 0); d->d1 = d->d2 = 0; sel = 0; } if(msg == MSG_END) { if(flist) { for(i=0; i<flist->size; i++) if(flist->name[i]) zc_free(flist->name[i]); zc_free(flist); flist = NULL; } } recurse_flag++; ret = jwin_abclist_proc(msg,d,c); /* call the parent procedure */ recurse_flag--; if(((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0)) { replace_filename(s, flist->dir, flist->name[d->d1], size); /* check if we want to `cd ..' */ if((!ustrncmp(flist->name[d->d1], uconvert_ascii("..", tmp), 2)) && (ret == D_CLOSE)) { /* let's remember the previous directory */ usetc(updir, 0); i = ustrlen(flist->dir); count = 0; while(i>0) { ch = ugetat(flist->dir, i); if((ch == '/') || (ch == OTHER_PATH_SEPARATOR)) { if(++count == 2) break; } uinsert(updir, 0, ch); i--; } /* ok, we have the dirname in updir */ } else { usetc(updir, 0); } object_message(file_selector+FS_EDIT, MSG_START, 0); object_message(file_selector+FS_EDIT, MSG_DRAW, 0); if(ret == D_CLOSE) return object_message(file_selector+FS_EDIT, MSG_KEY, 0); } return ret; }
/* fs_flist_putter: * Callback routine for for_each_file() to fill the file selector listbox. */ static int fs_flist_putter(AL_CONST char *str, int attrib, void *check_attrib) { char *s, *ext, *name; int c, c2; s = get_filename(str); fix_filename_case(s); if(!(attrib & FA_DIREC)) { /* Check if file extension matches. */ if(fext_p) { ext = get_extension(s); for(c=0; c<fext_size; c++) { if(ustricmp(ext, fext_p[c]) == 0) goto Next; } return 0; } Next: /* Check if file attributes match. */ if(check_attrib) { for(c=0; c<ATTRB_MAX; c++) { if((attrb_state[c] == ATTRB_SET) && (!(attrib & attrb_flag[c]))) return 0; if((attrb_state[c] == ATTRB_UNSET) && (attrib & attrb_flag[c])) return 0; } } } if((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) { int size = ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0); name = (char *) zc_malloc(size); if(!name) return -1; ustrzcpy(name, size, s); if(attrib & FA_DIREC) put_backslash(name); /* Sort alphabetically with directories first. */ for(c=0; c<flist->size; c++) { if(ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) { if(attrib & FA_DIREC) if(ustrfilecmp(name, flist->name[c]) < 0) break; } else { if(attrib & FA_DIREC) break; if(ustrfilecmp(name, flist->name[c]) < 0) break; } } /* Shift in preparation for inserting the new entry. */ for(c2=flist->size; c2>c; c2--) flist->name[c2] = flist->name[c2-1]; /* Insert the new entry. */ flist->name[c] = name; flist->size++; } return 0; }
/* fs_edit_proc: * Dialog procedure for the file selector editable string. */ static int fs_edit_proc(int msg, DIALOG *d, int c) { char *s = (char *) d->dp; int size = (d->d1 + 1) * uwidth_max(U_CURRENT); /* of s (in bytes) */ int list_size; int found = 0; char b[1024], tmp[16]; int ch, attr; int i; if(msg == MSG_START) { canonicalize_filename(b, s, sizeof(b)); ustrzcpy(s, size, b); } if(msg == MSG_KEY) { if((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR)) ustrzcat(s, size, uconvert_ascii("./", tmp)); canonicalize_filename(b, s, sizeof(b)); ustrzcpy(s, size - ucwidth(OTHER_PATH_SEPARATOR), b); ch = ugetat(s, -1); if((ch != '/') && (ch != OTHER_PATH_SEPARATOR)) { if(file_exists(s, FA_RDONLY | FA_HIDDEN | FA_DIREC, &attr)) { if(attr & FA_DIREC) put_backslash(s); else return D_CLOSE; } else return D_CLOSE; } object_message(file_selector+FS_FILES, MSG_START, 0); /* did we `cd ..' ? */ if(ustrlen(updir)) { /* now we have to find a directory name equal to updir */ for(i = 0; i<flist->size; i++) { if(!ustrcmp(updir, flist->name[i])) /* we got it ! */ { file_selector[FS_FILES].d1 = i; /* we have to know the number of visible lines in the filelist */ /* -1 to avoid an off-by-one problem */ list_size = (file_selector[FS_FILES].h-4) / text_height(font) - 1; if(i>list_size) file_selector[FS_FILES].d2 = i-list_size; else file_selector[FS_FILES].d2 = 0; found = 1; break; /* ok, our work is done... */ } } /* by some strange reason, we didn't find the old directory... */ if(!found) { file_selector[FS_FILES].d1 = 0; file_selector[FS_FILES].d2 = 0; } } /* and continue... */ object_message(file_selector+FS_FILES, MSG_DRAW, 0); object_message(d, MSG_START, 0); object_message(d, MSG_DRAW, 0); return D_O_K; } int allegro_lfn = ALLEGRO_LFN; //removes compiler warning if(msg == MSG_UCHAR) { if((c >= 'a') && (c <= 'z')) { if(!allegro_lfn) c = utoupper(c); } else if(c == '/') { c = OTHER_PATH_SEPARATOR; } else if(allegro_lfn) { if((c > 127) || (c < 32)) return D_O_K; } else { if((c != OTHER_PATH_SEPARATOR) && (c != '_') && (c != DEVICE_SEPARATOR) && (c != '.') && ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9'))) return D_O_K; } } // return _gui_edit_proc(msg, d, c); return jwin_edit_proc(msg, d, c); }
/* fs_flist_proc: * Dialog procedure for the file selector list. */ static int fs_flist_proc(int msg, DIALOG *d, int c) { static int recurse_flag = 0; char *s = file_selector[FS_EDIT].dp; char tmp[32]; int sel = d->d1; int i, ret; int ch, count; if (msg == MSG_START) { if (!flist) { flist = malloc(sizeof(FLIST)); if (!flist) { *allegro_errno = ENOMEM; return D_CLOSE; } } else { for (i=0; i<flist->size; i++) if (flist->name[i]) free(flist->name[i]); } flist->size = 0; replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir)); for_each_file(flist->dir, FA_RDONLY | FA_DIREC | FA_ARCH | FA_HIDDEN | FA_SYSTEM, fs_flist_putter, 0); if (*allegro_errno) raine_alert("", "Disk error", NULL, NULL, "OK", NULL, 13, 0); usetc(get_filename(flist->dir), 0); d->d1 = d->d2 = 0; sel = 0; } if (msg == MSG_END) { if (flist) { for (i=0; i<flist->size; i++) if (flist->name[i]) free(flist->name[i]); free(flist); flist = NULL; } } recurse_flag++; ret = d_text_list_proc(msg, d, c); /* call the parent procedure */ recurse_flag--; if (((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0)) { replace_filename(s, flist->dir, flist->name[d->d1], 512); /* check if we want to `cd ..' */ if ((!ustrncmp(flist->name[d->d1], "..", 2)) && (ret == D_CLOSE)) { /* let's remember the previous directory */ ustrcpy(updir, empty_string); i = ustrlen(flist->dir); count = 0; while (i>0) { ch = ugetat(flist->dir, i); if ((ch == '/') || (ch == OTHER_PATH_SEPARATOR)) { if (++count == 2) break; } uinsert(updir, 0, ch); i--; } /* ok, we have the dirname in updir */ } else { ustrcpy(updir, empty_string); } scare_mouse(); SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0); SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0); unscare_mouse(); if (ret == D_CLOSE) return SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0); } return ret; }
/* fs_flist_putter: * Callback routine for for_each_file() to fill the file selector listbox. */ static void fs_flist_putter(AL_CONST char *str, int attrib, int param) { char ext_tokens[32]; char *s, *ext, *tok, *name; char tmp[512], tmp2[32]; int c, c2, i, k, sign; /* attribute flags (rhsda order) * 0 = not required, 1 = must be set, -1 = must be unset */ int attr_flag[5+5] = { 0, -1, -1, 0, 0, FA_RDONLY, FA_HIDDEN, FA_SYSTEM, FA_DIREC, FA_ARCH }; c = usetc(ext_tokens, ' '); c += usetc(ext_tokens+c, ','); c += usetc(ext_tokens+c, ';'); usetc(ext_tokens+c, 0); s = get_filename(str); fix_filename_case(s); if (fext) { ustrcpy(tmp, fext); ustrtok(tmp, ext_tokens); c = (ustrtok(NULL, ext_tokens) ? 1 : 0); if (!c) { if (!ustrchr(fext, '/')) c = 1; } if (c && (!(attrib & FA_DIREC))) { ustrcpy(tmp, fext); ext = get_extension(s); tok = ustrtok(tmp, ext_tokens); while (tok) { if (ustricmp(ext, tok) == 0) break; tok = ustrtok(NULL, ext_tokens); } if (!tok) return; } c = usetc(ext_tokens, ' '); c += usetc(ext_tokens+c, ','); c += usetc(ext_tokens+c, ';'); c += usetc(ext_tokens+c, '/'); usetc(ext_tokens+c, 0); ustrcpy(tmp, fext); tok = ustrchr(tmp, '/'); if (tok) tok = ustrtok(tok, ext_tokens); if (tok) { sign = 1; c = usetc(tmp2, 'r'); c += usetc(tmp2+c, 'h'); c += usetc(tmp2+c, 's'); c += usetc(tmp2+c, 'd'); c += usetc(tmp2+c, 'a'); c += usetc(tmp2+c, '+'); c += usetc(tmp2+c, '-'); usetc(tmp2+c, 0); /* scan the string */ i = 0; while ((c = utolower(ugetat(tok, i)))) { k = 0; while ((c2 = ugetat(tmp2, k))!=0) { if (c == c2) { if (k<5) { attr_flag[k] = sign; break; } else sign = (k==5) ? 1 : -1; } k++; } i++; } } } /* check if file attributes match */ if (!(attr_flag[3+5] & attrib)) { /* if not a directory, we check all attributes except FA_DIREC */ for (c=0; c<5; c++) { if (c == 3) continue; if ((attr_flag[c] == 1) && (!(attrib & attr_flag[c+5]))) return; if ((attr_flag[c] == -1) && (attrib & attr_flag[c+5])) return; } } else { /* if a directory, we check only FA_DIREC */ if (attr_flag[3] == -1) return; } if ((flist->size < FLIST_SIZE) && ((ugetc(s) != '.') || (ugetat(s, 1)))) { name = malloc(ustrsizez(s) + ((attrib & FA_DIREC) ? ucwidth(OTHER_PATH_SEPARATOR) : 0)); if (!name) return; for (c=0; c<flist->size; c++) { if (ugetat(flist->name[c], -1) == OTHER_PATH_SEPARATOR) { if (attrib & FA_DIREC) if (ustrfilecmp(s, flist->name[c]) < 0) break; } else { if (attrib & FA_DIREC) break; if (ustrfilecmp(s, flist->name[c]) < 0) break; } } for (c2=flist->size; c2>c; c2--) flist->name[c2] = flist->name[c2-1]; flist->name[c] = name; ustrcpy(flist->name[c], s); if (attrib & FA_DIREC) put_backslash(flist->name[c]); flist->size++; } }
/* fs_edit_proc: * Dialog procedure for the file selector editable string. */ static int fs_edit_proc(int msg, DIALOG *d, int c) { char *s = d->dp; int list_size; int found = 0; char b[512]; int ch, attr; int i; if (msg == MSG_START) { fix_filename_path(b, s, sizeof(b)); ustrcpy(s, b); } if (msg == MSG_KEY) { if ((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR)) ustrcat(s, uconvert_ascii("./", NULL)); fix_filename_path(b, s, sizeof(b)); ustrcpy(s, b); ch = ugetat(s, -1); if ((ch != '/') && (ch != OTHER_PATH_SEPARATOR)) { if (file_exists(s, FA_RDONLY | FA_HIDDEN | FA_DIREC, &attr)) { if (attr & FA_DIREC) put_backslash(s); else return D_CLOSE; } else return D_CLOSE; } scare_mouse(); SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0); /* did we `cd ..' ? */ if (ustrlen(updir)) { /* now we have to find a directory name equal to updir */ for (i = 0; i<flist->size; i++) { if (!ustrcmp(updir, flist->name[i])) { /* we got it ! */ file_selector[FS_FILES].d1 = i; /* we have to know the number of visible lines in the filelist */ /* -1 to avoid an off-by-one problem */ list_size = (file_selector[FS_FILES].h-4) / text_height(font) - 1; if (i>list_size) file_selector[FS_FILES].d2 = i-list_size; else file_selector[FS_FILES].d2 = 0; found = 1; break; /* ok, our work is done... */ } } /* by some strange reason, we didn't find the old directory... */ if (!found) { file_selector[FS_FILES].d1 = 0; file_selector[FS_FILES].d2 = 0; } } /* and continue... */ SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0); SEND_MESSAGE(d, MSG_START, 0); SEND_MESSAGE(d, MSG_DRAW, 0); unscare_mouse(); return D_O_K; } if (msg == MSG_UCHAR) { if ((c >= 'a') && (c <= 'z')) { if (!ALLEGRO_LFN) c = utoupper(c); } else if (c == '/') { c = OTHER_PATH_SEPARATOR; } else if (ALLEGRO_LFN) { if ((c > 127) || (c < 32)) return D_O_K; } else { if ((c != OTHER_PATH_SEPARATOR) && (c != '_') && (c != DEVICE_SEPARATOR) && (c != '.') && ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9'))) return D_O_K; } } return x_edit_proc(msg, d, c); }
int d_aphoton_edit_proc(int msg, DIALOG *d, int c) { if (msg == MSG_DRAW) { int l, x, b, f, p, w, rtm; int fg = (d->flags & D_DISABLED) ? shadow : black; char *s = (char *)d->dp; char buf[16]; int fonth; agup_edit_adjust_position (d); fonth = text_height(font); l = ustrlen(s); /* set cursor pos */ if (d->d2 >= l) { d->d2 = l; usetc(buf+usetc(buf, ' '), 0); x = text_length(font, buf) + 2; } else x = 2; b = 0; /* num of chars to be blitted */ /* get the part of the string to be blitted */ for (p = d->d2; p >= 0; p--) { usetc(buf+usetc(buf, ugetat(s, p)), 0); x += text_length(font, buf); b++; if (x > d->w-4) break; } /* see if length of text is too wide */ if (x <= d->w-2) { b = l; p = 0; } else { b--; p = d->d2-b+1; b = d->d2; } photon_box(screen, d->x, d->y, d->w, fonth+8, edit_white); hline(screen, d->x+2, d->y+2, d->x+d->w-3, edit_gray); vline(screen, d->x+2, d->y+2, d->y+fonth+5, edit_gray); for (x = 4; p<=b; p++) { f = ugetat(s, p); usetc(buf+usetc(buf, (f) ? f : ' '), 0); w = text_length(font, buf); f = ((p == d->d2) && (d->flags & D_GOTFOCUS)); rtm = text_mode(edit_white); textout(screen, font, buf, d->x+x, d->y+4, fg); text_mode(rtm); if (f) vline(screen, d->x+x-1, d->y+3, d->y+fonth+5, black); if ((x += w) + w > d->w - 4) break; } if (d->flags & D_GOTFOCUS) hline(screen, d->x+4, d->y+fonth+4, d->x+d->w-5, highlight); agup_edit_restore_position (d); return D_O_K; } return d_agup_adjusted_edit_proc(msg, d, c); }
int d_aase_edit_proc(int msg, DIALOG *d, int c) { int ret; if (msg == MSG_START) { /* this is mainly for `file_select', because the size that it put to the `gui_edit_proc' is very small */ d->h = MAX(d->h, 3 + text_height(font) + 3); } else if (msg == MSG_DRAW) { int f, l, p, w, x, fg, b, scroll; char buf[16]; char *s; int rtm; agup_edit_adjust_position (d); if (!(d->flags & D_INTERNAL)) d->w -= 6; s = (char *)d->dp; l = ustrlen(s); if (d->d2 > l) d->d2 = l; /* calculate maximal number of displayable characters */ if (d->d2 == l) { usetc(buf+usetc(buf, ' '), 0); x = text_length(font, buf); } else x = 0; b = 0; for (p=d->d2; p>=0; p--) { usetc(buf+usetc(buf, ugetat(s, p)), 0); x += text_length(font, buf); b++; if (x > d->w) break; } if (x <= d->w) { b = l; scroll = FALSE; } else { b--; scroll = TRUE; } d->w += 6; ase_rectedge(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1, makecol(0, 0, 0), makecol(255, 255, 255)); ase_rectedge(screen, d->x+1, d->y+1, d->x+d->w-2, d->y+d->h-2, makecol(128, 128, 128), makecol(192, 192, 192)); ase_rectgouraud(screen, d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3, (d->flags & D_DISABLED)? 128: 224, 255); fg = (d->flags & D_DISABLED) ? aase_mg_color : d->fg; x = 3; if (scroll) { p = d->d2-b+1; b = d->d2; } else p = 0; for (; p<=b; p++) { f = ugetat(s, p); usetc(buf+usetc(buf, (f) ? f : ' '), 0); w = text_length(font, buf); if (x+w > d->w-2) break; f = ((p == d->d2) && (d->flags & D_GOTFOCUS)); rtm = text_mode((f) ? fg : -1); textout(screen, font, buf, d->x+x, d->y+d->h/2-text_height(font)/2, (f) ? d->bg : fg); text_mode(rtm); x += w; } if (d->flags & D_INTERNAL) d->w -= 6; agup_edit_restore_position (d); return D_O_K; } d->w -= 6; d->flags |= D_INTERNAL; ret = d_agup_adjusted_edit_proc(msg, d, c); d->flags &= ~D_INTERNAL; d->w += 6; return ret; }
int d_abitmap_edit_proc (int msg, DIALOG *d, int c) { if (msg == MSG_DRAW) { BITMAP *bmp = gui_get_screen(); int l, x, b, f, p, w; char *s = (char *) d->dp; char buf[16]; /* Buffer to hold one char at a time. */ int c = 0; int fg; agup_edit_adjust_position (d); if (d->flags & D_GOTFOCUS) c = 1; if (d->flags & D_DISABLED) c = 2; abitmap_draw_area (d, B_EDIT, 0, 0, d->w, text_height (font) + 8, 0, 0); l = ustrlen (s); /* set cursor pos */ if (d->d2 >= l) { d->d2 = l; usetc (buf + usetc (buf, ' '), 0); x = text_length (font, buf) + 2; } else x = 2; b = 0; /* num of chars to be blitted */ /* get the part of the string to be blitted */ for (p = d->d2; p >= 0; p--) { usetc (buf + usetc (buf, ugetat (s, p)), 0); x += text_length (font, buf); b++; if (x > d->w - 4) break; } /* see if length of text is too wide */ if (x <= d->w - 2) { b = l; p = 0; } else { b--; p = d->d2 - b + 1; b = d->d2; } for (x = 4; p <= b; p++) { f = ugetat (s, p); usetc (buf + usetc (buf, (f) ? f : ' '), 0); w = text_length (font, buf); if (((p == d->d2) && (d->flags & D_GOTFOCUS))) { abitmap_draw_bmp (bmp, &theme->bitmaps[B_CURSOR][c], d->x + x, d->y, w, text_height (font) + 4); fg = theme->bitmaps[B_CURSOR][c].color; } else fg = theme->bitmaps[B_EDIT][c].color; textout_ex (bmp, font, buf, d->x + x, d->y + 4, fg, -1); if ((x += w) + w > d->w - 4) break; } agup_edit_restore_position (d); return D_O_K; } if (msg == MSG_LOSTFOCUS || msg == MSG_LOSTMOUSE) return D_WANTFOCUS; return d_agup_adjusted_edit_proc (msg, d, c); }