Enlightenment CVS committal Author : moom16 Project : e17 Module : proto
Dir : e17/proto/etk/src/lib Modified Files: etk_notebook.c etk_notebook.h etk_toggle_button.c Log Message: * More notebook work =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_notebook.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- etk_notebook.c 23 Dec 2005 14:48:14 -0000 1.1 +++ etk_notebook.c 23 Dec 2005 23:01:06 -0000 1.2 @@ -10,18 +10,16 @@ * @addtogroup Etk_Notebook * @{ */ - -typedef struct _Etk_Notebook_Page -{ - Etk_Widget *tab; - Etk_Widget *page_widget; -} Etk_Notebook_Page; - + static void _etk_notebook_constructor(Etk_Notebook *notebook); +static void _etk_notebook_destructor(Etk_Notebook *notebook); static void _etk_notebook_child_add(Etk_Container *container, Etk_Widget *widget); static void _etk_notebook_child_remove(Etk_Container *container, Etk_Widget *widget); static void _etk_notebook_size_request(Etk_Widget *widget, Etk_Size *size_requisition); static void _etk_notebook_size_allocate(Etk_Widget *widget, Etk_Geometry geometry); +static void _etk_notebook_tab_toggled_cb(Etk_Object *object, void *data); +static Etk_Notebook_Page *_etk_notebook_page_create(Etk_Notebook *notebook, const char *tab_label, Etk_Widget *page_widget); +static void _etk_notebook_page_activate(Etk_Notebook_Page *page); /************************** * @@ -39,7 +37,7 @@ if (!notebook_type) { - notebook_type = etk_type_new("Etk_Notebook", ETK_CONTAINER_TYPE, sizeof(Etk_Notebook), ETK_CONSTRUCTOR(_etk_notebook_constructor), NULL); + notebook_type = etk_type_new("Etk_Notebook", ETK_CONTAINER_TYPE, sizeof(Etk_Notebook), ETK_CONSTRUCTOR(_etk_notebook_constructor), ETK_DESTRUCTOR(_etk_notebook_destructor)); } return notebook_type; @@ -55,23 +53,27 @@ } /* TODO */ -int etk_notebook_page_append(Etk_Notebook *notebook, const char *tab_label) +int etk_notebook_page_append(Etk_Notebook *notebook, const char *tab_label, Etk_Widget *page_widget) { - Etk_Notebook_Page *new_page, *prev_page; + Etk_Notebook_Page *new_page; if (!notebook) return -1; - new_page = malloc(sizeof(Etk_Notebook_Page)); - prev_page = notebook->pages ? notebook->pages->data : NULL; - new_page->tab = etk_radio_button_new_with_label_from_widget(tab_label, prev_page ? ETK_RADIO_BUTTON(prev_page->tab) : NULL); - etk_object_properties_set(ETK_OBJECT(new_page->tab), "theme_group", "notebook_tab", NULL); - etk_widget_parent_set(new_page->tab, ETK_CONTAINER(notebook)); - etk_widget_show(new_page->tab); - + if (!(new_page = _etk_notebook_page_create(notebook, tab_label, page_widget))) + return -1; notebook->pages = evas_list_append(notebook->pages, new_page); + return evas_list_count(notebook->pages) - 1; +} + +/* TODO */ +void etk_notebook_current_page_set(Etk_Notebook *notebook, int page_num) +{ + Etk_Notebook_Page *page; - return 1; + if (!notebook || !(page = evas_list_nth(notebook->pages, page_num))) + return; + etk_toggle_button_active_set(ETK_TOGGLE_BUTTON(page->tab), 1); } /************************** @@ -87,37 +89,66 @@ return; notebook->pages = NULL; - notebook->frame = etk_widget_new(ETK_BIN_TYPE, "theme_group", "notebook_frame", NULL); - etk_widget_parent_set(notebook->frame, ETK_CONTAINER(notebook)); - etk_widget_show(ETK_WIDGET(notebook)); + notebook->current_page = NULL; ETK_CONTAINER(notebook)->child_add = _etk_notebook_child_add; ETK_CONTAINER(notebook)->child_remove = _etk_notebook_child_remove; - //ETK_WIDGET(notebook)->size_request = _etk_notebook_size_request; + ETK_WIDGET(notebook)->size_request = _etk_notebook_size_request; ETK_WIDGET(notebook)->size_allocate = _etk_notebook_size_allocate; } +/* Destroys the notebook */ +static void _etk_notebook_destructor(Etk_Notebook *notebook) +{ + Evas_List *l; + Etk_Notebook_Page *page; + + if (!notebook) + return; + + for (l = notebook->pages; l; l = l->next) + { + page = l->data; + /* TODO */ + etk_object_destroy(ETK_OBJECT(page->tab)); + etk_object_destroy(ETK_OBJECT(page->page_frame)); + free(page); + } +} + /* Calculates the ideal size of the notebook */ static void _etk_notebook_size_request(Etk_Widget *widget, Etk_Size *size_requisition) { - /*Etk_Notebook *notebook; - Etk_Container *container; + Evas_List *l; + Etk_Notebook *notebook; + Etk_Notebook_Page *page; + Etk_Size tab_requisition; + Etk_Size frame_requisition; if (!(notebook = ETK_NOTEBOOK(widget)) || !size_requisition) return; - - container = ETK_CONTAINER(notebook); - - if (!notebook->child) + + size_requisition->w = 0; + size_requisition->h = 0; + + for (l = notebook->pages; l; l = l->next) { - size_requisition->w = 0; - size_requisition->h = 0; + page = l->data; + etk_widget_size_request(page->tab, &tab_requisition); + size_requisition->w += tab_requisition.w; + if (size_requisition->h < tab_requisition.h) + size_requisition->h = tab_requisition.h; + } + if (notebook->current_page) + { + etk_widget_size_request(notebook->current_page->page_frame, &frame_requisition); + if (size_requisition->w < frame_requisition.w) + size_requisition->w = frame_requisition.w; + size_requisition->h += frame_requisition.h; } - else - etk_widget_size_request(notebook->child, size_requisition); - size_requisition->w += 2 * etk_container_border_width_get(container); - size_requisition->h += 2 * etk_container_border_width_get(container);*/ + size_requisition->w += 2 * etk_container_border_width_get(ETK_CONTAINER(notebook)); + size_requisition->h += 2 * etk_container_border_width_get(ETK_CONTAINER(notebook)); } /* Resizes the notebook to the size allocation */ @@ -133,7 +164,7 @@ Etk_Geometry tab_geometry, frame_geometry; int tab_offset; - if (!(notebook = ETK_NOTEBOOK(widget))) + if (!(notebook = ETK_NOTEBOOK(widget)) || !notebook->current_page) return; notebook_container = ETK_CONTAINER(widget); @@ -151,7 +182,8 @@ max_tab_height = tab_requisition.h; } - tab_offset = (geometry.w - tabs_width) * 0.5; + //tab_offset = (geometry.w - tabs_width) * 0.5; + tab_offset = 0; tab_geometry.y = geometry.y; tab_geometry.h = max_tab_height; for (l = notebook->pages; l; l = l->next) @@ -168,16 +200,15 @@ frame_geometry.y = geometry.y + max_tab_height; frame_geometry.w = geometry.w; frame_geometry.h = geometry.h - max_tab_height; - etk_widget_size_allocate(notebook->frame, frame_geometry); + etk_widget_size_allocate(notebook->current_page->page_frame, frame_geometry); } /* Adds a child to the notebook */ static void _etk_notebook_child_add(Etk_Container *container, Etk_Widget *widget) { - /*if (!container || !widget) + if (!container || !widget) return; - - etk_notebook_child_set(ETK_NOTEBOOK(container), widget);*/ + etk_notebook_page_append(ETK_NOTEBOOK(container), "Tab", widget); } /* Removes the child from the notebook */ @@ -202,5 +233,75 @@ * **************************/ +/* Called when a tab is toggled (activated or deactivated) */ +static void _etk_notebook_tab_toggled_cb(Etk_Object *object, void *data) +{ + Etk_Widget *tab; + Etk_Notebook *notebook; + Etk_Notebook_Page *page; + + if (!(tab = ETK_WIDGET(object)) || !(notebook = ETK_NOTEBOOK(data))) + return; + + if (etk_toggle_button_active_get(ETK_TOGGLE_BUTTON(tab))) + { + if ((page = etk_object_data_get(object, "_Etk_Notebook::Page"))) + { + if (notebook->current_page) + etk_widget_hide(notebook->current_page->page_frame); + notebook->current_page = page; + etk_widget_show(notebook->current_page->page_frame); + etk_widget_size_recalc_queue(ETK_WIDGET(notebook)); + } + } +} + +/************************** + * + * Private functions + * + **************************/ + +/* Creates a new page to the notebook */ +static Etk_Notebook_Page *_etk_notebook_page_create(Etk_Notebook *notebook, const char *tab_label, Etk_Widget *page_widget) +{ + Etk_Notebook_Page *new_page, *prev_page; + + if (!notebook) + return NULL; + + new_page = malloc(sizeof(Etk_Notebook_Page)); + prev_page = notebook->pages ? notebook->pages->data : NULL; + new_page->tab = etk_radio_button_new_with_label_from_widget(tab_label, prev_page ? ETK_RADIO_BUTTON(prev_page->tab) : NULL); + etk_object_properties_set(ETK_OBJECT(new_page->tab), "theme_group", "notebook_tab", NULL); + etk_object_data_set(ETK_OBJECT(new_page->tab), "_Etk_Notebook::Page", new_page); + etk_widget_parent_set(new_page->tab, ETK_CONTAINER(notebook)); + etk_widget_visibility_locked_set(new_page->tab, TRUE); + etk_widget_show(new_page->tab); + etk_signal_connect("toggled", ETK_OBJECT(new_page->tab), ETK_CALLBACK(_etk_notebook_tab_toggled_cb), notebook); + + new_page->page_frame = etk_widget_new(ETK_BIN_TYPE, "theme_group", "notebook_frame", NULL); + etk_widget_parent_set(new_page->page_frame, ETK_CONTAINER(notebook)); + etk_widget_visibility_locked_set(new_page->page_frame, TRUE); + etk_widget_hide(new_page->page_frame); + + new_page->page_widget = page_widget; + if (new_page->page_widget) + etk_bin_child_set(ETK_BIN(new_page->page_frame), new_page->page_widget); + + if (!notebook->current_page) + _etk_notebook_page_activate(new_page); + etk_widget_size_recalc_queue(ETK_WIDGET(notebook)); + + return new_page; +} + +/* Activates a page of the notebook */ +static void _etk_notebook_page_activate(Etk_Notebook_Page *page) +{ + if (!page) + return; + etk_toggle_button_active_set(ETK_TOGGLE_BUTTON(page->tab), TRUE); +} /** @} */ =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_notebook.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- etk_notebook.h 23 Dec 2005 14:48:14 -0000 1.1 +++ etk_notebook.h 23 Dec 2005 23:01:06 -0000 1.2 @@ -18,6 +18,14 @@ /** @brief Checks if the object is an Etk_Notebook */ #define ETK_IS_NOTEBOOK(obj) (ETK_OBJECT_CHECK_TYPE((obj), ETK_NOTEBOOK_TYPE)) +/* A page of the notebook */ +typedef struct _Etk_Notebook_Page +{ + Etk_Widget *tab; + Etk_Widget *page_widget; + Etk_Widget *page_frame; +} Etk_Notebook_Page; + /** * @struct Etk_Notebook * @brief TODO @@ -29,13 +37,15 @@ Etk_Container container; Evas_List *pages; - Etk_Widget *frame; + Etk_Notebook_Page *current_page; }; Etk_Type *etk_notebook_type_get(); Etk_Widget *etk_notebook_new(); -int etk_notebook_page_append(Etk_Notebook *notebook, const char *tab_label); +int etk_notebook_page_append(Etk_Notebook *notebook, const char *tab_label, Etk_Widget *page_widget); + +void etk_notebook_current_page_set(Etk_Notebook *notebook, int page_num); /** @} */ =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_toggle_button.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- etk_toggle_button.c 2 Dec 2005 21:57:55 -0000 1.5 +++ etk_toggle_button.c 23 Dec 2005 23:01:06 -0000 1.6 @@ -89,7 +89,7 @@ } /** - * @brief Sets the status of the toggle button + * @brief Sets the state of the toggle button * @param toggle_button a toggle button * @param active if @a active != 0, the toggle button will be active */ @@ -99,6 +99,18 @@ etk_button_clicked(ETK_BUTTON(toggle_button)); } +/** + * @brief Gets the state of the toggle button + * @param toggle_button a toggle button + * @return Returns TRUE if the button is activated, FALSE otherwise + */ +Etk_Bool etk_toggle_button_active_get(Etk_Toggle_Button *toggle_button) +{ + if (!toggle_button) + return FALSE; + return toggle_button->active; +} + /************************** * * Etk specific functions ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs