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 "xvaluedisplay.h"
23 #include "xvaluedisplay_private.h"
24 
25 
add_popup_spinbox(Widget_t * parent,const char * label,int x,int y,int width,int height)26 Widget_t* add_popup_spinbox(Widget_t *parent, const char * label,
27                 int x, int y, int width, int height) {
28     int x1, y1;
29     Window child;
30     XTranslateCoordinates( parent->app->dpy, parent->widget, DefaultRootWindow(parent->app->dpy), 0, 0, &x1, &y1, &child );
31     Widget_t *wid = create_window(parent->app, DefaultRootWindow(parent->app->dpy), x1, y1, width +40, height+20);
32 
33     XSetWindowAttributes attributes;
34     attributes.override_redirect = True;
35     XChangeWindowAttributes(parent->app->dpy, wid->widget, CWOverrideRedirect, &attributes);
36 
37     Atom window_type = XInternAtom(wid->app->dpy, "_NET_WM_WINDOW_TYPE", False);
38     Atom window_type_popup = XInternAtom(wid->app->dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
39     XChangeProperty(wid->app->dpy, wid->widget, window_type,
40         XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_type_popup,1 );
41 
42     Atom window_state = XInternAtom(wid->app->dpy, "_NET_WM_STATE", False);
43     Atom window_state_modal = XInternAtom(wid->app->dpy, "_NET_WM_STATE_MODAL", False);
44     XChangeProperty(wid->app->dpy, wid->widget, window_state,
45         XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_state_modal, 1);
46 
47     XSetTransientForHint(parent->app->dpy,wid->widget,parent->widget);
48     //wid->func.expose_callback = _draw_spinbox;
49     wid->flags |= IS_POPUP;
50     wid->scale.gravity = NONE;
51     wid->parent = parent;
52     childlist_add_child(parent->childlist, wid);
53     Widget_t *view_port = create_widget(wid->app, wid, 0 , 0, width+20, height+20);
54     view_port->func.expose_callback = _draw_spinbox;
55     Widget_t *buttons = create_widget(wid->app, wid, width+20 , 0, 20, height+20);
56     buttons->func.expose_callback = _draw_buttons;
57     buttons->scale.gravity = NORTHWEST;
58     buttons->flags &= ~USE_TRANSPARENCY;
59     buttons->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
60     buttons->func.button_release_callback = _buttons_released;
61 
62     return wid;
63 }
64 
add_valuedisplay(Widget_t * parent,const char * label,int x,int y,int width,int height)65 Widget_t* add_valuedisplay(Widget_t *parent, const char * label,
66                 int x, int y, int width, int height) {
67 
68     Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
69     add_popup_spinbox(wid, label, x, y, width, height);
70     wid->label = label;
71     wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0, 0.01, CL_CONTINUOS);
72     wid->adj = wid->adj_y;
73     wid->scale.gravity = CENTER;
74     wid->func.enter_callback = transparent_draw;
75     wid->func.leave_callback = transparent_draw;
76     wid->func.double_click_callback = _popup_spinbox;
77     wid->func.expose_callback = _draw_valuedisplay;
78     return wid;
79 }
80