📄 interface.c
字号:
/* * File: interface.c * * Copyright (C) 1997 Raph Levien <raph@acm.org> * Copyright (C) 1999 Sammy Mannaert <nstalkie@tvd.be> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */#include <config.h>#include <stdio.h>#include <ctype.h>#include <gtk/gtk.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <fcntl.h>#include "msg.h"#include "list.h"#include "misc.h"#include "dillo.h"#include "history.h"#include "nav.h"#include "IO/Url.h"#include "IO/IO.h"#include "interface.h"#include "commands.h"#include "menu.h"#include "bookmark.h"#include "prefs.h"#include "url.h"#include "capi.h"#include "gtk_ext_button.h"#include "dw_widget.h"#include "dw_gtk_scrolled_window.h"#include "dw_gtk_viewport.h"#include "dw_gtk_statuslabel.h"#include "dw_container.h"#include "progressbar.h"#include "pixmaps.h"#include <gdk/gdkkeysyms.h>#define DEBUG_LEVEL 0#include "debug.h"/* * Local Data *//* BrowserWindow holds all the widgets (and perhaps more) * for each new_browser.*/static BrowserWindow **browser_window;static gint num_bw, num_bw_max;/* We need only one of them. */static GtkTooltips *tooltips = NULL;/* open dialog last dir */static gchar *open_dialog_last_dirname = NULL;/* save dialog last dir */static gchar *save_dialog_last_dirname = NULL;/* * Initialize global data */void a_Interface_init(void){ num_bw = 0; num_bw_max = 16; browser_window = NULL; tooltips = gtk_tooltips_new (); open_dialog_last_dirname = NULL; save_dialog_last_dirname = NULL;}/* * Stop all active connections in the browser window (except downloads) */void a_Interface_stop(BrowserWindow *bw){ DEBUG_MSG(3, "a_Interface_stop: hi!\n"); /* Remove root clients */ while ( bw->NumRootClients ) { a_Cache_stop_client(bw->RootClients[0]); a_List_remove(bw->RootClients, 0, bw->NumRootClients); } /* Remove image clients */ while ( bw->NumImageClients ) { a_Cache_stop_client(bw->ImageClients[0]); a_List_remove(bw->ImageClients, 0, bw->NumImageClients); }}/* * Empty RootClients, ImageClients and PageUrls lists and * reset progress bar data. */void a_Interface_clean(BrowserWindow *bw){ g_return_if_fail ( bw != NULL ); while ( bw->NumRootClients ) a_List_remove(bw->RootClients, 0, bw->NumRootClients); while ( bw->NumImageClients ) a_List_remove(bw->ImageClients, 0, bw->NumImageClients); while ( bw->NumPageUrls ) { a_Url_free(bw->PageUrls[0].Url); a_List_remove(bw->PageUrls, 0, bw->NumPageUrls); } /* Zero image-progressbar data */ bw->NumImages = 0; bw->NumImagesGot = 0;}/*=== Browser Window Interface Updating =====================================*//* * Remove the cache-client from the bw list * (client can be a image or a html page) */void a_Interface_remove_client(BrowserWindow *bw, gint ClientKey){ gint i; gboolean Found = FALSE; for ( i = 0; !Found && i < bw->NumRootClients; ++i) if ( bw->RootClients[i] == ClientKey ) { a_List_remove(bw->RootClients, i, bw->NumRootClients); Found = TRUE; } for ( i = 0; !Found && i < bw->NumImageClients; ++i) if ( bw->ImageClients[i] == ClientKey ) { a_List_remove(bw->ImageClients, i, bw->NumImageClients); bw->NumImagesGot++; Found = TRUE; } a_Interface_set_button_sens(bw);}/* * Remove the cache-client from the bw list * (client can be a image or a html page) */void a_Interface_close_client(BrowserWindow *bw, gint ClientKey){ gchar numstr[32]; a_Interface_remove_client(bw, ClientKey); /* --Progress bars stuff-- */ g_snprintf(numstr, 32, "%s%d of %d", PBAR_ISTR(prefs.panel_size == 1), bw->NumImagesGot, bw->NumImages); a_Progressbar_update(bw->imgprogress, numstr, (bw->NumImagesGot == bw->NumImages) ? 0 : 1 );}/* * Set the sensitivity on back/forw buttons and menu entries. */static gint Interface_sens_idle_func(BrowserWindow *bw){ gboolean back_sensitive, forw_sensitive, stop_sensitive; /* Stop button */ stop_sensitive = (bw->NumRootClients > 0); gtk_widget_set_sensitive(bw->stop_button, stop_sensitive); /* Back and Forward buttons */ back_sensitive = a_Nav_stack_ptr(bw) > 0; gtk_widget_set_sensitive(bw->back_button, back_sensitive); forw_sensitive = (a_Nav_stack_ptr(bw) < a_Nav_stack_size(bw) - 1 && !bw->nav_expecting); gtk_widget_set_sensitive(bw->forw_button, forw_sensitive); bw->sens_idle_id = 0; return FALSE;}/* * Set the sensitivity on back/forw buttons and menu entries. */void a_Interface_set_button_sens(BrowserWindow *bw){ if (bw->sens_idle_id == 0) bw->sens_idle_id = gtk_idle_add( (GtkFunction)Interface_sens_idle_func, bw);}/* * Add a reference to the cache-client in the browser window's list. * This helps us keep track of which are active in the window so that it's * possible to abort them. * (Root: Flag, whether a Root URL or not) */void a_Interface_add_client(BrowserWindow *bw, gint Key, gint Root){ gint nc; char numstr[32]; g_return_if_fail ( bw != NULL ); if ( Root ) { nc = bw->NumRootClients; a_List_add(bw->RootClients, nc, bw->MaxRootClients); bw->RootClients[nc] = Key; bw->NumRootClients++; a_Interface_set_button_sens(bw); } else { nc = bw->NumImageClients; a_List_add(bw->ImageClients, nc, bw->MaxImageClients); bw->ImageClients[nc] = Key; bw->NumImageClients++; bw->NumImages++; a_Interface_set_button_sens(bw); /* --Progress bar stuff-- */ g_snprintf(numstr, 32, "%s%d of %d", PBAR_ISTR(prefs.panel_size == 1), bw->NumImagesGot, bw->NumImages); a_Progressbar_update(bw->imgprogress, numstr, 1); }}/* * Add an URL to the browser window's list. * This helps us keep track of page requested URLs so that it's * possible to stop, abort and reload them.) * Flags: Chosen from {BW_Root, BW_Image, BW_Download} */void a_Interface_add_url(BrowserWindow *bw, const DilloUrl *Url, gint Flags){ gint nu, i; gboolean found = FALSE; g_return_if_fail ( bw != NULL && Url != NULL ); nu = bw->NumPageUrls; for ( i = 0; i < nu; i++ ) { if ( !a_Url_cmp(Url, bw->PageUrls[i].Url) ) { found = TRUE; break; } } if ( !found ) { a_List_add(bw->PageUrls, nu, bw->MaxPageUrls); bw->PageUrls[nu].Url = a_Url_dup(Url); bw->PageUrls[nu].Flags = Flags; bw->NumPageUrls++; } /* test: MSG("Urls:\n"); for (i = 0; i < bw->NumPageUrls; i++) MSG("%s\n", bw->PageUrls[i].Url); MSG("---\n"); */}/* * Remove a single browser window. This includes all its open childs, * freeing all resources associated with them, and exiting gtk * if no browser windows are left. */static gboolean Interface_quit(GtkWidget *widget, BrowserWindow *bw){ gint i; /* stop/abort open connections. */ a_Interface_stop(bw); g_slist_free(bw->PanelHandles); if (bw->open_dialog_window != NULL) gtk_widget_destroy(bw->open_dialog_window); if (bw->openfile_dialog_window != NULL) gtk_widget_destroy(bw->openfile_dialog_window); if (bw->quit_dialog_window != NULL) gtk_widget_destroy(bw->quit_dialog_window); if (bw->findtext_dialog_window != NULL) gtk_widget_destroy(bw->findtext_dialog_window); if (bw->search_dialog_window != NULL) gtk_widget_destroy(bw->search_dialog_window); if (bw->proxy_passwd_dialog_window != NULL) gtk_widget_destroy(bw->proxy_passwd_dialog_window); if (bw->question_dialog_window != NULL) gtk_widget_destroy(bw->question_dialog_window); if (bw->menu_popup.over_page) gtk_widget_destroy(bw->menu_popup.over_page); if (bw->menu_popup.over_link) /* this also destroys menu_popup.over_image */ gtk_widget_destroy(bw->menu_popup.over_link); if (bw->menu_popup.over_back) gtk_widget_destroy(bw->menu_popup.over_back); if (bw->menu_popup.over_forw) gtk_widget_destroy(bw->menu_popup.over_forw); if (bw->menu_popup.over_bug) gtk_widget_destroy(bw->menu_popup.over_bug); if (bw->menu_popup.url) a_Url_free(bw->menu_popup.url); if (bw->menu_popup.url2) a_Url_free(bw->menu_popup.url2); if (bw->sens_idle_id) gtk_idle_remove(bw->sens_idle_id); for (i = 0; i < num_bw; i++) if (browser_window[i] == bw) { browser_window[i] = browser_window[--num_bw]; break; } /* free nav_stack and nav_expect stuff */ a_Nav_free(bw); g_free(bw->RootClients); g_free(bw->ImageClients); for (i = 0; i < bw->NumPageUrls; i++) a_Url_free(bw->PageUrls[i].Url); g_free(bw->PageUrls); g_free(bw); if (num_bw == 0) gtk_main_quit(); return FALSE;}/*=== Browser Window Interface Construction =================================*//* * Clear a text entry */static void Interface_entry_clear(GtkEntry *entry){ gtk_entry_set_text(entry, ""); gtk_widget_grab_focus(GTK_WIDGET(entry));}/* * Get the selection into the clear url button. * (cub = clear url button) */static void Interface_cub_get_selection(GtkWidget *widget, gpointer data){ /* Request the the primary selection as a string */ gtk_selection_convert (widget, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME);}/* * Receive the selection (from a paste event) * (cub = clear url button) */static void Interface_cub_selection_received(GtkWidget *widget, GtkSelectionData *selection_data, guint32 time, gpointer data){ BrowserWindow *bw = data; gchar *damn_string; _MSG("Interface_cub_selection_received:\n"); if (selection_data->length < 0) { DEBUG_MSG (1, "Selection retrieval failed\n"); return; } damn_string = g_strndup((gchar *)selection_data->data, selection_data->length); gtk_entry_set_text(GTK_ENTRY(bw->location), damn_string); gtk_widget_activate(GTK_WIDGET(bw->location)); g_free(damn_string);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -