Changeset 1587
- Timestamp:
- 01/20/12 09:10:22 (16 months ago)
- Location:
- branches/tbox_test
- Files:
-
- 3 added
- 14 edited
-
CHDK/LANG/english.lng (modified) (1 diff)
-
CHDK/SCRIPTS/TEST/filetest.lua (added)
-
CHDK/SCRIPTS/TEST/tboxtest.lua (added)
-
core/action_stack.h (modified) (1 diff)
-
core/conf.c (modified) (1 diff)
-
core/gui.c (modified) (4 diffs)
-
core/gui_fselect.c (modified) (7 diffs)
-
core/gui_lang.h (modified) (1 diff)
-
core/gui_tbox.c (modified) (13 diffs)
-
core/gui_tbox.h (added)
-
core/luascript.c (modified) (4 diffs)
-
core/module_exportlist.c (modified) (1 diff)
-
core/module_load.c (modified) (1 diff)
-
core/modules.c (modified) (1 diff)
-
core/modules.h (modified) (1 diff)
-
core/script.c (modified) (1 diff)
-
include/conf.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/tbox_test/CHDK/LANG/english.lng
r1574 r1587 587 587 473 "Options" 588 588 589 474 " Select keyboard profile"590 475 " Load keyboard profile"589 474 "Text Box settings" 590 475 "Select textbox charmap" 591 591 476 "More ->" 592 592 477 "Make dir" -
branches/tbox_test/core/action_stack.h
r1359 r1587 23 23 AS_SCRIPT_WRITE_USB_MSG, // params: timeout, msg 24 24 AS_FILE_BROWSER, 25 AS_TEXTBOX, 25 26 }; 26 27 -
branches/tbox_test/core/conf.c
r1576 r1587 404 404 CONF_INFO(249, conf.remote_control_mode, CONF_DEF_VALUE, i:0, NULL), 405 405 406 // Text Box char map file407 CONF_INFO(250, conf.charmap_file, CONF_CHAR_PTR, ptr:"", NULL),408 409 406 }; 410 407 #define CONF_NUM (sizeof(conf_info)/sizeof(conf_info[0])) -
branches/tbox_test/core/gui.c
r1572 r1587 157 157 static void gui_draw_calendar(int arg); 158 158 #endif 159 static void gui_load_charmap(int arg);160 159 static void gui_draw_load_lang(int arg); 161 160 static void gui_menuproc_mkbootdisk(int arg); … … 588 587 MENU_ITEM(0x35,LANG_MENU_VIS_MENU_FONT, MENUITEM_PROC, gui_draw_load_menu_rbf, 0 ), 589 588 MENU_ITEM(0x35,LANG_MENU_VIS_MENU_SYMBOL_FONT, MENUITEM_PROC, gui_draw_load_symbol_rbf, 0 ), 590 MENU_ITEM(0x35,LANG_ MENU_VIS_CHARMAP, MENUITEM_PROC, gui_load_charmap, 0),591 MENU_ITEM(0x80,LANG_MENU_RESET_FILES ,MENUITEM_PROC, gui_menuproc_reset_files, 0 ),592 MENU_ITEM(0x0,LANG_MENU_VIS_COLORS, MENUITEM_SEPARATOR, 0, 0 ),589 MENU_ITEM(0x35,LANG_STR_TEXTBOX_SETTINGS, MENUITEM_SUBMENU_PROC, gui_menu_run_fltmodule, "_tbox.flt" ), 590 MENU_ITEM(0x80,LANG_MENU_RESET_FILES, MENUITEM_PROC, gui_menuproc_reset_files, 0 ), 591 MENU_ITEM(0x0,LANG_MENU_VIS_COLORS, MENUITEM_SEPARATOR, 0, 0 ), 593 592 MENU_ITEM(0x65,LANG_MENU_VIS_OSD_TEXT, MENUITEM_COLOR_FG, &conf.osd_color, 0 ), 594 593 MENU_ITEM(0x65,LANG_MENU_VIS_OSD_BKG, MENUITEM_COLOR_BG, &conf.osd_color, 0 ), … … 1409 1408 conf.menu_symbol_rbf_file[0] = 0; 1410 1409 conf.menu_rbf_file[0] = 0; 1411 conf.charmap_file[0] = 0;1412 1410 conf_save(); 1413 1411 gui_mbox_init(LANG_INFORMATION, LANG_MENU_RESTART_CAMERA, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); … … 2587 2585 } 2588 2586 2589 static void gui_charmap_selected(const char *fn) {2590 if (fn)2591 strcpy(conf.charmap_file, fn);2592 }2593 static void gui_load_charmap(int arg) {2594 module_fselect_init(LANG_STR_SELECT_CHARMAP_FILE, conf.charmap_file, "A/CHDK", gui_charmap_selected);2595 }2596 2597 2587 CMenuItem* find_mnu(CMenu *curr_menu, int itemid ) 2598 2588 { -
branches/tbox_test/core/gui_fselect.c
r1574 r1587 1105 1105 } 1106 1106 1107 static void mkdir_cb(c har* name)1107 static void mkdir_cb(const char* name) 1108 1108 { 1109 1109 if (name) { … … 1115 1115 } 1116 1116 1117 static void rename_cb(c har* name)1117 static void rename_cb(const char* name) 1118 1118 { 1119 1119 if (name) { … … 1131 1131 switch (actn) { 1132 1132 case MPOPUP_MKDIR: 1133 module_tbox_run( LANG_POPUP_MKDIR, LANG_PROMPT_MKDIR, "", 15, mkdir_cb); 1133 if (module_tbox_load()) 1134 module_tbox_load()->textbox_init(LANG_POPUP_MKDIR, LANG_PROMPT_MKDIR, "", 15, mkdir_cb); 1134 1135 break; 1135 1136 case MPOPUP_RMDIR: … … 1137 1138 break; 1138 1139 case MPOPUP_RENAME: 1139 module_tbox_run( LANG_POPUP_RENAME, LANG_PROMPT_RENAME, selected->name, 15, rename_cb); 1140 if (module_tbox_load()) 1141 module_tbox_load()->textbox_init(LANG_POPUP_RENAME, LANG_PROMPT_RENAME, selected->name, 15, rename_cb); 1140 1142 break; 1141 1143 } … … 1293 1295 case KEY_LEFT: 1294 1296 if (selected && selected->attr != 0xFF) { 1295 i=MPOPUP_CUT|MPOPUP_COPY|MPOPUP_SELINV ;1296 mpopup_rawop_flag=0;1297 i=MPOPUP_CUT|MPOPUP_COPY|MPOPUP_SELINV|MPOPUP_MORE; 1298 mpopup_rawop_flag=0; 1297 1299 if (fselect_marked_count() > 0) { 1298 1300 i |= MPOPUP_DELETE; … … 1304 1306 } 1305 1307 1306 if ( API_VERSION_MATCH_REQUIREMENT( module_tbox_get_version(), 1, 0 ) )1307 i |= MPOPUP_MORE;1308 1309 1308 if (marked_operation == MARKED_OP_CUT || marked_operation == MARKED_OP_COPY) 1310 1309 i |= MPOPUP_PASTE; 1311 1310 if (!(selected->attr & DOS_ATTR_DIRECTORY) || !(selected->name[0] == '.' && selected->name[1] == '.' && selected->name[2] == 0) ||//If item is not a folder or UpDir 1312 (selected->name[0] == 'D' && selected->name[1] == 'C' && selected->name[2] == 'I' && selected->name[3] == 'M') ||//If item is DCIM folder1313 (selected->name[3] == 'C'))//If item is a DCIM sub folder1311 (selected->name[0] == 'D' && selected->name[1] == 'C' && selected->name[2] == 'I' && selected->name[3] == 'M') ||//If item is DCIM folder 1312 (selected->name[3] == 'C'))//If item is a DCIM sub folder 1314 1313 i |= MPOPUP_PURGE;//Display PURGE RAW function in popup menu 1315 1314 if(selected->size == hook_raw_size()) 1316 1315 mpopup_rawop_flag |= MPOPUP_RAW_DEVELOP; 1317 1316 1318 if ( module_convert_dng_to_chdk_raw(0) ) // if dng module exist1319 if((fselect_marked_count()>1)||(selected->size > hook_raw_size()))1320 mpopup_rawop_flag |= MPOPUP_DNG_TO_CRW;1321 1322 if (selected->name[9] == 'B' && selected->name[10] == 'I' && selected->name[11] == 'N') //If item is DCIM folder1317 if ( module_convert_dng_to_chdk_raw(0) ) // if dng module exist 1318 if((fselect_marked_count()>1)||(selected->size > hook_raw_size())) 1319 mpopup_rawop_flag |= MPOPUP_DNG_TO_CRW; 1320 1321 if (selected->name[9] == 'B' && selected->name[10] == 'I' && selected->name[11] == 'N') //If item is DCIM folder 1323 1322 i |= MPOPUP_CHDK_REPLACE; 1324 1323 1325 if ( mpopup_rawop_flag )1326 i |= MPOPUP_RAWOPS;1327 1328 1329 mpopup_more_flag = MPOPUP_MKDIR;1330 if (selected->attr & DOS_ATTR_DIRECTORY)1331 mpopup_more_flag |=MPOPUP_RMDIR;1324 if ( mpopup_rawop_flag ) 1325 i |= MPOPUP_RAWOPS; 1326 1327 1328 mpopup_more_flag = MPOPUP_MKDIR; 1329 if (selected->attr & DOS_ATTR_DIRECTORY) 1330 mpopup_more_flag |=MPOPUP_RMDIR; 1332 1331 if ( !(selected->name[0] == '.' && selected->name[1] == '.' && selected->name[2] == 0) ) //If item is not UpDir 1333 mpopup_more_flag |=MPOPUP_RENAME;1332 mpopup_more_flag |=MPOPUP_RENAME; 1334 1333 1335 1334 module_mpopup_init( popup, i, fselect_mpopup_cb, 0); … … 1455 1454 module_set_flags(module_idx, MODULE_FLAG_DISABLE_AUTOUNLOAD); 1456 1455 1457 if ( argn == 5 ) { 1458 gui_fselect_init( arguments[0], (const char*) arguments[1], (const char*) arguments[2], (void*)arguments[3]); 1459 gui_fselect_set_key_redraw(arguments[4]); 1456 if ( argn == 5 ) 1457 { 1458 gui_fselect_init( arguments[0], (const char*) arguments[1], (const char*) arguments[2], (void*)arguments[3]); 1459 gui_fselect_set_key_redraw(arguments[4]); 1460 1460 } 1461 1461 else 1462 gui_fselect_init(LANG_STR_FILE_BROWSER, "A", "A", NULL);1462 gui_fselect_init(LANG_STR_FILE_BROWSER, "A", "A", NULL); 1463 1463 1464 1464 return 0; -
branches/tbox_test/core/gui_lang.h
r1574 r1587 594 594 #define LANG_MENU_REMOTE_OPTIONS 473 595 595 596 #define LANG_STR_ SELECT_CHARMAP_FILE474596 #define LANG_STR_TEXTBOX_SETTINGS 474 597 597 #define LANG_MENU_VIS_CHARMAP 475 598 598 #define LANG_POPUP_MORE 476 -
branches/tbox_test/core/gui_tbox.c
r1569 r1587 8 8 #include "gui_draw.h" 9 9 #include "gui_lang.h" 10 #include "gui_menu.h" 10 11 #include "gui_mbox.h" 12 #include "gui_tbox.h" 11 13 12 14 #include "module_load.h" 13 15 16 //------------------------------------------------------------------- 17 // Zebra config settings 18 19 typedef struct 20 { 21 int char_map; 22 } TextBoxConf; 23 24 TextBoxConf tconf; 25 26 static ConfInfo conf_info[] = { 27 CONF_INFO( 1, tconf.char_map, CONF_DEF_VALUE, i:0, NULL), 28 }; 29 30 //------------------------------------------------------------------- 14 31 extern void gui_tbox_kbd_process(); 15 32 extern void gui_tbox_draw(int enforce_redraw); … … 53 70 #define MAX_MSG_LENGH 20 //max length of hardcoded messages (>navigate cursor<, text limit reached) 54 71 55 typedef void (*tbox_on_select_t)(c har* newstr);72 typedef void (*tbox_on_select_t)(const char* newstr); 56 73 tbox_on_select_t tbox_on_select = 0; 57 74 58 75 static coord tbox_buttons_x, tbox_buttons_y; 59 76 60 // 61 const char *tbox_chars_default[] = {"ABCDEF|GHIJKL|MNOPQRS|TUVWXYZ", 62 "abcdef|ghijkl|mnopqrs|tuvwxyz", 63 "123|456|789|0+-=/", 64 ".,:;?!|@#$%^&|()[]{}|<>\"'`~", 65 0 }; 66 67 const char *tbox_chars[MAX_CHARSET+1]; // current char map (array of string. separator of groups is '|') 68 int lines = 0; // num of valid lines in tbox_chars 69 int subgroup_offs[4]; // offsets of subgroups in currently selected line of tbox_chars 77 // Char maps 78 const char *tbox_chars_default[] = 79 { 80 "ABCDEF|GHIJKL|MNOPQRS|TUVWXYZ", 81 "abcdef|ghijkl|mnopqrs|tuvwxyz", 82 "123|456|789|0+-=/", 83 ".,:;?!|@#$%^&|()[]{}|<>\"'`~", 84 0 85 }; 86 const char *tbox_chars_russian[] = 87 { 88 "ABCDEF|GKLHIJ|MNOPQRS|TUVWXYZ", 89 "abcdef|ghijkl|mnopqrs|tuvwxyz", 90 "ÀÁÂÃÄÅÆ|ÇÈÉÊËÌÍ|ÎÏÐÑÒÓÔ|ÕÖרÙÛÜÝÞß", 91 "àáâãäåæ|çèéêëìí|îïðñòóô|õö÷øùûüýþÿ", 92 "123|456|789|0+-=", 93 " .:,|;/\\|'\"*|#%&", 94 0 95 }; 96 97 const char **charmaps[] = { tbox_chars_default, tbox_chars_russian }; 98 99 const char **tbox_chars; // current char map (array of string. separator of groups is '|') 100 int lines = 0; // num of valid lines in tbox_chars 101 int subgroup_offs[4]; // offsets of subgroups in currently selected line of tbox_chars 70 102 71 103 … … 81 113 82 114 //------------------------------------------------------- 83 static void tbox_charmap_init( char* buffer, int buffer_size) 84 { 85 int i, size; 86 87 lines=0; 88 memset( tbox_chars, 0, sizeof(tbox_chars) ); 89 90 lines = 0; 91 for ( i=0; i<buffer_size && lines<MAX_CHARSET;) 115 static void tbox_charmap_init( const char** buffer ) 116 { 117 max_keyboard_lenght = 0; 118 tbox_chars = buffer; 119 120 for (lines=0; tbox_chars[lines] && lines<MAX_CHARSET; lines++) 92 121 { 93 size = strlen(buffer+i); 94 if ( size > 0 ) 95 tbox_chars[lines++]=(buffer+i); 96 if (max_keyboard_lenght<size) max_keyboard_lenght=size; 97 i+=size+1; 98 } 99 100 if ( lines>0 ) 101 return; 102 103 104 for (lines=0;lines<MAX_CHARSET;lines++) { 105 tbox_chars[lines] = tbox_chars_default[lines]; 106 if ( tbox_chars[lines]==0 ) 107 break; 108 if (max_keyboard_lenght<strlen(tbox_chars[lines])) max_keyboard_lenght=strlen(tbox_chars[lines]); 122 if (max_keyboard_lenght < strlen(tbox_chars[lines])) 123 max_keyboard_lenght = strlen(tbox_chars[lines]); 109 124 } 110 125 } … … 125 140 126 141 127 128 void gui_tbox_init(int title, int msg, char* defaultstr, unsigned int maxsize, void (*on_select)(char* newstr)) { 142 int textbox_init(int title, int msg, char* defaultstr, unsigned int maxsize, void (*on_select)(const char* newstr)) { 143 129 144 text = malloc(sizeof(char)*(maxsize+1)); 130 145 if ( text==0 ) { … … 133 148 tbox_on_select(0); // notify callback about exit as cancel 134 149 module_async_unload(module_idx); 135 return; 136 } 150 return 0; 151 } 152 153 tbox_charmap_init( charmaps[tconf.char_map] ); 137 154 138 155 memset(text, '\0', sizeof(char)*(maxsize+1)); … … 146 163 tbox_msg = lang_str(msg); 147 164 tbox_on_select = on_select; 148 gui_tbox_mode_old = gui_set_mode( &GUI_MODE_TBOX );149 165 150 166 Mode = 'K'; … … 157 173 158 174 gui_tbox_redraw = 2; 175 gui_tbox_mode_old = gui_set_mode( &GUI_MODE_TBOX ); 176 177 return 1; 159 178 } 160 179 … … 521 540 else { 522 541 free(text); 542 text = 0; 523 543 tbox_on_select(0); // cancel 524 544 } … … 536 556 537 557 538 // DEBUG TEST CALLBACK 539 void test_callback(char* txt ) 540 { 541 if ( txt==0 ) // cancel 542 { 543 gui_mbox_init(139, 139, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); 544 } 545 else //ok 546 { 547 gui_mbox_init(138, (int)txt, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL); 548 // should be free in real callback but here should be kept to correct mbox 549 } 550 } 558 //------------------------------------------------------------------- 559 560 static const char* gui_text_box_charmap[] = { "Default", "Russian" }; 561 static CMenuItem zebra_submenu_items[] = { 562 MENU_ENUM2(0x5f,LANG_MENU_VIS_CHARMAP, &tconf.char_map, gui_text_box_charmap ), 563 MENU_ITEM(0x51,LANG_MENU_BACK, MENUITEM_UP, 0, 0 ), 564 {0} 565 }; 566 static CMenu textbox_submenu = {0x26,LANG_STR_TEXTBOX_SETTINGS, NULL, zebra_submenu_items }; 551 567 552 568 553 569 //================================================== 570 571 struct libtextbox_sym libtextbox = { 572 MAKE_API_VERSION(1,0), // apiver: increase major if incompatible changes made in module, 573 // increase minor if compatible changes made(including extending this struct) 574 textbox_init, 575 }; 576 577 578 void* MODULE_EXPORT_LIST[] = { 579 /* 0 */ (void*)EXPORTLIST_MAGIC_NUMBER, 580 /* 1 */ (void*)1, 581 582 &libtextbox 583 }; 554 584 555 585 … … 568 598 return 1; 569 599 600 config_restore(&conf_info[0], "A/CHDK/MODULES/CFG/_tbox.cfg", sizeof(conf_info)/sizeof(conf_info[0]), 0, 0); 570 601 cl_greygrey = MAKE_COLOR(COLOR_GREY, COLOR_GREY); 571 602 572 603 return 0; 573 604 } 574 575 605 576 606 … … 581 611 int _module_unloader() 582 612 { 613 config_save(&conf_info[0], "A/CHDK/MODULES/CFG/_tbox.cfg", sizeof(conf_info)/sizeof(conf_info[0])); 614 583 615 // clean allocated resource 584 if ( text!=0 ) { 616 if ( text!=0 ) 617 { 585 618 free(text); 586 if (tbox_on_select) 587 tbox_on_select(0); // notify callback about exit as cancel 588 } 589 619 text = 0; 620 } 590 621 591 622 //sanity clean to prevent accidentaly assign/restore guimode to unloaded module … … 604 635 module_idx=moduleidx; 605 636 606 607 // DEBUG CASE 608 if ( argn==0 ) { 609 tbox_charmap_init( 0,0 ); 610 611 gui_tbox_init( 137 /*title*/, 137 /*msg*/, (char*)NULL /*defaultstr*/, 612 50 /*maxsize*/, test_callback /* on_select */); 613 return 0; 614 615 } 616 617 // "Run scenario #1" - no arguments request for keyboard API version 618 if ( argn!=7 || arguments==0 || arguments[6]==0) 619 { 620 module_async_unload(moduleidx); 621 return MAKE_API_VERSION(1,0); 622 } 623 624 // Autounloading is unsafe because it should exists to catch finalization of mpopup 625 //module_set_flags(module_idx, MODULE_FLAG_DISABLE_AUTOUNLOAD); 626 627 tbox_charmap_init( (char*)arguments[0] /*charmap_buffer*/, arguments[1] /*charmap_size*/); 628 629 gui_tbox_init( arguments[2] /*title*/, arguments[3] /*msg*/, (char*)arguments[4] /*defaultstr*/, 630 arguments[5] /*maxsize*/, (tbox_on_select_t) arguments[6] /* on_select */); 637 gui_activate_sub_menu(&textbox_submenu, module_idx); 631 638 632 639 return 0; … … 639 646 sizeof(struct ModuleInfo), 640 647 641 ANY_CHDK_BRANCH, 0, // Requirements of CHDK version642 ANY_PLATFORM_ALLOWED, // Specify platform dependency643 0, // MODULEINFO_FLAG_SYSTEM,// flag648 ANY_CHDK_BRANCH, 0, // Requirements of CHDK version 649 ANY_PLATFORM_ALLOWED, // Specify platform dependency 650 MODULEINFO_FLAG_SYSTEM, // flag 644 651 (int32_t)"Virtual keyboard", // Module name 645 1, 0, // Module version652 1, 0, // Module version 646 653 0 647 654 }; -
branches/tbox_test/core/luascript.c
r1570 r1587 817 817 } 818 818 819 static void file_browser_selected(const char *fn) {819 static void return_string_selected(const char *str) { 820 820 // Reconnect button input to script - will also signal action stack 821 // that file browser is finished and return last selected file821 // that file browser / textbox is finished and return last selected file 822 822 // to script caller 823 823 state_kbd_script_run = 1; 824 824 // Clear the Func/Set key so that when the script exits, pressing 825 // the Func/Set key again will enter the Script menu, not the File Browser 825 // the Func/Set key again will enter the Script menu, not the File Browser / Textbox 826 826 kbd_reset_autoclicked_key(); 827 827 828 828 // Push selected file as script return value 829 lua_pushstring( Lt, ( fn && fn[0])? fn: NULL );829 lua_pushstring( Lt, (str && str[0])? str : NULL ); 830 830 } 831 831 … … 836 836 action_push(AS_FILE_BROWSER); 837 837 // Switch to file browser gui mode. Path can be supplied in call or defaults to "A" (root directory). 838 module_fselect_init(LANG_STR_FILE_BROWSER, luaL_optstring( L, 1, "A" ), "A", file_browser_selected);838 module_fselect_init(LANG_STR_FILE_BROWSER, luaL_optstring( L, 1, "A" ), "A", return_string_selected); 839 839 // Yield the script so that the action stack will process the AS_FILE_BROWSER action 840 return lua_yield(L, 0); 841 } 842 843 static int luaCB_textbox( lua_State* L ) { 844 // Disconnect button input from script so buttons will work in the textbox 845 state_kbd_script_run = 0; 846 if (module_tbox_load()) 847 { 848 // Push textbox action onto stack - will loop doing nothing until textbox exits 849 action_push(AS_TEXTBOX); 850 // Switch to textbox gui mode. Text box prompt should be passed as param. 851 module_tbox_load()->textbox_init((int)luaL_optstring( L, 1, "A" ), (int)luaL_optstring( L, 1, "A" ), "", 30, return_string_selected); 852 } 853 else 854 return_string_selected(0); 855 856 // Yield the script so that the action stack will process the AS_TEXTBOX action 840 857 return lua_yield(L, 0); 841 858 } … … 2131 2148 2132 2149 if(strcmp(heapname,"system") == 0) { 2133 #if defined(CAM_FIRMWARE_MEMINFO)2134 2150 GetMemInfo(&meminfo); 2135 #else2136 memset(&meminfo,0xFF,sizeof(cam_meminfo));2137 meminfo.free_block_max_size = core_get_free_memory();2138 #endif2139 2151 } 2140 2152 #if defined(OPT_EXMEM_MALLOC) && !defined(OPT_EXMEM_TESTING) … … 2352 2364 2353 2365 FUNC(file_browser) 2366 FUNC(textbox) 2354 2367 2355 2368 FUNC(draw_pixel) -
branches/tbox_test/core/module_exportlist.c
r1572 r1587 317 317 &COLOR__EXPORTEDSYM_HISTO_RG_PLAY, 318 318 319 module_tbox_get_version, 320 module_tbox_run, 319 module_tbox_load, 321 320 322 321 config_save, -
branches/tbox_test/core/module_load.c
r1569 r1587 474 474 int module_check_is_exist(char* name) 475 475 { 476 char path[60]; 477 flat_module_path_make(path, name); 478 479 module_fd = open( path, O_RDONLY, 0777 ); 480 if ( module_fd >0 ) 481 close (module_fd); 482 483 return (module_fd>=0)?1:0; 476 char path[60]; 477 flat_module_path_make(path, name); 478 479 struct stat st; 480 if (stat(path,&st) != 0) return 0; // file does not exist 481 482 return 1; 484 483 } 485 484 -
branches/tbox_test/core/modules.c
r1569 r1587 328 328 /************* MODULE TBOX ******/ 329 329 330 static char* tbox_file_buffer = 0; 331 static char* tbox_file_buffer_default = "_tbox.flt"; 332 static int tbox_file_buffer_size = 0; 333 static char* charmap_buffer = 0; 334 static int charmap_buffer_size = 0; 335 336 // Auxilary function - Parse loaded keymap, ask module for its API version 337 // Input values: tbox_file_buffer, tbox_file_buffer_size 338 // Return value: 0-error, otherwise API version 339 //----------------------------------------------------- 340 static int module_tbox_charmap_preprocess() 341 { 342 charmap_buffer = 0; 343 charmap_buffer_size = 0; 344 345 //-- input checks 346 if ( tbox_file_buffer==0 || tbox_file_buffer_size<=0 ) 347 return 0; 348 349 int i, ver; 350 351 //-- Parse: split to lines 352 for( i=0; i<tbox_file_buffer_size; i++ ) 353 if ( tbox_file_buffer[i] == 0x0d || tbox_file_buffer[i] == 0x0a) 354 tbox_file_buffer[i]=0; 355 356 //-- First line is name of tbox module 357 i = strlen(tbox_file_buffer); // size 358 if ( i==0 ) 359 return 0; 360 361 // tbox "run scenario #1" - argc=1, argv=0 - mean "say your API version" 362 ver = module_run(tbox_file_buffer, 0, 1,0, UNLOAD_ALWAYS ); 363 364 // if mistake on load 365 if ( ver<=0 ) 366 return 0; 367 368 charmap_buffer=tbox_file_buffer+i+1; 369 charmap_buffer_size= tbox_file_buffer_size - (i+1); 370 371 return ver; 372 } 373 374 // Check version and existance and tbox api version 375 // return: 0 if no module exists at all, otherwise version of API of current tbox module 376 //----------------------------------------------------- 377 int module_tbox_get_version() 378 { 379 static int last_loaded_tbox_hash = 0; 380 static int cur_tbox_api_version = 0; 381 382 // -- If keymap is loaded and not changed - return stored value 383 384 if ( lang_strhash31((int)conf.charmap_file) == last_loaded_tbox_hash ) 385 return cur_tbox_api_version; 386 387 // -- Free resources 388 389 last_loaded_tbox_hash = 0; 390 if ( tbox_file_buffer && tbox_file_buffer!=tbox_file_buffer_default ) 391 ufree( tbox_file_buffer ); 392 393 // -- Try to load keymap file 394 395 tbox_file_buffer = load_file( conf.charmap_file, &tbox_file_buffer_size ); 396 397 // Check is module available, otherwise try default one 398 399 cur_tbox_api_version = module_tbox_charmap_preprocess(); 400 401 402 // if keymap wrong/module can't be loaded - try default 403 if ( cur_tbox_api_version==0 ) { 404 if ( tbox_file_buffer ) 405 ufree(tbox_file_buffer); 406 407 tbox_file_buffer = tbox_file_buffer_default; 408 tbox_file_buffer_size = strlen(tbox_file_buffer); 409 cur_tbox_api_version = module_tbox_charmap_preprocess(); 410 } 411 412 if ( cur_tbox_api_version ) 413 last_loaded_tbox_hash = lang_strhash31((int)conf.charmap_file); 414 415 return cur_tbox_api_version; 416 } 417 418 419 //----------------------------------------------------- 420 void module_tbox_run( int title, int msg, char* defaultvalue, unsigned int maxsize, void (*on_select)(char* newstr)) 421 { 422 int ver = module_tbox_get_version(); 423 424 if ( API_VERSION_MATCH_REQUIREMENT( ver, 1, 0 ) ) { 425 426 // Main "run scenario" - 7 argument, raise textbox 427 unsigned int argv[] = { (int)charmap_buffer, 428 charmap_buffer_size, 429 title, 430 msg, 431 (unsigned int)defaultvalue, 432 maxsize, 433 (unsigned int)on_select, 434 }; 435 module_run(tbox_file_buffer, 0, sizeof(argv)/sizeof(argv[0]), argv, UNLOAD_IF_ERR); 436 437 } 438 } 330 #define MODULE_NAME_TBOX "_tbox.flt" 331 332 struct libtextbox_sym* libtextbox; 333 334 static int bind_module_tbox( void** export_list ) 335 { 336 return bind_module_generic(export_list, (void**)&libtextbox, 1, 1, 0); 337 } 338 339 // Return: 0-fail, addr-ok 340 struct libtextbox_sym* module_tbox_load() 341 { 342 return module_load_generic((void**)&libtextbox, MODULE_NAME_TBOX, bind_module_tbox, 0); 343 } -
branches/tbox_test/core/modules.h
r1569 r1587 44 44 // MODULE "TBOX" 45 45 //-------------------------- 46 int module_tbox_get_version(); 47 void module_tbox_run( int title, int msg, char* defaultvalue, unsigned int maxsize, void (*on_select)(char* newstr)); 46 #include "gui_tbox.h" 48 47 49 48 #endif -
branches/tbox_test/core/script.c
r1569 r1587 580 580 action_pop(); 581 581 break; 582 case AS_TEXTBOX: 582 583 case AS_FILE_BROWSER: 583 584 // state_kbd_script_run is set to 0 when the file browser is started from a Lua script -
branches/tbox_test/include/conf.h
r1569 r1587 318 318 int remote_control_mode ; 319 319 320 // Text Box char map file321 char charmap_file[100];322 323 320 } Conf; 324 321
Note: See TracChangeset
for help on using the changeset viewer.