libxputty 0.1
Loading...
Searching...
No Matches
Data Structures | Functions
xcombobox.h File Reference

Go to the source code of this file.

Data Structures

struct  ComboBox_t
 ComboBox_t - struct to hold information for the combobox. More...
 

Functions

void pop_combobox_menu_show (Widget_t *parent, Widget_t *menu, bool above)
 
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_rename_entry (Widget_t *wid, int active, const char *label)
 combobox_rename_entry - rename a entry in 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
 
void combobox_set_active_entry (Widget_t *w, int active)
 combobox_set_active_entry - set the active combobox entry
 
void combobox_mem_free (void *w_, void *user_data)
 combobox_mem_free - release additional used memory when destroy the Widget_t
 
void combobox_delete_entrys (Widget_t *combobox)
 combobox_delete_entrys - free the list hold the combobox entrys
 
void combobox_set_menu_size (Widget_t *combobox, int v)
 combobox_set_menu_size - set the number of entrys shown in the pop menu
 

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}

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}
float min_value
Definition xadjustment.h:90
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.

◆ 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().