|
NetSurf
|
Single/Multi-line UTF-8 text area (implementation) More...
#include <inttypes.h>#include <stdbool.h>#include <stdint.h>#include <string.h>#include <swis.h>#include <oslib/colourtrans.h>#include <oslib/osbyte.h>#include <oslib/serviceinternational.h>#include <oslib/wimp.h>#include <oslib/wimpspriteop.h>#include "utils/log.h"#include "utils/utf8.h"#include "utils/utils.h"#include "riscos/gui.h"#include "riscos/oslib_pre7.h"#include "riscos/textarea.h"#include "riscos/ucstables.h"#include "riscos/wimp.h"#include "riscos/wimp_event.h"#include "riscos/wimputils.h"Go to the source code of this file.
Data Structures | |
| struct | line_info |
| struct | text_area |
Macros | |
| #define | MARGIN_LEFT 8 |
| #define | MARGIN_RIGHT 8 |
| #define | MAGIC (('T'<<24) | ('E'<<16) | ('X'<<8) | 'T') |
| #define | LINE_CHUNK_SIZE 256 |
Functions | |
| static void | ro_textarea_reflow (struct text_area *ta, unsigned int line) |
| Reflow a text area from the given line onwards. More... | |
| static bool | ro_textarea_mouse_click (wimp_pointer *pointer) |
| Handle mouse clicks in a text area. More... | |
| static bool | ro_textarea_key_press (wimp_key *key) |
| Handle key presses in a text area. More... | |
| static void | ro_textarea_redraw (wimp_draw *redraw) |
| Handle WIMP redraw requests for text areas. More... | |
| static void | ro_textarea_redraw_internal (wimp_draw *redraw, bool update) |
| Internal textarea redraw routine. More... | |
| static void | ro_textarea_open (wimp_open *open) |
| Handle a WIMP open window request. More... | |
| 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. More... | |
| bool | ro_textarea_update (uintptr_t self) |
| Update the a text area following a change in the parent icon. More... | |
| void | ro_textarea_destroy (uintptr_t self) |
| Destroy a text area. More... | |
| bool | ro_textarea_set_text (uintptr_t self, const char *text) |
| Set the text in a text area, discarding any current text. More... | |
| int | ro_textarea_get_text (uintptr_t self, char *buf, unsigned int len) |
| Extract the text from a text area. More... | |
| void | ro_textarea_insert_text (uintptr_t self, unsigned int index, const char *text) |
| Insert text into the text area. More... | |
| void | ro_textarea_replace_text (uintptr_t self, unsigned int start, unsigned int end, const char *text) |
| Replace text in a text area. More... | |
| void | ro_textarea_set_caret (uintptr_t self, unsigned int caret) |
| Set the caret's position. More... | |
| void | ro_textarea_set_caret_xy (uintptr_t self, int x, int y) |
| Set the caret's position. More... | |
| unsigned int | ro_textarea_get_caret (uintptr_t self) |
| Get the caret's position. More... | |
Variables | |
| static wimp_window | text_area_definition |
Single/Multi-line UTF-8 text area (implementation)
Definition in file textarea.c.
| #define LINE_CHUNK_SIZE 256 |
Definition at line 83 of file textarea.c.
| #define MAGIC (('T'<<24) | ('E'<<16) | ('X'<<8) | 'T') |
Definition at line 55 of file textarea.c.
| #define MARGIN_LEFT 8 |
Definition at line 46 of file textarea.c.
| #define MARGIN_RIGHT 8 |
Definition at line 47 of file textarea.c.
| 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.
| parent | Parent window |
| icon | Icon in parent window to replace |
| flags | Text area flags |
| font_family | RUfl font family to use, or NULL for default |
| font_size | Font size to use (pt * 16), or 0 for default |
| font_style | Font style to use, or 0 for default |
Definition at line 133 of file textarea.c.
References text_area::caret_pos, text_area::char_off, text_area::flags, text_area::font_family, text_area::font_size, text_area::font_style, text_area::icon, text_area::line, text_area::line_count, text_area::line_height, text_area::line_spacing, text_area::lines, MAGIC, text_area::magic, NSLOG, parent, text_area::parent, ro_gui_wimp_event_register_keypress(), ro_gui_wimp_event_register_mouse_click(), ro_gui_wimp_event_register_open_window(), ro_gui_wimp_event_register_redraw_window(), ro_gui_wimp_event_set_user_data(), ro_textarea_destroy(), ro_textarea_key_press(), ro_textarea_mouse_click(), ro_textarea_open(), ro_textarea_redraw(), ro_textarea_update(), text_area::text, text_area::text_alloc, text_area_definition, text_area::text_len, TEXTAREA_READONLY, and text_area::window.
| void ro_textarea_destroy | ( | uintptr_t | self | ) |
Destroy a text area.
| self | Text area to destroy |
Definition at line 305 of file textarea.c.
References text_area::font_family, MAGIC, text_area::magic, NSLOG, ro_gui_wimp_event_finalise(), text_area::text, and text_area::window.
Referenced by ro_textarea_create().
| unsigned int ro_textarea_get_caret | ( | uintptr_t | self | ) |
Get the caret's position.
| self | Text area |
Definition at line 677 of file textarea.c.
References line_info::b_start, text_area::caret_pos, text_area::char_off, text_area::line, text_area::lines, MAGIC, text_area::magic, NSLOG, text_area::text, text_area::text_len, and utf8_next().
Referenced by ro_textarea_key_press(), and ro_textarea_set_caret().
| int ro_textarea_get_text | ( | uintptr_t | self, |
| char * | buf, | ||
| unsigned int | len | ||
| ) |
Extract the text from a text area.
| self | Text area |
| buf | Pointer to buffer to receive data, or NULL to read length required |
| len | Length (bytes) of buffer pointed to by buf, or 0 to read length |
Definition at line 372 of file textarea.c.
References MAGIC, text_area::magic, NSLOG, text_area::text, and text_area::text_len.
| void ro_textarea_insert_text | ( | uintptr_t | self, |
| unsigned int | index, | ||
| const char * | text | ||
| ) |
Insert text into the text area.
| self | Text area |
| index | 0-based character index to insert at |
| text | UTF-8 text to insert |
Definition at line 404 of file textarea.c.
References MAGIC, text_area::magic, NSLOG, ro_textarea_reflow(), text_area::text, text(), text_area::text_alloc, text_area::text_len, utf8_length(), and utf8_next().
Referenced by ro_textarea_key_press(), and ro_textarea_replace_text().
|
static |
Handle key presses in a text area.
| key | Key pressed state block |
pass on RETURN and ESCAPE to the parent icon
Definition at line 915 of file textarea.c.
References fallthrough, IS_WIMP_KEY, NSLOG, os_version, RISCOS5, ro_gui_wimp_event_get_user_data(), ro_textarea_get_caret(), ro_textarea_insert_text(), ro_textarea_redraw_internal(), ro_textarea_replace_text(), ro_textarea_set_caret(), ro_textarea_set_text(), TEXTAREA_MULTILINE, TEXTAREA_READONLY, utf8_from_ucs4(), and utf8_length().
Referenced by ro_textarea_create().
|
static |
Handle mouse clicks in a text area.
| pointer | Mouse click state block |
Definition at line 899 of file textarea.c.
References ro_gui_wimp_event_get_user_data(), and ro_textarea_set_caret_xy().
Referenced by ro_textarea_create().
|
static |
Handle a WIMP open window request.
| open | OpenWindow block |
Definition at line 1191 of file textarea.c.
References NSLOG.
Referenced by ro_textarea_create().
|
static |
Handle WIMP redraw requests for text areas.
| redraw | Redraw request block |
Definition at line 1065 of file textarea.c.
References ro_textarea_redraw_internal().
Referenced by ro_textarea_create().
|
static |
Internal textarea redraw routine.
| redraw | Redraw/update request block |
| update | True if update, false if full redraw |
Definition at line 1076 of file textarea.c.
References line_info::b_length, line_info::b_start, colourtrans_SET_BG_GCOL, colourtrans_USE_ECFS_GCOL, text_area::flags, text_area::font_family, text_area::font_size, text_area::font_style, line(), text_area::line_count, text_area::line_height, text_area::line_spacing, text_area::lines, MARGIN_LEFT, NSLOG, ro_gui_wimp_event_get_user_data(), text_area::text, and TEXTAREA_READONLY.
Referenced by ro_textarea_key_press(), and ro_textarea_redraw().
|
static |
Reflow a text area from the given line onwards.
| ta | Text area to reflow |
| line | Line number to begin reflow on |
Definition at line 704 of file textarea.c.
References line_info::b_length, line_info::b_start, text_area::flags, text_area::font_family, text_area::font_size, text_area::font_style, LINE_CHUNK_SIZE, text_area::line_count, text_area::line_height, text_area::line_spacing, text_area::lines, MARGIN_LEFT, MARGIN_RIGHT, NSLOG, parent, PTR_WIMP_OPEN, ro_get_vscroll_width(), ro_gui_wimp_check_window_furniture(), ro_gui_wimp_update_window_furniture(), ro_textarea_reflow(), text_area::text, text(), text_area::text_len, TEXTAREA_MULTILINE, text_area::vis_height, text_area::vis_width, and text_area::window.
Referenced by ro_textarea_insert_text(), ro_textarea_reflow(), ro_textarea_replace_text(), ro_textarea_set_text(), and ro_textarea_update().
| void ro_textarea_replace_text | ( | uintptr_t | self, |
| unsigned int | start, | ||
| unsigned int | end, | ||
| const char * | text | ||
| ) |
Replace text in a text area.
| self | Text area |
| start | Start character index of replaced section (inclusive) |
| end | End character index of replaced section (exclusive) |
| text | UTF-8 text to insert |
Definition at line 458 of file textarea.c.
References MAGIC, text_area::magic, NSLOG, ro_textarea_insert_text(), ro_textarea_reflow(), text_area::text, text(), text_area::text_alloc, text_area::text_len, utf8_length(), and utf8_next().
Referenced by ro_textarea_key_press().
| void ro_textarea_set_caret | ( | uintptr_t | self, |
| unsigned int | caret | ||
| ) |
Set the caret's position.
| self | Text area |
| caret | 0-based character index to place caret at |
Definition at line 529 of file textarea.c.
References line_info::b_length, line_info::b_start, text_area::caret_pos, text_area::char_off, text_area::font_family, text_area::font_size, text_area::font_style, text_area::line, text_area::line_count, text_area::line_height, text_area::line_spacing, text_area::lines, MAGIC, text_area::magic, MARGIN_LEFT, NSLOG, ro_convert_pixels_to_os_units(), ro_textarea_get_caret(), text_area::text, text_area::text_len, utf8_length(), utf8_next(), and text_area::window.
Referenced by ro_textarea_key_press(), and ro_textarea_set_caret_xy().
| void ro_textarea_set_caret_xy | ( | uintptr_t | self, |
| int | x, | ||
| int | y | ||
| ) |
Set the caret's position.
| self | Text area |
| x | X position of caret on the screen |
| y | Y position of caret on the screen |
Definition at line 609 of file textarea.c.
References line_info::b_length, line_info::b_start, text_area::flags, text_area::font_family, text_area::font_size, text_area::font_style, line(), text_area::line_count, text_area::line_height, text_area::line_spacing, text_area::lines, MAGIC, text_area::magic, MARGIN_LEFT, NSLOG, ro_convert_pixels_to_os_units(), ro_textarea_set_caret(), text_area::text, text_area::text_len, TEXTAREA_READONLY, utf8_next(), and text_area::window.
Referenced by ro_textarea_mouse_click().
| bool ro_textarea_set_text | ( | uintptr_t | self, |
| const char * | text | ||
| ) |
Set the text in a text area, discarding any current text.
| self | Text area |
| text | UTF-8 text to set text area's contents to |
Definition at line 334 of file textarea.c.
References MAGIC, text_area::magic, NSLOG, ro_textarea_reflow(), text_area::text, text(), text_area::text_alloc, and text_area::text_len.
Referenced by ro_textarea_key_press().
| bool ro_textarea_update | ( | uintptr_t | self | ) |
Update the a text area following a change in the parent icon.
| self | Text area to update |
Definition at line 218 of file textarea.c.
References text_area::flags, text_area::icon, MAGIC, text_area::magic, NSLOG, text_area::parent, PTR_WIMP_OPEN, ro_get_hscroll_height(), ro_get_vscroll_width(), ro_textarea_reflow(), TEXTAREA_READONLY, text_area::vis_height, text_area::vis_width, and text_area::window.
Referenced by ro_textarea_create().
|
static |
Definition at line 90 of file textarea.c.
Referenced by ro_textarea_create().