libxputty 0.1
Loading...
Searching...
No Matches
Functions
xcombobox.c File Reference

Go to the source code of this file.

Functions

void combobox_set_active_entry (Widget_t *w, int active)
 combobox_set_active_entry - set the active combobox entry
 
void combobox_rename_entry (Widget_t *w, int active, const char *label)
 combobox_rename_entry - rename a entry in the combobox
 
void combobox_mem_free (void *w_, void *user_data)
 combobox_mem_free - release additional used memory when destroy the Widget_t
 
void combobox_set_menu_size (Widget_t *combobox, int v)
 combobox_set_menu_size - set the number of entrys shown in the pop menu
 
void combobox_delete_entrys (Widget_t *combobox)
 combobox_delete_entrys - free the list hold the combobox entrys
 
void pop_combobox_menu_show (Widget_t *parent, Widget_t *menu, bool above)
 
Widget_tcreate_combobox_viewport (Widget_t *parent, int elem, int width, int height)
 
Widget_tcreate_combobox_menu (Widget_t *parent, int height)
 
Widget_tadd_combobox (Widget_t *parent, const char *label, int x, int y, int width, int height)
 add_combobox - add a combobox
 
void combobox_add_entry (Widget_t *wid, const char *label)
 combobox_add_entry - add a entry to the combobox
 
void combobox_add_numeric_entrys (Widget_t *wid, int imin, int imax)
 combobox_add_numeric_items - add numeric items from imin to imax to wid
 

Function Documentation

◆ add_combobox()

Widget_t * add_combobox ( Widget_t parent,
const char *  label,
int  x,
int  y,
int  width,
int  height 
)

add_combobox - add a combobox

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

Definition at line 152 of file xcombobox.c.

152 {
153
154 Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
155 wid->label = label;
156 wid->scale.gravity = CENTER;
157 wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, -1.0,1.0, CL_ENUM);
158 wid->adj = wid->adj_y;
164
165 Widget_t* button = add_button(wid, "", width-20, 0, 20, height);
168
169 Widget_t* menu = create_combobox_menu(wid, 25);
171
172 return wid;
173}
evfunc button_release_callback
Definition xwidget.h:101
xevfunc expose_callback
Definition xwidget.h:85
xevfunc leave_callback
Definition xwidget.h:88
xevfunc adj_callback
Definition xwidget.h:89
xevfunc enter_callback
Definition xwidget.h:87
Gravity gravity
Definition xwidget.h:347
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
Adjustment_t * adj_y
Definition xwidget.h:495
Adjustment_t * adj
Definition xwidget.h:497
const char * label
Definition xwidget.h:463
Func_t func
Definition xwidget.h:481
Xputty * app
Definition xwidget.h:465
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
@ CL_ENUM
Definition xadjustment.h:55
Widget_t * add_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_button - add a button to a Widget_t connect to func.value_changed_callback to implement your acti...
Definition xbutton.c:26
Widget_t * create_combobox_menu(Widget_t *parent, int height)
Definition xcombobox.c:123
void _draw_combobox(void *w_, void *user_data)
_draw_combobox - internal draw the combobox to the buffer
void _combobox_button_released(void *w_, void *button_, void *user_data)
_combobox_button_released - popup menu on right click
void _draw_combobox_button(void *w_, void *user_data)
_draw_combobox_button - internal draw the combobox button to the buffer
void _button_combobox_released(void *w_, void *button_, void *user_data)
_button_combobox_released - popup the combobox menu
void _entry_released(void *w_, void *item_, void *user_data)
_entry_released - the combobox menu release func
void _set_entry(void *w_, void *user_data)
_set_entry - set the active combobox entry on adjustment change
void os_transparent_draw(void *w_, void *user_data)
os_transparent_draw - Draw the Widget_t to the back buffer
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:265
@ CENTER
Definition xwidget.h:320

References _button_combobox_released(), _combobox_button_released(), _draw_combobox(), _draw_combobox_button(), _entry_released(), _set_entry(), add_adjustment(), add_button(), Widget_t::adj, Func_t::adj_callback, Widget_t::adj_y, Widget_t::app, Func_t::button_release_callback, CENTER, CL_ENUM, create_combobox_menu(), create_widget(), Func_t::enter_callback, Func_t::expose_callback, Widget_t::func, Resize_t::gravity, Widget_t::label, Func_t::leave_callback, os_transparent_draw(), and Widget_t::scale.

Referenced by add_my_combobox(), mk_open_midi_keyboard(), open_directory_dialog(), open_file_dialog(), and save_file_dialog().

◆ combobox_add_entry()

void combobox_add_entry ( Widget_t wid,
const char *  label 
)

combobox_add_entry - add a entry to the combobox

Parameters
*wid- pointer to the Widget_t combobox
*label- Label to show on the menu

Definition at line 175 of file xcombobox.c.

175 {
176 Widget_t *menu = wid->childlist->childs[1];
177 Widget_t* view_port = menu->childlist->childs[0];
178 ComboBox_t *comboboxlist = (ComboBox_t*)view_port->parent_struct;
179 comboboxlist->list_size++;
180 comboboxlist->list_names = (char **)realloc(comboboxlist->list_names,
181 comboboxlist->list_size * sizeof(char *));
182 asprintf(&comboboxlist->list_names[comboboxlist->list_size-1],"%s",label);
183 assert(comboboxlist->list_names != NULL);
184 float max_value = wid->adj->max_value+1.0;
185 set_adjustment(wid->adj,0.0, max_value, 0.0, max_value,1.0, CL_ENUM);
186
187}
float max_value
Definition xadjustment.h:92
Widget_t ** childs
Definition xchildlist.h:51
ComboBox_t - struct to hold information for the combobox.
Definition xcombobox.h:45
Childlist_t * childlist
Definition xwidget.h:499
void * parent_struct
Definition xwidget.h:473
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 or create if it not exists yet
Definition xadjustment.c:80
int asprintf(char *strp[], const char *fmt,...)
Definition xasprintf.c:36

References Widget_t::adj, asprintf(), Widget_t::childlist, Childlist_t::childs, CL_ENUM, ComboBox_t::list_names, ComboBox_t::list_size, Adjustment_t::max_value, Widget_t::parent_struct, and set_adjustment().

Referenced by add_my_combobox(), combobox_add_numeric_entrys(), mk_open_midi_keyboard(), open_file_dialog(), and save_file_dialog().

◆ combobox_add_numeric_entrys()

void combobox_add_numeric_entrys ( Widget_t wid,
int  imin,
int  imax 
)

combobox_add_numeric_items - add numeric items from imin to imax to wid

Parameters
*wid- pointer to the Widget_t combobox
*imin- the low number of the numeric items
*imax- the high number of the numeric items

Definition at line 189 of file xcombobox.c.

189 {
190 int i = imin;
191 int o = imax+1;
192 for (;i<o;i++) {
193 char s[32];
194 snprintf(s, 31, "%i",i);
195 combobox_add_entry(wid, s);
196 }
197}
void combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition xcombobox.c:175

References combobox_add_entry().

◆ combobox_delete_entrys()

void combobox_delete_entrys ( Widget_t combobox)

combobox_delete_entrys - free the list hold the combobox entrys

Parameters
*combobox- void pointer to the Widget_t combobox

Definition at line 67 of file xcombobox.c.

67 {
68 Widget_t * menu = combobox->childlist->childs[1];
69 Widget_t* view_port = menu->childlist->childs[0];
70 ComboBox_t *comboboxlist = (ComboBox_t*)view_port->parent_struct;
71 unsigned int j = 0;
72 for(; j<comboboxlist->list_size;j++) {
73 free(comboboxlist->list_names[j]);
74 comboboxlist->list_names[j] = NULL;
75 }
76 comboboxlist->list_size = 0;
77 set_adjustment(combobox->adj,0.0, 0.0, 0.0, -1.0,1.0, CL_ENUM);
78 set_adjustment(view_port->adj,0.0, 0.0, 0.0, -6.0,1.0, CL_ENUM);
79 set_adjustment(comboboxlist->slider->adj,0.0, 0.0, 0.0, 1.0,0.0085, CL_VIEWPORTSLIDER);
80}
@ CL_VIEWPORTSLIDER
Definition xadjustment.h:65

References Widget_t::adj, Widget_t::childlist, Childlist_t::childs, CL_ENUM, CL_VIEWPORTSLIDER, ComboBox_t::list_names, ComboBox_t::list_size, Widget_t::parent_struct, set_adjustment(), and ComboBox_t::slider.

◆ combobox_mem_free()

void combobox_mem_free ( void *  w_,
void *  user_data 
)

combobox_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

Definition at line 47 of file xcombobox.c.

47 {
48 Widget_t *w = (Widget_t*)w_;
49 ComboBox_t *comboboxlist = (ComboBox_t*)w->parent_struct;
50 unsigned int j = 0;
51 for(; j<comboboxlist->list_size;j++) {
52 free(comboboxlist->list_names[j]);
53 comboboxlist->list_names[j] = NULL;
54 }
55 free(comboboxlist->list_names);
56 free(comboboxlist);
57}

References ComboBox_t::list_names, ComboBox_t::list_size, and Widget_t::parent_struct.

Referenced by create_combobox_viewport().

◆ combobox_rename_entry()

void combobox_rename_entry ( Widget_t wid,
int  active,
const char *  label 
)

combobox_rename_entry - rename a entry in the combobox

Parameters
*wid- pointer to the Widget_t combobox
active- the entry to rename (int)
*label- new Label to show on the menu

Definition at line 34 of file xcombobox.c.

34 {
35 float value = (float)active;
36 if ((value>w->adj->max_value) || (value<w->adj->min_value)) return;
37 Widget_t * menu = w->childlist->childs[1];
38 Widget_t* view_port = menu->childlist->childs[0];
39 ComboBox_t *comboboxlist = (ComboBox_t*)view_port->parent_struct;
40 //fprintf(stderr,"%s %s\n", comboboxlist->list_names[active], label);
41 free(comboboxlist->list_names[active]);
42 comboboxlist->list_names[active] = NULL;
43 asprintf(&comboboxlist->list_names[active],"%s",label);
44 assert(comboboxlist->list_names != NULL);
45}
float min_value
Definition xadjustment.h:90

References Widget_t::adj, asprintf(), Widget_t::childlist, Childlist_t::childs, ComboBox_t::list_names, Adjustment_t::max_value, Adjustment_t::min_value, and Widget_t::parent_struct.

◆ combobox_set_active_entry()

void combobox_set_active_entry ( Widget_t w,
int  active 
)

combobox_set_active_entry - set the active combobox entry

Parameters
*w- void pointer to the Widget_t combobox
active- the active entry (int)

Definition at line 27 of file xcombobox.c.

27 {
28 float value = (float)active;
29 if (value>w->adj->max_value) value = w->adj->max_value;
30 else if (value<w->adj->min_value) value = w->adj->min_value;
31 adj_set_value(w->adj, value);
32}
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t

References Widget_t::adj, adj_set_value(), Adjustment_t::max_value, and Adjustment_t::min_value.

Referenced by add_my_combobox(), mk_open_midi_keyboard(), open_directory_dialog(), open_file_dialog(), and save_file_dialog().

◆ combobox_set_menu_size()

void combobox_set_menu_size ( Widget_t combobox,
int  v 
)

combobox_set_menu_size - set the number of entrys shown in the pop menu

Parameters
*combobox- pointer to the Widget_t combobox
v- the max entry count (int)

Definition at line 59 of file xcombobox.c.

59 {
60 Widget_t * menu = combobox->childlist->childs[1];
61 Widget_t* view_port = menu->childlist->childs[0];
62 ComboBox_t *comboboxlist = (ComboBox_t*)view_port->parent_struct;
63 comboboxlist->show_items = v;
64 _configure_combobox_menu(combobox, menu, comboboxlist->show_items, true);
65}
void _configure_combobox_menu(Widget_t *parent, Widget_t *menu, int elem, bool above)
_configure_combobox_menu - set final size and position of menu to a Widget_t

References _configure_combobox_menu(), Widget_t::childlist, Childlist_t::childs, Widget_t::parent_struct, and ComboBox_t::show_items.

◆ create_combobox_menu()

Widget_t * create_combobox_menu ( Widget_t parent,
int  height 
)

Definition at line 123 of file xcombobox.c.

123 {
124
125 int x1, y1;
126 os_translate_coords( parent, parent->widget, os_get_root_window(parent->app, IS_WIDGET), 0, 0, &x1, &y1);
127 Widget_t *wid = create_window(parent->app, os_get_root_window(parent->app, IS_WIDGET), x1, y1, 10, height);
128 Widget_t *viewport = create_combobox_viewport(wid, 6, 10, 5*height);
129 ComboBox_t *comboboxlist = (ComboBox_t*)viewport->parent_struct;
130 comboboxlist->combobox = parent;
131
133 os_set_transient_for_hint(parent, wid);
135 wid->flags |= IS_POPUP;
136 wid->scale.gravity = NONE;
137 childlist_add_child(parent->childlist, wid);
138
139 comboboxlist->slider = add_vslider(wid, "", 0, 0, 10, height);
140 comboboxlist->slider->func.expose_callback = _draw_combobox_menu_slider;
141 set_adjustment(comboboxlist->slider->adj_y,0.0, 0.0, 0.0, 1.0,0.0085, CL_VIEWPORTSLIDER);
142 comboboxlist->slider->adj = comboboxlist->slider->adj_y;
143 comboboxlist->slider->func.value_changed_callback = _set_combobox_menu_viewport;
144 comboboxlist->slider->scale.gravity = NORTHWEST;
145 comboboxlist->slider->flags &= ~USE_TRANSPARENCY;
146 comboboxlist->slider->flags |= NO_AUTOREPEAT | NO_PROPAGATE;
147 comboboxlist->slider->parent_struct = viewport;
148
149 return wid;
150}
Window widget
Definition xwidget.h:469
long long flags
Definition xwidget.h:461
void childlist_add_child(Childlist_t *childlist, Widget_t *child)
childlist_add_child - internal use to add a child to the Childlist_t You usually didn't need to cal...
Definition xchildlist.c:42
Widget_t * create_combobox_viewport(Widget_t *parent, int elem, int width, int height)
Definition xcombobox.c:96
void _set_combobox_menu_viewport(void *w_, void *user_data)
_set_combobox_menu_viewport - set the viewport position from slider state
void _draw_combobox_menu_slider(void *w_, void *user_data)
_draw_combobox_menu_slider - internal draw the combobox menu slider
void _draw_combobox_menu(void *w_, void *user_data)
_draw_combobox_menu - internal draw the combobox menu to the buffer
Widget_t * add_vslider(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_vslider - add a vertical slider to a Widget_t connect to func.value_changed_callback to implement...
Definition xslider.c:30
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void os_translate_coords(Widget_t *w, Window from_window, Window to_window, int from_x, int from_y, int *to_x, int *to_y)
os_translate_coords - get x,y related to destination Window
void os_set_transient_for_hint(Widget_t *parent, Widget_t *w)
os_set_ transient_for_hint - set a Widget_t transient to a other Widget_t only work on linux,...
void os_set_window_attrb(Widget_t *w)
os_set_window_attrb - set the attribute mask to a Widget_t only work on linux, stub on Windows
Widget_t * create_window(Xputty *app, Window win, int x, int y, int width, int height)
*create_window - create a Window You need to create as least minimun one Window to get started....
Definition xwidget.c:163
@ NONE
Definition xwidget.h:328
@ NORTHWEST
Definition xwidget.h:300
@ IS_WIDGET
Definition xwidget.h:388
@ NO_AUTOREPEAT
Definition xwidget.h:408
@ NO_PROPAGATE
Definition xwidget.h:416
@ IS_POPUP
Definition xwidget.h:392

References _draw_combobox_menu(), _draw_combobox_menu_slider(), _set_combobox_menu_viewport(), add_vslider(), Widget_t::adj, Widget_t::adj_y, Widget_t::app, Widget_t::childlist, childlist_add_child(), CL_VIEWPORTSLIDER, ComboBox_t::combobox, create_combobox_viewport(), create_window(), Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, IS_POPUP, IS_WIDGET, NO_AUTOREPEAT, NO_PROPAGATE, NONE, NORTHWEST, os_get_root_window(), os_set_transient_for_hint(), os_set_window_attrb(), os_translate_coords(), Widget_t::parent_struct, Widget_t::scale, set_adjustment(), ComboBox_t::slider, Func_t::value_changed_callback, and Widget_t::widget.

Referenced by add_combobox().

◆ create_combobox_viewport()

Widget_t * create_combobox_viewport ( Widget_t parent,
int  elem,
int  width,
int  height 
)

Definition at line 96 of file xcombobox.c.

96 {
97 Widget_t *wid = create_widget(parent->app, parent, 0, 0, width, height);
99 wid->scale.gravity = CENTER;
100 ComboBox_t *comboboxlist;
101 comboboxlist = (ComboBox_t*)malloc(sizeof(ComboBox_t));
102 comboboxlist->show_items = elem;
103 comboboxlist->prelight_item = 0;
104 comboboxlist->active_item = 0;
105 comboboxlist->list_names = NULL;
106 comboboxlist->list_size = 0;
107 wid->flags |= HAS_MEM;
108 wid->parent_struct = comboboxlist;
109 float max_value = -elem;
110 wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, max_value,1.0, CL_VIEWPORT);
111 wid->adj = wid->adj_y;
120 return wid;
121}
int active_item
Definition xcombobox.h:49
char ** list_names
Definition xcombobox.h:52
int prelight_item
Definition xcombobox.h:48
unsigned int list_size
Definition xcombobox.h:51
int show_items
Definition xcombobox.h:50
xevfunc configure_notify_callback
Definition xwidget.h:93
evfunc key_press_callback
Definition xwidget.h:104
xevfunc mem_free_callback
Definition xwidget.h:92
evfunc motion_callback
Definition xwidget.h:103
@ CL_VIEWPORT
Definition xadjustment.h:57
void combobox_mem_free(void *w_, void *user_data)
combobox_mem_free - release additional used memory when destroy the Widget_t
Definition xcombobox.c:47
void _leave_combobox(void *w_, void *user_data)
_leave_combobox - mouse pointer leave the combobox
void _draw_combobox_entrys(void *w_, void *user_data)
_draw_combobox_entrys - internal draw the combobox entrys to the buffer
void _combobox_motion(void *w_, void *xmotion_, void *user_data)
_combobox_motion - mouse pointer move in viewport
void _set_combobox_viewpoint(void *w_, void *user_data)
_set_combobox_viewpoint - set the slider state from viewport position
void _combobox_entry_released(void *w_, void *button_, void *user_data)
_combobox_entry_released - viewport entry released mouse button
void _reconfigure_combobox_viewport(void *w_, void *user_data)
_reconfigure_combobox_viewport - set slider scale and step to match viewport entrys
void _combobox_key_pressed(void *w_, void *xkey_, void *user_data)
_combobox_key_released - viewport entry released key
void os_set_input_mask(Widget_t *w)
os_set_input_mask - set the Event mask to a Widget_t only work on linux, stub on Windows
@ HAS_MEM
Definition xwidget.h:406

References _combobox_entry_released(), _combobox_key_pressed(), _combobox_motion(), _draw_combobox_entrys(), _leave_combobox(), _reconfigure_combobox_viewport(), _set_combobox_viewpoint(), ComboBox_t::active_item, add_adjustment(), Widget_t::adj, Func_t::adj_callback, Widget_t::adj_y, Widget_t::app, Func_t::button_release_callback, CENTER, CL_VIEWPORT, combobox_mem_free(), Func_t::configure_notify_callback, create_widget(), Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, HAS_MEM, Func_t::key_press_callback, Func_t::leave_callback, ComboBox_t::list_names, ComboBox_t::list_size, Func_t::mem_free_callback, Func_t::motion_callback, os_set_input_mask(), Widget_t::parent_struct, ComboBox_t::prelight_item, Widget_t::scale, and ComboBox_t::show_items.

Referenced by create_combobox_menu().

◆ pop_combobox_menu_show()

void pop_combobox_menu_show ( Widget_t parent,
Widget_t menu,
bool  above 
)

Definition at line 82 of file xcombobox.c.

82 {
83 if (!childlist_has_child(menu->childlist)) return;
84 Widget_t* view_port = menu->childlist->childs[0];
85 ComboBox_t *comboboxlist = (ComboBox_t*)view_port->parent_struct;
86 if (!comboboxlist->list_size) return;
87 _configure_combobox_menu(parent, menu, comboboxlist->show_items, above);
89 int err = os_grab_pointer(menu);
90 menu->app->hold_grab = menu;
91
92 if (err) debug_print("Error grap pointer\n");
93}
Widget_t * hold_grab
Definition xputty.h:238
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition xchildlist.c:89
int os_grab_pointer(Widget_t *w)
os_grab_pointer - grab the mouse pointer. Works only on linux
void pop_widget_show_all(Widget_t *w)
pop_widget_show_all - map/show popup widget with all it's childs
Definition xwidget.c:400

References _configure_combobox_menu(), Widget_t::app, Widget_t::childlist, childlist_has_child(), Childlist_t::childs, Xputty::hold_grab, ComboBox_t::list_size, os_grab_pointer(), Widget_t::parent_struct, pop_widget_show_all(), and ComboBox_t::show_items.

Referenced by _button_combobox_released(), and _combobox_button_released().