30#include "oslib/colourtrans.h"
32#include "oslib/osfile.h"
33#include "oslib/wimp.h"
34#include "oslib/wimpextend.h"
35#include "oslib/wimpspriteop.h"
48static int ro_gui_strncmp(
const char *s1,
const char *s2,
size_t len);
107 "xwimpextend_get_furniture_sizes: 0x%x: %s",
127 error = xos_read_mode_variable(
mode, os_MODEVAR_XEIG_FACTOR, xeig, 0);
129 NSLOG(netsurf, INFO,
"xos_read_mode_variable: 0x%x: %s",
130 error->errnum, error->errmess);
134 error = xos_read_mode_variable(
mode, os_MODEVAR_YEIG_FACTOR, yeig, 0);
136 NSLOG(netsurf, INFO,
"xos_read_mode_variable: 0x%x: %s",
137 error->errnum, error->errmess);
153 int xeig = 1, yeig = 1;
156 os_units->x = ((os_units->x + (1 << xeig) - 1) >> xeig);
157 os_units->y = ((os_units->y + (1 << yeig) - 1) >> yeig);
169 int xeig = 1, yeig = 1;
172 pixels->x = (pixels->x << xeig);
173 pixels->y = (pixels->y << yeig);
184#define ro_gui_redraw_icon(w, i) xwimp_set_icon_state(w, i, 0, 0)
202 error = xwimp_get_icon_state(&ic);
204 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
205 error->errnum, error->errmess);
209 error = xwimp_force_redraw(w, ic.icon.extent.x0, ic.icon.extent.y0,
210 ic.icon.extent.x1, ic.icon.extent.y1);
212 NSLOG(netsurf, INFO,
"xwimp_force_redraw: 0x%x: %s",
213 error->errnum, error->errmess);
237 static wimp_icon_state ic;
243 error = xwimp_get_icon_state(&ic);
245 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
246 error->errnum, error->errmess);
250 itext = (ic.icon.flags & wimp_ICON_INDIRECTED)
251 ? ic.icon.data.indirected_text.text : ic.icon.data.text;
274 size_t old_len, new_len;
275 char *local_text = NULL;
276 const char *text_for_icon;
279 unsigned int button_type;
288 NSLOG(netsurf, INFO,
"utf8_to_enc failed");
292 text_for_icon = local_text ? local_text :
text;
295 text_for_icon =
text;
296 new_len = strlen(text_for_icon);
301 error = xwimp_get_icon_state(&ic);
303 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
304 error->errnum, error->errmess);
309 if (ic.icon.flags & wimp_ICON_INDIRECTED) {
310 dst_text = ic.icon.data.indirected_text.text;
311 dst_max_len = ic.icon.data.indirected_text.size;
314 dst_text = ic.icon.data.text;
315 dst_max_len =
sizeof(ic.icon.data.text);
318 assert(old_len < dst_max_len);
327 strncpy(dst_text, text_for_icon, dst_max_len - 1);
328 dst_text[dst_max_len - 1] =
'\0';
331 button_type = (ic.icon.flags & wimp_ICON_BUTTON_TYPE)
332 >> wimp_ICON_BUTTON_TYPE_SHIFT;
333 if ((button_type == wimp_BUTTON_WRITABLE) ||
334 (button_type == wimp_BUTTON_WRITE_CLICK_DRAG)) {
335 error = xwimp_get_caret_position(&caret);
338 "xwimp_get_caret_position: 0x%x: %s",
344 if ((caret.w == w) && (caret.i == i)) {
345 if ((
size_t)caret.index > new_len
346 || (
size_t)caret.index == old_len)
347 caret.index = new_len;
348 error = xwimp_set_caret_position(w, i, caret.pos.x,
349 caret.pos.y, -1, caret.index);
352 "xwimp_set_caret_position: 0x%x: %s",
378 sprintf(
buffer,
"%d", value);
396 switch (decimal_places) {
398 sprintf(
buffer,
"%d", value);
401 sprintf(
buffer,
"%.1f", (
float)value / 10);
404 sprintf(
buffer,
"%.2f", (
float)value / 100);
407 assert(!
"Unsupported decimal format");
428 for (; decimal_places > 0; decimal_places--)
448 error = xwimp_set_icon_state(w, i,
449 (state ? wimp_ICON_SELECTED : 0), wimp_ICON_SELECTED);
451 NSLOG(netsurf, INFO,
"xwimp_set_icon_state: 0x%x: %s",
452 error->errnum, error->errmess);
469 error = xwimp_get_icon_state(&ic);
471 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
472 error->errnum, error->errmess);
476 return ((ic.icon.flags & wimp_ICON_SELECTED) != 0);
495 error = xwimp_set_icon_state(w, i,
496 (state ? wimp_ICON_SHADED : 0), wimp_ICON_SHADED);
498 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
499 error->errnum, error->errmess);
506 error = xwimp_get_caret_position(&caret);
508 NSLOG(netsurf, INFO,
"xwimp_get_caret_position: 0x%x: %s",
509 error->errnum, error->errmess);
513 if ((caret.w != w) || (caret.i != i))
519 error = xwimp_set_caret_position((wimp_w)-1, (wimp_i)-1, -1, -1, -1, -1);
521 NSLOG(netsurf, INFO,
"xwimp_set_caret_position: 0x%x: %s",
522 error->errnum, error->errmess);
540 xwimp_get_icon_state(&ic);
541 return (ic.icon.flags & wimp_ICON_SHADED) != 0;
560 error = xwimp_set_icon_state(w, i,
561 (state ? wimp_ICON_DELETED : 0), wimp_ICON_DELETED);
563 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
564 error->errnum, error->errmess);
571 error = xwimp_get_caret_position(&caret);
573 NSLOG(netsurf, INFO,
"xwimp_get_caret_position: 0x%x: %s",
574 error->errnum, error->errmess);
578 if ((caret.w != w) || (caret.i != i))
584 error = xwimp_set_caret_position((wimp_w)-1, (wimp_i)-1, -1, -1, -1, -1);
586 NSLOG(netsurf, INFO,
"xwimp_set_caret_position: 0x%x: %s",
587 error->errnum, error->errmess);
605 xwimp_get_icon_state(&ic);
606 return (ic.icon.flags & wimp_ICON_DELETED) != 0;
620 error = xwimp_set_icon_state(w, i, wimp_ICON_BUTTON_TYPE,
621 (
type << wimp_ICON_BUTTON_TYPE_SHIFT));
623 NSLOG(netsurf, INFO,
"xwimp_set_icon_state: 0x%x: %s",
624 error->errnum, error->errmess);
647 error = xwimp_get_icon_state(&ic);
649 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
650 error->errnum, error->errmess);
656 if (ic.icon.data.indirected_text.size) {
657 strncpy(ic.icon.data.indirected_text.text, name,
658 (
unsigned int)ic.icon.data.indirected_text.size - 1);
659 ic.icon.data.indirected_text.text[
660 ic.icon.data.indirected_text.size - 1] =
'\0';
663 ic.icon.data.indirected_sprite.area = area;
677 wimp_window_info_base window;
679 char *title_local_enc;
685 error = xwimp_get_window_info_header_only((wimp_window_info *)&window);
687 NSLOG(netsurf, INFO,
"xwimp_get_window_info: 0x%x: %s",
688 error->errnum, error->errmess);
699 NSLOG(netsurf, INFO,
"utf8_to_enc failed");
705 strncpy(window.title_data.indirected_text.text, title_local_enc,
706 (
unsigned int)window.title_data.indirected_text.size
708 window.title_data.indirected_text.text[
709 window.title_data.indirected_text.size - 1] =
'\0';
713 error = xwimp_force_redraw_title(w);
715 NSLOG(netsurf, INFO,
"xwimp_force_redraw_title: 0x%x: %s",
716 error->errnum, error->errmess);
721 free(title_local_enc);
734 wimp_window_state win_state;
735 wimp_window_info_base window;
736 wimp_icon_state state;
741 error = xwimp_get_window_state(&win_state);
743 NSLOG(netsurf, INFO,
"xwimp_get_window_state: 0x%x: %s",
744 error->errnum, error->errmess);
748 if (!(win_state.flags & wimp_WINDOW_OPEN))
753 error = xwimp_get_window_info_header_only((wimp_window_info *)&window);
755 NSLOG(netsurf, INFO,
"xwimp_get_window_info: 0x%x: %s",
756 error->errnum, error->errmess);
763 for (icon = 0; icon < window.icon_count; icon++) {
765 error = xwimp_get_icon_state(&state);
768 "xwimp_get_icon_state: 0x%x: %s",
776 if (state.icon.flags & wimp_ICON_SHADED)
778 b = (state.icon.flags >> wimp_ICON_BUTTON_TYPE_SHIFT) & 0xf;
779 if ((b != wimp_BUTTON_WRITE_CLICK_DRAG) &&
780 (b != wimp_BUTTON_WRITABLE))
784 error = xwimp_set_caret_position(w, icon, 0, 0, -1,
785 strlen(state.icon.data.indirected_text.text));
788 "xwimp_set_caret_position: 0x%x: %s",
809 fileswitch_object_type obj_type;
810 osspriteop_area *area;
813 error = xosfile_read_stamped_no_path(pathname,
814 &obj_type, 0, 0, &len, 0, 0);
817 "xosfile_read_stamped_no_path: 0x%x: %s",
823 if (obj_type != fileswitch_IS_FILE) {
828 area = malloc(len + 4);
834 area->size = len + 4;
835 area->sprite_count = 0;
839 error = xosspriteop_load_sprite_file(osspriteop_USER_AREA,
843 "xosspriteop_load_sprite_file: 0x%x: %s",
864 static char last_sprite_found[16];
868 if (!strncmp(sprite, last_sprite_found,
sizeof(last_sprite_found)))
872 error = xwimpspriteop_select_sprite(sprite, 0);
874 if (error->errnum != error_SPRITE_OP_DOESNT_EXIST) {
876 "xwimpspriteop_select_sprite: 0x%x: %s",
883 snprintf(last_sprite_found,
sizeof(last_sprite_found), sprite);
898 osspriteop_area *rom_base, *ram_base;
901 error = xwimp_base_of_sprites(&rom_base, &ram_base);
902 if (error)
return error;
904 error = xosspriteop_select_sprite(osspriteop_USER_AREA,
905 ram_base, (osspriteop_id)name, sprite);
907 if (error && error->errnum == error_SPRITE_OP_DOESNT_EXIST)
908 error = xosspriteop_select_sprite(osspriteop_USER_AREA,
909 rom_base, (osspriteop_id)name, sprite);
928 os_error *error = NULL;
935 if (area != (osspriteop_area *) -1)
936 error = xosspriteop_read_sprite_info(osspriteop_USER_AREA,
937 area, (osspriteop_id) sprite,
938 &dimensions.x, &dimensions.y, 0, &
mode);
940 if (error != NULL || area == (osspriteop_area *) -1)
941 error = xwimpspriteop_read_sprite_info(sprite,
942 &dimensions.x, &dimensions.y, 0, &
mode);
947 *
width = dimensions.x;
950 }
else if (error->errnum != error_SPRITE_OP_DOESNT_EXIST) {
952 "xosspriteop_read_sprite_info: 0x%x: %s",
972 os_colour user_colour)
977 error = xwimp_redraw_window(redraw, &more);
979 NSLOG(netsurf, INFO,
"xwimp_redraw_window: 0x%x: %s",
980 error->errnum, error->errmess);
986 error = xcolourtrans_set_gcol(user_colour,
988 os_ACTION_OVERWRITE, 0, 0);
991 "xcolourtrans_set_gcol: 0x%x: %s",
998 error = xwimp_get_rectangle(redraw, &more);
1000 NSLOG(netsurf, INFO,
"xwimp_get_rectangle: 0x%x: %s",
1001 error->errnum, error->errmess);
1017 wimp_window_flags xor_mask)
1019 wimp_window_state state;
1026 error = xwimp_get_window_state_and_nesting(&state, &
parent, &linkage);
1028 NSLOG(netsurf, INFO,
"xwimp_get_window_state: 0x%x: %s",
1029 error->errnum, error->errmess);
1034 open = state.flags & wimp_WINDOW_OPEN;
1035 state.flags &= ~(63 << 16);
1036 state.flags &= ~bic_mask;
1037 state.flags ^= xor_mask;
1039 state.next = wimp_HIDDEN;
1040 error = xwimp_open_window_nested_with_flags(&state,
parent, linkage);
1042 NSLOG(netsurf, INFO,
"xwimp_open_window: 0x%x: %s",
1043 error->errnum, error->errmess);
1049 error = xwimp_close_window(w);
1051 NSLOG(netsurf, INFO,
"xwimp_close_window: 0x%x: %s",
1052 error->errnum, error->errmess);
1068 wimp_window_state state;
1072 error = xwimp_get_window_state(&state);
1074 NSLOG(netsurf, INFO,
"xwimp_get_window_state: 0x%x: %s",
1075 error->errnum, error->errmess);
1079 return state.flags & mask;
1090 const char *str_begin;
1095 for (str_begin = str; *str++ >=
' '; )
1098 return str - str_begin - 1;
1115 if (c1 <
' ' || c2 <
' ')
1116 return (c1 <
' ' ? 0 : c1) - (c2 <
' ' ? 0 : c2);
1134 int x = scroll->visible.x1 - scroll->visible.x0 - 32;
1135 int y = scroll->visible.y1 - scroll->visible.y0 - 32;
1137 switch (scroll->xmin) {
1138 case wimp_SCROLL_PAGE_LEFT:
1139 scroll->xscroll -= x;
1141 case wimp_SCROLL_COLUMN_LEFT:
1142 scroll->xscroll -= 100;
1144 case wimp_SCROLL_COLUMN_RIGHT:
1145 scroll->xscroll += 100;
1147 case wimp_SCROLL_PAGE_RIGHT:
1148 scroll->xscroll += x;
1151 scroll->xscroll += (x * (scroll->xmin>>2)) >> 2;
1155 switch (scroll->ymin) {
1156 case wimp_SCROLL_PAGE_UP:
1157 scroll->yscroll += y;
1159 case wimp_SCROLL_LINE_UP:
1160 scroll->yscroll += 100;
1162 case wimp_SCROLL_LINE_DOWN:
1163 scroll->yscroll -= 100;
1165 case wimp_SCROLL_PAGE_DOWN:
1166 scroll->yscroll -= y;
1169 scroll->yscroll += (y * (scroll->ymin>>2)) >> 2;
1173 error = xwimp_open_window((wimp_open *) scroll);
1175 NSLOG(netsurf, INFO,
"xwimp_open_window: 0x%x: %s",
1176 error->errnum, error->errmess);
static os_mode mode
The current sprite mode.
static osspriteop_area * buffer
The buffer characteristics.
nserror
Enumeration of error codes.
@ NSERROR_BAD_ENCODING
The character set is unknown.
nserror utf8_to_local_encoding(const char *string, size_t len, char **result)
#define NSLOG(catname, level, logmsg, args...)
Backward compatible defines to make NetSurf buildable with pre-OSLib 7 releases.
#define colourtrans_SET_BG_GCOL
After OSLib 6.90, there was a rename of colourtrans defines in order to avoid namespace clashes: svn ...
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Interface to utility string handling.
UCS conversion tables (interface) This is only used if nothing claims Service_International,...
UTF-8 manipulation functions (interface).
os_error * ro_gui_wimp_get_sprite(const char *name, osspriteop_header **sprite)
Locate a sprite in the Wimp sprite pool, returning a pointer to it.
static wimp_w furniture_window
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.
void ro_gui_set_icon_deleted_state(wimp_w w, wimp_i i, bool state)
Set the deleted state of an icon.
void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask, wimp_window_flags xor_mask)
Sets whether a piece of window furniture is present for a window.
int ro_get_hscroll_height(wimp_w w)
Gets the horizontal scrollbar height.
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_convert_os_units_to_pixels(os_coord *os_units, os_mode mode)
Converts the supplied os_coord from OS units to pixels.
static void ro_gui_wimp_cache_furniture_sizes(wimp_w w)
Caches window furniture information.
void ro_gui_set_icon_button_type(wimp_w w, wimp_i i, int type)
Set the button type of an icon.
void ro_gui_force_redraw_icon(wimp_w w, wimp_i i)
Forces an icon to be redrawn entirely (ie not just updated).
bool ro_gui_wimp_get_sprite_dimensions(osspriteop_area *area, char *sprite, int *width, int *height)
Get the dimensions of a sprite.
bool ro_gui_get_icon_deleted_state(wimp_w w, wimp_i i)
Gets the deleted state of an icon.
void ro_gui_set_window_title(wimp_w w, const char *text)
Set a window title.
int ro_get_title_height(wimp_w w)
Gets the title bar height.
osspriteop_area * ro_gui_load_sprite_file(const char *pathname)
Load a sprite file into memory.
void ro_gui_set_icon_shaded_state(wimp_w w, wimp_i i, bool state)
Set the shaded state of an icon.
bool ro_gui_wimp_sprite_exists(const char *sprite)
Check if a sprite is present in the Wimp sprite pool.
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
static int ro_gui_strncmp(const char *s1, const char *s2, size_t len)
RO GUI-specific strncmp, for control character terminated strings.
bool ro_gui_wimp_read_eig_factors(os_mode mode, int *xeig, int *yeig)
Reads a modes EIG factors.
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_sprite(wimp_w w, wimp_i i, osspriteop_area *area, const char *name)
Set an icon's sprite.
bool ro_gui_set_caret_first(wimp_w w)
Places the caret in the first available icon.
void ro_convert_pixels_to_os_units(os_coord *pixels, os_mode mode)
Converts the supplied os_coord from pixels to OS units.
static wimpextend_furniture_sizes furniture_sizes
static size_t ro_gui_strlen(const char *str)
RO GUI-specific strlen, for control character terminated strings.
#define ro_gui_redraw_icon(w, i)
Redraws an icon.
void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value)
Set the contents of an icon to a number.
void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour)
Performs simple user redraw for a window.
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.
void ro_gui_scroll(wimp_scroll *scroll)
Generic window scroll event handler.
int ro_get_vscroll_width(wimp_w w)
Gets the vertical scrollbar width.
General RISC OS WIMP/OS library functions (interface).
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.