summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-10-30 12:58:43 +0000
committerVincent Sanders <vince@kyllikki.org>2016-10-30 12:58:43 +0000
commita2388a91cf9ceb7efb203a7b4d6d250395cdb744 (patch)
tree12c969f54fd1b1a688dfe92bc94fde13ec6958d0 /frontends
parent3ecced92f335f80a372cf3fb0ab1c6f7c564cebb (diff)
downloadnetsurf-a2388a91cf9ceb7efb203a7b4d6d250395cdb744.tar.gz
netsurf-a2388a91cf9ceb7efb203a7b4d6d250395cdb744.tar.bz2
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.
Diffstat (limited to 'frontends')
-rw-r--r--frontends/windows/download.c276
-rw-r--r--frontends/windows/font.h4
-rw-r--r--frontends/windows/gui.c10
-rw-r--r--frontends/windows/gui.h2
-rw-r--r--frontends/windows/localhistory.c43
-rw-r--r--frontends/windows/main.c3
-rw-r--r--frontends/windows/window.c198
7 files changed, 310 insertions, 226 deletions
diff --git a/frontends/windows/download.c b/frontends/windows/download.c
index fff47ace8..3a969834e 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 f2128afc5..0e867554a 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 0ab1e32ee..043a93dd9 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 8dd2ded97..efbf02924 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 ce1877f6f..15705d1ad 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 7b93c3b63..7c94c0632 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 cc29d1920..b8c2b39a3 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;
}