Files
racket-webview/rktwebview_qt/rktwebview_qt.h
2026-03-05 14:42:42 +01:00

116 lines
3.1 KiB
C++

#ifndef RKTWEBVIEW_QT_H
#define RKTWEBVIEW_QT_H
#include "rktwebview_qt_global.h"
#include "rktwebview_internal.h"
#include "rktutils.h"
#include <QApplication>
#include <QWebEngineView>
#include <QMutex>
#include <QThread>
#include <QHash>
#include <QQueue>
#include <QTimer>
#include <QEventLoop>
class WebViewQt;
class WebviewWindow;
class Command;
class CommandEvent;
class RKTWEBVIEW_QT_EXPORT Rktwebview_qt : public QObject
{
Q_OBJECT
private:
QApplication *_app;
rktwebview_t _current_handle;
QHash<int, WebviewWindow *> _views;
QHash<int, event_cb_t> _view_js_callbacks;
QTimer _process_events;
int _evt_loop_depth;
QTimer _evt_loop_timer;
Rktwebview_qt **_handler;
int _argc;
char *_argv[1];
private:
void runJs(rktwebview_t wv, const char *js);
result_t doWindow(rktwebview_t w, int cmd);
public slots:
void processJsEventQueues();
private slots:
void stopEventloop();
private:
void postCommand(Command *cmd);
void handleCommandEvent(CommandEvent *e);
void processCommand(Command *cmd);
// QObject interface
protected:
void customEvent(QEvent *event);
public:
void removeView(int id);
public:
int nextHandle();
public:
int rktWebViewCreate(int parent, event_cb_t js_evt_cb);
void rktWebViewClose(int wv);
void rktQuit();
result_t rktOpenDevtools(rktwebview_t wv);
result_t rktSetUrl(rktwebview_t wv, const char *url);
result_t rktSetHtml(rktwebview_t wv, const char *html);
result_t rktRunJs(rktwebview_t wv, const char *js);
rkt_js_result_t *rktCallJs(rktwebview_t wv, const char *js);
result_t rktMove(rktwebview_t wv, int x, int y);
result_t rktResize(rktwebview_t wv, int w, int h);
result_t rktHideWindow(rktwebview_t w);
result_t rktShowWindow(rktwebview_t w);
result_t rktPresentWindow(rktwebview_t w);
result_t rktMaximizeWindow(rktwebview_t w);
result_t rktMinimizeWindow(rktwebview_t w);
result_t rktShowNormalWindow(rktwebview_t w);
window_state_t rktWindowState(rktwebview_t w);
rkt_js_result_t *rktChooseDir(rktwebview_t w, const char *title, const char *base_dir);
rkt_js_result_t * rktFileOpen(rktwebview_t w, const char *title, const char *base_dir, const char *permitted_exts);
rkt_js_result_t * rktFileSave(rktwebview_t w, const char *title, const char *base_dir, const char *permitted_exts);
result_t rktWindowSetTitle(rktwebview_t wv, const char *title);
bool rktValid(rktwebview_t wv);
public:
// Events for the backend
void pageLoaded(rktwebview_t w, bool ok);
void onPageLoad(rktwebview_t w);
public:
void triggerEvent(rktwebview_t wv, const QString &msg);
void triggerEvent(rktwebview_t wv, const EventContainer &e);
public:
void doEvents();
public:
void runCommandThread();
public:
Rktwebview_qt(Rktwebview_qt **handler);
};
#endif // RKTWEBVIEW_QT_H