libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xlistview.c File Reference
#include "xlistview.h"
#include "xlistview_private.h"
#include "xtooltip.h"
Include dependency graph for xlistview.c:

Go to the source code of this file.

Functions

void listview_set_active_entry (Widget_t *w, int active)
 listview_set_active_entry - set the active listview entry More...
 
Widget_tcreate_listview_viewport (Widget_t *parent, int elem, int width, int height)
 create_listview_viewport - create a viewport on a listview to a Widget_t More...
 
Widget_tadd_listview (Widget_t *parent, const char *label, int x, int y, int width, int height)
 add_label - add a listview to a Widget_t More...
 
void listview_mem_free (void *w_, void *user_data)
 listview_mem_free - release additional used memory when destroy the Widget_t More...
 
void listview_set_list (Widget_t *listview, char **list, int list_size)
 listview_set_list - set a list to a listview Widget_t More...
 

Function Documentation

◆ 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

Parameters
*parent- pointer to the Widget_t request the label
*label- Label to show on the button
x,y,width,height- the position/geometry to create the label
Returns
Widget_t* - pointer to the Widget_t label struct

Definition at line 64 of file xlistview.c.

65  {
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 }

References _draw_listview(), add_adjustment(), Widget_t::adj, Widget_t::adj_y, Widget_t::app, CENTER, CL_NONE, create_listview_viewport(), create_widget(), Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, Widget_t::label, Widget_t::scale, and USE_TRANSPARENCY.

◆ 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

Parameters
*parent- pointer to the Widget_t the listview should pop over
width- define the width of the viewport
height- define the height of the viewport
Returns
Widget_t* - pointer to the Widget_t viewport

Definition at line 38 of file xlistview.c.

38  {
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 }

References _configure_listview(), _draw_list(), _leave_list(), _list_entry_released(), _list_key_pressed(), _list_motion(), _reconfigure_listview_viewport(), _set_listview_viewpoint(), add_adjustment(), Widget_t::adj, Func_t::adj_callback, Widget_t::adj_y, Widget_t::app, Func_t::button_release_callback, CL_VIEWPORT, Func_t::configure_notify_callback, create_widget(), Xputty::dpy, Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, HAS_MEM, Func_t::key_press_callback, Func_t::leave_callback, listview_mem_free(), Func_t::map_notify_callback, Func_t::mem_free_callback, Func_t::motion_callback, NORTHEAST, Widget_t::parent_struct, Widget_t::scale, ViewList_t::show_items, and Widget_t::widget.

◆ listview_mem_free()

void listview_mem_free ( void *  w_,
void *  user_data 
)

listview_mem_free - release additional used memory when destroy the Widget_t

Parameters
*w_- void pointer to the Widget_t
*user_data- void pointer to attached user_data
Returns
void

Definition at line 79 of file xlistview.c.

79  {
80  Widget_t *w = (Widget_t*)w_;
81  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
82  free(filelist);
83 }

References Widget_t::parent_struct.

◆ listview_set_active_entry()

void listview_set_active_entry ( Widget_t w,
int  active 
)

listview_set_active_entry - set the active listview entry

Parameters
*w_- void pointer to the Widget_t listview
active- the active entry (int)
Returns
void

Definition at line 27 of file xlistview.c.

27  {
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 }

References ViewList_t::active_item, Widget_t::adj, adj_set_value(), Widget_t::childlist, Childlist_t::childs, Adjustment_t::max_value, Adjustment_t::min_value, and Widget_t::parent_struct.

◆ 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

Parameters
*listview- pointer to the Widget_t listview which should show the list
**list- pointer to the list
list_size- how many items contain the list
Returns
void

Definition at line 85 of file xlistview.c.

85  {
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 }

References _configure_listview(), Widget_t::adj, Widget_t::childlist, Childlist_t::childs, CL_NONE, CL_VIEWPORT, ViewList_t::list_names, ViewList_t::list_size, Adjustment_t::max_value, Widget_t::parent_struct, and set_adjustment().

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
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
_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
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
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
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
_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