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

📄 gtk2drawing.c

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 C
📖 第 1 页 / 共 5 页
字号:
        setup_widget_prototype(gScrolledWindowWidget);    }    return MOZ_GTK_SUCCESS;}static GtkStateTypeConvertGtkState(GtkWidgetState* state){    if (state->disabled)        return GTK_STATE_INSENSITIVE;    else if (state->depressed)        return (state->inHover ? GTK_STATE_PRELIGHT : GTK_STATE_ACTIVE);    else if (state->inHover)        return (state->active ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT);    else        return GTK_STATE_NORMAL;}static gintTSOffsetStyleGCArray(GdkGC** gcs, gint xorigin, gint yorigin){    int i;    /* there are 5 gc's in each array, for each of the widget states */    for (i = 0; i < 5; ++i)        gdk_gc_set_ts_origin(gcs[i], xorigin, yorigin);    return MOZ_GTK_SUCCESS;}static gintTSOffsetStyleGCs(GtkStyle* style, gint xorigin, gint yorigin){    TSOffsetStyleGCArray(style->fg_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->bg_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->light_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->dark_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->mid_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->text_gc, xorigin, yorigin);    TSOffsetStyleGCArray(style->base_gc, xorigin, yorigin);    gdk_gc_set_ts_origin(style->black_gc, xorigin, yorigin);    gdk_gc_set_ts_origin(style->white_gc, xorigin, yorigin);    return MOZ_GTK_SUCCESS;}static gintmoz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect,                     GdkRectangle* cliprect, GtkWidgetState* state,                     GtkReliefStyle relief, GtkWidget* widget,                     GtkTextDirection direction){    GtkShadowType shadow_type;    GtkStyle* style = widget->style;    GtkStateType button_state = ConvertGtkState(state);    gint x = rect->x, y=rect->y, width=rect->width, height=rect->height;    gboolean interior_focus;    gint focus_width, focus_pad;    moz_gtk_widget_get_focus(widget, &interior_focus, &focus_width, &focus_pad);    if (WINDOW_IS_MAPPED(drawable)) {        gdk_window_set_back_pixmap(drawable, NULL, TRUE);        gdk_window_clear_area(drawable, cliprect->x, cliprect->y,                              cliprect->width, cliprect->height);    }    gtk_widget_set_state(widget, button_state);    gtk_widget_set_direction(widget, direction);    if (state->isDefault)        GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_DEFAULT);    GTK_BUTTON(widget)->relief = relief;    /* Some theme engines love to cause us pain in that gtk_paint_focus is a       no-op on buttons and button-like widgets. They only listen to this flag. */    if (state->focused && !state->disabled)        GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS);    if (!interior_focus && state->focused) {        x += focus_width + focus_pad;        y += focus_width + focus_pad;        width -= 2 * (focus_width + focus_pad);        height -= 2 * (focus_width + focus_pad);    }    shadow_type = button_state == GTK_STATE_ACTIVE ||                      state->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;     if (state->isDefault && relief == GTK_RELIEF_NORMAL) {        gtk_paint_box(style, drawable, button_state, shadow_type, cliprect,                      widget, "buttondefault", x, y, width, height);                       }     if (relief != GTK_RELIEF_NONE || state->depressed ||           (button_state != GTK_STATE_NORMAL &&            button_state != GTK_STATE_INSENSITIVE)) {        TSOffsetStyleGCs(style, x, y);        /* the following line can trigger an assertion (Crux theme)           file ../../gdk/gdkwindow.c: line 1846 (gdk_window_clear_area):           assertion `GDK_IS_WINDOW (window)' failed */        gtk_paint_box(style, drawable, button_state, shadow_type, cliprect,                      widget, "button", x, y, width, height);    }    if (state->focused) {        if (interior_focus) {            x += widget->style->xthickness + focus_pad;            y += widget->style->ythickness + focus_pad;            width -= 2 * (widget->style->xthickness + focus_pad);            height -= 2 * (widget->style->ythickness + focus_pad);        } else {            x -= focus_width + focus_pad;            y -= focus_width + focus_pad;            width += 2 * (focus_width + focus_pad);            height += 2 * (focus_width + focus_pad);        }        TSOffsetStyleGCs(style, x, y);        gtk_paint_focus(style, drawable, button_state, cliprect,                        widget, "button", x, y, width, height);    }    GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_DEFAULT);    GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS);    return MOZ_GTK_SUCCESS;}gintmoz_gtk_init(){    GtkWidgetClass *entry_class;    is_initialized = TRUE;    have_arrow_scaling = (gtk_major_version > 2 ||                          (gtk_major_version == 2 && gtk_minor_version >= 12));    have_2_10 = (gtk_major_version > 2 ||                 (gtk_major_version == 2 && gtk_minor_version >= 10));    /* Add style property to GtkEntry.     * Adding the style property to the normal GtkEntry class means that it     * will work without issues inside GtkComboBox and for Spinbuttons. */    entry_class = g_type_class_ref(GTK_TYPE_ENTRY);    gtk_widget_class_install_style_property(entry_class,        g_param_spec_boolean("honors-transparent-bg-hint",                             "Transparent BG enabling flag",                             "If TRUE, the theme is able to draw the GtkEntry on non-prefilled background.",                             FALSE,                             G_PARAM_READWRITE));    return MOZ_GTK_SUCCESS;}gintmoz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing){    ensure_checkbox_widget();    gtk_widget_style_get (gCheckboxWidget,                          "indicator_size", indicator_size,                          "indicator_spacing", indicator_spacing,                          NULL);    return MOZ_GTK_SUCCESS;}gintmoz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing){    ensure_radiobutton_widget();    gtk_widget_style_get (gRadiobuttonWidget,                          "indicator_size", indicator_size,                          "indicator_spacing", indicator_spacing,                          NULL);    return MOZ_GTK_SUCCESS;}gintmoz_gtk_widget_get_focus(GtkWidget* widget, gboolean* interior_focus,                         gint* focus_width, gint* focus_pad) {    gtk_widget_style_get (widget,                          "interior-focus", interior_focus,                          "focus-line-width", focus_width,                          "focus-padding", focus_pad,                          NULL);    return MOZ_GTK_SUCCESS;}gintmoz_gtk_splitter_get_metrics(gint orientation, gint* size){    if (orientation == GTK_ORIENTATION_HORIZONTAL) {        ensure_hpaned_widget();        gtk_widget_style_get(gHPanedWidget, "handle_size", size, NULL);    } else {        ensure_vpaned_widget();        gtk_widget_style_get(gVPanedWidget, "handle_size", size, NULL);    }    return MOZ_GTK_SUCCESS;}gintmoz_gtk_button_get_inner_border(GtkWidget* widget, GtkBorder* inner_border){    static const GtkBorder default_inner_border = { 1, 1, 1, 1 };    GtkBorder *tmp_border = NULL;    if (have_2_10)        gtk_widget_style_get (widget, "inner-border", &tmp_border, NULL);    if (tmp_border) {        *inner_border = *tmp_border;        gtk_border_free(tmp_border);    }    else        *inner_border = default_inner_border;    return MOZ_GTK_SUCCESS;}static gintmoz_gtk_toggle_paint(GdkDrawable* drawable, GdkRectangle* rect,                     GdkRectangle* cliprect, GtkWidgetState* state,                     gboolean selected, gboolean isradio,                     GtkTextDirection direction){    GtkStateType state_type = ConvertGtkState(state);    GtkShadowType shadow_type = (selected)?GTK_SHADOW_IN:GTK_SHADOW_OUT;    gint indicator_size, indicator_spacing;    gint x, y, width, height;    gint focus_x, focus_y, focus_width, focus_height;    GtkWidget *w;    GtkStyle *style;    if (isradio) {        moz_gtk_radio_get_metrics(&indicator_size, &indicator_spacing);        w = gRadiobuttonWidget;    } else {        moz_gtk_checkbox_get_metrics(&indicator_size, &indicator_spacing);        w = gCheckboxWidget;    }    /*     * vertically center in the box, since XUL sometimes ignores our     * GetMinimumWidgetSize in the vertical dimension     */    x = rect->x;    y = rect->y + (rect->height - indicator_size) / 2;    width = indicator_size;    height = indicator_size;    focus_x = x - indicator_spacing;    focus_y = y - indicator_spacing;    focus_width = width + 2 * indicator_spacing;    focus_height = height + 2 * indicator_spacing;      style = w->style;    TSOffsetStyleGCs(style, x, y);    gtk_widget_set_sensitive(w, !state->disabled);    gtk_widget_set_direction(w, direction);    GTK_TOGGLE_BUTTON(w)->active = selected;          if (isradio) {        gtk_paint_option(style, drawable, state_type, shadow_type, cliprect,                         gRadiobuttonWidget, "radiobutton", x, y,                         width, height);        if (state->focused) {            gtk_paint_focus(style, drawable, GTK_STATE_ACTIVE, cliprect,                            gRadiobuttonWidget, "radiobutton", focus_x, focus_y,                            focus_width, focus_height);        }    }    else {        gtk_paint_check(style, drawable, state_type, shadow_type, cliprect,                         gCheckboxWidget, "checkbutton", x, y, width, height);        if (state->focused) {            gtk_paint_focus(style, drawable, GTK_STATE_ACTIVE, cliprect,                            gCheckboxWidget, "checkbutton", focus_x, focus_y,                            focus_width, focus_height);        }    }    return MOZ_GTK_SUCCESS;}static gintcalculate_button_inner_rect(GtkWidget* button, GdkRectangle* rect,                            GdkRectangle* inner_rect,                            GtkTextDirection direction,                            gboolean ignore_focus){    GtkBorder inner_border;    gboolean interior_focus;    gint focus_width, focus_pad;    GtkStyle* style;    style = button->style;    /* This mirrors gtkbutton's child positioning */    moz_gtk_button_get_inner_border(button, &inner_border);    moz_gtk_widget_get_focus(button, &interior_focus,                             &focus_width, &focus_pad);    if (ignore_focus)        focus_width = focus_pad = 0;    inner_rect->x = rect->x + XTHICKNESS(style) + focus_width + focus_pad;    inner_rect->x += direction == GTK_TEXT_DIR_LTR ?                        inner_border.left : inner_border.right;    inner_rect->y = rect->y + inner_border.top + YTHICKNESS(style) +                    focus_width + focus_pad;    inner_rect->width = MAX(1, rect->width - inner_border.left -       inner_border.right - (XTHICKNESS(style) + focus_pad + focus_width) * 2);    inner_rect->height = MAX(1, rect->height - inner_border.top -       inner_border.bottom - (YTHICKNESS(style) + focus_pad + focus_width) * 2);    return MOZ_GTK_SUCCESS;}static gintcalculate_arrow_rect(GtkWidget* arrow, GdkRectangle* rect,                     GdkRectangle* arrow_rect, GtkTextDirection direction){    /* defined in gtkarrow.c */    gfloat arrow_scaling = 0.7;    gfloat xalign, xpad;    gint extent;    GtkMisc* misc = GTK_MISC(arrow);    if (have_arrow_scaling)        gtk_widget_style_get(arrow, "arrow_scaling", &arrow_scaling, NULL);    extent = MIN((rect->width - misc->xpad * 2),                 (rect->height - misc->ypad * 2)) * arrow_scaling;    xalign = direction == GTK_TEXT_DIR_LTR ? misc->xalign : 1.0 - misc->xalign;    xpad = misc->xpad + (rect->width - extent) * xalign;    arrow_rect->x = direction == GTK_TEXT_DIR_LTR ?                        floor(rect->x + xpad) : ceil(rect->x + xpad);    arrow_rect->y = floor(rect->y + misc->ypad +                          ((rect->height - extent) * misc->yalign));    arrow_rect->width = arrow_rect->height = extent;    return MOZ_GTK_SUCCESS;}static gintmoz_gtk_scrollbar_button_paint(GdkDrawable* drawable, GdkRectangle* rect,                               GdkRectangle* cliprect, GtkWidgetState* state,                               GtkScrollbarButtonFlags flags,                               GtkTextDirection direction){    GtkStateType state_type = ConvertGtkState(state);    GtkShadowType shadow_type = (state->active) ?        GTK_SHADOW_IN : GTK_SHADOW_OUT;    GdkRectangle arrow_rect;    GtkStyle* style;    GtkWidget *scrollbar;    GtkArrowType arrow_type;    gint arrow_displacement_x, arrow_displacement_y;    const char* detail = (flags & MOZ_GTK_STEPPER_VERTICAL) ?                           "vscrollbar" : "hscrollbar";    ensure_scrollbar_widget();

⌨️ 快捷键说明

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