/* on the file list, that is */ static void handle_enter_key(void) { dmoz_file_t *file; int cur = instrument_get_current(); if (current_file < 0 || current_file >= flist.num_files) return; file = flist.files[current_file]; dmoz_cache_update(inst_cwd, &flist, NULL); if (file->type & TYPE_BROWSABLE_MASK) { change_dir(file->path); status.flags |= NEED_UPDATE; } else if (file->type & TYPE_INST_MASK) { if (_library_mode) return; status.flags |= SONG_NEEDS_SAVE; if (file->instnum > -1) { song_load_instrument_ex(cur, NULL, file->path, file->instnum); } else { song_load_instrument(cur, file->path); } if (!song_is_instrument_mode()) { dialog_create(DIALOG_YES_NO, "Enable instrument mode?", do_enable_inst, dont_enable_inst, 0, NULL); } else { set_page(PAGE_INSTRUMENT_LIST); } memused_songchanged(); } /* TODO */ }
static void do_enable_inst(UNUSED void *d) { song_set_instrument_mode(1); main_song_changed_cb(); set_page(PAGE_INSTRUMENT_LIST); memused_songchanged(); }
static void message_clear(UNUSED void *data) { current_song->message[0] = 0; memused_songchanged(); message_set_viewmode(); status.flags |= SONG_NEEDS_SAVE; }
static void message_insert_char(int c) { char *ptr; int n; if (!edit_mode) return; memused_songchanged(); if (c == '\t') { /* Find the number of characters until the next tab stop. * (This is new behaviour; Impulse Tracker just inserts * eight characters regardless of the cursor position.) */ n = 8 - cursor_char % 8; if (cursor_char + n > LINE_WRAP) { message_insert_char('\r'); } else { do { if (!message_add_char(' ', cursor_pos)) break; cursor_char++; cursor_pos++; n--; } while (n); } } else if (c < 32 && c != '\r') { return; } else { if (!message_add_char(c, cursor_pos)) return; cursor_pos++; if (c == '\r') { cursor_char = 0; cursor_line++; } else { cursor_char++; } } if (get_nth_line(current_song->message, cursor_line, &ptr) >= LINE_WRAP) { message_wrap_line(ptr); } if (cursor_char >= LINE_WRAP) { cursor_char = get_nth_line(current_song->message, ++cursor_line, &ptr); cursor_pos = get_absolute_position(current_song->message, cursor_line, cursor_char); } message_reposition(); status.flags |= NEED_UPDATE | SONG_NEEDS_SAVE; }
static int message_handle_key_editmode(struct key_event * k) { int line_len, num_lines = -1; int new_cursor_line = cursor_line; int new_cursor_char = cursor_char; char *ptr; int doing_drag = 0; int clipl, clipr, cp; if (k->mouse == MOUSE_SCROLL_UP) { if (k->state == KEY_RELEASE) return 0; new_cursor_line -= MOUSE_SCROLL_LINES; } else if (k->mouse == MOUSE_SCROLL_DOWN) { if (k->state == KEY_RELEASE) return 0; new_cursor_line += MOUSE_SCROLL_LINES; } else if (k->mouse == MOUSE_CLICK && k->mouse_button == 2) { if (k->state == KEY_RELEASE) status.flags |= CLIPPY_PASTE_SELECTION; return 1; } else if (k->mouse == MOUSE_CLICK) { if (k->x >= 2 && k->x <= 77 && k->y >= 13 && k->y <= 47) { new_cursor_line = (k->y - 13) + top_line; new_cursor_char = (k->x - 2); if (k->sx != k->x || k->sy != k->y) { /* yay drag operation */ cp = get_absolute_position(current_song->message, (k->sy-13)+top_line, (k->sx-2)); widgets_message[0].clip_start = cp; doing_drag = 1; } } } line_len = get_nth_line(current_song->message, cursor_line, &ptr); switch (k->sym) { case SDLK_UP: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_line--; break; case SDLK_DOWN: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_line++; break; case SDLK_LEFT: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_char--; break; case SDLK_RIGHT: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_char++; break; case SDLK_PAGEUP: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_line -= 35; break; case SDLK_PAGEDOWN: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; new_cursor_line += 35; break; case SDLK_HOME: if (k->state == KEY_RELEASE) return 1; if (k->mod & KMOD_CTRL) new_cursor_line = 0; else new_cursor_char = 0; break; case SDLK_END: if (k->state == KEY_RELEASE) return 1; if (k->mod & KMOD_CTRL) { num_lines = get_num_lines(current_song->message); new_cursor_line = num_lines; } else { new_cursor_char = line_len; } break; case SDLK_ESCAPE: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; message_set_viewmode(); memused_songchanged(); return 1; case SDLK_BACKSPACE: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) { _delete_selection(); } else { message_delete_char(); } return 1; case SDLK_DELETE: if (!NO_MODIFIER(k->mod)) return 0; if (k->state == KEY_RELEASE) return 1; if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) { _delete_selection(); } else { message_delete_next_char(); } return 1; default: if (k->mod & KMOD_CTRL) { if (k->state == KEY_RELEASE) return 1; if (k->sym == SDLK_t) { message_extfont = !message_extfont; break; } else if (k->sym == SDLK_y) { clippy_select(NULL, NULL, 0); message_delete_line(); break; } } else if (k->mod & KMOD_ALT) { if (k->state == KEY_RELEASE) return 1; if (k->sym == SDLK_c) { prompt_message_clear(); return 1; } } else if (k->mouse == MOUSE_NONE) { if (k->unicode == '\r' || k->unicode == '\t' || k->unicode >= 32) { if (k->state == KEY_RELEASE) return 1; if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) { _delete_selection(); } if (k->mod & (KMOD_SHIFT|KMOD_CAPS)) { message_insert_char(toupper((unsigned int)k->unicode)); } else { message_insert_char(k->unicode); } return 1; } return 0; } if (k->mouse != MOUSE_CLICK) return 0; if (k->state == KEY_RELEASE) return 1; if (!doing_drag) { clippy_select(NULL, NULL, 0); } } if (new_cursor_line != cursor_line) { if (num_lines == -1) num_lines = get_num_lines(current_song->message); if (new_cursor_line < 0) new_cursor_line = 0; else if (new_cursor_line > num_lines) new_cursor_line = num_lines; /* make sure the cursor doesn't go past the new eol */ line_len = get_nth_line(current_song->message, new_cursor_line, &ptr); if (new_cursor_char > line_len) new_cursor_char = line_len; cursor_char = new_cursor_char; cursor_line = new_cursor_line; } else if (new_cursor_char != cursor_char) { /* we say "else" here ESPECIALLY because the mouse can only come in the top section - not because it's some clever optimization */ if (new_cursor_char < 0) { if (cursor_line == 0) { new_cursor_char = cursor_char; } else { cursor_line--; new_cursor_char = get_nth_line(current_song->message, cursor_line, &ptr); } } else if (new_cursor_char > get_nth_line(current_song->message, cursor_line, &ptr)) { if (cursor_line == get_num_lines(current_song->message)) { new_cursor_char = cursor_char; } else { cursor_line++; new_cursor_char = 0; } } cursor_char = new_cursor_char; } message_reposition(); cursor_pos = get_absolute_position(current_song->message, cursor_line, cursor_char); if (doing_drag) { widgets_message[0].clip_end = cursor_pos; clipl = widgets_message[0].clip_start; clipr = widgets_message[0].clip_end; if (clipl > clipr) { cp = clipl; clipl = clipr; clipr = cp; } clippy_select(widgets_message, (current_song->message+clipl), clipr-clipl); } status.flags |= NEED_UPDATE; return 1; }