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

Go to the source code of this file.

Functions

void _draw_listview (void *w_, void *user_data)
 _draw_listview - draw listview on expose call More...
 
void _draw_list (void *w_, void *user_data)
 _draw_list - draw list on expose call More...
 
void _list_motion (void *w_, void *xmotion_, void *user_data)
 _list_motion - follow mouse pointer to set prelight item More...
 
void _list_key_pressed (void *w_, void *xkey_, void *user_data)
 _list_key_pressed - move listview or set active entry More...
 
void _list_entry_released (void *w_, void *button_, void *user_data)
 _list_entry_released - move listview or set active entry More...
 
void _leave_list (void *w_, void *user_data)
 _leave_list - draw list on pointer leave More...
 
void _reconfigure_listview_viewport (void *w_, void *user_data)
 _reconfigure_listview_viewport - reconfigure the viewport adjustment on size changes More...
 
void _configure_listview (void *w_, void *user_data)
 _configure_listview - configure the viewport on mapping More...
 
void _draw_listview_viewslider (void *w_, void *user_data)
 _draw_listview_viewslider - draw a slider on the viewport to indicate the view point More...
 
void _set_listview_viewpoint (void *w_, void *user_data)
 _set_listview_viewpoint - move the view_port to position More...
 

Function Documentation

◆ _configure_listview()

void _configure_listview ( void *  w_,
void *  user_data 
)

_configure_listview - configure the viewport on mapping

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

Definition at line 182 of file xlistview_private.c.

182  {
183  Widget_t *w = (Widget_t*)w_;
184  Widget_t* listview = (Widget_t*) w->parent;
185  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
186  XWindowAttributes attrs;
187  XGetWindowAttributes(listview->app->dpy, (Window)listview->widget, &attrs);
188  int width = attrs.width;
189  XResizeWindow (w->app->dpy, w->widget, width, 25*(max(1,filelist->list_size)));
190 }

References Widget_t::app, Xputty::dpy, max, Widget_t::parent, Widget_t::parent_struct, and Widget_t::widget.

◆ _draw_list()

void _draw_list ( void *  w_,
void *  user_data 
)

_draw_list - draw list on expose call

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

show label

Definition at line 33 of file xlistview_private.c.

33  {
34  Widget_t *w = (Widget_t*)w_;
35  _draw_listview_viewslider(w, user_data);
36  XWindowAttributes attrs;
37  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
38  if (attrs.map_state != IsViewable) return;
39  int width = attrs.width;
40  int height = attrs.height;
41  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
42 
43  int v = (int)w->adj->max_value;
44  int sub = (v<=0) ? 0 : 5;
46  cairo_rectangle(w->crb, 0, 0, width-sub , height);
47  cairo_fill (w->crb);
48 
49  int i = (int)max(0,adj_get_value(w->adj));
50  int j = filelist->list_size<filelist->show_items+i+1 ?
51  filelist->list_size : filelist->show_items+i+1;
52  for(;i<j;i++) {
53  if(i == filelist->prelight_item && i == filelist->active_item)
55  else if(i == filelist->prelight_item)
57  else if (i == filelist->active_item)
59  else
61  cairo_rectangle(w->crb, 0, i*25, width-sub , 25);
62  cairo_fill_preserve(w->crb);
63  cairo_set_line_width(w->crb, 1.0);
65  cairo_stroke(w->crb);
66  cairo_text_extents_t extents;
67  /** show label **/
68  if(i == filelist->prelight_item && i == filelist->active_item)
70  else if(i == filelist->prelight_item)
72  else if (i == filelist->active_item)
74  else
76  cairo_set_font_size (w->crb, 12);
77  cairo_text_extents(w->crb,filelist->list_names[i] , &extents);
78 
79  cairo_move_to (w->crb, (width-extents.width)/2., (25*(i+1)) - extents.height );
80  cairo_show_text(w->crb, filelist->list_names[i]);
81  cairo_new_path (w->crb);
82  if (i == filelist->prelight_item && extents.width > (float)width-20) {
83  tooltip_set_text(w,filelist->list_names[i]);
84  w->flags |= HAS_TOOLTIP;
85  show_tooltip(w);
86  } else {
87  w->flags &= ~HAS_TOOLTIP;
88  hide_tooltip(w);
89  }
90  }
91 }

References _draw_listview_viewslider(), ACTIVE_, ViewList_t::active_item, Widget_t::adj, adj_get_value(), Widget_t::app, Widget_t::crb, Xputty::dpy, Widget_t::flags, HAS_TOOLTIP, hide_tooltip(), ViewList_t::list_names, ViewList_t::list_size, max, Adjustment_t::max_value, NORMAL_, Widget_t::parent_struct, PRELIGHT_, ViewList_t::prelight_item, SELECTED_, ViewList_t::show_items, show_tooltip(), tooltip_set_text(), use_base_color_scheme(), use_frame_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _draw_listview()

void _draw_listview ( void *  w_,
void *  user_data 
)

_draw_listview - draw listview on expose call

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

Definition at line 26 of file xlistview_private.c.

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

References XColor_t::active, Widget_t::app, BACKGROUND_, Xputty::color_scheme, Widget_t::cr, XColor_t::normal, and set_pattern().

◆ _draw_listview_viewslider()

void _draw_listview_viewslider ( void *  w_,
void *  user_data 
)

_draw_listview_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 192 of file xlistview_private.c.

192  {
193  Widget_t *w = (Widget_t*)w_;
194  int v = (int)w->adj->max_value;
195  if (v<=0) return;
196  XWindowAttributes attrs;
197  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
198  if (attrs.map_state != IsViewable) return;
199  int width = attrs.width;
200  int height = attrs.height;
201  float sliderstate = adj_get_state(w->adj);
203  cairo_rectangle(w->crb, width-5,0,5,height);
204  cairo_fill_preserve(w->crb);
206  cairo_fill(w->crb);
208  cairo_rectangle(w->crb, width-5,(height-10)*sliderstate,5,10);
209  cairo_fill_preserve(w->crb);
211  cairo_set_line_width(w->crb,1);
212  cairo_stroke(w->crb);
213 }

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

◆ _leave_list()

void _leave_list ( void *  w_,
void *  user_data 
)

_leave_list - draw list on pointer leave

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

Definition at line 162 of file xlistview_private.c.

162  {
163  Widget_t *w = (Widget_t*)w_;
164  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
165  filelist->prelight_item = -1;
166  expose_widget(w);
167 }

References expose_widget(), Widget_t::parent_struct, and ViewList_t::prelight_item.

◆ _list_entry_released()

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

_list_entry_released - move listview or set active entry

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

Definition at line 134 of file xlistview_private.c.

134  {
135  Widget_t *w = (Widget_t*)w_;
136  if (w->flags & HAS_POINTER) {
137  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
138  XButtonEvent *xbutton = (XButtonEvent*)button_;
139  XWindowAttributes attrs;
140  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
141  int height = attrs.height;
142  int _items = height/(height/25);
143  int prelight_item = xbutton->y/_items;
144  if(xbutton->button == Button4) {
145  prelight_item = (xbutton->y-24)/_items;
146  if(prelight_item != filelist->prelight_item) {
147  filelist->prelight_item = prelight_item;
148  }
149  } else if (xbutton->button == Button5) {
150  prelight_item = (xbutton->y+24)/_items;
151  if(prelight_item != filelist->prelight_item) {
152  filelist->prelight_item = prelight_item;
153  }
154  } else if(xbutton->button == Button1) {
155  Widget_t* listview = (Widget_t*) w->parent;
156  filelist->active_item = filelist->prelight_item;
157  adj_set_value(listview->adj,filelist->active_item);
158  }
159  }
160 }

References ViewList_t::active_item, Widget_t::adj, adj_set_value(), Widget_t::app, Xputty::dpy, Widget_t::flags, HAS_POINTER, Widget_t::parent, Widget_t::parent_struct, ViewList_t::prelight_item, and Widget_t::widget.

◆ _list_key_pressed()

void _list_key_pressed ( void *  w_,
void *  xkey_,
void *  user_data 
)

_list_key_pressed - move listview or set active entry

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

Definition at line 108 of file xlistview_private.c.

108  {
109  Widget_t *w = (Widget_t*)w_;
110  XKeyEvent *xkey = (XKeyEvent*)xkey_;
111  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
112  XWindowAttributes attrs;
113  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
114  int height = attrs.height;
115  int _items = height/(height/25);
116  // filelist->prelight_item = xkey->y/_items;
117  int nk = key_mapping(w->app->dpy, xkey);
118  if (nk) {
119  switch (nk) {
120  case 3: filelist->prelight_item = (xkey->y+24)/_items;
121  break;
122  case 4: filelist->prelight_item = (xkey->y+24)/_items;
123  break;
124  case 5: filelist->prelight_item = (xkey->y-24)/_items;
125  break;
126  case 6: filelist->prelight_item = (xkey->y-24)/_items;
127  break;
128  default:
129  break;
130  }
131  }
132 }

References Widget_t::app, Xputty::dpy, key_mapping(), Widget_t::parent_struct, ViewList_t::prelight_item, and Widget_t::widget.

◆ _list_motion()

void _list_motion ( void *  w_,
void *  xmotion_,
void *  user_data 
)

_list_motion - follow mouse pointer to set prelight item

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

Definition at line 93 of file xlistview_private.c.

93  {
94  Widget_t *w = (Widget_t*)w_;
95  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
96  XMotionEvent *xmotion = (XMotionEvent*)xmotion_;
97  XWindowAttributes attrs;
98  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
99  int height = attrs.height;
100  int _items = height/(height/25);
101  int prelight_item = xmotion->y/_items;
102  if(prelight_item != filelist->prelight_item) {
103  filelist->prelight_item = prelight_item;
104  expose_widget(w);
105  }
106 }

References Widget_t::app, Xputty::dpy, expose_widget(), Widget_t::parent_struct, ViewList_t::prelight_item, and Widget_t::widget.

◆ _reconfigure_listview_viewport()

void _reconfigure_listview_viewport ( void *  w_,
void *  user_data 
)

_reconfigure_listview_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 169 of file xlistview_private.c.

169  {
170  Widget_t *w = (Widget_t*)w_;
171  float st = adj_get_state(w->adj);
172  Widget_t* listview = (Widget_t*) w->parent;
173  ViewList_t *filelist = (ViewList_t*)w->parent_struct;
174  XWindowAttributes attrs;
175  XGetWindowAttributes(listview->app->dpy, (Window)listview->widget, &attrs);
176  int height = attrs.height;
177  filelist->show_items = height/25;
178  w->adj->max_value = filelist->list_size-filelist->show_items;
179  adj_set_state(w->adj,st);
180 }

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

◆ _set_listview_viewpoint()

void _set_listview_viewpoint ( void *  w_,
void *  user_data 
)

_set_listview_viewpoint - move the view_port to position

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

Definition at line 215 of file xlistview_private.c.

215  {
216  Widget_t *w = (Widget_t*)w_;
217  int v = (int)max(0,adj_get_value(w->adj));
218  XMoveWindow(w->app->dpy,w->widget,0, -25*v);
219 }

References Widget_t::adj, adj_get_value(), Widget_t::app, Xputty::dpy, max, 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
XColor_t::active
Colors active
Definition: xcolor.h:92
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
ViewList_t::prelight_item
int prelight_item
Definition: xlistview.h:42
hide_tooltip
void hide_tooltip(Widget_t *wid)
hide_tooltip - check if a Widget_t have a tooltip, and hide it, if a tooltip is mapped.
Definition: xwidget.c:446
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
key_mapping
int key_mapping(Display *dpy, XKeyEvent *xkey)
_key_mapping - modifier key's mapped to a integer value
Definition: xwidget.c:26
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
use_shadow_color_scheme
void use_shadow_color_scheme(Widget_t *w, Color_state st)
use_shadow_color_scheme - use shadow Colors to paint on Widget_t
Definition: xcolor.c:206
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
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
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
Widget_t::cr
cairo_t * cr
Definition: xwidget.h:314
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
BACKGROUND_
@ BACKGROUND_
Definition: xcolor.h:53
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
ViewList_t::show_items
int show_items
Definition: xlistview.h:44
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
ACTIVE_
@ ACTIVE_
Definition: xcolor.h:42
Widget_t::widget
Window widget
Definition: xwidget.h:302
_draw_listview_viewslider
void _draw_listview_viewslider(void *w_, void *user_data)
_draw_listview_viewslider - draw a slider on the viewport to indicate the view point
Definition: xlistview_private.c:192
show_tooltip
void show_tooltip(Widget_t *wid)
show_tooltip - check if a Widget_t have a tooltip, and show it, if a tooltip is available.
Definition: xwidget.c:427
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
ViewList_t::list_size
int list_size
Definition: xlistview.h:45
PRELIGHT_
@ PRELIGHT_
Definition: xcolor.h:40
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
set_pattern
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
Definition: xcolor.c:227
ViewList_t::list_names
char ** list_names
Definition: xlistview.h:46
Xputty::color_scheme
XColor_t * color_scheme
Definition: xputty.h:183
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
ViewList_t
ViewList_t - struct to hold information for the listview.
Definition: xlistview.h:41
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
SELECTED_
@ SELECTED_
Definition: xcolor.h:41
XColor_t::normal
Colors normal
Definition: xcolor.h:89
ViewList_t::active_item
int active_item
Definition: xlistview.h:43