[project @ 2002-12-29 22:27:35 by monkeyson]

Font anti-alias colours corrected.

Begin displaying form elements - text, password, submit, reset

svn path=/import/netsurf/; revision=71
This commit is contained in:
Phil Mellor 2002-12-29 22:27:35 +00:00
parent 0eec3d6d4f
commit 50fc20c2d4
7 changed files with 240 additions and 23 deletions

View File

@ -1,5 +1,5 @@
/**
* $Id: browser.c,v 1.16 2002/12/25 22:59:21 bursa Exp $
* $Id: browser.c,v 1.17 2002/12/29 22:27:35 monkeyson Exp $
*/
#include "netsurf/riscos/font.h"
@ -684,10 +684,18 @@ void browser_window_text_selection(struct browser_window* bw,
start = &(bw->current_content->data.html.text_selection.start);
end = &(bw->current_content->data.html.text_selection.end);
if (click_boxes[i].box->font != 0)
{
font_position_in_string(click_boxes[i].box->text,
click_boxes[i].box->font, click_boxes[i].box->length,
click_x - click_boxes[i].actual_x,
&click_char_offset, &click_pixel_offset);
}
else
{
click_char_offset = 0;
click_pixel_offset = 0;
}
new_pos.box = click_boxes[i].box;
new_pos.actual_box_x = click_boxes[i].actual_x;
@ -989,5 +997,10 @@ char *url_join(const char* new, const char* base)
}
LOG(("ret = %s", ret));
if (ret == NULL)
{
ret = xcalloc(strlen(new) + 10, sizeof(char));
strcpy(ret, new);
}
return ret;
}

View File

@ -1,5 +1,5 @@
/**
* $Id: netsurf.c,v 1.4 2002/11/03 09:39:53 bursa Exp $
* $Id: netsurf.c,v 1.5 2002/12/29 22:27:35 monkeyson Exp $
*/
#include "netsurf/desktop/netsurf.h"
@ -51,7 +51,7 @@ int main(int argc, char** argv)
void Log(char* func, char* msg)
{
#ifdef NETSURF_DUMP
#ifdef NETSURF_DUMP_MONKEYS
FILE* logfile = NULL;
logfile = fopen("logfile","a");
if (logfile == NULL)

View File

@ -1,5 +1,5 @@
/**
* $Id: box.c,v 1.22 2002/12/27 20:35:32 bursa Exp $
* $Id: box.c,v 1.23 2002/12/29 22:27:35 monkeyson Exp $
*/
#include <assert.h>
@ -19,6 +19,8 @@
* internal functions
*/
struct box* box_gui_gadget(xmlNode * n, struct css_style* style);
void box_add_child(struct box * parent, struct box * child);
struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
const char *href);
@ -77,6 +79,7 @@ struct box * box_create(xmlNode * node, box_type type, struct css_style * style,
box->next_float = 0;
box->col = 0;
box->font = 0;
box->gadget = 0;
return box;
}
@ -173,6 +176,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
}
if (n->type == XML_TEXT_NODE ||
(n->type == XML_ELEMENT_NODE && (strcmp((const char *) n->name, "input") == 0)) ||
(n->type == XML_ELEMENT_NODE && (style->float_ == CSS_FLOAT_LEFT ||
style->float_ == CSS_FLOAT_RIGHT))) {
/* text nodes are converted to inline boxes, wrapped in an inline container block */
@ -194,6 +198,11 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
}
box->font = font_open(fonts, box->style);
box_add_child(inline_container, box);
} else if (strcmp((const char *) n->name, "input") == 0) {
LOG(("input"));
box = box_gui_gadget(n, parent_style);
if (box != NULL)
box_add_child(inline_container, box);
} else {
LOG(("float"));
box = box_create(0, BOX_FLOAT_LEFT, 0, href);
@ -406,6 +415,7 @@ void box_normalise_block(struct box *block)
assert(block->type == BOX_BLOCK || block->type == BOX_TABLE_CELL);
for (child = block->children; child != 0; prev_child = child, child = child->next) {
fprintf(stderr, "child->type = %d\n", child->type);
switch (child->type) {
case BOX_BLOCK:
/* ok */
@ -702,6 +712,12 @@ void box_free(struct box *box)
/* last this box */
// if (box->style != 0)
// free(box->style);
if (box->gadget != 0)
{
/* gadget_free(box->gadget); */
free((void*)box->gadget);
}
if (box->text != 0)
free((void*)box->text);
/* only free href if we're the top most user */
@ -713,3 +729,70 @@ void box_free(struct box *box)
free((void*)box->href);
}
}
struct box* box_gui_gadget(xmlNode * n, struct css_style* style)
{
struct box* box = 0;
char* s;
char* type;
if ((type = (char *) xmlGetProp(n, (xmlChar *) "type")))
{
if (strcmp(type, "submit") == 0 || strcmp(type, "reset") == 0)
{
//style->display = CSS_DISPLAY_BLOCK;
box = box_create(n, BOX_INLINE, style, NULL);
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
box->gadget->type = GADGET_ACTIONBUTTON;
box->text = 0;
box->length = 0;
box->font = 0;
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
box->gadget->data.actionbutt.label = s;
}
else
{
box->gadget->data.actionbutt.label = strdup(type);
box->gadget->data.actionbutt.label[0] = toupper(type[0]);
}
}
if (strcmp(type, "text") == 0 || strcmp(type, "password") == 0)
{
//style->display = CSS_DISPLAY_BLOCK;
box = box_create(n, BOX_INLINE, style, NULL);
box->gadget = xcalloc(1, sizeof(struct gui_gadget));
box->gadget->type = GADGET_TEXTBOX;
box->text = 0;
box->length = 0;
box->font = 0;
box->gadget->data.textbox.maxlength = 255;
if ((s = (char *) xmlGetProp(n, (xmlChar *) "maxlength"))) {
box->gadget->data.textbox.maxlength = atoi(s);
free(s);
}
box->gadget->data.textbox.size = box->gadget->data.textbox.maxlength;
if ((s = (char *) xmlGetProp(n, (xmlChar *) "size"))) {
box->gadget->data.textbox.size = atoi(s);
free(s);
}
box->gadget->data.textbox.text = xcalloc(box->gadget->data.textbox.maxlength + 1, sizeof(char));
if ((s = (char *) xmlGetProp(n, (xmlChar *) "value"))) {
strncpy(box->gadget->data.textbox.text, s,
box->gadget->data.textbox.maxlength);
free(s);
}
}
free(type);
}
return box;
}

View File

@ -1,5 +1,5 @@
/**
* $Id: box.h,v 1.12 2002/12/27 17:28:19 bursa Exp $
* $Id: box.h,v 1.13 2002/12/29 22:27:35 monkeyson Exp $
*/
#ifndef _NETSURF_RENDER_BOX_H_
@ -27,6 +27,21 @@ struct column {
unsigned long min, max, width;
};
struct gui_gadget {
enum { GADGET_HIDDEN = 0, GADGET_TEXTBOX, GADGET_RADIO, GADGET_OPTION,
GADGET_COMBO, GADGET_LIST, GADGET_TEXTAREA, GADGET_ACTIONBUTTON } type;
union {
struct {
int maxlength;
char* text;
int size;
} textbox;
struct {
char* label;
} actionbutt;
} data;
};
struct box {
box_type type;
xmlNode * node;
@ -46,6 +61,7 @@ struct box {
struct box * next_float;
struct column *col;
struct font_data *font;
struct gui_gadget* gadget;
};
#define UNKNOWN_WIDTH ULONG_MAX

View File

@ -1,5 +1,5 @@
/**
* $Id: layout.c,v 1.27 2002/12/27 22:29:45 bursa Exp $
* $Id: layout.c,v 1.28 2002/12/29 22:27:35 monkeyson Exp $
*/
#include <assert.h>
@ -107,6 +107,35 @@ void layout_node(struct box * box, unsigned long width, struct box * cont,
}
}
int gadget_width(struct gui_gadget* gadget)
{
switch (gadget->type)
{
case GADGET_TEXTBOX:
return gadget->data.textbox.size * 8;
case GADGET_ACTIONBUTTON:
return strlen(gadget->data.actionbutt.label) * 8 + 16;
default:
assert(0);
}
return 0;
}
int gadget_height(struct gui_gadget* gadget)
{
switch (gadget->type)
{
case GADGET_TEXTBOX:
return 28;
case GADGET_ACTIONBUTTON:
return 28;
default:
assert(0);
}
return 0;
}
/**
* layout_block -- position block and recursively layout children
*
@ -300,18 +329,31 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
find_sides(cont->float_children, cy, cy, &x0, &x1, &left, &right);
/* get minimum line height from containing block */
height = line_height(first->parent->parent->style);
if (first->text != 0)
height = line_height(first->parent->parent->style);
else if (first->gadget != 0)
height = gadget_height(first->gadget);
/* pass 1: find height of line assuming sides at top of line */
for (x = 0, b = first; x < x1 - x0 && b != 0; b = b->next) {
assert(b->type == BOX_INLINE || b->type == BOX_FLOAT_LEFT || b->type == BOX_FLOAT_RIGHT);
if (b->type == BOX_INLINE) {
h = line_height(b->style ? b->style : b->parent->parent->style);
if (b->text != 0)
h = line_height(b->style ? b->style : b->parent->parent->style);
else if (b->gadget != 0)
h = gadget_height(b->gadget);
b->height = h;
if (h > height) height = h;
if (b->width == UNKNOWN_WIDTH)
if (b->width == UNKNOWN_WIDTH && b->font != 0)
b->width = font_width(b->font, b->text, b->length);
x += b->width + b->space ? b->font->space_width : 0;
else if (b->width == UNKNOWN_WIDTH && b->gadget != 0)
b->width = gadget_width(b->gadget);
if (b->font != 0)
x += b->width + b->space ? b->font->space_width : 0;
else if (b->gadget != 0)
x += b->width;
}
}
@ -328,7 +370,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
b->x = x;
x += b->width;
space_before = space_after;
space_after = b->space ? b->font->space_width : 0;
if (b->font != 0)
space_after = b->space ? b->font->space_width : 0;
else
space_after = 0;
c = b;
move_y = 1;
/* fprintf(stderr, "layout_line: '%.*s' %li %li\n", b->length, b->text, xp, x); */
@ -378,8 +423,10 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
if (space == 0)
w = c->width;
else
else if (c->font != 0)
w = font_width(c->font, c->text, space - c->text);
else if (c->gadget != 0)
w = gadget_width(c->gadget);
if (x1 - x0 < x + space_before + w && left == 0 && right == 0 && c == first) {
/* first word doesn't fit, but no floats and first on line so force in */
@ -405,7 +452,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
/* first word doesn't fit, but full width not available so leave for later */
b = c;
/* fprintf(stderr, "layout_line: overflow, leaving\n"); */
} else {
} else if (c->text != 0) {
/* fit as many words as possible */
assert(space != 0);
space = font_split(c->font, c->text, c->length,
@ -669,8 +716,11 @@ void calculate_inline_container_widths(struct box *box)
switch (child->type) {
case BOX_INLINE:
/* max = all one line */
if (child->font != 0)
{
child->width = font_width(child->font,
child->text, child->length);
max += child->width;
/* min = widest word */
@ -682,6 +732,14 @@ void calculate_inline_container_widths(struct box *box)
}
width = font_width(child->font, word, strlen(word));
if (min < width) min = width;
}
else if (child->gadget != 0)
{
child->width = gadget_width(child->gadget);
max += child->width;
if (min < child->width)
min = child->width;
}
break;
case BOX_FLOAT_LEFT:

View File

@ -1,5 +1,5 @@
/**
* $Id: font.c,v 1.8 2002/12/27 17:28:19 bursa Exp $
* $Id: font.c,v 1.9 2002/12/29 22:27:35 monkeyson Exp $
*/
#include <assert.h>
@ -68,7 +68,7 @@ void font_position_in_string(const char* text, struct font_data* font,
block.letter.x = block.letter.y = 0;
block.split_char = -1;
xfont_scan_string(font, text,
xfont_scan_string(font->handle, text,
font_GIVEN_BLOCK | font_GIVEN_FONT | font_KERN | font_RETURN_CARET_POS | font_GIVEN_LENGTH,
ro_x_units(x) * 400,
0x7fffffff,

View File

@ -1,5 +1,5 @@
/**
* $Id: gui.c,v 1.9 2002/12/29 20:02:46 bursa Exp $
* $Id: gui.c,v 1.10 2002/12/29 22:27:35 monkeyson Exp $
*/
#include "netsurf/riscos/font.h"
@ -12,8 +12,10 @@
#include <string.h>
#include <stdlib.h>
int gadget_subtract_x;
int gadget_subtract_y;
#define browser_menu_flags (wimp_ICON_TEXT | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))
#define HOME_URL "file:/<NetSurf$Dir>/Resources/intro.html"
char* HOME_URL = "file:/<NetSurf$Dir>/Resources/intro.html\0";
wimp_MENU(2) netsurf_iconbar_menu =
{
@ -243,6 +245,7 @@ int window_y_units(int scr_units, wimp_window_state* win)
return scr_units - (win->visible.y1 - win->yscroll);
}
gui_window* create_gui_browser_window(struct browser_window* bw)
{
struct wimp_window window;
@ -458,7 +461,7 @@ gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s)
int select_on = 0;
void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, signed long y, os_box* clip)
void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, signed long y, os_box* clip, int current_background_color)
{
struct box * c;
const char * const noname = "";
@ -500,9 +503,50 @@ void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, si
colourtrans_set_gcol(box->style->background_color << 8, 0, os_ACTION_OVERWRITE, 0);
os_plot(os_MOVE_TO, x + box->x * 2, y - box->y * 2);
os_plot(os_PLOT_RECTANGLE | os_PLOT_BY, box->width * 2, -box->height * 2);
current_background_color = box->style->background_color;
}
if (box->type == BOX_INLINE)
if (box->gadget != 0)
{
wimp_icon icon;
fprintf(stderr, "writing GADGET\n");
icon.extent.x0 = -gadget_subtract_x + x + box->x * 2;
icon.extent.y0 = -gadget_subtract_y + y - box->y * 2 - box->height * 2;
icon.extent.x1 = -gadget_subtract_x + x + box->x * 2 + box->width * 2;
icon.extent.y1 = -gadget_subtract_y + y - box->y * 2;
switch (box->gadget->type)
{
case GADGET_TEXTBOX:
icon.flags = wimp_ICON_TEXT | wimp_ICON_BORDER |
wimp_ICON_VCENTRED | wimp_ICON_FILLED |
wimp_ICON_INDIRECTED |
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
icon.data.indirected_text.text = box->gadget->data.textbox.text;
icon.data.indirected_text.size = box->gadget->data.textbox.maxlength;
icon.data.indirected_text.validation = " ";
fprintf(stderr, "writing GADGET TEXTBOX\n");
wimp_plot_icon(&icon);
break;
case GADGET_ACTIONBUTTON:
icon.flags = wimp_ICON_TEXT | wimp_ICON_BORDER |
wimp_ICON_VCENTRED | wimp_ICON_FILLED |
wimp_ICON_INDIRECTED | wimp_ICON_HCENTRED |
(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) |
(wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT);
icon.data.indirected_text.text = box->gadget->data.actionbutt.label;
icon.data.indirected_text.size = strlen(box->gadget->data.actionbutt.label);
icon.data.indirected_text.validation = "R5,3";
fprintf(stderr, "writing GADGET ACTION\n");
wimp_plot_icon(&icon);
break;
}
}
if (box->type == BOX_INLINE && box->font != 0)
{
if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1)
@ -515,6 +559,7 @@ if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1)
if (start->box == box)
{
fprintf(stderr, "THE START OFFSET IS %d\n", start->pixel_offset * 2);
if (end->box == box)
{
colourtrans_set_gcol(os_COLOUR_VERY_LIGHT_GREY, colourtrans_SET_FG, 0, 0);
@ -563,7 +608,7 @@ if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1)
}
}
colourtrans_set_font_colours(box->font->handle, 0xffffff, box->style->color << 8,
colourtrans_set_font_colours(box->font->handle, current_background_color << 8, box->style->color << 8,
14, 0, 0, 0);
font_paint(box->font->handle, box->text,
@ -593,10 +638,10 @@ if (g->data.browser.bw->current_content->data.html.text_selection.selected == 1)
for (c = box->children; c != 0; c = c->next)
if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT)
ro_gui_window_redraw_box(g, c, x + box->x * 2, y - box->y * 2, clip);
ro_gui_window_redraw_box(g, c, x + box->x * 2, y - box->y * 2, clip, current_background_color);
for (c = box->float_children; c != 0; c = c->next_float)
ro_gui_window_redraw_box(g, c, x + box->x * 2, y - box->y * 2, clip);
ro_gui_window_redraw_box(g, c, x + box->x * 2, y - box->y * 2, clip, current_background_color);
}
@ -638,10 +683,12 @@ void ro_gui_window_redraw(gui_window* g, wimp_draw* redraw)
while (more)
{
gadget_subtract_x = redraw->box.x0 - redraw->xscroll;
gadget_subtract_y = redraw->box.y1 - redraw->yscroll;
ro_gui_window_redraw_box(g,
g->data.browser.bw->current_content->data.html.layout->children,
redraw->box.x0 - redraw->xscroll, redraw->box.y1 - redraw->yscroll,
&redraw->clip);
&redraw->clip, 0xffffff);
more = wimp_get_rectangle(redraw);
}
return;