1 /*
2  *                           0BSD
3  *
4  *                    BSD Zero Clause License
5  *
6  *  Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 
22 #include "xtabbox.h"
23 #include "xtabbox_private.h"
24 
25 
tabbox_add_tab(Widget_t * tabbox,const char * label)26 Widget_t* tabbox_add_tab(Widget_t *tabbox, const char * label) {
27     XWindowAttributes attrs;
28     XGetWindowAttributes(tabbox->app->dpy, (Window)tabbox->widget, &attrs);
29     int width = attrs.width;
30     int height = attrs.height;
31     Widget_t *wid = create_widget(tabbox->app,tabbox, 4, 20,  width-8, height-24);
32     wid->scale.gravity = NORTHWEST;
33     wid->label = label;
34     wid->func.expose_callback = _draw_tab;
35     //wid->func.map_notify_callback = _tab_mapped_callback;
36     float max_value = tabbox->adj->max_value+1.0;
37     set_adjustment(tabbox->adj,0.0, max_value, 0.0, max_value,1.0, CL_NONE);
38     adj_set_value(tabbox->adj,0.0);
39     return wid;
40 }
41 
add_tabbox(Widget_t * parent,const char * label,int x,int y,int width,int height)42 Widget_t* add_tabbox(Widget_t *parent, const char * label,
43                 int x, int y, int width, int height) {
44 
45     Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
46     wid->label = label;
47     wid->scale.gravity = CENTER;
48     wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, -1.0,1.0, CL_NONE);
49     wid->adj = wid->adj_y;
50     wid->func.expose_callback = _draw_tabbox;
51     //wid->func.button_press_callback = _tab_button_pressed;
52     wid->func.button_release_callback = _tab_button_released;
53     //wid->func.map_notify_callback = _tabbox_mapped_callback;
54     return wid;
55 }
56 
tabbox_remove_tab(Widget_t * tabbox,int tab)57 void tabbox_remove_tab(Widget_t *tabbox, int tab) {
58     int elem = tabbox->childlist->elem;
59     if (tab > elem) return;
60     Widget_t *wid = tabbox->childlist->childs[tab];
61     destroy_widget(wid, tabbox->app);
62     float max_value = tabbox->adj->max_value-1.0;
63     set_adjustment(tabbox->adj,0.0, max_value, 0.0, max_value,1.0, CL_NONE);
64 }
65