Author: jmb
Date: Wed Sep 22 18:32:58 2010
New Revision: 10819
URL:
http://source.netsurf-browser.org?rev=10819&view=rev
Log:
Purge redundant files.
Removed:
branches/paulblokus/treeview/amiga/fetch_file.c
branches/paulblokus/treeview/framebuffer/fbtk.c
branches/paulblokus/treeview/framebuffer/fbtk_widget.h
branches/paulblokus/treeview/framebuffer/fbtk_widget_scroll.c
branches/paulblokus/treeview/render/directory.c
branches/paulblokus/treeview/render/directory.h
Removed: branches/paulblokus/treeview/amiga/fetch_file.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/amiga/fetc...
==============================================================================
--- branches/paulblokus/treeview/amiga/fetch_file.c (original)
+++ branches/paulblokus/treeview/amiga/fetch_file.c (removed)
@@ -1,354 +1,0 @@
-/*
- * Copyright 2008 Chris Young <chris(a)unsatisfactorysoftware.co.uk>
- *
- * 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/>.
- */
-
-/** \file
- * Fetching of data from a file (implementation).
- */
-
-#include <string.h>
-#include "content/fetch.h"
-#include "utils/log.h"
-#include "utils/url.h"
-#include <proto/dos.h>
-#include <proto/exec.h>
-#include "amiga/object.h"
-#include <malloc.h>
-#include "content/content.h"
-#include <time.h>
-#include <proto/utility.h>
-#include "utils/messages.h"
-
-static struct MinList *ami_file_fetcher_list = NULL;
-static UBYTE *ami_file_fetcher_buffer = NULL;
-
-/** Information for a single fetch. */
-struct ami_file_fetch_info {
- struct fetch *fetch_handle; /**< The fetch handle we're parented by. */
- BPTR fh; /** File handle */
- bool only_2xx; /**< Only HTTP 2xx responses acceptable. */
- char *path;
- char *url; /**< URL of this fetch. */
- bool aborted;
- bool locked;
- bool is_dir;
- struct nsObject *obj;
- int httpcode;
- int64 len;
- char *mimetype;
-};
-
-static bool ami_fetch_file_initialise(const char *scheme);
-static void ami_fetch_file_finalise(const char *scheme);
-static void * ami_fetch_file_setup(struct fetch *parent_fetch, const char *url,
- bool only_2xx, const char *post_urlenc,
- struct fetch_multipart_data *post_multipart,
- const char **headers);
-static bool ami_fetch_file_start(void *vfetch);
-static void ami_fetch_file_abort(void *vf);
-static void ami_fetch_file_free(void *f);
-static void ami_fetch_file_poll(const char *scheme_ignored);
-
-/**
- * Initialise the fetcher.
- *
- * Must be called once before any other function.
- */
-
-void ami_fetch_file_register(void)
-{
- if (!fetch_add_fetcher("file",
- ami_fetch_file_initialise,
- ami_fetch_file_setup,
- ami_fetch_file_start,
- ami_fetch_file_abort,
- ami_fetch_file_free,
- ami_fetch_file_poll,
- ami_fetch_file_finalise)) {
- LOG(("Unable to register Amiga fetcher for file:"));
- }
-}
-
-
-/**
- * Initialise a cURL fetcher.
- */
-
-bool ami_fetch_file_initialise(const char *scheme)
-{
- LOG(("Initialise Amiga fetcher for %s", scheme));
- ami_file_fetcher_list = NewObjList();
- ami_file_fetcher_buffer = AllocVec(1024,MEMF_PRIVATE);
-
- if(ami_file_fetcher_list && ami_file_fetcher_buffer) return true;
- else return false;
-}
-
-
-/**
- * Finalise a cURL fetcher
- */
-
-void ami_fetch_file_finalise(const char *scheme)
-{
- LOG(("Finalise Amiga fetcher %s", scheme));
- FreeObjList(ami_file_fetcher_list);
- FreeVec(ami_file_fetcher_buffer);
-}
-
-
-/**
- * Start fetching data for the given URL.
- *
- * The function returns immediately. The fetch may be queued for later
- * processing.
- *
- * A pointer to an opaque struct curl_fetch_info is returned, which can be passed to
- * fetch_abort() to abort the fetch at any time. Returns 0 if memory is
- * exhausted (or some other fatal error occurred).
- *
- * The caller must supply a callback function which is called when anything
- * interesting happens. The callback function is first called with msg
- * FETCH_HEADER, with the header in data, then one or more times
- * with FETCH_DATA with some data for the url, and finally with
- * FETCH_FINISHED. Alternatively, FETCH_ERROR indicates an error occurred:
- * data contains an error message. FETCH_REDIRECT may replace the FETCH_HEADER,
- * FETCH_DATA, FETCH_FINISHED sequence if the server sends a replacement URL.
- *
- * Some private data can be passed as the last parameter to fetch_start, and
- * callbacks will contain this.
- */
-
-void * ami_fetch_file_setup(struct fetch *parent_fetch, const char *url,
- bool only_2xx, const char *post_urlenc,
- struct fetch_multipart_data *post_multipart,
- const char **headers)
-{
- struct ami_file_fetch_info *fetch;
-
- fetch = AllocVec(sizeof (*fetch),MEMF_PRIVATE | MEMF_CLEAR);
- if (!fetch)
- return 0;
-
- fetch->fetch_handle = parent_fetch;
-
- /* construct a new fetch structure */
- fetch->fh = 0;
- fetch->only_2xx = only_2xx;
-// fetch->url = strdup(url);
- fetch->path = url_to_path(url);
-
- LOG(("fetch %p, url '%s', path '%s'", fetch,
url,fetch->path));
-
- fetch->obj = AddObject(ami_file_fetcher_list,AMINS_FETCHER);
- fetch->obj->objstruct = fetch;
-
- return fetch;
-}
-
-
-/**
- * Dispatch a single job
- */
-bool ami_fetch_file_start(void *vfetch)
-{
- struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vfetch;
-
- /* LOG(("ami file fetcher start")); */
-
- return true;
-}
-
-void ami_fetch_file_abort(void *vf)
-{
- struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vf;
-
- /* LOG(("ami file fetcher abort")); */
-
- if (fetch->fh) {
- FClose(fetch->fh);
- fetch->fh = 0;
- }
- fetch->aborted = true;
-}
-
-
-/**
- * Free a fetch structure and associated resources.
- */
-
-void ami_fetch_file_free(void *vf)
-{
- struct ami_file_fetch_info *fetch = (struct ami_file_fetch_info*)vf;
- /* LOG(("ami file fetcher free %lx",fetch)); */
-
- if(fetch->fh) FClose(fetch->fh);
- if(fetch->mimetype) free(fetch->mimetype);
- if(fetch->path) free(fetch->path);
-
- DelObject(fetch->obj); // delobject frees fetch
-}
-
-static void ami_fetch_file_send_callback(fetch_msg msg,
- struct ami_file_fetch_info *fetch, const void *data,
- unsigned long size, fetch_error_code errorcode)
-{
- fetch->locked = true;
- /* LOG(("ami file fetcher callback %ld",msg)); */
- fetch_send_callback(msg,fetch->fetch_handle,data,size,errorcode);
- fetch->locked = false;
-}
-
-/**
- * Do some work on current fetches.
- *
- * Must be called regularly to make progress on fetches.
- */
-
-void ami_fetch_file_poll(const char *scheme_ignored)
-{
- struct nsObject *node;
- struct nsObject *nnode;
- struct ami_file_fetch_info *fetch;
- fetch_error_code errorcode;
-
- if(IsMinListEmpty(ami_file_fetcher_list)) return;
-
- node = (struct nsObject *)GetHead((struct List *)ami_file_fetcher_list);
-
- do
- {
- errorcode = FETCH_ERROR_NO_ERROR;
- nnode=(struct nsObject *)GetSucc((struct Node *)node);
-
- fetch = (struct ami_file_fetch_info *)node->objstruct;
-
- if(fetch->locked) continue;
-
- if(!fetch->aborted)
- {
- if(fetch->fh)
- {
- ULONG len;
-
- len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024);
-
- if (len == (ULONG)-1)
- errorcode = FETCH_ERROR_MISC;
- else if (len > 0)
- ami_fetch_file_send_callback(
- FETCH_DATA, fetch,
- ami_file_fetcher_buffer,
- len, errorcode);
-
- if((len<1024) && (!fetch->aborted))
- {
- ami_fetch_file_send_callback(FETCH_FINISHED,
- fetch, NULL, 0,
- errorcode);
-
- fetch->aborted = true;
- }
- }
- else
- {
- fetch->fh = FOpen(fetch->path,MODE_OLDFILE,0);
-
- if(fetch->fh)
- {
- char header[64];
- struct ExamineData *fib;
- if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE))
- {
- fetch->len = fib->FileSize;
- FreeDosObject(DOS_EXAMINEDATA,fib);
- }
-
- fetch_set_http_code(fetch->fetch_handle,200);
- fetch->mimetype = fetch_mimetype(fetch->path);
- LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len));
-
- snprintf(header, sizeof header,
- "Content-Type: %s",
- fetch->mimetype);
- ami_fetch_file_send_callback(FETCH_HEADER,
- fetch, header, strlen(header), errorcode);
-
- snprintf(header, sizeof header,
- "Content-Length: %ld",
- fetch->len);
- ami_fetch_file_send_callback(FETCH_HEADER,
- fetch, header, strlen(header), errorcode);
-
- }
- else
- {
- char header[64];
- STRPTR errorstring;
- struct ExamineData *fib;
- if(fib = ExamineObjectTags(EX_StringNameInput,fetch->path,TAG_DONE))
- {
- if(EXD_IS_DIRECTORY(fib)) fetch->is_dir = true;
- FreeDosObject(DOS_EXAMINEDATA,fib);
- }
-
- if(fetch->is_dir == true)
- {
- fetch_set_http_code(fetch->fetch_handle, 200);
- fetch->mimetype = fetch_mimetype(fetch->path);
- LOG(("mimetype %s", fetch->mimetype));
-
- snprintf(header, sizeof header,
- "Content-Type: %s",
- fetch->mimetype);
- ami_fetch_file_send_callback(FETCH_HEADER,
- fetch, header, strlen(header), errorcode);
-
- ami_fetch_file_send_callback(
- FETCH_DATA, fetch,
- fetch->path,
- strlen(fetch->path), errorcode);
-
- ami_fetch_file_send_callback(FETCH_FINISHED,
- fetch, NULL, 0,
- errorcode);
-
- fetch->aborted = true;
- }
- else
- {
- errorstring = ASPrintf("%s
%s",messages_get("FileError"),fetch->path);
- fetch_set_http_code(fetch->fetch_handle,404);
-
- errorcode = FETCH_ERROR_HTTP_NOT2;
- ami_fetch_file_send_callback(FETCH_ERROR, fetch,
- errorstring, 0, errorcode);
- fetch->aborted = true;
- FreeVec(errorstring);
- }
- }
- }
- }
-
- if(fetch && fetch->aborted)
- {
- fetch_remove_from_queues(fetch->fetch_handle);
- fetch_free(fetch->fetch_handle);
- return;
- }
- }while(node=nnode);
-}
Removed: branches/paulblokus/treeview/framebuffer/fbtk.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/framebuffe...
==============================================================================
--- branches/paulblokus/treeview/framebuffer/fbtk.c (original)
+++ branches/paulblokus/treeview/framebuffer/fbtk.c (removed)
@@ -1,1209 +1,0 @@
-/*
- * Copyright 2008 Vincent Sanders <vince(a)simtec.co.uk>
- *
- * Framebuffer windowing toolkit
- *
- * 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 <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include <libnsfb.h>
-#include <libnsfb_plot.h>
-#include <libnsfb_plot_util.h>
-#include <libnsfb_event.h>
-#include <libnsfb_cursor.h>
-
-#include "utils/utils.h"
-#include "utils/log.h"
-#include "css/css.h"
-#include "desktop/browser.h"
-#include "desktop/plotters.h"
-
-#include "framebuffer/gui.h"
-#include "framebuffer/fbtk.h"
-#include "framebuffer/fbtk_widget.h"
-#include "framebuffer/bitmap.h"
-#include "framebuffer/image_data.h"
-
-static plot_font_style_t root_style = {
- .family = PLOT_FONT_FAMILY_SANS_SERIF,
- .size = 11 * FONT_SIZE_SCALE,
- .weight = 400,
- .flags = FONTF_NONE,
-};
-
-
-/* widget list */
-struct fbtk_widget_list_s {
- struct fbtk_widget_list_s *next;
- struct fbtk_widget_list_s *prev;
- fbtk_widget_t *widget;
-} ;
-
-enum {
- POINT_LEFTOF_REGION = 1,
- POINT_RIGHTOF_REGION = 2,
- POINT_ABOVE_REGION = 4,
- POINT_BELOW_REGION = 8,
-};
-
-#define REGION(x,y,cx1,cx2,cy1,cy2) \
- (( (y) > (cy2) ? POINT_BELOW_REGION : 0) | \
- ( (y) < (cy1) ? POINT_ABOVE_REGION : 0) | \
- ( (x) > (cx2) ? POINT_RIGHTOF_REGION : 0) | \
- ( (x) < (cx1) ? POINT_LEFTOF_REGION : 0) )
-
-#define SWAP(a, b) do { int t; t=(a); (a)=(b); (b)=t; } while(0)
-
-/* clip a rectangle to another rectangle */
-bool fbtk_clip_rect(const bbox_t * restrict clip, bbox_t * restrict box)
-{
- uint8_t region1;
- uint8_t region2;
-
- if (box->x1 < box->x0) SWAP(box->x0, box->x1);
- if (box->y1 < box->y0) SWAP(box->y0, box->y1);
-
- region1 = REGION(box->x0, box->y0, clip->x0, clip->x1 - 1, clip->y0,
clip->y1 - 1);
- region2 = REGION(box->x1, box->y1, clip->x0, clip->x1 - 1, clip->y0,
clip->y1 - 1);
-
- /* area lies entirely outside the clipping rectangle */
- if ((region1 | region2) && (region1 & region2))
- return false;
-
- if (box->x0 < clip->x0)
- box->x0 = clip->x0;
- if (box->x0 > clip->x1)
- box->x0 = clip->x1;
-
- if (box->x1 < clip->x0)
- box->x1 = clip->x0;
- if (box->x1 > clip->x1)
- box->x1 = clip->x1;
-
- if (box->y0 < clip->y0)
- box->y0 = clip->y0;
- if (box->y0 > clip->y1)
- box->y0 = clip->y1;
-
- if (box->y1 < clip->y0)
- box->y1 = clip->y0;
- if (box->y1 > clip->y1)
- box->y1 = clip->y1;
-
- return true;
-}
-
-/* clip a rectangle to a widgets area rectangle */
-bool fbtk_clip_to_widget(fbtk_widget_t *widget, bbox_t * restrict box)
-{
- bbox_t wbox;
- wbox.x0 = 0;
- wbox.y0 = 0;
- wbox.x1 = widget->width;
- wbox.y1 = widget->height;
- return fbtk_clip_rect(&wbox, box);
-}
-
-
-/* creates a new widget of a given type */
-fbtk_widget_t *
-new_widget(enum fbtk_widgettype_e type)
-{
- fbtk_widget_t *neww;
- neww = calloc(1, sizeof(fbtk_widget_t));
- neww->type = type;
- return neww;
-}
-
-
-/* find the root widget from any widget in the toolkits hierarchy */
-fbtk_widget_t *
-get_root_widget(fbtk_widget_t *widget)
-{
- while (widget->parent != NULL)
- widget = widget->parent;
-
- /* check root widget was found */
- if (widget->type != FB_WIDGET_TYPE_ROOT) {
- LOG(("Widget with null parent that is not the root widget!"));
- return NULL;
- }
-
- return widget;
-}
-
-
-/* set widget to be redrawn */
-void
-fbtk_request_redraw(fbtk_widget_t *widget)
-{
- widget->redraw_required = true;
-
- if (widget->type == FB_WIDGET_TYPE_WINDOW) {
- fbtk_widget_list_t *lent = widget->u.window.widgets;
-
- while (lent != NULL) {
- lent->widget->redraw_required = true;
- lent = lent->next;
- }
- }
-
- while (widget->parent != NULL) {
- widget = widget->parent;
- widget->redraw_required = true;
- }
-}
-
-fbtk_widget_t *
-add_widget_to_window(fbtk_widget_t *window, fbtk_widget_t *widget)
-{
- fbtk_widget_list_t *newent;
- fbtk_widget_list_t **nextent;
- fbtk_widget_list_t *prevent; /* previous entry pointer */
-
- if (window->type == FB_WIDGET_TYPE_WINDOW) {
- /* caller attached widget to a window */
-
- nextent = &window->u.window.widgets;
- prevent = NULL;
- while (*nextent != NULL) {
- prevent = (*nextent);
- nextent = &(prevent->next);
- }
-
- newent = calloc(1, sizeof(struct fbtk_widget_list_s));
-
- newent->widget = widget;
- newent->next = NULL;
- newent->prev = prevent;
-
- *nextent = newent;
-
- window->u.window.widgets_end = newent;
- }
- widget->parent = window;
-
- fbtk_request_redraw(widget);
-
- return widget;
-}
-
-static void
-remove_widget_from_window(fbtk_widget_t *window, fbtk_widget_t *widget)
-{
- fbtk_widget_list_t *lent = window->u.window.widgets;
-
- while ((lent != NULL) && (lent->widget != widget)) {
- lent = lent->next;
- }
-
- if (lent != NULL) {
- if (lent->prev == NULL) {
- window->u.window.widgets = lent->next;
- } else {
- lent->prev->next = lent->next;
- }
- if (lent->next == NULL) {
- window->u.window.widgets_end = lent->prev;
- } else {
- lent->next->prev = lent->prev;
- }
- free(lent);
- }
-}
-
-static void
-fbtk_redraw_widget(fbtk_widget_t *widget)
-{
- nsfb_bbox_t saved_plot_ctx;
- nsfb_bbox_t plot_ctx;
- fbtk_widget_t *root = get_root_widget(widget);
-
- //LOG(("widget %p type %d", widget, widget->type));
- if (widget->redraw_required == false)
- return;
-
- widget->redraw_required = false;
-
- /* ensure there is a redraw handler */
- if (fbtk_get_handler(widget, FBTK_CBT_REDRAW) == NULL)
- return;
-
- /* get the current clipping rectangle */
- nsfb_plot_get_clip(root->u.root.fb, &saved_plot_ctx);
-
- plot_ctx.x0 = fbtk_get_x(widget);
- plot_ctx.y0 = fbtk_get_y(widget);
- plot_ctx.x1 = plot_ctx.x0 + widget->width;
- plot_ctx.y1 = plot_ctx.y0 + widget->height;
-
- /* clip widget to the current area and redraw if its exposed */
- if (nsfb_plot_clip(&saved_plot_ctx, &plot_ctx )) {
-
- nsfb_plot_set_clip(root->u.root.fb, &plot_ctx);
-
- fbtk_post_callback(widget, FBTK_CBT_REDRAW);
-
- /* restore clipping rectangle */
- nsfb_plot_set_clip(root->u.root.fb, &saved_plot_ctx);
-
- //LOG(("OS redrawing %d,%d %d,%d", fb_plot_ctx.x0,
fb_plot_ctx.y0, fb_plot_ctx.x1, fb_plot_ctx.y1));
- }
-
-}
-
-/*************** redraw widgets **************/
-
-static int
-fb_redraw_fill(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- nsfb_bbox_t bbox;
- fbtk_widget_t *root = get_root_widget(widget);
-
- fbtk_get_bbox(widget, &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);
- }
-
- nsfb_update(root->u.root.fb, &bbox);
- return 0;
-}
-
-
-
-static int
-fb_redraw_bitmap(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- nsfb_bbox_t bbox;
- nsfb_bbox_t rect;
- fbtk_widget_t *root = 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);
- }
-
- /* plot the image */
- nsfb_plot_bitmap(root->u.root.fb,
- &rect,
- (nsfb_colour_t *)widget->u.bitmap.bitmap->pixdata,
- widget->u.bitmap.bitmap->width,
- widget->u.bitmap.bitmap->height,
- widget->u.bitmap.bitmap->width,
- !widget->u.bitmap.bitmap->opaque);
-
- nsfb_update(root->u.root.fb, &bbox);
-
- return 0;
-}
-
-static int
-fbtk_window_default_redraw(fbtk_widget_t *window, fbtk_callback_info *cbi)
-{
- fbtk_widget_list_t *lent;
- int res = 0;
-
- /* get the list of widgets */
- lent = window->u.window.widgets;
-
- while (lent != NULL) {
- fbtk_redraw_widget(lent->widget);
- lent = lent->next;
- }
- return res;
-}
-
-static int
-fbtk_window_default_move(fbtk_widget_t *window, fbtk_callback_info *cbi)
-{
- fbtk_widget_list_t *lent;
- fbtk_widget_t *widget;
- int res = 0;
-
- /* get the list of widgets */
- lent = window->u.window.widgets_end;
-
- while (lent != NULL) {
- widget = lent->widget;
-
- if ((cbi->x > widget->x) &&
- (cbi->y > widget->y) &&
- (cbi->x < widget->x + widget->width) &&
- (cbi->y < widget->y + widget->height)) {
- res = fbtk_post_callback(widget,
- FBTK_CBT_POINTERMOVE,
- cbi->x - widget->x,
- cbi->y - widget->y);
- break;
- }
- lent = lent->prev;
- }
- return res;
-}
-
-static int
-fbtk_window_default_click(fbtk_widget_t *window, fbtk_callback_info *cbi)
-{
- fbtk_widget_list_t *lent;
- fbtk_widget_t *widget;
- int res = 0;
-
- /* get the list of widgets */
- lent = window->u.window.widgets;
-
- while (lent != NULL) {
- widget = lent->widget;
-
- if ((cbi->x > widget->x) &&
- (cbi->y > widget->y) &&
- (cbi->x < widget->x + widget->width) &&
- (cbi->y < widget->y + widget->height)) {
- if (fbtk_get_handler(widget, FBTK_CBT_INPUT) != NULL) {
- fbtk_widget_t *root = get_root_widget(widget);
- root->u.root.input = widget;
- }
-
- res = fbtk_post_callback(widget,
- FBTK_CBT_CLICK,
- cbi->event,
- cbi->x - widget->x,
- cbi->y - widget->y);
- if (res != 0)
- break;
-
- }
- lent = lent->next;
- }
- return res;
-}
-
-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 = 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);
- }
-
-
- if (widget->u.text.outline) {
- rect.x1--;
- rect.y1--;
- nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0x00000000, false,
false);
- }
-
- if (widget->u.text.text != NULL) {
- root_style.background = widget->bg;
- root_style.foreground = widget->fg;
-
- plot.text(bbox.x0 + 3,
- bbox.y0 + 17,
- widget->u.text.text,
- strlen(widget->u.text.text),
- &root_style);
- }
-
- nsfb_update(root->u.root.fb, &bbox);
-
- return 0;
-}
-
-
-
-
-static int
-text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int value;
- if (cbi->event == NULL) {
- /* gain focus */
- if (widget->u.text.text == NULL)
- widget->u.text.text = calloc(1,1);
- widget->u.text.idx = strlen(widget->u.text.text);
-
- fbtk_request_redraw(widget);
-
- return 0;
- }
-
- if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
- return 0;
-
- value = cbi->event->value.keycode;
- switch (value) {
- case NSFB_KEY_BACKSPACE:
- if (widget->u.text.idx <= 0)
- break;
- widget->u.text.idx--;
- widget->u.text.text[widget->u.text.idx] = 0;
- break;
-
- case NSFB_KEY_RETURN:
- widget->u.text.enter(widget->u.text.pw, widget->u.text.text);
- break;
-
- case NSFB_KEY_PAGEUP:
- case NSFB_KEY_PAGEDOWN:
- case NSFB_KEY_RIGHT:
- case NSFB_KEY_LEFT:
- case NSFB_KEY_UP:
- case NSFB_KEY_DOWN:
- case NSFB_KEY_RSHIFT:
- case NSFB_KEY_LSHIFT:
- /* Not handling any of these correctly yet, but avoid putting
- * charcters in the text widget when they're pressed. */
- break;
-
- default:
- /* allow for new character and null */
- {
- char *temp = realloc(widget->u.text.text,
- widget->u.text.idx + 2);
- if (temp != NULL) {
- widget->u.text.text = temp;
- widget->u.text.text[widget->u.text.idx] = value;
- widget->u.text.text[widget->u.text.idx + 1] = '\0';
- widget->u.text.idx++;
- }
- }
- break;
- }
-
- fbtk_request_redraw(widget);
-
- return 0;
-}
-
-/* sets the enter action on a writable icon */
-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);
-}
-
-
-/********** acessors ***********/
-int
-fbtk_get_height(fbtk_widget_t *widget)
-{
- return widget->height;
-}
-
-int
-fbtk_get_width(fbtk_widget_t *widget)
-{
- return widget->width;
-}
-
-int
-fbtk_get_x(fbtk_widget_t *widget)
-{
- int x = widget->x;
-
- while (widget->parent != NULL) {
- widget = widget->parent;
- x += widget->x;
- }
-
- return x;
-}
-
-int
-fbtk_get_y(fbtk_widget_t *widget)
-{
- int y = widget->y;
-
- while (widget->parent != NULL) {
- widget = widget->parent;
- y += widget->y;
- }
-
- return y;
-}
-
-/* get widgets bounding box in screen co-ordinates */
-bool
-fbtk_get_bbox(fbtk_widget_t *widget, nsfb_bbox_t *bbox)
-{
- bbox->x0 = widget->x;
- bbox->y0 = widget->y;
- bbox->x1 = widget->x + widget->width;
- bbox->y1 = widget->y + widget->height;
-
- while (widget->parent != NULL) {
- widget = widget->parent;
- bbox->x0 += widget->x;
- bbox->y0 += widget->y;
- bbox->x1 += widget->x;
- bbox->y1 += widget->y;
- }
-
- return true;
-}
-
-fbtk_callback
-fbtk_get_handler(fbtk_widget_t *widget, fbtk_callback_type cbt)
-{
- if ((cbt <= FBTK_CBT_START) || (cbt >= FBTK_CBT_END)) {
- /* type out of range, no way to report error so return NULL */
- return NULL;
- }
-
- return widget->callback[cbt];
-}
-
-fbtk_callback
-fbtk_set_handler(fbtk_widget_t *widget,
- fbtk_callback_type cbt,
- fbtk_callback cb,
- void *context)
-{
- fbtk_callback prevcb;
-
- if ((cbt <= FBTK_CBT_START) || (cbt >= FBTK_CBT_END)) {
- /* type out of range, no way to report error so return NULL */
- return NULL;
- }
-
- prevcb = widget->callback[cbt];
-
- widget->callback[cbt] = cb;
- widget->callback_context[cbt] = context;
-
- return prevcb;
-}
-
-
-void *
-fbtk_get_userpw(fbtk_widget_t *widget)
-{
- if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_USER))
- return NULL;
-
- return widget->u.user.pw;
-}
-
-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);
- widget->u.text.idx = strlen(text);
-
- fbtk_request_redraw(widget);
-}
-
-
-void
-fbtk_set_bitmap(fbtk_widget_t *widget, struct bitmap *image)
-{
- if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_BITMAP))
- return;
-
- widget->u.bitmap.bitmap = image;
-
- fbtk_request_redraw(widget);
-}
-
-void
-fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int height)
-{
- if ((widget->x != x) ||
- (widget->y != y) ||
- (widget->width != width) ||
- (widget->height != height)) {
- widget->x = x;
- widget->y = y;
- widget->width = width;
- widget->height = height;
- fbtk_request_redraw(widget);
- LOG(("%d,%d %d,%d",x,y,width,height));
- }
-}
-
-int
-fbtk_count_children(fbtk_widget_t *widget)
-{
- int count = 0;
- fbtk_widget_list_t *lent;
-
- if (widget->type != FB_WIDGET_TYPE_WINDOW) {
- if (widget->type != FB_WIDGET_TYPE_ROOT)
- return -1;
- widget = widget->u.root.rootw;
- }
-
- lent = widget->u.window.widgets;
-
- while (lent != NULL) {
- count++;
- lent = lent->next;
- }
-
- return count;
-}
-
-
-void
-fbtk_input(fbtk_widget_t *root, nsfb_event_t *event)
-{
- fbtk_widget_t *input;
-
- root = get_root_widget(root);
-
- /* obtain widget with input focus */
- input = root->u.root.input;
- if (input == NULL)
- return; /* no widget with input */
-
- fbtk_post_callback(input, FBTK_CBT_INPUT, event);
-}
-
-void
-fbtk_click(fbtk_widget_t *widget, nsfb_event_t *event)
-{
- fbtk_widget_t *root;
- nsfb_bbox_t cloc;
-
- /* ensure we have the root widget */
- root = get_root_widget(widget);
-
- nsfb_cursor_loc_get(root->u.root.fb, &cloc);
-
-
- /* post the click */
- fbtk_post_callback(root->u.root.rootw, FBTK_CBT_CLICK, event, cloc.x0, cloc.y0);
-}
-
-
-
-void
-fbtk_move_pointer(fbtk_widget_t *widget, int x, int y, bool relative)
-{
- fbtk_widget_t *root;
- nsfb_bbox_t cloc;
-
- /* ensure we have the root widget */
- root = get_root_widget(widget);
-
- if (relative) {
- nsfb_cursor_loc_get(root->u.root.fb, &cloc);
- cloc.x0 += x;
- cloc.y0 += y;
- } else {
- cloc.x0 = x;
- cloc.y0 = y;
- }
-
- root->redraw_required = true;
-
- /* update the pointer cursor */
- nsfb_cursor_loc_set(root->u.root.fb, &cloc);
-
- /* post the movement */
- fbtk_post_callback(root->u.root.rootw, FBTK_CBT_POINTERMOVE, cloc.x0, cloc.y0);
-
-}
-
-bool
-fbtk_redraw_pending(fbtk_widget_t *widget)
-{
- fbtk_widget_t *root;
-
- /* ensure we have the root widget */
- root = get_root_widget(widget);
-
- return root->redraw_required;
-}
-
-int
-fbtk_redraw(fbtk_widget_t *widget)
-{
- fbtk_widget_t *root;
-
- /* ensure we have the root widget */
- root = get_root_widget(widget);
-
- if (!root->redraw_required)
- return 0;
-
- fbtk_post_callback(root->u.root.rootw, FBTK_CBT_REDRAW);
-
- widget->redraw_required = false;
-
- return 1;
-}
-
-/****** widget destruction ********/
-int fbtk_destroy_widget(fbtk_widget_t *widget)
-{
- if (widget->type == FB_WIDGET_TYPE_WINDOW) {
- /* TODO: walk child widgets and destroy them */
- }
-
- remove_widget_from_window(widget->parent, widget);
- free(widget);
-
- return 0;
-}
-
-
-/************** Widget creation *************/
-fbtk_widget_t *
-fbtk_create_text(fbtk_widget_t *window,
- int x, int y,
- int width, int height,
- colour bg, colour fg,
- bool outline)
-{
- fbtk_widget_t *newt = new_widget(FB_WIDGET_TYPE_TEXT);
-
- newt->x = x;
- newt->y = y;
- newt->width = width;
- newt->height = height;
- newt->u.text.outline = outline;
-
- newt->fg = fg;
- newt->bg = bg;
-
- fbtk_set_handler(newt, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
-
- return add_widget_to_window(window, newt);
-}
-
-fbtk_widget_t *
-fbtk_create_bitmap(fbtk_widget_t *window, int x, int y, colour c, struct bitmap *image)
-{
- fbtk_widget_t *newb = new_widget(FB_WIDGET_TYPE_BITMAP);
-
- newb->x = x;
- newb->y = y;
- newb->width = image->width;
- newb->height = image->height;
- newb->bg = c;
-
- newb->u.bitmap.bitmap = image;
-
- fbtk_set_handler(newb, FBTK_CBT_REDRAW, fb_redraw_bitmap, NULL);
-
- return add_widget_to_window(window, newb);
-}
-
-static void
-fbtk_width_height(fbtk_widget_t *parent, int x, int y, int *width, int *height)
-{
- /* make widget fit inside parent */
- if (*width == 0) {
- *width = parent->width - x;
- } else if (*width < 0) {
- *width = parent->width + *width;
- }
- if ((*width + x) > parent->width) {
- *width = parent->width - x;
- }
-
- if (*height == 0) {
- *height = parent->height - y;
- } else if (*height < 0) {
- *height = parent->height + *height;
- }
- if ((*height + y) > parent->height) {
- *height = parent->height - y;
- }
-}
-
-fbtk_widget_t *
-fbtk_create_fill(fbtk_widget_t *window, int x, int y, int width, int height, colour c)
-{
- fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_FILL);
-
- neww->x = x;
- neww->y = y;
- neww->width = width;
- neww->height = height;
-
- fbtk_width_height(window, x, y, &neww->width, &neww->height);
-
- neww->bg = c;
-
- fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_fill, NULL);
-
- return add_widget_to_window(window, neww);
-}
-
-/* set pointer to bitmap in context on cursor move */
-static int
-fbtk_set_ptr_move(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- fbtk_widget_t *root = get_root_widget(widget);
- struct bitmap *bm = cbi->context;
-
- nsfb_cursor_set(root->u.root.fb,
- (nsfb_colour_t *)bm->pixdata,
- bm->width,
- bm->height,
- bm->width);
-
- return 0;
-}
-
-fbtk_widget_t *
-fbtk_create_button(fbtk_widget_t *window,
- int x, int y,
- colour c,
- struct bitmap *image,
- fbtk_callback click,
- void *pw)
-{
- fbtk_widget_t *newb = fbtk_create_bitmap(window, x, y, c, image);
-
- fbtk_set_handler(newb, FBTK_CBT_CLICK, click, pw);
- fbtk_set_handler(newb, FBTK_CBT_POINTERMOVE, fbtk_set_ptr_move, &hand_image);
-
- return newb;
-}
-
-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)
-{
- fbtk_widget_t *newt = fbtk_create_text(window, x, y, width, height,
bg,fg,outline);
- newt->u.text.enter = enter;
- newt->u.text.pw = pw;
-
- fbtk_set_handler(newt, FBTK_CBT_INPUT, text_input, newt);
-
- return newt;
-}
-
-/* create user widget
- *
- * @param x coord relative to parent
- */
-fbtk_widget_t *
-fbtk_create_user(fbtk_widget_t *window,
- int x, int y,
- int width, int height,
- void *pw)
-{
- fbtk_widget_t *newu = new_widget(FB_WIDGET_TYPE_USER);
-
-
- /* make new window fit inside parent */
- if (width == 0) {
- width = window->width - x;
- } else if (width < 0) {
- width = window->width + width;
- }
- if ((width + x) > window->width) {
- width = window->width - x;
- }
-
- if (height == 0) {
- height = window->height - y;
- } else if (height < 0) {
- height = window->height + height;
- }
- if ((height + y) > window->height) {
- height = window->height - y;
- }
-
- newu->x = x;
- newu->y = y;
- newu->width = width;
- newu->height = height;
-
- newu->u.user.pw = pw;
-
- return add_widget_to_window(window, newu);
-}
-
-
-/* create new window
- *
- * @param x coord relative to parent
- */
-fbtk_widget_t *
-fbtk_create_window(fbtk_widget_t *parent,
- int x, int y, int width, int height)
-{
- fbtk_widget_t *newwin;
-
- LOG(("Creating window %p %d,%d %d,%d",parent,x,y,width,height));
- if (parent == NULL)
- return NULL;
-
- if ((parent->type == FB_WIDGET_TYPE_ROOT) &&
- (parent->u.root.rootw != NULL)) {
- LOG(("Using root window"));
- parent = parent->u.root.rootw;
- }
-
- newwin = new_widget(FB_WIDGET_TYPE_WINDOW);
-
- /* make new window fit inside parent */
- if (width == 0) {
- width = parent->width - x;
- } else if (width < 0) {
- width = parent->width + width;
- }
- if ((width + x) > parent->width) {
- width = parent->width - x;
- }
-
- if (height == 0) {
- height = parent->height - y;
- } else if (height < 0) {
- height = parent->height + height;
- }
- if ((height + y) > parent->height) {
- height = parent->height - y;
- }
-
- newwin->x = x;
- newwin->y = y;
- newwin->width = width;
- newwin->height = height;
-
- fbtk_set_handler(newwin, FBTK_CBT_REDRAW, fbtk_window_default_redraw, NULL);
- fbtk_set_handler(newwin, FBTK_CBT_POINTERMOVE, fbtk_window_default_move, NULL);
- fbtk_set_handler(newwin, FBTK_CBT_CLICK, fbtk_window_default_click, NULL);
- LOG(("Created window %p %d,%d %d,%d",newwin,x,y,width,height));
-
- return add_widget_to_window(parent, newwin);
-}
-
-int
-fbtk_post_callback(fbtk_widget_t *widget, fbtk_callback_type cbt, ...)
-{
- fbtk_callback_info cbi;
- int ret = 0;
- va_list ap;
-
- if (widget->callback[cbt] != NULL) {
- cbi.type = cbt;
- cbi.context = widget->callback_context[cbt];
-
- va_start(ap, cbt);
-
- switch (cbt) {
- case FBTK_CBT_SCROLLX:
- cbi.x = va_arg(ap,int);
- break;
-
- case FBTK_CBT_SCROLLY:
- cbi.y = va_arg(ap,int);
- break;
-
- case FBTK_CBT_CLICK:
- cbi.event = va_arg(ap, void *);
- cbi.x = va_arg(ap, int);
- cbi.y = va_arg(ap, int);
- break;
-
- case FBTK_CBT_INPUT:
- cbi.event = va_arg(ap, void *);
- break;
-
- case FBTK_CBT_POINTERMOVE:
- cbi.x = va_arg(ap, int);
- cbi.y = va_arg(ap, int);
- break;
-
- case FBTK_CBT_REDRAW:
- break;
-
- case FBTK_CBT_USER:
- break;
-
- default:
- break;
- }
- va_end(ap);
-
- ret = (widget->callback[cbt])(widget, &cbi);
- }
-
- return ret;
-}
-
-bool fbtk_event(fbtk_widget_t *root, nsfb_event_t *event, int timeout)
-{
- bool unused = false; /* is the event available */
-
- /* ensure we have the root widget */
- root = get_root_widget(root);
-
- //LOG(("Reading event with timeout %d",timeout));
-
- if (nsfb_event(root->u.root.fb, event, timeout) == false)
- return false;
-
- switch (event->type) {
- case NSFB_EVENT_KEY_DOWN:
- case NSFB_EVENT_KEY_UP:
- if ((event->value.controlcode >= NSFB_KEY_MOUSE_1) &&
- (event->value.controlcode <= NSFB_KEY_MOUSE_5)) {
- fbtk_click(root, event);
- } else {
- fbtk_input(root, event);
- }
- break;
-
- case NSFB_EVENT_CONTROL:
- unused = true;
- break;
-
- case NSFB_EVENT_MOVE_RELATIVE:
- fbtk_move_pointer(root, event->value.vector.x,
event->value.vector.y, true);
- break;
-
- case NSFB_EVENT_MOVE_ABSOLUTE:
- fbtk_move_pointer(root, event->value.vector.x,
event->value.vector.y, false);
- break;
-
- default:
- break;
-
- }
- return unused;
-}
-
-
-nsfb_t *
-fbtk_get_nsfb(fbtk_widget_t *widget)
-{
- fbtk_widget_t *root;
-
- /* ensure we have the root widget */
- root = get_root_widget(widget);
-
- return root->u.root.fb;
-}
-
-/* Initialise toolkit for use */
-fbtk_widget_t *
-fbtk_init(nsfb_t *fb)
-{
- fbtk_widget_t *root = new_widget(FB_WIDGET_TYPE_ROOT);
-
- nsfb_get_geometry(fb, &root->width, &root->height, NULL);
-
- LOG(("width %d height %d",root->width, root->height));
- root->u.root.fb = fb;
- root->x = 0;
- root->y = 0;
- root->u.root.rootw = fbtk_create_window(root, 0, 0, 0, 0);
-
- return root;
-}
-
-static int keymap[] = {
- /* 0 1 2 3 4 5 6 7 8 9 */
- -1, -1, -1, -1, -1, -1, -1, -1, 8, 9, /* 0 - 9 */
- -1, -1, -1, 13, -1, -1, -1, -1, -1, -1, /* 10 - 19 */
- -1, -1, -1, -1, -1, -1, -1, 27, -1, -1, /* 20 - 29 */
- -1, -1, ' ', '!', '"', '#', '$',
-1, '&','\'', /* 30 - 39 */
- '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', /* 40 - 49 */
- '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', /* 50 - 59 */
- '<', '=', '>', '?', '@', -1, -1,
-1, -1, -1, /* 60 - 69 */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 - 79 */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 89 */
- -1, '[','\\', ']', '~', '_',
'`', 'a', 'b', 'c', /* 90 - 99 */
- 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', /* 100 - 109 */
- 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', /* 110 - 119 */
- 'x', 'y', 'z', -1, -1, -1, -1, -1, -1, -1, /* 120
- 129 */
-};
-
-static int sh_keymap[] = {
- /* 0 1 2 3 4 5 6 7 8 9 */
- -1, -1, -1, -1, -1, -1, -1, -1, 8, 9, /* 0 - 9 */
- -1, -1, -1, 13, -1, -1, -1, -1, -1, -1, /* 10 - 19 */
- -1, -1, -1, -1, -1, -1, -1, 27, -1, -1, /* 20 - 29 */
- -1, -1, ' ', '!', '"', '~', '$',
-1, '&', '@', /* 30 - 39 */
- '(', ')', '*', '+', '<', '_',
'>', '?', ')', '!', /* 40 - 49 */
- '"', 243, '$', '%', '^', '&',
'*', '(', ';', ':', /* 50 - 59 */
- '<', '+', '>', '?', '@', -1, -1,
-1, -1, -1, /* 60 - 69 */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 - 79 */
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 89 */
- -1, '{', '|', '}', '~', '_', 254,
'A', 'B', 'C', /* 90 - 99 */
- 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', /* 100 - 109 */
- 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', /* 110 - 119 */
- 'X', 'Y', 'Z', -1, -1, -1, -1, -1, -1, -1, /* 120
- 129 */
-};
-
-
-/* performs character mapping */
-int fbtk_keycode_to_ucs4(int code, uint8_t mods)
-{
- int ucs4 = -1;
-
- if (mods) {
- if ((code >= 0) && (code < (int) NOF_ELEMENTS(sh_keymap)))
- ucs4 = sh_keymap[code];
- } else {
- if ((code >= 0) && (code < (int) NOF_ELEMENTS(keymap)))
- ucs4 = keymap[code];
- }
- return ucs4;
-}
-
-/*
- * Local Variables:
- * c-basic-offset:8
- * End:
- */
Removed: branches/paulblokus/treeview/framebuffer/fbtk_widget.h
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/framebuffe...
==============================================================================
--- branches/paulblokus/treeview/framebuffer/fbtk_widget.h (original)
+++ branches/paulblokus/treeview/framebuffer/fbtk_widget.h (removed)
@@ -1,109 +1,0 @@
-/*
- * Copyright 2008 Vincent Sanders <vince(a)simtec.co.uk>
- *
- * 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/>.
- */
-
-#ifndef NETSURF_FB_FBTK_WIDGET_H
-#define NETSURF_FB_FBTK_WIDGET_H
-
-enum fbtk_widgettype_e {
- FB_WIDGET_TYPE_ROOT = 0,
- FB_WIDGET_TYPE_WINDOW,
- FB_WIDGET_TYPE_BITMAP,
- FB_WIDGET_TYPE_FILL,
- FB_WIDGET_TYPE_TEXT,
- FB_WIDGET_TYPE_HSCROLL,
- FB_WIDGET_TYPE_VSCROLL,
- FB_WIDGET_TYPE_USER,
-};
-
-typedef struct fbtk_widget_list_s fbtk_widget_list_t;
-
-/* wrapper struct for all widget types */
-struct fbtk_widget_s {
- /* Generic properties */
- int x;
- int y;
- int width;
- int height;
- colour bg;
- colour fg;
-
- /* event callback handlers */
- fbtk_callback callback[FBTK_CBT_END];
- void *callback_context[FBTK_CBT_END];
-
- bool redraw_required; /* the widget requires redrawing */
-
- fbtk_widget_t *parent; /* parent widget */
-
- /* Widget specific */
- enum fbtk_widgettype_e type;
-
- union {
- /* toolkit base handle */
- struct {
- nsfb_t *fb;
- fbtk_widget_t *rootw;
- fbtk_widget_t *input;
- } root;
-
- /* window */
- struct {
- /* widgets associated with this window */
- fbtk_widget_list_t *widgets; /* begining of list */
- fbtk_widget_list_t *widgets_end; /* end of list */
- } window;
-
- /* bitmap */
- struct {
- struct bitmap *bitmap;
- } bitmap;
-
- /* text */
- struct {
- char* text;
- bool outline;
- fbtk_enter_t enter;
- void *pw;
- int idx;
- } text;
-
- /* application driven widget */
- struct {
- void *pw; /* private data for user widget */
- } user;
-
- struct {
- int pos;
- int pct;
- struct fbtk_widget_s *btnul; /* scroll button up/left */
- struct fbtk_widget_s *btndr; /* scroll button down/right*/
- } scroll;
-
- } u;
-};
-
-
-/* widget manipulation functions */
-
-fbtk_widget_t *get_root_widget(fbtk_widget_t *widget);
-
-fbtk_widget_t *new_widget(enum fbtk_widgettype_e type);
-
-fbtk_widget_t *add_widget_to_window(fbtk_widget_t *window, fbtk_widget_t *widget);
-
-#endif
Removed: branches/paulblokus/treeview/framebuffer/fbtk_widget_scroll.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/framebuffe...
==============================================================================
--- branches/paulblokus/treeview/framebuffer/fbtk_widget_scroll.c (original)
+++ branches/paulblokus/treeview/framebuffer/fbtk_widget_scroll.c (removed)
@@ -1,305 +1,0 @@
-/*
- * Copyright 2008 Vincent Sanders <vince(a)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>
-
-#include <libnsfb.h>
-#include <libnsfb_plot.h>
-#include <libnsfb_event.h>
-#include <libnsfb_cursor.h>
-
-#include "utils/log.h"
-#include "desktop/browser.h"
-
-#include "framebuffer/gui.h"
-#include "framebuffer/fbtk.h"
-#include "framebuffer/fbtk_widget.h"
-#include "framebuffer/bitmap.h"
-#include "framebuffer/image_data.h"
-
-/** Vertical scroll widget */
-
-static int
-vscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int vscroll;
- int vpos;
-
- nsfb_bbox_t bbox;
- nsfb_bbox_t rect;
- fbtk_widget_t *root = get_root_widget(widget);
-
- fbtk_get_bbox(widget, &bbox);
-
- nsfb_claim(root->u.root.fb, &bbox);
-
- rect = bbox;
-
- /* background */
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
-
- rect.x0 = bbox.x0 + 2;
- rect.y0 = bbox.y0 + 1;
- rect.x1 = bbox.x1 - 3;
- rect.y1 = bbox.y1 - 2;
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
-
- /* scroll well */
- nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
-
- /* scroll well outline */
- vscroll = ((widget->height - 4) * widget->u.scroll.pct) / 100 ;
- vpos = ((widget->height - 4) * widget->u.scroll.pos) / 100 ;
-
- LOG(("scroll %d",vscroll));
-
- rect.x0 = bbox.x0 + 5;
- rect.y0 = bbox.y0 + 3 + vpos;
- rect.x1 = bbox.x0 + widget->width - 5;
- rect.y1 = bbox.y0 + vscroll + vpos;
-
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
-
- nsfb_update(root->u.root.fb, &bbox);
-
- return 0;
-}
-
-static int
-vscrollu_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int ret = 0;
- if (cbi->event->type == NSFB_EVENT_KEY_DOWN)
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, -1);
- return ret;
-}
-
-static int
-vscrolld_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int ret = 0;
- if (cbi->event->type == NSFB_EVENT_KEY_DOWN)
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, 1);
- return ret;
-}
-
-static int
-vscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int vscroll;
- int vpos;
- int ret = 0;
-
- if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
- return 0;
-
- vscroll = ((widget->height - 4) * widget->u.scroll.pct) / 100 ;
- vpos = ((widget->height - 4) * widget->u.scroll.pos) / 100 ;
-
- if (cbi->y < vpos) {
- /* above bar */
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, -1);
- } else if (cbi->y > (vpos + vscroll)) {
- /* below bar */
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLY, 1);
- }
- return ret;
-}
-
-
-fbtk_widget_t *
-fbtk_create_vscroll(fbtk_widget_t *window,
- int x, int y,
- int width, int height,
- colour fg,
- colour bg,
- fbtk_callback callback,
- void *context)
-{
- fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_VSCROLL);
-
- neww->x = x;
- neww->y = y + scrollu.height;
- neww->width = width;
- neww->height = height - scrollu.height - scrolld.height;
- neww->fg = fg;
- neww->bg = bg;
-
- fbtk_set_handler(neww, FBTK_CBT_REDRAW, vscroll_redraw, NULL);
-
- fbtk_set_handler(neww, FBTK_CBT_CLICK, vscrollarea_click, neww);
-
- fbtk_set_handler(neww, FBTK_CBT_SCROLLY, callback, context);
-
- neww->u.scroll.btnul = fbtk_create_button(window, x + (width - scrollu.width) / 2, y,
fg, &scrollu, vscrollu_click, neww);
-
- neww->u.scroll.btndr = fbtk_create_button(window, x + (width - scrolld.width) / 2, y
+ height - scrolld.height, fg, &scrolld, vscrolld_click, neww);
-
-
- return add_widget_to_window(window, neww);
-}
-
-/* Horizontal scroll widget */
-
-static int
-hscroll_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int hscroll;
- int hpos;
- nsfb_bbox_t bbox;
- nsfb_bbox_t rect;
- fbtk_widget_t *root = get_root_widget(widget);
-
- fbtk_get_bbox(widget, &bbox);
-
- nsfb_claim(root->u.root.fb, &bbox);
-
- rect = bbox;
-
- /* background */
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
-
- /* scroll well */
- rect.x0 = bbox.x0 + 1;
- rect.y0 = bbox.y0 + 2;
- rect.x1 = bbox.x1 - 2;
- rect.y1 = bbox.y1 - 3;
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->fg);
-
- /* scroll well outline */
- nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0xFF999999, false, false);
-
- hscroll = ((widget->width - 4) * widget->u.scroll.pct) / 100 ;
- hpos = ((widget->width - 4) * widget->u.scroll.pos) / 100 ;
-
- LOG(("hscroll %d",hscroll));
-
- rect.x0 = bbox.x0 + 3 + hpos;
- rect.y0 = bbox.y0 + 5;
- rect.x1 = bbox.x0 + hscroll + hpos;
- rect.y1 = bbox.y0 + widget->height - 5;
-
- nsfb_plot_rectangle_fill(root->u.root.fb, &rect, widget->bg);
-
- nsfb_update(root->u.root.fb, &bbox);
-
- return 0;
-}
-
-static int
-hscrolll_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int ret = 0;
- if (cbi->event->type == NSFB_EVENT_KEY_DOWN)
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, -1);
- return ret;
-}
-
-static int
-hscrollr_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int ret = 0;
- if (cbi->event->type == NSFB_EVENT_KEY_DOWN)
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, 1);
- return ret;
-}
-
-static int
-hscrollarea_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
-{
- int hscroll;
- int hpos;
- int ret;
-
- if (cbi->event->type != NSFB_EVENT_KEY_DOWN)
- return 0;
-
- hscroll = ((widget->width - 4) * widget->u.scroll.pct) / 100 ;
- hpos = ((widget->width - 4) * widget->u.scroll.pos) / 100 ;
-
- if (cbi->x < hpos) {
- /* above bar */
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, -1);
- } else if (cbi->x > (hpos + hscroll)) {
- /* below bar */
- ret = fbtk_post_callback(cbi->context, FBTK_CBT_SCROLLX, 1);
- }
- return ret;
-}
-
-fbtk_widget_t *
-fbtk_create_hscroll(fbtk_widget_t *window,
- int x, int y,
- int width, int height,
- colour fg,
- colour bg,
- fbtk_callback callback,
- void *context)
-{
- fbtk_widget_t *neww = new_widget(FB_WIDGET_TYPE_HSCROLL);
-
- neww->x = x + scrolll.width;
- neww->y = y;
- neww->width = width - scrolll.width - scrollr.width;
- neww->height = height;
- neww->fg = fg;
- neww->bg = bg;
-
- fbtk_set_handler(neww, FBTK_CBT_REDRAW, hscroll_redraw, NULL);
- fbtk_set_handler(neww, FBTK_CBT_CLICK, hscrollarea_click, neww);
- fbtk_set_handler(neww, FBTK_CBT_SCROLLX, callback, context);
-
- neww->u.scroll.btnul = fbtk_create_button(window, x, y + ((height - scrolll.height) /
2), fg, &scrolll, hscrolll_click, neww);
-
- neww->u.scroll.btndr = fbtk_create_button(window, x + width - scrollr.width, y +
((height - scrolll.height) / 2), fg, &scrollr, hscrollr_click, neww);
-
- return add_widget_to_window(window, neww);
-}
-
-
-void
-fbtk_set_scroll(fbtk_widget_t *widget, int pct)
-{
- if (widget == NULL)
- return;
-
- if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
- (widget->type == FB_WIDGET_TYPE_VSCROLL)) {
-
- widget->u.scroll.pct = pct;
- fbtk_request_redraw(widget);
- }
-}
-
-void
-fbtk_set_scroll_pos(fbtk_widget_t *widget, int pos)
-{
- if (widget == NULL)
- return;
-
- if ((widget->type == FB_WIDGET_TYPE_HSCROLL) ||
- (widget->type == FB_WIDGET_TYPE_VSCROLL)) {
-
- widget->u.scroll.pos = pos;
-
- fbtk_request_redraw(widget);
- }
-}
-
Removed: branches/paulblokus/treeview/render/directory.c
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/render/dir...
==============================================================================
--- branches/paulblokus/treeview/render/directory.c (original)
+++ branches/paulblokus/treeview/render/directory.c (removed)
@@ -1,291 +1,0 @@
-/*
- * Copyright 2006 Richard Wilson <info(a)tinct.net>
- * Copyright 2010 Chris Young <chris(a)unsatisfactorysoftware.co.uk>
- * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
- *
- * 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/>.
- */
-
-/** \file
- * Content for directory listings (implementation).
- */
-
-#include <sys/types.h>
-#include <dirent.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <time.h>
-#include "content/content_protected.h"
-#include "content/dirlist.h"
-#include "content/fetch.h"
-#include "render/directory.h"
-#include "render/html.h"
-#include "utils/messages.h"
-#include "utils/url.h"
-#include "utils/utils.h"
-
-#define MAX_LENGTH 2048
-
-bool directory_create(struct content *c, const struct http_parameter *params) {
- if (!html_create(c, params))
- /* html_create() must have broadcast MSG_ERROR already, so we
- * don't need to. */
- return false;
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) dirlist_generate_top(),
- strlen(dirlist_generate_top()));
-
- return true;
-}
-
-bool directory_convert(struct content *c) {
- char *path;
- DIR *parent;
- struct dirent *entry;
- union content_msg_data msg_data;
- char buffer[MAX_LENGTH];
- char *nice_path, *cnv, *tmp;
- url_func_result res;
- bool compare, directory;
- char *up;
- struct stat filestat;
- char *filepath, *mimetype = NULL;
- int filepath_size;
- char *urlpath;
- int urlpath_size;
- char moddate[100];
- char modtime[100];
- long long filesize;
- bool extendedinfo, evenrow = false;
- char *title;
- int title_length;
-
- /* Get directory path from URL */
- path = url_to_path(content__get_url(c));
- if (!path) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- /* Convert path for display */
- nice_path = malloc(strlen(path) * 4 + 1);
- if (!nice_path) {
- msg_data.error = messages_get("MiscErr");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
- /* Escape special HTML characters */
- for (cnv = nice_path, tmp = path; *tmp != '\0'; tmp++) {
- if (*tmp == '<') {
- *cnv++ = '&';
- *cnv++ = 'l';
- *cnv++ = 't';
- *cnv++ = ';';
- } else if (*tmp == '>') {
- *cnv++ = '&';
- *cnv++ = 'g';
- *cnv++ = 't';
- *cnv++ = ';';
- } else {
- *cnv++ = *tmp;
- }
- }
- *cnv = '\0';
-
- /* Set which columns to suppress */
- dirlist_generate_hide_columns(0, buffer, MAX_LENGTH);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) buffer, strlen(buffer));
-
- /* Construct a localised title string */
- title_length = strlen(nice_path) + strlen(messages_get("FileIndex"));
- title = malloc(title_length);
-
- if(title == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- /* Set title to localised "Index of <nice_path>" */
- snprintf(title, title_length, messages_get("FileIndex"), nice_path);
-
- /* Print document title and heading */
- dirlist_generate_title(title, buffer, MAX_LENGTH);
- free(nice_path);
- free(title);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) buffer, strlen(buffer));
-
- /* Print parent directory link */
- res = url_parent(content__get_url(c), &up);
- if (res == URL_FUNC_OK) {
- res = url_compare(content__get_url(c), up, false, &compare);
- if ((res == URL_FUNC_OK) && !compare) {
- dirlist_generate_parent_link(up, buffer, MAX_LENGTH);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) buffer, strlen(buffer));
- }
- free(up);
- }
-
- /* Print directory contents table column headings */
- dirlist_generate_headings(buffer, MAX_LENGTH);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) buffer, strlen(buffer));
-
- if ((parent = opendir(path)) == NULL) {
- msg_data.error = messages_get("EmptyErr");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- /* Print a row for each item in the directory */
- while ((entry = readdir(parent)) != NULL) {
- if (!strcmp(entry->d_name, ".") ||
- !strcmp(entry->d_name, ".."))
- /* Skip . and .. entries */
- continue;
-
- filepath_size = strlen(path) + strlen(entry->d_name) + 2;
- filepath = malloc(filepath_size);
- if (filepath != NULL) {
- strcpy(filepath, path);
- if (path_add_part(filepath, filepath_size,
- entry->d_name) == false) {
- msg_data.error = messages_get("MiscErr");
- content_broadcast(c, CONTENT_MSG_ERROR,
- msg_data);
- return false;
- }
- if (stat(filepath, &filestat) == 0)
- extendedinfo = true;
- else
- extendedinfo = false;
- } else {
- msg_data.error = messages_get("MiscErr");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- return false;
- }
-
- if (S_ISDIR(filestat.st_mode))
- directory = true;
- else
- directory = false;
-
- urlpath_size = strlen(content__get_url(c)) +
- strlen(entry->d_name) + 2;
- urlpath = malloc(urlpath_size);
- if (urlpath != NULL) {
- strcpy(urlpath, content__get_url(c));
- if(urlpath[strlen(urlpath) - 1] != '/')
- strncat(urlpath, "/", urlpath_size);
- strncat(urlpath, entry->d_name, urlpath_size);
-
- if (extendedinfo == true) {
- /* Get date in output format */
- if (strftime((char *)&moddate, sizeof moddate,
- "%a %d %b %Y",
- localtime(
- &filestat.st_mtime)) == 0)
- strncpy(moddate, "-", sizeof moddate);
- /* Get time in output format */
- if (strftime((char *)&modtime, sizeof modtime,
- "%H:%M",
- localtime(
- &filestat.st_mtime)) == 0)
- strncpy(modtime, "-", sizeof modtime);
-
- if (directory) {
- mimetype = strdup((char*)messages_get(
- "FileDirectory"));
- filesize = -1;
- } else {
- mimetype = fetch_mimetype(filepath);
- filesize = (long long)
- filestat.st_size;
- }
- } else {
- strncpy(moddate, "", sizeof moddate);
- strncpy(modtime, "", sizeof modtime);
- filesize = -1;
- }
- /* Print row */
- dirlist_generate_row(evenrow, directory,
- urlpath, entry->d_name,
- mimetype ? mimetype : (char*)"",
- filesize,
- moddate, modtime,
- buffer, MAX_LENGTH);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) buffer, strlen(buffer));
-
- free(urlpath);
- }
-
- if (evenrow == false)
- evenrow = true;
- else
- evenrow = false;
-
- if (mimetype != NULL) {
- free(mimetype);
- mimetype = NULL;
- }
- free(filepath);
- }
- closedir(parent);
-
- binding_parse_chunk(c->data.html.parser_binding,
- (uint8_t *) dirlist_generate_bottom(),
- strlen(dirlist_generate_bottom()));
-
- c->type = CONTENT_HTML;
- return html_convert(c);
-}
-
-void directory_destroy(struct content *c)
-{
- /* This will only get called if the content is destroyed before
- * content_convert() is called. Simply force the type to HTML and
- * delegate the cleanup to html_destroy() */
-
- c->type = CONTENT_HTML;
-
- html_destroy(c);
-
- return;
-}
-
-bool directory_clone(const struct content *old, struct content *new_content)
-{
- /* This will only get called if the content is cloned before
- * content_convert() is called. Simply replay creation. */
- if (directory_create(new_content, NULL) == false)
- return false;
-
- return true;
-}
-
Removed: branches/paulblokus/treeview/render/directory.h
URL:
http://source.netsurf-browser.org/branches/paulblokus/treeview/render/dir...
==============================================================================
--- branches/paulblokus/treeview/render/directory.h (original)
+++ branches/paulblokus/treeview/render/directory.h (removed)
@@ -1,38 +1,0 @@
-/*
- * Copyright 2006 Richard Wilson <info(a)tinct.net>
- *
- * 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/>.
- */
-
-/** \file
- * Content for directory listings (interface).
- *
- * These functions should in general be called via the content interface.
- */
-
-#ifndef _NETSURF_RENDER_DIRECTORY_H_
-#define _NETSURF_RENDER_DIRECTORY_H_
-
-#include <stdbool.h>
-#include "content/content_type.h"
-
-struct http_parameter;
-
-bool directory_create(struct content *c, const struct http_parameter *params);
-bool directory_convert(struct content *c);
-void directory_destroy(struct content *c);
-bool directory_clone(const struct content *old, struct content *new_content);
-
-#endif