netsurf: branch master updated. release/3.5-374-ga2388a9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/a2388a91cf9ceb7efb203...
...commit http://git.netsurf-browser.org/netsurf.git/commit/a2388a91cf9ceb7efb203a7...
...tree http://git.netsurf-browser.org/netsurf.git/tree/a2388a91cf9ceb7efb203a7b4...
The branch, master has been updated
via a2388a91cf9ceb7efb203a7b4d6d250395cdb744 (commit)
from 3ecced92f335f80a372cf3fb0ab1c6f7c564cebb (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=a2388a91cf9ceb7efb2...
commit a2388a91cf9ceb7efb203a7b4d6d250395cdb744
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Rationalise the use of win32 application instance handle use
The use of the application instance handle global variable was
inconsistent throughout the windows frontend.
By rationalising the passing of these handles it showed that some of
the toolbar and throbber parent handles were also setup wrong giving
odd offset behaviour.
All these issues have been addressed and the throbber is now in the
correct position.
diff --git a/frontends/windows/download.c b/frontends/windows/download.c
index fff47ac..3a96983 100644
--- a/frontends/windows/download.c
+++ b/frontends/windows/download.c
@@ -16,6 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * windows frontend download implementation
+ *
+ * \todo The windows download functionality is very buggy this needs redoing
+ */
+
#include <limits.h>
#include "utils/inet.h" /* get correct winsock ordering */
#include <shlobj.h>
@@ -48,30 +55,139 @@ struct gui_download_window {
char *original_total_size;
int size;
int downloaded;
- unsigned int progress;
+ unsigned int progress;
int time_remaining;
struct timeval start_time;
int speed;
int error;
- struct gui_window *window;
+ struct gui_window *window;
FILE *file;
- download_status status;
+ download_status status;
};
static bool downloading = false;
static struct gui_download_window *download1;
-BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam,
- LPARAM lparam);
-static void nsws_download_update_label(void *p);
-static void nsws_download_update_progress(void *p);
-static void nsws_download_clear_data(struct gui_download_window *w);
+
+static void nsws_download_update_label(void *p)
+{
+ struct gui_download_window *w = p;
+ if (w->hwnd == NULL) {
+ win32_schedule(-1, nsws_download_update_label, p);
+ return;
+ }
+ HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_LABEL);
+ char *size = human_friendly_bytesize(w->downloaded);
+ int i = 0, temp = w->time_remaining;
+ if (temp == -1) {
+ w->time_left = strdup(messages_get("UnknownSize"));
+ i = strlen(w->time_left);
+ } else {
+ do {
+ temp = temp / 10;
+ i++;
+ } while (temp > 2);
+ w->time_left = malloc(i + SLEN(" s") + 1);
+ if (w->time_left != NULL) {
+ if (w->time_remaining > 3600)
+ sprintf(w->time_left, "%d h",
+ w->time_remaining / 3600);
+ else if (w->time_remaining > 60)
+ sprintf(w->time_left, "%d m",
+ w->time_remaining / 60);
+ else
+ sprintf(w->time_left, "%d s",
+ w->time_remaining);
+ }
+ }
+ char label[strlen(w->title) + strlen(size) + strlen(w->total_size) +
+ + strlen(w->domain) + strlen(w->filename) +
+ SLEN("download from to \n[\t/\t]\n estimate of time"
+ " remaining ") + i + 1];
+ sprintf(label, "download %s from %s to %s\n[%s\t/\t%s] [%d%%]\n"
+ "estimate of time remaining %s", w->title, w->domain,
+ w->filename, size, w->total_size, w->progress / 100,
+ w->time_left);
+ if (w->time_left != NULL) {
+ free(w->time_left);
+ w->time_left = NULL;
+ }
+ SendMessage(sub, WM_SETTEXT, (WPARAM)0, (LPARAM)label);
+ if (w->progress < 10000) {
+ win32_schedule(500, nsws_download_update_label, p);
+ }
+}
+
+
+static void nsws_download_update_progress(void *p)
+{
+ struct gui_download_window *w = p;
+ if (w->hwnd == NULL) {
+ win32_schedule(-1, nsws_download_update_progress, p);
+ return;
+ }
+ HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_PROGRESS);
+ SendMessage(sub, PBM_SETPOS, (WPARAM)(w->progress / 100), 0);
+ if (w->progress < 10000) {
+ win32_schedule(500, nsws_download_update_progress, p);
+ }
+}
+
+
+static void nsws_download_clear_data(struct gui_download_window *w)
+{
+ if (w == NULL)
+ return;
+ if (w->title != NULL)
+ free(w->title);
+ if (w->filename != NULL)
+ free(w->filename);
+ if (w->domain != NULL)
+ free(w->domain);
+ if (w->time_left != NULL)
+ free(w->time_left);
+ if (w->total_size != NULL)
+ free(w->total_size);
+ if (w->file != NULL)
+ fclose(w->file);
+ win32_schedule(-1, nsws_download_update_progress, (void *)w);
+ win32_schedule(-1, nsws_download_update_label, (void *)w);
+}
+
+
+static BOOL CALLBACK
+nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ switch(msg) {
+ case WM_INITDIALOG:
+ nsws_download_update_label((void *)download1);
+ nsws_download_update_progress((void *)download1);
+ return TRUE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wparam)) {
+ case IDOK:
+ if (download1->downloaded != download1->size)
+ return TRUE;
+
+ case IDCANCEL:
+ nsws_download_clear_data(download1);
+ download1 = NULL;
+ downloading = false;
+ EndDialog(hwnd, IDCANCEL);
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
static bool nsws_download_window_up(struct gui_download_window *w)
{
- w->hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD),
- gui_window_main_window(w->window),
- nsws_download_event_callback);
+ w->hwnd = CreateDialog(hinst,
+ MAKEINTRESOURCE(IDD_DLG_DOWNLOAD),
+ gui_window_main_window(w->window),
+ nsws_download_event_callback);
if (w->hwnd == NULL) {
return false;
}
@@ -79,6 +195,7 @@ static bool nsws_download_window_up(struct gui_download_window *w)
return true;
}
+
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *gui)
{
@@ -88,8 +205,8 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
return NULL;
}
downloading = true;
- struct gui_download_window *w =
- malloc(sizeof(struct gui_download_window));
+ struct gui_download_window *w =
+ malloc(sizeof(struct gui_download_window));
if (w == NULL) {
win32_warning(messages_get("NoMemory"), 0);
return NULL;
@@ -98,10 +215,10 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
char *domain, *filename, *destination;
nsurl *url = download_context_get_url(ctx);
bool unknown_size = (total_size == 0);
- const char *size = (unknown_size) ?
- messages_get("UnknownSize") :
- human_friendly_bytesize(total_size);
-
+ const char *size = (unknown_size) ?
+ messages_get("UnknownSize") :
+ human_friendly_bytesize(total_size);
+
if (nsurl_nice(url, &filename, false) != NSERROR_OK) {
filename = strdup(messages_get("UnknownFile"));
}
@@ -186,119 +303,9 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
}
-BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam,
- LPARAM lparam)
-{
- switch(msg) {
- case WM_INITDIALOG:
- nsws_download_update_label((void *)download1);
- nsws_download_update_progress((void *)download1);
- return TRUE;
-
- case WM_COMMAND:
- switch(LOWORD(wparam)) {
- case IDOK:
- if (download1->downloaded != download1->size)
- return TRUE;
-
- case IDCANCEL:
- nsws_download_clear_data(download1);
- download1 = NULL;
- downloading = false;
- EndDialog(hwnd, IDCANCEL);
- return FALSE;
- }
- }
- return FALSE;
-}
-
-void nsws_download_update_label(void *p)
-{
- struct gui_download_window *w = p;
- if (w->hwnd == NULL) {
- win32_schedule(-1, nsws_download_update_label, p);
- return;
- }
- HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_LABEL);
- char *size = human_friendly_bytesize(w->downloaded);
- int i = 0, temp = w->time_remaining;
- if (temp == -1) {
- w->time_left = strdup(messages_get("UnknownSize"));
- i = strlen(w->time_left);
- } else {
- do {
- temp = temp / 10;
- i++;
- } while (temp > 2);
- w->time_left = malloc(i + SLEN(" s") + 1);
- if (w->time_left != NULL) {
- if (w->time_remaining > 3600)
- sprintf(w->time_left, "%d h",
- w->time_remaining / 3600);
- else if (w->time_remaining > 60)
- sprintf(w->time_left, "%d m",
- w->time_remaining / 60);
- else
- sprintf(w->time_left, "%d s",
- w->time_remaining);
- }
- }
- char label[strlen(w->title) + strlen(size) + strlen(w->total_size) +
- + strlen(w->domain) + strlen(w->filename) +
- SLEN("download from to \n[\t/\t]\n estimate of time"
- " remaining ") + i + 1];
- sprintf(label, "download %s from %s to %s\n[%s\t/\t%s] [%d%%]\n"
- "estimate of time remaining %s", w->title, w->domain,
- w->filename, size, w->total_size, w->progress / 100,
- w->time_left);
- if (w->time_left != NULL) {
- free(w->time_left);
- w->time_left = NULL;
- }
- SendMessage(sub, WM_SETTEXT, (WPARAM)0, (LPARAM)label);
- if (w->progress < 10000) {
- win32_schedule(500, nsws_download_update_label, p);
- }
-}
-
-void nsws_download_update_progress(void *p)
-{
- struct gui_download_window *w = p;
- if (w->hwnd == NULL) {
- win32_schedule(-1, nsws_download_update_progress, p);
- return;
- }
- HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_PROGRESS);
- SendMessage(sub, PBM_SETPOS, (WPARAM)(w->progress / 100), 0);
- if (w->progress < 10000) {
- win32_schedule(500, nsws_download_update_progress, p);
- }
-}
-
-void nsws_download_clear_data(struct gui_download_window *w)
-{
- if (w == NULL)
- return;
- if (w->title != NULL)
- free(w->title);
- if (w->filename != NULL)
- free(w->filename);
- if (w->domain != NULL)
- free(w->domain);
- if (w->time_left != NULL)
- free(w->time_left);
- if (w->total_size != NULL)
- free(w->total_size);
- if (w->file != NULL)
- fclose(w->file);
- win32_schedule(-1, nsws_download_update_progress, (void *)w);
- win32_schedule(-1, nsws_download_update_label, (void *)w);
-}
-
-
-static nserror
+static nserror
gui_download_window_data(struct gui_download_window *w, const char *data,
- unsigned int size)
+ unsigned int size)
{
if ((w == NULL) || (w->file == NULL))
return NSERROR_SAVE_FAILED;
@@ -309,16 +316,16 @@ gui_download_window_data(struct gui_download_window *w, const char *data,
LOG("file write error %d of %d", size - res, size);
w->downloaded += res;
w->progress = (unsigned int)(((long long)(w->downloaded) * 10000)
- / w->size);
+ / w->size);
gettimeofday(&val, NULL);
- w->time_remaining = (w->progress == 0) ? -1 :
- (int)((val.tv_sec - w->start_time.tv_sec) *
- (10000 - w->progress) / w->progress);
+ w->time_remaining = (w->progress == 0) ? -1 :
+ (int)((val.tv_sec - w->start_time.tv_sec) *
+ (10000 - w->progress) / w->progress);
return NSERROR_OK;
}
static void gui_download_window_error(struct gui_download_window *w,
- const char *error_msg)
+ const char *error_msg)
{
LOG("error %s", error_msg);
}
@@ -341,4 +348,3 @@ static struct gui_download_table download_table = {
};
struct gui_download_table *win32_download_table = &download_table;
-
diff --git a/frontends/windows/font.h b/frontends/windows/font.h
index f2128af..0e86755 100644
--- a/frontends/windows/font.h
+++ b/frontends/windows/font.h
@@ -22,8 +22,8 @@
* The interface to the win32 font and utf8 handling.
*/
-#ifndef _NETSURF_WINDOWS_FONT_H_
-#define _NETSURF_WINDOWS_FONT_H_
+#ifndef NETSURF_WINDOWS_FONT_H
+#define NETSURF_WINDOWS_FONT_H
extern HWND font_hwnd;
diff --git a/frontends/windows/gui.c b/frontends/windows/gui.c
index 0ab1e32..043a93d 100644
--- a/frontends/windows/gui.c
+++ b/frontends/windows/gui.c
@@ -39,10 +39,14 @@
#include "windows/filetype.h"
#include "windows/gui.h"
-static bool win32_quit = false;
-
-HINSTANCE hInstance; /** win32 application instance handle. */
+/**
+ * win32 application instance handle.
+ *
+ * This handle is set in the main windows entry point.
+ */
+HINSTANCE hinst;
+static bool win32_quit = false;
void win32_set_quit(bool q)
{
diff --git a/frontends/windows/gui.h b/frontends/windows/gui.h
index 8dd2ded..efbf029 100644
--- a/frontends/windows/gui.h
+++ b/frontends/windows/gui.h
@@ -23,7 +23,7 @@
struct gui_window;
struct gui_clipboard_table *win32_clipboard_table;
-extern HINSTANCE hInstance;
+extern HINSTANCE hinst;
/** Directory where all configuration files are held. */
extern char *nsw32_config_home;
diff --git a/frontends/windows/localhistory.c b/frontends/windows/localhistory.c
index ce1877f..15705d1 100644
--- a/frontends/windows/localhistory.c
+++ b/frontends/windows/localhistory.c
@@ -48,7 +48,9 @@ struct nsws_localhistory {
};
-static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct gui_window *gw)
+static void
+nsws_localhistory_scroll_check(struct nsws_localhistory *l,
+ struct gui_window *gw)
{
SCROLLINFO si;
@@ -76,8 +78,8 @@ static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct g
}
-
-static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw)
+static void
+nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw)
{
HDC tmp_hdc;
struct redraw_context ctx = {
@@ -114,6 +116,7 @@ void nsws_localhistory_close(struct gui_window *w)
CloseWindow(l->hwnd);
}
+
static LRESULT CALLBACK
nsws_localhistory_event_callback(HWND hwnd, UINT msg,
WPARAM wparam, LPARAM lparam)
@@ -297,6 +300,7 @@ nsws_localhistory_event_callback(HWND hwnd, UINT msg,
return 0;
}
+
/* exported method documented in windows/localhistory.h */
struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
{
@@ -347,23 +351,31 @@ struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
#endif
InitCommonControlsEx(&icc);
-
- LOG("creating local history window for hInstance %p", hInstance);
+ LOG("creating local history window for hInstance %p", hinst);
localhistory->hwnd = CreateWindow(windowclassname_localhistory,
- "NetSurf History",
- WS_THICKFRAME | WS_HSCROLL |
- WS_VSCROLL | WS_CLIPCHILDREN |
- WS_CLIPSIBLINGS | WS_SYSMENU | CS_DBLCLKS,
- r.left + margin/2,
- r.top + margin/2,
- localhistory->guiwidth,
- localhistory->guiheight,
- NULL, NULL, hInstance, NULL);
+ "NetSurf History",
+ WS_THICKFRAME |
+ WS_HSCROLL |
+ WS_VSCROLL |
+ WS_CLIPCHILDREN |
+ WS_CLIPSIBLINGS |
+ WS_SYSMENU |
+ CS_DBLCLKS,
+ r.left + margin/2,
+ r.top + margin/2,
+ localhistory->guiwidth,
+ localhistory->guiheight,
+ NULL,
+ NULL,
+ hinst,
+ NULL);
/* set the gui window associated with this browser */
SetProp(localhistory->hwnd, TEXT("GuiWnd"), (HANDLE)gw);
- LOG("gui_window %p width %d height %d hwnd %p", gw, localhistory->guiwidth, localhistory->guiheight, localhistory->hwnd);
+ LOG("gui_window %p width %d height %d hwnd %p",
+ gw, localhistory->guiwidth, localhistory->guiheight,
+ localhistory->hwnd);
nsws_localhistory_up(localhistory, gw);
UpdateWindow(localhistory->hwnd);
@@ -372,6 +384,7 @@ struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
return localhistory;
}
+
/* exported method documented in windows/localhistory.h */
nserror
nsws_create_localhistory_class(HINSTANCE hinstance) {
diff --git a/frontends/windows/main.c b/frontends/windows/main.c
index 7b93c3b..7c94c06 100644
--- a/frontends/windows/main.c
+++ b/frontends/windows/main.c
@@ -303,6 +303,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
die("NetSurf operation table registration failed");
}
+ /* Save the application-instance handle. */
+ hinst = hInstance;
+
setbuf(stderr, NULL);
/* Construct a unix style argc/argv */
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index cc29d19..b8c2b39 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -61,6 +61,9 @@ static const char windowclassname_main[] = "nswsmainwindow";
/** width of the throbber element */
#define NSWS_THROBBER_WIDTH 24
+/** height of the url entry box */
+#define NSWS_URLBAR_HEIGHT 23
+
/** Number of open windows */
static int open_windows = 0;
@@ -138,16 +141,15 @@ static void nsws_window_set_accels(struct gui_window *w)
/**
* creation of a new full browser window
*
+ * \param hInstance The application instance handle.
* \param gw gui window context.
* \return The newly created window instance.
*/
-static HWND nsws_window_create(struct gui_window *gw)
+static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw)
{
HWND hwnd;
INITCOMMONCONTROLSEX icc;
- LOG("GUI window %p", gw);
-
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES;
#if WINVER > 0x0501
@@ -158,11 +160,14 @@ static HWND nsws_window_create(struct gui_window *gw)
gw->mainmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN));
gw->rclick = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT));
- LOG("creating window for hInstance %p", hInstance);
+ LOG("creating hInstance %p GUI window %p", hInstance, gw);
hwnd = CreateWindowEx(0,
windowclassname_main,
"NetSurf Browser",
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_DBLCLKS,
+ WS_OVERLAPPEDWINDOW |
+ WS_CLIPCHILDREN |
+ WS_CLIPSIBLINGS |
+ CS_DBLCLKS,
CW_USEDEFAULT,
CW_USEDEFAULT,
gw->width,
@@ -186,10 +191,14 @@ static HWND nsws_window_create(struct gui_window *gw)
(nsoption_int(window_height) >= 100) &&
(nsoption_int(window_x) >= 0) &&
(nsoption_int(window_y) >= 0)) {
- LOG("Setting Window position %d,%d %d,%d", nsoption_int(window_x), nsoption_int(window_y), nsoption_int(window_width), nsoption_int(window_height));
+ LOG("Setting Window position %d,%d %d,%d",
+ nsoption_int(window_x), nsoption_int(window_y),
+ nsoption_int(window_width), nsoption_int(window_height));
SetWindowPos(hwnd, HWND_TOP,
- nsoption_int(window_x), nsoption_int(window_y),
- nsoption_int(window_width), nsoption_int(window_height),
+ nsoption_int(window_x),
+ nsoption_int(window_y),
+ nsoption_int(window_width),
+ nsoption_int(window_height),
SWP_SHOWWINDOW);
}
@@ -289,7 +298,7 @@ urlbar_dimensions(HWND hWndParent,
int *height)
{
RECT rc;
- const int cy_edit = 23;
+ const int cy_edit = NSWS_URLBAR_HEIGHT;
GetClientRect(hWndParent, &rc);
*x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
@@ -338,8 +347,10 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
/* move throbber */
if (gw->throbber != NULL) {
MoveWindow(gw->throbber,
- LOWORD(lparam) - NSWS_THROBBER_WIDTH - 4, 8,
- NSWS_THROBBER_WIDTH, NSWS_THROBBER_WIDTH,
+ LOWORD(lparam) - NSWS_THROBBER_WIDTH - 4,
+ urly,
+ NSWS_THROBBER_WIDTH,
+ NSWS_THROBBER_WIDTH,
true);
}
break;
@@ -434,12 +445,15 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
*
* Create an Edit control for enerting urls
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
- * \param hWndParent The main containing window.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
+nsws_window_urlbar_create(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
int urlx, urly, urlwidth, urlheight;
HWND hwnd;
@@ -499,23 +513,33 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
/**
* creation of throbber
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_throbber_create(struct gui_window *gw)
+nsws_window_throbber_create(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
HWND hwnd;
char avi[PATH_MAX];
+ int urlx, urly, urlwidth, urlheight;
+
+ urlbar_dimensions(hWndParent,
+ gw->toolbuttonsize,
+ gw->toolbuttonc,
+ &urlx, &urly, &urlwidth, &urlheight);
hwnd = CreateWindow(ANIMATE_CLASS,
"",
WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT,
gw->width - NSWS_THROBBER_WIDTH - 4,
- 8,
+ urly,
NSWS_THROBBER_WIDTH,
NSWS_THROBBER_WIDTH,
- gw->main,
+ hWndParent,
(HMENU) IDC_MAIN_THROBBER,
hInstance,
NULL);
@@ -537,27 +561,33 @@ nsws_window_throbber_create(struct gui_window *gw)
/**
* create a win32 image list for the toolbar.
*
+ * \param hInstance The application instance handle.
* \param resid The resource ID of the image.
* \param bsize The size of the image to load.
* \param bcnt The number of bitmaps to load into the list.
* \return The image list or NULL on error.
*/
static HIMAGELIST
-get_imagelist(int resid, int bsize, int bcnt)
+get_imagelist(HINSTANCE hInstance, int resid, int bsize, int bcnt)
{
HIMAGELIST hImageList;
HBITMAP hScrBM;
LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
- hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
+ hImageList = ImageList_Create(bsize, bsize,
+ ILC_COLOR24 | ILC_MASK, 0,
bcnt);
- if (hImageList == NULL)
+ if (hImageList == NULL) {
return NULL;
+ }
- hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
- IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
-
+ hScrBM = LoadImage(hInstance,
+ MAKEINTRESOURCE(resid),
+ IMAGE_BITMAP,
+ 0,
+ 0,
+ LR_DEFAULTCOLOR);
if (hScrBM == NULL) {
win_perror("LoadImage");
return NULL;
@@ -577,12 +607,18 @@ get_imagelist(int resid, int bsize, int bcnt)
/**
* create win32 main window toolbar and add controls and message handler
*
+ * Toolbar has buttons on the left, url entry space in the middle and
+ * activity throbber on the right.
+ *
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
- * \param hWndParent The main containing window.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
+nsws_window_create_toolbar(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
HIMAGELIST hImageList;
HWND hWndToolbar;
@@ -597,10 +633,15 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
WNDPROC toolproc;
/* Create the toolbar window and subclass its message handler. */
- hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, "Toolbar",
+ hWndToolbar = CreateWindowEx(0,
+ TOOLBARCLASSNAME,
+ "Toolbar",
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT,
0, 0, 0, 0,
- hWndParent, NULL, HINST_COMMCTRL, NULL);
+ hWndParent,
+ NULL,
+ HINST_COMMCTRL,
+ NULL);
if (!hWndToolbar) {
return NULL;
}
@@ -620,28 +661,38 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
gw->toolbuttonc = sizeof(tbButtons) / sizeof(TBBUTTON);
/* Create the standard image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);
+ SendMessage(hWndToolbar,
+ TB_SETIMAGELIST,
+ 0,
+ (LPARAM)hImageList);
}
/* Create the disabled image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_GREY,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP_GREY,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETDISABLEDIMAGELIST, 0,
+ SendMessage(hWndToolbar,
+ TB_SETDISABLEDIMAGELIST,
+ 0,
(LPARAM)hImageList);
}
/* Create the hot image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_HOT,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP_HOT,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETHOTIMAGELIST, 0,
+ SendMessage(hWndToolbar,
+ TB_SETHOTIMAGELIST,
+ 0,
(LPARAM)hImageList);
}
@@ -655,9 +706,9 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
(WPARAM)gw->toolbuttonc,
(LPARAM)&tbButtons);
- gw->urlbar = nsws_window_urlbar_create(gw, hWndToolbar);
+ gw->urlbar = nsws_window_urlbar_create(hInstance, hWndToolbar, gw);
- gw->throbber = nsws_window_throbber_create(gw);
+ gw->throbber = nsws_window_throbber_create(hInstance, hWndToolbar, gw);
return hWndToolbar;
}
@@ -666,20 +717,28 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
/**
* creation of status bar
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
*/
-static HWND nsws_window_create_statusbar(struct gui_window *gw)
+static HWND
+nsws_window_create_statusbar(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
- HWND hwnd = CreateWindowEx(0,
- STATUSCLASSNAME,
- NULL,
- WS_CHILD | WS_VISIBLE,
- 0, 0, 0, 0,
- gw->main,
- (HMENU)IDC_MAIN_STATUSBAR,
- hInstance,
- NULL);
- SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf");
+ HWND hwnd;
+ hwnd = CreateWindowEx(0,
+ STATUSCLASSNAME,
+ NULL,
+ WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0,
+ hWndParent,
+ (HMENU)IDC_MAIN_STATUSBAR,
+ hInstance,
+ NULL);
+ if (hwnd != NULL) {
+ SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf");
+ }
return hwnd;
}
@@ -1020,7 +1079,7 @@ nsws_window_command(HWND hwnd,
break;
case IDM_EDIT_PREFERENCES:
- nsws_prefs_dialog_init(hInstance, gw->main);
+ nsws_prefs_dialog_init(hinst, gw->main);
break;
case IDM_NAV_BACK:
@@ -1172,7 +1231,7 @@ nsws_window_command(HWND hwnd,
break;
case IDM_HELP_ABOUT:
- nsws_about_dialog_init(hInstance, gw->main);
+ nsws_about_dialog_init(hinst, gw->main);
break;
case IDC_MAIN_LAUNCH_URL:
@@ -1409,10 +1468,10 @@ win32_window_create(struct browser_window *bw,
gw->next = window_list;
window_list = gw;
- gw->main = nsws_window_create(gw);
- gw->toolbar = nsws_window_create_toolbar(gw, gw->main);
- gw->statusbar = nsws_window_create_statusbar(gw);
- gw->drawingarea = nsws_window_create_drawable(hInstance, gw->main, gw);
+ gw->main = nsws_window_create(hinst, gw);
+ gw->toolbar = nsws_window_create_toolbar(hinst, gw->main, gw);
+ gw->statusbar = nsws_window_create_statusbar(hinst, gw->main, gw);
+ gw->drawingarea = nsws_window_create_drawable(hinst, gw->main, gw);
LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p",
gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
@@ -1860,31 +1919,30 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
/* exported interface documented in windows/window.h */
nserror
-nsws_create_main_class(HINSTANCE hinstance) {
+nsws_create_main_class(HINSTANCE hinstance)
+{
nserror ret = NSERROR_OK;
- WNDCLASSEX w;
+ WNDCLASSEX wc;
/* main window */
- w.cbSize = sizeof(WNDCLASSEX);
- w.style = 0;
- w.lpfnWndProc = nsws_window_event_callback;
- w.cbClsExtra = 0;
- w.cbWndExtra = 0;
- w.hInstance = hinstance;
- w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
- w.hCursor = NULL;
- w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
- w.lpszMenuName = NULL;
- w.lpszClassName = windowclassname_main;
- w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
-
- if (RegisterClassEx(&w) == 0) {
- win_perror("DrawableClass");
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.style = 0;
+ wc.lpfnWndProc = nsws_window_event_callback;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hinstance;
+ wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+ wc.hCursor = NULL;
+ wc.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = windowclassname_main;
+ wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+
+ if (RegisterClassEx(&wc) == 0) {
+ win_perror("MainWindowClass");
ret = NSERROR_INIT_FAILED;
}
- hInstance = hinstance;
-
return ret;
}
-----------------------------------------------------------------------
Summary of changes:
frontends/windows/download.c | 276 +++++++++++++++++++-------------------
frontends/windows/font.h | 4 +-
frontends/windows/gui.c | 10 +-
frontends/windows/gui.h | 2 +-
frontends/windows/localhistory.c | 43 +++---
frontends/windows/main.c | 3 +
frontends/windows/window.c | 198 +++++++++++++++++----------
7 files changed, 310 insertions(+), 226 deletions(-)
diff --git a/frontends/windows/download.c b/frontends/windows/download.c
index fff47ac..3a96983 100644
--- a/frontends/windows/download.c
+++ b/frontends/windows/download.c
@@ -16,6 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * windows frontend download implementation
+ *
+ * \todo The windows download functionality is very buggy this needs redoing
+ */
+
#include <limits.h>
#include "utils/inet.h" /* get correct winsock ordering */
#include <shlobj.h>
@@ -48,30 +55,139 @@ struct gui_download_window {
char *original_total_size;
int size;
int downloaded;
- unsigned int progress;
+ unsigned int progress;
int time_remaining;
struct timeval start_time;
int speed;
int error;
- struct gui_window *window;
+ struct gui_window *window;
FILE *file;
- download_status status;
+ download_status status;
};
static bool downloading = false;
static struct gui_download_window *download1;
-BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam,
- LPARAM lparam);
-static void nsws_download_update_label(void *p);
-static void nsws_download_update_progress(void *p);
-static void nsws_download_clear_data(struct gui_download_window *w);
+
+static void nsws_download_update_label(void *p)
+{
+ struct gui_download_window *w = p;
+ if (w->hwnd == NULL) {
+ win32_schedule(-1, nsws_download_update_label, p);
+ return;
+ }
+ HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_LABEL);
+ char *size = human_friendly_bytesize(w->downloaded);
+ int i = 0, temp = w->time_remaining;
+ if (temp == -1) {
+ w->time_left = strdup(messages_get("UnknownSize"));
+ i = strlen(w->time_left);
+ } else {
+ do {
+ temp = temp / 10;
+ i++;
+ } while (temp > 2);
+ w->time_left = malloc(i + SLEN(" s") + 1);
+ if (w->time_left != NULL) {
+ if (w->time_remaining > 3600)
+ sprintf(w->time_left, "%d h",
+ w->time_remaining / 3600);
+ else if (w->time_remaining > 60)
+ sprintf(w->time_left, "%d m",
+ w->time_remaining / 60);
+ else
+ sprintf(w->time_left, "%d s",
+ w->time_remaining);
+ }
+ }
+ char label[strlen(w->title) + strlen(size) + strlen(w->total_size) +
+ + strlen(w->domain) + strlen(w->filename) +
+ SLEN("download from to \n[\t/\t]\n estimate of time"
+ " remaining ") + i + 1];
+ sprintf(label, "download %s from %s to %s\n[%s\t/\t%s] [%d%%]\n"
+ "estimate of time remaining %s", w->title, w->domain,
+ w->filename, size, w->total_size, w->progress / 100,
+ w->time_left);
+ if (w->time_left != NULL) {
+ free(w->time_left);
+ w->time_left = NULL;
+ }
+ SendMessage(sub, WM_SETTEXT, (WPARAM)0, (LPARAM)label);
+ if (w->progress < 10000) {
+ win32_schedule(500, nsws_download_update_label, p);
+ }
+}
+
+
+static void nsws_download_update_progress(void *p)
+{
+ struct gui_download_window *w = p;
+ if (w->hwnd == NULL) {
+ win32_schedule(-1, nsws_download_update_progress, p);
+ return;
+ }
+ HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_PROGRESS);
+ SendMessage(sub, PBM_SETPOS, (WPARAM)(w->progress / 100), 0);
+ if (w->progress < 10000) {
+ win32_schedule(500, nsws_download_update_progress, p);
+ }
+}
+
+
+static void nsws_download_clear_data(struct gui_download_window *w)
+{
+ if (w == NULL)
+ return;
+ if (w->title != NULL)
+ free(w->title);
+ if (w->filename != NULL)
+ free(w->filename);
+ if (w->domain != NULL)
+ free(w->domain);
+ if (w->time_left != NULL)
+ free(w->time_left);
+ if (w->total_size != NULL)
+ free(w->total_size);
+ if (w->file != NULL)
+ fclose(w->file);
+ win32_schedule(-1, nsws_download_update_progress, (void *)w);
+ win32_schedule(-1, nsws_download_update_label, (void *)w);
+}
+
+
+static BOOL CALLBACK
+nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ switch(msg) {
+ case WM_INITDIALOG:
+ nsws_download_update_label((void *)download1);
+ nsws_download_update_progress((void *)download1);
+ return TRUE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wparam)) {
+ case IDOK:
+ if (download1->downloaded != download1->size)
+ return TRUE;
+
+ case IDCANCEL:
+ nsws_download_clear_data(download1);
+ download1 = NULL;
+ downloading = false;
+ EndDialog(hwnd, IDCANCEL);
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
static bool nsws_download_window_up(struct gui_download_window *w)
{
- w->hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_DOWNLOAD),
- gui_window_main_window(w->window),
- nsws_download_event_callback);
+ w->hwnd = CreateDialog(hinst,
+ MAKEINTRESOURCE(IDD_DLG_DOWNLOAD),
+ gui_window_main_window(w->window),
+ nsws_download_event_callback);
if (w->hwnd == NULL) {
return false;
}
@@ -79,6 +195,7 @@ static bool nsws_download_window_up(struct gui_download_window *w)
return true;
}
+
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *gui)
{
@@ -88,8 +205,8 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
return NULL;
}
downloading = true;
- struct gui_download_window *w =
- malloc(sizeof(struct gui_download_window));
+ struct gui_download_window *w =
+ malloc(sizeof(struct gui_download_window));
if (w == NULL) {
win32_warning(messages_get("NoMemory"), 0);
return NULL;
@@ -98,10 +215,10 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
char *domain, *filename, *destination;
nsurl *url = download_context_get_url(ctx);
bool unknown_size = (total_size == 0);
- const char *size = (unknown_size) ?
- messages_get("UnknownSize") :
- human_friendly_bytesize(total_size);
-
+ const char *size = (unknown_size) ?
+ messages_get("UnknownSize") :
+ human_friendly_bytesize(total_size);
+
if (nsurl_nice(url, &filename, false) != NSERROR_OK) {
filename = strdup(messages_get("UnknownFile"));
}
@@ -186,119 +303,9 @@ gui_download_window_create(download_context *ctx, struct gui_window *gui)
}
-BOOL CALLBACK nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam,
- LPARAM lparam)
-{
- switch(msg) {
- case WM_INITDIALOG:
- nsws_download_update_label((void *)download1);
- nsws_download_update_progress((void *)download1);
- return TRUE;
-
- case WM_COMMAND:
- switch(LOWORD(wparam)) {
- case IDOK:
- if (download1->downloaded != download1->size)
- return TRUE;
-
- case IDCANCEL:
- nsws_download_clear_data(download1);
- download1 = NULL;
- downloading = false;
- EndDialog(hwnd, IDCANCEL);
- return FALSE;
- }
- }
- return FALSE;
-}
-
-void nsws_download_update_label(void *p)
-{
- struct gui_download_window *w = p;
- if (w->hwnd == NULL) {
- win32_schedule(-1, nsws_download_update_label, p);
- return;
- }
- HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_LABEL);
- char *size = human_friendly_bytesize(w->downloaded);
- int i = 0, temp = w->time_remaining;
- if (temp == -1) {
- w->time_left = strdup(messages_get("UnknownSize"));
- i = strlen(w->time_left);
- } else {
- do {
- temp = temp / 10;
- i++;
- } while (temp > 2);
- w->time_left = malloc(i + SLEN(" s") + 1);
- if (w->time_left != NULL) {
- if (w->time_remaining > 3600)
- sprintf(w->time_left, "%d h",
- w->time_remaining / 3600);
- else if (w->time_remaining > 60)
- sprintf(w->time_left, "%d m",
- w->time_remaining / 60);
- else
- sprintf(w->time_left, "%d s",
- w->time_remaining);
- }
- }
- char label[strlen(w->title) + strlen(size) + strlen(w->total_size) +
- + strlen(w->domain) + strlen(w->filename) +
- SLEN("download from to \n[\t/\t]\n estimate of time"
- " remaining ") + i + 1];
- sprintf(label, "download %s from %s to %s\n[%s\t/\t%s] [%d%%]\n"
- "estimate of time remaining %s", w->title, w->domain,
- w->filename, size, w->total_size, w->progress / 100,
- w->time_left);
- if (w->time_left != NULL) {
- free(w->time_left);
- w->time_left = NULL;
- }
- SendMessage(sub, WM_SETTEXT, (WPARAM)0, (LPARAM)label);
- if (w->progress < 10000) {
- win32_schedule(500, nsws_download_update_label, p);
- }
-}
-
-void nsws_download_update_progress(void *p)
-{
- struct gui_download_window *w = p;
- if (w->hwnd == NULL) {
- win32_schedule(-1, nsws_download_update_progress, p);
- return;
- }
- HWND sub = GetDlgItem(w->hwnd, IDC_DOWNLOAD_PROGRESS);
- SendMessage(sub, PBM_SETPOS, (WPARAM)(w->progress / 100), 0);
- if (w->progress < 10000) {
- win32_schedule(500, nsws_download_update_progress, p);
- }
-}
-
-void nsws_download_clear_data(struct gui_download_window *w)
-{
- if (w == NULL)
- return;
- if (w->title != NULL)
- free(w->title);
- if (w->filename != NULL)
- free(w->filename);
- if (w->domain != NULL)
- free(w->domain);
- if (w->time_left != NULL)
- free(w->time_left);
- if (w->total_size != NULL)
- free(w->total_size);
- if (w->file != NULL)
- fclose(w->file);
- win32_schedule(-1, nsws_download_update_progress, (void *)w);
- win32_schedule(-1, nsws_download_update_label, (void *)w);
-}
-
-
-static nserror
+static nserror
gui_download_window_data(struct gui_download_window *w, const char *data,
- unsigned int size)
+ unsigned int size)
{
if ((w == NULL) || (w->file == NULL))
return NSERROR_SAVE_FAILED;
@@ -309,16 +316,16 @@ gui_download_window_data(struct gui_download_window *w, const char *data,
LOG("file write error %d of %d", size - res, size);
w->downloaded += res;
w->progress = (unsigned int)(((long long)(w->downloaded) * 10000)
- / w->size);
+ / w->size);
gettimeofday(&val, NULL);
- w->time_remaining = (w->progress == 0) ? -1 :
- (int)((val.tv_sec - w->start_time.tv_sec) *
- (10000 - w->progress) / w->progress);
+ w->time_remaining = (w->progress == 0) ? -1 :
+ (int)((val.tv_sec - w->start_time.tv_sec) *
+ (10000 - w->progress) / w->progress);
return NSERROR_OK;
}
static void gui_download_window_error(struct gui_download_window *w,
- const char *error_msg)
+ const char *error_msg)
{
LOG("error %s", error_msg);
}
@@ -341,4 +348,3 @@ static struct gui_download_table download_table = {
};
struct gui_download_table *win32_download_table = &download_table;
-
diff --git a/frontends/windows/font.h b/frontends/windows/font.h
index f2128af..0e86755 100644
--- a/frontends/windows/font.h
+++ b/frontends/windows/font.h
@@ -22,8 +22,8 @@
* The interface to the win32 font and utf8 handling.
*/
-#ifndef _NETSURF_WINDOWS_FONT_H_
-#define _NETSURF_WINDOWS_FONT_H_
+#ifndef NETSURF_WINDOWS_FONT_H
+#define NETSURF_WINDOWS_FONT_H
extern HWND font_hwnd;
diff --git a/frontends/windows/gui.c b/frontends/windows/gui.c
index 0ab1e32..043a93d 100644
--- a/frontends/windows/gui.c
+++ b/frontends/windows/gui.c
@@ -39,10 +39,14 @@
#include "windows/filetype.h"
#include "windows/gui.h"
-static bool win32_quit = false;
-
-HINSTANCE hInstance; /** win32 application instance handle. */
+/**
+ * win32 application instance handle.
+ *
+ * This handle is set in the main windows entry point.
+ */
+HINSTANCE hinst;
+static bool win32_quit = false;
void win32_set_quit(bool q)
{
diff --git a/frontends/windows/gui.h b/frontends/windows/gui.h
index 8dd2ded..efbf029 100644
--- a/frontends/windows/gui.h
+++ b/frontends/windows/gui.h
@@ -23,7 +23,7 @@
struct gui_window;
struct gui_clipboard_table *win32_clipboard_table;
-extern HINSTANCE hInstance;
+extern HINSTANCE hinst;
/** Directory where all configuration files are held. */
extern char *nsw32_config_home;
diff --git a/frontends/windows/localhistory.c b/frontends/windows/localhistory.c
index ce1877f..15705d1 100644
--- a/frontends/windows/localhistory.c
+++ b/frontends/windows/localhistory.c
@@ -48,7 +48,9 @@ struct nsws_localhistory {
};
-static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct gui_window *gw)
+static void
+nsws_localhistory_scroll_check(struct nsws_localhistory *l,
+ struct gui_window *gw)
{
SCROLLINFO si;
@@ -76,8 +78,8 @@ static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct g
}
-
-static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw)
+static void
+nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw)
{
HDC tmp_hdc;
struct redraw_context ctx = {
@@ -114,6 +116,7 @@ void nsws_localhistory_close(struct gui_window *w)
CloseWindow(l->hwnd);
}
+
static LRESULT CALLBACK
nsws_localhistory_event_callback(HWND hwnd, UINT msg,
WPARAM wparam, LPARAM lparam)
@@ -297,6 +300,7 @@ nsws_localhistory_event_callback(HWND hwnd, UINT msg,
return 0;
}
+
/* exported method documented in windows/localhistory.h */
struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
{
@@ -347,23 +351,31 @@ struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
#endif
InitCommonControlsEx(&icc);
-
- LOG("creating local history window for hInstance %p", hInstance);
+ LOG("creating local history window for hInstance %p", hinst);
localhistory->hwnd = CreateWindow(windowclassname_localhistory,
- "NetSurf History",
- WS_THICKFRAME | WS_HSCROLL |
- WS_VSCROLL | WS_CLIPCHILDREN |
- WS_CLIPSIBLINGS | WS_SYSMENU | CS_DBLCLKS,
- r.left + margin/2,
- r.top + margin/2,
- localhistory->guiwidth,
- localhistory->guiheight,
- NULL, NULL, hInstance, NULL);
+ "NetSurf History",
+ WS_THICKFRAME |
+ WS_HSCROLL |
+ WS_VSCROLL |
+ WS_CLIPCHILDREN |
+ WS_CLIPSIBLINGS |
+ WS_SYSMENU |
+ CS_DBLCLKS,
+ r.left + margin/2,
+ r.top + margin/2,
+ localhistory->guiwidth,
+ localhistory->guiheight,
+ NULL,
+ NULL,
+ hinst,
+ NULL);
/* set the gui window associated with this browser */
SetProp(localhistory->hwnd, TEXT("GuiWnd"), (HANDLE)gw);
- LOG("gui_window %p width %d height %d hwnd %p", gw, localhistory->guiwidth, localhistory->guiheight, localhistory->hwnd);
+ LOG("gui_window %p width %d height %d hwnd %p",
+ gw, localhistory->guiwidth, localhistory->guiheight,
+ localhistory->hwnd);
nsws_localhistory_up(localhistory, gw);
UpdateWindow(localhistory->hwnd);
@@ -372,6 +384,7 @@ struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw)
return localhistory;
}
+
/* exported method documented in windows/localhistory.h */
nserror
nsws_create_localhistory_class(HINSTANCE hinstance) {
diff --git a/frontends/windows/main.c b/frontends/windows/main.c
index 7b93c3b..7c94c06 100644
--- a/frontends/windows/main.c
+++ b/frontends/windows/main.c
@@ -303,6 +303,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
die("NetSurf operation table registration failed");
}
+ /* Save the application-instance handle. */
+ hinst = hInstance;
+
setbuf(stderr, NULL);
/* Construct a unix style argc/argv */
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index cc29d19..b8c2b39 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -61,6 +61,9 @@ static const char windowclassname_main[] = "nswsmainwindow";
/** width of the throbber element */
#define NSWS_THROBBER_WIDTH 24
+/** height of the url entry box */
+#define NSWS_URLBAR_HEIGHT 23
+
/** Number of open windows */
static int open_windows = 0;
@@ -138,16 +141,15 @@ static void nsws_window_set_accels(struct gui_window *w)
/**
* creation of a new full browser window
*
+ * \param hInstance The application instance handle.
* \param gw gui window context.
* \return The newly created window instance.
*/
-static HWND nsws_window_create(struct gui_window *gw)
+static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw)
{
HWND hwnd;
INITCOMMONCONTROLSEX icc;
- LOG("GUI window %p", gw);
-
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES;
#if WINVER > 0x0501
@@ -158,11 +160,14 @@ static HWND nsws_window_create(struct gui_window *gw)
gw->mainmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN));
gw->rclick = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT));
- LOG("creating window for hInstance %p", hInstance);
+ LOG("creating hInstance %p GUI window %p", hInstance, gw);
hwnd = CreateWindowEx(0,
windowclassname_main,
"NetSurf Browser",
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_DBLCLKS,
+ WS_OVERLAPPEDWINDOW |
+ WS_CLIPCHILDREN |
+ WS_CLIPSIBLINGS |
+ CS_DBLCLKS,
CW_USEDEFAULT,
CW_USEDEFAULT,
gw->width,
@@ -186,10 +191,14 @@ static HWND nsws_window_create(struct gui_window *gw)
(nsoption_int(window_height) >= 100) &&
(nsoption_int(window_x) >= 0) &&
(nsoption_int(window_y) >= 0)) {
- LOG("Setting Window position %d,%d %d,%d", nsoption_int(window_x), nsoption_int(window_y), nsoption_int(window_width), nsoption_int(window_height));
+ LOG("Setting Window position %d,%d %d,%d",
+ nsoption_int(window_x), nsoption_int(window_y),
+ nsoption_int(window_width), nsoption_int(window_height));
SetWindowPos(hwnd, HWND_TOP,
- nsoption_int(window_x), nsoption_int(window_y),
- nsoption_int(window_width), nsoption_int(window_height),
+ nsoption_int(window_x),
+ nsoption_int(window_y),
+ nsoption_int(window_width),
+ nsoption_int(window_height),
SWP_SHOWWINDOW);
}
@@ -289,7 +298,7 @@ urlbar_dimensions(HWND hWndParent,
int *height)
{
RECT rc;
- const int cy_edit = 23;
+ const int cy_edit = NSWS_URLBAR_HEIGHT;
GetClientRect(hWndParent, &rc);
*x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
@@ -338,8 +347,10 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
/* move throbber */
if (gw->throbber != NULL) {
MoveWindow(gw->throbber,
- LOWORD(lparam) - NSWS_THROBBER_WIDTH - 4, 8,
- NSWS_THROBBER_WIDTH, NSWS_THROBBER_WIDTH,
+ LOWORD(lparam) - NSWS_THROBBER_WIDTH - 4,
+ urly,
+ NSWS_THROBBER_WIDTH,
+ NSWS_THROBBER_WIDTH,
true);
}
break;
@@ -434,12 +445,15 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
*
* Create an Edit control for enerting urls
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
- * \param hWndParent The main containing window.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
+nsws_window_urlbar_create(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
int urlx, urly, urlwidth, urlheight;
HWND hwnd;
@@ -499,23 +513,33 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
/**
* creation of throbber
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_throbber_create(struct gui_window *gw)
+nsws_window_throbber_create(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
HWND hwnd;
char avi[PATH_MAX];
+ int urlx, urly, urlwidth, urlheight;
+
+ urlbar_dimensions(hWndParent,
+ gw->toolbuttonsize,
+ gw->toolbuttonc,
+ &urlx, &urly, &urlwidth, &urlheight);
hwnd = CreateWindow(ANIMATE_CLASS,
"",
WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT,
gw->width - NSWS_THROBBER_WIDTH - 4,
- 8,
+ urly,
NSWS_THROBBER_WIDTH,
NSWS_THROBBER_WIDTH,
- gw->main,
+ hWndParent,
(HMENU) IDC_MAIN_THROBBER,
hInstance,
NULL);
@@ -537,27 +561,33 @@ nsws_window_throbber_create(struct gui_window *gw)
/**
* create a win32 image list for the toolbar.
*
+ * \param hInstance The application instance handle.
* \param resid The resource ID of the image.
* \param bsize The size of the image to load.
* \param bcnt The number of bitmaps to load into the list.
* \return The image list or NULL on error.
*/
static HIMAGELIST
-get_imagelist(int resid, int bsize, int bcnt)
+get_imagelist(HINSTANCE hInstance, int resid, int bsize, int bcnt)
{
HIMAGELIST hImageList;
HBITMAP hScrBM;
LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
- hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
+ hImageList = ImageList_Create(bsize, bsize,
+ ILC_COLOR24 | ILC_MASK, 0,
bcnt);
- if (hImageList == NULL)
+ if (hImageList == NULL) {
return NULL;
+ }
- hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
- IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
-
+ hScrBM = LoadImage(hInstance,
+ MAKEINTRESOURCE(resid),
+ IMAGE_BITMAP,
+ 0,
+ 0,
+ LR_DEFAULTCOLOR);
if (hScrBM == NULL) {
win_perror("LoadImage");
return NULL;
@@ -577,12 +607,18 @@ get_imagelist(int resid, int bsize, int bcnt)
/**
* create win32 main window toolbar and add controls and message handler
*
+ * Toolbar has buttons on the left, url entry space in the middle and
+ * activity throbber on the right.
+ *
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
- * \param hWndParent The main containing window.
* \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
+nsws_window_create_toolbar(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
HIMAGELIST hImageList;
HWND hWndToolbar;
@@ -597,10 +633,15 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
WNDPROC toolproc;
/* Create the toolbar window and subclass its message handler. */
- hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, "Toolbar",
+ hWndToolbar = CreateWindowEx(0,
+ TOOLBARCLASSNAME,
+ "Toolbar",
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT,
0, 0, 0, 0,
- hWndParent, NULL, HINST_COMMCTRL, NULL);
+ hWndParent,
+ NULL,
+ HINST_COMMCTRL,
+ NULL);
if (!hWndToolbar) {
return NULL;
}
@@ -620,28 +661,38 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
gw->toolbuttonc = sizeof(tbButtons) / sizeof(TBBUTTON);
/* Create the standard image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);
+ SendMessage(hWndToolbar,
+ TB_SETIMAGELIST,
+ 0,
+ (LPARAM)hImageList);
}
/* Create the disabled image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_GREY,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP_GREY,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETDISABLEDIMAGELIST, 0,
+ SendMessage(hWndToolbar,
+ TB_SETDISABLEDIMAGELIST,
+ 0,
(LPARAM)hImageList);
}
/* Create the hot image list and assign to toolbar. */
- hImageList = get_imagelist(IDR_TOOLBAR_BITMAP_HOT,
+ hImageList = get_imagelist(hInstance,
+ IDR_TOOLBAR_BITMAP_HOT,
gw->toolbuttonsize,
gw->toolbuttonc);
if (hImageList != NULL) {
- SendMessage(hWndToolbar, TB_SETHOTIMAGELIST, 0,
+ SendMessage(hWndToolbar,
+ TB_SETHOTIMAGELIST,
+ 0,
(LPARAM)hImageList);
}
@@ -655,9 +706,9 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
(WPARAM)gw->toolbuttonc,
(LPARAM)&tbButtons);
- gw->urlbar = nsws_window_urlbar_create(gw, hWndToolbar);
+ gw->urlbar = nsws_window_urlbar_create(hInstance, hWndToolbar, gw);
- gw->throbber = nsws_window_throbber_create(gw);
+ gw->throbber = nsws_window_throbber_create(hInstance, hWndToolbar, gw);
return hWndToolbar;
}
@@ -666,20 +717,28 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
/**
* creation of status bar
*
+ * \param hInstance The application instance handle.
+ * \param hWndParent The containing window.
* \param gw win32 frontends window context.
*/
-static HWND nsws_window_create_statusbar(struct gui_window *gw)
+static HWND
+nsws_window_create_statusbar(HINSTANCE hInstance,
+ HWND hWndParent,
+ struct gui_window *gw)
{
- HWND hwnd = CreateWindowEx(0,
- STATUSCLASSNAME,
- NULL,
- WS_CHILD | WS_VISIBLE,
- 0, 0, 0, 0,
- gw->main,
- (HMENU)IDC_MAIN_STATUSBAR,
- hInstance,
- NULL);
- SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf");
+ HWND hwnd;
+ hwnd = CreateWindowEx(0,
+ STATUSCLASSNAME,
+ NULL,
+ WS_CHILD | WS_VISIBLE,
+ 0, 0, 0, 0,
+ hWndParent,
+ (HMENU)IDC_MAIN_STATUSBAR,
+ hInstance,
+ NULL);
+ if (hwnd != NULL) {
+ SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf");
+ }
return hwnd;
}
@@ -1020,7 +1079,7 @@ nsws_window_command(HWND hwnd,
break;
case IDM_EDIT_PREFERENCES:
- nsws_prefs_dialog_init(hInstance, gw->main);
+ nsws_prefs_dialog_init(hinst, gw->main);
break;
case IDM_NAV_BACK:
@@ -1172,7 +1231,7 @@ nsws_window_command(HWND hwnd,
break;
case IDM_HELP_ABOUT:
- nsws_about_dialog_init(hInstance, gw->main);
+ nsws_about_dialog_init(hinst, gw->main);
break;
case IDC_MAIN_LAUNCH_URL:
@@ -1409,10 +1468,10 @@ win32_window_create(struct browser_window *bw,
gw->next = window_list;
window_list = gw;
- gw->main = nsws_window_create(gw);
- gw->toolbar = nsws_window_create_toolbar(gw, gw->main);
- gw->statusbar = nsws_window_create_statusbar(gw);
- gw->drawingarea = nsws_window_create_drawable(hInstance, gw->main, gw);
+ gw->main = nsws_window_create(hinst, gw);
+ gw->toolbar = nsws_window_create_toolbar(hinst, gw->main, gw);
+ gw->statusbar = nsws_window_create_statusbar(hinst, gw->main, gw);
+ gw->drawingarea = nsws_window_create_drawable(hinst, gw->main, gw);
LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p",
gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
@@ -1860,31 +1919,30 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
/* exported interface documented in windows/window.h */
nserror
-nsws_create_main_class(HINSTANCE hinstance) {
+nsws_create_main_class(HINSTANCE hinstance)
+{
nserror ret = NSERROR_OK;
- WNDCLASSEX w;
+ WNDCLASSEX wc;
/* main window */
- w.cbSize = sizeof(WNDCLASSEX);
- w.style = 0;
- w.lpfnWndProc = nsws_window_event_callback;
- w.cbClsExtra = 0;
- w.cbWndExtra = 0;
- w.hInstance = hinstance;
- w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
- w.hCursor = NULL;
- w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
- w.lpszMenuName = NULL;
- w.lpszClassName = windowclassname_main;
- w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
-
- if (RegisterClassEx(&w) == 0) {
- win_perror("DrawableClass");
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.style = 0;
+ wc.lpfnWndProc = nsws_window_event_callback;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hinstance;
+ wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+ wc.hCursor = NULL;
+ wc.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = windowclassname_main;
+ wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+
+ if (RegisterClassEx(&wc) == 0) {
+ win_perror("MainWindowClass");
ret = NSERROR_INIT_FAILED;
}
- hInstance = hinstance;
-
return ret;
}
--
NetSurf Browser
6 years, 10 months
netsurf: branch master updated. release/3.5-373-g3ecced9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/3ecced92f335f80a372cf...
...commit http://git.netsurf-browser.org/netsurf.git/commit/3ecced92f335f80a372cf3f...
...tree http://git.netsurf-browser.org/netsurf.git/tree/3ecced92f335f80a372cf3fb0...
The branch, master has been updated
via 3ecced92f335f80a372cf3fb0ab1c6f7c564cebb (commit)
from 57715fc70cef09e39b9f8b6277b02304d4281a95 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=3ecced92f335f80a372...
commit 3ecced92f335f80a372cf3fb0ab1c6f7c564cebb
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Complete windows main window documentation
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index 4614c2c..cc29d19 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -67,6 +67,9 @@ static int open_windows = 0;
/**
* Obtain the DPI of the display.
+ *
+ * \param hwnd A win32 window handle to get the DPI for
+ * \return The DPI of the device teh window is displayed on.
*/
static int get_window_dpi(HWND hwnd)
{
@@ -86,7 +89,9 @@ static int get_window_dpi(HWND hwnd)
/**
- * set accelerators
+ * create and attach accelerator table to main window
+ *
+ * \param gw gui window context.
*/
static void nsws_window_set_accels(struct gui_window *w)
{
@@ -132,6 +137,9 @@ static void nsws_window_set_accels(struct gui_window *w)
/**
* creation of a new full browser window
+ *
+ * \param gw gui window context.
+ * \return The newly created window instance.
*/
static HWND nsws_window_create(struct gui_window *gw)
{
@@ -192,29 +200,15 @@ static HWND nsws_window_create(struct gui_window *gw)
/**
- * calculate the dimensions of the url bar relative to the parent toolbar
+ * toolbar command message handler
+ *
+ * \todo This entire command handler appears superfluous.
+ *
+ * \param gw The graphical window context
+ * \param notification_code The notification code of the message
+ * \param identifier The identifier the command was delivered for
+ * \param ctrl_window The controlling window.
*/
-static void
-urlbar_dimensions(HWND hWndParent,
- int toolbuttonsize,
- int buttonc,
- int *x,
- int *y,
- int *width,
- int *height)
-{
- RECT rc;
- const int cy_edit = 23;
-
- GetClientRect(hWndParent, &rc);
- *x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
- *y = ((((rc.bottom - 1) - cy_edit) >> 1) * 2) / 3;
- *width = (rc.right - 1) - *x - (NSWS_THROBBER_WIDTH>>1) - NSWS_THROBBER_WIDTH;
- *height = cy_edit;
-}
-
-
-
static LRESULT
nsws_window_toolbar_command(struct gui_window *gw,
int notification_code,
@@ -275,7 +269,45 @@ nsws_window_toolbar_command(struct gui_window *gw,
/**
+ * calculate the dimensions of the url bar relative to the parent toolbar
+ *
+ * \param hWndParent The parent window of the url bar
+ * \param toolbuttonsize size of the buttons
+ * \param buttonc The number of buttons
+ * \param[out] x The calculated x location
+ * \param[out] y The calculated y location
+ * \param[out] width The calculated width
+ * \param[out] height The calculated height
+ */
+static void
+urlbar_dimensions(HWND hWndParent,
+ int toolbuttonsize,
+ int buttonc,
+ int *x,
+ int *y,
+ int *width,
+ int *height)
+{
+ RECT rc;
+ const int cy_edit = 23;
+
+ GetClientRect(hWndParent, &rc);
+ *x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
+ *y = ((((rc.bottom - 1) - cy_edit) >> 1) * 2) / 3;
+ *width = (rc.right - 1) - *x - (NSWS_THROBBER_WIDTH>>1) - NSWS_THROBBER_WIDTH;
+ *height = cy_edit;
+}
+
+
+/**
* callback for toolbar events
+ *
+ * message handler for toolbar window
+ *
+ * \param hwnd win32 window handle message arrived for
+ * \param msg The message ID
+ * \param wparam The w parameter of the message.
+ * \param lparam The l parameter of the message.
*/
static LRESULT CALLBACK
nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -340,40 +372,15 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-static HIMAGELIST
-get_imagelist(int resid, int bsize, int bcnt)
-{
- HIMAGELIST hImageList;
- HBITMAP hScrBM;
-
- LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
-
- hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
- bcnt);
- if (hImageList == NULL)
- return NULL;
-
- hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
- IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
-
- if (hScrBM == NULL) {
- win_perror("LoadImage");
- return NULL;
- }
-
- if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) {
- /* failed to add masked bitmap */
- ImageList_Destroy(hImageList);
- hImageList = NULL;
- }
- DeleteObject(hScrBM);
-
- return hImageList;
-}
-
-
/**
* callback for url bar events
+ *
+ * message handler for urlbar window
+ *
+ * \param hwnd win32 window handle message arrived for
+ * \param msg The message ID
+ * \param wparam The w parameter of the message.
+ * \param lparam The l parameter of the message.
*/
static LRESULT CALLBACK
nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -426,16 +433,20 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
* create a urlbar and message handler
*
* Create an Edit control for enerting urls
+ *
+ * \param gw win32 frontends window context.
+ * \param hWndParent The main containing window.
+ * \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
+nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
{
int urlx, urly, urlwidth, urlheight;
HWND hwnd;
WNDPROC urlproc;
HFONT hFont;
- urlbar_dimensions(hwndparent,
+ urlbar_dimensions(hWndParent,
gw->toolbuttonsize,
gw->toolbuttonc,
&urlx, &urly, &urlwidth, &urlheight);
@@ -449,7 +460,7 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
urly,
urlwidth,
urlheight,
- hwndparent,
+ hWndParent,
(HMENU)IDC_MAIN_URLBAR,
hInstance,
0);
@@ -463,19 +474,23 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
/* subclass the message handler */
urlproc = (WNDPROC)SetWindowLongPtr(hwnd,
- GWLP_WNDPROC,
- (LONG_PTR)nsws_window_urlbar_callback);
+ GWLP_WNDPROC,
+ (LONG_PTR)nsws_window_urlbar_callback);
/* save the real handler */
SetProp(hwnd, TEXT("OrigMsgProc"), (HANDLE)urlproc);
- hFont = CreateFont(urlheight - 4, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
+ hFont = CreateFont(urlheight - 4, 0, 0, 0, FW_BOLD, FALSE, FALSE,
+ FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_SWISS, "Arial");
if (hFont != NULL) {
LOG("Setting font object");
SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0);
}
- LOG("Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d", hwnd, urlx, urly, urlwidth, urlheight);
+ LOG("Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d",
+ hwnd, urlx, urly, urlwidth, urlheight);
return hwnd;
}
@@ -483,9 +498,12 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
/**
* creation of throbber
+ *
+ * \param gw win32 frontends window context.
+ * \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_throbber_create(struct gui_window *w)
+nsws_window_throbber_create(struct gui_window *gw)
{
HWND hwnd;
char avi[PATH_MAX];
@@ -493,11 +511,11 @@ nsws_window_throbber_create(struct gui_window *w)
hwnd = CreateWindow(ANIMATE_CLASS,
"",
WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT,
- w->width - NSWS_THROBBER_WIDTH - 4,
+ gw->width - NSWS_THROBBER_WIDTH - 4,
8,
NSWS_THROBBER_WIDTH,
NSWS_THROBBER_WIDTH,
- w->main,
+ gw->main,
(HMENU) IDC_MAIN_THROBBER,
hInstance,
NULL);
@@ -505,16 +523,64 @@ nsws_window_throbber_create(struct gui_window *w)
nsws_find_resource(avi, "throbber.avi", "windows/res/throbber.avi");
LOG("setting throbber avi as %s", avi);
Animate_Open(hwnd, avi);
- if (w->throbbing)
+ if (gw->throbbing) {
Animate_Play(hwnd, 0, -1, -1);
- else
+ } else {
Animate_Seek(hwnd, 0);
+ }
ShowWindow(hwnd, SW_SHOWNORMAL);
+
return hwnd;
}
-/* create a toolbar add controls and message handler */
+/**
+ * create a win32 image list for the toolbar.
+ *
+ * \param resid The resource ID of the image.
+ * \param bsize The size of the image to load.
+ * \param bcnt The number of bitmaps to load into the list.
+ * \return The image list or NULL on error.
+ */
+static HIMAGELIST
+get_imagelist(int resid, int bsize, int bcnt)
+{
+ HIMAGELIST hImageList;
+ HBITMAP hScrBM;
+
+ LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
+
+ hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
+ bcnt);
+ if (hImageList == NULL)
+ return NULL;
+
+ hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
+ IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
+
+ if (hScrBM == NULL) {
+ win_perror("LoadImage");
+ return NULL;
+ }
+
+ if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) {
+ /* failed to add masked bitmap */
+ ImageList_Destroy(hImageList);
+ hImageList = NULL;
+ }
+ DeleteObject(hScrBM);
+
+ return hImageList;
+}
+
+
+/**
+ * create win32 main window toolbar and add controls and message handler
+ *
+ * \param gw win32 frontends window context.
+ * \param hWndParent The main containing window.
+ * \return win32 window handle of created window or NULL on error.
+ */
static HWND
nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
{
@@ -599,15 +665,17 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
/**
* creation of status bar
+ *
+ * \param gw win32 frontends window context.
*/
-static HWND nsws_window_create_statusbar(struct gui_window *w)
+static HWND nsws_window_create_statusbar(struct gui_window *gw)
{
HWND hwnd = CreateWindowEx(0,
STATUSCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
- w->main,
+ gw->main,
(HMENU)IDC_MAIN_STATUSBAR,
hInstance,
NULL);
@@ -616,12 +684,18 @@ static HWND nsws_window_create_statusbar(struct gui_window *w)
}
+/**
+ * Update popup context menu editing functionality
+ *
+ * \param w win32 frontends window context.
+ */
static void nsws_update_edit(struct gui_window *w)
{
browser_editor_flags editor_flags = (w->bw == NULL) ?
BW_EDITOR_NONE : browser_window_get_editor_flags(w->bw);
bool paste, copy, del;
bool sel = (editor_flags & BW_EDITOR_CAN_COPY);
+
if (GetFocus() == w->urlbar) {
DWORD i, ii;
SendMessage(w->urlbar, EM_GETSEL, (WPARAM)&i, (LPARAM)&ii);
@@ -629,7 +703,7 @@ static void nsws_update_edit(struct gui_window *w)
copy = (i != ii);
del = (i != ii);
- } else if (sel){
+ } else if (sel) {
paste = (editor_flags & BW_EDITOR_CAN_PASTE);
copy = sel;
del = (editor_flags & BW_EDITOR_CAN_CUT);
@@ -668,6 +742,14 @@ static void nsws_update_edit(struct gui_window *w)
}
+/**
+ * Handle win32 context menu message
+ *
+ * \param gw win32 frontends graphical window.
+ * \param hwnd The win32 window handle
+ * \param int x The x coordinate of the event.
+ * \param y the y cooordiante of the event.
+ */
static bool
nsws_ctx_menu(struct gui_window *w, HWND hwnd, int x, int y)
{
@@ -702,6 +784,8 @@ nsws_ctx_menu(struct gui_window *w, HWND hwnd, int x, int y)
/**
* update state of forward/back buttons/menu items when page changes
+ *
+ * \param w win32 frontends graphical window.
*/
static void nsws_window_update_forward_back(struct gui_window *w)
{
@@ -735,37 +819,10 @@ static void nsws_window_update_forward_back(struct gui_window *w)
}
-static bool win32_window_get_scroll(struct gui_window *w, int *sx, int *sy)
-{
- LOG("get scroll");
- if (w == NULL)
- return false;
-
- *sx = w->scrollx;
- *sy = w->scrolly;
-
- return true;
-}
-
-
-static void nsws_set_scale(struct gui_window *gw, float scale)
-{
- assert(gw != NULL);
-
- if (gw->scale == scale)
- return;
-
- gw->scale = scale;
-
- if (gw->bw == NULL)
- return;
-
- browser_window_set_scale(gw->bw, scale, true);
-}
-
-
/**
* redraw the whole window
+ *
+ * \param gw win32 frontends graphical window.
*/
static void win32_window_redraw_window(struct gui_window *gw)
{
@@ -778,90 +835,32 @@ static void win32_window_redraw_window(struct gui_window *gw)
/**
- * scroll the window
+ * Set scale of a win32 browser window
*
- * \param w The win32 gui window to scroll.
- * \param sx the new 'absolute' horizontal scroll location
- * \param sy the new 'absolute' vertical scroll location
+ * \param gw win32 frontend window context
+ * \param scale The new scale
*/
-void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
+static void nsws_set_scale(struct gui_window *gw, float scale)
{
- SCROLLINFO si;
- nserror err;
- int height;
- int width;
- POINT p;
+ int x, y;
- if ((w == NULL) || (w->bw == NULL))
- return;
+ assert(gw != NULL);
- err = browser_window_get_extents(w->bw, true, &width, &height);
- if (err != NSERROR_OK) {
+ if (gw->scale == scale) {
return;
}
- /*LOG("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height);*/
+ x = gw->scrollx;
+ y = gw->scrolly;
- /* The resulting gui window scroll must remain withn the
- * windows bounding box.
- */
- if (sx < 0) {
- w->requestscrollx = -w->scrollx;
- } else if (sx > (width - w->width)) {
- w->requestscrollx = (width - w->width) - w->scrollx;
- } else {
- w->requestscrollx = sx - w->scrollx;
- }
- if (sy < 0) {
- w->requestscrolly = -w->scrolly;
- } else if (sy > (height - w->height)) {
- w->requestscrolly = (height - w->height) - w->scrolly;
- } else {
- w->requestscrolly = sy - w->scrolly;
- }
-
- /*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/
-
- /* set the vertical scroll offset */
- si.cbSize = sizeof(si);
- si.fMask = SIF_ALL;
- si.nMin = 0;
- si.nMax = height - 1;
- si.nPage = w->height;
- si.nPos = max(w->scrolly + w->requestscrolly, 0);
- si.nPos = min(si.nPos, height - w->height);
- SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE);
- /*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
-
- /* set the horizontal scroll offset */
- si.cbSize = sizeof(si);
- si.fMask = SIF_ALL;
- si.nMin = 0;
- si.nMax = width -1;
- si.nPage = w->width;
- si.nPos = max(w->scrollx + w->requestscrollx, 0);
- si.nPos = min(si.nPos, width - w->width);
- SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE);
- /*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
-
- /* Set caret position */
- GetCaretPos(&p);
- HideCaret(w->drawingarea);
- SetCaretPos(p.x - w->requestscrollx, p.y - w->requestscrolly);
- ShowCaret(w->drawingarea);
+ gw->scale = scale;
- RECT r, redraw;
- r.top = 0;
- r.bottom = w->height + 1;
- r.left = 0;
- r.right = w->width + 1;
- ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
- /*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/
- w->scrolly += w->requestscrolly;
- w->scrollx += w->requestscrollx;
- w->requestscrollx = 0;
- w->requestscrolly = 0;
+ if (gw->bw != NULL) {
+ browser_window_set_scale(gw->bw, scale, true);
+ }
+ win32_window_redraw_window(gw);
+ win32_window_set_scroll(gw, x, y);
}
@@ -1074,38 +1073,17 @@ nsws_window_command(HWND hwnd,
case IDM_NAV_GLOBALHISTORY:
break;
- case IDM_VIEW_ZOOMPLUS: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, gw->scale * 1.1);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMPLUS:
+ nsws_set_scale(gw, gw->scale * 1.1);
break;
- }
- case IDM_VIEW_ZOOMMINUS: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, gw->scale * 0.9);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMMINUS:
+ nsws_set_scale(gw, gw->scale * 0.9);
break;
- }
- case IDM_VIEW_ZOOMNORMAL: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, 1.0);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMNORMAL:
+ nsws_set_scale(gw, 1.0);
break;
- }
case IDM_VIEW_SOURCE:
break;
@@ -1235,6 +1213,27 @@ nsws_window_command(HWND hwnd,
/**
+ * Get the scroll position of a win32 browser window.
+ *
+ * \param g gui_window
+ * \param sx receives x ordinate of point at top-left of window
+ * \param sy receives y ordinate of point at top-left of window
+ * \return true iff successful
+ */
+static bool win32_window_get_scroll(struct gui_window *gw, int *sx, int *sy)
+{
+ LOG("get scroll");
+ if (gw == NULL)
+ return false;
+
+ *sx = gw->scrollx;
+ *sy = gw->scrolly;
+
+ return true;
+}
+
+
+/**
* handle WM_SIZE message on main browser window
*
* \param gw win32 gui window
@@ -1359,37 +1358,6 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-/* exported interface documented in windows/window.h */
-nserror
-nsws_create_main_class(HINSTANCE hinstance) {
- nserror ret = NSERROR_OK;
- WNDCLASSEX w;
-
- /* main window */
- w.cbSize = sizeof(WNDCLASSEX);
- w.style = 0;
- w.lpfnWndProc = nsws_window_event_callback;
- w.cbClsExtra = 0;
- w.cbWndExtra = 0;
- w.hInstance = hinstance;
- w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
- w.hCursor = NULL;
- w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
- w.lpszMenuName = NULL;
- w.lpszClassName = windowclassname_main;
- w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
-
- if (RegisterClassEx(&w) == 0) {
- win_perror("DrawableClass");
- ret = NSERROR_INIT_FAILED;
- }
-
- hInstance = hinstance;
-
- return ret;
-}
-
-
/**
* create a new gui_window to contain a browser_window.
*
@@ -1809,6 +1777,119 @@ bool nsws_window_go(HWND hwnd, const char *urltxt)
/* exported interface documented in windows/window.h */
+void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
+{
+ SCROLLINFO si;
+ nserror err;
+ int height;
+ int width;
+ POINT p;
+
+ if ((w == NULL) || (w->bw == NULL))
+ return;
+
+ err = browser_window_get_extents(w->bw, true, &width, &height);
+ if (err != NSERROR_OK) {
+ return;
+ }
+
+ /*LOG("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height);*/
+
+ /* The resulting gui window scroll must remain withn the
+ * windows bounding box.
+ */
+ if (sx < 0) {
+ w->requestscrollx = -w->scrollx;
+ } else if (sx > (width - w->width)) {
+ w->requestscrollx = (width - w->width) - w->scrollx;
+ } else {
+ w->requestscrollx = sx - w->scrollx;
+ }
+ if (sy < 0) {
+ w->requestscrolly = -w->scrolly;
+ } else if (sy > (height - w->height)) {
+ w->requestscrolly = (height - w->height) - w->scrolly;
+ } else {
+ w->requestscrolly = sy - w->scrolly;
+ }
+
+ /*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/
+
+ /* set the vertical scroll offset */
+ si.cbSize = sizeof(si);
+ si.fMask = SIF_ALL;
+ si.nMin = 0;
+ si.nMax = height - 1;
+ si.nPage = w->height;
+ si.nPos = max(w->scrolly + w->requestscrolly, 0);
+ si.nPos = min(si.nPos, height - w->height);
+ SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE);
+ /*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
+
+ /* set the horizontal scroll offset */
+ si.cbSize = sizeof(si);
+ si.fMask = SIF_ALL;
+ si.nMin = 0;
+ si.nMax = width -1;
+ si.nPage = w->width;
+ si.nPos = max(w->scrollx + w->requestscrollx, 0);
+ si.nPos = min(si.nPos, width - w->width);
+ SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE);
+ /*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
+
+ /* Set caret position */
+ GetCaretPos(&p);
+ HideCaret(w->drawingarea);
+ SetCaretPos(p.x - w->requestscrollx, p.y - w->requestscrolly);
+ ShowCaret(w->drawingarea);
+
+ RECT r, redraw;
+ r.top = 0;
+ r.bottom = w->height + 1;
+ r.left = 0;
+ r.right = w->width + 1;
+ ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
+ /*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/
+ w->scrolly += w->requestscrolly;
+ w->scrollx += w->requestscrollx;
+ w->requestscrollx = 0;
+ w->requestscrolly = 0;
+
+}
+
+
+/* exported interface documented in windows/window.h */
+nserror
+nsws_create_main_class(HINSTANCE hinstance) {
+ nserror ret = NSERROR_OK;
+ WNDCLASSEX w;
+
+ /* main window */
+ w.cbSize = sizeof(WNDCLASSEX);
+ w.style = 0;
+ w.lpfnWndProc = nsws_window_event_callback;
+ w.cbClsExtra = 0;
+ w.cbWndExtra = 0;
+ w.hInstance = hinstance;
+ w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+ w.hCursor = NULL;
+ w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
+ w.lpszMenuName = NULL;
+ w.lpszClassName = windowclassname_main;
+ w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+
+ if (RegisterClassEx(&w) == 0) {
+ win_perror("DrawableClass");
+ ret = NSERROR_INIT_FAILED;
+ }
+
+ hInstance = hinstance;
+
+ return ret;
+}
+
+
+/* exported interface documented in windows/window.h */
HWND gui_window_main_window(struct gui_window *w)
{
if (w == NULL)
diff --git a/frontends/windows/window.h b/frontends/windows/window.h
index 95c443e..d927c28 100644
--- a/frontends/windows/window.h
+++ b/frontends/windows/window.h
@@ -37,7 +37,7 @@ struct browser_mouse {
struct gui_window {
/* The front's private data connected to a browser window */
/* currently 1<->1 gui_window<->windows window [non-tabbed] */
- struct browser_window *bw; /** the browser_window */
+ struct browser_window *bw; /**< the browser_window */
HWND main; /**< handle to the actual window */
HWND toolbar; /**< toolbar handle */
@@ -90,6 +90,13 @@ struct gui_window *nsws_get_gui_window(HWND hwnd);
*/
bool nsws_window_go(HWND hwnd, const char *urltxt);
+/**
+ * scroll the window
+ *
+ * \param w The win32 gui window to scroll.
+ * \param sx the new 'absolute' horizontal scroll location
+ * \param sy the new 'absolute' vertical scroll location
+ */
void win32_window_set_scroll(struct gui_window *w, int sx, int sy);
/**
-----------------------------------------------------------------------
Summary of changes:
frontends/windows/window.c | 543 +++++++++++++++++++++++++-------------------
frontends/windows/window.h | 9 +-
2 files changed, 320 insertions(+), 232 deletions(-)
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index 4614c2c..cc29d19 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -67,6 +67,9 @@ static int open_windows = 0;
/**
* Obtain the DPI of the display.
+ *
+ * \param hwnd A win32 window handle to get the DPI for
+ * \return The DPI of the device teh window is displayed on.
*/
static int get_window_dpi(HWND hwnd)
{
@@ -86,7 +89,9 @@ static int get_window_dpi(HWND hwnd)
/**
- * set accelerators
+ * create and attach accelerator table to main window
+ *
+ * \param gw gui window context.
*/
static void nsws_window_set_accels(struct gui_window *w)
{
@@ -132,6 +137,9 @@ static void nsws_window_set_accels(struct gui_window *w)
/**
* creation of a new full browser window
+ *
+ * \param gw gui window context.
+ * \return The newly created window instance.
*/
static HWND nsws_window_create(struct gui_window *gw)
{
@@ -192,29 +200,15 @@ static HWND nsws_window_create(struct gui_window *gw)
/**
- * calculate the dimensions of the url bar relative to the parent toolbar
+ * toolbar command message handler
+ *
+ * \todo This entire command handler appears superfluous.
+ *
+ * \param gw The graphical window context
+ * \param notification_code The notification code of the message
+ * \param identifier The identifier the command was delivered for
+ * \param ctrl_window The controlling window.
*/
-static void
-urlbar_dimensions(HWND hWndParent,
- int toolbuttonsize,
- int buttonc,
- int *x,
- int *y,
- int *width,
- int *height)
-{
- RECT rc;
- const int cy_edit = 23;
-
- GetClientRect(hWndParent, &rc);
- *x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
- *y = ((((rc.bottom - 1) - cy_edit) >> 1) * 2) / 3;
- *width = (rc.right - 1) - *x - (NSWS_THROBBER_WIDTH>>1) - NSWS_THROBBER_WIDTH;
- *height = cy_edit;
-}
-
-
-
static LRESULT
nsws_window_toolbar_command(struct gui_window *gw,
int notification_code,
@@ -275,7 +269,45 @@ nsws_window_toolbar_command(struct gui_window *gw,
/**
+ * calculate the dimensions of the url bar relative to the parent toolbar
+ *
+ * \param hWndParent The parent window of the url bar
+ * \param toolbuttonsize size of the buttons
+ * \param buttonc The number of buttons
+ * \param[out] x The calculated x location
+ * \param[out] y The calculated y location
+ * \param[out] width The calculated width
+ * \param[out] height The calculated height
+ */
+static void
+urlbar_dimensions(HWND hWndParent,
+ int toolbuttonsize,
+ int buttonc,
+ int *x,
+ int *y,
+ int *width,
+ int *height)
+{
+ RECT rc;
+ const int cy_edit = 23;
+
+ GetClientRect(hWndParent, &rc);
+ *x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
+ *y = ((((rc.bottom - 1) - cy_edit) >> 1) * 2) / 3;
+ *width = (rc.right - 1) - *x - (NSWS_THROBBER_WIDTH>>1) - NSWS_THROBBER_WIDTH;
+ *height = cy_edit;
+}
+
+
+/**
* callback for toolbar events
+ *
+ * message handler for toolbar window
+ *
+ * \param hwnd win32 window handle message arrived for
+ * \param msg The message ID
+ * \param wparam The w parameter of the message.
+ * \param lparam The l parameter of the message.
*/
static LRESULT CALLBACK
nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -340,40 +372,15 @@ nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-static HIMAGELIST
-get_imagelist(int resid, int bsize, int bcnt)
-{
- HIMAGELIST hImageList;
- HBITMAP hScrBM;
-
- LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
-
- hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
- bcnt);
- if (hImageList == NULL)
- return NULL;
-
- hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
- IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
-
- if (hScrBM == NULL) {
- win_perror("LoadImage");
- return NULL;
- }
-
- if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) {
- /* failed to add masked bitmap */
- ImageList_Destroy(hImageList);
- hImageList = NULL;
- }
- DeleteObject(hScrBM);
-
- return hImageList;
-}
-
-
/**
* callback for url bar events
+ *
+ * message handler for urlbar window
+ *
+ * \param hwnd win32 window handle message arrived for
+ * \param msg The message ID
+ * \param wparam The w parameter of the message.
+ * \param lparam The l parameter of the message.
*/
static LRESULT CALLBACK
nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -426,16 +433,20 @@ nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
* create a urlbar and message handler
*
* Create an Edit control for enerting urls
+ *
+ * \param gw win32 frontends window context.
+ * \param hWndParent The main containing window.
+ * \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
+nsws_window_urlbar_create(struct gui_window *gw, HWND hWndParent)
{
int urlx, urly, urlwidth, urlheight;
HWND hwnd;
WNDPROC urlproc;
HFONT hFont;
- urlbar_dimensions(hwndparent,
+ urlbar_dimensions(hWndParent,
gw->toolbuttonsize,
gw->toolbuttonc,
&urlx, &urly, &urlwidth, &urlheight);
@@ -449,7 +460,7 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
urly,
urlwidth,
urlheight,
- hwndparent,
+ hWndParent,
(HMENU)IDC_MAIN_URLBAR,
hInstance,
0);
@@ -463,19 +474,23 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
/* subclass the message handler */
urlproc = (WNDPROC)SetWindowLongPtr(hwnd,
- GWLP_WNDPROC,
- (LONG_PTR)nsws_window_urlbar_callback);
+ GWLP_WNDPROC,
+ (LONG_PTR)nsws_window_urlbar_callback);
/* save the real handler */
SetProp(hwnd, TEXT("OrigMsgProc"), (HANDLE)urlproc);
- hFont = CreateFont(urlheight - 4, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
+ hFont = CreateFont(urlheight - 4, 0, 0, 0, FW_BOLD, FALSE, FALSE,
+ FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
+ CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+ DEFAULT_PITCH | FF_SWISS, "Arial");
if (hFont != NULL) {
LOG("Setting font object");
SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0);
}
- LOG("Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d", hwnd, urlx, urly, urlwidth, urlheight);
+ LOG("Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d",
+ hwnd, urlx, urly, urlwidth, urlheight);
return hwnd;
}
@@ -483,9 +498,12 @@ nsws_window_urlbar_create(struct gui_window *gw, HWND hwndparent)
/**
* creation of throbber
+ *
+ * \param gw win32 frontends window context.
+ * \return win32 window handle of created window or NULL on error.
*/
static HWND
-nsws_window_throbber_create(struct gui_window *w)
+nsws_window_throbber_create(struct gui_window *gw)
{
HWND hwnd;
char avi[PATH_MAX];
@@ -493,11 +511,11 @@ nsws_window_throbber_create(struct gui_window *w)
hwnd = CreateWindow(ANIMATE_CLASS,
"",
WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT,
- w->width - NSWS_THROBBER_WIDTH - 4,
+ gw->width - NSWS_THROBBER_WIDTH - 4,
8,
NSWS_THROBBER_WIDTH,
NSWS_THROBBER_WIDTH,
- w->main,
+ gw->main,
(HMENU) IDC_MAIN_THROBBER,
hInstance,
NULL);
@@ -505,16 +523,64 @@ nsws_window_throbber_create(struct gui_window *w)
nsws_find_resource(avi, "throbber.avi", "windows/res/throbber.avi");
LOG("setting throbber avi as %s", avi);
Animate_Open(hwnd, avi);
- if (w->throbbing)
+ if (gw->throbbing) {
Animate_Play(hwnd, 0, -1, -1);
- else
+ } else {
Animate_Seek(hwnd, 0);
+ }
ShowWindow(hwnd, SW_SHOWNORMAL);
+
return hwnd;
}
-/* create a toolbar add controls and message handler */
+/**
+ * create a win32 image list for the toolbar.
+ *
+ * \param resid The resource ID of the image.
+ * \param bsize The size of the image to load.
+ * \param bcnt The number of bitmaps to load into the list.
+ * \return The image list or NULL on error.
+ */
+static HIMAGELIST
+get_imagelist(int resid, int bsize, int bcnt)
+{
+ HIMAGELIST hImageList;
+ HBITMAP hScrBM;
+
+ LOG("resource id %d, bzize %d, bcnt %d", resid, bsize, bcnt);
+
+ hImageList = ImageList_Create(bsize, bsize, ILC_COLOR24 | ILC_MASK, 0,
+ bcnt);
+ if (hImageList == NULL)
+ return NULL;
+
+ hScrBM = LoadImage(hInstance, MAKEINTRESOURCE(resid),
+ IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
+
+ if (hScrBM == NULL) {
+ win_perror("LoadImage");
+ return NULL;
+ }
+
+ if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) {
+ /* failed to add masked bitmap */
+ ImageList_Destroy(hImageList);
+ hImageList = NULL;
+ }
+ DeleteObject(hScrBM);
+
+ return hImageList;
+}
+
+
+/**
+ * create win32 main window toolbar and add controls and message handler
+ *
+ * \param gw win32 frontends window context.
+ * \param hWndParent The main containing window.
+ * \return win32 window handle of created window or NULL on error.
+ */
static HWND
nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
{
@@ -599,15 +665,17 @@ nsws_window_create_toolbar(struct gui_window *gw, HWND hWndParent)
/**
* creation of status bar
+ *
+ * \param gw win32 frontends window context.
*/
-static HWND nsws_window_create_statusbar(struct gui_window *w)
+static HWND nsws_window_create_statusbar(struct gui_window *gw)
{
HWND hwnd = CreateWindowEx(0,
STATUSCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
- w->main,
+ gw->main,
(HMENU)IDC_MAIN_STATUSBAR,
hInstance,
NULL);
@@ -616,12 +684,18 @@ static HWND nsws_window_create_statusbar(struct gui_window *w)
}
+/**
+ * Update popup context menu editing functionality
+ *
+ * \param w win32 frontends window context.
+ */
static void nsws_update_edit(struct gui_window *w)
{
browser_editor_flags editor_flags = (w->bw == NULL) ?
BW_EDITOR_NONE : browser_window_get_editor_flags(w->bw);
bool paste, copy, del;
bool sel = (editor_flags & BW_EDITOR_CAN_COPY);
+
if (GetFocus() == w->urlbar) {
DWORD i, ii;
SendMessage(w->urlbar, EM_GETSEL, (WPARAM)&i, (LPARAM)&ii);
@@ -629,7 +703,7 @@ static void nsws_update_edit(struct gui_window *w)
copy = (i != ii);
del = (i != ii);
- } else if (sel){
+ } else if (sel) {
paste = (editor_flags & BW_EDITOR_CAN_PASTE);
copy = sel;
del = (editor_flags & BW_EDITOR_CAN_CUT);
@@ -668,6 +742,14 @@ static void nsws_update_edit(struct gui_window *w)
}
+/**
+ * Handle win32 context menu message
+ *
+ * \param gw win32 frontends graphical window.
+ * \param hwnd The win32 window handle
+ * \param int x The x coordinate of the event.
+ * \param y the y cooordiante of the event.
+ */
static bool
nsws_ctx_menu(struct gui_window *w, HWND hwnd, int x, int y)
{
@@ -702,6 +784,8 @@ nsws_ctx_menu(struct gui_window *w, HWND hwnd, int x, int y)
/**
* update state of forward/back buttons/menu items when page changes
+ *
+ * \param w win32 frontends graphical window.
*/
static void nsws_window_update_forward_back(struct gui_window *w)
{
@@ -735,37 +819,10 @@ static void nsws_window_update_forward_back(struct gui_window *w)
}
-static bool win32_window_get_scroll(struct gui_window *w, int *sx, int *sy)
-{
- LOG("get scroll");
- if (w == NULL)
- return false;
-
- *sx = w->scrollx;
- *sy = w->scrolly;
-
- return true;
-}
-
-
-static void nsws_set_scale(struct gui_window *gw, float scale)
-{
- assert(gw != NULL);
-
- if (gw->scale == scale)
- return;
-
- gw->scale = scale;
-
- if (gw->bw == NULL)
- return;
-
- browser_window_set_scale(gw->bw, scale, true);
-}
-
-
/**
* redraw the whole window
+ *
+ * \param gw win32 frontends graphical window.
*/
static void win32_window_redraw_window(struct gui_window *gw)
{
@@ -778,90 +835,32 @@ static void win32_window_redraw_window(struct gui_window *gw)
/**
- * scroll the window
+ * Set scale of a win32 browser window
*
- * \param w The win32 gui window to scroll.
- * \param sx the new 'absolute' horizontal scroll location
- * \param sy the new 'absolute' vertical scroll location
+ * \param gw win32 frontend window context
+ * \param scale The new scale
*/
-void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
+static void nsws_set_scale(struct gui_window *gw, float scale)
{
- SCROLLINFO si;
- nserror err;
- int height;
- int width;
- POINT p;
+ int x, y;
- if ((w == NULL) || (w->bw == NULL))
- return;
+ assert(gw != NULL);
- err = browser_window_get_extents(w->bw, true, &width, &height);
- if (err != NSERROR_OK) {
+ if (gw->scale == scale) {
return;
}
- /*LOG("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height);*/
+ x = gw->scrollx;
+ y = gw->scrolly;
- /* The resulting gui window scroll must remain withn the
- * windows bounding box.
- */
- if (sx < 0) {
- w->requestscrollx = -w->scrollx;
- } else if (sx > (width - w->width)) {
- w->requestscrollx = (width - w->width) - w->scrollx;
- } else {
- w->requestscrollx = sx - w->scrollx;
- }
- if (sy < 0) {
- w->requestscrolly = -w->scrolly;
- } else if (sy > (height - w->height)) {
- w->requestscrolly = (height - w->height) - w->scrolly;
- } else {
- w->requestscrolly = sy - w->scrolly;
- }
-
- /*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/
-
- /* set the vertical scroll offset */
- si.cbSize = sizeof(si);
- si.fMask = SIF_ALL;
- si.nMin = 0;
- si.nMax = height - 1;
- si.nPage = w->height;
- si.nPos = max(w->scrolly + w->requestscrolly, 0);
- si.nPos = min(si.nPos, height - w->height);
- SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE);
- /*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
-
- /* set the horizontal scroll offset */
- si.cbSize = sizeof(si);
- si.fMask = SIF_ALL;
- si.nMin = 0;
- si.nMax = width -1;
- si.nPage = w->width;
- si.nPos = max(w->scrollx + w->requestscrollx, 0);
- si.nPos = min(si.nPos, width - w->width);
- SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE);
- /*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
-
- /* Set caret position */
- GetCaretPos(&p);
- HideCaret(w->drawingarea);
- SetCaretPos(p.x - w->requestscrollx, p.y - w->requestscrolly);
- ShowCaret(w->drawingarea);
+ gw->scale = scale;
- RECT r, redraw;
- r.top = 0;
- r.bottom = w->height + 1;
- r.left = 0;
- r.right = w->width + 1;
- ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
- /*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/
- w->scrolly += w->requestscrolly;
- w->scrollx += w->requestscrollx;
- w->requestscrollx = 0;
- w->requestscrolly = 0;
+ if (gw->bw != NULL) {
+ browser_window_set_scale(gw->bw, scale, true);
+ }
+ win32_window_redraw_window(gw);
+ win32_window_set_scroll(gw, x, y);
}
@@ -1074,38 +1073,17 @@ nsws_window_command(HWND hwnd,
case IDM_NAV_GLOBALHISTORY:
break;
- case IDM_VIEW_ZOOMPLUS: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, gw->scale * 1.1);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMPLUS:
+ nsws_set_scale(gw, gw->scale * 1.1);
break;
- }
- case IDM_VIEW_ZOOMMINUS: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, gw->scale * 0.9);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMMINUS:
+ nsws_set_scale(gw, gw->scale * 0.9);
break;
- }
- case IDM_VIEW_ZOOMNORMAL: {
- int x, y;
- win32_window_get_scroll(gw, &x, &y);
- if (gw->bw != NULL) {
- nsws_set_scale(gw, 1.0);
- }
- win32_window_redraw_window(gw);
- win32_window_set_scroll(gw, x, y);
+ case IDM_VIEW_ZOOMNORMAL:
+ nsws_set_scale(gw, 1.0);
break;
- }
case IDM_VIEW_SOURCE:
break;
@@ -1235,6 +1213,27 @@ nsws_window_command(HWND hwnd,
/**
+ * Get the scroll position of a win32 browser window.
+ *
+ * \param g gui_window
+ * \param sx receives x ordinate of point at top-left of window
+ * \param sy receives y ordinate of point at top-left of window
+ * \return true iff successful
+ */
+static bool win32_window_get_scroll(struct gui_window *gw, int *sx, int *sy)
+{
+ LOG("get scroll");
+ if (gw == NULL)
+ return false;
+
+ *sx = gw->scrollx;
+ *sy = gw->scrolly;
+
+ return true;
+}
+
+
+/**
* handle WM_SIZE message on main browser window
*
* \param gw win32 gui window
@@ -1359,37 +1358,6 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-/* exported interface documented in windows/window.h */
-nserror
-nsws_create_main_class(HINSTANCE hinstance) {
- nserror ret = NSERROR_OK;
- WNDCLASSEX w;
-
- /* main window */
- w.cbSize = sizeof(WNDCLASSEX);
- w.style = 0;
- w.lpfnWndProc = nsws_window_event_callback;
- w.cbClsExtra = 0;
- w.cbWndExtra = 0;
- w.hInstance = hinstance;
- w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
- w.hCursor = NULL;
- w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
- w.lpszMenuName = NULL;
- w.lpszClassName = windowclassname_main;
- w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
-
- if (RegisterClassEx(&w) == 0) {
- win_perror("DrawableClass");
- ret = NSERROR_INIT_FAILED;
- }
-
- hInstance = hinstance;
-
- return ret;
-}
-
-
/**
* create a new gui_window to contain a browser_window.
*
@@ -1809,6 +1777,119 @@ bool nsws_window_go(HWND hwnd, const char *urltxt)
/* exported interface documented in windows/window.h */
+void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
+{
+ SCROLLINFO si;
+ nserror err;
+ int height;
+ int width;
+ POINT p;
+
+ if ((w == NULL) || (w->bw == NULL))
+ return;
+
+ err = browser_window_get_extents(w->bw, true, &width, &height);
+ if (err != NSERROR_OK) {
+ return;
+ }
+
+ /*LOG("scroll sx,sy:%d,%d x,y:%d,%d w.h:%d,%d",sx,sy,w->scrollx,w->scrolly, width,height);*/
+
+ /* The resulting gui window scroll must remain withn the
+ * windows bounding box.
+ */
+ if (sx < 0) {
+ w->requestscrollx = -w->scrollx;
+ } else if (sx > (width - w->width)) {
+ w->requestscrollx = (width - w->width) - w->scrollx;
+ } else {
+ w->requestscrollx = sx - w->scrollx;
+ }
+ if (sy < 0) {
+ w->requestscrolly = -w->scrolly;
+ } else if (sy > (height - w->height)) {
+ w->requestscrolly = (height - w->height) - w->scrolly;
+ } else {
+ w->requestscrolly = sy - w->scrolly;
+ }
+
+ /*LOG("requestscroll x,y:%d,%d", w->requestscrollx, w->requestscrolly);*/
+
+ /* set the vertical scroll offset */
+ si.cbSize = sizeof(si);
+ si.fMask = SIF_ALL;
+ si.nMin = 0;
+ si.nMax = height - 1;
+ si.nPage = w->height;
+ si.nPos = max(w->scrolly + w->requestscrolly, 0);
+ si.nPos = min(si.nPos, height - w->height);
+ SetScrollInfo(w->drawingarea, SB_VERT, &si, TRUE);
+ /*LOG("SetScrollInfo VERT min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
+
+ /* set the horizontal scroll offset */
+ si.cbSize = sizeof(si);
+ si.fMask = SIF_ALL;
+ si.nMin = 0;
+ si.nMax = width -1;
+ si.nPage = w->width;
+ si.nPos = max(w->scrollx + w->requestscrollx, 0);
+ si.nPos = min(si.nPos, width - w->width);
+ SetScrollInfo(w->drawingarea, SB_HORZ, &si, TRUE);
+ /*LOG("SetScrollInfo HORZ min:%d max:%d page:%d pos:%d", si.nMin, si.nMax, si.nPage, si.nPos);*/
+
+ /* Set caret position */
+ GetCaretPos(&p);
+ HideCaret(w->drawingarea);
+ SetCaretPos(p.x - w->requestscrollx, p.y - w->requestscrolly);
+ ShowCaret(w->drawingarea);
+
+ RECT r, redraw;
+ r.top = 0;
+ r.bottom = w->height + 1;
+ r.left = 0;
+ r.right = w->width + 1;
+ ScrollWindowEx(w->drawingarea, - w->requestscrollx, - w->requestscrolly, &r, NULL, NULL, &redraw, SW_INVALIDATE);
+ /*LOG("ScrollWindowEx %d, %d", - w->requestscrollx, - w->requestscrolly);*/
+ w->scrolly += w->requestscrolly;
+ w->scrollx += w->requestscrollx;
+ w->requestscrollx = 0;
+ w->requestscrolly = 0;
+
+}
+
+
+/* exported interface documented in windows/window.h */
+nserror
+nsws_create_main_class(HINSTANCE hinstance) {
+ nserror ret = NSERROR_OK;
+ WNDCLASSEX w;
+
+ /* main window */
+ w.cbSize = sizeof(WNDCLASSEX);
+ w.style = 0;
+ w.lpfnWndProc = nsws_window_event_callback;
+ w.cbClsExtra = 0;
+ w.cbWndExtra = 0;
+ w.hInstance = hinstance;
+ w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+ w.hCursor = NULL;
+ w.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
+ w.lpszMenuName = NULL;
+ w.lpszClassName = windowclassname_main;
+ w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
+
+ if (RegisterClassEx(&w) == 0) {
+ win_perror("DrawableClass");
+ ret = NSERROR_INIT_FAILED;
+ }
+
+ hInstance = hinstance;
+
+ return ret;
+}
+
+
+/* exported interface documented in windows/window.h */
HWND gui_window_main_window(struct gui_window *w)
{
if (w == NULL)
diff --git a/frontends/windows/window.h b/frontends/windows/window.h
index 95c443e..d927c28 100644
--- a/frontends/windows/window.h
+++ b/frontends/windows/window.h
@@ -37,7 +37,7 @@ struct browser_mouse {
struct gui_window {
/* The front's private data connected to a browser window */
/* currently 1<->1 gui_window<->windows window [non-tabbed] */
- struct browser_window *bw; /** the browser_window */
+ struct browser_window *bw; /**< the browser_window */
HWND main; /**< handle to the actual window */
HWND toolbar; /**< toolbar handle */
@@ -90,6 +90,13 @@ struct gui_window *nsws_get_gui_window(HWND hwnd);
*/
bool nsws_window_go(HWND hwnd, const char *urltxt);
+/**
+ * scroll the window
+ *
+ * \param w The win32 gui window to scroll.
+ * \param sx the new 'absolute' horizontal scroll location
+ * \param sy the new 'absolute' vertical scroll location
+ */
void win32_window_set_scroll(struct gui_window *w, int sx, int sy);
/**
--
NetSurf Browser
6 years, 11 months
netsurf: branch master updated. release/3.5-372-g57715fc
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/57715fc70cef09e39b9f8...
...commit http://git.netsurf-browser.org/netsurf.git/commit/57715fc70cef09e39b9f8b6...
...tree http://git.netsurf-browser.org/netsurf.git/tree/57715fc70cef09e39b9f8b627...
The branch, master has been updated
via 57715fc70cef09e39b9f8b6277b02304d4281a95 (commit)
via 489f6f1fa32f8017659529f2dc6a26780f8bb277 (commit)
from 3940a078b118b0b81b1d799d8b83a8753aa0d3ea (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=57715fc70cef09e39b9...
commit 57715fc70cef09e39b9f8b6277b02304d4281a95
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Improve windows win32 main browser window code documentation
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index 7069417..4614c2c 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2011-2016 Vincent Sanders <vince(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Main browser window handling for windows win32 frontend.
+ */
+
#include "utils/config.h"
#include <stdbool.h>
@@ -216,7 +221,8 @@ nsws_window_toolbar_command(struct gui_window *gw,
int identifier,
HWND ctrl_window)
{
- LOG("notification_code %d identifier %d ctrl_window %p", notification_code, identifier, ctrl_window);
+ LOG("notification_code %d identifier %d ctrl_window %p",
+ notification_code, identifier, ctrl_window);
switch(identifier) {
@@ -858,6 +864,7 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
}
+
/**
* Create a new window due to menu selection
*
@@ -889,6 +896,17 @@ static nserror win32_open_new_window(struct gui_window *gw)
return ret;
}
+
+/**
+ * handle command message on main browser window
+ *
+ * \param hwnd The win32 window handle
+ * \param gw win32 gui window
+ * \param notification_code notifiction code
+ * \param identifier notification identifier
+ * \param ctrl_window The win32 control window handle
+ * \return apropriate response for command
+ */
static LRESULT
nsws_window_command(HWND hwnd,
struct gui_window *gw,
@@ -1216,6 +1234,15 @@ nsws_window_command(HWND hwnd,
}
+/**
+ * handle WM_SIZE message on main browser window
+ *
+ * \param gw win32 gui window
+ * \param hwnd The win32 window handle
+ * \param wparam The w win32 parameter
+ * \param lparam The l win32 parameter
+ * \return apropriate response for resize
+ */
static LRESULT
nsws_window_resize(struct gui_window *gw,
HWND hwnd,
@@ -1262,7 +1289,12 @@ nsws_window_resize(struct gui_window *gw,
/**
- * callback for window events generally
+ * callback for browser window win32 events
+ *
+ * \param hwnd The win32 window handle
+ * \param msg The win32 message identifier
+ * \param wparam The w win32 parameter
+ * \param lparam The l win32 parameter
*/
static LRESULT CALLBACK
nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -1327,9 +1359,7 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-/**
- * Create the main window class.
- */
+/* exported interface documented in windows/window.h */
nserror
nsws_create_main_class(HINSTANCE hinstance) {
nserror ret = NSERROR_OK;
@@ -1360,10 +1390,6 @@ nsws_create_main_class(HINSTANCE hinstance) {
}
-
-
-
-
/**
* create a new gui_window to contain a browser_window.
*
@@ -1374,15 +1400,14 @@ nsws_create_main_class(HINSTANCE hinstance) {
*/
static struct gui_window *
win32_window_create(struct browser_window *bw,
- struct gui_window *existing,
- gui_window_create_flags flags)
+ struct gui_window *existing,
+ gui_window_create_flags flags)
{
struct gui_window *gw;
LOG("Creating gui window for browser window %p", bw);
gw = calloc(1, sizeof(struct gui_window));
-
if (gw == NULL) {
return NULL;
}
@@ -1410,8 +1435,9 @@ win32_window_create(struct browser_window *bw,
gw->mouse->pressed_y = 0;
/* add window to list */
- if (window_list != NULL)
+ if (window_list != NULL) {
window_list->prev = gw;
+ }
gw->next = window_list;
window_list = gw;
@@ -1420,7 +1446,8 @@ win32_window_create(struct browser_window *bw,
gw->statusbar = nsws_window_create_statusbar(gw);
gw->drawingarea = nsws_window_create_drawable(hInstance, gw->main, gw);
- LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
+ LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p",
+ gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
font_hwnd = gw->drawingarea;
open_windows++;
@@ -1431,7 +1458,9 @@ win32_window_create(struct browser_window *bw,
/**
- * window cleanup code
+ * Destroy previously created win32 window
+ *
+ * \param w The gui window to destroy.
*/
static void win32_window_destroy(struct gui_window *w)
{
@@ -1453,13 +1482,15 @@ static void win32_window_destroy(struct gui_window *w)
}
-
-
+/**
+ * Cause redraw of part of a win32 window.
+ *
+ * \param gw win32 gui window
+ * \param rect area to redraw
+ */
static void
-win32_window_update_box(struct gui_window *gw, const struct rect *rect)
+win32_window_update(struct gui_window *gw, const struct rect *rect)
{
- /* LOG("gw:%p %f,%f %f,%f", gw, data->redraw.x, data->redraw.y, data->redraw.width, data->redraw.height); */
-
if (gw == NULL)
return;
@@ -1470,17 +1501,25 @@ win32_window_update_box(struct gui_window *gw, const struct rect *rect)
redrawrect.right =(long)rect->x1;
redrawrect.bottom = (long)rect->y1;
- RedrawWindow(gw->drawingarea, &redrawrect, NULL,
+ RedrawWindow(gw->drawingarea,
+ &redrawrect,
+ NULL,
RDW_INVALIDATE | RDW_NOERASE);
-
}
-
-
-
-static void win32_window_get_dimensions(struct gui_window *gw, int *width, int *height,
- bool scaled)
+/**
+ * Find the current dimensions of a win32 browser window's content area.
+ *
+ * \param gw gui_window to measure
+ * \param width receives width of window
+ * \param height receives height of window
+ * \param scaled whether to return scaled values
+ */
+static void
+win32_window_get_dimensions(struct gui_window *gw,
+ int *width, int *height,
+ bool scaled)
{
if (gw == NULL)
return;
@@ -1491,13 +1530,21 @@ static void win32_window_get_dimensions(struct gui_window *gw, int *width, int *
*height = gw->height;
}
+
+/**
+ * Update the extent of the inside of a browser window to that of the
+ * current content.
+ *
+ * \param w gui_window to update the extent of
+ */
static void win32_window_update_extent(struct gui_window *w)
{
}
+
/**
- * callback from core to reformat a window.
+ * callback from core to reformat a win32 window.
*
* \param gw The win32 gui window to reformat.
*/
@@ -1510,9 +1557,9 @@ static void win32_window_reformat(struct gui_window *gw)
/**
- * set window title
+ * set win32 browser window title
*
- * \param w the Windows gui window.
+ * \param w the win32 gui window.
* \param title to set on window
*/
static void win32_window_set_title(struct gui_window *w, const char *title)
@@ -1533,51 +1580,76 @@ static void win32_window_set_title(struct gui_window *w, const char *title)
}
-static nserror win32_window_set_url(struct gui_window *w, nsurl *url)
+/**
+ * Set the navigation url is a win32 browser window.
+ *
+ * \param gw window to update.
+ * \param url The url to use as icon.
+ */
+static nserror win32_window_set_url(struct gui_window *gw, nsurl *url)
{
- SendMessage(w->urlbar, WM_SETTEXT, 0, (LPARAM) nsurl_access(url));
+ SendMessage(gw->urlbar, WM_SETTEXT, 0, (LPARAM) nsurl_access(url));
return NSERROR_OK;
}
/**
- * set the status bar message
+ * Set the status bar of a win32 browser window.
+ *
+ * \param w gui_window to update
+ * \param text new status text
*/
static void win32_window_set_status(struct gui_window *w, const char *text)
{
- if (w == NULL)
+ if (w == NULL) {
return;
+ }
SendMessage(w->statusbar, WM_SETTEXT, 0, (LPARAM)text);
}
/**
- * set the pointer shape
+ * Change the win32 mouse pointer shape
+ *
+ * \param w The gui window to change pointer shape in.
+ * \param shape The new shape to change to.
*/
-static void win32_window_set_pointer(struct gui_window *w,
- gui_pointer_shape shape)
+static void
+win32_window_set_pointer(struct gui_window *w, gui_pointer_shape shape)
{
SetCursor(nsws_get_pointer(shape));
}
/**
- * place caret in window
+ * Give the win32 input focus to a window
+ *
+ * \param w window with caret
+ * \param x coordinates of caret
+ * \param y coordinates of caret
+ * \param height height of caret
+ * \param clip rectangle to clip caret or NULL if none
*/
-static void win32_window_place_caret(struct gui_window *w, int x, int y,
- int height, const struct rect *clip)
+static void
+win32_window_place_caret(struct gui_window *w, int x, int y,
+ int height, const struct rect *clip)
{
- if (w == NULL)
+ if (w == NULL) {
return;
+ }
+
CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height * w->scale);
SetCaretPos(x * w->scale - w->scrollx,
y * w->scale - w->scrolly);
ShowCaret(w->drawingarea);
}
+
/**
- * clear window caret
+ * Remove the win32 input focus from window
+ *
+ * \param g window with caret
*/
static void win32_window_remove_caret(struct gui_window *w)
{
@@ -1587,8 +1659,11 @@ static void win32_window_remove_caret(struct gui_window *w)
}
-
-
+/**
+ * start a win32 navigation throbber.
+ *
+ * \param w window in which to start throbber.
+ */
static void win32_window_start_throbber(struct gui_window *w)
{
if (w == NULL)
@@ -1615,7 +1690,11 @@ static void win32_window_start_throbber(struct gui_window *w)
}
-
+/**
+ * stop a win32 navigation throbber.
+ *
+ * \param w window with throbber to stop
+ */
static void win32_window_stop_throbber(struct gui_window *w)
{
if (w == NULL)
@@ -1645,11 +1724,15 @@ static void win32_window_stop_throbber(struct gui_window *w)
Animate_Seek(w->throbber, 0);
}
+
+/**
+ * win32 frontend browser window handling operation table
+ */
static struct gui_window_table window_table = {
.create = win32_window_create,
.destroy = win32_window_destroy,
.redraw = win32_window_redraw_window,
- .update = win32_window_update_box,
+ .update = win32_window_update,
.get_scroll = win32_window_get_scroll,
.set_scroll = win32_window_set_scroll,
.get_dimensions = win32_window_get_dimensions,
@@ -1668,6 +1751,7 @@ static struct gui_window_table window_table = {
struct gui_window_table *win32_window_table = &window_table;
+
/* exported interface documented in windows/window.h */
struct gui_window *nsws_get_gui_window(HWND hwnd)
{
diff --git a/frontends/windows/window.h b/frontends/windows/window.h
index 047cec6..95c443e 100644
--- a/frontends/windows/window.h
+++ b/frontends/windows/window.h
@@ -74,7 +74,7 @@ struct gui_window {
};
-/**
+/**
* Obtain gui window structure from window handle.
*
* \param hwnd The window handle.
@@ -92,13 +92,19 @@ bool nsws_window_go(HWND hwnd, const char *urltxt);
void win32_window_set_scroll(struct gui_window *w, int sx, int sy);
+/**
+ * Create the main browser window class.
+ *
+ * \param hinstance The application instance
+ * \return NSERROR_OK on success or NSERROR_INIT_FAILED if the class
+ * creation failed.
+ */
nserror nsws_create_main_class(HINSTANCE hinstance);
/**
* Get the main win32 window handle from a gui window
*/
-HWND gui_window_main_window(struct gui_window *);
-
+HWND gui_window_main_window(struct gui_window *gw);
/**
* Get the localhistory win32 window handle from a gui window
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=489f6f1fa32f8017659...
commit 489f6f1fa32f8017659529f2dc6a26780f8bb277
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Improve window operation table documentation
diff --git a/include/netsurf/window.h b/include/netsurf/window.h
index 8b3e9c4..b887368 100644
--- a/include/netsurf/window.h
+++ b/include/netsurf/window.h
@@ -71,7 +71,7 @@ enum gui_pointer_shape;
*/
struct gui_window_table {
- /* Mandantory entries */
+ /* Mandatory entries */
/**
* Create and open a gui window for a browsing context.
@@ -161,8 +161,8 @@ struct gui_window_table {
* Reformat a window.
*
* This is used to perform reformats when the page contents
- * require reformating. The reformat is requested using
- * browser_window_schedule_reformat and occours via a scheduled
+ * require reformatting. The reformat is requested using
+ * browser_window_schedule_reformat and occurs via a scheduled
* callback hence from top level context.
*
* \param g gui_window to reformat.
@@ -197,15 +197,18 @@ struct gui_window_table {
void (*set_icon)(struct gui_window *gw, struct hlcache_handle *icon);
/**
- * Set the status bar of a browser window.
+ * Set the status bar message of a browser window.
*
- * \param g gui_window to update
- * \param text new status text
+ * \param g gui_window to update
+ * \param text new status text
*/
void (*set_status)(struct gui_window *g, const char *text);
/**
* Change mouse pointer shape
+ *
+ * \param g The gui window to change pointer shape in.
+ * \param shape The new shape to change to.
*/
void (*set_pointer)(struct gui_window *g, enum gui_pointer_shape shape);
@@ -227,16 +230,38 @@ struct gui_window_table {
*/
void (*remove_caret)(struct gui_window *g);
- /** start the navigation throbber. */
+ /**
+ * start the navigation throbber.
+ *
+ * \param g window in which to start throbber.
+ */
void (*start_throbber)(struct gui_window *g);
- /** stop the navigation throbber. */
+ /**
+ * stop the navigation throbber.
+ *
+ * \param g window with throbber to stop
+ */
void (*stop_throbber)(struct gui_window *g);
- /** start a drag operation within a window */
+ /**
+ * start a drag operation within a window
+ *
+ * \param g window to start drag from.
+ * \param type Type of drag to start
+ * \param rect Confining rectangle of drag operation.
+ * \return true if drag started else false.
+ */
bool (*drag_start)(struct gui_window *g, gui_drag_type type, const struct rect *rect);
- /** save link operation */
+ /**
+ * save link operation
+ *
+ * \param g window to save link from.
+ * \param url The link url.
+ * \param title The title of the link.
+ * \return NSERROR_OK on success else appropriate error code.
+ */
nserror (*save_link)(struct gui_window *g, struct nsurl *url, const char *title);
/**
-----------------------------------------------------------------------
Summary of changes:
frontends/windows/window.c | 178 ++++++++++++++++++++++++++++++++------------
frontends/windows/window.h | 12 ++-
include/netsurf/window.h | 45 ++++++++---
3 files changed, 175 insertions(+), 60 deletions(-)
diff --git a/frontends/windows/window.c b/frontends/windows/window.c
index 7069417..4614c2c 100644
--- a/frontends/windows/window.c
+++ b/frontends/windows/window.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2011-2016 Vincent Sanders <vince(a)netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Main browser window handling for windows win32 frontend.
+ */
+
#include "utils/config.h"
#include <stdbool.h>
@@ -216,7 +221,8 @@ nsws_window_toolbar_command(struct gui_window *gw,
int identifier,
HWND ctrl_window)
{
- LOG("notification_code %d identifier %d ctrl_window %p", notification_code, identifier, ctrl_window);
+ LOG("notification_code %d identifier %d ctrl_window %p",
+ notification_code, identifier, ctrl_window);
switch(identifier) {
@@ -858,6 +864,7 @@ void win32_window_set_scroll(struct gui_window *w, int sx, int sy)
}
+
/**
* Create a new window due to menu selection
*
@@ -889,6 +896,17 @@ static nserror win32_open_new_window(struct gui_window *gw)
return ret;
}
+
+/**
+ * handle command message on main browser window
+ *
+ * \param hwnd The win32 window handle
+ * \param gw win32 gui window
+ * \param notification_code notifiction code
+ * \param identifier notification identifier
+ * \param ctrl_window The win32 control window handle
+ * \return apropriate response for command
+ */
static LRESULT
nsws_window_command(HWND hwnd,
struct gui_window *gw,
@@ -1216,6 +1234,15 @@ nsws_window_command(HWND hwnd,
}
+/**
+ * handle WM_SIZE message on main browser window
+ *
+ * \param gw win32 gui window
+ * \param hwnd The win32 window handle
+ * \param wparam The w win32 parameter
+ * \param lparam The l win32 parameter
+ * \return apropriate response for resize
+ */
static LRESULT
nsws_window_resize(struct gui_window *gw,
HWND hwnd,
@@ -1262,7 +1289,12 @@ nsws_window_resize(struct gui_window *gw,
/**
- * callback for window events generally
+ * callback for browser window win32 events
+ *
+ * \param hwnd The win32 window handle
+ * \param msg The win32 message identifier
+ * \param wparam The w win32 parameter
+ * \param lparam The l win32 parameter
*/
static LRESULT CALLBACK
nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -1327,9 +1359,7 @@ nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
}
-/**
- * Create the main window class.
- */
+/* exported interface documented in windows/window.h */
nserror
nsws_create_main_class(HINSTANCE hinstance) {
nserror ret = NSERROR_OK;
@@ -1360,10 +1390,6 @@ nsws_create_main_class(HINSTANCE hinstance) {
}
-
-
-
-
/**
* create a new gui_window to contain a browser_window.
*
@@ -1374,15 +1400,14 @@ nsws_create_main_class(HINSTANCE hinstance) {
*/
static struct gui_window *
win32_window_create(struct browser_window *bw,
- struct gui_window *existing,
- gui_window_create_flags flags)
+ struct gui_window *existing,
+ gui_window_create_flags flags)
{
struct gui_window *gw;
LOG("Creating gui window for browser window %p", bw);
gw = calloc(1, sizeof(struct gui_window));
-
if (gw == NULL) {
return NULL;
}
@@ -1410,8 +1435,9 @@ win32_window_create(struct browser_window *bw,
gw->mouse->pressed_y = 0;
/* add window to list */
- if (window_list != NULL)
+ if (window_list != NULL) {
window_list->prev = gw;
+ }
gw->next = window_list;
window_list = gw;
@@ -1420,7 +1446,8 @@ win32_window_create(struct browser_window *bw,
gw->statusbar = nsws_window_create_statusbar(gw);
gw->drawingarea = nsws_window_create_drawable(hInstance, gw->main, gw);
- LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p", gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
+ LOG("new window: main:%p toolbar:%p statusbar %p drawingarea %p",
+ gw->main, gw->toolbar, gw->statusbar, gw->drawingarea);
font_hwnd = gw->drawingarea;
open_windows++;
@@ -1431,7 +1458,9 @@ win32_window_create(struct browser_window *bw,
/**
- * window cleanup code
+ * Destroy previously created win32 window
+ *
+ * \param w The gui window to destroy.
*/
static void win32_window_destroy(struct gui_window *w)
{
@@ -1453,13 +1482,15 @@ static void win32_window_destroy(struct gui_window *w)
}
-
-
+/**
+ * Cause redraw of part of a win32 window.
+ *
+ * \param gw win32 gui window
+ * \param rect area to redraw
+ */
static void
-win32_window_update_box(struct gui_window *gw, const struct rect *rect)
+win32_window_update(struct gui_window *gw, const struct rect *rect)
{
- /* LOG("gw:%p %f,%f %f,%f", gw, data->redraw.x, data->redraw.y, data->redraw.width, data->redraw.height); */
-
if (gw == NULL)
return;
@@ -1470,17 +1501,25 @@ win32_window_update_box(struct gui_window *gw, const struct rect *rect)
redrawrect.right =(long)rect->x1;
redrawrect.bottom = (long)rect->y1;
- RedrawWindow(gw->drawingarea, &redrawrect, NULL,
+ RedrawWindow(gw->drawingarea,
+ &redrawrect,
+ NULL,
RDW_INVALIDATE | RDW_NOERASE);
-
}
-
-
-
-static void win32_window_get_dimensions(struct gui_window *gw, int *width, int *height,
- bool scaled)
+/**
+ * Find the current dimensions of a win32 browser window's content area.
+ *
+ * \param gw gui_window to measure
+ * \param width receives width of window
+ * \param height receives height of window
+ * \param scaled whether to return scaled values
+ */
+static void
+win32_window_get_dimensions(struct gui_window *gw,
+ int *width, int *height,
+ bool scaled)
{
if (gw == NULL)
return;
@@ -1491,13 +1530,21 @@ static void win32_window_get_dimensions(struct gui_window *gw, int *width, int *
*height = gw->height;
}
+
+/**
+ * Update the extent of the inside of a browser window to that of the
+ * current content.
+ *
+ * \param w gui_window to update the extent of
+ */
static void win32_window_update_extent(struct gui_window *w)
{
}
+
/**
- * callback from core to reformat a window.
+ * callback from core to reformat a win32 window.
*
* \param gw The win32 gui window to reformat.
*/
@@ -1510,9 +1557,9 @@ static void win32_window_reformat(struct gui_window *gw)
/**
- * set window title
+ * set win32 browser window title
*
- * \param w the Windows gui window.
+ * \param w the win32 gui window.
* \param title to set on window
*/
static void win32_window_set_title(struct gui_window *w, const char *title)
@@ -1533,51 +1580,76 @@ static void win32_window_set_title(struct gui_window *w, const char *title)
}
-static nserror win32_window_set_url(struct gui_window *w, nsurl *url)
+/**
+ * Set the navigation url is a win32 browser window.
+ *
+ * \param gw window to update.
+ * \param url The url to use as icon.
+ */
+static nserror win32_window_set_url(struct gui_window *gw, nsurl *url)
{
- SendMessage(w->urlbar, WM_SETTEXT, 0, (LPARAM) nsurl_access(url));
+ SendMessage(gw->urlbar, WM_SETTEXT, 0, (LPARAM) nsurl_access(url));
return NSERROR_OK;
}
/**
- * set the status bar message
+ * Set the status bar of a win32 browser window.
+ *
+ * \param w gui_window to update
+ * \param text new status text
*/
static void win32_window_set_status(struct gui_window *w, const char *text)
{
- if (w == NULL)
+ if (w == NULL) {
return;
+ }
SendMessage(w->statusbar, WM_SETTEXT, 0, (LPARAM)text);
}
/**
- * set the pointer shape
+ * Change the win32 mouse pointer shape
+ *
+ * \param w The gui window to change pointer shape in.
+ * \param shape The new shape to change to.
*/
-static void win32_window_set_pointer(struct gui_window *w,
- gui_pointer_shape shape)
+static void
+win32_window_set_pointer(struct gui_window *w, gui_pointer_shape shape)
{
SetCursor(nsws_get_pointer(shape));
}
/**
- * place caret in window
+ * Give the win32 input focus to a window
+ *
+ * \param w window with caret
+ * \param x coordinates of caret
+ * \param y coordinates of caret
+ * \param height height of caret
+ * \param clip rectangle to clip caret or NULL if none
*/
-static void win32_window_place_caret(struct gui_window *w, int x, int y,
- int height, const struct rect *clip)
+static void
+win32_window_place_caret(struct gui_window *w, int x, int y,
+ int height, const struct rect *clip)
{
- if (w == NULL)
+ if (w == NULL) {
return;
+ }
+
CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height * w->scale);
SetCaretPos(x * w->scale - w->scrollx,
y * w->scale - w->scrolly);
ShowCaret(w->drawingarea);
}
+
/**
- * clear window caret
+ * Remove the win32 input focus from window
+ *
+ * \param g window with caret
*/
static void win32_window_remove_caret(struct gui_window *w)
{
@@ -1587,8 +1659,11 @@ static void win32_window_remove_caret(struct gui_window *w)
}
-
-
+/**
+ * start a win32 navigation throbber.
+ *
+ * \param w window in which to start throbber.
+ */
static void win32_window_start_throbber(struct gui_window *w)
{
if (w == NULL)
@@ -1615,7 +1690,11 @@ static void win32_window_start_throbber(struct gui_window *w)
}
-
+/**
+ * stop a win32 navigation throbber.
+ *
+ * \param w window with throbber to stop
+ */
static void win32_window_stop_throbber(struct gui_window *w)
{
if (w == NULL)
@@ -1645,11 +1724,15 @@ static void win32_window_stop_throbber(struct gui_window *w)
Animate_Seek(w->throbber, 0);
}
+
+/**
+ * win32 frontend browser window handling operation table
+ */
static struct gui_window_table window_table = {
.create = win32_window_create,
.destroy = win32_window_destroy,
.redraw = win32_window_redraw_window,
- .update = win32_window_update_box,
+ .update = win32_window_update,
.get_scroll = win32_window_get_scroll,
.set_scroll = win32_window_set_scroll,
.get_dimensions = win32_window_get_dimensions,
@@ -1668,6 +1751,7 @@ static struct gui_window_table window_table = {
struct gui_window_table *win32_window_table = &window_table;
+
/* exported interface documented in windows/window.h */
struct gui_window *nsws_get_gui_window(HWND hwnd)
{
diff --git a/frontends/windows/window.h b/frontends/windows/window.h
index 047cec6..95c443e 100644
--- a/frontends/windows/window.h
+++ b/frontends/windows/window.h
@@ -74,7 +74,7 @@ struct gui_window {
};
-/**
+/**
* Obtain gui window structure from window handle.
*
* \param hwnd The window handle.
@@ -92,13 +92,19 @@ bool nsws_window_go(HWND hwnd, const char *urltxt);
void win32_window_set_scroll(struct gui_window *w, int sx, int sy);
+/**
+ * Create the main browser window class.
+ *
+ * \param hinstance The application instance
+ * \return NSERROR_OK on success or NSERROR_INIT_FAILED if the class
+ * creation failed.
+ */
nserror nsws_create_main_class(HINSTANCE hinstance);
/**
* Get the main win32 window handle from a gui window
*/
-HWND gui_window_main_window(struct gui_window *);
-
+HWND gui_window_main_window(struct gui_window *gw);
/**
* Get the localhistory win32 window handle from a gui window
diff --git a/include/netsurf/window.h b/include/netsurf/window.h
index 8b3e9c4..b887368 100644
--- a/include/netsurf/window.h
+++ b/include/netsurf/window.h
@@ -71,7 +71,7 @@ enum gui_pointer_shape;
*/
struct gui_window_table {
- /* Mandantory entries */
+ /* Mandatory entries */
/**
* Create and open a gui window for a browsing context.
@@ -161,8 +161,8 @@ struct gui_window_table {
* Reformat a window.
*
* This is used to perform reformats when the page contents
- * require reformating. The reformat is requested using
- * browser_window_schedule_reformat and occours via a scheduled
+ * require reformatting. The reformat is requested using
+ * browser_window_schedule_reformat and occurs via a scheduled
* callback hence from top level context.
*
* \param g gui_window to reformat.
@@ -197,15 +197,18 @@ struct gui_window_table {
void (*set_icon)(struct gui_window *gw, struct hlcache_handle *icon);
/**
- * Set the status bar of a browser window.
+ * Set the status bar message of a browser window.
*
- * \param g gui_window to update
- * \param text new status text
+ * \param g gui_window to update
+ * \param text new status text
*/
void (*set_status)(struct gui_window *g, const char *text);
/**
* Change mouse pointer shape
+ *
+ * \param g The gui window to change pointer shape in.
+ * \param shape The new shape to change to.
*/
void (*set_pointer)(struct gui_window *g, enum gui_pointer_shape shape);
@@ -227,16 +230,38 @@ struct gui_window_table {
*/
void (*remove_caret)(struct gui_window *g);
- /** start the navigation throbber. */
+ /**
+ * start the navigation throbber.
+ *
+ * \param g window in which to start throbber.
+ */
void (*start_throbber)(struct gui_window *g);
- /** stop the navigation throbber. */
+ /**
+ * stop the navigation throbber.
+ *
+ * \param g window with throbber to stop
+ */
void (*stop_throbber)(struct gui_window *g);
- /** start a drag operation within a window */
+ /**
+ * start a drag operation within a window
+ *
+ * \param g window to start drag from.
+ * \param type Type of drag to start
+ * \param rect Confining rectangle of drag operation.
+ * \return true if drag started else false.
+ */
bool (*drag_start)(struct gui_window *g, gui_drag_type type, const struct rect *rect);
- /** save link operation */
+ /**
+ * save link operation
+ *
+ * \param g window to save link from.
+ * \param url The link url.
+ * \param title The title of the link.
+ * \return NSERROR_OK on success else appropriate error code.
+ */
nserror (*save_link)(struct gui_window *g, struct nsurl *url, const char *title);
/**
--
NetSurf Browser
6 years, 11 months
libsvgtiny: branch master updated. release/0.1.4-15-gf854f48
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/f854f48b7e9a5726a0...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/f854f48b7e9a5726a0e6...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/f854f48b7e9a5726a0e6d8...
The branch, master has been updated
via f854f48b7e9a5726a0e6d888a9e72de15d1888ec (commit)
from 4d485643c1a8a36f3127593e992bae197e70048f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=f854f48b7e9a5726...
commit f854f48b7e9a5726a0e6d888a9e72de15d1888ec
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Test data: Move file to correct place.
diff --git a/bad-grad.svg b/bad-grad.svg
deleted file mode 100644
index 4a3d26d..0000000
--- a/bad-grad.svg
+++ /dev/null
@@ -1,10 +0,0 @@
-<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
- <defs>
- <linearGradient id="foo">
- <stop stop-color="#69f" offset="0"/>
- <stop stop-color="#468" offset="1"/>
- </linearGradient>
- </defs>
- <path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
-</svg>
-
diff --git a/test/data/bad-grad.svg b/test/data/bad-grad.svg
new file mode 100644
index 0000000..4a3d26d
--- /dev/null
+++ b/test/data/bad-grad.svg
@@ -0,0 +1,10 @@
+<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="foo">
+ <stop stop-color="#69f" offset="0"/>
+ <stop stop-color="#468" offset="1"/>
+ </linearGradient>
+ </defs>
+ <path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
+</svg>
+
-----------------------------------------------------------------------
Summary of changes:
bad-grad.svg => test/data/bad-grad.svg | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename bad-grad.svg => test/data/bad-grad.svg (100%)
diff --git a/bad-grad.svg b/test/data/bad-grad.svg
similarity index 100%
rename from bad-grad.svg
rename to test/data/bad-grad.svg
--
NetSurf SVG decoder
6 years, 11 months
libsvgtiny: branch master updated. release/0.1.4-14-g4d48564
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/4d485643c1a8a36f31...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/4d485643c1a8a36f3127...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/4d485643c1a8a36f312759...
The branch, master has been updated
via 4d485643c1a8a36f3127593e992bae197e70048f (commit)
via 2ec1f74153c4a53252bdeee55e0fde14706ca598 (commit)
via 1d2996a366f1b34ff114319087cf1989c96dc398 (commit)
via 1e71d0472529b96ac35e2e4425b66e29146a01c1 (commit)
via 0f0342a4416a5b3bb03fe80d428d73a431f03a76 (commit)
via 059c01c90f5d3e64287853293097f56b8ca8ec1d (commit)
from 28ef4f0a47dcb9e257ce3b6f088d3ae09d65c2b5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=4d485643c1a8a36f...
commit 4d485643c1a8a36f3127593e992bae197e70048f
Merge: 28ef4f0 2ec1f74
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Merge branch 'tlsa/fix-gradients'
-----------------------------------------------------------------------
Summary of changes:
bad-grad.svg | 10 ++++
src/svgtiny.c | 111 ++++++++++++++++++++++----------------
src/svgtiny_gradient.c | 140 +++++++++++++++++++++++++-----------------------
src/svgtiny_internal.h | 24 ++++++---
4 files changed, 165 insertions(+), 120 deletions(-)
create mode 100644 bad-grad.svg
diff --git a/bad-grad.svg b/bad-grad.svg
new file mode 100644
index 0000000..4a3d26d
--- /dev/null
+++ b/bad-grad.svg
@@ -0,0 +1,10 @@
+<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="foo">
+ <stop stop-color="#69f" offset="0"/>
+ <stop stop-color="#468" offset="1"/>
+ </linearGradient>
+ </defs>
+ <path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
+</svg>
+
diff --git a/src/svgtiny.c b/src/svgtiny.c
index bd9aeaa..4661a58 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -54,54 +54,74 @@ static void svgtiny_parse_transform_attributes(dom_element *node,
static svgtiny_code svgtiny_add_path(float *p, unsigned int n,
struct svgtiny_parse_state *state);
static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
/**
- * Set the local externally-stored parts of a parse state.
- * Call this in functions that made a new state on the stack.
- * Doesn't make own copy of global state, such as the interned string list.
+ * Call this to ref the strings in a gradient state.
*/
-static void svgtiny_setup_state_local(struct svgtiny_parse_state *state)
+static void svgtiny_grad_string_ref(struct svgtiny_parse_state_gradient *grad)
{
- if (state->gradient_x1 != NULL) {
- dom_string_ref(state->gradient_x1);
+ if (grad->gradient_x1 != NULL) {
+ dom_string_ref(grad->gradient_x1);
}
- if (state->gradient_y1 != NULL) {
- dom_string_ref(state->gradient_y1);
+ if (grad->gradient_y1 != NULL) {
+ dom_string_ref(grad->gradient_y1);
}
- if (state->gradient_x2 != NULL) {
- dom_string_ref(state->gradient_x2);
+ if (grad->gradient_x2 != NULL) {
+ dom_string_ref(grad->gradient_x2);
}
- if (state->gradient_y2 != NULL) {
- dom_string_ref(state->gradient_y2);
+ if (grad->gradient_y2 != NULL) {
+ dom_string_ref(grad->gradient_y2);
}
}
/**
- * Cleanup the local externally-stored parts of a parse state.
- * Call this in functions that made a new state on the stack.
- * Doesn't cleanup global state, such as the interned string list.
+ * Call this to clean up the strings in a gradient state.
*/
-static void svgtiny_cleanup_state_local(struct svgtiny_parse_state *state)
+static void svgtiny_grad_string_cleanup(
+ struct svgtiny_parse_state_gradient *grad)
{
- if (state->gradient_x1 != NULL) {
- dom_string_unref(state->gradient_x1);
- state->gradient_x1 = NULL;
+ if (grad->gradient_x1 != NULL) {
+ dom_string_unref(grad->gradient_x1);
+ grad->gradient_x1 = NULL;
}
- if (state->gradient_y1 != NULL) {
- dom_string_unref(state->gradient_y1);
- state->gradient_y1 = NULL;
+ if (grad->gradient_y1 != NULL) {
+ dom_string_unref(grad->gradient_y1);
+ grad->gradient_y1 = NULL;
}
- if (state->gradient_x2 != NULL) {
- dom_string_unref(state->gradient_x2);
- state->gradient_x2 = NULL;
+ if (grad->gradient_x2 != NULL) {
+ dom_string_unref(grad->gradient_x2);
+ grad->gradient_x2 = NULL;
}
- if (state->gradient_y2 != NULL) {
- dom_string_unref(state->gradient_y2);
- state->gradient_y2 = NULL;
+ if (grad->gradient_y2 != NULL) {
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_y2 = NULL;
}
}
+/**
+ * Set the local externally-stored parts of a parse state.
+ * Call this in functions that made a new state on the stack.
+ * Doesn't make own copy of global state, such as the interned string list.
+ */
+static void svgtiny_setup_state_local(struct svgtiny_parse_state *state)
+{
+ svgtiny_grad_string_ref(&(state->fill_grad));
+ svgtiny_grad_string_ref(&(state->stroke_grad));
+}
+
+/**
+ * Cleanup the local externally-stored parts of a parse state.
+ * Call this in functions that made a new state on the stack.
+ * Doesn't cleanup global state, such as the interned string list.
+ */
+static void svgtiny_cleanup_state_local(struct svgtiny_parse_state *state)
+{
+ svgtiny_grad_string_cleanup(&(state->fill_grad));
+ svgtiny_grad_string_cleanup(&(state->stroke_grad));
+}
+
/**
* Create a new svgtiny_diagram structure.
@@ -152,11 +172,6 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
UNUSED(url);
- state.gradient_x1 = NULL;
- state.gradient_y1 = NULL;
- state.gradient_x2 = NULL;
- state.gradient_y2 = NULL;
-
parser = dom_xml_parser_create(NULL, NULL,
ignore_msg, NULL, &document);
@@ -253,7 +268,6 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
state.fill = 0x000000;
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
- state.linear_gradient_stop_count = 0;
/* parse tree */
code = svgtiny_parse_svg(svg, state);
@@ -1370,13 +1384,13 @@ void svgtiny_parse_paint_attributes(dom_element *node,
exc = dom_element_get_attribute(node, state->interned_fill, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &state->fill, state);
+ svgtiny_parse_color(attr, &state->fill, &state->fill_grad, state);
dom_string_unref(attr);
}
exc = dom_element_get_attribute(node, state->interned_stroke, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &state->stroke, state);
+ svgtiny_parse_color(attr, &state->stroke, &state->stroke_grad, state);
dom_string_unref(attr);
}
@@ -1398,7 +1412,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
while (*s == ' ')
s++;
value = strndup(s, strcspn(s, "; "));
- _svgtiny_parse_color(value, &state->fill, state);
+ _svgtiny_parse_color(value, &state->fill, &state->fill_grad, state);
free(value);
}
if ((s = strstr(style, "stroke:"))) {
@@ -1406,7 +1420,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
while (*s == ' ')
s++;
value = strndup(s, strcspn(s, "; "));
- _svgtiny_parse_color(value, &state->stroke, state);
+ _svgtiny_parse_color(value, &state->stroke, &state->stroke_grad, state);
free(value);
}
if ((s = strstr(style, "stroke-width:"))) {
@@ -1429,6 +1443,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
*/
static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
unsigned int r, g, b;
@@ -1460,19 +1475,21 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
} else if (5 < len && s[0] == 'u' && s[1] == 'r' && s[2] == 'l' &&
s[3] == '(') {
- if (s[4] == '#') {
+ if (grad == NULL) {
+ *c = svgtiny_RGB(0, 0, 0);
+ } else if (s[4] == '#') {
id = strdup(s + 5);
if (!id)
return;
rparen = strchr(id, ')');
if (rparen)
*rparen = 0;
- svgtiny_find_gradient(id, state);
+ svgtiny_find_gradient(id, grad, state);
free(id);
- if (state->linear_gradient_stop_count == 0)
+ if (grad->linear_gradient_stop_count == 0)
*c = svgtiny_TRANSPARENT;
- else if (state->linear_gradient_stop_count == 1)
- *c = state->gradient_stop[0].color;
+ else if (grad->linear_gradient_stop_count == 1)
+ *c = grad->gradient_stop[0].color;
else
*c = svgtiny_LINEAR_GRADIENT;
}
@@ -1486,11 +1503,12 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
}
void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
- char *ss = strndup(dom_string_data(s), dom_string_byte_length(s));
- _svgtiny_parse_color(ss, c, state);
- free(ss);
+ dom_string_ref(s);
+ _svgtiny_parse_color(dom_string_data(s), c, grad, state);
+ dom_string_unref(s);
}
/**
@@ -1571,6 +1589,7 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb,
a = d = 1;
b = c = 0;
e = f = 0;
+ n = 0;
if ((sscanf(s, " matrix (%f %f %f %f %f %f ) %n",
&a, &b, &c, &d, &e, &f, &n) == 6) && (n > 0))
;
diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c
index c36df32..b282f45 100644
--- a/src/svgtiny_gradient.c
+++ b/src/svgtiny_gradient.c
@@ -17,6 +17,7 @@
#undef GRADIENT_DEBUG
static svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
static float svgtiny_parse_gradient_offset(const char *s);
static void svgtiny_path_bbox(float *p, unsigned int n,
@@ -28,7 +29,9 @@ static void svgtiny_invert_matrix(float *m, float *inv);
* Find a gradient by id and parse it.
*/
-void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
+void svgtiny_find_gradient(const char *id,
+ struct svgtiny_parse_state_gradient *grad,
+ struct svgtiny_parse_state *state)
{
dom_element *gradient;
dom_string *id_str, *name;
@@ -38,26 +41,26 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
fprintf(stderr, "svgtiny_find_gradient: id \"%s\"\n", id);
#endif
- state->linear_gradient_stop_count = 0;
- if (state->gradient_x1 != NULL)
- dom_string_unref(state->gradient_x1);
- if (state->gradient_y1 != NULL)
- dom_string_unref(state->gradient_y1);
- if (state->gradient_x2 != NULL)
- dom_string_unref(state->gradient_x2);
- if (state->gradient_y2 != NULL)
- dom_string_unref(state->gradient_y2);
- state->gradient_x1 = dom_string_ref(state->interned_zero_percent);
- state->gradient_y1 = dom_string_ref(state->interned_zero_percent);
- state->gradient_x2 = dom_string_ref(state->interned_hundred_percent);
- state->gradient_y2 = dom_string_ref(state->interned_zero_percent);
- state->gradient_user_space_on_use = false;
- state->gradient_transform.a = 1;
- state->gradient_transform.b = 0;
- state->gradient_transform.c = 0;
- state->gradient_transform.d = 1;
- state->gradient_transform.e = 0;
- state->gradient_transform.f = 0;
+ grad->linear_gradient_stop_count = 0;
+ if (grad->gradient_x1 != NULL)
+ dom_string_unref(grad->gradient_x1);
+ if (grad->gradient_y1 != NULL)
+ dom_string_unref(grad->gradient_y1);
+ if (grad->gradient_x2 != NULL)
+ dom_string_unref(grad->gradient_x2);
+ if (grad->gradient_y2 != NULL)
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_x1 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_y1 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_x2 = dom_string_ref(state->interned_hundred_percent);
+ grad->gradient_y2 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_user_space_on_use = false;
+ grad->gradient_transform.a = 1;
+ grad->gradient_transform.b = 0;
+ grad->gradient_transform.c = 0;
+ grad->gradient_transform.d = 1;
+ grad->gradient_transform.e = 0;
+ grad->gradient_transform.f = 0;
exc = dom_string_create_interned((const uint8_t *) id,
strlen(id), &id_str);
@@ -81,14 +84,14 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
}
if (dom_string_isequal(name, state->interned_linearGradient))
- svgtiny_parse_linear_gradient(gradient, state);
+ svgtiny_parse_linear_gradient(gradient, grad, state);
dom_node_unref(gradient);
dom_string_unref(name);
#ifdef GRADIENT_DEBUG
fprintf(stderr, "linear_gradient_stop_count %i\n",
- state->linear_gradient_stop_count);
+ grad->linear_gradient_stop_count);
#endif
}
@@ -100,6 +103,7 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
*/
svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
unsigned int i = 0;
@@ -112,7 +116,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
if (dom_string_data(attr)[0] == (uint8_t) '#') {
char *s = strndup(dom_string_data(attr) + 1,
dom_string_byte_length(attr) - 1);
- svgtiny_find_gradient(s, state);
+ svgtiny_find_gradient(s, grad, state);
free(s);
}
dom_string_unref(attr);
@@ -120,36 +124,36 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
exc = dom_element_get_attribute(linear, state->interned_x1, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_x1);
- state->gradient_x1 = attr;
+ dom_string_unref(grad->gradient_x1);
+ grad->gradient_x1 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_y1, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_y1);
- state->gradient_y1 = attr;
+ dom_string_unref(grad->gradient_y1);
+ grad->gradient_y1 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_x2, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_x2);
- state->gradient_x2 = attr;
+ dom_string_unref(grad->gradient_x2);
+ grad->gradient_x2 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_y2, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_y2);
- state->gradient_y2 = attr;
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_y2 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_gradientUnits,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- state->gradient_user_space_on_use =
+ grad->gradient_user_space_on_use =
dom_string_isequal(attr,
state->interned_userSpaceOnUse);
dom_string_unref(attr);
@@ -172,12 +176,12 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
fprintf(stderr, "transform %g %g %g %g %g %g\n",
a, b, c, d, e, f);
#endif
- state->gradient_transform.a = a;
- state->gradient_transform.b = b;
- state->gradient_transform.c = c;
- state->gradient_transform.d = d;
- state->gradient_transform.e = e;
- state->gradient_transform.f = f;
+ grad->gradient_transform.a = a;
+ grad->gradient_transform.b = b;
+ grad->gradient_transform.c = c;
+ grad->gradient_transform.d = d;
+ grad->gradient_transform.e = e;
+ grad->gradient_transform.f = f;
dom_string_unref(attr);
}
@@ -214,7 +218,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
state->interned_stop_color,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &color, state);
+ svgtiny_parse_color(attr, &color, NULL, state);
dom_string_unref(attr);
}
exc = dom_element_get_attribute(stop,
@@ -237,6 +241,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
value != NULL) {
svgtiny_parse_color(value,
&color,
+ NULL,
state);
dom_string_unref(value);
}
@@ -248,8 +253,8 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
#ifdef GRADIENT_DEBUG
fprintf(stderr, "stop %g %x\n", offset, color);
#endif
- state->gradient_stop[i].offset = offset;
- state->gradient_stop[i].color = color;
+ grad->gradient_stop[i].offset = offset;
+ grad->gradient_stop[i].color = color;
i++;
}
dom_node_unref(stop);
@@ -259,9 +264,9 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
dom_nodelist_unref(stops);
}
-no_more_stops:
+no_more_stops:
if (i > 0)
- state->linear_gradient_stop_count = i;
+ grad->linear_gradient_stop_count = i;
return svgtiny_OK;
}
@@ -318,6 +323,10 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
float current_stop_r;
int red0, green0, blue0, red1, green1, blue1;
unsigned int t, a, b;
+ struct svgtiny_parse_state_gradient *grad;
+
+ assert(state->fill == svgtiny_LINEAR_GRADIENT);
+ grad = &state->fill_grad;
/* determine object bounding box */
svgtiny_path_bbox(p, n, &object_x0, &object_y0, &object_x1, &object_y1);
@@ -326,27 +335,27 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
object_x0, object_y0, object_x1, object_y1);
#endif
- if (!state->gradient_user_space_on_use) {
+ if (!grad->gradient_user_space_on_use) {
gradient_x0 = object_x0 +
- svgtiny_parse_length(state->gradient_x1,
+ svgtiny_parse_length(grad->gradient_x1,
object_x1 - object_x0, *state);
gradient_y0 = object_y0 +
- svgtiny_parse_length(state->gradient_y1,
+ svgtiny_parse_length(grad->gradient_y1,
object_y1 - object_y0, *state);
gradient_x1 = object_x0 +
- svgtiny_parse_length(state->gradient_x2,
+ svgtiny_parse_length(grad->gradient_x2,
object_x1 - object_x0, *state);
gradient_y1 = object_y0 +
- svgtiny_parse_length(state->gradient_y2,
+ svgtiny_parse_length(grad->gradient_y2,
object_y1 - object_y0, *state);
} else {
- gradient_x0 = svgtiny_parse_length(state->gradient_x1,
+ gradient_x0 = svgtiny_parse_length(grad->gradient_x1,
state->viewport_width, *state);
- gradient_y0 = svgtiny_parse_length(state->gradient_y1,
+ gradient_y0 = svgtiny_parse_length(grad->gradient_y1,
state->viewport_height, *state);
- gradient_x1 = svgtiny_parse_length(state->gradient_x2,
+ gradient_x1 = svgtiny_parse_length(grad->gradient_x2,
state->viewport_width, *state);
- gradient_y1 = svgtiny_parse_length(state->gradient_y2,
+ gradient_y1 = svgtiny_parse_length(grad->gradient_y2,
state->viewport_height, *state);
}
gradient_dx = gradient_x1 - gradient_x0;
@@ -399,7 +408,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
}*/
/* invert gradient transform for applying to vertices */
- svgtiny_invert_matrix(&state->gradient_transform.a, trans);
+ svgtiny_invert_matrix(&grad->gradient_transform.a, trans);
#ifdef GRADIENT_DEBUG
fprintf(stderr, "inverse transform %g %g %g %g %g %g\n",
trans[0], trans[1], trans[2], trans[3],
@@ -547,14 +556,14 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
}
/* render triangles */
- stop_count = state->linear_gradient_stop_count;
+ stop_count = grad->linear_gradient_stop_count;
assert(2 <= stop_count);
current_stop = 0;
last_stop_r = 0;
- current_stop_r = state->gradient_stop[0].offset;
- red0 = red1 = svgtiny_RED(state->gradient_stop[0].color);
- green0 = green1 = svgtiny_GREEN(state->gradient_stop[0].color);
- blue0 = blue1 = svgtiny_BLUE(state->gradient_stop[0].color);
+ current_stop_r = grad->gradient_stop[0].offset;
+ red0 = red1 = svgtiny_RED(grad->gradient_stop[0].color);
+ green0 = green1 = svgtiny_GREEN(grad->gradient_stop[0].color);
+ blue0 = blue1 = svgtiny_BLUE(grad->gradient_stop[0].color);
t = min_pt;
a = (min_pt + 1) % svgtiny_list_size(pts);
b = min_pt == 0 ? svgtiny_list_size(pts) - 1 : min_pt - 1;
@@ -576,14 +585,14 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
red0 = red1;
green0 = green1;
blue0 = blue1;
- red1 = svgtiny_RED(state->
+ red1 = svgtiny_RED(grad->
gradient_stop[current_stop].color);
- green1 = svgtiny_GREEN(state->
+ green1 = svgtiny_GREEN(grad->
gradient_stop[current_stop].color);
- blue1 = svgtiny_BLUE(state->
+ blue1 = svgtiny_BLUE(grad->
gradient_stop[current_stop].color);
last_stop_r = current_stop_r;
- current_stop_r = state->
+ current_stop_r = grad->
gradient_stop[current_stop].offset;
}
p = malloc(10 * sizeof p[0]);
@@ -609,10 +618,9 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
shape->path_length = 10;
/*shape->fill = svgtiny_TRANSPARENT;*/
if (current_stop == 0)
- shape->fill = state->gradient_stop[0].color;
+ shape->fill = grad->gradient_stop[0].color;
else if (current_stop == stop_count)
- shape->fill = state->
- gradient_stop[stop_count - 1].color;
+ shape->fill = grad->gradient_stop[stop_count - 1].color;
else {
float stop_r = (mean_r - last_stop_r) /
(current_stop_r - last_stop_r);
diff --git a/src/svgtiny_internal.h b/src/svgtiny_internal.h
index 542a0d0..158d230 100644
--- a/src/svgtiny_internal.h
+++ b/src/svgtiny_internal.h
@@ -24,6 +24,16 @@ struct svgtiny_gradient_stop {
#define svgtiny_MAX_STOPS 10
#define svgtiny_LINEAR_GRADIENT 0x2000000
+struct svgtiny_parse_state_gradient {
+ unsigned int linear_gradient_stop_count;
+ dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
+ struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
+ bool gradient_user_space_on_use;
+ struct {
+ float a, b, c, d, e, f;
+ } gradient_transform;
+};
+
struct svgtiny_parse_state {
struct svgtiny_diagram *diagram;
dom_document *document;
@@ -44,13 +54,8 @@ struct svgtiny_parse_state {
int stroke_width;
/* gradients */
- unsigned int linear_gradient_stop_count;
- dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
- struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
- bool gradient_user_space_on_use;
- struct {
- float a, b, c, d, e, f;
- } gradient_transform;
+ struct svgtiny_parse_state_gradient fill_grad;
+ struct svgtiny_parse_state_gradient stroke_grad;
/* Interned strings */
#define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
@@ -65,6 +70,7 @@ struct svgtiny_list;
float svgtiny_parse_length(dom_string *s, int viewport_size,
const struct svgtiny_parse_state state);
void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
void svgtiny_parse_transform(char *s, float *ma, float *mb,
float *mc, float *md, float *me, float *mf);
@@ -80,7 +86,9 @@ char *svgtiny_strndup(const char *s, size_t n);
#endif
/* svgtiny_gradient.c */
-void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);
+void svgtiny_find_gradient(const char *id,
+ struct svgtiny_parse_state_gradient *grad,
+ struct svgtiny_parse_state *state);
svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
struct svgtiny_parse_state *state);
--
NetSurf SVG decoder
6 years, 11 months
libsvgtiny: branch tlsa/fix-gradients updated. release/0.1.4-13-g2ec1f74
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/2ec1f74153c4a53252...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/2ec1f74153c4a53252bd...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/2ec1f74153c4a53252bdee...
The branch, tlsa/fix-gradients has been updated
via 2ec1f74153c4a53252bdeee55e0fde14706ca598 (commit)
from 1d2996a366f1b34ff114319087cf1989c96dc398 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=2ec1f74153c4a532...
commit 2ec1f74153c4a53252bdeee55e0fde14706ca598
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Test data: Add SVG with missing stroke gradient definition.
diff --git a/bad-grad.svg b/bad-grad.svg
new file mode 100644
index 0000000..4a3d26d
--- /dev/null
+++ b/bad-grad.svg
@@ -0,0 +1,10 @@
+<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="foo">
+ <stop stop-color="#69f" offset="0"/>
+ <stop stop-color="#468" offset="1"/>
+ </linearGradient>
+ </defs>
+ <path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
+</svg>
+
-----------------------------------------------------------------------
Summary of changes:
bad-grad.svg | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 bad-grad.svg
diff --git a/bad-grad.svg b/bad-grad.svg
new file mode 100644
index 0000000..4a3d26d
--- /dev/null
+++ b/bad-grad.svg
@@ -0,0 +1,10 @@
+<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="foo">
+ <stop stop-color="#69f" offset="0"/>
+ <stop stop-color="#468" offset="1"/>
+ </linearGradient>
+ </defs>
+ <path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
+</svg>
+
--
NetSurf SVG decoder
6 years, 11 months
libsvgtiny: branch tlsa/fix-gradients updated. release/0.1.4-12-g1d2996a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/1d2996a366f1b34ff1...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/1d2996a366f1b34ff114...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/1d2996a366f1b34ff11431...
The branch, tlsa/fix-gradients has been updated
via 1d2996a366f1b34ff114319087cf1989c96dc398 (commit)
from 1e71d0472529b96ac35e2e4425b66e29146a01c1 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=1d2996a366f1b34f...
commit 1d2996a366f1b34ff114319087cf1989c96dc398
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Parse: Ensure consumed characters count is initiliased.
diff --git a/src/svgtiny.c b/src/svgtiny.c
index efac788..4661a58 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -1589,6 +1589,7 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb,
a = d = 1;
b = c = 0;
e = f = 0;
+ n = 0;
if ((sscanf(s, " matrix (%f %f %f %f %f %f ) %n",
&a, &b, &c, &d, &e, &f, &n) == 6) && (n > 0))
;
-----------------------------------------------------------------------
Summary of changes:
src/svgtiny.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/svgtiny.c b/src/svgtiny.c
index efac788..4661a58 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -1589,6 +1589,7 @@ void svgtiny_parse_transform(char *s, float *ma, float *mb,
a = d = 1;
b = c = 0;
e = f = 0;
+ n = 0;
if ((sscanf(s, " matrix (%f %f %f %f %f %f ) %n",
&a, &b, &c, &d, &e, &f, &n) == 6) && (n > 0))
;
--
NetSurf SVG decoder
6 years, 11 months
libsvgtiny: branch tlsa/fix-gradients created. release/0.1.4-11-g1e71d04
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libsvgtiny.git/shortlog/1e71d0472529b96ac3...
...commit http://git.netsurf-browser.org/libsvgtiny.git/commit/1e71d0472529b96ac35e...
...tree http://git.netsurf-browser.org/libsvgtiny.git/tree/1e71d0472529b96ac35e2e...
The branch, tlsa/fix-gradients has been created
at 1e71d0472529b96ac35e2e4425b66e29146a01c1 (commit)
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=1e71d0472529b96a...
commit 1e71d0472529b96ac35e2e4425b66e29146a01c1
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Parse: Make the parse state have two sets of gradient details.
One for fills and another for strokes. This stops an SVG such as
<svg viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="foo">
<stop stop-color="#69f" offset="0"/>
<stop stop-color="#468" offset="1"/>
</linearGradient>
</defs>
<path fill="url(#foo)" stroke='url(#bar)' d='M10 10 H 90 V 90 H 10 Z' />
</svg>
from getting its fill gradient details trampled when we reset the
gradient for the the missing bar gadient definition. Note, we only
handle linearGradient on the fill anyway.
diff --git a/src/svgtiny.c b/src/svgtiny.c
index 76df69a..efac788 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -54,54 +54,74 @@ static void svgtiny_parse_transform_attributes(dom_element *node,
static svgtiny_code svgtiny_add_path(float *p, unsigned int n,
struct svgtiny_parse_state *state);
static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
/**
- * Set the local externally-stored parts of a parse state.
- * Call this in functions that made a new state on the stack.
- * Doesn't make own copy of global state, such as the interned string list.
+ * Call this to ref the strings in a gradient state.
*/
-static void svgtiny_setup_state_local(struct svgtiny_parse_state *state)
+static void svgtiny_grad_string_ref(struct svgtiny_parse_state_gradient *grad)
{
- if (state->gradient_x1 != NULL) {
- dom_string_ref(state->gradient_x1);
+ if (grad->gradient_x1 != NULL) {
+ dom_string_ref(grad->gradient_x1);
}
- if (state->gradient_y1 != NULL) {
- dom_string_ref(state->gradient_y1);
+ if (grad->gradient_y1 != NULL) {
+ dom_string_ref(grad->gradient_y1);
}
- if (state->gradient_x2 != NULL) {
- dom_string_ref(state->gradient_x2);
+ if (grad->gradient_x2 != NULL) {
+ dom_string_ref(grad->gradient_x2);
}
- if (state->gradient_y2 != NULL) {
- dom_string_ref(state->gradient_y2);
+ if (grad->gradient_y2 != NULL) {
+ dom_string_ref(grad->gradient_y2);
}
}
/**
- * Cleanup the local externally-stored parts of a parse state.
- * Call this in functions that made a new state on the stack.
- * Doesn't cleanup global state, such as the interned string list.
+ * Call this to clean up the strings in a gradient state.
*/
-static void svgtiny_cleanup_state_local(struct svgtiny_parse_state *state)
+static void svgtiny_grad_string_cleanup(
+ struct svgtiny_parse_state_gradient *grad)
{
- if (state->gradient_x1 != NULL) {
- dom_string_unref(state->gradient_x1);
- state->gradient_x1 = NULL;
+ if (grad->gradient_x1 != NULL) {
+ dom_string_unref(grad->gradient_x1);
+ grad->gradient_x1 = NULL;
}
- if (state->gradient_y1 != NULL) {
- dom_string_unref(state->gradient_y1);
- state->gradient_y1 = NULL;
+ if (grad->gradient_y1 != NULL) {
+ dom_string_unref(grad->gradient_y1);
+ grad->gradient_y1 = NULL;
}
- if (state->gradient_x2 != NULL) {
- dom_string_unref(state->gradient_x2);
- state->gradient_x2 = NULL;
+ if (grad->gradient_x2 != NULL) {
+ dom_string_unref(grad->gradient_x2);
+ grad->gradient_x2 = NULL;
}
- if (state->gradient_y2 != NULL) {
- dom_string_unref(state->gradient_y2);
- state->gradient_y2 = NULL;
+ if (grad->gradient_y2 != NULL) {
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_y2 = NULL;
}
}
+/**
+ * Set the local externally-stored parts of a parse state.
+ * Call this in functions that made a new state on the stack.
+ * Doesn't make own copy of global state, such as the interned string list.
+ */
+static void svgtiny_setup_state_local(struct svgtiny_parse_state *state)
+{
+ svgtiny_grad_string_ref(&(state->fill_grad));
+ svgtiny_grad_string_ref(&(state->stroke_grad));
+}
+
+/**
+ * Cleanup the local externally-stored parts of a parse state.
+ * Call this in functions that made a new state on the stack.
+ * Doesn't cleanup global state, such as the interned string list.
+ */
+static void svgtiny_cleanup_state_local(struct svgtiny_parse_state *state)
+{
+ svgtiny_grad_string_cleanup(&(state->fill_grad));
+ svgtiny_grad_string_cleanup(&(state->stroke_grad));
+}
+
/**
* Create a new svgtiny_diagram structure.
@@ -248,7 +268,6 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
state.fill = 0x000000;
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
- state.linear_gradient_stop_count = 0;
/* parse tree */
code = svgtiny_parse_svg(svg, state);
@@ -1365,13 +1384,13 @@ void svgtiny_parse_paint_attributes(dom_element *node,
exc = dom_element_get_attribute(node, state->interned_fill, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &state->fill, state);
+ svgtiny_parse_color(attr, &state->fill, &state->fill_grad, state);
dom_string_unref(attr);
}
exc = dom_element_get_attribute(node, state->interned_stroke, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &state->stroke, state);
+ svgtiny_parse_color(attr, &state->stroke, &state->stroke_grad, state);
dom_string_unref(attr);
}
@@ -1393,7 +1412,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
while (*s == ' ')
s++;
value = strndup(s, strcspn(s, "; "));
- _svgtiny_parse_color(value, &state->fill, state);
+ _svgtiny_parse_color(value, &state->fill, &state->fill_grad, state);
free(value);
}
if ((s = strstr(style, "stroke:"))) {
@@ -1401,7 +1420,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
while (*s == ' ')
s++;
value = strndup(s, strcspn(s, "; "));
- _svgtiny_parse_color(value, &state->stroke, state);
+ _svgtiny_parse_color(value, &state->stroke, &state->stroke_grad, state);
free(value);
}
if ((s = strstr(style, "stroke-width:"))) {
@@ -1424,6 +1443,7 @@ void svgtiny_parse_paint_attributes(dom_element *node,
*/
static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
unsigned int r, g, b;
@@ -1455,19 +1475,21 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
} else if (5 < len && s[0] == 'u' && s[1] == 'r' && s[2] == 'l' &&
s[3] == '(') {
- if (s[4] == '#') {
+ if (grad == NULL) {
+ *c = svgtiny_RGB(0, 0, 0);
+ } else if (s[4] == '#') {
id = strdup(s + 5);
if (!id)
return;
rparen = strchr(id, ')');
if (rparen)
*rparen = 0;
- svgtiny_find_gradient(id, state);
+ svgtiny_find_gradient(id, grad, state);
free(id);
- if (state->linear_gradient_stop_count == 0)
+ if (grad->linear_gradient_stop_count == 0)
*c = svgtiny_TRANSPARENT;
- else if (state->linear_gradient_stop_count == 1)
- *c = state->gradient_stop[0].color;
+ else if (grad->linear_gradient_stop_count == 1)
+ *c = grad->gradient_stop[0].color;
else
*c = svgtiny_LINEAR_GRADIENT;
}
@@ -1481,10 +1503,11 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
}
void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
dom_string_ref(s);
- _svgtiny_parse_color(dom_string_data(s), c, state);
+ _svgtiny_parse_color(dom_string_data(s), c, grad, state);
dom_string_unref(s);
}
diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c
index c36df32..b282f45 100644
--- a/src/svgtiny_gradient.c
+++ b/src/svgtiny_gradient.c
@@ -17,6 +17,7 @@
#undef GRADIENT_DEBUG
static svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
static float svgtiny_parse_gradient_offset(const char *s);
static void svgtiny_path_bbox(float *p, unsigned int n,
@@ -28,7 +29,9 @@ static void svgtiny_invert_matrix(float *m, float *inv);
* Find a gradient by id and parse it.
*/
-void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
+void svgtiny_find_gradient(const char *id,
+ struct svgtiny_parse_state_gradient *grad,
+ struct svgtiny_parse_state *state)
{
dom_element *gradient;
dom_string *id_str, *name;
@@ -38,26 +41,26 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
fprintf(stderr, "svgtiny_find_gradient: id \"%s\"\n", id);
#endif
- state->linear_gradient_stop_count = 0;
- if (state->gradient_x1 != NULL)
- dom_string_unref(state->gradient_x1);
- if (state->gradient_y1 != NULL)
- dom_string_unref(state->gradient_y1);
- if (state->gradient_x2 != NULL)
- dom_string_unref(state->gradient_x2);
- if (state->gradient_y2 != NULL)
- dom_string_unref(state->gradient_y2);
- state->gradient_x1 = dom_string_ref(state->interned_zero_percent);
- state->gradient_y1 = dom_string_ref(state->interned_zero_percent);
- state->gradient_x2 = dom_string_ref(state->interned_hundred_percent);
- state->gradient_y2 = dom_string_ref(state->interned_zero_percent);
- state->gradient_user_space_on_use = false;
- state->gradient_transform.a = 1;
- state->gradient_transform.b = 0;
- state->gradient_transform.c = 0;
- state->gradient_transform.d = 1;
- state->gradient_transform.e = 0;
- state->gradient_transform.f = 0;
+ grad->linear_gradient_stop_count = 0;
+ if (grad->gradient_x1 != NULL)
+ dom_string_unref(grad->gradient_x1);
+ if (grad->gradient_y1 != NULL)
+ dom_string_unref(grad->gradient_y1);
+ if (grad->gradient_x2 != NULL)
+ dom_string_unref(grad->gradient_x2);
+ if (grad->gradient_y2 != NULL)
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_x1 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_y1 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_x2 = dom_string_ref(state->interned_hundred_percent);
+ grad->gradient_y2 = dom_string_ref(state->interned_zero_percent);
+ grad->gradient_user_space_on_use = false;
+ grad->gradient_transform.a = 1;
+ grad->gradient_transform.b = 0;
+ grad->gradient_transform.c = 0;
+ grad->gradient_transform.d = 1;
+ grad->gradient_transform.e = 0;
+ grad->gradient_transform.f = 0;
exc = dom_string_create_interned((const uint8_t *) id,
strlen(id), &id_str);
@@ -81,14 +84,14 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
}
if (dom_string_isequal(name, state->interned_linearGradient))
- svgtiny_parse_linear_gradient(gradient, state);
+ svgtiny_parse_linear_gradient(gradient, grad, state);
dom_node_unref(gradient);
dom_string_unref(name);
#ifdef GRADIENT_DEBUG
fprintf(stderr, "linear_gradient_stop_count %i\n",
- state->linear_gradient_stop_count);
+ grad->linear_gradient_stop_count);
#endif
}
@@ -100,6 +103,7 @@ void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state)
*/
svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state)
{
unsigned int i = 0;
@@ -112,7 +116,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
if (dom_string_data(attr)[0] == (uint8_t) '#') {
char *s = strndup(dom_string_data(attr) + 1,
dom_string_byte_length(attr) - 1);
- svgtiny_find_gradient(s, state);
+ svgtiny_find_gradient(s, grad, state);
free(s);
}
dom_string_unref(attr);
@@ -120,36 +124,36 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
exc = dom_element_get_attribute(linear, state->interned_x1, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_x1);
- state->gradient_x1 = attr;
+ dom_string_unref(grad->gradient_x1);
+ grad->gradient_x1 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_y1, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_y1);
- state->gradient_y1 = attr;
+ dom_string_unref(grad->gradient_y1);
+ grad->gradient_y1 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_x2, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_x2);
- state->gradient_x2 = attr;
+ dom_string_unref(grad->gradient_x2);
+ grad->gradient_x2 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_y2, &attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- dom_string_unref(state->gradient_y2);
- state->gradient_y2 = attr;
+ dom_string_unref(grad->gradient_y2);
+ grad->gradient_y2 = attr;
attr = NULL;
}
exc = dom_element_get_attribute(linear, state->interned_gradientUnits,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- state->gradient_user_space_on_use =
+ grad->gradient_user_space_on_use =
dom_string_isequal(attr,
state->interned_userSpaceOnUse);
dom_string_unref(attr);
@@ -172,12 +176,12 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
fprintf(stderr, "transform %g %g %g %g %g %g\n",
a, b, c, d, e, f);
#endif
- state->gradient_transform.a = a;
- state->gradient_transform.b = b;
- state->gradient_transform.c = c;
- state->gradient_transform.d = d;
- state->gradient_transform.e = e;
- state->gradient_transform.f = f;
+ grad->gradient_transform.a = a;
+ grad->gradient_transform.b = b;
+ grad->gradient_transform.c = c;
+ grad->gradient_transform.d = d;
+ grad->gradient_transform.e = e;
+ grad->gradient_transform.f = f;
dom_string_unref(attr);
}
@@ -214,7 +218,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
state->interned_stop_color,
&attr);
if (exc == DOM_NO_ERR && attr != NULL) {
- svgtiny_parse_color(attr, &color, state);
+ svgtiny_parse_color(attr, &color, NULL, state);
dom_string_unref(attr);
}
exc = dom_element_get_attribute(stop,
@@ -237,6 +241,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
value != NULL) {
svgtiny_parse_color(value,
&color,
+ NULL,
state);
dom_string_unref(value);
}
@@ -248,8 +253,8 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
#ifdef GRADIENT_DEBUG
fprintf(stderr, "stop %g %x\n", offset, color);
#endif
- state->gradient_stop[i].offset = offset;
- state->gradient_stop[i].color = color;
+ grad->gradient_stop[i].offset = offset;
+ grad->gradient_stop[i].color = color;
i++;
}
dom_node_unref(stop);
@@ -259,9 +264,9 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear,
dom_nodelist_unref(stops);
}
-no_more_stops:
+no_more_stops:
if (i > 0)
- state->linear_gradient_stop_count = i;
+ grad->linear_gradient_stop_count = i;
return svgtiny_OK;
}
@@ -318,6 +323,10 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
float current_stop_r;
int red0, green0, blue0, red1, green1, blue1;
unsigned int t, a, b;
+ struct svgtiny_parse_state_gradient *grad;
+
+ assert(state->fill == svgtiny_LINEAR_GRADIENT);
+ grad = &state->fill_grad;
/* determine object bounding box */
svgtiny_path_bbox(p, n, &object_x0, &object_y0, &object_x1, &object_y1);
@@ -326,27 +335,27 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
object_x0, object_y0, object_x1, object_y1);
#endif
- if (!state->gradient_user_space_on_use) {
+ if (!grad->gradient_user_space_on_use) {
gradient_x0 = object_x0 +
- svgtiny_parse_length(state->gradient_x1,
+ svgtiny_parse_length(grad->gradient_x1,
object_x1 - object_x0, *state);
gradient_y0 = object_y0 +
- svgtiny_parse_length(state->gradient_y1,
+ svgtiny_parse_length(grad->gradient_y1,
object_y1 - object_y0, *state);
gradient_x1 = object_x0 +
- svgtiny_parse_length(state->gradient_x2,
+ svgtiny_parse_length(grad->gradient_x2,
object_x1 - object_x0, *state);
gradient_y1 = object_y0 +
- svgtiny_parse_length(state->gradient_y2,
+ svgtiny_parse_length(grad->gradient_y2,
object_y1 - object_y0, *state);
} else {
- gradient_x0 = svgtiny_parse_length(state->gradient_x1,
+ gradient_x0 = svgtiny_parse_length(grad->gradient_x1,
state->viewport_width, *state);
- gradient_y0 = svgtiny_parse_length(state->gradient_y1,
+ gradient_y0 = svgtiny_parse_length(grad->gradient_y1,
state->viewport_height, *state);
- gradient_x1 = svgtiny_parse_length(state->gradient_x2,
+ gradient_x1 = svgtiny_parse_length(grad->gradient_x2,
state->viewport_width, *state);
- gradient_y1 = svgtiny_parse_length(state->gradient_y2,
+ gradient_y1 = svgtiny_parse_length(grad->gradient_y2,
state->viewport_height, *state);
}
gradient_dx = gradient_x1 - gradient_x0;
@@ -399,7 +408,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
}*/
/* invert gradient transform for applying to vertices */
- svgtiny_invert_matrix(&state->gradient_transform.a, trans);
+ svgtiny_invert_matrix(&grad->gradient_transform.a, trans);
#ifdef GRADIENT_DEBUG
fprintf(stderr, "inverse transform %g %g %g %g %g %g\n",
trans[0], trans[1], trans[2], trans[3],
@@ -547,14 +556,14 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
}
/* render triangles */
- stop_count = state->linear_gradient_stop_count;
+ stop_count = grad->linear_gradient_stop_count;
assert(2 <= stop_count);
current_stop = 0;
last_stop_r = 0;
- current_stop_r = state->gradient_stop[0].offset;
- red0 = red1 = svgtiny_RED(state->gradient_stop[0].color);
- green0 = green1 = svgtiny_GREEN(state->gradient_stop[0].color);
- blue0 = blue1 = svgtiny_BLUE(state->gradient_stop[0].color);
+ current_stop_r = grad->gradient_stop[0].offset;
+ red0 = red1 = svgtiny_RED(grad->gradient_stop[0].color);
+ green0 = green1 = svgtiny_GREEN(grad->gradient_stop[0].color);
+ blue0 = blue1 = svgtiny_BLUE(grad->gradient_stop[0].color);
t = min_pt;
a = (min_pt + 1) % svgtiny_list_size(pts);
b = min_pt == 0 ? svgtiny_list_size(pts) - 1 : min_pt - 1;
@@ -576,14 +585,14 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
red0 = red1;
green0 = green1;
blue0 = blue1;
- red1 = svgtiny_RED(state->
+ red1 = svgtiny_RED(grad->
gradient_stop[current_stop].color);
- green1 = svgtiny_GREEN(state->
+ green1 = svgtiny_GREEN(grad->
gradient_stop[current_stop].color);
- blue1 = svgtiny_BLUE(state->
+ blue1 = svgtiny_BLUE(grad->
gradient_stop[current_stop].color);
last_stop_r = current_stop_r;
- current_stop_r = state->
+ current_stop_r = grad->
gradient_stop[current_stop].offset;
}
p = malloc(10 * sizeof p[0]);
@@ -609,10 +618,9 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
shape->path_length = 10;
/*shape->fill = svgtiny_TRANSPARENT;*/
if (current_stop == 0)
- shape->fill = state->gradient_stop[0].color;
+ shape->fill = grad->gradient_stop[0].color;
else if (current_stop == stop_count)
- shape->fill = state->
- gradient_stop[stop_count - 1].color;
+ shape->fill = grad->gradient_stop[stop_count - 1].color;
else {
float stop_r = (mean_r - last_stop_r) /
(current_stop_r - last_stop_r);
diff --git a/src/svgtiny_internal.h b/src/svgtiny_internal.h
index 542a0d0..158d230 100644
--- a/src/svgtiny_internal.h
+++ b/src/svgtiny_internal.h
@@ -24,6 +24,16 @@ struct svgtiny_gradient_stop {
#define svgtiny_MAX_STOPS 10
#define svgtiny_LINEAR_GRADIENT 0x2000000
+struct svgtiny_parse_state_gradient {
+ unsigned int linear_gradient_stop_count;
+ dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
+ struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
+ bool gradient_user_space_on_use;
+ struct {
+ float a, b, c, d, e, f;
+ } gradient_transform;
+};
+
struct svgtiny_parse_state {
struct svgtiny_diagram *diagram;
dom_document *document;
@@ -44,13 +54,8 @@ struct svgtiny_parse_state {
int stroke_width;
/* gradients */
- unsigned int linear_gradient_stop_count;
- dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
- struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
- bool gradient_user_space_on_use;
- struct {
- float a, b, c, d, e, f;
- } gradient_transform;
+ struct svgtiny_parse_state_gradient fill_grad;
+ struct svgtiny_parse_state_gradient stroke_grad;
/* Interned strings */
#define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
@@ -65,6 +70,7 @@ struct svgtiny_list;
float svgtiny_parse_length(dom_string *s, int viewport_size,
const struct svgtiny_parse_state state);
void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
void svgtiny_parse_transform(char *s, float *ma, float *mb,
float *mc, float *md, float *me, float *mf);
@@ -80,7 +86,9 @@ char *svgtiny_strndup(const char *s, size_t n);
#endif
/* svgtiny_gradient.c */
-void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);
+void svgtiny_find_gradient(const char *id,
+ struct svgtiny_parse_state_gradient *grad,
+ struct svgtiny_parse_state *state);
svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
struct svgtiny_parse_state *state);
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=0f0342a4416a5b3b...
commit 0f0342a4416a5b3bb03fe80d428d73a431f03a76
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Parse: Avoid strndup with unchecked return value.
diff --git a/src/svgtiny.c b/src/svgtiny.c
index ec15b35..76df69a 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -1483,9 +1483,9 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c,
void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
struct svgtiny_parse_state *state)
{
- char *ss = strndup(dom_string_data(s), dom_string_byte_length(s));
- _svgtiny_parse_color(ss, c, state);
- free(ss);
+ dom_string_ref(s);
+ _svgtiny_parse_color(dom_string_data(s), c, state);
+ dom_string_unref(s);
}
/**
commitdiff http://git.netsurf-browser.org/libsvgtiny.git/commit/?id=059c01c90f5d3e64...
commit 059c01c90f5d3e64287853293097f56b8ca8ec1d
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Parse: Remove explicit init of gradient state; gets memset anyway.
diff --git a/src/svgtiny.c b/src/svgtiny.c
index bd9aeaa..ec15b35 100644
--- a/src/svgtiny.c
+++ b/src/svgtiny.c
@@ -152,11 +152,6 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
UNUSED(url);
- state.gradient_x1 = NULL;
- state.gradient_y1 = NULL;
- state.gradient_x2 = NULL;
- state.gradient_y2 = NULL;
-
parser = dom_xml_parser_create(NULL, NULL,
ignore_msg, NULL, &document);
-----------------------------------------------------------------------
--
NetSurf SVG decoder
6 years, 11 months
netsurf: branch master updated. release/3.5-370-g3940a07
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/3940a078b118b0b81b1d7...
...commit http://git.netsurf-browser.org/netsurf.git/commit/3940a078b118b0b81b1d799...
...tree http://git.netsurf-browser.org/netsurf.git/tree/3940a078b118b0b81b1d799d8...
The branch, master has been updated
via 3940a078b118b0b81b1d799d8b83a8753aa0d3ea (commit)
via 2adf0a9c44a0ebb0dc9060aa5f3e27f65e21875d (commit)
from af5f4a570453c2d0b1dcfd06044ad3abb3bd4325 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=3940a078b118b0b81b1...
commit 3940a078b118b0b81b1d799d8b83a8753aa0d3ea
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
add some example code to aid in explaining the core window interface
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
index 0d5f7bc..0267f37 100644
--- a/Docs/core-window-interface
+++ b/Docs/core-window-interface
@@ -77,8 +77,8 @@ event occoured) it must call the corewindoe API wrappers
implementation e.g in the case of ssl certificate viewer
void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
- int x, int y, struct rect *clip,
- const struct redraw_context *ctx);
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
which will perform the plot operations required to update an area of
the window for that SSL data.
@@ -105,4 +105,573 @@ itself, this is purely the gtk wrapper) is used by ssl_cert.c which
creates a nsgtk_crtvrfy_window structure containing the
nsgtk_corewindow structure. It attaches actual GTK window handles to
this structure and populates elements of nsgtk_corewindow and then
-calls sslcert_viewer_init() directly.
\ No newline at end of file
+calls sslcert_viewer_init() directly.
+
+frontend skeleton
+-----------------
+
+An example core window implementation for a frontend ssl certficiate
+viewer is presented here. This implements the suggested usage above
+and provides generic corewindow helpers.
+
+
+frontends/example/corewindow.h
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXAMPLE_COREWINDOW_H
+#define EXAMPLE_COREWINDOW_H
+
+#include "netsurf/core_window.h"
+
+/**
+ * example core window state
+ */
+struct example_corewindow {
+
+
+ /*
+ * Any variables common to any frontend window would go here.
+ * e.g. drawing area handles, toolkit pointers or other state
+ */
+ example_toolkit_widget *tk_widget;
+
+
+
+ /** drag status set by core */
+ core_window_drag_status drag_staus;
+
+ /** table of callbacks for core window operations */
+ struct core_window_callback_table *cb_table;
+
+ /**
+ * callback to draw on drawable area of example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+ nserror (*draw)(struct example_corewindow *example_cw, struct rect *r);
+
+ /**
+ * callback for keypress on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
+ */
+ nserror (*key)(struct example_corewindow *example_cw, uint32_t nskey);
+
+ /**
+ * callback for mouse event on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
+ */
+ nserror (*mouse)(struct example_corewindow *example_cw, browser_mouse_state mouse_state, int x, int y);
+};
+
+/**
+ * initialise elements of example core window.
+ *
+ * As a pre-requisite the draw, key and mouse callbacks must be defined
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful initialisation otherwise error code.
+ */
+nserror example_corewindow_init(struct example_corewindow *example_cw);
+
+/**
+ * finalise elements of example core window.
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful finalisation otherwise error code.
+ */
+nserror example_corewindow_fini(struct example_corewindow *example_cw);
+
+#endif
+
+frontends/example/corewindow.c
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * EXAMPLE generic core window interface.
+ *
+ * Provides interface for core renderers to the example toolkit drawable area.
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct example_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call example_corewindow_init()
+ *
+ * The example core window structure requires the callback for draw, key and
+ * mouse operations.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#include "utils/log.h"
+#include "utils/utils.h"
+#include "utils/messages.h"
+#include "utils/utf8.h"
+#include "netsurf/keypress.h"
+#include "netsurf/mouse.h"
+#include "desktop/plot_style.h"
+
+/* extremely likely there will be additional headers required in a real frontend */
+#include "example/corewindow.h"
+
+
+/* toolkit event handlers that do generic things and call internal callbacks */
+
+
+static bool
+example_cw_mouse_press_event(toolkit_widget *widget, toolkit_button bt, int x, int y, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+
+ example_cw->mouse(example_cw, state, x, y);
+
+ return true;
+}
+
+static bool
+example_cw_keyrelease_event(toolkit_widget *widget, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+
+ example_cw->key(example_cw, keycode);
+
+ return true;
+}
+
+
+
+/* signal handler for toolkit window redraw */
+static bool
+example_cw_draw_event(toolkit_widget *widget,
+ toolkit_area *tk_area,
+ void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+ struct rect clip;
+
+ clip.x0 = tk_area.x;
+ clip.y0 = tk_area.y;
+ clip.x1 = tk_area.width;
+ clip.y1 = tk_area.height;
+
+ example_cw->draw(example_cw, &clip);
+
+ return true;
+}
+
+
+/**
+ * callback from core to request a redraw
+ */
+static void
+example_cw_redraw_request(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_widget_queue_draw_area(example_cw->widget,
+ r->x0, r->y0,
+ r->x1 - r->x0, r->y1 - r->y0);
+}
+
+
+static void
+example_cw_update_size(struct core_window *cw, int width, int height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_widget_set_size_request(EXAMPLE_WIDGET(example_cw->drawing_area),
+ width, height);
+}
+
+
+static void
+example_cw_scroll_visible(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_scroll_widget(example_cw->widget, r);
+}
+
+
+static void
+example_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ *width = toolkit_get_widget_width(example_cw->widget);
+ *height = toolkit_get_widget_height(example_cw->widget);
+}
+
+
+static void
+example_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+ example_cw->drag_staus = ds;
+}
+
+
+struct core_window_callback_table example_cw_cb_table = {
+ .redraw_request = example_cw_redraw_request,
+ .update_size = example_cw_update_size,
+ .scroll_visible = example_cw_scroll_visible,
+ .get_window_dimensions = example_cw_get_window_dimensions,
+ .drag_status = example_cw_drag_status
+};
+
+/* exported function documented example/corewindow.h */
+nserror example_corewindow_init(struct example_corewindow *example_cw)
+{
+ /* setup the core window callback table */
+ example_cw->cb_table = &example_cw_cb_table;
+
+ /* frontend toolkit specific method of causing example_cw_draw_event to be called when a drawing operation is required */
+ toolkit_connect_draw_event(example_cw->tk_widget,
+ example_cw_draw_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_button_press_event to be called when a button press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_button_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_button_release_event to be called when a button release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_button_release_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_motion_notify_event to be called when there is motion over the widget */
+ toolkit_connect_motion_event(example_cw->tk_widget,
+ example_cw_motion_notify_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_key_press_event to be called when a key press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_key_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_key_release_event to be called when a key release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_key_release_event,
+ example_cw);
+
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/corewindow.h */
+nserror example_corewindow_fini(struct example_corewindow *example_cw)
+{
+ return NSERROR_OK;
+}
+
+
+frontends/example/ssl_cert.h
+----------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_EXAMPLE_SSL_CERT_H
+#define NETSURF_EXAMPLE_SSL_CERT_H 1
+
+struct nsurl;
+struct ssl_cert_info;
+
+/**
+ * Prompt the user to verify a certificate with issuse.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror example_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
+
+#endif
+
+frontends/example/ssl_cert.c
+----------------------------
+
+/*
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Implementation of example certificate viewing using example core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "desktop/sslcert_viewer.h"
+
+#include "example/corewindow.h"
+
+
+/**
+ * EXAMPLE certificate viewing window context
+ */
+struct example_crtvrfy_window {
+ /** example core window context */
+ struct example_corewindow core;
+
+ /** SSL certificate viewer context data */
+ struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror example_crtvrfy_destroy(struct example_crtvrfy_window *crtvrfy_win)
+{
+ nserror res;
+
+ res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ if (res == NSERROR_OK) {
+ res = example_corewindow_fini(&crtvrfy_win->core);
+ toolkit_windown_destroy(crtvrfy_win->window);
+ free(crtvrfy_win);
+ }
+ return res;
+}
+
+static void
+example_crtvrfy_accept(ExampleButton *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_accept(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+example_crtvrfy_reject(ExampleWidget *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_mouse(struct example_corewindow *example_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+
+ return NSERROR_OK;
+}
+
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_key(struct example_corewindow *example_cw, uint32_t nskey)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_draw(struct example_corewindow *example_cw, struct rect *r)
+{
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &example_plotters
+ };
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/ssl_cert.h */
+nserror example_cert_verify(struct nsurl *url,
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw),
+ void *cbpw)
+{
+ struct example_crtvrfy_window *ncwin;
+ nserror res;
+
+ ncwin = malloc(sizeof(struct example_crtvrfy_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = toolkit_create_window(&ncwin->window);
+ if (res != NSERROR_OK) {
+ LOG("SSL UI builder init failed");
+ free(ncwin);
+ return res;
+ }
+
+ /* store the widget that the toolkit is drawing into */
+ ncwin->core.widget = toolkit_get_widget(ncwin->window, "SSLDrawingArea"));
+
+ /* would typicaly setup toolkit accept/reject buttons etc. here */
+ toolkit_connect_button_press(ncwin->tk_accept_button,
+ example_crtvrfy_accept,
+ ncwin);
+
+
+ /* initialise example core window */
+ ncwin->core.draw = example_crtvrfy_draw;
+ ncwin->core.key = example_crtvrfy_key;
+ ncwin->core.mouse = example_crtvrfy_mouse;
+
+ res = example_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* initialise certificate viewing interface */
+ res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+ &ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = sslcert_viewer_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ toolkit_widget_show(ncwin->window);
+
+ return NSERROR_OK;
+}
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=2adf0a9c44a0ebb0dc9...
commit 2adf0a9c44a0ebb0dc9060aa5f3e27f65e21875d
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
clean up documentation of GTK core window interfaces
diff --git a/frontends/gtk/cookies.c b/frontends/gtk/cookies.c
index d0fae97..dc77e1c 100644
--- a/frontends/gtk/cookies.c
+++ b/frontends/gtk/cookies.c
@@ -183,7 +183,7 @@ static void nsgtk_cookies_init_menu(struct nsgtk_cookie_window *ncwin)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -200,7 +200,7 @@ nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -216,7 +216,7 @@ nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
@@ -235,7 +235,7 @@ nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
/**
* Creates the window for the cookies tree.
*
- * \return NSERROR_OK on success else appropriate error code on faliure.
+ * \return NSERROR_OK on success else appropriate error code on failure.
*/
static nserror nsgtk_cookies_init(void)
{
diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c
index e60f2c4..a992601 100644
--- a/frontends/gtk/corewindow.c
+++ b/frontends/gtk/corewindow.c
@@ -23,7 +23,6 @@
* Provides interface for core renderers to the gtk toolkit drawable area.
* \todo should the interface really be called coredrawable?
*
-
* This module is an object that must be encapsulated. Client users
* should embed a struct nsgtk_corewindow at the beginning of their
* context for this display surface, fill in relevant data and then
@@ -54,6 +53,9 @@
/**
* Convert GDK mouse event to netsurf mouse state
+ *
+ * \param event The GDK mouse event to convert.
+ * \return The netsurf mouse state.
*/
static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
{
@@ -92,12 +94,16 @@ static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
return ms;
}
+
/**
* gtk event on mouse button press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk event for a mouse button transition to pressed from
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_button_press_event(GtkWidget *widget,
@@ -122,6 +128,17 @@ nsgtk_cw_button_press_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse button release.
+ *
+ * Service gtk event for a mouse button transition from pressed to
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_button_release_event(GtkWidget *widget,
GdkEventButton *event,
@@ -185,9 +202,20 @@ nsgtk_cw_button_release_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse movement.
+ *
+ * Service gtk motion-notify-event for mouse movement above a widget.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The motion event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_motion_notify_event(GtkWidget *widget,
- GdkEventMotion *event, gpointer g)
+ GdkEventMotion *event,
+ gpointer g)
{
struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)g;
struct nsgtk_corewindow_mouse *mouse = &nsgtk_cw->mouse_state;
@@ -265,11 +293,11 @@ nsgtk_cw_motion_notify_event(GtkWidget *widget,
/**
- * Deal with keypress events not handled but input method or callback
+ * Deal with keypress events not handled buy input method or callback
*
* \param nsgtk_cw nsgtk core window key event happened in.
* \param nskey The netsurf keycode of the event.
- * \return NSERROR_OK on sucess otherwise an error code.
+ * \return NSERROR_OK on success otherwise an error code.
*/
static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
@@ -359,9 +387,12 @@ static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
/**
* gtk event on key press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk key-press-event for key transition on a widget from
+ * released to pressed.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
@@ -397,6 +428,16 @@ nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
}
+/**
+ * gtk event on key release.
+ *
+ * Service gtk key-release-event for key transition on a widget from
+ * pressed to released.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
{
@@ -406,6 +447,15 @@ nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
}
+/**
+ * gtk event handler for input method commit.
+ *
+ * Service gtk commit for input method commit action.
+ *
+ * \param ctx The gtk input method context the event occurred for.
+ * \param str The resulting string from the input method.
+ * \param g The context pointer passed when the event was registered.
+ */
static void
nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
{
@@ -428,7 +478,15 @@ nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
#if GTK_CHECK_VERSION(3,0,0)
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 3
+ *
+ * \param widget The GTK widget to redraw.
+ * \param cr The cairo drawing context of the widget
+ * \param data The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
{
@@ -458,7 +516,15 @@ nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
#else
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 2
+ *
+ * \param widget The GTK widget to redraw.
+ * \param event The GDK expose event
+ * \param g The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget,
GdkEventExpose *event,
@@ -485,8 +551,12 @@ nsgtk_cw_draw_event(GtkWidget *widget,
#endif
+
/**
- * callback from core to request a redraw
+ * redraw window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs redrawing.
*/
static void
nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
@@ -499,6 +569,13 @@ nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
}
+/**
+ * update window size core window callback
+ *
+ * \param cw core window handle.
+ * \param width New widget width.
+ * \param height New widget height.
+ */
static void
nsgtk_cw_update_size(struct core_window *cw, int width, int height)
{
@@ -509,6 +586,12 @@ nsgtk_cw_update_size(struct core_window *cw, int width, int height)
}
+/**
+ * scroll window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs scrolling.
+ */
static void
nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
{
@@ -536,6 +619,13 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
}
+/**
+ * get window size core window callback
+ *
+ * \param cw core window handle.
+ * \param[out] width The width value to update
+ * \param[out] height The height value to update
+ */
static void
nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
{
@@ -554,9 +644,16 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
g_object_get(vadj, "page-size", &page, NULL);
*height = page;
- }}
+ }
+}
+/**
+ * update window drag status core window callback
+ *
+ * \param cw core window handle.
+ * \param ds The new drag status.
+ */
static void
nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
{
@@ -565,7 +662,10 @@ nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
}
-struct core_window_callback_table nsgtk_cw_cb_table = {
+/**
+ * core window callback table for nsgtk
+ */
+static struct core_window_callback_table nsgtk_cw_cb_table = {
.redraw_request = nsgtk_cw_redraw_request,
.update_size = nsgtk_cw_update_size,
.scroll_visible = nsgtk_cw_scroll_visible,
@@ -626,6 +726,7 @@ nserror nsgtk_corewindow_init(struct nsgtk_corewindow *nsgtk_cw)
return NSERROR_OK;
}
+/* exported interface documented in gtk/corewindow.h */
nserror nsgtk_corewindow_fini(struct nsgtk_corewindow *nsgtk_cw)
{
g_object_unref(nsgtk_cw->input_method);
diff --git a/frontends/gtk/corewindow.h b/frontends/gtk/corewindow.h
index cfb865e..90bfd61 100644
--- a/frontends/gtk/corewindow.h
+++ b/frontends/gtk/corewindow.h
@@ -58,7 +58,7 @@ struct nsgtk_corewindow {
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
nserror (*draw)(struct nsgtk_corewindow *nsgtk_cw, struct rect *r);
@@ -69,7 +69,7 @@ struct nsgtk_corewindow {
* \param nskey The netsurf key code.
* \return NSERROR_OK if key processed,
* NSERROR_NOT_IMPLEMENTED if key not processed
- * otherwise apropriate error code
+ * otherwise appropriate error code
*/
nserror (*key)(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey);
@@ -80,7 +80,7 @@ struct nsgtk_corewindow {
* \param mouse_state mouse state
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on sucess otherwise apropriate error code.
+ * \return NSERROR_OK on success otherwise appropriate error code.
*/
nserror (*mouse)(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state mouse_state, int x, int y);
};
diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c
index 8270b15..5388f01 100644
--- a/frontends/gtk/ssl_cert.c
+++ b/frontends/gtk/ssl_cert.c
@@ -104,7 +104,7 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -125,7 +125,7 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -146,7 +146,7 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
-----------------------------------------------------------------------
Summary of changes:
Docs/core-window-interface | 575 +++++++++++++++++++++++++++++++++++++++++++-
frontends/gtk/cookies.c | 8 +-
frontends/gtk/corewindow.c | 131 ++++++++--
frontends/gtk/corewindow.h | 6 +-
frontends/gtk/ssl_cert.c | 6 +-
5 files changed, 698 insertions(+), 28 deletions(-)
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
index 0d5f7bc..0267f37 100644
--- a/Docs/core-window-interface
+++ b/Docs/core-window-interface
@@ -77,8 +77,8 @@ event occoured) it must call the corewindoe API wrappers
implementation e.g in the case of ssl certificate viewer
void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
- int x, int y, struct rect *clip,
- const struct redraw_context *ctx);
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
which will perform the plot operations required to update an area of
the window for that SSL data.
@@ -105,4 +105,573 @@ itself, this is purely the gtk wrapper) is used by ssl_cert.c which
creates a nsgtk_crtvrfy_window structure containing the
nsgtk_corewindow structure. It attaches actual GTK window handles to
this structure and populates elements of nsgtk_corewindow and then
-calls sslcert_viewer_init() directly.
\ No newline at end of file
+calls sslcert_viewer_init() directly.
+
+frontend skeleton
+-----------------
+
+An example core window implementation for a frontend ssl certficiate
+viewer is presented here. This implements the suggested usage above
+and provides generic corewindow helpers.
+
+
+frontends/example/corewindow.h
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXAMPLE_COREWINDOW_H
+#define EXAMPLE_COREWINDOW_H
+
+#include "netsurf/core_window.h"
+
+/**
+ * example core window state
+ */
+struct example_corewindow {
+
+
+ /*
+ * Any variables common to any frontend window would go here.
+ * e.g. drawing area handles, toolkit pointers or other state
+ */
+ example_toolkit_widget *tk_widget;
+
+
+
+ /** drag status set by core */
+ core_window_drag_status drag_staus;
+
+ /** table of callbacks for core window operations */
+ struct core_window_callback_table *cb_table;
+
+ /**
+ * callback to draw on drawable area of example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+ nserror (*draw)(struct example_corewindow *example_cw, struct rect *r);
+
+ /**
+ * callback for keypress on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
+ */
+ nserror (*key)(struct example_corewindow *example_cw, uint32_t nskey);
+
+ /**
+ * callback for mouse event on example core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
+ */
+ nserror (*mouse)(struct example_corewindow *example_cw, browser_mouse_state mouse_state, int x, int y);
+};
+
+/**
+ * initialise elements of example core window.
+ *
+ * As a pre-requisite the draw, key and mouse callbacks must be defined
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful initialisation otherwise error code.
+ */
+nserror example_corewindow_init(struct example_corewindow *example_cw);
+
+/**
+ * finalise elements of example core window.
+ *
+ * \param example_cw A example core window structure to initialise
+ * \return NSERROR_OK on successful finalisation otherwise error code.
+ */
+nserror example_corewindow_fini(struct example_corewindow *example_cw);
+
+#endif
+
+frontends/example/corewindow.c
+------------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * EXAMPLE generic core window interface.
+ *
+ * Provides interface for core renderers to the example toolkit drawable area.
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct example_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call example_corewindow_init()
+ *
+ * The example core window structure requires the callback for draw, key and
+ * mouse operations.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#include "utils/log.h"
+#include "utils/utils.h"
+#include "utils/messages.h"
+#include "utils/utf8.h"
+#include "netsurf/keypress.h"
+#include "netsurf/mouse.h"
+#include "desktop/plot_style.h"
+
+/* extremely likely there will be additional headers required in a real frontend */
+#include "example/corewindow.h"
+
+
+/* toolkit event handlers that do generic things and call internal callbacks */
+
+
+static bool
+example_cw_mouse_press_event(toolkit_widget *widget, toolkit_button bt, int x, int y, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+
+ example_cw->mouse(example_cw, state, x, y);
+
+ return true;
+}
+
+static bool
+example_cw_keyrelease_event(toolkit_widget *widget, void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+
+ example_cw->key(example_cw, keycode);
+
+ return true;
+}
+
+
+
+/* signal handler for toolkit window redraw */
+static bool
+example_cw_draw_event(toolkit_widget *widget,
+ toolkit_area *tk_area,
+ void *ctx)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)ctx;
+ struct rect clip;
+
+ clip.x0 = tk_area.x;
+ clip.y0 = tk_area.y;
+ clip.x1 = tk_area.width;
+ clip.y1 = tk_area.height;
+
+ example_cw->draw(example_cw, &clip);
+
+ return true;
+}
+
+
+/**
+ * callback from core to request a redraw
+ */
+static void
+example_cw_redraw_request(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_widget_queue_draw_area(example_cw->widget,
+ r->x0, r->y0,
+ r->x1 - r->x0, r->y1 - r->y0);
+}
+
+
+static void
+example_cw_update_size(struct core_window *cw, int width, int height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_widget_set_size_request(EXAMPLE_WIDGET(example_cw->drawing_area),
+ width, height);
+}
+
+
+static void
+example_cw_scroll_visible(struct core_window *cw, const struct rect *r)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ toolkit_scroll_widget(example_cw->widget, r);
+}
+
+
+static void
+example_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+
+ *width = toolkit_get_widget_width(example_cw->widget);
+ *height = toolkit_get_widget_height(example_cw->widget);
+}
+
+
+static void
+example_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
+{
+ struct example_corewindow *example_cw = (struct example_corewindow *)cw;
+ example_cw->drag_staus = ds;
+}
+
+
+struct core_window_callback_table example_cw_cb_table = {
+ .redraw_request = example_cw_redraw_request,
+ .update_size = example_cw_update_size,
+ .scroll_visible = example_cw_scroll_visible,
+ .get_window_dimensions = example_cw_get_window_dimensions,
+ .drag_status = example_cw_drag_status
+};
+
+/* exported function documented example/corewindow.h */
+nserror example_corewindow_init(struct example_corewindow *example_cw)
+{
+ /* setup the core window callback table */
+ example_cw->cb_table = &example_cw_cb_table;
+
+ /* frontend toolkit specific method of causing example_cw_draw_event to be called when a drawing operation is required */
+ toolkit_connect_draw_event(example_cw->tk_widget,
+ example_cw_draw_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_button_press_event to be called when a button press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_button_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_button_release_event to be called when a button release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_button_release_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_motion_notify_event to be called when there is motion over the widget */
+ toolkit_connect_motion_event(example_cw->tk_widget,
+ example_cw_motion_notify_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_key_press_event to be called when a key press occours */
+ toolkit_connect_button_press_event(example_cw->tk_widget,
+ example_cw_key_press_event,
+ example_cw);
+
+ /* frontend toolkit specific method of causing example_cw_key_release_event to be called when a key release occours */
+ toolkit_connect_button_release_event(example_cw->tk_widget,
+ example_cw_key_release_event,
+ example_cw);
+
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/corewindow.h */
+nserror example_corewindow_fini(struct example_corewindow *example_cw)
+{
+ return NSERROR_OK;
+}
+
+
+frontends/example/ssl_cert.h
+----------------------------
+
+/*
+ * Copyright 2016 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_EXAMPLE_SSL_CERT_H
+#define NETSURF_EXAMPLE_SSL_CERT_H 1
+
+struct nsurl;
+struct ssl_cert_info;
+
+/**
+ * Prompt the user to verify a certificate with issuse.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ * \return NSERROR_OK or error code if prompt creation failed.
+ */
+nserror example_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
+
+#endif
+
+frontends/example/ssl_cert.c
+----------------------------
+
+/*
+ * Copyright 2015 Vincent Sanders <vince(a)netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Implementation of example certificate viewing using example core windows.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "desktop/sslcert_viewer.h"
+
+#include "example/corewindow.h"
+
+
+/**
+ * EXAMPLE certificate viewing window context
+ */
+struct example_crtvrfy_window {
+ /** example core window context */
+ struct example_corewindow core;
+
+ /** SSL certificate viewer context data */
+ struct sslcert_session_data *ssl_data;
+};
+
+/**
+ * destroy a previously created certificate view
+ */
+static nserror example_crtvrfy_destroy(struct example_crtvrfy_window *crtvrfy_win)
+{
+ nserror res;
+
+ res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ if (res == NSERROR_OK) {
+ res = example_corewindow_fini(&crtvrfy_win->core);
+ toolkit_windown_destroy(crtvrfy_win->window);
+ free(crtvrfy_win);
+ }
+ return res;
+}
+
+static void
+example_crtvrfy_accept(ExampleButton *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_accept(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+static void
+example_crtvrfy_reject(ExampleWidget *w, gpointer data)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ crtvrfy_win = (struct example_crtvrfy_window *)data;
+
+ sslcert_viewer_reject(crtvrfy_win->ssl_data);
+
+ example_crtvrfy_destroy(crtvrfy_win);
+}
+
+
+/**
+ * callback for mouse action for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_mouse(struct example_corewindow *example_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+
+ return NSERROR_OK;
+}
+
+/**
+ * callback for keypress for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_key(struct example_corewindow *example_cw, uint32_t nskey)
+{
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
+}
+
+/**
+ * callback on draw event for certificate verify on core window
+ *
+ * \param example_cw The example core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+example_crtvrfy_draw(struct example_corewindow *example_cw, struct rect *r)
+{
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &example_plotters
+ };
+ struct example_crtvrfy_window *crtvrfy_win;
+
+ /* technically degenerate container of */
+ crtvrfy_win = (struct example_crtvrfy_window *)example_cw;
+
+ sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in example/ssl_cert.h */
+nserror example_cert_verify(struct nsurl *url,
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw),
+ void *cbpw)
+{
+ struct example_crtvrfy_window *ncwin;
+ nserror res;
+
+ ncwin = malloc(sizeof(struct example_crtvrfy_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = toolkit_create_window(&ncwin->window);
+ if (res != NSERROR_OK) {
+ LOG("SSL UI builder init failed");
+ free(ncwin);
+ return res;
+ }
+
+ /* store the widget that the toolkit is drawing into */
+ ncwin->core.widget = toolkit_get_widget(ncwin->window, "SSLDrawingArea"));
+
+ /* would typicaly setup toolkit accept/reject buttons etc. here */
+ toolkit_connect_button_press(ncwin->tk_accept_button,
+ example_crtvrfy_accept,
+ ncwin);
+
+
+ /* initialise example core window */
+ ncwin->core.draw = example_crtvrfy_draw;
+ ncwin->core.key = example_crtvrfy_key;
+ ncwin->core.mouse = example_crtvrfy_mouse;
+
+ res = example_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* initialise certificate viewing interface */
+ res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+ &ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = sslcert_viewer_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ toolkit_widget_show(ncwin->window);
+
+ return NSERROR_OK;
+}
diff --git a/frontends/gtk/cookies.c b/frontends/gtk/cookies.c
index d0fae97..dc77e1c 100644
--- a/frontends/gtk/cookies.c
+++ b/frontends/gtk/cookies.c
@@ -183,7 +183,7 @@ static void nsgtk_cookies_init_menu(struct nsgtk_cookie_window *ncwin)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -200,7 +200,7 @@ nsgtk_cookies_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -216,7 +216,7 @@ nsgtk_cookies_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
@@ -235,7 +235,7 @@ nsgtk_cookies_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
/**
* Creates the window for the cookies tree.
*
- * \return NSERROR_OK on success else appropriate error code on faliure.
+ * \return NSERROR_OK on success else appropriate error code on failure.
*/
static nserror nsgtk_cookies_init(void)
{
diff --git a/frontends/gtk/corewindow.c b/frontends/gtk/corewindow.c
index e60f2c4..a992601 100644
--- a/frontends/gtk/corewindow.c
+++ b/frontends/gtk/corewindow.c
@@ -23,7 +23,6 @@
* Provides interface for core renderers to the gtk toolkit drawable area.
* \todo should the interface really be called coredrawable?
*
-
* This module is an object that must be encapsulated. Client users
* should embed a struct nsgtk_corewindow at the beginning of their
* context for this display surface, fill in relevant data and then
@@ -54,6 +53,9 @@
/**
* Convert GDK mouse event to netsurf mouse state
+ *
+ * \param event The GDK mouse event to convert.
+ * \return The netsurf mouse state.
*/
static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
{
@@ -92,12 +94,16 @@ static browser_mouse_state nsgtk_cw_gdkbutton_to_nsstate(GdkEventButton *event)
return ms;
}
+
/**
* gtk event on mouse button press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk event for a mouse button transition to pressed from
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_button_press_event(GtkWidget *widget,
@@ -122,6 +128,17 @@ nsgtk_cw_button_press_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse button release.
+ *
+ * Service gtk event for a mouse button transition from pressed to
+ * released state.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_button_release_event(GtkWidget *widget,
GdkEventButton *event,
@@ -185,9 +202,20 @@ nsgtk_cw_button_release_event(GtkWidget *widget,
return TRUE;
}
+
+/**
+ * gtk event on mouse movement.
+ *
+ * Service gtk motion-notify-event for mouse movement above a widget.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The motion event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_motion_notify_event(GtkWidget *widget,
- GdkEventMotion *event, gpointer g)
+ GdkEventMotion *event,
+ gpointer g)
{
struct nsgtk_corewindow *nsgtk_cw = (struct nsgtk_corewindow *)g;
struct nsgtk_corewindow_mouse *mouse = &nsgtk_cw->mouse_state;
@@ -265,11 +293,11 @@ nsgtk_cw_motion_notify_event(GtkWidget *widget,
/**
- * Deal with keypress events not handled but input method or callback
+ * Deal with keypress events not handled buy input method or callback
*
* \param nsgtk_cw nsgtk core window key event happened in.
* \param nskey The netsurf keycode of the event.
- * \return NSERROR_OK on sucess otherwise an error code.
+ * \return NSERROR_OK on success otherwise an error code.
*/
static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
@@ -359,9 +387,12 @@ static nserror nsgtk_cw_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
/**
* gtk event on key press.
*
- * \param widget The gtk widget the event occoured for.
- * \param event The event that occoured.
- * \param g The context pointer passed when teh event was registered.
+ * Service gtk key-press-event for key transition on a widget from
+ * released to pressed.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
*/
static gboolean
nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
@@ -397,6 +428,16 @@ nsgtk_cw_keypress_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
}
+/**
+ * gtk event on key release.
+ *
+ * Service gtk key-release-event for key transition on a widget from
+ * pressed to released.
+ *
+ * \param widget The gtk widget the event occurred for.
+ * \param event The event that occurred.
+ * \param g The context pointer passed when the event was registered.
+ */
static gboolean
nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
{
@@ -406,6 +447,15 @@ nsgtk_cw_keyrelease_event(GtkWidget *widget, GdkEventKey *event, gpointer g)
}
+/**
+ * gtk event handler for input method commit.
+ *
+ * Service gtk commit for input method commit action.
+ *
+ * \param ctx The gtk input method context the event occurred for.
+ * \param str The resulting string from the input method.
+ * \param g The context pointer passed when the event was registered.
+ */
static void
nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
{
@@ -428,7 +478,15 @@ nsgtk_cw_input_method_commit(GtkIMContext *ctx, const gchar *str, gpointer g)
#if GTK_CHECK_VERSION(3,0,0)
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 3
+ *
+ * \param widget The GTK widget to redraw.
+ * \param cr The cairo drawing context of the widget
+ * \param data The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
{
@@ -458,7 +516,15 @@ nsgtk_cw_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
#else
-/* signal handler for core window redraw */
+
+/**
+ * handler for gtk draw event on a nsgtk core window for GTK 2
+ *
+ * \param widget The GTK widget to redraw.
+ * \param event The GDK expose event
+ * \param g The context pointer passed when the event was registered.
+ * \return FALSE indicating no error.
+ */
static gboolean
nsgtk_cw_draw_event(GtkWidget *widget,
GdkEventExpose *event,
@@ -485,8 +551,12 @@ nsgtk_cw_draw_event(GtkWidget *widget,
#endif
+
/**
- * callback from core to request a redraw
+ * redraw window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs redrawing.
*/
static void
nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
@@ -499,6 +569,13 @@ nsgtk_cw_redraw_request(struct core_window *cw, const struct rect *r)
}
+/**
+ * update window size core window callback
+ *
+ * \param cw core window handle.
+ * \param width New widget width.
+ * \param height New widget height.
+ */
static void
nsgtk_cw_update_size(struct core_window *cw, int width, int height)
{
@@ -509,6 +586,12 @@ nsgtk_cw_update_size(struct core_window *cw, int width, int height)
}
+/**
+ * scroll window core window callback
+ *
+ * \param cw core window handle.
+ * \param r rectangle that needs scrolling.
+ */
static void
nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
{
@@ -536,6 +619,13 @@ nsgtk_cw_scroll_visible(struct core_window *cw, const struct rect *r)
}
+/**
+ * get window size core window callback
+ *
+ * \param cw core window handle.
+ * \param[out] width The width value to update
+ * \param[out] height The height value to update
+ */
static void
nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
{
@@ -554,9 +644,16 @@ nsgtk_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
vadj = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
g_object_get(vadj, "page-size", &page, NULL);
*height = page;
- }}
+ }
+}
+/**
+ * update window drag status core window callback
+ *
+ * \param cw core window handle.
+ * \param ds The new drag status.
+ */
static void
nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
{
@@ -565,7 +662,10 @@ nsgtk_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
}
-struct core_window_callback_table nsgtk_cw_cb_table = {
+/**
+ * core window callback table for nsgtk
+ */
+static struct core_window_callback_table nsgtk_cw_cb_table = {
.redraw_request = nsgtk_cw_redraw_request,
.update_size = nsgtk_cw_update_size,
.scroll_visible = nsgtk_cw_scroll_visible,
@@ -626,6 +726,7 @@ nserror nsgtk_corewindow_init(struct nsgtk_corewindow *nsgtk_cw)
return NSERROR_OK;
}
+/* exported interface documented in gtk/corewindow.h */
nserror nsgtk_corewindow_fini(struct nsgtk_corewindow *nsgtk_cw)
{
g_object_unref(nsgtk_cw->input_method);
diff --git a/frontends/gtk/corewindow.h b/frontends/gtk/corewindow.h
index cfb865e..90bfd61 100644
--- a/frontends/gtk/corewindow.h
+++ b/frontends/gtk/corewindow.h
@@ -58,7 +58,7 @@ struct nsgtk_corewindow {
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
nserror (*draw)(struct nsgtk_corewindow *nsgtk_cw, struct rect *r);
@@ -69,7 +69,7 @@ struct nsgtk_corewindow {
* \param nskey The netsurf key code.
* \return NSERROR_OK if key processed,
* NSERROR_NOT_IMPLEMENTED if key not processed
- * otherwise apropriate error code
+ * otherwise appropriate error code
*/
nserror (*key)(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey);
@@ -80,7 +80,7 @@ struct nsgtk_corewindow {
* \param mouse_state mouse state
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on sucess otherwise apropriate error code.
+ * \return NSERROR_OK on success otherwise appropriate error code.
*/
nserror (*mouse)(struct nsgtk_corewindow *nsgtk_cw, browser_mouse_state mouse_state, int x, int y);
};
diff --git a/frontends/gtk/ssl_cert.c b/frontends/gtk/ssl_cert.c
index 8270b15..5388f01 100644
--- a/frontends/gtk/ssl_cert.c
+++ b/frontends/gtk/ssl_cert.c
@@ -104,7 +104,7 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
* \param mouse_state netsurf mouse state on event
* \param x location of event
* \param y location of event
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
@@ -125,7 +125,7 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
@@ -146,7 +146,7 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
- * \return NSERROR_OK on success otherwise apropriate error code
+ * \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
--
NetSurf Browser
6 years, 11 months
netsurf: branch master updated. release/3.5-368-gaf5f4a5
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/af5f4a570453c2d0b1dcf...
...commit http://git.netsurf-browser.org/netsurf.git/commit/af5f4a570453c2d0b1dcfd0...
...tree http://git.netsurf-browser.org/netsurf.git/tree/af5f4a570453c2d0b1dcfd060...
The branch, master has been updated
via af5f4a570453c2d0b1dcfd06044ad3abb3bd4325 (commit)
from f814edee75db5158f8fbb1930e25e0877d5448de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commit/?id=af5f4a570453c2d0b1d...
commit af5f4a570453c2d0b1dcfd06044ad3abb3bd4325
Author: Vincent Sanders <vince(a)kyllikki.org>
Commit: Vincent Sanders <vince(a)kyllikki.org>
Initial attempt to document the core window interface
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
new file mode 100644
index 0000000..0d5f7bc
--- /dev/null
+++ b/Docs/core-window-interface
@@ -0,0 +1,108 @@
+Core Window Interface
+=====================
+
+The NetSurf core provides an optional API to frontend implementations
+which allows a number of "standard" window content interfaces to be
+provided.
+
+The currently available user interfaces are:
+
+ - Cookies
+ - Global history
+ - Hotlist
+ - SSL certificate view
+
+Although not currently included in future additional user interfaces
+will be available for:
+
+ - local history
+ - browser render
+
+To be clear these are generic implementations of this functionality
+that any frontend may use. Frontends are free to implement these
+interfaces in any manner as they see fit, the corewindow interface
+simply provides a default.
+
+core window API
+---------------
+
+The API is fairly simple and simply involves passing a callback table
+and context pointer to the interface element being constructed.
+
+The header that defines the callback interface is netsurf/core_window.h
+
+The callback table contains five function pointer interfaces which the
+frontend must implement for the core.
+
+ - redraw_request
+ request a redraw an area of a window
+
+ - update_size
+ Update the limits of the window
+
+ - scroll_visible
+ Scroll the window to make area visible
+
+ - get_window_dimensions
+ Get window viewport dimensions
+
+ - drag_status
+ Inform corewindow owner of drag status
+
+Each callback will be passed the context pointer for the corewindow
+instance and the relevant additional information necessary to perform
+the operation.
+
+Each exported user interface element wraps this generic interface with
+a concrete implementation. For example the SSL certificate viewer is
+initialised with:
+
+nserror sslcert_viewer_init(struct core_window_callback_table *cw_t,
+ void *core_window_handle,
+ struct sslcert_session_data *ssl_d);
+
+This call creates a context which will display and navigate the ssl
+session data passed. The frontend must service the callbacks from the
+core to provide the necessary interactions with the frontend windowing
+system.
+
+These actions should ideally use the standard frontend window
+processing. So for the GTK frontend when the core calls the redraw
+operation it simply marks the area passed as damaged (using
+gtk_widget_queue_draw_area()) and lets the standard expose event cause
+the redraw to occour.
+
+If the frontend needs to redraw an area of a window (perhaps an expose
+event occoured) it must call the corewindoe API wrappers
+implementation e.g in the case of ssl certificate viewer
+
+void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
+
+which will perform the plot operations required to update an area of
+the window for that SSL data.
+
+Usage
+-----
+
+The usage pattern that is expected is for a frontend to create a core
+window impementation that implements the necessary five API in a
+generic way and allows the frontend to provide the specific
+specialisation for each of the user interface elements it wishes to
+use (cookies, SSL viewer etc).
+
+The GTK frontend for example:
+
+has source corewindow.[ch] which implement the five core callbacks
+using generic GTK operations (redraw_request calls
+gtk_widget_queue_draw_area() etc.) and then provides additional
+operations on a GTK drawing area object to attach expose event
+processing, keypress processing etc.
+
+The GTK corewindow (not to be confused with the core window API
+itself, this is purely the gtk wrapper) is used by ssl_cert.c which
+creates a nsgtk_crtvrfy_window structure containing the
+nsgtk_corewindow structure. It attaches actual GTK window handles to
+this structure and populates elements of nsgtk_corewindow and then
+calls sslcert_viewer_init() directly.
\ No newline at end of file
-----------------------------------------------------------------------
Summary of changes:
Docs/core-window-interface | 108 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
create mode 100644 Docs/core-window-interface
diff --git a/Docs/core-window-interface b/Docs/core-window-interface
new file mode 100644
index 0000000..0d5f7bc
--- /dev/null
+++ b/Docs/core-window-interface
@@ -0,0 +1,108 @@
+Core Window Interface
+=====================
+
+The NetSurf core provides an optional API to frontend implementations
+which allows a number of "standard" window content interfaces to be
+provided.
+
+The currently available user interfaces are:
+
+ - Cookies
+ - Global history
+ - Hotlist
+ - SSL certificate view
+
+Although not currently included in future additional user interfaces
+will be available for:
+
+ - local history
+ - browser render
+
+To be clear these are generic implementations of this functionality
+that any frontend may use. Frontends are free to implement these
+interfaces in any manner as they see fit, the corewindow interface
+simply provides a default.
+
+core window API
+---------------
+
+The API is fairly simple and simply involves passing a callback table
+and context pointer to the interface element being constructed.
+
+The header that defines the callback interface is netsurf/core_window.h
+
+The callback table contains five function pointer interfaces which the
+frontend must implement for the core.
+
+ - redraw_request
+ request a redraw an area of a window
+
+ - update_size
+ Update the limits of the window
+
+ - scroll_visible
+ Scroll the window to make area visible
+
+ - get_window_dimensions
+ Get window viewport dimensions
+
+ - drag_status
+ Inform corewindow owner of drag status
+
+Each callback will be passed the context pointer for the corewindow
+instance and the relevant additional information necessary to perform
+the operation.
+
+Each exported user interface element wraps this generic interface with
+a concrete implementation. For example the SSL certificate viewer is
+initialised with:
+
+nserror sslcert_viewer_init(struct core_window_callback_table *cw_t,
+ void *core_window_handle,
+ struct sslcert_session_data *ssl_d);
+
+This call creates a context which will display and navigate the ssl
+session data passed. The frontend must service the callbacks from the
+core to provide the necessary interactions with the frontend windowing
+system.
+
+These actions should ideally use the standard frontend window
+processing. So for the GTK frontend when the core calls the redraw
+operation it simply marks the area passed as damaged (using
+gtk_widget_queue_draw_area()) and lets the standard expose event cause
+the redraw to occour.
+
+If the frontend needs to redraw an area of a window (perhaps an expose
+event occoured) it must call the corewindoe API wrappers
+implementation e.g in the case of ssl certificate viewer
+
+void sslcert_viewer_redraw(struct sslcert_session_data *ssl_d,
+ int x, int y, struct rect *clip,
+ const struct redraw_context *ctx);
+
+which will perform the plot operations required to update an area of
+the window for that SSL data.
+
+Usage
+-----
+
+The usage pattern that is expected is for a frontend to create a core
+window impementation that implements the necessary five API in a
+generic way and allows the frontend to provide the specific
+specialisation for each of the user interface elements it wishes to
+use (cookies, SSL viewer etc).
+
+The GTK frontend for example:
+
+has source corewindow.[ch] which implement the five core callbacks
+using generic GTK operations (redraw_request calls
+gtk_widget_queue_draw_area() etc.) and then provides additional
+operations on a GTK drawing area object to attach expose event
+processing, keypress processing etc.
+
+The GTK corewindow (not to be confused with the core window API
+itself, this is purely the gtk wrapper) is used by ssl_cert.c which
+creates a nsgtk_crtvrfy_window structure containing the
+nsgtk_corewindow structure. It attaches actual GTK window handles to
+this structure and populates elements of nsgtk_corewindow and then
+calls sslcert_viewer_init() directly.
\ No newline at end of file
--
NetSurf Browser
6 years, 11 months