Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_icon.c ewl_enums.h ewl_icon.h Log Message: - You can now use a label instead of a heavy Ewl_Text and an image instead of a thumbnail - you can now hide the label or the image of the icon =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_icon.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -3 -r1.24 -r1.25 --- ewl_icon.c 3 Dec 2006 06:21:33 -0000 1.24 +++ ewl_icon.c 7 Dec 2006 19:07:07 -0000 1.25 @@ -16,7 +16,10 @@ static void ewl_icon_cb_entry_value_changed(Ewl_Widget *w, void *ev, void *data); static void ewl_icon_cb_thumb_value_changed(Ewl_Widget *w, void *ev, void *data); -static void ewl_icon_update_label(Ewl_Icon *icon); +static void ewl_icon_parts_update(Ewl_Icon *icon); +static void ewl_icon_label_build(Ewl_Icon *icon); +static void ewl_icon_label_text_set(Ewl_Icon *icon, const char *txt); +static void ewl_icon_label_update(Ewl_Icon *icon); /** * @return Returns a new Ewl_Icon widget, or NULL on failure @@ -43,6 +46,37 @@ } /** + * @return Returns a new Ewl_Icon widget, or NULL on failure + * @brief Creates and initializes a new Ewl_Icon widget + * + * The difference to ewl_icon_new() is that it has lighter + * default values. The defaults are + * complex_label: no + * compressed_label: no + * editable: no + * thumbnailing: no + * + */ +Ewl_Widget * +ewl_icon_simple_new(void) +{ + Ewl_Widget *w; + + DENTER_FUNCTION(DLEVEL_STABLE); + + w = ewl_icon_new(); + if (!w) + DRETURN_PTR(NULL, DLEVEL_STABLE); + + ewl_icon_label_complex_set(EWL_ICON(w), FALSE); + ewl_icon_label_compressed_set(EWL_ICON(w), FALSE); + ewl_icon_thumbnailing_set(EWL_ICON(w), FALSE); + ewl_icon_editable_set(EWL_ICON(w), FALSE); + + DRETURN_PTR(w, DLEVEL_STABLE); +} + +/** * @param icon: The widget to initialize * @return Returns TRUE on successful initialization, FALSE otherwise * @brief Initializes the given Ewl_Icon widget @@ -67,6 +101,11 @@ ewl_callback_prepend(EWL_WIDGET(icon), EWL_CALLBACK_DESTROY, ewl_icon_cb_destroy, NULL); + /* + * set some defaults + */ + icon->thumbnailing = TRUE; + icon->complex_label = TRUE; DRETURN_INT(TRUE, DLEVEL_STABLE); } @@ -118,6 +157,29 @@ } /** + * @param icon: The icon to set the part to hide of + * @param part: The part to hide + * @return Returns no value. + * @brief Hide the given part of the icon. Note: You can only hide one part. + */ +void +ewl_icon_part_hide(Ewl_Icon *icon, Ewl_Icon_Part part) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + if (icon->hidden == part) + DRETURN(DLEVEL_STABLE); + + icon->hidden = part; + + ewl_icon_parts_update(icon); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param icon: The Ewl_Icon to set the image into * @param file: The file with the image * @param key: The key inside the file if applicable @@ -144,17 +206,27 @@ img = ewl_image_new(); ewl_image_file_set(EWL_IMAGE(img), file, key); - icon->image = ewl_image_thumbnail_get(EWL_IMAGE(img)); - ewl_image_proportional_set(EWL_IMAGE(icon->image), TRUE); - ewl_callback_append(icon->image, EWL_CALLBACK_VALUE_CHANGED, + if (icon->thumbnailing) { + icon->image = ewl_image_thumbnail_get(EWL_IMAGE(img)); + ewl_callback_append(icon->image, EWL_CALLBACK_VALUE_CHANGED, ewl_icon_cb_thumb_value_changed, icon); - ewl_icon_constrain_set(icon, constrain); + ewl_icon_constrain_set(icon, constrain); + } + else + icon->image = img; + + ewl_image_proportional_set(EWL_IMAGE(icon->image), TRUE); ewl_object_alignment_set(EWL_OBJECT(icon->image), EWL_FLAG_ALIGN_CENTER); ewl_widget_internal_set(icon->image, TRUE); ewl_container_child_prepend(EWL_CONTAINER(icon), icon->image); - if (!icon->alt) + if (icon->hidden == EWL_ICON_PART_IMAGE) + DRETURN(DLEVEL_STABLE); + + if (!icon->thumbnailing) + ewl_icon_parts_update(icon); + else if (!icon->alt) { ewl_image_file_set(EWL_IMAGE(icon->image), ewl_icon_theme_icon_path_get( @@ -248,7 +320,7 @@ { if (icon->label) { - ewl_text_text_set(EWL_TEXT(icon->label), NULL); + ewl_icon_label_text_set(icon, NULL); IF_FREE(icon->label_text); } @@ -256,37 +328,10 @@ } if (!icon->label) - { - icon->label = ewl_text_new(); - ewl_object_fill_policy_set(EWL_OBJECT(icon->label), - EWL_FLAG_FILL_NONE); - ewl_object_alignment_set(EWL_OBJECT(icon->label), - EWL_FLAG_ALIGN_CENTER); - - if (icon->editable) - ewl_callback_append(icon->label, - EWL_CALLBACK_MOUSE_DOWN, - ewl_icon_cb_label_mouse_down, icon); - - ewl_widget_show(icon->label); - - /* if we have a image make sure we are after it, but - * before anything that is after the image */ - if (icon->image && icon->extended) - { - int idx; - idx = ewl_container_child_index_get(EWL_CONTAINER(icon), - icon->image); - ewl_container_child_insert_internal(EWL_CONTAINER(icon), - icon->label, idx + 1); - } - else - ewl_container_child_append(EWL_CONTAINER(icon), - icon->label); - } + ewl_icon_label_build(icon); icon->label_text = strdup(label); - ewl_icon_update_label(icon); + ewl_icon_label_update(icon); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -449,7 +494,7 @@ DRETURN(DLEVEL_STABLE); icon->compress_label = !!compress; - ewl_icon_update_label(icon); + ewl_icon_label_update(icon); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -470,6 +515,94 @@ } /** + * @param icon: The icon to set if it has a complex label or not + * @param c: The value to set as the complex flag + * @return Returns no value. + * @brief Set if the icon use a label or a text widget for the label + * part + */ +void +ewl_icon_label_complex_set(Ewl_Icon *icon, unsigned int c) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + if (icon->complex_label == !!c) + DRETURN(DLEVEL_STABLE); + + icon->complex_label = !!c; + + if (!icon->label) + DRETURN(DLEVEL_STABLE); + + /* + * we are now switching from Ewl_Label to Ewl_Text + * or vice-verse, so first of all destroy the current + * widget + */ + ewl_widget_destroy(icon->label); + icon->label = NULL; + + ewl_icon_label_build(icon); + ewl_icon_label_update(icon); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param icon: The icon to check if its label is complex + * @return Returns TRUE if the label is complex, FALSE otherwise + * @brief Retrieve if the icon has a complex label or not + */ +unsigned int +ewl_icon_label_complex_get(Ewl_Icon *icon) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("icon", icon, FALSE); + DCHECK_TYPE_RET("icon", icon, EWL_ICON_TYPE, FALSE); + + DRETURN_INT(icon->complex_label, DLEVEL_STABLE); +} + + +/** + * @param icon: The icon to set if the image gets thumbnailed + * @param c: The value to set as the thumbnail flag + * @return Returns no value. + * @brief Set if the icon thumbnailed the image or use it directly + */ +void +ewl_icon_thumbnailing_set(Ewl_Icon *icon, unsigned int t) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + if (icon->thumbnailing == !!t) + DRETURN(DLEVEL_STABLE); + + icon->thumbnailing = !!t; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param icon: The icon to check if it's thumbnails the image + * @return Returns TRUE if the label use thumbnailing, FALSE otherwise + * @brief Retrieve if the icon use thumbnailing + */ +unsigned int +ewl_icon_thumbnailing_get(Ewl_Icon *icon) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("icon", icon, FALSE); + DCHECK_TYPE_RET("icon", icon, EWL_ICON_TYPE, FALSE); + + DRETURN_INT(icon->thumbnailing, DLEVEL_STABLE); +} + +/** * @param icon: The icon to work with * @param txt: The text to set as the alternate text * @return Returns no value @@ -626,7 +759,116 @@ } static void -ewl_icon_update_label(Ewl_Icon *icon) +ewl_icon_parts_update(Ewl_Icon *icon) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + /* + * show both the label and the image + */ + if (icon->hidden == EWL_ICON_PART_NONE) { + if (icon->label) + ewl_widget_show(icon->label); + if (icon->image) + ewl_widget_show(icon->image); + } + /* + * show only the label + */ + else if (icon->hidden == EWL_ICON_PART_IMAGE) { + if (icon->label && icon->image) { + ewl_widget_show(icon->label); + ewl_widget_hide(icon->image); + } + else if (icon->label) + ewl_widget_show(icon->label); + /* + * show the image if there is no label + */ + else if (icon->image) + ewl_widget_show(icon->image); + } + /* + * show only the image + */ + else if (icon->hidden == EWL_ICON_PART_LABEL) { + if (icon->label && icon->image) { + ewl_widget_show(icon->image); + ewl_widget_hide(icon->label); + } + else if (icon->image) + ewl_widget_show(icon->image); + /* + * show label if there is no image + */ + else if (icon->label) + ewl_widget_show(icon->label); + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static void +ewl_icon_label_build(Ewl_Icon *icon) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + if (icon->complex_label) + icon->label = ewl_text_new(); + else + icon->label = ewl_label_new(); + + ewl_object_fill_policy_set(EWL_OBJECT(icon->label), + EWL_FLAG_FILL_NONE); + ewl_object_alignment_set(EWL_OBJECT(icon->label), + EWL_FLAG_ALIGN_CENTER); + + if (icon->editable) + ewl_callback_append(icon->label, + EWL_CALLBACK_MOUSE_DOWN, + ewl_icon_cb_label_mouse_down, icon); + + if (icon->hidden != EWL_ICON_PART_LABEL) + ewl_widget_show(icon->label); + + /* if we have a image make sure we are after it, but + * before anything that is after the image */ + if (icon->image && icon->extended) + { + int idx; + idx = ewl_container_child_index_get(EWL_CONTAINER(icon), + icon->image); + ewl_container_child_insert_internal(EWL_CONTAINER(icon), + icon->label, idx + 1); + } + else + ewl_container_child_append(EWL_CONTAINER(icon), + icon->label); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static void +ewl_icon_label_text_set(Ewl_Icon *icon, const char *txt) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("icon", icon); + DCHECK_TYPE("icon", icon, EWL_ICON_TYPE); + + if (icon->complex_label) + ewl_text_text_set(EWL_TEXT(icon->label), txt); + else + ewl_label_text_set(EWL_LABEL(icon->label), txt); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +static void +ewl_icon_label_update(Ewl_Icon *icon) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("icon", icon); @@ -644,12 +886,12 @@ c = NEW(char, EWL_ICON_COMPRESS_SIZE + 4); strncpy(c, icon->label_text, EWL_ICON_COMPRESS_SIZE); strcat(c, "..."); - - ewl_text_text_set(EWL_TEXT(icon->label), c); + + ewl_icon_label_text_set(icon, c); FREE(c); } else - ewl_text_text_set(EWL_TEXT(icon->label), icon->label_text); + ewl_icon_label_text_set(icon, icon->label_text); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_enums.h,v retrieving revision 1.67 retrieving revision 1.68 diff -u -3 -r1.67 -r1.68 --- ewl_enums.h 5 Dec 2006 06:26:34 -0000 1.67 +++ ewl_enums.h 7 Dec 2006 19:07:07 -0000 1.68 @@ -553,6 +553,22 @@ typedef enum Ewl_Icon_Type Ewl_Icon_Type; /** + * @enum Ewl_Icon_Part + * The different Parts of an Icon + */ +enum Ewl_Icon_Part +{ + EWL_ICON_PART_NONE, + EWL_ICON_PART_IMAGE, + EWL_ICON_PART_LABEL +}; + +/** + * The Ewl_Icon_Part + */ +typedef enum Ewl_Icon_Part Ewl_Icon_Part; + +/** * @enum Ewl_Freebox_Layout_Type * The possibly layout settings for the freebox */ =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_icon.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- ewl_icon.h 4 Dec 2006 07:16:39 -0000 1.10 +++ ewl_icon.h 7 Dec 2006 19:07:07 -0000 1.11 @@ -43,41 +43,54 @@ char *label_text; /**< The label text */ Ewl_Icon_Type type; /**< The icons type */ + Ewl_Icon_Part hidden; /**< The hidden part */ unsigned char editable:1; /**< Is the icon editable? */ unsigned char compress_label:1; /**< Should the label be compressed? */ + unsigned char complex_label:1; /**< Should the label be a Ewl_Text? */ + unsigned char thumbnailing:1; /**< Should the image be thumbnailed?*/ }; Ewl_Widget *ewl_icon_new(void); +Ewl_Widget *ewl_icon_simple_new(void); int ewl_icon_init(Ewl_Icon *icon); void ewl_icon_type_set(Ewl_Icon *icon, Ewl_Icon_Type type); Ewl_Icon_Type ewl_icon_type_get(Ewl_Icon *icon); +void ewl_icon_part_hide(Ewl_Icon *icon, Ewl_Icon_Part part); + void ewl_icon_image_set(Ewl_Icon *icon, const char *file, const char *key); const char *ewl_icon_image_file_get(Ewl_Icon *icon); -void ewl_icon_editable_set(Ewl_Icon *icon, unsigned int e); -unsigned int ewl_icon_editable_get(Ewl_Icon *icon); +void ewl_icon_thumbnailing_set(Ewl_Icon *icon, unsigned int thumb); +unsigned int ewl_icon_thumbnailing_get(Ewl_Icon *icon); -void ewl_icon_label_set(Ewl_Icon *icon, const char *label); -const char *ewl_icon_label_get(Ewl_Icon *icon); +void ewl_icon_constrain_set(Ewl_Icon *icon, unsigned int val); +unsigned int ewl_icon_constrain_get(Ewl_Icon *icon); -void ewl_icon_extended_data_set(Ewl_Icon *icon, Ewl_Widget *ext); -Ewl_Widget *ewl_icon_extended_data_get(Ewl_Icon *icon); +void ewl_icon_alt_text_set(Ewl_Icon *icon, const char *txt); +const char *ewl_icon_alt_text_get(Ewl_Icon *icon); -void ewl_icon_menu_set(Ewl_Icon *icon, Ewl_Widget *menu); -Ewl_Widget *ewl_icon_menu_get(Ewl_Icon *icon); +void ewl_icon_label_set(Ewl_Icon *icon, const char *label); +const char *ewl_icon_label_get(Ewl_Icon *icon); -void ewl_icon_constrain_set(Ewl_Icon *icon, unsigned int val); -unsigned int ewl_icon_constrain_get(Ewl_Icon *icon); +void ewl_icon_editable_set(Ewl_Icon *icon, unsigned int e); +unsigned int ewl_icon_editable_get(Ewl_Icon *icon); void ewl_icon_label_compressed_set(Ewl_Icon *icon, unsigned int compress); unsigned int ewl_icon_label_compressed_get(Ewl_Icon *icon); -void ewl_icon_alt_text_set(Ewl_Icon *icon, const char *txt); -const char *ewl_icon_alt_text_get(Ewl_Icon *icon); +void ewl_icon_label_complex_set(Ewl_Icon *icon, + unsigned int complex_label); +unsigned int ewl_icon_label_complex_get(Ewl_Icon *icon); + +void ewl_icon_extended_data_set(Ewl_Icon *icon, Ewl_Widget *ext); +Ewl_Widget *ewl_icon_extended_data_get(Ewl_Icon *icon); + +void ewl_icon_menu_set(Ewl_Icon *icon, Ewl_Widget *menu); +Ewl_Widget *ewl_icon_menu_get(Ewl_Icon *icon); /* * Internal stuff ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs