libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xlistbox_private.h File Reference
#include "xlistbox.h"
Include dependency graph for xlistbox_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XLISTBOX_PRIVATE_H_
 

Functions

void _draw_listbox (void *w_, void *user_data)
 _draw_listbox - draw listbox on expose call More...
 
void _draw_listbox_item (void *w_, void *user_data)
 _draw_listbox_item - draw item on expose call More...
 
void _draw_listbox_viewslider (void *w_, void *user_data)
 _draw_listbox_viewslider - draw a slider on the viewport to indicate the view point More...
 
void _reconfigure_listbox_viewport (void *w_, void *user_data)
 _reconfigure_listbox_viewport - reconfigure the viewport adjustment on size changes More...
 
void _configure_listbox (void *w_, void *user_data)
 _configure_listbox - configure the viewport on mapping More...
 
void _set_listbox_viewpoint (void *w_, void *user_data)
 _set_listbox_viewpoint - move the view_port to position More...
 
void _listbox_entry_released (void *w_, void *button_, void *user_data)
 _listbox_entry_released - redraw the slider when buttob released More...
 

Macro Definition Documentation

◆ XLISTBOX_PRIVATE_H_

#define XLISTBOX_PRIVATE_H_

Definition at line 24 of file xlistbox_private.h.

Function Documentation

◆ _configure_listbox()

void _configure_listbox ( void *  w_,
void *  user_data 
)

_configure_listbox - configure the viewport on mapping

Parameters
*w_- void pointer to view_port
*user_data- attached user_data
Returns
void

Definition at line 90 of file xlistbox_private.c.

90  {
91  Widget_t *w = (Widget_t*)w_;
92  int si = max(1,childlist_has_child(w->childlist));
93  Widget_t* listbox = (Widget_t*)w->parent;
94  XWindowAttributes attrs;
95  XGetWindowAttributes(listbox->app->dpy, (Window)listbox->widget, &attrs);
96  int width = attrs.width;
97  XResizeWindow (w->app->dpy, w->widget, width, 25*(si));
98 }

References Widget_t::app, Widget_t::childlist, childlist_has_child(), Xputty::dpy, max, Widget_t::parent, and Widget_t::widget.

◆ _draw_listbox()

void _draw_listbox ( void *  w_,
void *  user_data 
)

_draw_listbox - draw listbox on expose call

Parameters
*w_- the listbox to draw
*user_data- attached user_data
Returns
void

Definition at line 26 of file xlistbox_private.c.

26  {
27  Widget_t *w = (Widget_t*)w_;
28  if (!w) return;
30  cairo_paint (w->crb);
31 }

References Widget_t::crb, NORMAL_, and use_bg_color_scheme().

◆ _draw_listbox_item()

void _draw_listbox_item ( void *  w_,
void *  user_data 
)

_draw_listbox_item - draw item on expose call

Parameters
*w_- the item to draw
*user_data- attached user_data
Returns
void

show label

Definition at line 33 of file xlistbox_private.c.

33  {
34  Widget_t *w = (Widget_t*)w_;
35  if (!w) return;
36  XWindowAttributes attrs;
37  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
38  int width = attrs.width;
39  int height = attrs.height;
40  if (attrs.map_state != IsViewable) return;
41  Widget_t* view_port = (Widget_t*)w->parent;
42  Widget_t* listbox = (Widget_t*)view_port->parent;
43  int j = (int)listbox->adj->value;
44  if(w == view_port->childlist->childs[j])
45  w->state = (w->state == 1) ? 1 : 3;
46 
48  cairo_rectangle(w->crb, 0, 0, width , height);
49  if(w->state==1) {
51  } else if(w->state==2) {
53  } else if(w->state==3) {
55  }
56  cairo_fill_preserve(w->crb);
57  cairo_set_line_width(w->crb, 1.0);
59  cairo_stroke(w->crb);
60  cairo_text_extents_t extents;
61  /** show label **/
63  cairo_set_font_size (w->crb, height/2);
64  cairo_text_extents(w->crb,w->label , &extents);
65 
66  cairo_move_to (w->crb, (width-extents.width)/2., height - extents.height );
67  cairo_show_text(w->crb, w->label);
68  cairo_new_path (w->crb);
69  if (extents.width > (float)width) {
70  tooltip_set_text(w,w->label);
71  w->flags |= HAS_TOOLTIP;
72  } else {
73  w->flags &= ~HAS_TOOLTIP;
74  }
75 }

References ACTIVE_, Widget_t::app, Widget_t::childlist, Childlist_t::childs, Widget_t::crb, Xputty::dpy, Widget_t::flags, get_color_state(), HAS_TOOLTIP, Widget_t::label, NORMAL_, Widget_t::parent, PRELIGHT_, SELECTED_, Widget_t::state, tooltip_set_text(), use_base_color_scheme(), use_frame_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _draw_listbox_viewslider()

void _draw_listbox_viewslider ( void *  w_,
void *  user_data 
)

_draw_listbox_viewslider - draw a slider on the viewport to indicate the view point

Parameters
*w_- void pointer to view_port
*user_data- attached user_data
Returns
void

Definition at line 100 of file xlistbox_private.c.

100  {
101  Widget_t *w = (Widget_t*)w_;
102  int v = (int)w->adj->max_value;
103  if (!v) return;
104  XWindowAttributes attrs;
105  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
106  if (attrs.map_state != IsViewable) return;
107  int width = attrs.width;
108  int height = attrs.height;
109  float sliderstate = adj_get_state(w->adj);
111  cairo_rectangle(w->crb, width-5,0,5,height);
112  cairo_fill_preserve(w->crb);
114  cairo_fill(w->crb);
116  cairo_rectangle(w->crb, width-5,(height-10)*sliderstate,5,10);
117  cairo_fill_preserve(w->crb);
119  cairo_set_line_width(w->crb,1);
120  cairo_stroke(w->crb);
121 }

References Widget_t::adj, adj_get_state(), Widget_t::app, Widget_t::crb, Xputty::dpy, Adjustment_t::max_value, NORMAL_, use_base_color_scheme(), use_bg_color_scheme(), use_fg_color_scheme(), and Widget_t::widget.

◆ _listbox_entry_released()

void _listbox_entry_released ( void *  w_,
void *  button_,
void *  user_data 
)

_listbox_entry_released - redraw the slider when buttob released

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

Definition at line 132 of file xlistbox_private.c.

132  {
133  Widget_t *w = (Widget_t*)w_;
134  Widget_t* view_port = (Widget_t*)w->parent;
135  int direction = 0 ;
136  if (w->flags & HAS_POINTER) {
137  XButtonEvent *xbutton = (XButtonEvent*)button_;
138  if(xbutton->button == Button1) {
139  Widget_t* listbox = (Widget_t*)view_port->parent;
140  int i = view_port->childlist->elem-1;
141  int old_value = (int) listbox->adj->value;
142  for(;i>-1;i--) {
143  Widget_t *wid = view_port->childlist->childs[i];
144  if (xbutton->window == wid->widget) {
145  const char *l = view_port->childlist->childs[i]->label;
146  float value = (float)i;
147  check_value_changed(listbox->adj, &value);
148  wid->state= 3;
149  listbox->func.button_release_callback(listbox, &i, &l);
150  }
151  wid->state= 0;
152  }
153  expose_widget(view_port->childlist->childs[old_value]);
154  expose_widget(w);
155  } else if(xbutton->button == Button4) {
156  direction = 1;
157  } else if(xbutton->button == Button5) {
158  direction = -1;
159  }
160  if (direction !=0) {
161  float value = view_port->adj->value + (view_port->adj->step * -direction);
162  if (value>view_port->adj->max_value) value = view_port->adj->max_value;
163  if (value<view_port->adj->min_value) value = view_port->adj->min_value;
164  check_value_changed(view_port->adj, &value);
165  }
166  }
167 }

References Widget_t::adj, Func_t::button_release_callback, check_value_changed(), Widget_t::childlist, Childlist_t::childs, Childlist_t::elem, expose_widget(), Widget_t::flags, Widget_t::func, HAS_POINTER, Widget_t::label, Adjustment_t::max_value, Adjustment_t::min_value, Widget_t::parent, Widget_t::state, Adjustment_t::step, Adjustment_t::value, and Widget_t::widget.

◆ _reconfigure_listbox_viewport()

void _reconfigure_listbox_viewport ( void *  w_,
void *  user_data 
)

_reconfigure_listbox_viewport - reconfigure the viewport adjustment on size changes

Parameters
*w_- void pointer to view_port
*user_data- attached user_data
Returns
void

Definition at line 77 of file xlistbox_private.c.

77  {
78  Widget_t *w = (Widget_t*)w_;
79  float st = adj_get_state(w->adj);
80  Widget_t* listbox = (Widget_t*)w->parent;
81  XWindowAttributes attrs;
82  XGetWindowAttributes(listbox->app->dpy, (Window)listbox->widget, &attrs);
83  int height = attrs.height;
84  int elem = height/25;
85  int si = childlist_has_child(w->childlist);
86  w->adj->max_value = si-elem;
87  adj_set_state(w->adj,st);
88 }

References Widget_t::adj, adj_get_state(), adj_set_state(), Widget_t::app, Widget_t::childlist, childlist_has_child(), Xputty::dpy, Adjustment_t::max_value, Widget_t::parent, and Widget_t::widget.

◆ _set_listbox_viewpoint()

void _set_listbox_viewpoint ( void *  w_,
void *  user_data 
)

_set_listbox_viewpoint - move the view_port to position

Parameters
*w_- void pointer to view_port
*user_data- attached user_data
Returns
void

Definition at line 123 of file xlistbox_private.c.

123  {
124  Widget_t *w = (Widget_t*)w_;
125  int v = (int)adj_get_value(w->adj);
126  XWindowAttributes attrs;
127  XGetWindowAttributes(w->app->dpy, (Window)w->childlist->childs[0]->widget, &attrs);
128  int height = attrs.height;
129  XMoveWindow(w->app->dpy,w->widget,0, -height*v);
130 }

References Widget_t::adj, adj_get_value(), Widget_t::app, Widget_t::childlist, Childlist_t::childs, Xputty::dpy, and Widget_t::widget.

use_text_color_scheme
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition: xcolor.c:199
HAS_TOOLTIP
@ HAS_TOOLTIP
Definition: xwidget.h:249
expose_widget
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition: xwidget.c:461
adj_get_state
float adj_get_state(Adjustment_t *adj)
adj_get_state - get the current state of the Adjustment_t
Definition: xadjustment.c:148
Adjustment_t::value
float value
Definition: xadjustment.h:86
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
get_color_state
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
Definition: xcolor.c:155
adj_get_value
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
Definition: xadjustment.c:154
HAS_POINTER
@ HAS_POINTER
Definition: xwidget.h:247
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
use_fg_color_scheme
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
Definition: xcolor.c:178
use_bg_color_scheme
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition: xcolor.c:185
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
use_frame_color_scheme
void use_frame_color_scheme(Widget_t *w, Color_state st)
use_frame_color_scheme - use frame Colors to paint on Widget_t
Definition: xcolor.c:213
Widget_t::state
int state
Definition: xwidget.h:342
ACTIVE_
@ ACTIVE_
Definition: xcolor.h:42
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
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
PRELIGHT_
@ PRELIGHT_
Definition: xcolor.h:40
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
adj_set_state
void adj_set_state(Adjustment_t *adj, float state)
adj_set_state - set the current state of the Adjustment_t
Definition: xadjustment.c:141
Childlist_t::elem
int elem
Definition: xchildlist.h:57
Widget_t::func
Func_t func
Definition: xwidget.h:310
childlist_has_child
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition: xchildlist.c:91
max
#define max(x, y)
max - set a minimal value (x) as return value
Definition: xputty.h:86
Widget_t::parent
void * parent
Definition: xwidget.h:304
tooltip_set_text
void tooltip_set_text(Widget_t *w, const char *label)
tooltip_set_text - set a (new) text to a tooltip for Widget_t
Definition: xtooltip.c:25
use_base_color_scheme
void use_base_color_scheme(Widget_t *w, Color_state st)
use_base_color_scheme - use base Colors to paint on Widget_t
Definition: xcolor.c:192
check_value_changed
void check_value_changed(Adjustment_t *adj, float *value)
check_value_changed - check if Adjustment_t value have changed and send value_changed_callback (VALUE...
Definition: xadjustment.c:241
SELECTED_
@ SELECTED_
Definition: xcolor.h:41
Widget_t::label
const char * label
Definition: xwidget.h:326
Adjustment_t::step
float step
Definition: xadjustment.h:92
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88