2010-01-31 03:36:02 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Vincent Sanders <vince@simtec.co.uk>
|
|
|
|
* Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-03-13 02:48:53 +03:00
|
|
|
#include <stdbool.h>
|
2010-01-31 03:36:02 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
2015-03-13 02:48:53 +03:00
|
|
|
#include "utils/errors.h"
|
|
|
|
#include "utils/nsurl.h"
|
2014-10-16 12:51:53 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/corestrings.h"
|
|
|
|
#include "utils/url.h"
|
2015-03-13 02:48:53 +03:00
|
|
|
#include "utils/file.h"
|
2014-05-15 17:15:50 +04:00
|
|
|
#include "desktop/browser.h"
|
2014-10-16 12:51:53 +04:00
|
|
|
#include "desktop/gui_clipboard.h"
|
2010-01-31 03:36:02 +03:00
|
|
|
|
2010-10-09 22:00:32 +04:00
|
|
|
#include "windows/schedule.h"
|
2015-03-13 02:48:53 +03:00
|
|
|
#include "windows/window.h"
|
2014-01-23 03:19:57 +04:00
|
|
|
#include "windows/filetype.h"
|
2015-03-13 02:48:53 +03:00
|
|
|
#include "windows/gui.h"
|
2010-01-31 03:36:02 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
static bool win32_quit = false;
|
|
|
|
|
2011-04-04 02:01:37 +04:00
|
|
|
HINSTANCE hInstance; /** win32 application instance handle. */
|
2010-01-31 03:36:02 +03:00
|
|
|
|
|
|
|
|
2015-03-13 02:48:53 +03:00
|
|
|
void win32_set_quit(bool q)
|
2014-05-15 16:56:01 +04:00
|
|
|
{
|
2015-03-13 02:48:53 +03:00
|
|
|
win32_quit = q;
|
2014-05-15 16:56:01 +04:00
|
|
|
}
|
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
/* exported interface documented in gui.h */
|
|
|
|
void win32_run(void)
|
2010-01-31 03:36:02 +03:00
|
|
|
{
|
2011-02-09 02:42:18 +03:00
|
|
|
MSG Msg; /* message from system */
|
|
|
|
BOOL bRet; /* message fetch result */
|
|
|
|
int timeout; /* timeout in miliseconds */
|
|
|
|
UINT timer_id = 0;
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("Starting messgae dispatcher");
|
2015-03-15 03:00:45 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
while (!win32_quit) {
|
|
|
|
/* run the scheduler and discover how long to wait for
|
|
|
|
* the next event.
|
|
|
|
*/
|
|
|
|
timeout = schedule_run();
|
2011-02-09 02:42:18 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
if (timeout == 0) {
|
|
|
|
bRet = PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE);
|
|
|
|
} else {
|
|
|
|
if (timeout > 0) {
|
|
|
|
/* set up a timer to ensure we get woken */
|
|
|
|
timer_id = SetTimer(NULL, 0, timeout, NULL);
|
|
|
|
}
|
2011-02-09 02:42:18 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
/* wait for a message */
|
|
|
|
bRet = GetMessage(&Msg, NULL, 0, 0);
|
2011-02-09 02:42:18 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
/* if a timer was sucessfully created remove it */
|
|
|
|
if (timer_id != 0) {
|
|
|
|
KillTimer(NULL, timer_id);
|
|
|
|
timer_id = 0;
|
|
|
|
}
|
2011-02-09 02:42:18 +03:00
|
|
|
}
|
2010-01-31 03:36:02 +03:00
|
|
|
|
2014-10-12 14:08:01 +04:00
|
|
|
if (bRet > 0) {
|
|
|
|
TranslateMessage(&Msg);
|
|
|
|
DispatchMessage(&Msg);
|
|
|
|
}
|
2011-02-09 02:42:18 +03:00
|
|
|
}
|
2010-01-31 03:36:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-08 21:07:04 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-01-15 03:31:54 +04:00
|
|
|
static void gui_get_clipboard(char **buffer, size_t *length)
|
2010-01-31 03:36:02 +03:00
|
|
|
{
|
2013-01-08 21:07:04 +04:00
|
|
|
/* TODO: Implement this */
|
2010-01-31 03:36:02 +03:00
|
|
|
HANDLE clipboard_handle;
|
|
|
|
char *content;
|
|
|
|
|
|
|
|
clipboard_handle = GetClipboardData(CF_TEXT);
|
|
|
|
if (clipboard_handle != NULL) {
|
|
|
|
content = GlobalLock(clipboard_handle);
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("pasting %s", content);
|
2010-01-31 03:36:02 +03:00
|
|
|
GlobalUnlock(clipboard_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 02:48:53 +03:00
|
|
|
|
2013-01-08 21:07:04 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-01-15 03:31:54 +04:00
|
|
|
static void gui_set_clipboard(const char *buffer, size_t length,
|
2013-01-08 21:07:04 +04:00
|
|
|
nsclipboard_styles styles[], int n_styles)
|
2010-01-31 03:36:02 +03:00
|
|
|
{
|
2013-01-08 21:07:04 +04:00
|
|
|
/* TODO: Implement this */
|
2010-01-31 03:36:02 +03:00
|
|
|
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);
|
2013-01-08 21:07:04 +04:00
|
|
|
snprintf(new, length + len, "%s%s", original, buffer);
|
2010-01-31 03:36:02 +03:00
|
|
|
|
|
|
|
if (h != NULL) {
|
|
|
|
GlobalUnlock(h);
|
|
|
|
EmptyClipboard();
|
|
|
|
}
|
|
|
|
GlobalUnlock(hnew);
|
|
|
|
SetClipboardData(CF_TEXT, hnew);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-23 03:19:57 +04:00
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_clipboard_table clipboard_table = {
|
|
|
|
.get = gui_get_clipboard,
|
|
|
|
.set = gui_set_clipboard,
|
|
|
|
};
|
2014-01-12 14:27:41 +04:00
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_clipboard_table *win32_clipboard_table = &clipboard_table;
|
|
|
|
|
2014-01-23 03:19:57 +04:00
|
|
|
|