summaryrefslogtreecommitdiff
path: root/frontends/windows/drawable.c
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/windows/drawable.c')
-rw-r--r--frontends/windows/drawable.c197
1 files changed, 140 insertions, 57 deletions
diff --git a/frontends/windows/drawable.c b/frontends/windows/drawable.c
index f491e0a2a..84b11ed78 100644
--- a/frontends/windows/drawable.c
+++ b/frontends/windows/drawable.c
@@ -41,7 +41,7 @@
#include "windows/local_history.h"
#include "windows/drawable.h"
-static const char windowclassname_drawable[] = "nswsdrawablewindow";
+static const wchar_t *windowclassname_drawable = L"nswsdrawablewindow";
/**
@@ -223,19 +223,71 @@ nsws_drawable_resize(struct gui_window *gw)
return 0;
}
+/**
+ * Handle unicode character messages.
+ */
+static LRESULT
+nsws_drawable_unichar(struct gui_window *gw, HWND hwnd, WPARAM wparam)
+{
+ uint32_t nskey;
+
+ if (wparam == UNICODE_NOCHAR) {
+ return 1;
+ }
+
+ nskey = wparam;
+ browser_window_key_press(gw->bw, nskey);
+ return 0;
+}
/**
- * Handle key press messages.
+ * Handle character messages.
+ *
+ * WM_CHAR is generated when WM_KEYDOWN message are passed to
+ * TranslateMessage; wParam is UTF-16. If the codepoint is 4
+ * bytes, there are 2 WM_CHAR message, one with the high
+ * surrogate and one with the low surrogate.
*/
static LRESULT
-nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam)
+nsws_drawable_char(struct gui_window *gw, HWND hwnd, WPARAM wparam)
{
- if (GetFocus() != hwnd)
- return 0 ;
+ uint32_t nskey;
+
+ nskey = wparam;
+
+ const uint32_t utf16_hi_surrogate_start = 0xD800;
+ const uint32_t utf16_lo_surrogate_start = 0xDC00;
+ const uint32_t utf16_surrogate_end = 0xDFFF;
+ static uint32_t highSurrogate = 0;
+
+ if ((nskey >= utf16_hi_surrogate_start) &&
+ (nskey < utf16_lo_surrogate_start) ) {
+ highSurrogate = nskey;
+ } else {
+ if ((nskey >= utf16_lo_surrogate_start) &&
+ (nskey <= utf16_surrogate_end)) {
+ uint32_t lowSurrogate = nskey;
+ nskey = (highSurrogate - utf16_hi_surrogate_start) << 10;
+ nskey |= ( lowSurrogate - utf16_lo_surrogate_start );
+ nskey += 0x10000;
+ }
+ highSurrogate = 0;
+
+ browser_window_key_press(gw->bw, nskey);
+ }
+
+ return 0;
+}
+
+/**
+ * Handle keydown messages.
+ */
+static LRESULT
+nsws_drawable_keydown(struct gui_window *gw, HWND hwnd, WPARAM wparam)
+{
uint32_t i;
bool shift = ((GetKeyState(VK_SHIFT) & 0x8000) == 0x8000);
- bool capslock = ((GetKeyState(VK_CAPITAL) & 1) == 1);
switch(wparam) {
case VK_LEFT:
@@ -285,30 +337,18 @@ nsws_drawable_key(struct gui_window *gw, HWND hwnd, WPARAM wparam)
break;
case VK_NEXT:
- i = wparam;
- SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0),
- 0);
- break;
+ SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0);
+ return 1;
case VK_PRIOR:
- i = wparam;
- SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0),
- 0);
- break;
+ SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), 0);
+ return 1;
default:
- i = wparam;
- break;
+ return 1;
}
- if ((i >= 'A') &&
- (i <= 'Z') &&
- (((!capslock) && (!shift)) || ((capslock) && (shift)))) {
- i += 'a' - 'A';
- }
-
- if (gw != NULL)
- browser_window_key_press(gw->bw, i);
+ browser_window_key_press(gw->bw, i);
return 0;
}
@@ -338,10 +378,15 @@ nsws_drawable_paint(struct gui_window *gw, HWND hwnd)
clip.x1 = ps.rcPaint.right;
clip.y1 = ps.rcPaint.bottom;
+ /**
+ * \todo work out why the heck scroll needs scaling
+ */
+
browser_window_redraw(gw->bw,
- -gw->scrollx / gw->scale,
- -gw->scrolly / gw->scale,
- &clip, &ctx);
+ -gw->scrollx,
+ -gw->scrolly,
+ &clip,
+ &ctx);
}
EndPaint(hwnd, &ps);
@@ -385,19 +430,21 @@ nsws_drawable_mouseup(struct gui_window *gw,
if ((gw->mouse->state & click) != 0) {
NSLOG(netsurf, INFO,
- "mouse click bw %p, state 0x%x, x %f, y %f", gw->bw,
- gw->mouse->state, (x + gw->scrollx) / gw->scale,
- (y + gw->scrolly) / gw->scale);
+ "mouse click bw %p, state 0x%x, x %d, y %d",
+ gw->bw,
+ gw->mouse->state,
+ x + gw->scrollx,
+ y + gw->scrolly);
browser_window_mouse_click(gw->bw,
gw->mouse->state,
- (x + gw->scrollx) / gw->scale,
- (y + gw->scrolly) / gw->scale);
+ x + gw->scrollx,
+ y + gw->scrolly);
} else {
browser_window_mouse_track(gw->bw,
0,
- (x + gw->scrollx) / gw->scale,
- (y + gw->scrolly) / gw->scale);
+ x + gw->scrollx,
+ y + gw->scrolly);
}
gw->mouse->state = 0;
@@ -428,16 +475,19 @@ nsws_drawable_mousedown(struct gui_window *gw,
if ((GetKeyState(VK_MENU) & 0x8000) == 0x8000)
gw->mouse->state |= BROWSER_MOUSE_MOD_3;
- gw->mouse->pressed_x = (x + gw->scrollx) / gw->scale;
- gw->mouse->pressed_y = (y + gw->scrolly) / gw->scale;
+ gw->mouse->pressed_x = x + gw->scrollx;
+ gw->mouse->pressed_y = y + gw->scrolly;
- NSLOG(netsurf, INFO, "mouse click bw %p, state %x, x %f, y %f",
- gw->bw, gw->mouse->state, (x + gw->scrollx) / gw->scale,
- (y + gw->scrolly) / gw->scale);
+ NSLOG(netsurf, INFO, "mouse click bw %p, state %x, x %d, y %d",
+ gw->bw,
+ gw->mouse->state,
+ x + gw->scrollx,
+ y + gw->scrolly);
- browser_window_mouse_click(gw->bw, gw->mouse->state,
- (x + gw->scrollx) / gw->scale,
- (y + gw->scrolly) / gw->scale);
+ browser_window_mouse_click(gw->bw,
+ gw->mouse->state,
+ x + gw->scrollx,
+ y + gw->scrolly);
return 0;
}
@@ -456,9 +506,9 @@ nsws_drawable_mousemove(struct gui_window *gw, int x, int y)
if ((gw == NULL) || (gw->mouse == NULL) || (gw->bw == NULL))
return 0;
- /* scale co-ordinates */
- x = (x + gw->scrollx) / gw->scale;
- y = (y + gw->scrolly) / gw->scale;
+ /* add scroll offsets */
+ x = x + gw->scrollx;
+ y = y + gw->scrolly;
/* if mouse button held down and pointer moved more than
* minimum distance drag is happening */
@@ -544,7 +594,6 @@ nsws_window_drawable_event_callback(HWND hwnd,
BROWSER_MOUSE_PRESS_2);
SetFocus(hwnd);
return 0;
- break;
case WM_LBUTTONUP:
return nsws_drawable_mouseup(gw,
@@ -567,7 +616,16 @@ nsws_window_drawable_event_callback(HWND hwnd,
return nsws_drawable_paint(gw, hwnd);
case WM_KEYDOWN:
- return nsws_drawable_key(gw, hwnd, wparam);
+ if (nsws_drawable_keydown(gw, hwnd, wparam) == 0) {
+ return 0;
+ }
+ break;
+
+ case WM_CHAR:
+ return nsws_drawable_char(gw, hwnd, wparam);
+
+ case WM_UNICHAR:
+ return nsws_drawable_unichar(gw, hwnd, wparam);
case WM_SIZE:
return nsws_drawable_resize(gw);
@@ -581,6 +639,29 @@ nsws_window_drawable_event_callback(HWND hwnd,
case WM_MOUSEWHEEL:
return nsws_drawable_wheel(gw, hwnd, wparam);
+ case WM_PASTE:
+ browser_window_key_press(gw->bw, NS_KEY_PASTE);
+ return 0;
+
+ case WM_COPY:
+ browser_window_key_press(gw->bw, NS_KEY_COPY_SELECTION);
+ return 0;
+
+ case WM_CUT:
+ browser_window_key_press(gw->bw, NS_KEY_CUT_SELECTION);
+ return 0;
+
+ case WM_CLEAR:
+ /**
+ * \todo win32 clear operation deletes the contents of
+ * the selection but ns clear selection only
+ * removes the highlight.
+ */
+ browser_window_key_press(gw->bw, NS_KEY_CLEAR_SELECTION);
+ return 0;
+
+
+
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
@@ -595,14 +676,16 @@ nsws_window_create_drawable(HINSTANCE hinstance,
struct gui_window *gw)
{
HWND hwnd;
- hwnd = CreateWindow(windowclassname_drawable,
- NULL,
- WS_VISIBLE | WS_CHILD,
- 0, 0, 0, 0,
- hparent,
- NULL,
- hinstance,
- NULL);
+ hwnd = CreateWindowExW(0,
+ windowclassname_drawable,
+ NULL,
+ WS_VISIBLE | WS_CHILD,
+ 0, 0,
+ 0, 0,
+ hparent,
+ NULL,
+ hinstance,
+ NULL);
if (hwnd == NULL) {
win_perror("WindowCreateDrawable");
@@ -623,7 +706,7 @@ nsws_window_create_drawable(HINSTANCE hinstance,
nserror
nsws_create_drawable_class(HINSTANCE hinstance) {
nserror ret = NSERROR_OK;
- WNDCLASSEX w;
+ WNDCLASSEXW w;
/* drawable area */
w.cbSize = sizeof(WNDCLASSEX);
@@ -639,7 +722,7 @@ nsws_create_drawable_class(HINSTANCE hinstance) {
w.lpszClassName = windowclassname_drawable;
w.hIconSm = NULL;
- if (RegisterClassEx(&w) == 0) {
+ if (RegisterClassExW(&w) == 0) {
win_perror("DrawableClass");
ret = NSERROR_INIT_FAILED;
}