libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xsavefile-dialoge.c
Go to the documentation of this file.
1 /*
2  * 0BSD
3  *
4  * BSD Zero Clause License
5  *
6  * Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 
22 /*
23 #ifndef _GNU_SOURCE
24 #define _GNU_SOURCE 1
25 #endif
26 */
27 
28 #include <dirent.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <string.h>
33 #include <unistd.h>
34 
35 #include <libgen.h>
36 
37 #include "xfile-dialog.h"
38 #include "xmessage-dialog.h"
39 
40 
41 static void draw_window(void *w_, void* user_data) {
42  Widget_t *w = (Widget_t*)w_;
43  XWindowAttributes attrs;
44  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
45  int width = attrs.width;
46  int height = attrs.height;
47  if (attrs.map_state != IsViewable) return;
48 
49  cairo_rectangle(w->crb,0,0,width,height);
51  cairo_fill (w->crb);
52 
55  cairo_set_font_size (w->crb, 12.0);
56  cairo_move_to (w->crb, 20, 35);
57  cairo_show_text(w->crb, "Directory");
58  cairo_move_to (w->crb, 20, 85);
59  cairo_show_text(w->crb, "File");
60  cairo_move_to (w->crb, 20, 340);
61  cairo_show_text(w->crb, "Save as: ");
62  cairo_move_to (w->crb, 45, 380);
63  cairo_show_text(w->crb, "Show hidden files");
64  //cairo_move_to (w->crb, 60, 340);
65  //cairo_show_text(w->crb, w->label);
67 }
68 
69 static void button_quit_callback(void *w_, void* user_data) {
70  Widget_t *w = (Widget_t*)w_;
71  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
72 
73  if (w->flags & HAS_POINTER && !adj_get_value(w->adj)){
74  file_dialog->parent->func.dialog_callback(file_dialog->parent,NULL);
75  file_dialog->send_clear_func = false;
76  destroy_widget(file_dialog->w,file_dialog->w->app);
77  }
78 }
79 
80 static inline int clear(Widget_t *w) {
81  destroy_widget(w,w->app);
82  return 0;
83 }
84 
85 static inline int set_files(FileDialog *file_dialog) {
86  listview_set_list(file_dialog->ft,file_dialog->fp->file_names , (int)file_dialog->fp->file_counter);
87  int ret = 0;
88  int i = 0;
89  for (; i<(int)file_dialog->fp->file_counter; i++) {
90  if(file_dialog->fp->selected_file && strcmp(file_dialog->fp->file_names[i],
91  basename(file_dialog->fp->selected_file))==0 ) ret = i;
92  }
93  return ret;
94 }
95 
96 static void set_dirs(FileDialog *file_dialog) {
97  int i = 0;
98  for (; i<(int)file_dialog->fp->dir_counter; i++) {
99  combobox_add_entry(file_dialog->ct,file_dialog->fp->dir_names[i]);
100  }
101 }
102 
103 static void center_widget(Widget_t *wid, Widget_t *w) {
104  XMoveWindow(wid->app->dpy,w->widget,w->scale.init_x /
105  wid->scale.cscale_x,w->scale.init_y / wid->scale.cscale_y);
106  XResizeWindow (wid->app->dpy, w->widget, max(1,
107  w->scale.init_width / (wid->scale.cscale_x)),
108  max(1,w->scale.init_height / (wid->scale.cscale_y)));
109 }
110 
111 static void get_entry(Widget_t *w) {
112  Widget_t *p = (Widget_t*)w->parent;
113  FileDialog *file_dialog = (FileDialog *)p->parent_struct;
114  if (strlen( file_dialog->text_entry->input_label))
115  file_dialog->text_entry->input_label[strlen( file_dialog->text_entry->input_label)-1] = 0;
116  file_dialog->text_entry->label = file_dialog->text_entry->input_label;
117 }
118 
119 static void set_selected_file(FileDialog *file_dialog) {
120  Widget_t* menu = file_dialog->ct->childlist->childs[1];
121  Widget_t* view_port = menu->childlist->childs[0];
122  if(!childlist_has_child(view_port->childlist)) return ;
123  Widget_t *dir = view_port->childlist->childs[(int)adj_get_value(file_dialog->ct->adj)];
124  free(file_dialog->fp->selected_file);
125  file_dialog->fp->selected_file = NULL;
126  get_entry(file_dialog->text_entry);
127  if (strlen(file_dialog->text_entry->label)) {
128  asprintf(&file_dialog->fp->selected_file, "%s/%s",dir->label,
129  file_dialog->text_entry->label);
130  } else if(file_dialog->fp->file_counter ) {
131  asprintf(&file_dialog->fp->selected_file, "%s/%s",dir->label,
132  file_dialog->fp->file_names[(int)adj_get_value(file_dialog->ft->adj)]);
133  }
134 }
135 
136 static void file_released_callback(void *w_, void* user_data) {
137  Widget_t *w = (Widget_t*)w_;
138  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
139  set_selected_file(file_dialog);
140  if(file_dialog->fp->selected_file) {
141  file_dialog->w->label = file_dialog->fp->selected_file;
142  expose_widget(file_dialog->w);
143  }
144 }
145 
146 static void forward_key_press(void *w_, void *key_, void *user_data) {
147  Widget_t *w = (Widget_t*)w_;
148  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
149  file_dialog->text_entry->func.key_press_callback(file_dialog->text_entry, key_, user_data);
150 }
151 
152 static void reload_file_entrys(FileDialog *file_dialog) {
153  clear(file_dialog->ft);
154  fp_get_files(file_dialog->fp,file_dialog->fp->path, 0);
155  file_dialog->ft = add_listview(file_dialog->w, "", 20, 90, 620, 225);
156  file_dialog->ft->parent_struct = file_dialog;
157  file_dialog->ft->func.key_press_callback = forward_key_press;
158  int set_f = set_files(file_dialog);
159  center_widget(file_dialog->w,file_dialog->ft);
160  listview_set_active_entry(file_dialog->ft, set_f);
161  file_dialog->ft->func.value_changed_callback = file_released_callback;
162  widget_show_all(file_dialog->w);
163 }
164 
165 static void combo_response(void *w_, void* user_data) {
166  Widget_t *w = (Widget_t*)w_;
167  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
168  Widget_t* menu = w->childlist->childs[1];
169  Widget_t* view_port = menu->childlist->childs[0];
170  if(!childlist_has_child(view_port->childlist)) return ;
171  Widget_t *entry = view_port->childlist->childs[(int)adj_get_value(w->adj)];
172  free(file_dialog->fp->path);
173  file_dialog->fp->path = NULL;
174  asprintf(&file_dialog->fp->path, "%s",entry->label);
175  assert(file_dialog->fp->path != NULL);
176  reload_file_entrys(file_dialog);
177 }
178 
179 static void save_and_exit(void *w_) {
180  Widget_t *w = (Widget_t*)w_;
181  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
182  if(file_dialog->fp->selected_file) {
183  file_dialog->parent->func.dialog_callback(file_dialog->parent,&file_dialog->fp->selected_file);
184  file_dialog->send_clear_func = false;
185  destroy_widget(file_dialog->w,file_dialog->w->app);
186  } else {
187  open_message_dialog(w, INFO_BOX, "MAMBA INFO",
188  "Please enter a file name",NULL);
189  }
190 
191 }
192 
193 static void question_response(void *w_, void* user_data) {
194  if(user_data !=NULL) {
195  int response = *(int*)user_data;
196  if(response == 0) {
197  save_and_exit(w_);
198  }
199  }
200 }
201 
202 static void button_ok_callback(void *w_, void* user_data) {
203  Widget_t *w = (Widget_t*)w_;
204  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
205  if (w->flags & HAS_POINTER && !*(int*)user_data){
206  set_selected_file(file_dialog);
207  if( access(file_dialog->fp->selected_file, F_OK ) != -1 ) {
209  "File already exsist, would you overwrite it?",NULL);
210  w->func.dialog_callback = question_response;
211  } else {
212  save_and_exit(w_);
213  }
214  }
215 }
216 
217 static void dummy(void *w_, void* user_data) {
218 
219 }
220 
221 static void reload_all(FileDialog *file_dialog) {
222  file_dialog->ct->func.value_changed_callback = dummy;
223  file_dialog->ft->func.value_changed_callback = dummy;
224  Widget_t* menu = file_dialog->ct->childlist->childs[1];
225  Widget_t* view_port = menu->childlist->childs[0];
226  if(!childlist_has_child(view_port->childlist)) return ;
227  Widget_t *entry = view_port->childlist->childs[(int)adj_get_value(file_dialog->ct->adj)];
228  free(file_dialog->fp->path);
229  file_dialog->fp->path = NULL;
230  asprintf(&file_dialog->fp->path, "%s",entry->label);
231  assert(file_dialog->fp->path != NULL);
232  clear(file_dialog->ft);
233  clear(file_dialog->ct);
234  int ds = fp_get_files(file_dialog->fp,file_dialog->fp->path, 1);
235  file_dialog->ct = add_combobox(file_dialog->w, "", 20, 40, 550, 30);
236  center_widget(file_dialog->w,file_dialog->ct);
237  file_dialog->ct->parent_struct = file_dialog;
238  file_dialog->ct->func.value_changed_callback = combo_response;
239  file_dialog->ct->func.key_press_callback = forward_key_press;
240  file_dialog->ft = add_listview(file_dialog->w, "", 20, 90, 620, 225);
241  file_dialog->ft->parent_struct = file_dialog;
242  file_dialog->ft->func.key_press_callback = forward_key_press;
243  int set_f = set_files(file_dialog);
244  center_widget(file_dialog->w,file_dialog->ft);
245  set_dirs(file_dialog);
246  combobox_set_active_entry(file_dialog->ct, ds);
247  listview_set_active_entry(file_dialog->ft, set_f);
248  file_dialog->ft->func.value_changed_callback = file_released_callback;
249  widget_show_all(file_dialog->w);
250 }
251 
252 static void open_dir_callback(void *w_, void* user_data) {
253  Widget_t *w = (Widget_t*)w_;
254  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
255  if (w->flags & HAS_POINTER && !*(int*)user_data){
256  reload_all(file_dialog);
257  }
258 }
259 
260 static void button_hidden_callback(void *w_, void* user_data) {
261  Widget_t *w = (Widget_t*)w_;
262  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
263  if (w->flags & HAS_POINTER) {
264  file_dialog->fp->show_hidden = adj_get_value(w->adj) ? true : false;
265  reload_all(file_dialog);
266  }
267 }
268 
269 static void set_filter_callback(void *w_, void* user_data) {
270  Widget_t *w = (Widget_t*)w_;
271  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
272  if (file_dialog->fp->use_filter != (int)adj_get_value(w->adj)) {
273  file_dialog->fp->use_filter = (int)adj_get_value(w->adj);
274  Widget_t* menu = w->childlist->childs[1];
275  Widget_t* view_port = menu->childlist->childs[0];
276  if(!childlist_has_child(view_port->childlist)) return ;
277  Widget_t *entry = view_port->childlist->childs[(int)adj_get_value(w->adj)];
278  free(file_dialog->fp->filter);
279  file_dialog->fp->filter = NULL;
280  asprintf(&file_dialog->fp->filter, "%s",entry->label);
281  assert(file_dialog->fp->filter != NULL);
282 
283  reload_file_entrys(file_dialog);
284  }
285 }
286 
287 static void draw_entry(void *w_, void* user_data) {
288  Widget_t *w = (Widget_t*)w_;
289  if (!w) return;
290  XWindowAttributes attrs;
291  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
292  int width = attrs.width;
293  int height = attrs.height;
294  if (attrs.map_state != IsViewable) return;
295 
297  cairo_rectangle(w->cr,0,0,width,height);
298  cairo_fill_preserve (w->cr);
300  cairo_set_line_width(w->cr, 2.0);
301  cairo_stroke(w->cr);
302 
303  cairo_set_font_size (w->cr, 9.0);
304 
305  cairo_move_to (w->cr, 2, 9);
306  cairo_show_text(w->cr, " ");
307 }
308 
309 static void entry_add_text(void *w_, void *label_) {
310  Widget_t *w = (Widget_t*)w_;
311  if (!w) return;
312  char *label = (char*)label_;
313  if (!label) {
314  label = (char*)"";
315  }
316  draw_entry(w,NULL);
317  cairo_text_extents_t extents;
319  cairo_set_font_size (w->cr, 11.0);
320  if (strlen( w->input_label))
321  w->input_label[strlen( w->input_label)-1] = 0;
322  if (strlen( w->input_label)<30) {
323  if (strlen(label))
324  strcat( w->input_label, label);
325  }
326  w->label = w->input_label;
327  strcat( w->input_label, "|");
328  cairo_set_font_size (w->cr, 12.0);
329  cairo_text_extents(w->cr, w->input_label , &extents);
330 
331  cairo_move_to (w->cr, 2, 12.0+extents.height);
332  cairo_show_text(w->cr, w->input_label);
333 
334 }
335 
336 static void entry_clip(Widget_t *w) {
337  draw_entry(w,NULL);
338  cairo_text_extents_t extents;
340  cairo_set_font_size (w->cr, 11.0);
341 
342  // check for UTF 8 char
343  if (strlen( w->input_label)>=2) {
344  int i = strlen( w->input_label)-1;
345  int j = 0;
346  int u = 0;
347  for(;i>0;i--) {
348  if(IS_UTF8(w->input_label[i])) {
349  u++;
350  }
351  j++;
352  if (u == 1) break;
353  if (j>2) break;
354  }
355  if (!u) j =2;
356 
357  memset(&w->input_label[strlen( w->input_label)-(sizeof(char)*(j))],0,sizeof(char)*(j));
358  strcat( w->input_label, "|");
359  }
360  cairo_set_font_size (w->cr, 12.0);
361  cairo_text_extents(w->cr, w->input_label , &extents);
362 
363  cairo_move_to (w->cr, 2, 12.0+extents.height);
364  cairo_show_text(w->cr, w->input_label);
365 
366 }
367 
368 static void entry_get_text(void *w_, void *key_, void *user_data) {
369  Widget_t *w = (Widget_t*)w_;
370  if (!w) return;
371  XKeyEvent *key = (XKeyEvent*)key_;
372  if (!key) return;
373  int nk = key_mapping(w->app->dpy, key);
374  if (nk == 11) {
375  entry_clip(w);
376  } else {
377  Status status;
378  KeySym keysym;
379  char buf[32];
380  Xutf8LookupString(w->xic, key, buf, sizeof(buf) - 1, &keysym, &status);
381  if(status == XLookupChars || status == XLookupBoth){
382  entry_add_text(w, buf);
383  }
384  }
385 }
386 
387 static void fd_mem_free(void *w_, void* user_data) {
388  Widget_t *w = (Widget_t*)w_;
389  FileDialog *file_dialog = (FileDialog *)w->parent_struct;
390  if(file_dialog->icon) {
391  XFreePixmap(w->app->dpy, (*file_dialog->icon));
392  file_dialog->icon = NULL;
393  }
394  if(file_dialog->send_clear_func)
395  file_dialog->parent->func.dialog_callback(file_dialog->parent,NULL);
396  fp_free(file_dialog->fp);
397  free(file_dialog->fp);
398  free(file_dialog);
399 }
400 
401 Widget_t *save_file_dialog(Widget_t *w, const char *path, const char *filter) {
402  FileDialog *file_dialog = (FileDialog*)malloc(sizeof(FileDialog));
403 
404  file_dialog->fp = (FilePicker*)malloc(sizeof(FilePicker));
405  fp_init(file_dialog->fp, (path) ? path : "/");
406  file_dialog->parent = w;
407  file_dialog->send_clear_func = true;
408  file_dialog->icon = NULL;
409 
410  file_dialog->w = create_window(w->app, DefaultRootWindow(w->app->dpy), 0, 0, 660, 420);
411  file_dialog->w->flags |= HAS_MEM;
412  file_dialog->w->parent_struct = file_dialog;
413  widget_set_title(file_dialog->w, "File Save");
414  file_dialog->w->func.expose_callback = draw_window;
415  file_dialog->w->func.key_press_callback = forward_key_press;
416  file_dialog->w->func.mem_free_callback = fd_mem_free;
417  widget_set_icon_from_png(file_dialog->w,file_dialog->icon,LDVAR(directory_png));
418 
419  file_dialog->ct = add_combobox(file_dialog->w, "", 20, 40, 550, 30);
420  file_dialog->ct->parent_struct = file_dialog;
421  file_dialog->ct->func.value_changed_callback = combo_response;
422  file_dialog->ct->func.key_press_callback = forward_key_press;
423 
424  file_dialog->sel_dir = add_button(file_dialog->w, "Open", 580, 40, 60, 30);
425  file_dialog->sel_dir->parent_struct = file_dialog;
426  file_dialog->sel_dir->scale.gravity = CENTER;
427  add_tooltip(file_dialog->sel_dir,"Open sub-directory's");
428  file_dialog->sel_dir->func.value_changed_callback = open_dir_callback;
429  file_dialog->sel_dir->func.key_press_callback = forward_key_press;
430 
431  file_dialog->ft = add_listview(file_dialog->w, "", 20, 90, 620, 225);
432  file_dialog->ft->parent_struct = file_dialog;
433  file_dialog->ft->func.key_press_callback = forward_key_press;
434 
435  int ds = fp_get_files(file_dialog->fp,file_dialog->fp->path, 1);
436  int set_f = set_files(file_dialog);
437  set_dirs(file_dialog);
438  combobox_set_active_entry(file_dialog->ct, ds);
439  listview_set_active_entry(file_dialog->ft, set_f);
440  file_dialog->ft->func.value_changed_callback = file_released_callback;
441 
442  file_dialog->text_entry = create_widget(file_dialog->w->app, file_dialog->w, 80, 320, 200, 30);
443  memset(file_dialog->text_entry->input_label, 0, 32 * (sizeof file_dialog->text_entry->input_label[0]) );
444  file_dialog->text_entry->func.expose_callback = entry_add_text;
445  file_dialog->text_entry->func.key_press_callback = entry_get_text;
446  file_dialog->text_entry->flags &= ~USE_TRANSPARENCY;
447  file_dialog->text_entry->scale.gravity = CENTER;
448 
449  file_dialog->w_quit = add_button(file_dialog->w, "Quit", 580, 350, 60, 60);
450  file_dialog->w_quit->parent_struct = file_dialog;
451  file_dialog->w_quit->scale.gravity = CENTER;
452  add_tooltip(file_dialog->w_quit,"Exit File Saver");
453  file_dialog->w_quit->func.value_changed_callback = button_quit_callback;
454  file_dialog->w_quit->func.key_press_callback = forward_key_press;
455 
456  file_dialog->w_okay = add_button(file_dialog->w, "Save", 510, 350, 60, 60);
457  file_dialog->w_okay->parent_struct = file_dialog;
458  file_dialog->w_okay->scale.gravity = CENTER;
459  add_tooltip(file_dialog->w_okay,"Save as selected file");
460  file_dialog->w_okay->func.value_changed_callback = button_ok_callback;
461  file_dialog->w_okay->func.key_press_callback = forward_key_press;
462 
463  file_dialog->set_filter = add_combobox(file_dialog->w, "", 360, 355, 120, 30);
464  file_dialog->set_filter->parent_struct = file_dialog;
465  combobox_add_entry(file_dialog->set_filter,"all");
466  combobox_add_entry(file_dialog->set_filter,"application");
467  combobox_add_entry(file_dialog->set_filter,"audio");
468  combobox_add_entry(file_dialog->set_filter,"font");
469  combobox_add_entry(file_dialog->set_filter,"image");
470  combobox_add_entry(file_dialog->set_filter,"text");
471  combobox_add_entry(file_dialog->set_filter,"video");
472  combobox_add_entry(file_dialog->set_filter,"x-content");
473  if(filter !=NULL && strlen(filter))
474  combobox_add_entry(file_dialog->set_filter,filter);
475  combobox_set_active_entry(file_dialog->set_filter, 0);
476  file_dialog->set_filter->func.value_changed_callback = set_filter_callback;
477  if(filter !=NULL && strlen(filter))
478  combobox_set_active_entry(file_dialog->set_filter, 8);
479  add_tooltip(file_dialog->set_filter->childlist->childs[0], "File filter type");
480 
481  file_dialog->w_hidden = add_check_button(file_dialog->w, "", 20, 365, 20, 20);
482  file_dialog->w_hidden->parent_struct = file_dialog;
483  file_dialog->w_hidden->scale.gravity = CENTER;
484  add_tooltip(file_dialog->w_hidden,"Show hidden files and folders");
485  file_dialog->w_hidden->func.value_changed_callback = button_hidden_callback;
486 
487  widget_show_all(file_dialog->w);
488  return file_dialog->w;
489 }
490 
491 /*---------------------------------------------------------------------
492 -----------------------------------------------------------------------
493  add_file_button
494 -----------------------------------------------------------------------
495 ----------------------------------------------------------------------*/
496 
497 static void fdialog_response(void *w_, void* user_data) {
498  Widget_t *w = (Widget_t*)w_;
499  FileButton *filebutton = (FileButton *)w->parent_struct;
500  if(user_data !=NULL) {
501  char *tmp = strdup(*(const char**)user_data);
502  free(filebutton->last_path);
503  filebutton->last_path = NULL;
504  filebutton->last_path = strdup(dirname(tmp));
505  filebutton->path = filebutton->last_path;
506  free(tmp);
507  }
508  w->func.user_callback(w,user_data);
509  filebutton->is_active = false;
510  adj_set_value(w->adj,0.0);
511 }
512 
513 static void fbutton_callback(void *w_, void* user_data) {
514  Widget_t *w = (Widget_t*)w_;
515  FileButton *filebutton = (FileButton *)w->parent_struct;
516  if (w->flags & HAS_POINTER && adj_get_value(w->adj)){
517  filebutton->w = save_file_dialog(w,filebutton->path,filebutton->filter);
518  filebutton->is_active = true;
519  } else if (w->flags & HAS_POINTER && !adj_get_value(w->adj)){
520  if(filebutton->is_active)
521  destroy_widget(filebutton->w,w->app);
522  }
523 }
524 
525 static void fbutton_mem_free(void *w_, void* user_data) {
526  Widget_t *w = (Widget_t*)w_;
527  FileButton *filebutton = (FileButton *)w->parent_struct;
528  free(filebutton->last_path);
529  filebutton->last_path = NULL;
530  free(filebutton);
531  filebutton = NULL;
532 }
533 
534 Widget_t *add_save_file_button(Widget_t *parent, int x, int y, int width, int height,
535  const char *path, const char *filter) {
536  FileButton *filebutton = (FileButton*)malloc(sizeof(FileButton));
537  filebutton->path = path;
538  filebutton->filter = filter;
539  filebutton->last_path = NULL;
540  filebutton->w = NULL;
541  filebutton->is_active = false;
542  Widget_t *fbutton = add_image_toggle_button(parent, "", x, y, width, height);
543  fbutton->parent_struct = filebutton;
544  fbutton->flags |= HAS_MEM;
545  widget_get_png(fbutton, LDVAR(directory_open_png));
546  fbutton->scale.gravity = CENTER;
547  fbutton->func.mem_free_callback = fbutton_mem_free;
548  fbutton->func.value_changed_callback = fbutton_callback;
549  fbutton->func.dialog_callback = fdialog_response;
550  return fbutton;
551 }
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
FileDialog::w_quit
Widget_t * w_quit
Definition: xfile-dialog.h:40
FileButton::last_path
char * last_path
Definition: xfile-dialog.h:53
fp_get_files
int fp_get_files(FilePicker *filepicker, char *path, int get_dirs)
fp_get_files - fill file_names and dir_names with the results from readdir path
Definition: xfilepicker.c:131
expose_widget
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition: xwidget.c:461
QUESTION_BOX
@ QUESTION_BOX
Definition: xmessage-dialog.h:36
FilePicker::selected_file
char * selected_file
Definition: xfilepicker.h:68
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
Resize_t::init_x
int init_x
Definition: xwidget.h:194
widget_set_title
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition: xwidget.c:387
FileDialog::ct
Widget_t * ct
Definition: xfile-dialog.h:38
fp_free
void fp_free(FilePicker *filepicker)
fp_free - release all memory used by the filepicker
Definition: xfilepicker.c:176
FilePicker::path
char * path
Definition: xfilepicker.h:67
Resize_t::cscale_y
float cscale_y
Definition: xwidget.h:208
FileButton
Definition: xfile-dialog.h:51
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
FilePicker::file_names
char ** file_names
Definition: xfilepicker.h:69
FileDialog::w_hidden
Widget_t * w_hidden
Definition: xfile-dialog.h:42
Childlist_t::childs
Widget_t ** childs
Definition: xchildlist.h:51
combobox_add_entry
Widget_t * combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Definition: xcombobox.c:56
FileDialog::sel_dir
Widget_t * sel_dir
Definition: xfile-dialog.h:43
widget_set_scale
void widget_set_scale(Widget_t *w)
widget_set_scale - set scaling mode to scale a image surface to the size of the Widget_t surface
Definition: xwidget.c:141
create_widget
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:268
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
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
CENTER
@ CENTER
Definition: xwidget.h:165
HAS_POINTER
@ HAS_POINTER
Definition: xwidget.h:247
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
listview_set_active_entry
void listview_set_active_entry(Widget_t *w, int active)
listview_set_active_entry - set the active listview entry
Definition: xlistview.c:27
xmessage-dialog.h
FileDialog
Definition: xfile-dialog.h:35
Func_t::user_callback
xevfunc user_callback
Definition: xwidget.h:86
Widget_t::flags
long long flags
Definition: xwidget.h:324
FilePicker::filter
char * filter
Definition: xfilepicker.h:66
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
FileDialog::fp
FilePicker * fp
Definition: xfile-dialog.h:47
add_image_toggle_button
Widget_t * add_image_toggle_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_image_toggle_button - add a button to a Widget_t connect to func.value_changed_callback to implem...
Definition: xbutton.c:73
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
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
BACKGROUND_
@ BACKGROUND_
Definition: xcolor.h:53
add_save_file_button
Widget_t * add_save_file_button(Widget_t *parent, int x, int y, int width, int height, const char *path, const char *filter)
add_save_file_button - add a pre-defined button which will pop-up a file dialog when pressed....
Definition: xsavefile-dialoge.c:534
Func_t::key_press_callback
evfunc key_press_callback
Definition: xwidget.h:96
FileButton::w
Widget_t * w
Definition: xfile-dialog.h:52
fp_init
void fp_init(FilePicker *filepicker, const char *path)
fp_init - set default values used by the filepicker
Definition: xfilepicker.c:184
FilePicker
Definition: xfilepicker.h:61
FileDialog::icon
Pixmap * icon
Definition: xfile-dialog.h:46
FileButton::filter
const char * filter
Definition: xfile-dialog.h:55
FileDialog::w_okay
Widget_t * w_okay
Definition: xfile-dialog.h:41
HAS_MEM
@ HAS_MEM
Definition: xwidget.h:251
Widget_t::app
Xputty * app
Definition: xwidget.h:300
FilePicker::file_counter
unsigned int file_counter
Definition: xfilepicker.h:64
Resize_t::init_y
int init_y
Definition: xwidget.h:196
Xputty::dpy
Display * dpy
Definition: xputty.h:181
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
FileButton::is_active
bool is_active
Definition: xfile-dialog.h:56
FilePicker::show_hidden
bool show_hidden
Definition: xfilepicker.h:63
widget_get_png
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
Definition: xpngloader.c:41
combobox_set_active_entry
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
Definition: xcombobox.c:25
FileDialog::w
Widget_t * w
Definition: xfile-dialog.h:37
INFO_BOX
@ INFO_BOX
Definition: xmessage-dialog.h:33
asprintf
int asprintf(char *strp[], const char *fmt,...)
Definition: xasprintf.c:36
FileButton::path
const char * path
Definition: xfile-dialog.h:54
FileDialog::ft
Widget_t * ft
Definition: xfile-dialog.h:39
Widget_t::widget
Window widget
Definition: xwidget.h:302
XColor_t::selected
Colors selected
Definition: xcolor.h:91
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
FileDialog::set_filter
Widget_t * set_filter
Definition: xfile-dialog.h:44
FileDialog::send_clear_func
bool send_clear_func
Definition: xfile-dialog.h:48
LDVAR
#define LDVAR(NAME)
Definition: xpngloader.h:71
widget_reset_scale
void widget_reset_scale(Widget_t *w)
widget_reset_scale - used to reset scaling mode after a image surface is drawn to the Widget_t surfac...
Definition: xwidget.c:137
Widget_t::xic
XIC xic
Definition: xwidget.h:338
save_file_dialog
Widget_t * save_file_dialog(Widget_t *w, const char *path, const char *filter)
save_file_dialog - open a non blocking dialog window, to select a file. The path to open the file-sel...
Definition: xsavefile-dialoge.c:401
FilePicker::use_filter
int use_filter
Definition: xfilepicker.h:62
destroy_widget
void destroy_widget(Widget_t *w, Xputty *main)
destroy_widget - destroy a widget When a Widget_t receive a destroy_widget() call,...
Definition: xwidget.c:71
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
open_message_dialog
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 ...
Definition: xmessage-dialog.c:322
FilePicker::dir_counter
unsigned int dir_counter
Definition: xfilepicker.h:65
Widget_t::childlist
Childlist_t * childlist
Definition: xwidget.h:336
add_check_button
Widget_t * add_check_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_check_button - add a button to a Widget_t connect to func.value_changed_callback to implement you...
Definition: xbutton.c:105
create_window
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:145
FileDialog::text_entry
Widget_t * text_entry
Definition: xfile-dialog.h:45
IS_UTF8
#define IS_UTF8(c)
IS_UTF8 - check if a char contain UTF 8 formated signs.
Definition: xputty.h:99
Widget_t::input_label
char input_label[32]
Definition: xwidget.h:328
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
FileDialog::parent
Widget_t * parent
Definition: xfile-dialog.h:36
Widget_t::func
Func_t func
Definition: xwidget.h:310
listview_set_list
void listview_set_list(Widget_t *listview, char **list, int list_size)
listview_set_list - set a list to a listview Widget_t
Definition: xlistview.c:85
widget_set_icon_from_png
void widget_set_icon_from_png(Widget_t *w, Pixmap *icon_, 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 ...
Definition: xpngloader.c:124
add_listview
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
Definition: xlistview.c:64
xfile-dialog.h
Xputty::color_scheme
XColor_t * color_scheme
Definition: xputty.h:183
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
Definition: xcombobox.c:32
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
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
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
Widget_t::label
const char * label
Definition: xwidget.h:326
Func_t::value_changed_callback
xevfunc value_changed_callback
Definition: xwidget.h:85
add_tooltip
void add_tooltip(Widget_t *w, const char *label)
add_tooltip - add a tooltip to Widget_t
Definition: xtooltip.c:41
add_button
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
Resize_t::cscale_x
float cscale_x
Definition: xwidget.h:206
Resize_t::init_width
int init_width
Definition: xwidget.h:198
XColor_t::normal
Colors normal
Definition: xcolor.h:89
Resize_t::init_height
int init_height
Definition: xwidget.h:200
widget_show_all
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition: xwidget.c:405
Func_t::dialog_callback
xevfunc dialog_callback
Definition: xwidget.h:91
FilePicker::dir_names
char ** dir_names
Definition: xfilepicker.h:70