122 lines
3.4 KiB
C++
122 lines
3.4 KiB
C++
#ifndef RKTWEBVIEW_H
|
|
#define RKTWEBVIEW_H
|
|
|
|
#include "rktwebview_global.h"
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
typedef HANDLE mutex_t;
|
|
typedef HANDLE thread_t;
|
|
typedef DWORD thread_id_t;
|
|
#define USE_WIN_THREADS
|
|
#endif
|
|
|
|
#ifdef _linux
|
|
#define USE_PTHREADS
|
|
#include <pthread.h>
|
|
#endif
|
|
|
|
#define CONTEXT_INVALID 0
|
|
#define CONTEXT_BOUND_EVENT 1
|
|
#define CONTEXT_WINDOW_RESIZE 2
|
|
#define CONTEXT_WINDOW_MOVE 3
|
|
#define CONTEXT_WINDOW_CAN_CLOSE 4
|
|
#define CONTEXT_WINDOW_CLOSED 5
|
|
#define CONTEXT_SET_HTML 6
|
|
#define CONTEXT_NAVIGATE 7
|
|
#define CONTEXT_EVAL_JS 8
|
|
#define CONTEXT_OPEN_DEVTOOLS 9
|
|
#define CONTEXT_CALL_JS 10
|
|
|
|
typedef enum {
|
|
oke = 0,
|
|
error = 1
|
|
} result_t;
|
|
|
|
typedef enum {
|
|
reason_no_result_yet = -1,
|
|
reason_oke = 0,
|
|
reason_set_html_failed,
|
|
reason_set_navigate_failed,
|
|
reason_eval_js_failed,
|
|
reason_no_devtools_on_platform,
|
|
reason_no_delegate_for_context
|
|
} reason_t;
|
|
|
|
typedef struct {
|
|
int context;
|
|
char *data;
|
|
} item_t;
|
|
|
|
typedef struct _item {
|
|
item_t item;
|
|
struct _item *next;
|
|
struct _item *prev;
|
|
} queue_item_t;
|
|
|
|
typedef struct {
|
|
queue_item_t *first;
|
|
queue_item_t *last;
|
|
int length;
|
|
} queue_t;
|
|
|
|
typedef struct {
|
|
void *webview_handle;
|
|
mutex_t mutex;
|
|
thread_t webview_thread;
|
|
thread_id_t webview_thread_id;
|
|
queue_t to_webview;
|
|
queue_t from_webview;
|
|
int wv_res;
|
|
result_t last_result;
|
|
reason_t last_reason;
|
|
bool handle_set;
|
|
bool handle_destroyed;
|
|
void (*queue_callback)(int id, item_t data);
|
|
int queue_callback_id;
|
|
thread_t queue_guard_thread;
|
|
thread_id_t queue_guard_thread_id;
|
|
std::map<int, std::string> *js_evaluated;
|
|
int js_call_nr;
|
|
} rkt_webview_t;
|
|
|
|
#define WEBVIEW_HANDLE(wv) reinterpret_cast<webview_t>(wv->webview_handle)
|
|
|
|
extern "C" {
|
|
|
|
RKTWEBVIEW_EXPORT rkt_webview_t *rkt_create_webview();
|
|
RKTWEBVIEW_EXPORT result_t rkt_destroy_webview(rkt_webview_t *wv);
|
|
|
|
RKTWEBVIEW_EXPORT result_t rkt_close_webview(rkt_webview_t *handle);
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_navigate(rkt_webview_t *handle, const char *url);
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_set_html(rkt_webview_t *handle, const char *html);
|
|
|
|
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_run_js(rkt_webview_t *handle, const char *js);
|
|
RKTWEBVIEW_EXPORT item_t rkt_webview_call_js(rkt_webview_t *handle, const char *js);
|
|
|
|
//RKTWEBVIEW_EXPORT result_t rkt_bind(rkt_webview_t *handle, const char *selector, const char *event);
|
|
//RKTWEBVIEW_EXPORT result_t rkt_unbind(rkt_webview_t *handle, const char *selector, const char *event);
|
|
|
|
RKTWEBVIEW_EXPORT bool rkt_webview_valid(rkt_webview_t *handle);
|
|
|
|
RKTWEBVIEW_EXPORT int rkt_webview_pending_events(rkt_webview_t *wv);
|
|
RKTWEBVIEW_EXPORT item_t rkt_webview_get_event(rkt_webview_t *wv);
|
|
RKTWEBVIEW_EXPORT void rkt_webview_register_queue_callback(rkt_webview_t *wv, int id, void(*cb)(int id, item_t item));
|
|
RKTWEBVIEW_EXPORT void rkt_webview_destroy_item(item_t item);
|
|
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_move(rkt_webview_t *wv, int x, int y);
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_resize(rkt_webview_t *wv, int w, int h);
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_set_title(rkt_webview_t *wv, const char *title);
|
|
|
|
RKTWEBVIEW_EXPORT result_t rkt_webview_devtools(rkt_webview_t *wv);
|
|
|
|
RKTWEBVIEW_EXPORT reason_t rkt_webview_last_reason(rkt_webview_t *wv);
|
|
|
|
|
|
}
|
|
|
|
#endif // RKTWEBVIEW_H
|