Changeset 1614


Ignore:
Timestamp:
01/26/12 07:50:34 (16 months ago)
Author:
philmoz
Message:

Update to text box test version.

Location:
branches/tbox_test/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/tbox_test/core/gui_fselect.c

    r1587 r1614  
    11321132            case MPOPUP_MKDIR: 
    11331133            if (module_tbox_load()) 
    1134                 module_tbox_load()->textbox_init(LANG_POPUP_MKDIR, LANG_PROMPT_MKDIR, "", 15, mkdir_cb); 
     1134                module_tbox_load()->textbox_init(LANG_POPUP_MKDIR, LANG_PROMPT_MKDIR, "", 15, mkdir_cb, 0); 
    11351135            break; 
    11361136        case MPOPUP_RMDIR: 
     
    11391139        case MPOPUP_RENAME: 
    11401140            if (module_tbox_load()) 
    1141                 module_tbox_load()->textbox_init(LANG_POPUP_RENAME, LANG_PROMPT_RENAME, selected->name, 15, rename_cb); 
     1141                module_tbox_load()->textbox_init(LANG_POPUP_RENAME, LANG_PROMPT_RENAME, selected->name, 15, rename_cb, 0); 
    11421142            break; 
    11431143        } 
  • branches/tbox_test/core/gui_tbox.c

    r1609 r1614  
    9797cmap *charmaps[] = { &tbox_chars_default, &tbox_chars_russian }; 
    9898 
    99 int lines = 0;              // num of valid lines in active charmap 
     99int lines = 0;                  // num of valid lines in active charmap 
    100100 
    101101int tbox_button_active, line; 
    102 int curchar;     // idx of current entered char in current tmap 
     102int curchar;                    // idx of current entered char in current tmap 
    103103int curgroup; 
    104104int cursor; 
    105 char lastKey;    // Last pressed key (Left, Right, Up, Down) 
    106 char Mode;       // K=keyboard, T=textnavigate, B=button 
    107  
    108 char *text = 0;  // Entered text 
     105char lastKey;                   // Last pressed key (Left, Right, Up, Down) 
     106char Mode;                      // K=keyboard, T=textnavigate, B=button 
     107 
     108char text_buf[MAX_TEXT_SIZE+1]; // Default buffer if not supplied by caller 
     109char *text = 0;                 // Entered text 
    109110int maxlen, offset; 
    110111coord text_offset_x, text_offset_y, key_offset_x; 
     
    134135 
    135136//------------------------------------------------------- 
    136 int textbox_init(int title, int msg, const char* defaultstr, unsigned int maxsize, void (*on_select)(const char* newstr)) { 
    137  
    138     text = malloc(sizeof(char)*(maxsize+1)); 
    139     if ( text==0 ) { 
    140         // fatal failure 
    141         if (on_select) 
    142             on_select(0);    // notify callback about exit as cancel 
    143         module_async_unload(module_idx); 
    144         return 0; 
     137int textbox_init(int title, int msg, const char* defaultstr, unsigned int maxsize, void (*on_select)(const char* newstr), char *input_buffer) 
     138{ 
     139    if (input_buffer) 
     140        text = input_buffer; 
     141    else 
     142    { 
     143        if (maxsize > MAX_TEXT_SIZE) maxsize = MAX_TEXT_SIZE; 
     144        text = text_buf; 
    145145    } 
    146146 
     
    538538                        tbox_on_select(0); // cancel 
    539539                    } 
    540                     free(text); 
    541540                    text=0; 
    542541                } 
     
    555554 
    556555static const char* gui_text_box_charmap[] = { "Default", "Russian" }; 
    557 static CMenuItem zebra_submenu_items[] = { 
     556static CMenuItem textbox_submenu_items[] = { 
    558557    MENU_ENUM2(0x5f,LANG_MENU_VIS_CHARMAP,              &tconf.char_map, gui_text_box_charmap ), 
    559558    MENU_ITEM(0x51,LANG_MENU_BACK,                      MENUITEM_UP, 0, 0 ), 
    560559    {0} 
    561560}; 
    562 static CMenu textbox_submenu = {0x26,LANG_STR_TEXTBOX_SETTINGS, NULL, zebra_submenu_items }; 
     561static CMenu textbox_submenu = {0x26,LANG_STR_TEXTBOX_SETTINGS, NULL, textbox_submenu_items }; 
    563562 
    564563 
     
    610609 
    611610    // clean allocated resource 
    612     if ( text!=0 ) 
    613     { 
    614         free(text); 
    615         if (tbox_on_select) 
    616             tbox_on_select(0);    // notify callback about exit as cancel 
    617         text = 0; 
    618     } 
     611    if (tbox_on_select) 
     612        tbox_on_select(0);    // notify callback about exit as cancel 
    619613 
    620614    //sanity clean to prevent accidentaly assign/restore guimode to unloaded module 
  • branches/tbox_test/core/gui_tbox.h

    r1608 r1614  
    22#define TEXTBOX_H 
    33 
     4#define MAX_TEXT_SIZE   100 
     5 
     6// Note: if using the text box module pass in a function to the 'on_select' parameter 
     7// the text box will call this function with the user entered text in 'newstr' 
     8 
     9// If supplied the 'input_buffer' array will be used to store the user input text, 
     10// this will also be the address passed to 'on_select' in 'newstr' - in this case 
     11// the calling function owns the data buffer. Ensure that the size of 'input_buffer' 
     12// is at least 'maxsize + 1'. 
     13 
     14// If 'input_buffer' is null then a local buffer in the module will be used to 
     15// store the text, the maximum size of this buffer is MAX_TEXT_SIZE. 
     16// In this case the module owns the buffer and the contents must be copied to local 
     17// storage in the 'on_select' code. 
     18 
    419struct libtextbox_sym { 
    520        int version; 
    6     int (*textbox_init)(int title, int msg, const char* defaultstr, unsigned int maxsize, void (*on_select)(const char* newstr)); 
     21    int (*textbox_init)(int title, int msg, const char* defaultstr, unsigned int maxsize, void (*on_select)(const char* newstr), char *input_buffer); 
    722}; 
    823 
  • branches/tbox_test/core/luascript.c

    r1608 r1614  
    853853                                         luaL_optstring( L, 3, ""  ),               //default string 
    854854                                         luaL_optnumber( L, 4, 30),                 //max size of a text 
    855                                          return_string_selected);    } 
     855                                         return_string_selected, 0); 
     856    } 
    856857    else 
    857858        return_string_selected(0); 
Note: See TracChangeset for help on using the changeset viewer.