Want more features on Pastebin? Sign Up, it's FREE!
Guest

hippo-canvas-box.h

By: a guest on Aug 25th, 2011  |  syntax: C  |  size: 16.48 KB  |  views: 58  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $ cat hippo-canvas-box.
  2. hippo-canvas-box.c  hippo-canvas-box.h  
  3. Arkygeek-2:~/Downloads/hippo-canvas/common/hippo arkygeek$ cat hippo-canvas-box.h
  4. /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
  5. #ifndef __HIPPO_CANVAS_BOX_H__
  6. #define __HIPPO_CANVAS_BOX_H__
  7.  
  8. #include <hippo/hippo-canvas-item.h>
  9. #include <hippo/hippo-canvas-container.h>
  10. #include <hippo/hippo-canvas-style.h>
  11. #include <hippo/hippo-canvas-theme.h>
  12.  
  13. G_BEGIN_DECLS
  14.  
  15. typedef enum /*< flags >*/
  16. {
  17.     HIPPO_PACK_EXPAND = 1,  /**< This is equivalent to both EXPAND and FILL for GtkBox,
  18.                              * the way you'd get FILL=false is to set the alignment
  19.                              * on the child item
  20.                              */
  21.     HIPPO_PACK_END = 2,
  22.     HIPPO_PACK_FIXED = 4,   /**< Like position: absolute or GtkFixed */
  23.     HIPPO_PACK_IF_FITS = 8, /**< Can hide this child to make space if allocation is too small
  24.                              * for the child's width request.
  25.                              * Include child width in box's natural width but not box's request.
  26.                              * (doesn't work in vertical boxes for now)
  27.                              */
  28.     /* Floated children: only works with vertical box, and cannot be used in combination
  29.      * with HIPPO_PACK_EXPAND or HIPPO_PACK_END
  30.      */
  31.     HIPPO_PACK_FLOAT_LEFT = 16,   /* Float to the left */
  32.     HIPPO_PACK_FLOAT_RIGHT = 32,  /* Float to the right */
  33.     HIPPO_PACK_CLEAR_LEFT = 64,   /* Pack below left-floated children */
  34.     HIPPO_PACK_CLEAR_RIGHT = 128, /* Pack below right-floated children */
  35.     HIPPO_PACK_CLEAR_BOTH = 192   /* Pack below left-and right floated children */
  36. } HippoPackFlags;
  37.  
  38. typedef int  (* HippoCanvasCompareChildFunc) (HippoCanvasItem *child_a,
  39.                                               HippoCanvasItem *child_b,
  40.                                               void            *data);
  41. typedef void (* HippoCanvasForeachChildFunc) (HippoCanvasItem *child,
  42.                                               void            *data);  
  43.  
  44. typedef struct _HippoCanvasBox      HippoCanvasBox;
  45. typedef struct _HippoCanvasBoxClass HippoCanvasBoxClass;
  46.  
  47. typedef struct _HippoCanvasBoxChild HippoCanvasBoxChild;
  48.  
  49. /* Declare here to avoid circular header file dependency */
  50. typedef struct _HippoCanvasLayout   HippoCanvasLayout;
  51.  
  52. #define HIPPO_TYPE_CANVAS_BOX              (hippo_canvas_box_get_type ())
  53. #define HIPPO_CANVAS_BOX(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), HIPPO_TYPE_CANVAS_BOX, HippoCanvasBox))
  54. #define HIPPO_CANVAS_BOX_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), HIPPO_TYPE_CANVAS_BOX, HippoCanvasBoxClass))
  55. #define HIPPO_IS_CANVAS_BOX(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), HIPPO_TYPE_CANVAS_BOX))
  56. #define HIPPO_IS_CANVAS_BOX_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), HIPPO_TYPE_CANVAS_BOX))
  57. #define HIPPO_CANVAS_BOX_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), HIPPO_TYPE_CANVAS_BOX, HippoCanvasBoxClass))
  58.  
  59. struct _HippoCanvasBox {
  60.     GObject base;
  61.     HippoCanvasContainer *parent;
  62.     HippoCanvasContext *context;
  63.     HippoCanvasStyle *style; /* may be NULL if no relevant props set */
  64.     HippoCanvasTheme *theme;
  65.     GSList *children;
  66.  
  67.     char *element_id;
  68.     char *element_class;
  69.  
  70.     HippoCanvasLayout *layout;
  71.  
  72.     char *tooltip;
  73.  
  74.     /* If set, we debug-spew about size allocation prefixed with this name */
  75.     char *debug_name;
  76.  
  77.     /* Cache of last requested sizes of content. This largely duplicates the caching
  78.      * in HippoCanvasBoxChild; removing the caching in HippoCanvasBoxChild would
  79.      * save 20 bytes per item at the expense of having to continually call into
  80.      * the child and have the child add back on the padding border */
  81.     int content_min_width;       /* -1 if invalid */
  82.     int content_natural_width;   /* always valid and >= 0 when min_width is valid */
  83.     int content_min_height;      /* -1 if invalid */
  84.     int content_natural_height;  /* always valid and >= 0 when min_height is valid */
  85.     int content_height_request_for_width; /* width the height_request is valid for */
  86.    
  87.     int allocated_width;
  88.     int allocated_height;
  89.  
  90.     /* these are -1 if unset, which means use natural size request */
  91.     int box_width;
  92.     int box_height;
  93.  
  94.     PangoFontDescription *font_desc;
  95.     guint32 color_rgba;
  96.     guint32 background_color_rgba;
  97.     guint32 border_color_rgba;
  98.  
  99.     /* padding is empty space around all children with the
  100.      * background color
  101.      */
  102.     guint8 padding_top;
  103.     guint8 padding_bottom;
  104.     guint8 padding_left;
  105.     guint8 padding_right;
  106.  
  107.     /* padding is empty space around the padding, with
  108.      * the border color
  109.      */
  110.     guint8 border_top;
  111.     guint8 border_bottom;
  112.     guint8 border_left;
  113.     guint8 border_right;
  114.    
  115.     guint8 spacing;
  116.  
  117.     guint needs_width_request : 1;
  118.     guint needs_height_request : 1;
  119.     guint needs_allocate : 1;
  120.     guint orientation : 2; /* enum only has 2 values so it fits with extra */
  121.     guint x_align : 3;     /* enum only has 4 values so it fits with extra */
  122.     guint y_align : 3;     /* enum only has 4 values so it fits with extra */
  123.     guint clickable : 1;   /* show a hand pointer and emit activated signal */
  124.     guint link_type : 2;   /* enum only has 3 values so it fits with extra */
  125.     guint hovering : 1;    /* the box or some child contains the pointer (have gotten enter without leave) */
  126.     guint color_set : 1;
  127.     guint background_color_set : 1;
  128.     guint border_color_set : 1;
  129.  
  130.     guint border_top_set : 1;
  131.     guint border_bottom_set : 1;
  132.     guint border_left_set : 1;
  133.     guint border_right_set : 1;
  134.  
  135.     guint padding_top_set : 1;
  136.     guint padding_bottom_set : 1;
  137.     guint padding_left_set : 1;
  138.     guint padding_right_set : 1;
  139. };
  140.  
  141. struct _HippoCanvasBoxClass {
  142.     GObjectClass base_class;
  143.  
  144.     void     (* paint_background)             (HippoCanvasBox   *box,
  145.                                                cairo_t          *cr,
  146.                                                GdkRegion        *damaged_region);
  147.     void     (* paint_children)               (HippoCanvasBox   *box,
  148.                                                cairo_t          *cr,
  149.                                                GdkRegion        *damaged_region);
  150.     void     (* paint_below_children)         (HippoCanvasBox   *box,
  151.                                                cairo_t          *cr,
  152.                                                GdkRegion        *damaged_region);
  153.     void     (* paint_above_children)         (HippoCanvasBox   *box,
  154.                                                cairo_t          *cr,
  155.                                                GdkRegion        *damaged_region);
  156.    
  157.     void     (* get_content_width_request)    (HippoCanvasBox   *box,
  158.                                                int              *min_width_p,
  159.                                                int              *natural_width_p);
  160.     void     (* get_content_height_request)   (HippoCanvasBox   *box,
  161.                                                int               for_width,
  162.                                                int              *min_height_p,
  163.                                                int              *natural_height_p);
  164.  
  165.     void     (* hovering_changed)             (HippoCanvasBox   *box,
  166.                                                gboolean          hovering);
  167. };
  168.  
  169. GType            hippo_canvas_box_get_type          (void) G_GNUC_CONST;
  170.  
  171. HippoCanvasItem* hippo_canvas_box_new               (void);
  172.  
  173. void             hippo_canvas_box_prepend           (HippoCanvasBox              *box,
  174.                                                      HippoCanvasItem             *child,
  175.                                                      HippoPackFlags               flags);
  176. void             hippo_canvas_box_append            (HippoCanvasBox              *box,
  177.                                                      HippoCanvasItem             *child,
  178.                                                      HippoPackFlags               flags);
  179.  
  180. void             hippo_canvas_box_move              (HippoCanvasBox              *box,
  181.                                                      HippoCanvasItem             *child,
  182.                                                      HippoGravity                 gravity,
  183.                                                      int                          x,
  184.                                                      int                          y);
  185. void             hippo_canvas_box_set_position      (HippoCanvasBox              *box,
  186.                                                      HippoCanvasItem             *child,
  187.                                                      int                          x,
  188.                                                      int                          y);
  189. void             hippo_canvas_box_get_position      (HippoCanvasBox              *box,
  190.                                                      HippoCanvasItem             *child,
  191.                                                      int                         *x,
  192.                                                      int                         *y);
  193. void             hippo_canvas_box_clear             (HippoCanvasBox              *box);
  194. void             hippo_canvas_box_remove            (HippoCanvasBox              *box,
  195.                                                      HippoCanvasItem             *child);
  196. void             hippo_canvas_box_remove_all        (HippoCanvasBox              *box);
  197. GList*           hippo_canvas_box_get_children      (HippoCanvasBox              *box);
  198. gboolean         hippo_canvas_box_is_empty          (HippoCanvasBox              *box);
  199. void             hippo_canvas_box_foreach           (HippoCanvasBox              *box,
  200.                                                      HippoCanvasForeachChildFunc  func,
  201.                                                      void                        *data);
  202. void             hippo_canvas_box_reverse           (HippoCanvasBox              *box);
  203. void             hippo_canvas_box_sort              (HippoCanvasBox              *box,
  204.                                                      HippoCanvasCompareChildFunc  compare_func,
  205.                                                      void                        *data);
  206. void             hippo_canvas_box_insert_after     (HippoCanvasBox              *box,
  207.                                                     HippoCanvasItem             *child,
  208.                                                     HippoCanvasItem             *ref_child,
  209.                                                     HippoPackFlags               flags);
  210. void             hippo_canvas_box_insert_before     (HippoCanvasBox              *box,
  211.                                                      HippoCanvasItem             *child,
  212.                                                      HippoCanvasItem             *ref_child,
  213.                                                      HippoPackFlags               flags);
  214. void             hippo_canvas_box_insert_sorted     (HippoCanvasBox              *box,
  215.                                                      HippoCanvasItem             *child,
  216.                                                      HippoPackFlags               flags,
  217.                                                      HippoCanvasCompareChildFunc  compare_func,
  218.                                                      void                        *data);
  219. void             hippo_canvas_box_set_child_packing (HippoCanvasBox              *box,
  220.                                                      HippoCanvasItem             *child,
  221.                                                      HippoPackFlags               flags);
  222. void             hippo_canvas_box_set_theme         (HippoCanvasBox              *box,
  223.                                                      HippoCanvasTheme            *theme);
  224.  
  225. void hippo_canvas_box_set_layout(HippoCanvasBox    *box,
  226.                                  HippoCanvasLayout *layout);
  227.    
  228. /* Protected accessors for subclasses */
  229. void                hippo_canvas_box_get_background_area (HippoCanvasBox *box,
  230.                                                           HippoRectangle *area);
  231. void                hippo_canvas_box_align               (HippoCanvasBox *box,
  232.                                                           int             content_width,
  233.                                                           int             content_height,
  234.                                                           int            *x_p,
  235.                                                           int            *y_p,
  236.                                                           int            *width_p,
  237.                                                           int            *height_p);
  238.  
  239. void                hippo_canvas_box_set_clickable       (HippoCanvasBox *box,
  240.                                                           gboolean        clickable);
  241.  
  242. gboolean            hippo_canvas_box_is_clickable        (HippoCanvasBox *box);
  243.  
  244. void                hippo_canvas_box_set_link_type       (HippoCanvasBox     *box,
  245.                                                           HippoCanvasLinkType link_type);
  246.  
  247. /* API for layout managers */
  248.  
  249. HippoCanvasBoxChild *hippo_canvas_box_find_box_child (HippoCanvasBox      *box,
  250.                                                       HippoCanvasItem     *item);
  251.  
  252. GList *hippo_canvas_box_get_layout_children (HippoCanvasBox *box);
  253.  
  254. #define HIPPO_TYPE_CANVAS_BOX_CHILD    (hippo_canvas_box_child_get_type ())
  255. #define HIPPO_CANVAS_BOX_CHILD(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), HIPPO_TYPE_CANVAS_BOX_CHILD, HippoCanvasBoxChild))
  256.  
  257. /**
  258.  * HippoCanvasBoxChild:
  259.  *
  260.  * #HippoCanvasBoxChild holds data associated with an item that has been
  261.  * added to a canvas box. It is used by implementations of #HippoCanvasLayout
  262.  * when implementing methods like get_width_request and size_allocate.
  263.  *
  264.  * The life-cycle of a #HippoCanvasBoxChild is effectively until the item
  265.  * is removed from its parent. If a reference is held beyond that point, calling
  266.  * methods on the box child is safe, but the methods will have no effect,
  267.  * and defaults results will be returned.
  268.  */
  269. struct _HippoCanvasBoxChild {
  270.     HippoCanvasItem *item;
  271.  
  272.     /* If this is false, layout managers should ignore this item */
  273.     guint            in_layout : 1;
  274.  
  275.     guint            expand : 1;
  276.     guint            end : 1;
  277.     guint            fixed : 1;
  278.     guint            if_fits : 1;
  279.     guint            float_left : 1;
  280.     guint            float_right : 1;
  281.     guint            clear_left : 1;
  282.     guint            clear_right : 1;
  283.     guint            visible : 1;
  284. };
  285.  
  286. GType     hippo_canvas_box_child_get_type           (void);
  287.  
  288. HippoCanvasBoxChild *hippo_canvas_box_child_ref   (HippoCanvasBoxChild *child);
  289. void                 hippo_canvas_box_child_unref (HippoCanvasBoxChild *child);
  290.  
  291. void     hippo_canvas_box_child_set_qdata (HippoCanvasBoxChild *child,
  292.                                            GQuark               key,
  293.                                            gpointer             data,
  294.                                            GDestroyNotify       notify);
  295. gpointer hippo_canvas_box_child_get_qdata (HippoCanvasBoxChild *child,
  296.                                            GQuark               key);
  297.  
  298. void      hippo_canvas_box_child_get_width_request  (HippoCanvasBoxChild *child,
  299.                                                      int                 *min_width_p,
  300.                                                      int                 *natural_width_p);
  301. void      hippo_canvas_box_child_get_height_request (HippoCanvasBoxChild *child,
  302.                                                      int                  for_width,
  303.                                                      int                 *min_height_p,
  304.                                                      int                 *natural_height_p);
  305. void     hippo_canvas_box_child_allocate            (HippoCanvasBoxChild *child,
  306.                                                      int                  x,
  307.                                                      int                  y,
  308.                                                      int                  width,
  309.                                                      int                  height,
  310.                                                      gboolean             origin_changed);
  311.  
  312. G_END_DECLS
  313.  
  314. #endif /* __HIPPO_CANVAS_BOX_H__ */
clone this paste RAW Paste Data