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

📄 mgdillo.c

📁 飞漫公司的minigui的1.6.8收费增值版本的demon等示例程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ** $Id: mgdillo.c,v 1.7 2005/02/19 11:30:26 weiym Exp $**** Copyright (C) 2004 Feynman Software.**** License: GPL*/#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "mgdillo.h"#include "cache.h"#include "html.h"#include "web.h"#include "prefs.h"#include "history.h"#include "nav.h"#include "dillo.h"#include "splash.h"static void set_default_style (DilloWeb* Web, DwWidget* dw){    DwStyle style_attrs, *style;    DwStyleFont font;    /* Set a style for the widget */    font.name = prefs.vw_fontname; /* must be defined */    font.size = (int)(12.0 * prefs.font_factor + 0.5);    font.weight = 400;    font.style = DW_STYLE_FONT_STYLE_NORMAL;    a_Dw_style_init_values (&style_attrs, Web->bw->main_window);    a_Dw_style_box_set_val (&style_attrs.margin, 5);    style_attrs.font = a_Dw_style_font_new (&font, NULL);    style_attrs.color =         a_Dw_style_color_new (prefs.text_color, Web->bw->main_window);    style_attrs.background_color =         a_Dw_style_color_new (prefs.bg_color, Web->bw->main_window);    style = a_Dw_style_new (&style_attrs, Web->bw->main_window);    a_Dw_widget_set_style (dw, style);    a_Dw_style_unref (style);}static void reset_content (BrowserWindow* bw){    DwViewport* viewport = (DwViewport*)bw->viewport;    if (viewport == NULL || viewport->child == NULL) {        return;    }    if (viewport->web) {        a_Web_free (viewport->web);        viewport->web = NULL;    }    a_Dw_widget_destroy (viewport->child);    Dw_viewport_remove_dw (viewport);}#define UT_ABOUT        1#define UT_FILE         2#define UT_NOTSUPPORTED 0static int check_url (const DilloUrl* url){    printf ("URL info: scheme: %s, path: %s, fragment: %s\n",             URL_SCHEME_(url),            URL_PATH_(url),            URL_FRAGMENT_(url));    if (strcasecmp (URL_SCHEME_(url), "about") == 0)        return UT_ABOUT;    if (strcasecmp (URL_SCHEME_(url), "file") == 0)        return UT_FILE;    return UT_NOTSUPPORTED;}#ifdef WIN32static void open_file (CacheClient_t* Client, CA_Callback_t callback, const DilloUrl* url){	int ret;    struct stat st;    char* err_txt = NULL;    int fd = -1;    char* buff = NULL;    char* path = strdup (URL_PATH_(url));    int i = 0;    while (path [i]) {        if (path [i] == '/')            path [i] = '\\';        i++;    }    ret = stat (path, &st);    if (ret == -1) {        switch (errno) {        case EACCES:            err_txt = "Permission denied.";            break;        case ENOENT:            err_txt = "A component of the path file_name does not exist, or the path is an empty string.";            break;        case ENOTDIR:            err_txt = "A component of the path is not a directory.";            break;        case EFAULT:            err_txt = "Bad address.";            break;        case ENOMEM:            err_txt = "Out of memory (i.e. kernel memory).";            break;        case ENAMETOOLONG:            err_txt = "File name too long.";            break;        default:            err_txt = "Unknow error.";            break;        }    }    else {		switch (st.st_mode & _S_IFMT) {		case _S_IFDIR:		    err_txt = "Attempt to open a directory.";			break;		case _S_IFCHR:            err_txt = "Attempt to open a character device.";			break;		case _S_IFIFO:            err_txt = "Attempt to open a fifo.";			break;		default:			fd = open (URL_PATH_(url), O_RDONLY);            if (fd < 0) {                err_txt = "Unknown error occurred when open the file.";            }            else {                buff = malloc (st.st_size);                if (buff == NULL)                    err_txt = "Not enough memory.";            }			break;        }	}	    if (err_txt) {        char html [1024];        strcpy (html, "<html><body><p>");        strcat (html, err_txt);        strcat (html, "</p></body></html>");        Client->Buf = html;        Client->BufSize = strlen (html);        callback (1, Client);    }    else if (fd >= 0 && buff) {        size_t count;        count = read (fd, buff, st.st_size);        Client->Buf = buff;        Client->BufSize = count;        callback (1, Client);    }    free (path);    if (buff)        free (buff);    if (fd >= 0)        close (fd);}#elsestatic void open_file (CacheClient_t* Client, CA_Callback_t callback, const DilloUrl* url){    int ret;    struct stat st;    char* err_txt = NULL;    int fd = -1;    char* buff = NULL;    ret = stat (URL_PATH_(url), &st);    if (ret == -1) {        switch (errno) {        case EACCES:            err_txt = "Permission denied.";            break;        case ENOENT:            err_txt = "A component of the path file_name does not exist, or the path is an empty string.";            break;        case ENOTDIR:            err_txt = "A component of the path is not a directory.";            break;        case ELOOP:            err_txt = "Too many symbolic links encountered while traversing the path.";            break;        case EFAULT:            err_txt = "Bad address.";            break;        case ENOMEM:            err_txt = "Out of memory (i.e. kernel memory).";            break;        case ENAMETOOLONG:            err_txt = "File name too long.";            break;        default:            err_txt = "Unknow error.";            break;        }    }    else {        if (S_ISDIR (st.st_mode)) {            err_txt = "Attempt to open a directory.";        }        else if (S_ISCHR (st.st_mode)) {            err_txt = "Attempt to open a character device.";        }        else if (S_ISBLK (st.st_mode)) {            err_txt = "Attempt to open a block device.";        }        else if (S_ISFIFO (st.st_mode)) {            err_txt = "Attempt to open a fifo.";        }        else if (S_ISSOCK (st.st_mode)) {            err_txt = "Attempt to open a socket.";        }        else {            fd = open (URL_PATH_(url), O_RDONLY);            if (fd < 0) {                err_txt = "Unknown error occurred when open the file.";            }            else {                buff = malloc (st.st_size);                if (buff == NULL)                    err_txt = "Not enough memory.";            }        }    }    if (err_txt) {        char html [1024];        strcpy (html, "<html><body><p>");        strcat (html, err_txt);        strcat (html, "</p></body></html>");        Client->Buf = html;        Client->BufSize = strlen (html);        callback (1, Client);    }    else if (fd >= 0 && buff) {        size_t count;        count = read (fd, buff, st.st_size);        Client->Buf = buff;        Client->BufSize = count;        callback (1, Client);    }    if (buff)        free (buff);    if (fd >= 0)        close (fd);}#endifstatic int write_url (DilloWeb* web, DwViewport* viewport, const DilloUrl* url){    CA_Callback_t callback;    CacheClient_t Client;    Client.Key = 0;    web->page = a_Html_text (NULL, web, &callback, &Client.CbData);    set_default_style (web, web->page);    a_Dw_viewport_add_dw (viewport, web->page);    switch (check_url (url)) {    case UT_FILE:        open_file (&Client, callback, url);        break;    case UT_ABOUT:        if (strcmp (URL_PATH_(url), "blank") == 0) {            Client.Buf = dillo_blank;            Client.BufSize = sizeof (dillo_blank);        }        else /* if (strcmp (URL_PATH_(url), "splash") == 0) */ {            Client.Buf = dillo_splash;            Client.BufSize = sizeof (dillo_splash);        }        callback (1, &Client);        break;    case UT_NOTSUPPORTED:        Client.Buf = dillo_error;        Client.BufSize = sizeof (dillo_error);        callback (1, &Client);        break;    }    return 0;}static BOOL open_url (BrowserWindow* bw, DilloUrl* start_url){    DwViewport* viewport = (DwViewport*)bw->viewport;    DilloWeb* web;    if (viewport->child) {        if (a_Url_cmp (viewport->web->url, start_url) == 0) {            printf ("Dillo on MiniGUI: You requested the same URL.\n");            if (strcmp (URL_FRAGMENT(viewport->web->url), URL_FRAGMENT(start_url))) {                a_Dw_viewport_set_anchor (viewport, URL_FRAGMENT(start_url));                return TRUE;            }            return FALSE;        }        reset_content (bw);    }    web = a_Web_new (start_url);    web->bw = bw;    write_url (web, viewport, start_url);    viewport->web = web;    viewport->world_x = viewport->world_y = 0;    Dw_viewport_calc_size (viewport);    if (URL_FRAGMENT_(start_url)) {        a_Dw_viewport_set_anchor (viewport, URL_FRAGMENT_(start_url));    }    return TRUE;}int MGD_open_url (HWND hwnd, const char* url_str){    BrowserWindow* bw = (BrowserWindow*) GetWindowAdditionalData2 (hwnd);    DwViewport* viewport = (DwViewport*)bw->viewport;    DilloUrl* start_url;    if (viewport == NULL)        return URL_ERROR;    start_url = a_Url_new (url_str, NULL, 0, 0, 0);    if (open_url (bw, start_url)) {        a_Nav_new_url (bw, start_url);    }    a_Url_free (start_url);    return 0;}static void on_create (HWND hwnd){    BrowserWindow* bw;    bw = g_new0 (BrowserWindow, 1);    bw->main_window = GetParent (hwnd);    bw->docwin = hwnd;    bw->viewport = NULL;    a_Nav_init(bw);    SetWindowAdditionalData2 (hwnd, (DWORD)bw);    SendNotifyMessage (hwnd, MGD_REALIZED, 0, 0);}

⌨️ 快捷键说明

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