void CL_MenuModalLoop::on_menubar_mouse_input(CL_InputEvent e) { e.mouse_pos = menubar->screen_to_component_coords(e.mouse_pos); if (ignore_menubar_mouse_up && e.type == CL_InputEvent::released) { ignore_menubar_mouse_up = false; } else if (e.type == CL_InputEvent::released) { end(); } else if (e.type == CL_InputEvent::pointer_moved) { int old_index = menubar->impl->get_selected_item_index(); menubar->impl->select_item_at(e.mouse_pos); int new_index = menubar->impl->get_selected_item_index(); if (new_index != old_index) { close_all_popup_windows(); CL_PopupMenu menu = menubar->impl->get_selected_menu(); create_popup_window(menu, menubar->impl->get_submenu_screen_pos()); } } }
void CL_MenuModalLoop::start(CL_GUIComponent *owner, CL_MenuBar *menubar) { if (running) throw CL_Exception("Menu loop already running!"); running = true; this->owner = owner; this->menubar = menubar; create_popup_window(menubar->impl->get_selected_menu(), menubar->impl->get_submenu_screen_pos()); owner->capture_mouse(true); }
void CL_MenuModalLoop::start(CL_GUIComponent *owner, CL_PopupMenu menu, const CL_Point &pos) { if (running) throw CL_Exception("Menu loop already running!"); running = true; this->owner = owner; create_popup_window(menu, pos); owner->capture_mouse(true); popup = true; }
void CL_MenuModalLoop::on_popup_mouse_input(CL_PopupMenuWindow *popup, CL_InputEvent e) { e.mouse_pos = popup->screen_to_component_coords(e.mouse_pos); if (e.type == CL_InputEvent::released) { CL_PopupMenuItem pmi = popup->get_selected_item(); if (!pmi.is_null() && !pmi.is_disabled()) { end(); if (!pmi.is_null()) { if (pmi.is_checkable()) pmi.set_checked(!pmi.is_checked()); if (!pmi.func_clicked().is_null()) pmi.func_clicked().invoke(); } } } else if (e.type == CL_InputEvent::pointer_moved) { int previous_item_index = popup->get_selected_item_index(); popup->select_item_at(e.mouse_pos); int new_item_index = popup->get_selected_item_index(); if (previous_item_index != new_item_index) { if (popup_windows.back() != popup) close_last_popup_window(); CL_PopupMenuItem pmi = popup->get_selected_item(); if (!pmi.is_null() && pmi.has_submenu() && !pmi.is_disabled()) { CL_Point pos = popup->get_submenu_screen_position(); create_popup_window(pmi.get_submenu(), pos); } } } }
void CL_MenuModalLoop::on_keyboard_input(CL_InputEvent e) { CL_PopupMenuWindow *window = popup_windows.back(); if (e.type == CL_InputEvent::pressed) { if (e.id == CL_KEY_LEFT && !popup) { CL_PopupMenuWindow *window = popup_windows.back(); popup_windows.pop_back(); delete window; if (popup_windows.empty()) { menubar->impl->select_previous(); create_popup_window(menubar->impl->get_selected_menu(), menubar->impl->get_submenu_screen_pos()); } else { window = popup_windows.back(); window->request_repaint(); } } else if (e.id == CL_KEY_RIGHT && !popup) { CL_PopupMenuItem pmi = window->get_selected_item(); if (!pmi.is_null() && pmi.has_submenu()) { create_popup_window(pmi.get_submenu(), window->get_submenu_screen_position()); } else { close_all_popup_windows(); menubar->impl->select_next(); create_popup_window(menubar->impl->get_selected_menu(), menubar->impl->get_submenu_screen_pos()); } } else if (e.id == CL_KEY_DOWN) { window->select_next(); } else if (e.id == CL_KEY_UP) { window->select_previous(); } } else if (e.type == CL_InputEvent::released) { if (e.id == CL_KEY_ENTER || e.id == CL_KEY_NUMPAD_ENTER) { CL_PopupMenuItem pmi = window->get_selected_item(); end(); if (!pmi.func_clicked().is_null()) pmi.func_clicked().invoke(); } else if (e.id == CL_KEY_ESCAPE) { end(); } } }
void show_popup(RESULT *result) { gchar *text=NULL; GtkTextIter iter; CANVAS canvas; DRAW_TEXT l_text; gint length; gchar *euc_str; g_assert(result->type == RESULT_TYPE_EB); LOG(LOG_DEBUG, "IN : show_popup()"); text = ebook_get_text(result->data.eb.book_info, result->data.eb.pos_text.page, result->data.eb.pos_text.offset); if(text == NULL) return; // Prevent the window from growing. //if(text[strlen(text)-1] == '\n') //text[strlen(text)-1] = '\0'; if(popup == NULL){ create_popup_window(); } // Program aborts if you enable this line. //gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_view), NULL); clear_text_buffer(); gtk_text_buffer_get_start_iter (text_buffer, &iter); length = strlen(text); if(text[length-1] == '\n'){ text[length-1] = '\0'; length --; } l_text.text = text; l_text.length = length; canvas.buffer = text_buffer; canvas.iter = &iter; canvas.indent = 0; if(result->word != NULL){ euc_str = iconv_convert("utf-8", "euc-jp", result->word); draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, euc_str); g_free(euc_str); } else { draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, NULL); } gtk_text_buffer_get_start_iter (text_buffer, &iter); gtk_text_buffer_place_cursor(text_buffer, &iter); if(bshow_popup_title){ gchar title[256]; sprintf(title, "%d of %d", g_list_index(search_result, current_in_result->data) + 1, g_list_length(search_result)); gtk_label_set_text(GTK_LABEL(title_label), title); } gtk_adjustment_set_value( gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0); gtk_adjustment_set_value( gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0); gtk_window_present(GTK_WINDOW(popup)); g_free(text); set_current_result(result); gtk_timeout_add(10, scroll_to_top, NULL); LOG(LOG_DEBUG, "OUT : show_popup()"); }
/** * Program entry point. Initializes gtk+, calls the widget creating * functions and starts the main loop. Also connects 'popup-menu', * 'activate' and 'button-release-event' to the tray_icon. * * @param argc count of arguments * @param argv string array of arguments * @return 0 for success, otherwise error code */ int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; want_debug = FALSE; #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif DEBUG_PRINT("[Debugging Mode Build]\n"); setlocale(LC_ALL, ""); context = g_option_context_new(_("- A mixer for the system tray.")); g_option_context_add_main_entries(context, args, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); g_option_context_parse(context, &argc, &argv, &error); gtk_init(&argc, &argv); g_option_context_free(context); if (version) { printf(_("%s version: %s\n"), PACKAGE, VERSION); exit(0); } popup_window = NULL; add_pixmap_directory(PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); add_pixmap_directory("./data/pixmaps"); prefs_ensure_save_dir(); prefs_load(); cards = NULL; // so we don't try and free on first run alsa_init(); init_libnotify(); create_popup_window(); create_popup_menu(); add_filter(); tray_icon = create_tray_icon(); g_signal_connect(G_OBJECT(tray_icon), "popup-menu", G_CALLBACK(popup_callback), popup_menu); g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); g_signal_connect(G_OBJECT(tray_icon), "button-release-event", G_CALLBACK(tray_icon_button), NULL); mute_check_popup_menu_handler = g_signal_connect(G_OBJECT(mute_check_popup_menu), "toggled", G_CALLBACK(on_mute_clicked), NULL); mute_check_popup_window_handler = g_signal_connect(G_OBJECT(mute_check_popup_window), "toggled", G_CALLBACK(on_mute_clicked), NULL); apply_prefs(0); gtk_main(); uninit_libnotify(); alsa_close(); return 0; }