r7454 paulblokus - in /branches/paulblokus/corewidgets: desktop/browser.c gtk/gtk_window.c render/form.c render/form.h

netsurf at semichrome.net netsurf at semichrome.net
Sun May 10 12:06:39 BST 2009


Author: paulblokus
Date: Sun May 10 06:06:38 2009
New Revision: 7454

URL: http://source.netsurf-browser.org?rev=7454&view=rev
Log:
First draft of the select menu

Modified:
    branches/paulblokus/corewidgets/desktop/browser.c
    branches/paulblokus/corewidgets/gtk/gtk_window.c
    branches/paulblokus/corewidgets/render/form.c
    branches/paulblokus/corewidgets/render/form.h

Modified: branches/paulblokus/corewidgets/desktop/browser.c
URL: http://source.netsurf-browser.org/branches/paulblokus/corewidgets/desktop/browser.c?rev=7454&r1=7453&r2=7454&view=diff
==============================================================================
--- branches/paulblokus/corewidgets/desktop/browser.c (original)
+++ branches/paulblokus/corewidgets/desktop/browser.c Sun May 10 06:06:38 2009
@@ -1408,6 +1408,31 @@
 	bw->drag_type = DRAGGING_NONE;
 	bw->scrolling_box = NULL;
 
+	
+	if (visible_select_menu != NULL) {
+		int x0, y0, x1, y1;
+		box = visible_select_menu->box;
+		box_coords(box, &box_x, &box_y);
+		x0 = box_x - box->border[3];
+		y0 = box_y + box->height + box->border[2] + box->padding[2]
+				+ box->padding[0];
+		x1 = box_x + box->width + box->border[1] + box->border[3]
+				+ box->padding[1] + box->padding[3];
+		y1 = y0 + visible_select_menu->data.select.height;
+		
+		if (x > x0 && x < x1 && y >  y0 && y < y1
+				&& mouse & BROWSER_MOUSE_CLICK_1) {
+			
+			form_select_menu_clicked(bw, visible_select_menu,
+					x - x0,
+					y - y0);
+		}
+		else if (mouse & BROWSER_MOUSE_CLICK_1)
+			form_hide_select_menu(bw);
+		
+		return;
+	}
+	
 	/* search the box tree for a link, imagemap, form control, or
 	 * box with scrollbars */
 
@@ -1498,7 +1523,8 @@
 			status = messages_get("FormSelect");
 			pointer = GUI_POINTER_MENU;
 			if (mouse & BROWSER_MOUSE_CLICK_1)
-				gui_create_form_select_menu(bw, gadget);
+				//gui_create_form_select_menu(bw, gadget);
+				form_show_select_menu(bw, gadget);
 			break;
 		case GADGET_CHECKBOX:
 			status = messages_get("FormCheckbox");

Modified: branches/paulblokus/corewidgets/gtk/gtk_window.c
URL: http://source.netsurf-browser.org/branches/paulblokus/corewidgets/gtk/gtk_window.c?rev=7454&r1=7453&r2=7454&view=diff
==============================================================================
--- branches/paulblokus/corewidgets/gtk/gtk_window.c (original)
+++ branches/paulblokus/corewidgets/gtk/gtk_window.c Sun May 10 06:06:38 2009
@@ -427,6 +427,19 @@
 	bool shift = event->state & GDK_SHIFT_MASK;
 	bool ctrl = event->state & GDK_CONTROL_MASK;
 
+	current_widget = widget;
+	current_drawable = widget->window;
+	current_gc = gdk_gc_new(current_drawable);
+#ifdef CAIRO_VERSION
+	current_cr = gdk_cairo_create(current_drawable);
+#endif
+
+	plot = nsgtk_plotters;
+	nsgtk_plot_set_scale(g->bw->scale);
+	current_redraw_browser = g->bw;	
+		
+	
+	
 	/* If the mouse state is PRESS then we are waiting for a release to emit
 	 * a click event, otherwise just reset the state to nothing*/
 	if (g->mouse->state & BROWSER_MOUSE_PRESS_1)
@@ -446,6 +459,16 @@
 	else
 		browser_window_mouse_drag_end(g->bw, 0, event->x, event->y);
 
+	
+	current_redraw_browser = NULL;
+
+	g_object_unref(current_gc);
+#ifdef CAIRO_VERSION
+	cairo_destroy(current_cr);
+#endif	
+	
+	
+	
 	g->mouse->state = 0;
 	return TRUE;
 }

Modified: branches/paulblokus/corewidgets/render/form.c
URL: http://source.netsurf-browser.org/branches/paulblokus/corewidgets/render/form.c?rev=7454&r1=7453&r2=7454&view=diff
==============================================================================
--- branches/paulblokus/corewidgets/render/form.c (original)
+++ branches/paulblokus/corewidgets/render/form.c Sun May 10 06:06:38 2009
@@ -29,6 +29,10 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
+#include "css/css.h"
+#include "desktop/browser.h"
+#include "desktop/plotters.h"
+#include "desktop/knockout.h"
 #include "render/box.h"
 #include "render/form.h"
 #include "utils/log.h"
@@ -36,11 +40,15 @@
 #include "utils/utf8.h"
 #include "utils/utils.h"
 
+//no scroll implementation no limit at the moment
+#define MAX_VISIBLE_SELECT_ROWS 2000000000
+#define SELECT_LINE_SPACING 0.3
 
 static char *form_textarea_value(struct form_control *textarea);
 static char *form_acceptable_charset(struct form *form);
 static char *form_encode_item(const char *item, const char *charset,
 		const char *fallback);
+static bool form_redraw_select_menu(struct browser_window *bw);		
 
 /**
  * Create a struct form.
@@ -812,3 +820,184 @@
 	return ret;
 }
 
+bool form_show_select_menu(struct browser_window *bw,
+		struct form_control *control)
+{
+	int i, first;
+	struct form_option *option;
+	
+	if (visible_select_menu)
+		return false;
+	
+	visible_select_menu = control;
+	first = 0;
+	if (visible_select_menu->data.select.num_selected > 0 &&
+			visible_select_menu->data.select.height == 0) {
+		i = 0;
+		option = visible_select_menu->data.select.items;
+		while (!option->selected) {
+			option = option->next;
+			i++;
+		}
+		
+		if (i >= MAX_VISIBLE_SELECT_ROWS)
+			first =  i - MAX_VISIBLE_SELECT_ROWS + 1;
+	}
+		
+	visible_select_menu->data.select.first_drawn = first;
+	form_redraw_select_menu(bw);
+	return true;
+}
+
+bool form_hide_select_menu(struct browser_window *bw)
+{
+	struct box *box;	
+	int x, y, width, height;	
+	
+	if (!visible_select_menu)
+		return false;
+	
+	box = visible_select_menu->box;
+	box_coords(box, &x, &y);
+	
+	x -= box->border[3];
+	y += box->height + box->border[2] + box->padding[2] + box->padding[0];	
+	
+	width = box->width + box->border[1] + box->border[3] + box->padding[1]
+			+ box->padding[3];	
+	height = visible_select_menu->data.select.height;
+	
+	x *= bw->scale;
+	y *= bw->scale;
+	width *= bw->scale;
+	height *= bw->scale;
+	
+	browser_window_redraw_rect(bw, x, y, width + 1, height + 1);
+	visible_select_menu = NULL;	
+	return true;
+}
+
+bool form_redraw_select_menu(struct browser_window *bw)
+{
+	struct box *box;
+	struct form_option *option;
+	bool result, want_knockout;
+	int x, y, width, height, line_height, line_height_with_spacing;
+	int x0, y0, x1, y1;
+	int num_lines, i;
+	int colour;
+	int first_option;
+	float scale = bw->scale;
+	
+	if (!visible_select_menu)
+		return false;
+		
+	first_option = visible_select_menu->data.select.first_drawn;
+	
+	box = visible_select_menu->box;
+	box_coords(box, &x, &y);
+	
+	x -= box->border[3];
+	y += box->height + box->border[2] + box->padding[2] + box->padding[0];
+	
+	width = box->width + box->border[1] + box->border[3] + box->padding[1]
+			+ box->padding[3];
+	
+	line_height = css_len2px(&(box->style->font_size.value.length),
+			box->style);
+	line_height_with_spacing = line_height + line_height * SELECT_LINE_SPACING;
+	
+	if (visible_select_menu->data.select.num_items - first_option <
+			MAX_VISIBLE_SELECT_ROWS)
+		num_lines = visible_select_menu->data.select.num_items
+				- first_option;
+	else
+		num_lines = MAX_VISIBLE_SELECT_ROWS;
+	
+	height = visible_select_menu->data.select.height = num_lines
+			* line_height_with_spacing;
+					
+	want_knockout = plot.option_knockout;
+	if (want_knockout)
+		knockout_plot_start(&plot);
+
+	x0 = x * scale;
+	y0 = y * scale;
+	x1 = (x + width) * scale;
+	y1 = (y + height) * scale;
+	
+	result = plot.clip(x0, y0, x1, y1);
+	result &= plot.clg(0xDDDDDD);
+	
+	option = visible_select_menu->data.select.items;
+	
+	for(i = 0; i < first_option; i++)
+		option = option->next;
+	
+	i = 0;
+	while (option && i < num_lines) {
+		
+		
+		y0 = (y + i * line_height_with_spacing) * scale;
+		y1 = (y + (i + 1) * line_height_with_spacing) * scale;
+		
+		plot.clip(x0, y0, x1, y1);		
+		if (option->selected) {
+			colour = 0xDB9370;
+			plot.clg(colour);
+		}
+		else
+			colour = 0xDDDDDD;
+		
+		y0 = y + i * line_height_with_spacing
+				+ (int) (line_height * (0.75 + SELECT_LINE_SPACING));
+		y0 *= scale;
+		plot.text((x + box->border[3] + box->padding[3]) * scale, y0,
+			  	box->style, option->text, strlen(option->text),
+    				colour, 0x000000);
+		
+		i++;
+		option = option->next;
+	}
+	
+	y0 = y * scale;
+	y1 = (y + height) * scale;
+	plot.clip(x0, y0, x1, y1);	
+	plot.rectangle(x0, y0, width * scale, height * scale, 1, 0x000000,
+			false, false);
+		
+	if (want_knockout)
+		knockout_plot_end();
+	return result;
+}
+
+void form_select_menu_clicked(struct browser_window *bw,
+		struct form_control *control, int x, int y)
+{
+	struct box *box;
+	struct form_option *option;	
+	int line_height, line_height_with_spacing;	
+	int i;
+	
+	box = visible_select_menu->box;
+	
+	line_height = css_len2px(&(box->style->font_size.value.length),
+				   box->style);
+	
+	line_height_with_spacing = line_height + line_height * SELECT_LINE_SPACING;
+	
+	option = visible_select_menu->data.select.items;
+	for (i = 0; i < visible_select_menu->data.select.first_drawn; i++)
+		option = option->next;
+	
+	while (option && y > line_height_with_spacing) {
+		y -= line_height_with_spacing;
+		i++;
+		option = option->next;
+	}
+	
+	if (option)
+		browser_window_form_select(bw, visible_select_menu, i);
+	
+	form_redraw_select_menu(bw);
+}

Modified: branches/paulblokus/corewidgets/render/form.h
URL: http://source.netsurf-browser.org/branches/paulblokus/corewidgets/render/form.h?rev=7454&r1=7453&r2=7454&view=diff
==============================================================================
--- branches/paulblokus/corewidgets/render/form.h (original)
+++ branches/paulblokus/corewidgets/render/form.h Sun May 10 06:06:38 2009
@@ -26,10 +26,13 @@
 
 #include <stdbool.h>
 #include "utils/config.h"
+#include "desktop/browser.h"
 
 struct box;
 struct form_control;
 struct form_option;
+
+struct form_control *visible_select_menu;
 
 /** Form submit method. */
 typedef enum {
@@ -105,6 +108,8 @@
 			int num_selected;
 			/** Currently selected item, if num_selected == 1. */
 			struct form_option *current;
+			int height;
+			int first_drawn;
 		} select;
 	} data;
 
@@ -144,5 +149,7 @@
 char *form_url_encode(struct form *form,
 		struct form_successful_control *control);
 void form_free_successful(struct form_successful_control *control);
-
+bool form_show_select_menu(struct browser_window *bw, struct form_control *control);
+bool form_hide_select_menu(struct browser_window *bw);
+void form_select_menu_clicked(struct browser_window *bw, struct form_control *control, int x, int y);
 #endif




More information about the netsurf-commits mailing list