libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xlistview.c
Go to the documentation of this file.
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 "xlistview.h"
23 #include "xlistview_private.h"
24 #include "xtooltip.h"
25 
26 
27 void listview_set_active_entry(Widget_t *w, int active) {
28  if(active<0) return;
29  Widget_t* view_port = w->childlist->childs[0];
30  ViewList_t *filelist = (ViewList_t*)view_port->parent_struct;
31  float value = (float)active;
32  if (value>w->adj->max_value) value = w->adj->max_value;
33  else if (value<w->adj->min_value) value = w->adj->min_value;
34  filelist->active_item = (int)value;
35  adj_set_value(w->adj,filelist->active_item);
36 }
37 
38 Widget_t* create_listview_viewport(Widget_t *parent, int elem, int width, int height) {
39  Widget_t *wid = create_widget(parent->app, parent, 0, 0, width, height);
40  XSelectInput(wid->app->dpy, wid->widget,StructureNotifyMask|ExposureMask|KeyPressMask
41  |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
42  |ButtonPressMask|Button1MotionMask|PointerMotionMask);
43  wid->scale.gravity = NORTHEAST;
44  ViewList_t *filelist;
45  filelist = (ViewList_t*)malloc(sizeof(ViewList_t));
46  filelist->show_items = elem;
47  wid->flags |= HAS_MEM;
48  wid->parent_struct = filelist;
49  float max_value = -elem;
50  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, max_value,1.0, CL_VIEWPORT);
51  wid->adj = wid->adj_y;
61  return wid;
62 }
63 
64 Widget_t* add_listview(Widget_t *parent, const char * label,
65  int x, int y, int width, int height) {
66 
67  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
68  wid->label = label;
69  wid->scale.gravity = CENTER;
70  wid->flags &= ~USE_TRANSPARENCY;
72  int elem = height/25;
73  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, -1.0,1.0, CL_NONE);
74  wid->adj = wid->adj_y;
75  create_listview_viewport(wid, elem, width, height);
76  return wid;
77 }
78 
79 void listview_mem_free(void *w_, void* user_data) {
80  Widget_t *w = (Widget_t*)w_;
81  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
82  free(filelist);
83 }
84 
85 void listview_set_list(Widget_t *listview, char **list, int list_size) {
86  Widget_t* view_port = listview->childlist->childs[0];
87  ViewList_t *filelist = (ViewList_t*)view_port->parent_struct;
88  filelist->list_names = list;
89  filelist->list_size = list_size;
90  set_adjustment(listview->adj,0.0, 0.0, 0.0, (float)(list_size-1.0),1.0, CL_NONE);
91  float max_value = view_port->adj->max_value+ (float)list_size;
92  set_adjustment(view_port->adj,0.0, 0.0, 0.0, max_value,1.0, CL_VIEWPORT);
93  _configure_listview(view_port, NULL);
94 }
95 
Func_t::leave_callback
xevfunc leave_callback
Definition: xwidget.h:83
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
create_listview_viewport
Widget_t * create_listview_viewport(Widget_t *parent, int elem, int width, int height)
create_listview_viewport - create a viewport on a listview to a Widget_t
Definition: xlistview.c:38
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
_reconfigure_listview_viewport
void _reconfigure_listview_viewport(void *w_, void *user_data)
_reconfigure_listview_viewport - reconfigure the viewport adjustment on size changes
Definition: xlistview_private.c:169
create_widget
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition: xwidget.c:268
_list_entry_released
void _list_entry_released(void *w_, void *button_, void *user_data)
_list_entry_released - move listview or set active entry
Definition: xlistview_private.c:134
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
listview_set_active_entry
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
Definition: xlistview.c:27
CENTER
@ CENTER
Definition: xwidget.h:165
Func_t::motion_callback
evfunc motion_callback
Definition: xwidget.h:95
Widget_t::flags
long long flags
Definition: xwidget.h:324
adj_set_value
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
Definition: xadjustment.c:163
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
_list_motion
void _list_motion(void *w_, void *xmotion_, void *user_data)
_list_motion - follow mouse pointer to set prelight item
Definition: xlistview_private.c:93
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
CL_VIEWPORT
@ CL_VIEWPORT
Definition: xadjustment.h:57
Func_t::key_press_callback
evfunc key_press_callback
Definition: xwidget.h:96
xlistview.h
_draw_list
void _draw_list(void *w_, void *user_data)
_draw_list - draw list on expose call
Definition: xlistview_private.c:33
_set_listview_viewpoint
void _set_listview_viewpoint(void *w_, void *user_data)
_set_listview_viewpoint - move the view_port to position
Definition: xlistview_private.c:215
listview_mem_free
void listview_mem_free(void *w_, void *user_data)
listview_mem_free - release additional used memory when destroy the Widget_t
Definition: xlistview.c:79
HAS_MEM
@ HAS_MEM
Definition: xwidget.h:251
Widget_t::app
Xputty * app
Definition: xwidget.h:300
_configure_listview
void _configure_listview(void *w_, void *user_data)
_configure_listview - configure the viewport on mapping
Definition: xlistview_private.c:182
Xputty::dpy
Display * dpy
Definition: xputty.h:181
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
ViewList_t::show_items
int show_items
Definition: xlistview.h:44
Func_t::map_notify_callback
xevfunc map_notify_callback
Definition: xwidget.h:89
Widget_t::widget
Window widget
Definition: xwidget.h:302
xlistview_private.h
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
ViewList_t::list_size
int list_size
Definition: xlistview.h:45
listview_set_list
void listview_set_list(Widget_t *listview, char **list, int list_size)
listview_set_list - set a list to a listview Widget_t
Definition: xlistview.c:85
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
add_listview
Widget_t * add_listview(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_label - add a listview to a Widget_t
Definition: xlistview.c:64
Func_t::button_release_callback
evfunc button_release_callback
Definition: xwidget.h:94
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
Adjustment_t::max_value
float max_value
Definition: xadjustment.h:90
set_adjustment
void set_adjustment(Adjustment_t *adj, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*set_adjustment - set a new range to a existing Adjustment_t it will be created if it not exsits yet
Definition: xadjustment.c:80
Func_t::adj_callback
xevfunc adj_callback
Definition: xwidget.h:84
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
CL_NONE
@ CL_NONE
Definition: xadjustment.h:47
add_adjustment
Adjustment_t * add_adjustment(Widget_t *w, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*add_adjustment - adding a adjustment to a Widget_t
Definition: xadjustment.c:25
ViewList_t::list_names
char ** list_names
Definition: xlistview.h:46
Func_t::configure_notify_callback
xevfunc configure_notify_callback
Definition: xwidget.h:88
_leave_list
void _leave_list(void *w_, void *user_data)
_leave_list - draw list on pointer leave
Definition: xlistview_private.c:162
ViewList_t
ViewList_t - struct to hold information for the listview.
Definition: xlistview.h:41
xtooltip.h
_list_key_pressed
void _list_key_pressed(void *w_, void *xkey_, void *user_data)
_list_key_pressed - move listview or set active entry
Definition: xlistview_private.c:108
Widget_t::label
const char * label
Definition: xwidget.h:326
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88
NORTHEAST
@ NORTHEAST
Definition: xwidget.h:159
_draw_listview
void _draw_listview(void *w_, void *user_data)
_draw_listview - draw listview on expose call
Definition: xlistview_private.c:26
ViewList_t::active_item
int active_item
Definition: xlistview.h:43