Changeset b71c0fc in mainline for uspace/lib/ui/src


Ignore:
Timestamp:
2020-11-07T16:07:22Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d55ab823
Parents:
fa01c05
Message:

Make fixed layout a UI control and hook it up to the window

Location:
uspace/lib/ui/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/control.c

    rfa01c05 rb71c0fc  
    8181 * extended data).
    8282 *
    83  * @param control Control
     83 * @param control Control or @c NULL
    8484 */
    8585void ui_control_destroy(ui_control_t *control)
    8686{
     87        if (control == NULL)
     88                return;
     89
    8790        return control->ops->destroy(control->ext);
    8891}
  • uspace/lib/ui/src/fixed.c

    rfa01c05 rb71c0fc  
    4444#include "../private/fixed.h"
    4545
     46static void ui_fixed_ctl_destroy(void *);
     47static errno_t ui_fixed_ctl_paint(void *);
     48static ui_evclaim_t ui_fixed_ctl_pos_event(void *, pos_event_t *);
     49
     50/** Push button control ops */
     51ui_control_ops_t ui_fixed_ops = {
     52        .destroy = ui_fixed_ctl_destroy,
     53        .paint = ui_fixed_ctl_paint,
     54        .pos_event = ui_fixed_ctl_pos_event
     55};
     56
    4657/** Create new fixed layout.
    4758 *
     
    5263{
    5364        ui_fixed_t *fixed;
     65        errno_t rc;
    5466
    5567        fixed = calloc(1, sizeof(ui_fixed_t));
    5668        if (fixed == NULL)
    5769                return ENOMEM;
     70
     71        rc = ui_control_new(&ui_fixed_ops, (void *) fixed, &fixed->control);
     72        if (rc != EOK) {
     73                free(fixed);
     74                return rc;
     75        }
    5876
    5977        list_initialize(&fixed->elem);
     
    83101        }
    84102
     103        ui_control_delete(fixed->control);
    85104        free(fixed);
     105}
     106
     107/** Get base control from fixed layout.
     108 *
     109 * @param fixed Fixed layout
     110 * @return Control
     111 */
     112ui_control_t *ui_fixed_ctl(ui_fixed_t *fixed)
     113{
     114        return fixed->control;
    86115}
    87116
     
    203232}
    204233
     234/** Destroy fixed layout control.
     235 *
     236 * @param arg Argument (ui_fixed_t *)
     237 */
     238void ui_fixed_ctl_destroy(void *arg)
     239{
     240        ui_fixed_t *fixed = (ui_fixed_t *) arg;
     241
     242        ui_fixed_destroy(fixed);
     243}
     244
     245/** Paint fixed layout control.
     246 *
     247 * @param arg Argument (ui_fixed_t *)
     248 * @return EOK on success or an error code
     249 */
     250errno_t ui_fixed_ctl_paint(void *arg)
     251{
     252        ui_fixed_t *fixed = (ui_fixed_t *) arg;
     253
     254        return ui_fixed_paint(fixed);
     255}
     256
     257/** Handle fixed layout control position event.
     258 *
     259 * @param arg Argument (ui_fixed_t *)
     260 * @param pos_event Position event
     261 * @return @c ui_claimed iff the event is claimed
     262 */
     263ui_evclaim_t ui_fixed_ctl_pos_event(void *arg, pos_event_t *event)
     264{
     265        ui_fixed_t *fixed = (ui_fixed_t *) arg;
     266
     267        return ui_fixed_pos_event(fixed, event);
     268}
     269
    205270/** @}
    206271 */
  • uspace/lib/ui/src/window.c

    rfa01c05 rb71c0fc  
    4242#include <mem.h>
    4343#include <stdlib.h>
     44#include <ui/control.h>
    4445#include <ui/resource.h>
    4546#include <ui/wdecor.h>
    4647#include <ui/window.h>
     48#include "../private/control.h"
    4749#include "../private/dummygc.h"
    4850#include "../private/resource.h"
     
    170172                return;
    171173
     174        ui_control_destroy(window->control);
    172175        ui_wdecor_destroy(window->wdecor);
    173176        ui_resource_destroy(window->res);
     
    177180}
    178181
     182/** Add control to window.
     183 *
     184 * Only one control can be added to a window. If more than one control
     185 * is added, the results are undefined.
     186 *
     187 * @param fixed Fixed layout
     188 * @param control Control
     189 * @return EOK on success, ENOMEM if out of memory
     190 */
     191void ui_window_add(ui_window_t *window, ui_control_t *control)
     192{
     193        assert(window->control == NULL);
     194
     195        window->control = control;
     196        control->elemp = (void *) window;
     197}
     198
     199/** Remove control from window.
     200 *
     201 * @param window Window
     202 * @param control Control
     203 */
     204void ui_window_remove(ui_window_t *window, ui_control_t *control)
     205{
     206        assert(window->control == control);
     207        assert((ui_window_t *) control->elemp == window);
     208
     209        window->control = NULL;
     210        control->elemp = NULL;
     211}
     212
    179213/** Set window callbacks.
    180214 *
     
    343377        if (window->cb != NULL && window->cb->pos != NULL)
    344378                window->cb->pos(window, window->arg, pos);
     379        else
     380                ui_window_def_pos(window, pos);
    345381}
    346382
     
    375411                return rc;
    376412
     413        if (window->control != NULL)
     414                return ui_control_paint(window->control);
     415
    377416        return EOK;
    378417}
    379418
     419/** Default window position event routine.
     420 *
     421 * @param window Window
     422 * @return EOK on success or an error code
     423 */
     424void ui_window_def_pos(ui_window_t *window, pos_event_t *pos)
     425{
     426        if (window->control != NULL)
     427                ui_control_pos_event(window->control, pos);
     428}
     429
    380430/** @}
    381431 */
Note: See TracChangeset for help on using the changeset viewer.