Exemplo n.º 1
0
static void handle_touch(struct wl_input_event *ev)
{
	//int offset,offset_count,
	int article_link_number=-1;
	int enter_touch_y_pos_record;
	//int time_diff_search;
	int mode;
	struct keyboard_key * key;
	static int last_5_y[5];
	static unsigned long last_5_y_time_ticks[5];
	int i;

	DP(DBG_WL, ("%s() touch event @%d,%d val %d\n", __func__,
		ev->touch_event.x, ev->touch_event.y, ev->touch_event.value));

	mode = keyboard_get_mode();
	if (display_mode == DISPLAY_MODE_INDEX && (mode == KEYBOARD_CHAR || mode == KEYBOARD_NUM))
	{
		article_buf_pointer = NULL;
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				handle_search_key(key->key);
			}
			else {
				if (!touch_down_on_list || ev->touch_event.y < RESULT_START - RESULT_HEIGHT) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				if(search_result_count()==0)
				   goto out;

				 //search_set_selection(last_selection);
				 //search_open_article(last_selection);
				 if(search_result_selected()>=0)
				 {
				    display_mode = DISPLAY_MODE_ARTICLE;
				    last_display_mode = DISPLAY_MODE_INDEX;
				    search_open_article(search_result_selected());
				 }
			}
			touch_down_on_keyboard = 0;
			touch_down_on_list = 0;
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			start_search_time = ev->touch_event.ticks;
			last_delete_time = start_search_time;
			if (key) {
				if(key->key==8)//press "<" button
				{
				    press_delete_button = true;
			       }
				else if(key->key == -42)
				{
					mode = keyboard_get_mode();
					if(mode == KEYBOARD_CHAR)
						keyboard_set_mode(KEYBOARD_NUM);
					else if(mode == KEYBOARD_NUM)
						keyboard_set_mode(KEYBOARD_CHAR);
					guilib_fb_lock();
					keyboard_paint();
					guilib_fb_unlock();
				}

				if (!touch_down_on_keyboard && !touch_down_on_list)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				if (!touch_down_on_keyboard && !touch_down_on_list)
					touch_down_on_list = 1;
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
				pre_key = NULL;

				if (!search_result_count()) goto out;

				if(touch_search == 0)
				{
				    //last_search_y_pos = ev->touch_event.y;
				    touch_search = 1;
				}
				else
				{
				    if(search_result_selected()>=0 && abs(ev->touch_event.y-search_touch_pos_y_last)>5)
				    {
					invert_selection(search_result_selected(),-1, RESULT_START, RESULT_HEIGHT);
					search_set_selection(-1);
				    }
				    goto out;
				}

				int new_selection;
				if((ev->touch_event.y - RESULT_START)<0)
				    new_selection = -1;
				else
				    new_selection = ((unsigned int)ev->touch_event.y - RESULT_START) / RESULT_HEIGHT;

				if (new_selection == search_result_selected()) goto out;

				unsigned int avail_count = keyboard_get_mode() == KEYBOARD_NONE ?
					NUMBER_OF_FIRST_PAGE_RESULTS : NUMBER_OF_RESULTS_KEYBOARD;
				avail_count = search_result_count() > avail_count ? avail_count : search_result_count();
				if (new_selection >= avail_count) goto out;
				if (touch_down_on_keyboard) goto out;

				//invert_selection(search_result_selected(), new_selection, RESULT_START, RESULT_HEIGHT);
				invert_selection(-1, new_selection, RESULT_START, RESULT_HEIGHT);

				 last_selection = new_selection ;
				search_set_selection(new_selection);
				search_touch_pos_y_last = ev->touch_event.y;
			}
		}
	}
	else if (display_mode == DISPLAY_MODE_HISTORY && mode == KEYBOARD_CLEAR_HISTORY)
	{
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			#ifdef INCLUDED_FROM_KERNEL
			delay_us(100000 * 2);
			#endif
			keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					touch_down_on_list = 0;
					goto out;
				}
				if (key->key == 'Y') {
					history_clear();
					keyboard_set_mode(KEYBOARD_NONE);
					history_reload();
				} else if (key->key == 'N') {
					keyboard_set_mode(KEYBOARD_NONE);
					guilib_fb_lock();
					draw_clear_history(1);
					guilib_fb_unlock();
				}
			}
			else {
				touch_down_on_keyboard = 0;
				touch_down_on_list = 0;
				goto out;
			}
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			if (key) {
				if (!touch_down_on_keyboard)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				touch_down_on_keyboard = 0;
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
				pre_key = NULL;

			}
		}
	}
	else if (display_mode == DISPLAY_MODE_RESTRICTED)
	{
		key = keyboard_get_data(ev->touch_event.x, ev->touch_event.y);
		if (ev->touch_event.value == 0) {
			if (key->key == 'Y' || key->key == 'N' || key->key == 'P')
			{
				#ifdef INCLUDED_FROM_KERNEL
				delay_us(100000 * 2);
				#endif
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
			}
			else
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_DELAY); // reset invert with delay
			enter_touch_y_pos_record = enter_touch_y_pos;
			enter_touch_y_pos = -1;
			touch_search = 0;
			press_delete_button = false;
			pre_key = NULL;
			if (key) {
				if (!touch_down_on_keyboard) {
					touch_down_on_keyboard = 0;
					goto out;
				}
				handle_password_key(key->key);
			}
			touch_down_on_keyboard = 0;
		} else {
			if(enter_touch_y_pos<0)  //record first touch y pos
			   enter_touch_y_pos = ev->touch_event.y;
			last_index_y_pos = ev->touch_event.y;
			start_search_time = ev->touch_event.ticks;
			last_delete_time = start_search_time;
			if (key) {
				if(key->key==8)//press "<" button
				{
				    press_delete_button = true;
			       }
				else if(key->key == -42)
				{
					mode = keyboard_get_mode();
					if(mode == KEYBOARD_PASSWORD_CHAR)
						keyboard_set_mode(KEYBOARD_PASSWORD_NUM);
					else if(mode == KEYBOARD_PASSWORD_NUM)
						keyboard_set_mode(KEYBOARD_PASSWORD_CHAR);
					guilib_fb_lock();
					keyboard_paint();
					guilib_fb_unlock();
				}

				if (!touch_down_on_keyboard)
					touch_down_on_keyboard = 1;

				if (pre_key && pre_key->key == key->key) goto out;

				if (touch_down_on_keyboard) {
					keyboard_key_invert(key);
					pre_key = key;
				}
			} else {
				keyboard_key_reset_invert(KEYBOARD_RESET_INVERT_NOW);
				pre_key = NULL;

				search_touch_pos_y_last = ev->touch_event.y;
			}
		}
	} else {
		if (ev->touch_event.value == 0) {
			unsigned long diff_ticks = 0;
			long diff_y = 0;

			for (i = 4; i > 0; i--)
			{
				if (last_5_y[i])
				{
					diff_y = ev->touch_event.y - last_5_y[i];
					diff_ticks = time_diff(ev->touch_event.ticks, last_5_y_time_ticks[i]);
					break;
				}
			}

			if (diff_ticks <= 0 || abs(article_moved_pixels) > SMOOTH_SCROLL_ACTIVATION_OFFSET_HIGH_THRESHOLD ||
				abs(article_moved_pixels) < SMOOTH_SCROLL_ACTIVATION_OFFSET_LOW_THRESHOLD)
				finger_move_speed = 0;
			else
			{
				// Event timesing is not good for short period due to the events are queued without timestamp
				finger_move_speed = -(float)diff_y * ((float)seconds_to_ticks(1) / (float)diff_ticks);
				if (abs(finger_move_speed) > SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD)
				{
					if (finger_move_speed > 0)
					{
						if (display_mode == DISPLAY_MODE_ARTICLE)
							finger_move_speed = ARTICLE_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed - SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
						else
							finger_move_speed = LIST_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed - SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
					}
					else
					{
						if (display_mode == DISPLAY_MODE_ARTICLE)
							finger_move_speed = ARTICLE_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed + SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
						else
							finger_move_speed = LIST_SMOOTH_SCROLL_SPEED_FACTOR *
								(finger_move_speed + SMOOTH_SCROLL_ACTIVATION_SPPED_THRESHOLD);
					}
				}
				else
					finger_move_speed = 0;
			}

			if (finger_move_speed != 0)
			{
				time_scroll_article_last = ev->touch_event.ticks;
			}

			article_moved = false;
			if (finger_move_speed == 0 && b_show_scroll_bar)
			{
				b_show_scroll_bar = 0;
				show_scroll_bar(0); // clear scroll bar
			}
			article_scroll_pixel = INITIAL_ARTICLE_SCROLL_PIXEL;
			article_moved_pixels = 0;
			touch_y_last_unreleased = 0;
			start_move_time = 0;

			article_link_number = get_activated_article_link_number();
			if(article_link_number>=0)
			{
				if (link_to_be_inverted >= 0)
				{
					if (link_currently_inverted >= 0)
						invert_link(link_currently_inverted);
					invert_link(link_to_be_inverted);
				}
				if (finger_move_speed == 0)
				{
					init_invert_link();
					last_display_mode = display_mode;
					display_mode = DISPLAY_MODE_ARTICLE;
					open_article_link_with_link_number(article_link_number);
				}
				else
				{
					if (link_currently_inverted >= 0)
						invert_link(link_currently_inverted);
					init_invert_link();
				}
				return;
			}

			reset_article_link_number();
			article_touch_down_handled = 0;
		} else {
			finger_move_speed = 0;

			if(touch_y_last_unreleased == 0)
			{
				touch_y_last_unreleased = ev->touch_event.y;
				last_unreleased_time = ev->touch_event.ticks;
				reset_article_link_number();
				article_moved_pixels = 0;
				last_5_y[0] = ev->touch_event.y;
				last_5_y_time_ticks[0] = ev->touch_event.ticks;
				for (i = 1; i < 5; i++)
					last_5_y[i] = 0;

			}
			else
			{
				article_moved_pixels += touch_y_last_unreleased - ev->touch_event.y;
				if(abs(touch_y_last_unreleased - ev->touch_event.y) >=article_scroll_pixel)
				{
					if (finger_move_speed == 0)
						display_article_with_pcf(touch_y_last_unreleased - ev->touch_event.y);
					touch_y_last_unreleased = ev->touch_event.y;
					for (i = 4; i >= 1; i--)
					{
						last_5_y[i] = last_5_y[i-1];
						last_5_y_time_ticks[i] = last_5_y_time_ticks[i-1];
					}
					last_5_y[0] = ev->touch_event.y;
					last_5_y_time_ticks[0] = ev->touch_event.ticks;
					b_show_scroll_bar = 1;
					article_scroll_pixel = 1;
				}
				else if (article_moved_pixels < article_scroll_pixel &&
					time_diff(get_time_ticks(), last_unreleased_time) > seconds_to_ticks(0.075))
				{
					article_moved_pixels = 0;
					touch_y_last_unreleased = ev->touch_event.y;
					last_unreleased_time = ev->touch_event.ticks;
					last_5_y[0] = ev->touch_event.y;
					last_5_y_time_ticks[0] = ev->touch_event.ticks;
					for (i = 1; i < 5; i++)
						last_5_y[i] = 0;
				}

				if (abs(article_moved_pixels) > ARTICLE_MOVED_THRESHOLD)
				{
					article_moved = true;
					reset_article_link_number();
				}
			}

			if (!article_moved)
			{
				article_link_number =isArticleLinkSelected(ev->touch_event.x,ev->touch_event.y);
				if (article_link_number >= 0)
					set_article_link_number(article_link_number, ev->touch_event.ticks);
				else
					reset_article_link_number();
			}

			if (!article_touch_down_handled) {
				article_touch_down_pos.x = ev->touch_event.x;
				article_touch_down_pos.y = ev->touch_event.y;
				article_touch_down_handled = 1;
			}
		}
	}
out:
	return;
}
Exemplo n.º 2
0
void editor_map::select_all()
{
	clear_selection();
	invert_selection();
}
Exemplo n.º 3
0
void
get_commands()
{
    int ch;

    for(;;) {
        can_resize = TRUE; /* it's safe to resize now */
        if(!opt_get_bool(BOOL_SHOW_CURSOR))
            hide_cursor();
        if(should_resize)
            refresh_screen();
        ch = getch();
        if(!opt_get_bool(BOOL_SHOW_CURSOR))
            show_cursor();
        can_resize = FALSE; /* it's not safe to resize anymore */
        switch(ch) {
        case 'q':
            return;
        case 'Q':
            quit_abook(QUIT_DONTSAVE);
            break;
        case 'P':
            print_stderr(selected_items() ?
                         -1 : list_get_curitem());
            return;
        case '?':
            display_help(HELP_MAIN);
            refresh_screen();
            break;
        case 'a':
            add_item();
            break;
        case '\r':
            edit_item(-1);
            break;
        case KEY_DC:
        case 'd':
        case 'r':
            ui_remove_items();
            break;
        case 'D':
            duplicate_item();
            break;
        case 12:
            refresh_screen();
            break;

        case 'k':
        case KEY_UP:
            scroll_up();
            break;
        case 'j':
        case KEY_DOWN:
            scroll_down();
            break;
        case 'K':
        case KEY_PPAGE:
            page_up();
            break;
        case 'J':
        case KEY_NPAGE:
            page_down();
            break;

        case 'g':
        case KEY_HOME:
            goto_home();
            break;
        case 'G':
        case KEY_END:
            goto_end();
            break;

        case 'w':
            save_database();
            break;
        case 'l':
            ui_read_database();
            break;
        case 'i':
            import_database();
            break;
        case 'e':
            export_database();
            break;
        case 'C':
            ui_clear_database();
            break;

        case 'o':
            ui_open_datafile();
            break;

        case 's':
            sort_by_field("name");
            break;
        case 'S':
            sort_surname();
            break;
        case 'F':
            sort_by_field(NULL);
            break;

        case '/':
            ui_find(0);
            break;
        case '\\':
            ui_find(1);
            break;

        case ' ':
            if(list_get_curitem() >= 0) {
                list_invert_curitem_selection();
                ui_print_number_of_items();
                refresh_list();
            }
            break;
        case '+':
            select_all();
            refresh_list();
            break;
        case '-':
            select_none();
            refresh_list();
            break;
        case '*':
            invert_selection();
            refresh_list();
            break;
        case 'A':
            move_curitem(MOVE_ITEM_UP);
            break;
        case 'Z':
            move_curitem(MOVE_ITEM_DOWN);
            break;

        case 'm':
            launch_mutt(selected_items() ?
                        -1 : list_get_curitem());
            refresh_screen();
            break;

        case 'p':
            ui_print_database();
            break;

        case 'v':
            launch_wwwbrowser(list_get_curitem());
            refresh_screen();
            break;
        case 'H':
            launch_callpgm(list_get_curitem(), 'H');
            refresh_screen();
            break;
        case 'W':
            launch_callpgm(list_get_curitem(), 'W');
            refresh_screen();
            break;
        case 'M':
            launch_callpgm(list_get_curitem(), 'M');
            refresh_screen();
            break;
        }
    }
}