Enlightenment CVS committal

Author  : codewarrior
Project : e17
Module  : libs/etk

Dir     : e17/libs/etk/src/lib


Modified Files:
        etk_canvas.c etk_canvas.h 


Log Message:
[Etk_Canvas] Initial code to support random widget placement within the
canvas. Not done. Needs formatting. API functions missing. Works. (=



===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_canvas.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -3 -r1.24 -r1.25
--- etk_canvas.c        28 Sep 2007 19:56:13 -0000      1.24
+++ etk_canvas.c        11 Apr 2008 03:25:19 -0000      1.25
@@ -1,3 +1,6 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
 /** @file etk_canvas.c */
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -39,7 +42,7 @@
 
    if (!canvas_type)
    {
-      canvas_type = etk_type_new("Etk_Canvas", ETK_WIDGET_TYPE,
+      canvas_type = etk_type_new("Etk_Canvas", ETK_CONTAINER_TYPE,
          sizeof(Etk_Canvas), ETK_CONSTRUCTOR(_etk_canvas_constructor),
          NULL, NULL);
    }
@@ -94,6 +97,29 @@
    return result;
 }
 
+Etk_Bool etk_canvas_widget_add(Etk_Canvas *canvas, Etk_Widget *widget)
+{
+       Etk_Geometry geometry;
+       Etk_Size size;
+       int cx, cy;
+
+       if (!canvas || !widget)
+               return ETK_FALSE;
+
+       
+       etk_widget_geometry_get(ETK_WIDGET(canvas), &cx, &cy, NULL, NULL);
+       etk_widget_size_request(widget, &size);
+       geometry.x = cx;
+       geometry.y = cy;
+       geometry.w = size.w;
+       geometry.h = size.h;
+       etk_widget_size_allocate(widget, geometry);
+       etk_widget_parent_set(widget, ETK_WIDGET(canvas));
+       canvas->widgets = evas_list_append(canvas->widgets, widget);
+
+       return ETK_TRUE;
+}
+
 /**
  * @brief Removes an Evas object from the canvas. The removed object will be 
automatically hidden
  * @param canvas a canvas
@@ -139,6 +165,24 @@
    evas_object_move(object, cx + x, cy + y);
 }
 
+void etk_canvas_widget_move(Etk_Canvas *canvas, Etk_Widget *widget, int x, int 
y)
+{
+       int cx, cy;
+       Etk_Geometry geometry;
+       Etk_Size size;
+
+       if (!canvas || !widget)
+               return;
+
+       etk_widget_geometry_get(ETK_WIDGET(canvas), &cx, &cy, NULL, NULL);
+       etk_widget_size_request(widget, &size);
+       geometry.x = cx + x;
+       geometry.y = cy + y;
+       geometry.w = size.w;
+       geometry.h = size.h;
+       etk_widget_size_allocate(widget, geometry);
+}
+
 /**
  * @brief Gets the geometry of an Evas Object. The returned position will be 
relative to the canvas' top-left corner
  * @param canvas a canvas
@@ -179,6 +223,7 @@
 
    canvas->clip = NULL;
    canvas->objects = NULL;
+   canvas->widgets= NULL;
    ETK_WIDGET(canvas)->size_allocate = _etk_canvas_size_allocate;
 
    etk_signal_connect_by_code(ETK_WIDGET_REALIZED_SIGNAL, ETK_OBJECT(canvas), 
ETK_CALLBACK(_etk_canvas_realized_cb), NULL);
@@ -189,12 +234,31 @@
 static void _etk_canvas_size_allocate(Etk_Widget *widget, Etk_Geometry 
geometry)
 {
    Etk_Canvas *canvas;
+        Etk_Widget *child;
+        Etk_Size size;
+        Etk_Geometry child_geometry;
+        Evas_List *l;
+        int x, y, w, h;
 
    if (!(canvas = ETK_CANVAS(widget)))
       return;
 
    evas_object_move(canvas->clip, geometry.x, geometry.y);
-   evas_object_resize(canvas->clip, geometry.w, geometry.h);
+        evas_object_resize(canvas->clip, geometry.w, geometry.h);
+
+        // TODO: this might not be needed everytime, better way?
+        for (l = canvas->widgets; l; l = l->next)
+        {
+                       child = l->data;
+                       etk_widget_size_request(child, &size);
+                       etk_widget_geometry_get(child, &x, &y, &w, &h);
+                       child_geometry.x = x;
+                       child_geometry.y = y;
+                       child_geometry.w = size.w;
+                       child_geometry.h = size.h;
+                       etk_widget_size_allocate(child, child_geometry);
+                       etk_widget_show_all(child);
+        }
 }
 
 /**************************
@@ -209,6 +273,7 @@
    Evas *evas;
    Etk_Canvas *canvas;
    Evas_Object *obj;
+   Etk_Widget *widget;
    Evas_List *l;
 
    if (!(canvas = ETK_CANVAS(object)) || !(evas = 
etk_widget_toplevel_evas_get(ETK_WIDGET(canvas))))
@@ -224,6 +289,12 @@
       evas_object_show(canvas->clip);
    }
 
+   for (l = canvas->widgets; l; l = l->next)
+   {
+      widget = l->data;
+                       etk_widget_show_all(widget);
+   }
+
    return ETK_TRUE;
 }
 
@@ -237,7 +308,9 @@
 
    canvas->clip = NULL;
    evas_list_free(canvas->objects);
+   evas_list_free(canvas->widgets);
    canvas->objects = NULL;
+   canvas->widgets= NULL;
 
    return ETK_TRUE;
 }
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_canvas.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- etk_canvas.h        19 Sep 2007 20:16:25 -0000      1.10
+++ etk_canvas.h        11 Apr 2008 03:25:19 -0000      1.11
@@ -5,6 +5,7 @@
 #include <Evas.h>
 
 #include "etk_widget.h"
+#include "etk_container.h"
 #include "etk_types.h"
 
 #ifdef __cplusplus
@@ -32,11 +33,12 @@
 struct Etk_Canvas
 {
    /* private: */
-   /* Inherit from Etk_Widget */
-   Etk_Widget widget;
+   /* Inherit from Etk_Container*/
+   Etk_Container container;
 
    Evas_Object *clip;
    Evas_List *objects;
+   Evas_List *widgets;
 };
 
 
@@ -47,6 +49,9 @@
 void        etk_canvas_object_remove(Etk_Canvas *canvas, Evas_Object *object);
 void        etk_canvas_object_move(Etk_Canvas *canvas, Evas_Object *object, 
int x, int y);
 void        etk_canvas_object_geometry_get(Etk_Canvas *canvas, Evas_Object 
*object, int *x, int *y, int *w, int *h);
+
+Etk_Bool    etk_canvas_widget_add(Etk_Canvas *canvas, Etk_Widget *widget);
+void        etk_canvas_widget_move(Etk_Canvas *canvas, Etk_Widget *widget, int 
x, int y);
 
 /** @} */
 



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to