diff options
Diffstat (limited to 'frontends/windows/gui.c')
-rw-r--r-- | frontends/windows/gui.c | 153 |
1 files changed, 87 insertions, 66 deletions
diff --git a/frontends/windows/gui.c b/frontends/windows/gui.c index 890bfae42..9a2c13b23 100644 --- a/frontends/windows/gui.c +++ b/frontends/windows/gui.c @@ -36,22 +36,90 @@ #include "utils/file.h" #include "utils/messages.h" #include "netsurf/browser_window.h" -#include "netsurf/clipboard.h" #include "windows/schedule.h" #include "windows/window.h" -#include "windows/filetype.h" #include "windows/gui.h" -/** - * win32 application instance handle. - * - * This handle is set in the main windows entry point. - */ +/* exported global defined in windows/gui.h */ HINSTANCE hinst; +/* exported global defined in windows/gui.h */ +char **G_resource_pathv; + +/* exported global defined in windows/gui.h */ +char *G_config_path; + static bool win32_quit = false; +struct dialog_list_entry { + struct dialog_list_entry *next; + HWND hwnd; +}; + +static struct dialog_list_entry *dlglist = NULL; + +/* exported interface documented in gui.h */ +nserror nsw32_add_dialog(HWND hwndDlg) +{ + struct dialog_list_entry *nentry; + nentry = malloc(sizeof(struct dialog_list_entry)); + if (nentry == NULL) { + return NSERROR_NOMEM; + } + + nentry->hwnd = hwndDlg; + nentry->next = dlglist; + dlglist = nentry; + + return NSERROR_OK; +} + +/* exported interface documented in gui.h */ +nserror nsw32_del_dialog(HWND hwndDlg) +{ + struct dialog_list_entry **prev; + struct dialog_list_entry *cur; + + prev = &dlglist; + cur = *prev; + + while (cur != NULL) { + if (cur->hwnd == hwndDlg) { + /* found match */ + *prev = cur->next; + NSLOG(netsurf, DEBUG, + "removed hwnd %p entry %p", cur->hwnd, cur); + free(cur); + return NSERROR_OK; + } + prev = &cur->next; + cur = *prev; + } + NSLOG(netsurf, INFO, "did not find hwnd %p", hwndDlg); + + return NSERROR_NOT_FOUND; +} + +/** + * walks dialog list and attempts to process any messages for them + */ +static nserror handle_dialog_message(LPMSG lpMsg) +{ + struct dialog_list_entry *cur; + cur = dlglist; + while (cur != NULL) { + if (IsDialogMessage(cur->hwnd, lpMsg)) { + NSLOG(netsurf, DEBUG, + "dispatched dialog hwnd %p", cur->hwnd); + return NSERROR_OK; + } + cur = cur->next; + } + + return NSERROR_NOT_FOUND; +} + /* exported interface documented in gui.h */ void win32_set_quit(bool q) { @@ -92,7 +160,8 @@ void win32_run(void) } } - if (bRet > 0) { + if ((bRet > 0) && + (handle_dialog_message(&Msg) != NSERROR_OK)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } @@ -113,65 +182,17 @@ nserror win32_warning(const char *warning, const char *detail) } -/** - * Core asks front end for clipboard contents. - * - * \param buffer UTF-8 text, allocated by front end, ownership yeilded to core - * \param length Byte length of UTF-8 text in buffer - */ -static void gui_get_clipboard(char **buffer, size_t *length) +/* exported function documented in windows/gui.h */ +nserror +win32_report_nserror(nserror error, const char *detail) { - /* TODO: Implement this */ - HANDLE clipboard_handle; - char *content; - - clipboard_handle = GetClipboardData(CF_TEXT); - if (clipboard_handle != NULL) { - content = GlobalLock(clipboard_handle); - NSLOG(netsurf, INFO, "pasting %s", content); - GlobalUnlock(clipboard_handle); - } -} - + size_t len = 1 + + strlen(messages_get_errorcode(error)) + + ((detail != 0) ? strlen(detail) : 0); + char message[len]; + snprintf(message, len, messages_get_errorcode(error), detail); + MessageBox(NULL, message, "Warning", MB_ICONWARNING); -/** - * Core tells front end to put given text in clipboard - * - * \param buffer UTF-8 text, owned by core - * \param length Byte length of UTF-8 text in buffer - * \param styles Array of styles given to text runs, owned by core, or NULL - * \param n_styles Number of text run styles in array - */ -static void gui_set_clipboard(const char *buffer, size_t length, - nsclipboard_styles styles[], int n_styles) -{ - /* TODO: Implement this */ - HANDLE hnew; - char *new, *original; - HANDLE h = GetClipboardData(CF_TEXT); - if (h == NULL) - original = (char *)""; - else - original = GlobalLock(h); - - size_t len = strlen(original) + 1; - hnew = GlobalAlloc(GHND, length + len); - new = (char *)GlobalLock(hnew); - snprintf(new, length + len, "%s%s", original, buffer); - - if (h != NULL) { - GlobalUnlock(h); - EmptyClipboard(); - } - GlobalUnlock(hnew); - SetClipboardData(CF_TEXT, hnew); + return NSERROR_OK; } - - -static struct gui_clipboard_table clipboard_table = { - .get = gui_get_clipboard, - .set = gui_set_clipboard, -}; - -struct gui_clipboard_table *win32_clipboard_table = &clipboard_table; |