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

Go to the source code of this file.

Macros

#define XCOMBOBOX_PRIVATE_H_
 

Functions

void _draw_combobox_button (void *w_, void *user_data)
 _draw_combobox_button - internal draw the combobox button to the buffer More...
 
void _draw_combobox (void *w_, void *user_data)
 _draw_combobox - internal draw the combobox to the buffer More...
 
void _combobox_button_released (void *w_, void *button_, void *user_data)
 _combobox_button_released - popup menu on right click More...
 
void _button_combobox_released (void *w_, void *button_, void *user_data)
 _button_combobox_released - popup the combobox menu More...
 
void _entry_released (void *w_, void *item_, void *user_data)
 _entry_released - the combobox menu release func More...
 
void _set_entry (void *w_, void *user_data)
 _set_entry - set the active combobox entry on adjustment change More...
 

Macro Definition Documentation

◆ XCOMBOBOX_PRIVATE_H_

#define XCOMBOBOX_PRIVATE_H_

Definition at line 24 of file xcombobox_private.h.

Function Documentation

◆ _button_combobox_released()

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

_button_combobox_released - popup the combobox menu

Parameters
*w_- void pointer to the Widget_t button
*button- void pointer to XEvent.xbutton struct
*user_data- void pointer to attached user_data
Returns
void

Definition at line 173 of file xcombobox_private.c.

173  {
174  Widget_t *w = (Widget_t*)w_;
175  XButtonEvent *xbutton = (XButtonEvent*)button_;
176  if (w->flags & HAS_POINTER && xbutton->button == Button1) {
177  Widget_t *parent = (Widget_t*)w->parent;
178  w->state=1;
179  pop_menu_show(parent, parent->childlist->childs[1], 6, true);
180  }
181  adj_set_value(w->adj, 0.0);
182 }

References Widget_t::adj, adj_set_value(), Widget_t::childlist, Childlist_t::childs, Widget_t::flags, HAS_POINTER, Widget_t::parent, pop_menu_show(), and Widget_t::state.

◆ _combobox_button_released()

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

_combobox_button_released - popup menu on right click

Parameters
*w_- void pointer to the Widget_t button
*button- void pointer to XEvent.xbutton struct
*user_data- void pointer to attached user_data
Returns
void

Definition at line 162 of file xcombobox_private.c.

162  {
163  Widget_t *w = (Widget_t*)w_;
164  if (w->flags & HAS_POINTER){
165  XButtonEvent *xbutton = (XButtonEvent*)button_;
166  if (xbutton->button == Button3) {
167  w->state=1;
168  pop_menu_show(w, w->childlist->childs[1], 6, true);
169  }
170  }
171 }

References Widget_t::childlist, Childlist_t::childs, Widget_t::flags, HAS_POINTER, pop_menu_show(), and Widget_t::state.

◆ _draw_combobox()

void _draw_combobox ( void *  w_,
void *  user_data 
)

_draw_combobox - internal draw the combobox to the buffer

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

Definition at line 100 of file xcombobox_private.c.

100  {
101  Widget_t *w = (Widget_t*)w_;
102  if (!w) return;
103  XWindowAttributes attrs;
104  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
105  int width = attrs.width-2;
106  int height = attrs.height-2;
107  if (attrs.map_state != IsViewable) return;
108 
109  cairo_rectangle(w->crb,2.0, 2.0, width, height);
110 
111  if(w->state==0) {
112  cairo_set_line_width(w->crb, 1.0);
114  cairo_fill_preserve(w->crb);
116  } else if(w->state==1) {
118  cairo_fill_preserve(w->crb);
119  cairo_set_line_width(w->crb, 1.5);
121  } else if(w->state==2) {
123  cairo_fill_preserve(w->crb);
124  cairo_set_line_width(w->crb, 1.0);
126  } else if(w->state==3) {
128  cairo_fill_preserve(w->crb);
129  cairo_set_line_width(w->crb, 1.0);
131  } else if(w->state==4) {
133  cairo_fill_preserve(w->crb);
134  cairo_set_line_width(w->crb, 1.0);
136  }
137  cairo_stroke(w->crb);
138 
139  cairo_rectangle(w->crb,4.0, 4.0, width, height);
140  cairo_stroke(w->crb);
141  cairo_rectangle(w->crb,3.0, 3.0, width, height);
142  cairo_stroke(w->crb);
143 
144  cairo_text_extents_t extents;
145 
147  float font_size = w->app->normal_font/w->scale.ascale;
148  cairo_set_font_size (w->crb, font_size);
149  cairo_text_extents(w->crb,w->label , &extents);
150 
151  cairo_move_to (w->crb, (width-extents.width)*0.4, (height+extents.height)*0.55);
152  cairo_show_text(w->crb, w->label);
153  cairo_new_path (w->crb);
154  if (extents.width > (float)width-20) {
155  tooltip_set_text(w,w->label);
156  w->flags |= HAS_TOOLTIP;
157  } else {
158  w->flags &= ~HAS_TOOLTIP;
159  }
160 }

References ACTIVE_, Widget_t::app, Resize_t::ascale, Widget_t::crb, Xputty::dpy, Widget_t::flags, get_color_state(), HAS_TOOLTIP, INSENSITIVE_, Widget_t::label, NORMAL_, Xputty::normal_font, PRELIGHT_, Widget_t::scale, SELECTED_, Widget_t::state, tooltip_set_text(), use_frame_color_scheme(), use_shadow_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _draw_combobox_button()

void _draw_combobox_button ( void *  w_,
void *  user_data 
)

_draw_combobox_button - internal draw the combobox button to the buffer

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

Definition at line 26 of file xcombobox_private.c.

26  {
27  Widget_t *w = (Widget_t*)w_;
28  if (!w) return;
29  XWindowAttributes attrs;
30  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
31  int width = attrs.width-2;
32  int height = attrs.height-4;
33  if (attrs.map_state != IsViewable) return;
34  if (!w->state && (int)w->adj_y->value)
35  w->state = 3;
36 
37  cairo_rectangle(w->crb,2.0, 4.0, width, height);
38 
39  if(w->state==0) {
40  cairo_set_line_width(w->crb, 1.0);
41  _pattern_out(w, NORMAL_, height);
42  cairo_fill_preserve(w->crb);
44  } else if(w->state==1) {
45  _pattern_out(w, PRELIGHT_, height);
46  cairo_fill_preserve(w->crb);
47  cairo_set_line_width(w->crb, 1.5);
49  } else if(w->state==2) {
50  _pattern_in(w, SELECTED_, height);
51  cairo_fill_preserve(w->crb);
52  cairo_set_line_width(w->crb, 1.0);
54  } else if(w->state==3) {
55  _pattern_in(w, ACTIVE_, height);
56  cairo_fill_preserve(w->crb);
57  cairo_set_line_width(w->crb, 1.0);
59  }
60  cairo_stroke(w->crb);
61 
62  if(w->state==2) {
63  cairo_rectangle(w->crb,4.0, 6.0, width, height);
64  cairo_stroke(w->crb);
65  cairo_rectangle(w->crb,3.0, 4.0, width, height);
66  cairo_stroke(w->crb);
67  } else if (w->state==3) {
68  cairo_rectangle(w->crb,3.0, 4.0, width, height);
69  cairo_stroke(w->crb);
70  }
71 
72  float offset = 0.0;
73  if(w->state==0) {
75  } else if(w->state==1) {
77  offset = 1.0;
78  } else if(w->state==2) {
80  offset = 2.0;
81  } else if(w->state==3) {
83  offset = 1.0;
84  }
86  int wa = width/1.1;
87  int h = height/2.2;
88  int wa1 = width/1.55;
89  int h1 = height/1.3;
90  int wa2 = width/2.8;
91 
92  cairo_move_to(w->crb, wa+offset, h+offset);
93  cairo_line_to(w->crb, wa1+offset, h1+offset);
94  cairo_line_to(w->crb, wa2+offset, h+offset);
95  cairo_line_to(w->crb, wa+offset, h+offset);
96  cairo_fill(w->crb);
97 
98 }

References _pattern_in(), _pattern_out(), ACTIVE_, Widget_t::adj_y, Widget_t::app, Widget_t::crb, Xputty::dpy, get_color_state(), NORMAL_, PRELIGHT_, SELECTED_, Widget_t::state, use_fg_color_scheme(), use_frame_color_scheme(), use_text_color_scheme(), Adjustment_t::value, and Widget_t::widget.

◆ _entry_released()

void _entry_released ( void *  w_,
void *  item_,
void *  user_data 
)

_entry_released - the combobox menu release func

Parameters
*w_- void pointer to the Widget_t menu
<em>item- void pointer to the selected item *(int)
*user_data- void pointer to the item label *(const char**)
Returns
void

Definition at line 184 of file xcombobox_private.c.

184  {
185  Widget_t *w = (Widget_t*)w_;
186  Widget_t * combo = NULL;
187  int i = w->app->childlist->elem-1;
188  for(;i>-1;i--) {
189  Widget_t *wid = w->app->childlist->childs[i];
190  if (wid == w) {
191  combo = w->app->childlist->childs[i-2];
192  adj_set_value(combo->adj, (float)*(int*)item_);
193  break;
194  }
195  }
196 }

References Widget_t::adj, adj_set_value(), Widget_t::app, Xputty::childlist, Childlist_t::childs, and Childlist_t::elem.

◆ _set_entry()

void _set_entry ( void *  w_,
void *  user_data 
)

_set_entry - set the active combobox entry on adjustment change

Parameters
*w_- void pointer to the Widget_t combobox
*user_data- void pointer to the item label *(const char**)
Returns
void

Definition at line 198 of file xcombobox_private.c.

198  {
199  Widget_t *w = (Widget_t*)w_;
200  int v = (int)adj_get_value(w->adj);
201  Widget_t * menu = w->childlist->childs[1];
202  if (!childlist_has_child(menu->childlist)) return;
203  Widget_t* view_port = menu->childlist->childs[0];
204  if(v>=0) {
205  w->label = view_port->childlist->childs[v]->label;
206  transparent_draw(w, user_data);
207  }
208 }

References Widget_t::adj, adj_get_value(), Widget_t::childlist, childlist_has_child(), Childlist_t::childs, Widget_t::label, and transparent_draw().

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
Xputty::childlist
Childlist_t * childlist
Definition: xputty.h:179
Adjustment_t::value
float value
Definition: xadjustment.h:86
INSENSITIVE_
@ INSENSITIVE_
Definition: xcolor.h:43
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
_pattern_in
void _pattern_in(Widget_t *w, Color_state st, int height)
_pattern_in - a little pattern to make press state more visible
Definition: xbutton_private.c:46
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
transparent_draw
void transparent_draw(void *wid, void *user_data)
transparent_draw - copy parent surface to child surface you usaualy didn't need to call this,...
Definition: xwidget.c:469
Xputty::normal_font
int normal_font
Definition: xputty.h:191
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
_pattern_out
void _pattern_out(Widget_t *w, Color_state st, int height)
_pattern_in - a little pattern to make press state more visible
Definition: xbutton_private.c:35
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::scale
Resize_t scale
Definition: xwidget.h:356
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
Resize_t::ascale
float ascale
Definition: xwidget.h:214
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
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
pop_menu_show
void pop_menu_show(Widget_t *parent, Widget_t *menu, int elem, bool above)
pop_menu_show - pop up a menu to a Widget_t
Definition: xmenu.c:26
Childlist_t::elem
int elem
Definition: xchildlist.h:57
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
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
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
SELECTED_
@ SELECTED_
Definition: xcolor.h:41
Widget_t::label
const char * label
Definition: xwidget.h:326