#include #include #include #include #include #include #include window_t *make_dialog_window(char *name, int width, int height) { int x, y; yzGetWindowCorner(&x, &y); x += 50; y += 50; return (window_t*)yzNewWindowFlagsAt("Question", x, y, width, height, 64); } char *get_string_dialog(char *prompt, char *in_string) { window_t *w, *ow; button_t *ok_button; editline_t *string_line; char *string; string = malloc(1024); strcpy(string, in_string); ow = yzGetSelectedWindow(); if(ow) w = make_dialog_window("Question", 320, 110); else w = yzNewWindow("Question", 320, 110); yzSelectWindow(w); yzPenColor(55000, 55000, 55000); yzClear(); yzPenColor(0,0,0); yzText(32, 30, prompt); ok_button = yzAddButton("OK", 80, 70, 160, 24, 1); yzSetButtonKeyEquiv(ok_button, '\n'); string_line = yzAddEditline(string, 20, 40, 280, 24, 1, YZ_EDITLINE_ENTER | YZ_EDITLINE_RETURN); yzSelectEditline(string_line, 0, -1); do { yzFlashCaret(); } while(yzGetEvent(50).type != YZ_BUTTON_HIT); strcpy(string, yzGetEditlineText(string_line)); yzRemoveEditline(string_line); yzRemoveButton(ok_button); yzDeleteWindow(w); // yzFlushAllEvents(); // XXX anybody know what this was for? if(ow)yzSelectWindow(ow); return string; } /* struct async_get_string_params { FILE *pipe; void (*callback)(char *string); }; void *async_get_string_listener(struct async_get_string_params *par) { char result[1024]; fscanf(par->pipe, "%[^\n]", result); pclose(par->pipe); par->callback(result); free(par); return 0; } async_get_string_dialog(char *prompt, char *def, void (*callback)(char *string)) { struct async_get_string_params *par; pthread_t pth; char command[256]; sprintf(command, "yzgetstring -p \"%s\" -d \"%s\"", prompt, def); par = malloc(sizeof(*par)); par->pipe = popen(command, "r"); par->callback = callback; pthread_create(&pth, 0, async_get_string_listener, par); pthread_detach(pth); } */