libxputty 0.1
Loading...
Searching...
No Matches
Functions
xmessage-dialog.c File Reference

Go to the source code of this file.

Functions

void hyperlink_pressed (void *w_, void *button_, void *user_data)
 
void draw_hyperlink (void *w_, void *user_data)
 
Widget_tcreate_hyperlink (Widget_t *w, char *label, int x, int y, int width, int height)
 
void radio_box_set_active (Widget_t *w)
 
Widget_topen_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 character "|" choices for the SELECTION_BOX should be separated as well with the character "|". message and/or choices could be NULL when not needed. To fetch the response of a dialog, connect to the dialog_callback supported "styles" been
INFO_BOX - a message dialog display a info text
WARNING_BOX - a message dialog display a warning
ERROR_BOX - a message dialog display a error message
QUESTION_BOX - a no/yes dialog message
SELECTION_BOX - a dialog to select between multiple options
ENTRY_BOX - a dialog to get text input
 

Function Documentation

◆ create_hyperlink()

Widget_t * create_hyperlink ( Widget_t w,
char *  label,
int  x,
int  y,
int  width,
int  height 
)

Definition at line 57 of file xmessage-dialog.c.

58 {
59 Widget_t *wid = create_widget(w->app, w, x, y, width, height);
60 wid->label = label;
61 wid->scale.gravity = ASPECT;
62#ifdef __linux__
63 Cursor c = XCreateFontCursor(wid->app->dpy, XC_hand2);
64 XDefineCursor (wid->app->dpy, wid->widget, c);
65 XFreeCursor(wid->app->dpy, c);
66#endif
71 return wid;
72}
xevfunc expose_callback
Definition xwidget.h:85
xevfunc leave_callback
Definition xwidget.h:88
xevfunc enter_callback
Definition xwidget.h:87
evfunc button_press_callback
Definition xwidget.h:100
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
Window widget
Definition xwidget.h:469
const char * label
Definition xwidget.h:463
Func_t func
Definition xwidget.h:481
Xputty * app
Definition xwidget.h:465
Display * dpy
Definition xputty.h:232
void hyperlink_pressed(void *w_, void *button_, void *user_data)
void draw_hyperlink(void *w_, void *user_data)
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
@ ASPECT
Definition xwidget.h:322
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:449

References Widget_t::app, ASPECT, Func_t::button_press_callback, create_widget(), Xputty::dpy, draw_hyperlink(), Func_t::enter_callback, Func_t::expose_callback, Widget_t::func, Resize_t::gravity, hyperlink_pressed(), Widget_t::label, Func_t::leave_callback, Widget_t::scale, transparent_draw(), and Widget_t::widget.

◆ draw_hyperlink()

void draw_hyperlink ( void *  w_,
void *  user_data 
)

Definition at line 40 of file xmessage-dialog.c.

40 {
41 Widget_t *w = (Widget_t*)w_;
42 Metrics_t metrics;
43 os_get_window_metrics(w, &metrics);
44 int width = metrics.width;
45 int height = metrics.height;
46
47 cairo_text_extents_t extents;
49 cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
50 cairo_text_extents(w->crb,w->label , &extents);
51
52 cairo_move_to (w->crb, (width*0.5)-(extents.width/2), height-(extents.height/4));
53 cairo_show_text(w->crb, w->label);
54 cairo_new_path (w->crb);
55}
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
float ascale
Definition xwidget.h:369
cairo_t * crb
Definition xwidget.h:489
int normal_font
Definition xputty.h:248
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:222
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:245
void os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t

References Widget_t::app, Resize_t::ascale, Widget_t::crb, get_color_state(), Metrics_t::height, Widget_t::label, Xputty::normal_font, os_get_window_metrics(), Widget_t::scale, use_fg_color_scheme(), and Metrics_t::width.

Referenced by create_hyperlink().

◆ hyperlink_pressed()

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

Definition at line 23 of file xmessage-dialog.c.

23 {
24 Widget_t *w = (Widget_t*)w_;
25 XButtonEvent *xbutton = (XButtonEvent*)button_;
26 if (xbutton->button == Button1) {
27 char *command;
28 asprintf(&command, "xdg-open '%s'",w->label);
29 if (system(NULL)) {
30 int ret = system(command);
31 if (ret) {
33 "Fail to open link", NULL);
34 }
35 }
36 free(command);
37 }
38}
int button
int asprintf(char *strp[], const char *fmt,...)
Definition xasprintf.c:36
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 ...
@ ERROR_BOX

References asprintf(), XEvent::button, ERROR_BOX, Widget_t::label, and open_message_dialog().

Referenced by create_hyperlink().

◆ 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 character "|" choices for the SELECTION_BOX should be separated as well with the character "|". message and/or choices could be NULL when not needed. To fetch the response of a dialog, connect to the dialog_callback supported "styles" been
INFO_BOX - a message dialog display a info text
WARNING_BOX - a message dialog display a warning
ERROR_BOX - a message dialog display a error message
QUESTION_BOX - a no/yes dialog message
SELECTION_BOX - a dialog to select between multiple options
ENTRY_BOX - a dialog to get text input

Returns
Widget_t* - pointer to the Widget_t struct

Definition at line 386 of file xmessage-dialog.c.

387 {
388
389 MessageDialog *mb = (MessageDialog*)malloc(sizeof(MessageDialog));
390 mb->response = 0;
391 mb->message_type = 0;
392 mb->lin = 0;
393 mb->width = 330;
394 mb->height = 200;
395 mb->message = NULL;
396 mb->sel = 0;
397 mb->choices = NULL;
398 check_for_message(mb, message);
399 check_for_choices(mb, choices);
400 check_for_style(mb, style);
401 Widget_t *wid = create_window(w->app, os_get_root_window(w->app, IS_WINDOW), 0, 0, mb->width, mb->height);
402 wid->label = message;
403 wid->flags |= HAS_MEM;
404 wid->scale.gravity = CENTER;
405 wid->parent_struct = mb;
406 wid->parent = w;
407 wid->func.mem_free_callback = mg_mem_free;
408 wid->func.expose_callback = draw_message_window;
409 check_for_hyperlinks(wid);
410 char *alternate_title = NULL;
411 char *button_title = (char*)_("OK");
412 Widget_t *no;
413 switch (style) {
414 case INFO_BOX:
415 widget_get_png(wid, LDVAR(info_png));
416 alternate_title = (char*)_("INFO");
419 break;
420 case WARNING_BOX:
421 widget_get_png(wid, LDVAR(warning_png));
422 alternate_title = (char*)_("WARNING");
425 break;
426 case ERROR_BOX:
427 widget_get_png(wid, LDVAR(error_png));
428 alternate_title = (char*)_("ERROR");
431 break;
432 case QUESTION_BOX:
433 widget_get_png(wid, LDVAR(question_png));
434 alternate_title = (char*)_("QUESTION");
435 no = add_button(wid, _("NO"), 10, mb->height-40, 60, 30);
436 no->scale.gravity = CENTER;
437 no->func.value_changed_callback = message_no_callback;
439 button_title = (char*)_("YES");
441 break;
442 case SELECTION_BOX:
443 widget_get_png(wid, LDVAR(choice_png));
444 alternate_title = (char*)_("SELECTION");
446 create_checkboxes(wid);
448 break;
449 case ENTRY_BOX:
450 widget_get_png(wid, LDVAR(message_png));
451 alternate_title = (char*)_("TEXT ENTRY");
453 create_entry_box(wid);
455 break;
456 }
457 widget_set_title(wid, (title)? title : alternate_title);
458
459 Widget_t *okay = add_button(wid, button_title, mb->width-70, mb->height-40, 60, 30);
460 okay->scale.gravity = CENTER;
461 okay->func.value_changed_callback = message_okay_callback;
462
463 widget_show_all(wid);
464 return wid;
465}
xevfunc value_changed_callback
Definition xwidget.h:90
xevfunc mem_free_callback
Definition xwidget.h:92
unsigned int lin
unsigned int height
unsigned int sel
unsigned int width
cairo_surface_t * image
Definition xwidget.h:491
void * parent
Definition xwidget.h:471
long long flags
Definition xwidget.h:461
void * parent_struct
Definition xwidget.h:473
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
@ QUESTION_BOX
@ WARNING_BOX
@ ENTRY_BOX
@ SELECTION_BOX
@ INFO_BOX
void widget_get_png(Widget_t *w, const unsigned char *name)
widget_get_png - read png into Widget_t xlib surface
Definition xpngloader.c:75
void widget_set_icon_from_surface(Widget_t *w, cairo_surface_t *image)
widget_set_icon_from_surface - set icon image from cairo surface for Widget_t those icon will be used...
Definition xpngloader.c:119
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition xwidget.c:359
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
@ CENTER
Definition xwidget.h:320
@ HAS_MEM
Definition xwidget.h:406
@ IS_WINDOW
Definition xwidget.h:390
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition xwidget.c:386

References add_button(), Widget_t::app, CENTER, MessageDialog::choices, create_window(), ENTRY_BOX, ERROR_BOX, Func_t::expose_callback, Widget_t::flags, Widget_t::func, Resize_t::gravity, HAS_MEM, MessageDialog::height, Widget_t::image, INFO_BOX, IS_WINDOW, Widget_t::label, MessageDialog::lin, Func_t::mem_free_callback, MessageDialog::message, MessageDialog::message_type, os_get_root_window(), Widget_t::parent, Widget_t::parent_struct, QUESTION_BOX, MessageDialog::response, Widget_t::scale, MessageDialog::sel, SELECTION_BOX, Func_t::value_changed_callback, WARNING_BOX, widget_get_png(), widget_set_icon_from_surface(), widget_set_title(), widget_show_all(), and MessageDialog::width.

Referenced by hyperlink_pressed().

◆ radio_box_set_active()

void radio_box_set_active ( Widget_t w)

Definition at line 235 of file xmessage-dialog.c.

235 {
236 Widget_t * p = (Widget_t*)w->parent;
237 MessageDialog *mb = (MessageDialog *)p->parent_struct;
238 int response = 0;
239 int i = 0;
240 for(;i<p->childlist->elem;i++) {
241 Widget_t *wid = p->childlist->childs[i];
242 if (wid->adj && wid->flags & IS_RADIO) {
243 ++response;
244 if (wid != w) adj_set_value(wid->adj_y, 0.0);
245 else if (wid == w) mb->response = response;
246 }
247 }
248}
Widget_t ** childs
Definition xchildlist.h:51
Adjustment_t * adj_y
Definition xwidget.h:495
Adjustment_t * adj
Definition xwidget.h:497
Childlist_t * childlist
Definition xwidget.h:499
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
@ IS_RADIO
Definition xwidget.h:394

References Widget_t::adj, adj_set_value(), Widget_t::adj_y, Widget_t::childlist, Childlist_t::childs, Childlist_t::elem, Widget_t::flags, IS_RADIO, Widget_t::parent, Widget_t::parent_struct, and MessageDialog::response.