/* Button to send chat message */ static void button_chat_send_onpress(void){ if (selected_item->item == ITEM_FRIEND) { FRIEND *f = selected_item->data; if (f->online) { // TODO clear the chat bar with a /slash command edit_msg_onenter(&edit_msg); // reset focus to the chat window on send to prevent segfault. May break on android. edit_setfocus(&edit_msg); } } else { edit_msg_onenter(&edit_msg_group); // reset focus to the chat window on send to prevent segfault. May break on android. edit_setfocus(&edit_msg_group); } }
static void button_chat_send_on_mup(void) { if (flist_get_type() == ITEM_GROUP) { e_group_msg_onenter(&edit_chat_msg_group); // reset focus to the chat window on send to prevent segfault. May break on android. edit_setfocus(&edit_chat_msg_group); } }
static void button_add_new_contact_onpress(void) { if (tox_thread_init) { /* Only change if we're logged in! */ edit_setstr(&edit_add_id, (char_t *)edit_search.data, edit_search.length); edit_setstr(&edit_search, (char_t *)"", 0); list_selectaddfriend(); edit_setfocus(&edit_add_msg); } }
_Bool edit_mmove(EDIT *edit, int px, int py, int width, int height, int x, int y, int dx, int dy) { if(utox_window_baseline && py > utox_window_baseline - font_small_lineheight - 4 * SCALE) { y += py - (utox_window_baseline - font_small_lineheight - 4 * SCALE); py = utox_window_baseline - font_small_lineheight - 4 * SCALE; } _Bool need_redraw = 0; _Bool mouseover = inrect(x, y, 0, 0, width - (edit->multiline ? SCROLL_WIDTH : 0), height); if(mouseover) { cursor = CURSOR_TEXT; } if(mouseover != edit->mouseover) { edit->mouseover = mouseover; if(edit != active_edit) { need_redraw = 1; } } if(edit->multiline) { need_redraw |= scroll_mmove(edit->scroll, px, py, width, height, x, y, dx, dy); y += scroll_gety(edit->scroll, height); } if(edit == active_edit && edit_select) { if (edit->select_completely) { edit_setfocus(edit); need_redraw = 1; return need_redraw; } setfont(FONT_TEXT); edit_sel.p2 = hittextmultiline(x - 2 * SCALE, width - 4 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0), y - 2 * SCALE, INT_MAX, font_small_lineheight, edit->data, edit->length, edit->multiline); STRING_IDX start, length; if(edit_sel.p2 > edit_sel.p1) { start = edit_sel.p1; length = edit_sel.p2 - edit_sel.p1; } else { start = edit_sel.p2; length = edit_sel.p1 - edit_sel.p2; } if(start != edit_sel.start || length != edit_sel.length) { edit_sel.start = start; edit_sel.length = length; need_redraw = 1; } } else if(mouseover) { setfont(FONT_TEXT); edit->mouseover_char = hittextmultiline(x - 2 * SCALE, width - 4 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0), y - 2 * SCALE, INT_MAX, font_small_lineheight, edit->data, edit->length, edit->multiline); } return need_redraw; }
// TODO move this out of here! static void show_page(ITEM *i){ // TODO!! // panel_item[selected_item->item - 1].disabled = 1; // panel_item[i->item - 1].disabled = 0; edit_resetfocus(); /* First things first, we need to deselect and store the old data. */ switch (selected_item->item){ case ITEM_FRIEND: { FRIEND *f = selected_item->data; free(f->typed); f->typed_length = edit_msg.length; f->typed = malloc(edit_msg.length); memcpy(f->typed, edit_msg.data, edit_msg.length); f->msg.scroll = messages_friend.panel.content_scroll->d; f->edit_history = edit_msg.history; f->edit_history_cur = edit_msg.history_cur; f->edit_history_length = edit_msg.history_length; panel_friend_chat.disabled = 1; } case ITEM_FRIEND_ADD: { panel_chat.disabled = 1; panel_friend_request.disabled = 1; break; } case ITEM_GROUP: { GROUPCHAT *g = selected_item->data; free(g->typed); g->typed_length = edit_msg_group.length; g->typed = malloc(edit_msg_group.length); memcpy(g->typed, edit_msg_group.data, edit_msg_group.length); g->msg.scroll = messages_group.panel.content_scroll->d; g->edit_history = edit_msg_group.history; g->edit_history_cur = edit_msg_group.history_cur; g->edit_history_length = edit_msg_group.history_length; panel_chat.disabled = 1; panel_group_chat.disabled = 1; break; } case ITEM_SETTINGS: { button_settings.disabled = 0; panel_settings_master.disabled = 1; panel_overhead.disabled = 1; break; } case ITEM_ADD: { button_add.disabled = 0; panel_add_friend.disabled = 1; break; } case ITEM_TRANSFER: { button_transfer.disabled = 0; panel_change_profile.disabled = 1; break; } /* End of last case */ } /* End of switch */ /* Now we activate/select the new page, and load stored data */ switch (i->item) { case ITEM_FRIEND_ADD: { panel_chat.disabled = 0; panel_friend_request.disabled = 0; break; } case ITEM_FRIEND: { FRIEND *f = i->data; #ifdef UNITY if (unity_running) { mm_rm_entry(f->cid); } #endif memcpy(edit_msg.data, f->typed, f->typed_length); edit_msg.length = f->typed_length; messages_friend.data = &f->msg; messages_updateheight(&messages_friend); messages_friend.iover = MSG_IDX_MAX; messages_friend.panel.content_scroll->content_height = f->msg.height; messages_friend.panel.content_scroll->d = f->msg.scroll; f->msg.id = f - friend; f->notify = 0; edit_msg.history = f->edit_history; edit_msg.history_cur = f->edit_history_cur; edit_msg.history_length = f->edit_history_length; edit_setfocus(&edit_msg); panel_chat.disabled = 0; panel_friend_chat.disabled = 0; break; } case ITEM_GROUP: { GROUPCHAT *g = i->data; memcpy(edit_msg_group.data, g->typed, g->typed_length); edit_msg_group.length = g->typed_length; messages_group.data = &g->msg; messages_updateheight(&messages_group); messages_group.iover = MSG_IDX_MAX; messages_group.panel.content_scroll->content_height = g->msg.height; messages_group.panel.content_scroll->d = g->msg.scroll; edit_setfocus(&edit_msg_group); g->msg.id = g - group; edit_msg_group.history = g->edit_history; edit_msg_group.history_cur = g->edit_history_cur; edit_msg_group.history_length = g->edit_history_length; panel_chat.disabled = 0; panel_group_chat.disabled = 0; break; } case ITEM_SETTINGS: { button_settings.disabled = 1; panel_overhead.disabled = 0; panel_settings_master.disabled = 0; break; } case ITEM_ADD: { button_add.disabled = 1; panel_overhead.disabled = 0; panel_add_friend.disabled = 0; edit_setfocus(&edit_add_id); break; } case ITEM_TRANSFER: { button_transfer.disabled = 1; panel_overhead.disabled = 0; panel_change_profile.disabled = 0; break; } // Last case } // Switch selected_item = i; addfriend_status = 0; // I think we shouldn't call this just here, redrawing should only be done when panel_draw is called, and now, we // don't even need to call the root tree, we can call subtrees/roots and should be able to increase performance. // redraw(); }
static void button_statusmsg_onpress(void){ button_settings_sub_profile_onpress(); edit_setfocus(&edit_status); }
static void button_name_onpress(void){ button_settings_sub_profile_onpress(); edit_setfocus(&edit_name); }
static void button_copyid_onpress(void) { edit_setfocus(&edit_toxid); copy(0); }