28#include <oslib/colourtrans.h>
29#include <oslib/osbyte.h>
30#include <oslib/serviceinternational.h>
31#include <oslib/wimp.h>
32#include <oslib/wimpspriteop.h>
55#define MAGIC (('T'<<24) | ('E'<<16) | ('X'<<8) | 'T')
83#define LINE_CHUNK_SIZE 256
95 wimp_WINDOW_NEW_FORMAT | wimp_WINDOW_NO_BOUNDS,
97 wimp_COLOUR_LIGHT_GREY,
98 wimp_COLOUR_LIGHT_GREY,
99 wimp_COLOUR_VERY_LIGHT_GREY,
100 wimp_COLOUR_DARK_GREY,
101 wimp_COLOUR_MID_LIGHT_GREY,
104 {0, -16384, 16384, 0},
105 wimp_ICON_TEXT | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED,
106 wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT,
142 NSLOG(netsurf, INFO,
"malloc failed");
150 ret->
text = malloc(64);
152 NSLOG(netsurf, INFO,
"malloc failed");
164 NSLOG(netsurf, INFO,
"strdup failed");
185 NSLOG(netsurf, INFO,
"xwimp_create_window: 0x%x: %s",
186 error->errnum, error->errmess);
210 return (uintptr_t)ret;
221 wimp_window_state state;
222 wimp_icon_state istate;
231 error = xwimp_get_window_state(&state);
233 NSLOG(netsurf, INFO,
"xwimp_get_window_state: 0x%x: %s",
234 error->errnum, error->errmess);
240 error = xwimp_get_icon_state(&istate);
242 NSLOG(netsurf, INFO,
"xwimp_get_icon_state: 0x%x: %s",
243 error->errnum, error->errmess);
248 state.visible.x1 = state.visible.x0 + istate.icon.extent.x1 -
250 state.visible.x0 += istate.icon.extent.x0 + 2 - state.xscroll;
251 state.visible.y0 = state.visible.y1 + istate.icon.extent.y0 +
253 state.visible.y1 += istate.icon.extent.y1 - 2 - state.yscroll;
256 state.visible.x0 += 2;
257 state.visible.x1 -= 4;
258 state.visible.y0 += 2;
259 state.visible.y1 -= 4;
263 ta->
vis_width = state.visible.x1 - state.visible.x0;
264 ta->
vis_height = state.visible.y1 - state.visible.y0;
272 error = xwimp_set_extent(ta->
window, &extent);
274 NSLOG(netsurf, INFO,
"xwimp_set_extent: 0x%x: %s",
275 error->errnum, error->errmess);
281 wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
282 << wimp_CHILD_XORIGIN_SHIFT |
283 wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
284 << wimp_CHILD_YORIGIN_SHIFT |
285 wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
286 << wimp_CHILD_LS_EDGE_SHIFT |
287 wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
288 << wimp_CHILD_RS_EDGE_SHIFT);
290 NSLOG(netsurf, INFO,
"xwimp_open_window_nested: 0x%x: %s",
291 error->errnum, error->errmess);
314 error = xwimp_delete_window(ta->
window);
316 NSLOG(netsurf, INFO,
"xwimp_delete_window: 0x%x: %s",
317 error->errnum, error->errmess);
337 unsigned int len = strlen(
text) + 1;
341 NSLOG(netsurf, INFO,
"magic doesn't match");
346 char *temp = realloc(ta->
text, len + 64);
348 NSLOG(netsurf, INFO,
"realloc failed");
378 NSLOG(netsurf, INFO,
"magic doesn't match");
382 if (buf == NULL && len == 0) {
388 NSLOG(netsurf, INFO,
"buffer too small");
408 unsigned int b_len = strlen(
text);
413 NSLOG(netsurf, INFO,
"magic doesn't match");
423 for (b_off = 0; index-- > 0;
428 char *temp = realloc(ta->
text, b_len + ta->
text_len + 64);
430 NSLOG(netsurf, INFO,
"realloc failed");
439 memmove(ta->
text + b_off + b_len, ta->
text + b_off,
442 memcpy(ta->
text + b_off,
text, b_len);
459 unsigned int end,
const char *
text)
462 int b_len = strlen(
text);
463 size_t b_start, b_end, c_len, diff;
467 NSLOG(netsurf, INFO,
"magic doesn't match");
489 for (b_start = 0; start-- > 0;
493 for (b_end = b_start; diff-- > 0;
498 char *temp = realloc(ta->
text,
499 b_len + ta->
text_len - (b_end - b_start) + 64);
501 NSLOG(netsurf, INFO,
"realloc failed");
507 b_len + ta->
text_len - (b_end - b_start) + 64;
511 memmove(ta->
text + b_start + b_len, ta->
text + b_end,
515 memcpy(ta->
text + b_start,
text, b_len);
517 ta->
text_len += b_len - (b_end - b_start);
536 os_coord os_line_height;
542 NSLOG(netsurf, INFO,
"magic doesn't match");
552 for (b_off = 0; caret > 0; caret--)
572 os_line_height.x = 0;
582 if (code != rufl_OK) {
583 if (code == rufl_FONT_MANAGER_ERROR)
584 NSLOG(netsurf, INFO,
"rufl_width: 0x%x: %s",
585 rufl_fm_error->errnum, rufl_fm_error->errmess);
587 NSLOG(netsurf, INFO,
"rufl_width: 0x%x", code);
594 os_line_height.y, -1);
596 NSLOG(netsurf, INFO,
"xwimp_set_caret_position: 0x%x: %s",
597 error->errnum, error->errmess);
612 wimp_window_state state;
613 size_t b_off, c_off, temp;
615 os_coord os_line_height;
621 NSLOG(netsurf, INFO,
"magic doesn't match");
628 os_line_height.x = 0;
633 error = xwimp_get_window_state(&state);
635 NSLOG(netsurf, INFO,
"xwimp_get_window_state: 0x%x: %s",
636 error->errnum, error->errmess);
640 x = x - (state.visible.x0 - state.xscroll) -
MARGIN_LEFT;
641 y = (state.visible.y1 - state.yscroll) - y;
655 if (code != rufl_OK) {
656 if (code == rufl_FONT_MANAGER_ERROR)
657 NSLOG(netsurf, INFO,
"rufl_x_to_offset: 0x%x: %s",
658 rufl_fm_error->errnum, rufl_fm_error->errmess);
660 NSLOG(netsurf, INFO,
"rufl_x_to_offset: 0x%x", code);
680 size_t c_off = 0, b_off;
684 NSLOG(netsurf, INFO,
"magic doesn't match");
725 NSLOG(netsurf, INFO,
"malloc failed");
741 len -= b_off,
text += b_off) {
746 if (code != rufl_OK) {
747 if (code == rufl_FONT_MANAGER_ERROR)
749 "rufl_x_to_offset: 0x%x: %s",
750 rufl_fm_error->errnum,
751 rufl_fm_error->errmess);
754 "rufl_x_to_offset: 0x%x", code);
763 NSLOG(netsurf, INFO,
"realloc failed");
771 for (space =
text; space <
text + b_off; space++) {
772 if (*space ==
'\r' || *space ==
'\n')
776 if (space !=
text + b_off) {
782 if (*space ==
'\r' && *(space + 1) ==
'\n')
784 else if (*space ==
'\n' && *(space + 1) ==
'\r')
787 b_off = space + 1 -
text;
789 if (len - b_off == 0) {
799 if (len - b_off > 0) {
801 for (space =
text + b_off; space >
text; space--)
806 b_off = space + 1 -
text;
825 error = xwimp_set_extent(ta->
window, &extent);
827 NSLOG(netsurf, INFO,
"xwimp_set_extent: 0x%x: %s",
828 error->errnum, error->errmess);
834 wimp_WINDOW_VSCROLL)) {
835 wimp_window_state state;
838 unsigned int vscroll_width;
842 error = xwimp_get_window_state_and_nesting(&state,
846 "xwimp_get_window_state_and_nesting: 0x%x: %s",
855 wimp_WINDOW_VSCROLL);
859 error = xwimp_get_window_state(&state);
862 "xwimp_get_window_state: 0x%x: %s",
872 state.visible.x1 -= vscroll_width;
879 "xwimp_open_window_nested: 0x%x: %s",
917 uint32_t c = (uint32_t) key->c;
929 (c <= 0x001f || (0x007f <= c && c <= 0x009f)))) {
935 utf8[utf8_len] =
'\0';
950 c_pos - 1, c_pos,
"");
960 case wimp_KEY_DELETE:
962 if (os_version < RISCOS5 && c_pos > 0) {
964 c_pos - 1, c_pos,
"");
990 case wimp_KEY_CONTROL | wimp_KEY_LEFT:
993 case wimp_KEY_CONTROL | wimp_KEY_RIGHT:
996 case wimp_KEY_CONTROL | wimp_KEY_UP:
999 case wimp_KEY_CONTROL | wimp_KEY_DOWN:
1015 case wimp_KEY_RETURN:
1028 case wimp_KEY_ESCAPE:
1030 keypress.w = ta->parent;
1031 keypress.i = ta->icon;
1033 error = xwimp_send_message_to_window(wimp_KEY_PRESSED,
1034 (wimp_message*)&keypress, ta->parent,
1037 NSLOG(netsurf, INFO,
1038 "xwimp_send_message: 0x%x:%s",
1049 update.w = ta->window;
1052 update.box.x1 = ta->vis_width;
1053 update.box.y0 = -ta->line_height * (ta->line_count + 1);
1087 error = xwimp_update_window(redraw, &more);
1089 error = xwimp_redraw_window(redraw, &more);
1091 NSLOG(netsurf, INFO,
"xwimp_redraw_window: 0x%x: %s",
1092 error->errnum, error->errmess);
1098 int clip_y0, clip_y1;
1099 clip_y0 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y1;
1100 clip_y1 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y0;
1102 error = xcolourtrans_set_gcol(
1106 os_ACTION_OVERWRITE, 0, 0);
1108 NSLOG(netsurf, INFO,
1109 "xcolourtrans_set_gcol: 0x%x: %s",
1117 NSLOG(netsurf, INFO,
"xos_clg: 0x%x: %s",
1118 error->errnum, error->errmess);
1144 error = xcolourtrans_set_font_colours(font_CURRENT,
1146 0xD9D9D900 : 0xFFFFFF00,
1147 0x00000000, 14, 0, 0, 0);
1149 NSLOG(netsurf, INFO,
1150 "xcolourtrans_set_font_colours: 0x%x: %s",
1161 redraw->box.y1 - redraw->yscroll -
1165 if (code != rufl_OK) {
1166 if (code == rufl_FONT_MANAGER_ERROR)
1167 NSLOG(netsurf, INFO,
1168 "rufl_paint: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
1169 rufl_fm_error->errnum,
1170 rufl_fm_error->errmess);
1172 NSLOG(netsurf, INFO,
1173 "rufl_paint: 0x%x", code);
1177 error = xwimp_get_rectangle(redraw, &more);
1179 NSLOG(netsurf, INFO,
"xwimp_get_rectangle: 0x%x: %s",
1180 error->errnum, error->errmess);
1195 error = xwimp_open_window(open);
1197 NSLOG(netsurf, INFO,
"xwimp_open_window: 0x%x: %s",
1198 error->errnum, error->errmess);
@ TEXTAREA_READONLY
Non-editable.
@ TEXTAREA_MULTILINE
Multiline area.
void ro_textarea_replace_text(uintptr_t self, unsigned int start, unsigned int end, const char *text)
Replace text in a text area.
static bool ro_textarea_mouse_click(wimp_pointer *pointer)
Handle mouse clicks in a text area.
bool ro_textarea_update(uintptr_t self)
Update the a text area following a change in the parent icon.
bool ro_textarea_set_text(uintptr_t self, const char *text)
Set the text in a text area, discarding any current text.
static void ro_textarea_reflow(struct text_area *ta, unsigned int line)
Reflow a text area from the given line onwards.
static void ro_textarea_open(wimp_open *open)
Handle a WIMP open window request.
int ro_textarea_get_text(uintptr_t self, char *buf, unsigned int len)
Extract the text from a text area.
static wimp_window text_area_definition
unsigned int ro_textarea_get_caret(uintptr_t self)
Get the caret's position.
void ro_textarea_set_caret(uintptr_t self, unsigned int caret)
Set the caret's position.
void ro_textarea_destroy(uintptr_t self)
Destroy a text area.
void ro_textarea_set_caret_xy(uintptr_t self, int x, int y)
Set the caret's position.
uintptr_t ro_textarea_create(wimp_w parent, wimp_i icon, unsigned int flags, const char *font_family, unsigned int font_size, rufl_style font_style)
Create a text area.
static bool ro_textarea_key_press(wimp_key *key)
Handle key presses in a text area.
void ro_textarea_insert_text(uintptr_t self, unsigned int index, const char *text)
Insert text into the text area.
static void ro_textarea_redraw_internal(wimp_draw *redraw, bool update)
Internal textarea redraw routine.
static void ro_textarea_redraw(wimp_draw *redraw)
Handle WIMP redraw requests for text areas.
Single/Multi-line UTF-8 text area (interface)
Netsurf additional integer type formatting macros.
#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 ...
#define colourtrans_USE_ECFS_GCOL
Interface to utility string handling.
unsigned int b_start
Byte offset of line start.
unsigned int b_length
Byte length of line.
unsigned int text_len
Length of text, in bytes.
struct text_area::@48 caret_pos
unsigned int text_alloc
Size of allocated text.
struct line_info * lines
Line info array.
unsigned int vis_width
Visible width, in pixels.
unsigned int magic
Magic word, for sanity.
unsigned int flags
Textarea flags.
unsigned int line_count
Count of lines.
int line_spacing
Height of line spacing, given font size.
struct text_area * prev
Prev text area in list.
wimp_i icon
Parent icon handle.
wimp_w parent
Parent window handle.
unsigned int font_size
Font size (16ths/pt)
unsigned int vis_height
Visible height, in pixels.
unsigned int char_off
Character index of caret.
rufl_style font_style
Font style (rufl)
int line_height
Total height of a line, given font size.
wimp_w window
Window handle.
char * font_family
Font family of text.
unsigned int line
Line caret is on.
struct text_area * next
Next text area in list.
UCS conversion tables (interface) This is only used if nothing claims Service_International,...
size_t utf8_from_ucs4(uint32_t c, char *s)
Convert a single UCS4 character into a UTF-8 multibyte sequence.
size_t utf8_next(const char *s, size_t l, size_t o)
Find next legal UTF-8 char in string.
size_t utf8_length(const char *s)
Calculate the length (in characters) of a NULL-terminated UTF-8 string.
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
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.
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.
void ro_convert_pixels_to_os_units(os_coord *pixels, os_mode mode)
Converts the supplied os_coord from pixels to OS units.
int ro_get_vscroll_width(wimp_w w)
Gets the vertical scrollbar width.
General RISC OS WIMP/OS library functions (interface).
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_redraw_window(wimp_w w, void(*callback)(wimp_draw *redraw))
Register a function to be called for all window redraw operations.
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.
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...
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_open_window(wimp_w w, void(*callback)(wimp_open *open))
Register a function to be called for all window opening requests.
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 line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
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.