void Tabs::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) { // clicks Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y ); int found=-1; for(int i=0;i<tabs.size();i++) { int ofs=tabs[i].ofs_cache; if (pos.x < ofs) { found=i; break; } } if (found!=-1) { set_current_tab(found); } } }
void gui_open_parallel_view_in_new_tab(void) { PASSAGE_TAB_INFO *pt; if (stop_refresh) return; if (!settings.browsing) return; if ((pt = g_new0(PASSAGE_TAB_INFO, 1)) == NULL) { gui_generic_warning("Could not allocate a new tab"); return; } pt->showtexts = FALSE; pt->showpreview = TRUE; pt->showcomms = FALSE; pt->showdicts = FALSE; pt->showparallel = TRUE; pt->text_mod = g_strdup(settings.MainWindowModule); pt->commentary_mod = g_strdup(settings.CommWindowModule); pt->dictlex_mod = g_strdup(settings.DictWindowModule); pt->book_mod = g_strdup(settings.book_mod); pt->showbookeditor = FALSE; pt->comm_showing = FALSE; pt->text_commentary_key = g_strdup(settings.currentverse); pt->dictlex_key = g_strdup(settings.dictkey); pt->book_offset = g_strdup_printf("%ld", settings.book_offset); passage_list = g_list_append(passage_list, (PASSAGE_TAB_INFO *)pt); set_current_tab(pt); gui_recompute_view_menu_choices(); notebook_main_add_page(pt); pt->paratab = gui_create_parallel_tab(); gui_parallel_tab_sync((gchar *)settings.currentverse); /*gtk_box_pack_start(GTK_BOX(widgets.page), pt->paratab, TRUE, TRUE, 0); */ gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets.notebook_main), gtk_notebook_page_num(GTK_NOTEBOOK(widgets.notebook_main), pt->page_widget)); }
void Tabs::_input_event(const InputEvent &p_event) { if (p_event.type == InputEvent::MOUSE_MOTION) { Point2 pos(p_event.mouse_motion.x, p_event.mouse_motion.y); hilite_arrow = -1; if (buttons_visible) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); if (pos.x > limit + decr->get_width()) { hilite_arrow = 1; } else if (pos.x > limit) { hilite_arrow = 0; } } // test hovering to display right or close button int hover_buttons = -1; hover = -1; for (int i = 0; i < tabs.size(); i++) { if (i < offset) continue; if (tabs[i].rb_rect.has_point(pos)) { rb_hover = i; cb_hover = -1; hover_buttons = i; break; } else if (tabs[i].cb_rect.has_point(pos)) { cb_hover = i; rb_hover = -1; hover_buttons = i; break; } } if (hover_buttons == -1) { // no hover rb_hover = hover_buttons; cb_hover = hover_buttons; } update(); return; } if (rb_pressing && p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { if (rb_hover != -1) { //pressed emit_signal("right_button_pressed", rb_hover); } rb_pressing = false; update(); } if (cb_pressing && p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { if (cb_hover != -1) { //pressed emit_signal("tab_close", cb_hover); } cb_pressing = false; update(); } if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { // clicks Point2 pos(p_event.mouse_button.x, p_event.mouse_button.y); if (buttons_visible) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); if (pos.x > limit + decr->get_width()) { if (missing_right) { offset++; update(); } return; } else if (pos.x > limit) { if (offset > 0) { offset--; update(); } return; } } int found = -1; for (int i = 0; i < tabs.size(); i++) { if (i < offset) continue; if (tabs[i].rb_rect.has_point(pos)) { rb_pressing = true; update(); return; } if (tabs[i].cb_rect.has_point(pos)) { cb_pressing = true; update(); return; } if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) { found = i; break; } } if (found != -1) { set_current_tab(found); } } }
void TabContainer::_input_event(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==BUTTON_LEFT) { // clicks Point2 pos( p_event.mouse_button.x, p_event.mouse_button.y ); int top_margin = _get_top_margin(); if (pos.y>top_margin) return; // no click (too far down) if (pos.x<tabs_ofs_cache) return; // no click (too far left) Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Font> font = get_font("font"); Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); Ref<Texture> menu = get_icon("menu"); Ref<Texture> menu_hl = get_icon("menu_hl"); if (popup && pos.x>get_size().width-menu->get_width()) { emit_signal("pre_popup_pressed"); Vector2 pp_pos = get_global_pos(); pp_pos.x+=get_size().width; pp_pos.x-=popup->get_size().width; pp_pos.y+=menu->get_height(); popup->set_global_pos( pp_pos ); popup->popup();; return; } pos.x-=tabs_ofs_cache; int idx=0; int found=-1; bool rightroom=false; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (idx<tab_display_ofs) { idx++; continue; } if (idx>last_tab_cache) { rightroom=true; break; } String s = c->has_meta("_tab_name")?String(XL_MESSAGE(String(c->get_meta("_tab_name")))):String(c->get_name()); int tab_width=font->get_string_size(s).width; if (c->has_meta("_tab_icon")) { Ref<Texture> icon = c->get_meta("_tab_icon"); if (icon.is_valid()) { tab_width+=icon->get_width(); if (s!="") tab_width+=get_constant("hseparation"); } } if (idx==current) { tab_width+=tab_fg->get_minimum_size().width; } else { tab_width+=tab_bg->get_minimum_size().width; } if (pos.x < tab_width) { found=idx; break; } pos.x-=tab_width; idx++; } if (buttons_visible_cache) { if (p_event.mouse_button.x>get_size().width-incr->get_width()) { if (rightroom) { tab_display_ofs+=1; update(); } } else if (p_event.mouse_button.x>get_size().width-incr->get_width()-decr->get_width()) { if (tab_display_ofs>0) { tab_display_ofs-=1; update(); } } } if (found!=-1) { set_current_tab(found); } } }
void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { Point2 pos(mb->get_position().x, mb->get_position().y); Size2 size = get_size(); // Click must be on tabs in the tab header area. if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin()) return; // Handle menu button. Ref<Texture> menu = get_icon("menu"); if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); Vector2 popup_pos = get_global_position(); popup_pos.x += size.width - popup->get_size().width; popup_pos.y += menu->get_height(); popup->set_global_position(popup_pos); popup->popup(); return; } Vector<Control *> tabs = _get_tabs(); // Handle navigation buttons. if (buttons_visible_cache) { Ref<Texture> increment = get_icon("increment"); Ref<Texture> decrement = get_icon("decrement"); if (pos.x > size.width - increment->get_width()) { if (last_tab_cache < tabs.size() - 1) { first_tab_cache += 1; update(); } return; } else if (pos.x > size.width - increment->get_width() - decrement->get_width()) { if (first_tab_cache > 0) { first_tab_cache -= 1; update(); } return; } } // Activate the clicked tab. pos.x -= tabs_ofs_cache; for (int i = first_tab_cache; i <= last_tab_cache; i++) { int tab_width = _get_tab_width(i); if (pos.x < tab_width) { if (!get_tab_disabled(i)) { set_current_tab(i); } break; } pos.x -= tab_width; } } }
void Tabs::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { Point2 pos = mm->get_position(); highlight_arrow = -1; if (buttons_visible) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); if (pos.x > limit + decr->get_width()) { highlight_arrow = 1; } else if (pos.x > limit) { highlight_arrow = 0; } } // test hovering to display right or close button int hover_now = -1; int hover_buttons = -1; for (int i = 0; i < tabs.size(); i++) { if (i < offset) continue; Rect2 rect = get_tab_rect(i); if (rect.has_point(pos)) { hover_now = i; } if (tabs[i].rb_rect.has_point(pos)) { rb_hover = i; cb_hover = -1; hover_buttons = i; break; } else if (!tabs[i].disabled && tabs[i].cb_rect.has_point(pos)) { cb_hover = i; rb_hover = -1; hover_buttons = i; break; } } if (hover != hover_now) { hover = hover_now; emit_signal("tab_hover", hover); } if (hover_buttons == -1) { // no hover rb_hover = hover_buttons; cb_hover = hover_buttons; } update(); return; } Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) { if (scrolling_enabled && buttons_visible) { if (offset > 0) { offset--; update(); } } } if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) { if (scrolling_enabled && buttons_visible) { if (missing_right) { offset++; update(); } } } if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { if (rb_hover != -1) { //pressed emit_signal("right_button_pressed", rb_hover); } rb_pressing = false; update(); } if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { if (cb_hover != -1) { //pressed emit_signal("tab_close", cb_hover); } cb_pressing = false; update(); } if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { // clicks Point2 pos(mb->get_position().x, mb->get_position().y); if (buttons_visible) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); if (pos.x > limit + decr->get_width()) { if (missing_right) { offset++; update(); } return; } else if (pos.x > limit) { if (offset > 0) { offset--; update(); } return; } } int found = -1; for (int i = 0; i < tabs.size(); i++) { if (i < offset) continue; if (tabs[i].rb_rect.has_point(pos)) { rb_pressing = true; update(); return; } if (tabs[i].cb_rect.has_point(pos)) { cb_pressing = true; update(); return; } if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) { if (!tabs[i].disabled) { found = i; } break; } } if (found != -1) { set_current_tab(found); emit_signal("tab_clicked", found); } } } }
void gui_notebook_main_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, GList **tl) #endif { gboolean comm_showing; gint number_of_pages = gtk_notebook_get_n_pages(notebook); PASSAGE_TAB_INFO *pt; if (stop_refresh) return; XI_message(("on_notebook_main_switch_page")); page_change = TRUE; /* get data structure for new passage */ /* * this is needed to stop seg fault if the left tab is closed when * there are only two tabs - because number_of_pages equals 2 even * thought there is only 1. */ if (number_of_pages == 2 && removed_page == 0) pt = (PASSAGE_TAB_INFO *)g_list_nth_data(*tl, 0); else pt = (PASSAGE_TAB_INFO *)g_list_nth_data(*tl, page_num); removed_page = 1; //cur_passage_tab = pt; #ifdef USE_TREEVIEW_PATH if (cur_passage_tab && cur_passage_tab->book_mod) gui_collapse_treeview_to_book(GTK_TREE_VIEW(sidebar.module_list), cur_passage_tab->book_mod); #endif /* USE_TREEVIEW_PATH */ if (!pt->showparallel) { if (cur_passage_tab && cur_passage_tab->paratab) gtk_widget_hide(cur_passage_tab->paratab); gtk_widget_show(widgets.hpaned); } set_current_tab(pt); companion_activity = TRUE; if (pt->showparallel) { gtk_widget_hide(widgets.hpaned); if (pt->paratab) gtk_widget_show(pt->paratab); companion_activity = FALSE; page_change = FALSE; settings.paratab_showing = TRUE; return; } else settings.paratab_showing = FALSE; //sets the book mod and key main_display_book(pt->book_mod, pt->book_offset); #ifdef USE_TREEVIEW_PATH if (pt->showcomms && pt->book_mod) gui_expand_treeview_to_path(GTK_TREE_VIEW(sidebar.module_list), pt->book_mod); #endif /* USE_TREEVIEW_PATH */ comm_showing = settings.comm_showing; settings.comm_showing = 1; //sets the commentary mod and key main_display_commentary(pt->commentary_mod, pt->text_commentary_key); settings.comm_showing = comm_showing; //sets the text mod and key main_display_bible(pt->text_mod, pt->text_commentary_key); navbar_versekey.module_name = g_string_assign(navbar_versekey.module_name, pt->text_mod); navbar_versekey.key = g_string_assign(navbar_versekey.key, pt->text_commentary_key); main_update_nav_controls(navbar_versekey.module_name->str, pt->text_commentary_key); //sets the dictionary mod and key main_display_dictionary(pt->dictlex_mod, pt->dictlex_key); gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets.notebook_comm_book), (pt->comm_showing ? 0 : 1)); gui_recompute_view_menu_choices(); companion_activity = FALSE; page_change = FALSE; }
void gui_load_tabs(const gchar *filename) { xmlDocPtr xml_doc; xmlNodePtr tmp_node, childnode; //const xmlChar *xml_filename; gboolean error = FALSE; gboolean back_compat_need_save = FALSE; settings.showparatab = FALSE; PASSAGE_TAB_INFO *pt = NULL, *pt_first = NULL; stop_refresh = TRUE; if (filename == NULL) { error = TRUE; } else { gchar *file; if (g_access(filename, F_OK) == 0) { /* we're done, just copy for local use that can be free'd */ file = g_strdup(filename); } else { gchar *tabs_dir = g_strdup_printf("%s/tabs/", settings.gSwordDir); if (g_access(tabs_dir, F_OK) == -1) { XI_message(("Creating new tabs directory\n")); gui_save_tabs(filename); } file = g_strdup_printf("%s%s", tabs_dir, filename); g_free(tabs_dir); } /* we need this for first time non tabbed browsing */ if (!settings.browsing && g_access(file, F_OK) == -1) { _save_off_tab(filename); } //xml_filename = (const xmlChar *) file; xml_doc = xmlParseFile(file); g_free(file); if (xml_doc == NULL) { gui_generic_warning_modal("Tabs document not parsed successfully."); error = TRUE; } else { tmp_node = xmlDocGetRootElement(xml_doc); if (tmp_node == NULL) { gui_generic_warning_modal("Tabs document is empty."); xmlFreeDoc(xml_doc); error = TRUE; } else if (xmlStrcmp(tmp_node->name, (const xmlChar *)"Xiphos_Tabs")) { gui_generic_warning_modal("Tabs document has wrong type, root node != Xiphos_Tabs"); xmlFreeDoc(xml_doc); error = TRUE; } } if (error == FALSE) { for (childnode = tmp_node->children; childnode != NULL; childnode = childnode->next) { if (!xmlStrcmp(childnode->name, (const xmlChar *)"tabs")) { tmp_node = childnode; for (tmp_node = tmp_node->children; tmp_node != NULL; tmp_node = tmp_node->next) { if (!xmlStrcmp(tmp_node->name, (const xmlChar *)"tab")) { gchar *val; pt = g_new0(PASSAGE_TAB_INFO, 1); if (pt_first == NULL) pt_first = pt; /* load per-tab module information. */ val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"text_mod"); pt->text_mod = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"commentary_mod"); pt->commentary_mod = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"dictlex_mod"); pt->dictlex_mod = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"book_mod"); pt->book_mod = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"text_commentary_key"); pt->text_commentary_key = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"dictlex_key"); pt->dictlex_key = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"book_offset"); pt->book_offset = g_strdup(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"comm_showing"); pt->comm_showing = yes_no2true_false(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"showparallel"); pt->showparallel = yes_no2true_false(val); xmlFree(val); if (pt->showparallel) { settings.showparatab = TRUE; pt->paratab = gui_create_parallel_tab(); gtk_box_pack_start(GTK_BOX(widgets.page), pt->paratab, TRUE, TRUE, 0); gtk_widget_hide(pt->paratab); gui_parallel_tab_sync((gchar *) settings.currentverse); settings.showparatab = TRUE; sync_on = TRUE; } else pt->paratab = NULL; /* * load per-tab "show" state. * includes backward compatibility: * if there is no per-tab state, * take tab state from global state. */ if ((val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"showtexts"))) { pt->showtexts = yes_no2true_false(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"showpreview"); pt->showpreview = yes_no2true_false(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"showcomms"); pt->showcomms = yes_no2true_false(val); xmlFree(val); val = (gchar *) xmlGetProp(tmp_node, (const xmlChar *)"showdicts"); pt->showdicts = yes_no2true_false(val); xmlFree(val); } else { pt->showtexts = settings.showtexts; pt->showpreview = settings.showpreview; pt->showcomms = settings.showcomms; pt->showdicts = settings.showdicts; back_compat_need_save = TRUE; } pt->history_items = 0; pt->current_history_item = 0; pt->first_back_click = TRUE; main_add_tab_history_item((PASSAGE_TAB_INFO *)pt); gui_reassign_strdup(&settings.currentverse, pt->text_commentary_key); passage_list = g_list_append(passage_list, (PASSAGE_TAB_INFO *)pt); notebook_main_add_page(pt); } } } } } xmlFreeDoc(xml_doc); /* backward compatibility completion. */ if (back_compat_need_save) gui_save_tabs(filename); if (error == TRUE || pt == NULL) { pt = g_new0(PASSAGE_TAB_INFO, 1); pt->text_mod = g_strdup(settings.MainWindowModule); pt->commentary_mod = g_strdup(settings.CommWindowModule); pt->dictlex_mod = g_strdup(settings.DictWindowModule); pt->book_mod = g_strdup(settings.book_mod); //NULL; pt->text_commentary_key = g_strdup(settings.currentverse); pt->dictlex_key = g_strdup(settings.dictkey); pt->book_offset = NULL; //settings.book_offset = atol(xml_get_value( "keys", "offset")); pt->paratab = NULL; pt->showtexts = settings.showtexts; pt->showpreview = settings.showpreview; pt->showcomms = settings.showcomms; pt->showdicts = settings.showdicts; pt->history_items = 0; pt->current_history_item = 0; pt->first_back_click = TRUE; // main_add_tab_history_item((PASSAGE_TAB_INFO*)pt); passage_list = g_list_append(passage_list, (PASSAGE_TAB_INFO *)pt); notebook_main_add_page(pt); } else { // first passage is current/displayed. pt = pt_first; pt->paratab = NULL; // This is a hack to keep gs from loading the settings // from the last session into the last tab loaded here. gui_reassign_strdup(&settings.MainWindowModule, pt->text_mod); gui_reassign_strdup(&settings.CommWindowModule, pt->commentary_mod); gui_reassign_strdup(&settings.DictWindowModule, pt->dictlex_mod); gui_reassign_strdup(&settings.book_mod, pt->book_mod); gui_reassign_strdup(&settings.currentverse, pt->text_commentary_key); gui_reassign_strdup(&settings.dictkey, pt->dictlex_key); settings.book_offset = atol(pt->book_offset); } } stop_refresh = FALSE; set_current_tab(pt); gui_recompute_view_menu_choices(); }