Enlightenment CVS committal

Author  : lordchaos
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_iconbox.c ewl_iconbox.h 


Log Message:
Memory cleanup on icon Delete.  Also start of label abbreviation work

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_iconbox.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- ewl_iconbox.c       22 Jul 2005 11:53:52 -0000      1.9
+++ ewl_iconbox.c       24 Jul 2005 23:35:35 -0000      1.10
@@ -233,6 +233,8 @@
        /* Ewl Entry for the purposes of label editing - if enabled */
        ib->entry = ewl_entry_new("Test");
        ewl_text_text_set(EWL_TEXT(ib->entry), "Test");
+
+
        
ewl_entry_cursor_position_set(EWL_ENTRY_CURSOR(EWL_ENTRY(ib->entry)->cursor), 
50);
        ewl_widget_show(ib->entry);
        ib->entry_floater = ewl_floater_new(ib->ewl_iconbox_pane_inner);
@@ -279,6 +281,34 @@
        ewl_object_custom_size_set(EWL_OBJECT(ib->ewl_iconbox_pane_inner), 
680,700);
 }
 
+void ewl_iconbox_icon_label_set(Ewl_IconBox_Icon* icon, char* text) {
+       char* compressed;
+       
+       /*If we have a current label, nuke it*/
+       if (icon->label) {
+               free(icon->label);
+       }
+       
+       /*Copy the existing label to our icon*/
+       icon->label = strdup(text);
+
+       if (strlen(text) <= LABEL_CHARS) {
+               ewl_border_text_set(EWL_BORDER(icon), text);
+       } else {
+               if (icon->label_compressed) {
+                       free(icon->label_compressed);
+               }
+               
+               compressed = malloc(sizeof(char) * LABEL_CHARS + 3);
+               strncpy(compressed, text, LABEL_CHARS);
+               strcpy(compressed+LABEL_CHARS, "..\0");
+               ewl_border_text_set(EWL_BORDER(icon),compressed);
+
+               icon->label_compressed = compressed;
+       }
+
+       
+}
 
 
 void ewl_iconbox_label_edit_key_down(Ewl_Widget *w, void *ev_data, void* 
user_data) {
@@ -315,7 +345,7 @@
 
        
        
-       ewl_object_current_size_get(EWL_OBJECT(ib->ewl_iconbox_pane_inner), 
&sw,&sh);
+       ewl_object_current_size_get(EWL_OBJECT(ib->ewl_iconbox_scrollpane), 
&sw,&sh);
        /*printf("   Ewl_IconBox -> We have %d*%d to work with\n", sw,sh);*/
 
        /*Hack for now - get the biggest icon in the list - this is 
inefficient*/
@@ -355,7 +385,7 @@
         * the size of the scrollpane, which ever is bigger
         */
        ewl_object_current_size_get(EWL_OBJECT(ib->ewl_iconbox_scrollpane), 
&pw, &ph);  
-       
ewl_object_preferred_inner_size_set(EWL_OBJECT(ib->ewl_iconbox_pane_inner), pw 
> maxx ? pw : maxx, ph > maxy+ih ? ph : maxy+ih);
+       ewl_object_custom_size_set(EWL_OBJECT(ib->ewl_iconbox_pane_inner), pw > 
maxx ? pw +iw: maxx+iw, ph > maxy+ih ? ph+ih : maxy+ih);
 
 
 
@@ -552,8 +582,17 @@
 }
 
 void ewl_iconbox_icon_select(Ewl_IconBox_Icon* ib, int loc) { /* Loc 0= image, 
1= label */
+       int sel = ib->selected;
        
-       if (ib->selected == 1 && loc == 1) {
+       if (!ib->icon_box_parent->drag_box) {
+               Ewl_IconBox_Icon* list_item;
+               
ecore_list_goto_first(ib->icon_box_parent->ewl_iconbox_icon_list);
+               while((list_item = 
(Ewl_IconBox_Icon*)ecore_list_next(ib->icon_box_parent->ewl_iconbox_icon_list)) 
!= NULL) {
+                       ewl_iconbox_icon_deselect(list_item);   
+               }
+       }
+       
+       if (sel && loc == 1) {
                int w,h;
                int iw,ih;
                int x,y;
@@ -580,19 +619,11 @@
                        
        } else {
                ewl_widget_hide(EWL_WIDGET(ib->icon_box_parent->entry_floater));
+               ewl_border_text_set(EWL_BORDER(ib), ib->label);
        }
 
        
        /*TODO allow multiselect, as per a "select policy" set on widget 
create/init*/
-       
-       if (!ib->icon_box_parent->drag_box) {
-               Ewl_IconBox_Icon* list_item;
-               
ecore_list_goto_first(ib->icon_box_parent->ewl_iconbox_icon_list);
-               while((list_item = 
(Ewl_IconBox_Icon*)ecore_list_next(ib->icon_box_parent->ewl_iconbox_icon_list)) 
!= NULL) {
-                       ewl_iconbox_icon_deselect(list_item);   
-               }
-       }
-       
        ib->selected = 1;
 
        /*printf("Setting color..\n");*/
@@ -603,6 +634,11 @@
 void ewl_iconbox_icon_deselect(Ewl_IconBox_Icon *ib) {
        ib->selected = 0;
        ewl_widget_color_set(EWL_WIDGET(EWL_BORDER(ib)->label), 0,0,0,255);
+
+       /*If we have a compressed label, set it now*/
+       if (ib->label_compressed) {
+               ewl_border_text_set(EWL_BORDER(ib), ib->label_compressed);
+       }
 }
 
 void ewl_iconbox_deselect_all(Ewl_IconBox* ib) {
@@ -621,6 +657,18 @@
        /*printf("Removing icon: %s", ewl_border_text_get(EWL_BORDER(icon)));*/
 }
 
+void ewl_iconbox_icon_destroy_cb(Ewl_Widget *w, void *ev_data __UNUSED__,
+                                       void *user_data __UNUSED__)
+{
+       Ewl_IconBox_Icon* icon = EWL_ICONBOX_ICON(w);
+       
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       ewl_widget_destroy(icon->image);
+       ewl_widget_destroy(icon->floater);
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+
 Ewl_IconBox_Icon* ewl_iconbox_icon_add(Ewl_IconBox* iconbox, char* name, char* 
icon_file) {
        Ewl_Widget* ib;
        /*ib = malloc(sizeof(Ewl_IconBox_Icon));*/
@@ -628,10 +676,17 @@
 
        ib = ewl_iconbox_icon_new();
 
+       /*ewl_callback_append(EWL_WIDGET(ib), EWL_CALLBACK_DESTROY,
+                           ewl_iconbox_icon_destroy_cb, NULL);*/
+
        EWL_ICONBOX_ICON(ib)->selected = 0;
 
        EWL_ICONBOX_ICON(ib)->floater = 
ewl_floater_new(iconbox->ewl_iconbox_pane_inner);
-       ewl_border_text_set(EWL_BORDER(ib), name);
+
+       /*Set the label*/
+       ewl_iconbox_icon_label_set(EWL_ICONBOX_ICON(ib), name);
+       
+       
        EWL_ICONBOX_ICON(ib)->icon_box_parent = iconbox; /* Set our parent */
        
        /*printf("Setting fill policy..\n");*/
@@ -657,7 +712,7 @@
 
        /* Find the enxt pos for this icon FIXME add this to layout engine */
        ewl_floater_position_set(EWL_FLOATER(EWL_ICONBOX_ICON(ib)->floater), 
nextx, 0);
-       nextx += 60;
+       nextx += 75;
 
 
        /*Show*/
@@ -701,3 +756,31 @@
        ewl_object_current_size_get(EWL_OBJECT(EWL_BORDER(icon)->label), &lw, 
&lh); /* Shouldn't access this directly, is there another way? */
        ewl_object_minimum_size_set(EWL_OBJECT(icon->floater), iw, ih+lh);
 }
+
+void ewl_iconbox_clear(Ewl_IconBox* ib) {
+       Ewl_IconBox_Icon* list_item;
+       nextx = 0;
+
+       /*printf("*** Deleting all icons...\n");*/
+
+       if (ib->ewl_iconbox_icon_list) {
+               ecore_list_goto_first(ib->ewl_iconbox_icon_list);
+               while((list_item = 
(Ewl_IconBox_Icon*)ecore_list_next(ib->ewl_iconbox_icon_list)) != NULL) {
+                       /*printf("Deleting icon..\n");*/
+                       if (list_item->label) {
+                               free(list_item->label);
+                       }
+                       if (list_item->label_compressed) {
+                               free(list_item->label_compressed);
+                       }
+
+                       
ewl_container_child_remove(EWL_CONTAINER(ib->ewl_iconbox_pane_inner), 
EWL_WIDGET(list_item));
+                       ewl_widget_destroy(EWL_WIDGET(list_item));              
+               }
+               /*printf("...dione\n");*/
+
+               ecore_list_destroy(ib->ewl_iconbox_icon_list);
+       }
+       
+       ib->ewl_iconbox_icon_list = ecore_list_new();
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_iconbox.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ewl_iconbox.h       17 Jul 2005 23:06:02 -0000      1.4
+++ ewl_iconbox.h       24 Jul 2005 23:35:35 -0000      1.5
@@ -5,6 +5,7 @@
 #define EWL_ICONBOX_ICON_PADDING 15
 #define EWL_ICONBOX_MOVE_TOLERANCE 5
 #define EWL_ICONBOX_MINIMUM_SIZE 50
+#define LABEL_CHARS 10
 
 /**
  * @file ewl_iconbox.h
@@ -33,6 +34,8 @@
        int drag;
        int selected ;
        Ewl_IconBox* icon_box_parent; /* Our reference upwards, kinda breaks OO 
conventions */
+       char* label;                  /*Our icon's full (unabbreviated) label) 
*/
+       char* label_compressed;
 };
 
 
@@ -101,6 +104,7 @@
 void ewl_iconbox_icon_arrange(Ewl_IconBox* ib);
 void ewl_iconbox_deselect_all(Ewl_IconBox* ib);
 Ewl_IconBox_Icon* ewl_iconbox_icon_add(Ewl_IconBox* iconbox, char* name, char* 
icon_file);
+void ewl_iconbox_clear(Ewl_IconBox* iconbox);
 void ewl_iconbox_icon_image_set(Ewl_IconBox_Icon* icon, char* filename);
 
 




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to