ELinks 0.18.0
textarea.c File Reference

Textarea form item handlers. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "bfu/dialog.h"
#include "document/document.h"
#include "document/forms.h"
#include "document/view.h"
#include "intl/libintl.h"
#include "session/session.h"
#include "terminal/draw.h"
#include "terminal/window.h"
#include "util/error.h"
#include "util/file.h"
#include "util/memory.h"
#include "util/string.h"
#include "viewer/action.h"
#include "viewer/text/form.h"
#include "viewer/text/textarea.h"
#include "viewer/text/view.h"
Include dependency graph for textarea.c:

Data Structures

struct  line_info
 
struct  textarea_data
 

Macros

#define _GNU_SOURCE   /* XXX: we want memrchr() ! */
 
#define realloc_line_info(info, size)    mem_align_alloc(info, size, (size) + 3, 0xFF)
 We add two extra entries to the table so the ending info can be added without reallocating.
 

Functions

static struct line_infoformat_textutf8 (char *text, int width, enum form_wrap wrap, int format)
 Allocates a line_info table describing the layout of the textarea buffer.
 
static struct line_infoformat_text (char *text, int width, enum form_wrap wrap, int format)
 Allocates a line_info table describing the layout of the textarea buffer.
 
static int get_textarea_line_number (struct line_info *line, int cursor_position)
 Searches for cursor_position (aka.
 
int area_cursor (struct el_form_control *fc, struct form_state *fs, int utf8)
 Fixes up the form_state.vpos and form_state.vypos members.
 
static void draw_textarea_utf8 (struct terminal *term, struct form_state *fs, struct document_view *doc_view, struct link *link)
 
void draw_textarea (struct terminal *term, struct form_state *fs, struct document_view *doc_view, struct link *link)
 
char * encode_textarea (struct submitted_value *sv)
 
static char * save_textarea_file (char *value)
 We use some evil hacking in order to make external textarea editor working.
 
static struct textarea_datainit_textarea_data (struct terminal *term, struct form_state *fs, struct document_view *doc_view, struct link *link)
 
static void done_textarea_data (struct textarea_data *td)
 
void free_textarea_data (struct terminal *term)
 
void textarea_edit (int op, struct terminal *term_, struct form_state *fs_, struct document_view *doc_view_, struct link *link_)
 
void menu_textarea_edit (struct terminal *term, void *xxx, void *ses_)
 
static enum frame_event_status textarea_op (struct form_state *fs, struct el_form_control *fc, int utf8, int(*do_op)(struct form_state *, struct line_info *, int, int))
 
void new_pos (struct form_state *fs, struct line_info *line, int current, int max_cells)
 
static int do_op_home (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_up (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_down (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_end (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_bob (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_eob (struct form_state *fs, struct line_info *line, int current, int utf8)
 
enum frame_event_status textarea_op_home (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_up (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_down (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_end (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_bob (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_eob (struct form_state *fs, struct el_form_control *fc, int utf8)
 Set the form state so the cursor is on the last line of the buffer.
 
enum frame_event_status textarea_op_enter (struct form_state *fs, struct el_form_control *fc, int utf8)
 
static int do_op_left (struct form_state *fs, struct line_info *line, int current, int utf8)
 
static int do_op_right (struct form_state *fs, struct line_info *line, int current, int utf8)
 
enum frame_event_status textarea_op_left (struct form_state *fs, struct el_form_control *fc, int utf8)
 
enum frame_event_status textarea_op_right (struct form_state *fs, struct el_form_control *fc, int utf8)
 
void set_textarea (struct document_view *doc_view, int direction)
 

Detailed Description

Textarea form item handlers.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* XXX: we want memrchr() ! */

◆ realloc_line_info

#define realloc_line_info ( info,
size )    mem_align_alloc(info, size, (size) + 3, 0xFF)

We add two extra entries to the table so the ending info can be added without reallocating.

Function Documentation

◆ area_cursor()

int area_cursor ( struct el_form_control * fc,
struct form_state * fs,
int utf8 )

Fixes up the form_state.vpos and form_state.vypos members.

Returns
the logical position in the textarea view.

◆ do_op_bob()

static int do_op_bob ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_down()

static int do_op_down ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_end()

static int do_op_end ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_eob()

static int do_op_eob ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_home()

static int do_op_home ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_left()

static int do_op_left ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_right()

static int do_op_right ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ do_op_up()

static int do_op_up ( struct form_state * fs,
struct line_info * line,
int current,
int utf8 )
static

◆ done_textarea_data()

static void done_textarea_data ( struct textarea_data * td)
static

◆ draw_textarea()

void draw_textarea ( struct terminal * term,
struct form_state * fs,
struct document_view * doc_view,
struct link * link )

◆ draw_textarea_utf8()

static void draw_textarea_utf8 ( struct terminal * term,
struct form_state * fs,
struct document_view * doc_view,
struct link * link )
static

◆ encode_textarea()

char * encode_textarea ( struct submitted_value * sv)

◆ format_text()

static struct line_info * format_text ( char * text,
int width,
enum form_wrap wrap,
int format )
static

Allocates a line_info table describing the layout of the textarea buffer.

Parameters
textthe text to format; must be in a unibyte charset
widthis max width and the offset at which text will be wrapped
wrapcontrols how the wrapping of text is performed
formatis non zero the text will be modified to make it suitable for encoding it for form posting

◆ format_textutf8()

static struct line_info * format_textutf8 ( char * text,
int width,
enum form_wrap wrap,
int format )
static

Allocates a line_info table describing the layout of the textarea buffer.

Parameters
textthe text to format; must be in UTF-8
widthis max width and the offset at which text will be wrapped
wrapcontrols how the wrapping of text is performed
formatis non zero the text will be modified to make it suitable for encoding it for form posting

◆ free_textarea_data()

void free_textarea_data ( struct terminal * term)

◆ get_textarea_line_number()

static int get_textarea_line_number ( struct line_info * line,
int cursor_position )
static

Searches for cursor_position (aka.

position in the form_state.value string) for the corresponding entry in the line info. Returns the index or -1 if position is not found.

◆ init_textarea_data()

static struct textarea_data * init_textarea_data ( struct terminal * term,
struct form_state * fs,
struct document_view * doc_view,
struct link * link )
static

◆ menu_textarea_edit()

void menu_textarea_edit ( struct terminal * term,
void * xxx,
void * ses_ )

◆ new_pos()

void new_pos ( struct form_state * fs,
struct line_info * line,
int current,
int max_cells )

◆ save_textarea_file()

static char * save_textarea_file ( char * value)
static

We use some evil hacking in order to make external textarea editor working.

We need to have some way how to be notified that the editor finished and we should reload content of the textarea. So we use global variable textarea_editor as a flag whether we have one running, and if we have, we just call textarea_edit(1, ...). Then we recover our state from static variables, reload content of textarea back from file and clean up.

Unfortunately, we can't support calling of editor from non-master links session, as it would be extremely ugly to hack (you would have to transfer the content of it back to master somehow, add special flags for not deleting of 'delete' etc) and I'm not going to do that now. Inter-links communication NEEDS rewrite, as it looks just like quick messy hack now. –pasky

◆ set_textarea()

void set_textarea ( struct document_view * doc_view,
int direction )

◆ textarea_edit()

void textarea_edit ( int op,
struct terminal * term_,
struct form_state * fs_,
struct document_view * doc_view_,
struct link * link_ )

◆ textarea_op()

static enum frame_event_status textarea_op ( struct form_state * fs,
struct el_form_control * fc,
int utf8,
int(* do_op )(struct form_state *, struct line_info *, int, int) )
static

◆ textarea_op_bob()

enum frame_event_status textarea_op_bob ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_down()

enum frame_event_status textarea_op_down ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_end()

enum frame_event_status textarea_op_end ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_enter()

enum frame_event_status textarea_op_enter ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_eob()

enum frame_event_status textarea_op_eob ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

Set the form state so the cursor is on the last line of the buffer.

Preserve the column if possible. This is done by getting current and last line and then shifting the state by the delta of both lines start position bounding the whole thing to the end of the last line.

◆ textarea_op_home()

enum frame_event_status textarea_op_home ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_left()

enum frame_event_status textarea_op_left ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_right()

enum frame_event_status textarea_op_right ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )

◆ textarea_op_up()

enum frame_event_status textarea_op_up ( struct form_state * fs,
struct el_form_control * fc,
int utf8 )