44static void combo_response(
void *w_,
void* user_data);
45static void set_selected_file(
FileDialog *file_dialog);
47static void draw_window(
void *w_,
void* user_data) {
52 int width = metrics.
width;
53 int height = metrics.
height;
56 cairo_rectangle(w->crb,0,0,width,height);
62 cairo_set_font_size (w->crb, 12.0);
63 cairo_move_to (w->crb, 20, 35);
64 cairo_show_text(w->crb, _(
"Base Directory"));
65 cairo_move_to (w->crb, 20, 85);
66 cairo_show_text(w->crb, _(
"Places"));
67 cairo_move_to (w->crb, 130, 85);
68 cairo_show_text(w->crb, _(
"Entries"));
69 cairo_move_to (w->crb, 20, 330-w->scale.scale_y);
70 cairo_show_text(w->crb, _(
"Load: "));
71 cairo_move_to (w->crb, 45, 360-w->scale.scale_y);
72 cairo_show_text(w->crb, _(
"Show hidden files"));
73 cairo_move_to (w->crb, 45, 390-w->scale.scale_y);
74 cairo_show_text(w->crb, _(
"List view"));
77 cairo_move_to (w->crb, 60, 330-w->scale.scale_y);
78 cairo_show_text(w->crb, file);
83 cairo_set_source_surface (w->crb, w->image, 180, 332-w->scale.scale_y);
88static void draw_fd_hslider(
void *w_,
void* user_data) {
91 int width = w->
width-2;
93 float center = (float)height/2;
98 cairo_move_to (w->
crb, 0.0, center);
99 cairo_line_to(w->
crb,width,center);
100 cairo_set_line_width(w->
crb,center/10);
101 cairo_stroke(w->
crb);
104 cairo_rectangle(w->
crb, (width-height)*sliderstate,0,height, height);
106 cairo_new_path (w->
crb);
109 cairo_set_line_width(w->
crb,3);
110 cairo_move_to (w->
crb,((width-height)*sliderstate)+center, 0.0);
111 cairo_line_to(w->
crb,((width-height)*sliderstate)+center,height);
112 cairo_stroke(w->
crb);
113 cairo_new_path (w->
crb);
116static void button_quit_callback(
void *w_,
void* user_data) {
121 file_dialog->parent->func.dialog_callback(file_dialog->parent,NULL);
122 file_dialog->send_clear_func =
false;
127static inline int set_files(
FileDialog *file_dialog) {
143static void set_dirs(
FileDialog *file_dialog) {
154static void file_released_b_callback(
void *w_,
void *button_,
void* user_data) {
158 if(xbutton->
button == Button1) {
159 set_selected_file(file_dialog);
167static void null_callback(
void *w,
void* user_data) {
171static void reload_from_dir(
FileDialog *file_dialog) {
172 assert(file_dialog->
fp->
path != NULL);
180 int set_f = set_files(file_dialog);
181 set_dirs(file_dialog);
206static void show_preview(
FileDialog *file_dialog,
const char* file_name) {
208 cairo_surface_t *getpng = cairo_image_surface_create_from_png (file_name);
213 double x = (double)width_t/(
double)width;
214 double y = (double)height_t/(
double)height;
215 if (width > 20*height)
216 x = y = (double)width_t/(
double)height;
217 cairo_surface_destroy(w->
image);
221 CAIRO_CONTENT_COLOR_ALPHA, width_t, height_t);
222 cairo_t *cri = cairo_create (w->
image);
223 cairo_scale(cri, x,y);
224 cairo_set_source_surface (cri, getpng,0,0);
226 cairo_surface_destroy(getpng);
231static void show_svg_preview(
FileDialog *file_dialog,
const char* file_name) {
237static void set_selected_file(
FileDialog *file_dialog) {
243 reload_from_dir(file_dialog);
264 }
else if (file_dialog->
w->
image) {
265 cairo_surface_destroy(file_dialog->
w->
image);
266 file_dialog->
w->
image = NULL;
271static void reload_file_entrys(
FileDialog *file_dialog) {
280 int set_f = set_files(file_dialog);
297static void combo_response(
void *w_,
void* user_data) {
304 free(file_dialog->
fp->
path);
305 file_dialog->
fp->
path = NULL;
307 assert(file_dialog->
fp->
path != NULL);
308 reload_from_dir(file_dialog);
311static void button_ok_callback(
void *w_,
void* user_data) {
327static void file_double_click_callback(
void *w_,
void *button,
void* user_data) {
331 set_selected_file(file_dialog);
344static void reload_all(
FileDialog *file_dialog) {
349 free(file_dialog->
fp->
path);
350 file_dialog->
fp->
path = NULL;
352 assert(file_dialog->
fp->
path != NULL);
360 int set_f = set_files(file_dialog);
361 set_dirs(file_dialog);
379static void set_scale_factor_callback(
void *w_,
void* user_data) {
388static void open_dir_callback(
void *w_,
void* user_data) {
392 reload_from_dir(file_dialog);
396static void button_hidden_callback(
void *w_,
void* user_data) {
401 reload_all(file_dialog);
405static void button_view_callback(
void *w_,
void* user_data) {
420 int set_f = set_files(file_dialog);
437 int set_f = set_files(file_dialog);
450static void set_filter_callback(
void *w_,
void* user_data) {
462 assert(file_dialog->
fp->
filter != NULL);
464 reload_file_entrys(file_dialog);
468static void fd_mem_free(
void *w_,
void* user_data) {
474 free(file_dialog->
fp);
489static int starts_with(
const char *restrict
string,
const char *restrict prefix) {
492 if(*prefix++ != *
string++)
499static int strremove(
char *
string,
const char *restrict find){
500 if(strstr(
string, find) == NULL)
return 0;
501 char *temporaryString = malloc(strlen(strstr(
string, find) + strlen(find)) + 1);
502 strcpy(temporaryString, strstr(
string, find) + strlen(find));
503 char* rep = strstr(
string, find);
506 strcat(
string, temporaryString);
507 free(temporaryString);
511static void parse_xdg_dirs(
FileDialog *file_dialog) {
514 file_dialog->
home_dir = getenv(
"HOME");
515 if (file_dialog->
home_dir == NULL) {
516 file_dialog->
home_dir = getpwuid(getuid())->pw_dir;
518 if (file_dialog->
home_dir == NULL)
return;
519 sprintf(xdg_dir,
"%s/.config/user-dirs.dirs", file_dialog->
home_dir);
525 fp = fopen(xdg_dir,
"r");
527 while ((read = getline(&line, &len, fp)) != -1) {
528 if(starts_with(line,
"XDG_")) {
547 while ((read = getline(&line, &len, fp)) != -1) {
548 if(starts_with(line,
"XDG_")) {
550 char* xdg = strstr(line,
"$HOME/");
552 xdg = strrchr(line,
'/')+1;
553 char* path = strstr(line,
"/");
554 char* re = strstr(path,
"\"");
558 }
else if (!strremove(xdg,
"$HOME/")) {
561 char* rep = strstr(xdg,
"\"");
562 if (rep) *rep =
'\0';
578static void xdg_dir_select_callback(
void *w_,
void *button,
void* user_data) {
582 free(file_dialog->
fp->
path);
583 file_dialog->
fp->
path = NULL;
585 assert(file_dialog->
fp->
path != NULL);
586 reload_from_dir(file_dialog);
589static void add_xdg_dirs(
FileDialog *file_dialog) {
608 parse_xdg_dirs(file_dialog);
611 if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) {
613 }
else if (stat(file_dialog->
home_dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
619 DWORD attr = GetFileAttributes(path);
620 if (attr&FILE_ATTRIBUTE_DIRECTORY) {
633 XSizeHints* win_size_hints;
634 win_size_hints = XAllocSizeHints();
635 win_size_hints->flags = PMinSize|PBaseSize|PMaxSize|PWinGravity;
636 win_size_hints->min_width = 660;
637 win_size_hints->min_height = 415;
638 win_size_hints->base_width = 660;
639 win_size_hints->base_height = 415;
640 win_size_hints->max_width = 960;
641 win_size_hints->max_height = 865;
642 win_size_hints->win_gravity = CenterGravity;
643 XSetWMNormalHints(file_dialog->
w->
app->
dpy, file_dialog->
w->
widget, win_size_hints);
644 XFree(win_size_hints);
685 int set_f = set_files(file_dialog);
686 set_dirs(file_dialog);
696 add_xdg_dirs(file_dialog);
724 if(filter !=NULL && strlen(filter))
728 if(filter !=NULL && strlen(filter))
747 return file_dialog->
w;
756static void fdialog_response(
void *w_,
void* user_data) {
759 if(user_data !=NULL) {
760 char *tmp = strdup(*(
const char**)user_data);
761 free(filebutton->last_path);
762 filebutton->last_path = NULL;
763 filebutton->last_path = strdup(dirname(tmp));
764 filebutton->path = filebutton->last_path;
768 filebutton->is_active =
false;
772static void fbutton_callback(
void *w_,
void* user_data) {
778 Atom wmStateAbove = XInternAtom(w->
app->
dpy,
"_NET_WM_STATE_ABOVE", 1 );
779 Atom wmNetWmState = XInternAtom(w->
app->
dpy,
"_NET_WM_STATE", 1 );
780 XChangeProperty(w->
app->
dpy, filebutton->w->widget, wmNetWmState, XA_ATOM, 32,
781 PropModeReplace, (
unsigned char *) &wmStateAbove, 1);
783 filebutton->is_active =
true;
785 if(filebutton->is_active)
790static void fbutton_mem_free(
void *w_,
void* user_data) {
793 free(filebutton->last_path);
794 filebutton->last_path = NULL;
800 const char *path,
const char *filter) {
802 filebutton->
path = path;
803 filebutton->
filter = filter;
805 filebutton->
w = NULL;
ComboBox_t - struct to hold information for the combobox.
unsigned int xdg_dir_counter
char ** xdg_user_dirs_path
unsigned int file_counter
evfunc button_release_callback
evfunc double_click_callback
xevfunc value_changed_callback
xevfunc mem_free_callback
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
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
float adj_get_state(Adjustment_t *adj)
adj_get_state - get the current state of the Adjustment_t
int asprintf(char *strp[], const char *fmt,...)
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
void combobox_delete_entrys(Widget_t *combobox)
combobox_delete_entrys - free the list hold the combobox entrys
void combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
Widget_t * add_file_button(Widget_t *parent, int x, int y, int width, int height, const char *path, const char *filter)
add_file_button - add a pre-defined button which will pop-up a file dialog when pressed....
Widget_t * open_file_dialog(Widget_t *w, const char *path, const char *filter)
open_file_dialog - open a non blocking dialog window, to select a file. The path to open the file-sel...
void fp_init(FilePicker *filepicker, const char *path)
fp_init - set default values used by the filepicker
int fp_get_files(FilePicker *filepicker, char *path, int get_dirs, int get_files)
fp_get_files - fill file_names and dir_names with the results from readdir path
void fp_free(FilePicker *filepicker)
fp_free - release all memory used by the filepicker
void listview_remove_list(Widget_t *listview)
listview_remove_list - remove the list from a listview Widget_t
Widget_t * add_listview(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_label - add a listview to a Widget_t
void listview_set_check_dir(Widget_t *listview, int set)
listview_set_check_dir - set optional check if list item is a directory
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
void listview_unset_active_entry(Widget_t *w)
listview_unset_active_entry - unset the active listview entry
void listview_set_list(Widget_t *listview, char **list, int list_size)
listview_set_list - set a list to a listview Widget_t
Widget_t * open_message_dialog(Widget_t *w, int style, const char *title, const char *message, const char *choices)
open_message_dialog - open a non blocking dialog window, lines in message chould be separated by the ...
void multi_listview_set_item_size(Widget_t *listview, float set)
multi_listview_set_item_size - set size for the icons in the viewport
void multi_listview_set_active_entry(Widget_t *w, int active)
multi_listview_set_active_entry - set the active listview entry
void multi_listview_unset_active_entry(Widget_t *w)
multi_listview_unset_active_entry - unset the active listview entry
Widget_t * add_multi_listview(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_label - add a listview to a Widget_t
void multi_listview_set_list(Widget_t *listview, char **list, int list_size)
multi_listview_set_multi_list - set a list to a listview Widget_t
void multi_listview_set_check_dir(Widget_t *listview, int set)
multi_listview_set_check_dir - set optional check if list item is a directory
void multi_listview_remove_list(Widget_t *listview)
multi_listview_remove_list - remove the list from a listview Widget_t
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
void widget_set_icon_from_png(Widget_t *w, const unsigned char *name)
widget_set_icon_from_png - set icon image from png binary to Widget_t those icon will be used in the ...
Widget_t * add_hslider(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_hslider - add a horizontal slider to a Widget_t connect to func.value_changed_callback to impleme...
void widget_get_scaled_svg_from_file(Widget_t *w, const char *filename, int width_t, int height_t)
widget_get_scaled_svg_from_file - read svg into Widget_t xlib surface