Esempio n. 1
0
static void
hippo_canvas_grip_paint_below_children(HippoCanvasBox  *box,
                                       cairo_t         *cr,
                                       HippoRectangle  *damaged_box)
{
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_grip_parent_class)->paint_below_children(box, cr, damaged_box);

#if 0
    HippoCanvasGrip *grip = HIPPO_CANVAS_GRIP(box);
    int x, y, w, h;

    get_grip_request(grip, &w, &h);

    hippo_canvas_box_align(box, w, h, &x, &y, &w, &h);

    cairo_rectangle(cr, x, y, w, h);
    cairo_clip(cr);

    if (grip->prelighted)
        hippo_cairo_set_source_rgba32(cr,
                                      hippo_canvas_context_get_color(box->context,
                                              HIPPO_STOCK_COLOR_BG_PRELIGHT));
    else
        hippo_cairo_set_source_rgba32(cr,
                                      hippo_canvas_context_get_color(box->context,
                                              HIPPO_STOCK_COLOR_BG_NORMAL));

    cairo_paint(cr);
#endif
}
Esempio n. 2
0
static void
hippo_canvas_text_get_content_width_request(HippoCanvasBox *box,
                                            int            *min_width_p,
                                            int            *natural_width_p)
{
    HippoCanvasText *text = HIPPO_CANVAS_TEXT(box);
    int children_min_width, children_natural_width;
    int layout_width;
    
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_text_parent_class)->get_content_width_request(box,
                                                                                      &children_min_width,
                                                                                      &children_natural_width);
    if (box->context != NULL) {
        PangoLayout *layout = create_layout(text, -1);
        pango_layout_get_size(layout, &layout_width, NULL);
        layout_width /= PANGO_SCALE;
        g_object_unref(layout);
    } else {
        layout_width = 0;
    }

    if (min_width_p) {
        if (text->size_mode == HIPPO_CANVAS_SIZE_FULL_WIDTH)
            *min_width_p = MAX(children_min_width, layout_width);
        else
            *min_width_p = children_min_width;
    }

    if (natural_width_p) {
        *natural_width_p = MAX(children_natural_width, layout_width);
    }
}
Esempio n. 3
0
static void
hippo_canvas_text_get_content_height_request(HippoCanvasBox  *box,
                                             int              for_width,
                                             int             *min_height_p,
                                             int             *natural_height_p)
{
    HippoCanvasText *text = HIPPO_CANVAS_TEXT(box);
    int children_min_height, children_natural_height;
    PangoLayout *layout;
    int layout_height;

    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_text_parent_class)->get_content_height_request(box,
                                                                                       for_width,
                                                                                       &children_min_height,
                                                                                       &children_natural_height);

    if (for_width > 0) {
        if (box->context != NULL) {
            layout = create_layout(text, for_width);
            pango_layout_get_size(layout, NULL, &layout_height);
            
            layout_height /= PANGO_SCALE;
            g_object_unref(layout);
        } else {
            layout_height = 0;
        }
    } else {
        layout_height = 0;
    }
    
    if (min_height_p)
        *min_height_p = MAX(layout_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(layout_height, children_natural_height);
}
Esempio n. 4
0
static void
hippo_canvas_grip_class_init(HippoCanvasGripClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    HippoCanvasBoxClass *box_class = HIPPO_CANVAS_BOX_CLASS(klass);

    object_class->set_property = hippo_canvas_grip_set_property;
    object_class->get_property = hippo_canvas_grip_get_property;

    object_class->finalize = hippo_canvas_grip_finalize;

    box_class->paint_below_children = hippo_canvas_grip_paint_below_children;
    box_class->get_content_width_request = hippo_canvas_grip_get_content_width_request;
    box_class->get_content_height_request = hippo_canvas_grip_get_content_height_request;

    g_object_class_install_property(object_class,
                                    PROP_SIDE,
                                    g_param_spec_int("side",
                                            _("Side"),
                                            _("Side of the window it's on"),
                                            0,
                                            G_MAXINT,
                                            HIPPO_SIDE_TOP,
                                            G_PARAM_READABLE | G_PARAM_WRITABLE));
}
Esempio n. 5
0
static void
hippo_canvas_image_get_content_height_request(HippoCanvasBox  *box, 
                                              int              for_width,
                                              int             *min_height_p,
                                              int             *natural_height_p)
{
    HippoCanvasImage *image = HIPPO_CANVAS_IMAGE(box);
    int children_min_height, children_natural_height;
    int image_height;

    /* get height of children and the box padding */
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_image_parent_class)->get_content_height_request(box,
                                                                                        for_width,
                                                                                        &children_min_height,
                                                                                        &children_natural_height);

    if (image->scale_height >= 0)
        image_height = image->scale_height;
    else
        image_height = image->surface ? cairo_image_surface_get_height(image->surface) : 0;

    if (min_height_p)
        *min_height_p = MAX(image_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(image_height, children_natural_height);
}
Esempio n. 6
0
static void
hippo_canvas_widget_get_content_width_request(HippoCanvasBox *box,
                                              int            *min_width_p,
                                              int            *natural_width_p)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box);
    int children_min_width, children_natural_width;
    int widget_width;
    GtkRequisition req;
    
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_width_request(box,
                                                                                        &children_min_width,
                                                                                        &children_natural_width);

    /* Note that we get the widget's size request even if the GTK widget visibility flag is
     * false; that's because we are slaving GTK visibility to whether we have a nonzero
     * allocation (canvas item visibility), so it would make a circular mess if
     * our size request depended on visibility. This means you can't set visibility
     * on the underlying GtkWidget and expect anything sensible to happen.
     */
    
    if (widget->widget) {
        gtk_widget_size_request(widget->widget, &req);
        widget_width = req.width;
    } else {
        widget_width = 0;
    }

    if (min_width_p)
        *min_width_p = MAX(widget_width, children_min_width);
    if (natural_width_p)
        *natural_width_p = MAX(widget_width, children_natural_width);
}
Esempio n. 7
0
static int
hippo_canvas_widget_get_content_height_request(HippoCanvasBox  *box,
                                               int              for_width)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box);
    int children_height;
    int widget_height;
    GtkRequisition req;
    
    /* get height of children and the box padding */
    children_height = HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_height_request(box,
                                                                                                           for_width);
    
    if (widget->widget && GTK_WIDGET_VISIBLE(widget->widget)) {
        /* We know a get_height_request was done first, so we can
         * just get widget->requisition instead of doing the size request
         * computation again.
         */
        gtk_widget_get_child_requisition(widget->widget, &req);
        widget_height = req.height;
    } else {
        widget_height = 0;
    }
    
    return MAX(widget_height, children_height);
}
Esempio n. 8
0
static void
hippo_canvas_control_get_content_height_request(HippoCanvasBox  *box,
                                                int              for_width,
                                                int             *min_height_p,
                                                int             *natural_height_p)
{
    HippoCanvasControl *control = HIPPO_CANVAS_CONTROL(box);
    int children_min_height, children_natural_height;
    int control_height;
    
    /* get height of children and the box padding */
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_control_parent_class)->get_content_height_request(box,
                                                                                          for_width, 
                                                                                          &children_min_height,
                                                                                          &children_natural_height);
    
    if (control->control) {
        control_height = control->control->getHeightRequest(for_width);
    } else {
        control_height = 0;
    }
    
    if (min_height_p)
        *min_height_p = MAX(control_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(control_height, children_natural_height);
}
Esempio n. 9
0
static int
hippo_canvas_widget_get_content_width_request(HippoCanvasBox *box)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box);
    int children_width;
    int widget_width;
    GtkRequisition req;
    
    children_width = HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_width_request(box);

    if (widget->widget && GTK_WIDGET_VISIBLE(widget->widget)) {
        gtk_widget_size_request(widget->widget, &req);
        widget_width = req.width;
    } else {
        widget_width = 0;
    }

    return MAX(widget_width, children_width);
}
Esempio n. 10
0
static void
hippo_canvas_grip_get_content_width_request(HippoCanvasBox *box,
        int            *min_width_p,
        int            *natural_width_p)
{
    HippoCanvasGrip *grip = HIPPO_CANVAS_GRIP(box);
    int children_min_width, children_natural_width;
    int grip_width;

    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_grip_parent_class)->get_content_width_request(box,
            &children_min_width, &children_natural_width);

    get_grip_request(grip, &grip_width, NULL);

    if (min_width_p)
        *min_width_p = MAX(grip_width, children_min_width);
    if (natural_width_p)
        *natural_width_p = MAX(grip_width, children_natural_width);
}
Esempio n. 11
0
static void
hippo_canvas_grip_get_content_height_request(HippoCanvasBox *box,
        int             for_width,
        int            *min_height_p,
        int            *natural_height_p)
{
    HippoCanvasGrip *grip = HIPPO_CANVAS_GRIP(box);
    int children_min_height, children_natural_height;
    int grip_height;

    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_grip_parent_class)->get_content_height_request(box, for_width,
            &children_min_height,
            &children_natural_height);

    get_grip_request(grip, NULL, &grip_height);

    if (min_height_p)
        *min_height_p = MAX(grip_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(grip_height, children_natural_height);
}
Esempio n. 12
0
static void
hippo_canvas_widget_get_content_height_request(HippoCanvasBox  *box,
                                               int              for_width,
                                               int             *min_height_p,
                                               int             *natural_height_p)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box);
    int children_min_height, children_natural_height;
    int widget_height;
    GtkRequisition req;
    
    /* get height of children and the box padding */
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_widget_parent_class)->get_content_height_request(box,
                                                                                         for_width,
                                                                                         &children_min_height,
                                                                                         &children_natural_height);

    /* Note that we get the widget's size request even if the GTK widget visibility flag is
     * false; that's because we are slaving GTK visibility to whether we have a nonzero
     * allocation (canvas item visibility), so it would make a circular mess if
     * our size request depended on visibility. This means you can't set visibility
     * on the underlying GtkWidget and expect anything sensible to happen.
     */
    
    if (widget->widget) {
        /* We know a get_height_request was done first, so we can
         * just get widget->requisition instead of doing the size request
         * computation again.
         */
        gtk_widget_get_child_requisition(widget->widget, &req);
        widget_height = req.height;
    } else {
        widget_height = 0;
    }
    
    if (min_height_p)
        *min_height_p = MAX(widget_height, children_min_height);
    if (natural_height_p)
        *natural_height_p = MAX(widget_height, children_natural_height);
}
Esempio n. 13
0
static void
hippo_canvas_control_get_content_width_request(HippoCanvasBox *box,
                                               int            *min_width_p,
                                               int            *natural_width_p)
{
    HippoCanvasControl *control = HIPPO_CANVAS_CONTROL(box);
    int children_min_width, children_natural_width;
    int control_width;
    
    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_control_parent_class)->get_content_width_request(box, &children_min_width, &children_natural_width);

    if (control->control) {
        control_width = control->control->getWidthRequest();
    } else {
        control_width = 0;
    }

    if (min_width_p)
        *min_width_p = MAX(control_width, children_min_width);
    if (natural_width_p)
        *natural_width_p = MAX(control_width, children_natural_width);
}
Esempio n. 14
0
static void
hippo_canvas_image_get_content_width_request(HippoCanvasBox *box,
                                             int            *min_width_p,
                                             int            *natural_width_p)
{
    HippoCanvasImage *image = HIPPO_CANVAS_IMAGE(box);
    int children_min_width, children_natural_width;
    int image_width;

    HIPPO_CANVAS_BOX_CLASS(hippo_canvas_image_parent_class)->get_content_width_request(box,
                                                                                       &children_min_width,
                                                                                       &children_natural_width);

    if (image->scale_width >= 0)
        image_width = image->scale_width;
    else
        image_width = image->surface ? cairo_image_surface_get_width(image->surface) : 0;

    if (min_width_p)
        *min_width_p = MAX(image_width, children_min_width);
    if (natural_width_p)
        *natural_width_p = MAX(image_width, children_natural_width);
}
Esempio n. 15
0
static void
hippo_canvas_control_class_init(HippoCanvasControlClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    HippoCanvasBoxClass *box_class = HIPPO_CANVAS_BOX_CLASS(klass);

    object_class->set_property = hippo_canvas_control_set_property;
    object_class->get_property = hippo_canvas_control_get_property;

    object_class->dispose = hippo_canvas_control_dispose;
    object_class->finalize = hippo_canvas_control_finalize;

    box_class->paint_below_children = hippo_canvas_control_paint_below_children;
    box_class->get_content_width_request = hippo_canvas_control_get_content_width_request;
    box_class->get_content_height_request = hippo_canvas_control_get_content_height_request;

    g_object_class_install_property(object_class,
                                    PROP_CONTROL,
                                    g_param_spec_pointer("control",
                                                         "Control",
                                                         "Control to put in the canvas item",
                                                         GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE)));
}
Esempio n. 16
0
static void
hippo_canvas_widget_class_init(HippoCanvasWidgetClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    HippoCanvasBoxClass *box_class = HIPPO_CANVAS_BOX_CLASS(klass);

    object_class->set_property = hippo_canvas_widget_set_property;
    object_class->get_property = hippo_canvas_widget_get_property;

    object_class->dispose = hippo_canvas_widget_dispose;
    object_class->finalize = hippo_canvas_widget_finalize;

    box_class->paint_below_children = hippo_canvas_widget_paint_below_children;
    box_class->get_content_width_request = hippo_canvas_widget_get_content_width_request;
    box_class->get_content_height_request = hippo_canvas_widget_get_content_height_request;

    g_object_class_install_property(object_class,
                                    PROP_WIDGET,
                                    g_param_spec_object("widget",
                                                        _("Widget"),
                                                        _("Widget to put in the canvas item"),
                                                        GTK_TYPE_WIDGET,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
}
Esempio n. 17
0
static void
hippo_canvas_image_class_init(HippoCanvasImageClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    HippoCanvasBoxClass *box_class = HIPPO_CANVAS_BOX_CLASS(klass);
    
    object_class->set_property = hippo_canvas_image_set_property;
    object_class->get_property = hippo_canvas_image_get_property;

    object_class->finalize = hippo_canvas_image_finalize;

    box_class->paint_below_children = hippo_canvas_image_paint_below_children;
    box_class->get_content_width_request = hippo_canvas_image_get_content_width_request;
    box_class->get_content_height_request = hippo_canvas_image_get_content_height_request;

    /**
     * HippoCanvasImage:image
     *
     * Specifies the Cairo surface to display.
     */
    g_object_class_install_property(object_class,
                                    PROP_IMAGE,
                                    g_param_spec_boxed("image",
                                                         _("Image"),
                                                         _("Image as cairo_surface_t"),
                                                         HIPPO_TYPE_CAIRO_SURFACE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));

    /**
     * HippoCanvasImage:image-name
     *
     * Specifies an image name to display; with GTK+ the image name is
     * an image name registered with the GTK+ theme system.
     */    
    g_object_class_install_property(object_class,
                                    PROP_IMAGE_NAME,
                                    g_param_spec_string("image-name",
                                                        _("Image Name"),
                                                        _("Image name to be loaded into the item"),
                                                        NULL,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));

    /**
     * HippoCanvasImage:scale-width
     *
     * A width in pixels to scale the image to, or -1 to use the image's original width.
     */
    g_object_class_install_property(object_class,
                                    PROP_SCALE_WIDTH,
                                    g_param_spec_int("scale-width",
                                                     _("Scale width"),
                                                     _("Width to scale to or -1 for no scale"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));
    /**
     * HippoCanvasImage:scale-height
     *
     * A height in pixels to scale the image to, or -1 to use the image's original height.
     */    
    g_object_class_install_property(object_class,
                                    PROP_SCALE_HEIGHT,
                                    g_param_spec_int("scale-height",
                                                     _("Scale height"),
                                                     _("Height to scale to or -1 for no scale"),
                                                     -1,
                                                     G_MAXINT,
                                                     -1,
                                                     G_PARAM_READABLE | G_PARAM_WRITABLE));    
}
Esempio n. 18
0
static void
hippo_canvas_text_class_init(HippoCanvasTextClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    HippoCanvasBoxClass *box_class = HIPPO_CANVAS_BOX_CLASS(klass);
    
    object_class->set_property = hippo_canvas_text_set_property;
    object_class->get_property = hippo_canvas_text_get_property;

    object_class->finalize = hippo_canvas_text_finalize;

    box_class->paint_below_children = hippo_canvas_text_paint_below_children;
    box_class->get_content_width_request = hippo_canvas_text_get_content_width_request;
    box_class->get_content_height_request = hippo_canvas_text_get_content_height_request;

    /**
     * HippoCanvasText:text
     *
     * The text to display.
     */
    g_object_class_install_property(object_class,
                                    PROP_TEXT,
                                    g_param_spec_string("text",
                                                        _("Text"),
                                                        _("Text to display"),
                                                        NULL,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));

    /**
     * HippoCanvasText:markup
     *
     * The text to display in Pango markup format, allowing you to do bold and other text styles.
     * This is a shortcut way to set the 'text' and 'attributes' properties.
     */    
    g_object_class_install_property(object_class,
                                    PROP_MARKUP,
                                    g_param_spec_string("markup",
                                                        _("Markup"),
                                                        _("Marked-up text to display"),
                                                        NULL,
                                                        G_PARAM_WRITABLE));

    
    /**
     * HippoCanvasText:attributes
     *
     * The Pango attributes of the text; usually it is more convenient to use the 'markup' property
     * than to do the attributes by hand.
     */    
    g_object_class_install_property(object_class,
                                    PROP_ATTRIBUTES,
                                    g_param_spec_boxed ("attributes",
                                                        _("Attributes"),
                                                        _("A list of style attributes to apply to the text"),
                                                        PANGO_TYPE_ATTR_LIST,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));

    /**
     * HippoCanvasText:font-scale
     *
     * A scale factor for the font; Pango exports constants for common
     * factors, such as #PANGO_SCALE_LARGE, #PANGO_SCALE_X_SMALL and
     * so forth. If you want to set an absolute font size, use the
     * 'font' or 'font-desc' properties which are introduced in the
     * HippoCanvasBox base class.
     */
    g_object_class_install_property(object_class,
                                    PROP_FONT_SCALE,
                                    g_param_spec_double("font-scale",
                                                        _("Font scale"),
                                                        _("Scale factor for fonts"),
                                                        0.0,
                                                        100.0,
                                                        1.0,
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));

    /**
     * HippoCanvasText:size-mode
     *
     * Three "size modes" are available. In #HIPPO_CANVAS_SIZE_FULL_WIDTH mode, the
     * text item will give the width of its text as its minimum size. In #HIPPO_CANVAS_SIZE_WRAP_WORD,
     * the text item will wrap to fit available space - its minimum width will be pretty small, but as
     * the width decreases its height will increase. In #HIPPO_CANVAS_SIZE_ELLIPSIZE_END mode, the
     * width of the text will be the natural width of the item, but the minimum width will be small.
     * If the item gets less than its natural width, it will ellipsize the text in order to fit
     * in available space.
     *
     * If none of that made sense, just decide whether you want to
     * always display all the text without wrapping, want to be able
     * to wrap as the available space shrinks, or want to ellipsize
     * the text as the available space shrinks.
     */
    g_object_class_install_property(object_class,
                                    PROP_SIZE_MODE,
                                    g_param_spec_enum("size-mode",
                                                      _("Size mode"),
                                                      _("Mode for size request and allocation"),
                                                      HIPPO_TYPE_CANVAS_SIZE_MODE,
                                                      HIPPO_CANVAS_SIZE_FULL_WIDTH,
                                                      G_PARAM_READABLE | G_PARAM_WRITABLE));    
}