NetSurf
Macros | Functions
text.c File Reference
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <libnsfb.h>
#include <libnsfb_plot.h>
#include <libnsfb_plot_util.h>
#include <libnsfb_event.h>
#include "utils/log.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
#include "framebuffer/font.h"
#include "framebuffer/framebuffer.h"
#include "framebuffer/image_data.h"
#include "widget.h"
Include dependency graph for text.c:

Go to the source code of this file.

Macros

#define brighten_colour(c1)
 
#define px_to_pt(x)   (((x) * 72) / FBTK_DPI)
 

Functions

static void fb_text_font_style (fbtk_widget_t *widget, int *font_height, int *padding, plot_font_style_t *font_style)
 
static int fb_redraw_text (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Text redraw callback. More...
 
static int fb_destroy_text (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Text destroy callback. More...
 
static int fb_redraw_text_button (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Text button redraw callback. More...
 
static void fb_text_input_remove_caret_cb (fbtk_widget_t *widget)
 
static int text_input (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Routine called when text events occour in writeable widget. More...
 
static int text_input_click (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Routine called when click events occour in writeable widget. More...
 
static int text_input_strip_focus (fbtk_widget_t *widget, fbtk_callback_info *cbi)
 Routine called when "stripped of focus" event occours for writeable widget. More...
 
void fbtk_writable_text (fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
 Alter a text widget to be writable. More...
 
void fbtk_set_text (fbtk_widget_t *widget, const char *text)
 Change the text of a text widget. More...
 
fbtk_widget_tfbtk_create_text (fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, bool outline)
 Create a text widget. More...
 
fbtk_widget_tfbtk_create_writable_text (fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, bool outline, fbtk_enter_t enter, void *pw)
 Create a writable text widget. More...
 
fbtk_widget_tfbtk_create_text_button (fbtk_widget_t *parent, int x, int y, int width, int height, colour bg, colour fg, fbtk_callback click, void *pw)
 Create a button with text. More...
 

Macro Definition Documentation

◆ brighten_colour

#define brighten_colour (   c1)
Value:
(((((7 * ((c1 >> 16) & 0xff)) >> 3) + 32) << 16) | \
((((7 * ((c1 >> 8) & 0xff)) >> 3) + 32) << 8) | \
((((7 * (c1 & 0xff)) >> 3) + 32) << 0))

Definition at line 47 of file text.c.

◆ px_to_pt

#define px_to_pt (   x)    (((x) * 72) / FBTK_DPI)

Definition at line 53 of file text.c.

Function Documentation

◆ fb_destroy_text()

static int fb_destroy_text ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Text destroy callback.

Called when a text widget is destroyed.

Parameters
widgetThe widget being destroyed.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 188 of file text.c.

References FB_WIDGET_TYPE_TEXT, fbtk_widget_s::text, fbtk_widget_s::type, and fbtk_widget_s::u.

Referenced by fbtk_create_text(), fbtk_create_text_button(), and fbtk_create_writable_text().

Here is the caller graph for this function:

◆ fb_redraw_text()

static int fb_redraw_text ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Text redraw callback.

Called when a text widget requires redrawing.

Parameters
widgetThe widget to be redrawn.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 90 of file text.c.

References fbtk_widget_s::bg, fb_plotters, fb_text_font_style(), fbtk_get_bbox(), fbtk_get_caret(), fbtk_get_nsfb(), fbtk_get_root_widget(), redraw_context::interactive, line(), nsfb, redraw_context::plot, root, fbtk_widget_s::text, plotter_table::text, fbtk_widget_s::u, fbtk_widget_s::width, rect::x1, and rect::y1.

Referenced by fbtk_create_text(), and fbtk_create_writable_text().

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

◆ fb_redraw_text_button()

static int fb_redraw_text_button ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Text button redraw callback.

Called when a text widget requires redrawing.

Parameters
widgetThe widget to be redrawn.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 210 of file text.c.

References fbtk_widget_s::bg, brighten_colour, darken_colour, fb_plotters, fb_text_font_style(), fbtk_get_bbox(), fbtk_get_root_widget(), redraw_context::interactive, line(), redraw_context::plot, root, fbtk_widget_s::text, plotter_table::text, fbtk_widget_s::u, rect::x0, rect::x1, rect::y0, and rect::y1.

Referenced by fbtk_create_text_button().

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

◆ fb_text_font_style()

static void fb_text_font_style ( fbtk_widget_t widget,
int *  font_height,
int *  padding,
plot_font_style_t font_style 
)
inlinestatic

◆ fb_text_input_remove_caret_cb()

static void fb_text_input_remove_caret_cb ( fbtk_widget_t widget)
static

Definition at line 286 of file text.c.

References fbtk_get_caret(), and fbtk_request_redraw().

Referenced by fbtk_set_text(), text_input(), and text_input_click().

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

◆ fbtk_create_text()

fbtk_widget_t * fbtk_create_text ( fbtk_widget_t window,
int  x,
int  y,
int  width,
int  height,
colour  bg,
colour  fg,
bool  outline 
)

Create a text widget.

Parameters
windowThe window to add the text widget to.
xX coordinate of widget.
yY coordinate of widget.
widthWidth of the widget
heightHeight of the widget
bgbackground colour
fgforeground colour
outlinewidget will have a border.
Returns
new widget handle or NULL on error.

Definition at line 581 of file text.c.

References fbtk_widget_s::bg, fb_destroy_text(), fb_redraw_text(), FB_WIDGET_TYPE_TEXT, FBTK_CBT_DESTROY, FBTK_CBT_REDRAW, fbtk_set_handler(), fbtk_widget_new(), fbtk_widget_s::fg, height, fbtk_widget_s::mapped, parent, fbtk_widget_s::text, fbtk_widget_s::u, and width.

Referenced by create_normal_browser_window().

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

◆ fbtk_create_text_button()

fbtk_widget_t * fbtk_create_text_button ( fbtk_widget_t window,
int  x,
int  y,
int  width,
int  height,
colour  bg,
colour  fg,
fbtk_callback  click,
void *  pw 
)

Create a button with text.

Parameters
windowThe window to add the text widget to.
xX coordinate of widget.
yY coordinate of widget.
widthWidth of the widget
heightHeight of the widget
bgbackground colour
fgforeground colour
clickThe callback upon a click
pwThe context tp pass to the callback
Returns
new widget handle or NULL on error.

Definition at line 639 of file text.c.

References fbtk_widget_s::bg, fb_destroy_text(), fb_redraw_text_button(), FB_WIDGET_TYPE_TEXT, FBTK_CBT_CLICK, FBTK_CBT_DESTROY, FBTK_CBT_POINTERENTER, FBTK_CBT_REDRAW, fbtk_set_handler(), fbtk_set_ptr(), fbtk_widget_new(), fbtk_widget_s::fg, hand_image, height, fbtk_widget_s::mapped, parent, fbtk_widget_s::text, fbtk_widget_s::u, and width.

Referenced by create_normal_browser_window(), and fbtk_enable_oskb().

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

◆ fbtk_create_writable_text()

fbtk_widget_t * fbtk_create_writable_text ( fbtk_widget_t window,
int  x,
int  y,
int  width,
int  height,
colour  bg,
colour  fg,
bool  outline,
fbtk_enter_t  enter,
void *  pw 
)

Create a writable text widget.

Helper function which creates a text widget and configures an input handler to create a writable text field. This call is equivalent to calling fbtk_create_text followed by fbtk_writable_text

Parameters
windowThe window to add the text widget to.
xX coordinate of widget.
yY coordinate of widget.
widthWidth of the widget
heightHeight of the widget
bgbackground colour
fgforeground colour
outlinewidget will have a border.
enterCallback when enter is pressed in widget.
pwContext pointer passed to entry callback.
Returns
new widget handle or NULL on error.

Definition at line 606 of file text.c.

References fbtk_widget_s::bg, fb_destroy_text(), fb_redraw_text(), FB_WIDGET_TYPE_TEXT, FBTK_CBT_CLICK, FBTK_CBT_DESTROY, FBTK_CBT_INPUT, FBTK_CBT_REDRAW, FBTK_CBT_STRIP_FOCUS, fbtk_set_handler(), fbtk_widget_new(), fbtk_widget_s::fg, height, fbtk_widget_s::mapped, parent, fbtk_widget_s::text, text_input(), text_input_click(), text_input_strip_focus(), fbtk_widget_s::u, and width.

Referenced by create_toolbar().

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

◆ fbtk_set_text()

void fbtk_set_text ( fbtk_widget_t widget,
const char *  text 
)

Change the text of a text widget.

Parameters
widgetText widget.
textThe new UTF-8 text to put in the widget.

Definition at line 542 of file text.c.

References fb_font_width(), fb_text_font_style(), fb_text_input_remove_caret_cb(), FB_WIDGET_TYPE_TEXT, fbtk_get_caret(), fbtk_request_redraw(), fbtk_set_caret(), fbtk_widget_s::height, fbtk_widget_s::text, text(), fbtk_widget_s::type, and fbtk_widget_s::u.

Referenced by fbtk_enable_oskb(), gui_window_set_status(), and gui_window_set_url().

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

◆ fbtk_writable_text()

void fbtk_writable_text ( fbtk_widget_t widget,
fbtk_enter_t  enter,
void *  pw 
)

Alter a text widget to be writable.

Parameters
widgetText widget.
enterThe routine to call when enter is pressed.
pwThe context to pass to the enter callback routine.

Definition at line 532 of file text.c.

References FBTK_CBT_INPUT, fbtk_set_handler(), fbtk_widget_s::text, text_input(), and fbtk_widget_s::u.

Here is the call graph for this function:

◆ text_input()

static int text_input ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Routine called when text events occour in writeable widget.

Parameters
widgetThe widget reciving input events.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 302 of file text.c.

References fbtk_callback_info::event, fb_font_width(), fb_text_font_style(), fb_text_input_remove_caret_cb(), fbtk_keycode_to_ucs4(), FBTK_MOD_CLEAR, FBTK_MOD_LCTRL, FBTK_MOD_LSHIFT, FBTK_MOD_RCTRL, FBTK_MOD_RSHIFT, fbtk_request_redraw(), fbtk_set_caret(), fbtk_widget_s::height, fbtk_widget_s::text, and fbtk_widget_s::u.

Referenced by fbtk_create_writable_text(), and fbtk_writable_text().

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

◆ text_input_click()

static int text_input_click ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Routine called when click events occour in writeable widget.

Parameters
widgetThe widget reciving click events.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 489 of file text.c.

References fb_font_position(), fb_text_font_style(), fb_text_input_remove_caret_cb(), fbtk_request_redraw(), fbtk_set_caret(), fbtk_widget_s::height, fbtk_widget_s::text, fbtk_widget_s::u, and fbtk_callback_info::x.

Referenced by fbtk_create_writable_text().

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

◆ text_input_strip_focus()

static int text_input_strip_focus ( fbtk_widget_t widget,
fbtk_callback_info cbi 
)
static

Routine called when "stripped of focus" event occours for writeable widget.

Parameters
widgetThe widget reciving "stripped of focus" event.
cbiThe callback parameters.
Returns
The callback result.

Definition at line 523 of file text.c.

References fbtk_set_caret().

Referenced by fbtk_create_writable_text().

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