31#include "oslib/osbyte.h"
32#include "oslib/serviceinternational.h"
33#include "oslib/wimp.h"
45#define WIN_HASH_SIZE 32
46#define WIN_HASH(w) (((unsigned)(w) >> 5) % WIN_HASH_SIZE)
112 const char *(*get_help_suffix)(wimp_w
w, wimp_i i, os_coord *pos,
113 wimp_mouse_state buttons);
121 wimp_mouse_state state);
149 for (event = window->
first; event; event = event->
next) {
150 switch (event->
type) {
155 event->previous_value.textual = strdup(
160 "Unable to store state for icon %i",
166 event->previous_value.boolean =
195 for (event = window->
first; event; event = event->
next) {
196 switch (event->
type) {
235 for (event = window->
first; event; event = event->
next) {
236 switch (event->
type) {
240 if (value < event->
data.numeric_field.min)
241 value =
event->data.numeric_field.min;
243 value =
event->data.numeric_field.max;
273 "Transferring all events from window 0x%x to window 0x%x",
278 if (window == NULL || window->
w !=
from)
301 NSLOG(netsurf, INFO,
"Removing all events for window 0x%x",
307 while (window->
first) {
308 event = window->
first;
310 switch (event->
type) {
315 event->previous_value.textual = NULL;
339 NSLOG(netsurf, INFO,
"Removing all events for window 0x%x, icon %d",
340 (
unsigned int)w, (
int)
i);
347 event = window->
first;
350 while (event != NULL) {
354 NSLOG(netsurf, INFO,
"Removing event 0x%x",
355 (
unsigned int)event);
358 window->
first = child;
362 switch (event->type) {
365 if (event->previous_value.textual)
366 free(event->previous_value.textual);
367 event->previous_value.textual = NULL;
426 os_coord *pos, wimp_mouse_state buttons))
449 os_coord *pos, wimp_mouse_state buttons)
525 wimp_menu_entry *menu_entry;
530 unsigned int button_type;
543 for (event = window->
first; event; event = event->
next)
560 menu_entry = &menu->entries[
selection->items[0]];
562 menu_entry = &menu_entry->sub_menu->
566 if (menu_entry->menu_flags & wimp_MENU_TICKED)
570 menu_entry->data.indirected_text.text,
false);
584 ic.i =
event->data.menu_gright.field;
585 error = xwimp_get_icon_state(&ic);
587 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
588 error->errnum, error->errmess);
592 button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE) >> wimp_ICON_BUTTON_TYPE_SHIFT;
593 if ((button_type != wimp_BUTTON_WRITABLE) &&
594 (button_type != wimp_BUTTON_WRITE_CLICK_DRAG))
596 error = xwimp_get_caret_position(&caret);
598 NSLOG(netsurf, INFO,
"xwimp_get_caret_position: 0x%x: %s",
599 error->errnum, error->errmess);
605 -1, -1, -1, strlen(menu_entry->data.indirected_text.text));
608 "xwimp_set_caret_position: 0x%x: %s",
645 int current, step, stepping,
min,
max, decimal_places;
646 wimp_window_state open;
656 if ((pointer->buttons == wimp_CLICK_MENU) &&
667 for (event = window->
first; event; event = event->
next)
668 if (event->
i == pointer->i)
673 switch (event->
type) {
679 for (search = window->
first; search; search = search->
next)
682 NSLOG(netsurf, INFO,
"Incorrect reference.");
690 if (pointer->buttons & wimp_CLICK_ADJUST)
692 else if (pointer->buttons & wimp_CLICK_SELECT)
717 error = xwimp_get_window_state(&open);
720 "xwimp_get_window_state: 0x%x: %s",
726 error = xwimp_get_caret_position(&caret);
729 "xwimp_get_caret_position: 0x%x: %s",
741 "xwimp_open_window: 0x%x: %s",
747 if (caret.w == pointer->w) {
748 error = xwimp_set_caret_position(caret.w,
750 caret.pos.x, caret.pos.y,
754 "xwimp_set_caret_position: 0x%x: %s",
775 for (search = window->
first; search; search = search->
next)
780 search->
i, (search == event));
784 event->data.callback(pointer);
787 if (pointer->buttons & wimp_CLICK_SELECT) {
813 unsigned int button_type;
821 ic.i =
event->data.menu_gright.field;
822 error = xwimp_get_icon_state(&ic);
824 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
825 error->errnum, error->errmess);
829 button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE)
830 >> wimp_ICON_BUTTON_TYPE_SHIFT;
831 if ((button_type == wimp_BUTTON_WRITABLE) ||
832 (button_type == wimp_BUTTON_WRITE_CLICK_DRAG))
835 menu =
event->data.menu_gright.menu;
838 if (!strcmp(menu->entries[
i].data.indirected_text.text,
text))
839 menu->entries[
i].menu_flags |= wimp_MENU_TICKED;
841 menu->entries[
i].menu_flags &= ~wimp_MENU_TICKED;
842 }
while (!(menu->entries[
i++].menu_flags & wimp_MENU_LAST));
853 wimp_mouse_state state)
857 for (search = window->
first; search; search = search->
next)
869 if (state & wimp_CLICK_SELECT) {
887 static const int *ucstable = NULL;
888 static int alphabet = 0;
889 static uint32_t wc = 0;
890 static int shift = 0;
893 wimp_pointer pointer;
895 uint32_t c = (uint32_t) key->c;
904 memcpy(&k, key,
sizeof(wimp_key));
930 error = xosbyte1(osbyte_ALPHABET_NUMBER, 127, 0, &t_alphabet);
932 NSLOG(netsurf, INFO,
"failed reading alphabet: 0x%x: %s",
933 error->errnum, error->errmess);
935 t_alphabet = alphabet;
938 if (t_alphabet != alphabet) {
942 alphabet = t_alphabet;
944 error = xserviceinternational_get_ucs_conversion_table(
945 alphabet, &unclaimed, &ostable);
948 "failed reading UCS conversion table: 0x%x: %s",
953 }
else if (unclaimed) {
963 if (alphabet != 111 && ucstable != NULL) {
965 if (ucstable[c] == -1)
971 else if (alphabet == 111 ) {
972 if ((c & 0x80) == 0x00 || (c & 0xC0) == 0xC0) {
974 if ((c & 0xE0) == 0xC0) {
975 wc = ((c & 0x1F) << 6);
979 else if ((c & 0xF0) == 0xE0) {
980 wc = ((c & 0x0F) << 12);
984 else if ((c & 0xF8) == 0xF0) {
985 wc = ((c & 0x07) << 18);
995 else if ((c & 0xFC) == 0xF8) {
996 wc = ((c & 0x03) << 24);
999 else if ((c & 0xFE) == 0xFC) {
1000 wc = ((c & 0x01) << 30);
1003 else if (c >= 0x80) {
1007 NSLOG(netsurf, INFO,
1008 "unexpected UTF8 start"" byte %x (ignoring)",
1016 if ((c & 0xC0) != 0x80) {
1020 NSLOG(netsurf, INFO,
1021 "unexpected keycode: ""%x (ignoring)",
1027 wc |= ((c & 0x3F) << (6 * --shift));
1049 case wimp_KEY_ESCAPE:
1050 for (event = window->
first; event; event = event->
next) {
1051 switch (event->
type) {
1054 pointer.i =
event->i;
1055 pointer.buttons = wimp_CLICK_SELECT;
1064 case wimp_KEY_CONTROL + wimp_KEY_F2:
1066 wimp_WINDOW_CLOSE_ICON))
1073 case wimp_KEY_RETURN:
1111 NSLOG(netsurf, INFO,
"Close event received for window 0x%x",
1192 && (pointer->buttons == wimp_CLICK_MENU)) {
1204 int gap_height = 24;
1206 xpos = pointer->pos.x;
1211 entries[entry].menu_flags &
1212 wimp_MENU_SEPARATE) != 0)
1215 entries[entry++].menu_flags &
1216 wimp_MENU_LAST) == 0);
1218 xpos = pointer->pos.x;
1219 ypos = pointer->pos.y;
1271 bool menu_auto,
bool position_ibar)
1288 wimp_i up, wimp_i down,
1289 int min,
int max,
int stepping,
int decimal_places)
1296 event->data.numeric_field.min =
min;
1297 event->data.numeric_field.max =
max;
1298 event->data.numeric_field.stepping = stepping;
1299 event->data.numeric_field.decimal_places = decimal_places;
1304 event->data.linked_icon =
i;
1309 event->data.linked_icon =
i;
1332 wimp_i gright, wimp_menu *menu)
1339 event->data.menu_gright.field =
i;
1340 event->data.menu_gright.menu = menu;
1388 void (*
callback)(wimp_pointer *pointer))
1440 bool (*
callback)(wimp_pointer *pointer))
1462 bool (*callback)(wimp_key *key))
1478 void (*callback)(wimp_open *open))
1493 void (*callback)(wimp_w
w))
1508 void (*callback)(wimp_draw *redraw))
1524 void (*callback)(wimp_scroll *scroll))
1540 void (*callback)(wimp_entering *entering))
1560 bool (*callback)(wimp_w
w, wimp_i i, wimp_menu *m,
1582 bool (*callback)(wimp_w
w, wimp_i i, wimp_menu *m,
1604 void (*callback)(wimp_w
w, wimp_i i, wimp_menu *m,
1625 void (*callback)(wimp_w
w, wimp_i i, wimp_menu *m))
1648 assert((
int)
w != 0);
1653 NSLOG(netsurf, INFO,
"Creating structure for window 0x%x",
1685 if (window->
w ==
w) {
1687 *prev = window->
next;
1690 prev = &window->
next;
1725 for (event = window->
first; event; event = event->
next) {
1726 if (event->
i ==
i) {
1732 event = calloc(1,
sizeof(
struct icon_event));
1737 event->next = window->
first;
1738 window->
first = event;
1771 for (event = window->
first; event; event = event->
next)
1823 for (event = window->
first; event; event = event->
next)
1838 window->
menu_close(w, wimp_ICON_WINDOW, menu);
static int line_height(const css_unit_ctx *unit_len_ctx, const css_computed_style *style)
Calculate line height from a style.
void ro_gui_dialog_add_persistent(wimp_w parent, wimp_w w)
void ro_gui_dialog_close(wimp_w close)
Close a dialog box.
Netsurf additional integer type formatting macros.
#define NSLOG(catname, level, logmsg, args...)
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
wimp_w current_menu_window
Window that owns the current menu.
Interface to utility string handling.
const char *(* get_help_suffix)(wimp_w w, wimp_i i, os_coord *pos, wimp_mouse_state buttons)
bool(* ok_click)(wimp_w w)
bool(* mouse_click)(wimp_pointer *pointer)
struct event_window * next
void(* redraw_window)(wimp_draw *redraw)
struct icon_event * first
bool(* menu_prepare)(wimp_w w, wimp_i i, wimp_menu *m, wimp_pointer *p)
void(* menu_warning)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a)
void(* open_window)(wimp_open *open)
void(* close_window)(wimp_w w)
void(* menu_close)(wimp_w w, wimp_i i, wimp_menu *m)
bool(* keypress)(wimp_key *key)
bool(* menu_selection)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a)
void(* scroll_window)(wimp_scroll *scroll)
void(* entering_window)(wimp_entering *entering)
union icon_event::@49 data
struct event_data_menu_gright menu_gright
void(* callback)(wimp_pointer *pointer)
union icon_event::@50 previous_value
struct event_data_numeric_field numeric_field
const int * ucstable_from_alphabet(int alphabet)
Retrieve UCS table (above), given alphabet number.
UCS conversion tables (interface) This is only used if nothing claims Service_International,...
char from[32]
Encoding name to convert from.
char to[32]
Encoding name to convert to.
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
int ro_gui_get_icon_decimal(wimp_w w, wimp_i i, int decimal_places)
Get the contents of an icon as a number.
void ro_gui_set_icon_shaded_state(wimp_w w, wimp_i i, bool state)
Set the shaded state of an icon.
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
void ro_gui_set_icon_selected_state(wimp_w w, wimp_i i, bool state)
Set the selected state of an icon.
bool ro_gui_wimp_check_window_furniture(wimp_w w, wimp_window_flags mask)
Checks whether a piece of window furniture is present for a window.
bool ro_gui_get_icon_shaded_state(wimp_w w, wimp_i i)
Gets the shaded state of an icon.
void ro_gui_set_icon_decimal(wimp_w w, wimp_i i, int value, int decimal_places)
Set the contents of an icon to a number.
bool ro_gui_get_icon_selected_state(wimp_w w, wimp_i i)
Gets the selected state of an icon.
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_register_text_field(wimp_w w, wimp_i i)
Register a text field to be automatically handled.
static wimp_w ro_gui_wimp_event_submenu
bool ro_gui_wimp_event_register_keypress(wimp_w w, bool(*callback)(wimp_key *key))
Register a function to be called for all keypresses within a particular window.
bool ro_gui_wimp_event_register_numeric_field(wimp_w w, wimp_i i, wimp_i up, wimp_i down, int min, int max, int stepping, int decimal_places)
Register a numeric field to be automatically handled.
bool ro_gui_wimp_event_set_help_prefix(wimp_w w, const char *help_prefix)
Set the associated help prefix for a given window.
const char * ro_gui_wimp_event_get_help_prefix(wimp_w w)
Get the associated help prefix.
bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer)
Handles a mouse click event in a registered window.
bool ro_gui_wimp_event_register_redraw_window(wimp_w w, void(*callback)(wimp_draw *redraw))
Register a function to be called for all window redraw operations.
bool ro_gui_wimp_event_register_menu_gright(wimp_w w, wimp_i i, wimp_i gright, wimp_menu *menu)
Register an icon menu to be automatically handled.
static struct event_window * ro_gui_wimp_event_get_window(wimp_w w)
Finds the event data associated with a given window handle, or creates a new one.
void ro_gui_wimp_event_finalise(wimp_w w)
Free any resources associated with a window.
void * ro_gui_wimp_event_get_user_data(wimp_w w)
Gets the user data associated with a window.
static void ro_gui_wimp_event_ok_click(struct event_window *window, wimp_mouse_state state)
Perform the necessary actions following a click on the OK button.
bool ro_gui_wimp_event_transfer(wimp_w from, wimp_w to)
Transfer event data from one window to another.
bool ro_gui_wimp_event_register_cancel(wimp_w w, wimp_i i)
Register a function to be called for the Cancel action on a window.
bool ro_gui_wimp_event_memorise(wimp_w w)
Memorises the current state of any registered components in a window.
bool ro_gui_wimp_event_register_menu_selection(wimp_w w, bool(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a))
Register a function to be called following a menu selection.
bool ro_gui_wimp_event_redraw_window(wimp_draw *redraw)
Handle any redraw window requests.
static struct event_window * ro_gui_wimp_event_remove_window(wimp_w w)
Removes the event data associated with a given handle from the hash tables, but does not delete it.
const char * ro_gui_wimp_event_get_help_suffix(wimp_w w, wimp_i i, os_coord *pos, wimp_mouse_state buttons)
Get the associated help suffix.
bool ro_gui_wimp_event_scroll_window(wimp_scroll *scroll)
Handle any scroll window requests.
bool ro_gui_wimp_event_prepare_menu(wimp_w w, wimp_i i, wimp_menu *menu)
Trigger a window's Prepare Menu event.
bool ro_gui_wimp_event_open_window(wimp_open *open)
Handle any open window requests.
void ro_gui_wimp_event_deregister(wimp_w w, wimp_i i)
Free any resources associated with a specific icon in a window.
void ro_gui_wimp_event_register_submenu(wimp_w w)
Register a submenu as being opened.
bool ro_gui_wimp_event_close_window(wimp_w w)
Service any close window handlers.
bool ro_gui_wimp_event_register_mouse_click(wimp_w w, bool(*callback)(wimp_pointer *pointer))
Register a function to be called for all mouse-clicks to icons in a window that don't have registered...
void ro_gui_wimp_event_menus_closed(wimp_w w, wimp_i i, wimp_menu *menu)
Handle menus being closed.
bool ro_gui_wimp_event_register_checkbox(wimp_w w, wimp_i i)
Register a checkbox to be automatically handled.
bool ro_gui_wimp_event_pointer_entering_window(wimp_entering *entering)
Handle any pointer entering window requests.
bool ro_gui_wimp_event_submenu_warning(wimp_w w, wimp_i i, wimp_menu *menu, wimp_selection *selection, menu_action action)
bool ro_gui_wimp_event_register_menu_prepare(wimp_w w, bool(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_pointer *p))
Register a function to be called before a menu is (re-)opened.
bool ro_gui_wimp_event_restore(wimp_w w)
Restore the state of any registered components in a window to their memorised state.
bool ro_gui_wimp_event_validate(wimp_w w)
Ensures all values are within pre-determined boundaries.
bool ro_gui_wimp_event_set_user_data(wimp_w w, void *user)
Sets the user data associated with a window.
bool ro_gui_wimp_event_register_menu_close(wimp_w w, void(*callback)(wimp_w w, wimp_i i, wimp_menu *m))
Register a function to be called before a menu is finally closed.
bool ro_gui_wimp_event_register_ok(wimp_w w, wimp_i i, bool(*callback)(wimp_w w))
Register a function to be called for the OK action on a window.
bool ro_gui_wimp_event_register_pointer_entering_window(wimp_w w, void(*callback)(wimp_entering *entering))
Register a function to be called for all pointer entering window requests.
bool ro_gui_wimp_event_register_close_window(wimp_w w, void(*callback)(wimp_w w))
Register a function to be called after the window has been closed.
bool ro_gui_wimp_event_register_radio(wimp_w w, wimp_i *i)
Register a group of radio icons to be automatically handled.
bool ro_gui_wimp_event_register_help_suffix(wimp_w w, const char *(*get_help_suffix)(wimp_w w, wimp_i i, os_coord *pos, wimp_mouse_state buttons))
Register a handler to decode help suffixes for a given window.
bool ro_gui_wimp_event_menu_selection(wimp_w w, wimp_i i, wimp_menu *menu, wimp_selection *selection, menu_action action)
Handles a menu selection event.
bool ro_gui_wimp_event_register_scroll_window(wimp_w w, void(*callback)(wimp_scroll *scroll))
Register a function to be called for all window scroll requests.
static struct event_window * ro_gui_wimp_event_find_window(wimp_w w)
Find the event data associated with a given window handle.
bool ro_gui_wimp_event_keypress(wimp_key *key)
Handle any registered keypresses, and the standard RISC OS ones.
bool ro_gui_wimp_event_register_button(wimp_w w, wimp_i i, void(*callback)(wimp_pointer *pointer))
Register a function to be called when a particular button is pressed.
static struct event_window * ro_gui_wimp_event_windows[WIN_HASH_SIZE]
bool ro_gui_wimp_event_register_open_window(wimp_w w, void(*callback)(wimp_open *open))
Register a function to be called for all window opening requests.
static struct icon_event * ro_gui_wimp_event_get_event(wimp_w w, wimp_i i, event_type type)
bool ro_gui_wimp_event_register_menu_warning(wimp_w w, void(*callback)(wimp_w w, wimp_i i, wimp_menu *m, wimp_selection *s, menu_action a))
Register a function to be called when a sub-menu warning is received.
static void ro_gui_wimp_event_prepare_gright_menu(wimp_w w, struct icon_event *event)
Prepare a menu ready for use.
bool ro_gui_wimp_event_register_menu(wimp_w w, wimp_menu *m, bool menu_auto, bool position_ibar)
Register a window menu to be (semi-)automatically handled.
bool ro_gui_wimp_event_process_window_menu_click(wimp_pointer *pointer)
Process a Menu click in a window, by checking for a registered window menu and opening it if one is f...
Automated RISC OS WIMP event handling (interface).
A collection of grubby utilities for working with OSLib's wimp API.
#define PTR_WIMP_OPEN(pstate)
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.