Enlightenment CVS committal Author : rbdpngn Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_button_stock.c ewl_button_stock.h ewl_colordialog.c ewl_dialog.c ewl_filedialog.c ewl_filedialog.h ewl_fileselector.c Log Message: Convert stock buttons and filedialog to new API conventions. Improve the image test to make its use more obvious. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_button_stock.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- ewl_button_stock.c 3 Oct 2005 06:43:06 -0000 1.6 +++ ewl_button_stock.c 5 Oct 2005 05:41:01 -0000 1.7 @@ -43,13 +43,11 @@ /** - * @param stock_id: the string to use as a stock If for the button, or - * just a string for the label. * @return Returns NULL on failure, a pointer to a new button on success. * @brief Allocate and initialize a new button with eventually a stock * icon. */ -Ewl_Widget *ewl_button_stock_new (char *stock_id) +Ewl_Widget *ewl_button_stock_new(void) { Ewl_Button_Stock *b; @@ -59,7 +57,7 @@ if (!b) return NULL; - ewl_button_stock_init(b, stock_id); + ewl_button_stock_init(b); DRETURN_PTR(EWL_WIDGET(b), DLEVEL_STABLE); } @@ -73,29 +71,33 @@ * * Initializes a button to default values and callbacks. */ -int ewl_button_stock_init(Ewl_Button_Stock * b, char *stock_id) +int ewl_button_stock_init(Ewl_Button_Stock * b) { Ewl_Widget *w; char *label; - int test = FALSE; + char *stock_id = EWL_STOCK_OK; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("b", b, 0); - - label = ewl_stock_label_get (stock_id); + if (!ewl_button_init(EWL_BUTTON(b))) + DRETURN_INT(FALSE, DLEVEL_STABLE); + + ewl_callback_append(EWL_WIDGET(b), EWL_CALLBACK_CLICKED, + ewl_button_stock_click_cb, + &(b->response_id)); + ewl_callback_append(EWL_WIDGET(b), EWL_CALLBACK_DESTROY, + ewl_button_stock_destroy_cb, NULL); + + label = ewl_stock_label_get(stock_id); + if (label) { /* TODO : */ /* mettre le theme ici ? */ - if (!ewl_button_init(EWL_BUTTON(b))) - DRETURN_INT(FALSE, DLEVEL_STABLE); ewl_button_label_set(EWL_BUTTON(b), label); - free (label); - test = TRUE; + FREE(label); } else { - if (!ewl_button_init(EWL_BUTTON(b))) - DRETURN_INT(FALSE, DLEVEL_STABLE); ewl_button_label_set(EWL_BUTTON(b), stock_id); } @@ -103,24 +105,21 @@ * and label */ ewl_box_homogeneous_set(EWL_BOX (b), FALSE); ewl_box_spacing_set(EWL_BOX (b), 6); + ewl_object_padding_set(EWL_OBJECT(b), 0, 3, 3, 3); + ewl_object_fill_policy_set(EWL_OBJECT(b), EWL_FLAG_FILL_VFILL | + EWL_FLAG_FILL_SHRINK); w = EWL_WIDGET(b); /* Create and setup the image for the button if it's desired */ - if (test) { - b->image_object = ewl_image_new(); - ewl_widget_appearance_set(b->image_object, stock_id); - } -/* ewl_widget_appearance_set(b->image_object, stock_id); */ - - if (b->image_object) { - ewl_object_fill_policy_set(EWL_OBJECT(b->image_object), - EWL_FLAG_FILL_NONE); - ewl_object_alignment_set(EWL_OBJECT(b->image_object), - EWL_FLAG_ALIGN_LEFT); - ewl_container_child_prepend(EWL_CONTAINER(b), b->image_object); - ewl_widget_show(b->image_object); - } + b->image_object = ewl_image_new(); + ewl_widget_appearance_set(b->image_object, stock_id); + ewl_object_fill_policy_set(EWL_OBJECT(b->image_object), + EWL_FLAG_FILL_NONE); + ewl_object_alignment_set(EWL_OBJECT(b->image_object), + EWL_FLAG_ALIGN_LEFT); + ewl_container_child_prepend(EWL_CONTAINER(b), b->image_object); + ewl_widget_show(b->image_object); /* Tweak the default alignment of the label */ if (EWL_BUTTON(b)->label_object) { @@ -132,37 +131,75 @@ } /** - * @param stock_id: the text of the button or a stock Id. - * @param response_id: The Id that will be retured when clicking on the button. - * @return Returns a button, or NULL on failure. - * @brief Convenient function to create a (stock) button, with a - * response id. To add this - * button in the action_area of a dialog, just use - * ewl_container_child_append(dialog, button) or - * ewl_container_child_prepend(dialog, button). Use this way to add - * buttons, instead of ewl_dialog_button_add() or - * ewl_dialog_button_left_add(). - */ -Ewl_Widget * -ewl_button_stock_with_id_new (char *stock_id, - int response_id) + * @param b: the button to set the stock id + * @return Returns no value. + * @brief Changes the stock id of the button. + */ +void ewl_button_stock_id_set(Ewl_Button_Stock *b, char *stock_id) { - Ewl_Widget *button; - + char *label; + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("b", b); - button = ewl_button_stock_new (stock_id); - ewl_object_padding_set(EWL_OBJECT (button), 0, 3, 3, 3); - ewl_object_fill_policy_set(EWL_OBJECT (button), EWL_FLAG_FILL_VFILL | - EWL_FLAG_FILL_SHRINK); + IF_FREE(b->stock_id); - EWL_BUTTON_STOCK(button)->response_id = response_id; + if (!stock_id) + stock_id = EWL_STOCK_OK; + b->stock_id = strdup(stock_id); - ewl_callback_append(button, EWL_CALLBACK_CLICKED, - ewl_button_stock_click_cb, - &(EWL_BUTTON_STOCK (button)->response_id)); - - DRETURN_PTR(button, DLEVEL_STABLE); + label = ewl_stock_label_get(stock_id); + if (label) { + ewl_button_label_set(EWL_BUTTON(b), label); + FREE(label); + } + else + ewl_button_label_set(EWL_BUTTON(b), stock_id); + + ewl_widget_appearance_set(b->image_object, stock_id); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param b: the button to set the stock id + * @return Returns no value. + * @brief Changes the stock id of the button. + */ +char *ewl_button_stock_id_get(Ewl_Button_Stock *b) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("b", b, NULL); + + DRETURN_PTR(strdup(b->stock_id), DLEVEL_STABLE); +} + +/** + * @param b: the button to set the response id + * @return Returns no value. + * @brief Changes the response id generated by the button being clicked. + */ +void ewl_button_stock_response_id_set(Ewl_Button_Stock *b, int response_id) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("b", b); + + b->response_id = response_id; + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param b: Retrieve the current response id on a stock button. + * @return Returns the current stock response. + * @brief Retrieve the current stock response id the button generates. + */ +int ewl_button_stock_response_id_get(Ewl_Button_Stock *b) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("b", b, FALSE); + + DRETURN_INT(b->response_id, DLEVEL_STABLE); } /* @@ -174,3 +211,11 @@ { ewl_callback_call_with_event_data (w, EWL_CALLBACK_VALUE_CHANGED, data); } + +void +ewl_button_stock_destroy_cb(Ewl_Widget *w, void *ev __UNUSED__, void *data) +{ + Ewl_Button_Stock *b = EWL_BUTTON_STOCK(w); + + IF_FREE(b->stock_id); +} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_button_stock.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- ewl_button_stock.h 10 Apr 2005 05:05:17 -0000 1.5 +++ ewl_button_stock.h 5 Oct 2005 05:41:01 -0000 1.6 @@ -106,16 +106,21 @@ int response_id; /* the response Id */ }; -Ewl_Widget *ewl_button_stock_new(char *stock_id); -Ewl_Widget *ewl_button_stock_with_id_new(char *stock_id, int response_id); +Ewl_Widget *ewl_button_stock_new(void); -int ewl_button_stock_init(Ewl_Button_Stock *b, char *stock_id); +int ewl_button_stock_init(Ewl_Button_Stock *b); +void ewl_button_stock_id_set(Ewl_Button_Stock *b, char *stock_id); +char *ewl_button_stock_id_get(Ewl_Button_Stock *b); +void ewl_button_stock_response_id_set(Ewl_Button_Stock *b, + int response_id); +int ewl_button_stock_response_id_get(Ewl_Button_Stock *b); /* * Internally used callbacks, override at your own risk. */ void ewl_button_stock_click_cb (Ewl_Widget *w, void *ev, void *data); +void ewl_button_stock_destroy_cb(Ewl_Widget *w, void *ev, void *data); /** * @} =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_colordialog.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- ewl_colordialog.c 3 Oct 2005 06:43:06 -0000 1.11 +++ ewl_colordialog.c 5 Oct 2005 05:41:01 -0000 1.12 @@ -175,7 +175,11 @@ ewl_colordialog_valuevalue_changed, cd); ewl_widget_show(cd->value_entry); - button = ewl_button_stock_with_id_new(EWL_STOCK_OK, EWL_RESPONSE_OK); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), + EWL_STOCK_OK); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), + EWL_RESPONSE_OK); ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL); ewl_object_alignment_set(EWL_OBJECT(button), EWL_FLAG_ALIGN_CENTER); ewl_callback_append(button, EWL_CALLBACK_CLICKED, @@ -183,8 +187,10 @@ ewl_container_child_append(EWL_CONTAINER(vbox), button); ewl_widget_show(button); - button = ewl_button_stock_with_id_new(EWL_STOCK_CANCEL, - EWL_RESPONSE_CANCEL); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), EWL_STOCK_CANCEL); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), + EWL_RESPONSE_CANCEL); ewl_object_fill_policy_set(EWL_OBJECT(button), EWL_FLAG_FILL_HFILL); ewl_object_alignment_set(EWL_OBJECT(button), EWL_FLAG_ALIGN_CENTER); ewl_callback_append(button, EWL_CALLBACK_CLICKED, =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_dialog.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- ewl_dialog.c 5 Sep 2005 14:12:15 -0000 1.4 +++ ewl_dialog.c 5 Oct 2005 05:41:01 -0000 1.5 @@ -277,7 +277,9 @@ if (!dialog) return NULL; - button = ewl_button_stock_with_id_new(button_text, response_id); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), button_text); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), response_id); ewl_object_padding_set(EWL_OBJECT(button), 0, 3, 3, 3); ewl_container_child_append(EWL_CONTAINER(dialog->action_area), button); @@ -306,7 +308,9 @@ if (!dialog) return NULL; - button = ewl_button_stock_with_id_new(button_text, response_id); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), button_text); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), response_id); ewl_object_padding_set(EWL_OBJECT(button), 0, 3, 3, 3); ewl_container_child_prepend(EWL_CONTAINER(dialog->action_area), button); =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_filedialog.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- ewl_filedialog.c 3 Oct 2005 06:43:06 -0000 1.5 +++ ewl_filedialog.c 5 Oct 2005 05:41:01 -0000 1.6 @@ -13,7 +13,7 @@ DENTER_FUNCTION(DLEVEL_STABLE); - fd = ewl_filedialog_new(EWL_FILEDIALOG_TYPE_OPEN); + fd = ewl_filedialog_new(); if (!fd) { DRETURN_PTR(NULL, DLEVEL_STABLE); } @@ -23,11 +23,10 @@ } /** - * @param type: type of dialog to display * @return Returns a new filedialog in success, NULL on failure. * @brief Create a new filedialog */ -Ewl_Widget *ewl_filedialog_new(Ewl_Filedialog_Type type) +Ewl_Widget *ewl_filedialog_new(void) { Ewl_Filedialog *fd; @@ -38,7 +37,7 @@ DRETURN_PTR(NULL, DLEVEL_STABLE); } - if (!ewl_filedialog_init(fd, type)) { + if (!ewl_filedialog_init(fd)) { ewl_widget_destroy(EWL_WIDGET(fd)); fd = NULL; } @@ -47,14 +46,12 @@ /** * @param fd: the filedialog - * @param type: the filedialog type * @return Returns no value. * @brief Initialize a new filedialog */ -int ewl_filedialog_init(Ewl_Filedialog * fd, Ewl_Filedialog_Type type) +int ewl_filedialog_init(Ewl_Filedialog * fd) { Ewl_Widget *w; - Ewl_Widget *button; Ewl_Widget *box; DENTER_FUNCTION(DLEVEL_STABLE); @@ -86,29 +83,68 @@ ewl_widget_show(box); /* Buttons */ - if (type == EWL_FILEDIALOG_TYPE_OPEN) - button = ewl_button_stock_with_id_new(EWL_STOCK_OPEN, - EWL_RESPONSE_OPEN); - else - button = ewl_button_stock_with_id_new(EWL_STOCK_SAVE, - EWL_RESPONSE_SAVE); - - ewl_callback_append(button, EWL_CALLBACK_CLICKED, + fd->confirm = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(fd->confirm), EWL_STOCK_OPEN); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(fd->confirm), + EWL_RESPONSE_OPEN); + + ewl_callback_append(fd->confirm, EWL_CALLBACK_CLICKED, ewl_filedialog_click_cb, fd); - ewl_container_child_append(EWL_CONTAINER(box), button); - ewl_widget_show(button); + ewl_container_child_append(EWL_CONTAINER(box), fd->confirm); + ewl_widget_show(fd->confirm); - button = ewl_button_stock_with_id_new(EWL_STOCK_CANCEL, + fd->cancel = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(fd->cancel), EWL_STOCK_CANCEL); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(fd->cancel), EWL_RESPONSE_CANCEL); - ewl_callback_append(button, EWL_CALLBACK_CLICKED, + ewl_callback_append(fd->cancel, EWL_CALLBACK_CLICKED, ewl_filedialog_click_cb, fd); - ewl_container_child_append(EWL_CONTAINER(box), button); - ewl_widget_show(button); + ewl_container_child_append(EWL_CONTAINER(box), fd->cancel); + ewl_widget_show(fd->cancel); DRETURN_INT(TRUE, DLEVEL_STABLE); } /** + * @param fd: the filedialog to get the current type + * @return Returns the current file dialog type. + * @brief Retrieve the current filedialog type. + */ +Ewl_Filedialog_Type ewl_filedialog_type_get(Ewl_Filedialog *fd) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("fd", fd, EWL_FILEDIALOG_TYPE_OPEN); + + DRETURN_INT(fd->type, DLEVEL_STABLE); +} + +/** + * @param fd: the filedialog to change types + * @return Returns no value. + * @brief Change the current filedialog type. + */ +void ewl_filedialog_type_set(Ewl_Filedialog *fd, Ewl_Filedialog_Type t) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fd", fd); + + if (t == EWL_FILEDIALOG_TYPE_OPEN) { + ewl_button_stock_id_set(EWL_BUTTON_STOCK(fd->confirm), + EWL_STOCK_OPEN); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(fd->confirm), + EWL_RESPONSE_OPEN); + } + else if (t == EWL_FILEDIALOG_TYPE_SAVE) { + ewl_button_stock_id_set(EWL_BUTTON_STOCK(fd->confirm), + EWL_STOCK_SAVE); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(fd->confirm), + EWL_RESPONSE_SAVE); + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** * @param fd: the filedialog * @return Returns the current path of filedialog * @brief Retrieve the current filedialog path =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_filedialog.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- ewl_filedialog.h 28 May 2005 19:01:41 -0000 1.3 +++ ewl_filedialog.h 5 Oct 2005 05:41:01 -0000 1.4 @@ -42,19 +42,24 @@ */ struct Ewl_Filedialog { - Ewl_Box box; /**< the overlay containing the fileselector */ - Ewl_Widget *fs; /**< Ewl_Fileselector */ + Ewl_Box box; /**< Box containing the fileselector */ + + Ewl_Filedialog_Type type; /**< Current type of filedialog */ + Ewl_Widget *fs; /**< Ewl_Fileselector */ + Ewl_Widget *confirm; /**< Confirmation OK/Save button */ + Ewl_Widget *cancel; /**< Cancel button */ }; Ewl_Widget *ewl_filedialog_multiselect_new(void); -Ewl_Widget *ewl_filedialog_new(Ewl_Filedialog_Type type); +Ewl_Widget *ewl_filedialog_new(void); -int ewl_filedialog_init(Ewl_Filedialog *fd, - Ewl_Filedialog_Type type); -char *ewl_filedialog_path_get(Ewl_Filedialog *fd); -char *ewl_filedialog_file_get(Ewl_Filedialog *fd); -void ewl_filedialog_path_set(Ewl_Filedialog *fd, char *path); +Ewl_Filedialog_Type ewl_filedialog_type_get(Ewl_Filedialog *fd); +void ewl_filedialog_type_set(Ewl_Filedialog *fd, Ewl_Filedialog_Type type); +int ewl_filedialog_init(Ewl_Filedialog *fd); +char *ewl_filedialog_path_get(Ewl_Filedialog *fd); +char *ewl_filedialog_file_get(Ewl_Filedialog *fd); +void ewl_filedialog_path_set(Ewl_Filedialog *fd, char *path); void ewl_filedialog_multiselect_set(Ewl_Filedialog *fd, unsigned int val); =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -3 -r1.24 -r1.25 --- ewl_fileselector.c 3 Oct 2005 06:43:06 -0000 1.24 +++ ewl_fileselector.c 5 Oct 2005 05:41:01 -0000 1.25 @@ -116,15 +116,26 @@ EWL_FLAG_FILL_FILL); ewl_widget_show(misc); - button = ewl_button_stock_with_id_new(EWL_STOCK_ARROW_UP, - EWL_RESPONSE_ARROW_UP); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), + EWL_STOCK_ARROW_UP); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), + EWL_RESPONSE_ARROW_UP); ewl_callback_append(button, EWL_CALLBACK_CLICKED, ewl_fileselector_go_up_cb, fs); ewl_container_child_append(EWL_CONTAINER(hbox), button); ewl_widget_show(button); - button = ewl_button_stock_with_id_new(EWL_STOCK_HOME, - EWL_RESPONSE_HOME); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), + EWL_STOCK_HOME); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), + EWL_RESPONSE_HOME); + button = ewl_button_stock_new(); + ewl_button_stock_id_set(EWL_BUTTON_STOCK(button), + EWL_STOCK_HOME); + ewl_button_stock_response_id_set(EWL_BUTTON_STOCK(button), + EWL_RESPONSE_HOME); ewl_callback_append(button, EWL_CALLBACK_CLICKED, ewl_fileselector_go_home_cb, fs); ewl_container_child_append(EWL_CONTAINER(hbox), button); ------------------------------------------------------- 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 enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs