HelenOS sources
This source file includes following definitions.
- ui_popup_params_init
- ui_popup_create
- ui_popup_destroy
- ui_popup_add
- ui_popup_remove
- ui_popup_set_cb
- ui_popup_get_res
- ui_popup_get_gc
- ui_popup_get_idev_id
- ui_popup_window_close
- ui_popup_window_kbd
- ui_popup_window_pos
#include <errno.h>
#include <gfx/context.h>
#include <io/kbd_event.h>
#include <io/pos_event.h>
#include <mem.h>
#include <stdlib.h>
#include <ui/control.h>
#include <ui/popup.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/popup.h"
static void ui_popup_window_close(ui_window_t *, void *);
static void ui_popup_window_kbd(ui_window_t *, void *, kbd_event_t *);
static void ui_popup_window_pos(ui_window_t *, void *, pos_event_t *);
static ui_window_cb_t ui_popup_window_cb = {
.close = ui_popup_window_close,
.kbd = ui_popup_window_kbd,
.pos = ui_popup_window_pos
};
void ui_popup_params_init(ui_popup_params_t *params)
{
memset(params, 0, sizeof(ui_popup_params_t));
}
errno_t ui_popup_create(ui_t *ui, ui_window_t *parent,
ui_popup_params_t *params, ui_popup_t **rpopup)
{
ui_popup_t *popup;
ui_window_t *window = NULL;
ui_wnd_params_t wparams;
gfx_coord2_t parent_pos;
errno_t rc;
popup = calloc(1, sizeof(ui_popup_t));
if (popup == NULL)
return ENOMEM;
rc = ui_window_get_pos(parent, &parent_pos);
if (rc != EOK)
goto error;
ui_wnd_params_init(&wparams);
wparams.rect = params->rect;
wparams.caption = "";
wparams.style &= ~ui_wds_decorated;
wparams.placement = ui_wnd_place_popup;
wparams.flags |= ui_wndf_popup | ui_wndf_topmost;
wparams.idev_id = params->idev_id;
gfx_rect_translate(&parent_pos, ¶ms->place, &wparams.prect);
rc = ui_window_create(ui, &wparams, &window);
if (rc != EOK)
goto error;
popup->ui = ui;
popup->parent = parent;
popup->window = window;
ui_window_set_cb(window, &ui_popup_window_cb, popup);
*rpopup = popup;
return EOK;
error:
free(popup);
return rc;
}
void ui_popup_destroy(ui_popup_t *popup)
{
if (popup == NULL)
return;
ui_window_destroy(popup->window);
free(popup);
}
void ui_popup_add(ui_popup_t *popup, ui_control_t *control)
{
ui_window_add(popup->window, control);
}
void ui_popup_remove(ui_popup_t *popup, ui_control_t *control)
{
ui_window_remove(popup->window, control);
}
void ui_popup_set_cb(ui_popup_t *popup, ui_popup_cb_t *cb, void *arg)
{
popup->cb = cb;
popup->arg = arg;
}
ui_resource_t *ui_popup_get_res(ui_popup_t *popup)
{
return ui_window_get_res(popup->window);
}
gfx_context_t *ui_popup_get_gc(ui_popup_t *popup)
{
return ui_window_get_gc(popup->window);
}
sysarg_t ui_popup_get_idev_id(ui_popup_t *popup)
{
return popup->idev_id;
}
static void ui_popup_window_close(ui_window_t *window, void *arg)
{
ui_popup_t *popup = (ui_popup_t *)arg;
if (popup->cb != NULL && popup->cb->close != NULL)
popup->cb->close(popup, popup->arg);
}
static void ui_popup_window_kbd(ui_window_t *window, void *arg,
kbd_event_t *event)
{
ui_popup_t *popup = (ui_popup_t *)arg;
popup->idev_id = event->kbd_id;
if (popup->cb != NULL && popup->cb->kbd != NULL)
popup->cb->kbd(popup, popup->arg, event);
}
static void ui_popup_window_pos(ui_window_t *window, void *arg,
pos_event_t *event)
{
ui_popup_t *popup = (ui_popup_t *)arg;
popup->idev_id = event->pos_id;
if (popup->cb != NULL && popup->cb->pos != NULL)
popup->cb->pos(popup, popup->arg, event);
}
HelenOS homepage, sources at GitHub