NetSurf
window.c
Go to the documentation of this file.
1/*
2 * Copyright 2011-2016 Vincent Sanders <vince@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Main browser window handling for windows win32 frontend.
22 */
23
24#include "utils/config.h"
25
26#include <stdbool.h>
27#include <windows.h>
28#include <windowsx.h>
29#include <commctrl.h>
30
31#include "utils/errors.h"
32#include "utils/log.h"
33#include "utils/utils.h"
34#include "utils/nsoption.h"
35#include "utils/nsurl.h"
36#include "utils/messages.h"
37#include "content/content.h"
39#include "netsurf/window.h"
40#include "netsurf/keypress.h"
42
43#include "windows/gui.h"
44#include "windows/pointers.h"
45#include "windows/about.h"
46#include "windows/resourceid.h"
47#include "windows/findfile.h"
48#include "windows/windbg.h"
49#include "windows/drawable.h"
50#include "windows/font.h"
51#include "windows/prefs.h"
53#include "windows/hotlist.h"
54#include "windows/cookies.h"
56#include "windows/window.h"
57
58/**
59 * List of all gui windows
60 */
61static struct gui_window *window_list = NULL;
62
63/**
64 * The main window class name
65 */
66static const LPCWSTR windowclassname_main = L"nswsmainwindow";
67
68/**
69 * width of the throbber element
70 */
71#define NSWS_THROBBER_WIDTH 24
72
73/**
74 * height of the url entry box
75 */
76#define NSWS_URLBAR_HEIGHT 23
77
78/**
79 * height of the Page Information bitmap button
80 */
81#define NSW32_PGIBUTTON_HEIGHT 16
82
83/**
84 * Number of open windows
85 */
86static int open_windows = 0;
87
88
89/**
90 * create and attach accelerator table to main window
91 *
92 * \param gw gui window context.
93 */
94static void nsws_window_set_accels(struct gui_window *gw)
95{
96 int i, nitems = 13;
97 ACCEL accels[nitems];
98
99 for (i = 0; i < nitems; i++) {
100 accels[i].fVirt = FCONTROL | FVIRTKEY;
101 }
102
103 accels[0].key = 0x51; /* Q */
104 accels[0].cmd = IDM_FILE_QUIT;
105 accels[1].key = 0x4E; /* N */
106 accels[1].cmd = IDM_FILE_OPEN_WINDOW;
107 accels[2].key = VK_LEFT;
108 accels[2].cmd = IDM_NAV_BACK;
109 accels[3].key = VK_RIGHT;
110 accels[3].cmd = IDM_NAV_FORWARD;
111 accels[4].key = VK_UP;
112 accels[4].cmd = IDM_NAV_HOME;
113 accels[5].key = VK_BACK;
114 accels[5].cmd = IDM_NAV_STOP;
115 accels[6].key = VK_SPACE;
116 accels[6].cmd = IDM_NAV_RELOAD;
117 accels[7].key = 0x4C; /* L */
118 accels[7].cmd = IDM_FILE_OPEN_LOCATION;
119 accels[8].key = 0x57; /* w */
120 accels[8].cmd = IDM_FILE_CLOSE_WINDOW;
121 accels[9].key = 0x41; /* A */
122 accels[9].cmd = IDM_EDIT_SELECT_ALL;
123 accels[10].key = VK_F8;
124 accels[10].cmd = IDM_VIEW_SOURCE;
125 accels[11].key = VK_RETURN;
126 accels[11].fVirt = FVIRTKEY;
127 accels[11].cmd = IDC_MAIN_LAUNCH_URL;
128 accels[12].key = VK_F11;
129 accels[12].fVirt = FVIRTKEY;
130 accels[12].cmd = IDM_VIEW_FULLSCREEN;
131
132 gw->acceltable = CreateAcceleratorTable(accels, nitems);
133}
134
135
136/**
137 * creation of a new full browser window
138 *
139 * \param hInstance The application instance handle.
140 * \param gw gui window context.
141 * \return The newly created window instance.
142 */
143static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw)
144{
145 HWND hwnd;
146 INITCOMMONCONTROLSEX icc;
147 int xpos = CW_USEDEFAULT;
148 int ypos = CW_USEDEFAULT;
149 int width = CW_USEDEFAULT;
150 int height = CW_USEDEFAULT;
151
152 if ((nsoption_int(window_width) >= 100) &&
153 (nsoption_int(window_height) >= 100) &&
154 (nsoption_int(window_x) >= 0) &&
155 (nsoption_int(window_y) >= 0)) {
156 xpos = nsoption_int(window_x);
157 ypos = nsoption_int(window_y);
158 width = nsoption_int(window_width);
159 height = nsoption_int(window_height);
160
161 NSLOG(netsurf, DEBUG, "Setting Window position %d,%d %d,%d",
162 xpos, ypos, width, height);
163 }
164
165 icc.dwSize = sizeof(icc);
166 icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES;
167#if WINVER > 0x0501
168 icc.dwICC |= ICC_STANDARD_CLASSES;
169#endif
170 InitCommonControlsEx(&icc);
171
172 gw->mainmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN));
173 gw->rclick = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT));
174
175 hwnd = CreateWindowExW(0,
177 L"NetSurf Browser",
178 WS_OVERLAPPEDWINDOW |
179 WS_CLIPCHILDREN |
180 WS_CLIPSIBLINGS |
181 CS_DBLCLKS,
182 xpos,
183 ypos,
184 width,
185 height,
186 NULL,
187 gw->mainmenu,
188 hInstance,
189 (LPVOID)gw);
190
191 if (hwnd == NULL) {
192 NSLOG(netsurf, INFO, "Window create failed");
193 } else {
195 }
196
197 return hwnd;
198}
199
200
201/**
202 * toolbar command message handler
203 *
204 * \todo This entire command handler appears superfluous.
205 *
206 * \param gw The graphical window context
207 * \param notification_code The notification code of the message
208 * \param identifier The identifier the command was delivered for
209 * \param ctrl_window The controlling window.
210 */
211static LRESULT
213 int notification_code,
214 int identifier,
215 HWND ctrl_window)
216{
217 NSLOG(netsurf, DEBUG,
218 "notification_code %d identifier %d ctrl_window %p",
219 notification_code,
220 identifier,
221 ctrl_window);
222
223 switch(identifier) {
224
225 case IDC_MAIN_URLBAR:
226 switch (notification_code) {
227 case EN_CHANGE:
228 NSLOG(netsurf, DEBUG, "EN_CHANGE");
229 break;
230
231 case EN_ERRSPACE:
232 NSLOG(netsurf, DEBUG, "EN_ERRSPACE");
233 break;
234
235 case EN_HSCROLL:
236 NSLOG(netsurf, DEBUG, "EN_HSCROLL");
237 break;
238
239 case EN_KILLFOCUS:
240 NSLOG(netsurf, DEBUG, "EN_KILLFOCUS");
241 break;
242
243 case EN_MAXTEXT:
244 NSLOG(netsurf, DEBUG, "EN_MAXTEXT");
245 break;
246
247 case EN_SETFOCUS:
248 NSLOG(netsurf, DEBUG, "EN_SETFOCUS");
249 break;
250
251 case EN_UPDATE:
252 NSLOG(netsurf, DEBUG, "EN_UPDATE");
253 break;
254
255 case EN_VSCROLL:
256 NSLOG(netsurf, DEBUG, "EN_VSCROLL");
257 break;
258
259 default:
260 NSLOG(netsurf, DEBUG, "Unknown notification_code");
261 break;
262 }
263 break;
264
265 default:
266 return 1; /* unhandled */
267
268 }
269 return 0; /* control message handled */
270}
271
272
273/**
274 * calculate the dimensions of the url bar relative to the parent toolbar
275 *
276 * \param hWndParent The parent window of the url bar
277 * \param toolbuttonsize size of the buttons
278 * \param buttonc The number of buttons
279 * \param[out] x The calculated x location
280 * \param[out] y The calculated y location
281 * \param[out] width The calculated width
282 * \param[out] height The calculated height
283 */
284static void
285urlbar_dimensions(HWND hWndParent,
286 int toolbuttonsize,
287 int buttonc,
288 int *x,
289 int *y,
290 int *width,
291 int *height)
292{
293 RECT rc;
294 const int cy_edit = NSWS_URLBAR_HEIGHT;
295
296 GetClientRect(hWndParent, &rc);
297 *x = (toolbuttonsize + 1) * (buttonc + 1) + (NSWS_THROBBER_WIDTH>>1);
298 *y = ((((rc.bottom - 1) - cy_edit) >> 1) * 2) / 3;
299 *width = (rc.right - 1) - *x - (NSWS_THROBBER_WIDTH>>1) - NSWS_THROBBER_WIDTH;
300 *height = cy_edit;
301}
302
303
304/**
305 * callback for toolbar events
306 *
307 * subclass message handler for toolbar window
308 *
309 * \param hwnd win32 window handle message arrived for
310 * \param msg The message ID
311 * \param wparam The w parameter of the message.
312 * \param lparam The l parameter of the message.
313 */
314static LRESULT CALLBACK
315nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
316{
317 struct gui_window *gw;
318 int urlx, urly, urlwidth, urlheight;
319 WNDPROC toolproc;
320
321 LOG_WIN_MSG(hwnd, msg, wparam, lparam);
322
323 toolproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc"));
324 assert(toolproc != NULL);
325
326 gw = nsws_get_gui_window(hwnd);
327 assert(gw != NULL);
328
329 switch (msg) {
330 case WM_SIZE:
332 gw->toolbuttonsize,
333 gw->toolbuttonc,
334 &urlx, &urly, &urlwidth, &urlheight);
335
336 /* resize url */
337 if (gw->urlbar != NULL) {
338 MoveWindow(gw->urlbar,
339 urlx, urly,
340 urlwidth, urlheight,
341 true);
342 }
343
344 /* move throbber */
345 if (gw->throbber != NULL) {
346 MoveWindow(gw->throbber,
347 LOWORD(lparam) - NSWS_THROBBER_WIDTH - 4,
348 urly,
351 true);
352 }
353 break;
354
355 case WM_COMMAND:
357 HIWORD(wparam),
358 LOWORD(wparam),
359 (HWND)lparam) == 0) {
360 return 0;
361 }
362 break;
363
364 case WM_NCDESTROY:
365 /* remove properties if window is being destroyed */
366 RemoveProp(hwnd, TEXT("GuiWnd"));
367 RemoveProp(hwnd, TEXT("OrigMsgProc"));
368 /* put the original message handler back */
369 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)toolproc);
370 break;
371
372 }
373
374 /* chain to the next handler */
375 return CallWindowProc(toolproc, hwnd, msg, wparam, lparam);
376}
377
378
379static void set_urlbar_edit_size(HWND hwnd)
380{
381 RECT rc;
382 GetClientRect(hwnd, &rc);
383 rc.left += NSW32_PGIBUTTON_HEIGHT;
384 SendMessage(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
385 NSLOG(netsurf, DEBUG, "left:%ld right:%ld top:%ld bot:%ld",
386 rc.left,rc.right,rc.top,rc.bottom);
387}
388
389
390/**
391 * callback for url bar events
392 *
393 * subclass message handler for urlbar window
394 *
395 * \param hwnd win32 window handle message arrived for
396 * \param msg The message ID
397 * \param wparam The w parameter of the message.
398 * \param lparam The l parameter of the message.
399 */
400static LRESULT CALLBACK
401nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
402{
403 struct gui_window *gw;
404 WNDPROC urlproc;
405 HFONT hFont;
406 LRESULT result;
407
408 LOG_WIN_MSG(hwnd, msg, wparam, lparam);
409
410 urlproc = (WNDPROC)GetProp(hwnd, TEXT("OrigMsgProc"));
411 assert(urlproc != NULL);
412
413 gw = nsws_get_gui_window(hwnd);
414 assert(gw != NULL);
415
416 /* override messages */
417 switch (msg) {
418 case WM_CHAR:
419 if (wparam == 1) {
420 /* handle ^A */
421 SendMessage(hwnd, EM_SETSEL, 0, -1);
422 return 1;
423 } else if (wparam == 13) {
424 SendMessage(gw->main, WM_COMMAND, IDC_MAIN_LAUNCH_URL, 0);
425 return 0;
426 }
427 break;
428
429 case WM_DESTROY:
430 hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
431 if (hFont != NULL) {
432 NSLOG(netsurf, INFO, "Destroyed font object");
433 DeleteObject(hFont);
434 }
436
437 case WM_NCDESTROY:
438 /* remove properties if window is being destroyed */
439 RemoveProp(hwnd, TEXT("GuiWnd"));
440 RemoveProp(hwnd, TEXT("OrigMsgProc"));
441 /* put the original message handler back */
442 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)urlproc);
443 break;
444
445 case WM_SIZE:
446 result = CallWindowProc(urlproc, hwnd, msg, wparam, lparam);
448 return result;
449
450 }
451
452 /* chain to the next handler */
453 return CallWindowProc(urlproc, hwnd, msg, wparam, lparam);
454}
455
456/**
457 * create a urlbar and message handler
458 *
459 * Create an Edit control for entering urls
460 *
461 * \param hInstance The application instance handle.
462 * \param hWndParent The containing window.
463 * \param gw win32 frontends window context.
464 * \return win32 window handle of created window or NULL on error.
465 */
466static HWND
467nsws_window_urlbar_create(HINSTANCE hInstance,
468 HWND hWndParent,
469 struct gui_window *gw)
470{
471 int urlx, urly, urlwidth, urlheight;
472 HWND hwnd;
473 HWND hbutton;
474 WNDPROC urlproc;
475 HFONT hFont;
476
477 urlbar_dimensions(hWndParent,
478 gw->toolbuttonsize,
479 gw->toolbuttonc,
480 &urlx, &urly, &urlwidth, &urlheight);
481
482 /* Create the edit control */
483 hwnd = CreateWindowEx(0L,
484 TEXT("Edit"),
485 NULL,
486 WS_CHILD | WS_BORDER | WS_VISIBLE |
487 ES_LEFT | ES_AUTOHSCROLL | ES_MULTILINE,
488 urlx,
489 urly,
490 urlwidth,
491 urlheight,
492 hWndParent,
493 (HMENU)IDC_MAIN_URLBAR,
494 hInstance,
495 NULL);
496
497 if (hwnd == NULL) {
498 return NULL;
499 }
500
501 /* set the gui window associated with this control */
502 SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw);
503
504 /* subclass the message handler */
505 urlproc = (WNDPROC)SetWindowLongPtr(hwnd,
506 GWLP_WNDPROC,
508
509 /* save the real handler */
510 SetProp(hwnd, TEXT("OrigMsgProc"), (HANDLE)urlproc);
511
512 hFont = CreateFont(urlheight - 4, 0, 0, 0, FW_BOLD, FALSE, FALSE,
513 FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
514 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
515 DEFAULT_PITCH | FF_SWISS, "Arial");
516 if (hFont != NULL) {
517 NSLOG(netsurf, INFO, "Setting font object");
518 SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0);
519 }
520
521
522 /* Create the page info button */
523 hbutton = CreateWindowEx(0L,
524 TEXT("BUTTON"),
525 NULL,
526 WS_CHILD | WS_VISIBLE | BS_BITMAP | BS_FLAT,
531 hwnd,
532 (HMENU)IDC_PAGEINFO,
533 hInstance,
534 NULL);
535
536 /* put a property on the parent toolbar so it can set the page info */
537 SetProp(hWndParent, TEXT("hPGIbutton"), (HANDLE)hbutton);
538
539 SendMessageW(hbutton, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)gw->hPageInfo[PAGE_STATE_UNKNOWN]);
540
542
543 NSLOG(netsurf, INFO,
544 "Created url bar hwnd:%p, x:%d, y:%d, w:%d, h:%d", hwnd, urlx,
545 urly, urlwidth, urlheight);
546
547 return hwnd;
548}
549
550
551/**
552 * creation of throbber
553 *
554 * \param hInstance The application instance handle.
555 * \param hWndParent The containing window.
556 * \param gw win32 frontends window context.
557 * \return win32 window handle of created window or NULL on error.
558 */
559static HWND
560nsws_window_throbber_create(HINSTANCE hInstance,
561 HWND hWndParent,
562 struct gui_window *gw)
563{
564 HWND hwnd;
565 int urlx, urly, urlwidth, urlheight;
566
567 urlbar_dimensions(hWndParent,
568 gw->toolbuttonsize,
569 gw->toolbuttonc,
570 &urlx, &urly, &urlwidth, &urlheight);
571
572 hwnd = CreateWindow(ANIMATE_CLASS,
573 "",
574 WS_CHILD | WS_VISIBLE | ACS_TRANSPARENT,
575 gw->width - NSWS_THROBBER_WIDTH - 4,
576 urly,
579 hWndParent,
580 (HMENU) IDC_MAIN_THROBBER,
581 hInstance,
582 NULL);
583
584 Animate_Open(hwnd, MAKEINTRESOURCE(IDR_THROBBER_AVI));
585
586 if (gw->throbbing) {
587 Animate_Play(hwnd, 0, -1, -1);
588 } else {
589 Animate_Seek(hwnd, 0);
590 }
591 ShowWindow(hwnd, SW_SHOWNORMAL);
592
593 return hwnd;
594}
595
596
597/**
598 * create a win32 image list for the toolbar.
599 *
600 * \param hInstance The application instance handle.
601 * \param resid The resource ID of the image.
602 * \param bsize The size of the image to load.
603 * \param bcnt The number of bitmaps to load into the list.
604 * \return The image list or NULL on error.
605 */
606static HIMAGELIST
607get_imagelist(HINSTANCE hInstance, int resid, int bsize, int bcnt)
608{
609 HIMAGELIST hImageList;
610 HBITMAP hScrBM;
611
612 NSLOG(netsurf, INFO, "resource id %d, bzize %d, bcnt %d", resid,
613 bsize, bcnt);
614
615 hImageList = ImageList_Create(bsize, bsize,
616 ILC_COLOR24 | ILC_MASK, 0,
617 bcnt);
618 if (hImageList == NULL) {
619 return NULL;
620 }
621
622 hScrBM = LoadImage(hInstance,
623 MAKEINTRESOURCE(resid),
624 IMAGE_BITMAP,
625 0,
626 0,
627 LR_DEFAULTCOLOR);
628 if (hScrBM == NULL) {
629 win_perror("LoadImage");
630 return NULL;
631 }
632
633 if (ImageList_AddMasked(hImageList, hScrBM, 0xcccccc) == -1) {
634 /* failed to add masked bitmap */
635 ImageList_Destroy(hImageList);
636 hImageList = NULL;
637 }
638 DeleteObject(hScrBM);
639
640 return hImageList;
641}
642
643
644/**
645 * create win32 main window toolbar and add controls and message handler
646 *
647 * Toolbar has buttons on the left, url entry space in the middle and
648 * activity throbber on the right.
649 *
650 * \param hInstance The application instance handle.
651 * \param hWndParent The containing window.
652 * \param gw win32 frontends window context.
653 * \return win32 window handle of created window or NULL on error.
654 */
655static HWND
656nsws_window_create_toolbar(HINSTANCE hInstance,
657 HWND hWndParent,
658 struct gui_window *gw)
659{
660 HIMAGELIST hImageList;
661 HWND hWndToolbar;
662 /* Toolbar buttons */
663 TBBUTTON tbButtons[] = {
664 {0, IDM_NAV_BACK, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
665 {1, IDM_NAV_FORWARD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
666 {2, IDM_NAV_HOME, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
667 {3, IDM_NAV_RELOAD, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
668 {4, IDM_NAV_STOP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
669 };
670 WNDPROC toolproc;
671
672 /* Create the toolbar window and subclass its message handler. */
673 hWndToolbar = CreateWindowEx(0,
674 TOOLBARCLASSNAME,
675 "Toolbar",
676 WS_CHILD | TBSTYLE_FLAT,
677 0, 0, 0, 0,
678 hWndParent,
679 NULL,
680 HINST_COMMCTRL,
681 NULL);
682 if (!hWndToolbar) {
683 return NULL;
684 }
685
686 /* set the gui window associated with this toolbar */
687 SetProp(hWndToolbar, TEXT("GuiWnd"), (HANDLE)gw);
688
689 /* subclass the message handler */
690 toolproc = (WNDPROC)SetWindowLongPtr(hWndToolbar,
691 GWLP_WNDPROC,
693
694 /* save the real handler */
695 SetProp(hWndToolbar, TEXT("OrigMsgProc"), (HANDLE)toolproc);
696
697 /* remember how many buttons are being created */
698 gw->toolbuttonc = sizeof(tbButtons) / sizeof(TBBUTTON);
699
700 /* Create the standard image list and assign to toolbar. */
701 hImageList = get_imagelist(hInstance,
703 gw->toolbuttonsize,
704 gw->toolbuttonc);
705 if (hImageList != NULL) {
706 SendMessage(hWndToolbar,
707 TB_SETIMAGELIST,
708 0,
709 (LPARAM)hImageList);
710 }
711
712 /* Create the disabled image list and assign to toolbar. */
713 hImageList = get_imagelist(hInstance,
715 gw->toolbuttonsize,
716 gw->toolbuttonc);
717 if (hImageList != NULL) {
718 SendMessage(hWndToolbar,
719 TB_SETDISABLEDIMAGELIST,
720 0,
721 (LPARAM)hImageList);
722 }
723
724 /* Create the hot image list and assign to toolbar. */
725 hImageList = get_imagelist(hInstance,
727 gw->toolbuttonsize,
728 gw->toolbuttonc);
729 if (hImageList != NULL) {
730 SendMessage(hWndToolbar,
731 TB_SETHOTIMAGELIST,
732 0,
733 (LPARAM)hImageList);
734 }
735
736 /* Add buttons. */
737 SendMessage(hWndToolbar,
738 TB_BUTTONSTRUCTSIZE,
739 (WPARAM)sizeof(TBBUTTON),
740 0);
741
742 SendMessage(hWndToolbar,
743 TB_ADDBUTTONS,
744 (WPARAM)gw->toolbuttonc,
745 (LPARAM)&tbButtons);
746
747 /* create url widget */
748 gw->urlbar = nsws_window_urlbar_create(hInstance, hWndToolbar, gw);
749
750 /* create throbber widget */
751 gw->throbber = nsws_window_throbber_create(hInstance, hWndToolbar, gw);
752
753 SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
754 ShowWindow(hWndToolbar, TRUE);
755
756 return hWndToolbar;
757}
758
759
760/**
761 * creation of status bar
762 *
763 * \param hInstance The application instance handle.
764 * \param hWndParent The containing window.
765 * \param gw win32 frontends window context.
766 */
767static HWND
769 HWND hWndParent,
770 struct gui_window *gw)
771{
772 HWND hwnd;
773 hwnd = CreateWindowEx(0,
774 STATUSCLASSNAME,
775 NULL,
776 WS_CHILD | WS_VISIBLE,
777 0, 0, 0, 0,
778 hWndParent,
779 (HMENU)IDC_MAIN_STATUSBAR,
780 hInstance,
781 NULL);
782 if (hwnd != NULL) {
783 SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)"NetSurf");
784 }
785 return hwnd;
786}
787
788
789/**
790 * Update popup context menu editing functionality
791 *
792 * \param w win32 frontends window context.
793 */
794static void nsws_update_edit(struct gui_window *w)
795{
796 browser_editor_flags editor_flags = (w->bw == NULL) ?
798 bool paste, copy, del;
799 bool sel = (editor_flags & BW_EDITOR_CAN_COPY);
800
801 if (GetFocus() == w->urlbar) {
802 DWORD i, ii;
803 SendMessage(w->urlbar, EM_GETSEL, (WPARAM)&i, (LPARAM)&ii);
804 paste = true;
805 copy = (i != ii);
806 del = (i != ii);
807
808 } else if (sel) {
809 paste = (editor_flags & BW_EDITOR_CAN_PASTE);
810 copy = sel;
811 del = (editor_flags & BW_EDITOR_CAN_CUT);
812 } else {
813 paste = false;
814 copy = false;
815 del = false;
816 }
817 EnableMenuItem(w->mainmenu,
819 (paste ? MF_ENABLED : MF_GRAYED));
820
821 EnableMenuItem(w->rclick,
823 (paste ? MF_ENABLED : MF_GRAYED));
824
825 EnableMenuItem(w->mainmenu,
827 (copy ? MF_ENABLED : MF_GRAYED));
828
829 EnableMenuItem(w->rclick,
831 (copy ? MF_ENABLED : MF_GRAYED));
832
833 if (del == true) {
834 EnableMenuItem(w->mainmenu, IDM_EDIT_CUT, MF_ENABLED);
835 EnableMenuItem(w->mainmenu, IDM_EDIT_DELETE, MF_ENABLED);
836 EnableMenuItem(w->rclick, IDM_EDIT_CUT, MF_ENABLED);
837 EnableMenuItem(w->rclick, IDM_EDIT_DELETE, MF_ENABLED);
838 } else {
839 EnableMenuItem(w->mainmenu, IDM_EDIT_CUT, MF_GRAYED);
840 EnableMenuItem(w->mainmenu, IDM_EDIT_DELETE, MF_GRAYED);
841 EnableMenuItem(w->rclick, IDM_EDIT_CUT, MF_GRAYED);
842 EnableMenuItem(w->rclick, IDM_EDIT_DELETE, MF_GRAYED);
843 }
844}
845
846
847/**
848 * Handle win32 context menu message
849 *
850 * \param gw win32 frontends graphical window.
851 * \param hwnd The win32 window handle
852 * \param x The x coordinate of the event.
853 * \param y the y coordinate of the event.
854 * \return true if menu displayed else false
855 */
856static bool
857nsws_ctx_menu(struct gui_window *gw, HWND hwnd, int x, int y)
858{
859 RECT rc; /* client area of window */
860 POINT pt = { x, y }; /* location of mouse click */
861
862 /* Get the bounding rectangle of the client area. */
863 GetClientRect(hwnd, &rc);
864
865 /* Convert the mouse position to client coordinates. */
866 ScreenToClient(hwnd, &pt);
867
868 /* If the position is in the client area, display a shortcut menu. */
869 if (PtInRect(&rc, pt)) {
870 ClientToScreen(hwnd, &pt);
872 TrackPopupMenu(GetSubMenu(gw->rclick, 0),
873 TPM_CENTERALIGN | TPM_TOPALIGN,
874 x,
875 y,
876 0,
877 hwnd,
878 NULL);
879
880 return true;
881 }
882
883 /* Return false if no menu is displayed. */
884 return false;
885}
886
887
888/**
889 * update state of forward/back buttons/menu items when page changes
890 *
891 * \param w win32 frontends graphical window.
892 */
894{
895 if (w->bw == NULL)
896 return;
897
900
901 if (w->mainmenu != NULL) {
902 EnableMenuItem(w->mainmenu, IDM_NAV_FORWARD,
903 (forward ? MF_ENABLED : MF_GRAYED));
904 EnableMenuItem(w->mainmenu, IDM_NAV_BACK,
905 (back ? MF_ENABLED : MF_GRAYED));
906 EnableMenuItem(w->rclick, IDM_NAV_FORWARD,
907 (forward ? MF_ENABLED : MF_GRAYED));
908 EnableMenuItem(w->rclick, IDM_NAV_BACK,
909 (back ? MF_ENABLED : MF_GRAYED));
910 }
911
912 if (w->toolbar != NULL) {
913 SendMessage(w->toolbar, TB_SETSTATE,
914 (WPARAM) IDM_NAV_FORWARD,
915 MAKELONG((forward ? TBSTATE_ENABLED :
916 TBSTATE_INDETERMINATE), 0));
917 SendMessage(w->toolbar, TB_SETSTATE,
918 (WPARAM) IDM_NAV_BACK,
919 MAKELONG((back ? TBSTATE_ENABLED :
920 TBSTATE_INDETERMINATE), 0));
921 }
923}
924
925
926/**
927 * Invalidate an area of a win32 browser window
928 *
929 * \param gw The netsurf window being invalidated.
930 * \param rect area to redraw or NULL for entrire window area.
931 * \return NSERROR_OK or appropriate error code.
932 */
933static nserror
935{
936 RECT *redrawrectp = NULL;
937 RECT redrawrect;
938
939 assert(gw != NULL);
940
941 if (rect != NULL) {
942 redrawrectp = &redrawrect;
943
944 redrawrect.left = (long)rect->x0 - gw->scrollx;
945 redrawrect.top = (long)rect->y0 - gw->scrolly;
946 redrawrect.right =(long)rect->x1;
947 redrawrect.bottom = (long)rect->y1;
948
949 }
950 RedrawWindow(gw->drawingarea,
951 redrawrectp,
952 NULL,
953 RDW_INVALIDATE | RDW_NOERASE);
954
955 return NSERROR_OK;
956}
957
958
959/**
960 * Create a new window due to menu selection
961 *
962 * \param gw frontends graphical window.
963 * \return NSERROR_OK on success else appropriate error code.
964 */
966{
967 const char *addr;
968 nsurl *url;
969 nserror ret;
970
971 if (nsoption_charp(homepage_url) != NULL) {
972 addr = nsoption_charp(homepage_url);
973 } else {
974 addr = NETSURF_HOMEPAGE;
975 }
976
977 ret = nsurl_create(addr, &url);
978 if (ret == NSERROR_OK) {
980 url,
981 NULL,
982 gw->bw,
983 NULL);
985 }
986
987 return ret;
988}
989
990
991/**
992 * handle command message on main browser window
993 *
994 * \param hwnd The win32 window handle
995 * \param gw win32 gui window
996 * \param notification_code notification code
997 * \param identifier notification identifier
998 * \param ctrl_window The win32 control window handle
999 * \return appropriate response for command
1000 */
1001static LRESULT
1003 struct gui_window *gw,
1004 int notification_code,
1005 int identifier,
1006 HWND ctrl_window)
1007{
1008 nserror ret;
1009
1010 NSLOG(netsurf, INFO,
1011 "notification_code %x identifier %x ctrl_window %p",
1012 notification_code,
1013 identifier,
1014 ctrl_window);
1015
1016 switch(identifier) {
1017
1018 case IDM_FILE_QUIT:
1019 {
1020 struct gui_window *w;
1021 w = window_list;
1022 while (w != NULL) {
1023 PostMessage(w->main, WM_CLOSE, 0, 0);
1024 w = w->next;
1025 }
1026 break;
1027 }
1028
1030 SetFocus(gw->urlbar);
1031 break;
1032
1034 ret = win32_open_new_window(gw);
1035 if (ret != NSERROR_OK) {
1037 }
1038 break;
1039
1041 PostMessage(gw->main, WM_CLOSE, 0, 0);
1042 break;
1043
1044 case IDM_FILE_SAVE_PAGE:
1045 break;
1046
1048 break;
1049
1051 break;
1052
1054 break;
1055
1057 break;
1058
1059 case IDM_FILE_PRINT:
1060 break;
1061
1062 case IDM_EDIT_CUT:
1063 if (GetFocus() == gw->urlbar) {
1064 SendMessage(gw->urlbar, WM_CUT, 0, 0);
1065 } else {
1066 SendMessage(gw->drawingarea, WM_CUT, 0, 0);
1067 }
1068 break;
1069
1070 case IDM_EDIT_COPY:
1071 if (GetFocus() == gw->urlbar) {
1072 SendMessage(gw->urlbar, WM_COPY, 0, 0);
1073 } else {
1074 SendMessage(gw->drawingarea, WM_COPY, 0, 0);
1075 }
1076 break;
1077
1078 case IDM_EDIT_PASTE: {
1079 if (GetFocus() == gw->urlbar) {
1080 SendMessage(gw->urlbar, WM_PASTE, 0, 0);
1081 } else {
1082 SendMessage(gw->drawingarea, WM_PASTE, 0, 0);
1083 }
1084 break;
1085 }
1086
1087 case IDM_EDIT_DELETE:
1088 if (GetFocus() == gw->urlbar)
1089 SendMessage(gw->urlbar, WM_CLEAR, 0, 0);
1090 else
1091 SendMessage(gw->drawingarea, WM_CLEAR, 0, 0);
1092 break;
1093
1095 if (GetFocus() == gw->urlbar)
1096 SendMessage(gw->urlbar, EM_SETSEL, 0, -1);
1097 else
1099 break;
1100
1101 case IDM_EDIT_SEARCH:
1102 break;
1103
1106 break;
1107
1108 case IDM_NAV_BACK:
1109 if ((gw->bw != NULL) &&
1111 browser_window_history_back(gw->bw, false);
1112 }
1114 break;
1115
1116 case IDM_NAV_FORWARD:
1117 if ((gw->bw != NULL) &&
1120 }
1122 break;
1123
1124 case IDM_NAV_HOME:
1125 {
1126 nsurl *url;
1127 ret = nsurl_create(nsoption_charp(homepage_url), &url);
1128
1129 if (ret != NSERROR_OK) {
1130 win32_report_nserror(ret, 0);
1131 } else {
1133 url,
1134 NULL,
1136 NULL,
1137 NULL,
1138 NULL);
1140 }
1141 break;
1142 }
1143
1144 case IDM_NAV_STOP:
1146 break;
1147
1148 case IDM_NAV_RELOAD:
1149 browser_window_reload(gw->bw, true);
1150 break;
1151
1154 break;
1155
1158 break;
1159
1160 case IDM_TOOLS_COOKIES:
1162 break;
1163
1164 case IDM_NAV_BOOKMARKS:
1166 break;
1167
1168 case IDM_VIEW_ZOOMPLUS:
1169 browser_window_set_scale(gw->bw, 0.1, false);
1170 break;
1171
1172 case IDM_VIEW_ZOOMMINUS:
1173 browser_window_set_scale(gw->bw, -0.1, false);
1174 break;
1175
1177 browser_window_set_scale(gw->bw, 1.0, true);
1178 break;
1179
1180 case IDM_VIEW_SOURCE:
1181 break;
1182
1184 RECT r;
1185 GetWindowRect(gw->main, &r);
1186 nsoption_set_int(window_x, r.left);
1187 nsoption_set_int(window_y, r.top);
1188 nsoption_set_int(window_width, r.right - r.left);
1189 nsoption_set_int(window_height, r.bottom - r.top);
1190
1192 break;
1193 }
1194
1195 case IDM_VIEW_FULLSCREEN: {
1196 RECT rdesk;
1197 if (gw->fullscreen == NULL) {
1198 HWND desktop = GetDesktopWindow();
1199 gw->fullscreen = malloc(sizeof(RECT));
1200 if ((desktop == NULL) ||
1201 (gw->fullscreen == NULL)) {
1202 win32_warning("NoMemory", 0);
1203 break;
1204 }
1205 GetWindowRect(desktop, &rdesk);
1206 GetWindowRect(gw->main, gw->fullscreen);
1207 DeleteObject(desktop);
1208 SetWindowLong(gw->main, GWL_STYLE, 0);
1209 SetWindowPos(gw->main, HWND_TOPMOST, 0, 0,
1210 rdesk.right - rdesk.left,
1211 rdesk.bottom - rdesk.top,
1212 SWP_SHOWWINDOW);
1213 } else {
1214 SetWindowLong(gw->main, GWL_STYLE,
1215 WS_OVERLAPPEDWINDOW |
1216 WS_HSCROLL | WS_VSCROLL |
1217 WS_CLIPCHILDREN |
1218 WS_CLIPSIBLINGS | CS_DBLCLKS);
1219 SetWindowPos(gw->main, HWND_TOPMOST,
1220 gw->fullscreen->left,
1221 gw->fullscreen->top,
1222 gw->fullscreen->right -
1223 gw->fullscreen->left,
1224 gw->fullscreen->bottom -
1225 gw->fullscreen->top,
1226 SWP_SHOWWINDOW | SWP_FRAMECHANGED);
1227 free(gw->fullscreen);
1228 gw->fullscreen = NULL;
1229 }
1230 break;
1231 }
1232
1234 break;
1235
1237 if (gw->bw != NULL) {
1239 /* TODO: This should only redraw, not reformat.
1240 * (Layout doesn't change, so reformat is a waste of time) */
1242 }
1243 break;
1244
1246 break;
1247
1249 break;
1250
1251 case IDM_HELP_CONTENTS:
1252 nsws_window_go(hwnd,
1253 "https://www.netsurf-browser.org/documentation/");
1254 break;
1255
1256 case IDM_HELP_GUIDE:
1257 nsws_window_go(hwnd,
1258 "https://www.netsurf-browser.org/documentation/guide");
1259 break;
1260
1261 case IDM_HELP_INFO:
1262 nsws_window_go(hwnd,
1263 "https://www.netsurf-browser.org/documentation/info");
1264 break;
1265
1266 case IDM_HELP_ABOUT:
1268 break;
1269
1271 {
1272 nsurl *url;
1273 nserror err;
1274
1275 if (GetFocus() != gw->urlbar)
1276 break;
1277
1278 int len = SendMessage(gw->urlbar, WM_GETTEXTLENGTH, 0, 0);
1279 char addr[len + 1];
1280 SendMessage(gw->urlbar, WM_GETTEXT, (WPARAM)(len + 1), (LPARAM)addr);
1281 NSLOG(netsurf, INFO, "launching %s\n", addr);
1282
1283 err = nsurl_create(addr, &url);
1284
1285 if (err != NSERROR_OK) {
1286 win32_report_nserror(err, 0);
1287 } else {
1289 url,
1290 NULL,
1292 NULL,
1293 NULL,
1294 NULL);
1296 }
1297
1298 break;
1299 }
1300
1301
1302 default:
1303 return 1; /* unhandled */
1304
1305 }
1306 return 0; /* control message handled */
1307}
1308
1309
1310/**
1311 * Get the scroll position of a win32 browser window.
1312 *
1313 * \param gw gui_window
1314 * \param sx receives x ordinate of point at top-left of window
1315 * \param sy receives y ordinate of point at top-left of window
1316 * \return true iff successful
1317 */
1318static bool win32_window_get_scroll(struct gui_window *gw, int *sx, int *sy)
1319{
1320 NSLOG(netsurf, INFO, "get scroll");
1321 if (gw == NULL)
1322 return false;
1323
1324 *sx = gw->scrollx;
1325 *sy = gw->scrolly;
1326
1327 return true;
1328}
1329
1330
1331/**
1332 * handle WM_SIZE message on main browser window
1333 *
1334 * \param gw win32 gui window
1335 * \param hwnd The win32 window handle
1336 * \param wparam The w win32 parameter
1337 * \param lparam The l win32 parameter
1338 * \return appropriate response for resize
1339 */
1340static LRESULT
1342 HWND hwnd,
1343 WPARAM wparam,
1344 LPARAM lparam)
1345{
1346 RECT rstatus, rtool;
1347
1348 if ((gw->toolbar == NULL) ||
1349 (gw->urlbar == NULL) ||
1350 (gw->statusbar == NULL))
1351 return 0;
1352
1353 SendMessage(gw->statusbar, WM_SIZE, wparam, lparam);
1354 SendMessage(gw->toolbar, WM_SIZE, wparam, lparam);
1355
1356 GetClientRect(gw->toolbar, &rtool);
1357 GetWindowRect(gw->statusbar, &rstatus);
1358 gw->width = LOWORD(lparam);
1359 gw->height = HIWORD(lparam) - (rtool.bottom - rtool.top) - (rstatus.bottom - rstatus.top);
1360
1361 if (gw->drawingarea != NULL) {
1362 MoveWindow(gw->drawingarea,
1363 0,
1364 rtool.bottom,
1365 gw->width,
1366 gw->height,
1367 true);
1368 }
1370
1371 if (gw->toolbar != NULL) {
1372 SendMessage(gw->toolbar, TB_SETSTATE,
1373 (WPARAM) IDM_NAV_STOP,
1374 MAKELONG(TBSTATE_INDETERMINATE, 0));
1375 }
1376
1377 return 0;
1378}
1379
1380
1381/**
1382 * callback for browser window win32 events
1383 *
1384 * \param hwnd The win32 window handle
1385 * \param msg The win32 message identifier
1386 * \param wparam The w win32 parameter
1387 * \param lparam The l win32 parameter
1388 */
1389static LRESULT CALLBACK
1390nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1391{
1392 struct gui_window *gw;
1393 RECT rmain;
1394 LPCREATESTRUCTW createstruct;
1395
1396 LOG_WIN_MSG(hwnd, msg, wparam, lparam);
1397
1398 gw = nsws_get_gui_window(hwnd);
1399
1400 switch (msg) {
1401 case WM_NCCREATE: /* non client area create */
1402 /* gw is passed as the lpParam from createwindowex() */
1403 createstruct = (LPCREATESTRUCTW)lparam;
1404 gw = (struct gui_window *)createstruct->lpCreateParams;
1405
1406 /* set the gui window associated with this window handle */
1407 SetProp(hwnd, TEXT("GuiWnd"), (HANDLE)gw);
1408
1409 NSLOG(netsurf, INFO,
1410 "created hWnd:%p hInstance %p GUI window %p",
1411 hwnd, createstruct->hInstance, gw);
1412
1413 break;
1414
1415 case WM_CREATE:
1416 /*
1417 * To cause all the component child windows to be
1418 * re-sized correctly a WM_SIZE message of the actual
1419 * created size must be sent.
1420 *
1421 * The message must be posted here because the actual
1422 * size values of the component windows are not known
1423 * until after the WM_CREATE message is dispatched.
1424 */
1425 GetClientRect(hwnd, &rmain);
1426 PostMessage(hwnd, WM_SIZE, 0,
1427 MAKELPARAM(rmain.right, rmain.bottom));
1428 break;
1429
1430 case WM_CONTEXTMENU:
1431 if (nsws_ctx_menu(gw, hwnd, GET_X_LPARAM(lparam),
1432 GET_Y_LPARAM(lparam))) {
1433 return 0;
1434 }
1435 break;
1436
1437 case WM_COMMAND:
1438 if (nsws_window_command(hwnd, gw, HIWORD(wparam),
1439 LOWORD(wparam), (HWND)lparam) == 0) {
1440 return 0;
1441 }
1442 break;
1443
1444 case WM_SIZE:
1445 return nsws_window_resize(gw, hwnd, wparam, lparam);
1446
1447 case WM_NCDESTROY:
1448 RemoveProp(hwnd, TEXT("GuiWnd"));
1451 if (--open_windows <= 0) {
1452 win32_set_quit(true);
1453 }
1454 break;
1455
1456 }
1457
1458 return DefWindowProcW(hwnd, msg, wparam, lparam);
1459}
1460
1462{
1463 DeleteObject(gw->hPageInfo[PAGE_STATE_UNKNOWN]);
1464 DeleteObject(gw->hPageInfo[PAGE_STATE_INTERNAL]);
1465 DeleteObject(gw->hPageInfo[PAGE_STATE_LOCAL]);
1466 DeleteObject(gw->hPageInfo[PAGE_STATE_INSECURE]);
1467 DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE_OVERRIDE]);
1468 DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE_ISSUES]);
1469 DeleteObject(gw->hPageInfo[PAGE_STATE_SECURE]);
1470}
1471
1472static void load_page_info_bitmaps(HINSTANCE hInstance, struct gui_window *gw)
1473{
1474 gw->hPageInfo[PAGE_STATE_UNKNOWN] = LoadImage(hInstance,
1475 MAKEINTRESOURCE(IDB_PAGEINFO_INTERNAL),
1476 IMAGE_BITMAP,
1477 0,
1478 0,
1479 LR_DEFAULTCOLOR);
1480 gw->hPageInfo[PAGE_STATE_INTERNAL] = LoadImage(hInstance,
1481 MAKEINTRESOURCE(IDB_PAGEINFO_INTERNAL),
1482 IMAGE_BITMAP,
1483 0,
1484 0,
1485 LR_DEFAULTCOLOR);
1486 gw->hPageInfo[PAGE_STATE_LOCAL] = LoadImage(hInstance,
1487 MAKEINTRESOURCE(IDB_PAGEINFO_LOCAL),
1488 IMAGE_BITMAP,
1489 0,
1490 0,
1491 LR_DEFAULTCOLOR);
1492 gw->hPageInfo[PAGE_STATE_INSECURE] = LoadImage(hInstance,
1493 MAKEINTRESOURCE(IDB_PAGEINFO_INSECURE),
1494 IMAGE_BITMAP,
1495 0,
1496 0,
1497 LR_DEFAULTCOLOR);
1498 gw->hPageInfo[PAGE_STATE_SECURE_OVERRIDE] = LoadImage(hInstance,
1499 MAKEINTRESOURCE(IDB_PAGEINFO_WARNING),
1500 IMAGE_BITMAP,
1501 0,
1502 0,
1503 LR_DEFAULTCOLOR);
1504 gw->hPageInfo[PAGE_STATE_SECURE_ISSUES] = LoadImage(hInstance,
1505 MAKEINTRESOURCE(IDB_PAGEINFO_WARNING),
1506 IMAGE_BITMAP,
1507 0,
1508 0,
1509 LR_DEFAULTCOLOR);
1510 gw->hPageInfo[PAGE_STATE_SECURE] = LoadImage(hInstance,
1511 MAKEINTRESOURCE(IDB_PAGEINFO_SECURE),
1512 IMAGE_BITMAP,
1513 0,
1514 0,
1515 LR_DEFAULTCOLOR);
1516}
1517
1518
1519/**
1520 * create a new gui_window to contain a browser_window.
1521 *
1522 * \param bw the browser_window to connect to the new gui_window
1523 * \param existing An existing window.
1524 * \param flags The flags controlling the construction.
1525 * \return The new win32 gui window or NULL on error.
1526 */
1527static struct gui_window *
1529 struct gui_window *existing,
1531{
1532 struct gui_window *gw;
1533
1534 NSLOG(netsurf, INFO, "Creating gui window for browser window %p", bw);
1535
1536 gw = calloc(1, sizeof(struct gui_window));
1537 if (gw == NULL) {
1538 return NULL;
1539 }
1540
1541 /* connect gui window to browser window */
1542 gw->bw = bw;
1543
1544 gw->width = 800;
1545 gw->height = 600;
1546 gw->toolbuttonsize = 24;
1547 gw->requestscrollx = 0;
1548 gw->requestscrolly = 0;
1549 gw->localhistory = NULL;
1550
1552
1553 gw->mouse = malloc(sizeof(struct browser_mouse));
1554 if (gw->mouse == NULL) {
1555 free(gw);
1556 NSLOG(netsurf, INFO, "Unable to allocate mouse state");
1557 return NULL;
1558 }
1559 gw->mouse->gui = gw;
1560 gw->mouse->state = 0;
1561 gw->mouse->pressed_x = 0;
1562 gw->mouse->pressed_y = 0;
1563
1564 /* add window to list */
1565 if (window_list != NULL) {
1566 window_list->prev = gw;
1567 }
1568 gw->next = window_list;
1569 window_list = gw;
1570
1571 gw->main = nsws_window_create(hinst, gw);
1575
1576 NSLOG(netsurf, INFO,
1577 "new window: main:%p toolbar:%p statusbar %p drawingarea %p",
1578 gw->main,
1579 gw->toolbar,
1580 gw->statusbar,
1581 gw->drawingarea);
1582
1583 font_hwnd = gw->drawingarea;
1584 open_windows++;
1585 ShowWindow(gw->main, SW_SHOWNORMAL);
1586
1587 return gw;
1588}
1589
1590
1591/**
1592 * Destroy previously created win32 window
1593 *
1594 * \param w The gui window to destroy.
1595 */
1596static void win32_window_destroy(struct gui_window *w)
1597{
1598 if (w == NULL)
1599 return;
1600
1601 if (w->prev != NULL)
1602 w->prev->next = w->next;
1603 else
1604 window_list = w->next;
1605
1606 if (w->next != NULL)
1607 w->next->prev = w->prev;
1608
1609 DestroyAcceleratorTable(w->acceltable);
1610
1612
1613 free(w);
1614 w = NULL;
1615}
1616
1617
1618/**
1619 * Find the current dimensions of a win32 browser window's content area.
1620 *
1621 * \param gw gui_window to measure
1622 * \param width receives width of window
1623 * \param height receives height of window
1624 * \return NSERROR_OK and width and height updated
1625 */
1626static nserror
1628{
1629 *width = gw->width;
1630 *height = gw->height;
1631
1632 NSLOG(netsurf, INFO, "gw:%p w=%d h=%d", gw, *width, *height);
1633
1634 return NSERROR_OK;
1635}
1636
1637
1638/**
1639 * Update the extent of the inside of a browser window to that of the
1640 * current content.
1641 *
1642 * \param w gui_window to update the extent of
1643 */
1645{
1646 struct rect rect;
1647 rect.x0 = rect.x1 = gw->scrollx;
1648 rect.y0 = rect.y1 = gw->scrolly;
1650}
1651
1652
1653/**
1654 * set win32 browser window title
1655 *
1656 * \param w the win32 gui window.
1657 * \param title to set on window
1658 */
1659static void win32_window_set_title(struct gui_window *w, const char *title)
1660{
1661 char *fulltitle;
1662 int wlen;
1663 LPWSTR enctitle;
1664
1665 if (w == NULL) {
1666 return;
1667 }
1668
1669 NSLOG(netsurf, INFO, "%p, title %s", w, title);
1670 fulltitle = malloc(strlen(title) + SLEN(" - NetSurf") + 1);
1671 if (fulltitle == NULL) {
1672 NSLOG(netsurf, ERROR, "%s",
1674 return;
1675 }
1676
1677 strcpy(fulltitle, title);
1678 strcat(fulltitle, " - NetSurf");
1679
1680 wlen = MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, NULL, 0);
1681 if (wlen == 0) {
1682 NSLOG(netsurf, ERROR, "failed encoding \"%s\"", fulltitle);
1683 free(fulltitle);
1684 return;
1685 }
1686
1687 enctitle = malloc(2 * (wlen + 1));
1688 if (enctitle == NULL) {
1689 NSLOG(netsurf, ERROR, "%s encoding \"%s\" len %d",
1690 messages_get_errorcode(NSERROR_NOMEM), fulltitle, wlen);
1691 free(fulltitle);
1692 return;
1693 }
1694
1695 MultiByteToWideChar(CP_UTF8, 0, fulltitle, -1, enctitle, wlen);
1696 SetWindowTextW(w->main, enctitle);
1697 free(enctitle);
1698 free(fulltitle);
1699}
1700
1701
1702/**
1703 * Set the navigation url in a win32 browser window.
1704 *
1705 * \param gw window to update.
1706 * \param url The url to use as icon.
1707 */
1709{
1710 SendMessage(gw->urlbar, WM_SETTEXT, 0, (LPARAM) nsurl_access(url));
1711
1712 return NSERROR_OK;
1713}
1714
1715
1716/**
1717 * Set the status bar of a win32 browser window.
1718 *
1719 * \param w gui_window to update
1720 * \param text new status text
1721 */
1722static void win32_window_set_status(struct gui_window *w, const char *text)
1723{
1724 if (w == NULL) {
1725 return;
1726 }
1727 SendMessage(w->statusbar, WM_SETTEXT, 0, (LPARAM)text);
1728}
1729
1730
1731/**
1732 * Change the win32 mouse pointer shape
1733 *
1734 * \param w The gui window to change pointer shape in.
1735 * \param shape The new shape to change to.
1736 */
1737static void
1739{
1740 SetCursor(nsws_get_pointer(shape));
1741}
1742
1743
1744/**
1745 * Give the win32 input focus to a window
1746 *
1747 * \param w window with caret
1748 * \param x coordinates of caret
1749 * \param y coordinates of caret
1750 * \param height height of caret
1751 * \param clip rectangle to clip caret or NULL if none
1752 */
1753static void
1754win32_window_place_caret(struct gui_window *w, int x, int y,
1755 int height, const struct rect *clip)
1756{
1757 if (w == NULL) {
1758 return;
1759 }
1760
1761 CreateCaret(w->drawingarea, (HBITMAP)NULL, 1, height );
1762 SetCaretPos(x - w->scrollx, y - w->scrolly);
1763 ShowCaret(w->drawingarea);
1764}
1765
1766
1767/**
1768 * Remove the win32 input focus from window
1769 *
1770 * \param gw window with caret
1771 */
1773{
1774 if (gw == NULL)
1775 return;
1776 HideCaret(gw->drawingarea);
1777}
1778
1779
1780/**
1781 * start a win32 navigation throbber.
1782 *
1783 * \param w window in which to start throbber.
1784 */
1786{
1787 if (w == NULL)
1788 return;
1790
1791 if (w->mainmenu != NULL) {
1792 EnableMenuItem(w->mainmenu, IDM_NAV_STOP, MF_ENABLED);
1793 EnableMenuItem(w->mainmenu, IDM_NAV_RELOAD, MF_GRAYED);
1794 }
1795 if (w->rclick != NULL) {
1796 EnableMenuItem(w->rclick, IDM_NAV_STOP, MF_ENABLED);
1797 EnableMenuItem(w->rclick, IDM_NAV_RELOAD, MF_GRAYED);
1798 }
1799 if (w->toolbar != NULL) {
1800 SendMessage(w->toolbar, TB_SETSTATE, (WPARAM) IDM_NAV_STOP,
1801 MAKELONG(TBSTATE_ENABLED, 0));
1802 SendMessage(w->toolbar, TB_SETSTATE,
1803 (WPARAM) IDM_NAV_RELOAD,
1804 MAKELONG(TBSTATE_INDETERMINATE, 0));
1805 }
1806 w->throbbing = true;
1807 Animate_Play(w->throbber, 0, -1, -1);
1808}
1809
1810
1811/**
1812 * stop a win32 navigation throbber.
1813 *
1814 * \param w window with throbber to stop
1815 */
1817{
1818 if (w == NULL)
1819 return;
1820
1822 if (w->mainmenu != NULL) {
1823 EnableMenuItem(w->mainmenu, IDM_NAV_STOP, MF_GRAYED);
1824 EnableMenuItem(w->mainmenu, IDM_NAV_RELOAD, MF_ENABLED);
1825 }
1826
1827 if (w->rclick != NULL) {
1828 EnableMenuItem(w->rclick, IDM_NAV_STOP, MF_GRAYED);
1829 EnableMenuItem(w->rclick, IDM_NAV_RELOAD, MF_ENABLED);
1830 }
1831
1832 if (w->toolbar != NULL) {
1833 SendMessage(w->toolbar, TB_SETSTATE, (WPARAM) IDM_NAV_STOP,
1834 MAKELONG(TBSTATE_INDETERMINATE, 0));
1835 SendMessage(w->toolbar, TB_SETSTATE,
1836 (WPARAM) IDM_NAV_RELOAD,
1837 MAKELONG(TBSTATE_ENABLED, 0));
1838 }
1839
1840 w->throbbing = false;
1841 Animate_Stop(w->throbber);
1842 Animate_Seek(w->throbber, 0);
1843}
1844
1845
1846/**
1847 * win32 page info change.
1848 *
1849 * \param gw window to chnage info on
1850 */
1852{
1853 HWND hbutton;
1855
1856 hbutton = GetProp(gw->toolbar, TEXT("hPGIbutton"));
1857
1859
1860 SendMessageW(hbutton, BM_SETIMAGE, IMAGE_BITMAP,
1861 (LPARAM)gw->hPageInfo[pistate]);
1862}
1863
1864
1865/**
1866 * process miscellaneous window events
1867 *
1868 * \param gw The window receiving the event.
1869 * \param event The event code.
1870 * \return NSERROR_OK when processed ok
1871 */
1872static nserror
1874{
1875 switch (event) {
1878 break;
1879
1882 break;
1883
1886 break;
1887
1890 break;
1891
1894 break;
1895
1896 default:
1897 break;
1898 }
1899 return NSERROR_OK;
1900}
1901
1902/**
1903 * win32 frontend browser window handling operation table
1904 */
1907 .destroy = win32_window_destroy,
1908 .invalidate = win32_window_invalidate_area,
1909 .get_scroll = win32_window_get_scroll,
1910 .set_scroll = win32_window_set_scroll,
1911 .get_dimensions = win32_window_get_dimensions,
1912 .event = win32_window_event,
1913
1914 .set_title = win32_window_set_title,
1915 .set_url = win32_window_set_url,
1916 .set_status = win32_window_set_status,
1917 .set_pointer = win32_window_set_pointer,
1918 .place_caret = win32_window_place_caret,
1919};
1920
1922
1923
1924/* exported interface documented in windows/window.h */
1926{
1927 struct gui_window *gw = NULL;
1928 HWND phwnd = hwnd;
1929
1930 /* scan the window hierarchy for gui window */
1931 while (phwnd != NULL) {
1932 gw = GetProp(phwnd, TEXT("GuiWnd"));
1933 if (gw != NULL)
1934 break;
1935 phwnd = GetParent(phwnd);
1936 }
1937
1938 if (gw == NULL) {
1939 /* try again looking for owner windows instead */
1940 phwnd = hwnd;
1941 while (phwnd != NULL) {
1942 gw = GetProp(phwnd, TEXT("GuiWnd"));
1943 if (gw != NULL)
1944 break;
1945 phwnd = GetWindow(phwnd, GW_OWNER);
1946 }
1947 }
1948
1949 return gw;
1950}
1951
1952
1953/* exported interface documented in windows/window.h */
1954bool nsws_window_go(HWND hwnd, const char *urltxt)
1955{
1956 struct gui_window *gw;
1957 nsurl *url;
1958 nserror ret;
1959
1960 gw = nsws_get_gui_window(hwnd);
1961 if (gw == NULL)
1962 return false;
1963 ret = nsurl_create(urltxt, &url);
1964
1965 if (ret != NSERROR_OK) {
1966 win32_report_nserror(ret, 0);
1967 } else {
1969 url,
1970 NULL,
1972 NULL,
1973 NULL,
1974 NULL);
1976 }
1977
1978 return true;
1979}
1980
1981
1982/* exported interface documented in windows/window.h */
1984{
1985 SCROLLINFO si;
1986 nserror res;
1987 int height;
1988 int width;
1989 POINT p;
1990
1991 if ((gw == NULL) || (gw->bw == NULL)) {
1992 return NSERROR_BAD_PARAMETER;
1993 }
1994
1995 res = browser_window_get_extents(gw->bw, true, &width, &height);
1996 if (res != NSERROR_OK) {
1997 return res;
1998 }
1999
2000 /* The resulting gui window scroll must remain within the
2001 * windows bounding box.
2002 */
2003 if (rect->x0 < 0) {
2004 gw->requestscrollx = -gw->scrollx;
2005 } else if (rect->x0 > (width - gw->width)) {
2006 gw->requestscrollx = (width - gw->width) - gw->scrollx;
2007 } else {
2008 gw->requestscrollx = rect->x0 - gw->scrollx;
2009 }
2010 if (rect->y0 < 0) {
2011 gw->requestscrolly = -gw->scrolly;
2012 } else if (rect->y0 > (height - gw->height)) {
2013 gw->requestscrolly = (height - gw->height) - gw->scrolly;
2014 } else {
2015 gw->requestscrolly = rect->y0 - gw->scrolly;
2016 }
2017
2018 NSLOG(netsurf, DEEPDEBUG,
2019 "requestscroll x,y:%d,%d",
2021
2022 /* set the vertical scroll offset */
2023 si.cbSize = sizeof(si);
2024 si.fMask = SIF_ALL;
2025 si.nMin = 0;
2026 si.nMax = height - 1;
2027 si.nPage = gw->height;
2028 si.nPos = max(gw->scrolly + gw->requestscrolly, 0);
2029 si.nPos = min(si.nPos, height - gw->height);
2030 SetScrollInfo(gw->drawingarea, SB_VERT, &si, TRUE);
2031 NSLOG(netsurf, DEEPDEBUG,
2032 "SetScrollInfo VERT min:%d max:%d page:%d pos:%d",
2033 si.nMin, si.nMax, si.nPage, si.nPos);
2034
2035 /* set the horizontal scroll offset */
2036 si.cbSize = sizeof(si);
2037 si.fMask = SIF_ALL;
2038 si.nMin = 0;
2039 si.nMax = width -1;
2040 si.nPage = gw->width;
2041 si.nPos = max(gw->scrollx + gw->requestscrollx, 0);
2042 si.nPos = min(si.nPos, width - gw->width);
2043 SetScrollInfo(gw->drawingarea, SB_HORZ, &si, TRUE);
2044 NSLOG(netsurf, DEEPDEBUG,
2045 "SetScrollInfo HORZ min:%d max:%d page:%d pos:%d",
2046 si.nMin, si.nMax, si.nPage, si.nPos);
2047
2048 /* Set caret position */
2049 GetCaretPos(&p);
2050 HideCaret(gw->drawingarea);
2051 SetCaretPos(p.x - gw->requestscrollx, p.y - gw->requestscrolly);
2052 ShowCaret(gw->drawingarea);
2053
2054 RECT r, redraw;
2055 r.top = 0;
2056 r.bottom = gw->height + 1;
2057 r.left = 0;
2058 r.right = gw->width + 1;
2059 ScrollWindowEx(gw->drawingarea,
2060 - gw->requestscrollx,
2061 - gw->requestscrolly,
2062 &r,
2063 NULL,
2064 NULL,
2065 &redraw,
2066 SW_INVALIDATE);
2067 NSLOG(netsurf, DEEPDEBUG,
2068 "ScrollWindowEx %d, %d",
2069 - gw->requestscrollx,
2070 - gw->requestscrolly);
2071
2072 gw->scrolly += gw->requestscrolly;
2073 gw->scrollx += gw->requestscrollx;
2074 gw->requestscrollx = 0;
2075 gw->requestscrolly = 0;
2076
2077 return NSERROR_OK;
2078}
2079
2080
2081/* exported interface documented in windows/window.h */
2082nserror
2083nsws_create_main_class(HINSTANCE hinstance)
2084{
2085 nserror ret = NSERROR_OK;
2086 WNDCLASSEXW wc;
2087
2088 /* main window */
2089 wc.cbSize = sizeof(WNDCLASSEX);
2090 wc.style = 0;
2091 wc.lpfnWndProc = nsws_window_event_callback;
2092 wc.cbClsExtra = 0;
2093 wc.cbWndExtra = 0;
2094 wc.hInstance = hinstance;
2095 wc.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
2096 wc.hCursor = NULL;
2097 wc.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
2098 wc.lpszMenuName = NULL;
2099 wc.lpszClassName = windowclassname_main;
2100 wc.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON));
2101
2102 if (RegisterClassExW(&wc) == 0) {
2103 win_perror("MainWindowClass");
2104 ret = NSERROR_INIT_FAILED;
2105 }
2106
2107 return ret;
2108}
2109
2110
2111/* exported interface documented in windows/window.h */
2113{
2114 if (w == NULL)
2115 return NULL;
2116 return w->main;
2117}
STATIC char result[100]
Definition: arexx.c:77
nserror browser_window_history_forward(struct browser_window *bw, bool new_window)
Go forward in the history.
bool browser_window_history_forward_available(struct browser_window *bw)
Check whether it is pssible to go forwards in the history.
bool browser_window_history_back_available(struct browser_window *bw)
Check whether it is pssible to go back in the history.
nserror browser_window_history_back(struct browser_window *bw, bool new_window)
Go back in the history.
Interface to browser history operations.
Browser window creation and manipulation interface.
nserror browser_window_schedule_reformat(struct browser_window *bw)
Reformat the browser window contents in a safe context.
nserror browser_window_navigate(struct browser_window *bw, struct nsurl *url, struct nsurl *referrer, enum browser_window_nav_flags flags, char *post_urlenc, struct fetch_multipart_data *post_multipart, struct hlcache_handle *parent)
Start fetching a page in a browser window.
nserror browser_window_debug(struct browser_window *bw, enum content_debug op)
Set debug options on a window.
void browser_window_destroy(struct browser_window *bw)
Close and destroy a browser window.
nserror browser_window_reload(struct browser_window *bw, bool all)
Reload the page in a browser window.
browser_editor_flags
@ BW_EDITOR_CAN_PASTE
Can paste, input.
@ BW_EDITOR_NONE
No selection, no editing.
@ BW_EDITOR_CAN_CUT
Selection not read-only.
@ BW_EDITOR_CAN_COPY
Have selection.
browser_window_page_info_state
Browser window page information states.
@ PAGE_STATE_INSECURE
Insecure page load.
@ PAGE_STATE_UNKNOWN
Unable to determine.
@ PAGE_STATE_SECURE_ISSUES
Secure load, but has insecure elements.
@ PAGE_STATE_SECURE
Secure load.
@ PAGE_STATE_SECURE_OVERRIDE
Secure load, but had to override.
@ PAGE_STATE_LOCAL
Page loaded from file:/// etc.
@ PAGE_STATE_INTERNAL
Page loaded from internal handler.
nserror browser_window_get_extents(struct browser_window *bw, bool scaled, int *width, int *height)
Get a browser window's content extents.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
void browser_window_stop(struct browser_window *bw)
Stop all fetching activity in a browser window.
nserror browser_window_set_scale(struct browser_window *bw, float scale, bool absolute)
Sets the scale of a browser window.
browser_window_page_info_state browser_window_get_page_info_state(const struct browser_window *bw)
Request the current browser window page info state.
browser_editor_flags browser_window_get_editor_flags(struct browser_window *bw)
Check whether browser window can accept a cut/copy/paste, or has a selection that could be saved.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
@ BW_NAVIGATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
Content handling interface.
@ CONTENT_DEBUG_REDRAW
Debug redraw operations.
Definition: content_type.h:38
HWND nsws_window_create_drawable(HINSTANCE hinstance, HWND hparent, struct gui_window *gw)
Create a drawable window.
Definition: drawable.c:674
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_INIT_FAILED
Initialisation failed.
Definition: errors.h:38
@ NSERROR_BAD_PARAMETER
Bad Parameter.
Definition: errors.h:48
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_OK
No error.
Definition: errors.h:30
HWND font_hwnd
Definition: font.c:39
The interface to the win32 font and utf8 handling.
nserror nsw32_global_history_present(HINSTANCE hInstance)
make the global history window visible.
Interface to win32 global history manager using nsw32 core window.
nserror nsw32_hotlist_present(HINSTANCE hInstance)
make the hotlist window visible.
Definition: hotlist.c:166
Interface to win32 bookmark manager (hotlist).
nserror nsw32_local_history_hide(void)
hide the local history window.
nserror nsw32_local_history_present(HWND hWndParent, struct browser_window *bw)
make the local history window visible.
Interface to win32 local history manager using nsw32 core window.
struct gui_window * window_list
Definition: window.c:147
gui_pointer_shape
Definition: mouse.h:89
Interface to platform-specific graphical user interface window operations.
gui_window_create_flags
Window creation control flags.
Definition: window.h:66
gui_window_event
Window events.
Definition: window.h:80
@ GW_EVENT_PAGE_INFO_CHANGE
Page status has changed and so the padlock should be updated.
Definition: window.h:129
@ GW_EVENT_REMOVE_CARET
Remove the caret, if present.
Definition: window.h:98
@ GW_EVENT_STOP_THROBBER
stop the navigation throbber.
Definition: window.h:108
@ GW_EVENT_UPDATE_EXTENT
Update the extent of the inside of a browser window to that of the current content.
Definition: window.h:93
@ GW_EVENT_START_THROBBER
start the navigation throbber.
Definition: window.h:103
Interface to key press operations.
@ NS_KEY_SELECT_ALL
Definition: keypress.h:32
bool browser_window_key_press(struct browser_window *bw, uint32_t key)
Handle key presses in a browser window.
Definition: textinput.c:107
#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
Localised message support (interface).
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
#define ShowWindow(...)
Definition: os3support.h:172
HCURSOR nsws_get_pointer(gui_pointer_shape shape)
get a win32 cursor handle for a pointer shape
Definition: pointers.c:76
Windows mouse cursor interface.
nserror nsws_prefs_save(void)
Save the users preferances.
Definition: prefs.c:673
void nsws_prefs_dialog_init(HINSTANCE hinst, HWND parent)
open the preferences dialog and respond to user.
Definition: prefs.c:689
#define IDM_NAV_HOME
Definition: resourceid.h:124
#define IDM_VIEW_SAVE_WIN_METRICS
Definition: resourceid.h:121
#define IDC_MAIN_THROBBER
Definition: resourceid.h:55
#define IDM_NAV_STOP
Definition: resourceid.h:114
#define IDM_NAV_RELOAD
Definition: resourceid.h:115
#define IDM_NAV_BOOKMARKS
Definition: resourceid.h:127
#define IDB_PAGEINFO_SECURE
Definition: resourceid.h:35
#define IDM_HELP_CONTENTS
Definition: resourceid.h:134
#define IDM_EDIT_PASTE
Definition: resourceid.h:110
#define IDM_FILE_PRINT_PREVIEW
Definition: resourceid.h:105
#define IDC_MAIN_LAUNCH_URL
Definition: resourceid.h:58
#define IDC_PAGEINFO
Definition: resourceid.h:33
#define IDM_VIEW_FULLSCREEN
Definition: resourceid.h:120
#define IDM_VIEW_ZOOMNORMAL
Definition: resourceid.h:118
#define IDR_MENU_CONTEXT
Definition: resourceid.h:139
#define IDR_TOOLBAR_BITMAP
Definition: resourceid.h:28
#define IDM_EDIT_CUT
Definition: resourceid.h:108
#define IDB_PAGEINFO_LOCAL
Definition: resourceid.h:38
#define IDM_FILE_SAVE_PAGE
Definition: resourceid.h:101
#define IDR_TOOLBAR_BITMAP_GREY
Definition: resourceid.h:29
#define IDM_HELP_GUIDE
Definition: resourceid.h:135
#define IDM_HELP_INFO
Definition: resourceid.h:136
#define IDM_NAV_LOCALHISTORY
Definition: resourceid.h:125
#define IDM_FILE_SAVEAS_POSTSCRIPT
Definition: resourceid.h:104
#define IDB_PAGEINFO_WARNING
Definition: resourceid.h:37
#define IDM_FILE_SAVEAS_TEXT
Definition: resourceid.h:102
#define IDB_PAGEINFO_INTERNAL
Definition: resourceid.h:36
#define IDM_FILE_CLOSE_WINDOW
Definition: resourceid.h:100
#define IDM_NAV_FORWARD
Definition: resourceid.h:123
#define IDM_EDIT_COPY
Definition: resourceid.h:109
#define IDM_EDIT_DELETE
Definition: resourceid.h:111
#define IDM_EDIT_SEARCH
Definition: resourceid.h:113
#define IDM_EDIT_PREFERENCES
Definition: resourceid.h:133
#define IDM_FILE_QUIT
Definition: resourceid.h:107
#define IDM_FILE_SAVEAS_PDF
Definition: resourceid.h:103
#define IDM_FILE_OPEN_LOCATION
Definition: resourceid.h:99
#define IDC_MAIN_STATUSBAR
Definition: resourceid.h:57
#define IDM_VIEW_SOURCE
Definition: resourceid.h:119
#define IDB_PAGEINFO_INSECURE
Definition: resourceid.h:34
#define IDM_VIEW_ZOOMMINUS
Definition: resourceid.h:117
#define IDR_NETSURF_ICON
Definition: resourceid.h:26
#define IDR_MENU_MAIN
Definition: resourceid.h:97
#define IDM_TOOLS_COOKIES
Definition: resourceid.h:129
#define IDR_TOOLBAR_BITMAP_HOT
Definition: resourceid.h:30
#define IDC_MAIN_URLBAR
Definition: resourceid.h:54
#define IDM_VIEW_DEBUGGING_SAVE_DOMTREE
Definition: resourceid.h:132
#define IDM_NAV_BACK
Definition: resourceid.h:122
#define IDM_FILE_OPEN_WINDOW
Definition: resourceid.h:98
#define IDR_THROBBER_AVI
Definition: resourceid.h:27
#define IDM_FILE_PRINT
Definition: resourceid.h:106
#define IDM_EDIT_SELECT_ALL
Definition: resourceid.h:112
#define IDM_HELP_ABOUT
Definition: resourceid.h:137
#define IDM_TOOLS_DOWNLOADS
Definition: resourceid.h:128
#define IDM_NAV_GLOBALHISTORY
Definition: resourceid.h:126
#define IDM_VIEW_DEBUGGING_SAVE_BOXTREE
Definition: resourceid.h:131
#define IDM_VIEW_ZOOMPLUS
Definition: resourceid.h:116
#define IDM_VIEW_TOGGLE_DEBUG_RENDERING
Definition: resourceid.h:130
int width
Definition: gui.c:160
int height
Definition: gui.c:161
Browser window data.
Graphical user interface window function table.
Definition: window.h:137
struct gui_window *(* create)(struct browser_window *bw, struct gui_window *existing, gui_window_create_flags flags)
Create and open a gui window for a browsing context.
Definition: window.h:164
first entry in window list
Definition: gui.c:297
struct gui_window * prev
Previous in linked list.
Definition: gui.h:159
HWND main
handle to the actual window
Definition: window.h:41
struct nsws_localhistory * localhistory
handle to local history window
Definition: window.h:52
HMENU mainmenu
the main menu
Definition: window.h:50
HACCEL acceltable
accelerators
Definition: window.h:62
struct fbtk_widget_s * toolbar
Definition: gui.h:46
int toolbuttonsize
width, height of buttons
Definition: window.h:57
struct gui_window * next
list for cleanup
Definition: gui.h:159
bool throbbing
whether currently throbbing
Definition: gui.c:311
int state
Definition: window.cpp:73
int toolbuttonc
number of toolbar buttons
Definition: window.h:56
struct fbtk_widget_s * back
Definition: gui.h:34
RECT * fullscreen
memorize non-fullscreen area
Definition: window.h:69
int height
height of drawing area
Definition: browser.h:34
int width
width of window
Definition: browser.h:34
struct gui_window * gui
Definition: window.c:89
int requestscrolly
scolling requested.
Definition: window.h:71
int requestscrollx
Definition: window.h:71
char * url
Definition: gui.h:154
int scrollx
current scroll location
Definition: gui.c:306
int pressed_y
Definition: window.cpp:72
HMENU rclick
the right-click menu
Definition: window.h:51
RECT redraw
Area needing redraw.
Definition: window.h:70
int pressed_x
Definition: window.cpp:71
HWND drawingarea
throbber handle
Definition: window.h:45
struct fbtk_widget_s * throbber
Definition: gui.h:42
HWND urlbar
url bar handle
Definition: window.h:43
struct fbtk_widget_s * forward
Definition: gui.h:35
struct gui_window::@32 mouse
HWND statusbar
status bar handle
Definition: window.h:46
HBITMAP hPageInfo[8]
page info handles
Definition: window.h:64
int scrolly
current scroll location
Definition: gui.c:307
struct browser_window * bw
The 'content' window that is rendered in the gui_window.
Definition: gui.c:315
Definition: gui.h:44
int y
Definition: gui.h:46
int x
Definition: gui.h:45
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:348
Interface to a number of general purpose functionality.
#define fallthrough
switch fall through
Definition: utils.h:119
#define min(x, y)
Definition: utils.h:46
#define max(x, y)
Definition: utils.h:50
#define SLEN(x)
Calculate length of constant C string.
Definition: utils.h:88
void win_perror(const char *lpszFunction)
Definition: windbg.c:633
#define LOG_WIN_MSG(h, m, w, l)
log windows message
Definition: windbg.h:32
void nsw32_about_dialog_init(HINSTANCE hinst, HWND parent)
Definition: about.c:142
nserror nsw32_cookies_present(const char *search_term)
make the cookie window visible.
Definition: cookies.c:173
Interface to win32 cookie viewing using nsw32 core windows.
nserror win32_warning(const char *warning, const char *detail)
Warn the user of an event.
Definition: gui.c:173
nserror win32_report_nserror(nserror error, const char *detail)
Warn the user of an unexpected nserror.
Definition: gui.c:187
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
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357
static void nsws_window_set_accels(struct gui_window *gw)
create and attach accelerator table to main window
Definition: window.c:94
struct gui_window_table * win32_window_table
The window operation function table for win32.
Definition: window.c:1921
static void win32_window_page_info_change(struct gui_window *gw)
win32 page info change.
Definition: window.c:1851
static LRESULT nsws_window_toolbar_command(struct gui_window *gw, int notification_code, int identifier, HWND ctrl_window)
toolbar command message handler
Definition: window.c:212
static void win32_window_update_extent(struct gui_window *gw)
Update the extent of the inside of a browser window to that of the current content.
Definition: window.c:1644
static void win32_window_set_title(struct gui_window *w, const char *title)
set win32 browser window title
Definition: window.c:1659
nserror nsws_create_main_class(HINSTANCE hinstance)
Create the main browser window class.
Definition: window.c:2083
static void win32_window_remove_caret(struct gui_window *gw)
Remove the win32 input focus from window.
Definition: window.c:1772
HWND gui_window_main_window(struct gui_window *w)
Get the main win32 window handle from a gui window.
Definition: window.c:2112
static void set_urlbar_edit_size(HWND hwnd)
Definition: window.c:379
static bool nsws_ctx_menu(struct gui_window *gw, HWND hwnd, int x, int y)
Handle win32 context menu message.
Definition: window.c:857
static LRESULT CALLBACK nsws_window_toolbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
callback for toolbar events
Definition: window.c:315
static LRESULT nsws_window_resize(struct gui_window *gw, HWND hwnd, WPARAM wparam, LPARAM lparam)
handle WM_SIZE message on main browser window
Definition: window.c:1341
static LRESULT CALLBACK nsws_window_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
callback for browser window win32 events
Definition: window.c:1390
static struct gui_window_table window_table
win32 frontend browser window handling operation table
Definition: window.c:1905
static void load_page_info_bitmaps(HINSTANCE hInstance, struct gui_window *gw)
Definition: window.c:1472
static void win32_window_set_pointer(struct gui_window *w, gui_pointer_shape shape)
Change the win32 mouse pointer shape.
Definition: window.c:1738
static bool win32_window_get_scroll(struct gui_window *gw, int *sx, int *sy)
Get the scroll position of a win32 browser window.
Definition: window.c:1318
static const LPCWSTR windowclassname_main
The main window class name.
Definition: window.c:66
static nserror win32_window_event(struct gui_window *gw, enum gui_window_event event)
process miscellaneous window events
Definition: window.c:1873
static LRESULT CALLBACK nsws_window_urlbar_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
callback for url bar events
Definition: window.c:401
static void win32_window_set_status(struct gui_window *w, const char *text)
Set the status bar of a win32 browser window.
Definition: window.c:1722
static HWND nsws_window_create(HINSTANCE hInstance, struct gui_window *gw)
creation of a new full browser window
Definition: window.c:143
static LRESULT nsws_window_command(HWND hwnd, struct gui_window *gw, int notification_code, int identifier, HWND ctrl_window)
handle command message on main browser window
Definition: window.c:1002
static void urlbar_dimensions(HWND hWndParent, int toolbuttonsize, int buttonc, int *x, int *y, int *width, int *height)
calculate the dimensions of the url bar relative to the parent toolbar
Definition: window.c:285
static void win32_window_start_throbber(struct gui_window *w)
start a win32 navigation throbber.
Definition: window.c:1785
struct gui_window * nsws_get_gui_window(HWND hwnd)
Obtain gui window structure from window handle.
Definition: window.c:1925
static void nsws_update_edit(struct gui_window *w)
Update popup context menu editing functionality.
Definition: window.c:794
static struct gui_window * win32_window_create(struct browser_window *bw, struct gui_window *existing, gui_window_create_flags flags)
create a new gui_window to contain a browser_window.
Definition: window.c:1528
static HWND nsws_window_create_toolbar(HINSTANCE hInstance, HWND hWndParent, struct gui_window *gw)
create win32 main window toolbar and add controls and message handler
Definition: window.c:656
static void nsws_window_update_forward_back(struct gui_window *w)
update state of forward/back buttons/menu items when page changes
Definition: window.c:893
static nserror win32_window_invalidate_area(struct gui_window *gw, const struct rect *rect)
Invalidate an area of a win32 browser window.
Definition: window.c:934
static int open_windows
Number of open windows.
Definition: window.c:86
static nserror win32_window_set_url(struct gui_window *gw, nsurl *url)
Set the navigation url in a win32 browser window.
Definition: window.c:1708
static HWND nsws_window_create_statusbar(HINSTANCE hInstance, HWND hWndParent, struct gui_window *gw)
creation of status bar
Definition: window.c:768
static nserror win32_window_get_dimensions(struct gui_window *gw, int *width, int *height)
Find the current dimensions of a win32 browser window's content area.
Definition: window.c:1627
static nserror win32_open_new_window(struct gui_window *gw)
Create a new window due to menu selection.
Definition: window.c:965
bool nsws_window_go(HWND hwnd, const char *urltxt)
Cause a browser window to navigate to a url.
Definition: window.c:1954
#define NSWS_URLBAR_HEIGHT
height of the url entry box
Definition: window.c:76
nserror win32_window_set_scroll(struct gui_window *gw, const struct rect *rect)
Set the scroll position of a win32 browser window.
Definition: window.c:1983
static HIMAGELIST get_imagelist(HINSTANCE hInstance, int resid, int bsize, int bcnt)
create a win32 image list for the toolbar.
Definition: window.c:607
static HWND nsws_window_urlbar_create(HINSTANCE hInstance, HWND hWndParent, struct gui_window *gw)
create a urlbar and message handler
Definition: window.c:467
static void win32_window_place_caret(struct gui_window *w, int x, int y, int height, const struct rect *clip)
Give the win32 input focus to a window.
Definition: window.c:1754
static void win32_window_destroy(struct gui_window *w)
Destroy previously created win32 window.
Definition: window.c:1596
static HWND nsws_window_throbber_create(HINSTANCE hInstance, HWND hWndParent, struct gui_window *gw)
creation of throbber
Definition: window.c:560
static void win32_window_stop_throbber(struct gui_window *w)
stop a win32 navigation throbber.
Definition: window.c:1816
#define NSW32_PGIBUTTON_HEIGHT
height of the Page Information bitmap button
Definition: window.c:81
#define NSWS_THROBBER_WIDTH
width of the throbber element
Definition: window.c:71
static void destroy_page_info_bitmaps(struct gui_window *gw)
Definition: window.c:1461