summaryrefslogtreecommitdiff
path: root/src/layeng/cr-box-view.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/layeng/cr-box-view.c')
-rw-r--r--src/layeng/cr-box-view.c359
1 files changed, 330 insertions, 29 deletions
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) ;
- }
}