SayoriOS  0.3.3
widget.c
1 #include "desktop/widget.h"
2 #include "io/serial_port.h"
3 #include "mem/vmm.h"
4 #include "io/ports.h"
5 
6 Widget_t* new_bare_widget(renderer_func_t renderer, destroyer_func_t destroyer, size_t x, size_t y, size_t width, size_t height) {
7  Widget_t* wgt = kcalloc(sizeof(Widget_t), 1);
8  wgt->x = x;
9  wgt->y = y;
10  wgt->width = width;
11  wgt->height = height;
12  wgt->renderer = renderer;
13  wgt->destroyer = destroyer;
14 
15  wgt->on_click = 0;
16 
17  return wgt;
18 }
19 
20 void destroy_widget(Widget_t* widget) {
21  qemu_log("Destroying widget at %x: W: %d; H: %d", widget, widget->width, widget->height);
22  widget->destroyer(widget);
23  kfree(widget);
24  qemu_ok("Destroyed widget");
25 }
26 
27 void widget_notify(struct Window* window, struct Widget* widget, WidgetNotifyCode_t code, void* data) {
28  qemu_log("Reached widget_notify()");
29  qemu_log("Got WIDGET notifcation: (WINDOW@%v)(id: %d) (WIDGET@%v) (CODE: %s)",
30  window,
31  window->id,
32  widget,
33  (code == WIDGET_CLICK ?
34  "WIDGET_CLICK":
35  "UNKNOWN"
36  )
37  );
38 
39  if(code == WIDGET_CLICK) {
40  qemu_log("Code check: onclick at %x", widget->on_click);
41  if(widget->on_click) {
42  qemu_log("On Click: %x", widget->on_click);
43  widget->on_click(widget, (Coordinates_t*)data);
44  qemu_log("Returning from on_click");
45  }else{
46  qemu_log("Function widget->on_click not defined!!!");
47  }
48  }
49 }
Definition: widget.h:12
Definition: window.h:25