Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <yyjson.h>

#include <thread>

static std::string get_archive_path()
{
std::string result(ARCHIVE_DIRECTORY);
Expand Down Expand Up @@ -80,6 +82,16 @@ class greeting_ipc_handler : public webframe::handler
}
};

class window_listener : public webframe::window_listener
{
public:
void on_close(webframe::window *source) override
{
source->set_title("Goodbye!");
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
};

class example_application : public webframe::application
{
public:
Expand All @@ -95,8 +107,10 @@ class example_application : public webframe::application
webframe::window *win = context->create_window(nullptr, 800, 600);
win->set_title("WebFrame Example");
win->load_path("index.html");
win->add_listener(&_window_listener);
}
private:
window_listener _window_listener;
archive_handler _archive_handler;
greeting_ipc_handler _greeting_ipc_handler;
};
Expand Down
11 changes: 11 additions & 0 deletions include/webframe/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@

namespace webframe
{
class window;

class window_listener
{
public:
virtual void on_close(window *source) = 0;
};

class window
{
public:
virtual void set_title(const std::string& title) = 0;
virtual void load_url(const std::string& url) = 0;
virtual void load_path(const std::string& path) = 0;

virtual void add_listener(window_listener *listener) = 0;

virtual std::string get_id() const = 0;
};

Expand Down
7 changes: 6 additions & 1 deletion src/runtimes/desktop/include/desktop/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ namespace webframe::desktop

void load_path(const std::string &path) override;
void load_url(const std::string &url) override;

std::string get_id() const override;

wxFrame *get_frame() const;

void add_listener(window_listener *listener) override;

void set_title(const std::string &title) override;

private:
void on_close(wxCloseEvent &event);

std::unique_ptr<wxFrame> _frame;
std::vector<window_listener*> _listeners;
wxWebView *_webview;
struct webview_data
{
Expand Down
15 changes: 15 additions & 0 deletions src/runtimes/desktop/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace webframe::desktop
}
_webview_data.created = true;
});
_frame->Bind(wxEVT_CLOSE_WINDOW, &window::on_close, this);
_frame->Show();
}

Expand Down Expand Up @@ -46,11 +47,25 @@ namespace webframe::desktop
return std::to_string(_frame->GetId());
}

void window::add_listener(window_listener *listener)
{
_listeners.push_back(listener);
}

wxFrame *window::get_frame() const
{
return _frame.get();
}

void window::on_close(wxCloseEvent &event)
{
for (window_listener *listener : _listeners)
{
listener->on_close(this);
}
event.Skip();
}

void window::set_title(const std::string &title)
{
wxString wx_title = wxString(title.c_str());
Expand Down
Loading