Enlightenment CVS committal
Author : rbdpngn
Project : e17
Module : libs/ewl
Dir : e17/libs/ewl/src/lib
Modified Files:
ewl_combo.c ewl_iconbox.c ewl_imenu.c ewl_imenu.h ewl_menu.c
ewl_menu.h ewl_menu_base.c ewl_menu_base.h ewl_menubar.c
Log Message:
Convert the menu API to the new constructor style.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_combo.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- ewl_combo.c 9 Oct 2005 05:18:39 -0000 1.7
+++ ewl_combo.c 10 Oct 2005 18:43:31 -0000 1.8
@@ -42,7 +42,8 @@
/*
* Initialize the defaults of the inherited fields.
*/
- ewl_menu_base_init(EWL_MENU_BASE(combo), NULL, title);
+ ewl_menu_base_init(EWL_MENU_BASE(combo));
+ ewl_menu_item_text_set(EWL_MENU_ITEM(combo), title);
ewl_object_fill_policy_set(EWL_OBJECT(combo), EWL_FLAG_FILL_HFILL |
EWL_FLAG_FILL_HSHRINK);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_iconbox.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -3 -r1.27 -r1.28
--- ewl_iconbox.c 9 Oct 2005 23:34:05 -0000 1.27
+++ ewl_iconbox.c 10 Oct 2005 18:43:31 -0000 1.28
@@ -204,20 +204,26 @@
/* Get the context menu ready */
- ib->ewl_iconbox_context_menu = ewl_imenu_new(NULL, "");
+ ib->ewl_iconbox_context_menu = ewl_imenu_new();
+ ewl_menu_item_text_set(EWL_MENU_ITEM(ib->ewl_iconbox_context_menu), "");
ewl_container_child_append(EWL_CONTAINER(ib->ewl_iconbox_menu_floater),
ib->ewl_iconbox_context_menu);
ewl_widget_show(ib->ewl_iconbox_context_menu);
/* Add auto-arrange ability */
- ib->ewl_iconbox_view_menu = ewl_imenu_new(NULL, "View");
+ ib->ewl_iconbox_view_menu = ewl_imenu_new();
+ ewl_menu_item_text_set(EWL_MENU_ITEM(ib->ewl_iconbox_view_menu),
+ "View");
ewl_container_child_append(EWL_CONTAINER(ib->ewl_iconbox_context_menu),
ib->ewl_iconbox_view_menu);
- ib->ewl_iconbox_context_menu_item = ewl_menu_item_new(NULL,
"Auto-Arrange");
+ ib->ewl_iconbox_context_menu_item = ewl_menu_item_new();
+ ewl_menu_item_text_set(EWL_MENU_ITEM(ib->ewl_iconbox_context_menu_item),
+ "Auto-Arrange");
ewl_container_child_append(EWL_CONTAINER(ib->ewl_iconbox_view_menu),
ib->ewl_iconbox_context_menu_item);
ewl_callback_append(ib->ewl_iconbox_context_menu_item,
EWL_CALLBACK_MOUSE_DOWN, ewl_iconbox_arrange_cb, ib);
ewl_widget_show(ib->ewl_iconbox_context_menu_item);
- ib->ewl_iconbox_context_menu_item = ewl_menu_item_new(NULL, "Expansion
Test");
+ ib->ewl_iconbox_context_menu_item = ewl_menu_item_new();
+
ewl_menu_item_text_set(EWL_MENU_ITEM(ib->ewl_iconbox_context_menu_item),
"Expansion Test");
ewl_container_child_append(EWL_CONTAINER(ib->ewl_iconbox_view_menu),
ib->ewl_iconbox_context_menu_item);
ewl_callback_append(ib->ewl_iconbox_context_menu_item,
EWL_CALLBACK_MOUSE_DOWN, ewl_iconbox_expansion_cb, ib);
ewl_widget_show(ib->ewl_iconbox_context_menu_item);
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_imenu.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ewl_imenu.c 9 Oct 2005 05:18:39 -0000 1.4
+++ ewl_imenu.c 10 Oct 2005 18:43:31 -0000 1.5
@@ -4,12 +4,10 @@
#include "ewl_private.h"
/**
- * @param image: the image icon to use for this menu
- * @param title: the text to place in the menu
* @return Returns a pointer to a new menu on success, NULL on failure.
* @brief Create a new internal menu
*/
-Ewl_Widget *ewl_imenu_new(char *image, char *title)
+Ewl_Widget *ewl_imenu_new(void)
{
Ewl_IMenu *menu;
@@ -19,7 +17,7 @@
if (!menu)
DRETURN_PTR(NULL, DLEVEL_STABLE);
- ewl_imenu_init(menu, image, title);
+ ewl_imenu_init(menu);
DRETURN_PTR(EWL_WIDGET(menu), DLEVEL_STABLE);
}
@@ -27,12 +25,10 @@
/**
* @param menu: the menu to initialize
- * @param image: the path to the icon image
- * @param title: the string displayed in the title
* @return Returns no value.
* @brief Initialize an internal menu to starting values
*/
-void ewl_imenu_init(Ewl_IMenu * menu, char *image, char *title)
+void ewl_imenu_init(Ewl_IMenu * menu)
{
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -41,7 +37,7 @@
/*
* Initialize the defaults of the inherited fields.
*/
- ewl_menu_base_init(EWL_MENU_BASE(menu), image, title);
+ ewl_menu_base_init(EWL_MENU_BASE(menu));
ewl_widget_inherit(EWL_WIDGET(menu), "imenu");
ewl_callback_append(EWL_WIDGET(menu), EWL_CALLBACK_SELECT,
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_imenu.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ewl_imenu.h 9 Feb 2005 20:44:12 -0000 1.2
+++ ewl_imenu.h 10 Oct 2005 18:43:31 -0000 1.3
@@ -36,8 +36,8 @@
Ewl_Menu_Base base;
};
-Ewl_Widget *ewl_imenu_new(char *image, char *title);
-void ewl_imenu_init(Ewl_IMenu * menu, char *image, char *title);
+Ewl_Widget *ewl_imenu_new(void);
+void ewl_imenu_init(Ewl_IMenu * menu);
/*
* Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- ewl_menu.c 9 Oct 2005 04:43:43 -0000 1.7
+++ ewl_menu.c 10 Oct 2005 18:43:31 -0000 1.8
@@ -9,7 +9,7 @@
* @return Returns a pointer to a new menu on success, NULL on failure.
* @brief Create a new internal menu
*/
-Ewl_Widget *ewl_menu_new(char *image, char *title)
+Ewl_Widget *ewl_menu_new(void)
{
Ewl_Menu *menu;
@@ -19,7 +19,7 @@
if (!menu)
DRETURN_PTR(NULL, DLEVEL_STABLE);
- ewl_menu_init(menu, image, title);
+ ewl_menu_init(menu);
DRETURN_PTR(EWL_WIDGET(menu), DLEVEL_STABLE);
}
@@ -32,7 +32,7 @@
* @return Returns no value.
* @brief Initialize an internal menu to starting values
*/
-void ewl_menu_init(Ewl_Menu * menu, char *image, char *title)
+void ewl_menu_init(Ewl_Menu * menu)
{
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -41,8 +41,7 @@
/*
* Initialize the defaults of the inherited fields.
*/
- ewl_menu_base_init(EWL_MENU_BASE(menu), image, title);
- ewl_widget_appearance_set(EWL_WIDGET(menu), "menu");
+ ewl_menu_base_init(EWL_MENU_BASE(menu));
ewl_widget_inherit(EWL_WIDGET(menu), "menu");
ewl_callback_append(EWL_WIDGET(menu), EWL_CALLBACK_SELECT,
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- ewl_menu.h 25 Apr 2005 05:44:19 -0000 1.3
+++ ewl_menu.h 10 Oct 2005 18:43:31 -0000 1.4
@@ -38,12 +38,9 @@
int popup_y;
};
-Ewl_Widget *ewl_menu_new (char *image,
- char *title);
+Ewl_Widget *ewl_menu_new(void);
-void ewl_menu_init (Ewl_Menu *menu,
- char *image,
- char *title);
+void ewl_menu_init(Ewl_Menu *menu);
/*
* Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu_base.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- ewl_menu_base.c 3 Oct 2005 06:43:07 -0000 1.6
+++ ewl_menu_base.c 10 Oct 2005 18:43:31 -0000 1.7
@@ -3,20 +3,15 @@
#include "ewl_macros.h"
#include "ewl_private.h"
-static int ewl_menu_item_image_create( Ewl_Menu_Item *item,
- char *image, char *text );
-
/**
* @param menu: the menu item to initialize
- * @param image: the icon for the menu item
- * @param title: the label for the menu item
* @return Returns nothing.
* @brief Initialize a menu item to default values
*
* Sets up the internal variables for the menu item and places the icon from
* @a image and label from @a title in the menu item.
*/
-void ewl_menu_base_init(Ewl_Menu_Base * menu, char *image, char *title)
+void ewl_menu_base_init(Ewl_Menu_Base * menu)
{
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -25,7 +20,7 @@
/*
* Initialize the defaults of the inherited fields.
*/
- ewl_menu_item_init(EWL_MENU_ITEM(menu), image, title);
+ ewl_menu_item_init(EWL_MENU_ITEM(menu));
ewl_widget_appearance_set(EWL_WIDGET(menu), "menu_base");
ewl_widget_inherit(EWL_WIDGET(menu), "menu_base");
@@ -64,12 +59,10 @@
}
/**
- * @param image: the path to the image to use as an icon
- * @param text: the text to display for the menu item
* @return Returns a pointer to a new menu item on success, NULL on failure.
* @brief Create a new menu item to place in a menu
*/
-Ewl_Widget *ewl_menu_item_new(char *image, char *text)
+Ewl_Widget *ewl_menu_item_new(void)
{
Ewl_Menu_Item *item;
@@ -79,22 +72,17 @@
if (!item)
DRETURN_PTR(NULL, DLEVEL_STABLE);
- ewl_menu_item_init(item, image, text);
+ ewl_menu_item_init(item);
DRETURN_PTR(EWL_WIDGET(item), DLEVEL_STABLE);
}
/**
* @param item: the item to be initialized
- * @param image: the path to image to be used, NULL for no image
- * @param text: the text for this menuitem
* @return Returns no value.
* @brief Initialize the fields of a menu item to their defaults
- *
- * Initializes a menu item to default values and adds the
- * image pointed to by the path @a image, and adds the text in @a text.
*/
-int ewl_menu_item_init(Ewl_Menu_Item * item, char *image, char *text)
+int ewl_menu_item_init(Ewl_Menu_Item * item)
{
DENTER_FUNCTION(DLEVEL_STABLE);
@@ -126,67 +114,6 @@
ewl_container_callback_intercept(EWL_CONTAINER(item),
EWL_CALLBACK_DESELECT);
- item->icon = NULL;
- if (!ewl_menu_item_image_create(item, image, text))
- DRETURN_INT(FALSE, DLEVEL_STABLE);
-
- /*
- * Create the text object for the menu item.
- */
- if (text) {
- item->text = ewl_text_new();
- ewl_text_text_set(EWL_TEXT(item->text), text);
- }
-
- if (item->text) {
- ewl_container_child_append(EWL_CONTAINER(item), item->text);
- ewl_object_alignment_set(EWL_OBJECT(item->text),
- EWL_FLAG_ALIGN_LEFT);
- ewl_widget_show(item->text);
- }
- else
- DRETURN_INT(FALSE, DLEVEL_STABLE);
-
- DRETURN_INT(TRUE, DLEVEL_STABLE);
-}
-
-static int ewl_menu_item_image_create( Ewl_Menu_Item *item,
- char *image, char *text ) {
- Ewl_Container *redirect;
-
- if (item->icon)
- ewl_widget_destroy(item->icon);
-
- redirect = ewl_container_redirect_get(EWL_CONTAINER(item));
-
- ewl_container_redirect_set(EWL_CONTAINER(item), NULL);
-
- /*
- * Create the icon if one is requested, or a spacer if not, but there is
- * text to be displayed.
- */
- if (image) {
- item->icon = ewl_image_new();
- ewl_image_file_set(EWL_IMAGE(item->icon), image, NULL);
- }
- else if (text)
- item->icon = ewl_spacer_new();
-
- if (!item->icon)
- DRETURN_INT(FALSE, DLEVEL_STABLE);
-
- /*
- * Did we create an icon or a placeholder? Goodie, then finish it's
- * setup. We don't always want to create one, in the case that a
- * separator is going to be packed in here instead.
- */
- ewl_object_alignment_set(EWL_OBJECT(item->icon), EWL_FLAG_ALIGN_CENTER);
- ewl_object_maximum_size_set(EWL_OBJECT(item->icon), 20, 20);
- ewl_container_child_prepend(EWL_CONTAINER(item), item->icon);
- ewl_widget_show(item->icon);
-
- ewl_container_redirect_set(EWL_CONTAINER(item), redirect);
-
DRETURN_INT(TRUE, DLEVEL_STABLE);
}
@@ -211,8 +138,46 @@
void
ewl_menu_item_text_set( Ewl_Menu_Item *item, char *text )
{
- if (item->text)
- ewl_text_text_set(EWL_TEXT(item->text), text);
+ Ewl_Container *redirect;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("item", item);
+
+ /*
+ * Save and restore after we've made our changes.
+ */
+ redirect = ewl_container_redirect_get(EWL_CONTAINER(item));
+ ewl_container_redirect_set(EWL_CONTAINER(item), NULL);
+
+ if (text) {
+
+ /*
+ * Setup the text object and add it to the menu.
+ */
+ if (!item->text) {
+ item->text = ewl_text_new();
+ ewl_container_child_append(EWL_CONTAINER(item),
+ item->text);
+ ewl_widget_show(item->text);
+ }
+
+ /*
+ * Set the request text.
+ */
+ if (item->text) {
+ ewl_text_text_set(EWL_TEXT(item->text), text);
+ if (!item->icon)
+ ewl_menu_item_image_set(item, NULL);
+ }
+ }
+ else if (item->text) {
+ ewl_widget_destroy(item->text);
+ item->text = NULL;
+ }
+
+ ewl_container_redirect_set(EWL_CONTAINER(item), redirect);
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
}
/**
@@ -221,8 +186,11 @@
* @brief Get the image of a menu item
*/
char *
-ewl_menu_item_image_get( Ewl_Menu_Item *item )
+ewl_menu_item_image_get(Ewl_Menu_Item *item)
{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET("item", item, NULL);
+
if (item->icon && ewl_widget_type_is(item->icon, "image"))
DRETURN_PTR(ewl_image_file_get(EWL_IMAGE(item->icon)),
DLEVEL_STABLE);
DRETURN_PTR(NULL, DLEVEL_STABLE);
@@ -236,12 +204,60 @@
void
ewl_menu_item_image_set( Ewl_Menu_Item *item, char *image )
{
- if (item->icon && ewl_widget_type_is(item->icon, "image"))
- ewl_image_file_set(EWL_IMAGE(item->icon), image, NULL);
- else {
- ewl_menu_item_image_create( item, image,
- ewl_text_text_get(EWL_TEXT(item->text)) );
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR("item", item);
+
+ /*
+ * Destroy the icon if it's the wrong type.
+ */
+ if ((item->icon && (image && !ewl_widget_type_is(item->icon, "image")))
+ || (!image && (!ewl_widget_type_is(item->icon,
"spacer")))) {
+ ewl_widget_destroy(item->icon);
+ item->icon = NULL;
}
+
+ /*
+ * Create the appropriate widget if necessary.
+ */
+ if (!item->icon) {
+ Ewl_Container *redirect;
+
+ /*
+ * Save the current redirect and override to avoid issues with
+ * submenus
+ */
+ redirect = ewl_container_redirect_get(EWL_CONTAINER(item));
+ ewl_container_redirect_set(EWL_CONTAINER(item), NULL);
+
+ /*
+ * Create the icon if one is requested, or a spacer if not, but
+ * there is text to be displayed.
+ */
+ if (image)
+ item->icon = ewl_image_new();
+ else if (item->text)
+ item->icon = ewl_spacer_new();
+
+ /*
+ * Setup display prperties on icon if created.
+ */
+ if (item->icon) {
+ ewl_object_alignment_set(EWL_OBJECT(item->icon),
+ EWL_FLAG_ALIGN_CENTER);
+ ewl_object_maximum_size_set(EWL_OBJECT(item->icon),
+ 20, 20);
+ ewl_container_child_prepend(EWL_CONTAINER(item),
+ item->icon);
+ ewl_widget_show(item->icon);
+ }
+
+ ewl_container_redirect_set(EWL_CONTAINER(item), redirect);
+ }
+
+ if (image && item->icon)
+ ewl_image_file_set(EWL_IMAGE(item->icon), image, NULL);
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
}
/**
@@ -279,7 +295,7 @@
DCHECK_PARAM_PTR("sep", sep);
- ewl_menu_item_init(EWL_MENU_ITEM(sep), NULL, NULL);
+ ewl_menu_item_init(EWL_MENU_ITEM(sep));
separator = ewl_separator_new(EWL_ORIENTATION_HORIZONTAL);
if (!separator)
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menu_base.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- ewl_menu_base.h 25 Apr 2005 05:44:19 -0000 1.4
+++ ewl_menu_base.h 10 Oct 2005 18:43:31 -0000 1.5
@@ -37,7 +37,7 @@
*/
struct Ewl_Menu_Item
{
- Ewl_Box box; /**< Inherit from Ewl_Container */
+ Ewl_Box box; /**< Inherit from Ewl_Box */
Ewl_Widget *icon; /**< The image in this menu item */
Ewl_Widget *text; /**< The text label for this menu item */
Ewl_Widget *inmenu; /**< Set if inside a menu */
@@ -79,15 +79,14 @@
struct Ewl_Menu_Base
{
- Ewl_Menu_Item item; /**< Inherit from Ewl_Menu_Item */
- Ewl_Widget *popup; /**< The popup portion of the menu */
+ Ewl_Menu_Item item; /**< Inherit from Ewl_Menu_Item */
+ Ewl_Widget *popup; /**< The popup portion of the menu */
Ewl_Widget *popbox; /**< Box for layout in popup */
- int hold; /**< Indicates not to hide this on a deselect */
+ int hold; /**< Indicates not to hide this on a deselect */
};
-Ewl_Widget *ewl_menu_item_new(char *image, char *title);
-int ewl_menu_item_init(Ewl_Menu_Item * menu, char *image,
- char *title);
+Ewl_Widget *ewl_menu_item_new(void);
+int ewl_menu_item_init(Ewl_Menu_Item * menu);
char *ewl_menu_item_text_get(Ewl_Menu_Item * item);
void ewl_menu_item_text_set(Ewl_Menu_Item * item, char *text);
char *ewl_menu_item_image_get(Ewl_Menu_Item * item);
@@ -97,8 +96,7 @@
Ewl_Widget *ewl_menu_separator_new(void);
void ewl_menu_separator_init(Ewl_Menu_Separator *sep);
-void ewl_menu_base_init(Ewl_Menu_Base * menu, char *image,
- char *title);
+void ewl_menu_base_init(Ewl_Menu_Base * menu);
/*
* Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_menubar.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- ewl_menubar.c 3 Oct 2005 06:43:07 -0000 1.5
+++ ewl_menubar.c 10 Oct 2005 18:43:31 -0000 1.6
@@ -94,7 +94,9 @@
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR_RET("mb", mb, FALSE);
- menu = ewl_imenu_new(img, title);
+ menu = ewl_imenu_new();
+ ewl_menu_item_image_set(EWL_MENU_ITEM(menu), img);
+ ewl_menu_item_text_set(EWL_MENU_ITEM(menu), title);
ewl_container_child_append(EWL_CONTAINER(mb), menu);
ewl_object_fill_policy_set(EWL_OBJECT(menu), EWL_FLAG_FILL_NONE);
ewl_widget_show(menu);
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs