Index: apps/action.h
===================================================================
--- apps/action.h	(revision 27411)
+++ apps/action.h	(working copy)
@@ -239,6 +239,8 @@
     ACTION_KBD_DOWN,
     ACTION_KBD_MORSE_INPUT,
     ACTION_KBD_MORSE_SELECT,
+    ACTION_KBD_SCROLL_FWD,
+    ACTION_KBD_SCROLL_BACK,
     
 #ifdef HAVE_TOUCHSCREEN
     /* the following are helper actions for touchscreen targets,
Index: apps/recorder/keyboard.c
===================================================================
--- apps/recorder/keyboard.c	(revision 27411)
+++ apps/recorder/keyboard.c	(working copy)
@@ -53,6 +53,14 @@
         ((s) == SCREEN_MAIN && MIN_GRID_SIZE > (x) ? MIN_GRID_SIZE: (x))
 #endif
 
+#ifndef BUTTONBAR_HEIGHT
+#define BUTTONBAR_HEIGHT 0
+#endif
+#define KBD_SHOW_MODE
+#define PRED_TEXT
+#define MAX_DICT 10000 
+#define MAX_DICT_WORD 50
+
 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) \
     || (CONFIG_KEYPAD == IRIVER_H300_PAD) \
     || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
@@ -63,17 +71,14 @@
     || (CONFIG_KEYPAD == GIGABEAT_S_PAD) \
     || (CONFIG_KEYPAD == MROBE100_PAD) \
     || (CONFIG_KEYPAD == SANSA_E200_PAD) \
+    || (CONFIG_KEYPAD == SANSA_FUZE_PAD) \
     || (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) \
     || (CONFIG_KEYPAD == PHILIPS_SA9200_PAD) \
     || (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
-/* certain key combos toggle input mode between keyboard input and Morse input */
+/* certain key combos change keyboard entry modes */
 #define KBD_TOGGLE_INPUT
 #endif
 
-#define CHANGED_PICKER 1
-#define CHANGED_CURSOR 2
-#define CHANGED_TEXT   3
-
 struct keyboard_parameters
 {
     unsigned short kbd_buf[KBD_BUF_SIZE];
@@ -102,9 +107,37 @@
     bool line_edit;
 #ifdef HAVE_TOUCHSCREEN
     bool show_buttons;
+    int  button_h;
 #endif
 };
 
+enum { KBD_MODE_STANDARD=0,
+#ifdef HAVE_SCROLLWHEEL
+       KBD_MODE_SIDEWAYS,       
+       KBD_MODE_KEEP_ROLLIN,
+       KBD_MODE_SCROLL_1D,
+       KBD_MODE_ROWCOL,
+#endif
+#ifdef HAVE_MORSE_INPUT
+       KBD_MODE_MORSE,
+#endif
+       KBD_MODE_END 
+};
+
+char  *mode_labels[] = 
+{   ID2P(LANG_KBD_MODE_STANDARD), 
+#ifdef HAVE_SCROLLWHEEL
+    ID2P(LANG_KBD_MODE_SIDEWAYS), 
+    ID2P(LANG_KBD_MODE_KEEP_ROLLIN), 
+    ID2P(LANG_KBD_MODE_SCROLL_1D), 
+    ID2P(LANG_KBD_MODE_ROW_COL),
+#endif
+#ifdef HAVE_MORSE_INPUT
+    ID2P(LANG_KBD_MODE_MORSE),
+#endif
+    "Bad Mode!" 
+};
+
 struct edit_state
 {
     char* text;
@@ -115,12 +148,21 @@
     bool hangul;
     unsigned short hlead, hvowel, htail;
 #ifdef HAVE_MORSE_INPUT
-    bool morse_mode;
     bool morse_reading;
     unsigned char morse_code;
     int morse_tick;
 #endif
-    int changed;
+#if defined (HAVE_MORSE_INPUT) || defined (HAVE_SCROLLWHEEL)
+    int keyboard_mode;
+#endif
+#ifdef HAVE_SCROLLWHEEL
+    int prev_button;
+    bool row;
+#endif
+#ifdef PRED_TEXT
+    char pred_word[MAX_DICT_WORD+1];
+    int pred_input_len;
+#endif
 };
 
 static struct keyboard_parameters kbd_param[NB_SCREENS];
@@ -137,6 +179,65 @@
     0x73,0x55,0x4c,0x61,0x5a,0x80 };
 #endif
 
+static void kbd_calc_params(struct keyboard_parameters *pm,
+                            struct screen *sc, struct edit_state *state);
+static void kbd_draw_picker(struct keyboard_parameters *pm,
+                            struct screen *sc, struct edit_state *state);
+static void kbd_draw_edit_line(struct keyboard_parameters *pm,
+                               struct screen *sc, struct edit_state *state);
+static void kbd_inschar(struct edit_state *state, unsigned short ch);
+#ifdef HAVE_TOUCHSCREEN
+static void kbd_draw_buttons(struct keyboard_parameters *pm, struct screen *sc);
+static int keyboard_touchscreen(struct keyboard_parameters *pm,
+                                struct screen *sc, struct edit_state *state);
+#endif
+static void kbd_delchar(struct edit_state *state);
+
+#ifdef HAVE_MORSE_INPUT
+static void kbd_morse_select(struct edit_state *state);
+#endif /* HAVE_MORSE_INPUT */
+#ifdef HAVE_SCROLLWHEEL     
+static void kbd_scroll_fwd( struct edit_state *state, 
+                            struct keyboard_parameters *pm);
+static void kbd_scroll_back(struct edit_state *state, 
+                            struct keyboard_parameters *pm);
+#endif
+#ifdef PRED_TEXT
+static void kbd_learn_text(char *input);
+
+static void kbd_load_predicted(void);
+
+static void kbd_save_predicted(void);
+
+static void kbd_draw_predicted(struct keyboard_parameters *pm,
+                               struct screen *sc, struct edit_state *state);
+static void kbd_insert_predicted(struct edit_state *state);
+#endif
+static void kbd_picker_right( struct edit_state *state, 
+                              struct keyboard_parameters *pm );
+
+static void kbd_right( struct edit_state *state, 
+                       struct keyboard_parameters *pm );
+static void kbd_picker_left( struct edit_state *state, 
+                             struct keyboard_parameters *pm );
+static void kbd_left( struct edit_state *state, 
+                      struct keyboard_parameters *pm );
+static void kbd_down(struct edit_state *state, 
+                     struct keyboard_parameters *pm);
+static void kbd_up (struct edit_state *state, 
+                    struct keyboard_parameters *pm);
+static void kbd_cursor_right(struct edit_state *state);
+
+static void kbd_cursor_left(struct edit_state *state);
+
+static void kbd_backspace(struct edit_state *state);
+
+static void kbd_insert_current_char(struct edit_state *state, 
+                                 struct keyboard_parameters *pm);
+static void kbd_select(struct edit_state *state, 
+                       struct keyboard_parameters *pm);
+static void kbd_none(struct edit_state *state);
+
 /* Loads a custom keyboard into memory
    call with NULL to reset keyboard    */
 int load_kbd(unsigned char* filename)
@@ -259,7 +360,6 @@
         memmove(utf8 + j, utf8, len - i + 1);
         memcpy(utf8, tmp, j);
         state->editpos++;
-        state->changed = CHANGED_TEXT;
     }
 }
 
@@ -276,7 +376,6 @@
         utf8 = state->text + i;
         j = utf8seek(utf8, 1);
         memmove(utf8, utf8 + j, len - i - j + 1);
-        state->changed = CHANGED_TEXT;
     }
 }
 
@@ -305,26 +404,562 @@
     return (*pbuf != 0xFEFF && k < *pbuf)? pbuf[k+1]: ' ';
 }
 
-static void kbd_calc_params(struct keyboard_parameters *pm,
-                            struct screen *sc, struct edit_state *state);
-static void kbd_draw_picker(struct keyboard_parameters *pm,
-                            struct screen *sc, struct edit_state *state);
-static void kbd_draw_edit_line(struct keyboard_parameters *pm,
-                               struct screen *sc, struct edit_state *state);
-#ifdef HAVE_TOUCHSCREEN
-static void kbd_draw_buttons(struct keyboard_parameters *pm, struct screen *sc);
-static int keyboard_touchscreen(struct keyboard_parameters *pm,
-                                struct screen *sc, struct edit_state *state);
+#ifdef KBD_TOGGLE_INPUT
+static void kbd_switch_mode ( struct edit_state *state ) 
+{
+    int l;
+    FOR_NB_SCREENS(l)
+    {
+        kbd_param[l].line_edit = false;
+        kbd_param[l].x = 0;
+        kbd_param[l].y = 0;
+        kbd_param[l].page = 0;
+    }
+    state->keyboard_mode++;
+    if ( state->keyboard_mode == KBD_MODE_END )
+        state->keyboard_mode = KBD_MODE_STANDARD;
+    splash(HZ,mode_labels[state->keyboard_mode-KBD_MODE_STANDARD] );
+}
 #endif
-static void kbd_insert_selected(struct keyboard_parameters *pm,
-                                struct edit_state *state);
-static void kbd_backspace(struct edit_state *state);
-static void kbd_move_cursor(struct edit_state *state, int dir);
-static void kbd_move_picker_horizontal(struct keyboard_parameters *pm,
-                                       struct edit_state *state, int dir);
-static void kbd_move_picker_vertical(struct keyboard_parameters *pm,
-                                     struct edit_state *state, int dir);
 
+static void kbd_page_flip ( struct edit_state *state, 
+                            struct keyboard_parameters *pm ) 
+{
+    (void) state;
+#ifdef HAVE_MORSE_INPUT
+    if (state->keyboard_mode == KBD_MODE_MORSE)
+        return;
+#endif
+    if (++pm->page >= pm->pages)
+        pm->page = 0;
+
+    kbd_spellchar( get_kbd_ch(pm, pm->x, pm->y) );
+}
+
+#ifdef HAVE_SCROLLWHEEL     
+static void kbd_scroll_fwd( struct edit_state *state, 
+                            struct keyboard_parameters *pm ) 
+{
+    switch ( state->keyboard_mode ) 
+    {
+        case KBD_MODE_ROWCOL:
+            if ( state->row )
+                kbd_down( state, pm );
+            else
+                kbd_picker_right( state, pm );
+            break;
+
+        case KBD_MODE_KEEP_ROLLIN:
+            if ( state->prev_button == ACTION_KBD_SCROLL_FWD )
+                kbd_picker_right( state, pm );
+            break;
+
+        case KBD_MODE_MORSE:
+            kbd_cursor_right( state );
+            break;
+
+        case KBD_MODE_SCROLL_1D:
+            kbd_picker_right( state, pm );
+            break;
+
+        case KBD_MODE_SIDEWAYS:
+            if ( pm->line_edit )
+                kbd_cursor_right( state );
+            else
+                kbd_picker_right( state, pm );
+            break;
+            
+        case KBD_MODE_STANDARD:
+        default:
+            kbd_down( state, pm );
+            break;
+    }
+    state->prev_button = ACTION_KBD_SCROLL_FWD;
+}
+
+static void kbd_scroll_back( struct edit_state *state, 
+                             struct keyboard_parameters *pm ) 
+{
+    switch ( state->keyboard_mode ) 
+    {
+        case KBD_MODE_ROWCOL:
+        if ( state->row )
+            kbd_up( state, pm );
+        else
+            kbd_picker_left( state, pm );
+            break;
+        case KBD_MODE_KEEP_ROLLIN:
+            if ( state->prev_button == ACTION_KBD_SCROLL_FWD ) 
+            {
+                kbd_insert_current_char( state, pm );
+                pm->x = pm->y = 0;
+            }
+            else 
+                kbd_down( state, pm );
+            break;
+            
+        case KBD_MODE_SCROLL_1D:
+            kbd_picker_left( state, pm );
+            break;
+
+        case KBD_MODE_MORSE:
+            kbd_cursor_left( state );
+            break;
+            
+        case KBD_MODE_SIDEWAYS:
+
+            if ( pm->line_edit )
+                kbd_cursor_left( state );
+            else
+                kbd_picker_left( state, pm );
+            break;
+
+        case KBD_MODE_STANDARD:
+        default:
+            kbd_up( state, pm );
+    }
+    state->prev_button = ACTION_KBD_SCROLL_BACK;
+}
+#endif
+
+static void kbd_picker_right( struct edit_state *state, 
+                              struct keyboard_parameters *pm ) 
+{
+    (void) state;
+    if (++pm->x >= pm->max_chars) 
+    {
+#ifdef HAVE_SCROLLWHEEL
+        switch ( state->keyboard_mode ) 
+        {
+            case KBD_MODE_ROWCOL:
+                pm->x = pm->max_chars-1;
+                state->row = true;
+                return;
+            case KBD_MODE_SCROLL_1D:
+                kbd_down( state, pm );
+            case KBD_MODE_KEEP_ROLLIN:
+                pm->x = 0;
+                return;
+    /* FIXME: */
+    #ifdef HAVE_KBD_MODES
+            case KBD_MODE_SIDEWAYS:
+    #endif
+            default:
+                break;
+        }
+#endif    
+        if (++pm->page >= pm->pages)
+            pm->page = 0;
+        pm->x = 0;
+    }
+    kbd_spellchar( get_kbd_ch(pm, pm->x, pm->y) );
+}
+
+static void kbd_right( struct edit_state *state, 
+                       struct keyboard_parameters *pm ) 
+{
+#ifdef HAVE_SCROLLWHEEL
+    switch ( state->keyboard_mode ) 
+    {
+        case KBD_MODE_STANDARD:
+            if ( pm->line_edit )
+                kbd_cursor_right( state );
+            else
+                kbd_picker_right( state, pm );
+            return;
+        
+        case KBD_MODE_SIDEWAYS:
+            kbd_down( state, pm );
+            return;
+        
+        case KBD_MODE_KEEP_ROLLIN:
+        case KBD_MODE_SCROLL_1D:
+        case KBD_MODE_ROWCOL:
+        case KBD_MODE_MORSE:
+            kbd_cursor_right( state );
+            return;
+        default:
+            break;
+    }
+#else /* (not) HAVE_SCROLLWHEEL */
+    if ( pm->line_edit )
+        kbd_cursor_right( state );
+    else
+        kbd_picker_right( state, pm );
+#endif /* HAVE_SCROLLWHEEL */
+}
+
+static void kbd_picker_left( struct edit_state *state, 
+                             struct keyboard_parameters *pm ) 
+{
+    (void) state;
+    if (--pm->x < 0) 
+    {
+#ifdef HAVE_SCROLLWHEEL
+        switch ( state->keyboard_mode ) 
+        {
+            case KBD_MODE_ROWCOL:
+                pm->x = 0;
+                state->row = true;
+                return;
+            case KBD_MODE_SCROLL_1D:
+                kbd_up( state, pm );
+            case KBD_MODE_KEEP_ROLLIN:
+                pm->x = pm->max_chars - 1;
+                return;
+            default:
+                break;
+        }
+#endif    
+
+        if (--pm->page < 0)
+            pm->page = pm->pages - 1;
+        pm->x = pm->max_chars - 1;
+    }
+    kbd_spellchar( get_kbd_ch(pm, pm->x, pm->y) );
+}
+
+static void kbd_left( struct edit_state *state, 
+                      struct keyboard_parameters *pm ) 
+{
+#ifdef HAVE_SCROLLWHEEL
+    switch ( state->keyboard_mode ) 
+    {
+        case KBD_MODE_STANDARD:
+            if ( pm->line_edit )
+                kbd_cursor_left( state );
+            else
+                kbd_picker_left( state, pm );
+            return;
+        
+        case KBD_MODE_SIDEWAYS:
+            kbd_up( state, pm );
+            return; 
+        case KBD_MODE_KEEP_ROLLIN:
+        case KBD_MODE_SCROLL_1D:
+        case KBD_MODE_ROWCOL:
+        case KBD_MODE_MORSE:
+            kbd_cursor_left( state );
+            return;
+        default:
+            return;
+    }
+#else /* (not) HAVE_SCROLLWHEEL */
+    if ( pm->line_edit )
+        kbd_cursor_left( state );
+    else
+        kbd_picker_left( state, pm );    
+#endif /* HAVE_SCROLLWHEEL */
+
+}
+               
+static void kbd_down( struct edit_state *state, 
+                      struct keyboard_parameters *pm ) 
+{
+#ifdef HAVE_SCROLLWHEEL
+    if ( state->keyboard_mode == KBD_MODE_KEEP_ROLLIN ||
+         state->keyboard_mode == KBD_MODE_SCROLL_1D ||
+         state->keyboard_mode == KBD_MODE_ROWCOL ) 
+    {
+        if (++pm->y >= pm->lines) 
+        {
+           if (++pm->page >= pm->pages)
+                pm->page = 0;
+           pm->y = 0;
+        }
+        return;
+    }
+#endif
+#ifdef HAVE_MORSE_INPUT
+    if (state->keyboard_mode == KBD_MODE_MORSE) 
+    {
+        pm->line_edit = !pm->line_edit;
+        return;
+    }
+#endif /* HAVE_MORSE_INPUT */
+
+    if (pm->line_edit)
+    {
+        pm->y = 0;
+        pm->line_edit = false;
+    }
+    else if (++pm->y >= pm->lines)
+    {
+        pm->line_edit = true;
+    }
+    if (!pm->line_edit)
+    {
+        kbd_spellchar( get_kbd_ch(pm, pm->x, pm->y) );
+    }
+    return;
+}
+
+static void kbd_up ( struct edit_state *state, 
+                     struct keyboard_parameters *pm ) 
+{
+#ifdef HAVE_SCROLLWHEEL
+    if ( state->keyboard_mode == KBD_MODE_KEEP_ROLLIN ||
+         state->keyboard_mode == KBD_MODE_SCROLL_1D ||
+         state->keyboard_mode == KBD_MODE_ROWCOL ) 
+    {
+        if (--pm->y < 0) 
+        {
+            pm->y = pm->lines - 1;
+            if (--pm->page < 0)
+                pm->page = pm->pages - 1;
+        }
+        return;
+    }
+#endif
+#ifdef HAVE_MORSE_INPUT
+    if (state->keyboard_mode == KBD_MODE_MORSE)
+    {
+        pm->line_edit = !pm->line_edit;
+        return;
+    }
+#endif /* HAVE_MORSE_INPUT */
+    if (pm->line_edit)
+    {
+        pm->y = pm->lines - 1;
+        pm->line_edit = false;
+    }
+    else if (--pm->y < 0)
+    {
+        pm->line_edit = true;
+    }
+    if (!pm->line_edit)    
+        kbd_spellchar( get_kbd_ch(pm, pm->x, pm->y) );
+}
+
+static void kbd_cursor_right( struct edit_state *state ) 
+{
+    state->hangul = false;
+
+    if (state->editpos < state->len_utf8)
+    {
+        int c = utf8seek(state->text, ++state->editpos);
+        kbd_spellchar(state->text[c]);
+        return;
+    }
+#ifdef PRED_TEXT
+    if( state->pred_word[0] ) 
+    {
+        kbd_insert_predicted( state );
+        return;
+    }
+#endif
+#if CONFIG_CODEC == SWCODEC
+    if (global_settings.talk_menu)
+        pcmbuf_beep(1000, 150, 1500);
+#endif
+}
+
+static void kbd_cursor_left( struct edit_state *state ) 
+{
+    state->hangul = false;
+
+    if (state->editpos > 0)
+    {
+        int c = utf8seek(state->text, --state->editpos);
+        kbd_spellchar(state->text[c]);
+    }
+#if CONFIG_CODEC == SWCODEC
+    else if (global_settings.talk_menu)
+        pcmbuf_beep(1000, 150, 1500);
+#endif
+}
+
+static void kbd_backspace( struct edit_state *state ) 
+{
+    unsigned short ch;
+    
+    if (state->hangul)
+    {
+        if (state->htail)
+            state->htail = 0;
+        else if (state->hvowel)
+            state->hvowel = 0;
+        else
+            state->hangul = false;
+    }
+
+    kbd_delchar(state);
+
+    if (state->hangul)
+    {
+        if (state->hvowel)
+            ch = hangul_join(state->hlead, state->hvowel, state->htail);
+        else
+            ch = state->hlead;
+        kbd_inschar(state, ch);
+    }
+
+    if (global_settings.talk_menu)      /* voice UI? */
+        talk_spell(state->text, false);  /* speak revised text */
+}
+
+static void kbd_insert_current_char( struct edit_state *state, 
+                                     struct keyboard_parameters *pm ) 
+{
+
+    /* inserts the selected char */
+    /* find input char */
+    unsigned short ch;
+    ch = get_kbd_ch(pm, pm->x, pm->y);
+
+    /* check for hangul input */
+    if (ch >= 0x3131 && ch <= 0x3163)
+    {
+        unsigned short tmp;
+
+        if (!state->hangul)
+        {
+            state->hlead = state->hvowel = state->htail = 0;
+            state->hangul = true;
+        }
+
+        if (!state->hvowel)
+        {
+            state->hvowel = ch;
+        }
+        else if (!state->htail)
+        {
+            state->htail = ch;
+        }
+        else
+        {
+            /* previous hangul complete */
+            /* check whether tail is actually lead of next char */
+            tmp = hangul_join(state->htail, ch, 0);
+
+            if (tmp != 0xfffd)
+            {
+                tmp = hangul_join(state->hlead, state->hvowel, 0);
+                kbd_delchar(state);
+                kbd_inschar(state, tmp);
+                /* insert dummy char */
+                kbd_inschar(state, ' ');
+                state->hlead = state->htail;
+                state->hvowel = ch;
+                state->htail = 0;
+            }
+            else
+            {
+                state->hvowel = state->htail = 0;
+                state->hlead = ch;
+            }
+        }
+
+        /* combine into hangul */
+        tmp = hangul_join(state->hlead, state->hvowel, state->htail);
+
+        if (tmp != 0xfffd)
+        {
+            kbd_delchar(state);
+            ch = tmp;
+        }
+        else
+        {
+            state->hvowel = state->htail = 0;
+            state->hlead = ch;
+        }
+    }
+    else
+    {
+        state->hangul = false;
+    }
+
+    /* insert char */
+    kbd_inschar(state, ch);
+
+    if (global_settings.talk_menu)      /* voice UI? */
+        talk_spell(state->text, false);  /* speak revised text */
+}
+
+static void kbd_select( struct edit_state *state, 
+                        struct keyboard_parameters *pm ) 
+{
+#ifdef HAVE_SCROLLWHEEL
+    if ( state->keyboard_mode == KBD_MODE_ROWCOL ) 
+    {
+        if ( state->row ) 
+        {
+            state->row = false;
+            return;
+        }
+        else 
+        {
+            kbd_insert_current_char( state, pm );
+            return;
+        }
+    }
+#endif /* HAVE_SCROLLWHEEL */
+    if ( pm->line_edit ) 
+    {
+        kbd_backspace( state );
+        return;
+    }
+#ifdef HAVE_MORSE_INPUT
+    if (state->keyboard_mode == KBD_MODE_MORSE)
+    {
+        state->morse_tick = current_tick;
+
+        if (!state->morse_reading)
+        {
+            logf("Morse char start:\n");
+            state->morse_reading = true;
+            state->morse_code = 1;
+        }
+    }
+    else
+#endif /* HAVE_MORSE_INPUT */
+        kbd_insert_current_char( state, pm );
+}
+
+#ifdef HAVE_MORSE_INPUT
+static void kbd_morse_select( struct edit_state *state )
+{         
+    if (state->keyboard_mode == KBD_MODE_MORSE && state->morse_reading)
+    {
+        state->morse_code <<= 1;
+        if ((current_tick - state->morse_tick) > HZ/5)
+            state->morse_code |= 0x01;
+    }
+}
+#endif /* HAVE_MORSE_INPUT */
+
+static void kbd_none( struct edit_state *state )
+{
+    (void) state;
+#ifdef HAVE_MORSE_INPUT
+    if (state->morse_reading)
+    {
+        int j;
+        logf("Morse: 0x%02x", state->morse_code);
+        state->morse_reading = false;
+
+        for (j = 0; morse_alphabets[j] != '\0'; j++)
+        {
+            if (morse_codes[j] == state->morse_code)
+                break;
+        }
+
+        if (morse_alphabets[j] == '\0')
+        {
+            logf("Morse code not found");
+            return;
+        }
+
+        /* turn off hangul input */
+        state->hangul = false;
+        kbd_inschar(state, morse_alphabets[j]);
+
+        if (global_settings.talk_menu)      /* voice UI? */
+            talk_spell(state->text, false);  /* speak revised text */
+    }
+#endif /* HAVE_MORSE_INPUT */
+}
+
 int kbd_input(char* text, int buflen)
 {
     bool done = false;
@@ -336,7 +971,6 @@
 #endif
     struct edit_state state;
     int l; /* screen loop variable */
-    unsigned short ch;
     int ret = 0; /* assume success */
     FOR_NB_SCREENS(l)
     {
@@ -355,15 +989,24 @@
     /* initialize state */
     state.text = text;
     state.buflen = buflen;
+#ifdef HAVE_SCROLLWHEEL
+    state.prev_button = BUTTON_NONE;
+    state.row = true;
+#endif
+#ifdef PRED_TEXT
+    kbd_load_predicted();
+    state.pred_word[0] = 0;
+#endif
     /* Initial edit position is after last character */
     state.editpos = utf8length(state.text);
     state.cur_blink = true;
+#if defined (HAVE_MORSE_INPUT) || defined (HAVE_SCROLLWHEEL)
+    state.keyboard_mode = global_settings.keyboard_mode;
+#endif
 #ifdef HAVE_MORSE_INPUT
-    state.morse_mode = global_settings.morse_input;
     state.morse_reading = false;
 #endif
     state.hangul = false;
-    state.changed = 0;
 
     if (!kbd_loaded)
     {
@@ -441,11 +1084,17 @@
         struct keyboard_parameters *pm = &param[l];
         struct screen *sc = &screens[l];
         kbd_calc_params(pm, sc, &state);
+#ifdef HAVE_SCROLLWHEEL
+        pm->x = pm->y = pm->page = 0;
+        pm->line_edit = false;
+#endif
     }
 
     if (global_settings.talk_menu)      /* voice UI? */
         talk_spell(state.text, true);   /* spell initial text */
 
+    /* don't splash if showing the mode anyway */
+    splash(HZ/2,mode_labels[state.keyboard_mode] );  
     while (!done)
     {
         /* These declarations are assigned to the screen on which the key
@@ -475,6 +1124,9 @@
             if (pm->show_buttons)
                 kbd_draw_buttons(pm, sc);
 #endif
+#ifdef PRED_TEXT
+            kbd_draw_predicted(pm, sc, &state);
+#endif
         }
 
 #ifdef HAVE_BUTTONBAR
@@ -488,11 +1140,13 @@
 
         state.cur_blink = !state.cur_blink;
 
-        button = get_action(
 #ifdef HAVE_MORSE_INPUT
-                state.morse_mode? CONTEXT_MORSE_INPUT:
+        button = get_action( state.keyboard_mode == KBD_MODE_MORSE ? 
+                         CONTEXT_MORSE_INPUT: CONTEXT_KEYBOARD, HZ/2 );
+#else
+        button = get_action( CONTEXT_KEYBOARD, HZ/2 );
 #endif
-                            CONTEXT_KEYBOARD, HZ/2);
+
 #if NB_SCREENS > 1
         button_screen = (get_action_statuscode(NULL) & ACTION_REMOTE) ? 1 : 0;
 #endif
@@ -502,25 +1156,14 @@
         if (button == ACTION_TOUCHSCREEN)
             button = keyboard_touchscreen(pm, sc, &state);
 #endif
-
-        /* Remap some buttons to allow to move
-         * cursor in line edit mode and morse mode. */
-        if (pm->line_edit
-#ifdef HAVE_MORSE_INPUT
-            || state.morse_mode
-#endif /* HAVE_MORSE_INPUT */
-            )
-        {
-            if (button == ACTION_KBD_LEFT)
-                button = ACTION_KBD_CURSOR_LEFT;
-            if (button == ACTION_KBD_RIGHT)
-                button = ACTION_KBD_CURSOR_RIGHT;
-        }
-
         switch ( button )
         {
             case ACTION_KBD_DONE:
                 /* accepts what was entered and continues */
+#ifdef PRED_TEXT
+                kbd_learn_text( state.text );
+                kbd_save_predicted();
+#endif
                 ret = 0;
                 done = true;
                 break;
@@ -529,79 +1172,48 @@
                 ret = -1;
                 done = true;
                 break;
-
+#ifdef HAVE_SCROLLWHEEL
+            case ACTION_KBD_SCROLL_FWD:
+                kbd_scroll_fwd(&state, pm);
+                break;
+        
+            case ACTION_KBD_SCROLL_BACK:
+                kbd_scroll_back(&state, pm);
+                break;
+#endif
             case ACTION_KBD_PAGE_FLIP:
-#ifdef HAVE_MORSE_INPUT
-                if (state.morse_mode)
-                    break;
-#endif
-                if (++pm->page >= pm->pages)
-                    pm->page = 0;
+                kbd_page_flip(&state, pm);
+                break;
 
-                state.changed = CHANGED_PICKER;
+#ifdef KBD_TOGGLE_INPUT
+            case ACTION_KBD_MORSE_INPUT:
+                kbd_switch_mode(&state);
                 break;
+#endif
+#ifdef HAVE_MORSE_INPUT
+            case ACTION_KBD_MORSE_SELECT:
+                kbd_morse_select(&state);
+                break;
+#endif /* HAVE_MORSE_INPUT */
 
             case ACTION_KBD_RIGHT:
-                kbd_move_picker_horizontal(pm, &state, 1);
+                kbd_right(&state, pm);
                 break;
 
             case ACTION_KBD_LEFT:
-                kbd_move_picker_horizontal(pm, &state, -1);
+                kbd_left(&state, pm);
                 break;
 
             case ACTION_KBD_DOWN:
-                kbd_move_picker_vertical(pm, &state, 1);
+                kbd_down(&state, pm);
                 break;
 
             case ACTION_KBD_UP:
-                kbd_move_picker_vertical(pm, &state, -1);
+                kbd_up(&state, pm);
                 break;
 
-#ifdef HAVE_MORSE_INPUT
-#ifdef KBD_TOGGLE_INPUT
-            case ACTION_KBD_MORSE_INPUT:
-                state.morse_mode = !state.morse_mode;
-                state.changed = CHANGED_PICKER;
-
-                FOR_NB_SCREENS(l)
-                {
-                    struct keyboard_parameters *pm = &param[l];
-                    int y = pm->main_y;
-                    pm->main_y = pm->old_main_y;
-                    pm->old_main_y = y;
-                }
-                break;
-#endif /* KBD_TOGGLE_INPUT */
-
-            case ACTION_KBD_MORSE_SELECT:
-                if (state.morse_mode && state.morse_reading)
-                {
-                    state.morse_code <<= 1;
-                    if ((current_tick - state.morse_tick) > HZ/5)
-                        state.morse_code |= 0x01;
-                }
-                break;
-#endif /* HAVE_MORSE_INPUT */
-
             case ACTION_KBD_SELECT:
-                /* select doubles as backspace in line_edit */
-                if (pm->line_edit)
-                    kbd_backspace(&state);
-                else
-#ifdef HAVE_MORSE_INPUT
-                if (state.morse_mode)
-                {
-                    state.morse_tick = current_tick;
-
-                    if (!state.morse_reading)
-                    {
-                        state.morse_reading = true;
-                        state.morse_code = 1;
-                    }
-                }
-                else
-#endif /* HAVE_MORSE_INPUT */
-                    kbd_insert_selected(pm, &state);
+                kbd_select(&state, pm);
                 break;
 
             case ACTION_KBD_BACKSPACE:
@@ -609,38 +1221,15 @@
                 break;
 
             case ACTION_KBD_CURSOR_RIGHT:
-                kbd_move_cursor(&state, 1);
+                kbd_cursor_right(&state);
                 break;
 
             case ACTION_KBD_CURSOR_LEFT:
-                kbd_move_cursor(&state, -1);
+                kbd_cursor_left(&state);
                 break;
 
             case ACTION_NONE:
-#ifdef HAVE_MORSE_INPUT
-                if (state.morse_reading)
-                {
-                    int j;
-                    logf("Morse: 0x%02x", state.morse_code);
-                    state.morse_reading = false;
-
-                    for (j = 0; morse_alphabets[j] != '\0'; j++)
-                    {
-                        if (morse_codes[j] == state.morse_code)
-                            break ;
-                    }
-
-                    if (morse_alphabets[j] == '\0')
-                    {
-                        logf("Morse code not found");
-                        break ;
-                    }
-
-                    /* turn off hangul input */
-                    state.hangul = false;
-                    kbd_inschar(&state, morse_alphabets[j]);
-                }
-#endif /* HAVE_MORSE_INPUT */
+                kbd_none(&state);
                 break;
 
             default:
@@ -652,38 +1241,10 @@
                 break;
 
         } /* end switch */
-
         if (button != ACTION_NONE)
         {
             state.cur_blink = true;
         }
-        if (global_settings.talk_menu)  /* voice UI? */
-        {
-            if (state.changed == CHANGED_PICKER)
-            {
-                if (pm->line_edit)
-                {
-                    talk_id(VOICE_EDIT, false);
-                }
-                else
-#ifdef HAVE_MORSE_INPUT
-                /* FIXME: We should talk something like Morse mode.. */
-                if (!state.morse_mode)
-#endif
-                {
-                    ch = get_kbd_ch(pm, pm->x, pm->y);
-                    kbd_spellchar(ch);
-                }
-            }
-            else if (state.changed == CHANGED_CURSOR)
-            {
-                int c = utf8seek(state.text, state.editpos);
-                kbd_spellchar(state.text[c]);
-            }
-            else if (state.changed == CHANGED_TEXT)
-                talk_spell(state.text, false);  /* speak revised text */
-        }
-        state.changed = 0;
     }
 
 #ifdef HAVE_BUTTONBAR
@@ -692,11 +1253,10 @@
 
     if (ret < 0)
         splash(HZ/2, ID2P(LANG_CANCEL));
-
-#if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT)
-    if (global_settings.morse_input != state.morse_mode)
+#if defined(HAVE_MORSE_INPUT) || defined(HAVE_SCROLLWHEEL)
+    if (global_settings.keyboard_mode != state.keyboard_mode)
     {
-        global_settings.morse_input = state.morse_mode;
+        global_settings.keyboard_mode = state.keyboard_mode;
         settings_save();
     }
 #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */
@@ -779,13 +1339,23 @@
 
     /* calculate pm->pages and pm->lines */
     sc_h = sc->getheight();
+#ifdef PRED_TEXT
+    if ( sc_h / pm->font_h > 5 )
+        /* reserve a line for predicted text */
+        sc_h -= pm->font_h;
+#endif
+#ifdef KBD_SHOW_MODE
+    if ( sc_h / pm->font_h > 6 )
+    sc_h -= pm->font_h;
+#endif
 #ifdef HAVE_TOUCHSCREEN
     /* add space for buttons */
     if (pm->show_buttons)
     {
         /* reserve place for OK/Del/Cancel buttons, use ui font for them */
         button_h = GRID_SIZE(sc->screen_type, sc->getcharheight());
-        sc_h -= MAX(MIN_GRID_SIZE*2, button_h);
+        pm->button_h = MAX(MIN_GRID_SIZE*2, button_h);
+        sc_h -= pm->button_h;
     }
 recalc_param:
 #endif
@@ -834,7 +1404,7 @@
 
 #ifdef HAVE_MORSE_INPUT
     pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT;
-    if (state->morse_mode)
+    if (state->keyboard_mode == KBD_MODE_MORSE)
     {
         int y = pm->main_y;
         pm->main_y = pm->old_main_y;
@@ -848,7 +1418,7 @@
 {
     char outline[8];
 #ifdef HAVE_MORSE_INPUT
-    if (state->morse_mode)
+    if (state->keyboard_mode == KBD_MODE_MORSE)
     {
         const int w = 6, h = 8; /* sysfixed font width, height */
         int i, j, x, y;
@@ -903,7 +1473,7 @@
         int w, h;
         unsigned short ch;
         unsigned char *utf8;
-
+        
         sc->setfont(pm->curfont);
 
         for (j = 0; j < pm->lines; j++)
@@ -924,6 +1494,20 @@
         {
             /* highlight the key that has focus */
             sc->set_drawmode(DRMODE_COMPLEMENT);
+#ifdef HAVE_SCROLLWHEEL
+            if ( (state->keyboard_mode == KBD_MODE_ROWCOL && state->row) ||
+                    (state->keyboard_mode == KBD_MODE_KEEP_ROLLIN && 
+                     state->prev_button != ACTION_KBD_SCROLL_FWD ))
+/* define this if you want selected row inversed instead of underlined */
+#ifdef KBD_INVERSE_ROW 
+                sc->fillrect(0,pm->font_h*pm->y,
+                    pm->font_w*pm->max_chars, pm->font_h);
+#else /* underline current row */
+                sc->hline(pm->font_w, pm->font_w*(pm->max_chars-1), 
+                    pm->font_h*(pm->y+1));
+#endif
+            else
+#endif /* HAVE_SCROLLWHEEL */
             sc->fillrect(pm->font_w*pm->x, pm->font_h*pm->y,
                          pm->font_w, pm->font_h);
             sc->set_drawmode(DRMODE_SOLID);
@@ -934,6 +1518,7 @@
 static void kbd_draw_edit_line(struct keyboard_parameters *pm,
                                struct screen *sc, struct edit_state *state)
 {
+    //char mode_label[20];
     char outline[8];
     unsigned char *utf8;
     int i = 0, j = 0, icon_w, w;
@@ -1007,16 +1592,30 @@
     if (state->hangul) /* draw underbar */
         sc->hline(i - pm->text_w, i, pm->main_y + pm->font_h - 1);
 
+#ifdef KBD_TOGGLE_INPUT
     if (pm->line_edit)
     {
         sc->set_drawmode(DRMODE_COMPLEMENT);
         sc->fillrect(0, y + 2, sc_w, pm->font_h + 2);
         sc->set_drawmode(DRMODE_SOLID);
     }
+#endif
+
+#ifdef KBD_SHOW_MODE
+#ifdef HAVE_TOUCHSCREEN
+    if ( pm-> show_buttons )
+        sc->putsxy(0, sc->getheight()-pm->font_h-pm->button_h,  
+            P2STR((unsigned char *)mode_labels[state->keyboard_mode]) );
+    else
+#endif
+    sc->putsxy(0, sc->getheight()-pm->font_h,  
+        P2STR((unsigned char *)mode_labels[state->keyboard_mode]) );
+#endif
 }
 
 #ifdef HAVE_TOUCHSCREEN
-static void kbd_draw_buttons(struct keyboard_parameters *pm, struct screen *sc)
+static void kbd_draw_buttons(struct keyboard_parameters *pm, 
+                             struct screen *sc)
 {
     struct viewport vp;
     int button_h, text_h, text_y;
@@ -1064,7 +1663,8 @@
     const int sc_w = sc->getwidth(), sc_h = sc->getheight();
     int button_h = MAX(MIN_GRID_SIZE*2, sc->getcharheight());
 #ifdef HAVE_MORSE_INPUT
-    if (state->morse_mode && y < pm->main_y - pm->keyboard_margin)
+    if (state->keyboard_mode == KBD_MODE_MORSE && 
+        y < pm->main_y - pm->keyboard_margin)
     {
         /* don't return ACTION_NONE since it has effect in morse mode. */
         return button == BUTTON_TOUCHSCREEN? ACTION_KBD_SELECT:
@@ -1080,7 +1680,7 @@
         if (x/pm->font_w < pm->max_chars)
         {
             /* picker area */
-            state->changed = CHANGED_PICKER;
+//            state->changed = CHANGED_PICKER;
             pm->x = x/pm->font_w;
             pm->y = y/pm->font_h;
             pm->line_edit = false;
@@ -1122,164 +1722,249 @@
 }
 #endif
 
-/* inserts the selected char */
-static void kbd_insert_selected(struct keyboard_parameters *pm,
-                                struct edit_state *state)
+
+#ifdef PRED_TEXT
+/* This is a very simple dictionary based text predictor.
+   The dictionary file is one word per line (\n terminated.)
+   at /.rockbox/pred_dict.txt.
+
+   The first word in the file that matches the letters input 
+   will be offered for completion. The dictionary should be
+   ordered with most common words first for better matching.
+   Dictionary words can be phrases containing spaces but the 
+   code will only match the first phrase with the same first
+   word.
+
+   Needs to reboot to reload dictionary.
+   
+*/
+#include "ctype.h"
+#include "string.h"
+
+static bool dict_loaded = false, dict_changed = false;
+static char dictionary[MAX_DICT];
+
+static void kbd_learn_text(char *input)
 {
-    /* find input char */
-    unsigned short ch = get_kbd_ch(pm, pm->x, pm->y);
+    /* dictionary end, word start, word end */
+    int  de,ws,we,i,len;
+    char *line, word[MAX_DICT_WORD+1];
 
-    /* check for hangul input */
-    if (ch >= 0x3131 && ch <= 0x3163)
+    if ( ! dict_loaded )
+        return;
+    
+    for ( de = 0; dictionary[de]; de++ )
+    if ( de == MAX_DICT )
+        return;
+    
+    line = input;
+
+    while(1)
     {
-        unsigned short tmp;
+        /* find word start */
+        for ( ws = 0; line[ws] == ' '; ws++ );
+        if ( line[ws] == 0 )
+             return;
+        /* find word end */
+        for ( we = ws; line[we] != ' ' && line[we] != 0 ; we++ );
+        len = we-ws;
+        if ( de+len >= MAX_DICT ) {
+            splash(HZ,"No room.");return;}
 
-        if (!state->hangul)
+        if ( len >= MAX_DICT_WORD ) {
+            splash(HZ,"Word too big.");return;}
+        
+        /* don't save small words */
+        if ( len < 3 ) 
         {
-            state->hlead = state->hvowel = state->htail = 0;
-            state->hangul = true;
+            line += we;
+            continue;
         }
-
-        if (!state->hvowel)
+            
+        /* check if it's in there already */
+        /* FIXME: do something smart about case ?*/
+        for ( i=0; i < len; i++ )
+            word[i] = line[i+ws];
+        word[len]=0;
+        if ( strstr( dictionary, word ) != NULL ) 
         {
-            state->hvowel = ch;
+            line += we;
+            continue;
         }
-        else if (!state->htail)
-        {
-            state->htail = ch;
-        }
-        else
-        {
-            /* previous hangul complete */
-            /* check whether tail is actually lead of next char */
-            tmp = hangul_join(state->htail, ch, 0);
 
-            if (tmp != 0xfffd)
-            {
-                tmp = hangul_join(state->hlead, state->hvowel, 0);
-                kbd_delchar(state);
-                kbd_inschar(state, tmp);
-                /* insert dummy char */
-                kbd_inschar(state, ' ');
-                state->hlead = state->htail;
-                state->hvowel = ch;
-                state->htail = 0;
-            }
-            else
-            {
-                state->hvowel = state->htail = 0;
-                state->hlead = ch;
-            }
-        }
+        splashf(HZ/3,"Adding %s",word);
+        dict_changed = true;
 
-        /* combine into hangul */
-        tmp = hangul_join(state->hlead, state->hvowel, state->htail);
+        /* shift dictionary forward */
+        memmove( dictionary+len+1, dictionary, de );
 
-        if (tmp != 0xfffd)
+        /* copy word */
+        strcpy( dictionary, word );
+        dictionary[len]='\n';
+        de += len;
+        line += we;
+    }
+}
+
+static void kbd_save_predicted()
+{
+    int length;
+    
+    if ( dict_loaded && dict_changed )
+    {    
+        int fd = open("/.rockbox/pred_dict.txt", O_WRONLY|O_BINARY);
+        if (fd < 0)
         {
-            kbd_delchar(state);
-            ch = tmp;
+            splash(HZ,"Can't open file");
+            return;
         }
-        else
+        for ( length = 0; dictionary[length]; length++ )
+            if ( length == MAX_DICT )
+                break;
+            
+        if ( write( fd, dictionary, length ) != length )
         {
-            state->hvowel = state->htail = 0;
-            state->hlead = ch;
+            splash(HZ,"Write error");
         }
+        close(fd);
     }
-    else
+    return;
+}
+    
+     
+static void kbd_load_predicted()
+{
+    int length;
+    
+    if ( ! dict_loaded ) 
     {
-        state->hangul = false;
-    }
-
-    /* insert char */
-    kbd_inschar(state, ch);
+        int fd = open("/.rockbox/pred_dict.txt", O_RDONLY|O_BINARY);
+        if (fd < 0)
+            return; /* File Open Error */
+        length = read(fd, dictionary, MAX_DICT);
+        if (length < 0)                 
+            return; /* Read Error */
+            else {
+                dictionary[length] = 0;
+                dict_loaded = true;
+            }
+        close(fd);
+    }   
 }
 
-static void kbd_backspace(struct edit_state *state)
+static void kbd_draw_predicted(struct keyboard_parameters *pm,
+                               struct screen *sc, struct edit_state *state)
 {
-    unsigned short ch;
-    if (state->hangul)
+    int i, left = -1, length;
+    static int  last_editpos = 0;
+    char *partial, *dict;
+
+    if ( !dict_loaded )
+        return;
+    
+    /* be lazy if edit cursor hasn't moved */
+    if ( state->editpos == last_editpos )
     {
-        if (state->htail)
-            state->htail = 0;
-        else if (state->hvowel)
-            state->hvowel = 0;
-        else
-            state->hangul = false;
+        sc->putsxy(0, pm->main_y+pm->font_h, state->pred_word);
+        return;
     }
+    else
+        last_editpos = state->editpos;
+    
+    /* Start with nothing predicted */
+    state->pred_word[0] = 0; 
 
-    kbd_delchar(state);
+    dict = dictionary;            /* Points to current dictionary word */
+    i = state->editpos;
 
-    if (state->hangul)
-    {
-        if (state->hvowel)
-            ch = hangul_join(state->hlead, state->hvowel, state->htail);
+    if ( state->editpos != state->len_utf8 )
+        return;
+
+    while( --i >= 0 )     /* find left of word */
+        if ( state->text[utf8seek(state->text,i)] != ' ' )
+            left = i;
         else
-            ch = state->hlead;
-        kbd_inschar(state, ch);
-    }
-}
+            break;
 
-static void kbd_move_cursor(struct edit_state *state, int dir)
-{
-    state->hangul = false;
-    state->editpos += dir;
+    if ( left == -1 ) /* whitespace */
+        return;
 
-    if (state->editpos >= 0 && state->editpos <= state->len_utf8)
+    /* search for matching word */
+    length = utf8seek(state->text,state->editpos) - 
+                    utf8seek(state->text,left);
+
+    partial = &state->text[utf8seek(state->text,left)];
+    for ( i = 0; i <= length ; )
     {
-        state->changed = CHANGED_CURSOR;
+        if ( dict[i] == '\n' )
+        {
+            /* already typed out this whole word, look for another */
+            dict += i +1;
+            i = 0;
+            continue;
+        }
+        if ( dict[i] == 0 )
+        {
+            /* end of dictionary, give up */
+            return;
+        }
+        if ( partial[i] == dict[i] )
+        {
+            i++;
+            continue;
+        }
+        /* Case fuzz on first letter */
+        if ( !i && tolower(partial[i]) == tolower(dict[i]) )
+        {
+            i++;
+            continue;
+        }
+        if ( i == length ) /* got a match */
+        {
+            break; 
+        }
+        /* mismatch, reset to next word */
+        while ( dict[++i] != '\n' )
+            if ( dict[i] == 0 )
+                return;
+        dict += i + 1;
+        i = 0;
     }
-    else
-    {
-        state->editpos -= dir;
-#if CONFIG_CODEC == SWCODEC
-        if (global_settings.talk_menu)
-            pcmbuf_beep(1000, 150, 1500);
-#endif
-    }
+
+    /* get length of dictionary word in bytes */
+    for ( i = 0 ; dict[i] != '\n' && dict[i] != 0 ; 
+            i += utf8seek( dict,1) ) 
+        if ( i >= MAX_DICT_WORD ) 
+        {
+            i = MAX_DICT_WORD;
+            break;
+        }
+    /* copy */
+    state->pred_word[i] = 0;
+    while ( --i >= 0 )
+        state->pred_word[i] = dict[i];
+    state->pred_input_len = length;
+    //if ( pm->main_y+2*pm->font_h < sc->getheight() )
+        sc->putsxy(0, pm->main_y+pm->font_h, state->pred_word);
 }
 
-static void kbd_move_picker_horizontal(struct keyboard_parameters *pm,
-                                       struct edit_state *state, int dir)
+static void kbd_insert_predicted(struct edit_state *state)
 {
-    state->changed = CHANGED_PICKER;
-
-    pm->x += dir;
-    if (pm->x < 0)
+    int i;
+    
+    i = utf8seek(state->text,state->editpos);
+    if ( i + (int)strlen(state->pred_word) - 
+         state->pred_input_len >= state->buflen )
+        return; 
+    
+    if( state->pred_word[0] ) 
     {
-        if (--pm->page < 0)
-            pm->page = pm->pages - 1;
-        pm->x = pm->max_chars - 1;
-    }
-    else if (pm->x >= pm->max_chars)
-    {
-        if (++pm->page >= pm->pages)
-            pm->page = 0;
-        pm->x = 0;
-    }
-}
+        strcpy( i + state->text,
+                state->pred_word + state->pred_input_len );
 
-static void kbd_move_picker_vertical(struct keyboard_parameters *pm,
-                                     struct edit_state *state, int dir)
-{
-    state->changed = CHANGED_PICKER;
-
-#ifdef HAVE_MORSE_INPUT
-    if (state->morse_mode)
-    {
-        pm->line_edit = !pm->line_edit;
+        while ( state->text[utf8seek(state->text,state->editpos )] != 0 )
+            state->editpos++;
         return;
     }
-#endif /* HAVE_MORSE_INPUT */
-
-    pm->y += dir;
-    if (pm->line_edit)
-    {
-        pm->y = (dir > 0 ? 0 : pm->lines - 1);
-        pm->line_edit = false;
-    }
-    else if (pm->y < 0 || pm->y >= pm->lines)
-    {
-        pm->line_edit = true;
-    }
 }
+#endif
Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang	(revision 27411)
+++ apps/lang/english.lang	(working copy)
@@ -12619,3 +12619,116 @@
     *: "Update on Stop"
   </voice>
 </phrase>
+<phrase>
+  id: LANG_KBD_MODE
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Keyboard Mode"
+  </source>
+  <dest>
+    *: "Keyboard Mode"
+  </dest>
+  <voice>
+    *: "Keyboard Mode"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_STANDARD
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Standard"
+  </source>
+  <dest>
+    *: "Standard"
+  </dest>
+  <voice>
+    *: "Standard"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_SIDEWAYS
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Sideways"
+  </source>
+  <dest>
+    *: "Sideways"
+  </dest>
+  <voice>
+    *: "Sideways"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_MORSE
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Morse"
+  </source>
+  <dest>
+    *: "Morse"
+  </dest>
+  <voice>
+    *: "Morse"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_KEEP_ROLLIN
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Keep Rollin"
+  </source>
+  <dest>
+    *: "Keep Rollin"
+  </dest>
+  <voice>
+    *: "Keep Rollin"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_SCROLL_1D
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Scroll 1D"
+  </source>
+  <dest>
+    *: "Scroll 1D"
+  </dest>
+  <voice>
+    *: "Scroll won dee"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_KBD_MODE_ROW_COL
+  desc: in settings.general.system
+  user: core
+  <source>
+    *: "Row-Column"
+  </source>
+  <dest>
+    *: "Row-Column"
+  </dest>
+  <voice>
+    *: "Row Colum"
+  </voice>
+</phrase>
+<phrase>
+  id: LANG_WHEEL_SPEED
+  desc: Display for setting IPOD wheel spped
+  user: core
+  <source>
+    *: "Thumb Wheel Speed"
+  </source>
+  <dest>
+    *: "Thumb Wheel Speed"
+  </dest>
+  <voice>
+    *: "Thumb Wheel Speed"
+  </voice>
+</phrase>
+
Index: apps/settings.h
===================================================================
--- apps/settings.h	(revision 27411)
+++ apps/settings.h	(working copy)
@@ -814,10 +814,14 @@
     int compressor_release_time;
 #endif
 
-#ifdef HAVE_MORSE_INPUT
-    bool morse_input; /* text input method setting */
+#if defined(HAVE_MORSE_INPUT) || defined(HAVE_SCROLLWHEEL)
+    int keyboard_mode;
 #endif
 
+#ifdef IPOD_ARCH
+    int wheel_speed;
+#endif
+
 #ifdef HAVE_HOTKEY
     /* hotkey assignments - acceptable values are in
        hotkey_action enum in onplay.h */
Index: apps/menus/settings_menu.c
===================================================================
--- apps/menus/settings_menu.c	(revision 27411)
+++ apps/menus/settings_menu.c	(working copy)
@@ -259,10 +259,14 @@
 MENUITEM_SETTING(usb_keypad_mode, &global_settings.usb_keypad_mode, NULL);
 #endif
 
-#ifdef HAVE_MORSE_INPUT
-MENUITEM_SETTING(morse_input, &global_settings.morse_input, NULL);
+#if defined(HAVE_MORSE_INPUT) || defined(HAVE_SCROLLWHEEL)
+MENUITEM_SETTING(keyboard_mode, &global_settings.keyboard_mode, NULL);
 #endif
 
+#ifdef IPOD_ARCH
+MENUITEM_SETTING(wheel_speed, &global_settings.wheel_speed, NULL);
+#endif
+
 #ifdef HAVE_BUTTON_LIGHT
 MENUITEM_SETTING(buttonlight_timeout, &global_settings.buttonlight_timeout, NULL);
 #endif
@@ -286,8 +290,8 @@
 #endif
             &poweroff,
             &limits_menu,
-#ifdef HAVE_MORSE_INPUT
-            &morse_input,
+#if defined(HAVE_MORSE_INPUT) || defined(HAVE_SCROLLWHEEL)
+            &keyboard_mode,
 #endif
 #if CONFIG_CODEC == MAS3507D
             &line_in,
@@ -313,6 +317,9 @@
 #if CONFIG_CODEC == SWCODEC
             &keyclick_menu,
 #endif
+#ifdef IPOD_ARCH
+            &wheel_speed,
+#endif
 #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
             &touchpad_sensitivity,
 #endif
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c	(revision 27411)
+++ apps/settings_list.c	(working copy)
@@ -1746,10 +1746,33 @@
 #endif
 #endif
 
-#ifdef HAVE_MORSE_INPUT
-    OFFON_SETTING(0, morse_input, LANG_MORSE_INPUT, false, "morse input", NULL),
+#if defined (HAVE_SCROLLWHEEL) && defined (HAVE_MORSE_INPUT)
+CHOICE_SETTING(0, keyboard_mode, LANG_KBD_MODE, 0, "keyboard mode", 
+  "Standard,Sideways,Keep_Rollin,Scroll_1D,Row_Column,Morse", NULL, 6, 
+   ID2P(LANG_KBD_MODE_STANDARD), ID2P(LANG_KBD_MODE_SIDEWAYS),
+   ID2P(LANG_KBD_MODE_KEEP_ROLLIN), ID2P(LANG_KBD_MODE_SCROLL_1D), 
+   ID2P(LANG_KBD_MODE_ROW_COL), ID2P(LANG_KBD_MODE_MORSE) ),
+#else
+#ifdef HAVE_MORSE_INPUT /* No scrollwheel */
+     CHOICE_SETTING(0, keyboard_mode, LANG_KBD_MODE, 0, "keyboard mode", 
+         "Standard,Morse", NULL, 2, 
+         ID2P(LANG_KBD_MODE_STANDARD), ID2P(LANG_KBD_MODE_MORSE)),
 #endif
+#ifdef HAVE_SCROLLWHEEL /* No Morse */
+   CHOICE_SETTING(0, keyboard_mode, LANG_KBD_MODE, 0, "keyboard mode", 
+       "Standard,Sideways,Keep_Rollin,Scroll_1D,Row_Column", NULL, 5, 
+   ID2P(LANG_KBD_MODE_STANDARD), ID2P(LANG_KBD_MODE_SIDEWAYS),
+   ID2P(LANG_KBD_MODE_KEEP_ROLLIN), ID2P(LANG_KBD_MODE_SCROLL_1D), 
+   ID2P(LANG_KBD_MODE_ROW_COL)),
+#endif
+#endif
 
+#ifdef IPOD_ARCH
+    INT_SETTING(0, wheel_speed, LANG_WHEEL_SPEED, 8,
+            "wheel_speed", UNIT_INT, 3, 20, 1, NULL, NULL,
+            NULL),
+#endif
+
 #ifdef HAVE_HOTKEY
     TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, hotkey_wps,
         LANG_HOTKEY_WPS, HOTKEY_VIEW_PLAYLIST, "hotkey wps",
Index: apps/keymaps/keymap-e200.c
===================================================================
--- apps/keymaps/keymap-e200.c	(revision 27411)
+++ apps/keymaps/keymap-e200.c	(working copy)
@@ -256,10 +256,10 @@
     { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT,               BUTTON_NONE },
     { ACTION_KBD_CURSOR_RIGHT, BUTTON_REC|BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
     
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK,                 BUTTON_NONE },
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK|BUTTON_REPEAT,   BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD,               BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK,                 BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK|BUTTON_REPEAT,   BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD,               BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
     { ACTION_KBD_PAGE_FLIP,    BUTTON_REC|BUTTON_SELECT,         BUTTON_REC },
     { ACTION_KBD_BACKSPACE,    BUTTON_DOWN,                      BUTTON_NONE },
     { ACTION_KBD_BACKSPACE,    BUTTON_DOWN|BUTTON_REPEAT,        BUTTON_NONE },
Index: apps/keymaps/keymap-ipod.c
===================================================================
--- apps/keymaps/keymap-ipod.c	(revision 27411)
+++ apps/keymaps/keymap-ipod.c	(working copy)
@@ -90,7 +90,7 @@
     { ACTION_WPS_VOLDOWN,   BUTTON_SCROLL_BACK|BUTTON_REPEAT,   BUTTON_NONE },
     { ACTION_WPS_VOLUP,     BUTTON_SCROLL_FWD,                  BUTTON_NONE },
     { ACTION_WPS_VOLUP,     BUTTON_SCROLL_FWD|BUTTON_REPEAT,    BUTTON_NONE },
-    { ACTION_WPS_BROWSE,    BUTTON_SELECT|BUTTON_REL,           BUTTON_SELECT },
+    { ACTION_WPS_HOTKEY,    BUTTON_SELECT|BUTTON_REL,           BUTTON_SELECT },
     { ACTION_WPS_CONTEXT,   BUTTON_SELECT|BUTTON_REPEAT,        BUTTON_SELECT },
     { ACTION_WPS_HOTKEY,        BUTTON_SELECT|BUTTON_PLAY,      BUTTON_NONE },
     { ACTION_WPS_MENU,          BUTTON_MENU|BUTTON_REL,         BUTTON_MENU },
@@ -162,12 +162,13 @@
     { ACTION_KBD_RIGHT,        BUTTON_RIGHT,                          BUTTON_NONE },
     { ACTION_KBD_RIGHT,        BUTTON_RIGHT|BUTTON_REPEAT,            BUTTON_NONE },
     { ACTION_KBD_SELECT,       BUTTON_SELECT,                         BUTTON_NONE },
-    { ACTION_KBD_DONE,         BUTTON_PLAY,                           BUTTON_NONE },
-    { ACTION_KBD_ABORT,        BUTTON_MENU|BUTTON_REL,                BUTTON_MENU },
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK,                    BUTTON_NONE },
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK|BUTTON_REPEAT,      BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD,                     BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD|BUTTON_REPEAT,       BUTTON_NONE },
+    { ACTION_KBD_DONE,         BUTTON_PLAY|BUTTON_REL,                BUTTON_NONE },
+    { ACTION_KBD_ABORT,        BUTTON_PLAY|BUTTON_REPEAT,             BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK,                    BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK|BUTTON_REPEAT,      BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD,                     BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD|BUTTON_REPEAT,       BUTTON_NONE },
+    { ACTION_KBD_BACKSPACE,    BUTTON_MENU|BUTTON_REL,                BUTTON_MENU },
     { ACTION_KBD_MORSE_INPUT,  BUTTON_MENU|BUTTON_REPEAT,             BUTTON_MENU },
     { ACTION_KBD_MORSE_SELECT, BUTTON_SELECT|BUTTON_REL,              BUTTON_NONE },
     LAST_ITEM_IN_LIST
Index: apps/keymaps/keymap-fuze.c
===================================================================
--- apps/keymaps/keymap-fuze.c	(revision 27411)
+++ apps/keymaps/keymap-fuze.c	(working copy)
@@ -258,13 +258,13 @@
     { ACTION_KBD_CURSOR_RIGHT, BUTTON_HOME|BUTTON_RIGHT,               BUTTON_NONE },
     { ACTION_KBD_CURSOR_RIGHT, BUTTON_HOME|BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
     
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK,               BUTTON_NONE },
-    { ACTION_KBD_UP,           BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD,                BUTTON_NONE },
-    { ACTION_KBD_DOWN,         BUTTON_SCROLL_FWD|BUTTON_REPEAT,  BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK,               BUTTON_NONE },
+    { ACTION_KBD_SCROLL_BACK,  BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD,                BUTTON_NONE },
+    { ACTION_KBD_SCROLL_FWD,   BUTTON_SCROLL_FWD|BUTTON_REPEAT,  BUTTON_NONE },
     { ACTION_KBD_PAGE_FLIP,    BUTTON_HOME|BUTTON_SELECT,        BUTTON_HOME },
-    { ACTION_KBD_BACKSPACE,    BUTTON_DOWN,                      BUTTON_NONE },
-    { ACTION_KBD_BACKSPACE,    BUTTON_DOWN|BUTTON_REPEAT,        BUTTON_NONE },
+    { ACTION_KBD_BACKSPACE,    BUTTON_DOWN|BUTTON_REL,           BUTTON_DOWN },
+    { ACTION_KBD_MORSE_INPUT,  BUTTON_DOWN|BUTTON_REPEAT,        BUTTON_DOWN },
     { ACTION_KBD_SELECT,       BUTTON_SELECT,                    BUTTON_NONE },
     { ACTION_KBD_DONE,         BUTTON_UP,                        BUTTON_NONE },
     { ACTION_KBD_ABORT,        BUTTON_HOME|BUTTON_REPEAT,        BUTTON_NONE },
Index: firmware/target/arm/ipod/button-clickwheel.c
===================================================================
--- firmware/target/arm/ipod/button-clickwheel.c	(revision 27411)
+++ firmware/target/arm/ipod/button-clickwheel.c	(working copy)
@@ -35,6 +35,9 @@
 #include "system.h"
 #include "button.h"
 #include "kernel.h"
+#ifndef BOOTLOADER
+#include "settings.h"
+#endif
 #include "backlight.h"
 #include "serial.h"
 #include "power.h"
@@ -57,15 +60,7 @@
 
 #define WHEELCLICKS_PER_ROTATION     96 /* wheelclicks per full rotation */
 
-/* This amount of clicks is needed for at least scrolling 1 item. Choose small values 
- * to have high sensitivity but few precision, choose large values to have less 
- * sensitivity and good precision. */
-#if defined(IPOD_NANO) || defined(IPOD_NANO2G)
-#define WHEEL_SENSITIVITY 6 /* iPod nano has smaller wheel, lower sensitivity needed */
-#else
-#define WHEEL_SENSITIVITY 4 /* default sensitivity */
-#endif
-
+int  wheel_sensitivity;
 int  old_wheel_value  = -1;
 int  new_wheel_value  = 0;
 int  repeat           = 0;
@@ -97,6 +92,7 @@
 }
 #endif
 
+
 static inline int ipod_4g_button_read(void)
 {
     int whl = -1;
@@ -153,6 +149,11 @@
                     /* This is for later = BUTTON_SCROLL_TOUCH;*/
                     wheel_delta = new_wheel_value - old_wheel_value;
                     unsigned int wheel_keycode = BUTTON_NONE;
+#ifdef BOOTLOADER
+                    wheel_sensitivity = 6;
+#else
+                    wheel_sensitivity = global_settings.wheel_speed;
+#endif
 
                     /* Taking into account wrapping during transition from highest 
                      * to lowest wheel position and back */
@@ -163,9 +164,9 @@
     
                     /* Getting direction and wheel_keycode from wheel_delta.
                      * Need at least some clicks to be sure to avoid haptic fuzziness */
-                    if      (wheel_delta >=  WHEEL_SENSITIVITY)
+                    if      (wheel_delta >=  wheel_sensitivity)
                         wheel_keycode = BUTTON_SCROLL_FWD;
-                    else if (wheel_delta <= -WHEEL_SENSITIVITY)
+                    else if (wheel_delta <= -wheel_sensitivity)
                         wheel_keycode = BUTTON_SCROLL_BACK;
                     else 
                         wheel_keycode = BUTTON_NONE;
@@ -217,8 +218,8 @@
                         /* The queue should have no other events when scrolling */
                         if (queue_empty(&button_queue))
                         {
-                            /* each WHEEL_SENSITIVITY clicks = scrolling 1 item */
-                            accumulated_wheel_delta /= WHEEL_SENSITIVITY;
+                            /* each wheel_sensitivity clicks = scrolling 1 item */
+                            accumulated_wheel_delta /= wheel_sensitivity;
 #ifdef HAVE_SCROLLWHEEL
                             /* use data-format for HAVE_SCROLLWHEEL */
                             /* always use acceleration mode (1<<31) */
