📄 html.c
字号:
#if 0/* * Popup the image menu ("button_press_event" callback of image) */static gboolean Html_image_menu (DwWidget *widget, Sint32 x, Sint32 y, GdkEventButton *event, BrowserWindow *bw){ DwImage *image = DW_IMAGE (widget); if (event->button == 3 && image->url) { a_Menu_popup_set_url (bw, image->url); gtk_menu_popup(GTK_MENU (bw->menu_popup.over_image), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE; } return FALSE;}/* * Popup the page menu ("button_press_event" callback of the viewport) */static int Html_page_menu (MGWidget *viewport, GdkEventButton *event, BrowserWindow *bw){ POINT bug_pix; if (event->button == 3) { /* set the working URL */ a_Menu_popup_set_url(bw, a_History_get_url(NAV_TOP(bw))); /* set "View page Bugs" sensitivity */ bug_pix = gtk_object_get_data(GTK_OBJECT(bw->status_bug_meter), "bug"); gtk_widget_set_sensitive(bw->viewbugs_menuitem, GTK_WIDGET_VISIBLE(GTK_WIDGET(bug_pix))); gtk_menu_popup(GTK_MENU(bw->menu_popup.over_page), NULL, NULL, NULL, NULL, event->button, event->time); return TRUE; } else return FALSE;}#endif/* * Connect all signals of a page or an image. */static void Html_connect_signals (DilloHtml *html, GObject *widget){ g_signal_connect (widget, "link_entered", G_CALLBACK (Html_handle_status), (gpointer)html->linkblock);#if 0 gtk_signal_connect (widget, "link_pressed", GTK_SIGNAL_FUNC(Html_link_menu), (gpointer)html->linkblock);#endif g_signal_connect (widget, "link_clicked", G_CALLBACK (Html_link_clicked), (gpointer)html->linkblock);}/* * Create a new link in the linkblock, set it as the url's parent * and return the index. */static int Html_set_new_link (DilloHtml *html, DilloUrl **url){ int nl; nl = html->linkblock->num_links; a_List_add (html->linkblock->links, nl, html->linkblock->num_links_max); html->linkblock->links[nl] = (*url) ? *url : NULL; return html->linkblock->num_links++;}/* * Allocate and insert form information into the Html linkblock */static int Html_form_new (DilloHtmlLB *html_lb, DilloHtmlMethod method, const DilloUrl *action, DilloHtmlEnc enc){ int nf; a_List_add (html_lb->forms, html_lb->num_forms, html_lb->num_forms_max); nf = html_lb->num_forms; html_lb->forms[nf].method = method; html_lb->forms[nf].action = a_Url_dup(action); html_lb->forms[nf].enc = enc; html_lb->forms[nf].num_inputs = 0; html_lb->forms[nf].num_inputs_max = 4; html_lb->forms[nf].inputs = NULL; html_lb->forms[nf].num_entry_fields = 0; html_lb->forms[nf].num_submit_buttons = 0; html_lb->num_forms++; _MSG("Html_form_new: action=%s nform=%d\n", action, nf); return nf;}/* * Change one toplevel attribute. var should be an identifier. val is * only evaluated once, so you can safely use a function call for it. */#define HTML_SET_TOP_ATTR(html, var, val) \ do { \ DwStyle style_attrs, *old_style; \ \ old_style = (html)->stack[(html)->stack_top].style; \ style_attrs = *old_style; \ style_attrs.var = (val); \ (html)->stack[(html)->stack_top].style = \ a_Dw_style_new (&style_attrs, html->bw->main_window); \ a_Dw_style_unref (old_style); \ } while (FALSE)/* * Set the font at the top of the stack. BImask specifies which * attributes in BI should be changed. */static void Html_set_top_font (DilloHtml *html, char *name, int size, int BI, int BImask){ DwStyleFont font_attrs; font_attrs = *html->stack[(html)->stack_top].style->font; if ( name ) font_attrs.name = name; if ( size ) font_attrs.size = size; if ( BImask & 1 ) font_attrs.weight = (BI & 1) ? 700 : 400; if ( BImask & 2 ) font_attrs.style = (BI & 2) ? (prefs.use_oblique ? DW_STYLE_FONT_STYLE_OBLIQUE : DW_STYLE_FONT_STYLE_ITALIC) : DW_STYLE_FONT_STYLE_NORMAL; HTML_SET_TOP_ATTR (html, font, a_Dw_style_font_new (&font_attrs, html->logfont?html->logfont->charset:NULL));}/* * Evaluates the ALIGN attribute (left|center|right|justify) and * sets the style at the top of the stack. */static void Html_tag_set_align_attr(DilloHtml *html, char *tag, int tagsize){ const char *align, *charattr; if ((align = Html_get_attr(html, tag, tagsize, "align"))) { if (strcasecmp (align, "left") == 0) HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_LEFT); else if (strcasecmp (align, "right") == 0) HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_RIGHT); else if (strcasecmp (align, "center") == 0) HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_CENTER); else if (strcasecmp (align, "justify") == 0) HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_JUSTIFY); else if (strcasecmp (align, "char") == 0) { /* todo: Actually not supported for <p> etc. */ HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_STRING); if ((charattr = Html_get_attr(html, tag, tagsize, "char"))) { if (charattr[0] == 0) /* todo: ALIGN=" ", and even ALIGN="&32;" will reult in * an empty string (don't know whether the latter is * correct, has to be clarified with the specs), so * that for empty strings, " " is assumed. */ HTML_SET_TOP_ATTR (html, text_align_char, ' '); else HTML_SET_TOP_ATTR (html, text_align_char, charattr[0]); } else /* todo: Examine LANG attr of <html>. */ HTML_SET_TOP_ATTR (html, text_align_char, '.'); } }}/* * Evaluates the VALIGN attribute (top|bottom|middle|baseline) and * sets the style in style_attrs. Returns TRUE when set. */static gboolean Html_tag_set_valign_attr(DilloHtml *html, char *tag, int tagsize, DwStyle *style_attrs){ const char *attr; if ((attr = Html_get_attr(html, tag, tagsize, "valign"))) { if (strcasecmp (attr, "top") == 0) style_attrs->valign = DW_STYLE_VALIGN_TOP; else if (strcasecmp (attr, "bottom") == 0) style_attrs->valign = DW_STYLE_VALIGN_BOTTOM; else if (strcasecmp (attr, "baseline") == 0) style_attrs->valign = DW_STYLE_VALIGN_BASELINE; else style_attrs->valign = DW_STYLE_VALIGN_MIDDLE; return TRUE; } else return FALSE;}/* * Add a new DwPage into the current DwPage, for indentation. * left and right are the horizontal indentation amounts, space is the * vertical space around the block. */static void Html_add_indented_widget (DilloHtml *html, DwWidget *page, int left, int right, int space){ DwStyle style_attrs, *style; style_attrs = *html->stack[html->stack_top].style; a_Dw_style_box_set_val(&style_attrs.margin, 0); a_Dw_style_box_set_val(&style_attrs.border_width, 0); a_Dw_style_box_set_val(&style_attrs.padding, 0); /* Activate this for debugging */#if 0 a_Dw_style_box_set_val(&style_attrs.border_width, 1); a_Dw_style_box_set_border_color (&style_attrs, a_Dw_style_shaded_color_new(style_attrs.color->color_val)); a_Dw_style_box_set_border_style(&style_attrs, DW_STYLE_BORDER_DASHED);#endif style_attrs.margin.left = left; style_attrs.margin.right = right; style = a_Dw_style_new (&style_attrs, html->bw->main_window); a_Dw_page_add_parbreak (DW_PAGE (html->dw), space, style); a_Dw_page_add_widget (DW_PAGE (html->dw), page, style); a_Dw_page_add_parbreak (DW_PAGE (html->dw), space, style); html->stack[html->stack_top].page = html->dw = page; html->stack[html->stack_top].hand_over_break = TRUE; a_Dw_style_unref (style); /* Handle it when the user clicks on a link */ Html_connect_signals(html, G_OBJECT(page));}/* * Create and add a new indented DwPage to the current DwPage */static void Html_add_indented (DilloHtml *html, int left, int right, int space){ DwWidget *page = a_Dw_page_new (); Html_add_indented_widget (html, page, left, right, space);}/* * Given a font_size, this will return the correct 'level'. * (or the closest, if the exact level isn't found). */static int Html_fontsize_to_level(int fontsize){ int i, level; double normalized_size = fontsize / prefs.font_factor, approximation = FontSizes[FontSizesNum-1] + 1; for (i = level = 0; i < FontSizesNum; i++) if (approximation >= fabs(normalized_size - FontSizes[i])) { approximation = fabs(normalized_size - FontSizes[i]); level = i; } else { break; } return level;}/* * Given a level of a font, this will return the correct 'size'. */static int Html_level_to_fontsize (int level){ level = MAX(0, level); level = MIN(FontSizesNum - 1, level); // return rint(FontSizes[level]*prefs.font_factor); return (int)(FontSizes[level]*prefs.font_factor + 0.5);}/* * Miscelaneous initializations for a DwPage */static void Html_set_dwpage(DilloHtml *html){ DwWidget *widget; DwPage *page; DwStyle style_attrs; DwStyleFont font; if (html->dw) return; widget = a_Dw_page_new (); page = DW_PAGE (widget); html->dw = html->stack[0].page = widget; /* Create a dummy font, attribute, and tag for the bottom of the stack. */ font.name = prefs.vw_fontname; /* Helvetica */ font.size = Html_level_to_fontsize(FontSizesBase); font.weight = 400; font.style = DW_STYLE_FONT_STYLE_NORMAL; a_Dw_style_init_values (&style_attrs, html->bw->main_window); style_attrs.font = a_Dw_style_font_new (&font, html->logfont?html->logfont->charset:NULL); style_attrs.color = a_Dw_style_color_new (prefs.text_color, html->bw->main_window); html->stack[0].style = a_Dw_style_new (&style_attrs, html->bw->main_window); html->stack[0].table_cell_style = NULL; /* Handle it when the user clicks on a link */ Html_connect_signals (html, G_OBJECT(widget));#if 0 gtk_signal_connect_while_alive ( GTK_OBJECT(GTK_BIN(html->bw->docwin)->child), "button_press_event", GTK_SIGNAL_FUNC(Html_page_menu), (gpointer)html->bw, GTK_OBJECT (page)); /* Connect the "bug meter" button-press to the linkblock */ gtk_signal_connect_while_alive( GTK_OBJECT (html->bw->status_bug_meter), "button_press_event", GTK_SIGNAL_FUNC (a_Commands_view_page_bugs_callback), (gpointer)html->linkblock, GTK_OBJECT (page)); /* also connect with the "View page Bugs" menuitem */ gtk_signal_connect_while_alive( GTK_OBJECT (html->bw->viewbugs_menuitem), "button_press_event", GTK_SIGNAL_FUNC (a_Commands_view_page_bugs_callback), (gpointer)html->linkblock, GTK_OBJECT (page));#else /* Destroy the linkblock when the DwPage is destroyed */ g_signal_connect_swapped (G_OBJECT(widget), "destroy", G_CALLBACK (Html_lb_free), (gpointer)html->linkblock); printf ("Create HTML Page and register the callbacks.\n");#endif}static void Html_find_charset (DilloHtml *html, const char* content){ char *my_con; char *charset; char fontname [256]; if (html->logfont) return; my_con = g_strdup (content); charset = my_con; while (*charset) { *charset = tolower (*charset); charset ++; } charset = strstr (my_con, "charset"); if (charset == NULL) { charset = "gb2312"; /* this is the default charset */ } else { int tmp; /* find the charset defined in head of this page */ charset = strchr (charset, '='); charset ++; while (*charset == ' ' || *charset == '\t') charset ++; tmp = strcspn (charset, " \t\n"); charset [tmp] = '\0'; } printf ("The charset defined by this page: %s\n", charset); strcpy (fontname, "*-fixed-rrncnn-*-12-"); strcat (fontname, charset); html->logfont = CreateLogFontByName (fontname); g_free (my_con);}/* * Create and initialize a new DilloHtml structure */static DilloHtml *Html_new(BrowserWindow *bw, const DilloUrl *url){ DilloHtml *html; html = g_malloc0 (sizeof (DilloHtml)); html->Start_Buf = NULL; html->Start_Ofs = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -