示例#1
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);
}
示例#2
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);
}
示例#3
0
static void
hippo_canvas_widget_set_property(GObject         *object,
                                 guint            prop_id,
                                 const GValue    *value,
                                 GParamSpec      *pspec)
{
    HippoCanvasWidget *widget;

    widget = HIPPO_CANVAS_WIDGET(object);

    switch (prop_id) {
    case PROP_WIDGET:
        {
            GtkWidget *w = (GtkWidget*) g_value_get_object(value);
            if (widget->widget != w) {
                if (w) {
                    gtk_object_ref(GTK_OBJECT(w));
                    gtk_object_sink(GTK_OBJECT(w));
                }
                if (widget->widget)
                    g_object_unref(widget->widget);
                widget->widget = w;

                update_widget_visibility(widget);

                hippo_canvas_item_emit_request_changed(HIPPO_CANVAS_ITEM(widget));
            }
        }
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}
示例#4
0
static void
hippo_canvas_button_dispose(GObject *object)
{
    HippoCanvasButton *canvas_button = HIPPO_CANVAS_BUTTON (object);
    GtkWidget *button = HIPPO_CANVAS_WIDGET(object)->widget;

    if (button) {
        g_signal_handlers_disconnect_by_func(button, (void *)on_canvas_button_clicked, canvas_button);
    }

    G_OBJECT_CLASS(hippo_canvas_button_parent_class)->dispose(object);
}
示例#5
0
static void
hippo_canvas_widget_dispose(GObject *object)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(object);

    if (widget->widget) {
        g_object_unref(widget->widget);
        widget->widget = NULL;
        g_object_notify(object, "widget");
    }

    G_OBJECT_CLASS(hippo_canvas_widget_parent_class)->dispose(object);
}
示例#6
0
static void
hippo_canvas_button_get_property(GObject        *object,
                                guint            prop_id,
                                GValue          *value,
                                GParamSpec      *pspec)
{
    /* HippoCanvasButton *canvas_button = HIPPO_CANVAS_BUTTON (object); */
    GtkWidget *button = HIPPO_CANVAS_WIDGET(object)->widget;

    switch (prop_id) {
    case BUTTON_PROP_TEXT:
        g_value_set_string(value, gtk_button_get_label(GTK_BUTTON(button)));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}
示例#7
0
static void
hippo_canvas_widget_paint_below_children(HippoCanvasBox  *box,
                                         cairo_t         *cr,
                                         HippoRectangle  *damage_box)
{
    HippoCanvasWidget *widget = HIPPO_CANVAS_WIDGET(box);

    if (widget->widget == NULL)
        return;

    /* For now the HippoCanvas is responsible for drawing all widgets; it
     * plops them all on top, after rending all canvas items.
     * 
     * For no-window widgets, adding a canvas_context_paint_widget_item() to
     * call right here
     * is a simple way to get them in the right z-order, if we ever
     * need it.
     */
}
示例#8
0
static void
hippo_canvas_widget_allocate(HippoCanvasItem *item,
                             int              width,
                             int              height,
                             gboolean         origin_changed)
{
    int x, y, w, h;
    int widget_x, widget_y;
    GtkAllocation child_allocation;
    HippoCanvasWidget *widget;
    HippoCanvasBox *box;

    widget = HIPPO_CANVAS_WIDGET(item);
    box = HIPPO_CANVAS_BOX(item);
    
    /* get the box set up */
    item_parent_class->allocate(item, width, height, origin_changed);

    if (widget->widget == NULL)
        return;
    
    /* this probably queues a resize, which is not ideal */
    update_widget_visibility(widget);
    
    /* Now do the GTK allocation for the child widget */
    w = widget->widget->requisition.width;
    h = widget->widget->requisition.height;

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

    widget_x = 0;
    widget_y = 0;
    if (box->context)
        hippo_canvas_context_translate_to_widget(box->context, item,
                                                 &widget_x, &widget_y);

    child_allocation.x = widget_x + x;
    child_allocation.y = widget_y + y;
    child_allocation.width = MAX(w, 1);
    child_allocation.height = MAX(h, 1);

    gtk_widget_size_allocate(widget->widget, &child_allocation);
}
示例#9
0
static void
hippo_canvas_widget_get_property(GObject         *object,
                                 guint            prop_id,
                                 GValue          *value,
                                 GParamSpec      *pspec)
{
    HippoCanvasWidget *widget;

    widget = HIPPO_CANVAS_WIDGET (object);

    switch (prop_id) {
    case PROP_WIDGET:
        g_value_set_object(value, widget->widget);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
    }
}
示例#10
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);
}
示例#11
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);
}
示例#12
0
static void
hippo_canvas_widget_allocate(HippoCanvasItem *item,
                             int              width,
                             int              height,
                             gboolean         origin_changed)
{
    int x, y, w, h;
    int widget_x, widget_y;
    GtkAllocation child_allocation;
    HippoCanvasWidget *widget;
    HippoCanvasBox *box;

    widget = HIPPO_CANVAS_WIDGET(item);
    box = HIPPO_CANVAS_BOX(item);
    
    /* get the box set up */
    item_parent_class->allocate(item, width, height, origin_changed);

    /* Now do the GTK allocation for the child widget */
    if (widget->widget == NULL || !GTK_WIDGET_VISIBLE(widget->widget))
        return;
    
    w = widget->widget->requisition.width;
    h = widget->widget->requisition.height;

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

    widget_x = 0;
    widget_y = 0;
    if (box->context)
        hippo_canvas_context_translate_to_widget(box->context, item,
                                                 &widget_x, &widget_y);

    child_allocation.x = widget_x + x;
    child_allocation.y = widget_y + y;
    child_allocation.width = w;
    child_allocation.height = h;

    gtk_widget_size_allocate(widget->widget, &child_allocation);
}