NetSurf
Macros | Functions
textarea.h File Reference

Single/Multi-line UTF-8 text area (interface) More...

#include <stdbool.h>
#include <stdint.h>
#include "rufl.h"
#include "oslib/wimp.h"
Include dependency graph for textarea.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define TEXTAREA_MULTILINE   0x01
 Text area is multiline. More...
 
#define TEXTAREA_READONLY   0x02
 Text area is read only. More...
 

Functions

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...
 

Detailed Description

Single/Multi-line UTF-8 text area (interface)

Definition in file textarea.h.

Macro Definition Documentation

◆ TEXTAREA_MULTILINE

#define TEXTAREA_MULTILINE   0x01

Text area is multiline.

Definition at line 31 of file textarea.h.

◆ TEXTAREA_READONLY

#define TEXTAREA_READONLY   0x02

Text area is read only.

Definition at line 32 of file textarea.h.

Function Documentation

◆ ro_textarea_create()

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.

Parameters
parentParent window
iconIcon in parent window to replace
flagsText area flags
font_familyRUfl font family to use, or NULL for default
font_sizeFont size to use (pt * 16), or 0 for default
font_styleFont style to use, or 0 for default
Returns
Opaque handle for textarea or 0 on error
Todo:
Better line height calculation

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.

Here is the call graph for this function:

◆ ro_textarea_destroy()

void ro_textarea_destroy ( uintptr_t  self)

Destroy a text area.

Parameters
selfText 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_get_caret()

unsigned int ro_textarea_get_caret ( uintptr_t  self)

Get the caret's position.

Parameters
selfText area
Returns
0-based character index of caret location, or -1 on error

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_get_text()

int ro_textarea_get_text ( uintptr_t  self,
char *  buf,
unsigned int  len 
)

Extract the text from a text area.

Parameters
selfText area
bufPointer to buffer to receive data, or NULL to read length required
lenLength (bytes) of buffer pointed to by buf, or 0 to read length
Returns
Length (bytes) written/required or -1 on error

Definition at line 372 of file textarea.c.

References MAGIC, text_area::magic, NSLOG, text_area::text, and text_area::text_len.

◆ ro_textarea_insert_text()

void ro_textarea_insert_text ( uintptr_t  self,
unsigned int  index,
const char *  text 
)

Insert text into the text area.

Parameters
selfText area
index0-based character index to insert at
textUTF-8 text to insert
Todo:
calculate line to reflow from

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_replace_text()

void ro_textarea_replace_text ( uintptr_t  self,
unsigned int  start,
unsigned int  end,
const char *  text 
)

Replace text in a text area.

Parameters
selfText area
startStart character index of replaced section (inclusive)
endEnd character index of replaced section (exclusive)
textUTF-8 text to insert
Todo:
calculate line to reflow from

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_set_caret()

void ro_textarea_set_caret ( uintptr_t  self,
unsigned int  caret 
)

Set the caret's position.

Parameters
selfText area
caret0-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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_set_caret_xy()

void ro_textarea_set_caret_xy ( uintptr_t  self,
int  x,
int  y 
)

Set the caret's position.

Parameters
selfText area
xX position of caret on the screen
yY 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_set_text()

bool ro_textarea_set_text ( uintptr_t  self,
const char *  text 
)

Set the text in a text area, discarding any current text.

Parameters
selfText area
textUTF-8 text to set text area's contents to
Returns
true on success, false on memory exhaustion

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_textarea_update()

bool ro_textarea_update ( uintptr_t  self)

Update the a text area following a change in the parent icon.

Parameters
selfText 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().

Here is the call graph for this function:
Here is the caller graph for this function: