Enlightenment CVS committal Author : moom Project : e17 Module : libs/etk
Dir : e17/libs/etk/src/lib Modified Files: etk_button.c etk_button.h etk_widget.c Log Message: * [Button] Fix potential bugs and cleanup/doc =================================================================== RCS file: /cvs/e/e17/libs/etk/src/lib/etk_button.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- etk_button.c 22 Feb 2007 04:36:25 -0000 1.34 +++ etk_button.c 23 Feb 2007 03:25:39 -0000 1.35 @@ -119,9 +119,10 @@ } /** - * @brief Creates a new button with a label and an icon defined by a stock id - * @param stock_id the stock id corresponding to the label and the icon to use + * @brief Creates a new button with a label and an icon defined by a stock-id + * @param stock_id the stock-id corresponding to the label and the icon to use * @return Returns the new button + * @note For some stock-id, the label is empty * @see Etk_Stock */ Etk_Widget *etk_button_new_from_stock(Etk_Stock_Id stock_id) @@ -135,7 +136,7 @@ } /** - * @brief Presses the button (the button should be released) + * @brief Presses the button if it wasn't already pressed * @param button a button */ void etk_button_press(Etk_Button *button) @@ -148,7 +149,7 @@ } /** - * @brief Releases the button (the button should be pressed) + * @brief Releases the button if it was pressed * @param button a button */ void etk_button_release(Etk_Button *button) @@ -178,30 +179,34 @@ */ void etk_button_label_set(Etk_Button *button, const char *label) { - Etk_Widget *widget, *parent; + Etk_Widget *parent; Etk_Bool rebuild; - if (!(widget = ETK_WIDGET(button))) + if (!button) return; etk_label_set(ETK_LABEL(button->label), label); - if (!label || *label == '\0') - etk_widget_hide(button->label); - else - etk_widget_show(button->label); /* Rebuild the button only if necessary (i.e. if the label is currently not packed into the button) */ rebuild = ETK_TRUE; for (parent = etk_widget_parent_get(button->label); parent; parent = etk_widget_parent_get(parent)) { - if (parent == widget) + if (parent == ETK_WIDGET(button)) { rebuild = ETK_FALSE; break; } } + if (rebuild) _etk_button_rebuild(button); + else + { + if (!label || *label == '\0') + etk_widget_hide(button->label); + else + etk_widget_show(button->label); + } etk_object_notify(ETK_OBJECT(button), "label"); } @@ -219,9 +224,13 @@ } /** - * @brief Sets the image of the button. The current image will be unpacked, but not destroyed + * @brief Sets the image of the button * @param button a button * @param image the image to set + * @note The current image will be destroyed only if it has been set with etk_button_new_from_stock() + * or with etk_button_set_from_stock(). Otherwise, it will just be unpacked and you'll still be able to use it + * @note The image will be automatically shown, but you can still manually hide it with calling etk_widget_hide() + * after having called etk_button_image_set() */ void etk_button_image_set(Etk_Button *button, Etk_Image *image) { @@ -230,12 +239,16 @@ if (button->image) { - etk_signal_block("child_removed", ETK_OBJECT(button->box), ETK_CALLBACK(_etk_button_image_removed_cb)); - etk_container_remove(ETK_CONTAINER(button->box), ETK_WIDGET(button->image)); - etk_signal_unblock("child_removed", ETK_OBJECT(button->box), ETK_CALLBACK(_etk_button_image_removed_cb)); + button->ignore_image_remove = ETK_TRUE; + if (button->image_from_stock) + etk_object_destroy(ETK_OBJECT(button->image)); + else + etk_container_remove(ETK_CONTAINER(button->box), ETK_WIDGET(button->image)); + button->ignore_image_remove = ETK_FALSE; } button->image = image; + button->image_from_stock = ETK_FALSE; _etk_button_rebuild(button); etk_object_notify(ETK_OBJECT(button), "image"); } @@ -243,7 +256,7 @@ /** * @brief Gets the image of the button * @param button a button - * @return Returns the image of button + * @return Returns the image of the button, or NULL if the button has no image */ Etk_Image *etk_button_image_get(Etk_Button *button) { @@ -253,9 +266,10 @@ } /** - * @brief Sets the label and the image of the button from a stock id + * @brief Sets the label and the image of the button from a stock-id * @param button a button - * @param stock_id the stock id to use + * @param stock_id the stock-id to use + * @note For some stock-id, the label is empty */ void etk_button_set_from_stock(Etk_Button *button, Etk_Stock_Id stock_id) { @@ -270,15 +284,16 @@ image = etk_image_new_from_stock(stock_id, button->stock_size); etk_widget_internal_set(image, ETK_TRUE); - etk_widget_show(image); etk_button_image_set(ETK_BUTTON(button), ETK_IMAGE(image)); + button->image_from_stock = ETK_TRUE; } /** - * @brief Sets the alignment of the child of the button (it only has effect if the child is a label, or an alignment) + * @brief Sets the alignment of the child of the button * @param button a button * @param xalign the horizontal alignment (0.0 = left, 0.5 = center, 1.0 = right, ...) * @param yalign the vertical alignment (0.0 = top, 0.5 = center, 1.0 = bottom, ...) + * @note It only has effect if the child is a label or an alignment */ void etk_button_alignment_set(Etk_Button *button, float xalign, float yalign) { @@ -314,7 +329,7 @@ } /** - * @brief Gets the alignment of the child of the button + * @brief Gets the alignment of the button's child * @param button a button * @param xalign the location where to store the horizontal alignment * @param yalign the location where to store the vertical alignment @@ -340,17 +355,13 @@ button->style = style; if (button->box) { - if (button->image) - { - etk_signal_block("child_removed", ETK_OBJECT(button->box), ETK_CALLBACK(_etk_button_image_removed_cb)); - etk_container_remove(ETK_CONTAINER(button->box), ETK_WIDGET(button->image)); - etk_signal_unblock("child_removed", ETK_OBJECT(button->box), ETK_CALLBACK(_etk_button_image_removed_cb)); - } - if (button->label) - etk_container_remove(ETK_CONTAINER(button->box), ETK_WIDGET(button->label)); + button->ignore_image_remove = ETK_TRUE; + etk_container_remove_all(ETK_CONTAINER(button->box)); etk_object_destroy(ETK_OBJECT(button->box)); + button->ignore_image_remove = ETK_FALSE; button->box = NULL; } + _etk_button_rebuild(button); etk_object_notify(ETK_OBJECT(button), "style"); } @@ -432,8 +443,9 @@ button->released = _etk_button_released_handler; button->clicked = _etk_button_clicked_handler; - button->building = ETK_FALSE; + button->ignore_image_remove = ETK_FALSE; button->is_pressed = ETK_FALSE; + button->image_from_stock = ETK_FALSE; button->xalign = 0.5; button->yalign = 0.5; @@ -537,10 +549,12 @@ if (!(button = ETK_BUTTON(data)) || (child != ETK_WIDGET(button->image))) return; - if (!button->building) + if (!button->ignore_image_remove) { button->image = NULL; - _etk_button_rebuild(button); + /* We rebuild the button only if the button's child is not a user-defined widget */ + if (button->alignment == etk_bin_child_get(ETK_BIN(button))) + _etk_button_rebuild(button); etk_object_notify(ETK_OBJECT(button), "image"); } } @@ -640,22 +654,24 @@ etk_widget_theme_signal_emit(ETK_WIDGET(button), "etk,state,clicked", ETK_FALSE); } -/* Rebuilds the children of the button */ +/* Rebuilds the default layout for the button */ static void _etk_button_rebuild(Etk_Button *button) { + const char *text; + if (!button) return; - button->building = ETK_TRUE; + button->ignore_image_remove = ETK_TRUE; + /* Rebuild the containers containing the label and image */ if (button->image) { if (!button->alignment) { button->alignment = etk_alignment_new(button->xalign, button->yalign, 0.0, 0.0); - etk_container_add(ETK_CONTAINER(button), button->alignment); etk_widget_internal_set(button->alignment, ETK_TRUE); - etk_widget_pass_mouse_events_set(button->alignment, ETK_TRUE); + etk_container_add(ETK_CONTAINER(button), button->alignment); etk_widget_show(button->alignment); } @@ -665,11 +681,11 @@ button->box = etk_vbox_new(ETK_FALSE, 2); else button->box = etk_hbox_new(ETK_FALSE, 8); - etk_container_add(ETK_CONTAINER(button->alignment), button->box); etk_widget_internal_set(button->box, ETK_TRUE); - etk_widget_pass_mouse_events_set(button->box, ETK_TRUE); + etk_container_add(ETK_CONTAINER(button->alignment), button->box); etk_widget_show(button->box); - etk_signal_connect("child_removed", ETK_OBJECT(button->box), ETK_CALLBACK(_etk_button_image_removed_cb), button); + etk_signal_connect("child_removed", ETK_OBJECT(button->box), + ETK_CALLBACK(_etk_button_image_removed_cb), button); } else etk_container_remove_all(ETK_CONTAINER(button->box)); @@ -685,17 +701,24 @@ etk_object_destroy(ETK_OBJECT(button->alignment)); button->alignment = NULL; button->box = NULL; - + etk_label_alignment_set(ETK_LABEL(button->label), button->xalign, button->yalign); etk_container_add(ETK_CONTAINER(button), button->label); } - if (button->style == ETK_BUTTON_TEXT) - etk_widget_hide(ETK_WIDGET(button->image)); - else if (button->style == ETK_BUTTON_ICON) + /* Show/hide the label and the image */ + text = etk_label_get(ETK_LABEL(button->label)); + if (button->style != ETK_BUTTON_ICON && text && *text != '\0') + etk_widget_show(button->label); + else etk_widget_hide(button->label); - button->building = ETK_FALSE; + if (button->style != ETK_BUTTON_TEXT) + etk_widget_show(ETK_WIDGET(button->image)); + else + etk_widget_hide(ETK_WIDGET(button->image)); + + button->ignore_image_remove = ETK_FALSE; } /** @} */ @@ -712,7 +735,7 @@ * @image html widgets/button.png * An Etk_Button usually contains only a label and an icon, but it can contain any type of widgets. @n * You can change the label of the button with etk_button_label_set(), and you can change its icon with - * etk_button_image_set() + * etk_button_image_set(). You can also pack your own widget with etk_bin_child_set() * * \par Object Hierarchy: * - Etk_Object =================================================================== RCS file: /cvs/e/e17/libs/etk/src/lib/etk_button.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- etk_button.h 22 Feb 2007 04:36:25 -0000 1.14 +++ etk_button.h 23 Feb 2007 03:25:40 -0000 1.15 @@ -19,10 +19,8 @@ /** Checks if the object is an Etk_Button */ #define ETK_IS_BUTTON(obj) (ETK_OBJECT_CHECK_TYPE((obj), ETK_BUTTON_TYPE)) -/** - * @enum Etk_Button_Style - * @brief The button's style (icon, text, both vertically, both horizontally) - */ + +/** @brief The button's style (icon, text, both vertically, both horizontally) */ typedef enum Etk_Button_Style { ETK_BUTTON_ICON, /**< Only the icon is visible */ @@ -31,6 +29,7 @@ ETK_BUTTON_BOTH_VERT /**< Both the icon and the label are visible, the icon is above the label */ } Etk_Button_Style; + /** * @brief @widget A widget that can be pressed, released or clicked * @structinfo @@ -50,13 +49,15 @@ void (*released)(Etk_Button *button); void (*clicked)(Etk_Button *button); - Etk_Bool building; Etk_Bool is_pressed; + Etk_Bool ignore_image_remove; + Etk_Bool image_from_stock; float xalign; float yalign; Etk_Button_Style style; Etk_Stock_Size stock_size; }; + Etk_Type *etk_button_type_get(void); Etk_Widget *etk_button_new(void); =================================================================== RCS file: /cvs/e/e17/libs/etk/src/lib/etk_widget.c,v retrieving revision 1.98 retrieving revision 1.99 diff -u -3 -r1.98 -r1.99 --- etk_widget.c 22 Feb 2007 22:24:25 -0000 1.98 +++ etk_widget.c 23 Feb 2007 03:25:40 -0000 1.99 @@ -1693,7 +1693,7 @@ */ void etk_widget_dnd_source_set(Etk_Widget *widget, Etk_Bool on) { - if (!widget) + //if (!widget) return; if (on) @@ -1767,7 +1767,7 @@ */ void etk_widget_dnd_drag_widget_set(Etk_Widget *widget, Etk_Widget *drag_widget) { - if(!widget || !drag_widget) + //if(!widget || !drag_widget) return; etk_container_add(ETK_CONTAINER(widget->drag), drag_widget); ------------------------------------------------------------------------- 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