static adv_error cmd_offvideo_test(int userkey) { adv_crtc* crtc; adv_crtc crtc_save; adv_bool modify = 0; crtc = menu_current(); if (!crtc) return -1; crtc_save = *crtc; modify = test_exe_crtc(userkey, crtc); if (!modify) { sound_warn(); return 0; } menu_modify(); if (strcmp(crtc->name, DEFAULT_TEXT_MODE)==0) { if (!crtc_clock_check(&the_monitor, crtc) && crtc_clock_check(&the_monitor, &crtc_save)) { *crtc = crtc_save; sound_error(); return 0; } text_reset(); } return 0; }
static UBool text_open(TestText *tt) { FILE *f; char *s; int32_t length; uprv_memset(tt, 0, sizeof(TestText)); f = fopenOrError("ConverterSelectorTestUTF8.txt"); if(!f) { return FALSE; } fseek(f, 0, SEEK_END); length = (int32_t)ftell(f); fseek(f, 0, SEEK_SET); tt->text = (char *)uprv_malloc(length + 1); if (tt->text == NULL) { fclose(f); return FALSE; } if (length != fread(tt->text, 1, length, f)) { log_err("error reading %ld bytes from test text file\n", (long)length); length = 0; uprv_free(tt->text); } fclose(f); tt->textLimit = tt->text + length; *tt->textLimit = 0; /* replace all Unicode '#' (U+0023) with NUL */ for(s = tt->text; (s = uprv_strchr(s, 0x23)) != NULL; *s++ = 0) {} text_reset(tt); return TRUE; }
void TextEditBox::text_reset(char *newtext, int N) { STACKTRACE; textinfo->textinfo = newtext; text = newtext; textinfo->Nchars = N; maxchars = N; text_reset(); }
static adv_error cmd_onvideo_calib(void) { adv_mode mode; adv_crtc* crtc; unsigned speed; char buffer[128]; mode_reset(&mode); if (the_mode_index == MODE_FLAGS_INDEX_TEXT) { error_set("Command supported only in graphics mode"); return -1; } crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } video_write_lock(); draw_graphics_palette(); /* draw_graphics_out_of_screen(0); */ draw_graphics_clear(); speed = draw_graphics_speed(0, 0, video_size_x(), video_size_y()); draw_graphics_calib(0, 0, video_size_x(), video_size_y()); snprintf(buffer, sizeof(buffer), " %.2f MB/s", speed / (double)(1024*1024)); draw_string(0, 0, buffer, DRAW_COLOR_WHITE); video_write_unlock(0, 0, 0, 0, 0); video_wait_vsync(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); return 0; }
/* Read directory entries into the textboxes */ static void dirent_read(kiss_textbox *textbox1, kiss_vscrollbar *vscrollbar1, kiss_textbox *textbox2, kiss_vscrollbar *vscrollbar2, kiss_label *label_sel) { kiss_dirent *ent; kiss_stat s; kiss_dir *dir; char buf[KISS_MAX_LENGTH], ending[2]; kiss_array_free(textbox1->array); kiss_array_free(textbox2->array); kiss_array_new(textbox1->array); kiss_array_new(textbox2->array); kiss_getcwd(buf, KISS_MAX_LENGTH); strcpy(ending, "/"); if (buf[0] == 'C') strcpy(ending, "\\"); if (!strcmp(buf, "/") || !strcmp(buf, "C:\\")) strcpy(ending, ""); kiss_string_copy(label_sel->text, (2 * textbox1->rect.w + 2 * kiss_up.w) / kiss_textfont.advance, buf, ending); #ifdef _MSC_VER dir = kiss_opendir("*"); #else dir = kiss_opendir("."); #endif while ((ent = kiss_readdir(dir))) { if (!ent->d_name) continue; kiss_getstat(ent->d_name, &s); if (kiss_isdir(s)) kiss_array_appendstring(textbox1->array, 0, ent->d_name, "/"); else if (kiss_isreg(s)) kiss_array_appendstring(textbox2->array, 0, ent->d_name, NULL); } kiss_closedir(dir); text_reset(textbox1, vscrollbar1); text_reset(textbox2, vscrollbar2); }
static void TestSelector() { TestText text; USet* excluded_sets[3] = { NULL }; int32_t i, testCaseIdx; if (!getAvailableNames()) { return; } if (!text_open(&text)) { releaseAvailableNames();; } excluded_sets[0] = uset_openEmpty(); for(i = 1 ; i < 3 ; i++) { excluded_sets[i] = uset_open(i*30, i*30+500); } for(testCaseIdx = 0; testCaseIdx < UPRV_LENGTHOF(getEncodingsFns); testCaseIdx++) { int32_t excluded_set_id; int32_t num_encodings; const char **encodings = getEncodingsFns[testCaseIdx](&num_encodings); if (getTestOption(QUICK_OPTION) && num_encodings > 25) { uprv_free((void *)encodings); continue; } /* * for(excluded_set_id = 0 ; excluded_set_id < 3 ; excluded_set_id++) * * This loop was replaced by the following statement because * the loop made the test run longer without adding to the code coverage. * The handling of the exclusion set is independent of the * set of encodings, so there is no need to test every combination. */ excluded_set_id = testCaseIdx % UPRV_LENGTHOF(excluded_sets); { UConverterSelector *sel_rt, *sel_fb; char *buffer_fb = NULL; UErrorCode status = U_ZERO_ERROR; sel_rt = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET, &status); if (num_encodings == gCountAvailable) { /* test the special "all converters" parameter values */ sel_fb = ucnvsel_open(NULL, 0, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else if (uset_isEmpty(excluded_sets[excluded_set_id])) { /* test that a NULL set gives the same results as an empty set */ sel_fb = ucnvsel_open(encodings, num_encodings, NULL, UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } else { sel_fb = ucnvsel_open(encodings, num_encodings, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET, &status); } if (U_FAILURE(status)) { log_err("ucnv_sel_open(encodings %ld) failed - %s\n", testCaseIdx, u_errorName(status)); ucnvsel_close(sel_rt); uprv_free((void *)encodings); continue; } text_reset(&text); for (;;) { UBool *manual_rt, *manual_fb; static UChar utf16[10000]; char *s; int32_t length8, length16; s = text_nextString(&text, &length8); if (s == NULL || (getTestOption(QUICK_OPTION) && text.number > 3)) { break; } manual_rt = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_SET); manual_fb = getResultsManually(encodings, num_encodings, s, length8, excluded_sets[excluded_set_id], UCNV_ROUNDTRIP_AND_FALLBACK_SET); /* UTF-8 with length */ status = U_ZERO_ERROR; verifyResult(ucnvsel_selectForUTF8(sel_rt, s, length8, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, length8, &status), manual_fb); /* UTF-8 NUL-terminated */ verifyResult(ucnvsel_selectForUTF8(sel_rt, s, -1, &status), manual_rt); verifyResult(ucnvsel_selectForUTF8(sel_fb, s, -1, &status), manual_fb); u_strFromUTF8(utf16, UPRV_LENGTHOF(utf16), &length16, s, length8, &status); if (U_FAILURE(status)) { log_err("error converting the test text (string %ld) to UTF-16 - %s\n", (long)text.number, u_errorName(status)); } else { if (text.number == 0) { sel_fb = serializeAndUnserialize(sel_fb, &buffer_fb, &status); } if (U_SUCCESS(status)) { /* UTF-16 with length */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, length16, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, length16, &status), manual_fb); /* UTF-16 NUL-terminated */ verifyResult(ucnvsel_selectForString(sel_rt, utf16, -1, &status), manual_rt); verifyResult(ucnvsel_selectForString(sel_fb, utf16, -1, &status), manual_fb); } } uprv_free(manual_rt); uprv_free(manual_fb); } ucnvsel_close(sel_rt); ucnvsel_close(sel_fb); uprv_free(buffer_fb); } uprv_free((void *)encodings); } releaseAvailableNames(); text_close(&text); for(i = 0 ; i < 3 ; i++) { uset_close(excluded_sets[i]); } }
/* Menu */ static int menu_run(void) { adv_bool done; int userkey; menu_base = 0; menu_rel = 0; menu_rel_max = MENU_DY; menu_max = crtc_container_max(&the_modes); menu_base_max = menu_max - menu_rel_max; if (menu_base_max < 0) menu_base_max = 0; done = 0; while (!done) { draw_text_index(BAR_X, BAR_Y1+1, BAR_DX); draw_text_bar(BAR_X, BAR_Y1, BAR_Y2, BAR_DX); draw_text_info(INFO_X, INFO_Y, INFO_DX, INFO_DY, menu_base + menu_rel); menu_draw(MENU_X, MENU_Y, MENU_DX, MENU_DY); video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_UP: cmd_gotopos(menu_base + menu_rel - 1); break; case INPUTB_DOWN: cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_HOME: { int i = menu_base + menu_rel - 1; if (i<0) i = 0; while (i>0 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) --i; cmd_gotopos(i); break; } case INPUTB_END: { int i = menu_base + menu_rel + 1; if (i >= menu_max) i = menu_max - 1; while (i < menu_max - 1 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) ++i; cmd_gotopos(i); break; } case INPUTB_PGDN: cmd_gotopos(menu_base + menu_rel + menu_rel_max); break; case INPUTB_PGUP: cmd_gotopos(menu_base + menu_rel - menu_rel_max); break; case INPUTB_F2: cmd_save(); break; case INPUTB_LEFT : case INPUTB_RIGHT : cmd_type(userkey); break; case INPUTB_ESC: done = cmd_exit(); break; case INPUTB_SPACE: cmd_select(); cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_ENTER: if (cmd_onvideo_test() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F9: if (cmd_onvideo_calib() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F10: if (cmd_onvideo_animate() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_TAB : cmd_rename(); break; case INPUTB_F5 : if (cmd_modeline_create(1) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F6 : if (cmd_modeline_create(0) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F7 : cmd_copy(); break; case INPUTB_F8 : if (cmd_mode_clock() !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_DEL : cmd_del(); cmd_gotopos(menu_base + menu_rel); break; case INPUTB_F1: draw_text_help(); break; default: if (cmd_offvideo_test(userkey) != 0) { draw_text_error(); } break; } } return userkey; }
static adv_error cmd_onvideo_animate(void) { adv_mode mode; adv_crtc* crtc; unsigned i; int counter; mode_reset(&mode); if (the_mode_index == MODE_FLAGS_INDEX_TEXT) { error_set("Command supported only in graphics mode"); return -1; } crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } update_init(2); draw_graphics_palette(); for(i=0;i<3;++i) { update_start(); video_clear(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 0); update_stop(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 1); } counter = update_page_max_get(); while (!inputb_hit()) { os_poll(); update_start(); draw_graphics_animate(update_x_get(), update_y_get(), video_size_x(), video_size_y(), counter - update_page_max_get() + 1, 1); ++counter; draw_graphics_animate(update_x_get(), update_y_get(), video_size_x(), video_size_y(), counter, 0); update_stop(update_x_get(), update_y_get(), video_size_x(), video_size_y(), 1); } update_done(); do { target_idle(); os_poll(); } while (inputb_get()==INPUTB_NONE); return 0; }
static adv_error cmd_onvideo_test(void) { adv_crtc* crtc; adv_mode mode; adv_bool done; adv_crtc crtc_save; adv_bool dirty = 1; adv_bool crtc_save_modified; mode_reset(&mode); crtc = menu_current(); if (!crtc) return -1; if (!crtc_is_fake(crtc) && !crtc_clock_check(&the_monitor, crtc)) return -1; if (video_mode_generate(&mode, crtc, the_mode_index)!=0) { return -1; } if (text_mode_set(&mode) != 0) { text_reset(); return -1; } crtc_save = *crtc; crtc_save_modified = the_modes_modified; done = 0; while (!done) { int userkey; adv_bool modify = 0; adv_crtc last_crtc = *crtc; adv_mode last_mode = mode; adv_bool vm_last_modified = the_modes_modified; if (dirty) { video_write_lock(); test_draw(1, 1, &mode); video_write_unlock(0, 0, 0, 0, 0); dirty = 0; } video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_ESC : done = 1; /* restore */ *crtc = crtc_save; the_modes_modified = crtc_save_modified; break; case INPUTB_ENTER : done = 1; break; } if (!done) { modify = test_exe_crtc(userkey, crtc); if (modify) { the_modes_modified = 1; dirty = 1; if ((crtc_is_fake(crtc) || crtc_clock_check(&the_monitor, crtc)) && video_mode_generate(&mode, crtc, the_mode_index)==0) { if (text_mode_set(&mode) != 0) { text_reset(); /* abort */ *crtc = crtc_save; the_modes_modified = crtc_save_modified; return -1; } } else { /* restore */ mode = last_mode; *crtc = last_crtc; the_modes_modified = vm_last_modified; dirty = 1; sound_error(); } } else { sound_warn(); } } } return 0; }
// this is, where text is detected and entered ... I think .... void TextEditBox::calculate() { STACKTRACE; if (textinfo->textinfo != text) {tw_error("text mismatch");} TextInfoArea::calculate(); int ys; ys = scroll.yselect; // perhaps this could happen if someone changes the text pointer. if (ys < 0) ys = 0; if (ys > textinfo->Nlines-1) ys = textinfo->Nlines-1; scroll.calculate(); // if scrolled, then update the position in the text if (scroll.yselect > textinfo->Nlines-1) scroll.yselect = textinfo->Nlines-1; if (scroll.yselect < 0) scroll.yselect = 0; if (scroll.yselect != ys) { // update the charpos ... textinfo->changeline(&charpos, ys, scroll.yselect); } if (!flag.focus) return; int ikey; // check all the keys that were pressed ... for ( ikey = 0; ikey < keyhandler.Nbuf; ++ikey ) { // normal character format int k = keyhandler.keybuf[ikey] & 0x0FF; if (keyhandler.keynew[KEY_LCONTROL]) continue; // don't use any keyboard presses when the control key is being held... if ( (k >= 0x020 && k < 0x080) || k == '\r' || k == '\n' ) { if (k == '\r') k = '\n'; // return should yield a newline! // insert a character memmove(&text[charpos+1], &text[charpos], (maxchars-1)-charpos-1); text[charpos] = k; if (charpos < (int)strlen(text)) ++charpos; //text[charpos] = 0; } } // Insert text from the clipboard (?) #ifdef WIN32 if (keyhandler.keyhit[KEY_V] && keyhandler.keynew[KEY_LCONTROL]) { //Test: this can show contents of the clipboard ... HWND w; w = win_get_window(); OpenClipboard(w); char *txt = (char*) ::GetClipboardData(CF_TEXT); int L; L = strlen(txt); if (L + charpos < maxchars) { memmove(&text[charpos+L], &text[charpos], (maxchars-1)-charpos-L); memcpy(&text[charpos], txt, L); // update the editor linestarts and stuff... text_reset(); } CloseClipboard(); } #endif // check the special keys ? if ( keyhandler.keyhit[KEY_BACKSPACE] && charpos > 0 ) { // delete the previous character int m; m = 1; // if it's a return, then delete that as well // if (text[charpos-1] == '\n' && charpos > 1) // ++m; // nah, don't delete, otherwise you can't undelete a line, purely memmove(&text[charpos-m], &text[charpos], (maxchars-m)-charpos); text[maxchars-m] = 0; charpos -= m; } if ( keyhandler.keyhit[KEY_DEL] && text[charpos] != 0 ) { // delete the current character (if it's not the closing zero) int m; m = 1; // if it's a return, then delete that as well if (text[charpos+1] == '\n') ++m; memmove(&text[charpos], &text[charpos+m], (maxchars-m)-charpos); text[maxchars-m] = 0; } if ( keyhandler.keyhit[KEY_LEFT] ) { if (charpos > 0 ) --charpos; //if (charpos > 0 && text[charpos] == '\n') // --charpos; } if ( keyhandler.keyhit[KEY_RIGHT] ) { if (charpos < (int)strlen(textinfo->textinfo)) ++charpos; //if (charpos < strlen(textinfo->textinfo) && text[charpos] == '\n') // ++charpos; } if ( keyhandler.keyhit[KEY_UP] ) { // update the charpos ... int ys; ys = scroll.yselect - 1; if (ys < 0) ys = 0; textinfo->changeline(&charpos, scroll.yselect, ys); } if ( keyhandler.keyhit[KEY_DOWN] ) { // update the charpos ... int ys; ys = scroll.yselect + 1; if (ys > textinfo->Nlines-1) ys = textinfo->Nlines-1; textinfo->changeline(&charpos, scroll.yselect, ys); } if (ikey > 0) text_reset(); }