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

📄 interface.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 4 页
字号:
/* * 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 <glib.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/time.h>#include <fcntl.h>#include "mgdconfig.h"#include "msg.h"#include "list.h"#include "misc.h"#include "dillo.h"#include "history.h"#include "nav.h"#include "io/url_io.h"#include "io/io.h"#include "interface.h"#include "prefs.h"#include "url.h"#include "dw_widget.h"#include "dw_viewport.h"#include "dw_container.h"#include "progressbar.h"#include "edillo.h"#include "mgwidget.h"#include "debug.h"#define DEBUG_LEVEL 0/* control id of browser window */#define IDC_NAV_BACKWARD    10#define IDC_NAV_FORWARD     20#define IDC_NAV_HOME        30#define IDC_NAV_RELOAD      40#define IDC_NAV_STOP        50 #define IDC_NAV_RESET       60 #define IDC_NAV_EXIT        70/* other option control*/#define IDC_DILLO           110#define IDC_LOCATION        111 #define IDC_MENUBAR         112 #define IDC_TOOLBAR         113#define IDC_STATUSBAR       114#define IDC_PROGRESSBAR     115#define STATUSBAR_HEIGHT  18#define PROGRESSBAR_WIDTH 100#define LOCATION_HEIGHT   24static BITMAP ntb_bmp;gal_pixel pixel;/* * 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;/* * 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]={0};   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, numstr,                        (bw->NumImagesGot == bw->NumImages) ? 0 : 1 );}/* * Set the sensitivity on back/forw buttons and menu entries. */#if 0 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;}#endif/* * Set the sensitivity on back/forw buttons and menu entries. */#if 0void a_Interface_set_button_sens(BrowserWindow *bw){   if (bw->sens_idle_id == 0)      bw->sens_idle_id = g_idle_add(                             (GFunc)Interface_sens_idle_func, bw);}#endif/* * 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, 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. */gboolean a_Interface_quit(BrowserWindow *bw){   gint i;   /* stop/abort open connections. */   a_Interface_stop(bw);#if 0   g_slist_free(bw->PanelHandles);   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);#endif   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 0   if (num_bw == 0)      gtk_main_quit();#endif   return FALSE;}/* * Open an url string. * The URL is not sent "as is", illegal chars are ripped out, * then it's fully parsed by a_Url_new(). */void a_Interface_open_url_string(gchar *text, BrowserWindow *bw){   gchar *new_text;   DilloUrl *url;   if (text && *text) {      /* Filter URL string */      new_text = a_Url_string_strip_delimiters(text);      url = a_Url_new(new_text, NULL, 0, 0, 0);      if (url) {         a_Nav_push(bw, url);         a_Url_free(url);      }      g_free(new_text);   }   //gtk_widget_grab_focus(GTK_BIN(bw->docwin)->child);}/*=== Browser Window Interface Construction =================================*//* * Clear a text entry */void Interface_entry_clear (BrowserWindow * bw){    if (bw->hwnd_location != -1)        SendMessage (bw->hwnd_location, MSG_SETTEXT, 0, (LPARAM)"");}/* * Create a pixmap and return it. */#if 0static 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);   printf("Interface_pixmap_new \n");   return (pixmapwid);}#endif/* * Set the bw's cursor type */#if 0void 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;   }   printf("a_Interface_set_cursor \n");}#endif/* * Connect button's "clicked" event with (key, key_mod) pair. */#if 0static void Interface_set_button_accel(GtkButton *button,                                       gint key,                                       gint key_mod,                                       GtkAccelGroup *accel_group){   gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel_group,                              key, key_mod, GTK_ACCEL_LOCKED);   printf("Interface_set_button_accel \n");}#endifHWND Interface_statusbar_new(HWND hwnd_parent, HWND hwnd){    HWND ctrl;    RECT rc_bw, rc;    int  title_height;    int  width;    int  height;    title_height = GetMainWinMetrics(MWM_CAPTIONY);    GetWindowRect(hwnd_parent,&rc_bw);    width = RECTW(rc_bw);    height = RECTH(rc_bw);    if (hwnd != -1)    {        GetWindowRect(hwnd, &rc);        width = width - RECTW(rc);     }    ctrl = CreateWindow (CTRL_STATIC, "",                           WS_VISIBLE | SS_LEFT | SS_NOTIFY | WS_BORDER, 			              IDC_STATUSBAR, 0,                           height - STATUSBAR_HEIGHT - title_height - 2,                          width, STATUSBAR_HEIGHT, hwnd_parent, 0);    return ctrl;}/* * Open an URL specified in the location entry, or in the open URL dialog. *///void a_Interface_entry_open_url(GtkWidget *widget, BrowserWindow *bw)

⌨️ 快捷键说明

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