Changeset 10cb47e in mainline


Ignore:
Timestamp:
2016-08-31T15:43:01Z (8 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bdfdc51c
Parents:
58563585
Message:

add support for custom client data into widgets

Location:
uspace
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/barber/barber.c

    r58563585 r10cb47e  
    308308       
    309309        winreg = argv[1];
    310         window_t *main_window = window_open(argv[1],
     310        window_t *main_window = window_open(argv[1], NULL,
    311311            WINDOW_MAIN | WINDOW_DECORATED, "barber");
    312312        if (!main_window) {
     
    315315        }
    316316       
    317         frame_canvas = create_canvas(window_root(main_window),
     317        frame_canvas = create_canvas(window_root(main_window), NULL,
    318318            FRAME_WIDTH, FRAME_HEIGHT, frames[frame]);
    319319       
  • uspace/app/fontviewer/fontviewer.c

    r58563585 r10cb47e  
    260260        }
    261261       
    262         main_window = window_open(argv[1], WINDOW_MAIN, "fontviewer");
     262        main_window = window_open(argv[1], NULL, WINDOW_MAIN, "fontviewer");
    263263        if (!main_window) {
    264264                printf("Cannot open main window.\n");
     
    282282        }
    283283       
    284         canvas = create_canvas(window_root(main_window),
     284        canvas = create_canvas(window_root(main_window), NULL,
    285285            WINDOW_WIDTH, WINDOW_HEIGHT, surface);
    286286        if (canvas == NULL) {
  • uspace/app/vdemo/vdemo.c

    r58563585 r10cb47e  
    8585        lbl->confirm = on_confirm;
    8686        lbl->cancel = on_cancel;
    87         bool initialized = init_label(
    88             &lbl->label, parent, caption, points, background, foreground);
     87        bool initialized = init_label(&lbl->label, parent, NULL, caption,
     88            points, background, foreground);
    8989        lbl->label.widget.destroy = my_label_destroy;
    9090        return initialized;
     
    110110{
    111111        if (argc >= 2) {
    112                 window_t *main_window = window_open(argv[1],
     112                window_t *main_window = window_open(argv[1], NULL,
    113113                    WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vdemo");
    114114                if (!main_window) {
     
    128128                my_label_t *lbl_action = create_my_label(NULL, "Hello there!", 16,
    129129                    lbl_bg, lbl_text);
    130                 button_t *btn_confirm = create_button(NULL, "Confirm", 16, btn_bg,
    131                     btn_fg, btn_text);
    132                 button_t *btn_cancel = create_button(NULL, "Cancel", 16, btn_bg,
    133                     btn_fg, btn_text);
    134                 grid_t *grid = create_grid(window_root(main_window), 2, 2, grd_bg);
     130                button_t *btn_confirm = create_button(NULL, NULL, "Confirm", 16,
     131                    btn_bg, btn_fg, btn_text);
     132                button_t *btn_cancel = create_button(NULL, NULL, "Cancel", 16,
     133                    btn_bg, btn_fg, btn_text);
     134                grid_t *grid = create_grid(window_root(main_window), NULL, 2, 2,
     135                    grd_bg);
    135136                if (!lbl_action || !btn_confirm || !btn_cancel || !grid) {
    136137                        window_close(main_window);
  • uspace/app/viewer/viewer.c

    r58563585 r10cb47e  
    157157                }
    158158        } else {
    159                 canvas = create_canvas(window_root(main_window),
     159                canvas = create_canvas(window_root(main_window), NULL,
    160160                    img_width, img_height, local_surface);
    161161                if (canvas == NULL) {
     
    219219                flags |= WINDOW_DECORATED;
    220220
    221         main_window = window_open(argv[1], flags, "viewer");
     221        main_window = window_open(argv[1], NULL, flags, "viewer");
    222222        if (!main_window) {
    223223                printf("Cannot open main window.\n");
  • uspace/app/vlaunch/vlaunch.c

    r58563585 r10cb47e  
    8585}
    8686
    87 static void on_vterm(widget_t *widget, void *data)
     87static void on_btn_click(widget_t *widget, void *data)
    8888{
    89         app_launch("/app/vterm");
    90 }
    91 
    92 static void on_vdemo(widget_t *widget, void *data)
    93 {
    94         app_launch("/app/vdemo");
    95 }
    96 
    97 static void on_vlaunch(widget_t *widget, void *data)
    98 {
    99         app_launch("/app/vlaunch");
     89        const char *app = (const char *) widget_get_data(widget);
     90        app_launch(app);
    10091}
    10192
     
    114105       
    115106        winreg = argv[1];
    116         window_t *main_window = window_open(argv[1],
     107        window_t *main_window = window_open(argv[1], NULL,
    117108            WINDOW_MAIN | WINDOW_DECORATED | WINDOW_RESIZEABLE, "vlaunch");
    118109        if (!main_window) {
     
    130121        pixel_t lbl_text = PIXEL(255, 0, 0, 0);
    131122       
    132         canvas_t *logo_canvas = create_canvas(NULL, LOGO_WIDTH, LOGO_HEIGHT,
     123        canvas_t *logo_canvas = create_canvas(NULL, NULL, LOGO_WIDTH, LOGO_HEIGHT,
    133124            logo);
    134         label_t *lbl_caption = create_label(NULL, "Launch application:", 16,
    135             lbl_bg, lbl_text);
    136         button_t *btn_vterm = create_button(NULL, "vterm", 16, btn_bg,
    137             btn_fg, btn_text);
    138         button_t *btn_vdemo = create_button(NULL, "vdemo", 16, btn_bg,
    139             btn_fg, btn_text);
    140         button_t *btn_vlaunch = create_button(NULL, "vlaunch", 16, btn_bg,
    141             btn_fg, btn_text);
    142         grid_t *grid = create_grid(window_root(main_window), 1, 5, grd_bg);
     125        label_t *lbl_caption = create_label(NULL, NULL, "Launch application:",
     126            16, lbl_bg, lbl_text);
     127        button_t *btn_vterm = create_button(NULL, "/app/vterm", "vterm",
     128            16, btn_bg, btn_fg, btn_text);
     129        button_t *btn_vdemo = create_button(NULL, "/app/vdemo", "vdemo",
     130            16, btn_bg, btn_fg, btn_text);
     131        button_t *btn_vlaunch = create_button(NULL, "/app/vlaunch", "vlaunch",
     132            16, btn_bg, btn_fg, btn_text);
     133        grid_t *grid = create_grid(window_root(main_window), NULL, 1, 5, grd_bg);
    143134       
    144135        if ((!logo_canvas) || (!lbl_caption) || (!btn_vterm) ||
     
    149140        }
    150141       
    151         sig_connect(&btn_vterm->clicked, NULL, on_vterm);
    152         sig_connect(&btn_vdemo->clicked, NULL, on_vdemo);
    153         sig_connect(&btn_vlaunch->clicked, NULL, on_vlaunch);
     142        sig_connect(&btn_vterm->clicked, &btn_vterm->widget, on_btn_click);
     143        sig_connect(&btn_vdemo->clicked, &btn_vdemo->widget, on_btn_click);
     144        sig_connect(&btn_vlaunch->clicked, &btn_vlaunch->widget, on_btn_click);
    154145       
    155146        grid->add(grid, &logo_canvas->widget, 0, 0, 1, 1);
  • uspace/app/vterm/vterm.c

    r58563585 r10cb47e  
    4949        }
    5050       
    51         window_t *main_window = window_open(argv[1],
     51        window_t *main_window = window_open(argv[1], NULL,
    5252            WINDOW_MAIN | WINDOW_DECORATED, "vterm");
    5353        if (!main_window) {
     
    5858        window_resize(main_window, 0, 0, 648, 508, WINDOW_PLACEMENT_ANY);
    5959        terminal_t *terminal_widget =
    60             create_terminal(window_root(main_window), 640, 480);
     60            create_terminal(window_root(main_window), NULL, 640, 480);
    6161        if (!terminal_widget) {
    6262                window_close(main_window);
  • uspace/lib/gui/button.c

    r58563585 r10cb47e  
    147147}
    148148
    149 bool init_button(button_t *btn, widget_t *parent, const char *caption,
    150     uint16_t points, pixel_t background, pixel_t foreground, pixel_t text)
    151 {
    152         widget_init(&btn->widget, parent);
     149bool init_button(button_t *btn, widget_t *parent, const void *data,
     150    const char *caption, uint16_t points, pixel_t background,
     151    pixel_t foreground, pixel_t text)
     152{
     153        widget_init(&btn->widget, parent, data);
    153154       
    154155        btn->widget.destroy = button_destroy;
     
    191192}
    192193
    193 button_t *create_button(widget_t *parent, const char *caption, uint16_t points,
    194     pixel_t background, pixel_t foreground, pixel_t text)
     194button_t *create_button(widget_t *parent, const void *data, const char *caption,
     195    uint16_t points, pixel_t background, pixel_t foreground, pixel_t text)
    195196{
    196197        button_t *btn = (button_t *) malloc(sizeof(button_t));
     
    198199                return NULL;
    199200       
    200         if (init_button(btn, parent, caption, points, background, foreground,
     201        if (init_button(btn, parent, data, caption, points, background, foreground,
    201202            text))
    202203                return btn;
  • uspace/lib/gui/button.h

    r58563585 r10cb47e  
    5656} button_t;
    5757
    58 extern bool init_button(button_t *, widget_t *, const char *, uint16_t, pixel_t,
    59     pixel_t, pixel_t);
    60 extern button_t *create_button(widget_t *, const char *, uint16_t, pixel_t,
    61     pixel_t, pixel_t);
     58extern bool init_button(button_t *, widget_t *, const void *, const char *,
     59    uint16_t, pixel_t, pixel_t, pixel_t);
     60extern button_t *create_button(widget_t *, const void *, const char *, uint16_t,
     61    pixel_t, pixel_t, pixel_t);
    6262extern void deinit_button(button_t *);
    6363
  • uspace/lib/gui/canvas.c

    r58563585 r10cb47e  
    123123}
    124124
    125 bool init_canvas(canvas_t *canvas, widget_t *parent, sysarg_t width,
    126     sysarg_t height, surface_t *surface)
     125bool init_canvas(canvas_t *canvas, widget_t *parent, const void *data,
     126    sysarg_t width, sysarg_t height, surface_t *surface)
    127127{
    128         widget_init(&canvas->widget, parent);
     128        widget_init(&canvas->widget, parent, data);
    129129       
    130130        canvas->widget.width = width;
     
    161161}
    162162
    163 canvas_t *create_canvas(widget_t *parent, sysarg_t width, sysarg_t height,
    164     surface_t *surface)
     163canvas_t *create_canvas(widget_t *parent, const void *data, sysarg_t width,
     164    sysarg_t height, surface_t *surface)
    165165{
    166166        canvas_t *canvas = (canvas_t *) malloc(sizeof(canvas_t));
     
    168168                return NULL;
    169169       
    170         if (init_canvas(canvas, parent, width, height, surface))
     170        if (init_canvas(canvas, parent, data, width, height, surface))
    171171                return canvas;
    172172       
  • uspace/lib/gui/canvas.h

    r58563585 r10cb47e  
    5353} canvas_t;
    5454
    55 extern bool init_canvas(canvas_t *, widget_t *, sysarg_t, sysarg_t,
     55extern bool init_canvas(canvas_t *, widget_t *, const void *, sysarg_t,
     56    sysarg_t, surface_t *);
     57extern canvas_t *create_canvas(widget_t *, const void *, sysarg_t, sysarg_t,
    5658    surface_t *);
    57 extern canvas_t *create_canvas(widget_t *, sysarg_t, sysarg_t, surface_t *);
    5859extern bool update_canvas(canvas_t *, surface_t *);
    5960extern void deinit_canvas(canvas_t *);
  • uspace/lib/gui/connection.c

    r58563585 r10cb47e  
    198198        list_foreach(sig_node->slots, link, slot_node_t, cur) {
    199199                void *data_copy = NULL;
    200                 if (data != NULL) {
     200                if (data != NULL)
    201201                        data_copy = malloc(data_size);
    202                 }
    203                 if (data_copy != NULL) {
     202               
     203                if (data_copy != NULL)
    204204                        memcpy(data_copy, data, data_size);
    205                 }
     205               
    206206                window_event_t *event =
    207                         (window_event_t *) malloc(sizeof(window_event_t));
    208 
     207                    (window_event_t *) malloc(sizeof(window_event_t));
     208               
    209209                if (event) {
    210210                        link_initialize(&event->link);
     
    215215                        prodcons_produce(&cur->widget->window->events, &event->link);
    216216                } else {
    217                         if (data_copy != NULL) {
     217                        if (data_copy != NULL)
    218218                                free(data_copy);
    219                         }
    220219                }
    221220        }
  • uspace/lib/gui/grid.c

    r58563585 r10cb47e  
    363363}
    364364
    365 bool init_grid(grid_t *grid, widget_t *parent, size_t cols, size_t rows,
    366     pixel_t background)
     365bool init_grid(grid_t *grid, widget_t *parent, const void *data, size_t cols,
     366    size_t rows, pixel_t background)
    367367{
    368368        if ((cols == 0) || (rows == 0))
     
    376376        memset(grid->layout, 0, cols * rows * sizeof(grid_cell_t));
    377377       
    378         widget_init(&grid->widget, parent);
     378        widget_init(&grid->widget, parent, data);
    379379       
    380380        grid->widget.destroy = grid_destroy;
     
    393393}
    394394
    395 grid_t *create_grid(widget_t *parent, size_t cols, size_t rows, pixel_t background)
     395grid_t *create_grid(widget_t *parent, const void *data, size_t cols,
     396    size_t rows, pixel_t background)
    396397{
    397398        grid_t *grid = (grid_t *) malloc(sizeof(grid_t));
     
    399400                return NULL;
    400401       
    401         if (init_grid(grid, parent, cols, rows, background))
     402        if (init_grid(grid, parent, data, cols, rows, background))
    402403                return grid;
    403404       
  • uspace/lib/gui/grid.h

    r58563585 r10cb47e  
    5656} grid_t;
    5757
    58 extern bool init_grid(grid_t *, widget_t *, size_t, size_t, pixel_t);
    59 extern grid_t *create_grid(widget_t *, size_t, size_t, pixel_t);
     58extern bool init_grid(grid_t *, widget_t *, const void *, size_t, size_t,
     59    pixel_t);
     60extern grid_t *create_grid(widget_t *, const void *, size_t, size_t, pixel_t);
    6061extern void deinit_grid(grid_t *);
    6162
  • uspace/lib/gui/label.c

    r58563585 r10cb47e  
    140140}
    141141
    142 bool init_label(label_t *lbl, widget_t *parent, const char *caption,
    143     uint16_t points, pixel_t background, pixel_t text)
    144 {
    145         widget_init(&lbl->widget, parent);
     142bool init_label(label_t *lbl, widget_t *parent, const void *data,
     143    const char *caption, uint16_t points, pixel_t background, pixel_t text)
     144{
     145        widget_init(&lbl->widget, parent, data);
    146146       
    147147        lbl->widget.destroy = label_destroy;
     
    184184}
    185185
    186 label_t *create_label(widget_t *parent, const char *caption, uint16_t points,
    187     pixel_t background, pixel_t text)
     186label_t *create_label(widget_t *parent, const void *data, const char *caption,
     187    uint16_t points, pixel_t background, pixel_t text)
    188188{
    189189        label_t *lbl = (label_t *) malloc(sizeof(label_t));
     
    191191                return NULL;
    192192       
    193         if (init_label(lbl, parent, caption, points, background, text))
     193        if (init_label(lbl, parent, data, caption, points, background, text))
    194194                return lbl;
    195195       
  • uspace/lib/gui/label.h

    r58563585 r10cb47e  
    5555} label_t;
    5656
    57 extern bool init_label(label_t *, widget_t *, const char *, uint16_t, pixel_t,
    58     pixel_t);
    59 extern label_t *create_label(widget_t *, const char *, uint16_t, pixel_t,
    60     pixel_t);
     57extern bool init_label(label_t *, widget_t *, const void *, const char *,
     58    uint16_t, pixel_t, pixel_t);
     59extern label_t *create_label(widget_t *, const void *, const char *, uint16_t,
     60    pixel_t, pixel_t);
    6161extern void deinit_label(label_t *);
    6262
  • uspace/lib/gui/minimal.c

    r58563585 r10cb47e  
    112112}
    113113
    114 bool init_minimal(minimal_t *min, widget_t *parent, pixel_t a, pixel_t b)
     114bool init_minimal(minimal_t *min, widget_t *parent, const void *data, pixel_t a,
     115    pixel_t b)
    115116{
    116         widget_init(&min->widget, parent);
     117        widget_init(&min->widget, parent, data);
    117118
    118119        min->widget.destroy = minimal_destroy;
     
    129130}
    130131
    131 minimal_t *create_minimal(widget_t *parent, pixel_t a, pixel_t b)
     132minimal_t *create_minimal(widget_t *parent, const void *data, pixel_t a,
     133    pixel_t b)
    132134{
    133135        minimal_t *min = (minimal_t *) malloc(sizeof(minimal_t));
     
    136138        }
    137139
    138         if (init_minimal(min, parent, a, b)) {
     140        if (init_minimal(min, parent, data, a, b)) {
    139141                return min;
    140142        } else {
  • uspace/lib/gui/minimal.h

    r58563585 r10cb47e  
    4949} minimal_t;
    5050
    51 extern bool init_minimal(minimal_t *, widget_t *, pixel_t, pixel_t);
    52 extern minimal_t *create_minimal(widget_t *, pixel_t, pixel_t);
     51extern bool init_minimal(minimal_t *, widget_t *, const void *, pixel_t,
     52    pixel_t);
     53extern minimal_t *create_minimal(widget_t *, const void *, pixel_t, pixel_t);
    5354extern void deinit_minimal(minimal_t *);
    5455
     
    5758/** @}
    5859 */
    59 
  • uspace/lib/gui/terminal.c

    r58563585 r10cb47e  
    696696}
    697697
    698 bool init_terminal(terminal_t *term, widget_t *parent, sysarg_t width,
    699     sysarg_t height)
    700 {
    701         widget_init(&term->widget, parent);
     698bool init_terminal(terminal_t *term, widget_t *parent, const void *data,
     699    sysarg_t width, sysarg_t height)
     700{
     701        widget_init(&term->widget, parent, data);
    702702       
    703703        link_initialize(&term->link);
     
    771771}
    772772
    773 terminal_t *create_terminal(widget_t *parent, sysarg_t width, sysarg_t height)
     773terminal_t *create_terminal(widget_t *parent, const void *data, sysarg_t width,
     774    sysarg_t height)
    774775{
    775776        terminal_t *term = (terminal_t *) malloc(sizeof(terminal_t));
     
    777778                return NULL;
    778779       
    779         bool ret = init_terminal(term, parent, width, height);
     780        bool ret = init_terminal(term, parent, data, width, height);
    780781        if (!ret) {
    781782                free(term);
  • uspace/lib/gui/terminal.h

    r58563585 r10cb47e  
    7070} terminal_t;
    7171
    72 extern bool init_terminal(terminal_t *, widget_t *, sysarg_t, sysarg_t);
    73 extern terminal_t *create_terminal(widget_t *, sysarg_t, sysarg_t);
     72extern bool init_terminal(terminal_t *, widget_t *, const void *, sysarg_t,
     73    sysarg_t);
     74extern terminal_t *create_terminal(widget_t *, const void *, sysarg_t,
     75    sysarg_t);
    7476extern void deinit_terminal(terminal_t *);
    7577
  • uspace/lib/gui/widget.c

    r58563585 r10cb47e  
    3636#include "widget.h"
    3737
    38 void widget_init(widget_t *widget, widget_t *parent)
     38/** Link widget with parent and initialize default position and size. */
     39void widget_init(widget_t *widget, widget_t *parent, const void *data)
    3940{
    4041        link_initialize(&widget->link);
    4142        list_initialize(&widget->children);
     43       
    4244        if (parent) {
    4345                widget->parent = parent;
     
    4850                widget->window = NULL;
    4951        }
    50 
     52       
     53        widget->data = data;
     54       
    5155        widget->hpos = 0;
    5256        widget->vpos = 0;
    5357        widget->width = 0;
    5458        widget->height = 0;
    55 
     59       
    5660        widget->width_min = 0;
    5761        widget->height_min = 0;
     
    6266}
    6367
     68/** Change position and size of the widget. */
    6469void widget_modify(widget_t *widget, sysarg_t hpos, sysarg_t vpos,
    6570    sysarg_t width, sysarg_t height)
     
    7176}
    7277
     78/** Get custom client data */
     79const void *widget_get_data(widget_t *widget)
     80{
     81        return widget->data;
     82}
     83
     84/** Unlink widget from its parent. */
    7385void widget_deinit(widget_t *widget)
    7486{
    75         if (widget->parent) {
     87        if (widget->parent)
    7688                list_remove(&widget->link);
    77         }
    7889}
    7990
  • uspace/lib/gui/widget.h

    r58563585 r10cb47e  
    5353struct widget {
    5454        link_t link;
    55         widget_t *parent; /**< Parent widget of this widget. NULL for root widget. */
    56         list_t children; /**< Children widgets of this widget. */
    57         window_t *window; /**< Window into which this widget belongs. */
    58 
     55        widget_t *parent;  /**< Parent widget of this widget. NULL for root widget. */
     56        list_t children;   /**< Children widgets of this widget. */
     57        window_t *window;  /**< Window into which this widget belongs. */
     58        const void *data;  /**< Custom client data. */
     59       
    5960        sysarg_t hpos; /**< Horizontal position in window coordinates. */
    6061        sysarg_t vpos; /**< Vertical position in window coordinates. */
     
    128129 */
    129130
    130 /** Link widget with parent and initialize default position and size. */
    131 extern void widget_init(widget_t *, widget_t *);
    132 /** Just convenience function to change position and size of the widget. */
     131extern void widget_init(widget_t *, widget_t *, const void *);
    133132extern void widget_modify(widget_t *, sysarg_t, sysarg_t, sysarg_t, sysarg_t);
    134 /** Unlink widget from its parent. */
     133extern const void *widget_get_data(widget_t *);
    135134extern void widget_deinit(widget_t *);
    136135
  • uspace/lib/gui/window.c

    r58563585 r10cb47e  
    591591}
    592592
    593 window_t *window_open(const char *winreg, window_flags_t flags,
    594     const char *caption)
     593window_t *window_open(const char *winreg, const void *data,
     594    window_flags_t flags, const char *caption)
    595595{
    596596        window_t *win = (window_t *) malloc(sizeof(window_t));
     
    604604        fibril_mutex_initialize(&win->guard);
    605605       
    606         widget_init(&win->root, NULL);
     606        widget_init(&win->root, NULL, data);
    607607        win->root.window = win;
    608608        win->root.destroy = root_destroy;
  • uspace/lib/gui/window.h

    r58563585 r10cb47e  
    6767 * whole application. Note that opened window does not have any surface yet.
    6868 */
    69 extern window_t *window_open(const char *, window_flags_t, const char *);
     69extern window_t *window_open(const char *, const void *, window_flags_t,
     70    const char *);
    7071
    7172/**
Note: See TracChangeset for help on using the changeset viewer.