From a66adbbfefcc61f4f577b80398a9a0d8941b8441 Mon Sep 17 00:00:00 2001 From: François Revel Date: Thu, 22 Mar 2012 21:48:24 +0000 Subject: Rename BeOS frontend files to strip the useless beos_ prefix. Fix includes and the rest so it builds. svn path=/trunk/netsurf/; revision=13554 --- beos/Makefile.target | 16 +- beos/about.cpp | 145 +++ beos/about.h | 24 + beos/beos_about.cpp | 145 --- beos/beos_about.h | 24 - beos/beos_bitmap.cpp | 424 -------- beos/beos_bitmap.h | 34 - beos/beos_fetch_rsrc.cpp | 383 ------- beos/beos_fetch_rsrc.h | 35 - beos/beos_filetype.cpp | 143 --- beos/beos_filetype.h | 20 - beos/beos_font.cpp | 376 ------- beos/beos_font.h | 31 - beos/beos_gui.cpp | 1195 --------------------- beos/beos_gui.h | 71 -- beos/beos_login.cpp | 199 ---- beos/beos_options.cpp | 49 - beos/beos_options.h | 34 - beos/beos_plotters.cpp | 894 ---------------- beos/beos_plotters.h | 56 - beos/beos_res.h | 30 - beos/beos_res.rdef | 399 ------- beos/beos_save_complete.cpp | 85 -- beos/beos_scaffolding.cpp | 2417 ------------------------------------------- beos/beos_scaffolding.h | 203 ---- beos/beos_schedule.cpp | 133 --- beos/beos_schedule.h | 26 - beos/beos_search.cpp | 76 -- beos/beos_throbber.cpp | 119 --- beos/beos_throbber.h | 36 - beos/beos_thumbnail.cpp | 168 --- beos/beos_treeview.cpp | 56 - beos/beos_window.cpp | 1773 ------------------------------- beos/beos_window.h | 64 -- beos/bitmap.cpp | 424 ++++++++ beos/bitmap.h | 34 + beos/fetch_rsrc.cpp | 383 +++++++ beos/fetch_rsrc.h | 35 + beos/filetype.cpp | 143 +++ beos/filetype.h | 20 + beos/font.cpp | 376 +++++++ beos/font.h | 31 + beos/gui.cpp | 1195 +++++++++++++++++++++ beos/gui.h | 71 ++ beos/gui_options.cpp | 49 + beos/gui_options.h | 34 + beos/login.cpp | 199 ++++ beos/plotters.cpp | 894 ++++++++++++++++ beos/plotters.h | 56 + beos/res.h | 30 + beos/res.rdef | 399 +++++++ beos/save_complete.cpp | 85 ++ beos/scaffolding.cpp | 2417 +++++++++++++++++++++++++++++++++++++++++++ beos/scaffolding.h | 203 ++++ beos/schedule.cpp | 133 +++ beos/schedule.h | 26 + beos/search.cpp | 76 ++ beos/system_colour.cpp | 2 +- beos/throbber.cpp | 119 +++ beos/throbber.h | 36 + beos/thumbnail.cpp | 168 +++ beos/treeview.cpp | 56 + beos/window.cpp | 1773 +++++++++++++++++++++++++++++++ beos/window.h | 64 ++ 64 files changed, 9707 insertions(+), 9707 deletions(-) create mode 100644 beos/about.cpp create mode 100644 beos/about.h delete mode 100644 beos/beos_about.cpp delete mode 100644 beos/beos_about.h delete mode 100644 beos/beos_bitmap.cpp delete mode 100644 beos/beos_bitmap.h delete mode 100644 beos/beos_fetch_rsrc.cpp delete mode 100644 beos/beos_fetch_rsrc.h delete mode 100644 beos/beos_filetype.cpp delete mode 100644 beos/beos_filetype.h delete mode 100644 beos/beos_font.cpp delete mode 100644 beos/beos_font.h delete mode 100644 beos/beos_gui.cpp delete mode 100644 beos/beos_gui.h delete mode 100644 beos/beos_login.cpp delete mode 100644 beos/beos_options.cpp delete mode 100644 beos/beos_options.h delete mode 100644 beos/beos_plotters.cpp delete mode 100644 beos/beos_plotters.h delete mode 100644 beos/beos_res.h delete mode 100644 beos/beos_res.rdef delete mode 100644 beos/beos_save_complete.cpp delete mode 100644 beos/beos_scaffolding.cpp delete mode 100644 beos/beos_scaffolding.h delete mode 100644 beos/beos_schedule.cpp delete mode 100644 beos/beos_schedule.h delete mode 100644 beos/beos_search.cpp delete mode 100644 beos/beos_throbber.cpp delete mode 100644 beos/beos_throbber.h delete mode 100644 beos/beos_thumbnail.cpp delete mode 100644 beos/beos_treeview.cpp delete mode 100644 beos/beos_window.cpp delete mode 100644 beos/beos_window.h create mode 100644 beos/bitmap.cpp create mode 100644 beos/bitmap.h create mode 100644 beos/fetch_rsrc.cpp create mode 100644 beos/fetch_rsrc.h create mode 100644 beos/filetype.cpp create mode 100644 beos/filetype.h create mode 100644 beos/font.cpp create mode 100644 beos/font.h create mode 100644 beos/gui.cpp create mode 100644 beos/gui.h create mode 100644 beos/gui_options.cpp create mode 100644 beos/gui_options.h create mode 100644 beos/login.cpp create mode 100644 beos/plotters.cpp create mode 100644 beos/plotters.h create mode 100644 beos/res.h create mode 100644 beos/res.rdef create mode 100644 beos/save_complete.cpp create mode 100644 beos/scaffolding.cpp create mode 100644 beos/scaffolding.h create mode 100644 beos/schedule.cpp create mode 100644 beos/schedule.h create mode 100644 beos/search.cpp create mode 100644 beos/throbber.cpp create mode 100644 beos/throbber.h create mode 100644 beos/thumbnail.cpp create mode 100644 beos/treeview.cpp create mode 100644 beos/window.cpp create mode 100644 beos/window.h (limited to 'beos') diff --git a/beos/Makefile.target b/beos/Makefile.target index 9436e3d2c..964907ed3 100644 --- a/beos/Makefile.target +++ b/beos/Makefile.target @@ -84,18 +84,18 @@ # ---------------------------------------------------------------------------- # S_BEOS are sources purely for the BeOS build -S_BEOS := beos_about.cpp beos_bitmap.cpp beos_fetch_rsrc.cpp \ - beos_filetype.cpp beos_font.cpp beos_gui.cpp beos_login.cpp \ - beos_options.cpp beos_plotters.cpp beos_save_complete.cpp \ - beos_scaffolding.cpp beos_search.cpp beos_schedule.cpp \ - beos_thumbnail.cpp beos_treeview.cpp beos_throbber.cpp \ - beos_window.cpp system_colour.cpp +S_BEOS := about.cpp bitmap.cpp fetch_rsrc.cpp \ + filetype.cpp font.cpp gui.cpp login.cpp \ + gui_options.cpp plotters.cpp save_complete.cpp \ + scaffolding.cpp search.cpp schedule.cpp \ + thumbnail.cpp treeview.cpp throbber.cpp \ + window.cpp system_colour.cpp S_BEOS := $(addprefix beos/,$(S_BEOS)) -RDEF_BEOS := beos_res.rdef +RDEF_BEOS := res.rdef RDEF_BEOS := $(addprefix beos/,$(RDEF_BEOS)) -RDEF_IMP_BEOS := beos_res_import.rdef +RDEF_IMP_BEOS := res_import.rdef RDEF_IMP_BEOS := $(addprefix $(OBJROOT)/,$(subst /,_,$(RDEF_IMP_BEOS))) RDEP_BEOS := \ diff --git a/beos/about.cpp b/beos/about.cpp new file mode 100644 index 000000000..e5d79df4d --- /dev/null +++ b/beos/about.cpp @@ -0,0 +1,145 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +extern "C" { +#include "utils/log.h" +} +#include "beos/about.h" +#include "beos/scaffolding.h" +#include "beos/window.h" + +#include +#include +#include +#include + +static const char *authors[] = { + "John-Mark Bell", "James Bursa", "Michael Drake", + "Rob Kendrick", "Adrian Lees", "Vincent Sanders", + "Daniel Silverstone", "Richard Wilson", + "\nContributors:", "Kevin Bagust", "Stefaan Claes", + "Matthew Hambley", "Rob Jackson", "Jeffrey Lee", "Phil Mellor", + "Philip Pemberton", "Darren Salt", "Andrew Timmins", + "John Tytgat", "Chris Williams", + "\nGoogle Summer of Code Contributors:", "Adam Blokus", + "Sean Fox", "Michael Lester", "Andrew Sidwell", NULL +}; + +static const char *translators[] = { "Sebastian Barthel", "Bruno D'Arcangeli", + "Gerard van Katwijk", "Jérôme Mathevet", "Simon Voortman.", NULL +}; +static const char *artists[] = { + "Michael Drake", "\nContributors:", "Andrew Duffell", + "John Duffell", "Richard Hallas", "Phil Mellor", NULL +}; + +static const char *documenters[] = { + "John-Mark Bell", "James Bursa", "Michael Drake", + "Richard Wilson", "\nContributors:", "James Shaw", NULL +}; + +static const char *name = "NetSurf"; +static const char *description = + "Small as a mouse, fast as a cheetah, and available for free.\n" + "NetSurf is a web browser for RISC OS and UNIX-like platforms."; +static const char *url = "http://www.netsurf-browser.org/"; +static const char *url_label = "NetSurf Website"; +static const char *copyright = + "Copyright © 2003 - 2008 The NetSurf Developers"; + +static void add_section(BTextView *textview, const char *header, + const char *text) +{ + BFont titleFont; + titleFont.SetSize(titleFont.Size() + 10); + BFont textFont; + text_run_array titleRuns = { 1, { 0, titleFont, { 0, 0, 0, 255 } } }; + text_run_array textRuns = { 1, { 0, textFont, { 0, 0, 0, 255 } } }; + BString h(header); + BString t(text); + h << "\n"; + t << "\n\n"; + if (header) + textview->Insert(h.String(), &titleRuns); + if (text) + textview->Insert(t.String(), &textRuns); +} + +static void add_section(BTextView *textview, const char *header, + const char **texts) +{ + BString t; + while (*texts) { + t << *texts; + t << ", "; + texts++; + } + add_section(textview, header, t.String()); +} + +/** + * Creates the about alert + */ +void nsbeos_about(struct gui_window *gui) +{ + BAlert *alert; + alert = new BAlert("about", "", /*"HomePage",*/ "Ok"); + //XXX: i18n-ize + BTextView *tv = alert->TextView(); + if (gui) { + alert->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); + nsbeos_scaffolding *s = nsbeos_get_scaffold(gui); + if (s) { + NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s); + if (w) + alert->AddToSubset(w); + } + } + tv->SetStylable(true); + add_section(tv, name, description); + add_section(tv, NULL, copyright); + add_section(tv, "authors", authors); + add_section(tv, "translators", translators); + add_section(tv, "artists", artists); + add_section(tv, "documenters", documenters); + add_section(tv, url_label, url); +#if 0 + BView *p = tv->Parent(); + //tv->MakeSelectable(true); + + //tv->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); + //tv->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); + if (p && p->RemoveChild(tv)) { + BScrollView *sv = new BScrollView("sv", tv, B_FOLLOW_ALL, 0, + false, true, B_NO_BORDER); + p->AddChild(sv); + } + + //tv->ResizeToPreferred(); +#endif + // make space for controls + alert->ResizeBy(200, 500); + alert->MoveTo(alert->AlertPosition(alert->Frame().Width() + 1, + alert->Frame().Height() + 1)); + + alert->Go(NULL); +} diff --git a/beos/about.h b/beos/about.h new file mode 100644 index 000000000..f80d33f01 --- /dev/null +++ b/beos/about.h @@ -0,0 +1,24 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#ifndef __BEOS_ABOUT_H__ +#define __BEOS_ABOUT_H__ + +void nsbeos_about(struct gui_window *gui); + +#endif /* __BEOS_ABOUT_H__ */ diff --git a/beos/beos_about.cpp b/beos/beos_about.cpp deleted file mode 100644 index 2d8aaff9f..000000000 --- a/beos/beos_about.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -extern "C" { -#include "utils/log.h" -} -#include "beos/beos_about.h" -#include "beos/beos_scaffolding.h" -#include "beos/beos_window.h" - -#include -#include -#include -#include - -static const char *authors[] = { - "John-Mark Bell", "James Bursa", "Michael Drake", - "Rob Kendrick", "Adrian Lees", "Vincent Sanders", - "Daniel Silverstone", "Richard Wilson", - "\nContributors:", "Kevin Bagust", "Stefaan Claes", - "Matthew Hambley", "Rob Jackson", "Jeffrey Lee", "Phil Mellor", - "Philip Pemberton", "Darren Salt", "Andrew Timmins", - "John Tytgat", "Chris Williams", - "\nGoogle Summer of Code Contributors:", "Adam Blokus", - "Sean Fox", "Michael Lester", "Andrew Sidwell", NULL -}; - -static const char *translators[] = { "Sebastian Barthel", "Bruno D'Arcangeli", - "Gerard van Katwijk", "Jérôme Mathevet", "Simon Voortman.", NULL -}; -static const char *artists[] = { - "Michael Drake", "\nContributors:", "Andrew Duffell", - "John Duffell", "Richard Hallas", "Phil Mellor", NULL -}; - -static const char *documenters[] = { - "John-Mark Bell", "James Bursa", "Michael Drake", - "Richard Wilson", "\nContributors:", "James Shaw", NULL -}; - -static const char *name = "NetSurf"; -static const char *description = - "Small as a mouse, fast as a cheetah, and available for free.\n" - "NetSurf is a web browser for RISC OS and UNIX-like platforms."; -static const char *url = "http://www.netsurf-browser.org/"; -static const char *url_label = "NetSurf Website"; -static const char *copyright = - "Copyright © 2003 - 2008 The NetSurf Developers"; - -static void add_section(BTextView *textview, const char *header, - const char *text) -{ - BFont titleFont; - titleFont.SetSize(titleFont.Size() + 10); - BFont textFont; - text_run_array titleRuns = { 1, { 0, titleFont, { 0, 0, 0, 255 } } }; - text_run_array textRuns = { 1, { 0, textFont, { 0, 0, 0, 255 } } }; - BString h(header); - BString t(text); - h << "\n"; - t << "\n\n"; - if (header) - textview->Insert(h.String(), &titleRuns); - if (text) - textview->Insert(t.String(), &textRuns); -} - -static void add_section(BTextView *textview, const char *header, - const char **texts) -{ - BString t; - while (*texts) { - t << *texts; - t << ", "; - texts++; - } - add_section(textview, header, t.String()); -} - -/** - * Creates the about alert - */ -void nsbeos_about(struct gui_window *gui) -{ - BAlert *alert; - alert = new BAlert("about", "", /*"HomePage",*/ "Ok"); - //XXX: i18n-ize - BTextView *tv = alert->TextView(); - if (gui) { - alert->SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); - nsbeos_scaffolding *s = nsbeos_get_scaffold(gui); - if (s) { - NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s); - if (w) - alert->AddToSubset(w); - } - } - tv->SetStylable(true); - add_section(tv, name, description); - add_section(tv, NULL, copyright); - add_section(tv, "authors", authors); - add_section(tv, "translators", translators); - add_section(tv, "artists", artists); - add_section(tv, "documenters", documenters); - add_section(tv, url_label, url); -#if 0 - BView *p = tv->Parent(); - //tv->MakeSelectable(true); - - //tv->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); - //tv->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); - if (p && p->RemoveChild(tv)) { - BScrollView *sv = new BScrollView("sv", tv, B_FOLLOW_ALL, 0, - false, true, B_NO_BORDER); - p->AddChild(sv); - } - - //tv->ResizeToPreferred(); -#endif - // make space for controls - alert->ResizeBy(200, 500); - alert->MoveTo(alert->AlertPosition(alert->Frame().Width() + 1, - alert->Frame().Height() + 1)); - - alert->Go(NULL); -} diff --git a/beos/beos_about.h b/beos/beos_about.h deleted file mode 100644 index f80d33f01..000000000 --- a/beos/beos_about.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#ifndef __BEOS_ABOUT_H__ -#define __BEOS_ABOUT_H__ - -void nsbeos_about(struct gui_window *gui); - -#endif /* __BEOS_ABOUT_H__ */ diff --git a/beos/beos_bitmap.cpp b/beos/beos_bitmap.cpp deleted file mode 100644 index 5df1fce38..000000000 --- a/beos/beos_bitmap.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -/** \file - * Generic bitmap handling (BeOS implementation). - * - * This implements the interface given by desktop/bitmap.h using BBitmap. - */ - -#define __STDBOOL_H__ 1 -//#include -#include -#include -#include -#include -#include -#include -#include -#include -extern "C" { -#include "content/content.h" -#include "image/bitmap.h" -#include "utils/log.h" -} -#include "beos/beos_bitmap.h" -#include "beos/beos_gui.h" -#include "beos/beos_scaffolding.h" - -struct bitmap { - BBitmap *primary; - BBitmap *shadow; // in NetSurf's ABGR order - BBitmap *pretile_x; - BBitmap *pretile_y; - BBitmap *pretile_xy; - bool opaque; -}; - -#define MIN_PRETILE_WIDTH 256 -#define MIN_PRETILE_HEIGHT 256 - -#warning TODO: check rgba order -#warning TODO: add correct locking (not strictly required) - - -/** Convert to BeOS RGBA32_LITTLE (strictly BGRA) from NetSurf's favoured ABGR format. - * Copies the converted data elsewhere. Operation is rotate left 8 bits. - * - * \param pixels Array of 32-bit values, in the form of ABGR. This will - * be overwritten with new data in the form of BGRA. - * \param width Width of the bitmap - * \param height Height of the bitmap - * \param rowstride Number of bytes to skip after each row (this - * implementation requires this to be a multiple of 4.) - */ -static inline void nsbeos_rgba_to_bgra(void *src, void *dst, int width, int height, - size_t rowstride) -{ - struct abgr { uint8 a, b, g, r; }; - struct rgba { uint8 r, g, b ,a; }; - struct bgra { uint8 b, g, r, a; }; - struct rgba *from = (struct rgba *)src; - struct bgra *to = (struct bgra *)dst; - - rowstride >>= 2; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - to[x].b = from[x].b; - to[x].g = from[x].g; - to[x].r = from[x].r; - to[x].a = from[x].a; - /* - if (from[x].a == 0) - *(rgb_color *)&to[x] = B_TRANSPARENT_32_BIT; - */ - } - from += rowstride; - to += rowstride; - } -} - - -/** - * Create a bitmap. - * - * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state - * \return an opaque struct bitmap, or NULL on memory exhaustion - */ - -void *bitmap_create(int width, int height, unsigned int state) -{ - CALLED(); - struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap)); - if (bmp == NULL) - return NULL; - - int32 flags = 0; - if (state & BITMAP_CLEAR_MEMORY) - flags |= B_BITMAP_CLEAR_TO_WHITE; - - BRect frame(0, 0, width - 1, height - 1); - //XXX: bytes per row ? - bmp->primary = new BBitmap(frame, flags, B_RGBA32); - bmp->shadow = new BBitmap(frame, flags, B_RGBA32); - - bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL; - - bmp->opaque = (state & BITMAP_OPAQUE) != 0; - - return bmp; -} - - -/** - * Sets whether a bitmap should be plotted opaque - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \param opaque whether the bitmap should be plotted opaque - */ -void bitmap_set_opaque(void *vbitmap, bool opaque) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - bitmap->opaque = opaque; -} - - -/** - * Tests whether a bitmap has an opaque alpha channel - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \return whether the bitmap is opaque - */ -bool bitmap_test_opaque(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); -/* todo: test if bitmap is opaque */ - return false; -} - - -/** - * Gets whether a bitmap should be plotted opaque - * - * \param vbitmap a bitmap, as returned by bitmap_create() - */ -bool bitmap_get_opaque(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - return bitmap->opaque; -} - - -/** - * Return a pointer to the pixel data in a bitmap. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \return pointer to the pixel buffer - * - * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end - * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). - */ - -unsigned char *bitmap_get_buffer(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - return (unsigned char *)(bitmap->shadow->Bits()); -} - - -/** - * Find the width of a pixel row in bytes. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \return width of a pixel row in the bitmap - */ - -size_t bitmap_get_rowstride(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - return (bitmap->primary->BytesPerRow()); -} - - -/** - * Find the bytes per pixels of a bitmap. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \return bytes per pixels of the bitmap - */ - -size_t bitmap_get_bpp(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - return 4; -} - - -static void -nsbeos_bitmap_free_pretiles(struct bitmap *bitmap) -{ -#define FREE_TILE(XY) if (bitmap->pretile_##XY) delete (bitmap->pretile_##XY); bitmap->pretile_##XY = NULL - FREE_TILE(x); - FREE_TILE(y); - FREE_TILE(xy); -#undef FREE_TILE -} - -/** - * Free a bitmap. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - */ - -void bitmap_destroy(void *vbitmap) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - assert(bitmap); - nsbeos_bitmap_free_pretiles(bitmap); - delete bitmap->primary; - delete bitmap->shadow; - free(bitmap); -} - - -/** - * Save a bitmap in the platform's native format. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \param path pathname for file - * \param flags modify the behaviour of the save - * \return true on success, false on error and error reported - */ - -bool bitmap_save(void *vbitmap, const char *path, unsigned flags) -{ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - BTranslatorRoster *roster = BTranslatorRoster::Default(); - BBitmapStream stream(bitmap->primary); - BFile file(path, B_WRITE_ONLY | B_CREATE_FILE); - uint32 type = B_PNG_FORMAT; - - if (file.InitCheck() < B_OK) - return false; - - if (roster->Translate(&stream, NULL, NULL, &file, type) < B_OK) - return false; - -#if 0 /* GTK */ - GError *err = NULL; - - gdk_pixbuf_save(bitmap->primary, path, "png", &err, NULL); - - if (err == NULL) - /* TODO: report an error here */ - return false; - -#endif - return true; -} - - -/** - * The bitmap image has changed, so flush any persistant cache. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - */ -void bitmap_modified(void *vbitmap) { - CALLED(); - struct bitmap *bitmap = (struct bitmap *)vbitmap; - // convert the shadow (ABGR) to into the primary bitmap - nsbeos_rgba_to_bgra(bitmap->shadow->Bits(), bitmap->primary->Bits(), - bitmap->primary->Bounds().Width() + 1, - bitmap->primary->Bounds().Height() + 1, - bitmap->primary->BytesPerRow()); - nsbeos_bitmap_free_pretiles(bitmap); -} - - -/** - * The bitmap image can be suspended. - * - * \param vbitmap a bitmap, as returned by bitmap_create() - * \param private_word a private word to be returned later - * \param suspend the function to be called upon suspension - * \param resume the function to be called when resuming - */ -void bitmap_set_suspendable(void *vbitmap, void *private_word, - void (*invalidate)(void *vbitmap, void *private_word)) { - struct bitmap *bitmap = (struct bitmap *)vbitmap; -} - -int bitmap_get_width(void *vbitmap){ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - return bitmap->primary->Bounds().Width() + 1; -} - -int bitmap_get_height(void *vbitmap){ - struct bitmap *bitmap = (struct bitmap *)vbitmap; - return bitmap->primary->Bounds().Height() + 1; -} - -static BBitmap * -nsbeos_bitmap_generate_pretile(BBitmap *primary, int repeat_x, int repeat_y) -{ - int width = primary->Bounds().Width() + 1; - int height = primary->Bounds().Height() + 1; - size_t primary_stride = primary->BytesPerRow(); - BRect frame(0, 0, width * repeat_x - 1, height * repeat_y - 1); - BBitmap *result = new BBitmap(frame, 0, B_RGBA32); - - char *target_buffer = (char *)result->Bits(); - int x,y,row; - /* This algorithm won't work if the strides are not multiples */ - assert((size_t)(result->BytesPerRow()) == - (primary_stride * repeat_x)); - - if (repeat_x == 1 && repeat_y == 1) { - delete result; - // just return a copy - return new BBitmap(primary); - } - - for (y = 0; y < repeat_y; ++y) { - char *primary_buffer = (char *)primary->Bits(); - for (row = 0; row < height; ++row) { - for (x = 0; x < repeat_x; ++x) { - memcpy(target_buffer, - primary_buffer, primary_stride); - target_buffer += primary_stride; - } - primary_buffer += primary_stride; - } - } - return result; - -} - -/** - * The primary image associated with this bitmap object. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -BBitmap * -nsbeos_bitmap_get_primary(struct bitmap* bitmap) -{ - return bitmap->primary; -} - -/** - * The X-pretiled image associated with this bitmap object. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -BBitmap * -nsbeos_bitmap_get_pretile_x(struct bitmap* bitmap) -{ - if (!bitmap->pretile_x) { - int width = bitmap->primary->Bounds().Width() + 1; - int xmult = (MIN_PRETILE_WIDTH + width - 1)/width; - LOG(("Pretiling %p for X*%d", bitmap, xmult)); - bitmap->pretile_x = nsbeos_bitmap_generate_pretile(bitmap->primary, xmult, 1); - } - return bitmap->pretile_x; - -} - -/** - * The Y-pretiled image associated with this bitmap object. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -BBitmap * -nsbeos_bitmap_get_pretile_y(struct bitmap* bitmap) -{ - if (!bitmap->pretile_y) { - int height = bitmap->primary->Bounds().Height() + 1; - int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height; - LOG(("Pretiling %p for Y*%d", bitmap, ymult)); - bitmap->pretile_y = nsbeos_bitmap_generate_pretile(bitmap->primary, 1, ymult); - } - return bitmap->pretile_y; -} - -/** - * The XY-pretiled image associated with this bitmap object. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -BBitmap * -nsbeos_bitmap_get_pretile_xy(struct bitmap* bitmap) -{ - if (!bitmap->pretile_xy) { - int width = bitmap->primary->Bounds().Width() + 1; - int height = bitmap->primary->Bounds().Height() + 1; - int xmult = (MIN_PRETILE_WIDTH + width - 1)/width; - int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height; - LOG(("Pretiling %p for X*%d Y*%d", bitmap, xmult, ymult)); - bitmap->pretile_xy = nsbeos_bitmap_generate_pretile(bitmap->primary, xmult, ymult); - } - return bitmap->pretile_xy; -} diff --git a/beos/beos_bitmap.h b/beos/beos_bitmap.h deleted file mode 100644 index 6ec662198..000000000 --- a/beos/beos_bitmap.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#ifndef NS_BEOS_BITMAP_H -#define NS_BEOS_BITMAP_H - -#include -extern "C" { -#include "image/bitmap.h" -} - -BBitmap *nsbeos_bitmap_get_primary(struct bitmap*); -BBitmap *nsbeos_bitmap_get_pretile_x(struct bitmap*); -BBitmap *nsbeos_bitmap_get_pretile_y(struct bitmap*); -BBitmap *nsbeos_bitmap_get_pretile_xy(struct bitmap*); - - - -#endif /* NS_BEOS_BITMAP_H */ diff --git a/beos/beos_fetch_rsrc.cpp b/beos/beos_fetch_rsrc.cpp deleted file mode 100644 index 15b2000a4..000000000 --- a/beos/beos_fetch_rsrc.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2008 Rob Kendrick - * - * This file is part of NetSurf. - * - * 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 . - */ - -/* rsrc: URL handling. */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for URL unescaping functions */ -extern "C" { -#include "utils/config.h" -#include "content/fetch.h" -#include "content/urldb.h" -#include "desktop/netsurf.h" -#include "desktop/options.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" -#include "utils/ring.h" -#include "utils/base64.h" -} -#include "beos/beos_fetch_rsrc.h" -#include "beos/beos_gui.h" - -#include -#include - -struct fetch_rsrc_context { - struct fetch *parent_fetch; - char *name; - char *url; - char *mimetype; - char *data; - size_t datalen; - - bool aborted; - bool locked; - - struct fetch_rsrc_context *r_next, *r_prev; -}; - -static struct fetch_rsrc_context *ring = NULL; - -static BResources *gAppResources = NULL; - -static bool fetch_rsrc_initialise(lwc_string *scheme) -{ - LOG(("fetch_rsrc_initialise called for %s", lwc_string_data(scheme))); - return true; -} - -static void fetch_rsrc_finalise(lwc_string *scheme) -{ - LOG(("fetch_rsrc_finalise called for %s", lwc_string_data(scheme))); -} - -static bool fetch_rsrc_can_fetch(const nsurl *url) -{ - return true; -} - -static void *fetch_rsrc_setup(struct fetch *parent_fetch, nsurl *url, - bool only_2xx, const char *post_urlenc, - const struct fetch_multipart_data *post_multipart, - const char **headers) -{ - struct fetch_rsrc_context *ctx; - ctx = (struct fetch_rsrc_context *)calloc(1, sizeof(*ctx)); - - if (ctx == NULL) - return NULL; - - ctx->parent_fetch = parent_fetch; - /* TODO: keep as nsurl to avoid copy */ - ctx->url = (char *)malloc(nsurl_length(url) + 1); - - if (ctx->url == NULL) { - free(ctx); - return NULL; - } - memcpy(ctx->url, nsurl_access(url), nsurl_length(url) + 1); - - RING_INSERT(ring, ctx); - - return ctx; -} - -static bool fetch_rsrc_start(void *ctx) -{ - return true; -} - -static void fetch_rsrc_free(void *ctx) -{ - struct fetch_rsrc_context *c = (struct fetch_rsrc_context *)ctx; - - free(c->name); - free(c->url); - free(c->data); - free(c->mimetype); - RING_REMOVE(ring, c); - free(ctx); -} - -static void fetch_rsrc_abort(void *ctx) -{ - struct fetch_rsrc_context *c = (struct fetch_rsrc_context *)ctx; - - /* To avoid the poll loop having to deal with the fetch context - * disappearing from under it, we simply flag the abort here. - * The poll loop itself will perform the appropriate cleanup. - */ - c->aborted = true; -} - -static void fetch_rsrc_send_callback(const fetch_msg *msg, - struct fetch_rsrc_context *c) -{ - c->locked = true; - fetch_send_callback(msg, c->parent_fetch); - c->locked = false; -} - -static bool fetch_rsrc_process(struct fetch_rsrc_context *c) -{ - fetch_msg msg; - char *params; - char *at = NULL; - char *slash; - char *comma = NULL; - char *unescaped; - uint32 type = 'data'; // default for embeded files - int32 id = 0; - - /* format of a rsrc: URL is: - * rsrc://[TYPE][@NUM]/name[,mime] - */ - - LOG(("*** Processing %s", c->url)); - - if (strlen(c->url) < 7) { - /* 7 is the minimum possible length (rsrc://) */ - msg.type = FETCH_ERROR; - msg.data.error = "Malformed rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - - /* skip the rsrc: part */ - params = c->url + sizeof("rsrc://") - 1; - - /* find the slash */ - if ( (slash = strchr(params, '/')) == NULL) { - msg.type = FETCH_ERROR; - msg.data.error = "Malformed rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - - // doesn't exist in the filesystem but we should hit the internal types. - c->mimetype = strdup(fetch_filetype(slash)); - c->name = strdup(slash + 1); - - if (c->mimetype == NULL) { - msg.type = FETCH_ERROR; - msg.data.error = - "Unable to allocate memory for mimetype in rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - - if (params[0] != '/') { - uint8 c1, c2, c3, c4; - if (sscanf(params, "%c%c%c%c", &c1, &c2, &c3, &c4) > 3) { - type = c1 << 24 | c2 << 16 | c3 << 8 | c4; - printf("type:%4.4s\n", &type); - } - } - - fprintf(stderr, "fetch_rsrc: 0x%08lx, %ld, '%s'\n", type, id, c->name); - - bool found; - if (id) - found = gAppResources->HasResource(type, id); - else - found = gAppResources->HasResource(type, c->name); - if (!found) { - msg.type = FETCH_ERROR; - msg.data.error = "Cannot locate rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - - size_t len; - const void *data; - if (id) - data = gAppResources->LoadResource(type, id, &len); - else - data = gAppResources->LoadResource(type, c->name, &len); - - if (!data) { - msg.type = FETCH_ERROR; - msg.data.error = "Cannot load rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - - c->datalen = len; - c->data = (char *)malloc(c->datalen); - if (c->data == NULL) { - msg.type = FETCH_ERROR; - msg.data.error = "Unable to allocate memory for rsrc: URL"; - fetch_rsrc_send_callback(&msg, c); - return false; - } - memcpy(c->data, data, c->datalen); - - return true; -} - -static void fetch_rsrc_poll(lwc_string *scheme) -{ - fetch_msg msg; - struct fetch_rsrc_context *c, *next; - - if (ring == NULL) return; - - /* Iterate over ring, processing each pending fetch */ - c = ring; - do { - /* Take a copy of the next pointer as we may destroy - * the ring item we're currently processing */ - next = c->r_next; - - /* Ignore fetches that have been flagged as locked. - * This allows safe re-entrant calls to this function. - * Re-entrancy can occur if, as a result of a callback, - * the interested party causes fetch_poll() to be called - * again. - */ - if (c->locked == true) { - continue; - } - - /* Only process non-aborted fetches */ - if (!c->aborted && fetch_rsrc_process(c) == true) { - char header[64]; - - fetch_set_http_code(c->parent_fetch, 200); - LOG(("setting rsrc: MIME type to %s, length to %zd", - c->mimetype, c->datalen)); - /* Any callback can result in the fetch being aborted. - * Therefore, we _must_ check for this after _every_ - * call to fetch_rsrc_send_callback(). - */ - snprintf(header, sizeof header, "Content-Type: %s", - c->mimetype); - msg.type = FETCH_HEADER; - msg.data.header_or_data.buf = (const uint8_t *) header; - msg.data.header_or_data.len = strlen(header); - fetch_rsrc_send_callback(&msg, c); - - snprintf(header, sizeof header, "Content-Length: %zd", - c->datalen); - msg.type = FETCH_HEADER; - msg.data.header_or_data.buf = (const uint8_t *) header; - msg.data.header_or_data.len = strlen(header); - fetch_rsrc_send_callback(&msg, c); - - if (!c->aborted) { - msg.type = FETCH_DATA; - msg.data.header_or_data.buf = (const uint8_t *) c->data; - msg.data.header_or_data.len = c->datalen; - fetch_rsrc_send_callback(&msg, c); - } - if (!c->aborted) { - msg.type = FETCH_FINISHED; - fetch_rsrc_send_callback(&msg, c); - } - } else { - LOG(("Processing of %s failed!", c->url)); - - /* Ensure that we're unlocked here. If we aren't, - * then fetch_rsrc_process() is broken. - */ - assert(c->locked == false); - } - - fetch_remove_from_queues(c->parent_fetch); - fetch_free(c->parent_fetch); - - /* Advance to next ring entry, exiting if we've reached - * the start of the ring or the ring has become empty - */ - } while ( (c = next) != ring && ring != NULL); -} - -/* BAppFileInfo is supposed to find the app's resources for us, - * but this won't work if we ever want to be used as a replicant. - * This trick should work regardless, - */ -static int find_app_resources() -{ - char path[B_PATH_NAME_LENGTH]; - if (nsbeos_find_app_path(path) < B_OK) - return B_ERROR; -//fprintf(stderr, "loading resources from '%s'\n", path); - - BFile file(path, B_READ_ONLY); - if (file.InitCheck() < 0) - return file.InitCheck(); - gAppResources = new BResources; - status_t err; - err = gAppResources->SetTo(&file); - if (err >= B_OK) - return B_OK; - delete gAppResources; - gAppResources = NULL; - return err; -} - -BResources *get_app_resources() -{ - return gAppResources; -} - -void fetch_rsrc_register(void) -{ - lwc_string *scheme; - int err; - - err = find_app_resources(); - - if (err < B_OK) { - warn_user("Resources", strerror(err)); - return; - } - - if (lwc_intern_string("rsrc", SLEN("rsrc"), &scheme) != lwc_error_ok) { - die("Failed to initialise the fetch module " - "(couldn't intern \"rsrc\")."); - } - - fetch_add_fetcher(scheme, - fetch_rsrc_initialise, - fetch_rsrc_can_fetch, - fetch_rsrc_setup, - fetch_rsrc_start, - fetch_rsrc_abort, - fetch_rsrc_free, - fetch_rsrc_poll, - fetch_rsrc_finalise); -} - -void fetch_rsrc_unregister(void) -{ - delete gAppResources; - gAppResources = NULL; -} diff --git a/beos/beos_fetch_rsrc.h b/beos/beos_fetch_rsrc.h deleted file mode 100644 index 0607dbd07..000000000 --- a/beos/beos_fetch_rsrc.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2008 Rob Kendrick - * - * This file is part of NetSurf. - * - * 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 . - */ - -/** \file - * rsrc: URL method handler - */ - -#ifndef NETSURF_BEOS_FETCH_DATA_H -#define NETSURF_BEOS_FETCH_DATA_H - -void fetch_rsrc_register(void); -void fetch_rsrc_unregister(void); - -class BResources; -BResources *get_app_resources(); - -#include "beos_res.h" - -#endif diff --git a/beos/beos_filetype.cpp b/beos/beos_filetype.cpp deleted file mode 100644 index d8920902d..000000000 --- a/beos/beos_filetype.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -extern "C" { -#include "content/fetch.h" -#include "utils/log.h" -#include "utils/hashtable.h" -#include "utils/utils.h" -} - -#include "beos/beos_filetype.h" - -static struct { - const char *type; - const char *ext1; - const char *ext2; -} default_types[] = { - { "text/plain", "txt", NULL }, - { "text/html", "htm", "html" }, - { "text/css", "css", NULL }, - { "image/gif", "gif", NULL }, - { "image/jpeg", "jpg", "jpeg" }, - { "image/png", "png", NULL }, - { "image/jng", "jng", NULL }, - { NULL, NULL, NULL } -}; - -void beos_fetch_filetype_init(void) -{ - BMimeType m; - status_t err; - int i; - - // make sure we have basic mime types in the database - for (i = 0; default_types[i].type; i++) { - if (m.SetTo(default_types[i].type) < B_OK) - continue; - if (m.IsInstalled()) - continue; - err = m.Install(); - if (err < B_OK) { - warn_user("Mime", strerror(err)); - continue; - } - // the mime db doesn't know about it yet - BMessage extensions(0UL); - if (default_types[i].ext1) - extensions.AddString("extensions", default_types[i].ext1); - if (default_types[i].ext2) - extensions.AddString("extensions", default_types[i].ext2); - err = m.SetFileExtensions(&extensions); - if (err < B_OK) { - warn_user("Mime", strerror(err)); - } - } -} - -void beos_fetch_filetype_fin(void) -{ -} - -const char *fetch_filetype(const char *unix_path) -{ - struct stat statbuf; - status_t err; - int i; - // NOT THREADSAFE - static char type[B_MIME_TYPE_LENGTH]; - - // override reading the mime type for known types - // avoids getting CSS files as text/x-source-code - // even though it's the mime sniffer rules that should be fixed. - BString ext(unix_path); - ext.Remove(0, ext.FindLast('.') + 1); - for (i = 0; default_types[i].type; i++) { - if (ext == default_types[i].ext1) - return default_types[i].type; - if (ext == default_types[i].ext2) - return default_types[i].type; - } - - BEntry entry(unix_path, true); - BNode node(&entry); - err = node.InitCheck(); - if (err < B_OK) - return "text/plain"; - - if (node.IsDirectory()) - return "application/x-netsurf-directory"; - - BNodeInfo info(&node); - err = info.InitCheck(); - if (err < B_OK) - return "test/plain"; - - err = info.GetType(type); - if (err < B_OK) { - // not there yet, sniff and retry - err = update_mime_info(unix_path, false, true, false); - if (err < B_OK) - return "text/plain"; - err = info.GetType(type); - if (err < B_OK) - return "text/plain"; - } - - return type; -} - -char *fetch_mimetype(const char *unix_path) -{ - return strdup(fetch_filetype(unix_path)); -} - diff --git a/beos/beos_filetype.h b/beos/beos_filetype.h deleted file mode 100644 index ab0ef410f..000000000 --- a/beos/beos_filetype.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -void beos_fetch_filetype_init(void); -void beos_fetch_filetype_fin(void); diff --git a/beos/beos_font.cpp b/beos/beos_font.cpp deleted file mode 100644 index 5c7d1caf8..000000000 --- a/beos/beos_font.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -/** \file - * Font handling (BeOS implementation). - * TODO: check for correctness, the code is taken from the GTK one. - * maybe use the current view instead of constructing a new BFont each time ? - */ - - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -extern "C" { -#include "css/css.h" -#include "render/font.h" -#include "utils/utils.h" -#include "utils/log.h" -#include "desktop/options.h" -} - -#include "beos/beos_gui.h" -#include "beos/beos_font.h" -#include "beos/beos_plotters.h" - -static bool nsfont_width(const plot_font_style_t *fstyle, - const char *string, size_t length, - int *width); -static bool nsfont_position_in_string(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); -static bool nsfont_split(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x); - -const struct font_functions nsfont = { - nsfont_width, - nsfont_position_in_string, - nsfont_split -}; - - -/** - * Measure the width of a string. - * - * \param fstyle style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param width updated to width of string[0..length) - * \return true on success, false on error and error reported - */ - -bool nsfont_width(const plot_font_style_t *fstyle, - const char *string, size_t length, - int *width) -{ - //fprintf(stderr, "%s(, '%s', %d, )\n", __FUNCTION__, string, length); - BFont font; - - if (length == 0) { - *width = 0; - return true; - } - - nsbeos_style_to_font(font, fstyle); - *width = (int)font.StringWidth(string, length); - return true; -} - - -static int utf8_char_len(const char *c) -{ - uint8 *p = (uint8 *)c; - uint8 m = 0xE0; - uint8 v = 0xC0; - int i; - if (!*p) - return 0; - if ((*p & 0x80) == 0) - return 1; - if ((*p & 0xC0) == 0x80) - return 1; // actually one of the remaining bytes... - for (i = 2; i < 5; i++) { - if ((*p & m) == v) - return i; - v = (v >> 1) | 0x80; - m = (m >> 1) | 0x80; - } - return i; -} - - -/** - * Find the position in a string where an x coordinate falls. - * - * \param fstyle style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param x x coordinate to search for - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported - */ - -bool nsfont_position_in_string(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x) -{ - //LOG(("(, '%s', %d, %d, , )", string, length, x)); - //fprintf(stderr, "%s(, '%s', %d, %d, , )\n", __FUNCTION__, string, length, x); - int index; - BFont font; - - nsbeos_style_to_font(font, fstyle); - BString str(string); - int32 len = str.CountChars(); - float escapements[len]; - float esc = 0.0; - float current = 0.0; - int i; - index = 0; - font.GetEscapements(string, len, escapements); - // slow but it should work - for (i = 0; string[index] && i < len; i++) { - if (x < current) - break; - esc += escapements[i]; - current = font.Size() * esc; - index += utf8_char_len(&string[index]); - } - *actual_x = (int)current; - *char_offset = i; //index; - - return true; -} - - -/** - * Find where to split a string to make it fit a width. - * - * \param fstyle style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param x width available - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported - * - * On exit, [char_offset == 0 || - * string[char_offset] == ' ' || - * char_offset == length] - */ - -bool nsfont_split(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x) -{ - //fprintf(stderr, "%s(, '%s', %d, %d, , )\n", __FUNCTION__, string, length, x); - //LOG(("(, '%s', %d, %d, , )", string, length, x)); - int index = 0; - BFont font; - - nsbeos_style_to_font(font, fstyle); - BString str(string); - int32 len = str.CountChars(); - float escapements[len]; - float esc = 0.0; - float current = 0.0; - float last_x = 0.0; - int i; - int last_space = 0; - font.GetEscapements(string, len, escapements); - // slow but it should work - for (i = 0; string[index] && i < len; i++) { - if (string[index] == ' ') { - last_x = current; - last_space = index; - } - if (x < current) { - *actual_x = (int)last_x; - *char_offset = last_space; - return true; - } - esc += escapements[i]; - current = font.Size() * esc; - index += utf8_char_len(&string[index]); - } - *actual_x = MIN(*actual_x, (int)current); - *char_offset = index; - - return true; -} - - -/** - * Render a string. - * - * \param fstyle style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param x x coordinate - * \param y y coordinate - * \return true on success, false on error and error reported - */ - -bool nsfont_paint(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, int y) -{ - //fprintf(stderr, "%s(, '%s', %d, %d, %d, )\n", __FUNCTION__, string, length, x, y); - //CALLED(); - BFont font; - rgb_color oldbg; - rgb_color background; - rgb_color foreground; - BView *view; - float size; - - if (length == 0) - return true; - - nsbeos_style_to_font(font, fstyle); - background = nsbeos_rgb_colour(fstyle->background); - foreground = nsbeos_rgb_colour(fstyle->foreground); - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - oldbg = view->LowColor(); - drawing_mode oldmode = view->DrawingMode(); -#if 0 - if (oldbg != background) - view->SetLowColor(background); -#endif - view->SetLowColor(B_TRANSPARENT_32_BIT); - - //view->SetScale() XXX - -//printf("nsfont_paint: Size: %f\n", font.Size()); - size = (float)font.Size(); -#warning XXX use scale - - view->SetFont(&font); - view->SetHighColor(foreground); - view->SetDrawingMode(B_OP_OVER); - - BString line(string, length); - - BPoint where(x, y + 1); - view->DrawString(line.String(), where); - - view->SetDrawingMode(oldmode); - if (memcmp(&oldbg, &background, sizeof(rgb_color))) - view->SetLowColor(oldbg); - - //nsbeos_current_gc_unlock(); - - return true; -} - - -/** - * Convert a font style to a PangoFontDescription. - * - * \param fstyle style for this text - * \return a new Pango font description - */ - -void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle) -{ - float size; - uint16 face = 0; - const char *family; - - switch (fstyle->family) { - case PLOT_FONT_FAMILY_SERIF: - family = nsoption_charp(font_serif); - break; - case PLOT_FONT_FAMILY_MONOSPACE: - family = nsoption_charp(font_mono); - break; - case PLOT_FONT_FAMILY_CURSIVE: - family = nsoption_charp(font_cursive); - break; - case PLOT_FONT_FAMILY_FANTASY: - family = nsoption_charp(font_fantasy); - break; - case PLOT_FONT_FAMILY_SANS_SERIF: - default: - family = nsoption_charp(font_sans); - break; - } - - if ((fstyle->flags & FONTF_ITALIC)) { - face = B_ITALIC_FACE; - } else if ((fstyle->flags & FONTF_OBLIQUE)) { - face = B_ITALIC_FACE; - // XXX: no OBLIQUE flag ?? - // maybe find "Oblique" style - // or use SetShear() ? - } - -#ifndef __HAIKU__XXX - if (fstyle->weight >= 600) { - face |= B_BOLD_FACE; - } -#else - if (fstyle->weight >= 600) { - if (fstyle->weight >= 800) - face |= B_HEAVY_FACE; - else - face |= B_BOLD_FACE; - } else if (fstyle->weight <= 300) { - face |= B_LIGHT_FACE; - } -#endif -/* - case CSS_FONT_WEIGHT_100: weight = 100; break; - case CSS_FONT_WEIGHT_200: weight = 200; break; - case CSS_FONT_WEIGHT_300: weight = 300; break; - case CSS_FONT_WEIGHT_400: weight = 400; break; - case CSS_FONT_WEIGHT_500: weight = 500; break; - case CSS_FONT_WEIGHT_600: weight = 600; break; - case CSS_FONT_WEIGHT_700: weight = 700; break; - case CSS_FONT_WEIGHT_800: weight = 800; break; - case CSS_FONT_WEIGHT_900: weight = 900; break; -*/ - - if (!face) - face = B_REGULAR_FACE; - -//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face); - - if (family) { - font_family beos_family; - - strncpy(beos_family, family, B_FONT_FAMILY_LENGTH); - // Ensure it's terminated - beos_family[B_FONT_FAMILY_LENGTH] = '\0'; - - font.SetFamilyAndFace(beos_family, face); - } else { - //XXX not used - font = be_plain_font; - font.SetFace(face); - } - -//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); - size = fstyle->size / FONT_SIZE_SCALE; - -//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit); - - font.SetSize(size); -} diff --git a/beos/beos_font.h b/beos/beos_font.h deleted file mode 100644 index aefd898da..000000000 --- a/beos/beos_font.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -/** \file - * Font handling (GTK interface). - */ - -#include - -#include "desktop/plotters.h" - -bool nsfont_paint(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, int y); - -void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle); diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp deleted file mode 100644 index a9cf3473c..000000000 --- a/beos/beos_gui.cpp +++ /dev/null @@ -1,1195 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2005 James Bursa - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { - -#include "content/content.h" -#include "content/content_protected.h" -#include "content/fetch.h" -#include "content/fetchers/curl.h" -#include "content/fetchers/resource.h" -#include "content/urldb.h" -#include "desktop/401login.h" -#include "desktop/browser.h" -#include "desktop/cookies.h" -#include "desktop/gui.h" -#include "desktop/netsurf.h" -#include "desktop/options.h" - -#include "render/box.h" -#include "render/form.h" -#include "render/html.h" -#include "utils/filename.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utf8.h" -#include "utils/utils.h" -} - -#include "beos/beos_gui.h" - -#include "beos/beos_options.h" -//#include "beos/beos_completion.h" -#include "beos/beos_window.h" -#include "beos/beos_throbber.h" -#include "beos/beos_filetype.h" -//#include "beos/beos_download.h" -#include "beos/beos_schedule.h" -#include "beos/beos_fetch_rsrc.h" -#include "beos/beos_scaffolding.h" - - -static void *myrealloc(void *ptr, size_t len, void *pw); -void gui_init(int argc, char** argv); - - -/* Where to search for shared resources. Must have trailing / */ -#define RESPATH "/boot/apps/netsurf/res/" - -//TODO: use resources -// enable using resources instead of files -#define USE_RESOURCES 1 - -bool replicated = false; /**< if we are running as a replicant */ - -char *options_file_location; -char *glade_file_location; - -struct gui_window *search_current_window = 0; - -BWindow *wndAbout; -BWindow *wndWarning; -//GladeXML *gladeWindows; -BWindow *wndTooltip; -//beosLabel *labelTooltip; -BFilePanel *wndOpenFile; - -//static beosWidget *select_menu; -static struct browser_window *select_menu_bw; -static struct form_control *select_menu_control; - -static thread_id sBAppThreadID; - -static BMessage *gFirstRefsReceived = NULL; - -static int sEventPipe[2]; - -#if 0 /* GTK */ -static void nsbeos_create_ssl_verify_window(struct browser_window *bw, - hlcache_handle *c, const struct ssl_cert_info *certs, - unsigned long num); -static void nsbeos_ssl_accept(BButton *w, gpointer data); -static void nsbeos_ssl_reject(BButton *w, gpointer data); -static void nsbeos_select_menu_clicked(BCheckMenuItem *checkmenuitem, - gpointer user_data); -#endif - -// #pragma mark - class NSBrowserFrameView - - -NSBrowserApplication::NSBrowserApplication() - : BApplication("application/x-vnd.NetSurf") -{ -} - - -NSBrowserApplication::~NSBrowserApplication() -{ -} - - -void -NSBrowserApplication::MessageReceived(BMessage *message) -{ - switch (message->what) { - case B_REFS_RECEIVED: - // messages for top-level - // we'll just send them to the first window - case 'back': - case 'forw': - case 'stop': - case 'relo': - case 'home': - case 'urlc': - case 'urle': - case 'menu': - // NetPositive messages - case B_NETPOSITIVE_OPEN_URL: - case B_NETPOSITIVE_BACK: - case B_NETPOSITIVE_FORWARD: - case B_NETPOSITIVE_HOME: - case B_NETPOSITIVE_RELOAD: - case B_NETPOSITIVE_STOP: - case B_NETPOSITIVE_DOWN: - case B_NETPOSITIVE_UP: - //DetachCurrentMessage(); - //nsbeos_pipe_message(message, this, fGuiWindow); - break; - default: - BApplication::MessageReceived(message); - } -} - - -void -NSBrowserApplication::ArgvReceived(int32 argc, char **argv) -{ - CALLED(); - NSBrowserWindow *win = nsbeos_find_last_window(); - if (!win) { - return; - } - win->Unlock(); - BMessage *message = DetachCurrentMessage(); - nsbeos_pipe_message_top(message, win, win->Scaffolding()); -} - - -void -NSBrowserApplication::RefsReceived(BMessage *message) -{ - CALLED(); - DetachCurrentMessage(); - NSBrowserWindow *win = nsbeos_find_last_window(); - if (!win) { - gFirstRefsReceived = message; - return; - } - win->Unlock(); - nsbeos_pipe_message_top(message, win, win->Scaffolding()); -} - - -void -NSBrowserApplication::AboutRequested() -{ - nsbeos_pipe_message(new BMessage(B_ABOUT_REQUESTED), NULL, NULL); -} - - -bool -NSBrowserApplication::QuitRequested() -{ - // let it notice it - nsbeos_pipe_message(new BMessage(B_QUIT_REQUESTED), NULL, NULL); - // we'll let the main thread Quit() ourselves when it's done. - return false; -} - - -// #pragma mark - implementation - - -// XXX doesn't work -#if 0 -static char *generate_default_css() -{ - BString text; - rgb_color colBg = { 255, 255, 255, 255 }; - rgb_color colFg = { 0, 0, 0, 255 }; - rgb_color colControlBg = { 255, 255, 255, 255 }; - rgb_color colControlFg = { 0, 0, 0, 255 }; - const char *url = "file://beosdefault.css"; - - text << "/*\n"; - text << " * This file is part of NetSurf, http://netsurf-browser.org/\n"; - text << " */\n"; - text << "\n"; - text << "/* Load base stylesheet. */\n"; - text << "\n"; - text << "@import \"default.css\";\n"; - text << "\n"; - text << "/* Apply BeOS specific rules. */\n"; - text << "\n"; - text << "\n"; - text << "\n"; - text << "\n"; - - text << "input { font-size: 95%; border: medium inset #ddd; }\n"; - text << "input[type=button], input[type=reset], input[type=submit], button {\n"; - text << " background-color: #ddd; border: medium outset #ddd; }\n"; - text << "input[type=checkbox], input[type=radio] { font-size: 105%; }\n"; - text << "input[type=file] { background-color: #ddd; border: medium inset #ddd; }\n"; - text << "\n"; - text << "select { background-color: #ddd; border: medium inset #ddd; font-size: 95%; }\n"; - text << "select:after { border-left:4px ridge #ddd; }\n"; - text << "\n"; - text << "textarea { font-size: 95%; border: medium inset #ddd; }\n"; - - struct content *c; - c = content_create(url); - if (c == NULL) - return NULL; - - const char *params[] = { 0 }; - if (!content_set_type(c, CONTENT_CSS, "text/css", params, NULL)) - return NULL; - - if (!content_process_data(c, text.String(), text.Length())) - return NULL; - - content_set_done(c); - - return strdup(url); -} -#endif - -/* realpath fallback on R5 */ -#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO) -extern "C" char *realpath(const char *f, char *buf); -char *realpath(const char *f, char *buf) -{ - BPath path(f, NULL, true); - if (path.InitCheck() < 0) { - strncpy(buf, f, MAXPATHLEN); - return NULL; - } - //printf("RP: '%s'\n", path.Path()); - strncpy(buf, path.Path(), MAXPATHLEN); - return buf; -} -#endif - -/* finds the NetSurf binary image ID and path - * - */ -image_id nsbeos_find_app_path(char *path) -{ - image_info info; - int32 cookie = 0; - while (get_next_image_info(0, &cookie, &info) == B_OK) { -//fprintf(stderr, "%p <> %p, %p\n", (char *)&find_app_resources, (char *)info.text, (char *)info.text + info.text_size); - if (((char *)&nsbeos_find_app_path >= (char *)info.text) - && ((char *)&nsbeos_find_app_path < (char *)info.text + info.text_size)) { -//fprintf(stderr, "match\n"); - if (path) { - memset(path, 0, B_PATH_NAME_LENGTH); - strncpy(path, info.name, B_PATH_NAME_LENGTH-1); - } - return info.id; - } - } - return B_ERROR; -} - -/** - * Locate a shared resource file by searching known places in order. - * - * \param buf buffer to write to. must be at least PATH_MAX chars - * \param filename file to look for - * \param def default to return if file not found - * \return buf - * - * Search order is: ~/config/settings/NetSurf/, ~/.netsurf/, $NETSURFRES/ - * (where NETSURFRES is an environment variable), and finally the path - * specified by the #define at the top of this file. - */ - -static char *find_resource(char *buf, const char *filename, const char *def) -{ - CALLED(); - const char *cdir = NULL; - status_t err; - BPath path; - char t[PATH_MAX]; - - err = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - path.Append("NetSurf"); - if (err >= B_OK) - cdir = path.Path(); - if (cdir != NULL) { - strcpy(t, cdir); - strcat(t, "/"); - strcat(t, filename); - realpath(t, buf); - if (access(buf, R_OK) == 0) - return buf; - } - - cdir = getenv("HOME"); - if (cdir != NULL) { - strcpy(t, cdir); - strcat(t, "/.netsurf/"); - strcat(t, filename); - realpath(t, buf); - if (access(buf, R_OK) == 0) - return buf; - } - - cdir = getenv("NETSURFRES"); - - if (cdir != NULL) { - realpath(cdir, buf); - strcat(buf, "/"); - strcat(buf, filename); - if (access(buf, R_OK) == 0) - return buf; - } - - strcpy(t, RESPATH); - strcat(t, filename); - realpath(t, buf); - if (access(buf, R_OK) == 0) - return buf; - - if (def[0] == '%') { - snprintf(t, PATH_MAX, "%s%s", path.Path(), def + 1); - realpath(t, buf); - } else if (def[0] == '~') { - snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1); - realpath(t, buf); - } else { - realpath(def, buf); - } - - return buf; -} - -/** - * Check that ~/.netsurf/ exists, and if it doesn't, create it. - */ -static void check_homedir(void) -{ - CALLED(); - status_t err; - - BPath path; - err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); - - if (err < B_OK) { - /* we really can't continue without a home directory. */ - LOG(("Can't find user settings directory - nowhere to store state!")); - die("NetSurf needs to find the user settings directory in order to run.\n"); - } - - path.Append("NetSurf"); - err = create_directory(path.Path(), 0644); - if (err < B_OK) { - LOG(("Unable to create %s", path.Path())); - die("NetSurf could not create its settings directory.\n"); - } -} - -static int32 bapp_thread(void *arg) -{ - be_app->Lock(); - be_app->Run(); - return 0; -} - -nsurl *gui_get_resource_url(const char *path) -{ - nsurl *url = NULL; - BString u("rsrc:///"); - if (strcmp(path, "default.css") == 0) - u << "beosdefault.css"; - else - u << path; - fprintf(stderr, "%s(%s) -> '%s'\n", __FUNCTION__, path, u.String()); - nsurl_create(u.String(), &url); - return url; -} - -static void gui_init2(int argc, char** argv) -{ - CALLED(); - const char *addr = NETSURF_HOMEPAGE; - - if (nsoption_charp(homepage_url) != NULL) - addr = nsoption_charp(homepage_url); - - if (argc > 1) addr = argv[1]; - if (gFirstRefsReceived) addr = NULL; - browser_window_create(addr, 0, 0, true, false); - if (gFirstRefsReceived) { - // resend the refs we got before having a window to send them to - be_app_messenger.SendMessage(gFirstRefsReceived); - delete gFirstRefsReceived; - gFirstRefsReceived = NULL; - } -} - -/** Normal entry point from OS */ -int main(int argc, char** argv) -{ - char buf[PATH_MAX]; - setbuf(stderr, NULL); - - BPath options; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { - options.Append("x-vnd.NetSurf"); - } - - find_resource(buf, "messages", "./beos/res/messages"); - LOG(("Using '%s' as Messages file", buf)); - //messages_load(buf); - - /* initialise netsurf */ - netsurf_init(&argc, &argv, options.Path(), buf); - - gui_init(argc, argv); - gui_init2(argc, argv); - - netsurf_main_loop(); - - netsurf_exit(); - - return 0; -} - - -void gui_init(int argc, char** argv) -{ - char buf[PATH_MAX]; - CALLED(); - - if (pipe(sEventPipe) < 0) - return; - if (!replicated) { - new NSBrowserApplication; - sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); - if (sBAppThreadID < B_OK) - return; /* #### handle errors */ - if (resume_thread(sBAppThreadID) < B_OK) - return; - } - - // ui_color() gives hardcoded values before BApplication is created. - nsbeos_update_system_ui_colors(); - - fetch_rsrc_register(); - - check_homedir(); - - // make sure the cache dir exists - create_directory(TEMP_FILENAME_PREFIX, 0600); - - //nsbeos_completion_init(); - - - /* This is an ugly hack to just get the new-style throbber going. - * It, along with the PNG throbber loader, need making more generic. - */ - { -#define STROF(n) #n -#define FIND_THROB(n) filenames[(n)] = \ - "throbber" STROF(n) ".png"; - char *filenames[9]; - FIND_THROB(0); - FIND_THROB(1); - FIND_THROB(2); - FIND_THROB(3); - FIND_THROB(4); - FIND_THROB(5); - FIND_THROB(6); - FIND_THROB(7); - FIND_THROB(8); - nsbeos_throbber_initialise_from_png(9, - filenames[0], filenames[1], filenames[2], filenames[3], - filenames[4], filenames[5], filenames[6], filenames[7], - filenames[8]); -#undef FIND_THROB -#undef STROF - } - -#if 0 - find_resource(buf, "throbber.gif", "./beos/res/throbber.gif"); - nsbeos_throbber_initialise_from_gif(buf); -#endif - - if (nsbeos_throbber == NULL) - die("Unable to load throbber image.\n"); - - find_resource(buf, "Choices", "%/Choices"); - LOG(("Using '%s' as Preferences file", buf)); - options_file_location = strdup(buf); - nsoption_read(buf); - - - /* check what the font settings are, setting them to a default font - * if they're not set - stops Pango whinging - */ - - //XXX: use be_plain_font & friends, when we can check if font is serif or not. -/* - font_family family; - font_style style; - be_plain_font->GetFamilyAndStyle(&family, &style); - nsoption_setnull_charp(font_sans, family); - nsoption_setnull_charp(font_serif, family); - nsoption_setnull_charp(font_mono, family); - nsoption_setnull_charp(font_cursive, family); - nsoption_setnull_charp(font_fantasy, family); -*/ -#ifdef __HAIKU__ - nsoption_setnull_charp(font_sans, "DejaVu Sans"); - nsoption_setnull_charp(font_serif, "DejaVu Serif"); - nsoption_setnull_charp(font_mono, "DejaVu Mono"); - nsoption_setnull_charp(font_cursive, "DejaVu Sans"); - nsoption_setnull_charp(font_fantasy, "DejaVu Sans"); -#else - nsoption_setnull_charp(font_sans, "Bitstream Vera Sans"); - nsoption_setnull_charp(font_serif, "Bitstream Vera Serif"); - nsoption_setnull_charp(font_mono, "Bitstream Vera Sans Mono"); - nsoption_setnull_charp(font_cursive, "Bitstream Vera Serif"); - nsoption_setnull_charp(font_fantasy, "Bitstream Vera Serif"); -#if 0 - nsoption_setnull_charp(font_sans, "Swis721 BT"); - nsoption_setnull_charp(font_serif, "Dutch801 Rm BT"); - //nsoption_setnull_charp(font_mono, "Monospac821 BT"); - nsoption_setnull_charp(font_mono, "Courier10 BT"); - nsoption_setnull_charp(font_cursive, "Swis721 BT"); - nsoption_setnull_charp(font_fantasy, "Swis721 BT"); -#endif -#endif - - nsbeos_options_init(); - - if (nsoption_charp(cookie_file) == NULL) { - find_resource(buf, "Cookies", "%/Cookies"); - LOG(("Using '%s' as Cookies file", buf)); - nsoption_set_charp(cookie_file, strdup(buf)); - } - if (nsoption_charp(cookie_jar) == NULL) { - find_resource(buf, "Cookies", "%/Cookies"); - LOG(("Using '%s' as Cookie Jar file", buf)); - nsoption_set_charp(cookie_jar, strdup(buf)); - } - if ((nsoption_charp(cookie_file) == NULL) || - (nsoption_charp(cookie_jar) == NULL)) - die("Failed initialising cookie options"); - - if (nsoption_charp(url_file) == NULL) { - find_resource(buf, "URLs", "%/URLs"); - LOG(("Using '%s' as URL file", buf)); - nsoption_set_charp(url_file, strdup(buf)); - } - - if (nsoption_charp(ca_path) == NULL) { - find_resource(buf, "certs", "/etc/ssl/certs"); - LOG(("Using '%s' as certificate path", buf)); - nsoption_set_charp(ca_path, strdup(buf)); - } - - //find_resource(buf, "mime.types", "/etc/mime.types"); - beos_fetch_filetype_init(); - - urldb_load(nsoption_charp(url_file)); - urldb_load_cookies(nsoption_charp(cookie_file)); - - //nsbeos_download_initialise(); - - if (!replicated) - be_app->Unlock(); - -#if 0 /* GTK */ - wndAbout = beos_WINDOW(glade_xml_get_widget(gladeWindows, "wndAbout")); - beos_label_set_text(beos_LABEL( - glade_xml_get_widget(gladeWindows, "labelVersion")), - netsurf_version); - beos_image_set_from_file(beos_IMAGE( - glade_xml_get_widget(gladeWindows, "imageLogo")), - find_resource(buf, "netsurf-logo.png", "netsurf-logo.png")); - fontdesc = pango_font_description_from_string("Monospace 8"); - beos_widget_modify_font(beos_WIDGET( - glade_xml_get_widget(gladeWindows, "textviewGPL")), fontdesc); - - wndWarning = beos_WINDOW(glade_xml_get_widget(gladeWindows, "wndWarning")); - wndOpenFile = beos_DIALOG(glade_xml_get_widget(gladeWindows, "wndOpenFile")); -#endif -} - - - - -void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui) -{ - if (message == NULL) { - fprintf(stderr, "%s(NULL)!\n", __FUNCTION__); - return; - } - if (_this) - message->AddPointer("View", _this); - if (gui) - message->AddPointer("gui_window", gui); - int len = write(sEventPipe[1], &message, sizeof(void *)); - //LOG(("nsbeos_pipe_message: %d written", len)); - //printf("nsbeos_pipe_message: %d written\n", len); -} - - -void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold) -{ - if (message == NULL) { - fprintf(stderr, "%s(NULL)!\n", __FUNCTION__); - return; - } - if (_this) - message->AddPointer("Window", _this); - if (scaffold) - message->AddPointer("scaffolding", scaffold); - int len = write(sEventPipe[1], &message, sizeof(void *)); - //LOG(("nsbeos_pipe_message: %d written", len)); - //printf("nsbeos_pipe_message: %d written\n", len); -} - - -void gui_poll(bool active) -{ - //CALLED(); - CURLMcode code; - - fd_set read_fd_set, write_fd_set, exc_fd_set; - int max_fd = 0; - struct timeval timeout; - unsigned int fd_count = 0; - bool block = true; - - if (browser_reformat_pending) - block = false; - - FD_ZERO(&read_fd_set); - FD_ZERO(&write_fd_set); - FD_ZERO(&exc_fd_set); - - if (active) { - code = curl_multi_fdset(fetch_curl_multi, - &read_fd_set, - &write_fd_set, - &exc_fd_set, - &max_fd); - assert(code == CURLM_OK); - } - - // our own event pipe - FD_SET(sEventPipe[0], &read_fd_set); - max_fd = MAX(max_fd, sEventPipe[0] + 1); - - - bigtime_t next_schedule = earliest_callback_timeout - system_time(); - if (!block) - next_schedule = 0LL; // now - if (block && earliest_callback_timeout != B_INFINITE_TIMEOUT) - block = false; - timeout.tv_sec = (long)(next_schedule / 1000000LL); - timeout.tv_usec = (long)(next_schedule % 1000000LL); - LOG(("gui_poll: select(%d, ..., %Ldus", max_fd, next_schedule)); - - fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set, - block ? NULL : &timeout); - - if (fd_count > 0 && FD_ISSET(sEventPipe[0], &read_fd_set)) { - BMessage *message; - int len = read(sEventPipe[0], &message, sizeof(void *)); - LOG(("gui_poll: BMessage ? %d read", len)); - if (len == sizeof(void *)) - nsbeos_dispatch_event(message); - } - - schedule_run(); - - if (browser_reformat_pending) - nsbeos_window_process_reformats(); -} - - -void gui_quit(void) -{ - CALLED(); - urldb_save_cookies(nsoption_charp(cookie_jar)); - urldb_save(nsoption_charp(url_file)); - //options_save_tree(hotlist,nsoption_charp(hotlist_file),messages_get("TreeHotlist")); - - free(nsoption_charp(cookie_file)); - free(nsoption_charp(cookie_jar)); - beos_fetch_filetype_fin(); - fetch_rsrc_unregister(); -} - - - -struct gui_download_window *gui_download_window_create(download_context *ctx, - struct gui_window *gui) -{ - return NULL; -} - - -nserror gui_download_window_data(struct gui_download_window *dw, - const char *data, unsigned int size) -{ - return NSERROR_OK; -} - - -void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ -} - - -void gui_download_window_done(struct gui_download_window *dw) -{ -} - -#if 0 /* GTK */ -static void nsbeos_select_menu_clicked(BCheckMenuItem *checkmenuitem, - gpointer user_data) -{ - form_select_process_selection(select_menu_bw->current_content, - select_menu_control, (intptr_t)user_data); -} -#endif - -void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ - CALLED(); -#if 0 /* GTK */ - - intptr_t i; - struct form_option *option; - - beosWidget *menu_item; - - /* control->data.select.multiple is true if multiple selections - * are allowable. We ignore this, as the core handles it for us. - * Yay. \o/ - */ - - if (select_menu != NULL) - beos_widget_destroy(select_menu); - - select_menu = beos_menu_new(); - select_menu_bw = bw; - select_menu_control = control; - - for (i = 0, option = control->data.select.items; option; - i++, option = option->next) { - menu_item = beos_check_menu_item_new_with_label(option->text); - if (option->selected) - beos_check_menu_item_set_active( - beos_CHECK_MENU_ITEM(menu_item), TRUE); - - g_signal_connect(menu_item, "toggled", - G_CALLBACK(nsbeos_select_menu_clicked), (gpointer)i); - - beos_menu_shell_append(beos_MENU_SHELL(select_menu), menu_item); - } - - beos_widget_show_all(select_menu); - - beos_menu_popup(beos_MENU(select_menu), NULL, NULL, NULL, - NULL /* data */, 0, beos_get_current_event_time()); - -#endif -} - -void -gui_window_save_link(struct gui_window *g, const char *url, const char *title) -{ -} - -/** - * Send the source of a content to a text editor. - */ - -void nsbeos_gui_view_source(struct hlcache_handle *content, struct selection *selection) -{ - char *temp_name; - bool done = false; - BPath path; - status_t err; - size_t size; - const char *source = content_get_source_data(content, &size); - - if (!content || !source) { - warn_user("MiscError", "No document source"); - return; - } - - /* try to load local files directly. */ - temp_name = url_to_path(nsurl_access(hlcache_handle_get_url(content))); - if (temp_name) { - path.SetTo(temp_name); - BEntry entry; - if (entry.SetTo(path.Path()) >= B_OK - && entry.Exists() && entry.IsFile()) - done = true; - } - if (!done) { - /* We cannot release the requested filename until after it - * has finished being used. As we can't easily find out when - * this is, we simply don't bother releasing it and simply - * allow it to be re-used next time NetSurf is started. The - * memory overhead from doing this is under 1 byte per - * filename. */ - const char *filename = filename_request(); - if (!filename) { - warn_user("NoMemory", 0); - return; - } - path.SetTo(TEMP_FILENAME_PREFIX); - path.Append(filename); - BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); - err = file.InitCheck(); - if (err < B_OK) { - warn_user("IOError", strerror(err)); - return; - } - err = file.Write(source, size); - if (err < B_OK) { - warn_user("IOError", strerror(err)); - return; - } - lwc_string *mime = content_get_mime_type(content); - const char *mime_string = lwc_string_data(mime); - if (mime) - file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, - mime_string, lwc_string_length(mime) + 1); - - } - - entry_ref ref; - if (get_ref_for_path(path.Path(), &ref) < B_OK) - return; - - BMessage m(B_REFS_RECEIVED); - m.AddRef("refs", &ref); - -#if 0 - if (selection && selection->defined) { - int32 line = -1; - if (content_get_type(content) == CONTENT_HTML) { - // XXX: use selection, find line in source code - } - if (content_get_type(content) == CONTENT_TEXTPLAIN) { - line = MAKELINE_FROM_IDX(start_idx); - } - // not CSS! - - if (line > -1) - message.AddInt32("be:line", line); - } -#endif - - // apps to try - const char *editorSigs[] = { - "application/x-vnd.beunited.pe", - "application/x-vnd.XEmacs", - "application/x-vnd.Haiku-StyledEdit", - "application/x-vnd.Be-STEE", - "application/x-vnd.yT-STEE", - NULL - }; - int i; - for (i = 0; editorSigs[i]; i++) { - team_id team = -1; - { - BMessenger msgr(editorSigs[i], team); - if (msgr.SendMessage(&m) >= B_OK) - break; - } - - err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team); - if (err >= B_OK) - break; - } -} - -/** - * Broadcast an URL that we can't handle. - */ - -void gui_launch_url(const char *url) -{ - status_t status; - // try to open it as an URI - BString mimeType = "application/x-vnd.Be.URL."; - BString arg(url); - mimeType.Append(arg, arg.FindFirst(":")); - - // special case, text/x-email is used traditionally - // use it instead - if (arg.IFindFirst("mailto:") == 0) - mimeType = "text/x-email"; - - // the protocol should be alphanum - // we just check if it's registered - // if not there is likely no supporting app anyway - if (!BMimeType::IsValid(mimeType.String())) - return; - char *args[2] = { (char *)url, NULL }; - status = be_roster->Launch(mimeType.String(), 1, args); - if (status < B_OK) - warn_user("Cannot launch url", strerror(status)); -} - - -/** - * Display a warning for a serious problem (eg memory exhaustion). - * - * \param warning message key for warning message - * \param detail additional message, or 0 - */ - -void warn_user(const char *warning, const char *detail) -{ - LOG(("warn_user: %s (%s)", warning, detail)); - BAlert *alert; - BString text(warning); - if (detail) - text << ":\n" << detail; -#if 0 - alert = new BAlert("NetSurf Warning", text.String(), "Ok", NULL, NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT); - alert->Go(); -#else - alert = new BAlert("NetSurf Warning", text.String(), "Debug", "Ok", NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT); - if (alert->Go() < 1) - debugger("warn_user"); -#endif -} - -void die(const char * const error) -{ - fprintf(stderr, "%s", error); - BAlert *alert; - BString text("Cannot continue:\n"); - text << error; -#if 0 - alert = new BAlert("NetSurf Error", text.String(), "Ok", NULL, NULL, - B_WIDTH_AS_USUAL, B_STOP_ALERT); - alert->Go(); -#else - alert = new BAlert("NetSurf Error", text.String(), "Debug", "Ok", NULL, - B_WIDTH_AS_USUAL, B_STOP_ALERT); - if (alert->Go() < 1) - debugger("die"); -#endif - exit(EXIT_FAILURE); -} - -void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, - unsigned long num, nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - CALLED(); -#if 0 /* GTK */ - nsbeos_create_ssl_verify_window(bw, c, certs, num); -#endif -} - -static void nsbeos_create_ssl_verify_window(struct browser_window *bw, - hlcache_handle *c, const struct ssl_cert_info *certs, - unsigned long num) -{ - CALLED(); -#if 0 /* GTK */ - GladeXML *x = glade_xml_new(glade_file_location, NULL, NULL); - beosWindow *wnd = beos_WINDOW(glade_xml_get_widget(x, "wndSSLProblem")); - beosButton *accept, *reject; - void **session = calloc(sizeof(void *), 4); - - session[0] = bw; - session[1] = strdup(c->url); - session[2] = x; - session[3] = wnd; - - accept = beos_BUTTON(glade_xml_get_widget(x, "sslaccept")); - reject = beos_BUTTON(glade_xml_get_widget(x, "sslreject")); - - g_signal_connect(G_OBJECT(accept), "clicked", - G_CALLBACK(nsbeos_ssl_accept), (gpointer)session); - g_signal_connect(G_OBJECT(reject), "clicked", - G_CALLBACK(nsbeos_ssl_reject), (gpointer)session); - - beos_widget_show(beos_WIDGET(wnd)); -#endif -} - -#if 0 /* GTK */ -static void nsbeos_ssl_accept(beosButton *w, gpointer data) -{ - void **session = data; - struct browser_window *bw = session[0]; - char *url = session[1]; - GladeXML *x = session[2]; - beosWindow *wnd = session[3]; - - urldb_set_cert_permissions(url, true); - browser_window_go(bw, url, 0, true); - - beos_widget_destroy(beos_WIDGET(wnd)); - g_object_unref(G_OBJECT(x)); - free(url); - free(session); -} - -static void nsbeos_ssl_reject(beosButton *w, gpointer data) -{ - void **session = data; - GladeXML *x = session[2]; - beosWindow *wnd = session[3]; - - beos_widget_destroy(beos_WIDGET(wnd)); - g_object_unref(G_OBJECT(x)); - free(session[1]); - free(session); -} -#endif - -utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, - char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return UTF8_CONVERT_NOMEM; - - return UTF8_CONVERT_OK; -} - -utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, - char **result) -{ - assert(string && result); - - if (len == 0) - len = strlen(string); - - *result = strndup(string, len); - if (!(*result)) - return UTF8_CONVERT_NOMEM; - - return UTF8_CONVERT_OK; -} - -char *path_to_url(const char *path) -{ - int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - char *url = (char *)malloc(urllen); - - if (url == NULL) { - return NULL; - } - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - -char *url_to_path(const char *url) -{ - char *url_path = curl_unescape(url, 0); - char *path; - - /* return the absolute path including leading / */ - path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); - curl_free(url_path); - - return path; -} - -bool cookies_update(const char *domain, const struct cookie_data *data) -{ - return true; -} - -static void *myrealloc(void *ptr, size_t len, void *pw) -{ - if (len == 0) { - free(ptr); - return NULL; - } - - return realloc(ptr, len); -} - -/** - * Return the filename part of a full path - * - * \param path full path and filename - * \return filename (will be freed with free()) - */ - -char *filename_from_path(char *path) -{ - char *leafname; - - leafname = strrchr(path, '/'); - if (!leafname) - leafname = path; - else - leafname += 1; - - return strdup(leafname); -} - -/** - * Add a path component/filename to an existing path - * - * \param path buffer containing path + free space - * \param length length of buffer "path" - * \param newpart string containing path component to add to path - * \return true on success - */ - -bool path_add_part(char *path, int length, const char *newpart) -{ - if(path[strlen(path) - 1] != '/') - strncat(path, "/", length); - - strncat(path, newpart, length); - - return true; -} diff --git a/beos/beos_gui.h b/beos/beos_gui.h deleted file mode 100644 index 6bbfa1dd1..000000000 --- a/beos/beos_gui.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2005 James Bursa - * - * 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 . - */ - -#include -#include -#include -#include -#include - -#ifndef B_BEOS_VERSION_DANO -#define B_UI_SETTINGS_CHANGED '_UIC' -#endif - -#define CALLED() fprintf(stderr, "%s()\n", __FUNCTION__); - -extern bool replicated; - -#if 0 /* GTK */ -//extern GladeXML *gladeWindows; -//extern char *glade_file_location; -#endif -extern char *options_file_location; - -class NSBrowserApplication : public BApplication { -public: - NSBrowserApplication(); -virtual ~NSBrowserApplication(); - -virtual void MessageReceived(BMessage *message); -virtual void RefsReceived(BMessage *message); -virtual void ArgvReceived(int32 argc, char **argv); - -virtual void AboutRequested(); -virtual bool QuitRequested(); -}; - - -extern void schedule_run(void); - -extern BWindow *wndAbout; - -extern BWindow *wndTooltip; -#if 0 /* GTK */ -//extern GtkLabel *labelTooltip; -#endif - -extern BFilePanel *wndOpenFile; - -void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui); -void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold); - -void nsbeos_gui_view_source(struct hlcache_handle *content, struct selection *selection); -image_id nsbeos_find_app_path(char *path); - -void nsbeos_update_system_ui_colors(void); diff --git a/beos/beos_login.cpp b/beos/beos_login.cpp deleted file mode 100644 index c732cd398..000000000 --- a/beos/beos_login.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -extern "C" { -#include "utils/log.h" -#include "content/content.h" -#include "content/urldb.h" -#include "desktop/browser.h" -#include "desktop/401login.h" -#include "desktop/gui.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" -} -#include "beos/beos_gui.h" -#include "beos/beos_scaffolding.h" -#include "beos/beos_window.h" - -class LoginAlert : public BAlert { -public: - LoginAlert(nserror (*callback)(bool proceed, void *pw), - void *callbaclpw, - const char *url, - const char *host, - const char *realm, - const char *text); - virtual ~LoginAlert(); - void MessageReceived(BMessage *message); - -private: - BString fUrl; /**< URL being fetched */ - BString fHost; /**< Host for user display */ - BString fRealm; /**< Authentication realm */ - nserror (*fCallback)(bool proceed, void *pw); - void *fCallbackPw; - - BTextControl *fUserControl; - BTextControl *fPassControl; -}; - -static void create_login_window(const char *host, - const char *realm, const char *fetchurl, - nserror (*cb)(bool proceed, void *pw), void *cbpw); - - -#define TC_H 25 -#define TC_MARGIN 10 - -LoginAlert::LoginAlert(nserror (*callback)(bool proceed, void *pw), - void *callbackpw, - const char *url, - const char *host, - const char *realm, - const char *text) - : BAlert("Login", text, "Cancel", "Ok", NULL, - B_WIDTH_AS_USUAL, B_WARNING_ALERT) -{ - fCallback = callback; - fCallbackPw = callbackpw; - fUrl = url; - fHost = host; - fRealm = realm; - - SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); - /* - // XXX: can't do that anymore - nsbeos_scaffolding *s = nsbeos_get_scaffold(bw->window); - if (s) { - NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s); - if (w) - AddToSubset(w); - }*/ - - // make space for controls - ResizeBy(0, 2 * TC_H); - MoveTo(AlertPosition(Frame().Width() + 1, - Frame().Height() + 1)); - - - BTextView *tv = TextView(); - BRect r(TC_MARGIN, tv->Bounds().bottom - 2 * TC_H, - tv->Bounds().right - TC_MARGIN, tv->Bounds().bottom - TC_H); - - fUserControl = new BTextControl(r, "user", "Username", "", - new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); - fUserControl->SetDivider(60); - tv->AddChild(fUserControl); - - r.OffsetBySelf(0, TC_H); - - fPassControl = new BTextControl(r, "pass", "Password", "", - new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); - fPassControl->TextView()->HideTyping(true); - fPassControl->SetDivider(60); - tv->AddChild(fPassControl); - - SetShortcut(0, B_ESCAPE); -} - -LoginAlert::~LoginAlert() -{ -} - -void -LoginAlert::MessageReceived(BMessage *message) -{ - switch (message->what) { - case 'ALTB': - { - int32 which; - if (message->FindInt32("which", &which) < B_OK) - break; - // not 'Ok' - if (which != 1) - break; - BMessage *m = new BMessage(*message); - m->what = 'nsLO'; - m->AddString("URL", fUrl.String()); - m->AddString("Host", fHost.String()); - m->AddString("Realm", fRealm.String()); - m->AddPointer("callback", (void *)fCallback); - m->AddPointer("callback_pw", (void *)fCallbackPw); - m->AddString("User", fUserControl->Text()); - m->AddString("Pass", fPassControl->Text()); - BString auth(fUserControl->Text()); - auth << ":" << fPassControl->Text(); - m->AddString("Auth", auth.String()); - - // notify the main thread - // the event dispatcher will handle it - nsbeos_pipe_message(m, NULL, NULL); - } - break; - default: - break; - } - BAlert::MessageReceived(message); -} - - -void gui_401login_open(const char *url, const char *realm, - nserror (*cb)(bool proceed, void *pw), void *cbpw) -{ - char *host; - url_func_result res; - - res = url_host(url, &host); - assert(res == URL_FUNC_OK); - - create_login_window(url, host, realm, cb, cbpw); - - free(host); -} - -//void create_login_window(struct browser_window *bw, const char *host, -// const char *realm, const char *fetchurl) -static void create_login_window(const char *url, const char *host, - const char *realm, nserror (*cb)(bool proceed, void *pw), - void *cbpw) -{ - BString r("Secure Area"); - if (realm) - r = realm; - BString text(/*messages_get(*/"Please login\n"); - text << "Realm: " << r << "\n"; - text << "Host: " << host << "\n"; - //text << "\n"; - - LoginAlert *a = new LoginAlert(cb, cbpw, url, host, r.String(), - text.String()); - // asynchronously - a->Go(NULL); - -} diff --git a/beos/beos_options.cpp b/beos/beos_options.cpp deleted file mode 100644 index acef3dcc6..000000000 --- a/beos/beos_options.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Rob Kendrick - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -extern "C" { -#include "utils/log.h" -#include "desktop/options.h" -} -#include "beos/beos_gui.h" -#include "beos/beos_scaffolding.h" -#include "beos/beos_options.h" - -#include -#include - -BWindow *wndPreferences; - -void nsbeos_options_init(void) { - /* set the widgets to reflect the current options */ - nsbeos_options_load(); -} - -void nsbeos_options_load(void) { -#warning WRITEME -} - - -void nsbeos_options_save(void) { -#warning WRITEME -} diff --git a/beos/beos_options.h b/beos/beos_options.h deleted file mode 100644 index 38aaf866a..000000000 --- a/beos/beos_options.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Rob Kendrick - * - * 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 . - */ - -#ifndef NETSURF_BEOS_OPTIONS_H -#define NETSURF_BEOS_OPTIONS_H - -#include - -#if 0 /* GTK */ -extern GtkWindow *wndPreferences; -#endif -extern BWindow *wndPreferences; - -void nsbeos_options_init(void); /** Init options and load window */ -void nsbeos_options_load(void); /** Load current options into window */ -void nsbeos_options_save(void); /** Save options from window */ - -#endif diff --git a/beos/beos_plotters.cpp b/beos/beos_plotters.cpp deleted file mode 100644 index adc9588b3..000000000 --- a/beos/beos_plotters.cpp +++ /dev/null @@ -1,894 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Rob Kendrick - * Copyright 2005 James Bursa - * - * 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 . - */ - -/** \file - * Target independent plotting (BeOS/Haiku implementation). - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -extern "C" { -#include "desktop/plotters.h" -#include "render/font.h" -#include "utils/log.h" -#include "utils/utils.h" -#include "desktop/options.h" -} -#include "beos/beos_font.h" -#include "beos/beos_gui.h" -#include "beos/beos_plotters.h" -//#include "beos/beos_scaffolding.h" -//#include "beos/options.h" -#include "beos/beos_bitmap.h" - -#warning MAKE ME static -/*static*/ BView *current_view; - -#if 0 /* GTK */ -GtkWidget *current_widget; -GdkDrawable *current_drawable; -GdkGC *current_gc; -#ifdef CAIRO_VERSION -cairo_t *current_cr; -#endif -#endif - -/* - * NOTE: BeOS rects differ from NetSurf ones: - * the right-bottom pixel is actually part of the BRect! - */ - -static bool nsbeos_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); -static bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style); -static bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style); -static bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float width, - colour c, const float transform[6]); -static bool nsbeos_plot_clip(const struct rect *ns_clip); -static bool nsbeos_plot_text(int x, int y, const char *text, size_t length, - const plot_font_style_t *fstyle); -static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style); -static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, - const plot_style_t *style); -static bool nsbeos_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, - bitmap_flags_t flags); - -#if 0 /* GTK */ -static GdkRectangle cliprect; -#endif - -#warning make patterns nicer -static const pattern kDottedPattern = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; -static const pattern kDashedPattern = { 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33 }; - -static const rgb_color kBlackColor = { 0, 0, 0, 255 }; - -struct plotter_table plot; - -const struct plotter_table nsbeos_plotters = { - nsbeos_plot_clip, - nsbeos_plot_arc, - nsbeos_plot_disc, - nsbeos_plot_line, - nsbeos_plot_rectangle, - nsbeos_plot_polygon, - nsbeos_plot_path, - nsbeos_plot_bitmap, - nsbeos_plot_text, - NULL, // Group Start - NULL, // Group End - NULL, // Flush - true // option_knockout -}; - - -// #pragma mark - implementation - - -BView *nsbeos_current_gc(void) -{ - return current_view; -} - -BView *nsbeos_current_gc_lock(void) -{ - BView *view = current_view; - if (view && view->LockLooper()) - return view; - return NULL; -} - -void nsbeos_current_gc_unlock(void) -{ - if (current_view) - current_view->UnlockLooper(); -} - -void nsbeos_current_gc_set(BView *view) -{ - // XXX: (un)lock previous ? - current_view = view; -} - -bool nsbeos_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) -{ - if (style->fill_type != PLOT_OP_TYPE_NONE) { - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->fill_colour); - - BRect rect(x0, y0, x1 - 1, y1 - 1); - view->FillRect(rect); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ - nsbeos_set_colour(style->fill_colour); - nsbeos_set_solid(); -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - cairo_set_line_width(current_cr, 0); - cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0); - cairo_fill(current_cr); - cairo_stroke(current_cr); - } else -#endif - gdk_draw_rectangle(current_drawable, current_gc, - TRUE, x0, y0, x1 - x0, y1 - y0); -#endif - } - - if (style->stroke_type != PLOT_OP_TYPE_NONE) { - pattern pat; - BView *view; - - switch (style->stroke_type) { - case PLOT_OP_TYPE_SOLID: /**< Solid colour */ - default: - pat = B_SOLID_HIGH; - break; - - case PLOT_OP_TYPE_DOT: /**< Doted plot */ - pat = kDottedPattern; - break; - - case PLOT_OP_TYPE_DASH: /**< dashed plot */ - pat = kDashedPattern; - break; - } - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->stroke_colour); - - float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); - - BRect rect(x0, y0, x1, y1); - view->StrokeRect(rect, pat); - - view->SetPenSize(pensize); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - if (line_width == 0) - line_width = 1; - - cairo_set_line_width(current_cr, line_width); - cairo_rectangle(current_cr, x0, y0, width, height); - cairo_stroke(current_cr); - } else -#endif - gdk_draw_rectangle(current_drawable, current_gc, - FALSE, x0, y0, width, height); - return true; -#endif - } - - return true; -} - - - -bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style) -{ - pattern pat; - BView *view; - - switch (style->stroke_type) { - case PLOT_OP_TYPE_SOLID: /**< Solid colour */ - default: - pat = B_SOLID_HIGH; - break; - - case PLOT_OP_TYPE_DOT: /**< Doted plot */ - pat = kDottedPattern; - break; - - case PLOT_OP_TYPE_DASH: /**< dashed plot */ - pat = kDashedPattern; - break; - } - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->stroke_colour); - - float pensize = view->PenSize(); - view->SetPenSize(style->stroke_width); - - BPoint start(x0, y0); - BPoint end(x1, y1); - view->StrokeLine(start, end, pat); - - view->SetPenSize(pensize); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - if (width == 0) - width = 1; - - cairo_set_line_width(current_cr, width); - cairo_move_to(current_cr, x0, y0 - 0.5); - cairo_line_to(current_cr, x1, y1 - 0.5); - cairo_stroke(current_cr); - } else -#endif - gdk_draw_line(current_drawable, current_gc, - x0, y0, x1, y1); -#endif - return true; -} - - -bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style) -{ - unsigned int i; - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->fill_colour); - - BPoint points[n]; - - for (i = 0; i < n; i++) { - points[i] = BPoint(p[2 * i] - 0.5, p[2 * i + 1] - 0.5); - } - - if (style->fill_colour == NS_TRANSPARENT) - view->StrokePolygon(points, (int32)n); - else - view->FillPolygon(points, (int32)n); - - return true; -} - - - - -bool nsbeos_plot_clip(const struct rect *ns_clip) -{ - BView *view; - //fprintf(stderr, "%s(%d, %d, %d, %d)\n", __FUNCTION__, clip_x0, clip_y0, clip_x1, clip_y1); - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - BRect rect(ns_clip->x0, ns_clip->y0, ns_clip->x1 - 1, - ns_clip->y1 - 1); - BRegion clip(rect); - view->ConstrainClippingRegion(NULL); - if (view->Bounds() != rect) - view->ConstrainClippingRegion(&clip); - - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - cairo_reset_clip(current_cr); - cairo_rectangle(current_cr, clip->x0, clip->y0, - clip->x1 - clip->x0, clip->y1 - clip->y0); - cairo_clip(current_cr); - } -#endif - cliprect.x = clip->x0; - cliprect.y = clip->y0; - cliprect.width = clip->x1 - clip->x0; - cliprect.height = clip->y1 - clip->y0; - gdk_gc_set_clip_rectangle(current_gc, &cliprect); -#endif - return true; -} - - -bool nsbeos_plot_text(int x, int y, const char *text, size_t length, - const plot_font_style_t *fstyle) -{ - return nsfont_paint(fstyle, text, length, x, y); -} - - -bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style) -{ - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->fill_colour); - - BPoint center(x, y); - if (style->fill_type != PLOT_OP_TYPE_NONE) - view->FillEllipse(center, radius, radius); - else - view->StrokeEllipse(center, radius, radius); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ - nsbeos_set_colour(c); - nsbeos_set_solid(); -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - if (filled) - cairo_set_line_width(current_cr, 0); - else - cairo_set_line_width(current_cr, 1); - - cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); - - if (filled) - cairo_fill(current_cr); - - cairo_stroke(current_cr); - } else -#endif - gdk_draw_arc(current_drawable, current_gc, - filled ? TRUE : FALSE, x - (radius), y - radius, - radius * 2, radius * 2, - 0, - 360 * 64); - -#endif - return true; -} - -bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) -{ - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - nsbeos_set_colour(style->fill_colour); - - BPoint center(x, y); - float angle = angle1; // in degree - float span = angle2 - angle1; // in degree - view->StrokeArc(center, radius, radius, angle, span); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ - nsbeos_set_colour(style->fill_colour); - nsbeos_set_solid(); -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) { - cairo_set_line_width(current_cr, 1); - cairo_arc(current_cr, x, y, radius, - (angle1 + 90) * (M_PI / 180), - (angle2 + 90) * (M_PI / 180)); - cairo_stroke(current_cr); - } else -#endif - gdk_draw_arc(current_drawable, current_gc, - FALSE, x - (radius), y - radius, - radius * 2, radius * 2, - angle1 * 64, angle2 * 64); - -#endif - return true; -} - -static bool nsbeos_plot_bbitmap(int x, int y, int width, int height, - BBitmap *b, colour bg) -{ - /* XXX: This currently ignores the background colour supplied. - * Does this matter? - */ - - if (width == 0 || height == 0) - return true; - - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - drawing_mode oldmode = view->DrawingMode(); - source_alpha alpha; - alpha_function func; - view->GetBlendingMode(&alpha, &func); - //view->SetDrawingMode(B_OP_OVER); - view->SetDrawingMode(B_OP_ALPHA); - view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - - // XXX DrawBitmap() resamples if rect doesn't match, - // but doesn't do any filtering - // XXX: use Zeta API if available ? - - BRect rect(x, y, x + width - 1, y + height - 1); - /* - rgb_color old = view->LowColor(); - if (bg != NS_TRANSPARENT) { - view->SetLowColor(nsbeos_rgb_colour(bg)); - view->FillRect(rect, B_SOLID_LOW); - } - */ - view->DrawBitmap(b, rect); - // maybe not needed? - //view->SetLowColor(old); - view->SetBlendingMode(alpha, func); - view->SetDrawingMode(oldmode); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ - /* XXX: This currently ignores the background colour supplied. - * Does this matter? - */ - - if (width == 0 || height == 0) - return true; - - if (gdk_pixbuf_get_width(pixbuf) == width && - gdk_pixbuf_get_height(pixbuf) == height) { - gdk_draw_pixbuf(current_drawable, current_gc, - pixbuf, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_MAX, 0, 0); - - } else { - GdkPixbuf *scaled; - scaled = gdk_pixbuf_scale_simple(pixbuf, - width, height, - nsoption_bool(render_resample) ? GDK_INTERP_BILINEAR - : GDK_INTERP_NEAREST); - if (!scaled) - return false; - - gdk_draw_pixbuf(current_drawable, current_gc, - scaled, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_MAX, 0, 0); - - g_object_unref(scaled); - } - -#endif - return true; -} - - -bool nsbeos_plot_bitmap(int x, int y, int width, int height, - struct bitmap *bitmap, colour bg, - bitmap_flags_t flags) -{ - int doneheight = 0, donewidth = 0; - BBitmap *primary; - BBitmap *pretiled; - bool repeat_x = (flags & BITMAPF_REPEAT_X); - bool repeat_y = (flags & BITMAPF_REPEAT_Y); - - if (!(repeat_x || repeat_y)) { - /* Not repeating at all, so just plot it */ - primary = nsbeos_bitmap_get_primary(bitmap); - return nsbeos_plot_bbitmap(x, y, width, height, primary, bg); - } - - if (repeat_x && !repeat_y) - pretiled = nsbeos_bitmap_get_pretile_x(bitmap); - if (repeat_x && repeat_y) - pretiled = nsbeos_bitmap_get_pretile_xy(bitmap); - if (!repeat_x && repeat_y) - pretiled = nsbeos_bitmap_get_pretile_y(bitmap); - primary = nsbeos_bitmap_get_primary(bitmap); - - /* use the primary and pretiled widths to scale the w/h provided */ - width *= pretiled->Bounds().Width() + 1; - width /= primary->Bounds().Width() + 1; - height *= pretiled->Bounds().Height() + 1; - height /= primary->Bounds().Height() + 1; - - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) { - warn_user("No GC", 0); - return false; - } - - // XXX: do we really need to use clipping reg ? - // I guess it's faster to not draw clipped out stuff... - - BRect cliprect; - BRegion clipreg; - view->GetClippingRegion(&clipreg); - cliprect = clipreg.Frame(); - - //XXX: FIXME - - if (y > cliprect.top) - doneheight = ((int)cliprect.top - height) + ((y - (int)cliprect.top) % height); - else - doneheight = y; - - while (doneheight < ((int)cliprect.bottom)) { - if (x > cliprect.left) - donewidth = ((int)cliprect.left - width) + ((x - (int)cliprect.left) % width); - else - donewidth = x; - while (donewidth < (cliprect.right)) { - nsbeos_plot_bbitmap(donewidth, doneheight, - width, height, pretiled, bg); - donewidth += width; - if (!repeat_x) break; - } - doneheight += height; - if (!repeat_y) break; - } - -#warning WRITEME -#if 0 /* GTK */ - int doneheight = 0, donewidth = 0; - GdkPixbuf *primary; - GdkPixbuf *pretiled; - - if (!(repeat_x || repeat_y)) { - /* Not repeating at all, so just pass it on */ - return nsbeos_plot_bitmap(x,y,width,height,bitmap,bg); - } - - if (repeat_x && !repeat_y) - pretiled = gtk_bitmap_get_pretile_x(bitmap); - if (repeat_x && repeat_y) - pretiled = gtk_bitmap_get_pretile_xy(bitmap); - if (!repeat_x && repeat_y) - pretiled = gtk_bitmap_get_pretile_y(bitmap); - primary = gtk_bitmap_get_primary(bitmap); - /* use the primary and pretiled widths to scale the w/h provided */ - width *= gdk_pixbuf_get_width(pretiled); - width /= gdk_pixbuf_get_width(primary); - height *= gdk_pixbuf_get_height(pretiled); - height /= gdk_pixbuf_get_height(primary); - - if (y > cliprect.y) - doneheight = (cliprect.y - height) + ((y - cliprect.y) % height); - else - doneheight = y; - - while (doneheight < (cliprect.y + cliprect.height)) { - if (x > cliprect.x) - donewidth = (cliprect.x - width) + ((x - cliprect.x) % width); - else - donewidth = x; - while (donewidth < (cliprect.x + cliprect.width)) { - nsbeos_plot_pixbuf(donewidth, doneheight, - width, height, pretiled, bg); - donewidth += width; - if (!repeat_x) break; - } - doneheight += height; - if (!repeat_y) break; - } - - -#endif - return true; -} - -static BPoint transform_pt(float x, float y, const float transform[6]) -{ -#warning XXX: verify - //return BPoint(x, y); - BPoint pt; - pt.x = x * transform[0] + y * transform[1] + transform[4]; - pt.y = x * transform[2] + y * transform[3] + transform[5]; - /* - printf("TR: {%f, %f} { %f, %f, %f, %f, %f, %f} = { %f, %f }\n", - x, y, - transform[0], transform[1], transform[2], - transform[3], transform[4], transform[5], - pt.x, pt.y); - */ - return pt; -} - -bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float width, - colour c, const float transform[6]) -{ - unsigned int i; - - if (n == 0) - return true; - - if (p[0] != PLOTTER_PATH_MOVE) { - LOG(("path doesn't start with a move")); - return false; - } - - BShape shape; - - for (i = 0; i < n; ) { - if (p[i] == PLOTTER_PATH_MOVE) { - BPoint pt(transform_pt(p[i + 1], p[i + 2], transform)); - shape.MoveTo(pt); - i += 3; - } else if (p[i] == PLOTTER_PATH_CLOSE) { - shape.Close(); - i++; - } else if (p[i] == PLOTTER_PATH_LINE) { - BPoint pt(transform_pt(p[i + 1], p[i + 2], transform)); - shape.LineTo(pt); - i += 3; - } else if (p[i] == PLOTTER_PATH_BEZIER) { - BPoint pt[3] = { - transform_pt(p[i + 1], p[i + 2], transform), - transform_pt(p[i + 3], p[i + 4], transform), - transform_pt(p[i + 5], p[i + 6], transform) - }; - shape.BezierTo(pt); - i += 7; - } else { - LOG(("bad path command %f", p[i])); - return false; - } - } - shape.Close(); - - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) - return false; - - rgb_color old_high = view->HighColor(); - float old_pen = view->PenSize(); - view->SetPenSize(width); - view->MovePenTo(0, 0); - if (fill != NS_TRANSPARENT) { - view->SetHighColor(nsbeos_rgb_colour(fill)); - view->FillShape(&shape); - } - if (c != NS_TRANSPARENT) { - view->SetHighColor(nsbeos_rgb_colour(c)); - view->StrokeShape(&shape); - } - // restore - view->SetPenSize(old_pen); - view->SetHighColor(old_high); - - //nsbeos_current_gc_unlock(); - - return true; -} - -rgb_color nsbeos_rgb_colour(colour c) -{ - rgb_color color; - if (c == NS_TRANSPARENT) - return B_TRANSPARENT_32_BIT; - color.red = c & 0x0000ff; - color.green = (c & 0x00ff00) >> 8; - color.blue = (c & 0xff0000) >> 16; - return color; -} - -void nsbeos_set_colour(colour c) -{ - rgb_color color = nsbeos_rgb_colour(c); - BView *view = nsbeos_current_gc(); - view->SetHighColor(color); -#if 0 /* GTK */ - int r, g, b; - GdkColor colour; - - r = c & 0xff; - g = (c & 0xff00) >> 8; - b = (c & 0xff0000) >> 16; - - colour.red = r | (r << 8); - colour.green = g | (g << 8); - colour.blue = b | (b << 8); - colour.pixel = (r << 16) | (g << 8) | b; - - gdk_color_alloc(gdk_colormap_get_system(), - &colour); - gdk_gc_set_foreground(current_gc, &colour); -#ifdef CAIRO_VERSION - if (nsoption_bool(render_cairo)) - cairo_set_source_rgba(current_cr, r / 255.0, - g / 255.0, b / 255.0, 1.0); -#endif -#endif -} - -/** Plot a caret. It is assumed that the plotters have been set up. */ -void nsbeos_plot_caret(int x, int y, int h) -{ - BView *view; - - view = nsbeos_current_gc/*_lock*/(); - if (view == NULL) - /* TODO: report an error here */ - return; - - BPoint start(x, y); - BPoint end(x, y + h - 1); -#if defined(__HAIKU__) || defined(B_BEOS_VERSION_DANO) - view->SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR)); -#else - view->SetHighColor(kBlackColor); -#endif - view->StrokeLine(start, end); - - //nsbeos_current_gc_unlock(); - -#if 0 /* GTK */ - GdkColor colour; - - colour.red = 0; - colour.green = 0; - colour.blue = 0; - colour.pixel = 0; - gdk_color_alloc(gdk_colormap_get_system(), - &colour); - gdk_gc_set_foreground(current_gc, &colour); - - gdk_draw_line(current_drawable, current_gc, - x, y, - x, y + h - 1); -#endif -} - -#ifdef TEST_PLOTTERS -// -static void test_plotters(void) -{ - int x0, y0; - int x1, y1; - struct rect r; - - x0 = 5; - y0 = 5; - x1 = 35; - y1 = 6; - - plot.line(x0, y0, x1, y1, 1, 0x0000ff00, false, false); - y0+=2; y1+=2; - plot.line(x0, y0, x1, y1, 1, 0x0000ff00, true, false); - y0+=2; y1+=2; - plot.line(x0, y0, x1, y1, 1, 0x0000ff00, false, true); - y0+=2; y1+=2; - plot.line(x0, y0, x1, y1, 1, 0x0000ff00, true, true); - y0+=10; y1+=20; - - plot.fill(x0, y0, x1, y1, 0x00ff0000); - plot.rectangle(x0+10, y0+10, x1-x0+1, y1-y0+1, 2, 0x00ffff00, true, false); - y0+=30; y1+=30; - - r.x0 = x0 + 2; - r.y0 = y0 + 2; - r.x1 = x1 - 2; - r.y1 = y1 - 2; - plot.clip(&r); - - plot.fill(x0, y0, x1, y1, 0x00000000); - plot.disc(x1, y1, 8, 0x000000ff, false); - - r.x0 = 0; - r.y0 = 0; - r.x1 = 300; - r.y1 = 300; - plot.clip(&r); - - y0+=30; y1+=30; - -} - -#include -#include -#include -class PTView : public BView { -public: - PTView(BRect frame) : BView(frame, "view", B_FOLLOW_NONE, B_WILL_DRAW) {}; - virtual ~PTView() {}; - virtual void Draw(BRect update) - { - test_plotters(); - }; - -}; - -extern "C" void test_plotters_main(void); -void test_plotters_main(void) -{ - BApplication app("application/x-vnd.NetSurf"); - memcpy(&plot, &nsbeos_plotters, sizeof(plot)); - BRect frame(0,0,300,300); - PTView *view = new PTView(frame); - frame.OffsetBySelf(100,100); - BWindow *win = new BWindow(frame, "NetSurfPlotterTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE); - win->AddChild(view); - nsbeos_current_gc_set(view); - win->Show(); - app.Run(); -} -#endif /* TEST_PLOTTERS */ - diff --git a/beos/beos_plotters.h b/beos/beos_plotters.h deleted file mode 100644 index 15b97a89e..000000000 --- a/beos/beos_plotters.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2005 James Bursa - * - * 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 . - */ - -/** \file - * Target independent plotting (BeOS interface). - */ - -#ifndef NETSURF_BEOS_PLOTTERS_H -#define NETSURF_BEOS_PLOTTERS_H 1 - -extern "C" { - -struct plotter_table; - -extern const struct plotter_table nsbeos_plotters; - -} - -#include - -extern BView *current_view; -#if 0 /* GTK */ -extern GtkWidget *current_widget; -extern GdkDrawable *current_drawable; -extern GdkGC *current_gc; -#ifdef CAIRO_VERSION -extern cairo_t *current_cr; -#endif -#endif - -extern BView *nsbeos_current_gc(void); -extern BView *nsbeos_current_gc_lock(void); -extern void nsbeos_current_gc_unlock(void); -extern void nsbeos_current_gc_set(BView *view); - -rgb_color nsbeos_rgb_colour(colour c); -void nsbeos_set_colour(colour c); -void nsbeos_plot_caret(int x, int y, int h); - -#endif /* NETSURF_GTK_PLOTTERS_H */ diff --git a/beos/beos_res.h b/beos/beos_res.h deleted file mode 100644 index 4e6497815..000000000 --- a/beos/beos_res.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -enum { - R_ResizeHandle = 1000, - R_ResBackNavActive = 1042, - R_ResBackNavInactive = 1043, - R_ResForwNavActive = 1044, - R_ResForwNavInactive = 1045, - R_ResUpNavActive = 1046, - R_ResUpNavInactive = 1047, - R_ResBackNavActiveSel = 1048, - R_ResForwNavActiveSel = 1049, - R_ResUpNavActiveSel = 1050 -}; diff --git a/beos/beos_res.rdef b/beos/beos_res.rdef deleted file mode 100644 index 8cb8fd09f..000000000 --- a/beos/beos_res.rdef +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#include "beos_res.h" - -/* throbber */ -resource(400, "throbber0.png") #'data' import "res/throbber/throbber0.png"; -resource(401, "throbber1.png") #'data' import "res/throbber/throbber1.png"; -resource(402, "throbber2.png") #'data' import "res/throbber/throbber2.png"; -resource(403, "throbber3.png") #'data' import "res/throbber/throbber3.png"; -resource(404, "throbber4.png") #'data' import "res/throbber/throbber4.png"; -resource(405, "throbber5.png") #'data' import "res/throbber/throbber5.png"; -resource(406, "throbber6.png") #'data' import "res/throbber/throbber6.png"; -resource(407, "throbber7.png") #'data' import "res/throbber/throbber7.png"; -resource(408, "throbber8.png") #'data' import "res/throbber/throbber8.png"; - -/* */ -resource(500, "credits.html") #'data' import "res/en/credits.html,faf"; -resource(501, "licence.html") #'data' import "res/en/licence.html,faf"; - - -resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000"; - -resource(101, "BEOS:L:STD_ICON") #'ICON' array { - $"FFFFFFFFFFFFFFFFFFFFFF0E0A00D600D6000AAF0EFFFFFFFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFF0E0A000001DED5D5D5DE020000090EFFFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFF0B0001B58D6666666C6C6C6C93B50200090EFFFFFFFFFFFFFF" - $"FFFFFFFFFF0E0000016D66666666666C6C6C6C6C6C6CB40104AFFFFFFFFFFFFF" - $"FFFFFFFF0E0001B503464666666666666C6C6C6C6C6C6C9303000DFFFFFFFFFF" - $"FFFFFF0E000267AEB5464666666666666C6C6C6C66666C7292DE000DFFFFFFFF" - $"FFFFFF070167464666464646666666666C666C6C1F1F66664092DE000EFFFFFF" - $"FFFF0B008E46464646464646666666666C403F1E3F3F3F3F6692930100FFFFFF" - $"FFFF00074646668D46464666666666666C663F3F3F3F3F3F6672927E000EFFFF" - $"FF0B006D6646670246464666666666666C663F3F3F3F3F3F3F1E6C923D00FFFF" - $"FF00D56666668E044646666666666666403F3F3F3F3F3F3F1F6692927E000EFF" - $"0E008E666666678E666666666666666C6C661E3F3F3F3F3F1D92929293000BFF" - $"0B016C66666666666666666666666C6C6C6C403F3F3F3F3F3F6C929292DE00FF" - $"08036C666666666666666666666C6C6C6C6C1E1D403F1E6C666C929292DD00FF" - $"00D56C6C66668D06666666666C6C6C6C6C6C6C6C6C1D667292929292927E03FF" - $"00D56C6C6C6C8D02666C6C6C6C6C6C6C6C6C6C6C6C6C729292929292927E03FF" - $"00D56C6C6C6C6CDE6C6C6C6C6C6C6C6C6C6C6C6C7272729292929292927E03FF" - $"00DE6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C7272729292929292925F0103FF" - $"09026C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C72727292929292929293010100FF" - $"0B008D6C6C6C6C8DD56C6C6C6C6C6C6C6C72727272929292929292927E3D29FF" - $"0E00B46C6C6C6C6C01936C6C6C6C6C6C72727292929292927E7E92925F000BFF" - $"FF00DE6C6C6C6C6CB5B46C6C6C6C727272729292929292DE297E9292DD020EFF" - $"FF0C0002B4726C6C6C6C7272727272727292B4DD7F929293929292920100FFFF" - $"FFFF00007F7272B4DDDD927293DDDEB49292DEDDB3929292929292DD000EFFFF" - $"FFFFAF00B4727293B47FDEB4937E7E93929292929292929292925F0009FFFFFF" - $"FFFFFF0A00B4929292929301939292929292929292929292925F0100FFFFFFFF" - $"FFFFFFFF0700B4929292927E9392929292929292929292925F01000EFFFFFFFF" - $"FFFFFFFFFF0700DD9292929292929292929292929292927E01000EFFFFFFFFFF" - $"FFFFFFFFFFFF0A003D7E9292927E7E9292929292925FDE00000EFFFFFFFFFFFF" - $"FFFFFFFFFFFFFF0D00003D7F5F5F017E92925F7EDE000300FFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFF0D00030000000001010000000C0EFFFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFFFF0E0B000A0A0A0D0EFFFFFFFFFFFFFFFFFFFFFFFF" -}; - -resource(101, "BEOS:M:STD_ICON") #'MICN' array { - $"FFFFFFFF0E0900020205000DFFFFFFFF" - $"FFFFFF09038E66666C6C93DD000EFFFF" - $"FFFF00B5AE4666666C6C666CB4050EFF" - $"FF098E464646666666401D4066B400FF" - $"0E05668E664666666C1E3F3F1D6CDDAF" - $"098E668E66666666661F3F3F1E729300" - $"006C66666666666C6C401E1E40729204" - $"026C6CB46C666C6C6C6C6C66929292DE" - $"026C6C8D6C6C6C6C6C6C72729292923D" - $"006C6C6C8D6C6C6C6C72729292927E04" - $"09946C6CB56C6C6C72729292DD935F00" - $"0E009492B49293B492B47E929292DE0D" - $"FF0A7F92937F939392929292927E00FF" - $"FFFF08DD92929292929292927E00FFFF" - $"FFFFFF0B017E93DD92927EDE09FFFFFF" - $"FFFFFFFF0E0B000500000A0EFFFFFFFF" -}; - -resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.NetSurf"; - -resource(1, "BEOS:FILE_TYPES") message { - "types" = "text/html", - "types" = "image/gif", - "types" = "image/jpeg", - "types" = "application/x-vnd.Be-bookmark", - "types" = "text", - "types" = "application/x-vnd.Be-doc_bookmark", - "types" = "application/x-vnd.Be.URL.file", - "types" = "application/x-vnd.Be.URL.ftp", - "types" = "application/x-vnd.Be.URL.http", - "types" = "application/x-vnd.Be.URL.https" -}; - -resource(R_ResizeHandle) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 13.0, 13.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 16, - "_data" = array { - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B0C1B1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"1B1B1B1B1B1B0C1B1B0D1B1B133F3F3F1B1B1B1B1B1B1B3F1B1B3F1B133F3F3F" - $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B0C1B1B0D1B1B0C1B1B133F3F3F" - $"1B1B1B1B3F1B1B3F1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" - $"131313131313131313131313133F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F" - } -}; - -resource(R_ResBackNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3B18FFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF3B35353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" - $"18FFFF3FFFFFFF3B34343535363637373737373B1418FF3FFFFF3B3434343535" - $"363637373737373B1418FF3FFF3B343434353536363637373737373B1418FF3F" - $"FF183B3535353536363637373737373B1418FF3FFFFF183B3536363636373737" - $"3737373B1418FF3FFFFFFF183B3636373B3B3B3B3B3B3B3B1418FF3FFFFFFFFF" - $"183B37373B141414141414141418FF3FFFFFFFFFFF183B373B14181818181818" - $"18FFFF3FFFFFFFFFFFFF183B3B1418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF18" - $"141418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResBackNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF0000FFFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF001800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF00181800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF001C18180000000000000000" - $"FFFFFF3FFFFFFF001C1C18181515111111111100FFFFFF3FFFFF001C1C1C1818" - $"1515111111111100FFFFFF3FFF001C1C1C1818151515111111111100FFFFFF3F" - $"FFFF0018181818151515111111111100FFFFFF3FFFFFFF001815151515111111" - $"11111100FFFFFF3FFFFFFFFF001515110000000000000000FFFFFF3FFFFFFFFF" - $"FF00111100FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF001100FFFFFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3B18FF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353B18FFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B35363B18FFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363B18FFFF" - $"FFFFFF3FFF3B34343434353535363636373B18FFFFFFFF3FFF3B343434353535" - $"3536363637373B18FFFFFF3FFF3B343435353535363636373737373B18FFFF3F" - $"FF3B3535353535363636373737373B141418FF3FFF3B35353536363636373737" - $"373B141418FFFF3FFF3B3B3B3B3B3B3B3B3737373B141418FFFFFF3FFF181414" - $"141414143B37373B141418FFFFFFFF3FFFFF1818181818183B373B141418FFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF3B3B141418FFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"18141418FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF0000FFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001800FFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF00181500FFFFFFFFFFFFFF3FFF000000000000000018151500FFFFFF" - $"FFFFFF3FFF001C1C1C1C1818181515151100FFFFFFFFFF3FFF001C1C1C181818" - $"18151515111100FFFFFFFF3FFF001C1C181818181515151111111100FFFFFF3F" - $"FF0018181818181515151111111100FFFFFFFF3FFF0018181815151515111111" - $"1100FFFFFFFFFF3FFF000000000000000011111100FFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF00111100FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001100FFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResUpNavActive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E50018FFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF00E5BDBD0018FFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD0018FFFFFF" - $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD0018FFFFFFFF3F3FFFFFFF00E5BDBDBD" - $"BDBDBDBDBD0018FFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD9898980018FFFF3F3F" - $"FF00000000E5BDBDBDBDBD980000000018FF3F3FFFFF141400E5BDBDBDBDBD98" - $"00141418FFFF3F3FFFFFFF1800E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF" - $"00E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF00E5989898989898001418FF" - $"FFFF3F3FFFFFFFFF0000000000000000001418FFFFFF3F3FFFFFFFFF18141414" - $"141414141418FFFFFFFF3F3FFFFFFFFFFF181818181818181818FFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - -resource(R_ResUpNavInactive) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF001C00FFFFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF001C171700FFFFFFFFFFFFFF3F3FFFFFFFFFFF001C1717171700FFFFFFFF" - $"FFFF3F3FFFFFFFFF001C17171717171700FFFFFFFFFF3F3FFFFFFF001C171717" - $"171717171700FFFFFFFF3F3FFFFF001C1C1C171717171712121200FFFFFF3F3F" - $"FF000000001C17171717171200000000FFFF3F3FFFFFFFFF001C171717171712" - $"00FFFFFFFFFF3F3FFFFFFFFF001C17171717171200FFFFFFFFFF3F3FFFFFFFFF" - $"001C17171717171200FFFFFFFFFF3F3FFFFFFFFF001C12121212121200FFFFFF" - $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - -resource(R_ResBackNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FF3B35353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" - $"FFFFFF3FFFFFFF3B34343535363637373737373BFFFFFF3FFFFF3B3434343535" - $"363637373737373BFFFFFF3FFF3B343434353536363637373737373BFFFFFF3F" - $"FFFF3B3535353536363637373737373BFFFFFF3FFFFFFF3B3536363636373737" - $"3737373BFFFFFF3FFFFFFFFF3B3636373B3B3B3B3B3B3B3BFFFFFF3FFFFFFFFF" - $"FF3B37373BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF3B373BFFFFFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResForwNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFF" - $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B35363BFFFFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363BFFFFFF" - $"FFFFFF3FFF3B34343434353535363636373BFFFFFFFFFF3FFF3B343434353535" - $"3536363637373BFFFFFFFF3FFF3B343435353535363636373737373BFFFFFF3F" - $"FF3B3535353535363636373737373BFFFFFFFF3FFF3B35353536363636373737" - $"373BFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3737373BFFFFFFFFFFFF3FFFFFFFFF" - $"FFFFFFFF3B37373BFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B373BFFFFFFFFFF" - $"FFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" - } -}; - -resource(R_ResUpNavActiveSel) archive(, 0x00000000) BBitmap { - "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, - "_cspace" = 4, - "_bmflags" = 1, - "_rowbytes" = 20, - "_data" = array { - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" - $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E500FFFFFFFFFFFFFFFF3F3FFFFFFFFF" - $"FFFF00E5BDBD00FFFFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD00FFFFFFFF" - $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD00FFFFFFFFFF3F3FFFFFFF00E5BDBDBD" - $"BDBDBDBDBD00FFFFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD98989800FFFFFF3F3F" - $"FF00000000E5BDBDBDBDBD9800000000FFFF3F3FFFFFFFFF00E5BDBDBDBDBD98" - $"00FFFFFFFFFF3F3FFFFFFFFF00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF" - $"00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF00E598989898989800FFFFFF" - $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" - $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" - } -}; - -resource(101, "BEOS:ICON") #'VICN' array { - $"6E6369660A02010203AE259A400198BFFA65AE20E548AF9547F2037F30A0FFFF" - $"00E8F1FDFFF131A0FFFB02000602B83B85BC57333C5733B83B8549EAE1481199" - $"00359FFFFFFFFFFF05FF05010400600500020002033D9F21B889EB3A4CEE3F48" - $"204AB4B1440D2D10339DFF51369381810DB3339DFF68020002013E7E6E26628C" - $"A83C7540569A4565A3CA24492BEEF3F70001EEF3F731017D828B95160204BFE6" - $"B413C670B413B95DB413B411BF78B411B92DB411C5C3BFE6CADDB95CCADDC66F" - $"CADDCBBCBF78CBBCC5C4CBBCB92E0204BC63B4EAC0E922B7DDB608B570BBF0B4" - $"C0B92EB61EBEB2BEDDBEE8BA56C007C363BDCBC5D0B7E2C67FBAA5C522B52002" - $"04BFDEB448C60DB448B9ADB448B4ADBF9AB4ADB955B4ADC5DABFDECAEDB9ABCA" - $"EDC60BCAEDCB0FBF9ACB0FC5DCCB0FB9570204BFDFB4D8C5BFB4D8B9FEB4D8B5" - $"3DBF9AB53DB9A5B53DC58ABFDFCA5CB9FCCA5CC5BDCA5CCA81BF9ACA81C58BCA" - $"81B9A70606BA0BBF11CB5CC71BCAFECB92C8F7CA15CAF2CCF9C666CA36C48EC4" - $"A7CA76C78DC943C2BECB40BF11CB5D0A04BB16B6B2BA9C2EB9CFB86BBA5AB65D" - $"0A04BA10BC6AB954BC62B96CBADFBA3EBAE70A04BA21BEB5BA5AC047B98DC071" - $"B93ABEF30A04BAFDC28BBB88C3E9BAD5C43EBA59C2CD0A04BD84C730BCE154BC" - $"1CC679BCAAC5F90A04BEF3C932C015CA3BBF51CAA0BE4FC9AB0A04B812C4E6B8" - $"1CC5AEB693C46DB6DEC3F70A04BA6AC535BBD4C545BBCDC617BAACC6020A04BE" - $"1EC565BF9AC51CBFB2C5E6BE5FC6340A04C1DCC4D3C348C459C381C524C244C5" - $"8D0A04C6D0C2EDC721C39FC5E5C45FC595C3AA0A04C8E6C175C9A042CA54C102" - $"C962C20E0611AAAAAAAE02C14FB955C2EAB96FC38BB7E6C47FB928C628B8C3C6" - $"04BA40C793BB18C64ABC15C6B4BDE0C50CBDCAC479BF41C372BE11C17FBE79C1" - $"FEBCB2C207BCB3C1F5BCB2C047BC1CC1A7BAEBC14EB9540205C03CC10EC030C0" - $"EFC0B9C250BFCBC606BE8FC591C21CC6E2C5DBC385C74DC4AAC5AAC35EC643BC" - $"27C7D2BF42C4B3B90CC27CB994C3B1BA28C084B8A30605EF03B6CFBA0EB779B7" - $"92B672BB6AB633BD29B598BCA2B7B3BE77BD4BBD3EC58CB654C86EB88FC42DB5" - $"45BC71B55CBF70B47FB920B65000000204CB77C91ACB76C797CB79CAACC293CB" - $"88C456CB8AC0CCCB86BAB3C975BAACCAF2BABAC7F6C286C704C0CCC704C44DC7" - $"04250A090115023FFFDCB41DBB3451734030CDBF6EE7C3CF400A000100023F88" - $"1AB4F02F34DE2C3F9E484326CF4422000A060112023CDC96413114C145263E69" - $"DE4C32CFCB0EE00A0301031A4002C300000000000040012FBD3E023BCFC439BF" - $"01178100040A0301031A4002C300000000000040012FBD3E023BCFC42F390117" - $"8200040A0301031A4002C300000000000040012FBD3E023BCFC41A2F01178200" - $"040A050105023EF4D13E9DFDBE66B43EB65E491E02C6E7CA0A0501051A3EE861" - $"3EABC8BE735C3EAAF54929C0C6EFBE1A3901178100040A050106023F4B963E44" - $"75BE44753F4B9648D9CDC72B1A0A0501061A3F4B963E4475BE44753F4B9648D9" - $"CDC72B1A1A3901178100040A0501061A3F4B963E4475BE44753F4B9648D9CDC7" - $"2B1A001901178300040A050107023F4B963E4475BE44753F4B9648D9CDC72B1A" - $"0A0501071A3F4B963E4475BE44753F4B9648D9CDC72B1A1A3901178100040A05" - $"0108023F4B963E4475BE44753F4B9648D9CDC72B1A0A0501081A3F4B963E4475" - $"BE44753F4B9648D9CDC72B1A1A3901178100040A0501081A3F4B963E4475BE44" - $"753F4B9648D9CDC72B1A001901178300040A050109023F70F53E0A00BE0A003F" - $"70F5485F8CC6CD790A0501091A3F70F53E0A00BE0A003F70F5485F8CC6CD791A" - $"3901178100040A05010A023F4B963E4475BD81043E8BD247F0BEC26F710A0501" - $"0A1A3F4B963E4475BD81043E8BD247F0BEC26F711A3901178100040A05010A1A" - $"3F4B963E4475BD81043E8BD247F0BEC26F71001901178300040A05010B023F7B" - $"673D4154BE6C8B3F3385495313C5FE290A05010B1A3F7B673D4154BE6C8B3F33" - $"85495313C5FE291A3901178100040A05010C023F70093E0B8EBE0B8E3F700948" - $"A7CCC721CF0A05010C1A3F70093E0B8EBE0B8E3F700948A7CCC721CF1A390117" - $"8100040A05010D023F70093E0B8EBE0B8E3F700948A7CCC721CF0A05010D1A3F" - $"70093E0B8EBE0B8E3F700948A7CCC721CF1A3901178100040A05010D1A3F7009" - $"3E0B8EBE0B8E3F700948A7CCC721CF001901178300040A05010E023F70093E0B" - $"8EBE0B8E3F700948A7CCC721CF0A05010E1A3F70093E0B8EBE0B8E3F700948A7" - $"CCC721CF1A3901178100040A05010F023FB1173D145ABD145A3FB117474282C6" - $"7CF80A05010F1A3FB1173D145ABD145A3FB117474282C67CF81A390117810004" - $"0A05010F1A3FB1173D145ABD145A3FB117474282C67CF8001901178300040A05" - $"0110023F68373CD78FBD05193F9ECF48132CC5E0A80A0501101A3F68373CD78F" - $"BD05193F9ECF48132CC5E0A81A3901178100040A020111000A0301031A4002C3" - $"00000000000040012FBD3E023BCFC400190117850004" -}; - -resource(101, "BEOS:D:STD_ICON") (#'iICO') $"4944585A055300"; - -resource(101, "BEOS:V:STD_ICON") #'zICO' array { - $"7A10000078DAED57DD6EDB3618BDEF5310CA4D03C40C7F3E8A6466B7C002AC37" - $"2C066CCD03B8B1EC6853A44052B3644FBFF351769C7601D68B41BB5814C03AA2" - $"8EA8C3F3FD5059BE7FB86DC47DD50F75D7AE0A2D5521AAF6BADBD4ED6E555C7D" - $"FA69110A318CEB76B36EBAB65A158FD550BC7FF76639DCEFC41FF566BC591525" - $"15E2A6AA7737E384AFBBA6EB17753B56FD5DD7ACC73C7353B7D5BAFFE5C38FC5" - $"BB3762B9C38F58DEADC71B4CFED860DE6DDD341727DB7C14B8391D9B55F131C8" - $"6085355299CB0C8D92C10BEDF3AFCE231137277C494AEAC3384569F49E3FE169" - $"9A099365E6C4772633F33C195F4EF34FE3F9B513FD28E6CFA3CAB15FB7C3B6EB" - $"6F57C5ED7AECEB87B75A928E670A7F135AE08D21B8B385B6D2913FE567CF5FF6" - $"A085CD3F60A4EF7EAF0E861CAE17D9F10B92D6C5F26990ADFDADABDB8BCFD57D" - $"D5FC9FCCEBD79B7ADD7CE053D58EA2C68A77FB0BE4F1015EB5F538AC8A2F43D5" - $"FF7AB7BEAE7E6EAF860A69FAB02AC0BA7ECCA77ECADDC3339FFEA64A49174C56" - $"B598A00ED2C4F20C0E292277CA790D49C3D8DD896EBB1DAA31CFCBD78B5C11AB" - $"E2E473D83AA4F7F90B54FD0D55A9E80FD4E5F9D70B7D3971BEF4CDDB93A7E59F" - $"BE16D15311A97C7C53445A3AEBC26B117D6717262309EB0CD287449A8518278D" - $"4F445295C260529BB0923208A36524E638811229CB64BD8C41E828A34DB69486" - $"D83A054CB2746C0EE964B5B49E39A01B5912CFA875821F1E9864C03846A0A094" - $"44CCB1D92D6F9275321856468E5FE5BCE0C980A3D450869743E551FD7FD8B7D1" - $"29BCF9BEBEFD6AF73F25E954D45FBBC68BC6B2E09449C02A5B02CD30C069C604" - $"1CA42B858619E9197D5E9921DB89CA8E90C39185DFBA942E66CC30F26D45E919" - $"7566891C6E477BBB900CCAB18DE84EC0F6492E3248A70379EE5813C494B23489" - $"1B2C9A629441735029705325CBC24088313D23CF2A1281837B68DCCA2794150A" - $"8D9C8C09D54668FFA50CC05A9A4C0958C7913EAF4C98640405CE438E64291CFA" - $"0970902AF2166493C9658F7DCB43F2913E6FC8D1080D875621FF48EA2828B71E" - $"6DB3366E64893981C7C384F7FC79757AE9598ECAD1B591B1A58CF32E1EFCBE23" - $"01E7AADAB3E78DB9934AF37B89C3CC9969789730874F0DC721577EAFF7C89E55" - $"A4CD5F3F882605DE78BCE668A2E3A09235ED2D06C7E5E847979EF1E7D589E70D" - $"37206C8A6C12FACEB4115A2E20BE5BF206E9F3D75EC8F8C09F5527BA0F3666B8" - $"A774227C5F46EEE6E8F2FC3D4A025F088025F726C8D7907FA4FF2B3297E7F8C7" - $"7F793EDCE3F417BB10DA0B" -}; - diff --git a/beos/beos_save_complete.cpp b/beos/beos_save_complete.cpp deleted file mode 100644 index 19306dc21..000000000 --- a/beos/beos_save_complete.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2009 Mark Benjamin - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -extern "C" { -#include "content/content.h" -#include "desktop/save_complete.h" -#include "utils/utils.h" -} - -/** -* conducts the filesystem save appropriate to the gui -* \param path save path -* \param filename name of file to save -* \param len data length -* \param sourcedata pointer to data to save -* \param type content type -* \return true for success -*/ - -bool save_complete_gui_save(const char *path, const char *filename, - size_t len, const char *sourcedata, lwc_string *mime_type) -{ - int res; - int namelen; - namelen = strlen(path) + strlen(filename) + 2; /* '/', '\0' */ - char *fullpath = (char *)malloc(namelen); - if (!fullpath) { - warn_user("NoMemory", 0); - return false; - } - snprintf(fullpath, namelen, "%s/%s", path, filename); - FILE *f; - f = fopen(fullpath, "wb"); - free(fullpath); - if (f == NULL) - return false; - res = fwrite(sourcedata, len, 1, f); - fclose(f); - if (res != 1) - return false; - return true; -} - -/** -* wrapper for lib function htmlSaveFileFormat; front sets path from path -* + filename in a filesystem-specific way -*/ - -int save_complete_htmlSaveFileFormat(const char *path, const char *filename, - xmlDocPtr cur, const char *encoding, int format) -{ - int ret; - int len = strlen(path) + strlen(filename) + 2; - char *fullpath = (char *)malloc(len); - if (fullpath == NULL) { - warn_user("NoMemory", 0); - return -1; - } - snprintf(fullpath, len, "%s/%s", path, filename); - ret = htmlSaveFileFormat(fullpath, cur, encoding, format); - free(fullpath); - return ret; -} - diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp deleted file mode 100644 index 0ba2004d9..000000000 --- a/beos/beos_scaffolding.cpp +++ /dev/null @@ -1,2417 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Rob Kendrick - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -extern "C" { -#include "content/content.h" -#include "desktop/browser.h" -#include "desktop/history_core.h" -#include "desktop/gui.h" -#include "desktop/netsurf.h" -#include "desktop/plotters.h" -#include "desktop/options.h" -#include "desktop/selection.h" -#include "desktop/textinput.h" -#include "render/box.h" -#include "render/font.h" -#include "render/form.h" -#include "render/html.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/utils.h" -#include "utils/log.h" -} -#include "beos/beos_gui.h" -#include "beos/beos_plotters.h" -#include "beos/beos_scaffolding.h" -#include "beos/beos_options.h" -//#include "beos/beos_completion.h" -#include "beos/beos_throbber.h" -#include "beos/beos_window.h" -//#include "beos/beos_schedule.h" -//#include "beos/beos_download.h" - -#define TOOLBAR_HEIGHT 32 -#define DRAGGER_WIDTH 8 - -struct beos_history_window; - -class NSBrowserWindow; -class NSThrobber; - -struct beos_scaffolding { - NSBrowserWindow *window; // top-level container object - - // top-level view, contains toolbar & top-level browser view - NSBaseView *top_view; - - BMenuBar *menu_bar; - - BPopUpMenu *popup_menu; - - BDragger *dragger; - - BView *tool_bar; - - BControl *back_button; - BControl *forward_button; - BControl *stop_button; - BControl *reload_button; - BControl *home_button; - - BTextControl *url_bar; - //BMenuField *url_bar_completion; - - NSThrobber *throbber; - - BStringView *status_bar; - - BScrollView *scroll_view; -#warning XXX -#if 0 /* GTK */ - GtkEntryCompletion *url_bar_completion; - GtkMenuBar *menu_bar; - GtkMenuItem *back_menu; - GtkMenuItem *forward_menu; - GtkMenuItem *stop_menu; - GtkMenuItem *reload_menu; - - GladeXML *popup_xml; - GtkMenu *popup_menu; - -#endif - struct beos_history_window *history_window; - - int throb_frame; - struct gui_window *top_level; - int being_destroyed; - - bool fullscreen; -}; - -struct beos_history_window { - struct beos_scaffolding *g; - BWindow *window; - -#warning XXX -#if 0 /* GTK */ - GtkWindow *window; - GtkScrolledWindow *scrolled; - GtkDrawingArea *drawing_area; -#endif -}; - -struct menu_events { - const char *widget; -#warning XXX -#if 0 /* GTK */ - GCallback handler; -#endif -}; - -// passed to the replicant main thread -struct replicant_thread_info { - char app[B_PATH_NAME_LENGTH]; - BString url; - char *args[3]; -}; - - -static int open_windows = 0; /**< current number of open browsers */ -static struct beos_scaffolding *current_model; /**< current window for model dialogue use */ -static NSBaseView *replicant_view = NULL; /**< if not NULL, the replicant View we are running NetSurf for */ -static sem_id replicant_done_sem = -1; - -static void nsbeos_window_update_back_forward(struct beos_scaffolding *); -static void nsbeos_throb(void *); -static int32 nsbeos_replicant_main_thread(void *_arg); - -// in beos_gui.cpp -extern int main(int argc, char** argv); - -#warning XXX -#if 0 /* GTK */ -static gboolean nsbeos_window_url_activate_event(beosWidget *, gpointer); -static gboolean nsbeos_window_url_changed(beosWidget *, GdkEventKey *, gpointer); - -static gboolean nsbeos_history_expose_event(beosWidget *, GdkEventExpose *, - gpointer); -static gboolean nsbeos_history_button_press_event(beosWidget *, GdkEventButton *, - gpointer); - -static void nsbeos_attach_menu_handlers(GladeXML *, gpointer); - -gboolean nsbeos_openfile_open(beosWidget *widget, gpointer data); - -#define MENUEVENT(x) { #x, G_CALLBACK(nsbeos_on_##x##_activate) } -#define MENUPROTO(x) static gboolean nsbeos_on_##x##_activate( \ - beosMenuItem *widget, gpointer g) -/* prototypes for menu handlers */ -/* file menu */ -MENUPROTO(new_window); -MENUPROTO(open_location); -MENUPROTO(open_file); -MENUPROTO(close_window); -MENUPROTO(quit); - -/* edit menu */ -MENUPROTO(preferences); - -/* view menu */ -MENUPROTO(stop); -MENUPROTO(reload); -MENUPROTO(zoom_in); -MENUPROTO(normal_size); -MENUPROTO(zoom_out); -MENUPROTO(full_screen); -MENUPROTO(menu_bar); -MENUPROTO(tool_bar); -MENUPROTO(status_bar); -MENUPROTO(downloads); -MENUPROTO(save_window_size); -MENUPROTO(toggle_debug_rendering); -MENUPROTO(save_box_tree); - -/* navigate menu */ -MENUPROTO(back); -MENUPROTO(forward); -MENUPROTO(home); -MENUPROTO(local_history); -MENUPROTO(global_history); - -/* help menu */ -MENUPROTO(about); - -/* structure used by nsbeos_attach_menu_handlers to connect menu items to - * their handling functions. - */ -static struct menu_events menu_events[] = { - /* file menu */ - MENUEVENT(new_window), - MENUEVENT(open_location), - MENUEVENT(open_file), - MENUEVENT(close_window), - MENUEVENT(quit), - - /* edit menu */ - MENUEVENT(preferences), - - /* view menu */ - MENUEVENT(stop), - MENUEVENT(reload), - MENUEVENT(zoom_in), - MENUEVENT(normal_size), - MENUEVENT(zoom_out), - MENUEVENT(full_screen), - MENUEVENT(menu_bar), - MENUEVENT(tool_bar), - MENUEVENT(status_bar), - MENUEVENT(downloads), - MENUEVENT(save_window_size), - MENUEVENT(toggle_debug_rendering), - MENUEVENT(save_box_tree), - - /* navigate menu */ - MENUEVENT(back), - MENUEVENT(forward), - MENUEVENT(home), - MENUEVENT(local_history), - MENUEVENT(global_history), - - /* help menu */ - MENUEVENT(about), - - /* sentinel */ - { NULL, NULL } -}; - -void nsbeos_attach_menu_handlers(GladeXML *xml, gpointer g) -{ - struct menu_events *event = menu_events; - - while (event->widget != NULL) - { - beosWidget *w = glade_xml_get_widget(xml, event->widget); - g_signal_connect(G_OBJECT(w), "activate", event->handler, g); - event++; - } -} -#endif - -// #pragma mark - class NSThrobber - -class NSThrobber : public BView { -public: - NSThrobber(BRect frame); -virtual ~NSThrobber(); - -virtual void MessageReceived(BMessage *message); -virtual void Draw(BRect updateRect); -void SetBitmap(const BBitmap *bitmap); - -private: - const BBitmap *fBitmap; -}; - -NSThrobber::NSThrobber(BRect frame) - : BView(frame, "NSThrobber", B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW), - fBitmap(NULL) -{ -} - - -NSThrobber::~NSThrobber() -{ -} - - -void -NSThrobber::MessageReceived(BMessage *message) -{ - BView::MessageReceived(message); -} - - -void -NSThrobber::Draw(BRect updateRect) -{ - if (!fBitmap) - return; - DrawBitmap(fBitmap); -} - - -void -NSThrobber::SetBitmap(const BBitmap *bitmap) -{ - fBitmap = bitmap; -} - - -// #pragma mark - class NSBaseView - - -NSBaseView::NSBaseView(BRect frame) - : BView(frame, "NetSurf", B_FOLLOW_ALL_SIDES, - 0 /*B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS*/ /*| B_SUBPIXEL_PRECISE*/), - fScaffolding(NULL) -{ -} - -NSBaseView::NSBaseView(BMessage *archive) - : BView(archive), - fScaffolding(NULL) -{ -} - - -NSBaseView::~NSBaseView() -{ - //warn_user ("~NSBaseView()", NULL); - BMessage *message = new BMessage(B_QUIT_REQUESTED); - nsbeos_pipe_message_top(message, NULL, fScaffolding); - while (acquire_sem(replicant_done_sem) == EINTR); -} - - -void -NSBaseView::MessageReceived(BMessage *message) -{ - switch (message->what) { - case B_SIMPLE_DATA: - case B_ARGV_RECEIVED: - case B_REFS_RECEIVED: - case B_COPY: - case B_CUT: - case B_PASTE: - case B_SELECT_ALL: - //case B_MOUSE_WHEEL_CHANGED: - case B_UI_SETTINGS_CHANGED: - // NetPositive messages - case B_NETPOSITIVE_OPEN_URL: - case B_NETPOSITIVE_BACK: - case B_NETPOSITIVE_FORWARD: - case B_NETPOSITIVE_HOME: - case B_NETPOSITIVE_RELOAD: - case B_NETPOSITIVE_STOP: - case B_NETPOSITIVE_DOWN: - case B_NETPOSITIVE_UP: - // messages for top-level - case 'back': - case 'forw': - case 'stop': - case 'relo': - case 'home': - case 'urlc': - case 'urle': - case 'menu': - case NO_ACTION: - case HELP_OPEN_CONTENTS: - case HELP_OPEN_GUIDE: - case HELP_OPEN_INFORMATION: - case HELP_OPEN_ABOUT: - case HELP_LAUNCH_INTERACTIVE: - case HISTORY_SHOW_LOCAL: - case HISTORY_SHOW_GLOBAL: - case HOTLIST_ADD_URL: - case HOTLIST_SHOW: - case COOKIES_SHOW: - case COOKIES_DELETE: - case BROWSER_PAGE: - case BROWSER_PAGE_INFO: - case BROWSER_PRINT: - case BROWSER_NEW_WINDOW: - case BROWSER_VIEW_SOURCE: - case BROWSER_OBJECT: - case BROWSER_OBJECT_INFO: - case BROWSER_OBJECT_RELOAD: - case BROWSER_OBJECT_SAVE: - case BROWSER_OBJECT_EXPORT_SPRITE: - case BROWSER_OBJECT_SAVE_URL_URI: - case BROWSER_OBJECT_SAVE_URL_URL: - case BROWSER_OBJECT_SAVE_URL_TEXT: - case BROWSER_SAVE: - case BROWSER_SAVE_COMPLETE: - case BROWSER_EXPORT_DRAW: - case BROWSER_EXPORT_TEXT: - case BROWSER_SAVE_URL_URI: - case BROWSER_SAVE_URL_URL: - case BROWSER_SAVE_URL_TEXT: - case HOTLIST_EXPORT: - case HISTORY_EXPORT: - case BROWSER_NAVIGATE_HOME: - case BROWSER_NAVIGATE_BACK: - case BROWSER_NAVIGATE_FORWARD: - case BROWSER_NAVIGATE_UP: - case BROWSER_NAVIGATE_RELOAD: - case BROWSER_NAVIGATE_RELOAD_ALL: - case BROWSER_NAVIGATE_STOP: - case BROWSER_NAVIGATE_URL: - case BROWSER_SCALE_VIEW: - case BROWSER_FIND_TEXT: - case BROWSER_IMAGES_FOREGROUND: - case BROWSER_IMAGES_BACKGROUND: - case BROWSER_BUFFER_ANIMS: - case BROWSER_BUFFER_ALL: - case BROWSER_SAVE_VIEW: - case BROWSER_WINDOW_DEFAULT: - case BROWSER_WINDOW_STAGGER: - case BROWSER_WINDOW_COPY: - case BROWSER_WINDOW_RESET: - case TREE_NEW_FOLDER: - case TREE_NEW_LINK: - case TREE_EXPAND_ALL: - case TREE_EXPAND_FOLDERS: - case TREE_EXPAND_LINKS: - case TREE_COLLAPSE_ALL: - case TREE_COLLAPSE_FOLDERS: - case TREE_COLLAPSE_LINKS: - case TREE_SELECTION: - case TREE_SELECTION_EDIT: - case TREE_SELECTION_LAUNCH: - case TREE_SELECTION_DELETE: - case TREE_SELECT_ALL: - case TREE_CLEAR_SELECTION: - case TOOLBAR_BUTTONS: - case TOOLBAR_ADDRESS_BAR: - case TOOLBAR_THROBBER: - case TOOLBAR_EDIT: - case CHOICES_SHOW: - case APPLICATION_QUIT: - if (Window()) - Window()->DetachCurrentMessage(); - nsbeos_pipe_message_top(message, NULL, fScaffolding); - break; - default: - message->PrintToStream(); - BView::MessageReceived(message); - } -} - - -status_t -NSBaseView::Archive(BMessage *archive, bool deep) const -{ - // force archiving only the base view - deep = false; - status_t err; - err = BView::Archive(archive, deep); - if (err < B_OK) - return err; - // add our own fields - // we try to reuse the same fields as NetPositive - archive->AddString("add_on", "application/x-vnd.NetSurf"); - //archive->AddInt32("version", 2); - archive->AddString("url", fScaffolding->url_bar->Text()); - archive->AddBool("openAsText", false); - archive->AddInt32("encoding", 258); - return err; -} - - -BArchivable * -NSBaseView::Instantiate(BMessage *archive) -{ - if (!validate_instantiation(archive, "NSBaseView")) - return NULL; - const char *url; - if (archive->FindString("url", &url) < B_OK) { - return NULL; - } - - struct replicant_thread_info *info = new replicant_thread_info; - info->url = url; - if (nsbeos_find_app_path(info->app) < B_OK) - return NULL; - info->args[0] = info->app; - info->args[1] = (char *)info->url.String(); - info->args[2] = NULL; - NSBaseView *view = new NSBaseView(archive); - replicant_view = view; - replicated = true; - - //TODO:FIXME: fix replicants - // netsurf_init() needs different args now... - //netsurf_init(2, info->args); - //return NULL; - - replicant_done_sem = create_sem(0, "NS Replicant created"); - thread_id nsMainThread = spawn_thread(nsbeos_replicant_main_thread, - "NetSurf Main Thread", B_NORMAL_PRIORITY, info); - if (nsMainThread < B_OK) { - delete_sem(replicant_done_sem); - delete info; - delete view; - return NULL; - } - resume_thread(nsMainThread); - while (acquire_sem(replicant_done_sem) == EINTR); - - return view; -} - - -void -NSBaseView::SetScaffolding(struct beos_scaffolding *scaf) -{ - fScaffolding = scaf; -} - - -// AttachedToWindow() is not enough to get the dragger and status bar -// stick to the panel color -void -NSBaseView::AllAttached() -{ - BView::AllAttached(); - struct beos_scaffolding *g = fScaffolding; - if (!g) - return; - // set targets to the topmost ns view - g->back_button->SetTarget(this); - g->forward_button->SetTarget(this); - g->stop_button->SetTarget(this); - g->reload_button->SetTarget(this); - g->home_button->SetTarget(this); - - g->url_bar->SetTarget(this); - - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - g->tool_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - g->status_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->status_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; -#if defined(__HAIKU__) || defined(B_DANO_VERSION) - g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); -#endif -} - - -// #pragma mark - class NSBrowserWindow - - -NSBrowserWindow::NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf) - : BWindow(frame, "NetSurf", B_DOCUMENT_WINDOW, 0), - fScaffolding(scaf) -{ -} - - -NSBrowserWindow::~NSBrowserWindow() -{ -} - - -void -NSBrowserWindow::DispatchMessage(BMessage *message, BHandler *handler) -{ - BMessage *msg; - switch (message->what) { - case B_UI_SETTINGS_CHANGED: - msg = new BMessage(*message); - nsbeos_pipe_message_top(msg, this, fScaffolding); - break; - } - BWindow::DispatchMessage(message, handler); -} - - -void -NSBrowserWindow::MessageReceived(BMessage *message) -{ - switch (message->what) { - case B_ARGV_RECEIVED: - case B_REFS_RECEIVED: - case B_UI_SETTINGS_CHANGED: - DetachCurrentMessage(); - nsbeos_pipe_message_top(message, this, fScaffolding); - break; - default: - BWindow::MessageReceived(message); - } -} - -bool -NSBrowserWindow::QuitRequested(void) -{ - BWindow::QuitRequested(); - BMessage *message = DetachCurrentMessage(); - // BApplication::Quit() calls us directly... - if (message == NULL) - message = new BMessage(B_QUIT_REQUESTED); - nsbeos_pipe_message_top(message, this, fScaffolding); - return false; // we will Quit() ourselves from the main thread -} - - -// #pragma mark - implementation - -int32 nsbeos_replicant_main_thread(void *_arg) -{ - struct replicant_thread_info *info = (struct replicant_thread_info *)_arg; - int32 ret; - ret = main(2, info->args); - //netsurf_main_loop(); - //netsurf_exit(); - delete info; - //release - delete_sem(replicant_done_sem); - return ret; -} - - -/* event handlers and support functions for them */ - -static void nsbeos_window_destroy_event(NSBrowserWindow *window, nsbeos_scaffolding *g, BMessage *event) -{ - LOG(("Being Destroyed = %d", g->being_destroyed)); - - if (--open_windows == 0) - netsurf_quit = true; - - if (window) { - window->Lock(); - window->Quit(); - } - - if (!g->being_destroyed) { - g->being_destroyed = 1; - nsbeos_window_destroy_browser(g->top_level); - } -} - - -void nsbeos_scaffolding_update_colors(nsbeos_scaffolding *g) -{ - if (!g->top_view->LockLooper()) - return; - rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); - g->top_view->SetViewColor(c); - - g->tool_bar->SetViewColor(c); - g->back_button->SetViewColor(c); - g->forward_button->SetViewColor(c); - g->stop_button->SetViewColor(c); - g->reload_button->SetViewColor(c); - g->home_button->SetViewColor(c); - g->url_bar->SetViewColor(c); - g->throbber->SetViewColor(c); - g->scroll_view->SetViewColor(c); - - g->dragger->SetViewColor(c); - - g->status_bar->SetViewColor(c); - g->status_bar->SetLowColor(c); -#if defined(__HAIKU__) || defined(B_DANO_VERSION) - g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); -#endif - g->top_view->UnlockLooper(); -} - - -void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *message) -{ - int width, height; - struct browser_window *bw; - bw = nsbeos_get_browser_for_gui(scaffold->top_level); - bool reloadAll = false; - - LOG(("nsbeos_scaffolding_dispatch_event() what = 0x%08lx", message->what)); - switch (message->what) { - case B_QUIT_REQUESTED: - nsbeos_scaffolding_destroy(scaffold); - break; - case B_NETPOSITIVE_DOWN: - //XXX WRITEME - break; - case B_SIMPLE_DATA: - { - if (!message->HasRef("refs")) { - // XXX handle DnD - break; - } - // FALL THROUGH - // handle refs - } - case B_REFS_RECEIVED: - { - int32 i; - entry_ref ref; - - for (i = 0; message->FindRef("refs", i, &ref) >= B_OK; i++) { - BString url("file://"); - BPath path(&ref); - if (path.InitCheck() < B_OK) - break; - - BNode node(path.Path()); - if (node.InitCheck() < B_OK) - break; - if (node.IsSymLink()) { - // dereference the symlink - BEntry entry(path.Path(), true); - if (entry.InitCheck() < B_OK) - break; - if (entry.GetPath(&path) < B_OK) - break; - if (node.SetTo(path.Path()) < B_OK) - break; - } - - attr_info ai; - if (node.GetAttrInfo("META:url", &ai) >= B_OK) { - char data[(size_t)ai.size + 1]; - memset(data, 0, (size_t)ai.size + 1); - if (node.ReadAttr("META:url", B_STRING_TYPE, 0LL, data, (size_t)ai.size) < 4) - break; - url = data; - } else - url << path.Path(); - - if (/*message->WasDropped() &&*/ i == 0) - browser_window_go(bw, url.String(), 0, true); - else - browser_window_create(url.String(), bw, NULL, false, false); - } - break; - } - case B_ARGV_RECEIVED: - { - int32 i; - BString url; - for (i = 1; message->FindString("argv", i, &url) >= B_OK; i++) { - browser_window_create(url.String(), bw, NULL, false, false); - } - break; - } - case B_UI_SETTINGS_CHANGED: - nsbeos_update_system_ui_colors(); - nsbeos_scaffolding_update_colors(scaffold); - break; - case B_NETPOSITIVE_OPEN_URL: - { - int32 i; - BString url; - if (message->FindString("be:url", &url) < B_OK) - break; - browser_window_go(bw, url.String(), 0, true); - break; - } - case B_COPY: - gui_copy_to_clipboard(browser_window_get_selection(bw)); - break; - case B_CUT: - browser_window_key_press(bw, 24); - break; - case B_PASTE: - gui_paste_from_clipboard(scaffold->top_level, 0, 0); - break; - case B_SELECT_ALL: - LOG(("Selecting all text")); - selection_select_all(browser_window_get_selection(bw)); - break; - case B_NETPOSITIVE_BACK: - case BROWSER_NAVIGATE_BACK: - case 'back': - if (!history_back_available(bw->history)) - break; - history_back(bw, bw->history); - nsbeos_window_update_back_forward(scaffold); - break; - case B_NETPOSITIVE_FORWARD: - case BROWSER_NAVIGATE_FORWARD: - case 'forw': - if (!history_forward_available(bw->history)) - break; - history_forward(bw, bw->history); - nsbeos_window_update_back_forward(scaffold); - break; - case B_NETPOSITIVE_STOP: - case BROWSER_NAVIGATE_STOP: - case 'stop': - browser_window_stop(bw); - break; - case B_NETPOSITIVE_RELOAD: - case BROWSER_NAVIGATE_RELOAD_ALL: - case 'relo': - reloadAll = true; - // FALLTHRU - case BROWSER_NAVIGATE_RELOAD: - browser_window_reload(bw, reloadAll); - break; - case B_NETPOSITIVE_HOME: - case BROWSER_NAVIGATE_HOME: - case 'home': - { - static const char *addr = NETSURF_HOMEPAGE; - - if (nsoption_charp(homepage_url) != NULL) - addr = nsoption_charp(homepage_url); - - browser_window_go(bw, addr, 0, true); - break; - } - case 'urle': - { - BString text; - if (!scaffold->url_bar->LockLooper()) - break; - text = scaffold->url_bar->Text(); - scaffold->scroll_view->Target()->MakeFocus(); - scaffold->url_bar->UnlockLooper(); - browser_window_go(bw, text.String(), 0, true); - break; - } - case 'urlc': - { - BString text; - if (!scaffold->url_bar->LockLooper()) - break; - text = scaffold->url_bar->Text(); - scaffold->url_bar->UnlockLooper(); - //nsbeos_completion_update(text.String()); - break; - } -/* - case 'menu': - { - menu_action action; - if (message->FindInt32("action", (int32 *)&action) < B_OK) - break; - switch (action) { - case NO_ACTION: - case HELP_OPEN_CONTENTS: - case HELP_OPEN_GUIDE: - case HELP_OPEN_INFORMATION: - case HELP_OPEN_ABOUT: - case HELP_LAUNCH_INTERACTIVE: - - break; - } -#warning XXX - break; - } -*/ - case NO_ACTION: - break; - case HELP_OPEN_CONTENTS: - break; - case HELP_OPEN_GUIDE: - break; - case HELP_OPEN_INFORMATION: - break; - case HELP_OPEN_ABOUT: - break; - case HELP_LAUNCH_INTERACTIVE: - break; - case HISTORY_SHOW_LOCAL: - break; - case HISTORY_SHOW_GLOBAL: - break; - case HOTLIST_ADD_URL: - break; - case HOTLIST_SHOW: - break; - case COOKIES_SHOW: - break; - case COOKIES_DELETE: - break; - case BROWSER_PAGE: - break; - case BROWSER_PAGE_INFO: - break; - case BROWSER_PRINT: - break; - case BROWSER_NEW_WINDOW: - { - BString text; - if (!scaffold->url_bar->LockLooper()) - break; - text = scaffold->url_bar->Text(); - scaffold->url_bar->UnlockLooper(); - - browser_window_create(text.String(), bw, NULL, false, false); - break; - } - case BROWSER_VIEW_SOURCE: - { - if (!bw || !bw->current_content) - break; - nsbeos_gui_view_source(bw->current_content, - browser_window_get_selection(bw)); - break; - } - case BROWSER_OBJECT: - break; - case BROWSER_OBJECT_INFO: - break; - case BROWSER_OBJECT_RELOAD: - break; - case BROWSER_OBJECT_SAVE: - break; - case BROWSER_OBJECT_EXPORT_SPRITE: - break; - case BROWSER_OBJECT_SAVE_URL_URI: - break; - case BROWSER_OBJECT_SAVE_URL_URL: - break; - case BROWSER_OBJECT_SAVE_URL_TEXT: - break; - case BROWSER_SAVE: - break; - case BROWSER_SAVE_COMPLETE: - break; - case BROWSER_EXPORT_DRAW: - break; - case BROWSER_EXPORT_TEXT: - break; - case BROWSER_SAVE_URL_URI: - break; - case BROWSER_SAVE_URL_URL: - break; - case BROWSER_SAVE_URL_TEXT: - break; - case HOTLIST_EXPORT: - break; - case HISTORY_EXPORT: - break; - case B_NETPOSITIVE_UP: - case BROWSER_NAVIGATE_UP: - break; - case BROWSER_NAVIGATE_URL: - if (!scaffold->url_bar->LockLooper()) - break; - scaffold->url_bar->MakeFocus(); - scaffold->url_bar->UnlockLooper(); - break; - case BROWSER_SCALE_VIEW: - break; - case BROWSER_FIND_TEXT: - break; - case BROWSER_IMAGES_FOREGROUND: - break; - case BROWSER_IMAGES_BACKGROUND: - break; - case BROWSER_BUFFER_ANIMS: - break; - case BROWSER_BUFFER_ALL: - break; - case BROWSER_SAVE_VIEW: - break; - case BROWSER_WINDOW_DEFAULT: - break; - case BROWSER_WINDOW_STAGGER: - break; - case BROWSER_WINDOW_COPY: - break; - case BROWSER_WINDOW_RESET: - break; - case TREE_NEW_FOLDER: - case TREE_NEW_LINK: - case TREE_EXPAND_ALL: - case TREE_EXPAND_FOLDERS: - case TREE_EXPAND_LINKS: - case TREE_COLLAPSE_ALL: - case TREE_COLLAPSE_FOLDERS: - case TREE_COLLAPSE_LINKS: - case TREE_SELECTION: - case TREE_SELECTION_EDIT: - case TREE_SELECTION_LAUNCH: - case TREE_SELECTION_DELETE: - case TREE_SELECT_ALL: - case TREE_CLEAR_SELECTION: - break; - case TOOLBAR_BUTTONS: - break; - case TOOLBAR_ADDRESS_BAR: - break; - case TOOLBAR_THROBBER: - break; - case TOOLBAR_EDIT: - break; - case CHOICES_SHOW: - break; - case APPLICATION_QUIT: - netsurf_quit = true; - break; - default: - break; - } -} - -void nsbeos_scaffolding_destroy(nsbeos_scaffolding *scaffold) -{ - LOG(("Being Destroyed = %d", scaffold->being_destroyed)); - if (scaffold->being_destroyed) return; - scaffold->being_destroyed = 1; - nsbeos_window_destroy_event(scaffold->window, scaffold, NULL); -} - - -void nsbeos_window_update_back_forward(struct beos_scaffolding *g) -{ - int width, height; - struct browser_window *bw = nsbeos_get_browser_for_gui(g->top_level); - - if (!g->top_view->LockLooper()) - return; - - g->back_button->SetEnabled(history_back_available(bw->history)); - g->forward_button->SetEnabled(history_forward_available(bw->history)); - - g->top_view->UnlockLooper(); - -#warning XXX -#if 0 /* GTK */ - beos_widget_set_sensitive(beos_WIDGET(g->back_button), - history_back_available(bw->history)); - beos_widget_set_sensitive(beos_WIDGET(g->forward_button), - history_forward_available(bw->history)); - - beos_widget_set_sensitive(beos_WIDGET(g->back_menu), - history_back_available(bw->history)); - beos_widget_set_sensitive(beos_WIDGET(g->forward_menu), - history_forward_available(bw->history)); - - /* update the local history window, as well as queuing a redraw - * for it. - */ - history_size(bw->history, &width, &height); - beos_widget_set_size_request(beos_WIDGET(g->history_window->drawing_area), - width, height); - beos_widget_queue_draw(beos_WIDGET(g->history_window->drawing_area)); -#endif -} - -void nsbeos_throb(void *p) -{ - struct beos_scaffolding *g = (struct beos_scaffolding *)p; - - if (g->throb_frame >= (nsbeos_throbber->nframes - 1)) - g->throb_frame = 1; - else - g->throb_frame++; - - if (!g->top_view->LockLooper()) - return; - -#if 0 - g->throbber->SetViewBitmap(nsbeos_throbber->framedata[g->throb_frame], - B_FOLLOW_RIGHT | B_FOLLOW_TOP); -#endif - g->throbber->SetBitmap(nsbeos_throbber->framedata[g->throb_frame]); - g->throbber->Invalidate(); - - g->top_view->UnlockLooper(); - - schedule(10, nsbeos_throb, p); - -} - -#warning XXX -#if 0 /* GTK */ - -gboolean nsbeos_openfile_open(beosWidget *widget, gpointer data) -{ - struct browser_window *bw = nsbeos_get_browser_for_gui( - current_model->top_level); - char *filename = beos_file_chooser_get_filename( - beos_FILE_CHOOSER(wndOpenFile)); - char *url = malloc(strlen(filename) + sizeof("file://")); - - sprintf(url, "file://%s", filename); - - browser_window_go(bw, url, 0, true); - - g_free(filename); - free(url); - - return TRUE; -} -#endif - -#warning XXX -#if 0 /* GTK */ -/* signal handlers for menu entries */ -#define MENUHANDLER(x) gboolean nsbeos_on_##x##_activate(beosMenuItem *widget, \ - gpointer g) - -MENUHANDLER(new_window) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); - const char *url = beos_entry_get_text(beos_ENTRY(gw->url_bar)); - - browser_window_create(url, bw, NULL, false); - - return TRUE; -} - -MENUHANDLER(open_location) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - beos_widget_grab_focus(beos_WIDGET(gw->url_bar)); - - return TRUE; -} - -MENUHANDLER(open_file) -{ - current_model = (struct beos_scaffolding *)g; - beos_dialog_run(wndOpenFile); - - return TRUE; -} - -MENUHANDLER(close_window) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - beos_widget_destroy(beos_WIDGET(gw->window)); - - return TRUE; -} - -MENUHANDLER(quit) -{ - netsurf_quit = true; - return TRUE; -} - -MENUHANDLER(preferences) -{ - beos_widget_show(beos_WIDGET(wndPreferences)); - - return TRUE; -} - -MENUHANDLER(zoom_in) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); - float old_scale = nsbeos_get_scale_for_gui(gw->top_level); - - browser_window_set_scale(bw, old_scale + 0.05, true); - - return TRUE; -} - -MENUHANDLER(normal_size) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); - - browser_window_set_scale(bw, 1.0, true); - - return TRUE; -} - -MENUHANDLER(zoom_out) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); - float old_scale = nsbeos_get_scale_for_gui(gw->top_level); - - browser_window_set_scale(bw, old_scale - 0.05, true); - - return TRUE; -} - -MENUHANDLER(full_screen) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - if (gw->fullscreen) { - beos_window_unfullscreen(gw->window); - } else { - beos_window_fullscreen(gw->window); - } - - gw->fullscreen = !gw->fullscreen; - - return TRUE; -} - -MENUHANDLER(menu_bar) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { - beos_widget_show(beos_WIDGET(gw->menu_bar)); - } else { - beos_widget_hide(beos_WIDGET(gw->menu_bar)); - } - - return TRUE; -} - -MENUHANDLER(tool_bar) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { - beos_widget_show(beos_WIDGET(gw->tool_bar)); - } else { - beos_widget_hide(beos_WIDGET(gw->tool_bar)); - } - - return TRUE; -} - -MENUHANDLER(status_bar) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { - beos_widget_show(beos_WIDGET(gw->status_bar)); - } else { - beos_widget_hide(beos_WIDGET(gw->status_bar)); - } - - return TRUE; -} - -MENUHANDLER(downloads) -{ - nsbeos_download_show(); - - return TRUE; -} - -MENUHANDLER(save_window_size) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - int x,y,w,h; - - nsoption_set_int(toolbar_status_width, - beos_paned_get_position(gw->status_pane)); - beos_window_get_position(gw->window, &x, &y); - beos_window_get_size(gw->window, &w, &h); - - nsoption_set_int(window_x, x); - nsoption_set_int(window_y, y); - nsoption_set_int(window_width, w); - nsoption_set_int(window_height, h); - - nsoption_write(options_file_location); - - return TRUE; -} - -MENUHANDLER(toggle_debug_rendering) -{ - html_redraw_debug = !html_redraw_debug; - nsbeos_reflow_all_windows(); - return TRUE; -} - -MENUHANDLER(save_box_tree) -{ - beosWidget *save_dialog; - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - save_dialog = beos_file_chooser_dialog_new("Save File", gw->window, - beos_FILE_CHOOSER_ACTION_SAVE, - beos_STOCK_CANCEL, beos_RESPONSE_CANCEL, - beos_STOCK_SAVE, beos_RESPONSE_ACCEPT, - NULL); - - beos_file_chooser_set_current_folder(beos_FILE_CHOOSER(save_dialog), - getenv("HOME") ? getenv("HOME") : "/"); - - beos_file_chooser_set_current_name(beos_FILE_CHOOSER(save_dialog), - "boxtree.txt"); - - if (beos_dialog_run(beos_DIALOG(save_dialog)) == beos_RESPONSE_ACCEPT) { - char *filename = beos_file_chooser_get_filename( - beos_FILE_CHOOSER(save_dialog)); - FILE *fh; - LOG(("Saving box tree dump to %s...\n", filename)); - - fh = fopen(filename, "w"); - if (fh == NULL) { - warn_user("Error saving box tree dump.", - "Unable to open file for writing."); - } else { - struct browser_window *bw; - bw = nsbeos_get_browser_window(gw->top_level); - - if (bw->current_content && - bw->current_content->type == - CONTENT_HTML) { - box_dump(fh, - bw->current_content->data.html.layout, - 0); - } - - fclose(fh); - } - - g_free(filename); - } - - beos_widget_destroy(save_dialog); -} - -MENUHANDLER(stop) -{ - return nsbeos_window_stop_button_clicked(beos_WIDGET(widget), g); -} - -MENUHANDLER(reload) -{ - return nsbeos_window_reload_button_clicked(beos_WIDGET(widget), g); -} - -MENUHANDLER(back) -{ - return nsbeos_window_back_button_clicked(beos_WIDGET(widget), g); -} - -MENUHANDLER(forward) -{ - return nsbeos_window_forward_button_clicked(beos_WIDGET(widget), g); -} - -MENUHANDLER(home) -{ - return nsbeos_window_home_button_clicked(beos_WIDGET(widget), g); -} - -MENUHANDLER(local_history) -{ - struct beos_scaffolding *gw = (struct beos_scaffolding *)g; - - beos_widget_show(beos_WIDGET(gw->history_window->window)); - gdk_window_raise(beos_WIDGET(gw->history_window->window)->window); - - return TRUE; -} - -MENUHANDLER(global_history) -{ - beos_widget_show(beos_WIDGET(wndHistory)); - gdk_window_raise(beos_WIDGET(wndHistory)->window); - - return TRUE; -} - -MENUHANDLER(about) -{ - beos_widget_show(beos_WIDGET(wndAbout)); - gdk_window_raise(beos_WIDGET(wndAbout)->window); - return TRUE; -} - -/* signal handler functions for the local history window */ -gboolean nsbeos_history_expose_event(beosWidget *widget, - GdkEventExpose *event, gpointer g) -{ - struct beos_history_window *hw = (struct beos_history_window *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(hw->g->top_level); - - struct redraw_context ctx = { - .interactive = true, - .background_images = true, - .plot = &nsbeos_plotters - }; - - 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 = nsbeos_plotters; - - history_redraw(bw->history, &ctx); - - g_object_unref(current_gc); -#ifdef CAIRO_VERSION - cairo_destroy(current_cr); -#endif - return FALSE; -} - -gboolean nsbeos_history_button_press_event(beosWidget *widget, - GdkEventButton *event, gpointer g) -{ - struct beos_history_window *hw = (struct beos_history_window *)g; - struct browser_window *bw = nsbeos_get_browser_for_gui(hw->g->top_level); - - LOG(("X=%g, Y=%g", event->x, event->y)); - - history_click(bw, bw->history, - event->x, event->y, false); - - return TRUE; -} - -#define GET_WIDGET(x) glade_xml_get_widget(g->xml, (x)) - -static gboolean do_scroll_event(beosWidget *widget, GdkEvent *ev, - gpointer data) -{ - switch (((GdkEventScroll *)ev)->direction) - { - case GDK_SCROLL_UP: - case GDK_SCROLL_DOWN: - beos_widget_event(g_object_get_data( - G_OBJECT(widget), "vScroll"), ev); - break; - default: - beos_widget_event(g_object_get_data( - G_OBJECT(widget), "hScroll"), ev); - } - - return TRUE; -} -#endif - -NSBrowserWindow *nsbeos_find_last_window(void) -{ - int32 i; - if (!be_app || !be_app->Lock()) - return NULL; - for (i = be_app->CountWindows() - 1; i >= 0; i--) { - if (be_app->WindowAt(i) == NULL) - continue; - NSBrowserWindow *win; - win = dynamic_cast(be_app->WindowAt(i)); - if (win) { - win->Lock(); - be_app->Unlock(); - return win; - } - } - be_app->Unlock(); - return NULL; -} - -NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold) -{ - return scaffold->window; -} - -static void recursively_set_menu_items_target(BMenu *menu, BHandler *handler) -{ - menu->SetTargetForItems(handler); - for (int i = 0; menu->ItemAt(i); i++) { - if (!menu->SubmenuAt(i)) - continue; - recursively_set_menu_items_target(menu->SubmenuAt(i), handler); - } -} - -void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view) -{ - LOG(("Attaching view to scaffolding %p", g)); - - // this is a replicant,... and it went bad - if (!g->window) { - if (g->top_view->Looper() && !g->top_view->LockLooper()) - return; - } - - BRect rect(g->top_view->Bounds()); - rect.top += TOOLBAR_HEIGHT; - rect.right -= B_V_SCROLL_BAR_WIDTH; - rect.bottom -= B_H_SCROLL_BAR_HEIGHT; - - view->ResizeTo(rect.Width() /*+ 1*/, rect.Height() /*+ 1*/); - view->MoveTo(rect.LeftTop()); - - - g->scroll_view = new BScrollView("NetSurfScrollView", view, - B_FOLLOW_ALL, 0, true, true, B_NO_BORDER); - - g->top_view->AddChild(g->scroll_view); - - view->MakeFocus(); - - // resize the horiz scrollbar to make room for the status bar and add it. - - BScrollBar *sb = g->scroll_view->ScrollBar(B_HORIZONTAL); - rect = sb->Frame(); - float divider = rect.Width() + 1; - //divider /= 2; - divider *= 67.0/100; // 67% - - sb->ResizeBy(-divider, 0); - sb->MoveBy(divider, 0); - - rect.right = rect.left + divider - 1; - - /* - BBox *statusBarBox = new BBox(rect, "StatusBarBox", - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, - B_WILL_DRAW | B_FRAME_EVENTS, - B_RAISED_BORDER); - */ - - g->status_bar->MoveTo(rect.LeftTop()); - g->status_bar->ResizeTo(rect.Width() + 1, rect.Height() + 1); - g->scroll_view->AddChild(g->status_bar); - g->status_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->status_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; -#if defined(__HAIKU__) || defined(B_DANO_VERSION) - g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); -#endif - - - - // set targets to the topmost ns view, - // we might not have a window later (replicant ?) - // this won't work for replicants, since the base view isn't attached yet - // we'll redo this in NSBaseView::AllAttached - g->back_button->SetTarget(view); - g->forward_button->SetTarget(view); - g->stop_button->SetTarget(view); - g->reload_button->SetTarget(view); - g->home_button->SetTarget(view); - - g->url_bar->SetTarget(view); - - if (g->window) { - recursively_set_menu_items_target(g->menu_bar, view); - - // add toolbar shortcuts - BMessage *message; - - message = new BMessage('back'); - message->AddPointer("scaffolding", g); - g->window->AddShortcut(B_LEFT_ARROW, 0, message, view); - - message = new BMessage('forw'); - message->AddPointer("scaffolding", g); - g->window->AddShortcut(B_RIGHT_ARROW, 0, message, view); - - message = new BMessage('stop'); - message->AddPointer("scaffolding", g); - g->window->AddShortcut('S', 0, message, view); - - message = new BMessage('relo'); - message->AddPointer("scaffolding", g); - g->window->AddShortcut('R', 0, message, view); - - message = new BMessage('home'); - message->AddPointer("scaffolding", g); - g->window->AddShortcut('H', 0, message, view); - - g->window->Show(); - } else { - if (g->top_view->Looper()) - g->top_view->UnlockLooper(); - } - - -#warning XXX -#if 0 /* GTK */ - beosWidget *scrollbar; - - /* Insert the viewport into the right part of our table */ - beosTable *table = beos_TABLE(GET_WIDGET("centreTable")); - LOG(("Attaching viewport to scaffolding %p", g)); - beos_table_attach_defaults(table, beos_WIDGET(vp), 0, 1, 0, 1); - - /* connect our scrollbars to the viewport */ - scrollbar = GET_WIDGET("coreScrollHorizontal"); - beos_viewport_set_hadjustment(vp, - beos_range_get_adjustment(beos_RANGE(scrollbar))); - g_object_set_data(G_OBJECT(vp), "hScroll", scrollbar); - scrollbar = GET_WIDGET("coreScrollVertical"); - beos_viewport_set_vadjustment(vp, - beos_range_get_adjustment(beos_RANGE(scrollbar))); - g_object_set_data(G_OBJECT(vp), "vScroll", scrollbar); - g_signal_connect(G_OBJECT(vp), "scroll_event", - G_CALLBACK(do_scroll_event), NULL); - - gdk_window_set_accept_focus (beos_WIDGET(vp)->window, TRUE); - - /* And set the size-request to zero to cause it to get its act together */ - beos_widget_set_size_request(beos_WIDGET(vp), 0, 0); - -#endif -} - -static BMenuItem *make_menu_item(const char *name, BMessage *message) -{ - BMenuItem *item; - BString label(messages_get(name)); - BString accel; - uint32 mods = 0; - char key = 0; - // try to understand accelerators - int32 start = label.IFindLast(" "); - if (start > 0 && (label.Length() - start > 1) - && (label.Length() - start < 7) - && (label[start + 1] == 'F' - || !strcmp(label.String() + start + 1, "PRINT") - || label[start + 1] == '\xe2' - || label[start + 1] == '^')) { - - label.MoveInto(accel, start + 1, label.Length()); - // strip the trailing spaces - while (label[label.Length() - 1] == ' ') - label.Truncate(label.Length() - 1); - - if (accel.FindFirst("\xe2\x87\x91") > -1) { - accel.RemoveFirst("\xe2\x87\x91"); - mods |= B_SHIFT_KEY; - } - if (accel.FindFirst("^") > -1) { - accel.RemoveFirst("^"); - mods |= B_CONTROL_KEY; // ALT!!! - } - if (accel.FindFirst("PRINT") > -1) { - accel.RemoveFirst("PRINT"); - //mods |= ; // ALT!!! - key = B_PRINT_KEY; - } - if (accel.Length() > 1 && accel[0] == 'F') { // Function key - int num; - if (sscanf(accel.String(), "F%d", &num) > 0) { - // - } - } else if (accel.Length() > 0) { - key = accel[0]; - } - //printf("MENU: detected accel '%s' mods 0x%08lx, key %d\n", accel.String(), mods, key); - } - - // turn ... into ellipsis - label.ReplaceAll("...", B_UTF8_ELLIPSIS); - - item = new BMenuItem(label.String(), message, key, mods); - - return item; -} - -nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel) -{ - struct beos_scaffolding *g = (struct beos_scaffolding *)malloc(sizeof(*g)); - - LOG(("Constructing a scaffold of %p for gui_window %p", g, toplevel)); - - g->top_level = toplevel; - g->being_destroyed = 0; - g->fullscreen = false; - - open_windows++; - - BMessage *message; - BRect rect; - - g->window = NULL; - g->menu_bar = NULL; - g->window = NULL; - - if (replicated && !replicant_view) { - warn_user("Error: No subwindow allowed when replicated.", NULL); - return NULL; - } - - - if (!replicant_view) { - - BRect frame(0, 0, 600-1, 500-1); - if (nsoption_int(window_width) > 0) { - frame.Set(0, 0, nsoption_int(window_width) - 1, nsoption_int(window_height) - 1); - frame.OffsetToSelf(nsoption_int(window_x), nsoption_int(window_y)); - } else { - BPoint pos(50, 50); - // XXX: use last BApplication::WindowAt()'s dynamic_cast Frame() - NSBrowserWindow *win = nsbeos_find_last_window(); - if (win) { - pos = win->Frame().LeftTop(); - win->Unlock(); - } - pos += BPoint(20, 20); - BScreen screen; - BRect screenFrame(screen.Frame()); - if (pos.y + frame.Height() >= screenFrame.Height()) { - pos.y = 50; - pos.x += 50; - } - if (pos.x + frame.Width() >= screenFrame.Width()) { - pos.x = 50; - pos.y = 50; - } - frame.OffsetToSelf(pos); - } - - g->window = new NSBrowserWindow(frame, g); - - rect = frame.OffsetToCopy(0,0); - rect.bottom = rect.top + 20; - - // build menus - g->menu_bar = new BMenuBar(rect, "menu_bar"); - g->window->AddChild(g->menu_bar); - - BMenu *menu; - BMenu *submenu; - BMenuItem *item; - - // App menu - //XXX: use icon item ? - - menu = new BMenu(messages_get("NetSurf")); - g->menu_bar->AddItem(menu); - - message = new BMessage(NO_ACTION); - item = make_menu_item("Info", message); - menu->AddItem(item); - - message = new BMessage(NO_ACTION); - item = make_menu_item("AppHelp", message); - menu->AddItem(item); - - submenu = new BMenu(messages_get("Open")); - menu->AddItem(submenu); - - message = new BMessage(NO_ACTION); - item = make_menu_item("OpenURL", message); - submenu->AddItem(item); - - message = new BMessage(CHOICES_SHOW); - item = make_menu_item("Choices", message); - menu->AddItem(item); - - message = new BMessage(APPLICATION_QUIT); - item = make_menu_item("Quit", message); - menu->AddItem(item); - - // Page menu - - menu = new BMenu(messages_get("Page")); - g->menu_bar->AddItem(menu); - - message = new BMessage(BROWSER_PAGE_INFO); - item = make_menu_item("PageInfo", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_SAVE); - item = make_menu_item("Save", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_SAVE_COMPLETE); - item = make_menu_item("SaveComp", message); - menu->AddItem(item); - - submenu = new BMenu(messages_get("Export")); - menu->AddItem(submenu); - - /* - message = new BMessage(BROWSER_EXPORT_DRAW); - item = make_menu_item("Draw", message); - submenu->AddItem(item); - */ - - message = new BMessage(BROWSER_EXPORT_TEXT); - item = make_menu_item("Text", message); - submenu->AddItem(item); - - - submenu = new BMenu(messages_get("SaveURL")); - menu->AddItem(submenu); - - //XXX - message = new BMessage(BROWSER_OBJECT_SAVE_URL_URL); - item = make_menu_item("URL", message); - submenu->AddItem(item); - - - message = new BMessage(BROWSER_PRINT); - item = make_menu_item("Print", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NEW_WINDOW); - item = make_menu_item("NewWindow", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_VIEW_SOURCE); - item = make_menu_item("ViewSrc", message); - menu->AddItem(item); - - // Object menu - - menu = new BMenu(messages_get("Object")); - g->menu_bar->AddItem(menu); - - message = new BMessage(BROWSER_OBJECT_INFO); - item = make_menu_item("ObjInfo", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_OBJECT_SAVE); - item = make_menu_item("ObjSave", message); - menu->AddItem(item); - // XXX: submenu: Sprite ? - - message = new BMessage(BROWSER_OBJECT_RELOAD); - item = make_menu_item("ObjReload", message); - menu->AddItem(item); - - // Navigate menu - - menu = new BMenu(messages_get("Navigate")); - g->menu_bar->AddItem(menu); - - message = new BMessage(BROWSER_NAVIGATE_HOME); - item = make_menu_item("Home", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NAVIGATE_BACK); - item = make_menu_item("Back", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NAVIGATE_FORWARD); - item = make_menu_item("Forward", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NAVIGATE_UP); - item = make_menu_item("UpLevel", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NAVIGATE_RELOAD); - item = make_menu_item("Reload", message); - menu->AddItem(item); - - message = new BMessage(BROWSER_NAVIGATE_STOP); - item = make_menu_item("Stop", message); - menu->AddItem(item); - - // View menu - - menu = new BMenu(messages_get("View")); - g->menu_bar->AddItem(menu); - - message = new BMessage(BROWSER_SCALE_VIEW); - item = make_menu_item("ScaleView", message); - menu->AddItem(item); - - submenu = new BMenu(messages_get("Images")); - menu->AddItem(submenu); - - message = new BMessage(BROWSER_IMAGES_FOREGROUND); - item = make_menu_item("ForeImg", message); - submenu->AddItem(item); - - message = new BMessage(BROWSER_IMAGES_BACKGROUND); - item = make_menu_item("BackImg", message); - submenu->AddItem(item); - - - submenu = new BMenu(messages_get("Toolbars")); - menu->AddItem(submenu); - submenu->SetEnabled(false); - - message = new BMessage(NO_ACTION); - item = make_menu_item("ToolButtons", message); - submenu->AddItem(item); - - message = new BMessage(NO_ACTION); - item = make_menu_item("ToolAddress", message); - submenu->AddItem(item); - - message = new BMessage(NO_ACTION); - item = make_menu_item("ToolThrob", message); - submenu->AddItem(item); - - message = new BMessage(NO_ACTION); - item = make_menu_item("ToolStatus", message); - submenu->AddItem(item); - - - submenu = new BMenu(messages_get("Render")); - menu->AddItem(submenu); - - message = new BMessage(BROWSER_BUFFER_ANIMS); - item = make_menu_item("RenderAnims", message); - submenu->AddItem(item); - - message = new BMessage(BROWSER_BUFFER_ALL); - item = make_menu_item("RenderAll", message); - submenu->AddItem(item); - - - message = new BMessage(NO_ACTION); - item = make_menu_item("OptDefault", message); - menu->AddItem(item); - - // Utilities menu - - menu = new BMenu(messages_get("Utilities")); - g->menu_bar->AddItem(menu); - - submenu = new BMenu(messages_get("Hotlist")); - menu->AddItem(submenu); - - message = new BMessage(HOTLIST_ADD_URL); - item = make_menu_item("HotlistAdd", message); - submenu->AddItem(item); - - message = new BMessage(HOTLIST_SHOW); - item = make_menu_item("HotlistShow", message); - submenu->AddItem(item); - - - submenu = new BMenu(messages_get("History")); - menu->AddItem(submenu); - - message = new BMessage(HISTORY_SHOW_LOCAL); - item = make_menu_item("HistLocal", message); - submenu->AddItem(item); - - message = new BMessage(HISTORY_SHOW_GLOBAL); - item = make_menu_item("HistGlobal", message); - submenu->AddItem(item); - - - submenu = new BMenu(messages_get("Cookies")); - menu->AddItem(submenu); - - message = new BMessage(COOKIES_SHOW); - item = make_menu_item("ShowCookies", message); - submenu->AddItem(item); - - message = new BMessage(COOKIES_DELETE); - item = make_menu_item("DeleteCookies", message); - submenu->AddItem(item); - - - message = new BMessage(BROWSER_FIND_TEXT); - item = make_menu_item("FindText", message); - menu->AddItem(item); - - submenu = new BMenu(messages_get("Window")); - menu->AddItem(submenu); - - message = new BMessage(BROWSER_WINDOW_DEFAULT); - item = make_menu_item("WindowSave", message); - submenu->AddItem(item); - - message = new BMessage(BROWSER_WINDOW_STAGGER); - item = make_menu_item("WindowStagr", message); - submenu->AddItem(item); - - message = new BMessage(BROWSER_WINDOW_COPY); - item = make_menu_item("WindowSize", message); - submenu->AddItem(item); - - message = new BMessage(BROWSER_WINDOW_RESET); - item = make_menu_item("WindowReset", message); - submenu->AddItem(item); - - - // Help menu - - menu = new BMenu(messages_get("Help")); - g->menu_bar->AddItem(menu); - - message = new BMessage(HELP_OPEN_CONTENTS); - item = make_menu_item("HelpContent", message); - menu->AddItem(item); - - message = new BMessage(HELP_OPEN_GUIDE); - item = make_menu_item("HelpGuide", message); - menu->AddItem(item); - - message = new BMessage(HELP_OPEN_INFORMATION); - item = make_menu_item("HelpInfo", message); - menu->AddItem(item); - - message = new BMessage(HELP_OPEN_ABOUT); - item = make_menu_item("HelpAbout", message); - menu->AddItem(item); - - message = new BMessage(HELP_LAUNCH_INTERACTIVE); - item = make_menu_item("HelpInter", message); - menu->AddItem(item); - - // the base view that receives the toolbar, statusbar and top-level view. - rect = frame.OffsetToCopy(0,0); - rect.top = g->menu_bar->Bounds().Height() + 1; - //rect.top = 20 + 1; // XXX - //rect.bottom -= B_H_SCROLL_BAR_HEIGHT; - g->top_view = new NSBaseView(rect); - // add the top view to the window - g->window->AddChild(g->top_view); - } else { // replicant_view - // the base view has already been created with the archive constructor - g->top_view = replicant_view; - } - g->top_view->SetScaffolding(g); - - // build popup menu - g->popup_menu = new BPopUpMenu(""); - - - // the dragger to allow replicating us - // XXX: try to stuff it in the status bar at the bottom - // (BDragger *must* be a parent, sibiling or direct child of NSBaseView!) - rect = g->top_view->Bounds(); - rect.bottom = rect.top + TOOLBAR_HEIGHT - 1; - rect.left = rect.right - DRAGGER_WIDTH + 1; - g->dragger = new BDragger(rect, g->top_view, - B_FOLLOW_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW); - g->top_view->AddChild(g->dragger); - g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->dragger->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; - - // tool_bar - // the toolbar is also the dragger for now - // XXX: try to stuff it in the status bar at the bottom - // (BDragger *must* be a parent, sibiling or direct child of NSBaseView!) - rect = g->top_view->Bounds(); - rect.bottom = rect.top + TOOLBAR_HEIGHT - 1; - rect.right = rect.right - DRAGGER_WIDTH; - g->tool_bar = new BView(rect, "Toolbar", - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW); - g->top_view->AddChild(g->tool_bar); - g->tool_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - g->tool_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; - - // buttons -#warning use BPictureButton - rect = g->tool_bar->Bounds(); - rect.right = TOOLBAR_HEIGHT; - rect.InsetBySelf(5, 5); - rect.OffsetBySelf(0, -1); - int nButtons = 0; - - message = new BMessage('back'); - message->AddPointer("scaffolding", g); - g->back_button = new BButton(rect, "back_button", "<", message); - g->tool_bar->AddChild(g->back_button); - nButtons++; - - rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); - message = new BMessage('forw'); - message->AddPointer("scaffolding", g); - g->forward_button = new BButton(rect, "forward_button", ">", message); - g->tool_bar->AddChild(g->forward_button); - nButtons++; - - rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); - message = new BMessage('stop'); - message->AddPointer("scaffolding", g); - g->stop_button = new BButton(rect, "stop_button", "S", message); - g->tool_bar->AddChild(g->stop_button); - nButtons++; - - rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); - message = new BMessage('relo'); - message->AddPointer("scaffolding", g); - g->reload_button = new BButton(rect, "reload_button", "R", message); - g->tool_bar->AddChild(g->reload_button); - nButtons++; - - rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); - message = new BMessage('home'); - message->AddPointer("scaffolding", g); - g->home_button = new BButton(rect, "home_button", "H", message); - g->tool_bar->AddChild(g->home_button); - nButtons++; - - - // url bar - rect = g->tool_bar->Bounds(); - rect.left += TOOLBAR_HEIGHT * nButtons; - rect.right -= TOOLBAR_HEIGHT * 1; - rect.InsetBySelf(5, 5); - message = new BMessage('urle'); - message->AddPointer("scaffolding", g); - g->url_bar = new BTextControl(rect, "url_bar", "url", "", message, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); - g->url_bar->SetDivider(g->url_bar->StringWidth("url ")); - g->tool_bar->AddChild(g->url_bar); - - - // throbber - rect.Set(0, 0, 24, 24); - rect.OffsetTo(g->tool_bar->Bounds().right - 24 - (TOOLBAR_HEIGHT - 24) / 2, - (TOOLBAR_HEIGHT - 24) / 2); - g->throbber = new NSThrobber(rect); - g->tool_bar->AddChild(g->throbber); - g->throbber->SetViewColor(g->tool_bar->ViewColor()); - g->throbber->SetLowColor(g->tool_bar->ViewColor()); - g->throbber->SetDrawingMode(B_OP_ALPHA); - g->throbber->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - /* set up the throbber. */ - g->throbber->SetBitmap(nsbeos_throbber->framedata[0]); - g->throb_frame = 0; - - - // the status bar at the bottom - BString status("NetSurf"); - status << " " << netsurf_version; - g->status_bar = new BStringView(BRect(0,0,-1,-1), "StatusBar", - status.String(), B_FOLLOW_LEFT/*_RIGHT*/ | B_FOLLOW_BOTTOM); - - // will be added to the scrollview when adding the top view. - - // notify the thread creating the replicant that we're done - if (replicant_view) - release_sem(replicant_done_sem); - - replicant_view = NULL; - -#warning XXX -#if 0 /* GTK */ - /* load the window template from the glade xml file, and extract - * widget references from it for later use. - */ - g->xml = glade_xml_new(glade_file_location, "wndBrowser", NULL); - glade_xml_signal_autoconnect(g->xml); - g->window = beos_WINDOW(GET_WIDGET("wndBrowser")); - g->url_bar = beos_ENTRY(GET_WIDGET("URLBar")); - g->menu_bar = beos_MENU_BAR(GET_WIDGET("menubar")); - g->status_bar = beos_LABEL(GET_WIDGET("statusBar")); - g->tool_bar = beos_TOOLBAR(GET_WIDGET("toolbar")); - g->back_button = beos_TOOL_BUTTON(GET_WIDGET("toolBack")); - g->forward_button = beos_TOOL_BUTTON(GET_WIDGET("toolForward")); - g->stop_button = beos_TOOL_BUTTON(GET_WIDGET("toolStop")); - g->reload_button = beos_TOOL_BUTTON(GET_WIDGET("toolReload")); - g->back_menu = beos_MENU_ITEM(GET_WIDGET("back")); - g->forward_menu = beos_MENU_ITEM(GET_WIDGET("forward")); - g->stop_menu = beos_MENU_ITEM(GET_WIDGET("stop")); - g->reload_menu = beos_MENU_ITEM(GET_WIDGET("reload")); - g->throbber = beos_IMAGE(GET_WIDGET("throbber")); - g->status_pane = beos_PANED(GET_WIDGET("hpaned1")); - - /* set this window's size and position to what's in the options, or - * or some sensible default if they're not set yet. - */ - if (nsoption_int(window_width) > 0) { - beos_window_move(g->window, nsoption_int(window_x), nsoption_int(window_y)); - beos_window_resize(g->window, nsoption_int(window_width), - nsoption_int(window_height)); - } else { - beos_window_set_default_size(g->window, 600, 600); - } - - /* set the size of the hpane with status bar and h scrollbar */ - beos_paned_set_position(g->status_pane, nsoption_int(toolbar_status_width)); - - /* set the URL entry box to expand, as we can't do this from within - * glade because of the way it emulates toolbars. - */ - beos_tool_item_set_expand(beos_TOOL_ITEM(GET_WIDGET("toolURLBar")), TRUE); - - /* disable toolbar buttons that make no sense initially. */ - beos_widget_set_sensitive(beos_WIDGET(g->back_button), FALSE); - beos_widget_set_sensitive(beos_WIDGET(g->forward_button), FALSE); - beos_widget_set_sensitive(beos_WIDGET(g->stop_button), FALSE); - - /* create the local history window to be assoicated with this browser */ - g->history_window = malloc(sizeof(struct beos_history_window)); - g->history_window->g = g; - g->history_window->window = beos_WINDOW( - beos_window_new(beos_WINDOW_TOPLEVEL)); - beos_window_set_transient_for(g->history_window->window, g->window); - beos_window_set_default_size(g->history_window->window, 400, 400); - beos_window_set_title(g->history_window->window, "NetSurf History"); - beos_window_set_type_hint(g->history_window->window, - GDK_WINDOW_TYPE_HINT_UTILITY); - g->history_window->scrolled = beos_SCROLLED_WINDOW( - beos_scrolled_window_new(0, 0)); - beos_container_add(beos_CONTAINER(g->history_window->window), - beos_WIDGET(g->history_window->scrolled)); - - beos_widget_show(beos_WIDGET(g->history_window->scrolled)); - g->history_window->drawing_area = beos_DRAWING_AREA( - beos_drawing_area_new()); - - beos_widget_set_events(beos_WIDGET(g->history_window->drawing_area), - GDK_EXPOSURE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_PRESS_MASK); - beos_widget_modify_bg(beos_WIDGET(g->history_window->drawing_area), - beos_STATE_NORMAL, - &((GdkColor) { 0, 0xffff, 0xffff, 0xffff } )); - beos_scrolled_window_add_with_viewport(g->history_window->scrolled, - beos_WIDGET(g->history_window->drawing_area)); - beos_widget_show(beos_WIDGET(g->history_window->drawing_area)); - - /* set up URL bar completion */ - g->url_bar_completion = beos_entry_completion_new(); - beos_entry_set_completion(g->url_bar, g->url_bar_completion); - beos_entry_completion_set_match_func(g->url_bar_completion, - nsbeos_completion_match, NULL, NULL); - beos_entry_completion_set_model(g->url_bar_completion, - beos_TREE_MODEL(nsbeos_completion_list)); - beos_entry_completion_set_text_column(g->url_bar_completion, 0); - beos_entry_completion_set_minimum_key_length(g->url_bar_completion, 1); - beos_entry_completion_set_popup_completion(g->url_bar_completion, TRUE); - g_object_set(G_OBJECT(g->url_bar_completion), - "popup-set-width", TRUE, - "popup-single-match", TRUE, - NULL); - - /* set up the throbber. */ - beos_image_set_from_pixbuf(g->throbber, nsbeos_throbber->framedata[0]); - g->throb_frame = 0; - -#define CONNECT(obj, sig, callback, ptr) \ - g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) - - /* connect history window signals to their handlers */ - CONNECT(g->history_window->drawing_area, "expose_event", - nsbeos_history_expose_event, g->history_window); -// CONNECT(g->history_window->drawing_area, "motion_notify_event", -// nsbeos_history_motion_notify_event, g->history_window); - CONNECT(g->history_window->drawing_area, "button_press_event", - nsbeos_history_button_press_event, g->history_window); - CONNECT(g->history_window->window, "delete_event", - beos_widget_hide_on_delete, NULL); - - /* connect signals to handlers. */ - CONNECT(g->window, "destroy", nsbeos_window_destroy_event, g); - - /* toolbar and URL bar signal handlers */ - CONNECT(g->back_button, "clicked", nsbeos_window_back_button_clicked, g); - CONNECT(g->forward_button, "clicked", - nsbeos_window_forward_button_clicked, g); - CONNECT(g->stop_button, "clicked", nsbeos_window_stop_button_clicked, g); - CONNECT(g->reload_button, "clicked", - nsbeos_window_reload_button_clicked, g); - CONNECT(GET_WIDGET("toolHome"), "clicked", - nsbeos_window_home_button_clicked, g); - CONNECT(g->url_bar, "activate", nsbeos_window_url_activate_event, g); - CONNECT(g->url_bar, "changed", nsbeos_window_url_changed, g); - - /* set up the menu signal handlers */ - nsbeos_attach_menu_handlers(g->xml, g); - - g->being_destroyed = 0; - - g->fullscreen = false; - - /* create the popup version of the menu */ - g->popup_xml = glade_xml_new(glade_file_location, "menuPopup", NULL); - g->popup_menu = beos_MENU(glade_xml_get_widget(g->popup_xml, "menuPopup")); - -#define POPUP_ATTACH(x, y) beos_menu_item_set_submenu( \ - beos_MENU_ITEM(glade_xml_get_widget(g->popup_xml, x)),\ - beos_WIDGET(glade_xml_get_widget(g->xml, y))) - - POPUP_ATTACH("menupopup_file", "menumain_file"); - POPUP_ATTACH("menupopup_edit", "menumain_edit"); - POPUP_ATTACH("menupopup_view", "menumain_view"); - POPUP_ATTACH("menupopup_navigate", "menumain_navigate"); - POPUP_ATTACH("menupopup_help", "menumain_help"); - -#undef POPUP_ATTACH - - /* finally, show the window. */ - beos_widget_show(beos_WIDGET(g->window)); - -#endif - return g; -} - -void gui_window_set_title(struct gui_window *_g, const char *title) -{ - struct beos_scaffolding *g = nsbeos_get_scaffold(_g); - if (g->top_level != _g) return; - - // if we're a replicant, discard - if (!g->window) - return; - - BString nt(title); - if (nt.Length()) - nt << " - "; - nt << "NetSurf"; - - if (!g->top_view->LockLooper()) - return; - - g->window->SetTitle(nt.String()); - - g->top_view->UnlockLooper(); -} - -void gui_window_set_status(struct gui_window *_g, const char *text) -{ - struct beos_scaffolding *g = nsbeos_get_scaffold(_g); - assert(g); - assert(g->status_bar); - - if (!g->top_view->LockLooper()) - return; - - if (text == NULL || text[0] == '\0') - { - BString status("NetSurf"); - status << " " << netsurf_version; - g->status_bar->SetText(status.String()); - } - else - { - g->status_bar->SetText(text); - } - g->top_view->UnlockLooper(); -} - -void gui_window_set_url(struct gui_window *_g, const char *url) -{ - struct beos_scaffolding *g = nsbeos_get_scaffold(_g); - if (g->top_level != _g) return; - assert(g->status_bar); - - if (!g->top_view->LockLooper()) - return; - - g->url_bar->SetText(url); - - g->top_view->UnlockLooper(); -} - -void gui_window_start_throbber(struct gui_window* _g) -{ - struct beos_scaffolding *g = nsbeos_get_scaffold(_g); - - if (!g->top_view->LockLooper()) - return; - - g->stop_button->SetEnabled(true); - g->reload_button->SetEnabled(false); - - g->top_view->UnlockLooper(); - - nsbeos_window_update_back_forward(g); - - schedule(10, nsbeos_throb, g); -} - -void gui_window_stop_throbber(struct gui_window* _g) -{ - struct beos_scaffolding *g = nsbeos_get_scaffold(_g); - - nsbeos_window_update_back_forward(g); - - schedule_remove(nsbeos_throb, g); - - if (!g->top_view->LockLooper()) - return; - - g->stop_button->SetEnabled(false); - g->reload_button->SetEnabled(true); - - g->throbber->SetBitmap(nsbeos_throbber->framedata[0]); - g->throbber->Invalidate(); - - g->top_view->UnlockLooper(); -} - -/** - * add retrieved favicon to the gui - */ -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) -{ -} - -/** -* set gui display of a retrieved favicon representing the search provider -* \param ico may be NULL for local calls; then access current cache from -* search_web_ico() -*/ -void gui_window_set_search_ico(hlcache_handle *ico) -{ -} - -#warning XXX -#if 0 /* GTK */ -gboolean nsbeos_scaffolding_is_busy(nsbeos_scaffolding *scaffold) -{ - /* We are considered "busy" if the stop button is sensitive */ - return beos_WIDGET_SENSITIVE((beos_WIDGET(scaffold->stop_button))); -} -#endif - -void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where) -{ - g->popup_menu->Go(where); -} diff --git a/beos/beos_scaffolding.h b/beos/beos_scaffolding.h deleted file mode 100644 index ae7839175..000000000 --- a/beos/beos_scaffolding.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2005 James Bursa - * - * 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 . - */ - -#ifndef NETSURF_BEOS_SCAFFOLDING_H -#define NETSURF_BEOS_SCAFFOLDING_H 1 - -#include -#include -#include - -extern "C" { -#include "desktop/gui.h" -#include "desktop/plotters.h" -} - -typedef struct beos_scaffolding nsbeos_scaffolding; - -class NSBaseView : public BView { -public: - NSBaseView(BRect frame); - NSBaseView(BMessage *archive); -virtual ~NSBaseView(); - -virtual void MessageReceived(BMessage *message); -//virtual void Draw(BRect updateRect); - -//virtual void FrameMoved(BPoint new_location); -//virtual void FrameResized(float new_width, float new_height); - -virtual void AllAttached(void); - -virtual status_t Archive(BMessage *archive, bool deep=true) const; -static BArchivable *Instantiate(BMessage *archive); - -void SetScaffolding(struct beos_scaffolding *scaf); -private: - struct beos_scaffolding *fScaffolding; -}; - -class NSBrowserWindow : public BWindow { -public: - NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf); -virtual ~NSBrowserWindow(); - -virtual void DispatchMessage(BMessage *message, BHandler *handler); -virtual void MessageReceived(BMessage *message); -virtual bool QuitRequested(void); - -struct beos_scaffolding *Scaffolding() const { return fScaffolding; }; - -private: - struct beos_scaffolding *fScaffolding; -}; - - -// XXX: clean up -typedef enum { - - /* no/unknown actions */ - NO_ACTION = 'nsMA', - - /* help actions */ - HELP_OPEN_CONTENTS, - HELP_OPEN_GUIDE, - HELP_OPEN_INFORMATION, - HELP_OPEN_ABOUT, - HELP_LAUNCH_INTERACTIVE, - - /* history actions */ - HISTORY_SHOW_LOCAL, - HISTORY_SHOW_GLOBAL, - - /* hotlist actions */ - HOTLIST_ADD_URL, - HOTLIST_SHOW, - - /* cookie actions */ - COOKIES_SHOW, - COOKIES_DELETE, - - /* page actions */ - BROWSER_PAGE, - BROWSER_PAGE_INFO, - BROWSER_PRINT, - BROWSER_NEW_WINDOW, - BROWSER_VIEW_SOURCE, - - /* object actions */ - BROWSER_OBJECT, - BROWSER_OBJECT_INFO, - BROWSER_OBJECT_RELOAD, - - /* save actions */ - BROWSER_OBJECT_SAVE, - BROWSER_OBJECT_EXPORT_SPRITE, - BROWSER_OBJECT_SAVE_URL_URI, - BROWSER_OBJECT_SAVE_URL_URL, - BROWSER_OBJECT_SAVE_URL_TEXT, - BROWSER_SAVE, - BROWSER_SAVE_COMPLETE, - BROWSER_EXPORT_DRAW, - BROWSER_EXPORT_TEXT, - BROWSER_SAVE_URL_URI, - BROWSER_SAVE_URL_URL, - BROWSER_SAVE_URL_TEXT, - HOTLIST_EXPORT, - HISTORY_EXPORT, - - /* navigation actions */ - BROWSER_NAVIGATE_HOME, - BROWSER_NAVIGATE_BACK, - BROWSER_NAVIGATE_FORWARD, - BROWSER_NAVIGATE_UP, - BROWSER_NAVIGATE_RELOAD, - BROWSER_NAVIGATE_RELOAD_ALL, - BROWSER_NAVIGATE_STOP, - BROWSER_NAVIGATE_URL, - - /* browser window/display actions */ - BROWSER_SCALE_VIEW, - BROWSER_FIND_TEXT, - BROWSER_IMAGES_FOREGROUND, - BROWSER_IMAGES_BACKGROUND, - BROWSER_BUFFER_ANIMS, - BROWSER_BUFFER_ALL, - BROWSER_SAVE_VIEW, - BROWSER_WINDOW_DEFAULT, - BROWSER_WINDOW_STAGGER, - BROWSER_WINDOW_COPY, - BROWSER_WINDOW_RESET, - - /* tree actions */ - TREE_NEW_FOLDER, - TREE_NEW_LINK, - TREE_EXPAND_ALL, - TREE_EXPAND_FOLDERS, - TREE_EXPAND_LINKS, - TREE_COLLAPSE_ALL, - TREE_COLLAPSE_FOLDERS, - TREE_COLLAPSE_LINKS, - TREE_SELECTION, - TREE_SELECTION_EDIT, - TREE_SELECTION_LAUNCH, - TREE_SELECTION_DELETE, - TREE_SELECT_ALL, - TREE_CLEAR_SELECTION, - - /* toolbar actions */ - TOOLBAR_BUTTONS, - TOOLBAR_ADDRESS_BAR, - TOOLBAR_THROBBER, - TOOLBAR_EDIT, - - /* misc actions */ - CHOICES_SHOW, - APPLICATION_QUIT, -} menu_action; - - -NSBrowserWindow *nsbeos_find_last_window(void); - -NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold); - -nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel); - -bool nsbeos_scaffolding_is_busy(nsbeos_scaffolding *scaffold); - -void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view); - -#if 0 /* GTK */ -void nsbeos_attach_toplevel_viewport(nsbeos_scaffolding *g, GtkViewport *vp); -#endif - -void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *message); - -void nsbeos_scaffolding_destroy(nsbeos_scaffolding *scaffold); - -//void nsbeos_window_destroy_event(NSBrowserWindow *window, nsbeos_scaffolding *g, BMessage *event); - - -void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where); - -#if 0 /* GTK */ -void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, guint button); -#endif - -#endif /* NETSURF_BEOS_SCAFFOLDING_H */ diff --git a/beos/beos_schedule.cpp b/beos/beos_schedule.cpp deleted file mode 100644 index 3f822352a..000000000 --- a/beos/beos_schedule.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include - -extern "C" { -#include "utils/schedule.h" -#include "desktop/browser.h" - -#ifdef DEBUG_BEOS_SCHEDULE -#include "utils/log.h" -#else -#define LOG(X) -#endif -} - -/** Killable callback closure embodiment. */ -typedef struct { - void (*callback)(void *); /**< The callback function. */ - void *context; /**< The context for the callback. */ - bool callback_killed; /**< Whether or not this was killed. */ - bool callback_fired; /**< Whether or not this has fired yet. */ - bigtime_t timeout; -} _nsbeos_callback_t; - -/** List of all callbacks. */ -static BList *callbacks = NULL; - -/** earliest deadline. It's used for select() in gui_poll() */ -bigtime_t earliest_callback_timeout = B_INFINITE_TIMEOUT; - - -static bool -nsbeos_schedule_kill_callback(void *_target, void *_match) -{ - _nsbeos_callback_t *target = (_nsbeos_callback_t *)_target; - _nsbeos_callback_t *match = (_nsbeos_callback_t *)_match; - if ((target->callback == match->callback) && - (target->context == match->context)) { - LOG(("Found match for %p(%p), killing.", - target->callback, target->context)); - target->callback = NULL; - target->context = NULL; - target->callback_killed = true; - } - return false; -} - -void -schedule_remove(void (*callback)(void *p), void *p) -{ - LOG(("schedule_remove() for %p(%p)", cb->callback, cb->context)); - if (callbacks == NULL) - return; - _nsbeos_callback_t cb_match; - cb_match.callback = callback; - cb_match.context = p; - - - callbacks->DoForEach(nsbeos_schedule_kill_callback, &cb_match); -} - -void -schedule(int t, void (*callback)(void *p), void *p) -{ - LOG(("schedule(%d, %p, %p)", t, cb->callback, cb->context)); - if (callbacks == NULL) - callbacks = new BList; - - bigtime_t timeout = system_time() + t * 10 * 1000LL; - const int msec_timeout = t * 10; - _nsbeos_callback_t *cb = (_nsbeos_callback_t *)malloc(sizeof(_nsbeos_callback_t)); - /* Kill any pending schedule of this kind. */ - schedule_remove(callback, p); - cb->callback = callback; - cb->context = p; - cb->callback_killed = cb->callback_fired = false; - cb->timeout = timeout; - if (earliest_callback_timeout > timeout) - earliest_callback_timeout = timeout; - callbacks->AddItem(cb); -} - -bool -schedule_run(void) -{ - LOG(("schedule_run()")); - if (callbacks == NULL) - return false; /* Nothing to do */ - - bigtime_t now = system_time(); - earliest_callback_timeout = B_INFINITE_TIMEOUT; - int32 i; - - LOG(("Checking %ld callbacks to for deadline.", this_run->CountItems())); - - /* Run all the callbacks which made it this far. */ - for (i = 0; i < callbacks->CountItems(); ) { - _nsbeos_callback_t *cb = (_nsbeos_callback_t *)(callbacks->ItemAt(i)); - if (cb->timeout > now) { - // update next deadline - if (earliest_callback_timeout > cb->timeout) - earliest_callback_timeout = cb->timeout; - i++; - continue; - } - LOG(("Running callbacks %p(%p).", cb->callback, cb->context)); - if (!cb->callback_killed) - cb->callback(cb->context); - callbacks->RemoveItem(cb); - free(cb); - } - return true; -} diff --git a/beos/beos_schedule.h b/beos/beos_schedule.h deleted file mode 100644 index 02205baf4..000000000 --- a/beos/beos_schedule.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#ifndef NETSURF_BEOS_CALLBACK_H -#define NETSURF_BEOS_CALLBACK_H 1 - -typedef void (*beos_callback)(void *p); - -extern bigtime_t earliest_callback_timeout; - -#endif /* NETSURF_BEOS_CALLBACK_H */ diff --git a/beos/beos_search.cpp b/beos/beos_search.cpp deleted file mode 100644 index 97e3d6d5b..000000000 --- a/beos/beos_search.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2009 Mark Benjamin - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -//#include -#include - -extern "C" { -#include "utils/log.h" -} -/* callback functions for search implementation */ -static void gui_search_set_status(bool found, void *p); -static void gui_search_set_hourglass(bool active, void *p); -static void gui_search_add_recent(const char *string, void *p); -static void gui_search_set_forward_state(bool active, void *p); -static void gui_search_set_back_state(bool active, void *p); - -/** - * Change the displayed search status. - * \param found search pattern matched in text - * \param p the pointer sent to search_verify_new() / search_create_context() - */ -void gui_search_set_status(bool found, void *p) -{ -} - -/** - * display hourglass while searching - * \param active start/stop indicator - * \param p the pointer sent to search_verify_new() / search_create_context() - */ -void gui_search_set_hourglass(bool active, void *p) -{ -} - -/** - * add search string to recent searches list - * \param string search pattern - * \param p the pointer sent to search_verify_new() / search_create_context() - */ -void gui_search_add_recent(const char *string, void *p) -{ -} - -/** - * activate search forwards button in gui - * \param active activate/inactivate - * \param p the pointer sent to search_verify_new() / search_create_context() - */ -void gui_search_set_forward_state(bool active, void *p) -{ -} - -/** - * activate search forwards button in gui - * \param active activate/inactivate - * \param p the pointer sent to search_verify_new() / search_create_context() - */ -void gui_search_set_back_state(bool active, void *p) -{ -} diff --git a/beos/beos_throbber.cpp b/beos/beos_throbber.cpp deleted file mode 100644 index 6b344068b..000000000 --- a/beos/beos_throbber.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -extern "C" { -#include "utils/log.h" -} -#include "beos/beos_throbber.h" -#include "beos/beos_bitmap.h" -#include "beos/beos_fetch_rsrc.h" - -#include -#include -#include - -struct nsbeos_throbber *nsbeos_throbber = NULL; - -/** - * Creates the throbber using a PNG for each frame. The number of frames must - * be at least two. The first frame is the inactive frame, others are the - * active frames. - * - * \param frames The number of frames. Must be at least two. - * \param ... Filenames of PNGs containing frames. - * \return true on success. - */ -bool nsbeos_throbber_initialise_from_png(const int frames, ...) -{ - va_list filenames; - struct nsbeos_throbber *throb; /**< structure we generate */ - bool errors_when_loading = false; /**< true if a frame failed */ - - if (frames < 2) { - /* we need at least two frames - one for idle, one for active */ - LOG(("Insufficent number of frames in throbber animation!")); - LOG(("(called with %d frames, where 2 is a minimum.)", - frames)); - return false; - } - - BResources *res = get_app_resources(); - if (res == NULL) { - LOG(("Can't find resources for throbber!")); - return false; - } - - throb = (struct nsbeos_throbber *)malloc(sizeof(throb)); - throb->nframes = frames; - throb->framedata = (BBitmap **)malloc(sizeof(BBitmap *) * throb->nframes); - - va_start(filenames, frames); - - for (int i = 0; i < frames; i++) { - const char *fn = va_arg(filenames, const char *); - const void *data; - size_t size; - data = res->LoadResource('data', fn, &size); - throb->framedata[i] = NULL; - if (!data) { - LOG(("Error when loading resource %s", fn)); - errors_when_loading = true; - continue; - } - BMemoryIO mem(data, size); - throb->framedata[i] = BTranslationUtils::GetBitmap(&mem); - if (throb->framedata[i] == NULL) { - LOG(("Error when loading %s: GetBitmap() returned NULL", fn)); - errors_when_loading = true; - } - } - - va_end(filenames); - - if (errors_when_loading == true) { - for (int i = 0; i < frames; i++) { - delete throb->framedata[i]; - } - - free(throb->framedata); - free(throb); - - return false; - } - - nsbeos_throbber = throb; - - return true; -} - -void nsbeos_throbber_finalise(void) -{ - int i; - - for (i = 0; i < nsbeos_throbber->nframes; i++) - delete nsbeos_throbber->framedata[i]; - - free(nsbeos_throbber->framedata); - free(nsbeos_throbber); - - nsbeos_throbber = NULL; -} diff --git a/beos/beos_throbber.h b/beos/beos_throbber.h deleted file mode 100644 index 670c60a06..000000000 --- a/beos/beos_throbber.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#ifndef __BEOS_THROBBER_H__ -#define __BEOS_THROBBER_H__ - -#include - -struct nsbeos_throbber -{ - int nframes; /**< Number of frames in the throbber */ - BBitmap **framedata; -}; - -extern struct nsbeos_throbber *nsbeos_throbber; - -bool nsbeos_throbber_initialise_from_gif(const char *fn); -bool nsbeos_throbber_initialise_from_png(const int frames, ...); -void nsbeos_throbber_finalise(void); - -#endif /* __BEOS_THROBBER_H__ */ diff --git a/beos/beos_thumbnail.cpp b/beos/beos_thumbnail.cpp deleted file mode 100644 index bd8d74bb0..000000000 --- a/beos/beos_thumbnail.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -/** \file - * Page thumbnail creation (implementation). - * - * Thumbnails are created by setting the current drawing contexts to a BView - * attached to the BBitmap we are passed, and plotting the page at a small - * scale. - */ - -#define __STDBOOL_H__ 1 -#include -#include -#include -#include -extern "C" { -#include "content/content.h" -#include "content/urldb.h" -#include "desktop/plotters.h" -#include "desktop/browser.h" -#include "desktop/thumbnail.h" -#include "image/bitmap.h" -#include "render/font.h" -#include "utils/log.h" -} -#include "beos/beos_scaffolding.h" -#include "beos/beos_plotters.h" -#include "beos/beos_bitmap.h" - -// Zeta PRIVATE: in libzeta for now. -extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap); - -#warning XXX do we need to set bitmap:shadow ? - - -/** - * Create a thumbnail of a page. - * - * \param content content structure to thumbnail - * \param bitmap the bitmap to draw to - * \param url the URL the thumnail belongs to, or NULL - */ -bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, - const char *url) -{ - BBitmap *thumbnail; - BBitmap *small; - BBitmap *big; - BView *oldView; - BView *view; - BView *thumbView; - float width; - float height; - int big_width; - int big_height; - int depth; - - struct redraw_context ctx; - ctx.interactive = false; - ctx.background_images = true; - ctx.plot = &nsbeos_plotters; - - assert(content); - assert(bitmap); - - thumbnail = nsbeos_bitmap_get_primary(bitmap); - width = thumbnail->Bounds().Width(); - height = thumbnail->Bounds().Height(); - depth = 32; - - big_width = MIN(content_get_width(content), 1024); - big_height = (int)(((big_width * height) + (width / 2)) / width); - - BRect contentRect(0, 0, big_width - 1, big_height - 1); - big = new BBitmap(contentRect, B_BITMAP_ACCEPTS_VIEWS, B_RGB32); - - if (big->InitCheck() < B_OK) { - delete big; - return false; - } - - small = new BBitmap(thumbnail->Bounds(), - B_BITMAP_ACCEPTS_VIEWS, B_RGB32); - - if (small->InitCheck() < B_OK) { - delete small; - delete big; - return false; - } - - //XXX: _lock ? - // backup the current gc - oldView = nsbeos_current_gc(); - - view = new BView(contentRect, "thumbnailer", - B_FOLLOW_NONE, B_WILL_DRAW); - big->AddChild(view); - - thumbView = new BView(small->Bounds(), "thumbnail", - B_FOLLOW_NONE, B_WILL_DRAW); - small->AddChild(thumbView); - - view->LockLooper(); - - /* impose our view on the content... */ - nsbeos_current_gc_set(view); - - /* render the content */ - thumbnail_redraw(content, big_width, big_height, &ctx); - - view->Sync(); - view->UnlockLooper(); - - // restore the current gc - nsbeos_current_gc_set(oldView); - - - // now scale it down -//XXX: use Zeta's bilinear scaler ? -//#ifdef B_ZETA_VERSION -// err = ScaleBitmap(*shot, *scaledBmp); -//#else - thumbView->LockLooper(); - thumbView->DrawBitmap(big, big->Bounds(), small->Bounds()); - thumbView->Sync(); - thumbView->UnlockLooper(); - - small->LockBits(); - thumbnail->LockBits(); - - // copy it to the bitmap - memcpy(thumbnail->Bits(), small->Bits(), thumbnail->BitsLength()); - - thumbnail->UnlockBits(); - small->UnlockBits(); - - /* register the thumbnail with the URL */ - if (url) - urldb_set_thumbnail(url, bitmap); - - bitmap_modified(bitmap); - - // cleanup - small->RemoveChild(thumbView); - delete thumbView; - delete small; - big->RemoveChild(view); - delete view; - delete big; - - return true; -} diff --git a/beos/beos_treeview.cpp b/beos/beos_treeview.cpp deleted file mode 100644 index 4728995ad..000000000 --- a/beos/beos_treeview.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2004 Richard Wilson - * - * 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 . - */ - -/** \file - * Generic tree handling (implementation). - */ - - -#define __STDBOOL_H__ 1 -extern "C" { -#include "utils/config.h" -#include "desktop/tree.h" -#include "desktop/tree_url_node.h" -} - -const char tree_directory_icon_name[] = "directory.png"; -const char tree_content_icon_name[] = "content.png"; - - - - -/** - * Translates a content_type to the name of a respective icon - * - * \param content_type content type - * \param buffer buffer for the icon name - */ -void tree_icon_name_from_content_type(char *buffer, content_type type) -{ - // TODO: design/acquire icons - switch (type) { - case CONTENT_HTML: - case CONTENT_TEXTPLAIN: - case CONTENT_CSS: - case CONTENT_IMAGE: - default: - sprintf(buffer, tree_content_icon_name); - break; - } -} diff --git a/beos/beos_window.cpp b/beos/beos_window.cpp deleted file mode 100644 index 9c608d50d..000000000 --- a/beos/beos_window.cpp +++ /dev/null @@ -1,1773 +0,0 @@ -/* - * Copyright 2008 François Revol - * Copyright 2006 Daniel Silverstone - * Copyright 2006 Rob Kendrick - * - * 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 . - */ - -#define __STDBOOL_H__ 1 -#include -extern "C" { -#include "content/urldb.h" -#include "css/utils.h" -#include "desktop/browser.h" -#include "desktop/mouse.h" -#include "desktop/options.h" -#include "desktop/selection.h" -#include "desktop/textinput.h" -#include "render/font.h" -#include "utils/log.h" -#include "utils/types.h" -#include "utils/utf8.h" -#include "utils/utils.h" -} -#include "beos/beos_about.h" -#include "beos/beos_window.h" -#include "beos/beos_font.h" -#include "beos/beos_gui.h" -#include "beos/beos_scaffolding.h" -#include "beos/beos_plotters.h" -//#include "beos/beos_schedule.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class NSBrowserFrameView; - -struct gui_window { - /* All gui_window objects have an ultimate scaffold */ - nsbeos_scaffolding *scaffold; - bool toplevel; - /* A gui_window is the rendering of a browser_window */ - struct browser_window *bw; - - struct { - int pressed_x; - int pressed_y; - int state; /* browser_mouse_state */ - } mouse; - - /* These are the storage for the rendering */ - int caretx, carety, careth; - gui_pointer_shape current_pointer; - int last_x, last_y; - - NSBrowserFrameView *view; - - // some cached events to speed up things - // those are the last queued event of their kind, - // we can safely drop others and avoid wasting cpu. - // number of pending resizes - vint32 pending_resizes; - // accumulated rects of pending redraws - //volatile BMessage *lastRedraw; - // UNUSED YET - BRect pendingRedraw; -#if 0 /* GTK */ - /* Within GTK, a gui_window is a scrolled window - * with a viewport inside - * with a gtkfixed in that - * with a drawing area in that - * The scrolled window is optional and only chosen - * for frames which need it. Otherwise we just use - * a viewport. - */ - GtkScrolledWindow *scrolledwindow; - GtkViewport *viewport; - GtkFixed *fixed; - GtkDrawingArea *drawing_area; -#endif - - /* Keep gui_windows in a list for cleanup later */ - struct gui_window *next, *prev; -}; - - - -static const rgb_color kWhiteColor = {255, 255, 255, 255}; - -static struct gui_window *window_list = 0; /**< first entry in win list*/ - -static BString current_selection; -static BList current_selection_textruns; - -/* Methods which apply only to a gui_window */ -static void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message); -static void nsbeos_window_keypress_event(BView *view, gui_window *g, BMessage *event); -static void nsbeos_window_resize_event(BView *view, gui_window *g, BMessage *event); -static void nsbeos_window_moved_event(BView *view, gui_window *g, BMessage *event); -/* Other useful bits */ -static void nsbeos_redraw_caret(struct gui_window *g); - -#if 0 /* GTK */ -static GdkCursor *nsbeos_create_menu_cursor(void); -#endif - -// #pragma mark - class NSBrowserFrameView - - -NSBrowserFrameView::NSBrowserFrameView(BRect frame, struct gui_window *gui) - : BView(frame, "NSBrowserFrameView", B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS /*| B_SUBPIXEL_PRECISE*/), - fGuiWindow(gui) -{ -} - - -NSBrowserFrameView::~NSBrowserFrameView() -{ -} - - -void -NSBrowserFrameView::MessageReceived(BMessage *message) -{ - switch (message->what) { - case B_SIMPLE_DATA: - case B_ARGV_RECEIVED: - case B_REFS_RECEIVED: - case B_COPY: - case B_CUT: - case B_PASTE: - case B_SELECT_ALL: - //case B_MOUSE_WHEEL_CHANGED: - case B_UI_SETTINGS_CHANGED: - // NetPositive messages - case B_NETPOSITIVE_OPEN_URL: - case B_NETPOSITIVE_BACK: - case B_NETPOSITIVE_FORWARD: - case B_NETPOSITIVE_HOME: - case B_NETPOSITIVE_RELOAD: - case B_NETPOSITIVE_STOP: - case B_NETPOSITIVE_DOWN: - case B_NETPOSITIVE_UP: - // messages for top-level - case 'back': - case 'forw': - case 'stop': - case 'relo': - case 'home': - case 'urlc': - case 'urle': - case 'menu': - case NO_ACTION: - case HELP_OPEN_CONTENTS: - case HELP_OPEN_GUIDE: - case HELP_OPEN_INFORMATION: - case HELP_OPEN_ABOUT: - case HELP_LAUNCH_INTERACTIVE: - case HISTORY_SHOW_LOCAL: - case HISTORY_SHOW_GLOBAL: - case HOTLIST_ADD_URL: - case HOTLIST_SHOW: - case COOKIES_SHOW: - case COOKIES_DELETE: - case BROWSER_PAGE: - case BROWSER_PAGE_INFO: - case BROWSER_PRINT: - case BROWSER_NEW_WINDOW: - case BROWSER_VIEW_SOURCE: - case BROWSER_OBJECT: - case BROWSER_OBJECT_INFO: - case BROWSER_OBJECT_RELOAD: - case BROWSER_OBJECT_SAVE: - case BROWSER_OBJECT_EXPORT_SPRITE: - case BROWSER_OBJECT_SAVE_URL_URI: - case BROWSER_OBJECT_SAVE_URL_URL: - case BROWSER_OBJECT_SAVE_URL_TEXT: - case BROWSER_SAVE: - case BROWSER_SAVE_COMPLETE: - case BROWSER_EXPORT_DRAW: - case BROWSER_EXPORT_TEXT: - case BROWSER_SAVE_URL_URI: - case BROWSER_SAVE_URL_URL: - case BROWSER_SAVE_URL_TEXT: - case HOTLIST_EXPORT: - case HISTORY_EXPORT: - case BROWSER_NAVIGATE_HOME: - case BROWSER_NAVIGATE_BACK: - case BROWSER_NAVIGATE_FORWARD: - case BROWSER_NAVIGATE_UP: - case BROWSER_NAVIGATE_RELOAD: - case BROWSER_NAVIGATE_RELOAD_ALL: - case BROWSER_NAVIGATE_STOP: - case BROWSER_NAVIGATE_URL: - case BROWSER_SCALE_VIEW: - case BROWSER_FIND_TEXT: - case BROWSER_IMAGES_FOREGROUND: - case BROWSER_IMAGES_BACKGROUND: - case BROWSER_BUFFER_ANIMS: - case BROWSER_BUFFER_ALL: - case BROWSER_SAVE_VIEW: - case BROWSER_WINDOW_DEFAULT: - case BROWSER_WINDOW_STAGGER: - case BROWSER_WINDOW_COPY: - case BROWSER_WINDOW_RESET: - case TREE_NEW_FOLDER: - case TREE_NEW_LINK: - case TREE_EXPAND_ALL: - case TREE_EXPAND_FOLDERS: - case TREE_EXPAND_LINKS: - case TREE_COLLAPSE_ALL: - case TREE_COLLAPSE_FOLDERS: - case TREE_COLLAPSE_LINKS: - case TREE_SELECTION: - case TREE_SELECTION_EDIT: - case TREE_SELECTION_LAUNCH: - case TREE_SELECTION_DELETE: - case TREE_SELECT_ALL: - case TREE_CLEAR_SELECTION: - case TOOLBAR_BUTTONS: - case TOOLBAR_ADDRESS_BAR: - case TOOLBAR_THROBBER: - case TOOLBAR_EDIT: - case CHOICES_SHOW: - case APPLICATION_QUIT: - Window()->DetachCurrentMessage(); - nsbeos_pipe_message_top(message, NULL, fGuiWindow->scaffold); - break; - default: - message->PrintToStream(); - BView::MessageReceived(message); - } -} - - -void -NSBrowserFrameView::Draw(BRect updateRect) -{ - BMessage *message = NULL; - //message = Window()->DetachCurrentMessage(); - // might be called directly... - if (message == NULL) - message = new BMessage(_UPDATE_); - message->AddRect("rect", updateRect); - nsbeos_pipe_message(message, this, fGuiWindow); -} - - -#if 0 -void -NSBrowserFrameView::FrameMoved(BPoint new_location) -{ - BMessage *message = Window()->DetachCurrentMessage(); - // discard any other pending resize, - // so we don't end up processing them all, the last one matters. - //atomic_add(&fGuiWindow->pending_resizes, 1); - nsbeos_pipe_message(message, this, fGuiWindow); - BView::FrameMoved(new_location); -} -#endif - -void -NSBrowserFrameView::FrameResized(float new_width, float new_height) -{ - BMessage *message = Window()->DetachCurrentMessage(); - // discard any other pending resize, - // so we don't end up processing them all, the last one matters. - atomic_add(&fGuiWindow->pending_resizes, 1); - nsbeos_pipe_message(message, this, fGuiWindow); - BView::FrameResized(new_width, new_height); -} - - -void -NSBrowserFrameView::KeyDown(const char *bytes, int32 numBytes) -{ - BMessage *message = Window()->DetachCurrentMessage(); - nsbeos_pipe_message(message, this, fGuiWindow); -} - - -void -NSBrowserFrameView::MouseDown(BPoint where) -{ - BMessage *message = Window()->DetachCurrentMessage(); - BPoint screenWhere; - if (message->FindPoint("screen_where", &screenWhere) < B_OK) { - screenWhere = ConvertToScreen(where); - message->AddPoint("screen_where", screenWhere); - } - nsbeos_pipe_message(message, this, fGuiWindow); -} - - -void -NSBrowserFrameView::MouseUp(BPoint where) -{ - //BMessage *message = Window()->DetachCurrentMessage(); - //nsbeos_pipe_message(message, this, fGuiWindow); - BMessage *message = Window()->DetachCurrentMessage(); - BPoint screenWhere; - if (message->FindPoint("screen_where", &screenWhere) < B_OK) { - screenWhere = ConvertToScreen(where); - message->AddPoint("screen_where", screenWhere); - } - nsbeos_pipe_message(message, this, fGuiWindow); -} - - -void -NSBrowserFrameView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg) -{ - if (transit != B_INSIDE_VIEW) { - BView::MouseMoved(where, transit, msg); - return; - } - BMessage *message = Window()->DetachCurrentMessage(); - nsbeos_pipe_message(message, this, fGuiWindow); -} - - -// #pragma mark - gui_window - -struct browser_window *nsbeos_get_browser_window(struct gui_window *g) -{ - return g->bw; -} - -nsbeos_scaffolding *nsbeos_get_scaffold(struct gui_window *g) -{ - return g->scaffold; -} - -struct browser_window *nsbeos_get_browser_for_gui(struct gui_window *g) -{ - return g->bw; -} - -float nsbeos_get_scale_for_gui(struct gui_window *g) -{ - return g->bw->scale; -} - -/* Create a gui_window */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) -{ - struct gui_window *g; /**< what we're creating to return */ - - g = (struct gui_window *)malloc(sizeof(*g)); - if (!g) { - warn_user("NoMemory", 0); - return 0; - } - - LOG(("Creating gui window %p for browser window %p", g, bw)); - - g->bw = bw; - g->mouse.state = 0; - g->current_pointer = GUI_POINTER_DEFAULT; - if (clone != NULL) - bw->scale = clone->scale; - else - bw->scale = (float) nsoption_int(scale) / 100; - - g->careth = 0; - g->pending_resizes = 0; - - /* Attach ourselves to the list (push_top) */ - if (window_list) - window_list->prev = g; - g->next = window_list; - g->prev = NULL; - window_list = g; - - /* Now construct and attach a scaffold */ - g->scaffold = nsbeos_new_scaffolding(g); - if (!g->scaffold) - return NULL; - - /* Construct our primary elements */ - BRect frame(0,0,-1,-1); // will be resized later - g->view = new NSBrowserFrameView(frame, g); - /* set the default background colour of the drawing area to white. */ - //g->view->SetViewColor(kWhiteColor); - /* NOOO! Since we defer drawing (DetachCurrent()), the white flickers, - * besides sometimes text was drawn twice, making it ugly. - * Instead we set to transparent here, and implement plot_clg() to - * do it just before the rest. This almost removes the flicker. */ - g->view->SetViewColor(B_TRANSPARENT_COLOR); - g->view->SetLowColor(kWhiteColor); - -#ifdef B_BEOS_VERSION_DANO - /* enable double-buffering on the content view */ -/* - XXX: doesn't really work - g->view->SetDoubleBuffering(B_UPDATE_INVALIDATED - | B_UPDATE_SCROLLED - //| B_UPDATE_RESIZED - | B_UPDATE_EXPOSED); -*/ -#endif - - - g->toplevel = true; - - /* Attach our viewport into the scaffold */ - nsbeos_attach_toplevel_view(g->scaffold, g->view); - -#warning WRITEME -#if 0 /* GTK */ - GtkPolicyType scrollpolicy; - - /* Construct our primary elements */ - g->fixed = GTK_FIXED(gtk_fixed_new()); - g->drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new()); - gtk_fixed_put(g->fixed, GTK_WIDGET(g->drawing_area), 0, 0); - gtk_container_set_border_width(GTK_CONTAINER(g->fixed), 0); - - g->scrolledwindow = 0; - g->viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL)); /* Need to attach adjustments */ - gtk_container_add(GTK_CONTAINER(g->viewport), GTK_WIDGET(g->fixed)); - - /* Attach our viewport into the scaffold */ - nsbeos_attach_toplevel_viewport(g->scaffold, g->viewport); - - gtk_container_set_border_width(GTK_CONTAINER(g->viewport), 0); - gtk_viewport_set_shadow_type(g->viewport, GTK_SHADOW_NONE); - if (g->scrolledwindow) - gtk_widget_show(GTK_WIDGET(g->scrolledwindow)); - /* And enable visibility from our viewport down */ - gtk_widget_show(GTK_WIDGET(g->viewport)); - gtk_widget_show(GTK_WIDGET(g->fixed)); - gtk_widget_show(GTK_WIDGET(g->drawing_area)); - - switch(bw->scrolling) { - case SCROLLING_NO: - scrollpolicy = GTK_POLICY_NEVER; - break; - case SCROLLING_YES: - scrollpolicy = GTK_POLICY_ALWAYS; - break; - case SCROLLING_AUTO: - default: - scrollpolicy = GTK_POLICY_AUTOMATIC; - break; - }; - - - if (g->scrolledwindow) - gtk_scrolled_window_set_policy(g->scrolledwindow, - scrollpolicy, scrollpolicy); - - /* set the events we're interested in receiving from the browser's - * drawing area. - */ - gtk_widget_add_events(GTK_WIDGET(g->drawing_area), - GDK_EXPOSURE_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_POINTER_MOTION_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK); - GTK_WIDGET_SET_FLAGS(GTK_WIDGET(g->drawing_area), GTK_CAN_FOCUS); - - /* set the default background colour of the drawing area to white. */ - gtk_widget_modify_bg(GTK_WIDGET(g->drawing_area), GTK_STATE_NORMAL, - &((GdkColor) { 0, 0xffff, 0xffff, 0xffff } )); - -#define CONNECT(obj, sig, callback, ptr) \ - g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) - CONNECT(g->drawing_area, "expose_event", nsgtk_window_expose_event, g); - CONNECT(g->drawing_area, "motion_notify_event", - nsgtk_window_motion_notify_event, g); - CONNECT(g->drawing_area, "button_press_event", - nsgtk_window_button_press_event, g); - CONNECT(g->drawing_area, "key_press_event", - nsgtk_window_keypress_event, g); - CONNECT(g->viewport, "size_allocate", - nsgtk_window_size_allocate_event, g); -#endif - - return g; -} - - -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, - int x1, int y1) -{ - gui_window_set_scroll(g, x0, y0); -} - -void nsbeos_dispatch_event(BMessage *message) -{ - struct gui_window *gui = NULL; - NSBrowserFrameView *view = NULL; - struct beos_scaffolding *scaffold = NULL; - NSBrowserWindow *window = NULL; - - //message->PrintToStream(); - if (message->FindPointer("View", (void **)&view) < B_OK) - view = NULL; - if (message->FindPointer("gui_window", (void **)&gui) < B_OK) - gui = NULL; - if (message->FindPointer("Window", (void **)&window) < B_OK) - window = NULL; - if (message->FindPointer("scaffolding", (void **)&scaffold) < B_OK) - scaffold = NULL; - - struct gui_window *z; - for (z = window_list; z && gui && z != gui; z = z->next) - continue; - - struct gui_window *y; - for (y = window_list; y && scaffold && y->scaffold != scaffold; y = y->next) - continue; - - if (gui && gui != z) { - LOG(("discarding event for destroyed gui_window")); - delete message; - return; - } - if (scaffold && (!y || scaffold != y->scaffold)) { - LOG(("discarding event for destroyed scaffolding")); - delete message; - return; - } - - // messages for top-level - if (scaffold) { - LOG(("dispatching to top-level")); - nsbeos_scaffolding_dispatch_event(scaffold, message); - delete message; - return; - } - - //LOG(("processing message")); - switch (message->what) { - case B_QUIT_REQUESTED: - // from the BApplication - netsurf_quit = true; - break; - case B_ABOUT_REQUESTED: - { - nsbeos_about(gui); - /* XXX: doesn't work yet! bug in rsrc:/ - BString url("rsrc:/about.en.html,text/html"); - browser_window_create(url.String(), NULL, NULL, true, false); - */ - break; - } - case _UPDATE_: - if (gui && view) - nsbeos_window_expose_event(view, gui, message); - break; - case B_MOUSE_MOVED: - { - if (gui == NULL) - break; - - BPoint where; - int32 mods; - // where refers to Window coords !? - // check be:view_where first - if (message->FindPoint("be:view_where", &where) < B_OK) { - if (message->FindPoint("where", &where) < B_OK) - break; - } - if (message->FindInt32("modifiers", &mods) < B_OK) - mods = 0; - - - if (gui->mouse.state & BROWSER_MOUSE_PRESS_1) { - /* Start button 1 drag */ - browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_1, - gui->mouse.pressed_x, gui->mouse.pressed_y); - /* Replace PRESS with HOLDING and declare drag in progress */ - gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | - BROWSER_MOUSE_HOLDING_1); - gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; - } else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) { - /* Start button 2 drag */ - browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_2, - gui->mouse.pressed_x, gui->mouse.pressed_y); - /* Replace PRESS with HOLDING and declare drag in progress */ - gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | - BROWSER_MOUSE_HOLDING_2); - gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; - } - - bool shift = mods & B_SHIFT_KEY; - bool ctrl = mods & B_CONTROL_KEY; - - /* Handle modifiers being removed */ - if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) - gui->mouse.state ^= BROWSER_MOUSE_MOD_1; - if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) - gui->mouse.state ^= BROWSER_MOUSE_MOD_2; - - browser_window_mouse_track(gui->bw, (browser_mouse_state)gui->mouse.state, - (int)(where.x / gui->bw->scale), - (int)(where.y / gui->bw->scale)); - - gui->last_x = (int)where.x; - gui->last_y = (int)where.y; - break; - } - case B_MOUSE_DOWN: - { - if (gui == NULL) - break; - - BPoint where; - int32 buttons; - int32 mods; - BPoint screenWhere; - if (message->FindPoint("be:view_where", &where) < B_OK) { - if (message->FindPoint("where", &where) < B_OK) - break; - } - if (message->FindInt32("buttons", &buttons) < B_OK) - break; - if (message->FindPoint("screen_where", &screenWhere) < B_OK) - break; - if (message->FindInt32("modifiers", &mods) < B_OK) - mods = 0; - - if (buttons & B_SECONDARY_MOUSE_BUTTON) { - /* 2 == right button on BeOS */ - - nsbeos_scaffolding_popup_menu(gui->scaffold, screenWhere); - break; - } - - gui->mouse.state = BROWSER_MOUSE_PRESS_1; - - if (buttons & B_TERTIARY_MOUSE_BUTTON) /* 3 == middle button on BeOS */ - gui->mouse.state = BROWSER_MOUSE_PRESS_2; - - if (mods & B_SHIFT_KEY) - gui->mouse.state |= BROWSER_MOUSE_MOD_1; - if (mods & B_CONTROL_KEY) - gui->mouse.state |= BROWSER_MOUSE_MOD_2; - - gui->mouse.pressed_x = where.x / gui->bw->scale; - gui->mouse.pressed_y = where.y / gui->bw->scale; - - // make sure the view is in focus - if (view && view->LockLooper()) { - if (!view->IsFocus()) - view->MakeFocus(); - view->UnlockLooper(); - } - - browser_window_mouse_click(gui->bw, - (browser_mouse_state)gui->mouse.state, - gui->mouse.pressed_x, gui->mouse.pressed_y); - - break; - } - case B_MOUSE_UP: - { - if (gui == NULL) - break; - - BPoint where; - int32 buttons; - int32 mods; - BPoint screenWhere; - if (message->FindPoint("be:view_where", &where) < B_OK) { - if (message->FindPoint("where", &where) < B_OK) - break; - } - if (message->FindInt32("buttons", &buttons) < B_OK) - break; - if (message->FindPoint("screen_where", &screenWhere) < B_OK) - break; - if (message->FindInt32("modifiers", &mods) < B_OK) - mods = 0; - - /* 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 (gui->mouse.state & BROWSER_MOUSE_PRESS_1) - gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_CLICK_1); - else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) - gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | BROWSER_MOUSE_CLICK_2); - - bool shift = mods & B_SHIFT_KEY; - bool ctrl = mods & B_CONTROL_KEY; - - /* Handle modifiers being removed */ - if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) - gui->mouse.state ^= BROWSER_MOUSE_MOD_1; - if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) - gui->mouse.state ^= BROWSER_MOUSE_MOD_2; - - /* - if (view && view->LockLooper()) { - view->MakeFocus(); - view->UnlockLooper(); - } - */ - - if (gui->mouse.state & (BROWSER_MOUSE_CLICK_1|BROWSER_MOUSE_CLICK_2)) - browser_window_mouse_click(gui->bw, - (browser_mouse_state)gui->mouse.state, - where.x / gui->bw->scale, - where.y / gui->bw->scale); - else - browser_window_mouse_track(gui->bw, (browser_mouse_state)0, - where.x, where.y); - - gui->mouse.state = 0; - - break; - } - case B_KEY_DOWN: - if (gui && view) - nsbeos_window_keypress_event(view, gui, message); - break; - case B_VIEW_RESIZED: - if (gui && view) - nsbeos_window_resize_event(view, gui, message); - break; - case B_VIEW_MOVED: - if (gui && view) - nsbeos_window_moved_event(view, gui, message); - break; - case B_MOUSE_WHEEL_CHANGED: - break; - case B_UI_SETTINGS_CHANGED: - nsbeos_update_system_ui_colors(); - break; - case 'nsLO': // login - { - BString url; - BString realm; - BString auth; - if (message->FindString("URL", &url) < B_OK) - break; - if (message->FindString("Realm", &realm) < B_OK) - break; - if (message->FindString("Auth", &auth) < B_OK) - break; - //printf("login to '%s' with '%s'\n", url.String(), auth.String()); - urldb_set_auth_details(url.String(), realm.String(), auth.String()); - browser_window_go(gui->bw, url.String(), 0, true); - break; - } - default: - break; - } - delete message; -} - -void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message) -{ - BRect updateRect; - hlcache_handle *c; - float scale = g->bw->scale; - struct rect clip; - - struct redraw_context ctx = { true, true, &nsbeos_plotters }; - - assert(g); - assert(g->bw); - - struct gui_window *z; - for (z = window_list; z && z != g; z = z->next) - continue; - assert(z); - assert(g->view == view); - - // we'll be resizing = reflowing = redrawing everything anyway... - if (g->pending_resizes > 1) - return; - - if (message->FindRect("rect", &updateRect) < B_OK) - return; - - c = g->bw->current_content; - if (c == NULL) - return; - - if (!view->LockLooper()) - return; - nsbeos_current_gc_set(view); - - if (view->Window()) - view->Window()->BeginViewTransaction(); - - clip.x0 = (int)updateRect.left; - clip.y0 = (int)updateRect.top; - clip.x1 = (int)updateRect.right + 1; - clip.y1 = (int)updateRect.bottom + 1; - - browser_window_redraw(g->bw, 0, 0, &clip, &ctx); - - if (g->careth != 0) - nsbeos_plot_caret(g->caretx, g->carety, g->careth); - - if (view->Window()) - view->Window()->EndViewTransaction(); - - // reset clipping just in case - view->ConstrainClippingRegion(NULL); - nsbeos_current_gc_set(NULL); - view->UnlockLooper(); -} - -void nsbeos_window_keypress_event(BView *view, gui_window *g, BMessage *event) -{ - const char *bytes; - char buff[6]; - int numbytes = 0; - uint32 mods; - uint32 key; - uint32 raw_char; - uint32_t nskey; - int i; - - if (event->FindInt32("modifiers", (int32 *)&mods) < B_OK) - mods = modifiers(); - if (event->FindInt32("key", (int32 *)&key) < B_OK) - key = 0; - if (event->FindInt32("raw_char", (int32 *)&raw_char) < B_OK) - raw_char = 0; - /* check for byte[] first, because C-space gives bytes="" (and byte[0] = '\0') */ - for (i = 0; i < 5; i++) { - buff[i] = '\0'; - if (event->FindInt8("byte", i, (int8 *)&buff[i]) < B_OK) - break; - } - - if (i) { - bytes = buff; - numbytes = i; - } else if (event->FindString("bytes", &bytes) < B_OK) - bytes = ""; - - if (!numbytes) - numbytes = strlen(bytes); - - LOG(("mods 0x%08lx key %ld raw %ld byte[0] %d", mods, key, raw_char, buff[0])); - - char byte; - if (numbytes == 1) { - byte = bytes[0]; - if (mods & B_CONTROL_KEY) - byte = (char)raw_char; - if (byte >= '!' && byte <= '~') - nskey = (uint32_t)byte; - else { - switch (byte) { - case B_BACKSPACE: nskey = KEY_DELETE_LEFT; break; - case B_TAB: nskey = KEY_TAB; break; - /*case XK_Linefeed: return QKlinefeed;*/ - case B_ENTER: nskey = (uint32_t)10; break; - case B_ESCAPE: nskey = (uint32_t)'\033'; break; - case B_SPACE: nskey = (uint32_t)' '; break; - case B_DELETE: nskey = KEY_DELETE_RIGHT; break; - /* - case B_INSERT: nskey = KEYSYM("insert"); break; - */ - case B_HOME: nskey = KEY_LINE_START; break; // XXX ? - case B_END: nskey = KEY_LINE_END; break; // XXX ? - case B_PAGE_UP: nskey = KEY_PAGE_UP; break; - case B_PAGE_DOWN: nskey = KEY_PAGE_DOWN; break; - case B_LEFT_ARROW: nskey = KEY_LEFT; break; - case B_RIGHT_ARROW: nskey = KEY_RIGHT; break; - case B_UP_ARROW: nskey = KEY_UP; break; - case B_DOWN_ARROW: nskey = KEY_DOWN; break; - /* - case B_FUNCTION_KEY: - switch (scancode) { - case B_F1_KEY: nskey = KEYSYM("f1"); break; - case B_F2_KEY: nskey = KEYSYM("f2"); break; - case B_F3_KEY: nskey = KEYSYM("f3"); break; - case B_F4_KEY: nskey = KEYSYM("f4"); break; - case B_F5_KEY: nskey = KEYSYM("f5"); break; - case B_F6_KEY: nskey = KEYSYM("f6"); break; - case B_F7_KEY: nskey = KEYSYM("f7"); break; - case B_F8_KEY: nskey = KEYSYM("f8"); break; - case B_F9_KEY: nskey = KEYSYM("f9"); break; - case B_F10_KEY: nskey = KEYSYM("f10"); break; - case B_F11_KEY: nskey = KEYSYM("f11"); break; - case B_F12_KEY: nskey = KEYSYM("f12"); break; - case B_PRINT_KEY: nskey = KEYSYM("print"); break; - case B_SCROLL_KEY: nskey = KEYSYM("scroll-lock"); break; - case B_PAUSE_KEY: nskey = KEYSYM("pause"); break; - } - */ - case 0: - nskey = (uint32_t)0; - default: - nskey = (uint32_t)raw_char; - /*if (simple_p) - nskey = (uint32_t)0;*/ - break; - } - } - } else { - nskey = utf8_to_ucs4(bytes, numbytes); - } - - bool done = browser_window_key_press(g->bw, nskey); - LOG(("nskey %d %d", nskey, done)); - //if (browser_window_key_press(g->bw, nskey)) - return; - -} - -#warning WRITEME -#if 0 /* GTK */ -gboolean nsbeos_window_keypress_event(GtkWidget *widget, GdkEventKey *event, - gpointer data) -{ - struct gui_window *g = data; - uint32_t nskey = gdkkey_to_nskey(event); - - if (browser_window_key_press(g->bw, nskey)) - return TRUE; - - if (event->state == 0) { - double value; - GtkAdjustment *vscroll = gtk_viewport_get_vadjustment(g->viewport); - - GtkAdjustment *hscroll = gtk_viewport_get_hadjustment(g->viewport); - - GtkAdjustment *scroll; - - const GtkAllocation *const alloc = - >K_WIDGET(g->viewport)->allocation; - - switch (event->keyval) { - default: - return TRUE; - - case GDK_Home: - case GDK_KP_Home: - scroll = vscroll; - value = scroll->lower; - break; - - case GDK_End: - case GDK_KP_End: - scroll = vscroll; - value = scroll->upper - alloc->height; - if (value < scroll->lower) - value = scroll->lower; - break; - - case GDK_Left: - case GDK_KP_Left: - scroll = hscroll; - value = gtk_adjustment_get_value(scroll) - - scroll->step_increment; - if (value < scroll->lower) - value = scroll->lower; - break; - - case GDK_Up: - case GDK_KP_Up: - scroll = vscroll; - value = gtk_adjustment_get_value(scroll) - - scroll->step_increment; - if (value < scroll->lower) - value = scroll->lower; - break; - - case GDK_Right: - case GDK_KP_Right: - scroll = hscroll; - value = gtk_adjustment_get_value(scroll) + - scroll->step_increment; - if (value > scroll->upper - alloc->width) - value = scroll->upper - alloc->width; - break; - - case GDK_Down: - case GDK_KP_Down: - scroll = vscroll; - value = gtk_adjustment_get_value(scroll) + - scroll->step_increment; - if (value > scroll->upper - alloc->height) - value = scroll->upper - alloc->height; - break; - - case GDK_Page_Up: - case GDK_KP_Page_Up: - scroll = vscroll; - value = gtk_adjustment_get_value(scroll) - - scroll->page_increment; - if (value < scroll->lower) - value = scroll->lower; - break; - - case GDK_Page_Down: - case GDK_KP_Page_Down: - scroll = vscroll; - value = gtk_adjustment_get_value(scroll) + - scroll->page_increment; - if (value > scroll->upper - alloc->height) - value = scroll->upper - alloc->height; - break; - } - - gtk_adjustment_set_value(scroll, value); - } - - return TRUE; -} - -#endif - -void nsbeos_window_resize_event(BView *view, gui_window *g, BMessage *event) -{ - CALLED(); - int32 width; - int32 height; - - // drop this event if we have at least 2 resize pending -#if 1 - if (atomic_add(&g->pending_resizes, -1) > 1) - return; -#endif - - if (event->FindInt32("width", &width) < B_OK) - width = -1; - if (event->FindInt32("height", &height) < B_OK) - height = -1; - width++; - height++; - - -#if 0 - hlcache_handle *content; - - content = g->bw->current_content; - - /* reformat or change extent if necessary */ - if ((content) && (g->old_width != width || g->old_height != height)) { - /* Ctrl-resize of a top-level window scales the content size */ -#if 0 - if ((g->old_width > 0) && (g->old_width != width) && (!g->bw->parent) && - (ro_gui_ctrl_pressed())) - new_scale = (g->bw->scale * width) / g->old_width; -#endif - g->bw->reformat_pending = true; - browser_reformat_pending = true; - } - if (g->update_extent || g->old_width != width || g->old_height != height) { - g->old_width = width; - g->old_height = height; - g->update_extent = false; - gui_window_set_extent(g, width, height); - } -#endif - g->bw->reformat_pending = true; - browser_reformat_pending = true; - - return; -} - - -void nsbeos_window_moved_event(BView *view, gui_window *g, BMessage *event) -{ - CALLED(); - -#warning XXX: Invalidate ? - if (!view || !view->LockLooper()) - return; - //view->Invalidate(view->Bounds()); - view->UnlockLooper(); - - //g->bw->reformat_pending = true; - //browser_reformat_pending = true; - - - return; -} - - -void nsbeos_reflow_all_windows(void) -{ - for (struct gui_window *g = window_list; g; g = g->next) - g->bw->reformat_pending = true; - - browser_reformat_pending = true; -} - - -/** - * Process pending reformats - */ - -void nsbeos_window_process_reformats(void) -{ - struct gui_window *g; - - browser_reformat_pending = false; - for (g = window_list; g; g = g->next) { - NSBrowserFrameView *view = g->view; - if (!g->bw->reformat_pending) - continue; - if (!view || !view->LockLooper()) - continue; - g->bw->reformat_pending = false; - BRect bounds = view->Bounds(); - view->UnlockLooper(); -#warning XXX why - 1 & - 2 !??? - browser_window_reformat(g->bw, - false, - bounds.Width() + 1 /* - 2*/, - bounds.Height() + 1); - } - -#warning WRITEME -#if 0 /* GTK */ - for (g = window_list; g; g = g->next) { - GtkWidget *widget = GTK_WIDGET(g->viewport); - if (!g->bw->reformat_pending) - continue; - g->bw->reformat_pending = false; - browser_window_reformat(g->bw, - false, - widget->allocation.width - 2, - widget->allocation.height); - } -#endif -} - - -void nsbeos_window_destroy_browser(struct gui_window *g) -{ - browser_window_destroy(g->bw); -} - -void gui_window_destroy(struct gui_window *g) -{ - if (!g) - return; - - if (g->prev) - g->prev->next = g->next; - else - window_list = g->next; - - if (g->next) - g->next->prev = g->prev; - - - LOG(("Destroying gui_window %p", g)); - assert(g != NULL); - assert(g->bw != NULL); - LOG((" Scaffolding: %p", g->scaffold)); - LOG((" Window name: %s", g->bw->name)); - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - BLooper *looper = g->view->Looper(); - /* If we're a top-level gui_window, destroy our scaffold */ - if (g->toplevel) { - g->view->RemoveSelf(); - delete g->view; - nsbeos_scaffolding_destroy(g->scaffold); - } else { - g->view->RemoveSelf(); - delete g->view; - looper->Unlock(); - } - //XXX - //looper->Unlock(); - -#warning FIXME - -#if 0 /* GTK */ - /* If we're a top-level gui_window, destroy our scaffold */ - if (g->scrolledwindow == NULL) { - gtk_widget_destroy(GTK_WIDGET(g->viewport)); - nsgtk_scaffolding_destroy(g->scaffold); - } else { - gtk_widget_destroy(GTK_WIDGET(g->scrolledwindow)); - } -#endif - - free(g); - -} - -void nsbeos_redraw_caret(struct gui_window *g) -{ - if (g->careth == 0) - return; - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - nsbeos_current_gc_set(g->view); - - g->view->Invalidate(BRect(g->caretx, g->carety, - g->caretx, g->carety + g->careth)); - - nsbeos_current_gc_set(NULL); - g->view->UnlockLooper(); -} - -void gui_window_redraw_window(struct gui_window *g) -{ - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - nsbeos_current_gc_set(g->view); - - g->view->Invalidate(); - - nsbeos_current_gc_set(NULL); - g->view->UnlockLooper(); -} - -void gui_window_update_box(struct gui_window *g, const struct rect *rect) -{ - hlcache_handle *c = g->bw->current_content; - - if (c == NULL) - return; - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - nsbeos_current_gc_set(g->view); - -//XXX +1 ?? - g->view->Invalidate(BRect(rect->x0, rect->y0, - rect->x1 - 1, rect->y1 - 1)); - - nsbeos_current_gc_set(NULL); - g->view->UnlockLooper(); -} - -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) -{ - CALLED(); - if (g->view == NULL) - return false; - if (!g->view->LockLooper()) - return false; - -#warning XXX: report to view frame ? - if (g->view->ScrollBar(B_HORIZONTAL)) - *sx = (int)g->view->ScrollBar(B_HORIZONTAL)->Value(); - if (g->view->ScrollBar(B_VERTICAL)) - *sy = (int)g->view->ScrollBar(B_VERTICAL)->Value(); - - g->view->UnlockLooper(); -#warning WRITEME -#if 0 /* GTK */ - GtkAdjustment *vadj = gtk_viewport_get_vadjustment(g->viewport); - GtkAdjustment *hadj = gtk_viewport_get_hadjustment(g->viewport); - - assert(vadj); - assert(hadj); - - *sy = (int)(gtk_adjustment_get_value(vadj)); - *sx = (int)(gtk_adjustment_get_value(hadj)); - -#endif - return true; -} - -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) -{ - CALLED(); - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - -#warning XXX: report to view frame ? - if (g->view->ScrollBar(B_HORIZONTAL)) - g->view->ScrollBar(B_HORIZONTAL)->SetValue(sx); - if (g->view->ScrollBar(B_VERTICAL)) - g->view->ScrollBar(B_VERTICAL)->SetValue(sy); - - g->view->UnlockLooper(); -#warning WRITEME -#if 0 /* GTK */ - GtkAdjustment *vadj = gtk_viewport_get_vadjustment(g->viewport); - GtkAdjustment *hadj = gtk_viewport_get_hadjustment(g->viewport); - gdouble vlower, vpage, vupper, hlower, hpage, hupper, x = (double)sx, y = (double)sy; - - assert(vadj); - assert(hadj); - - g_object_get(vadj, "page-size", &vpage, "lower", &vlower, "upper", &vupper, NULL); - g_object_get(hadj, "page-size", &hpage, "lower", &hlower, "upper", &hupper, NULL); - - if (x < hlower) - x = hlower; - if (x > (hupper - hpage)) - x = hupper - hpage; - if (y < vlower) - y = vlower; - if (y > (vupper - vpage)) - y = vupper - vpage; - - gtk_adjustment_set_value(vadj, y); - gtk_adjustment_set_value(hadj, x); -#endif -} - - -void gui_window_update_extent(struct gui_window *g) -{ - CALLED(); - if (!g->bw->current_content) - return; - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - float x_max = content_get_width(g->bw->current_content) * g->bw->scale /* - 1*/; - float y_max = content_get_height(g->bw->current_content) * g->bw->scale /* - 1*/; - float x_prop = g->view->Bounds().Width() / x_max; - float y_prop = g->view->Bounds().Height() / y_max; - x_max -= g->view->Bounds().Width() + 1; - y_max -= g->view->Bounds().Height() + 1; -printf("x_max = %f y_max = %f x_prop = %f y_prop = %f\n", x_max, y_max, x_prop, y_prop); - if (g->view->ScrollBar(B_HORIZONTAL)) { - g->view->ScrollBar(B_HORIZONTAL)->SetRange(0, x_max); - g->view->ScrollBar(B_HORIZONTAL)->SetProportion(x_prop); - g->view->ScrollBar(B_HORIZONTAL)->SetSteps(10, 50); - } - if (g->view->ScrollBar(B_VERTICAL)) { - g->view->ScrollBar(B_VERTICAL)->SetRange(0, y_max); - g->view->ScrollBar(B_VERTICAL)->SetProportion(y_prop); - g->view->ScrollBar(B_VERTICAL)->SetSteps(10, 50); - } - -#if 0 - g->view->ResizeTo( - g->bw->current_content->width * g->bw->scale /* - 1*/, - g->bw->current_content->height * g->bw->scale /* - 1*/); -#endif - - g->view->UnlockLooper(); - -#warning WRITEME -#if 0 /* GTK */ - gtk_widget_set_size_request(GTK_WIDGET(g->drawing_area), - g->bw->current_content->width * g->bw->scale, - g->bw->current_content->height * g->bw->scale); - - gtk_widget_set_size_request(GTK_WIDGET(g->viewport), 0, 0); -#endif -} - -/* some cursors like those in Firefox */ -// XXX: move to separate file or resource ? - -const uint8 kLinkCursorBits[] = { - 16, /* cursor size */ - 1, /* bits per pixel */ - 2, /* vertical hot spot */ - 2, /* horizontal hot spot */ - - /* data */ - 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x24, 0x00, 0x24, 0x00, 0x13, 0xe0, 0x12, 0x5c, 0x09, 0x2a, - 0x08, 0x01, 0x3c, 0x21, 0x4c, 0x71, 0x42, 0x71, 0x30, 0xf9, 0x0c, 0xf9, 0x02, 0x02, 0x01, 0x00, - - /* mask */ - 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1f, 0xe0, 0x1f, 0xfc, 0x0f, 0xfe, - 0x0f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x0f, 0xff, 0x03, 0xfc, 0x01, 0xe0 -}; - -const uint8 kWatchCursorBits[] = { - 16, /* cursor size */ - 1, /* bits per pixel */ - 0, /* vertical hot spot */ - 1, /* horizontal hot spot */ - - /* data */ - 0x70, 0x00, 0x48, 0x00, 0x48, 0x00, 0x27, 0xc0, 0x24, 0xb8, 0x12, 0x54, 0x10, 0x02, 0x78, 0x02, - 0x98, 0x02, 0x84, 0x02, 0x60, 0x3a, 0x18, 0x46, 0x04, 0x8a, 0x02, 0x92, 0x01, 0x82, 0x00, 0x45, - - /* mask */ - 0x70, 0x00, 0x78, 0x00, 0x78, 0x00, 0x3f, 0xc0, 0x3f, 0xf8, 0x1f, 0xfc, 0x1f, 0xfe, 0x7f, 0xfe, - 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfe, 0x1f, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x00, 0x7f -}; - -const uint8 kWatch2CursorBits[] = { - 16, /* cursor size */ - 1, /* bits per pixel */ - 0, /* vertical hot spot */ - 1, /* horizontal hot spot */ - - /* data */ - 0x70, 0x00, 0x48, 0x00, 0x48, 0x00, 0x27, 0xc0, 0x24, 0xb8, 0x12, 0x54, 0x10, 0x02, 0x78, 0x02, - 0x98, 0x02, 0x84, 0x02, 0x60, 0x3a, 0x18, 0x46, 0x04, 0xa2, 0x02, 0x92, 0x01, 0xa2, 0x00, 0x45, - - /* mask */ - 0x70, 0x00, 0x78, 0x00, 0x78, 0x00, 0x3f, 0xc0, 0x3f, 0xf8, 0x1f, 0xfc, 0x1f, 0xfe, 0x7f, 0xfe, - 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfe, 0x1f, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x00, 0x7f -}; - - -void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) -{ - BCursor *cursor = NULL; - bool allocated = false; - - if (g->current_pointer == shape) - return; - - g->current_pointer = shape; - - switch (shape) { - case GUI_POINTER_POINT: - cursor = new BCursor(kLinkCursorBits); - allocated = true; -#if 0 // it's ugly anyway -#ifdef B_ZETA_VERSION - cursor = (BCursor *)B_CURSOR_LINK; -#endif -#endif - break; - case GUI_POINTER_CARET: - cursor = (BCursor *)B_CURSOR_I_BEAM; - break; - case GUI_POINTER_WAIT: - cursor = new BCursor(kWatchCursorBits); - allocated = true; - break; - case GUI_POINTER_PROGRESS: - cursor = new BCursor(kWatch2CursorBits); - allocated = true; - break; -#if 0 /* GTK */ - case GUI_POINTER_UP: - cursortype = GDK_TOP_SIDE; - break; - case GUI_POINTER_DOWN: - cursortype = GDK_BOTTOM_SIDE; - break; - case GUI_POINTER_LEFT: - cursortype = GDK_LEFT_SIDE; - break; - case GUI_POINTER_RIGHT: - cursortype = GDK_RIGHT_SIDE; - break; - case GUI_POINTER_LD: - cursortype = GDK_BOTTOM_LEFT_CORNER; - break; - case GUI_POINTER_RD: - cursortype = GDK_BOTTOM_RIGHT_CORNER; - break; - case GUI_POINTER_LU: - cursortype = GDK_TOP_LEFT_CORNER; - break; - case GUI_POINTER_RU: - cursortype = GDK_TOP_RIGHT_CORNER; - break; - case GUI_POINTER_CROSS: - cursortype = GDK_CROSS; - break; - case GUI_POINTER_MOVE: - cursortype = GDK_FLEUR; - break; - case GUI_POINTER_WAIT: - cursortype = GDK_WATCH; - break; - case GUI_POINTER_HELP: - cursortype = GDK_QUESTION_ARROW; - break; - case GUI_POINTER_MENU: - cursor = nsbeos_create_menu_cursor(); - nullcursor = true; - break; - case GUI_POINTER_PROGRESS: - /* In reality, this needs to be the funky left_ptr_watch - * which we can't do easily yet. - */ - cursortype = GDK_WATCH; - break; - /* The following we're not sure about */ - case GUI_POINTER_NO_DROP: - case GUI_POINTER_NOT_ALLOWED: - case GUI_POINTER_DEFAULT: -#endif - default: - cursor = (BCursor *)B_CURSOR_SYSTEM_DEFAULT; - allocated = false; - } - - if (g->view && g->view->LockLooper()) { - g->view->SetViewCursor(cursor); - g->view->UnlockLooper(); - } - - if (allocated) - delete cursor; -} - -void gui_window_hide_pointer(struct gui_window *g) -{ - //XXX no BView::HideCursor... use empty one -} - -void gui_window_place_caret(struct gui_window *g, int x, int y, int height) -{ - CALLED(); - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - nsbeos_redraw_caret(g); - - g->caretx = x; - g->carety = y + 1; - g->careth = height - 2; - - nsbeos_redraw_caret(g); - g->view->MakeFocus(); - - g->view->UnlockLooper(); -} - -void gui_window_remove_caret(struct gui_window *g) -{ - int oh = g->careth; - - if (oh == 0) - return; - - g->careth = 0; - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - nsbeos_current_gc_set(g->view); - - g->view->Invalidate(BRect(g->caretx, g->carety, g->caretx, g->carety + oh)); - - nsbeos_current_gc_set(NULL); - g->view->UnlockLooper(); -} - -void gui_window_new_content(struct gui_window *g) -{ - if (!g->toplevel) - return; - - if (g->view == NULL) - return; - if (!g->view->LockLooper()) - return; - - // scroll back to top - g->view->ScrollTo(0,0); - - g->view->UnlockLooper(); -} - -bool gui_window_scroll_start(struct gui_window *g) -{ - return true; -} - -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, - const struct rect *rect) -{ - return true; -} - -void gui_drag_save_object(gui_save_type type, hlcache_handle *c, - struct gui_window *g) -{ - -} - -void gui_drag_save_selection(struct selection *s, struct gui_window *g) -{ - -} - -void gui_start_selection(struct gui_window *g) -{ - current_selection.Truncate(0); - while (current_selection_textruns.ItemAt(0)) { - text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L); - delete run; - } - - if (!g->view->LockLooper()) - return; - - g->view->MakeFocus(); - - g->view->UnlockLooper(); -} - -void gui_clear_selection(struct gui_window *g) -{ -} - -void gui_paste_from_clipboard(struct gui_window *g, int x, int y) -{ - BMessage *clip; - if (be_clipboard->Lock()) { - clip = be_clipboard->Data(); - if (clip) { - const char *text; - int32 textlen; - if (clip->FindData("text/plain", B_MIME_TYPE, - (const void **)&text, &textlen) >= B_OK) { - browser_window_paste_text(g->bw,text,textlen,true); - } - } - be_clipboard->Unlock(); - } -} - -bool gui_empty_clipboard(void) -{ - current_selection.Truncate(0); - while (current_selection_textruns.ItemAt(0)) { - text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L); - delete run; - } - return true; -} - -bool gui_add_to_clipboard(const char *text, size_t length, bool space) -{ - BString s; - s.SetTo(text, length); - current_selection << s; - if (space) - current_selection << " "; - return true; -} - -bool gui_commit_clipboard(void) -{ - BMessage *clip; - - if (current_selection.Length() == 0) - return true; - - if (be_clipboard->Lock()) { - be_clipboard->Clear(); - clip = be_clipboard->Data(); - if (clip) { - clip->AddData("text/plain", B_MIME_TYPE, - current_selection.String(), - current_selection.Length()); - int arraySize = sizeof(text_run_array) + - current_selection_textruns.CountItems() * sizeof(text_run); - text_run_array *array = (text_run_array *)malloc(arraySize); - array->count = current_selection_textruns.CountItems(); - for (int i = 0; i < array->count; i++) - memcpy(&array->runs[i], current_selection_textruns.ItemAt(i), - sizeof(text_run)); - clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, - array, arraySize); - free(array); - - gui_empty_clipboard(); - be_clipboard->Commit(); - } - be_clipboard->Unlock(); - } - return true; -} - -static bool copy_handler(const char *text, size_t length, struct box *box, - void *handle, const char *whitespace_text, - size_t whitespace_length) -{ - bool space = false; - //XXX: handle box->style to StyledEdit / RTF ? - /* add any whitespace which precedes the text from this box */ - if (whitespace_text) { - if (!gui_add_to_clipboard(whitespace_text, - whitespace_length, false)) { - return false; - } - } - - // add a text_run for StyledEdit-like text formating - if (box && box->style) { - text_run *run = new text_run; - BFont font; - plot_font_style_t style; - font_plot_style_from_css(box->style, &style); - nsbeos_style_to_font(font, &style); - run->offset = current_selection.Length(); - run->font = font; - css_color csscolor; - if (css_computed_color(box->style, &csscolor) == CSS_COLOR_COLOR) { - run->color = nsbeos_rgb_colour(nscss_color_to_ns(csscolor)); - } - current_selection_textruns.AddItem(run); - space = box->space != 0; - } - - /* add the text from this box */ - if (!gui_add_to_clipboard(text, length, space)) - return false; - - return true; -} - -bool gui_copy_to_clipboard(struct selection *s) -{ - if (s->defined && selection_traverse(s, copy_handler, NULL)) - gui_commit_clipboard(); - return true; -} - - -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, - bool scaled) -{ - if (g->view && g->view->LockLooper()) { - *width = g->view->Bounds().Width() + 1; - *height = g->view->Bounds().Height() + 1; - g->view->UnlockLooper(); - } - - if (scaled) { - *width /= g->bw->scale; - *height /= g->bw->scale; - } -} - diff --git a/beos/beos_window.h b/beos/beos_window.h deleted file mode 100644 index 52b87cc11..000000000 --- a/beos/beos_window.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008 François Revol - * - * 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 . - */ - -#ifndef NETSURF_BEOS_WINDOW_H -#define NETSURF_BEOS_WINDOW_H 1 - -extern "C" { -#include "desktop/gui.h" -#include "desktop/browser.h" -} -#include "beos/beos_scaffolding.h" - -class NSBrowserFrameView : public BView { -public: - NSBrowserFrameView(BRect frame, struct gui_window *gui); -virtual ~NSBrowserFrameView(); - -virtual void MessageReceived(BMessage *message); -virtual void Draw(BRect updateRect); - -//virtual void FrameMoved(BPoint new_location); -virtual void FrameResized(float new_width, float new_height); - -virtual void KeyDown(const char *bytes, int32 numBytes); -virtual void MouseDown(BPoint where); -virtual void MouseUp(BPoint where); -virtual void MouseMoved(BPoint where, uint32 transit, const BMessage *msg); - -private: - struct gui_window *fGuiWindow; -}; - -void nsbeos_dispatch_event(BMessage *message); - - - -void nsbeos_reflow_all_windows(void); -void nsbeos_window_process_reformats(void); - -nsbeos_scaffolding *nsbeos_get_scaffold(struct gui_window *g); -struct browser_window *nsbeos_get_browser_for_gui(struct gui_window *g); - -float nsbeos_get_scale_for_gui(struct gui_window *g); -int nsbeos_gui_window_update_targets(struct gui_window *g); -void nsbeos_window_destroy_browser(struct gui_window *g); - -struct browser_window *nsbeos_get_browser_window(struct gui_window *g); - -#endif /* NETSURF_BEOS_WINDOW_H */ diff --git a/beos/bitmap.cpp b/beos/bitmap.cpp new file mode 100644 index 000000000..fed692315 --- /dev/null +++ b/beos/bitmap.cpp @@ -0,0 +1,424 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +/** \file + * Generic bitmap handling (BeOS implementation). + * + * This implements the interface given by desktop/bitmap.h using BBitmap. + */ + +#define __STDBOOL_H__ 1 +//#include +#include +#include +#include +#include +#include +#include +#include +#include +extern "C" { +#include "content/content.h" +#include "image/bitmap.h" +#include "utils/log.h" +} +#include "beos/bitmap.h" +#include "beos/gui.h" +#include "beos/scaffolding.h" + +struct bitmap { + BBitmap *primary; + BBitmap *shadow; // in NetSurf's ABGR order + BBitmap *pretile_x; + BBitmap *pretile_y; + BBitmap *pretile_xy; + bool opaque; +}; + +#define MIN_PRETILE_WIDTH 256 +#define MIN_PRETILE_HEIGHT 256 + +#warning TODO: check rgba order +#warning TODO: add correct locking (not strictly required) + + +/** Convert to BeOS RGBA32_LITTLE (strictly BGRA) from NetSurf's favoured ABGR format. + * Copies the converted data elsewhere. Operation is rotate left 8 bits. + * + * \param pixels Array of 32-bit values, in the form of ABGR. This will + * be overwritten with new data in the form of BGRA. + * \param width Width of the bitmap + * \param height Height of the bitmap + * \param rowstride Number of bytes to skip after each row (this + * implementation requires this to be a multiple of 4.) + */ +static inline void nsbeos_rgba_to_bgra(void *src, void *dst, int width, int height, + size_t rowstride) +{ + struct abgr { uint8 a, b, g, r; }; + struct rgba { uint8 r, g, b ,a; }; + struct bgra { uint8 b, g, r, a; }; + struct rgba *from = (struct rgba *)src; + struct bgra *to = (struct bgra *)dst; + + rowstride >>= 2; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + to[x].b = from[x].b; + to[x].g = from[x].g; + to[x].r = from[x].r; + to[x].a = from[x].a; + /* + if (from[x].a == 0) + *(rgb_color *)&to[x] = B_TRANSPARENT_32_BIT; + */ + } + from += rowstride; + to += rowstride; + } +} + + +/** + * Create a bitmap. + * + * \param width width of image in pixels + * \param height width of image in pixels + * \param state a flag word indicating the initial state + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ + +void *bitmap_create(int width, int height, unsigned int state) +{ + CALLED(); + struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap)); + if (bmp == NULL) + return NULL; + + int32 flags = 0; + if (state & BITMAP_CLEAR_MEMORY) + flags |= B_BITMAP_CLEAR_TO_WHITE; + + BRect frame(0, 0, width - 1, height - 1); + //XXX: bytes per row ? + bmp->primary = new BBitmap(frame, flags, B_RGBA32); + bmp->shadow = new BBitmap(frame, flags, B_RGBA32); + + bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL; + + bmp->opaque = (state & BITMAP_OPAQUE) != 0; + + return bmp; +} + + +/** + * Sets whether a bitmap should be plotted opaque + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \param opaque whether the bitmap should be plotted opaque + */ +void bitmap_set_opaque(void *vbitmap, bool opaque) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + bitmap->opaque = opaque; +} + + +/** + * Tests whether a bitmap has an opaque alpha channel + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \return whether the bitmap is opaque + */ +bool bitmap_test_opaque(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); +/* todo: test if bitmap is opaque */ + return false; +} + + +/** + * Gets whether a bitmap should be plotted opaque + * + * \param vbitmap a bitmap, as returned by bitmap_create() + */ +bool bitmap_get_opaque(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + return bitmap->opaque; +} + + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ + +unsigned char *bitmap_get_buffer(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + return (unsigned char *)(bitmap->shadow->Bits()); +} + + +/** + * Find the width of a pixel row in bytes. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ + +size_t bitmap_get_rowstride(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + return (bitmap->primary->BytesPerRow()); +} + + +/** + * Find the bytes per pixels of a bitmap. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \return bytes per pixels of the bitmap + */ + +size_t bitmap_get_bpp(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + return 4; +} + + +static void +nsbeos_bitmap_free_pretiles(struct bitmap *bitmap) +{ +#define FREE_TILE(XY) if (bitmap->pretile_##XY) delete (bitmap->pretile_##XY); bitmap->pretile_##XY = NULL + FREE_TILE(x); + FREE_TILE(y); + FREE_TILE(xy); +#undef FREE_TILE +} + +/** + * Free a bitmap. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + */ + +void bitmap_destroy(void *vbitmap) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + assert(bitmap); + nsbeos_bitmap_free_pretiles(bitmap); + delete bitmap->primary; + delete bitmap->shadow; + free(bitmap); +} + + +/** + * Save a bitmap in the platform's native format. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \param flags modify the behaviour of the save + * \return true on success, false on error and error reported + */ + +bool bitmap_save(void *vbitmap, const char *path, unsigned flags) +{ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + BTranslatorRoster *roster = BTranslatorRoster::Default(); + BBitmapStream stream(bitmap->primary); + BFile file(path, B_WRITE_ONLY | B_CREATE_FILE); + uint32 type = B_PNG_FORMAT; + + if (file.InitCheck() < B_OK) + return false; + + if (roster->Translate(&stream, NULL, NULL, &file, type) < B_OK) + return false; + +#if 0 /* GTK */ + GError *err = NULL; + + gdk_pixbuf_save(bitmap->primary, path, "png", &err, NULL); + + if (err == NULL) + /* TODO: report an error here */ + return false; + +#endif + return true; +} + + +/** + * The bitmap image has changed, so flush any persistant cache. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + */ +void bitmap_modified(void *vbitmap) { + CALLED(); + struct bitmap *bitmap = (struct bitmap *)vbitmap; + // convert the shadow (ABGR) to into the primary bitmap + nsbeos_rgba_to_bgra(bitmap->shadow->Bits(), bitmap->primary->Bits(), + bitmap->primary->Bounds().Width() + 1, + bitmap->primary->Bounds().Height() + 1, + bitmap->primary->BytesPerRow()); + nsbeos_bitmap_free_pretiles(bitmap); +} + + +/** + * The bitmap image can be suspended. + * + * \param vbitmap a bitmap, as returned by bitmap_create() + * \param private_word a private word to be returned later + * \param suspend the function to be called upon suspension + * \param resume the function to be called when resuming + */ +void bitmap_set_suspendable(void *vbitmap, void *private_word, + void (*invalidate)(void *vbitmap, void *private_word)) { + struct bitmap *bitmap = (struct bitmap *)vbitmap; +} + +int bitmap_get_width(void *vbitmap){ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + return bitmap->primary->Bounds().Width() + 1; +} + +int bitmap_get_height(void *vbitmap){ + struct bitmap *bitmap = (struct bitmap *)vbitmap; + return bitmap->primary->Bounds().Height() + 1; +} + +static BBitmap * +nsbeos_bitmap_generate_pretile(BBitmap *primary, int repeat_x, int repeat_y) +{ + int width = primary->Bounds().Width() + 1; + int height = primary->Bounds().Height() + 1; + size_t primary_stride = primary->BytesPerRow(); + BRect frame(0, 0, width * repeat_x - 1, height * repeat_y - 1); + BBitmap *result = new BBitmap(frame, 0, B_RGBA32); + + char *target_buffer = (char *)result->Bits(); + int x,y,row; + /* This algorithm won't work if the strides are not multiples */ + assert((size_t)(result->BytesPerRow()) == + (primary_stride * repeat_x)); + + if (repeat_x == 1 && repeat_y == 1) { + delete result; + // just return a copy + return new BBitmap(primary); + } + + for (y = 0; y < repeat_y; ++y) { + char *primary_buffer = (char *)primary->Bits(); + for (row = 0; row < height; ++row) { + for (x = 0; x < repeat_x; ++x) { + memcpy(target_buffer, + primary_buffer, primary_stride); + target_buffer += primary_stride; + } + primary_buffer += primary_stride; + } + } + return result; + +} + +/** + * The primary image associated with this bitmap object. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +BBitmap * +nsbeos_bitmap_get_primary(struct bitmap* bitmap) +{ + return bitmap->primary; +} + +/** + * The X-pretiled image associated with this bitmap object. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +BBitmap * +nsbeos_bitmap_get_pretile_x(struct bitmap* bitmap) +{ + if (!bitmap->pretile_x) { + int width = bitmap->primary->Bounds().Width() + 1; + int xmult = (MIN_PRETILE_WIDTH + width - 1)/width; + LOG(("Pretiling %p for X*%d", bitmap, xmult)); + bitmap->pretile_x = nsbeos_bitmap_generate_pretile(bitmap->primary, xmult, 1); + } + return bitmap->pretile_x; + +} + +/** + * The Y-pretiled image associated with this bitmap object. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +BBitmap * +nsbeos_bitmap_get_pretile_y(struct bitmap* bitmap) +{ + if (!bitmap->pretile_y) { + int height = bitmap->primary->Bounds().Height() + 1; + int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height; + LOG(("Pretiling %p for Y*%d", bitmap, ymult)); + bitmap->pretile_y = nsbeos_bitmap_generate_pretile(bitmap->primary, 1, ymult); + } + return bitmap->pretile_y; +} + +/** + * The XY-pretiled image associated with this bitmap object. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +BBitmap * +nsbeos_bitmap_get_pretile_xy(struct bitmap* bitmap) +{ + if (!bitmap->pretile_xy) { + int width = bitmap->primary->Bounds().Width() + 1; + int height = bitmap->primary->Bounds().Height() + 1; + int xmult = (MIN_PRETILE_WIDTH + width - 1)/width; + int ymult = (MIN_PRETILE_HEIGHT + height - 1)/height; + LOG(("Pretiling %p for X*%d Y*%d", bitmap, xmult, ymult)); + bitmap->pretile_xy = nsbeos_bitmap_generate_pretile(bitmap->primary, xmult, ymult); + } + return bitmap->pretile_xy; +} diff --git a/beos/bitmap.h b/beos/bitmap.h new file mode 100644 index 000000000..6ec662198 --- /dev/null +++ b/beos/bitmap.h @@ -0,0 +1,34 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#ifndef NS_BEOS_BITMAP_H +#define NS_BEOS_BITMAP_H + +#include +extern "C" { +#include "image/bitmap.h" +} + +BBitmap *nsbeos_bitmap_get_primary(struct bitmap*); +BBitmap *nsbeos_bitmap_get_pretile_x(struct bitmap*); +BBitmap *nsbeos_bitmap_get_pretile_y(struct bitmap*); +BBitmap *nsbeos_bitmap_get_pretile_xy(struct bitmap*); + + + +#endif /* NS_BEOS_BITMAP_H */ diff --git a/beos/fetch_rsrc.cpp b/beos/fetch_rsrc.cpp new file mode 100644 index 000000000..79dea4e76 --- /dev/null +++ b/beos/fetch_rsrc.cpp @@ -0,0 +1,383 @@ +/* + * Copyright 2008 François Revol + * Copyright 2008 Rob Kendrick + * + * This file is part of NetSurf. + * + * 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 . + */ + +/* rsrc: URL handling. */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for URL unescaping functions */ +extern "C" { +#include "utils/config.h" +#include "content/fetch.h" +#include "content/urldb.h" +#include "desktop/netsurf.h" +#include "desktop/options.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "utils/utils.h" +#include "utils/ring.h" +#include "utils/base64.h" +} +#include "beos/fetch_rsrc.h" +#include "beos/gui.h" + +#include +#include + +struct fetch_rsrc_context { + struct fetch *parent_fetch; + char *name; + char *url; + char *mimetype; + char *data; + size_t datalen; + + bool aborted; + bool locked; + + struct fetch_rsrc_context *r_next, *r_prev; +}; + +static struct fetch_rsrc_context *ring = NULL; + +static BResources *gAppResources = NULL; + +static bool fetch_rsrc_initialise(lwc_string *scheme) +{ + LOG(("fetch_rsrc_initialise called for %s", lwc_string_data(scheme))); + return true; +} + +static void fetch_rsrc_finalise(lwc_string *scheme) +{ + LOG(("fetch_rsrc_finalise called for %s", lwc_string_data(scheme))); +} + +static bool fetch_rsrc_can_fetch(const nsurl *url) +{ + return true; +} + +static void *fetch_rsrc_setup(struct fetch *parent_fetch, nsurl *url, + bool only_2xx, const char *post_urlenc, + const struct fetch_multipart_data *post_multipart, + const char **headers) +{ + struct fetch_rsrc_context *ctx; + ctx = (struct fetch_rsrc_context *)calloc(1, sizeof(*ctx)); + + if (ctx == NULL) + return NULL; + + ctx->parent_fetch = parent_fetch; + /* TODO: keep as nsurl to avoid copy */ + ctx->url = (char *)malloc(nsurl_length(url) + 1); + + if (ctx->url == NULL) { + free(ctx); + return NULL; + } + memcpy(ctx->url, nsurl_access(url), nsurl_length(url) + 1); + + RING_INSERT(ring, ctx); + + return ctx; +} + +static bool fetch_rsrc_start(void *ctx) +{ + return true; +} + +static void fetch_rsrc_free(void *ctx) +{ + struct fetch_rsrc_context *c = (struct fetch_rsrc_context *)ctx; + + free(c->name); + free(c->url); + free(c->data); + free(c->mimetype); + RING_REMOVE(ring, c); + free(ctx); +} + +static void fetch_rsrc_abort(void *ctx) +{ + struct fetch_rsrc_context *c = (struct fetch_rsrc_context *)ctx; + + /* To avoid the poll loop having to deal with the fetch context + * disappearing from under it, we simply flag the abort here. + * The poll loop itself will perform the appropriate cleanup. + */ + c->aborted = true; +} + +static void fetch_rsrc_send_callback(const fetch_msg *msg, + struct fetch_rsrc_context *c) +{ + c->locked = true; + fetch_send_callback(msg, c->parent_fetch); + c->locked = false; +} + +static bool fetch_rsrc_process(struct fetch_rsrc_context *c) +{ + fetch_msg msg; + char *params; + char *at = NULL; + char *slash; + char *comma = NULL; + char *unescaped; + uint32 type = 'data'; // default for embeded files + int32 id = 0; + + /* format of a rsrc: URL is: + * rsrc://[TYPE][@NUM]/name[,mime] + */ + + LOG(("*** Processing %s", c->url)); + + if (strlen(c->url) < 7) { + /* 7 is the minimum possible length (rsrc://) */ + msg.type = FETCH_ERROR; + msg.data.error = "Malformed rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + + /* skip the rsrc: part */ + params = c->url + sizeof("rsrc://") - 1; + + /* find the slash */ + if ( (slash = strchr(params, '/')) == NULL) { + msg.type = FETCH_ERROR; + msg.data.error = "Malformed rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + + // doesn't exist in the filesystem but we should hit the internal types. + c->mimetype = strdup(fetch_filetype(slash)); + c->name = strdup(slash + 1); + + if (c->mimetype == NULL) { + msg.type = FETCH_ERROR; + msg.data.error = + "Unable to allocate memory for mimetype in rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + + if (params[0] != '/') { + uint8 c1, c2, c3, c4; + if (sscanf(params, "%c%c%c%c", &c1, &c2, &c3, &c4) > 3) { + type = c1 << 24 | c2 << 16 | c3 << 8 | c4; + printf("type:%4.4s\n", &type); + } + } + + fprintf(stderr, "fetch_rsrc: 0x%08lx, %ld, '%s'\n", type, id, c->name); + + bool found; + if (id) + found = gAppResources->HasResource(type, id); + else + found = gAppResources->HasResource(type, c->name); + if (!found) { + msg.type = FETCH_ERROR; + msg.data.error = "Cannot locate rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + + size_t len; + const void *data; + if (id) + data = gAppResources->LoadResource(type, id, &len); + else + data = gAppResources->LoadResource(type, c->name, &len); + + if (!data) { + msg.type = FETCH_ERROR; + msg.data.error = "Cannot load rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + + c->datalen = len; + c->data = (char *)malloc(c->datalen); + if (c->data == NULL) { + msg.type = FETCH_ERROR; + msg.data.error = "Unable to allocate memory for rsrc: URL"; + fetch_rsrc_send_callback(&msg, c); + return false; + } + memcpy(c->data, data, c->datalen); + + return true; +} + +static void fetch_rsrc_poll(lwc_string *scheme) +{ + fetch_msg msg; + struct fetch_rsrc_context *c, *next; + + if (ring == NULL) return; + + /* Iterate over ring, processing each pending fetch */ + c = ring; + do { + /* Take a copy of the next pointer as we may destroy + * the ring item we're currently processing */ + next = c->r_next; + + /* Ignore fetches that have been flagged as locked. + * This allows safe re-entrant calls to this function. + * Re-entrancy can occur if, as a result of a callback, + * the interested party causes fetch_poll() to be called + * again. + */ + if (c->locked == true) { + continue; + } + + /* Only process non-aborted fetches */ + if (!c->aborted && fetch_rsrc_process(c) == true) { + char header[64]; + + fetch_set_http_code(c->parent_fetch, 200); + LOG(("setting rsrc: MIME type to %s, length to %zd", + c->mimetype, c->datalen)); + /* Any callback can result in the fetch being aborted. + * Therefore, we _must_ check for this after _every_ + * call to fetch_rsrc_send_callback(). + */ + snprintf(header, sizeof header, "Content-Type: %s", + c->mimetype); + msg.type = FETCH_HEADER; + msg.data.header_or_data.buf = (const uint8_t *) header; + msg.data.header_or_data.len = strlen(header); + fetch_rsrc_send_callback(&msg, c); + + snprintf(header, sizeof header, "Content-Length: %zd", + c->datalen); + msg.type = FETCH_HEADER; + msg.data.header_or_data.buf = (const uint8_t *) header; + msg.data.header_or_data.len = strlen(header); + fetch_rsrc_send_callback(&msg, c); + + if (!c->aborted) { + msg.type = FETCH_DATA; + msg.data.header_or_data.buf = (const uint8_t *) c->data; + msg.data.header_or_data.len = c->datalen; + fetch_rsrc_send_callback(&msg, c); + } + if (!c->aborted) { + msg.type = FETCH_FINISHED; + fetch_rsrc_send_callback(&msg, c); + } + } else { + LOG(("Processing of %s failed!", c->url)); + + /* Ensure that we're unlocked here. If we aren't, + * then fetch_rsrc_process() is broken. + */ + assert(c->locked == false); + } + + fetch_remove_from_queues(c->parent_fetch); + fetch_free(c->parent_fetch); + + /* Advance to next ring entry, exiting if we've reached + * the start of the ring or the ring has become empty + */ + } while ( (c = next) != ring && ring != NULL); +} + +/* BAppFileInfo is supposed to find the app's resources for us, + * but this won't work if we ever want to be used as a replicant. + * This trick should work regardless, + */ +static int find_app_resources() +{ + char path[B_PATH_NAME_LENGTH]; + if (nsbeos_find_app_path(path) < B_OK) + return B_ERROR; +//fprintf(stderr, "loading resources from '%s'\n", path); + + BFile file(path, B_READ_ONLY); + if (file.InitCheck() < 0) + return file.InitCheck(); + gAppResources = new BResources; + status_t err; + err = gAppResources->SetTo(&file); + if (err >= B_OK) + return B_OK; + delete gAppResources; + gAppResources = NULL; + return err; +} + +BResources *get_app_resources() +{ + return gAppResources; +} + +void fetch_rsrc_register(void) +{ + lwc_string *scheme; + int err; + + err = find_app_resources(); + + if (err < B_OK) { + warn_user("Resources", strerror(err)); + return; + } + + if (lwc_intern_string("rsrc", SLEN("rsrc"), &scheme) != lwc_error_ok) { + die("Failed to initialise the fetch module " + "(couldn't intern \"rsrc\")."); + } + + fetch_add_fetcher(scheme, + fetch_rsrc_initialise, + fetch_rsrc_can_fetch, + fetch_rsrc_setup, + fetch_rsrc_start, + fetch_rsrc_abort, + fetch_rsrc_free, + fetch_rsrc_poll, + fetch_rsrc_finalise); +} + +void fetch_rsrc_unregister(void) +{ + delete gAppResources; + gAppResources = NULL; +} diff --git a/beos/fetch_rsrc.h b/beos/fetch_rsrc.h new file mode 100644 index 000000000..ce17670a4 --- /dev/null +++ b/beos/fetch_rsrc.h @@ -0,0 +1,35 @@ +/* + * Copyright 2008 François Revol + * Copyright 2008 Rob Kendrick + * + * This file is part of NetSurf. + * + * 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 . + */ + +/** \file + * rsrc: URL method handler + */ + +#ifndef NETSURF_BEOS_FETCH_DATA_H +#define NETSURF_BEOS_FETCH_DATA_H + +void fetch_rsrc_register(void); +void fetch_rsrc_unregister(void); + +class BResources; +BResources *get_app_resources(); + +#include "beos/res.h" + +#endif diff --git a/beos/filetype.cpp b/beos/filetype.cpp new file mode 100644 index 000000000..7975041ac --- /dev/null +++ b/beos/filetype.cpp @@ -0,0 +1,143 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +extern "C" { +#include "content/fetch.h" +#include "utils/log.h" +#include "utils/hashtable.h" +#include "utils/utils.h" +} + +#include "beos/filetype.h" + +static struct { + const char *type; + const char *ext1; + const char *ext2; +} default_types[] = { + { "text/plain", "txt", NULL }, + { "text/html", "htm", "html" }, + { "text/css", "css", NULL }, + { "image/gif", "gif", NULL }, + { "image/jpeg", "jpg", "jpeg" }, + { "image/png", "png", NULL }, + { "image/jng", "jng", NULL }, + { NULL, NULL, NULL } +}; + +void beos_fetch_filetype_init(void) +{ + BMimeType m; + status_t err; + int i; + + // make sure we have basic mime types in the database + for (i = 0; default_types[i].type; i++) { + if (m.SetTo(default_types[i].type) < B_OK) + continue; + if (m.IsInstalled()) + continue; + err = m.Install(); + if (err < B_OK) { + warn_user("Mime", strerror(err)); + continue; + } + // the mime db doesn't know about it yet + BMessage extensions(0UL); + if (default_types[i].ext1) + extensions.AddString("extensions", default_types[i].ext1); + if (default_types[i].ext2) + extensions.AddString("extensions", default_types[i].ext2); + err = m.SetFileExtensions(&extensions); + if (err < B_OK) { + warn_user("Mime", strerror(err)); + } + } +} + +void beos_fetch_filetype_fin(void) +{ +} + +const char *fetch_filetype(const char *unix_path) +{ + struct stat statbuf; + status_t err; + int i; + // NOT THREADSAFE + static char type[B_MIME_TYPE_LENGTH]; + + // override reading the mime type for known types + // avoids getting CSS files as text/x-source-code + // even though it's the mime sniffer rules that should be fixed. + BString ext(unix_path); + ext.Remove(0, ext.FindLast('.') + 1); + for (i = 0; default_types[i].type; i++) { + if (ext == default_types[i].ext1) + return default_types[i].type; + if (ext == default_types[i].ext2) + return default_types[i].type; + } + + BEntry entry(unix_path, true); + BNode node(&entry); + err = node.InitCheck(); + if (err < B_OK) + return "text/plain"; + + if (node.IsDirectory()) + return "application/x-netsurf-directory"; + + BNodeInfo info(&node); + err = info.InitCheck(); + if (err < B_OK) + return "test/plain"; + + err = info.GetType(type); + if (err < B_OK) { + // not there yet, sniff and retry + err = update_mime_info(unix_path, false, true, false); + if (err < B_OK) + return "text/plain"; + err = info.GetType(type); + if (err < B_OK) + return "text/plain"; + } + + return type; +} + +char *fetch_mimetype(const char *unix_path) +{ + return strdup(fetch_filetype(unix_path)); +} + diff --git a/beos/filetype.h b/beos/filetype.h new file mode 100644 index 000000000..ab0ef410f --- /dev/null +++ b/beos/filetype.h @@ -0,0 +1,20 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +void beos_fetch_filetype_init(void); +void beos_fetch_filetype_fin(void); diff --git a/beos/font.cpp b/beos/font.cpp new file mode 100644 index 000000000..a7b1a0c96 --- /dev/null +++ b/beos/font.cpp @@ -0,0 +1,376 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +/** \file + * Font handling (BeOS implementation). + * TODO: check for correctness, the code is taken from the GTK one. + * maybe use the current view instead of constructing a new BFont each time ? + */ + + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +extern "C" { +#include "css/css.h" +#include "render/font.h" +#include "utils/utils.h" +#include "utils/log.h" +#include "desktop/options.h" +} + +#include "beos/gui.h" +#include "beos/font.h" +#include "beos/plotters.h" + +static bool nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, + int *width); +static bool nsfont_position_in_string(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); +static bool nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x); + +const struct font_functions nsfont = { + nsfont_width, + nsfont_position_in_string, + nsfont_split +}; + + +/** + * Measure the width of a string. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param width updated to width of string[0..length) + * \return true on success, false on error and error reported + */ + +bool nsfont_width(const plot_font_style_t *fstyle, + const char *string, size_t length, + int *width) +{ + //fprintf(stderr, "%s(, '%s', %d, )\n", __FUNCTION__, string, length); + BFont font; + + if (length == 0) { + *width = 0; + return true; + } + + nsbeos_style_to_font(font, fstyle); + *width = (int)font.StringWidth(string, length); + return true; +} + + +static int utf8_char_len(const char *c) +{ + uint8 *p = (uint8 *)c; + uint8 m = 0xE0; + uint8 v = 0xC0; + int i; + if (!*p) + return 0; + if ((*p & 0x80) == 0) + return 1; + if ((*p & 0xC0) == 0x80) + return 1; // actually one of the remaining bytes... + for (i = 2; i < 5; i++) { + if ((*p & m) == v) + return i; + v = (v >> 1) | 0x80; + m = (m >> 1) | 0x80; + } + return i; +} + + +/** + * Find the position in a string where an x coordinate falls. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param x x coordinate to search for + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + */ + +bool nsfont_position_in_string(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + //LOG(("(, '%s', %d, %d, , )", string, length, x)); + //fprintf(stderr, "%s(, '%s', %d, %d, , )\n", __FUNCTION__, string, length, x); + int index; + BFont font; + + nsbeos_style_to_font(font, fstyle); + BString str(string); + int32 len = str.CountChars(); + float escapements[len]; + float esc = 0.0; + float current = 0.0; + int i; + index = 0; + font.GetEscapements(string, len, escapements); + // slow but it should work + for (i = 0; string[index] && i < len; i++) { + if (x < current) + break; + esc += escapements[i]; + current = font.Size() * esc; + index += utf8_char_len(&string[index]); + } + *actual_x = (int)current; + *char_offset = i; //index; + + return true; +} + + +/** + * Find where to split a string to make it fit a width. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param x width available + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + * + * On exit, [char_offset == 0 || + * string[char_offset] == ' ' || + * char_offset == length] + */ + +bool nsfont_split(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + //fprintf(stderr, "%s(, '%s', %d, %d, , )\n", __FUNCTION__, string, length, x); + //LOG(("(, '%s', %d, %d, , )", string, length, x)); + int index = 0; + BFont font; + + nsbeos_style_to_font(font, fstyle); + BString str(string); + int32 len = str.CountChars(); + float escapements[len]; + float esc = 0.0; + float current = 0.0; + float last_x = 0.0; + int i; + int last_space = 0; + font.GetEscapements(string, len, escapements); + // slow but it should work + for (i = 0; string[index] && i < len; i++) { + if (string[index] == ' ') { + last_x = current; + last_space = index; + } + if (x < current) { + *actual_x = (int)last_x; + *char_offset = last_space; + return true; + } + esc += escapements[i]; + current = font.Size() * esc; + index += utf8_char_len(&string[index]); + } + *actual_x = MIN(*actual_x, (int)current); + *char_offset = index; + + return true; +} + + +/** + * Render a string. + * + * \param fstyle style for this text + * \param string UTF-8 string to measure + * \param length length of string + * \param x x coordinate + * \param y y coordinate + * \return true on success, false on error and error reported + */ + +bool nsfont_paint(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, int y) +{ + //fprintf(stderr, "%s(, '%s', %d, %d, %d, )\n", __FUNCTION__, string, length, x, y); + //CALLED(); + BFont font; + rgb_color oldbg; + rgb_color background; + rgb_color foreground; + BView *view; + float size; + + if (length == 0) + return true; + + nsbeos_style_to_font(font, fstyle); + background = nsbeos_rgb_colour(fstyle->background); + foreground = nsbeos_rgb_colour(fstyle->foreground); + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + oldbg = view->LowColor(); + drawing_mode oldmode = view->DrawingMode(); +#if 0 + if (oldbg != background) + view->SetLowColor(background); +#endif + view->SetLowColor(B_TRANSPARENT_32_BIT); + + //view->SetScale() XXX + +//printf("nsfont_paint: Size: %f\n", font.Size()); + size = (float)font.Size(); +#warning XXX use scale + + view->SetFont(&font); + view->SetHighColor(foreground); + view->SetDrawingMode(B_OP_OVER); + + BString line(string, length); + + BPoint where(x, y + 1); + view->DrawString(line.String(), where); + + view->SetDrawingMode(oldmode); + if (memcmp(&oldbg, &background, sizeof(rgb_color))) + view->SetLowColor(oldbg); + + //nsbeos_current_gc_unlock(); + + return true; +} + + +/** + * Convert a font style to a PangoFontDescription. + * + * \param fstyle style for this text + * \return a new Pango font description + */ + +void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle) +{ + float size; + uint16 face = 0; + const char *family; + + switch (fstyle->family) { + case PLOT_FONT_FAMILY_SERIF: + family = nsoption_charp(font_serif); + break; + case PLOT_FONT_FAMILY_MONOSPACE: + family = nsoption_charp(font_mono); + break; + case PLOT_FONT_FAMILY_CURSIVE: + family = nsoption_charp(font_cursive); + break; + case PLOT_FONT_FAMILY_FANTASY: + family = nsoption_charp(font_fantasy); + break; + case PLOT_FONT_FAMILY_SANS_SERIF: + default: + family = nsoption_charp(font_sans); + break; + } + + if ((fstyle->flags & FONTF_ITALIC)) { + face = B_ITALIC_FACE; + } else if ((fstyle->flags & FONTF_OBLIQUE)) { + face = B_ITALIC_FACE; + // XXX: no OBLIQUE flag ?? + // maybe find "Oblique" style + // or use SetShear() ? + } + +#ifndef __HAIKU__XXX + if (fstyle->weight >= 600) { + face |= B_BOLD_FACE; + } +#else + if (fstyle->weight >= 600) { + if (fstyle->weight >= 800) + face |= B_HEAVY_FACE; + else + face |= B_BOLD_FACE; + } else if (fstyle->weight <= 300) { + face |= B_LIGHT_FACE; + } +#endif +/* + case CSS_FONT_WEIGHT_100: weight = 100; break; + case CSS_FONT_WEIGHT_200: weight = 200; break; + case CSS_FONT_WEIGHT_300: weight = 300; break; + case CSS_FONT_WEIGHT_400: weight = 400; break; + case CSS_FONT_WEIGHT_500: weight = 500; break; + case CSS_FONT_WEIGHT_600: weight = 600; break; + case CSS_FONT_WEIGHT_700: weight = 700; break; + case CSS_FONT_WEIGHT_800: weight = 800; break; + case CSS_FONT_WEIGHT_900: weight = 900; break; +*/ + + if (!face) + face = B_REGULAR_FACE; + +//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face); + + if (family) { + font_family beos_family; + + strncpy(beos_family, family, B_FONT_FAMILY_LENGTH); + // Ensure it's terminated + beos_family[B_FONT_FAMILY_LENGTH] = '\0'; + + font.SetFamilyAndFace(beos_family, face); + } else { + //XXX not used + font = be_plain_font; + font.SetFace(face); + } + +//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit); + size = fstyle->size / FONT_SIZE_SCALE; + +//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit); + + font.SetSize(size); +} diff --git a/beos/font.h b/beos/font.h new file mode 100644 index 000000000..aefd898da --- /dev/null +++ b/beos/font.h @@ -0,0 +1,31 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +/** \file + * Font handling (GTK interface). + */ + +#include + +#include "desktop/plotters.h" + +bool nsfont_paint(const plot_font_style_t *fstyle, + const char *string, size_t length, + int x, int y); + +void nsbeos_style_to_font(BFont &font, const plot_font_style_t *fstyle); diff --git a/beos/gui.cpp b/beos/gui.cpp new file mode 100644 index 000000000..0c3075006 --- /dev/null +++ b/beos/gui.cpp @@ -0,0 +1,1195 @@ +/* + * Copyright 2008 François Revol + * Copyright 2005 James Bursa + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +extern "C" { + +#include "content/content.h" +#include "content/content_protected.h" +#include "content/fetch.h" +#include "content/fetchers/curl.h" +#include "content/fetchers/resource.h" +#include "content/urldb.h" +#include "desktop/401login.h" +#include "desktop/browser.h" +#include "desktop/cookies.h" +#include "desktop/gui.h" +#include "desktop/netsurf.h" +#include "desktop/options.h" + +#include "render/box.h" +#include "render/form.h" +#include "render/html.h" +#include "utils/filename.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "utils/utf8.h" +#include "utils/utils.h" +} + +#include "beos/gui.h" + +#include "beos/gui_options.h" +//#include "beos/completion.h" +#include "beos/window.h" +#include "beos/throbber.h" +#include "beos/filetype.h" +//#include "beos/download.h" +#include "beos/schedule.h" +#include "beos/fetch_rsrc.h" +#include "beos/scaffolding.h" + + +static void *myrealloc(void *ptr, size_t len, void *pw); +void gui_init(int argc, char** argv); + + +/* Where to search for shared resources. Must have trailing / */ +#define RESPATH "/boot/apps/netsurf/res/" + +//TODO: use resources +// enable using resources instead of files +#define USE_RESOURCES 1 + +bool replicated = false; /**< if we are running as a replicant */ + +char *options_file_location; +char *glade_file_location; + +struct gui_window *search_current_window = 0; + +BWindow *wndAbout; +BWindow *wndWarning; +//GladeXML *gladeWindows; +BWindow *wndTooltip; +//beosLabel *labelTooltip; +BFilePanel *wndOpenFile; + +//static beosWidget *select_menu; +static struct browser_window *select_menu_bw; +static struct form_control *select_menu_control; + +static thread_id sBAppThreadID; + +static BMessage *gFirstRefsReceived = NULL; + +static int sEventPipe[2]; + +#if 0 /* GTK */ +static void nsbeos_create_ssl_verify_window(struct browser_window *bw, + hlcache_handle *c, const struct ssl_cert_info *certs, + unsigned long num); +static void nsbeos_ssl_accept(BButton *w, gpointer data); +static void nsbeos_ssl_reject(BButton *w, gpointer data); +static void nsbeos_select_menu_clicked(BCheckMenuItem *checkmenuitem, + gpointer user_data); +#endif + +// #pragma mark - class NSBrowserFrameView + + +NSBrowserApplication::NSBrowserApplication() + : BApplication("application/x-vnd.NetSurf") +{ +} + + +NSBrowserApplication::~NSBrowserApplication() +{ +} + + +void +NSBrowserApplication::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_REFS_RECEIVED: + // messages for top-level + // we'll just send them to the first window + case 'back': + case 'forw': + case 'stop': + case 'relo': + case 'home': + case 'urlc': + case 'urle': + case 'menu': + // NetPositive messages + case B_NETPOSITIVE_OPEN_URL: + case B_NETPOSITIVE_BACK: + case B_NETPOSITIVE_FORWARD: + case B_NETPOSITIVE_HOME: + case B_NETPOSITIVE_RELOAD: + case B_NETPOSITIVE_STOP: + case B_NETPOSITIVE_DOWN: + case B_NETPOSITIVE_UP: + //DetachCurrentMessage(); + //nsbeos_pipe_message(message, this, fGuiWindow); + break; + default: + BApplication::MessageReceived(message); + } +} + + +void +NSBrowserApplication::ArgvReceived(int32 argc, char **argv) +{ + CALLED(); + NSBrowserWindow *win = nsbeos_find_last_window(); + if (!win) { + return; + } + win->Unlock(); + BMessage *message = DetachCurrentMessage(); + nsbeos_pipe_message_top(message, win, win->Scaffolding()); +} + + +void +NSBrowserApplication::RefsReceived(BMessage *message) +{ + CALLED(); + DetachCurrentMessage(); + NSBrowserWindow *win = nsbeos_find_last_window(); + if (!win) { + gFirstRefsReceived = message; + return; + } + win->Unlock(); + nsbeos_pipe_message_top(message, win, win->Scaffolding()); +} + + +void +NSBrowserApplication::AboutRequested() +{ + nsbeos_pipe_message(new BMessage(B_ABOUT_REQUESTED), NULL, NULL); +} + + +bool +NSBrowserApplication::QuitRequested() +{ + // let it notice it + nsbeos_pipe_message(new BMessage(B_QUIT_REQUESTED), NULL, NULL); + // we'll let the main thread Quit() ourselves when it's done. + return false; +} + + +// #pragma mark - implementation + + +// XXX doesn't work +#if 0 +static char *generate_default_css() +{ + BString text; + rgb_color colBg = { 255, 255, 255, 255 }; + rgb_color colFg = { 0, 0, 0, 255 }; + rgb_color colControlBg = { 255, 255, 255, 255 }; + rgb_color colControlFg = { 0, 0, 0, 255 }; + const char *url = "file://beosdefault.css"; + + text << "/*\n"; + text << " * This file is part of NetSurf, http://netsurf-browser.org/\n"; + text << " */\n"; + text << "\n"; + text << "/* Load base stylesheet. */\n"; + text << "\n"; + text << "@import \"default.css\";\n"; + text << "\n"; + text << "/* Apply BeOS specific rules. */\n"; + text << "\n"; + text << "\n"; + text << "\n"; + text << "\n"; + + text << "input { font-size: 95%; border: medium inset #ddd; }\n"; + text << "input[type=button], input[type=reset], input[type=submit], button {\n"; + text << " background-color: #ddd; border: medium outset #ddd; }\n"; + text << "input[type=checkbox], input[type=radio] { font-size: 105%; }\n"; + text << "input[type=file] { background-color: #ddd; border: medium inset #ddd; }\n"; + text << "\n"; + text << "select { background-color: #ddd; border: medium inset #ddd; font-size: 95%; }\n"; + text << "select:after { border-left:4px ridge #ddd; }\n"; + text << "\n"; + text << "textarea { font-size: 95%; border: medium inset #ddd; }\n"; + + struct content *c; + c = content_create(url); + if (c == NULL) + return NULL; + + const char *params[] = { 0 }; + if (!content_set_type(c, CONTENT_CSS, "text/css", params, NULL)) + return NULL; + + if (!content_process_data(c, text.String(), text.Length())) + return NULL; + + content_set_done(c); + + return strdup(url); +} +#endif + +/* realpath fallback on R5 */ +#if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO) +extern "C" char *realpath(const char *f, char *buf); +char *realpath(const char *f, char *buf) +{ + BPath path(f, NULL, true); + if (path.InitCheck() < 0) { + strncpy(buf, f, MAXPATHLEN); + return NULL; + } + //printf("RP: '%s'\n", path.Path()); + strncpy(buf, path.Path(), MAXPATHLEN); + return buf; +} +#endif + +/* finds the NetSurf binary image ID and path + * + */ +image_id nsbeos_find_app_path(char *path) +{ + image_info info; + int32 cookie = 0; + while (get_next_image_info(0, &cookie, &info) == B_OK) { +//fprintf(stderr, "%p <> %p, %p\n", (char *)&find_app_resources, (char *)info.text, (char *)info.text + info.text_size); + if (((char *)&nsbeos_find_app_path >= (char *)info.text) + && ((char *)&nsbeos_find_app_path < (char *)info.text + info.text_size)) { +//fprintf(stderr, "match\n"); + if (path) { + memset(path, 0, B_PATH_NAME_LENGTH); + strncpy(path, info.name, B_PATH_NAME_LENGTH-1); + } + return info.id; + } + } + return B_ERROR; +} + +/** + * Locate a shared resource file by searching known places in order. + * + * \param buf buffer to write to. must be at least PATH_MAX chars + * \param filename file to look for + * \param def default to return if file not found + * \return buf + * + * Search order is: ~/config/settings/NetSurf/, ~/.netsurf/, $NETSURFRES/ + * (where NETSURFRES is an environment variable), and finally the path + * specified by the #define at the top of this file. + */ + +static char *find_resource(char *buf, const char *filename, const char *def) +{ + CALLED(); + const char *cdir = NULL; + status_t err; + BPath path; + char t[PATH_MAX]; + + err = find_directory(B_USER_SETTINGS_DIRECTORY, &path); + path.Append("NetSurf"); + if (err >= B_OK) + cdir = path.Path(); + if (cdir != NULL) { + strcpy(t, cdir); + strcat(t, "/"); + strcat(t, filename); + realpath(t, buf); + if (access(buf, R_OK) == 0) + return buf; + } + + cdir = getenv("HOME"); + if (cdir != NULL) { + strcpy(t, cdir); + strcat(t, "/.netsurf/"); + strcat(t, filename); + realpath(t, buf); + if (access(buf, R_OK) == 0) + return buf; + } + + cdir = getenv("NETSURFRES"); + + if (cdir != NULL) { + realpath(cdir, buf); + strcat(buf, "/"); + strcat(buf, filename); + if (access(buf, R_OK) == 0) + return buf; + } + + strcpy(t, RESPATH); + strcat(t, filename); + realpath(t, buf); + if (access(buf, R_OK) == 0) + return buf; + + if (def[0] == '%') { + snprintf(t, PATH_MAX, "%s%s", path.Path(), def + 1); + realpath(t, buf); + } else if (def[0] == '~') { + snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1); + realpath(t, buf); + } else { + realpath(def, buf); + } + + return buf; +} + +/** + * Check that ~/.netsurf/ exists, and if it doesn't, create it. + */ +static void check_homedir(void) +{ + CALLED(); + status_t err; + + BPath path; + err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); + + if (err < B_OK) { + /* we really can't continue without a home directory. */ + LOG(("Can't find user settings directory - nowhere to store state!")); + die("NetSurf needs to find the user settings directory in order to run.\n"); + } + + path.Append("NetSurf"); + err = create_directory(path.Path(), 0644); + if (err < B_OK) { + LOG(("Unable to create %s", path.Path())); + die("NetSurf could not create its settings directory.\n"); + } +} + +static int32 bapp_thread(void *arg) +{ + be_app->Lock(); + be_app->Run(); + return 0; +} + +nsurl *gui_get_resource_url(const char *path) +{ + nsurl *url = NULL; + BString u("rsrc:///"); + if (strcmp(path, "default.css") == 0) + u << "beosdefault.css"; + else + u << path; + fprintf(stderr, "%s(%s) -> '%s'\n", __FUNCTION__, path, u.String()); + nsurl_create(u.String(), &url); + return url; +} + +static void gui_init2(int argc, char** argv) +{ + CALLED(); + const char *addr = NETSURF_HOMEPAGE; + + if (nsoption_charp(homepage_url) != NULL) + addr = nsoption_charp(homepage_url); + + if (argc > 1) addr = argv[1]; + if (gFirstRefsReceived) addr = NULL; + browser_window_create(addr, 0, 0, true, false); + if (gFirstRefsReceived) { + // resend the refs we got before having a window to send them to + be_app_messenger.SendMessage(gFirstRefsReceived); + delete gFirstRefsReceived; + gFirstRefsReceived = NULL; + } +} + +/** Normal entry point from OS */ +int main(int argc, char** argv) +{ + char buf[PATH_MAX]; + setbuf(stderr, NULL); + + BPath options; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { + options.Append("x-vnd.NetSurf"); + } + + find_resource(buf, "messages", "./beos/res/messages"); + LOG(("Using '%s' as Messages file", buf)); + //messages_load(buf); + + /* initialise netsurf */ + netsurf_init(&argc, &argv, options.Path(), buf); + + gui_init(argc, argv); + gui_init2(argc, argv); + + netsurf_main_loop(); + + netsurf_exit(); + + return 0; +} + + +void gui_init(int argc, char** argv) +{ + char buf[PATH_MAX]; + CALLED(); + + if (pipe(sEventPipe) < 0) + return; + if (!replicated) { + new NSBrowserApplication; + sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); + if (sBAppThreadID < B_OK) + return; /* #### handle errors */ + if (resume_thread(sBAppThreadID) < B_OK) + return; + } + + // ui_color() gives hardcoded values before BApplication is created. + nsbeos_update_system_ui_colors(); + + fetch_rsrc_register(); + + check_homedir(); + + // make sure the cache dir exists + create_directory(TEMP_FILENAME_PREFIX, 0600); + + //nsbeos_completion_init(); + + + /* This is an ugly hack to just get the new-style throbber going. + * It, along with the PNG throbber loader, need making more generic. + */ + { +#define STROF(n) #n +#define FIND_THROB(n) filenames[(n)] = \ + "throbber" STROF(n) ".png"; + char *filenames[9]; + FIND_THROB(0); + FIND_THROB(1); + FIND_THROB(2); + FIND_THROB(3); + FIND_THROB(4); + FIND_THROB(5); + FIND_THROB(6); + FIND_THROB(7); + FIND_THROB(8); + nsbeos_throbber_initialise_from_png(9, + filenames[0], filenames[1], filenames[2], filenames[3], + filenames[4], filenames[5], filenames[6], filenames[7], + filenames[8]); +#undef FIND_THROB +#undef STROF + } + +#if 0 + find_resource(buf, "throbber.gif", "./beos/res/throbber.gif"); + nsbeos_throbber_initialise_from_gif(buf); +#endif + + if (nsbeos_throbber == NULL) + die("Unable to load throbber image.\n"); + + find_resource(buf, "Choices", "%/Choices"); + LOG(("Using '%s' as Preferences file", buf)); + options_file_location = strdup(buf); + nsoption_read(buf); + + + /* check what the font settings are, setting them to a default font + * if they're not set - stops Pango whinging + */ + + //XXX: use be_plain_font & friends, when we can check if font is serif or not. +/* + font_family family; + font_style style; + be_plain_font->GetFamilyAndStyle(&family, &style); + nsoption_setnull_charp(font_sans, family); + nsoption_setnull_charp(font_serif, family); + nsoption_setnull_charp(font_mono, family); + nsoption_setnull_charp(font_cursive, family); + nsoption_setnull_charp(font_fantasy, family); +*/ +#ifdef __HAIKU__ + nsoption_setnull_charp(font_sans, "DejaVu Sans"); + nsoption_setnull_charp(font_serif, "DejaVu Serif"); + nsoption_setnull_charp(font_mono, "DejaVu Mono"); + nsoption_setnull_charp(font_cursive, "DejaVu Sans"); + nsoption_setnull_charp(font_fantasy, "DejaVu Sans"); +#else + nsoption_setnull_charp(font_sans, "Bitstream Vera Sans"); + nsoption_setnull_charp(font_serif, "Bitstream Vera Serif"); + nsoption_setnull_charp(font_mono, "Bitstream Vera Sans Mono"); + nsoption_setnull_charp(font_cursive, "Bitstream Vera Serif"); + nsoption_setnull_charp(font_fantasy, "Bitstream Vera Serif"); +#if 0 + nsoption_setnull_charp(font_sans, "Swis721 BT"); + nsoption_setnull_charp(font_serif, "Dutch801 Rm BT"); + //nsoption_setnull_charp(font_mono, "Monospac821 BT"); + nsoption_setnull_charp(font_mono, "Courier10 BT"); + nsoption_setnull_charp(font_cursive, "Swis721 BT"); + nsoption_setnull_charp(font_fantasy, "Swis721 BT"); +#endif +#endif + + nsbeos_options_init(); + + if (nsoption_charp(cookie_file) == NULL) { + find_resource(buf, "Cookies", "%/Cookies"); + LOG(("Using '%s' as Cookies file", buf)); + nsoption_set_charp(cookie_file, strdup(buf)); + } + if (nsoption_charp(cookie_jar) == NULL) { + find_resource(buf, "Cookies", "%/Cookies"); + LOG(("Using '%s' as Cookie Jar file", buf)); + nsoption_set_charp(cookie_jar, strdup(buf)); + } + if ((nsoption_charp(cookie_file) == NULL) || + (nsoption_charp(cookie_jar) == NULL)) + die("Failed initialising cookie options"); + + if (nsoption_charp(url_file) == NULL) { + find_resource(buf, "URLs", "%/URLs"); + LOG(("Using '%s' as URL file", buf)); + nsoption_set_charp(url_file, strdup(buf)); + } + + if (nsoption_charp(ca_path) == NULL) { + find_resource(buf, "certs", "/etc/ssl/certs"); + LOG(("Using '%s' as certificate path", buf)); + nsoption_set_charp(ca_path, strdup(buf)); + } + + //find_resource(buf, "mime.types", "/etc/mime.types"); + beos_fetch_filetype_init(); + + urldb_load(nsoption_charp(url_file)); + urldb_load_cookies(nsoption_charp(cookie_file)); + + //nsbeos_download_initialise(); + + if (!replicated) + be_app->Unlock(); + +#if 0 /* GTK */ + wndAbout = beos_WINDOW(glade_xml_get_widget(gladeWindows, "wndAbout")); + beos_label_set_text(beos_LABEL( + glade_xml_get_widget(gladeWindows, "labelVersion")), + netsurf_version); + beos_image_set_from_file(beos_IMAGE( + glade_xml_get_widget(gladeWindows, "imageLogo")), + find_resource(buf, "netsurf-logo.png", "netsurf-logo.png")); + fontdesc = pango_font_description_from_string("Monospace 8"); + beos_widget_modify_font(beos_WIDGET( + glade_xml_get_widget(gladeWindows, "textviewGPL")), fontdesc); + + wndWarning = beos_WINDOW(glade_xml_get_widget(gladeWindows, "wndWarning")); + wndOpenFile = beos_DIALOG(glade_xml_get_widget(gladeWindows, "wndOpenFile")); +#endif +} + + + + +void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui) +{ + if (message == NULL) { + fprintf(stderr, "%s(NULL)!\n", __FUNCTION__); + return; + } + if (_this) + message->AddPointer("View", _this); + if (gui) + message->AddPointer("gui_window", gui); + int len = write(sEventPipe[1], &message, sizeof(void *)); + //LOG(("nsbeos_pipe_message: %d written", len)); + //printf("nsbeos_pipe_message: %d written\n", len); +} + + +void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold) +{ + if (message == NULL) { + fprintf(stderr, "%s(NULL)!\n", __FUNCTION__); + return; + } + if (_this) + message->AddPointer("Window", _this); + if (scaffold) + message->AddPointer("scaffolding", scaffold); + int len = write(sEventPipe[1], &message, sizeof(void *)); + //LOG(("nsbeos_pipe_message: %d written", len)); + //printf("nsbeos_pipe_message: %d written\n", len); +} + + +void gui_poll(bool active) +{ + //CALLED(); + CURLMcode code; + + fd_set read_fd_set, write_fd_set, exc_fd_set; + int max_fd = 0; + struct timeval timeout; + unsigned int fd_count = 0; + bool block = true; + + if (browser_reformat_pending) + block = false; + + FD_ZERO(&read_fd_set); + FD_ZERO(&write_fd_set); + FD_ZERO(&exc_fd_set); + + if (active) { + code = curl_multi_fdset(fetch_curl_multi, + &read_fd_set, + &write_fd_set, + &exc_fd_set, + &max_fd); + assert(code == CURLM_OK); + } + + // our own event pipe + FD_SET(sEventPipe[0], &read_fd_set); + max_fd = MAX(max_fd, sEventPipe[0] + 1); + + + bigtime_t next_schedule = earliest_callback_timeout - system_time(); + if (!block) + next_schedule = 0LL; // now + if (block && earliest_callback_timeout != B_INFINITE_TIMEOUT) + block = false; + timeout.tv_sec = (long)(next_schedule / 1000000LL); + timeout.tv_usec = (long)(next_schedule % 1000000LL); + LOG(("gui_poll: select(%d, ..., %Ldus", max_fd, next_schedule)); + + fd_count = select(max_fd, &read_fd_set, &write_fd_set, &exc_fd_set, + block ? NULL : &timeout); + + if (fd_count > 0 && FD_ISSET(sEventPipe[0], &read_fd_set)) { + BMessage *message; + int len = read(sEventPipe[0], &message, sizeof(void *)); + LOG(("gui_poll: BMessage ? %d read", len)); + if (len == sizeof(void *)) + nsbeos_dispatch_event(message); + } + + schedule_run(); + + if (browser_reformat_pending) + nsbeos_window_process_reformats(); +} + + +void gui_quit(void) +{ + CALLED(); + urldb_save_cookies(nsoption_charp(cookie_jar)); + urldb_save(nsoption_charp(url_file)); + //options_save_tree(hotlist,nsoption_charp(hotlist_file),messages_get("TreeHotlist")); + + free(nsoption_charp(cookie_file)); + free(nsoption_charp(cookie_jar)); + beos_fetch_filetype_fin(); + fetch_rsrc_unregister(); +} + + + +struct gui_download_window *gui_download_window_create(download_context *ctx, + struct gui_window *gui) +{ + return NULL; +} + + +nserror gui_download_window_data(struct gui_download_window *dw, + const char *data, unsigned int size) +{ + return NSERROR_OK; +} + + +void gui_download_window_error(struct gui_download_window *dw, + const char *error_msg) +{ +} + + +void gui_download_window_done(struct gui_download_window *dw) +{ +} + +#if 0 /* GTK */ +static void nsbeos_select_menu_clicked(BCheckMenuItem *checkmenuitem, + gpointer user_data) +{ + form_select_process_selection(select_menu_bw->current_content, + select_menu_control, (intptr_t)user_data); +} +#endif + +void gui_create_form_select_menu(struct browser_window *bw, + struct form_control *control) +{ + CALLED(); +#if 0 /* GTK */ + + intptr_t i; + struct form_option *option; + + beosWidget *menu_item; + + /* control->data.select.multiple is true if multiple selections + * are allowable. We ignore this, as the core handles it for us. + * Yay. \o/ + */ + + if (select_menu != NULL) + beos_widget_destroy(select_menu); + + select_menu = beos_menu_new(); + select_menu_bw = bw; + select_menu_control = control; + + for (i = 0, option = control->data.select.items; option; + i++, option = option->next) { + menu_item = beos_check_menu_item_new_with_label(option->text); + if (option->selected) + beos_check_menu_item_set_active( + beos_CHECK_MENU_ITEM(menu_item), TRUE); + + g_signal_connect(menu_item, "toggled", + G_CALLBACK(nsbeos_select_menu_clicked), (gpointer)i); + + beos_menu_shell_append(beos_MENU_SHELL(select_menu), menu_item); + } + + beos_widget_show_all(select_menu); + + beos_menu_popup(beos_MENU(select_menu), NULL, NULL, NULL, + NULL /* data */, 0, beos_get_current_event_time()); + +#endif +} + +void +gui_window_save_link(struct gui_window *g, const char *url, const char *title) +{ +} + +/** + * Send the source of a content to a text editor. + */ + +void nsbeos_gui_view_source(struct hlcache_handle *content, struct selection *selection) +{ + char *temp_name; + bool done = false; + BPath path; + status_t err; + size_t size; + const char *source = content_get_source_data(content, &size); + + if (!content || !source) { + warn_user("MiscError", "No document source"); + return; + } + + /* try to load local files directly. */ + temp_name = url_to_path(nsurl_access(hlcache_handle_get_url(content))); + if (temp_name) { + path.SetTo(temp_name); + BEntry entry; + if (entry.SetTo(path.Path()) >= B_OK + && entry.Exists() && entry.IsFile()) + done = true; + } + if (!done) { + /* We cannot release the requested filename until after it + * has finished being used. As we can't easily find out when + * this is, we simply don't bother releasing it and simply + * allow it to be re-used next time NetSurf is started. The + * memory overhead from doing this is under 1 byte per + * filename. */ + const char *filename = filename_request(); + if (!filename) { + warn_user("NoMemory", 0); + return; + } + path.SetTo(TEMP_FILENAME_PREFIX); + path.Append(filename); + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); + err = file.InitCheck(); + if (err < B_OK) { + warn_user("IOError", strerror(err)); + return; + } + err = file.Write(source, size); + if (err < B_OK) { + warn_user("IOError", strerror(err)); + return; + } + lwc_string *mime = content_get_mime_type(content); + const char *mime_string = lwc_string_data(mime); + if (mime) + file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, + mime_string, lwc_string_length(mime) + 1); + + } + + entry_ref ref; + if (get_ref_for_path(path.Path(), &ref) < B_OK) + return; + + BMessage m(B_REFS_RECEIVED); + m.AddRef("refs", &ref); + +#if 0 + if (selection && selection->defined) { + int32 line = -1; + if (content_get_type(content) == CONTENT_HTML) { + // XXX: use selection, find line in source code + } + if (content_get_type(content) == CONTENT_TEXTPLAIN) { + line = MAKELINE_FROM_IDX(start_idx); + } + // not CSS! + + if (line > -1) + message.AddInt32("be:line", line); + } +#endif + + // apps to try + const char *editorSigs[] = { + "application/x-vnd.beunited.pe", + "application/x-vnd.XEmacs", + "application/x-vnd.Haiku-StyledEdit", + "application/x-vnd.Be-STEE", + "application/x-vnd.yT-STEE", + NULL + }; + int i; + for (i = 0; editorSigs[i]; i++) { + team_id team = -1; + { + BMessenger msgr(editorSigs[i], team); + if (msgr.SendMessage(&m) >= B_OK) + break; + } + + err = be_roster->Launch(editorSigs[i], (BMessage *)&m, &team); + if (err >= B_OK) + break; + } +} + +/** + * Broadcast an URL that we can't handle. + */ + +void gui_launch_url(const char *url) +{ + status_t status; + // try to open it as an URI + BString mimeType = "application/x-vnd.Be.URL."; + BString arg(url); + mimeType.Append(arg, arg.FindFirst(":")); + + // special case, text/x-email is used traditionally + // use it instead + if (arg.IFindFirst("mailto:") == 0) + mimeType = "text/x-email"; + + // the protocol should be alphanum + // we just check if it's registered + // if not there is likely no supporting app anyway + if (!BMimeType::IsValid(mimeType.String())) + return; + char *args[2] = { (char *)url, NULL }; + status = be_roster->Launch(mimeType.String(), 1, args); + if (status < B_OK) + warn_user("Cannot launch url", strerror(status)); +} + + +/** + * Display a warning for a serious problem (eg memory exhaustion). + * + * \param warning message key for warning message + * \param detail additional message, or 0 + */ + +void warn_user(const char *warning, const char *detail) +{ + LOG(("warn_user: %s (%s)", warning, detail)); + BAlert *alert; + BString text(warning); + if (detail) + text << ":\n" << detail; +#if 0 + alert = new BAlert("NetSurf Warning", text.String(), "Ok", NULL, NULL, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->Go(); +#else + alert = new BAlert("NetSurf Warning", text.String(), "Debug", "Ok", NULL, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); + if (alert->Go() < 1) + debugger("warn_user"); +#endif +} + +void die(const char * const error) +{ + fprintf(stderr, "%s", error); + BAlert *alert; + BString text("Cannot continue:\n"); + text << error; +#if 0 + alert = new BAlert("NetSurf Error", text.String(), "Ok", NULL, NULL, + B_WIDTH_AS_USUAL, B_STOP_ALERT); + alert->Go(); +#else + alert = new BAlert("NetSurf Error", text.String(), "Debug", "Ok", NULL, + B_WIDTH_AS_USUAL, B_STOP_ALERT); + if (alert->Go() < 1) + debugger("die"); +#endif + exit(EXIT_FAILURE); +} + +void gui_cert_verify(const char *url, const struct ssl_cert_info *certs, + unsigned long num, nserror (*cb)(bool proceed, void *pw), + void *cbpw) +{ + CALLED(); +#if 0 /* GTK */ + nsbeos_create_ssl_verify_window(bw, c, certs, num); +#endif +} + +static void nsbeos_create_ssl_verify_window(struct browser_window *bw, + hlcache_handle *c, const struct ssl_cert_info *certs, + unsigned long num) +{ + CALLED(); +#if 0 /* GTK */ + GladeXML *x = glade_xml_new(glade_file_location, NULL, NULL); + beosWindow *wnd = beos_WINDOW(glade_xml_get_widget(x, "wndSSLProblem")); + beosButton *accept, *reject; + void **session = calloc(sizeof(void *), 4); + + session[0] = bw; + session[1] = strdup(c->url); + session[2] = x; + session[3] = wnd; + + accept = beos_BUTTON(glade_xml_get_widget(x, "sslaccept")); + reject = beos_BUTTON(glade_xml_get_widget(x, "sslreject")); + + g_signal_connect(G_OBJECT(accept), "clicked", + G_CALLBACK(nsbeos_ssl_accept), (gpointer)session); + g_signal_connect(G_OBJECT(reject), "clicked", + G_CALLBACK(nsbeos_ssl_reject), (gpointer)session); + + beos_widget_show(beos_WIDGET(wnd)); +#endif +} + +#if 0 /* GTK */ +static void nsbeos_ssl_accept(beosButton *w, gpointer data) +{ + void **session = data; + struct browser_window *bw = session[0]; + char *url = session[1]; + GladeXML *x = session[2]; + beosWindow *wnd = session[3]; + + urldb_set_cert_permissions(url, true); + browser_window_go(bw, url, 0, true); + + beos_widget_destroy(beos_WIDGET(wnd)); + g_object_unref(G_OBJECT(x)); + free(url); + free(session); +} + +static void nsbeos_ssl_reject(beosButton *w, gpointer data) +{ + void **session = data; + GladeXML *x = session[2]; + beosWindow *wnd = session[3]; + + beos_widget_destroy(beos_WIDGET(wnd)); + g_object_unref(G_OBJECT(x)); + free(session[1]); + free(session); +} +#endif + +utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, + char **result) +{ + assert(string && result); + + if (len == 0) + len = strlen(string); + + *result = strndup(string, len); + if (!(*result)) + return UTF8_CONVERT_NOMEM; + + return UTF8_CONVERT_OK; +} + +utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, + char **result) +{ + assert(string && result); + + if (len == 0) + len = strlen(string); + + *result = strndup(string, len); + if (!(*result)) + return UTF8_CONVERT_NOMEM; + + return UTF8_CONVERT_OK; +} + +char *path_to_url(const char *path) +{ + int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; + char *url = (char *)malloc(urllen); + + if (url == NULL) { + return NULL; + } + + if (*path == '/') { + path++; /* file: paths are already absolute */ + } + + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); + + return url; +} + +char *url_to_path(const char *url) +{ + char *url_path = curl_unescape(url, 0); + char *path; + + /* return the absolute path including leading / */ + path = strdup(url_path + (FILE_SCHEME_PREFIX_LEN - 1)); + curl_free(url_path); + + return path; +} + +bool cookies_update(const char *domain, const struct cookie_data *data) +{ + return true; +} + +static void *myrealloc(void *ptr, size_t len, void *pw) +{ + if (len == 0) { + free(ptr); + return NULL; + } + + return realloc(ptr, len); +} + +/** + * Return the filename part of a full path + * + * \param path full path and filename + * \return filename (will be freed with free()) + */ + +char *filename_from_path(char *path) +{ + char *leafname; + + leafname = strrchr(path, '/'); + if (!leafname) + leafname = path; + else + leafname += 1; + + return strdup(leafname); +} + +/** + * Add a path component/filename to an existing path + * + * \param path buffer containing path + free space + * \param length length of buffer "path" + * \param newpart string containing path component to add to path + * \return true on success + */ + +bool path_add_part(char *path, int length, const char *newpart) +{ + if(path[strlen(path) - 1] != '/') + strncat(path, "/", length); + + strncat(path, newpart, length); + + return true; +} diff --git a/beos/gui.h b/beos/gui.h new file mode 100644 index 000000000..6bbfa1dd1 --- /dev/null +++ b/beos/gui.h @@ -0,0 +1,71 @@ +/* + * Copyright 2008 François Revol + * Copyright 2005 James Bursa + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#ifndef B_BEOS_VERSION_DANO +#define B_UI_SETTINGS_CHANGED '_UIC' +#endif + +#define CALLED() fprintf(stderr, "%s()\n", __FUNCTION__); + +extern bool replicated; + +#if 0 /* GTK */ +//extern GladeXML *gladeWindows; +//extern char *glade_file_location; +#endif +extern char *options_file_location; + +class NSBrowserApplication : public BApplication { +public: + NSBrowserApplication(); +virtual ~NSBrowserApplication(); + +virtual void MessageReceived(BMessage *message); +virtual void RefsReceived(BMessage *message); +virtual void ArgvReceived(int32 argc, char **argv); + +virtual void AboutRequested(); +virtual bool QuitRequested(); +}; + + +extern void schedule_run(void); + +extern BWindow *wndAbout; + +extern BWindow *wndTooltip; +#if 0 /* GTK */ +//extern GtkLabel *labelTooltip; +#endif + +extern BFilePanel *wndOpenFile; + +void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui); +void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold); + +void nsbeos_gui_view_source(struct hlcache_handle *content, struct selection *selection); +image_id nsbeos_find_app_path(char *path); + +void nsbeos_update_system_ui_colors(void); diff --git a/beos/gui_options.cpp b/beos/gui_options.cpp new file mode 100644 index 000000000..62e6640c3 --- /dev/null +++ b/beos/gui_options.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2008 François Revol + * Copyright 2006 Rob Kendrick + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +extern "C" { +#include "utils/log.h" +#include "desktop/options.h" +} +#include "beos/gui.h" +#include "beos/scaffolding.h" +#include "beos/gui_options.h" + +#include +#include + +BWindow *wndPreferences; + +void nsbeos_options_init(void) { + /* set the widgets to reflect the current options */ + nsbeos_options_load(); +} + +void nsbeos_options_load(void) { +#warning WRITEME +} + + +void nsbeos_options_save(void) { +#warning WRITEME +} diff --git a/beos/gui_options.h b/beos/gui_options.h new file mode 100644 index 000000000..38aaf866a --- /dev/null +++ b/beos/gui_options.h @@ -0,0 +1,34 @@ +/* + * Copyright 2008 François Revol + * Copyright 2006 Rob Kendrick + * + * 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 . + */ + +#ifndef NETSURF_BEOS_OPTIONS_H +#define NETSURF_BEOS_OPTIONS_H + +#include + +#if 0 /* GTK */ +extern GtkWindow *wndPreferences; +#endif +extern BWindow *wndPreferences; + +void nsbeos_options_init(void); /** Init options and load window */ +void nsbeos_options_load(void); /** Load current options into window */ +void nsbeos_options_save(void); /** Save options from window */ + +#endif diff --git a/beos/login.cpp b/beos/login.cpp new file mode 100644 index 000000000..32860de20 --- /dev/null +++ b/beos/login.cpp @@ -0,0 +1,199 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +extern "C" { +#include "utils/log.h" +#include "content/content.h" +#include "content/urldb.h" +#include "desktop/browser.h" +#include "desktop/401login.h" +#include "desktop/gui.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "utils/utils.h" +} +#include "beos/gui.h" +#include "beos/scaffolding.h" +#include "beos/window.h" + +class LoginAlert : public BAlert { +public: + LoginAlert(nserror (*callback)(bool proceed, void *pw), + void *callbaclpw, + const char *url, + const char *host, + const char *realm, + const char *text); + virtual ~LoginAlert(); + void MessageReceived(BMessage *message); + +private: + BString fUrl; /**< URL being fetched */ + BString fHost; /**< Host for user display */ + BString fRealm; /**< Authentication realm */ + nserror (*fCallback)(bool proceed, void *pw); + void *fCallbackPw; + + BTextControl *fUserControl; + BTextControl *fPassControl; +}; + +static void create_login_window(const char *host, + const char *realm, const char *fetchurl, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + + +#define TC_H 25 +#define TC_MARGIN 10 + +LoginAlert::LoginAlert(nserror (*callback)(bool proceed, void *pw), + void *callbackpw, + const char *url, + const char *host, + const char *realm, + const char *text) + : BAlert("Login", text, "Cancel", "Ok", NULL, + B_WIDTH_AS_USUAL, B_WARNING_ALERT) +{ + fCallback = callback; + fCallbackPw = callbackpw; + fUrl = url; + fHost = host; + fRealm = realm; + + SetFeel(B_MODAL_SUBSET_WINDOW_FEEL); + /* + // XXX: can't do that anymore + nsbeos_scaffolding *s = nsbeos_get_scaffold(bw->window); + if (s) { + NSBrowserWindow *w = nsbeos_get_bwindow_for_scaffolding(s); + if (w) + AddToSubset(w); + }*/ + + // make space for controls + ResizeBy(0, 2 * TC_H); + MoveTo(AlertPosition(Frame().Width() + 1, + Frame().Height() + 1)); + + + BTextView *tv = TextView(); + BRect r(TC_MARGIN, tv->Bounds().bottom - 2 * TC_H, + tv->Bounds().right - TC_MARGIN, tv->Bounds().bottom - TC_H); + + fUserControl = new BTextControl(r, "user", "Username", "", + new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); + fUserControl->SetDivider(60); + tv->AddChild(fUserControl); + + r.OffsetBySelf(0, TC_H); + + fPassControl = new BTextControl(r, "pass", "Password", "", + new BMessage(), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT); + fPassControl->TextView()->HideTyping(true); + fPassControl->SetDivider(60); + tv->AddChild(fPassControl); + + SetShortcut(0, B_ESCAPE); +} + +LoginAlert::~LoginAlert() +{ +} + +void +LoginAlert::MessageReceived(BMessage *message) +{ + switch (message->what) { + case 'ALTB': + { + int32 which; + if (message->FindInt32("which", &which) < B_OK) + break; + // not 'Ok' + if (which != 1) + break; + BMessage *m = new BMessage(*message); + m->what = 'nsLO'; + m->AddString("URL", fUrl.String()); + m->AddString("Host", fHost.String()); + m->AddString("Realm", fRealm.String()); + m->AddPointer("callback", (void *)fCallback); + m->AddPointer("callback_pw", (void *)fCallbackPw); + m->AddString("User", fUserControl->Text()); + m->AddString("Pass", fPassControl->Text()); + BString auth(fUserControl->Text()); + auth << ":" << fPassControl->Text(); + m->AddString("Auth", auth.String()); + + // notify the main thread + // the event dispatcher will handle it + nsbeos_pipe_message(m, NULL, NULL); + } + break; + default: + break; + } + BAlert::MessageReceived(message); +} + + +void gui_401login_open(const char *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw) +{ + char *host; + url_func_result res; + + res = url_host(url, &host); + assert(res == URL_FUNC_OK); + + create_login_window(url, host, realm, cb, cbpw); + + free(host); +} + +//void create_login_window(struct browser_window *bw, const char *host, +// const char *realm, const char *fetchurl) +static void create_login_window(const char *url, const char *host, + const char *realm, nserror (*cb)(bool proceed, void *pw), + void *cbpw) +{ + BString r("Secure Area"); + if (realm) + r = realm; + BString text(/*messages_get(*/"Please login\n"); + text << "Realm: " << r << "\n"; + text << "Host: " << host << "\n"; + //text << "\n"; + + LoginAlert *a = new LoginAlert(cb, cbpw, url, host, r.String(), + text.String()); + // asynchronously + a->Go(NULL); + +} diff --git a/beos/plotters.cpp b/beos/plotters.cpp new file mode 100644 index 000000000..186627783 --- /dev/null +++ b/beos/plotters.cpp @@ -0,0 +1,894 @@ +/* + * Copyright 2008 François Revol + * Copyright 2006 Rob Kendrick + * Copyright 2005 James Bursa + * + * 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 . + */ + +/** \file + * Target independent plotting (BeOS/Haiku implementation). + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +extern "C" { +#include "desktop/plotters.h" +#include "render/font.h" +#include "utils/log.h" +#include "utils/utils.h" +#include "desktop/options.h" +} +#include "beos/font.h" +#include "beos/gui.h" +#include "beos/plotters.h" +//#include "beos/scaffolding.h" +//#include "beos/options.h" +#include "beos/bitmap.h" + +#warning MAKE ME static +/*static*/ BView *current_view; + +#if 0 /* GTK */ +GtkWidget *current_widget; +GdkDrawable *current_drawable; +GdkGC *current_gc; +#ifdef CAIRO_VERSION +cairo_t *current_cr; +#endif +#endif + +/* + * NOTE: BeOS rects differ from NetSurf ones: + * the right-bottom pixel is actually part of the BRect! + */ + +static bool nsbeos_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); +static bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style); +static bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style); +static bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float width, + colour c, const float transform[6]); +static bool nsbeos_plot_clip(const struct rect *ns_clip); +static bool nsbeos_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle); +static bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style); +static bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, + const plot_style_t *style); +static bool nsbeos_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bitmap_flags_t flags); + +#if 0 /* GTK */ +static GdkRectangle cliprect; +#endif + +#warning make patterns nicer +static const pattern kDottedPattern = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; +static const pattern kDashedPattern = { 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33 }; + +static const rgb_color kBlackColor = { 0, 0, 0, 255 }; + +struct plotter_table plot; + +const struct plotter_table nsbeos_plotters = { + nsbeos_plot_clip, + nsbeos_plot_arc, + nsbeos_plot_disc, + nsbeos_plot_line, + nsbeos_plot_rectangle, + nsbeos_plot_polygon, + nsbeos_plot_path, + nsbeos_plot_bitmap, + nsbeos_plot_text, + NULL, // Group Start + NULL, // Group End + NULL, // Flush + true // option_knockout +}; + + +// #pragma mark - implementation + + +BView *nsbeos_current_gc(void) +{ + return current_view; +} + +BView *nsbeos_current_gc_lock(void) +{ + BView *view = current_view; + if (view && view->LockLooper()) + return view; + return NULL; +} + +void nsbeos_current_gc_unlock(void) +{ + if (current_view) + current_view->UnlockLooper(); +} + +void nsbeos_current_gc_set(BView *view) +{ + // XXX: (un)lock previous ? + current_view = view; +} + +bool nsbeos_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) +{ + if (style->fill_type != PLOT_OP_TYPE_NONE) { + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->fill_colour); + + BRect rect(x0, y0, x1 - 1, y1 - 1); + view->FillRect(rect); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ + nsbeos_set_colour(style->fill_colour); + nsbeos_set_solid(); +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + cairo_set_line_width(current_cr, 0); + cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0); + cairo_fill(current_cr); + cairo_stroke(current_cr); + } else +#endif + gdk_draw_rectangle(current_drawable, current_gc, + TRUE, x0, y0, x1 - x0, y1 - y0); +#endif + } + + if (style->stroke_type != PLOT_OP_TYPE_NONE) { + pattern pat; + BView *view; + + switch (style->stroke_type) { + case PLOT_OP_TYPE_SOLID: /**< Solid colour */ + default: + pat = B_SOLID_HIGH; + break; + + case PLOT_OP_TYPE_DOT: /**< Doted plot */ + pat = kDottedPattern; + break; + + case PLOT_OP_TYPE_DASH: /**< dashed plot */ + pat = kDashedPattern; + break; + } + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->stroke_colour); + + float pensize = view->PenSize(); + view->SetPenSize(style->stroke_width); + + BRect rect(x0, y0, x1, y1); + view->StrokeRect(rect, pat); + + view->SetPenSize(pensize); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + if (line_width == 0) + line_width = 1; + + cairo_set_line_width(current_cr, line_width); + cairo_rectangle(current_cr, x0, y0, width, height); + cairo_stroke(current_cr); + } else +#endif + gdk_draw_rectangle(current_drawable, current_gc, + FALSE, x0, y0, width, height); + return true; +#endif + } + + return true; +} + + + +bool nsbeos_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style) +{ + pattern pat; + BView *view; + + switch (style->stroke_type) { + case PLOT_OP_TYPE_SOLID: /**< Solid colour */ + default: + pat = B_SOLID_HIGH; + break; + + case PLOT_OP_TYPE_DOT: /**< Doted plot */ + pat = kDottedPattern; + break; + + case PLOT_OP_TYPE_DASH: /**< dashed plot */ + pat = kDashedPattern; + break; + } + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->stroke_colour); + + float pensize = view->PenSize(); + view->SetPenSize(style->stroke_width); + + BPoint start(x0, y0); + BPoint end(x1, y1); + view->StrokeLine(start, end, pat); + + view->SetPenSize(pensize); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + if (width == 0) + width = 1; + + cairo_set_line_width(current_cr, width); + cairo_move_to(current_cr, x0, y0 - 0.5); + cairo_line_to(current_cr, x1, y1 - 0.5); + cairo_stroke(current_cr); + } else +#endif + gdk_draw_line(current_drawable, current_gc, + x0, y0, x1, y1); +#endif + return true; +} + + +bool nsbeos_plot_polygon(const int *p, unsigned int n, const plot_style_t *style) +{ + unsigned int i; + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->fill_colour); + + BPoint points[n]; + + for (i = 0; i < n; i++) { + points[i] = BPoint(p[2 * i] - 0.5, p[2 * i + 1] - 0.5); + } + + if (style->fill_colour == NS_TRANSPARENT) + view->StrokePolygon(points, (int32)n); + else + view->FillPolygon(points, (int32)n); + + return true; +} + + + + +bool nsbeos_plot_clip(const struct rect *ns_clip) +{ + BView *view; + //fprintf(stderr, "%s(%d, %d, %d, %d)\n", __FUNCTION__, clip_x0, clip_y0, clip_x1, clip_y1); + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + BRect rect(ns_clip->x0, ns_clip->y0, ns_clip->x1 - 1, + ns_clip->y1 - 1); + BRegion clip(rect); + view->ConstrainClippingRegion(NULL); + if (view->Bounds() != rect) + view->ConstrainClippingRegion(&clip); + + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + cairo_reset_clip(current_cr); + cairo_rectangle(current_cr, clip->x0, clip->y0, + clip->x1 - clip->x0, clip->y1 - clip->y0); + cairo_clip(current_cr); + } +#endif + cliprect.x = clip->x0; + cliprect.y = clip->y0; + cliprect.width = clip->x1 - clip->x0; + cliprect.height = clip->y1 - clip->y0; + gdk_gc_set_clip_rectangle(current_gc, &cliprect); +#endif + return true; +} + + +bool nsbeos_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) +{ + return nsfont_paint(fstyle, text, length, x, y); +} + + +bool nsbeos_plot_disc(int x, int y, int radius, const plot_style_t *style) +{ + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->fill_colour); + + BPoint center(x, y); + if (style->fill_type != PLOT_OP_TYPE_NONE) + view->FillEllipse(center, radius, radius); + else + view->StrokeEllipse(center, radius, radius); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ + nsbeos_set_colour(c); + nsbeos_set_solid(); +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + if (filled) + cairo_set_line_width(current_cr, 0); + else + cairo_set_line_width(current_cr, 1); + + cairo_arc(current_cr, x, y, radius, 0, M_PI * 2); + + if (filled) + cairo_fill(current_cr); + + cairo_stroke(current_cr); + } else +#endif + gdk_draw_arc(current_drawable, current_gc, + filled ? TRUE : FALSE, x - (radius), y - radius, + radius * 2, radius * 2, + 0, + 360 * 64); + +#endif + return true; +} + +bool nsbeos_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style) +{ + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + nsbeos_set_colour(style->fill_colour); + + BPoint center(x, y); + float angle = angle1; // in degree + float span = angle2 - angle1; // in degree + view->StrokeArc(center, radius, radius, angle, span); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ + nsbeos_set_colour(style->fill_colour); + nsbeos_set_solid(); +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) { + cairo_set_line_width(current_cr, 1); + cairo_arc(current_cr, x, y, radius, + (angle1 + 90) * (M_PI / 180), + (angle2 + 90) * (M_PI / 180)); + cairo_stroke(current_cr); + } else +#endif + gdk_draw_arc(current_drawable, current_gc, + FALSE, x - (radius), y - radius, + radius * 2, radius * 2, + angle1 * 64, angle2 * 64); + +#endif + return true; +} + +static bool nsbeos_plot_bbitmap(int x, int y, int width, int height, + BBitmap *b, colour bg) +{ + /* XXX: This currently ignores the background colour supplied. + * Does this matter? + */ + + if (width == 0 || height == 0) + return true; + + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + drawing_mode oldmode = view->DrawingMode(); + source_alpha alpha; + alpha_function func; + view->GetBlendingMode(&alpha, &func); + //view->SetDrawingMode(B_OP_OVER); + view->SetDrawingMode(B_OP_ALPHA); + view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + + // XXX DrawBitmap() resamples if rect doesn't match, + // but doesn't do any filtering + // XXX: use Zeta API if available ? + + BRect rect(x, y, x + width - 1, y + height - 1); + /* + rgb_color old = view->LowColor(); + if (bg != NS_TRANSPARENT) { + view->SetLowColor(nsbeos_rgb_colour(bg)); + view->FillRect(rect, B_SOLID_LOW); + } + */ + view->DrawBitmap(b, rect); + // maybe not needed? + //view->SetLowColor(old); + view->SetBlendingMode(alpha, func); + view->SetDrawingMode(oldmode); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ + /* XXX: This currently ignores the background colour supplied. + * Does this matter? + */ + + if (width == 0 || height == 0) + return true; + + if (gdk_pixbuf_get_width(pixbuf) == width && + gdk_pixbuf_get_height(pixbuf) == height) { + gdk_draw_pixbuf(current_drawable, current_gc, + pixbuf, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_MAX, 0, 0); + + } else { + GdkPixbuf *scaled; + scaled = gdk_pixbuf_scale_simple(pixbuf, + width, height, + nsoption_bool(render_resample) ? GDK_INTERP_BILINEAR + : GDK_INTERP_NEAREST); + if (!scaled) + return false; + + gdk_draw_pixbuf(current_drawable, current_gc, + scaled, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_MAX, 0, 0); + + g_object_unref(scaled); + } + +#endif + return true; +} + + +bool nsbeos_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bitmap_flags_t flags) +{ + int doneheight = 0, donewidth = 0; + BBitmap *primary; + BBitmap *pretiled; + bool repeat_x = (flags & BITMAPF_REPEAT_X); + bool repeat_y = (flags & BITMAPF_REPEAT_Y); + + if (!(repeat_x || repeat_y)) { + /* Not repeating at all, so just plot it */ + primary = nsbeos_bitmap_get_primary(bitmap); + return nsbeos_plot_bbitmap(x, y, width, height, primary, bg); + } + + if (repeat_x && !repeat_y) + pretiled = nsbeos_bitmap_get_pretile_x(bitmap); + if (repeat_x && repeat_y) + pretiled = nsbeos_bitmap_get_pretile_xy(bitmap); + if (!repeat_x && repeat_y) + pretiled = nsbeos_bitmap_get_pretile_y(bitmap); + primary = nsbeos_bitmap_get_primary(bitmap); + + /* use the primary and pretiled widths to scale the w/h provided */ + width *= pretiled->Bounds().Width() + 1; + width /= primary->Bounds().Width() + 1; + height *= pretiled->Bounds().Height() + 1; + height /= primary->Bounds().Height() + 1; + + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) { + warn_user("No GC", 0); + return false; + } + + // XXX: do we really need to use clipping reg ? + // I guess it's faster to not draw clipped out stuff... + + BRect cliprect; + BRegion clipreg; + view->GetClippingRegion(&clipreg); + cliprect = clipreg.Frame(); + + //XXX: FIXME + + if (y > cliprect.top) + doneheight = ((int)cliprect.top - height) + ((y - (int)cliprect.top) % height); + else + doneheight = y; + + while (doneheight < ((int)cliprect.bottom)) { + if (x > cliprect.left) + donewidth = ((int)cliprect.left - width) + ((x - (int)cliprect.left) % width); + else + donewidth = x; + while (donewidth < (cliprect.right)) { + nsbeos_plot_bbitmap(donewidth, doneheight, + width, height, pretiled, bg); + donewidth += width; + if (!repeat_x) break; + } + doneheight += height; + if (!repeat_y) break; + } + +#warning WRITEME +#if 0 /* GTK */ + int doneheight = 0, donewidth = 0; + GdkPixbuf *primary; + GdkPixbuf *pretiled; + + if (!(repeat_x || repeat_y)) { + /* Not repeating at all, so just pass it on */ + return nsbeos_plot_bitmap(x,y,width,height,bitmap,bg); + } + + if (repeat_x && !repeat_y) + pretiled = gtk_bitmap_get_pretile_x(bitmap); + if (repeat_x && repeat_y) + pretiled = gtk_bitmap_get_pretile_xy(bitmap); + if (!repeat_x && repeat_y) + pretiled = gtk_bitmap_get_pretile_y(bitmap); + primary = gtk_bitmap_get_primary(bitmap); + /* use the primary and pretiled widths to scale the w/h provided */ + width *= gdk_pixbuf_get_width(pretiled); + width /= gdk_pixbuf_get_width(primary); + height *= gdk_pixbuf_get_height(pretiled); + height /= gdk_pixbuf_get_height(primary); + + if (y > cliprect.y) + doneheight = (cliprect.y - height) + ((y - cliprect.y) % height); + else + doneheight = y; + + while (doneheight < (cliprect.y + cliprect.height)) { + if (x > cliprect.x) + donewidth = (cliprect.x - width) + ((x - cliprect.x) % width); + else + donewidth = x; + while (donewidth < (cliprect.x + cliprect.width)) { + nsbeos_plot_pixbuf(donewidth, doneheight, + width, height, pretiled, bg); + donewidth += width; + if (!repeat_x) break; + } + doneheight += height; + if (!repeat_y) break; + } + + +#endif + return true; +} + +static BPoint transform_pt(float x, float y, const float transform[6]) +{ +#warning XXX: verify + //return BPoint(x, y); + BPoint pt; + pt.x = x * transform[0] + y * transform[1] + transform[4]; + pt.y = x * transform[2] + y * transform[3] + transform[5]; + /* + printf("TR: {%f, %f} { %f, %f, %f, %f, %f, %f} = { %f, %f }\n", + x, y, + transform[0], transform[1], transform[2], + transform[3], transform[4], transform[5], + pt.x, pt.y); + */ + return pt; +} + +bool nsbeos_plot_path(const float *p, unsigned int n, colour fill, float width, + colour c, const float transform[6]) +{ + unsigned int i; + + if (n == 0) + return true; + + if (p[0] != PLOTTER_PATH_MOVE) { + LOG(("path doesn't start with a move")); + return false; + } + + BShape shape; + + for (i = 0; i < n; ) { + if (p[i] == PLOTTER_PATH_MOVE) { + BPoint pt(transform_pt(p[i + 1], p[i + 2], transform)); + shape.MoveTo(pt); + i += 3; + } else if (p[i] == PLOTTER_PATH_CLOSE) { + shape.Close(); + i++; + } else if (p[i] == PLOTTER_PATH_LINE) { + BPoint pt(transform_pt(p[i + 1], p[i + 2], transform)); + shape.LineTo(pt); + i += 3; + } else if (p[i] == PLOTTER_PATH_BEZIER) { + BPoint pt[3] = { + transform_pt(p[i + 1], p[i + 2], transform), + transform_pt(p[i + 3], p[i + 4], transform), + transform_pt(p[i + 5], p[i + 6], transform) + }; + shape.BezierTo(pt); + i += 7; + } else { + LOG(("bad path command %f", p[i])); + return false; + } + } + shape.Close(); + + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) + return false; + + rgb_color old_high = view->HighColor(); + float old_pen = view->PenSize(); + view->SetPenSize(width); + view->MovePenTo(0, 0); + if (fill != NS_TRANSPARENT) { + view->SetHighColor(nsbeos_rgb_colour(fill)); + view->FillShape(&shape); + } + if (c != NS_TRANSPARENT) { + view->SetHighColor(nsbeos_rgb_colour(c)); + view->StrokeShape(&shape); + } + // restore + view->SetPenSize(old_pen); + view->SetHighColor(old_high); + + //nsbeos_current_gc_unlock(); + + return true; +} + +rgb_color nsbeos_rgb_colour(colour c) +{ + rgb_color color; + if (c == NS_TRANSPARENT) + return B_TRANSPARENT_32_BIT; + color.red = c & 0x0000ff; + color.green = (c & 0x00ff00) >> 8; + color.blue = (c & 0xff0000) >> 16; + return color; +} + +void nsbeos_set_colour(colour c) +{ + rgb_color color = nsbeos_rgb_colour(c); + BView *view = nsbeos_current_gc(); + view->SetHighColor(color); +#if 0 /* GTK */ + int r, g, b; + GdkColor colour; + + r = c & 0xff; + g = (c & 0xff00) >> 8; + b = (c & 0xff0000) >> 16; + + colour.red = r | (r << 8); + colour.green = g | (g << 8); + colour.blue = b | (b << 8); + colour.pixel = (r << 16) | (g << 8) | b; + + gdk_color_alloc(gdk_colormap_get_system(), + &colour); + gdk_gc_set_foreground(current_gc, &colour); +#ifdef CAIRO_VERSION + if (nsoption_bool(render_cairo)) + cairo_set_source_rgba(current_cr, r / 255.0, + g / 255.0, b / 255.0, 1.0); +#endif +#endif +} + +/** Plot a caret. It is assumed that the plotters have been set up. */ +void nsbeos_plot_caret(int x, int y, int h) +{ + BView *view; + + view = nsbeos_current_gc/*_lock*/(); + if (view == NULL) + /* TODO: report an error here */ + return; + + BPoint start(x, y); + BPoint end(x, y + h - 1); +#if defined(__HAIKU__) || defined(B_BEOS_VERSION_DANO) + view->SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR)); +#else + view->SetHighColor(kBlackColor); +#endif + view->StrokeLine(start, end); + + //nsbeos_current_gc_unlock(); + +#if 0 /* GTK */ + GdkColor colour; + + colour.red = 0; + colour.green = 0; + colour.blue = 0; + colour.pixel = 0; + gdk_color_alloc(gdk_colormap_get_system(), + &colour); + gdk_gc_set_foreground(current_gc, &colour); + + gdk_draw_line(current_drawable, current_gc, + x, y, + x, y + h - 1); +#endif +} + +#ifdef TEST_PLOTTERS +// +static void test_plotters(void) +{ + int x0, y0; + int x1, y1; + struct rect r; + + x0 = 5; + y0 = 5; + x1 = 35; + y1 = 6; + + plot.line(x0, y0, x1, y1, 1, 0x0000ff00, false, false); + y0+=2; y1+=2; + plot.line(x0, y0, x1, y1, 1, 0x0000ff00, true, false); + y0+=2; y1+=2; + plot.line(x0, y0, x1, y1, 1, 0x0000ff00, false, true); + y0+=2; y1+=2; + plot.line(x0, y0, x1, y1, 1, 0x0000ff00, true, true); + y0+=10; y1+=20; + + plot.fill(x0, y0, x1, y1, 0x00ff0000); + plot.rectangle(x0+10, y0+10, x1-x0+1, y1-y0+1, 2, 0x00ffff00, true, false); + y0+=30; y1+=30; + + r.x0 = x0 + 2; + r.y0 = y0 + 2; + r.x1 = x1 - 2; + r.y1 = y1 - 2; + plot.clip(&r); + + plot.fill(x0, y0, x1, y1, 0x00000000); + plot.disc(x1, y1, 8, 0x000000ff, false); + + r.x0 = 0; + r.y0 = 0; + r.x1 = 300; + r.y1 = 300; + plot.clip(&r); + + y0+=30; y1+=30; + +} + +#include +#include +#include +class PTView : public BView { +public: + PTView(BRect frame) : BView(frame, "view", B_FOLLOW_NONE, B_WILL_DRAW) {}; + virtual ~PTView() {}; + virtual void Draw(BRect update) + { + test_plotters(); + }; + +}; + +extern "C" void test_plotters_main(void); +void test_plotters_main(void) +{ + BApplication app("application/x-vnd.NetSurf"); + memcpy(&plot, &nsbeos_plotters, sizeof(plot)); + BRect frame(0,0,300,300); + PTView *view = new PTView(frame); + frame.OffsetBySelf(100,100); + BWindow *win = new BWindow(frame, "NetSurfPlotterTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE); + win->AddChild(view); + nsbeos_current_gc_set(view); + win->Show(); + app.Run(); +} +#endif /* TEST_PLOTTERS */ + diff --git a/beos/plotters.h b/beos/plotters.h new file mode 100644 index 000000000..15b97a89e --- /dev/null +++ b/beos/plotters.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008 François Revol + * Copyright 2005 James Bursa + * + * 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 . + */ + +/** \file + * Target independent plotting (BeOS interface). + */ + +#ifndef NETSURF_BEOS_PLOTTERS_H +#define NETSURF_BEOS_PLOTTERS_H 1 + +extern "C" { + +struct plotter_table; + +extern const struct plotter_table nsbeos_plotters; + +} + +#include + +extern BView *current_view; +#if 0 /* GTK */ +extern GtkWidget *current_widget; +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; +#ifdef CAIRO_VERSION +extern cairo_t *current_cr; +#endif +#endif + +extern BView *nsbeos_current_gc(void); +extern BView *nsbeos_current_gc_lock(void); +extern void nsbeos_current_gc_unlock(void); +extern void nsbeos_current_gc_set(BView *view); + +rgb_color nsbeos_rgb_colour(colour c); +void nsbeos_set_colour(colour c); +void nsbeos_plot_caret(int x, int y, int h); + +#endif /* NETSURF_GTK_PLOTTERS_H */ diff --git a/beos/res.h b/beos/res.h new file mode 100644 index 000000000..4e6497815 --- /dev/null +++ b/beos/res.h @@ -0,0 +1,30 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +enum { + R_ResizeHandle = 1000, + R_ResBackNavActive = 1042, + R_ResBackNavInactive = 1043, + R_ResForwNavActive = 1044, + R_ResForwNavInactive = 1045, + R_ResUpNavActive = 1046, + R_ResUpNavInactive = 1047, + R_ResBackNavActiveSel = 1048, + R_ResForwNavActiveSel = 1049, + R_ResUpNavActiveSel = 1050 +}; diff --git a/beos/res.rdef b/beos/res.rdef new file mode 100644 index 000000000..b047bd02a --- /dev/null +++ b/beos/res.rdef @@ -0,0 +1,399 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#include "res.h" + +/* throbber */ +resource(400, "throbber0.png") #'data' import "res/throbber/throbber0.png"; +resource(401, "throbber1.png") #'data' import "res/throbber/throbber1.png"; +resource(402, "throbber2.png") #'data' import "res/throbber/throbber2.png"; +resource(403, "throbber3.png") #'data' import "res/throbber/throbber3.png"; +resource(404, "throbber4.png") #'data' import "res/throbber/throbber4.png"; +resource(405, "throbber5.png") #'data' import "res/throbber/throbber5.png"; +resource(406, "throbber6.png") #'data' import "res/throbber/throbber6.png"; +resource(407, "throbber7.png") #'data' import "res/throbber/throbber7.png"; +resource(408, "throbber8.png") #'data' import "res/throbber/throbber8.png"; + +/* */ +resource(500, "credits.html") #'data' import "res/en/credits.html,faf"; +resource(501, "licence.html") #'data' import "res/en/licence.html,faf"; + + +resource(1, "BEOS:APP_FLAGS") (#'APPF') $"01000000"; + +resource(101, "BEOS:L:STD_ICON") #'ICON' array { + $"FFFFFFFFFFFFFFFFFFFFFF0E0A00D600D6000AAF0EFFFFFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFF0E0A000001DED5D5D5DE020000090EFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFF0B0001B58D6666666C6C6C6C93B50200090EFFFFFFFFFFFFFF" + $"FFFFFFFFFF0E0000016D66666666666C6C6C6C6C6C6CB40104AFFFFFFFFFFFFF" + $"FFFFFFFF0E0001B503464666666666666C6C6C6C6C6C6C9303000DFFFFFFFFFF" + $"FFFFFF0E000267AEB5464666666666666C6C6C6C66666C7292DE000DFFFFFFFF" + $"FFFFFF070167464666464646666666666C666C6C1F1F66664092DE000EFFFFFF" + $"FFFF0B008E46464646464646666666666C403F1E3F3F3F3F6692930100FFFFFF" + $"FFFF00074646668D46464666666666666C663F3F3F3F3F3F6672927E000EFFFF" + $"FF0B006D6646670246464666666666666C663F3F3F3F3F3F3F1E6C923D00FFFF" + $"FF00D56666668E044646666666666666403F3F3F3F3F3F3F1F6692927E000EFF" + $"0E008E666666678E666666666666666C6C661E3F3F3F3F3F1D92929293000BFF" + $"0B016C66666666666666666666666C6C6C6C403F3F3F3F3F3F6C929292DE00FF" + $"08036C666666666666666666666C6C6C6C6C1E1D403F1E6C666C929292DD00FF" + $"00D56C6C66668D06666666666C6C6C6C6C6C6C6C6C1D667292929292927E03FF" + $"00D56C6C6C6C8D02666C6C6C6C6C6C6C6C6C6C6C6C6C729292929292927E03FF" + $"00D56C6C6C6C6CDE6C6C6C6C6C6C6C6C6C6C6C6C7272729292929292927E03FF" + $"00DE6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C7272729292929292925F0103FF" + $"09026C6C6C6C6C6C6C6C6C6C6C6C6C6C6C6C72727292929292929293010100FF" + $"0B008D6C6C6C6C8DD56C6C6C6C6C6C6C6C72727272929292929292927E3D29FF" + $"0E00B46C6C6C6C6C01936C6C6C6C6C6C72727292929292927E7E92925F000BFF" + $"FF00DE6C6C6C6C6CB5B46C6C6C6C727272729292929292DE297E9292DD020EFF" + $"FF0C0002B4726C6C6C6C7272727272727292B4DD7F929293929292920100FFFF" + $"FFFF00007F7272B4DDDD927293DDDEB49292DEDDB3929292929292DD000EFFFF" + $"FFFFAF00B4727293B47FDEB4937E7E93929292929292929292925F0009FFFFFF" + $"FFFFFF0A00B4929292929301939292929292929292929292925F0100FFFFFFFF" + $"FFFFFFFF0700B4929292927E9392929292929292929292925F01000EFFFFFFFF" + $"FFFFFFFFFF0700DD9292929292929292929292929292927E01000EFFFFFFFFFF" + $"FFFFFFFFFFFF0A003D7E9292927E7E9292929292925FDE00000EFFFFFFFFFFFF" + $"FFFFFFFFFFFFFF0D00003D7F5F5F017E92925F7EDE000300FFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFF0D00030000000001010000000C0EFFFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFFFF0E0B000A0A0A0D0EFFFFFFFFFFFFFFFFFFFFFFFF" +}; + +resource(101, "BEOS:M:STD_ICON") #'MICN' array { + $"FFFFFFFF0E0900020205000DFFFFFFFF" + $"FFFFFF09038E66666C6C93DD000EFFFF" + $"FFFF00B5AE4666666C6C666CB4050EFF" + $"FF098E464646666666401D4066B400FF" + $"0E05668E664666666C1E3F3F1D6CDDAF" + $"098E668E66666666661F3F3F1E729300" + $"006C66666666666C6C401E1E40729204" + $"026C6CB46C666C6C6C6C6C66929292DE" + $"026C6C8D6C6C6C6C6C6C72729292923D" + $"006C6C6C8D6C6C6C6C72729292927E04" + $"09946C6CB56C6C6C72729292DD935F00" + $"0E009492B49293B492B47E929292DE0D" + $"FF0A7F92937F939392929292927E00FF" + $"FFFF08DD92929292929292927E00FFFF" + $"FFFFFF0B017E93DD92927EDE09FFFFFF" + $"FFFFFFFF0E0B000500000A0EFFFFFFFF" +}; + +resource(1, "BEOS:APP_SIG") (#'MIMS') "application/x-vnd.NetSurf"; + +resource(1, "BEOS:FILE_TYPES") message { + "types" = "text/html", + "types" = "image/gif", + "types" = "image/jpeg", + "types" = "application/x-vnd.Be-bookmark", + "types" = "text", + "types" = "application/x-vnd.Be-doc_bookmark", + "types" = "application/x-vnd.Be.URL.file", + "types" = "application/x-vnd.Be.URL.ftp", + "types" = "application/x-vnd.Be.URL.http", + "types" = "application/x-vnd.Be.URL.https" +}; + +resource(R_ResizeHandle) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 13.0, 13.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 16, + "_data" = array { + $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" + $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B1B1B1B1B1B1B0C1B1B133F3F3F" + $"1B1B1B1B1B1B1B1B1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" + $"1B1B1B1B1B1B0C1B1B0D1B1B133F3F3F1B1B1B1B1B1B1B3F1B1B3F1B133F3F3F" + $"1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F1B1B1B0C1B1B0D1B1B0C1B1B133F3F3F" + $"1B1B1B1B3F1B1B3F1B1B3F1B133F3F3F1B1B1B1B1B1B1B1B1B1B1B1B133F3F3F" + $"131313131313131313131313133F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F" + } +}; + +resource(R_ResBackNavActive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3B18FFFF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF" + $"FF3B35353B1418FFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" + $"18FFFF3FFFFFFF3B34343535363637373737373B1418FF3FFFFF3B3434343535" + $"363637373737373B1418FF3FFF3B343434353536363637373737373B1418FF3F" + $"FF183B3535353536363637373737373B1418FF3FFFFF183B3536363636373737" + $"3737373B1418FF3FFFFFFF183B3636373B3B3B3B3B3B3B3B1418FF3FFFFFFFFF" + $"183B37373B141414141414141418FF3FFFFFFFFFFF183B373B14181818181818" + $"18FFFF3FFFFFFFFFFFFF183B3B1418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF18" + $"141418FFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResBackNavInactive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF0000FFFFFF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF001800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" + $"FF00181800FFFFFFFFFFFFFFFFFFFF3FFFFFFFFF001C18180000000000000000" + $"FFFFFF3FFFFFFF001C1C18181515111111111100FFFFFF3FFFFF001C1C1C1818" + $"1515111111111100FFFFFF3FFF001C1C1C1818151515111111111100FFFFFF3F" + $"FFFF0018181818151515111111111100FFFFFF3FFFFFFF001815151515111111" + $"11111100FFFFFF3FFFFFFFFF001515110000000000000000FFFFFF3FFFFFFFFF" + $"FF00111100FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF001100FFFFFFFFFFFFFF" + $"FFFFFF3FFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResForwNavActive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3B18FF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353B18FFFFFFFFFFFFFF3FFFFFFFFF" + $"FFFFFFFF3B35363B18FFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363B18FFFF" + $"FFFFFF3FFF3B34343434353535363636373B18FFFFFFFF3FFF3B343434353535" + $"3536363637373B18FFFFFF3FFF3B343435353535363636373737373B18FFFF3F" + $"FF3B3535353535363636373737373B141418FF3FFF3B35353536363636373737" + $"373B141418FFFF3FFF3B3B3B3B3B3B3B3B3737373B141418FFFFFF3FFF181414" + $"141414143B37373B141418FFFFFFFF3FFFFF1818181818183B373B141418FFFF" + $"FFFFFF3FFFFFFFFFFFFFFFFF3B3B141418FFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" + $"18141418FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFF1818FFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResForwNavInactive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF0000FFFF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001800FFFFFFFFFFFFFFFF3FFFFFFFFF" + $"FFFFFFFF00181500FFFFFFFFFFFFFF3FFF000000000000000018151500FFFFFF" + $"FFFFFF3FFF001C1C1C1C1818181515151100FFFFFFFFFF3FFF001C1C1C181818" + $"18151515111100FFFFFFFF3FFF001C1C181818181515151111111100FFFFFF3F" + $"FF0018181818181515151111111100FFFFFFFF3FFF0018181815151515111111" + $"1100FFFFFFFFFF3FFF000000000000000011111100FFFFFFFFFFFF3FFFFFFFFF" + $"FFFFFFFF00111100FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF001100FFFFFFFFFF" + $"FFFFFF3FFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResUpNavActive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" + $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E50018FFFFFFFFFFFFFF3F3FFFFFFFFF" + $"FFFF00E5BDBD0018FFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD0018FFFFFF" + $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD0018FFFFFFFF3F3FFFFFFF00E5BDBDBD" + $"BDBDBDBDBD0018FFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD9898980018FFFF3F3F" + $"FF00000000E5BDBDBDBDBD980000000018FF3F3FFFFF141400E5BDBDBDBDBD98" + $"00141418FFFF3F3FFFFFFF1800E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF" + $"00E5BDBDBDBDBD98001418FFFFFF3F3FFFFFFFFF00E5989898989898001418FF" + $"FFFF3F3FFFFFFFFF0000000000000000001418FFFFFF3F3FFFFFFFFF18141414" + $"141414141418FFFFFFFF3F3FFFFFFFFFFF181818181818181818FFFFFFFF3F3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" + } +}; + +resource(R_ResUpNavInactive) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" + $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF001C00FFFFFFFFFFFFFFFF3F3FFFFFFFFF" + $"FFFF001C171700FFFFFFFFFFFFFF3F3FFFFFFFFFFF001C1717171700FFFFFFFF" + $"FFFF3F3FFFFFFFFF001C17171717171700FFFFFFFFFF3F3FFFFFFF001C171717" + $"171717171700FFFFFFFF3F3FFFFF001C1C1C171717171712121200FFFFFF3F3F" + $"FF000000001C17171717171200000000FFFF3F3FFFFFFFFF001C171717171712" + $"00FFFFFFFFFF3F3FFFFFFFFF001C17171717171200FFFFFFFFFF3F3FFFFFFFFF" + $"001C17171717171200FFFFFFFFFF3F3FFFFFFFFF001C12121212121200FFFFFF" + $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" + } +}; + +resource(R_ResBackNavActiveSel) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF" + $"FF3B35353BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFF3B3435353B3B3B3B3B3B3B3B" + $"FFFFFF3FFFFFFF3B34343535363637373737373BFFFFFF3FFFFF3B3434343535" + $"363637373737373BFFFFFF3FFF3B343434353536363637373737373BFFFFFF3F" + $"FFFF3B3535353536363637373737373BFFFFFF3FFFFFFF3B3536363636373737" + $"3737373BFFFFFF3FFFFFFFFF3B3636373B3B3B3B3B3B3B3BFFFFFF3FFFFFFFFF" + $"FF3B37373BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFF3B373BFFFFFFFFFFFFFF" + $"FFFFFF3FFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResForwNavActiveSel) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 18.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFF" + $"FFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B353BFFFFFFFFFFFFFFFF3FFFFFFFFF" + $"FFFFFFFF3B35363BFFFFFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3536363BFFFFFF" + $"FFFFFF3FFF3B34343434353535363636373BFFFFFFFFFF3FFF3B343434353535" + $"3536363637373BFFFFFFFF3FFF3B343435353535363636373737373BFFFFFF3F" + $"FF3B3535353535363636373737373BFFFFFFFF3FFF3B35353536363636373737" + $"373BFFFFFFFFFF3FFF3B3B3B3B3B3B3B3B3737373BFFFFFFFFFFFF3FFFFFFFFF" + $"FFFFFFFF3B37373BFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF3B373BFFFFFFFFFF" + $"FFFFFF3FFFFFFFFFFFFFFFFF3B3BFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFFFF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F" + } +}; + +resource(R_ResUpNavActiveSel) archive(, 0x00000000) BBitmap { + "_frame" = rect { 0.0, 0.0, 17.0, 16.0 }, + "_cspace" = 4, + "_bmflags" = 1, + "_rowbytes" = 20, + "_data" = array { + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFF00FFFFFF" + $"FFFFFFFFFFFF3F3FFFFFFFFFFFFFFF00E500FFFFFFFFFFFFFFFF3F3FFFFFFFFF" + $"FFFF00E5BDBD00FFFFFFFFFFFFFF3F3FFFFFFFFFFF00E5BDBDBDBD00FFFFFFFF" + $"FFFF3F3FFFFFFFFF00E5BDBDBDBDBDBD00FFFFFFFFFF3F3FFFFFFF00E5BDBDBD" + $"BDBDBDBDBD00FFFFFFFF3F3FFFFF00E5E5E5BDBDBDBDBD98989800FFFFFF3F3F" + $"FF00000000E5BDBDBDBDBD9800000000FFFF3F3FFFFFFFFF00E5BDBDBDBDBD98" + $"00FFFFFFFFFF3F3FFFFFFFFF00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF" + $"00E5BDBDBDBDBD9800FFFFFFFFFF3F3FFFFFFFFF00E598989898989800FFFFFF" + $"FFFF3F3FFFFFFFFF000000000000000000FFFFFFFFFF3F3FFFFFFFFFFFFFFFFF" + $"FFFFFFFFFFFFFFFFFFFF3F3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" + $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF3F3F" + } +}; + +resource(101, "BEOS:ICON") #'VICN' array { + $"6E6369660A02010203AE259A400198BFFA65AE20E548AF9547F2037F30A0FFFF" + $"00E8F1FDFFF131A0FFFB02000602B83B85BC57333C5733B83B8549EAE1481199" + $"00359FFFFFFFFFFF05FF05010400600500020002033D9F21B889EB3A4CEE3F48" + $"204AB4B1440D2D10339DFF51369381810DB3339DFF68020002013E7E6E26628C" + $"A83C7540569A4565A3CA24492BEEF3F70001EEF3F731017D828B95160204BFE6" + $"B413C670B413B95DB413B411BF78B411B92DB411C5C3BFE6CADDB95CCADDC66F" + $"CADDCBBCBF78CBBCC5C4CBBCB92E0204BC63B4EAC0E922B7DDB608B570BBF0B4" + $"C0B92EB61EBEB2BEDDBEE8BA56C007C363BDCBC5D0B7E2C67FBAA5C522B52002" + $"04BFDEB448C60DB448B9ADB448B4ADBF9AB4ADB955B4ADC5DABFDECAEDB9ABCA" + $"EDC60BCAEDCB0FBF9ACB0FC5DCCB0FB9570204BFDFB4D8C5BFB4D8B9FEB4D8B5" + $"3DBF9AB53DB9A5B53DC58ABFDFCA5CB9FCCA5CC5BDCA5CCA81BF9ACA81C58BCA" + $"81B9A70606BA0BBF11CB5CC71BCAFECB92C8F7CA15CAF2CCF9C666CA36C48EC4" + $"A7CA76C78DC943C2BECB40BF11CB5D0A04BB16B6B2BA9C2EB9CFB86BBA5AB65D" + $"0A04BA10BC6AB954BC62B96CBADFBA3EBAE70A04BA21BEB5BA5AC047B98DC071" + $"B93ABEF30A04BAFDC28BBB88C3E9BAD5C43EBA59C2CD0A04BD84C730BCE154BC" + $"1CC679BCAAC5F90A04BEF3C932C015CA3BBF51CAA0BE4FC9AB0A04B812C4E6B8" + $"1CC5AEB693C46DB6DEC3F70A04BA6AC535BBD4C545BBCDC617BAACC6020A04BE" + $"1EC565BF9AC51CBFB2C5E6BE5FC6340A04C1DCC4D3C348C459C381C524C244C5" + $"8D0A04C6D0C2EDC721C39FC5E5C45FC595C3AA0A04C8E6C175C9A042CA54C102" + $"C962C20E0611AAAAAAAE02C14FB955C2EAB96FC38BB7E6C47FB928C628B8C3C6" + $"04BA40C793BB18C64ABC15C6B4BDE0C50CBDCAC479BF41C372BE11C17FBE79C1" + $"FEBCB2C207BCB3C1F5BCB2C047BC1CC1A7BAEBC14EB9540205C03CC10EC030C0" + $"EFC0B9C250BFCBC606BE8FC591C21CC6E2C5DBC385C74DC4AAC5AAC35EC643BC" + $"27C7D2BF42C4B3B90CC27CB994C3B1BA28C084B8A30605EF03B6CFBA0EB779B7" + $"92B672BB6AB633BD29B598BCA2B7B3BE77BD4BBD3EC58CB654C86EB88FC42DB5" + $"45BC71B55CBF70B47FB920B65000000204CB77C91ACB76C797CB79CAACC293CB" + $"88C456CB8AC0CCCB86BAB3C975BAACCAF2BABAC7F6C286C704C0CCC704C44DC7" + $"04250A090115023FFFDCB41DBB3451734030CDBF6EE7C3CF400A000100023F88" + $"1AB4F02F34DE2C3F9E484326CF4422000A060112023CDC96413114C145263E69" + $"DE4C32CFCB0EE00A0301031A4002C300000000000040012FBD3E023BCFC439BF" + $"01178100040A0301031A4002C300000000000040012FBD3E023BCFC42F390117" + $"8200040A0301031A4002C300000000000040012FBD3E023BCFC41A2F01178200" + $"040A050105023EF4D13E9DFDBE66B43EB65E491E02C6E7CA0A0501051A3EE861" + $"3EABC8BE735C3EAAF54929C0C6EFBE1A3901178100040A050106023F4B963E44" + $"75BE44753F4B9648D9CDC72B1A0A0501061A3F4B963E4475BE44753F4B9648D9" + $"CDC72B1A1A3901178100040A0501061A3F4B963E4475BE44753F4B9648D9CDC7" + $"2B1A001901178300040A050107023F4B963E4475BE44753F4B9648D9CDC72B1A" + $"0A0501071A3F4B963E4475BE44753F4B9648D9CDC72B1A1A3901178100040A05" + $"0108023F4B963E4475BE44753F4B9648D9CDC72B1A0A0501081A3F4B963E4475" + $"BE44753F4B9648D9CDC72B1A1A3901178100040A0501081A3F4B963E4475BE44" + $"753F4B9648D9CDC72B1A001901178300040A050109023F70F53E0A00BE0A003F" + $"70F5485F8CC6CD790A0501091A3F70F53E0A00BE0A003F70F5485F8CC6CD791A" + $"3901178100040A05010A023F4B963E4475BD81043E8BD247F0BEC26F710A0501" + $"0A1A3F4B963E4475BD81043E8BD247F0BEC26F711A3901178100040A05010A1A" + $"3F4B963E4475BD81043E8BD247F0BEC26F71001901178300040A05010B023F7B" + $"673D4154BE6C8B3F3385495313C5FE290A05010B1A3F7B673D4154BE6C8B3F33" + $"85495313C5FE291A3901178100040A05010C023F70093E0B8EBE0B8E3F700948" + $"A7CCC721CF0A05010C1A3F70093E0B8EBE0B8E3F700948A7CCC721CF1A390117" + $"8100040A05010D023F70093E0B8EBE0B8E3F700948A7CCC721CF0A05010D1A3F" + $"70093E0B8EBE0B8E3F700948A7CCC721CF1A3901178100040A05010D1A3F7009" + $"3E0B8EBE0B8E3F700948A7CCC721CF001901178300040A05010E023F70093E0B" + $"8EBE0B8E3F700948A7CCC721CF0A05010E1A3F70093E0B8EBE0B8E3F700948A7" + $"CCC721CF1A3901178100040A05010F023FB1173D145ABD145A3FB117474282C6" + $"7CF80A05010F1A3FB1173D145ABD145A3FB117474282C67CF81A390117810004" + $"0A05010F1A3FB1173D145ABD145A3FB117474282C67CF8001901178300040A05" + $"0110023F68373CD78FBD05193F9ECF48132CC5E0A80A0501101A3F68373CD78F" + $"BD05193F9ECF48132CC5E0A81A3901178100040A020111000A0301031A4002C3" + $"00000000000040012FBD3E023BCFC400190117850004" +}; + +resource(101, "BEOS:D:STD_ICON") (#'iICO') $"4944585A055300"; + +resource(101, "BEOS:V:STD_ICON") #'zICO' array { + $"7A10000078DAED57DD6EDB3618BDEF5310CA4D03C40C7F3E8A6466B7C002AC37" + $"2C066CCD03B8B1EC6853A44052B3644FBFF351769C7601D68B41BB5814C03AA2" + $"8EA8C3F3FD5059BE7FB86DC47DD50F75D7AE0A2D5521AAF6BADBD4ED6E555C7D" + $"FA69110A318CEB76B36EBAB65A158FD550BC7FF76639DCEFC41FF566BC591525" + $"15E2A6AA7737E384AFBBA6EB17753B56FD5DD7ACC73C7353B7D5BAFFE5C38FC5" + $"BB3762B9C38F58DEADC71B4CFED860DE6DDD341727DB7C14B8391D9B55F131C8" + $"6085355299CB0C8D92C10BEDF3AFCE231137277C494AEAC3384569F49E3FE169" + $"9A099365E6C4772633F33C195F4EF34FE3F9B513FD28E6CFA3CAB15FB7C3B6EB" + $"6F57C5ED7AECEB87B75A928E670A7F135AE08D21B8B385B6D2913FE567CF5FF6" + $"A085CD3F60A4EF7EAF0E861CAE17D9F10B92D6C5F26990ADFDADABDB8BCFD57D" + $"D5FC9FCCEBD79B7ADD7CE053D58EA2C68A77FB0BE4F1015EB5F538AC8A2F43D5" + $"FF7AB7BEAE7E6EAF860A69FAB02AC0BA7ECCA77ECADDC3339FFEA64A49174C56" + $"B598A00ED2C4F20C0E292277CA790D49C3D8DD896EBB1DAA31CFCBD78B5C11AB" + $"E2E473D83AA4F7F90B54FD0D55A9E80FD4E5F9D70B7D3971BEF4CDDB93A7E59F" + $"BE16D15311A97C7C53445A3AEBC26B117D6717262309EB0CD287449A8518278D" + $"4F445295C260529BB0923208A36524E638811229CB64BD8C41E828A34DB69486" + $"D83A054CB2746C0EE964B5B49E39A01B5912CFA875821F1E9864C03846A0A094" + $"44CCB1D92D6F9275321856468E5FE5BCE0C980A3D450869743E551FD7FD8B7D1" + $"29BCF9BEBEFD6AF73F25E954D45FBBC68BC6B2E09449C02A5B02CD30C069C604" + $"1CA42B858619E9197D5E9921DB89CA8E90C39185DFBA942E66CC30F26D45E919" + $"7566891C6E477BBB900CCAB18DE84EC0F6492E3248A70379EE5813C494B23489" + $"1B2C9A629441735029705325CBC24088313D23CF2A1281837B68DCCA2794150A" + $"8D9C8C09D54668FFA50CC05A9A4C0958C7913EAF4C98640405CE438E64291CFA" + $"0970902AF2166493C9658F7DCB43F2913E6FC8D1080D875621FF48EA2828B71E" + $"6DB3366E64893981C7C384F7FC79757AE9598ECAD1B591B1A58CF32E1EFCBE23" + $"01E7AADAB3E78DB9934AF37B89C3CC9969789730874F0DC721577EAFF7C89E55" + $"A4CD5F3F882605DE78BCE668A2E3A09235ED2D06C7E5E847979EF1E7D589E70D" + $"37206C8A6C12FACEB4115A2E20BE5BF206E9F3D75EC8F8C09F5527BA0F3666B8" + $"A774227C5F46EEE6E8F2FC3D4A025F088025F726C8D7907FA4FF2B3297E7F8C7" + $"7F793EDCE3F417BB10DA0B" +}; + diff --git a/beos/save_complete.cpp b/beos/save_complete.cpp new file mode 100644 index 000000000..19306dc21 --- /dev/null +++ b/beos/save_complete.cpp @@ -0,0 +1,85 @@ +/* + * Copyright 2008 François Revol + * Copyright 2009 Mark Benjamin + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +extern "C" { +#include "content/content.h" +#include "desktop/save_complete.h" +#include "utils/utils.h" +} + +/** +* conducts the filesystem save appropriate to the gui +* \param path save path +* \param filename name of file to save +* \param len data length +* \param sourcedata pointer to data to save +* \param type content type +* \return true for success +*/ + +bool save_complete_gui_save(const char *path, const char *filename, + size_t len, const char *sourcedata, lwc_string *mime_type) +{ + int res; + int namelen; + namelen = strlen(path) + strlen(filename) + 2; /* '/', '\0' */ + char *fullpath = (char *)malloc(namelen); + if (!fullpath) { + warn_user("NoMemory", 0); + return false; + } + snprintf(fullpath, namelen, "%s/%s", path, filename); + FILE *f; + f = fopen(fullpath, "wb"); + free(fullpath); + if (f == NULL) + return false; + res = fwrite(sourcedata, len, 1, f); + fclose(f); + if (res != 1) + return false; + return true; +} + +/** +* wrapper for lib function htmlSaveFileFormat; front sets path from path +* + filename in a filesystem-specific way +*/ + +int save_complete_htmlSaveFileFormat(const char *path, const char *filename, + xmlDocPtr cur, const char *encoding, int format) +{ + int ret; + int len = strlen(path) + strlen(filename) + 2; + char *fullpath = (char *)malloc(len); + if (fullpath == NULL) { + warn_user("NoMemory", 0); + return -1; + } + snprintf(fullpath, len, "%s/%s", path, filename); + ret = htmlSaveFileFormat(fullpath, cur, encoding, format); + free(fullpath); + return ret; +} + diff --git a/beos/scaffolding.cpp b/beos/scaffolding.cpp new file mode 100644 index 000000000..afe36bd8f --- /dev/null +++ b/beos/scaffolding.cpp @@ -0,0 +1,2417 @@ +/* + * Copyright 2008 François Revol + * Copyright 2006 Rob Kendrick + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +extern "C" { +#include "content/content.h" +#include "desktop/browser.h" +#include "desktop/history_core.h" +#include "desktop/gui.h" +#include "desktop/netsurf.h" +#include "desktop/plotters.h" +#include "desktop/options.h" +#include "desktop/selection.h" +#include "desktop/textinput.h" +#include "render/box.h" +#include "render/font.h" +#include "render/form.h" +#include "render/html.h" +#include "utils/messages.h" +#include "utils/schedule.h" +#include "utils/utils.h" +#include "utils/log.h" +} +#include "beos/gui.h" +#include "beos/plotters.h" +#include "beos/scaffolding.h" +#include "beos/gui_options.h" +//#include "beos/completion.h" +#include "beos/throbber.h" +#include "beos/window.h" +//#include "beos/schedule.h" +//#include "beos/download.h" + +#define TOOLBAR_HEIGHT 32 +#define DRAGGER_WIDTH 8 + +struct beos_history_window; + +class NSBrowserWindow; +class NSThrobber; + +struct beos_scaffolding { + NSBrowserWindow *window; // top-level container object + + // top-level view, contains toolbar & top-level browser view + NSBaseView *top_view; + + BMenuBar *menu_bar; + + BPopUpMenu *popup_menu; + + BDragger *dragger; + + BView *tool_bar; + + BControl *back_button; + BControl *forward_button; + BControl *stop_button; + BControl *reload_button; + BControl *home_button; + + BTextControl *url_bar; + //BMenuField *url_bar_completion; + + NSThrobber *throbber; + + BStringView *status_bar; + + BScrollView *scroll_view; +#warning XXX +#if 0 /* GTK */ + GtkEntryCompletion *url_bar_completion; + GtkMenuBar *menu_bar; + GtkMenuItem *back_menu; + GtkMenuItem *forward_menu; + GtkMenuItem *stop_menu; + GtkMenuItem *reload_menu; + + GladeXML *popup_xml; + GtkMenu *popup_menu; + +#endif + struct beos_history_window *history_window; + + int throb_frame; + struct gui_window *top_level; + int being_destroyed; + + bool fullscreen; +}; + +struct beos_history_window { + struct beos_scaffolding *g; + BWindow *window; + +#warning XXX +#if 0 /* GTK */ + GtkWindow *window; + GtkScrolledWindow *scrolled; + GtkDrawingArea *drawing_area; +#endif +}; + +struct menu_events { + const char *widget; +#warning XXX +#if 0 /* GTK */ + GCallback handler; +#endif +}; + +// passed to the replicant main thread +struct replicant_thread_info { + char app[B_PATH_NAME_LENGTH]; + BString url; + char *args[3]; +}; + + +static int open_windows = 0; /**< current number of open browsers */ +static struct beos_scaffolding *current_model; /**< current window for model dialogue use */ +static NSBaseView *replicant_view = NULL; /**< if not NULL, the replicant View we are running NetSurf for */ +static sem_id replicant_done_sem = -1; + +static void nsbeos_window_update_back_forward(struct beos_scaffolding *); +static void nsbeos_throb(void *); +static int32 nsbeos_replicant_main_thread(void *_arg); + +// in beos_gui.cpp +extern int main(int argc, char** argv); + +#warning XXX +#if 0 /* GTK */ +static gboolean nsbeos_window_url_activate_event(beosWidget *, gpointer); +static gboolean nsbeos_window_url_changed(beosWidget *, GdkEventKey *, gpointer); + +static gboolean nsbeos_history_expose_event(beosWidget *, GdkEventExpose *, + gpointer); +static gboolean nsbeos_history_button_press_event(beosWidget *, GdkEventButton *, + gpointer); + +static void nsbeos_attach_menu_handlers(GladeXML *, gpointer); + +gboolean nsbeos_openfile_open(beosWidget *widget, gpointer data); + +#define MENUEVENT(x) { #x, G_CALLBACK(nsbeos_on_##x##_activate) } +#define MENUPROTO(x) static gboolean nsbeos_on_##x##_activate( \ + beosMenuItem *widget, gpointer g) +/* prototypes for menu handlers */ +/* file menu */ +MENUPROTO(new_window); +MENUPROTO(open_location); +MENUPROTO(open_file); +MENUPROTO(close_window); +MENUPROTO(quit); + +/* edit menu */ +MENUPROTO(preferences); + +/* view menu */ +MENUPROTO(stop); +MENUPROTO(reload); +MENUPROTO(zoom_in); +MENUPROTO(normal_size); +MENUPROTO(zoom_out); +MENUPROTO(full_screen); +MENUPROTO(menu_bar); +MENUPROTO(tool_bar); +MENUPROTO(status_bar); +MENUPROTO(downloads); +MENUPROTO(save_window_size); +MENUPROTO(toggle_debug_rendering); +MENUPROTO(save_box_tree); + +/* navigate menu */ +MENUPROTO(back); +MENUPROTO(forward); +MENUPROTO(home); +MENUPROTO(local_history); +MENUPROTO(global_history); + +/* help menu */ +MENUPROTO(about); + +/* structure used by nsbeos_attach_menu_handlers to connect menu items to + * their handling functions. + */ +static struct menu_events menu_events[] = { + /* file menu */ + MENUEVENT(new_window), + MENUEVENT(open_location), + MENUEVENT(open_file), + MENUEVENT(close_window), + MENUEVENT(quit), + + /* edit menu */ + MENUEVENT(preferences), + + /* view menu */ + MENUEVENT(stop), + MENUEVENT(reload), + MENUEVENT(zoom_in), + MENUEVENT(normal_size), + MENUEVENT(zoom_out), + MENUEVENT(full_screen), + MENUEVENT(menu_bar), + MENUEVENT(tool_bar), + MENUEVENT(status_bar), + MENUEVENT(downloads), + MENUEVENT(save_window_size), + MENUEVENT(toggle_debug_rendering), + MENUEVENT(save_box_tree), + + /* navigate menu */ + MENUEVENT(back), + MENUEVENT(forward), + MENUEVENT(home), + MENUEVENT(local_history), + MENUEVENT(global_history), + + /* help menu */ + MENUEVENT(about), + + /* sentinel */ + { NULL, NULL } +}; + +void nsbeos_attach_menu_handlers(GladeXML *xml, gpointer g) +{ + struct menu_events *event = menu_events; + + while (event->widget != NULL) + { + beosWidget *w = glade_xml_get_widget(xml, event->widget); + g_signal_connect(G_OBJECT(w), "activate", event->handler, g); + event++; + } +} +#endif + +// #pragma mark - class NSThrobber + +class NSThrobber : public BView { +public: + NSThrobber(BRect frame); +virtual ~NSThrobber(); + +virtual void MessageReceived(BMessage *message); +virtual void Draw(BRect updateRect); +void SetBitmap(const BBitmap *bitmap); + +private: + const BBitmap *fBitmap; +}; + +NSThrobber::NSThrobber(BRect frame) + : BView(frame, "NSThrobber", B_FOLLOW_TOP | B_FOLLOW_RIGHT, B_WILL_DRAW), + fBitmap(NULL) +{ +} + + +NSThrobber::~NSThrobber() +{ +} + + +void +NSThrobber::MessageReceived(BMessage *message) +{ + BView::MessageReceived(message); +} + + +void +NSThrobber::Draw(BRect updateRect) +{ + if (!fBitmap) + return; + DrawBitmap(fBitmap); +} + + +void +NSThrobber::SetBitmap(const BBitmap *bitmap) +{ + fBitmap = bitmap; +} + + +// #pragma mark - class NSBaseView + + +NSBaseView::NSBaseView(BRect frame) + : BView(frame, "NetSurf", B_FOLLOW_ALL_SIDES, + 0 /*B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS*/ /*| B_SUBPIXEL_PRECISE*/), + fScaffolding(NULL) +{ +} + +NSBaseView::NSBaseView(BMessage *archive) + : BView(archive), + fScaffolding(NULL) +{ +} + + +NSBaseView::~NSBaseView() +{ + //warn_user ("~NSBaseView()", NULL); + BMessage *message = new BMessage(B_QUIT_REQUESTED); + nsbeos_pipe_message_top(message, NULL, fScaffolding); + while (acquire_sem(replicant_done_sem) == EINTR); +} + + +void +NSBaseView::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_SIMPLE_DATA: + case B_ARGV_RECEIVED: + case B_REFS_RECEIVED: + case B_COPY: + case B_CUT: + case B_PASTE: + case B_SELECT_ALL: + //case B_MOUSE_WHEEL_CHANGED: + case B_UI_SETTINGS_CHANGED: + // NetPositive messages + case B_NETPOSITIVE_OPEN_URL: + case B_NETPOSITIVE_BACK: + case B_NETPOSITIVE_FORWARD: + case B_NETPOSITIVE_HOME: + case B_NETPOSITIVE_RELOAD: + case B_NETPOSITIVE_STOP: + case B_NETPOSITIVE_DOWN: + case B_NETPOSITIVE_UP: + // messages for top-level + case 'back': + case 'forw': + case 'stop': + case 'relo': + case 'home': + case 'urlc': + case 'urle': + case 'menu': + case NO_ACTION: + case HELP_OPEN_CONTENTS: + case HELP_OPEN_GUIDE: + case HELP_OPEN_INFORMATION: + case HELP_OPEN_ABOUT: + case HELP_LAUNCH_INTERACTIVE: + case HISTORY_SHOW_LOCAL: + case HISTORY_SHOW_GLOBAL: + case HOTLIST_ADD_URL: + case HOTLIST_SHOW: + case COOKIES_SHOW: + case COOKIES_DELETE: + case BROWSER_PAGE: + case BROWSER_PAGE_INFO: + case BROWSER_PRINT: + case BROWSER_NEW_WINDOW: + case BROWSER_VIEW_SOURCE: + case BROWSER_OBJECT: + case BROWSER_OBJECT_INFO: + case BROWSER_OBJECT_RELOAD: + case BROWSER_OBJECT_SAVE: + case BROWSER_OBJECT_EXPORT_SPRITE: + case BROWSER_OBJECT_SAVE_URL_URI: + case BROWSER_OBJECT_SAVE_URL_URL: + case BROWSER_OBJECT_SAVE_URL_TEXT: + case BROWSER_SAVE: + case BROWSER_SAVE_COMPLETE: + case BROWSER_EXPORT_DRAW: + case BROWSER_EXPORT_TEXT: + case BROWSER_SAVE_URL_URI: + case BROWSER_SAVE_URL_URL: + case BROWSER_SAVE_URL_TEXT: + case HOTLIST_EXPORT: + case HISTORY_EXPORT: + case BROWSER_NAVIGATE_HOME: + case BROWSER_NAVIGATE_BACK: + case BROWSER_NAVIGATE_FORWARD: + case BROWSER_NAVIGATE_UP: + case BROWSER_NAVIGATE_RELOAD: + case BROWSER_NAVIGATE_RELOAD_ALL: + case BROWSER_NAVIGATE_STOP: + case BROWSER_NAVIGATE_URL: + case BROWSER_SCALE_VIEW: + case BROWSER_FIND_TEXT: + case BROWSER_IMAGES_FOREGROUND: + case BROWSER_IMAGES_BACKGROUND: + case BROWSER_BUFFER_ANIMS: + case BROWSER_BUFFER_ALL: + case BROWSER_SAVE_VIEW: + case BROWSER_WINDOW_DEFAULT: + case BROWSER_WINDOW_STAGGER: + case BROWSER_WINDOW_COPY: + case BROWSER_WINDOW_RESET: + case TREE_NEW_FOLDER: + case TREE_NEW_LINK: + case TREE_EXPAND_ALL: + case TREE_EXPAND_FOLDERS: + case TREE_EXPAND_LINKS: + case TREE_COLLAPSE_ALL: + case TREE_COLLAPSE_FOLDERS: + case TREE_COLLAPSE_LINKS: + case TREE_SELECTION: + case TREE_SELECTION_EDIT: + case TREE_SELECTION_LAUNCH: + case TREE_SELECTION_DELETE: + case TREE_SELECT_ALL: + case TREE_CLEAR_SELECTION: + case TOOLBAR_BUTTONS: + case TOOLBAR_ADDRESS_BAR: + case TOOLBAR_THROBBER: + case TOOLBAR_EDIT: + case CHOICES_SHOW: + case APPLICATION_QUIT: + if (Window()) + Window()->DetachCurrentMessage(); + nsbeos_pipe_message_top(message, NULL, fScaffolding); + break; + default: + message->PrintToStream(); + BView::MessageReceived(message); + } +} + + +status_t +NSBaseView::Archive(BMessage *archive, bool deep) const +{ + // force archiving only the base view + deep = false; + status_t err; + err = BView::Archive(archive, deep); + if (err < B_OK) + return err; + // add our own fields + // we try to reuse the same fields as NetPositive + archive->AddString("add_on", "application/x-vnd.NetSurf"); + //archive->AddInt32("version", 2); + archive->AddString("url", fScaffolding->url_bar->Text()); + archive->AddBool("openAsText", false); + archive->AddInt32("encoding", 258); + return err; +} + + +BArchivable * +NSBaseView::Instantiate(BMessage *archive) +{ + if (!validate_instantiation(archive, "NSBaseView")) + return NULL; + const char *url; + if (archive->FindString("url", &url) < B_OK) { + return NULL; + } + + struct replicant_thread_info *info = new replicant_thread_info; + info->url = url; + if (nsbeos_find_app_path(info->app) < B_OK) + return NULL; + info->args[0] = info->app; + info->args[1] = (char *)info->url.String(); + info->args[2] = NULL; + NSBaseView *view = new NSBaseView(archive); + replicant_view = view; + replicated = true; + + //TODO:FIXME: fix replicants + // netsurf_init() needs different args now... + //netsurf_init(2, info->args); + //return NULL; + + replicant_done_sem = create_sem(0, "NS Replicant created"); + thread_id nsMainThread = spawn_thread(nsbeos_replicant_main_thread, + "NetSurf Main Thread", B_NORMAL_PRIORITY, info); + if (nsMainThread < B_OK) { + delete_sem(replicant_done_sem); + delete info; + delete view; + return NULL; + } + resume_thread(nsMainThread); + while (acquire_sem(replicant_done_sem) == EINTR); + + return view; +} + + +void +NSBaseView::SetScaffolding(struct beos_scaffolding *scaf) +{ + fScaffolding = scaf; +} + + +// AttachedToWindow() is not enough to get the dragger and status bar +// stick to the panel color +void +NSBaseView::AllAttached() +{ + BView::AllAttached(); + struct beos_scaffolding *g = fScaffolding; + if (!g) + return; + // set targets to the topmost ns view + g->back_button->SetTarget(this); + g->forward_button->SetTarget(this); + g->stop_button->SetTarget(this); + g->reload_button->SetTarget(this); + g->home_button->SetTarget(this); + + g->url_bar->SetTarget(this); + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + g->tool_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + g->status_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->status_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; +#if defined(__HAIKU__) || defined(B_DANO_VERSION) + g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); +#endif +} + + +// #pragma mark - class NSBrowserWindow + + +NSBrowserWindow::NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf) + : BWindow(frame, "NetSurf", B_DOCUMENT_WINDOW, 0), + fScaffolding(scaf) +{ +} + + +NSBrowserWindow::~NSBrowserWindow() +{ +} + + +void +NSBrowserWindow::DispatchMessage(BMessage *message, BHandler *handler) +{ + BMessage *msg; + switch (message->what) { + case B_UI_SETTINGS_CHANGED: + msg = new BMessage(*message); + nsbeos_pipe_message_top(msg, this, fScaffolding); + break; + } + BWindow::DispatchMessage(message, handler); +} + + +void +NSBrowserWindow::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_ARGV_RECEIVED: + case B_REFS_RECEIVED: + case B_UI_SETTINGS_CHANGED: + DetachCurrentMessage(); + nsbeos_pipe_message_top(message, this, fScaffolding); + break; + default: + BWindow::MessageReceived(message); + } +} + +bool +NSBrowserWindow::QuitRequested(void) +{ + BWindow::QuitRequested(); + BMessage *message = DetachCurrentMessage(); + // BApplication::Quit() calls us directly... + if (message == NULL) + message = new BMessage(B_QUIT_REQUESTED); + nsbeos_pipe_message_top(message, this, fScaffolding); + return false; // we will Quit() ourselves from the main thread +} + + +// #pragma mark - implementation + +int32 nsbeos_replicant_main_thread(void *_arg) +{ + struct replicant_thread_info *info = (struct replicant_thread_info *)_arg; + int32 ret; + ret = main(2, info->args); + //netsurf_main_loop(); + //netsurf_exit(); + delete info; + //release + delete_sem(replicant_done_sem); + return ret; +} + + +/* event handlers and support functions for them */ + +static void nsbeos_window_destroy_event(NSBrowserWindow *window, nsbeos_scaffolding *g, BMessage *event) +{ + LOG(("Being Destroyed = %d", g->being_destroyed)); + + if (--open_windows == 0) + netsurf_quit = true; + + if (window) { + window->Lock(); + window->Quit(); + } + + if (!g->being_destroyed) { + g->being_destroyed = 1; + nsbeos_window_destroy_browser(g->top_level); + } +} + + +void nsbeos_scaffolding_update_colors(nsbeos_scaffolding *g) +{ + if (!g->top_view->LockLooper()) + return; + rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); + g->top_view->SetViewColor(c); + + g->tool_bar->SetViewColor(c); + g->back_button->SetViewColor(c); + g->forward_button->SetViewColor(c); + g->stop_button->SetViewColor(c); + g->reload_button->SetViewColor(c); + g->home_button->SetViewColor(c); + g->url_bar->SetViewColor(c); + g->throbber->SetViewColor(c); + g->scroll_view->SetViewColor(c); + + g->dragger->SetViewColor(c); + + g->status_bar->SetViewColor(c); + g->status_bar->SetLowColor(c); +#if defined(__HAIKU__) || defined(B_DANO_VERSION) + g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); +#endif + g->top_view->UnlockLooper(); +} + + +void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *message) +{ + int width, height; + struct browser_window *bw; + bw = nsbeos_get_browser_for_gui(scaffold->top_level); + bool reloadAll = false; + + LOG(("nsbeos_scaffolding_dispatch_event() what = 0x%08lx", message->what)); + switch (message->what) { + case B_QUIT_REQUESTED: + nsbeos_scaffolding_destroy(scaffold); + break; + case B_NETPOSITIVE_DOWN: + //XXX WRITEME + break; + case B_SIMPLE_DATA: + { + if (!message->HasRef("refs")) { + // XXX handle DnD + break; + } + // FALL THROUGH + // handle refs + } + case B_REFS_RECEIVED: + { + int32 i; + entry_ref ref; + + for (i = 0; message->FindRef("refs", i, &ref) >= B_OK; i++) { + BString url("file://"); + BPath path(&ref); + if (path.InitCheck() < B_OK) + break; + + BNode node(path.Path()); + if (node.InitCheck() < B_OK) + break; + if (node.IsSymLink()) { + // dereference the symlink + BEntry entry(path.Path(), true); + if (entry.InitCheck() < B_OK) + break; + if (entry.GetPath(&path) < B_OK) + break; + if (node.SetTo(path.Path()) < B_OK) + break; + } + + attr_info ai; + if (node.GetAttrInfo("META:url", &ai) >= B_OK) { + char data[(size_t)ai.size + 1]; + memset(data, 0, (size_t)ai.size + 1); + if (node.ReadAttr("META:url", B_STRING_TYPE, 0LL, data, (size_t)ai.size) < 4) + break; + url = data; + } else + url << path.Path(); + + if (/*message->WasDropped() &&*/ i == 0) + browser_window_go(bw, url.String(), 0, true); + else + browser_window_create(url.String(), bw, NULL, false, false); + } + break; + } + case B_ARGV_RECEIVED: + { + int32 i; + BString url; + for (i = 1; message->FindString("argv", i, &url) >= B_OK; i++) { + browser_window_create(url.String(), bw, NULL, false, false); + } + break; + } + case B_UI_SETTINGS_CHANGED: + nsbeos_update_system_ui_colors(); + nsbeos_scaffolding_update_colors(scaffold); + break; + case B_NETPOSITIVE_OPEN_URL: + { + int32 i; + BString url; + if (message->FindString("be:url", &url) < B_OK) + break; + browser_window_go(bw, url.String(), 0, true); + break; + } + case B_COPY: + gui_copy_to_clipboard(browser_window_get_selection(bw)); + break; + case B_CUT: + browser_window_key_press(bw, 24); + break; + case B_PASTE: + gui_paste_from_clipboard(scaffold->top_level, 0, 0); + break; + case B_SELECT_ALL: + LOG(("Selecting all text")); + selection_select_all(browser_window_get_selection(bw)); + break; + case B_NETPOSITIVE_BACK: + case BROWSER_NAVIGATE_BACK: + case 'back': + if (!history_back_available(bw->history)) + break; + history_back(bw, bw->history); + nsbeos_window_update_back_forward(scaffold); + break; + case B_NETPOSITIVE_FORWARD: + case BROWSER_NAVIGATE_FORWARD: + case 'forw': + if (!history_forward_available(bw->history)) + break; + history_forward(bw, bw->history); + nsbeos_window_update_back_forward(scaffold); + break; + case B_NETPOSITIVE_STOP: + case BROWSER_NAVIGATE_STOP: + case 'stop': + browser_window_stop(bw); + break; + case B_NETPOSITIVE_RELOAD: + case BROWSER_NAVIGATE_RELOAD_ALL: + case 'relo': + reloadAll = true; + // FALLTHRU + case BROWSER_NAVIGATE_RELOAD: + browser_window_reload(bw, reloadAll); + break; + case B_NETPOSITIVE_HOME: + case BROWSER_NAVIGATE_HOME: + case 'home': + { + static const char *addr = NETSURF_HOMEPAGE; + + if (nsoption_charp(homepage_url) != NULL) + addr = nsoption_charp(homepage_url); + + browser_window_go(bw, addr, 0, true); + break; + } + case 'urle': + { + BString text; + if (!scaffold->url_bar->LockLooper()) + break; + text = scaffold->url_bar->Text(); + scaffold->scroll_view->Target()->MakeFocus(); + scaffold->url_bar->UnlockLooper(); + browser_window_go(bw, text.String(), 0, true); + break; + } + case 'urlc': + { + BString text; + if (!scaffold->url_bar->LockLooper()) + break; + text = scaffold->url_bar->Text(); + scaffold->url_bar->UnlockLooper(); + //nsbeos_completion_update(text.String()); + break; + } +/* + case 'menu': + { + menu_action action; + if (message->FindInt32("action", (int32 *)&action) < B_OK) + break; + switch (action) { + case NO_ACTION: + case HELP_OPEN_CONTENTS: + case HELP_OPEN_GUIDE: + case HELP_OPEN_INFORMATION: + case HELP_OPEN_ABOUT: + case HELP_LAUNCH_INTERACTIVE: + + break; + } +#warning XXX + break; + } +*/ + case NO_ACTION: + break; + case HELP_OPEN_CONTENTS: + break; + case HELP_OPEN_GUIDE: + break; + case HELP_OPEN_INFORMATION: + break; + case HELP_OPEN_ABOUT: + break; + case HELP_LAUNCH_INTERACTIVE: + break; + case HISTORY_SHOW_LOCAL: + break; + case HISTORY_SHOW_GLOBAL: + break; + case HOTLIST_ADD_URL: + break; + case HOTLIST_SHOW: + break; + case COOKIES_SHOW: + break; + case COOKIES_DELETE: + break; + case BROWSER_PAGE: + break; + case BROWSER_PAGE_INFO: + break; + case BROWSER_PRINT: + break; + case BROWSER_NEW_WINDOW: + { + BString text; + if (!scaffold->url_bar->LockLooper()) + break; + text = scaffold->url_bar->Text(); + scaffold->url_bar->UnlockLooper(); + + browser_window_create(text.String(), bw, NULL, false, false); + break; + } + case BROWSER_VIEW_SOURCE: + { + if (!bw || !bw->current_content) + break; + nsbeos_gui_view_source(bw->current_content, + browser_window_get_selection(bw)); + break; + } + case BROWSER_OBJECT: + break; + case BROWSER_OBJECT_INFO: + break; + case BROWSER_OBJECT_RELOAD: + break; + case BROWSER_OBJECT_SAVE: + break; + case BROWSER_OBJECT_EXPORT_SPRITE: + break; + case BROWSER_OBJECT_SAVE_URL_URI: + break; + case BROWSER_OBJECT_SAVE_URL_URL: + break; + case BROWSER_OBJECT_SAVE_URL_TEXT: + break; + case BROWSER_SAVE: + break; + case BROWSER_SAVE_COMPLETE: + break; + case BROWSER_EXPORT_DRAW: + break; + case BROWSER_EXPORT_TEXT: + break; + case BROWSER_SAVE_URL_URI: + break; + case BROWSER_SAVE_URL_URL: + break; + case BROWSER_SAVE_URL_TEXT: + break; + case HOTLIST_EXPORT: + break; + case HISTORY_EXPORT: + break; + case B_NETPOSITIVE_UP: + case BROWSER_NAVIGATE_UP: + break; + case BROWSER_NAVIGATE_URL: + if (!scaffold->url_bar->LockLooper()) + break; + scaffold->url_bar->MakeFocus(); + scaffold->url_bar->UnlockLooper(); + break; + case BROWSER_SCALE_VIEW: + break; + case BROWSER_FIND_TEXT: + break; + case BROWSER_IMAGES_FOREGROUND: + break; + case BROWSER_IMAGES_BACKGROUND: + break; + case BROWSER_BUFFER_ANIMS: + break; + case BROWSER_BUFFER_ALL: + break; + case BROWSER_SAVE_VIEW: + break; + case BROWSER_WINDOW_DEFAULT: + break; + case BROWSER_WINDOW_STAGGER: + break; + case BROWSER_WINDOW_COPY: + break; + case BROWSER_WINDOW_RESET: + break; + case TREE_NEW_FOLDER: + case TREE_NEW_LINK: + case TREE_EXPAND_ALL: + case TREE_EXPAND_FOLDERS: + case TREE_EXPAND_LINKS: + case TREE_COLLAPSE_ALL: + case TREE_COLLAPSE_FOLDERS: + case TREE_COLLAPSE_LINKS: + case TREE_SELECTION: + case TREE_SELECTION_EDIT: + case TREE_SELECTION_LAUNCH: + case TREE_SELECTION_DELETE: + case TREE_SELECT_ALL: + case TREE_CLEAR_SELECTION: + break; + case TOOLBAR_BUTTONS: + break; + case TOOLBAR_ADDRESS_BAR: + break; + case TOOLBAR_THROBBER: + break; + case TOOLBAR_EDIT: + break; + case CHOICES_SHOW: + break; + case APPLICATION_QUIT: + netsurf_quit = true; + break; + default: + break; + } +} + +void nsbeos_scaffolding_destroy(nsbeos_scaffolding *scaffold) +{ + LOG(("Being Destroyed = %d", scaffold->being_destroyed)); + if (scaffold->being_destroyed) return; + scaffold->being_destroyed = 1; + nsbeos_window_destroy_event(scaffold->window, scaffold, NULL); +} + + +void nsbeos_window_update_back_forward(struct beos_scaffolding *g) +{ + int width, height; + struct browser_window *bw = nsbeos_get_browser_for_gui(g->top_level); + + if (!g->top_view->LockLooper()) + return; + + g->back_button->SetEnabled(history_back_available(bw->history)); + g->forward_button->SetEnabled(history_forward_available(bw->history)); + + g->top_view->UnlockLooper(); + +#warning XXX +#if 0 /* GTK */ + beos_widget_set_sensitive(beos_WIDGET(g->back_button), + history_back_available(bw->history)); + beos_widget_set_sensitive(beos_WIDGET(g->forward_button), + history_forward_available(bw->history)); + + beos_widget_set_sensitive(beos_WIDGET(g->back_menu), + history_back_available(bw->history)); + beos_widget_set_sensitive(beos_WIDGET(g->forward_menu), + history_forward_available(bw->history)); + + /* update the local history window, as well as queuing a redraw + * for it. + */ + history_size(bw->history, &width, &height); + beos_widget_set_size_request(beos_WIDGET(g->history_window->drawing_area), + width, height); + beos_widget_queue_draw(beos_WIDGET(g->history_window->drawing_area)); +#endif +} + +void nsbeos_throb(void *p) +{ + struct beos_scaffolding *g = (struct beos_scaffolding *)p; + + if (g->throb_frame >= (nsbeos_throbber->nframes - 1)) + g->throb_frame = 1; + else + g->throb_frame++; + + if (!g->top_view->LockLooper()) + return; + +#if 0 + g->throbber->SetViewBitmap(nsbeos_throbber->framedata[g->throb_frame], + B_FOLLOW_RIGHT | B_FOLLOW_TOP); +#endif + g->throbber->SetBitmap(nsbeos_throbber->framedata[g->throb_frame]); + g->throbber->Invalidate(); + + g->top_view->UnlockLooper(); + + schedule(10, nsbeos_throb, p); + +} + +#warning XXX +#if 0 /* GTK */ + +gboolean nsbeos_openfile_open(beosWidget *widget, gpointer data) +{ + struct browser_window *bw = nsbeos_get_browser_for_gui( + current_model->top_level); + char *filename = beos_file_chooser_get_filename( + beos_FILE_CHOOSER(wndOpenFile)); + char *url = malloc(strlen(filename) + sizeof("file://")); + + sprintf(url, "file://%s", filename); + + browser_window_go(bw, url, 0, true); + + g_free(filename); + free(url); + + return TRUE; +} +#endif + +#warning XXX +#if 0 /* GTK */ +/* signal handlers for menu entries */ +#define MENUHANDLER(x) gboolean nsbeos_on_##x##_activate(beosMenuItem *widget, \ + gpointer g) + +MENUHANDLER(new_window) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); + const char *url = beos_entry_get_text(beos_ENTRY(gw->url_bar)); + + browser_window_create(url, bw, NULL, false); + + return TRUE; +} + +MENUHANDLER(open_location) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + beos_widget_grab_focus(beos_WIDGET(gw->url_bar)); + + return TRUE; +} + +MENUHANDLER(open_file) +{ + current_model = (struct beos_scaffolding *)g; + beos_dialog_run(wndOpenFile); + + return TRUE; +} + +MENUHANDLER(close_window) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + beos_widget_destroy(beos_WIDGET(gw->window)); + + return TRUE; +} + +MENUHANDLER(quit) +{ + netsurf_quit = true; + return TRUE; +} + +MENUHANDLER(preferences) +{ + beos_widget_show(beos_WIDGET(wndPreferences)); + + return TRUE; +} + +MENUHANDLER(zoom_in) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); + float old_scale = nsbeos_get_scale_for_gui(gw->top_level); + + browser_window_set_scale(bw, old_scale + 0.05, true); + + return TRUE; +} + +MENUHANDLER(normal_size) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); + + browser_window_set_scale(bw, 1.0, true); + + return TRUE; +} + +MENUHANDLER(zoom_out) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(gw->top_level); + float old_scale = nsbeos_get_scale_for_gui(gw->top_level); + + browser_window_set_scale(bw, old_scale - 0.05, true); + + return TRUE; +} + +MENUHANDLER(full_screen) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + if (gw->fullscreen) { + beos_window_unfullscreen(gw->window); + } else { + beos_window_fullscreen(gw->window); + } + + gw->fullscreen = !gw->fullscreen; + + return TRUE; +} + +MENUHANDLER(menu_bar) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { + beos_widget_show(beos_WIDGET(gw->menu_bar)); + } else { + beos_widget_hide(beos_WIDGET(gw->menu_bar)); + } + + return TRUE; +} + +MENUHANDLER(tool_bar) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { + beos_widget_show(beos_WIDGET(gw->tool_bar)); + } else { + beos_widget_hide(beos_WIDGET(gw->tool_bar)); + } + + return TRUE; +} + +MENUHANDLER(status_bar) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + if (beos_check_menu_item_get_active(beos_CHECK_MENU_ITEM(widget))) { + beos_widget_show(beos_WIDGET(gw->status_bar)); + } else { + beos_widget_hide(beos_WIDGET(gw->status_bar)); + } + + return TRUE; +} + +MENUHANDLER(downloads) +{ + nsbeos_download_show(); + + return TRUE; +} + +MENUHANDLER(save_window_size) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + int x,y,w,h; + + nsoption_set_int(toolbar_status_width, + beos_paned_get_position(gw->status_pane)); + beos_window_get_position(gw->window, &x, &y); + beos_window_get_size(gw->window, &w, &h); + + nsoption_set_int(window_x, x); + nsoption_set_int(window_y, y); + nsoption_set_int(window_width, w); + nsoption_set_int(window_height, h); + + nsoption_write(options_file_location); + + return TRUE; +} + +MENUHANDLER(toggle_debug_rendering) +{ + html_redraw_debug = !html_redraw_debug; + nsbeos_reflow_all_windows(); + return TRUE; +} + +MENUHANDLER(save_box_tree) +{ + beosWidget *save_dialog; + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + save_dialog = beos_file_chooser_dialog_new("Save File", gw->window, + beos_FILE_CHOOSER_ACTION_SAVE, + beos_STOCK_CANCEL, beos_RESPONSE_CANCEL, + beos_STOCK_SAVE, beos_RESPONSE_ACCEPT, + NULL); + + beos_file_chooser_set_current_folder(beos_FILE_CHOOSER(save_dialog), + getenv("HOME") ? getenv("HOME") : "/"); + + beos_file_chooser_set_current_name(beos_FILE_CHOOSER(save_dialog), + "boxtree.txt"); + + if (beos_dialog_run(beos_DIALOG(save_dialog)) == beos_RESPONSE_ACCEPT) { + char *filename = beos_file_chooser_get_filename( + beos_FILE_CHOOSER(save_dialog)); + FILE *fh; + LOG(("Saving box tree dump to %s...\n", filename)); + + fh = fopen(filename, "w"); + if (fh == NULL) { + warn_user("Error saving box tree dump.", + "Unable to open file for writing."); + } else { + struct browser_window *bw; + bw = nsbeos_get_browser_window(gw->top_level); + + if (bw->current_content && + bw->current_content->type == + CONTENT_HTML) { + box_dump(fh, + bw->current_content->data.html.layout, + 0); + } + + fclose(fh); + } + + g_free(filename); + } + + beos_widget_destroy(save_dialog); +} + +MENUHANDLER(stop) +{ + return nsbeos_window_stop_button_clicked(beos_WIDGET(widget), g); +} + +MENUHANDLER(reload) +{ + return nsbeos_window_reload_button_clicked(beos_WIDGET(widget), g); +} + +MENUHANDLER(back) +{ + return nsbeos_window_back_button_clicked(beos_WIDGET(widget), g); +} + +MENUHANDLER(forward) +{ + return nsbeos_window_forward_button_clicked(beos_WIDGET(widget), g); +} + +MENUHANDLER(home) +{ + return nsbeos_window_home_button_clicked(beos_WIDGET(widget), g); +} + +MENUHANDLER(local_history) +{ + struct beos_scaffolding *gw = (struct beos_scaffolding *)g; + + beos_widget_show(beos_WIDGET(gw->history_window->window)); + gdk_window_raise(beos_WIDGET(gw->history_window->window)->window); + + return TRUE; +} + +MENUHANDLER(global_history) +{ + beos_widget_show(beos_WIDGET(wndHistory)); + gdk_window_raise(beos_WIDGET(wndHistory)->window); + + return TRUE; +} + +MENUHANDLER(about) +{ + beos_widget_show(beos_WIDGET(wndAbout)); + gdk_window_raise(beos_WIDGET(wndAbout)->window); + return TRUE; +} + +/* signal handler functions for the local history window */ +gboolean nsbeos_history_expose_event(beosWidget *widget, + GdkEventExpose *event, gpointer g) +{ + struct beos_history_window *hw = (struct beos_history_window *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(hw->g->top_level); + + struct redraw_context ctx = { + .interactive = true, + .background_images = true, + .plot = &nsbeos_plotters + }; + + 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 = nsbeos_plotters; + + history_redraw(bw->history, &ctx); + + g_object_unref(current_gc); +#ifdef CAIRO_VERSION + cairo_destroy(current_cr); +#endif + return FALSE; +} + +gboolean nsbeos_history_button_press_event(beosWidget *widget, + GdkEventButton *event, gpointer g) +{ + struct beos_history_window *hw = (struct beos_history_window *)g; + struct browser_window *bw = nsbeos_get_browser_for_gui(hw->g->top_level); + + LOG(("X=%g, Y=%g", event->x, event->y)); + + history_click(bw, bw->history, + event->x, event->y, false); + + return TRUE; +} + +#define GET_WIDGET(x) glade_xml_get_widget(g->xml, (x)) + +static gboolean do_scroll_event(beosWidget *widget, GdkEvent *ev, + gpointer data) +{ + switch (((GdkEventScroll *)ev)->direction) + { + case GDK_SCROLL_UP: + case GDK_SCROLL_DOWN: + beos_widget_event(g_object_get_data( + G_OBJECT(widget), "vScroll"), ev); + break; + default: + beos_widget_event(g_object_get_data( + G_OBJECT(widget), "hScroll"), ev); + } + + return TRUE; +} +#endif + +NSBrowserWindow *nsbeos_find_last_window(void) +{ + int32 i; + if (!be_app || !be_app->Lock()) + return NULL; + for (i = be_app->CountWindows() - 1; i >= 0; i--) { + if (be_app->WindowAt(i) == NULL) + continue; + NSBrowserWindow *win; + win = dynamic_cast(be_app->WindowAt(i)); + if (win) { + win->Lock(); + be_app->Unlock(); + return win; + } + } + be_app->Unlock(); + return NULL; +} + +NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold) +{ + return scaffold->window; +} + +static void recursively_set_menu_items_target(BMenu *menu, BHandler *handler) +{ + menu->SetTargetForItems(handler); + for (int i = 0; menu->ItemAt(i); i++) { + if (!menu->SubmenuAt(i)) + continue; + recursively_set_menu_items_target(menu->SubmenuAt(i), handler); + } +} + +void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view) +{ + LOG(("Attaching view to scaffolding %p", g)); + + // this is a replicant,... and it went bad + if (!g->window) { + if (g->top_view->Looper() && !g->top_view->LockLooper()) + return; + } + + BRect rect(g->top_view->Bounds()); + rect.top += TOOLBAR_HEIGHT; + rect.right -= B_V_SCROLL_BAR_WIDTH; + rect.bottom -= B_H_SCROLL_BAR_HEIGHT; + + view->ResizeTo(rect.Width() /*+ 1*/, rect.Height() /*+ 1*/); + view->MoveTo(rect.LeftTop()); + + + g->scroll_view = new BScrollView("NetSurfScrollView", view, + B_FOLLOW_ALL, 0, true, true, B_NO_BORDER); + + g->top_view->AddChild(g->scroll_view); + + view->MakeFocus(); + + // resize the horiz scrollbar to make room for the status bar and add it. + + BScrollBar *sb = g->scroll_view->ScrollBar(B_HORIZONTAL); + rect = sb->Frame(); + float divider = rect.Width() + 1; + //divider /= 2; + divider *= 67.0/100; // 67% + + sb->ResizeBy(-divider, 0); + sb->MoveBy(divider, 0); + + rect.right = rect.left + divider - 1; + + /* + BBox *statusBarBox = new BBox(rect, "StatusBarBox", + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, + B_WILL_DRAW | B_FRAME_EVENTS, + B_RAISED_BORDER); + */ + + g->status_bar->MoveTo(rect.LeftTop()); + g->status_bar->ResizeTo(rect.Width() + 1, rect.Height() + 1); + g->scroll_view->AddChild(g->status_bar); + g->status_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->status_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; +#if defined(__HAIKU__) || defined(B_DANO_VERSION) + g->status_bar->SetHighColor(ui_color(B_PANEL_TEXT_COLOR)); +#endif + + + + // set targets to the topmost ns view, + // we might not have a window later (replicant ?) + // this won't work for replicants, since the base view isn't attached yet + // we'll redo this in NSBaseView::AllAttached + g->back_button->SetTarget(view); + g->forward_button->SetTarget(view); + g->stop_button->SetTarget(view); + g->reload_button->SetTarget(view); + g->home_button->SetTarget(view); + + g->url_bar->SetTarget(view); + + if (g->window) { + recursively_set_menu_items_target(g->menu_bar, view); + + // add toolbar shortcuts + BMessage *message; + + message = new BMessage('back'); + message->AddPointer("scaffolding", g); + g->window->AddShortcut(B_LEFT_ARROW, 0, message, view); + + message = new BMessage('forw'); + message->AddPointer("scaffolding", g); + g->window->AddShortcut(B_RIGHT_ARROW, 0, message, view); + + message = new BMessage('stop'); + message->AddPointer("scaffolding", g); + g->window->AddShortcut('S', 0, message, view); + + message = new BMessage('relo'); + message->AddPointer("scaffolding", g); + g->window->AddShortcut('R', 0, message, view); + + message = new BMessage('home'); + message->AddPointer("scaffolding", g); + g->window->AddShortcut('H', 0, message, view); + + g->window->Show(); + } else { + if (g->top_view->Looper()) + g->top_view->UnlockLooper(); + } + + +#warning XXX +#if 0 /* GTK */ + beosWidget *scrollbar; + + /* Insert the viewport into the right part of our table */ + beosTable *table = beos_TABLE(GET_WIDGET("centreTable")); + LOG(("Attaching viewport to scaffolding %p", g)); + beos_table_attach_defaults(table, beos_WIDGET(vp), 0, 1, 0, 1); + + /* connect our scrollbars to the viewport */ + scrollbar = GET_WIDGET("coreScrollHorizontal"); + beos_viewport_set_hadjustment(vp, + beos_range_get_adjustment(beos_RANGE(scrollbar))); + g_object_set_data(G_OBJECT(vp), "hScroll", scrollbar); + scrollbar = GET_WIDGET("coreScrollVertical"); + beos_viewport_set_vadjustment(vp, + beos_range_get_adjustment(beos_RANGE(scrollbar))); + g_object_set_data(G_OBJECT(vp), "vScroll", scrollbar); + g_signal_connect(G_OBJECT(vp), "scroll_event", + G_CALLBACK(do_scroll_event), NULL); + + gdk_window_set_accept_focus (beos_WIDGET(vp)->window, TRUE); + + /* And set the size-request to zero to cause it to get its act together */ + beos_widget_set_size_request(beos_WIDGET(vp), 0, 0); + +#endif +} + +static BMenuItem *make_menu_item(const char *name, BMessage *message) +{ + BMenuItem *item; + BString label(messages_get(name)); + BString accel; + uint32 mods = 0; + char key = 0; + // try to understand accelerators + int32 start = label.IFindLast(" "); + if (start > 0 && (label.Length() - start > 1) + && (label.Length() - start < 7) + && (label[start + 1] == 'F' + || !strcmp(label.String() + start + 1, "PRINT") + || label[start + 1] == '\xe2' + || label[start + 1] == '^')) { + + label.MoveInto(accel, start + 1, label.Length()); + // strip the trailing spaces + while (label[label.Length() - 1] == ' ') + label.Truncate(label.Length() - 1); + + if (accel.FindFirst("\xe2\x87\x91") > -1) { + accel.RemoveFirst("\xe2\x87\x91"); + mods |= B_SHIFT_KEY; + } + if (accel.FindFirst("^") > -1) { + accel.RemoveFirst("^"); + mods |= B_CONTROL_KEY; // ALT!!! + } + if (accel.FindFirst("PRINT") > -1) { + accel.RemoveFirst("PRINT"); + //mods |= ; // ALT!!! + key = B_PRINT_KEY; + } + if (accel.Length() > 1 && accel[0] == 'F') { // Function key + int num; + if (sscanf(accel.String(), "F%d", &num) > 0) { + // + } + } else if (accel.Length() > 0) { + key = accel[0]; + } + //printf("MENU: detected accel '%s' mods 0x%08lx, key %d\n", accel.String(), mods, key); + } + + // turn ... into ellipsis + label.ReplaceAll("...", B_UTF8_ELLIPSIS); + + item = new BMenuItem(label.String(), message, key, mods); + + return item; +} + +nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel) +{ + struct beos_scaffolding *g = (struct beos_scaffolding *)malloc(sizeof(*g)); + + LOG(("Constructing a scaffold of %p for gui_window %p", g, toplevel)); + + g->top_level = toplevel; + g->being_destroyed = 0; + g->fullscreen = false; + + open_windows++; + + BMessage *message; + BRect rect; + + g->window = NULL; + g->menu_bar = NULL; + g->window = NULL; + + if (replicated && !replicant_view) { + warn_user("Error: No subwindow allowed when replicated.", NULL); + return NULL; + } + + + if (!replicant_view) { + + BRect frame(0, 0, 600-1, 500-1); + if (nsoption_int(window_width) > 0) { + frame.Set(0, 0, nsoption_int(window_width) - 1, nsoption_int(window_height) - 1); + frame.OffsetToSelf(nsoption_int(window_x), nsoption_int(window_y)); + } else { + BPoint pos(50, 50); + // XXX: use last BApplication::WindowAt()'s dynamic_cast Frame() + NSBrowserWindow *win = nsbeos_find_last_window(); + if (win) { + pos = win->Frame().LeftTop(); + win->Unlock(); + } + pos += BPoint(20, 20); + BScreen screen; + BRect screenFrame(screen.Frame()); + if (pos.y + frame.Height() >= screenFrame.Height()) { + pos.y = 50; + pos.x += 50; + } + if (pos.x + frame.Width() >= screenFrame.Width()) { + pos.x = 50; + pos.y = 50; + } + frame.OffsetToSelf(pos); + } + + g->window = new NSBrowserWindow(frame, g); + + rect = frame.OffsetToCopy(0,0); + rect.bottom = rect.top + 20; + + // build menus + g->menu_bar = new BMenuBar(rect, "menu_bar"); + g->window->AddChild(g->menu_bar); + + BMenu *menu; + BMenu *submenu; + BMenuItem *item; + + // App menu + //XXX: use icon item ? + + menu = new BMenu(messages_get("NetSurf")); + g->menu_bar->AddItem(menu); + + message = new BMessage(NO_ACTION); + item = make_menu_item("Info", message); + menu->AddItem(item); + + message = new BMessage(NO_ACTION); + item = make_menu_item("AppHelp", message); + menu->AddItem(item); + + submenu = new BMenu(messages_get("Open")); + menu->AddItem(submenu); + + message = new BMessage(NO_ACTION); + item = make_menu_item("OpenURL", message); + submenu->AddItem(item); + + message = new BMessage(CHOICES_SHOW); + item = make_menu_item("Choices", message); + menu->AddItem(item); + + message = new BMessage(APPLICATION_QUIT); + item = make_menu_item("Quit", message); + menu->AddItem(item); + + // Page menu + + menu = new BMenu(messages_get("Page")); + g->menu_bar->AddItem(menu); + + message = new BMessage(BROWSER_PAGE_INFO); + item = make_menu_item("PageInfo", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_SAVE); + item = make_menu_item("Save", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_SAVE_COMPLETE); + item = make_menu_item("SaveComp", message); + menu->AddItem(item); + + submenu = new BMenu(messages_get("Export")); + menu->AddItem(submenu); + + /* + message = new BMessage(BROWSER_EXPORT_DRAW); + item = make_menu_item("Draw", message); + submenu->AddItem(item); + */ + + message = new BMessage(BROWSER_EXPORT_TEXT); + item = make_menu_item("Text", message); + submenu->AddItem(item); + + + submenu = new BMenu(messages_get("SaveURL")); + menu->AddItem(submenu); + + //XXX + message = new BMessage(BROWSER_OBJECT_SAVE_URL_URL); + item = make_menu_item("URL", message); + submenu->AddItem(item); + + + message = new BMessage(BROWSER_PRINT); + item = make_menu_item("Print", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NEW_WINDOW); + item = make_menu_item("NewWindow", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_VIEW_SOURCE); + item = make_menu_item("ViewSrc", message); + menu->AddItem(item); + + // Object menu + + menu = new BMenu(messages_get("Object")); + g->menu_bar->AddItem(menu); + + message = new BMessage(BROWSER_OBJECT_INFO); + item = make_menu_item("ObjInfo", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_OBJECT_SAVE); + item = make_menu_item("ObjSave", message); + menu->AddItem(item); + // XXX: submenu: Sprite ? + + message = new BMessage(BROWSER_OBJECT_RELOAD); + item = make_menu_item("ObjReload", message); + menu->AddItem(item); + + // Navigate menu + + menu = new BMenu(messages_get("Navigate")); + g->menu_bar->AddItem(menu); + + message = new BMessage(BROWSER_NAVIGATE_HOME); + item = make_menu_item("Home", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NAVIGATE_BACK); + item = make_menu_item("Back", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NAVIGATE_FORWARD); + item = make_menu_item("Forward", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NAVIGATE_UP); + item = make_menu_item("UpLevel", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NAVIGATE_RELOAD); + item = make_menu_item("Reload", message); + menu->AddItem(item); + + message = new BMessage(BROWSER_NAVIGATE_STOP); + item = make_menu_item("Stop", message); + menu->AddItem(item); + + // View menu + + menu = new BMenu(messages_get("View")); + g->menu_bar->AddItem(menu); + + message = new BMessage(BROWSER_SCALE_VIEW); + item = make_menu_item("ScaleView", message); + menu->AddItem(item); + + submenu = new BMenu(messages_get("Images")); + menu->AddItem(submenu); + + message = new BMessage(BROWSER_IMAGES_FOREGROUND); + item = make_menu_item("ForeImg", message); + submenu->AddItem(item); + + message = new BMessage(BROWSER_IMAGES_BACKGROUND); + item = make_menu_item("BackImg", message); + submenu->AddItem(item); + + + submenu = new BMenu(messages_get("Toolbars")); + menu->AddItem(submenu); + submenu->SetEnabled(false); + + message = new BMessage(NO_ACTION); + item = make_menu_item("ToolButtons", message); + submenu->AddItem(item); + + message = new BMessage(NO_ACTION); + item = make_menu_item("ToolAddress", message); + submenu->AddItem(item); + + message = new BMessage(NO_ACTION); + item = make_menu_item("ToolThrob", message); + submenu->AddItem(item); + + message = new BMessage(NO_ACTION); + item = make_menu_item("ToolStatus", message); + submenu->AddItem(item); + + + submenu = new BMenu(messages_get("Render")); + menu->AddItem(submenu); + + message = new BMessage(BROWSER_BUFFER_ANIMS); + item = make_menu_item("RenderAnims", message); + submenu->AddItem(item); + + message = new BMessage(BROWSER_BUFFER_ALL); + item = make_menu_item("RenderAll", message); + submenu->AddItem(item); + + + message = new BMessage(NO_ACTION); + item = make_menu_item("OptDefault", message); + menu->AddItem(item); + + // Utilities menu + + menu = new BMenu(messages_get("Utilities")); + g->menu_bar->AddItem(menu); + + submenu = new BMenu(messages_get("Hotlist")); + menu->AddItem(submenu); + + message = new BMessage(HOTLIST_ADD_URL); + item = make_menu_item("HotlistAdd", message); + submenu->AddItem(item); + + message = new BMessage(HOTLIST_SHOW); + item = make_menu_item("HotlistShow", message); + submenu->AddItem(item); + + + submenu = new BMenu(messages_get("History")); + menu->AddItem(submenu); + + message = new BMessage(HISTORY_SHOW_LOCAL); + item = make_menu_item("HistLocal", message); + submenu->AddItem(item); + + message = new BMessage(HISTORY_SHOW_GLOBAL); + item = make_menu_item("HistGlobal", message); + submenu->AddItem(item); + + + submenu = new BMenu(messages_get("Cookies")); + menu->AddItem(submenu); + + message = new BMessage(COOKIES_SHOW); + item = make_menu_item("ShowCookies", message); + submenu->AddItem(item); + + message = new BMessage(COOKIES_DELETE); + item = make_menu_item("DeleteCookies", message); + submenu->AddItem(item); + + + message = new BMessage(BROWSER_FIND_TEXT); + item = make_menu_item("FindText", message); + menu->AddItem(item); + + submenu = new BMenu(messages_get("Window")); + menu->AddItem(submenu); + + message = new BMessage(BROWSER_WINDOW_DEFAULT); + item = make_menu_item("WindowSave", message); + submenu->AddItem(item); + + message = new BMessage(BROWSER_WINDOW_STAGGER); + item = make_menu_item("WindowStagr", message); + submenu->AddItem(item); + + message = new BMessage(BROWSER_WINDOW_COPY); + item = make_menu_item("WindowSize", message); + submenu->AddItem(item); + + message = new BMessage(BROWSER_WINDOW_RESET); + item = make_menu_item("WindowReset", message); + submenu->AddItem(item); + + + // Help menu + + menu = new BMenu(messages_get("Help")); + g->menu_bar->AddItem(menu); + + message = new BMessage(HELP_OPEN_CONTENTS); + item = make_menu_item("HelpContent", message); + menu->AddItem(item); + + message = new BMessage(HELP_OPEN_GUIDE); + item = make_menu_item("HelpGuide", message); + menu->AddItem(item); + + message = new BMessage(HELP_OPEN_INFORMATION); + item = make_menu_item("HelpInfo", message); + menu->AddItem(item); + + message = new BMessage(HELP_OPEN_ABOUT); + item = make_menu_item("HelpAbout", message); + menu->AddItem(item); + + message = new BMessage(HELP_LAUNCH_INTERACTIVE); + item = make_menu_item("HelpInter", message); + menu->AddItem(item); + + // the base view that receives the toolbar, statusbar and top-level view. + rect = frame.OffsetToCopy(0,0); + rect.top = g->menu_bar->Bounds().Height() + 1; + //rect.top = 20 + 1; // XXX + //rect.bottom -= B_H_SCROLL_BAR_HEIGHT; + g->top_view = new NSBaseView(rect); + // add the top view to the window + g->window->AddChild(g->top_view); + } else { // replicant_view + // the base view has already been created with the archive constructor + g->top_view = replicant_view; + } + g->top_view->SetScaffolding(g); + + // build popup menu + g->popup_menu = new BPopUpMenu(""); + + + // the dragger to allow replicating us + // XXX: try to stuff it in the status bar at the bottom + // (BDragger *must* be a parent, sibiling or direct child of NSBaseView!) + rect = g->top_view->Bounds(); + rect.bottom = rect.top + TOOLBAR_HEIGHT - 1; + rect.left = rect.right - DRAGGER_WIDTH + 1; + g->dragger = new BDragger(rect, g->top_view, + B_FOLLOW_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW); + g->top_view->AddChild(g->dragger); + g->dragger->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->dragger->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; + + // tool_bar + // the toolbar is also the dragger for now + // XXX: try to stuff it in the status bar at the bottom + // (BDragger *must* be a parent, sibiling or direct child of NSBaseView!) + rect = g->top_view->Bounds(); + rect.bottom = rect.top + TOOLBAR_HEIGHT - 1; + rect.right = rect.right - DRAGGER_WIDTH; + g->tool_bar = new BView(rect, "Toolbar", + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW); + g->top_view->AddChild(g->tool_bar); + g->tool_bar->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + g->tool_bar->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)) ; + + // buttons +#warning use BPictureButton + rect = g->tool_bar->Bounds(); + rect.right = TOOLBAR_HEIGHT; + rect.InsetBySelf(5, 5); + rect.OffsetBySelf(0, -1); + int nButtons = 0; + + message = new BMessage('back'); + message->AddPointer("scaffolding", g); + g->back_button = new BButton(rect, "back_button", "<", message); + g->tool_bar->AddChild(g->back_button); + nButtons++; + + rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); + message = new BMessage('forw'); + message->AddPointer("scaffolding", g); + g->forward_button = new BButton(rect, "forward_button", ">", message); + g->tool_bar->AddChild(g->forward_button); + nButtons++; + + rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); + message = new BMessage('stop'); + message->AddPointer("scaffolding", g); + g->stop_button = new BButton(rect, "stop_button", "S", message); + g->tool_bar->AddChild(g->stop_button); + nButtons++; + + rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); + message = new BMessage('relo'); + message->AddPointer("scaffolding", g); + g->reload_button = new BButton(rect, "reload_button", "R", message); + g->tool_bar->AddChild(g->reload_button); + nButtons++; + + rect.OffsetBySelf(TOOLBAR_HEIGHT, 0); + message = new BMessage('home'); + message->AddPointer("scaffolding", g); + g->home_button = new BButton(rect, "home_button", "H", message); + g->tool_bar->AddChild(g->home_button); + nButtons++; + + + // url bar + rect = g->tool_bar->Bounds(); + rect.left += TOOLBAR_HEIGHT * nButtons; + rect.right -= TOOLBAR_HEIGHT * 1; + rect.InsetBySelf(5, 5); + message = new BMessage('urle'); + message->AddPointer("scaffolding", g); + g->url_bar = new BTextControl(rect, "url_bar", "url", "", message, + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + g->url_bar->SetDivider(g->url_bar->StringWidth("url ")); + g->tool_bar->AddChild(g->url_bar); + + + // throbber + rect.Set(0, 0, 24, 24); + rect.OffsetTo(g->tool_bar->Bounds().right - 24 - (TOOLBAR_HEIGHT - 24) / 2, + (TOOLBAR_HEIGHT - 24) / 2); + g->throbber = new NSThrobber(rect); + g->tool_bar->AddChild(g->throbber); + g->throbber->SetViewColor(g->tool_bar->ViewColor()); + g->throbber->SetLowColor(g->tool_bar->ViewColor()); + g->throbber->SetDrawingMode(B_OP_ALPHA); + g->throbber->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); + /* set up the throbber. */ + g->throbber->SetBitmap(nsbeos_throbber->framedata[0]); + g->throb_frame = 0; + + + // the status bar at the bottom + BString status("NetSurf"); + status << " " << netsurf_version; + g->status_bar = new BStringView(BRect(0,0,-1,-1), "StatusBar", + status.String(), B_FOLLOW_LEFT/*_RIGHT*/ | B_FOLLOW_BOTTOM); + + // will be added to the scrollview when adding the top view. + + // notify the thread creating the replicant that we're done + if (replicant_view) + release_sem(replicant_done_sem); + + replicant_view = NULL; + +#warning XXX +#if 0 /* GTK */ + /* load the window template from the glade xml file, and extract + * widget references from it for later use. + */ + g->xml = glade_xml_new(glade_file_location, "wndBrowser", NULL); + glade_xml_signal_autoconnect(g->xml); + g->window = beos_WINDOW(GET_WIDGET("wndBrowser")); + g->url_bar = beos_ENTRY(GET_WIDGET("URLBar")); + g->menu_bar = beos_MENU_BAR(GET_WIDGET("menubar")); + g->status_bar = beos_LABEL(GET_WIDGET("statusBar")); + g->tool_bar = beos_TOOLBAR(GET_WIDGET("toolbar")); + g->back_button = beos_TOOL_BUTTON(GET_WIDGET("toolBack")); + g->forward_button = beos_TOOL_BUTTON(GET_WIDGET("toolForward")); + g->stop_button = beos_TOOL_BUTTON(GET_WIDGET("toolStop")); + g->reload_button = beos_TOOL_BUTTON(GET_WIDGET("toolReload")); + g->back_menu = beos_MENU_ITEM(GET_WIDGET("back")); + g->forward_menu = beos_MENU_ITEM(GET_WIDGET("forward")); + g->stop_menu = beos_MENU_ITEM(GET_WIDGET("stop")); + g->reload_menu = beos_MENU_ITEM(GET_WIDGET("reload")); + g->throbber = beos_IMAGE(GET_WIDGET("throbber")); + g->status_pane = beos_PANED(GET_WIDGET("hpaned1")); + + /* set this window's size and position to what's in the options, or + * or some sensible default if they're not set yet. + */ + if (nsoption_int(window_width) > 0) { + beos_window_move(g->window, nsoption_int(window_x), nsoption_int(window_y)); + beos_window_resize(g->window, nsoption_int(window_width), + nsoption_int(window_height)); + } else { + beos_window_set_default_size(g->window, 600, 600); + } + + /* set the size of the hpane with status bar and h scrollbar */ + beos_paned_set_position(g->status_pane, nsoption_int(toolbar_status_width)); + + /* set the URL entry box to expand, as we can't do this from within + * glade because of the way it emulates toolbars. + */ + beos_tool_item_set_expand(beos_TOOL_ITEM(GET_WIDGET("toolURLBar")), TRUE); + + /* disable toolbar buttons that make no sense initially. */ + beos_widget_set_sensitive(beos_WIDGET(g->back_button), FALSE); + beos_widget_set_sensitive(beos_WIDGET(g->forward_button), FALSE); + beos_widget_set_sensitive(beos_WIDGET(g->stop_button), FALSE); + + /* create the local history window to be assoicated with this browser */ + g->history_window = malloc(sizeof(struct beos_history_window)); + g->history_window->g = g; + g->history_window->window = beos_WINDOW( + beos_window_new(beos_WINDOW_TOPLEVEL)); + beos_window_set_transient_for(g->history_window->window, g->window); + beos_window_set_default_size(g->history_window->window, 400, 400); + beos_window_set_title(g->history_window->window, "NetSurf History"); + beos_window_set_type_hint(g->history_window->window, + GDK_WINDOW_TYPE_HINT_UTILITY); + g->history_window->scrolled = beos_SCROLLED_WINDOW( + beos_scrolled_window_new(0, 0)); + beos_container_add(beos_CONTAINER(g->history_window->window), + beos_WIDGET(g->history_window->scrolled)); + + beos_widget_show(beos_WIDGET(g->history_window->scrolled)); + g->history_window->drawing_area = beos_DRAWING_AREA( + beos_drawing_area_new()); + + beos_widget_set_events(beos_WIDGET(g->history_window->drawing_area), + GDK_EXPOSURE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_PRESS_MASK); + beos_widget_modify_bg(beos_WIDGET(g->history_window->drawing_area), + beos_STATE_NORMAL, + &((GdkColor) { 0, 0xffff, 0xffff, 0xffff } )); + beos_scrolled_window_add_with_viewport(g->history_window->scrolled, + beos_WIDGET(g->history_window->drawing_area)); + beos_widget_show(beos_WIDGET(g->history_window->drawing_area)); + + /* set up URL bar completion */ + g->url_bar_completion = beos_entry_completion_new(); + beos_entry_set_completion(g->url_bar, g->url_bar_completion); + beos_entry_completion_set_match_func(g->url_bar_completion, + nsbeos_completion_match, NULL, NULL); + beos_entry_completion_set_model(g->url_bar_completion, + beos_TREE_MODEL(nsbeos_completion_list)); + beos_entry_completion_set_text_column(g->url_bar_completion, 0); + beos_entry_completion_set_minimum_key_length(g->url_bar_completion, 1); + beos_entry_completion_set_popup_completion(g->url_bar_completion, TRUE); + g_object_set(G_OBJECT(g->url_bar_completion), + "popup-set-width", TRUE, + "popup-single-match", TRUE, + NULL); + + /* set up the throbber. */ + beos_image_set_from_pixbuf(g->throbber, nsbeos_throbber->framedata[0]); + g->throb_frame = 0; + +#define CONNECT(obj, sig, callback, ptr) \ + g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) + + /* connect history window signals to their handlers */ + CONNECT(g->history_window->drawing_area, "expose_event", + nsbeos_history_expose_event, g->history_window); +// CONNECT(g->history_window->drawing_area, "motion_notify_event", +// nsbeos_history_motion_notify_event, g->history_window); + CONNECT(g->history_window->drawing_area, "button_press_event", + nsbeos_history_button_press_event, g->history_window); + CONNECT(g->history_window->window, "delete_event", + beos_widget_hide_on_delete, NULL); + + /* connect signals to handlers. */ + CONNECT(g->window, "destroy", nsbeos_window_destroy_event, g); + + /* toolbar and URL bar signal handlers */ + CONNECT(g->back_button, "clicked", nsbeos_window_back_button_clicked, g); + CONNECT(g->forward_button, "clicked", + nsbeos_window_forward_button_clicked, g); + CONNECT(g->stop_button, "clicked", nsbeos_window_stop_button_clicked, g); + CONNECT(g->reload_button, "clicked", + nsbeos_window_reload_button_clicked, g); + CONNECT(GET_WIDGET("toolHome"), "clicked", + nsbeos_window_home_button_clicked, g); + CONNECT(g->url_bar, "activate", nsbeos_window_url_activate_event, g); + CONNECT(g->url_bar, "changed", nsbeos_window_url_changed, g); + + /* set up the menu signal handlers */ + nsbeos_attach_menu_handlers(g->xml, g); + + g->being_destroyed = 0; + + g->fullscreen = false; + + /* create the popup version of the menu */ + g->popup_xml = glade_xml_new(glade_file_location, "menuPopup", NULL); + g->popup_menu = beos_MENU(glade_xml_get_widget(g->popup_xml, "menuPopup")); + +#define POPUP_ATTACH(x, y) beos_menu_item_set_submenu( \ + beos_MENU_ITEM(glade_xml_get_widget(g->popup_xml, x)),\ + beos_WIDGET(glade_xml_get_widget(g->xml, y))) + + POPUP_ATTACH("menupopup_file", "menumain_file"); + POPUP_ATTACH("menupopup_edit", "menumain_edit"); + POPUP_ATTACH("menupopup_view", "menumain_view"); + POPUP_ATTACH("menupopup_navigate", "menumain_navigate"); + POPUP_ATTACH("menupopup_help", "menumain_help"); + +#undef POPUP_ATTACH + + /* finally, show the window. */ + beos_widget_show(beos_WIDGET(g->window)); + +#endif + return g; +} + +void gui_window_set_title(struct gui_window *_g, const char *title) +{ + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + if (g->top_level != _g) return; + + // if we're a replicant, discard + if (!g->window) + return; + + BString nt(title); + if (nt.Length()) + nt << " - "; + nt << "NetSurf"; + + if (!g->top_view->LockLooper()) + return; + + g->window->SetTitle(nt.String()); + + g->top_view->UnlockLooper(); +} + +void gui_window_set_status(struct gui_window *_g, const char *text) +{ + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + assert(g); + assert(g->status_bar); + + if (!g->top_view->LockLooper()) + return; + + if (text == NULL || text[0] == '\0') + { + BString status("NetSurf"); + status << " " << netsurf_version; + g->status_bar->SetText(status.String()); + } + else + { + g->status_bar->SetText(text); + } + g->top_view->UnlockLooper(); +} + +void gui_window_set_url(struct gui_window *_g, const char *url) +{ + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + if (g->top_level != _g) return; + assert(g->status_bar); + + if (!g->top_view->LockLooper()) + return; + + g->url_bar->SetText(url); + + g->top_view->UnlockLooper(); +} + +void gui_window_start_throbber(struct gui_window* _g) +{ + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + + if (!g->top_view->LockLooper()) + return; + + g->stop_button->SetEnabled(true); + g->reload_button->SetEnabled(false); + + g->top_view->UnlockLooper(); + + nsbeos_window_update_back_forward(g); + + schedule(10, nsbeos_throb, g); +} + +void gui_window_stop_throbber(struct gui_window* _g) +{ + struct beos_scaffolding *g = nsbeos_get_scaffold(_g); + + nsbeos_window_update_back_forward(g); + + schedule_remove(nsbeos_throb, g); + + if (!g->top_view->LockLooper()) + return; + + g->stop_button->SetEnabled(false); + g->reload_button->SetEnabled(true); + + g->throbber->SetBitmap(nsbeos_throbber->framedata[0]); + g->throbber->Invalidate(); + + g->top_view->UnlockLooper(); +} + +/** + * add retrieved favicon to the gui + */ +void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +{ +} + +/** +* set gui display of a retrieved favicon representing the search provider +* \param ico may be NULL for local calls; then access current cache from +* search_web_ico() +*/ +void gui_window_set_search_ico(hlcache_handle *ico) +{ +} + +#warning XXX +#if 0 /* GTK */ +gboolean nsbeos_scaffolding_is_busy(nsbeos_scaffolding *scaffold) +{ + /* We are considered "busy" if the stop button is sensitive */ + return beos_WIDGET_SENSITIVE((beos_WIDGET(scaffold->stop_button))); +} +#endif + +void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where) +{ + g->popup_menu->Go(where); +} diff --git a/beos/scaffolding.h b/beos/scaffolding.h new file mode 100644 index 000000000..ae7839175 --- /dev/null +++ b/beos/scaffolding.h @@ -0,0 +1,203 @@ +/* + * Copyright 2008 François Revol + * Copyright 2005 James Bursa + * + * 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 . + */ + +#ifndef NETSURF_BEOS_SCAFFOLDING_H +#define NETSURF_BEOS_SCAFFOLDING_H 1 + +#include +#include +#include + +extern "C" { +#include "desktop/gui.h" +#include "desktop/plotters.h" +} + +typedef struct beos_scaffolding nsbeos_scaffolding; + +class NSBaseView : public BView { +public: + NSBaseView(BRect frame); + NSBaseView(BMessage *archive); +virtual ~NSBaseView(); + +virtual void MessageReceived(BMessage *message); +//virtual void Draw(BRect updateRect); + +//virtual void FrameMoved(BPoint new_location); +//virtual void FrameResized(float new_width, float new_height); + +virtual void AllAttached(void); + +virtual status_t Archive(BMessage *archive, bool deep=true) const; +static BArchivable *Instantiate(BMessage *archive); + +void SetScaffolding(struct beos_scaffolding *scaf); +private: + struct beos_scaffolding *fScaffolding; +}; + +class NSBrowserWindow : public BWindow { +public: + NSBrowserWindow(BRect frame, struct beos_scaffolding *scaf); +virtual ~NSBrowserWindow(); + +virtual void DispatchMessage(BMessage *message, BHandler *handler); +virtual void MessageReceived(BMessage *message); +virtual bool QuitRequested(void); + +struct beos_scaffolding *Scaffolding() const { return fScaffolding; }; + +private: + struct beos_scaffolding *fScaffolding; +}; + + +// XXX: clean up +typedef enum { + + /* no/unknown actions */ + NO_ACTION = 'nsMA', + + /* help actions */ + HELP_OPEN_CONTENTS, + HELP_OPEN_GUIDE, + HELP_OPEN_INFORMATION, + HELP_OPEN_ABOUT, + HELP_LAUNCH_INTERACTIVE, + + /* history actions */ + HISTORY_SHOW_LOCAL, + HISTORY_SHOW_GLOBAL, + + /* hotlist actions */ + HOTLIST_ADD_URL, + HOTLIST_SHOW, + + /* cookie actions */ + COOKIES_SHOW, + COOKIES_DELETE, + + /* page actions */ + BROWSER_PAGE, + BROWSER_PAGE_INFO, + BROWSER_PRINT, + BROWSER_NEW_WINDOW, + BROWSER_VIEW_SOURCE, + + /* object actions */ + BROWSER_OBJECT, + BROWSER_OBJECT_INFO, + BROWSER_OBJECT_RELOAD, + + /* save actions */ + BROWSER_OBJECT_SAVE, + BROWSER_OBJECT_EXPORT_SPRITE, + BROWSER_OBJECT_SAVE_URL_URI, + BROWSER_OBJECT_SAVE_URL_URL, + BROWSER_OBJECT_SAVE_URL_TEXT, + BROWSER_SAVE, + BROWSER_SAVE_COMPLETE, + BROWSER_EXPORT_DRAW, + BROWSER_EXPORT_TEXT, + BROWSER_SAVE_URL_URI, + BROWSER_SAVE_URL_URL, + BROWSER_SAVE_URL_TEXT, + HOTLIST_EXPORT, + HISTORY_EXPORT, + + /* navigation actions */ + BROWSER_NAVIGATE_HOME, + BROWSER_NAVIGATE_BACK, + BROWSER_NAVIGATE_FORWARD, + BROWSER_NAVIGATE_UP, + BROWSER_NAVIGATE_RELOAD, + BROWSER_NAVIGATE_RELOAD_ALL, + BROWSER_NAVIGATE_STOP, + BROWSER_NAVIGATE_URL, + + /* browser window/display actions */ + BROWSER_SCALE_VIEW, + BROWSER_FIND_TEXT, + BROWSER_IMAGES_FOREGROUND, + BROWSER_IMAGES_BACKGROUND, + BROWSER_BUFFER_ANIMS, + BROWSER_BUFFER_ALL, + BROWSER_SAVE_VIEW, + BROWSER_WINDOW_DEFAULT, + BROWSER_WINDOW_STAGGER, + BROWSER_WINDOW_COPY, + BROWSER_WINDOW_RESET, + + /* tree actions */ + TREE_NEW_FOLDER, + TREE_NEW_LINK, + TREE_EXPAND_ALL, + TREE_EXPAND_FOLDERS, + TREE_EXPAND_LINKS, + TREE_COLLAPSE_ALL, + TREE_COLLAPSE_FOLDERS, + TREE_COLLAPSE_LINKS, + TREE_SELECTION, + TREE_SELECTION_EDIT, + TREE_SELECTION_LAUNCH, + TREE_SELECTION_DELETE, + TREE_SELECT_ALL, + TREE_CLEAR_SELECTION, + + /* toolbar actions */ + TOOLBAR_BUTTONS, + TOOLBAR_ADDRESS_BAR, + TOOLBAR_THROBBER, + TOOLBAR_EDIT, + + /* misc actions */ + CHOICES_SHOW, + APPLICATION_QUIT, +} menu_action; + + +NSBrowserWindow *nsbeos_find_last_window(void); + +NSBrowserWindow *nsbeos_get_bwindow_for_scaffolding(nsbeos_scaffolding *scaffold); + +nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel); + +bool nsbeos_scaffolding_is_busy(nsbeos_scaffolding *scaffold); + +void nsbeos_attach_toplevel_view(nsbeos_scaffolding *g, BView *view); + +#if 0 /* GTK */ +void nsbeos_attach_toplevel_viewport(nsbeos_scaffolding *g, GtkViewport *vp); +#endif + +void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *message); + +void nsbeos_scaffolding_destroy(nsbeos_scaffolding *scaffold); + +//void nsbeos_window_destroy_event(NSBrowserWindow *window, nsbeos_scaffolding *g, BMessage *event); + + +void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, BPoint where); + +#if 0 /* GTK */ +void nsbeos_scaffolding_popup_menu(nsbeos_scaffolding *g, guint button); +#endif + +#endif /* NETSURF_BEOS_SCAFFOLDING_H */ diff --git a/beos/schedule.cpp b/beos/schedule.cpp new file mode 100644 index 000000000..3f822352a --- /dev/null +++ b/beos/schedule.cpp @@ -0,0 +1,133 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include + +extern "C" { +#include "utils/schedule.h" +#include "desktop/browser.h" + +#ifdef DEBUG_BEOS_SCHEDULE +#include "utils/log.h" +#else +#define LOG(X) +#endif +} + +/** Killable callback closure embodiment. */ +typedef struct { + void (*callback)(void *); /**< The callback function. */ + void *context; /**< The context for the callback. */ + bool callback_killed; /**< Whether or not this was killed. */ + bool callback_fired; /**< Whether or not this has fired yet. */ + bigtime_t timeout; +} _nsbeos_callback_t; + +/** List of all callbacks. */ +static BList *callbacks = NULL; + +/** earliest deadline. It's used for select() in gui_poll() */ +bigtime_t earliest_callback_timeout = B_INFINITE_TIMEOUT; + + +static bool +nsbeos_schedule_kill_callback(void *_target, void *_match) +{ + _nsbeos_callback_t *target = (_nsbeos_callback_t *)_target; + _nsbeos_callback_t *match = (_nsbeos_callback_t *)_match; + if ((target->callback == match->callback) && + (target->context == match->context)) { + LOG(("Found match for %p(%p), killing.", + target->callback, target->context)); + target->callback = NULL; + target->context = NULL; + target->callback_killed = true; + } + return false; +} + +void +schedule_remove(void (*callback)(void *p), void *p) +{ + LOG(("schedule_remove() for %p(%p)", cb->callback, cb->context)); + if (callbacks == NULL) + return; + _nsbeos_callback_t cb_match; + cb_match.callback = callback; + cb_match.context = p; + + + callbacks->DoForEach(nsbeos_schedule_kill_callback, &cb_match); +} + +void +schedule(int t, void (*callback)(void *p), void *p) +{ + LOG(("schedule(%d, %p, %p)", t, cb->callback, cb->context)); + if (callbacks == NULL) + callbacks = new BList; + + bigtime_t timeout = system_time() + t * 10 * 1000LL; + const int msec_timeout = t * 10; + _nsbeos_callback_t *cb = (_nsbeos_callback_t *)malloc(sizeof(_nsbeos_callback_t)); + /* Kill any pending schedule of this kind. */ + schedule_remove(callback, p); + cb->callback = callback; + cb->context = p; + cb->callback_killed = cb->callback_fired = false; + cb->timeout = timeout; + if (earliest_callback_timeout > timeout) + earliest_callback_timeout = timeout; + callbacks->AddItem(cb); +} + +bool +schedule_run(void) +{ + LOG(("schedule_run()")); + if (callbacks == NULL) + return false; /* Nothing to do */ + + bigtime_t now = system_time(); + earliest_callback_timeout = B_INFINITE_TIMEOUT; + int32 i; + + LOG(("Checking %ld callbacks to for deadline.", this_run->CountItems())); + + /* Run all the callbacks which made it this far. */ + for (i = 0; i < callbacks->CountItems(); ) { + _nsbeos_callback_t *cb = (_nsbeos_callback_t *)(callbacks->ItemAt(i)); + if (cb->timeout > now) { + // update next deadline + if (earliest_callback_timeout > cb->timeout) + earliest_callback_timeout = cb->timeout; + i++; + continue; + } + LOG(("Running callbacks %p(%p).", cb->callback, cb->context)); + if (!cb->callback_killed) + cb->callback(cb->context); + callbacks->RemoveItem(cb); + free(cb); + } + return true; +} diff --git a/beos/schedule.h b/beos/schedule.h new file mode 100644 index 000000000..02205baf4 --- /dev/null +++ b/beos/schedule.h @@ -0,0 +1,26 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#ifndef NETSURF_BEOS_CALLBACK_H +#define NETSURF_BEOS_CALLBACK_H 1 + +typedef void (*beos_callback)(void *p); + +extern bigtime_t earliest_callback_timeout; + +#endif /* NETSURF_BEOS_CALLBACK_H */ diff --git a/beos/search.cpp b/beos/search.cpp new file mode 100644 index 000000000..97e3d6d5b --- /dev/null +++ b/beos/search.cpp @@ -0,0 +1,76 @@ +/* + * Copyright 2009 Mark Benjamin + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +//#include +#include + +extern "C" { +#include "utils/log.h" +} +/* callback functions for search implementation */ +static void gui_search_set_status(bool found, void *p); +static void gui_search_set_hourglass(bool active, void *p); +static void gui_search_add_recent(const char *string, void *p); +static void gui_search_set_forward_state(bool active, void *p); +static void gui_search_set_back_state(bool active, void *p); + +/** + * Change the displayed search status. + * \param found search pattern matched in text + * \param p the pointer sent to search_verify_new() / search_create_context() + */ +void gui_search_set_status(bool found, void *p) +{ +} + +/** + * display hourglass while searching + * \param active start/stop indicator + * \param p the pointer sent to search_verify_new() / search_create_context() + */ +void gui_search_set_hourglass(bool active, void *p) +{ +} + +/** + * add search string to recent searches list + * \param string search pattern + * \param p the pointer sent to search_verify_new() / search_create_context() + */ +void gui_search_add_recent(const char *string, void *p) +{ +} + +/** + * activate search forwards button in gui + * \param active activate/inactivate + * \param p the pointer sent to search_verify_new() / search_create_context() + */ +void gui_search_set_forward_state(bool active, void *p) +{ +} + +/** + * activate search forwards button in gui + * \param active activate/inactivate + * \param p the pointer sent to search_verify_new() / search_create_context() + */ +void gui_search_set_back_state(bool active, void *p) +{ +} diff --git a/beos/system_colour.cpp b/beos/system_colour.cpp index 1d03b35e6..9c25d8f5e 100644 --- a/beos/system_colour.cpp +++ b/beos/system_colour.cpp @@ -39,7 +39,7 @@ extern "C" { } -#include "beos/beos_gui.h" +#include "beos/gui.h" #if !defined(__HAIKU__) && !defined(B_BEOS_VERSION_DANO) diff --git a/beos/throbber.cpp b/beos/throbber.cpp new file mode 100644 index 000000000..f7fb35306 --- /dev/null +++ b/beos/throbber.cpp @@ -0,0 +1,119 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +extern "C" { +#include "utils/log.h" +} +#include "beos/throbber.h" +#include "beos/bitmap.h" +#include "beos/fetch_rsrc.h" + +#include +#include +#include + +struct nsbeos_throbber *nsbeos_throbber = NULL; + +/** + * Creates the throbber using a PNG for each frame. The number of frames must + * be at least two. The first frame is the inactive frame, others are the + * active frames. + * + * \param frames The number of frames. Must be at least two. + * \param ... Filenames of PNGs containing frames. + * \return true on success. + */ +bool nsbeos_throbber_initialise_from_png(const int frames, ...) +{ + va_list filenames; + struct nsbeos_throbber *throb; /**< structure we generate */ + bool errors_when_loading = false; /**< true if a frame failed */ + + if (frames < 2) { + /* we need at least two frames - one for idle, one for active */ + LOG(("Insufficent number of frames in throbber animation!")); + LOG(("(called with %d frames, where 2 is a minimum.)", + frames)); + return false; + } + + BResources *res = get_app_resources(); + if (res == NULL) { + LOG(("Can't find resources for throbber!")); + return false; + } + + throb = (struct nsbeos_throbber *)malloc(sizeof(throb)); + throb->nframes = frames; + throb->framedata = (BBitmap **)malloc(sizeof(BBitmap *) * throb->nframes); + + va_start(filenames, frames); + + for (int i = 0; i < frames; i++) { + const char *fn = va_arg(filenames, const char *); + const void *data; + size_t size; + data = res->LoadResource('data', fn, &size); + throb->framedata[i] = NULL; + if (!data) { + LOG(("Error when loading resource %s", fn)); + errors_when_loading = true; + continue; + } + BMemoryIO mem(data, size); + throb->framedata[i] = BTranslationUtils::GetBitmap(&mem); + if (throb->framedata[i] == NULL) { + LOG(("Error when loading %s: GetBitmap() returned NULL", fn)); + errors_when_loading = true; + } + } + + va_end(filenames); + + if (errors_when_loading == true) { + for (int i = 0; i < frames; i++) { + delete throb->framedata[i]; + } + + free(throb->framedata); + free(throb); + + return false; + } + + nsbeos_throbber = throb; + + return true; +} + +void nsbeos_throbber_finalise(void) +{ + int i; + + for (i = 0; i < nsbeos_throbber->nframes; i++) + delete nsbeos_throbber->framedata[i]; + + free(nsbeos_throbber->framedata); + free(nsbeos_throbber); + + nsbeos_throbber = NULL; +} diff --git a/beos/throbber.h b/beos/throbber.h new file mode 100644 index 000000000..670c60a06 --- /dev/null +++ b/beos/throbber.h @@ -0,0 +1,36 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#ifndef __BEOS_THROBBER_H__ +#define __BEOS_THROBBER_H__ + +#include + +struct nsbeos_throbber +{ + int nframes; /**< Number of frames in the throbber */ + BBitmap **framedata; +}; + +extern struct nsbeos_throbber *nsbeos_throbber; + +bool nsbeos_throbber_initialise_from_gif(const char *fn); +bool nsbeos_throbber_initialise_from_png(const int frames, ...); +void nsbeos_throbber_finalise(void); + +#endif /* __BEOS_THROBBER_H__ */ diff --git a/beos/thumbnail.cpp b/beos/thumbnail.cpp new file mode 100644 index 000000000..ea03d29d8 --- /dev/null +++ b/beos/thumbnail.cpp @@ -0,0 +1,168 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +/** \file + * Page thumbnail creation (implementation). + * + * Thumbnails are created by setting the current drawing contexts to a BView + * attached to the BBitmap we are passed, and plotting the page at a small + * scale. + */ + +#define __STDBOOL_H__ 1 +#include +#include +#include +#include +extern "C" { +#include "content/content.h" +#include "content/urldb.h" +#include "desktop/plotters.h" +#include "desktop/browser.h" +#include "desktop/thumbnail.h" +#include "image/bitmap.h" +#include "render/font.h" +#include "utils/log.h" +} +#include "beos/scaffolding.h" +#include "beos/plotters.h" +#include "beos/bitmap.h" + +// Zeta PRIVATE: in libzeta for now. +extern status_t ScaleBitmap(const BBitmap& inBitmap, BBitmap& outBitmap); + +#warning XXX do we need to set bitmap:shadow ? + + +/** + * Create a thumbnail of a page. + * + * \param content content structure to thumbnail + * \param bitmap the bitmap to draw to + * \param url the URL the thumnail belongs to, or NULL + */ +bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, + const char *url) +{ + BBitmap *thumbnail; + BBitmap *small; + BBitmap *big; + BView *oldView; + BView *view; + BView *thumbView; + float width; + float height; + int big_width; + int big_height; + int depth; + + struct redraw_context ctx; + ctx.interactive = false; + ctx.background_images = true; + ctx.plot = &nsbeos_plotters; + + assert(content); + assert(bitmap); + + thumbnail = nsbeos_bitmap_get_primary(bitmap); + width = thumbnail->Bounds().Width(); + height = thumbnail->Bounds().Height(); + depth = 32; + + big_width = MIN(content_get_width(content), 1024); + big_height = (int)(((big_width * height) + (width / 2)) / width); + + BRect contentRect(0, 0, big_width - 1, big_height - 1); + big = new BBitmap(contentRect, B_BITMAP_ACCEPTS_VIEWS, B_RGB32); + + if (big->InitCheck() < B_OK) { + delete big; + return false; + } + + small = new BBitmap(thumbnail->Bounds(), + B_BITMAP_ACCEPTS_VIEWS, B_RGB32); + + if (small->InitCheck() < B_OK) { + delete small; + delete big; + return false; + } + + //XXX: _lock ? + // backup the current gc + oldView = nsbeos_current_gc(); + + view = new BView(contentRect, "thumbnailer", + B_FOLLOW_NONE, B_WILL_DRAW); + big->AddChild(view); + + thumbView = new BView(small->Bounds(), "thumbnail", + B_FOLLOW_NONE, B_WILL_DRAW); + small->AddChild(thumbView); + + view->LockLooper(); + + /* impose our view on the content... */ + nsbeos_current_gc_set(view); + + /* render the content */ + thumbnail_redraw(content, big_width, big_height, &ctx); + + view->Sync(); + view->UnlockLooper(); + + // restore the current gc + nsbeos_current_gc_set(oldView); + + + // now scale it down +//XXX: use Zeta's bilinear scaler ? +//#ifdef B_ZETA_VERSION +// err = ScaleBitmap(*shot, *scaledBmp); +//#else + thumbView->LockLooper(); + thumbView->DrawBitmap(big, big->Bounds(), small->Bounds()); + thumbView->Sync(); + thumbView->UnlockLooper(); + + small->LockBits(); + thumbnail->LockBits(); + + // copy it to the bitmap + memcpy(thumbnail->Bits(), small->Bits(), thumbnail->BitsLength()); + + thumbnail->UnlockBits(); + small->UnlockBits(); + + /* register the thumbnail with the URL */ + if (url) + urldb_set_thumbnail(url, bitmap); + + bitmap_modified(bitmap); + + // cleanup + small->RemoveChild(thumbView); + delete thumbView; + delete small; + big->RemoveChild(view); + delete view; + delete big; + + return true; +} diff --git a/beos/treeview.cpp b/beos/treeview.cpp new file mode 100644 index 000000000..4728995ad --- /dev/null +++ b/beos/treeview.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2008 François Revol + * Copyright 2004 Richard Wilson + * + * 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 . + */ + +/** \file + * Generic tree handling (implementation). + */ + + +#define __STDBOOL_H__ 1 +extern "C" { +#include "utils/config.h" +#include "desktop/tree.h" +#include "desktop/tree_url_node.h" +} + +const char tree_directory_icon_name[] = "directory.png"; +const char tree_content_icon_name[] = "content.png"; + + + + +/** + * Translates a content_type to the name of a respective icon + * + * \param content_type content type + * \param buffer buffer for the icon name + */ +void tree_icon_name_from_content_type(char *buffer, content_type type) +{ + // TODO: design/acquire icons + switch (type) { + case CONTENT_HTML: + case CONTENT_TEXTPLAIN: + case CONTENT_CSS: + case CONTENT_IMAGE: + default: + sprintf(buffer, tree_content_icon_name); + break; + } +} diff --git a/beos/window.cpp b/beos/window.cpp new file mode 100644 index 000000000..b0ead3e5c --- /dev/null +++ b/beos/window.cpp @@ -0,0 +1,1773 @@ +/* + * Copyright 2008 François Revol + * Copyright 2006 Daniel Silverstone + * Copyright 2006 Rob Kendrick + * + * 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 . + */ + +#define __STDBOOL_H__ 1 +#include +extern "C" { +#include "content/urldb.h" +#include "css/utils.h" +#include "desktop/browser.h" +#include "desktop/mouse.h" +#include "desktop/options.h" +#include "desktop/selection.h" +#include "desktop/textinput.h" +#include "render/font.h" +#include "utils/log.h" +#include "utils/types.h" +#include "utils/utf8.h" +#include "utils/utils.h" +} +#include "beos/about.h" +#include "beos/window.h" +#include "beos/font.h" +#include "beos/gui.h" +#include "beos/scaffolding.h" +#include "beos/plotters.h" +//#include "beos/schedule.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class NSBrowserFrameView; + +struct gui_window { + /* All gui_window objects have an ultimate scaffold */ + nsbeos_scaffolding *scaffold; + bool toplevel; + /* A gui_window is the rendering of a browser_window */ + struct browser_window *bw; + + struct { + int pressed_x; + int pressed_y; + int state; /* browser_mouse_state */ + } mouse; + + /* These are the storage for the rendering */ + int caretx, carety, careth; + gui_pointer_shape current_pointer; + int last_x, last_y; + + NSBrowserFrameView *view; + + // some cached events to speed up things + // those are the last queued event of their kind, + // we can safely drop others and avoid wasting cpu. + // number of pending resizes + vint32 pending_resizes; + // accumulated rects of pending redraws + //volatile BMessage *lastRedraw; + // UNUSED YET + BRect pendingRedraw; +#if 0 /* GTK */ + /* Within GTK, a gui_window is a scrolled window + * with a viewport inside + * with a gtkfixed in that + * with a drawing area in that + * The scrolled window is optional and only chosen + * for frames which need it. Otherwise we just use + * a viewport. + */ + GtkScrolledWindow *scrolledwindow; + GtkViewport *viewport; + GtkFixed *fixed; + GtkDrawingArea *drawing_area; +#endif + + /* Keep gui_windows in a list for cleanup later */ + struct gui_window *next, *prev; +}; + + + +static const rgb_color kWhiteColor = {255, 255, 255, 255}; + +static struct gui_window *window_list = 0; /**< first entry in win list*/ + +static BString current_selection; +static BList current_selection_textruns; + +/* Methods which apply only to a gui_window */ +static void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message); +static void nsbeos_window_keypress_event(BView *view, gui_window *g, BMessage *event); +static void nsbeos_window_resize_event(BView *view, gui_window *g, BMessage *event); +static void nsbeos_window_moved_event(BView *view, gui_window *g, BMessage *event); +/* Other useful bits */ +static void nsbeos_redraw_caret(struct gui_window *g); + +#if 0 /* GTK */ +static GdkCursor *nsbeos_create_menu_cursor(void); +#endif + +// #pragma mark - class NSBrowserFrameView + + +NSBrowserFrameView::NSBrowserFrameView(BRect frame, struct gui_window *gui) + : BView(frame, "NSBrowserFrameView", B_FOLLOW_ALL_SIDES, + B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS /*| B_SUBPIXEL_PRECISE*/), + fGuiWindow(gui) +{ +} + + +NSBrowserFrameView::~NSBrowserFrameView() +{ +} + + +void +NSBrowserFrameView::MessageReceived(BMessage *message) +{ + switch (message->what) { + case B_SIMPLE_DATA: + case B_ARGV_RECEIVED: + case B_REFS_RECEIVED: + case B_COPY: + case B_CUT: + case B_PASTE: + case B_SELECT_ALL: + //case B_MOUSE_WHEEL_CHANGED: + case B_UI_SETTINGS_CHANGED: + // NetPositive messages + case B_NETPOSITIVE_OPEN_URL: + case B_NETPOSITIVE_BACK: + case B_NETPOSITIVE_FORWARD: + case B_NETPOSITIVE_HOME: + case B_NETPOSITIVE_RELOAD: + case B_NETPOSITIVE_STOP: + case B_NETPOSITIVE_DOWN: + case B_NETPOSITIVE_UP: + // messages for top-level + case 'back': + case 'forw': + case 'stop': + case 'relo': + case 'home': + case 'urlc': + case 'urle': + case 'menu': + case NO_ACTION: + case HELP_OPEN_CONTENTS: + case HELP_OPEN_GUIDE: + case HELP_OPEN_INFORMATION: + case HELP_OPEN_ABOUT: + case HELP_LAUNCH_INTERACTIVE: + case HISTORY_SHOW_LOCAL: + case HISTORY_SHOW_GLOBAL: + case HOTLIST_ADD_URL: + case HOTLIST_SHOW: + case COOKIES_SHOW: + case COOKIES_DELETE: + case BROWSER_PAGE: + case BROWSER_PAGE_INFO: + case BROWSER_PRINT: + case BROWSER_NEW_WINDOW: + case BROWSER_VIEW_SOURCE: + case BROWSER_OBJECT: + case BROWSER_OBJECT_INFO: + case BROWSER_OBJECT_RELOAD: + case BROWSER_OBJECT_SAVE: + case BROWSER_OBJECT_EXPORT_SPRITE: + case BROWSER_OBJECT_SAVE_URL_URI: + case BROWSER_OBJECT_SAVE_URL_URL: + case BROWSER_OBJECT_SAVE_URL_TEXT: + case BROWSER_SAVE: + case BROWSER_SAVE_COMPLETE: + case BROWSER_EXPORT_DRAW: + case BROWSER_EXPORT_TEXT: + case BROWSER_SAVE_URL_URI: + case BROWSER_SAVE_URL_URL: + case BROWSER_SAVE_URL_TEXT: + case HOTLIST_EXPORT: + case HISTORY_EXPORT: + case BROWSER_NAVIGATE_HOME: + case BROWSER_NAVIGATE_BACK: + case BROWSER_NAVIGATE_FORWARD: + case BROWSER_NAVIGATE_UP: + case BROWSER_NAVIGATE_RELOAD: + case BROWSER_NAVIGATE_RELOAD_ALL: + case BROWSER_NAVIGATE_STOP: + case BROWSER_NAVIGATE_URL: + case BROWSER_SCALE_VIEW: + case BROWSER_FIND_TEXT: + case BROWSER_IMAGES_FOREGROUND: + case BROWSER_IMAGES_BACKGROUND: + case BROWSER_BUFFER_ANIMS: + case BROWSER_BUFFER_ALL: + case BROWSER_SAVE_VIEW: + case BROWSER_WINDOW_DEFAULT: + case BROWSER_WINDOW_STAGGER: + case BROWSER_WINDOW_COPY: + case BROWSER_WINDOW_RESET: + case TREE_NEW_FOLDER: + case TREE_NEW_LINK: + case TREE_EXPAND_ALL: + case TREE_EXPAND_FOLDERS: + case TREE_EXPAND_LINKS: + case TREE_COLLAPSE_ALL: + case TREE_COLLAPSE_FOLDERS: + case TREE_COLLAPSE_LINKS: + case TREE_SELECTION: + case TREE_SELECTION_EDIT: + case TREE_SELECTION_LAUNCH: + case TREE_SELECTION_DELETE: + case TREE_SELECT_ALL: + case TREE_CLEAR_SELECTION: + case TOOLBAR_BUTTONS: + case TOOLBAR_ADDRESS_BAR: + case TOOLBAR_THROBBER: + case TOOLBAR_EDIT: + case CHOICES_SHOW: + case APPLICATION_QUIT: + Window()->DetachCurrentMessage(); + nsbeos_pipe_message_top(message, NULL, fGuiWindow->scaffold); + break; + default: + message->PrintToStream(); + BView::MessageReceived(message); + } +} + + +void +NSBrowserFrameView::Draw(BRect updateRect) +{ + BMessage *message = NULL; + //message = Window()->DetachCurrentMessage(); + // might be called directly... + if (message == NULL) + message = new BMessage(_UPDATE_); + message->AddRect("rect", updateRect); + nsbeos_pipe_message(message, this, fGuiWindow); +} + + +#if 0 +void +NSBrowserFrameView::FrameMoved(BPoint new_location) +{ + BMessage *message = Window()->DetachCurrentMessage(); + // discard any other pending resize, + // so we don't end up processing them all, the last one matters. + //atomic_add(&fGuiWindow->pending_resizes, 1); + nsbeos_pipe_message(message, this, fGuiWindow); + BView::FrameMoved(new_location); +} +#endif + +void +NSBrowserFrameView::FrameResized(float new_width, float new_height) +{ + BMessage *message = Window()->DetachCurrentMessage(); + // discard any other pending resize, + // so we don't end up processing them all, the last one matters. + atomic_add(&fGuiWindow->pending_resizes, 1); + nsbeos_pipe_message(message, this, fGuiWindow); + BView::FrameResized(new_width, new_height); +} + + +void +NSBrowserFrameView::KeyDown(const char *bytes, int32 numBytes) +{ + BMessage *message = Window()->DetachCurrentMessage(); + nsbeos_pipe_message(message, this, fGuiWindow); +} + + +void +NSBrowserFrameView::MouseDown(BPoint where) +{ + BMessage *message = Window()->DetachCurrentMessage(); + BPoint screenWhere; + if (message->FindPoint("screen_where", &screenWhere) < B_OK) { + screenWhere = ConvertToScreen(where); + message->AddPoint("screen_where", screenWhere); + } + nsbeos_pipe_message(message, this, fGuiWindow); +} + + +void +NSBrowserFrameView::MouseUp(BPoint where) +{ + //BMessage *message = Window()->DetachCurrentMessage(); + //nsbeos_pipe_message(message, this, fGuiWindow); + BMessage *message = Window()->DetachCurrentMessage(); + BPoint screenWhere; + if (message->FindPoint("screen_where", &screenWhere) < B_OK) { + screenWhere = ConvertToScreen(where); + message->AddPoint("screen_where", screenWhere); + } + nsbeos_pipe_message(message, this, fGuiWindow); +} + + +void +NSBrowserFrameView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg) +{ + if (transit != B_INSIDE_VIEW) { + BView::MouseMoved(where, transit, msg); + return; + } + BMessage *message = Window()->DetachCurrentMessage(); + nsbeos_pipe_message(message, this, fGuiWindow); +} + + +// #pragma mark - gui_window + +struct browser_window *nsbeos_get_browser_window(struct gui_window *g) +{ + return g->bw; +} + +nsbeos_scaffolding *nsbeos_get_scaffold(struct gui_window *g) +{ + return g->scaffold; +} + +struct browser_window *nsbeos_get_browser_for_gui(struct gui_window *g) +{ + return g->bw; +} + +float nsbeos_get_scale_for_gui(struct gui_window *g) +{ + return g->bw->scale; +} + +/* Create a gui_window */ +struct gui_window *gui_create_browser_window(struct browser_window *bw, + struct browser_window *clone, bool new_tab) +{ + struct gui_window *g; /**< what we're creating to return */ + + g = (struct gui_window *)malloc(sizeof(*g)); + if (!g) { + warn_user("NoMemory", 0); + return 0; + } + + LOG(("Creating gui window %p for browser window %p", g, bw)); + + g->bw = bw; + g->mouse.state = 0; + g->current_pointer = GUI_POINTER_DEFAULT; + if (clone != NULL) + bw->scale = clone->scale; + else + bw->scale = (float) nsoption_int(scale) / 100; + + g->careth = 0; + g->pending_resizes = 0; + + /* Attach ourselves to the list (push_top) */ + if (window_list) + window_list->prev = g; + g->next = window_list; + g->prev = NULL; + window_list = g; + + /* Now construct and attach a scaffold */ + g->scaffold = nsbeos_new_scaffolding(g); + if (!g->scaffold) + return NULL; + + /* Construct our primary elements */ + BRect frame(0,0,-1,-1); // will be resized later + g->view = new NSBrowserFrameView(frame, g); + /* set the default background colour of the drawing area to white. */ + //g->view->SetViewColor(kWhiteColor); + /* NOOO! Since we defer drawing (DetachCurrent()), the white flickers, + * besides sometimes text was drawn twice, making it ugly. + * Instead we set to transparent here, and implement plot_clg() to + * do it just before the rest. This almost removes the flicker. */ + g->view->SetViewColor(B_TRANSPARENT_COLOR); + g->view->SetLowColor(kWhiteColor); + +#ifdef B_BEOS_VERSION_DANO + /* enable double-buffering on the content view */ +/* + XXX: doesn't really work + g->view->SetDoubleBuffering(B_UPDATE_INVALIDATED + | B_UPDATE_SCROLLED + //| B_UPDATE_RESIZED + | B_UPDATE_EXPOSED); +*/ +#endif + + + g->toplevel = true; + + /* Attach our viewport into the scaffold */ + nsbeos_attach_toplevel_view(g->scaffold, g->view); + +#warning WRITEME +#if 0 /* GTK */ + GtkPolicyType scrollpolicy; + + /* Construct our primary elements */ + g->fixed = GTK_FIXED(gtk_fixed_new()); + g->drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new()); + gtk_fixed_put(g->fixed, GTK_WIDGET(g->drawing_area), 0, 0); + gtk_container_set_border_width(GTK_CONTAINER(g->fixed), 0); + + g->scrolledwindow = 0; + g->viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL)); /* Need to attach adjustments */ + gtk_container_add(GTK_CONTAINER(g->viewport), GTK_WIDGET(g->fixed)); + + /* Attach our viewport into the scaffold */ + nsbeos_attach_toplevel_viewport(g->scaffold, g->viewport); + + gtk_container_set_border_width(GTK_CONTAINER(g->viewport), 0); + gtk_viewport_set_shadow_type(g->viewport, GTK_SHADOW_NONE); + if (g->scrolledwindow) + gtk_widget_show(GTK_WIDGET(g->scrolledwindow)); + /* And enable visibility from our viewport down */ + gtk_widget_show(GTK_WIDGET(g->viewport)); + gtk_widget_show(GTK_WIDGET(g->fixed)); + gtk_widget_show(GTK_WIDGET(g->drawing_area)); + + switch(bw->scrolling) { + case SCROLLING_NO: + scrollpolicy = GTK_POLICY_NEVER; + break; + case SCROLLING_YES: + scrollpolicy = GTK_POLICY_ALWAYS; + break; + case SCROLLING_AUTO: + default: + scrollpolicy = GTK_POLICY_AUTOMATIC; + break; + }; + + + if (g->scrolledwindow) + gtk_scrolled_window_set_policy(g->scrolledwindow, + scrollpolicy, scrollpolicy); + + /* set the events we're interested in receiving from the browser's + * drawing area. + */ + gtk_widget_add_events(GTK_WIDGET(g->drawing_area), + GDK_EXPOSURE_MASK | + GDK_LEAVE_NOTIFY_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_POINTER_MOTION_MASK | + GDK_KEY_PRESS_MASK | + GDK_KEY_RELEASE_MASK); + GTK_WIDGET_SET_FLAGS(GTK_WIDGET(g->drawing_area), GTK_CAN_FOCUS); + + /* set the default background colour of the drawing area to white. */ + gtk_widget_modify_bg(GTK_WIDGET(g->drawing_area), GTK_STATE_NORMAL, + &((GdkColor) { 0, 0xffff, 0xffff, 0xffff } )); + +#define CONNECT(obj, sig, callback, ptr) \ + g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr)) + CONNECT(g->drawing_area, "expose_event", nsgtk_window_expose_event, g); + CONNECT(g->drawing_area, "motion_notify_event", + nsgtk_window_motion_notify_event, g); + CONNECT(g->drawing_area, "button_press_event", + nsgtk_window_button_press_event, g); + CONNECT(g->drawing_area, "key_press_event", + nsgtk_window_keypress_event, g); + CONNECT(g->viewport, "size_allocate", + nsgtk_window_size_allocate_event, g); +#endif + + return g; +} + + +void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, + int x1, int y1) +{ + gui_window_set_scroll(g, x0, y0); +} + +void nsbeos_dispatch_event(BMessage *message) +{ + struct gui_window *gui = NULL; + NSBrowserFrameView *view = NULL; + struct beos_scaffolding *scaffold = NULL; + NSBrowserWindow *window = NULL; + + //message->PrintToStream(); + if (message->FindPointer("View", (void **)&view) < B_OK) + view = NULL; + if (message->FindPointer("gui_window", (void **)&gui) < B_OK) + gui = NULL; + if (message->FindPointer("Window", (void **)&window) < B_OK) + window = NULL; + if (message->FindPointer("scaffolding", (void **)&scaffold) < B_OK) + scaffold = NULL; + + struct gui_window *z; + for (z = window_list; z && gui && z != gui; z = z->next) + continue; + + struct gui_window *y; + for (y = window_list; y && scaffold && y->scaffold != scaffold; y = y->next) + continue; + + if (gui && gui != z) { + LOG(("discarding event for destroyed gui_window")); + delete message; + return; + } + if (scaffold && (!y || scaffold != y->scaffold)) { + LOG(("discarding event for destroyed scaffolding")); + delete message; + return; + } + + // messages for top-level + if (scaffold) { + LOG(("dispatching to top-level")); + nsbeos_scaffolding_dispatch_event(scaffold, message); + delete message; + return; + } + + //LOG(("processing message")); + switch (message->what) { + case B_QUIT_REQUESTED: + // from the BApplication + netsurf_quit = true; + break; + case B_ABOUT_REQUESTED: + { + nsbeos_about(gui); + /* XXX: doesn't work yet! bug in rsrc:/ + BString url("rsrc:/about.en.html,text/html"); + browser_window_create(url.String(), NULL, NULL, true, false); + */ + break; + } + case _UPDATE_: + if (gui && view) + nsbeos_window_expose_event(view, gui, message); + break; + case B_MOUSE_MOVED: + { + if (gui == NULL) + break; + + BPoint where; + int32 mods; + // where refers to Window coords !? + // check be:view_where first + if (message->FindPoint("be:view_where", &where) < B_OK) { + if (message->FindPoint("where", &where) < B_OK) + break; + } + if (message->FindInt32("modifiers", &mods) < B_OK) + mods = 0; + + + if (gui->mouse.state & BROWSER_MOUSE_PRESS_1) { + /* Start button 1 drag */ + browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_1, + gui->mouse.pressed_x, gui->mouse.pressed_y); + /* Replace PRESS with HOLDING and declare drag in progress */ + gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | + BROWSER_MOUSE_HOLDING_1); + gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; + } else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) { + /* Start button 2 drag */ + browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_2, + gui->mouse.pressed_x, gui->mouse.pressed_y); + /* Replace PRESS with HOLDING and declare drag in progress */ + gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | + BROWSER_MOUSE_HOLDING_2); + gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; + } + + bool shift = mods & B_SHIFT_KEY; + bool ctrl = mods & B_CONTROL_KEY; + + /* Handle modifiers being removed */ + if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) + gui->mouse.state ^= BROWSER_MOUSE_MOD_1; + if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) + gui->mouse.state ^= BROWSER_MOUSE_MOD_2; + + browser_window_mouse_track(gui->bw, (browser_mouse_state)gui->mouse.state, + (int)(where.x / gui->bw->scale), + (int)(where.y / gui->bw->scale)); + + gui->last_x = (int)where.x; + gui->last_y = (int)where.y; + break; + } + case B_MOUSE_DOWN: + { + if (gui == NULL) + break; + + BPoint where; + int32 buttons; + int32 mods; + BPoint screenWhere; + if (message->FindPoint("be:view_where", &where) < B_OK) { + if (message->FindPoint("where", &where) < B_OK) + break; + } + if (message->FindInt32("buttons", &buttons) < B_OK) + break; + if (message->FindPoint("screen_where", &screenWhere) < B_OK) + break; + if (message->FindInt32("modifiers", &mods) < B_OK) + mods = 0; + + if (buttons & B_SECONDARY_MOUSE_BUTTON) { + /* 2 == right button on BeOS */ + + nsbeos_scaffolding_popup_menu(gui->scaffold, screenWhere); + break; + } + + gui->mouse.state = BROWSER_MOUSE_PRESS_1; + + if (buttons & B_TERTIARY_MOUSE_BUTTON) /* 3 == middle button on BeOS */ + gui->mouse.state = BROWSER_MOUSE_PRESS_2; + + if (mods & B_SHIFT_KEY) + gui->mouse.state |= BROWSER_MOUSE_MOD_1; + if (mods & B_CONTROL_KEY) + gui->mouse.state |= BROWSER_MOUSE_MOD_2; + + gui->mouse.pressed_x = where.x / gui->bw->scale; + gui->mouse.pressed_y = where.y / gui->bw->scale; + + // make sure the view is in focus + if (view && view->LockLooper()) { + if (!view->IsFocus()) + view->MakeFocus(); + view->UnlockLooper(); + } + + browser_window_mouse_click(gui->bw, + (browser_mouse_state)gui->mouse.state, + gui->mouse.pressed_x, gui->mouse.pressed_y); + + break; + } + case B_MOUSE_UP: + { + if (gui == NULL) + break; + + BPoint where; + int32 buttons; + int32 mods; + BPoint screenWhere; + if (message->FindPoint("be:view_where", &where) < B_OK) { + if (message->FindPoint("where", &where) < B_OK) + break; + } + if (message->FindInt32("buttons", &buttons) < B_OK) + break; + if (message->FindPoint("screen_where", &screenWhere) < B_OK) + break; + if (message->FindInt32("modifiers", &mods) < B_OK) + mods = 0; + + /* 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 (gui->mouse.state & BROWSER_MOUSE_PRESS_1) + gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_CLICK_1); + else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) + gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | BROWSER_MOUSE_CLICK_2); + + bool shift = mods & B_SHIFT_KEY; + bool ctrl = mods & B_CONTROL_KEY; + + /* Handle modifiers being removed */ + if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) + gui->mouse.state ^= BROWSER_MOUSE_MOD_1; + if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) + gui->mouse.state ^= BROWSER_MOUSE_MOD_2; + + /* + if (view && view->LockLooper()) { + view->MakeFocus(); + view->UnlockLooper(); + } + */ + + if (gui->mouse.state & (BROWSER_MOUSE_CLICK_1|BROWSER_MOUSE_CLICK_2)) + browser_window_mouse_click(gui->bw, + (browser_mouse_state)gui->mouse.state, + where.x / gui->bw->scale, + where.y / gui->bw->scale); + else + browser_window_mouse_track(gui->bw, (browser_mouse_state)0, + where.x, where.y); + + gui->mouse.state = 0; + + break; + } + case B_KEY_DOWN: + if (gui && view) + nsbeos_window_keypress_event(view, gui, message); + break; + case B_VIEW_RESIZED: + if (gui && view) + nsbeos_window_resize_event(view, gui, message); + break; + case B_VIEW_MOVED: + if (gui && view) + nsbeos_window_moved_event(view, gui, message); + break; + case B_MOUSE_WHEEL_CHANGED: + break; + case B_UI_SETTINGS_CHANGED: + nsbeos_update_system_ui_colors(); + break; + case 'nsLO': // login + { + BString url; + BString realm; + BString auth; + if (message->FindString("URL", &url) < B_OK) + break; + if (message->FindString("Realm", &realm) < B_OK) + break; + if (message->FindString("Auth", &auth) < B_OK) + break; + //printf("login to '%s' with '%s'\n", url.String(), auth.String()); + urldb_set_auth_details(url.String(), realm.String(), auth.String()); + browser_window_go(gui->bw, url.String(), 0, true); + break; + } + default: + break; + } + delete message; +} + +void nsbeos_window_expose_event(BView *view, gui_window *g, BMessage *message) +{ + BRect updateRect; + hlcache_handle *c; + float scale = g->bw->scale; + struct rect clip; + + struct redraw_context ctx = { true, true, &nsbeos_plotters }; + + assert(g); + assert(g->bw); + + struct gui_window *z; + for (z = window_list; z && z != g; z = z->next) + continue; + assert(z); + assert(g->view == view); + + // we'll be resizing = reflowing = redrawing everything anyway... + if (g->pending_resizes > 1) + return; + + if (message->FindRect("rect", &updateRect) < B_OK) + return; + + c = g->bw->current_content; + if (c == NULL) + return; + + if (!view->LockLooper()) + return; + nsbeos_current_gc_set(view); + + if (view->Window()) + view->Window()->BeginViewTransaction(); + + clip.x0 = (int)updateRect.left; + clip.y0 = (int)updateRect.top; + clip.x1 = (int)updateRect.right + 1; + clip.y1 = (int)updateRect.bottom + 1; + + browser_window_redraw(g->bw, 0, 0, &clip, &ctx); + + if (g->careth != 0) + nsbeos_plot_caret(g->caretx, g->carety, g->careth); + + if (view->Window()) + view->Window()->EndViewTransaction(); + + // reset clipping just in case + view->ConstrainClippingRegion(NULL); + nsbeos_current_gc_set(NULL); + view->UnlockLooper(); +} + +void nsbeos_window_keypress_event(BView *view, gui_window *g, BMessage *event) +{ + const char *bytes; + char buff[6]; + int numbytes = 0; + uint32 mods; + uint32 key; + uint32 raw_char; + uint32_t nskey; + int i; + + if (event->FindInt32("modifiers", (int32 *)&mods) < B_OK) + mods = modifiers(); + if (event->FindInt32("key", (int32 *)&key) < B_OK) + key = 0; + if (event->FindInt32("raw_char", (int32 *)&raw_char) < B_OK) + raw_char = 0; + /* check for byte[] first, because C-space gives bytes="" (and byte[0] = '\0') */ + for (i = 0; i < 5; i++) { + buff[i] = '\0'; + if (event->FindInt8("byte", i, (int8 *)&buff[i]) < B_OK) + break; + } + + if (i) { + bytes = buff; + numbytes = i; + } else if (event->FindString("bytes", &bytes) < B_OK) + bytes = ""; + + if (!numbytes) + numbytes = strlen(bytes); + + LOG(("mods 0x%08lx key %ld raw %ld byte[0] %d", mods, key, raw_char, buff[0])); + + char byte; + if (numbytes == 1) { + byte = bytes[0]; + if (mods & B_CONTROL_KEY) + byte = (char)raw_char; + if (byte >= '!' && byte <= '~') + nskey = (uint32_t)byte; + else { + switch (byte) { + case B_BACKSPACE: nskey = KEY_DELETE_LEFT; break; + case B_TAB: nskey = KEY_TAB; break; + /*case XK_Linefeed: return QKlinefeed;*/ + case B_ENTER: nskey = (uint32_t)10; break; + case B_ESCAPE: nskey = (uint32_t)'\033'; break; + case B_SPACE: nskey = (uint32_t)' '; break; + case B_DELETE: nskey = KEY_DELETE_RIGHT; break; + /* + case B_INSERT: nskey = KEYSYM("insert"); break; + */ + case B_HOME: nskey = KEY_LINE_START; break; // XXX ? + case B_END: nskey = KEY_LINE_END; break; // XXX ? + case B_PAGE_UP: nskey = KEY_PAGE_UP; break; + case B_PAGE_DOWN: nskey = KEY_PAGE_DOWN; break; + case B_LEFT_ARROW: nskey = KEY_LEFT; break; + case B_RIGHT_ARROW: nskey = KEY_RIGHT; break; + case B_UP_ARROW: nskey = KEY_UP; break; + case B_DOWN_ARROW: nskey = KEY_DOWN; break; + /* + case B_FUNCTION_KEY: + switch (scancode) { + case B_F1_KEY: nskey = KEYSYM("f1"); break; + case B_F2_KEY: nskey = KEYSYM("f2"); break; + case B_F3_KEY: nskey = KEYSYM("f3"); break; + case B_F4_KEY: nskey = KEYSYM("f4"); break; + case B_F5_KEY: nskey = KEYSYM("f5"); break; + case B_F6_KEY: nskey = KEYSYM("f6"); break; + case B_F7_KEY: nskey = KEYSYM("f7"); break; + case B_F8_KEY: nskey = KEYSYM("f8"); break; + case B_F9_KEY: nskey = KEYSYM("f9"); break; + case B_F10_KEY: nskey = KEYSYM("f10"); break; + case B_F11_KEY: nskey = KEYSYM("f11"); break; + case B_F12_KEY: nskey = KEYSYM("f12"); break; + case B_PRINT_KEY: nskey = KEYSYM("print"); break; + case B_SCROLL_KEY: nskey = KEYSYM("scroll-lock"); break; + case B_PAUSE_KEY: nskey = KEYSYM("pause"); break; + } + */ + case 0: + nskey = (uint32_t)0; + default: + nskey = (uint32_t)raw_char; + /*if (simple_p) + nskey = (uint32_t)0;*/ + break; + } + } + } else { + nskey = utf8_to_ucs4(bytes, numbytes); + } + + bool done = browser_window_key_press(g->bw, nskey); + LOG(("nskey %d %d", nskey, done)); + //if (browser_window_key_press(g->bw, nskey)) + return; + +} + +#warning WRITEME +#if 0 /* GTK */ +gboolean nsbeos_window_keypress_event(GtkWidget *widget, GdkEventKey *event, + gpointer data) +{ + struct gui_window *g = data; + uint32_t nskey = gdkkey_to_nskey(event); + + if (browser_window_key_press(g->bw, nskey)) + return TRUE; + + if (event->state == 0) { + double value; + GtkAdjustment *vscroll = gtk_viewport_get_vadjustment(g->viewport); + + GtkAdjustment *hscroll = gtk_viewport_get_hadjustment(g->viewport); + + GtkAdjustment *scroll; + + const GtkAllocation *const alloc = + >K_WIDGET(g->viewport)->allocation; + + switch (event->keyval) { + default: + return TRUE; + + case GDK_Home: + case GDK_KP_Home: + scroll = vscroll; + value = scroll->lower; + break; + + case GDK_End: + case GDK_KP_End: + scroll = vscroll; + value = scroll->upper - alloc->height; + if (value < scroll->lower) + value = scroll->lower; + break; + + case GDK_Left: + case GDK_KP_Left: + scroll = hscroll; + value = gtk_adjustment_get_value(scroll) - + scroll->step_increment; + if (value < scroll->lower) + value = scroll->lower; + break; + + case GDK_Up: + case GDK_KP_Up: + scroll = vscroll; + value = gtk_adjustment_get_value(scroll) - + scroll->step_increment; + if (value < scroll->lower) + value = scroll->lower; + break; + + case GDK_Right: + case GDK_KP_Right: + scroll = hscroll; + value = gtk_adjustment_get_value(scroll) + + scroll->step_increment; + if (value > scroll->upper - alloc->width) + value = scroll->upper - alloc->width; + break; + + case GDK_Down: + case GDK_KP_Down: + scroll = vscroll; + value = gtk_adjustment_get_value(scroll) + + scroll->step_increment; + if (value > scroll->upper - alloc->height) + value = scroll->upper - alloc->height; + break; + + case GDK_Page_Up: + case GDK_KP_Page_Up: + scroll = vscroll; + value = gtk_adjustment_get_value(scroll) - + scroll->page_increment; + if (value < scroll->lower) + value = scroll->lower; + break; + + case GDK_Page_Down: + case GDK_KP_Page_Down: + scroll = vscroll; + value = gtk_adjustment_get_value(scroll) + + scroll->page_increment; + if (value > scroll->upper - alloc->height) + value = scroll->upper - alloc->height; + break; + } + + gtk_adjustment_set_value(scroll, value); + } + + return TRUE; +} + +#endif + +void nsbeos_window_resize_event(BView *view, gui_window *g, BMessage *event) +{ + CALLED(); + int32 width; + int32 height; + + // drop this event if we have at least 2 resize pending +#if 1 + if (atomic_add(&g->pending_resizes, -1) > 1) + return; +#endif + + if (event->FindInt32("width", &width) < B_OK) + width = -1; + if (event->FindInt32("height", &height) < B_OK) + height = -1; + width++; + height++; + + +#if 0 + hlcache_handle *content; + + content = g->bw->current_content; + + /* reformat or change extent if necessary */ + if ((content) && (g->old_width != width || g->old_height != height)) { + /* Ctrl-resize of a top-level window scales the content size */ +#if 0 + if ((g->old_width > 0) && (g->old_width != width) && (!g->bw->parent) && + (ro_gui_ctrl_pressed())) + new_scale = (g->bw->scale * width) / g->old_width; +#endif + g->bw->reformat_pending = true; + browser_reformat_pending = true; + } + if (g->update_extent || g->old_width != width || g->old_height != height) { + g->old_width = width; + g->old_height = height; + g->update_extent = false; + gui_window_set_extent(g, width, height); + } +#endif + g->bw->reformat_pending = true; + browser_reformat_pending = true; + + return; +} + + +void nsbeos_window_moved_event(BView *view, gui_window *g, BMessage *event) +{ + CALLED(); + +#warning XXX: Invalidate ? + if (!view || !view->LockLooper()) + return; + //view->Invalidate(view->Bounds()); + view->UnlockLooper(); + + //g->bw->reformat_pending = true; + //browser_reformat_pending = true; + + + return; +} + + +void nsbeos_reflow_all_windows(void) +{ + for (struct gui_window *g = window_list; g; g = g->next) + g->bw->reformat_pending = true; + + browser_reformat_pending = true; +} + + +/** + * Process pending reformats + */ + +void nsbeos_window_process_reformats(void) +{ + struct gui_window *g; + + browser_reformat_pending = false; + for (g = window_list; g; g = g->next) { + NSBrowserFrameView *view = g->view; + if (!g->bw->reformat_pending) + continue; + if (!view || !view->LockLooper()) + continue; + g->bw->reformat_pending = false; + BRect bounds = view->Bounds(); + view->UnlockLooper(); +#warning XXX why - 1 & - 2 !??? + browser_window_reformat(g->bw, + false, + bounds.Width() + 1 /* - 2*/, + bounds.Height() + 1); + } + +#warning WRITEME +#if 0 /* GTK */ + for (g = window_list; g; g = g->next) { + GtkWidget *widget = GTK_WIDGET(g->viewport); + if (!g->bw->reformat_pending) + continue; + g->bw->reformat_pending = false; + browser_window_reformat(g->bw, + false, + widget->allocation.width - 2, + widget->allocation.height); + } +#endif +} + + +void nsbeos_window_destroy_browser(struct gui_window *g) +{ + browser_window_destroy(g->bw); +} + +void gui_window_destroy(struct gui_window *g) +{ + if (!g) + return; + + if (g->prev) + g->prev->next = g->next; + else + window_list = g->next; + + if (g->next) + g->next->prev = g->prev; + + + LOG(("Destroying gui_window %p", g)); + assert(g != NULL); + assert(g->bw != NULL); + LOG((" Scaffolding: %p", g->scaffold)); + LOG((" Window name: %s", g->bw->name)); + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + BLooper *looper = g->view->Looper(); + /* If we're a top-level gui_window, destroy our scaffold */ + if (g->toplevel) { + g->view->RemoveSelf(); + delete g->view; + nsbeos_scaffolding_destroy(g->scaffold); + } else { + g->view->RemoveSelf(); + delete g->view; + looper->Unlock(); + } + //XXX + //looper->Unlock(); + +#warning FIXME + +#if 0 /* GTK */ + /* If we're a top-level gui_window, destroy our scaffold */ + if (g->scrolledwindow == NULL) { + gtk_widget_destroy(GTK_WIDGET(g->viewport)); + nsgtk_scaffolding_destroy(g->scaffold); + } else { + gtk_widget_destroy(GTK_WIDGET(g->scrolledwindow)); + } +#endif + + free(g); + +} + +void nsbeos_redraw_caret(struct gui_window *g) +{ + if (g->careth == 0) + return; + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + nsbeos_current_gc_set(g->view); + + g->view->Invalidate(BRect(g->caretx, g->carety, + g->caretx, g->carety + g->careth)); + + nsbeos_current_gc_set(NULL); + g->view->UnlockLooper(); +} + +void gui_window_redraw_window(struct gui_window *g) +{ + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + nsbeos_current_gc_set(g->view); + + g->view->Invalidate(); + + nsbeos_current_gc_set(NULL); + g->view->UnlockLooper(); +} + +void gui_window_update_box(struct gui_window *g, const struct rect *rect) +{ + hlcache_handle *c = g->bw->current_content; + + if (c == NULL) + return; + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + nsbeos_current_gc_set(g->view); + +//XXX +1 ?? + g->view->Invalidate(BRect(rect->x0, rect->y0, + rect->x1 - 1, rect->y1 - 1)); + + nsbeos_current_gc_set(NULL); + g->view->UnlockLooper(); +} + +bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +{ + CALLED(); + if (g->view == NULL) + return false; + if (!g->view->LockLooper()) + return false; + +#warning XXX: report to view frame ? + if (g->view->ScrollBar(B_HORIZONTAL)) + *sx = (int)g->view->ScrollBar(B_HORIZONTAL)->Value(); + if (g->view->ScrollBar(B_VERTICAL)) + *sy = (int)g->view->ScrollBar(B_VERTICAL)->Value(); + + g->view->UnlockLooper(); +#warning WRITEME +#if 0 /* GTK */ + GtkAdjustment *vadj = gtk_viewport_get_vadjustment(g->viewport); + GtkAdjustment *hadj = gtk_viewport_get_hadjustment(g->viewport); + + assert(vadj); + assert(hadj); + + *sy = (int)(gtk_adjustment_get_value(vadj)); + *sx = (int)(gtk_adjustment_get_value(hadj)); + +#endif + return true; +} + +void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +{ + CALLED(); + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + +#warning XXX: report to view frame ? + if (g->view->ScrollBar(B_HORIZONTAL)) + g->view->ScrollBar(B_HORIZONTAL)->SetValue(sx); + if (g->view->ScrollBar(B_VERTICAL)) + g->view->ScrollBar(B_VERTICAL)->SetValue(sy); + + g->view->UnlockLooper(); +#warning WRITEME +#if 0 /* GTK */ + GtkAdjustment *vadj = gtk_viewport_get_vadjustment(g->viewport); + GtkAdjustment *hadj = gtk_viewport_get_hadjustment(g->viewport); + gdouble vlower, vpage, vupper, hlower, hpage, hupper, x = (double)sx, y = (double)sy; + + assert(vadj); + assert(hadj); + + g_object_get(vadj, "page-size", &vpage, "lower", &vlower, "upper", &vupper, NULL); + g_object_get(hadj, "page-size", &hpage, "lower", &hlower, "upper", &hupper, NULL); + + if (x < hlower) + x = hlower; + if (x > (hupper - hpage)) + x = hupper - hpage; + if (y < vlower) + y = vlower; + if (y > (vupper - vpage)) + y = vupper - vpage; + + gtk_adjustment_set_value(vadj, y); + gtk_adjustment_set_value(hadj, x); +#endif +} + + +void gui_window_update_extent(struct gui_window *g) +{ + CALLED(); + if (!g->bw->current_content) + return; + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + float x_max = content_get_width(g->bw->current_content) * g->bw->scale /* - 1*/; + float y_max = content_get_height(g->bw->current_content) * g->bw->scale /* - 1*/; + float x_prop = g->view->Bounds().Width() / x_max; + float y_prop = g->view->Bounds().Height() / y_max; + x_max -= g->view->Bounds().Width() + 1; + y_max -= g->view->Bounds().Height() + 1; +printf("x_max = %f y_max = %f x_prop = %f y_prop = %f\n", x_max, y_max, x_prop, y_prop); + if (g->view->ScrollBar(B_HORIZONTAL)) { + g->view->ScrollBar(B_HORIZONTAL)->SetRange(0, x_max); + g->view->ScrollBar(B_HORIZONTAL)->SetProportion(x_prop); + g->view->ScrollBar(B_HORIZONTAL)->SetSteps(10, 50); + } + if (g->view->ScrollBar(B_VERTICAL)) { + g->view->ScrollBar(B_VERTICAL)->SetRange(0, y_max); + g->view->ScrollBar(B_VERTICAL)->SetProportion(y_prop); + g->view->ScrollBar(B_VERTICAL)->SetSteps(10, 50); + } + +#if 0 + g->view->ResizeTo( + g->bw->current_content->width * g->bw->scale /* - 1*/, + g->bw->current_content->height * g->bw->scale /* - 1*/); +#endif + + g->view->UnlockLooper(); + +#warning WRITEME +#if 0 /* GTK */ + gtk_widget_set_size_request(GTK_WIDGET(g->drawing_area), + g->bw->current_content->width * g->bw->scale, + g->bw->current_content->height * g->bw->scale); + + gtk_widget_set_size_request(GTK_WIDGET(g->viewport), 0, 0); +#endif +} + +/* some cursors like those in Firefox */ +// XXX: move to separate file or resource ? + +const uint8 kLinkCursorBits[] = { + 16, /* cursor size */ + 1, /* bits per pixel */ + 2, /* vertical hot spot */ + 2, /* horizontal hot spot */ + + /* data */ + 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x24, 0x00, 0x24, 0x00, 0x13, 0xe0, 0x12, 0x5c, 0x09, 0x2a, + 0x08, 0x01, 0x3c, 0x21, 0x4c, 0x71, 0x42, 0x71, 0x30, 0xf9, 0x0c, 0xf9, 0x02, 0x02, 0x01, 0x00, + + /* mask */ + 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x1f, 0xe0, 0x1f, 0xfc, 0x0f, 0xfe, + 0x0f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x0f, 0xff, 0x03, 0xfc, 0x01, 0xe0 +}; + +const uint8 kWatchCursorBits[] = { + 16, /* cursor size */ + 1, /* bits per pixel */ + 0, /* vertical hot spot */ + 1, /* horizontal hot spot */ + + /* data */ + 0x70, 0x00, 0x48, 0x00, 0x48, 0x00, 0x27, 0xc0, 0x24, 0xb8, 0x12, 0x54, 0x10, 0x02, 0x78, 0x02, + 0x98, 0x02, 0x84, 0x02, 0x60, 0x3a, 0x18, 0x46, 0x04, 0x8a, 0x02, 0x92, 0x01, 0x82, 0x00, 0x45, + + /* mask */ + 0x70, 0x00, 0x78, 0x00, 0x78, 0x00, 0x3f, 0xc0, 0x3f, 0xf8, 0x1f, 0xfc, 0x1f, 0xfe, 0x7f, 0xfe, + 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfe, 0x1f, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x00, 0x7f +}; + +const uint8 kWatch2CursorBits[] = { + 16, /* cursor size */ + 1, /* bits per pixel */ + 0, /* vertical hot spot */ + 1, /* horizontal hot spot */ + + /* data */ + 0x70, 0x00, 0x48, 0x00, 0x48, 0x00, 0x27, 0xc0, 0x24, 0xb8, 0x12, 0x54, 0x10, 0x02, 0x78, 0x02, + 0x98, 0x02, 0x84, 0x02, 0x60, 0x3a, 0x18, 0x46, 0x04, 0xa2, 0x02, 0x92, 0x01, 0xa2, 0x00, 0x45, + + /* mask */ + 0x70, 0x00, 0x78, 0x00, 0x78, 0x00, 0x3f, 0xc0, 0x3f, 0xf8, 0x1f, 0xfc, 0x1f, 0xfe, 0x7f, 0xfe, + 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfe, 0x1f, 0xfe, 0x07, 0xfe, 0x03, 0xfe, 0x01, 0xfe, 0x00, 0x7f +}; + + +void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) +{ + BCursor *cursor = NULL; + bool allocated = false; + + if (g->current_pointer == shape) + return; + + g->current_pointer = shape; + + switch (shape) { + case GUI_POINTER_POINT: + cursor = new BCursor(kLinkCursorBits); + allocated = true; +#if 0 // it's ugly anyway +#ifdef B_ZETA_VERSION + cursor = (BCursor *)B_CURSOR_LINK; +#endif +#endif + break; + case GUI_POINTER_CARET: + cursor = (BCursor *)B_CURSOR_I_BEAM; + break; + case GUI_POINTER_WAIT: + cursor = new BCursor(kWatchCursorBits); + allocated = true; + break; + case GUI_POINTER_PROGRESS: + cursor = new BCursor(kWatch2CursorBits); + allocated = true; + break; +#if 0 /* GTK */ + case GUI_POINTER_UP: + cursortype = GDK_TOP_SIDE; + break; + case GUI_POINTER_DOWN: + cursortype = GDK_BOTTOM_SIDE; + break; + case GUI_POINTER_LEFT: + cursortype = GDK_LEFT_SIDE; + break; + case GUI_POINTER_RIGHT: + cursortype = GDK_RIGHT_SIDE; + break; + case GUI_POINTER_LD: + cursortype = GDK_BOTTOM_LEFT_CORNER; + break; + case GUI_POINTER_RD: + cursortype = GDK_BOTTOM_RIGHT_CORNER; + break; + case GUI_POINTER_LU: + cursortype = GDK_TOP_LEFT_CORNER; + break; + case GUI_POINTER_RU: + cursortype = GDK_TOP_RIGHT_CORNER; + break; + case GUI_POINTER_CROSS: + cursortype = GDK_CROSS; + break; + case GUI_POINTER_MOVE: + cursortype = GDK_FLEUR; + break; + case GUI_POINTER_WAIT: + cursortype = GDK_WATCH; + break; + case GUI_POINTER_HELP: + cursortype = GDK_QUESTION_ARROW; + break; + case GUI_POINTER_MENU: + cursor = nsbeos_create_menu_cursor(); + nullcursor = true; + break; + case GUI_POINTER_PROGRESS: + /* In reality, this needs to be the funky left_ptr_watch + * which we can't do easily yet. + */ + cursortype = GDK_WATCH; + break; + /* The following we're not sure about */ + case GUI_POINTER_NO_DROP: + case GUI_POINTER_NOT_ALLOWED: + case GUI_POINTER_DEFAULT: +#endif + default: + cursor = (BCursor *)B_CURSOR_SYSTEM_DEFAULT; + allocated = false; + } + + if (g->view && g->view->LockLooper()) { + g->view->SetViewCursor(cursor); + g->view->UnlockLooper(); + } + + if (allocated) + delete cursor; +} + +void gui_window_hide_pointer(struct gui_window *g) +{ + //XXX no BView::HideCursor... use empty one +} + +void gui_window_place_caret(struct gui_window *g, int x, int y, int height) +{ + CALLED(); + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + nsbeos_redraw_caret(g); + + g->caretx = x; + g->carety = y + 1; + g->careth = height - 2; + + nsbeos_redraw_caret(g); + g->view->MakeFocus(); + + g->view->UnlockLooper(); +} + +void gui_window_remove_caret(struct gui_window *g) +{ + int oh = g->careth; + + if (oh == 0) + return; + + g->careth = 0; + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + nsbeos_current_gc_set(g->view); + + g->view->Invalidate(BRect(g->caretx, g->carety, g->caretx, g->carety + oh)); + + nsbeos_current_gc_set(NULL); + g->view->UnlockLooper(); +} + +void gui_window_new_content(struct gui_window *g) +{ + if (!g->toplevel) + return; + + if (g->view == NULL) + return; + if (!g->view->LockLooper()) + return; + + // scroll back to top + g->view->ScrollTo(0,0); + + g->view->UnlockLooper(); +} + +bool gui_window_scroll_start(struct gui_window *g) +{ + return true; +} + +bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, + const struct rect *rect) +{ + return true; +} + +void gui_drag_save_object(gui_save_type type, hlcache_handle *c, + struct gui_window *g) +{ + +} + +void gui_drag_save_selection(struct selection *s, struct gui_window *g) +{ + +} + +void gui_start_selection(struct gui_window *g) +{ + current_selection.Truncate(0); + while (current_selection_textruns.ItemAt(0)) { + text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L); + delete run; + } + + if (!g->view->LockLooper()) + return; + + g->view->MakeFocus(); + + g->view->UnlockLooper(); +} + +void gui_clear_selection(struct gui_window *g) +{ +} + +void gui_paste_from_clipboard(struct gui_window *g, int x, int y) +{ + BMessage *clip; + if (be_clipboard->Lock()) { + clip = be_clipboard->Data(); + if (clip) { + const char *text; + int32 textlen; + if (clip->FindData("text/plain", B_MIME_TYPE, + (const void **)&text, &textlen) >= B_OK) { + browser_window_paste_text(g->bw,text,textlen,true); + } + } + be_clipboard->Unlock(); + } +} + +bool gui_empty_clipboard(void) +{ + current_selection.Truncate(0); + while (current_selection_textruns.ItemAt(0)) { + text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L); + delete run; + } + return true; +} + +bool gui_add_to_clipboard(const char *text, size_t length, bool space) +{ + BString s; + s.SetTo(text, length); + current_selection << s; + if (space) + current_selection << " "; + return true; +} + +bool gui_commit_clipboard(void) +{ + BMessage *clip; + + if (current_selection.Length() == 0) + return true; + + if (be_clipboard->Lock()) { + be_clipboard->Clear(); + clip = be_clipboard->Data(); + if (clip) { + clip->AddData("text/plain", B_MIME_TYPE, + current_selection.String(), + current_selection.Length()); + int arraySize = sizeof(text_run_array) + + current_selection_textruns.CountItems() * sizeof(text_run); + text_run_array *array = (text_run_array *)malloc(arraySize); + array->count = current_selection_textruns.CountItems(); + for (int i = 0; i < array->count; i++) + memcpy(&array->runs[i], current_selection_textruns.ItemAt(i), + sizeof(text_run)); + clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, + array, arraySize); + free(array); + + gui_empty_clipboard(); + be_clipboard->Commit(); + } + be_clipboard->Unlock(); + } + return true; +} + +static bool copy_handler(const char *text, size_t length, struct box *box, + void *handle, const char *whitespace_text, + size_t whitespace_length) +{ + bool space = false; + //XXX: handle box->style to StyledEdit / RTF ? + /* add any whitespace which precedes the text from this box */ + if (whitespace_text) { + if (!gui_add_to_clipboard(whitespace_text, + whitespace_length, false)) { + return false; + } + } + + // add a text_run for StyledEdit-like text formating + if (box && box->style) { + text_run *run = new text_run; + BFont font; + plot_font_style_t style; + font_plot_style_from_css(box->style, &style); + nsbeos_style_to_font(font, &style); + run->offset = current_selection.Length(); + run->font = font; + css_color csscolor; + if (css_computed_color(box->style, &csscolor) == CSS_COLOR_COLOR) { + run->color = nsbeos_rgb_colour(nscss_color_to_ns(csscolor)); + } + current_selection_textruns.AddItem(run); + space = box->space != 0; + } + + /* add the text from this box */ + if (!gui_add_to_clipboard(text, length, space)) + return false; + + return true; +} + +bool gui_copy_to_clipboard(struct selection *s) +{ + if (s->defined && selection_traverse(s, copy_handler, NULL)) + gui_commit_clipboard(); + return true; +} + + +void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, + bool scaled) +{ + if (g->view && g->view->LockLooper()) { + *width = g->view->Bounds().Width() + 1; + *height = g->view->Bounds().Height() + 1; + g->view->UnlockLooper(); + } + + if (scaled) { + *width /= g->bw->scale; + *height /= g->bw->scale; + } +} + diff --git a/beos/window.h b/beos/window.h new file mode 100644 index 000000000..fc8a4f832 --- /dev/null +++ b/beos/window.h @@ -0,0 +1,64 @@ +/* + * Copyright 2008 François Revol + * + * 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 . + */ + +#ifndef NETSURF_BEOS_WINDOW_H +#define NETSURF_BEOS_WINDOW_H 1 + +extern "C" { +#include "desktop/gui.h" +#include "desktop/browser.h" +} +#include "beos/scaffolding.h" + +class NSBrowserFrameView : public BView { +public: + NSBrowserFrameView(BRect frame, struct gui_window *gui); +virtual ~NSBrowserFrameView(); + +virtual void MessageReceived(BMessage *message); +virtual void Draw(BRect updateRect); + +//virtual void FrameMoved(BPoint new_location); +virtual void FrameResized(float new_width, float new_height); + +virtual void KeyDown(const char *bytes, int32 numBytes); +virtual void MouseDown(BPoint where); +virtual void MouseUp(BPoint where); +virtual void MouseMoved(BPoint where, uint32 transit, const BMessage *msg); + +private: + struct gui_window *fGuiWindow; +}; + +void nsbeos_dispatch_event(BMessage *message); + + + +void nsbeos_reflow_all_windows(void); +void nsbeos_window_process_reformats(void); + +nsbeos_scaffolding *nsbeos_get_scaffold(struct gui_window *g); +struct browser_window *nsbeos_get_browser_for_gui(struct gui_window *g); + +float nsbeos_get_scale_for_gui(struct gui_window *g); +int nsbeos_gui_window_update_targets(struct gui_window *g); +void nsbeos_window_destroy_browser(struct gui_window *g); + +struct browser_window *nsbeos_get_browser_window(struct gui_window *g); + +#endif /* NETSURF_BEOS_WINDOW_H */ -- cgit v1.2.3