NetSurf
gui.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
3 * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/**
21 * \file
22 * win32 gui implementation.
23 */
24
25#include <stdbool.h>
26#include <sys/types.h>
27#include <sys/stat.h>
28#include <unistd.h>
29#include <windows.h>
30
31#include "utils/errors.h"
32#include "utils/nsurl.h"
33#include "utils/log.h"
34#include "utils/corestrings.h"
35#include "utils/url.h"
36#include "utils/file.h"
37#include "utils/messages.h"
39
40#include "windows/schedule.h"
41#include "windows/window.h"
42#include "windows/gui.h"
43
44/* exported global defined in windows/gui.h */
45HINSTANCE hinst;
46
47/* exported global defined in windows/gui.h */
49
50/* exported global defined in windows/gui.h */
52
53static bool win32_quit = false;
54
57 HWND hwnd;
58};
59
60static struct dialog_list_entry *dlglist = NULL;
61
62/* exported interface documented in gui.h */
64{
65 struct dialog_list_entry *nentry;
66 nentry = malloc(sizeof(struct dialog_list_entry));
67 if (nentry == NULL) {
68 return NSERROR_NOMEM;
69 }
70
71 nentry->hwnd = hwndDlg;
72 nentry->next = dlglist;
73 dlglist = nentry;
74
75 return NSERROR_OK;
76}
77
78/* exported interface documented in gui.h */
80{
81 struct dialog_list_entry **prev;
82 struct dialog_list_entry *cur;
83
84 prev = &dlglist;
85 cur = *prev;
86
87 while (cur != NULL) {
88 if (cur->hwnd == hwndDlg) {
89 /* found match */
90 *prev = cur->next;
91 NSLOG(netsurf, DEBUG,
92 "removed hwnd %p entry %p", cur->hwnd, cur);
93 free(cur);
94 return NSERROR_OK;
95 }
96 prev = &cur->next;
97 cur = *prev;
98 }
99 NSLOG(netsurf, INFO, "did not find hwnd %p", hwndDlg);
100
101 return NSERROR_NOT_FOUND;
102}
103
104/**
105 * walks dialog list and attempts to process any messages for them
106 */
108{
109 struct dialog_list_entry *cur;
110 cur = dlglist;
111 while (cur != NULL) {
112 if (IsDialogMessage(cur->hwnd, lpMsg)) {
113 NSLOG(netsurf, DEBUG,
114 "dispatched dialog hwnd %p", cur->hwnd);
115 return NSERROR_OK;
116 }
117 cur = cur->next;
118 }
119
120 return NSERROR_NOT_FOUND;
121}
122
123/* exported interface documented in gui.h */
124void win32_set_quit(bool q)
125{
126 win32_quit = q;
127}
128
129/* exported interface documented in gui.h */
130void win32_run(void)
131{
132 MSG Msg; /* message from system */
133 BOOL bRet; /* message fetch result */
134 int timeout; /* timeout in miliseconds */
135 UINT timer_id = 0;
136
137 NSLOG(netsurf, INFO, "Starting messgae dispatcher");
138
139 while (!win32_quit) {
140 /* run the scheduler and discover how long to wait for
141 * the next event.
142 */
143 timeout = schedule_run();
144
145 if (timeout == 0) {
146 bRet = PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE);
147 } else {
148 if (timeout > 0) {
149 /* set up a timer to ensure we get woken */
150 timer_id = SetTimer(NULL, 0, timeout, NULL);
151 }
152
153 /* wait for a message */
154 bRet = GetMessage(&Msg, NULL, 0, 0);
155
156 /* if a timer was sucessfully created remove it */
157 if (timer_id != 0) {
158 KillTimer(NULL, timer_id);
159 timer_id = 0;
160 }
161 }
162
163 if ((bRet > 0) &&
165 TranslateMessage(&Msg);
166 DispatchMessage(&Msg);
167 }
168 }
169}
170
171
172/* exported function documented in windows/gui.h */
173nserror win32_warning(const char *warning, const char *detail)
174{
175 size_t len = 1 + ((warning != NULL) ? strlen(messages_get(warning)) :
176 0) + ((detail != 0) ? strlen(detail) : 0);
177 char message[len];
178 snprintf(message, len, messages_get(warning), detail);
179 MessageBox(NULL, message, "Warning", MB_ICONWARNING);
180
181 return NSERROR_OK;
182}
183
184
185/* exported function documented in windows/gui.h */
187win32_report_nserror(nserror error, const char *detail)
188{
189 size_t len = 1 +
190 strlen(messages_get_errorcode(error)) +
191 ((detail != 0) ? strlen(detail) : 0);
192 char message[len];
193 snprintf(message, len, messages_get_errorcode(error), detail);
194 MessageBox(NULL, message, "Warning", MB_ICONWARNING);
195
196 return NSERROR_OK;
197}
198
int schedule_run(void)
Process events up to current time.
Definition: schedule.c:137
Browser window creation and manipulation interface.
Useful interned string pointers (interface).
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOT_FOUND
Requested item not found.
Definition: errors.h:34
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
NetSurf URL handling (interface).
Definition: gui.c:55
struct dialog_list_entry * next
Definition: gui.c:56
HWND hwnd
Definition: gui.c:57
Interface to URL parsing and joining operations.
Default operations table for files.
char ** G_resource_pathv
resource search path vector.
Definition: gui.c:48
char * G_config_path
path to where all user config files are held.
Definition: gui.c:51
nserror nsw32_del_dialog(HWND hwndDlg)
remove a modeless dialog from the special handling list
Definition: gui.c:79
nserror win32_warning(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:173
nserror nsw32_add_dialog(HWND hwndDlg)
add a modeless dialog to the special handling list
Definition: gui.c:63
void win32_run(void)
Run the win32 message loop with scheduling.
Definition: gui.c:130
nserror win32_report_nserror(nserror error, const char *detail)
Warn the user of an unexpected nserror.
Definition: gui.c:187
static bool win32_quit
Definition: gui.c:53
static struct dialog_list_entry * dlglist
Definition: gui.c:60
static nserror handle_dialog_message(LPMSG lpMsg)
walks dialog list and attempts to process any messages for them
Definition: gui.c:107
void win32_set_quit(bool q)
cause the main message loop to exit
Definition: gui.c:124
HINSTANCE hinst
win32 application instance handle.
Definition: gui.c:45