summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--TODO4
-rw-r--r--src/layeng/cr-box-view.c359
-rw-r--r--src/layeng/cr-box-view.h12
-rw-r--r--src/layeng/cr-box.h9
-rw-r--r--src/layeng/cr-lay-eng.c7
-rw-r--r--tests/test7-main.c3
7 files changed, 368 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index e4cc10b..122e8c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2003-04-28 Dodji <dodji@seketeli.org>
+
+ * tests/test7-main.c: woohoo, this now shows some text.
+ Okay, it is a crappy design sketch, but this is a milestone.
+
+ * src/layeng/cr-lay-eng.c: store the created label widget in the cache.
+ box content cache.
+ * src/layeng/cr-box.h:created a box content cache to store the label
+ widget used to calculate text box size.
+
+ * src/layeng/cr-box-view.[hc]: made this simpler and manage to
+ make it show someting on the screen. Now the box view
+ is just the view port. To render the box model, we just walk thru it
+ and draw each box in the box view.
+
+
2003-04-26 dodji <dodji@seketeli.org>
* configure.in: made sure to include the libgnomeui clflags and
diff --git a/TODO b/TODO
index 978da86..0decb75 100644
--- a/TODO
+++ b/TODO
@@ -3,8 +3,8 @@
Go forward in the box layout (positioning) code. (hard, very hard).
This is gonna take me a coupe of months I think.
- cr-lay-eng.c:adjust_edges_on_inner_edge() code the TODO of this
- method. this is the must have before coding the draw_box() function.
+ cr-box-view.c: code the draw_borders() function.
+
I wonder when the draw_box will enable me to see something on the
screen.
that day would then be a great day.
diff --git a/src/layeng/cr-box-view.c b/src/layeng/cr-box-view.c
index d113171..8ebfbde 100644
--- a/src/layeng/cr-box-view.c
+++ b/src/layeng/cr-box-view.c
@@ -29,6 +29,7 @@
#include "cr-box-view.h"
#define PRIVATE(a_this) ((a_this)->priv)
+
struct _CRBoxViewPriv
{
CRBox *box ;
@@ -53,8 +54,24 @@ expose_event_cb (GtkWidget *a_this,
static enum CRStatus
draw_box (CRBoxView *a_this,
+ CRBox *a_box,
GdkRectangle *a_region_to_draw) ;
+static enum CRStatus
+draw_margins (CRBoxView *a_bv,
+ CRBox *a_box) ;
+
+static enum CRStatus
+draw_borders (CRBoxView *a_bv,
+ CRBox *a_box) ;
+
+static enum CRStatus
+draw_paddings (CRBoxView *a_bv,
+ CRBox *a_box) ;
+
+static enum CRStatus
+draw_inner_box (CRBoxView *a_bv,
+ CRBox *a_box) ;
static void
cr_box_view_class_init (CRBoxViewClass *a_klass)
@@ -98,6 +115,7 @@ expose_event_cb (GtkWidget *a_this,
{
case GDK_EXPOSE:
draw_box (CR_BOX_VIEW (a_this),
+ PRIVATE (CR_BOX_VIEW (a_this))->box,
&a_event->area) ;
break ;
@@ -113,34 +131,315 @@ expose_event_cb (GtkWidget *a_this,
}
static enum CRStatus
+draw_margins (CRBoxView *a_bv,
+ CRBox *a_box)
+{
+ GdkWindow * window = NULL ;
+ GtkWidget *widget = NULL ;
+ CRBox *box = NULL ;
+ GdkRectangle rect ;
+
+ g_return_val_if_fail (a_bv
+ && CR_IS_BOX_VIEW (a_bv)
+ && a_box,
+ CR_BAD_PARAM_ERROR) ;
+
+ widget = GTK_WIDGET (a_bv) ;
+ window = GTK_LAYOUT (a_bv)->bin_window ;
+ g_return_val_if_fail (window, CR_ERROR) ;
+
+ box = a_box ;
+ g_return_val_if_fail (box, CR_ERROR) ;
+
+ /*
+ *draw left margin rectangle
+ */
+ rect.x = box->outer_edge.x ;
+ rect.y = box->border_edge.y ;
+ rect.width = box->border_edge.x - box->outer_edge.x ;
+ rect.height = box->border_edge.height ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw right margin rectangle
+ *Note: this uses the previous left margin rectangle calculation result.
+ */
+ rect.x = box->border_edge.x + box->border_edge.width;
+ /*rect.y remains the same*/
+ rect.width = box->outer_edge.width -
+ (box->border_edge.width + rect.width) ;
+ /*rect.height remains the same;*/
+ gdk_draw_rectangle
+ (window,
+ GTK_WIDGET (a_bv)->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+
+ /*
+ *draw top margin rectangle.
+ */
+ rect.x = box->outer_edge.x ;
+ rect.y = box->outer_edge.y ;
+ rect.width = box->outer_edge.width ;
+ rect.height = box->border_edge.y - box->outer_edge.y ;
+
+ gdk_draw_rectangle
+ (window,
+ GTK_WIDGET (a_bv)->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw bottom margin rectangle.
+ */
+ /*rect.x remains the same*/
+ rect.y = box->border_edge.y + box->border_edge.height ;
+ /*rect.width remains the same as for top margin rect.*/
+ rect.height = box->outer_edge.height -
+ (box->border_edge.height + rect.height) ;
+
+ gdk_draw_rectangle
+ (window,
+ GTK_WIDGET (a_bv)->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ return CR_OK ;
+}
+
+static enum CRStatus
+draw_borders (CRBoxView *a_bv,
+ CRBox *a_box)
+{
+ GdkWindow * window = NULL ;
+ GtkWidget *widget = NULL ;
+ CRBox *box = NULL ;
+ GdkRectangle rect ;
+
+ g_return_val_if_fail (a_bv
+ && CR_IS_BOX_VIEW (a_bv)
+ && a_box,
+ CR_BAD_PARAM_ERROR) ;
+
+ widget = GTK_WIDGET (a_bv) ;
+ window = GTK_LAYOUT (a_bv)->bin_window ;
+ g_return_val_if_fail (window, CR_ERROR) ;
+
+ box = a_box ;
+ g_return_val_if_fail (box, CR_ERROR) ;
+
+ /*
+ *draw left border rectangle
+ */
+ rect.x = box->border_edge.x ;
+ rect.y = box->padding_edge.y ;
+ rect.width = box->padding_edge.x - box->border_edge.x ;
+ rect.height = box->padding_edge.height ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+ /*
+ *draw right border rectangle
+ */
+ rect.x = box->padding_edge.x + box->padding_edge.width ;
+ rect.y = box->padding_edge.y ;
+ rect.width = box->border_edge.width -
+ (rect.width + box->padding_edge.width) ;
+ /*rect.height remains the same*/
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw top border rectangle
+ */
+ rect.x = box->border_edge.x ;
+ rect.y = box->border_edge.y ;
+ rect.width = box->border_edge.width ;
+ rect.height = box->padding_edge.y - box->border_edge.y ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw bottom border rectangle
+ */
+ /*rect.x remains the same*/
+ rect.y = box->padding_edge.x + box->padding_edge.height;
+ /*rect.width remains the same as the top border rect width*/
+ rect.height = box->border_edge.height -
+ (rect.height + box->padding_edge.height) ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ return CR_OK ;
+}
+
+static enum CRStatus
+draw_paddings (CRBoxView *a_bv,
+ CRBox *a_box)
+{
+ GdkWindow * window = NULL ;
+ GtkWidget *widget = NULL ;
+ CRBox *box = NULL ;
+ GdkRectangle rect ;
+
+ g_return_val_if_fail (a_bv
+ && CR_IS_BOX_VIEW (a_bv)
+ && a_box,
+ CR_BAD_PARAM_ERROR) ;
+
+ widget = GTK_WIDGET (a_bv) ;
+ window = GTK_LAYOUT (a_bv)->bin_window ;
+ g_return_val_if_fail (window, CR_ERROR) ;
+
+ box = a_box ;
+ g_return_val_if_fail (box, CR_ERROR) ;
+
+ /*
+ *draw the left padding
+ */
+ rect.x = box->padding_edge.x ;
+ rect.y = box->inner_edge.y ;
+ rect.width = box->inner_edge.x - box->padding_edge.x ;
+ rect.height = box->inner_edge.height ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw the right padding rectangle.
+ */
+ rect.x = box->inner_edge.x + box->inner_edge.width ;
+ /*rect.y remains the same*/
+ rect.width = box->padding_edge.width -
+ (rect.width + box->inner_edge.width) ;
+ /*rect.height remains the same*/
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw the top padding rectangle.
+ */
+ rect.x = box->padding_edge.x ;
+ rect.y = box->padding_edge.y ;
+ rect.width = box->padding_edge.width ;
+ rect.height = box->inner_edge.y - box->padding_edge.y ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ /*
+ *draw the the bottom padding rectangle.
+ */
+ /*rect.x remains the same*/
+ rect.y = box->inner_edge.y + box->inner_edge.height ;
+ /*rect.width remains the same*/
+ rect.height = box->padding_edge.height -
+ (rect.height + box->inner_edge.height) ;
+ gdk_draw_rectangle
+ (window,
+ widget->style->base_gc[widget->state],
+ FALSE,
+ rect.x, rect.y, rect.width, rect.height) ;
+
+ return CR_OK ;
+}
+
+
+static enum CRStatus
+draw_inner_box (CRBoxView *a_bv,
+ CRBox *a_box)
+{
+ GtkWidget *widget = NULL, *label = NULL ;
+ CRBox *box = NULL ;
+
+ g_return_val_if_fail (a_bv
+ && CR_IS_BOX_VIEW (a_bv)
+ && a_box,
+ CR_BAD_PARAM_ERROR) ;
+
+ widget = GTK_WIDGET (a_bv) ;
+ g_return_val_if_fail (widget, CR_ERROR) ;
+
+ box = a_box ;
+ g_return_val_if_fail (box, CR_ERROR) ;
+
+ if (!box->content)
+ return CR_OK ;
+
+ if (box->content->content_cache)
+ {
+ label = GTK_WIDGET (box->content->content_cache) ;
+ g_return_val_if_fail (label, CR_ERROR) ;
+ }
+
+ g_return_val_if_fail (label, CR_ERROR) ;
+
+ if (label->parent == NULL)
+ gtk_layout_put (GTK_LAYOUT (a_bv), label,
+ box->inner_edge.x,
+ box->inner_edge.y) ;
+ else
+ gtk_layout_move (GTK_LAYOUT (a_bv), label,
+ box->inner_edge.x,
+ box->inner_edge.y) ;
+
+ gtk_widget_show_all (widget) ;
+
+ return CR_OK ;
+}
+
+
+static enum CRStatus
draw_box (CRBoxView *a_this,
+ CRBox *a_box,
GdkRectangle *a_region_to_draw)
{
- GdkWindow *window = NULL ;
- CRBoxView *cur_bv = NULL ;
+ CRBox *cur_box = NULL ;
GtkWidget *widget = NULL;
g_return_val_if_fail (a_this
- && CR_IS_BOX_VIEW (a_this),
+ && CR_IS_BOX_VIEW (a_this)
+ && a_box,
CR_BAD_PARAM_ERROR) ;
widget = GTK_WIDGET (a_this) ;
g_return_val_if_fail (widget, CR_ERROR) ;
- window = GTK_LAYOUT (a_this)->bin_window ;
- g_return_val_if_fail (window, CR_ERROR) ;
- for (cur_bv = a_this; cur_bv ; cur_bv = cur_bv->next)
+ for (cur_box = a_box; cur_box ; cur_box = cur_box->next)
{
- if (PRIVATE (cur_bv) && PRIVATE (cur_bv)->box)
+ draw_margins (a_this, cur_box) ;
+ draw_borders (a_this, cur_box) ;
+ draw_paddings (a_this, cur_box) ;
+ draw_inner_box (a_this, cur_box) ;
+
+ if (cur_box->children)
{
- gdk_draw_rectangle
- (window,
- widget->style->base_gc[widget->state],
- TRUE,
- PRIVATE (cur_bv)->box->outer_edge.x,
- PRIVATE (cur_bv)->box->outer_edge.y,
- PRIVATE (cur_bv)->box->outer_edge.width,
- PRIVATE (cur_bv)->box->outer_edge.height) ;
+ draw_box (a_this,
+ cur_box->children,
+ a_region_to_draw) ;
}
}
@@ -178,11 +477,12 @@ cr_box_view_get_type (void)
CRBoxView *
-cr_box_view_new (CRBox *a_box)
+cr_box_view_new (CRBox *a_box, CRBoxView *a_parent)
{
CRBoxView *result = NULL ;
- result = g_object_new (CR_TYPE_BOX_VIEW, NULL) ;
+
+ result = g_object_new (CR_TYPE_BOX_VIEW, NULL) ;
g_return_val_if_fail (result, NULL) ;
cr_box_view_set_box (result, a_box) ;
@@ -227,7 +527,6 @@ cr_box_view_get_box (CRBoxView *a_this, CRBox **a_box)
return TRUE ;
}
-
void
cr_box_view_destroy (GtkObject *a_this)
{
@@ -235,7 +534,8 @@ cr_box_view_destroy (GtkObject *a_this)
g_return_if_fail (a_this && CR_IS_BOX_VIEW (a_this)) ;
- self = CR_BOX_VIEW (a_this) ;
+ self = CR_BOX_VIEW (a_this) ;
+ g_return_if_fail (self) ;
if (PRIVATE (self) && PRIVATE (self)->box)
{
@@ -243,15 +543,16 @@ cr_box_view_destroy (GtkObject *a_this)
PRIVATE (self)->box = NULL ;
}
- if (PRIVATE (self))
- {
- g_free (PRIVATE (self)) ;
- PRIVATE (self) = NULL ;
- }
+ if (PRIVATE (self))
+ {
+ g_free (PRIVATE (self)) ;
+ PRIVATE (self) = NULL ;
+ }
+
+ if (gv_parent_class
+ && GTK_OBJECT_CLASS (gv_parent_class)->destroy)
+ {
+ GTK_OBJECT_CLASS (gv_parent_class)->destroy (a_this) ;
+ }
- if (gv_parent_class
- && GTK_OBJECT_CLASS (gv_parent_class)->destroy)
- {
- GTK_OBJECT_CLASS (gv_parent_class)->destroy (a_this) ;
- }
}
diff --git a/src/layeng/cr-box-view.h b/src/layeng/cr-box-view.h
index 7e9460d..40452e9 100644
--- a/src/layeng/cr-box-view.h
+++ b/src/layeng/cr-box-view.h
@@ -47,14 +47,8 @@ typedef struct _CRBoxViewPriv CRBoxViewPriv ;
struct _CRBoxView
{
- GtkLayout parent ;
+ GtkLayout parent_widget ;
CRBoxViewPriv *priv ;
-
- /**<public fields>*/
- CRBoxView *children ;
- CRBoxView *next ;
- CRBoxView *prev ;
-
} ;
struct _CRBoxViewClass
@@ -67,7 +61,7 @@ GType
cr_box_view_get_type (void) ;
CRBoxView *
-cr_box_view_new (CRBox *a_box) ;
+cr_box_view_new (CRBox *a_box, CRBoxView *a_parent) ;
enum CRStatus
cr_box_view_get_box (CRBoxView *a_this, CRBox **a_box) ;
@@ -76,10 +70,10 @@ enum CRStatus
cr_box_view_set_box (CRBoxView *a_this,
CRBox *a_box) ;
+
void
cr_box_view_destroy (GtkObject *a_this) ;
-
G_END_DECLS
#endif
diff --git a/src/layeng/cr-box.h b/src/layeng/cr-box.h
index 03aee96..bb90ff3 100644
--- a/src/layeng/cr-box.h
+++ b/src/layeng/cr-box.h
@@ -60,6 +60,15 @@ struct _CRBoxContent
guchar *text ;
CRImageContentDesc *img_desc ;
} u ;
+
+ /*
+ *a place where the rendered content can be cached.
+ *This can be usefull because sometime, during the layout,
+ *calculating the size of the content is better achieve by
+ *rendering it. In this case, the rendered content is just cached
+ *here so that the rendering stage can just pick it.
+ */
+ gpointer content_cache ;
} ;
typedef struct _CRBoxEdge CRBoxEdge ;
diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c
index ec12e98..90034b8 100644
--- a/src/layeng/cr-lay-eng.c
+++ b/src/layeng/cr-lay-eng.c
@@ -406,8 +406,10 @@ compute_text_box_inner_edge_size (CRBox *a_this)
text = a_this->content->u.text ;
- label = gtk_label_new (NULL) ;
+ label = gtk_label_new (NULL) ;
g_return_val_if_fail (label, CR_ERROR) ;
+ gtk_misc_set_alignment (GTK_MISC (label),0, 0) ;
+ gtk_misc_set_padding (GTK_MISC (label), 0, 0) ;
pgo_layout = gtk_widget_create_pango_layout (label, text) ;
pango_layout_get_pixel_extents (pgo_layout, &ink_rect,
@@ -415,6 +417,9 @@ compute_text_box_inner_edge_size (CRBox *a_this)
a_this->inner_edge.width = logical_rect.width ;
a_this->inner_edge.height = logical_rect.height ;
+ gtk_label_set_text (GTK_LABEL (label), text) ;
+ a_this->content->content_cache = label ;
+ label = NULL ;
/* cleanup:*/
diff --git a/tests/test7-main.c b/tests/test7-main.c
index 236b0a2..d36a802 100644
--- a/tests/test7-main.c
+++ b/tests/test7-main.c
@@ -158,7 +158,8 @@ test_layout_box (void)
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC) ;
- box_view = cr_box_view_new (((CRBox*)box_model)->children) ;
+ box_view = cr_box_view_new (((CRBox*)box_model)->children,
+ NULL) ;
gtk_container_add (GTK_CONTAINER (window), scroll) ;
gtk_container_add (GTK_CONTAINER (scroll),
GTK_WIDGET (box_view)) ;