bool selector_widget::handle_event(const SDL_Event& event, bool claimed) { SDL_Event ev = event; normalize_event(&ev); if(claimed) { return claimed; } if(event.type == SDL_MOUSEMOTION) { return handle_mousemotion(event.motion, claimed); } else if(event.type == SDL_MOUSEBUTTONDOWN) { return handle_mousedown(event.button, claimed); } else if(event.type == SDL_MOUSEBUTTONUP) { return handle_mouseup(event.button, claimed); } else if(event.type == SDL_KEYDOWN) { const SDL_Keycode key = event.key.keysym.sym; if(key == SDLK_LEFT || key == SDLK_PAGEUP) { select_left(); } else if(key == SDLK_RIGHT || key == SDLK_PAGEDOWN) { select_right(); } else if(key == SDLK_HOME) { if(!list_.empty()) { set_selection(0); } } else if(key == SDLK_END) { if(!list_.empty()) { set_selection(list_.size()-1); } } else if(key == SDLK_RETURN && on_select_) { on_select_(list_[current_selection_].first); } } return claimed; }
void TMemo::set_line_colour(int line, int colour) { int old = current_pos(); int ofs1 = line_offset(line-1), ofs2 = line_offset(line); set_selection(ofs1,ofs2); set_text_colour(colour); set_selection(old,old); }
void TextWidget::on_mouse_move(const MouseEvent *event) { if (_on_mouse_event(this, event)) return; if (!_text_interaction_on) return; switch (event->action) { case MouseActionDown: if (event->button == MouseButtonLeft) { if (event->dbl_click_count > 0) { int start = advance_word_from_index(_cursor_end + 1, -1); int end = advance_word_from_index(_cursor_end - 1, 1); set_selection(start, end); _dbl_select_start = start; _dbl_select_end = end; _mouse_down_dbl = true; _select_down = true; } else { int index = cursor_at_pos(event->x + _scroll_x, event->y); _cursor_start = index; _cursor_end = index; _select_down = true; scroll_cursor_into_view(); } } break; case MouseActionUp: if (event->button == MouseButtonLeft && _select_down) { _select_down = false; _mouse_down_dbl = false; } break; case MouseActionMove: if (event->buttons.left && _select_down) { int new_end = cursor_at_pos(event->x + _scroll_x, event->y); if (_mouse_down_dbl) { if (new_end >= _dbl_select_start) { int new_end2 = advance_word_from_index(new_end - 1, 1); set_selection(_dbl_select_start, new_end2); } else { int new_start = advance_word_from_index(new_end + 1, -1); set_selection(_dbl_select_end, new_start); } } else { _cursor_end = new_end; } scroll_cursor_into_view(); } break; } }
void scene_view::mousePressEvent(QMouseEvent *event) { auto btns = event->buttons(); const bool mouse_left = btns.testFlag(Qt::LeftButton); if (m_mode == mode_add && mouse_left && !m_selected_add.id.empty()) { m_objects.push_back(m_selected_add); m_objects.back().name = new_name("object", m_objects); update_objects_tree(); } if (m_mode == mode_zone && mouse_left) { add_zone(m_zone_add); m_zones.back().name = new_name("zone", m_zones); update_objects_tree(); } if (m_mode == mode_path && mouse_left) { auto p0 = nya_math::vec4(m_cursor_pos, m_selected_add.y); const auto &sel_paths = m_selection["paths"]; if (sel_paths.empty()) { path p; p.name = new_name("path", m_paths); p.points.push_back(p0); m_paths.push_back(p); update_objects_tree(); set_selection("paths", m_paths.size() - 1); } else { int idx = *sel_paths.rbegin(); if (idx < (int)m_paths.size()) { m_paths[idx].points.push_back(p0); set_selection("paths", idx); } } } m_mouse_x = event->localPos().x(); m_mouse_y = event->localPos().y(); update(); }
void QWaylandDataDevice::setSelectionSource(QWaylandDataSource *source) { m_selectionSource.reset(source); if (source) connect(source, &QWaylandDataSource::cancelled, this, &QWaylandDataDevice::selectionSourceCancelled); set_selection(source ? source->object() : Q_NULLPTR, m_inputDevice->serial()); }
void selector_widget::set_value(const std::string& key, const variant& v) { if(key == "selection") { set_selection(v.as_string()); } widget::set_value(key, v); }
void select_entry(const string& inName, bool inIsDirectory) { dir_entry theEntryToFind(inName, NONE /* length - ignored for our purpose */, inIsDirectory); vector<dir_entry>::iterator theEntry = find(entries.begin(), entries.end(), theEntryToFind); if(theEntry != entries.end()) set_selection(theEntry - entries.begin()); }
void set_selection() { #ifndef USE_GDI // XXX #else set_selection(0, -1); #endif }
void w_saves::click(int x, int y) { if (x == 0 && y == 0 && active) { // almost certainly a simulated click if (num_items > 0) item_selected(); } else if (x >= trough_rect.x && x < trough_rect.x + trough_rect.w && y >= thumb_y && y <= thumb_y + thumb_height) { thumb_dragging = dirty = true; thumb_drag_y = y - thumb_y; } else { if (x < get_theme_space(LIST_WIDGET, L_SPACE) || x >= rect.w - get_theme_space(LIST_WIDGET, R_SPACE) || y < get_theme_space(LIST_WIDGET, T_SPACE) || y >= rect.h - get_theme_space(LIST_WIDGET, B_SPACE)) return; if ((y - get_theme_space(LIST_WIDGET, T_SPACE)) / item_height() + top_item < min(num_items, top_item + shown_items)) { size_t old_sel = selection; set_selection((y - get_theme_space(LIST_WIDGET, T_SPACE)) / item_height() + top_item); if (selection == old_sel && num_items > 0 && is_item_selectable(selection)) item_selected(); } } }
void selector_widget::set_selection(const std::string& sel) { selector_list::iterator it = std::find_if(list_.begin(), list_.end(), boost::bind(&selector_list::value_type::first,_1) == sel); ASSERT_LOG(it != list_.end(), "Selection not in list" << sel); set_selection(it - list_.begin()); }
void TMemo::go_to(int idx1, int idx2, int nscroll) { if (idx2==-1) idx2 = idx1; set_focus(); set_selection(idx1,idx2); scroll_caret(); scroll_line(nscroll); //*SJD* Should have an estimate of the page size!! }
void WndProperty::Editor::OnSetFocus() { KeyTimer(true, 0); EditWindow::OnSetFocus(); parent->on_editor_setfocus(); set_selection(); }
void CTutorialWindow::OnSetFocus(HWND hWndOld) { metadb_handle_list items; metadb_handle_ptr track; if (static_api_ptr_t<playback_control>()->get_now_playing(track)) { items.add_item(track); } set_selection(items); }
bool WndProperty::Editor::on_setfocus() { KeyTimer(true, 0); EditWindow::on_setfocus(); parent->on_editor_setfocus(); set_selection(); return true; }
void TextWidget::set_text(const String &text) { if (String::compare(text, _label.text()) != 0) { _label.set_text(text); _label.update(); set_selection(_cursor_start, _cursor_end); if (_auto_size) on_size_hints_changed(); } }
static void hide_popup(GntComboBox *box, gboolean set) { gnt_widget_set_size(box->dropdown, box->dropdown->priv.width - 1, box->dropdown->priv.height); if (set) set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); else gnt_tree_set_selected(GNT_TREE(box->dropdown), box->selected); gnt_widget_hide(box->dropdown->parent); }
static edit_status editor_kill_line (rp_input_line *line) { if (line->position == line->length) return EDIT_NO_OP; /* Add the line to the X11 selection. */ set_selection (&line->buffer[line->position]); line->length = line->position; line->buffer[line->length] = '\0'; return EDIT_DELETE; }
void do_smartsel (GtkWidget *widget, gpointer data) { int i; float linamp= (float)pow(10., (double)(sdata->tres/20.)); float amp, ampsum=0., rmspow, max_peak=0.; int x, temp; if(sdata->from > sdata->to) { SWAP_INT(sdata->from,sdata->to) } set_selection(h.viewstart, h.viewend,0,main_graph->allocation.width, main_graph->allocation.width); vertex1=0; vertex2=1; //something IS selected //set_avec(selection.to - selection.from); for(i=0; i<(int)atshed.par; i++) selected[i]=FALSE; //unselect all for(i=sdata->from; i < sdata->to+1; i+=sdata->step) { if(i >(int)atshed.par-1 || i >(int)sdata->to) break; for(x=h.viewstart; x < h.viewend; x++) { //amplitude evaluation amp =ats_sound->amp[i][x]; switch(sdata->met) { case 0: //peak if(amp > max_peak) max_peak=amp; break; case 1: //RMS POW ampsum+= amp*amp; break; } } switch(sdata->met) { case 0: //peak if(max_peak >= linamp) selected[i]=TRUE; break; case 1: //RMS POW rmspow= (float)sqrt((double)ampsum / (double)h.diff ); if(rmspow >= linamp) selected[i]=TRUE; break; } ampsum=max_peak=0.; } draw_pixm(); gtk_widget_destroy (GTK_WIDGET (data)); }
void text_display::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::RightButton || focusPolicy() == Qt::NoFocus){ return; } int nibble = screen_to_nibble(clip_mouse(event->x(), event->y())); set_cursor_nibble(nibble); selection selection_area = get_selection(); selection_area.set_start(nibble); selection_area.set_active(false); selection_area.set_dragging(false); set_selection(selection_area); }
void text_display::timerEvent(QTimerEvent *event) { if(event->timerId() == cursor_timer_id){ cursor_state = !cursor_state; QPoint screen = nibble_to_screen(get_cursor_nibble()); update(screen.x(), screen.y(), cursor_width, editor_font::get_height()); }else if(event->timerId() == scroll_timer_id){ selection selection_area = get_selection(); set_offset(get_offset() + columns * scroll_direction * scroll_speed); if(selection_area.is_dragging()){ selection_area.move_end(columns * 2 * scroll_direction); set_selection(selection_area); } editor->update_window(); } }
void on_ok_delete_clicked(void) { runPeos(del_cmd); /* I changed this: it was before parse in the function */ gtk_widget_destroy (notebook); freeAll_extra(); notebook = create_notebook(); gtk_widget_set_name (notebook, "notebook"); gtk_widget_ref (notebook); gtk_object_set_data_full (GTK_OBJECT (Peos), "notebook", notebook, (GtkDestroyNotify) gtk_widget_unref); set_selection(1); /* with current action selected */ gtk_container_add (GTK_CONTAINER (vbox), notebook); redisplay_menu(); }
void text_display::mouseReleaseEvent(QMouseEvent *event) { if(focusPolicy() == Qt::NoFocus){ return; } int nibble = screen_to_nibble(clip_mouse(event->x(), event->y())); set_cursor_nibble(nibble); selection selection_area = get_selection(); if(selection_area.is_active()){ selection_area.set_end(nibble); selection_area.set_dragging(false); set_selection(selection_area); } if(scroll_timer_id){ killTimer(scroll_timer_id); scroll_timer_id = 0; } }
void menu_file_selector::type_search_char(char32_t ch) { std::string const current(m_filename); if (input_character(m_filename, ch, uchar_is_printable)) { ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename.c_str()); file_selector_entry const *const cur_selected(reinterpret_cast<file_selector_entry const *>(get_selection_ref())); // if it's a perfect match for the current selection, don't move it if (!cur_selected || core_strnicmp(cur_selected->basename.c_str(), m_filename.c_str(), m_filename.size())) { std::string::size_type bestmatch(0); file_selector_entry const *selected_entry(cur_selected); for (auto &entry : m_entrylist) { // TODO: more efficient "common prefix" code std::string::size_type match(0); for (std::string::size_type i = 1; m_filename.size() >= i; ++i) { if (!core_strnicmp(entry.basename.c_str(), m_filename.c_str(), i)) match = i; else break; } if (match > bestmatch) { bestmatch = match; selected_entry = &entry; } } if (selected_entry && (selected_entry != cur_selected)) { set_selection((void *)selected_entry); centre_selection(); } } } }
void text_display::mouseMoveEvent(QMouseEvent *event) { if(focusPolicy() == Qt::NoFocus){ return; } int nibble = screen_to_nibble(clip_mouse(event->x(), event->y())); set_cursor_nibble(nibble); selection selection_area = get_selection(); if(!scroll_timer_id){ selection_area.set_end(nibble); } selection_area.set_dragging(true); set_selection(selection_area); if((event->y() > height() || event->y() < 0) && !scroll_timer_id){ scroll_timer_id = startTimer(scroll_timer_speed); scroll_direction = event->y() > 0 ? 1 : -1; }else if(!(event->y() > height() || event->y() < 0) && scroll_timer_id){ killTimer(scroll_timer_id); scroll_timer_id = 0; } }
static int v4l2_subdev_parse_setup_format(struct media_device *media, const char *p, char **endp) { struct v4l2_mbus_framefmt format = { 0, 0, 0 , 0, 0, {0}}; struct media_pad *pad; struct v4l2_rect crop = { -1, -1, -1, -1 }; struct v4l2_rect compose = crop; struct v4l2_fract interval = { 0, 0 }; unsigned int i; char *end; int ret; pad = v4l2_subdev_parse_pad_format(media, &format, &crop, &compose, &interval, p, &end); if (pad == NULL) { media_print_streampos(media, p, end); media_dbg(media, "Unable to parse format\n"); return -EINVAL; } if (pad->flags & MEDIA_PAD_FL_SINK) { ret = set_format(pad, &format); if (ret < 0) return ret; } ret = set_selection(pad, V4L2_SEL_TGT_CROP, &crop); if (ret < 0) return ret; ret = set_selection(pad, V4L2_SEL_TGT_COMPOSE, &compose); if (ret < 0) return ret; if (pad->flags & MEDIA_PAD_FL_SOURCE) { ret = set_format(pad, &format); if (ret < 0) return ret; } ret = set_frame_interval(pad->entity, &interval); if (ret < 0) return ret; /* If the pad is an output pad, automatically set the same format on * the remote subdev input pads, if any. */ if (pad->flags & MEDIA_PAD_FL_SOURCE) { for (i = 0; i < pad->entity->num_links; ++i) { struct media_link *link = &pad->entity->links[i]; struct v4l2_mbus_framefmt remote_format; if (!(link->flags & MEDIA_LNK_FL_ENABLED)) continue; if (link->source == pad && link->sink->entity->info.type == MEDIA_ENT_T_V4L2_SUBDEV) { remote_format = format; set_format(link->sink, &remote_format); } } } *endp = end; return 0; }
void menu_file_selector::handle() { osd_file::error err; const file_selector_entry *selected_entry = nullptr; int bestmatch = 0; // process the menu const event *event = process(0); if (event != nullptr && event->itemref != nullptr) { // handle selections if (event->iptkey == IPT_UI_SELECT) { auto entry = (const file_selector_entry *) event->itemref; switch (entry->type) { case SELECTOR_ENTRY_TYPE_EMPTY: // empty slot - unload m_result = result::EMPTY; stack_pop(); break; case SELECTOR_ENTRY_TYPE_CREATE: // create m_result = result::CREATE; stack_pop(); break; case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST: m_result = result::SOFTLIST; stack_pop(); break; case SELECTOR_ENTRY_TYPE_DRIVE: case SELECTOR_ENTRY_TYPE_DIRECTORY: // drive/directory - first check the path err = util::zippath_opendir(entry->fullpath, nullptr); if (err != osd_file::error::NONE) { // this path is problematic; present the user with an error and bail ui().popup_time(1, "Error accessing %s", entry->fullpath); break; } m_current_directory.assign(entry->fullpath); reset(reset_options::SELECT_FIRST); break; case SELECTOR_ENTRY_TYPE_FILE: // file m_current_file.assign(entry->fullpath); m_result = result::FILE; stack_pop(); break; } // reset the char buffer when pressing IPT_UI_SELECT m_filename.clear(); } else if (event->iptkey == IPT_SPECIAL) { // if it's any other key and we're not maxed out, update if (input_character(m_filename, event->unichar, uchar_is_printable)) { ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename.c_str()); file_selector_entry const *const cur_selected(reinterpret_cast<file_selector_entry const *>(get_selection_ref())); // check for entries which matches our m_filename_buffer: for (auto &entry : m_entrylist) { if (cur_selected != &entry) { int match = 0; for (int i = 0; i < m_filename.size() + 1; i++) { if (core_strnicmp(entry.basename.c_str(), m_filename.c_str(), i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = &entry; } } } if (selected_entry != nullptr && selected_entry != cur_selected) { set_selection((void *)selected_entry); centre_selection(); } } } else if (event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case m_filename.clear(); } } }
void menu_software_list::handle() { const entry_info *selected_entry = nullptr; int bestmatch = 0; // process the menu const event *event = process(0); if (event && event->itemref) { if ((uintptr_t)event->itemref == 1 && event->iptkey == IPT_UI_SELECT) { m_ordered_by_shortname = !m_ordered_by_shortname; // reset the char buffer if we change ordering criterion m_filename_buffer.clear(); // reload the menu with the new order reset(reset_options::REMEMBER_REF); machine().popmessage(_("Switched Order: entries now ordered by %s"), m_ordered_by_shortname ? _("shortname") : _("description")); } // handle selections else if (event->iptkey == IPT_UI_SELECT) { entry_info *info = (entry_info *) event->itemref; m_result = info->short_name; stack_pop(); } else if (event->iptkey == IPT_SPECIAL) { if (input_character(m_filename_buffer, event->unichar, &is_valid_softlist_part_char)) { // display the popup ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer); // identify the selected entry entry_info const *const cur_selected = (uintptr_t(event->itemref) != 1) ? reinterpret_cast<entry_info const *>(get_selection_ref()) : nullptr; // loop through all entries for (auto &entry : m_entrylist) { // is this entry the selected entry? if (cur_selected != &entry) { auto &compare_name = m_ordered_by_shortname ? entry.short_name : entry.long_name; int match = 0; for (int i = 0; i < m_filename_buffer.size() + 1; i++) { if (core_strnicmp(compare_name.c_str(), m_filename_buffer.c_str(), i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = &entry; } } } if (selected_entry != nullptr && selected_entry != cur_selected) { set_selection((void *)selected_entry); centre_selection(); } } } else if (event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case m_filename_buffer.clear(); m_result = m_filename_buffer; stack_pop(); } } }
int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg) { struct tty_struct * tty; struct tty_struct * other_tty; struct tty_struct * termios_tty; pid_t pgrp; int dev; int termios_dev; int retval; if (MAJOR(file->f_rdev) != TTY_MAJOR) { printk("tty_ioctl: tty pseudo-major != TTY_MAJOR\n"); return -EINVAL; } dev = MINOR(file->f_rdev); tty = TTY_TABLE(dev); if (!tty) return -EINVAL; if (IS_A_PTY(dev)) other_tty = tty_table[PTY_OTHER(dev)]; else other_tty = NULL; if (IS_A_PTY_MASTER(dev)) { termios_tty = other_tty; termios_dev = PTY_OTHER(dev); } else { termios_tty = tty; termios_dev = dev; } switch (cmd) { case TCGETS: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (struct termios)); if (retval) return retval; memcpy_tofs((struct termios *) arg, termios_tty->termios, sizeof (struct termios)); return 0; case TCSETSF: case TCSETSW: case TCSETS: retval = check_change(termios_tty, termios_dev); if (retval) return retval; if (cmd == TCSETSF || cmd == TCSETSW) { if (cmd == TCSETSF) flush_input(termios_tty); wait_until_sent(termios_tty, 0); } return set_termios(termios_tty, (struct termios *) arg, termios_dev); case TCGETA: return get_termio(termios_tty,(struct termio *) arg); case TCSETAF: case TCSETAW: case TCSETA: retval = check_change(termios_tty, termios_dev); if (retval) return retval; if (cmd == TCSETAF || cmd == TCSETAW) { if (cmd == TCSETAF) flush_input(termios_tty); wait_until_sent(termios_tty, 0); } return set_termio(termios_tty, (struct termio *) arg, termios_dev); case TCXONC: retval = check_change(tty, dev); if (retval) return retval; switch (arg) { case TCOOFF: stop_tty(tty); break; case TCOON: start_tty(tty); break; case TCIOFF: if (STOP_CHAR(tty) != __DISABLED_CHAR) put_tty_queue(STOP_CHAR(tty), &tty->write_q); break; case TCION: if (START_CHAR(tty) != __DISABLED_CHAR) put_tty_queue(START_CHAR(tty), &tty->write_q); break; default: return -EINVAL; } return 0; case TCFLSH: retval = check_change(tty, dev); if (retval) return retval; switch (arg) { case TCIFLUSH: flush_input(tty); break; case TCIOFLUSH: flush_input(tty); /* fall through */ case TCOFLUSH: flush_output(tty); break; default: return -EINVAL; } return 0; case TIOCEXCL: set_bit(TTY_EXCLUSIVE, &tty->flags); return 0; case TIOCNXCL: clear_bit(TTY_EXCLUSIVE, &tty->flags); return 0; case TIOCSCTTY: if (current->leader && (current->session == tty->session)) return 0; /* * The process must be a session leader and * not have a controlling tty already. */ if (!current->leader || (current->tty >= 0)) return -EPERM; if (tty->session > 0) { /* * This tty is already the controlling * tty for another session group! */ if ((arg == 1) && suser()) { /* * Steal it away */ struct task_struct *p; for_each_task(p) if (p->tty == dev) p->tty = -1; } else return -EPERM; } current->tty = dev; tty->session = current->session; tty->pgrp = current->pgrp; return 0; case TIOCGPGRP: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (pid_t)); if (retval) return retval; if (current->tty != termios_dev) return -ENOTTY; put_fs_long(termios_tty->pgrp, (pid_t *) arg); return 0; case TIOCSPGRP: retval = check_change(termios_tty, termios_dev); if (retval) return retval; if ((current->tty < 0) || (current->tty != termios_dev) || (termios_tty->session != current->session)) return -ENOTTY; pgrp = get_fs_long((pid_t *) arg); if (pgrp < 0) return -EINVAL; if (session_of_pgrp(pgrp) != current->session) return -EPERM; termios_tty->pgrp = pgrp; return 0; case TIOCOUTQ: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (unsigned long)); if (retval) return retval; put_fs_long(CHARS(&tty->write_q), (unsigned long *) arg); return 0; case TIOCINQ: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (unsigned long)); if (retval) return retval; if (L_ICANON(tty)) put_fs_long(inq_canon(tty), (unsigned long *) arg); else put_fs_long(CHARS(&tty->secondary), (unsigned long *) arg); return 0; case TIOCSTI: if ((current->tty != dev) && !suser()) return -EPERM; retval = verify_area(VERIFY_READ, (void *) arg, 1); if (retval) return retval; put_tty_queue(get_fs_byte((char *) arg), &tty->read_q); TTY_READ_FLUSH(tty); return 0; case TIOCGWINSZ: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (struct winsize)); if (retval) return retval; memcpy_tofs((struct winsize *) arg, &tty->winsize, sizeof (struct winsize)); return 0; case TIOCSWINSZ: if (IS_A_PTY_MASTER(dev)) set_window_size(other_tty,(struct winsize *) arg); return set_window_size(tty,(struct winsize *) arg); case TIOCLINUX: switch (get_fs_byte((char *)arg)) { case 0: return do_screendump(arg); case 1: return do_get_ps_info(arg); #ifdef CONFIG_SELECTION case 2: return set_selection(arg); case 3: return paste_selection(tty); case 4: unblank_screen(); return 0; #endif /* CONFIG_SELECTION */ default: return -EINVAL; } case TIOCCONS: if (IS_A_CONSOLE(dev)) { if (!suser()) return -EPERM; redirect = NULL; return 0; } if (redirect) return -EBUSY; if (!suser()) return -EPERM; if (IS_A_PTY_MASTER(dev)) redirect = other_tty; else if (IS_A_PTY_SLAVE(dev)) redirect = tty; else return -ENOTTY; return 0; case FIONBIO: arg = get_fs_long((unsigned long *) arg); if (arg) file->f_flags |= O_NONBLOCK; else file->f_flags &= ~O_NONBLOCK; return 0; case TIOCNOTTY: if (current->tty != dev) return -ENOTTY; if (current->leader) disassociate_ctty(0); current->tty = -1; return 0; case TIOCGETD: retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (unsigned long)); if (retval) return retval; put_fs_long(tty->disc, (unsigned long *) arg); return 0; case TIOCSETD: retval = check_change(tty, dev); if (retval) return retval; arg = get_fs_long((unsigned long *) arg); return tty_set_ldisc(tty, arg); case TIOCGLCKTRMIOS: arg = get_fs_long((unsigned long *) arg); retval = verify_area(VERIFY_WRITE, (void *) arg, sizeof (struct termios)); if (retval) return retval; memcpy_tofs((struct termios *) arg, &termios_locked[termios_dev], sizeof (struct termios)); return 0; case TIOCSLCKTRMIOS: if (!suser()) return -EPERM; arg = get_fs_long((unsigned long *) arg); memcpy_fromfs(&termios_locked[termios_dev], (struct termios *) arg, sizeof (struct termios)); return 0; case TIOCPKT: if (!IS_A_PTY_MASTER(dev)) return -ENOTTY; retval = verify_area(VERIFY_READ, (void *) arg, sizeof (unsigned long)); if (retval) return retval; if (get_fs_long(arg)) { if (!tty->packet) { tty->packet = 1; tty->link->ctrl_status = 0; } } else tty->packet = 0; return 0; case TCSBRK: case TCSBRKP: retval = check_change(tty, dev); if (retval) return retval; wait_until_sent(tty, 0); if (!tty->ioctl) return 0; tty->ioctl(tty, file, cmd, arg); return 0; default: if (tty->ioctl) { retval = (tty->ioctl)(tty, file, cmd, arg); if (retval != -EINVAL) return retval; } if (ldiscs[tty->disc].ioctl) { retval = (ldiscs[tty->disc].ioctl) (tty, file, cmd, arg); return retval; } return -EINVAL; }
void ui_menu_file_selector::handle() { file_error err; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int bestmatch = 0; // process the menu const ui_menu_event *event = process(0); if (event != NULL && event->itemref != NULL) { // handle selections if (event->iptkey == IPT_UI_SELECT) { entry = (const file_selector_entry *) event->itemref; switch(entry->type) { case SELECTOR_ENTRY_TYPE_EMPTY: // empty slot - unload *m_result = R_EMPTY; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_CREATE: // create *m_result = R_CREATE; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST: *m_result = R_SOFTLIST; ui_menu::stack_pop(machine()); break; case SELECTOR_ENTRY_TYPE_DRIVE: case SELECTOR_ENTRY_TYPE_DIRECTORY: // drive/directory - first check the path err = zippath_opendir(entry->fullpath, NULL); if (err != FILERR_NONE) { // this path is problematic; present the user with an error and bail machine().ui().popup_time(1, "Error accessing %s", entry->fullpath); break; } m_current_directory.assign(entry->fullpath); reset((ui_menu_reset_options)0); break; case SELECTOR_ENTRY_TYPE_FILE: // file m_current_file.assign(entry->fullpath); *m_result = R_FILE; ui_menu::stack_pop(machine()); break; } // reset the char buffer when pressing IPT_UI_SELECT if (m_filename_buffer[0] != '\0') memset(m_filename_buffer, '\0', ARRAY_LENGTH(m_filename_buffer)); } else if (event->iptkey == IPT_SPECIAL) { int buflen = strlen(m_filename_buffer); bool update_selected = FALSE; // if it's a backspace and we can handle it, do so if ((event->unichar == 8 || event->unichar == 0x7f) && buflen > 0) { *(char *)utf8_previous_char(&m_filename_buffer[buflen]) = 0; update_selected = TRUE; if (ARRAY_LENGTH(m_filename_buffer) > 0) machine().ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer); } // if it's any other key and we're not maxed out, update else if (event->unichar >= ' ' && event->unichar < 0x7f) { buflen += utf8_from_uchar(&m_filename_buffer[buflen], ARRAY_LENGTH(m_filename_buffer) - buflen, event->unichar); m_filename_buffer[buflen] = 0; update_selected = TRUE; if (ARRAY_LENGTH(m_filename_buffer) > 0) machine().ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer); } if (update_selected) { const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection(); // check for entries which matches our m_filename_buffer: // from current entry to the end for (entry = cur_selected; entry != NULL; entry = entry->next) { if (entry->basename != NULL && m_filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) { if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } // and from the first entry to current one for (entry = m_entrylist; entry != cur_selected; entry = entry->next) { if (entry->basename != NULL && m_filename_buffer != NULL) { int match = 0; for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++) { if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0) match = i; } if (match > bestmatch) { bestmatch = match; selected_entry = entry; } } } if (selected_entry != NULL && selected_entry != cur_selected) set_selection((void *) selected_entry); } } else if (event->iptkey == IPT_UI_CANCEL) { // reset the char buffer also in this case if (m_filename_buffer[0] != '\0') memset(m_filename_buffer, '\0', ARRAY_LENGTH(m_filename_buffer)); } } }
void ui_menu_file_selector::populate() { zippath_directory *directory = NULL; file_error err; const osd_directory_entry *dirent; const file_selector_entry *entry; const file_selector_entry *selected_entry = NULL; int i; const char *volume_name; const char *path = m_current_directory.c_str(); // open the directory err = zippath_opendir(path, &directory); // clear out the menu entries m_entrylist = NULL; if (m_has_empty) { // add the "[empty slot]" entry append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL); } if (m_has_create) { // add the "[create]" entry append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL); } if (m_has_softlist) { // add the "[software list]" entry entry = append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL); selected_entry = entry; } // add the drives i = 0; while((volume_name = osd_get_volume_name(i))!=NULL) { append_entry(SELECTOR_ENTRY_TYPE_DRIVE, volume_name, volume_name); i++; } // build the menu for each item if (err == FILERR_NONE) { while((dirent = zippath_readdir(directory)) != NULL) { // append a dirent entry entry = append_dirent_entry(dirent); if (entry != NULL) { // set the selected item to be the first non-parent directory or file if ((selected_entry == NULL) && strcmp(dirent->name, "..")) selected_entry = entry; // do we have to select this file? if (!core_stricmp(m_current_file.c_str(), dirent->name)) selected_entry = entry; } } } // append all of the menu entries for (entry = m_entrylist; entry != NULL; entry = entry->next) append_entry_menu_item(entry); // set the selection (if we have one) if (selected_entry != NULL) set_selection((void *) selected_entry); // set up custom render proc customtop = machine().ui().get_line_height() + 3.0f * UI_BOX_TB_BORDER; if (directory != NULL) zippath_closedir(directory); }