⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface.c

📁 嵌入式浏览器Dillo源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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 <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 "list.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 "config.h"#include "bookmark.h"#include "prefs.h"#include "url.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.*/BrowserWindow **browser_window;gint num_bw, num_bw_max;/* * Initialize global data */void a_Interface_init(void){   num_bw = 0;   num_bw_max = 16;   browser_window = 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-- */   sprintf(numstr, "%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_tag = 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_tag != 0)      return;   bw->sens_idle_tag = 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-- */      sprintf(numstr, "%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:   g_print("Urls:\n");   for (i = 0; i < bw->NumPageUrls; i++)      g_print("%s\n", bw->PageUrls[i].Url);   g_print("---\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->question_dialog_window != NULL)      gtk_widget_destroy(bw->question_dialog_window);   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.url)      a_Url_free(bw->menu_popup.url);   if (bw->sens_idle_tag)      gtk_idle_remove(bw->sens_idle_tag);   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(GTK_ENTRY (entry), "");   gtk_widget_grab_focus(GTK_WIDGET(entry));}/* * Create a pixmap and return it. */static GtkWidget *Interface_pixmap_new(GtkWidget *parent, gchar **data){   GtkWidget *pixmapwid;   GdkPixmap *pixmap;   GdkBitmap *mask;   GtkStyle *style;   style = gtk_widget_get_style(parent);   pixmap = gdk_pixmap_create_from_xpm_d(parent->window, &mask,                                         &style->bg[GTK_STATE_NORMAL], data);   pixmapwid = gtk_pixmap_new(pixmap, mask);   return (pixmapwid);}/* * Set the bw's cursor type */void a_Interface_set_cursor(BrowserWindow *bw, GdkCursorType CursorType){   GdkCursor *cursor;   if ( bw->CursorType != CursorType ) {      cursor = gdk_cursor_new(CursorType);      gdk_window_set_cursor(bw->docwin->window, cursor);      gdk_cursor_destroy(cursor);      bw->CursorType = CursorType;   }}/* * Extract accelerator key from 'key_str' and * connect button's "clicked" event with {Alt | MOD2} + key */static void Interface_set_button_accel(GtkButton *button,                                       const char *key_str,                                       GtkAccelGroup *accel_group){   gint accel_key = tolower(key_str[1]);   gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel_group,                              accel_key, GDK_MOD1_MASK, GTK_ACCEL_LOCKED);   gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel_group,                              accel_key, GDK_MOD2_MASK, GTK_ACCEL_LOCKED);}/* * Create the "NEW" button and its location-entry. */static GtkWidget *Interface_locbar_new(BrowserWindow *bw){   GtkWidget *hbox, *toolbar;   hbox = gtk_hbox_new(FALSE, 0);   /* location entry */   bw->location = gtk_entry_new();   gtk_signal_connect(GTK_OBJECT(bw->location), "activate",                      (GtkSignalFunc) a_Interface_entry_open_url, bw);   toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);   gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);   GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);   bw->clear_url_button = gtk_toolbar_append_item(                             GTK_TOOLBAR(toolbar),                             NULL, "Clear the url-box!", "Toolbar/New",                             Interface_pixmap_new(bw->main_window, s_new_xpm),                             NULL, NULL);   gtk_signal_connect_object(GTK_OBJECT(bw->clear_url_button), "clicked",                             GTK_SIGNAL_FUNC (Interface_entry_clear),                             GTK_OBJECT(bw->location));   gtk_box_pack_start(GTK_BOX(hbox), toolbar, FALSE, FALSE, 0);   gtk_widget_show(toolbar);   gtk_box_pack_start(GTK_BOX(hbox), bw->location, TRUE, TRUE, 0);   gtk_widget_show(bw->location);   gtk_widget_show(hbox);   return (hbox);}/* * Create a new toolbar (Back, Forward, Home, Reload, Save and Stop buttons) */static GtkWidget *Interface_toolbar_new(BrowserWindow *bw, gint label){   GtkWidget *toolbar;   gboolean s = prefs.small_icons;   toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);   gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);   /* back button */   bw->back_button = gtk_toolbar_append_item(                        GTK_TOOLBAR(toolbar),                        label ? "Back" : NULL,                        "Go to previous page", "Toolbar/Back",                        Interface_pixmap_new(bw->main_window,                                             s ? s_left_xpm : left_xpm),                        (GtkSignalFunc) a_Commands_back_callback, bw);   gtk_widget_set_sensitive(bw->back_button, FALSE);   Interface_set_button_accel(GTK_BUTTON(bw->back_button), "_,",                              bw->accel_group);   gtk_signal_connect(GTK_OBJECT(bw->back_button), "button-press-event",                      GTK_SIGNAL_FUNC(a_Commands_navpress_callback), bw);   /* forward button */   bw->forw_button = gtk_toolbar_append_item(                        GTK_TOOLBAR(toolbar),                        label ? "Forward" : NULL,                        "Go to next page", "Toolbar/Forward",                        Interface_pixmap_new(bw->main_window,                                             s ? s_right_xpm : right_xpm),                        (GtkSignalFunc) a_Commands_forw_callback, bw);   gtk_widget_set_sensitive(bw->forw_button, FALSE);   Interface_set_button_accel(GTK_BUTTON(bw->forw_button), "_.",                              bw->accel_group);   gtk_signal_connect(GTK_OBJECT(bw->forw_button), "button-press-event",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -