2010-07-07 22:08:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Vincent Sanders <vince@simtec.co.uk>
|
|
|
|
*
|
|
|
|
* Framebuffer windowing toolkit scrollbar widgets.
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2011-01-06 12:24:14 +03:00
|
|
|
#include <stdlib.h>
|
2010-07-07 22:08:17 +04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libnsfb.h>
|
|
|
|
#include <libnsfb_plot.h>
|
|
|
|
#include <libnsfb_plot_util.h>
|
|
|
|
#include <libnsfb_event.h>
|
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "desktop/browser.h"
|
2012-07-31 23:43:43 +04:00
|
|
|
#include "render/font.h"
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
#include "framebuffer/gui.h"
|
|
|
|
#include "framebuffer/fbtk.h"
|
2012-07-31 23:43:43 +04:00
|
|
|
#include "framebuffer/font.h"
|
2011-06-30 19:48:07 +04:00
|
|
|
#include "framebuffer/framebuffer.h"
|
2010-07-07 22:08:17 +04:00
|
|
|
#include "framebuffer/image_data.h"
|
|
|
|
|
|
|
|
#include "widget.h"
|
|
|
|
|
2011-03-21 10:51:37 +03:00
|
|
|
//#define TEXT_WIDGET_BORDER 3 /**< The pixel border round a text widget. */
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
/* Lighten a colour by taking seven eights of each channel's intensity
|
|
|
|
* and adding a full eighth
|
|
|
|
*/
|
|
|
|
#define brighten_colour(c1) \
|
|
|
|
(((((7 * ((c1 >> 16) & 0xff)) >> 3) + 32) << 16) | \
|
|
|
|
((((7 * ((c1 >> 8) & 0xff)) >> 3) + 32) << 8) | \
|
|
|
|
((((7 * (c1 & 0xff)) >> 3) + 32) << 0))
|
|
|
|
|
2011-03-13 13:52:09 +03:00
|
|
|
/* Convert pixels to points, assuming a DPI of 90 */
|
2011-03-21 10:51:37 +03:00
|
|
|
#define px_to_pt(x) (((x) * 72) / FBTK_DPI)
|
2011-03-13 13:52:09 +03:00
|
|
|
|
2012-07-31 17:06:57 +04:00
|
|
|
/* Get a font style for a text input */
|
|
|
|
static inline void
|
2012-07-31 23:43:43 +04:00
|
|
|
fb_text_font_style(fbtk_widget_t *widget, int *font_height, int *padding,
|
2012-07-31 17:06:57 +04:00
|
|
|
plot_font_style_t *font_style)
|
|
|
|
{
|
2012-07-31 23:43:43 +04:00
|
|
|
if (widget->u.text.outline)
|
|
|
|
*padding = 1;
|
|
|
|
else
|
|
|
|
*padding = 0;
|
|
|
|
|
|
|
|
#ifdef FB_USE_FREETYPE
|
|
|
|
*padding += widget->height / 6;
|
|
|
|
*font_height = widget->height - *padding - *padding;
|
|
|
|
#else
|
|
|
|
*font_height = font_regular.height;
|
|
|
|
*padding = (widget->height - *padding - *font_height) / 2;
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 17:06:57 +04:00
|
|
|
font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
|
2012-07-31 23:43:43 +04:00
|
|
|
font_style->size = px_to_pt(*font_height) * FONT_SIZE_SCALE;
|
2012-07-31 17:06:57 +04:00
|
|
|
font_style->weight = 400;
|
|
|
|
font_style->flags = FONTF_NONE;
|
|
|
|
font_style->background = widget->bg;
|
|
|
|
font_style->foreground = widget->fg;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:08:17 +04:00
|
|
|
/** Text redraw callback.
|
|
|
|
*
|
|
|
|
* Called when a text widget requires redrawing.
|
|
|
|
*
|
|
|
|
* @param widget The widget to be redrawn.
|
|
|
|
* @param cbi The callback parameters.
|
|
|
|
* @return The callback result.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
|
|
|
|
{
|
|
|
|
nsfb_bbox_t bbox;
|
|
|
|
nsfb_bbox_t rect;
|
|
|
|
fbtk_widget_t *root;
|
|
|
|
plot_font_style_t font_style;
|
2012-07-31 23:43:43 +04:00
|
|
|
int caret_x, caret_y, caret_h;
|
2010-07-07 22:08:17 +04:00
|
|
|
int fh;
|
2011-03-21 10:51:37 +03:00
|
|
|
int padding;
|
2010-07-07 22:08:17 +04:00
|
|
|
|
2012-07-31 23:43:43 +04:00
|
|
|
fb_text_font_style(widget, &fh, &padding, &font_style);
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
root = fbtk_get_root_widget(widget);
|
|
|
|
|
|
|
|
fbtk_get_bbox(widget, &bbox);
|
|
|
|
|
|
|
|
rect = bbox;
|
|
|
|
|
|
|
|
nsfb_claim(root->u.root.fb, &bbox);
|
|
|
|
|
|
|
|
/* clear background */
|
|
|
|
if ((widget->bg & 0xFF000000) != 0) {
|
|
|
|
/* transparent polygon filling isnt working so fake it */
|
|
|
|
nsfb_plot_rectangle_fill(root->u.root.fb, &bbox, widget->bg);
|
|
|
|
}
|
|
|
|
|
2011-03-21 10:51:37 +03:00
|
|
|
/* widget can have a single pixel outline border */
|
2010-07-07 22:08:17 +04:00
|
|
|
if (widget->u.text.outline) {
|
|
|
|
rect.x1--;
|
|
|
|
rect.y1--;
|
2012-07-31 23:43:43 +04:00
|
|
|
nsfb_plot_rectangle(root->u.root.fb, &rect, 1,
|
|
|
|
0x00000000, false, false);
|
2010-07-07 22:08:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (widget->u.text.text != NULL) {
|
2012-07-31 23:43:43 +04:00
|
|
|
FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d "
|
|
|
|
"font h %d padding %d",
|
2010-07-07 22:08:17 +04:00
|
|
|
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
|
2011-03-21 10:51:37 +03:00
|
|
|
widget->width, widget->height, fh, padding));
|
2012-07-31 23:43:43 +04:00
|
|
|
/* Call the fb text plotting, baseline is 3/4 down the font */
|
2011-06-30 19:48:07 +04:00
|
|
|
fb_plotters.text(bbox.x0 + padding,
|
2012-07-31 23:43:43 +04:00
|
|
|
bbox.y0 + ((fh * 3) / 4) + padding,
|
|
|
|
widget->u.text.text,
|
|
|
|
widget->u.text.len,
|
|
|
|
&font_style);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
|
|
|
|
/* This widget has caret, so render it */
|
|
|
|
nsfb_t *nsfb = fbtk_get_nsfb(widget);
|
|
|
|
nsfb_bbox_t line;
|
|
|
|
nsfb_plot_pen_t pen;
|
|
|
|
|
|
|
|
line.x0 = bbox.x0 + caret_x;
|
|
|
|
line.y0 = bbox.y0 + caret_y;
|
|
|
|
line.x1 = bbox.x0 + caret_x;
|
|
|
|
line.y1 = bbox.y0 + caret_y + caret_h;
|
|
|
|
|
|
|
|
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
|
|
|
|
pen.stroke_width = 1;
|
|
|
|
pen.stroke_colour = 0xFF0000FF;
|
|
|
|
|
|
|
|
nsfb_plot_line(nsfb, &line, &pen);
|
2010-07-07 22:08:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsfb_update(root->u.root.fb, &bbox);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Text button redraw callback.
|
|
|
|
*
|
|
|
|
* Called when a text widget requires redrawing.
|
|
|
|
*
|
|
|
|
* @param widget The widget to be redrawn.
|
|
|
|
* @param cbi The callback parameters.
|
|
|
|
* @return The callback result.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
|
|
|
|
{
|
|
|
|
nsfb_bbox_t bbox;
|
|
|
|
nsfb_bbox_t rect;
|
|
|
|
nsfb_bbox_t line;
|
|
|
|
nsfb_plot_pen_t pen;
|
|
|
|
plot_font_style_t font_style;
|
2012-07-31 23:43:43 +04:00
|
|
|
int caret_x, caret_y, caret_h;
|
2010-07-07 22:08:17 +04:00
|
|
|
int fh;
|
|
|
|
int border;
|
|
|
|
fbtk_widget_t *root = fbtk_get_root_widget(widget);
|
|
|
|
|
2012-07-31 23:43:43 +04:00
|
|
|
fb_text_font_style(widget, &fh, &border, &font_style);
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
|
|
|
|
pen.stroke_width = 1;
|
|
|
|
pen.stroke_colour = brighten_colour(widget->bg);
|
|
|
|
|
|
|
|
fbtk_get_bbox(widget, &bbox);
|
|
|
|
|
|
|
|
rect = bbox;
|
|
|
|
rect.x1--;
|
|
|
|
rect.y1--;
|
|
|
|
|
|
|
|
nsfb_claim(root->u.root.fb, &bbox);
|
|
|
|
|
|
|
|
/* clear background */
|
|
|
|
if ((widget->bg & 0xFF000000) != 0) {
|
|
|
|
/* transparent polygon filling isnt working so fake it */
|
|
|
|
nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget->u.text.outline) {
|
|
|
|
line.x0 = rect.x0;
|
|
|
|
line.y0 = rect.y0;
|
|
|
|
line.x1 = rect.x0;
|
|
|
|
line.y1 = rect.y1;
|
|
|
|
nsfb_plot_line(root->u.root.fb, &line, &pen);
|
|
|
|
line.x0 = rect.x0;
|
|
|
|
line.y0 = rect.y0;
|
|
|
|
line.x1 = rect.x1;
|
|
|
|
line.y1 = rect.y0;
|
|
|
|
nsfb_plot_line(root->u.root.fb, &line, &pen);
|
|
|
|
pen.stroke_colour = darken_colour(widget->bg);
|
|
|
|
line.x0 = rect.x0;
|
|
|
|
line.y0 = rect.y1;
|
|
|
|
line.x1 = rect.x1;
|
|
|
|
line.y1 = rect.y1;
|
|
|
|
nsfb_plot_line(root->u.root.fb, &line, &pen);
|
|
|
|
line.x0 = rect.x1;
|
|
|
|
line.y0 = rect.y0;
|
|
|
|
line.x1 = rect.x1;
|
|
|
|
line.y1 = rect.y1;
|
|
|
|
nsfb_plot_line(root->u.root.fb, &line, &pen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget->u.text.text != NULL) {
|
|
|
|
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
|
|
|
|
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
|
|
|
|
widget->width, widget->height, fh, border));
|
2012-07-31 23:43:43 +04:00
|
|
|
/* Call the fb text plotting, baseline is 3/4 down the font */
|
2011-06-30 19:48:07 +04:00
|
|
|
fb_plotters.text(bbox.x0 + border,
|
2012-07-31 23:43:43 +04:00
|
|
|
bbox.y0 + ((fh * 3) / 4) + border,
|
|
|
|
widget->u.text.text,
|
|
|
|
widget->u.text.len,
|
|
|
|
&font_style);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
|
|
|
|
/* This widget has caret, so render it */
|
|
|
|
nsfb_t *nsfb = fbtk_get_nsfb(widget);
|
|
|
|
nsfb_bbox_t line;
|
|
|
|
nsfb_plot_pen_t pen;
|
|
|
|
|
|
|
|
line.x0 = bbox.x0 + caret_x;
|
|
|
|
line.y0 = bbox.y0 + caret_y;
|
|
|
|
line.x1 = bbox.x0 + caret_x;
|
|
|
|
line.y1 = bbox.y0 + caret_y + caret_h;
|
|
|
|
|
|
|
|
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
|
|
|
|
pen.stroke_width = 1;
|
|
|
|
pen.stroke_colour = 0xFF0000FF;
|
|
|
|
|
|
|
|
nsfb_plot_line(nsfb, &line, &pen);
|
2010-07-07 22:08:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsfb_update(root->u.root.fb, &bbox);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-31 23:43:43 +04:00
|
|
|
static void
|
|
|
|
fb_text_input_remove_caret_cb(fbtk_widget_t *widget)
|
|
|
|
{
|
|
|
|
int c_x, c_y, c_h;
|
|
|
|
|
|
|
|
if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
|
|
|
|
fbtk_request_redraw(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:08:17 +04:00
|
|
|
/** Routine called when text events occour in writeable widget.
|
|
|
|
*
|
|
|
|
* @param widget The widget reciving input events.
|
|
|
|
* @param cbi The callback parameters.
|
|
|
|
* @return The callback result.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
static uint8_t modifier = 0;
|
|
|
|
char *temp;
|
2012-07-31 23:43:43 +04:00
|
|
|
plot_font_style_t font_style;
|
|
|
|
int fh;
|
|
|
|
int border;
|
|
|
|
|
|
|
|
fb_text_font_style(widget, &fh, &border, &font_style);
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
if (cbi->event == NULL) {
|
|
|
|
/* gain focus */
|
|
|
|
if (widget->u.text.text == NULL)
|
|
|
|
widget->u.text.text = calloc(1,1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = cbi->event->value.keycode;
|
|
|
|
|
|
|
|
if (cbi->event->type != NSFB_EVENT_KEY_DOWN) {
|
|
|
|
switch (value) {
|
|
|
|
case NSFB_KEY_RSHIFT:
|
|
|
|
modifier &= ~1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_LSHIFT:
|
|
|
|
modifier &= ~(1<<1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case NSFB_KEY_BACKSPACE:
|
|
|
|
if (widget->u.text.idx <= 0)
|
|
|
|
break;
|
2012-07-31 18:13:52 +04:00
|
|
|
memmove(widget->u.text.text + widget->u.text.idx - 1,
|
|
|
|
widget->u.text.text + widget->u.text.idx,
|
|
|
|
widget->u.text.len - widget->u.text.idx);
|
2010-07-07 22:08:17 +04:00
|
|
|
widget->u.text.idx--;
|
2012-07-31 18:13:52 +04:00
|
|
|
widget->u.text.len--;
|
|
|
|
widget->u.text.text[widget->u.text.len] = 0;
|
2012-07-31 23:43:43 +04:00
|
|
|
|
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.len, &widget->u.text.width);
|
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.idx, &widget->u.text.idx_offset);
|
|
|
|
fbtk_set_caret(widget, true,
|
|
|
|
widget->u.text.idx_offset + border,
|
|
|
|
border,
|
|
|
|
widget->height - border - border,
|
|
|
|
fb_text_input_remove_caret_cb);
|
2010-07-07 22:08:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_RETURN:
|
|
|
|
widget->u.text.enter(widget->u.text.pw, widget->u.text.text);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_RIGHT:
|
2012-07-31 18:13:52 +04:00
|
|
|
if (widget->u.text.idx < widget->u.text.len)
|
|
|
|
widget->u.text.idx++;
|
2012-07-31 23:43:43 +04:00
|
|
|
|
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.idx, &widget->u.text.idx_offset);
|
|
|
|
fbtk_set_caret(widget, true,
|
|
|
|
widget->u.text.idx_offset + border,
|
|
|
|
border,
|
|
|
|
widget->height - border - border,
|
|
|
|
fb_text_input_remove_caret_cb);
|
2012-07-31 18:13:52 +04:00
|
|
|
break;
|
|
|
|
|
2010-07-07 22:08:17 +04:00
|
|
|
case NSFB_KEY_LEFT:
|
2012-07-31 18:13:52 +04:00
|
|
|
if (widget->u.text.idx > 0)
|
|
|
|
widget->u.text.idx--;
|
2012-07-31 23:43:43 +04:00
|
|
|
|
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.idx, &widget->u.text.idx_offset);
|
|
|
|
fbtk_set_caret(widget, true,
|
|
|
|
widget->u.text.idx_offset + border,
|
|
|
|
border,
|
|
|
|
widget->height - border - border,
|
|
|
|
fb_text_input_remove_caret_cb);
|
2012-07-31 18:13:52 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_PAGEUP:
|
|
|
|
case NSFB_KEY_PAGEDOWN:
|
2010-07-07 22:08:17 +04:00
|
|
|
case NSFB_KEY_UP:
|
|
|
|
case NSFB_KEY_DOWN:
|
|
|
|
/* Not handling any of these correctly yet, but avoid putting
|
|
|
|
* charcters in the text widget when they're pressed. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_RSHIFT:
|
|
|
|
modifier |= 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSFB_KEY_LSHIFT:
|
|
|
|
modifier |= 1<<1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* allow for new character and null */
|
2012-07-31 18:13:52 +04:00
|
|
|
temp = realloc(widget->u.text.text, widget->u.text.len + 2);
|
|
|
|
if (temp == NULL) {
|
|
|
|
break;
|
2010-07-07 22:08:17 +04:00
|
|
|
}
|
|
|
|
|
2012-07-31 18:13:52 +04:00
|
|
|
widget->u.text.text = temp;
|
|
|
|
memmove(widget->u.text.text + widget->u.text.idx + 1,
|
|
|
|
widget->u.text.text + widget->u.text.idx,
|
|
|
|
widget->u.text.len - widget->u.text.idx);
|
|
|
|
widget->u.text.text[widget->u.text.idx] =
|
|
|
|
fbtk_keycode_to_ucs4(value, modifier);
|
|
|
|
widget->u.text.idx++;
|
|
|
|
widget->u.text.len++;
|
|
|
|
widget->u.text.text[widget->u.text.len] = '\0';
|
|
|
|
|
2012-07-31 23:43:43 +04:00
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.len, &widget->u.text.width);
|
|
|
|
nsfont.font_width(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.idx, &widget->u.text.idx_offset);
|
|
|
|
fbtk_set_caret(widget, true,
|
|
|
|
widget->u.text.idx_offset + border,
|
|
|
|
border,
|
|
|
|
widget->height - border - border,
|
|
|
|
fb_text_input_remove_caret_cb);
|
2010-07-07 22:08:17 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fbtk_request_redraw(widget);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-31 23:43:43 +04:00
|
|
|
/** Routine called when text events occour in writeable widget.
|
|
|
|
*
|
|
|
|
* @param widget The widget reciving input events.
|
|
|
|
* @param cbi The callback parameters.
|
|
|
|
* @return The callback result.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
|
|
|
|
{
|
|
|
|
plot_font_style_t font_style;
|
|
|
|
int fh;
|
|
|
|
int border;
|
|
|
|
size_t idx;
|
|
|
|
|
|
|
|
fb_text_font_style(widget, &fh, &border, &font_style);
|
|
|
|
|
|
|
|
widget->u.text.idx = widget->u.text.len;
|
|
|
|
|
|
|
|
nsfont.font_position_in_string(&font_style, widget->u.text.text,
|
|
|
|
widget->u.text.len, cbi->x - border,
|
|
|
|
&idx,
|
|
|
|
&widget->u.text.idx_offset);
|
|
|
|
widget->u.text.idx = idx;
|
|
|
|
fbtk_set_caret(widget, true,
|
|
|
|
widget->u.text.idx_offset + border,
|
|
|
|
border,
|
|
|
|
widget->height - border - border,
|
|
|
|
fb_text_input_remove_caret_cb);
|
|
|
|
|
|
|
|
fbtk_request_redraw(widget);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-07 22:08:17 +04:00
|
|
|
/* exported function documented in fbtk.h */
|
|
|
|
void
|
|
|
|
fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
|
|
|
|
{
|
|
|
|
widget->u.text.enter = enter;
|
|
|
|
widget->u.text.pw = pw;
|
|
|
|
|
|
|
|
fbtk_set_handler(widget, FBTK_CBT_INPUT, text_input, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported function documented in fbtk.h */
|
|
|
|
void
|
|
|
|
fbtk_set_text(fbtk_widget_t *widget, const char *text)
|
|
|
|
{
|
|
|
|
if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_TEXT))
|
|
|
|
return;
|
|
|
|
if (widget->u.text.text != NULL) {
|
|
|
|
if (strcmp(widget->u.text.text, text) == 0)
|
|
|
|
return; /* text is being set to the same thing */
|
|
|
|
free(widget->u.text.text);
|
|
|
|
}
|
|
|
|
widget->u.text.text = strdup(text);
|
2012-07-31 18:13:52 +04:00
|
|
|
widget->u.text.len = strlen(text);
|
|
|
|
widget->u.text.idx = widget->u.text.len;
|
2010-07-07 22:08:17 +04:00
|
|
|
|
|
|
|
fbtk_request_redraw(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported function documented in fbtk.h */
|
|
|
|
fbtk_widget_t *
|
|
|
|
fbtk_create_text(fbtk_widget_t *parent,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
colour bg,
|
|
|
|
colour fg,
|
|
|
|
bool outline)
|
|
|
|
{
|
|
|
|
fbtk_widget_t *neww;
|
|
|
|
|
|
|
|
neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_TEXT, x, y, width, height);
|
|
|
|
neww->fg = fg;
|
|
|
|
neww->bg = bg;
|
|
|
|
neww->mapped = true;
|
|
|
|
neww->u.text.outline = outline;
|
|
|
|
|
|
|
|
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
|
|
|
|
|
|
|
|
return neww;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported function documented in fbtk.h */
|
|
|
|
fbtk_widget_t *
|
|
|
|
fbtk_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)
|
|
|
|
{
|
|
|
|
fbtk_widget_t *neww;
|
|
|
|
|
|
|
|
neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_TEXT, x, y, width, height);
|
|
|
|
neww->fg = fg;
|
|
|
|
neww->bg = bg;
|
|
|
|
neww->mapped = true;
|
|
|
|
|
|
|
|
neww->u.text.outline = outline;
|
|
|
|
neww->u.text.enter = enter;
|
|
|
|
neww->u.text.pw = pw;
|
|
|
|
|
|
|
|
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
|
2012-07-31 23:43:43 +04:00
|
|
|
fbtk_set_handler(neww, FBTK_CBT_CLICK, text_input_click, pw);
|
2010-07-07 22:08:17 +04:00
|
|
|
fbtk_set_handler(neww, FBTK_CBT_INPUT, text_input, neww);
|
|
|
|
|
|
|
|
return neww;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* exported function documented in fbtk.h */
|
|
|
|
fbtk_widget_t *
|
|
|
|
fbtk_create_text_button(fbtk_widget_t *parent,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
colour bg,
|
|
|
|
colour fg,
|
|
|
|
fbtk_callback click,
|
|
|
|
void *pw)
|
|
|
|
{
|
|
|
|
fbtk_widget_t *neww;
|
|
|
|
|
|
|
|
neww = fbtk_widget_new(parent, FB_WIDGET_TYPE_TEXT, x, y, width, height);
|
|
|
|
neww->fg = fg;
|
|
|
|
neww->bg = bg;
|
|
|
|
neww->mapped = true;
|
|
|
|
|
|
|
|
neww->u.text.outline = true;
|
|
|
|
|
|
|
|
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text_button, NULL);
|
|
|
|
fbtk_set_handler(neww, FBTK_CBT_CLICK, click, pw);
|
|
|
|
fbtk_set_handler(neww, FBTK_CBT_POINTERENTER, fbtk_set_ptr, &hand_image);
|
|
|
|
|
|
|
|
return neww;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset:8
|
|
|
|
* End:
|
|
|
|
*/
|