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
Binary file added example/frontend/cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 18 additions & 21 deletions example/frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebFrame</title>
<script src="form.js"></script>
</head>
<body>
<header>
<h1>WebFrame</h1>
</header>

<form id="name-form" onsubmit="handleNameSubmit(event)">
<label for="name">Name</label>
<input id="name" name="name" type="text" required>
<button type="submit">Submit</button>
</form>

<footer>
<p>&copy; 2026 Maxtek Consulting LLC. All rights reserved.</p>
</footer>
</body>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WebFrame Example</title>
<link rel="stylesheet" href="style.css" />
<script src="form.js"></script>
</head>
<body>
<img src="cat.jpg" alt="WebFrame Logo" class="logo" width="20%"/>
<div class="divClass">
<form id="name-form" onsubmit="handleNameSubmit(event)">
<label for="name">Name</label>
<input id="name" name="name" type="text" required>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
44 changes: 44 additions & 0 deletions example/frontend/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
html,
body {
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
}

body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: linear-gradient(to bottom, darkcyan, darkgray);
/* Gradient background */
}

.logo {
margin-bottom: 24px;
}

.divClass {
text-align: center;
color: #ffffff;
/* White text color */
font-size: 2.5rem;
/* Adjusted font size */
font-weight: 700;
/* Bold text */
background: rgba(0, 0, 0, 0.6);
/* Semi-transparent background */
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.divClass div {
margin-bottom: 10px;
}

.divClass div:last-child {
margin-bottom: 0;
font-size: 1.5rem;
/* Smaller font size for the second line */
}
2 changes: 1 addition & 1 deletion example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class archive_handler : public webframe::handler
else {
res->set_status(404);
res->set_header("Content-Type", "text/plain");
const std::string not_found_msg = "404 Not Found";
const std::string not_found_msg = "Not Found";
res->set_body(reinterpret_cast<const uint8_t*>(not_found_msg.data()), not_found_msg.size());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/runtimes/desktop/desktop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <webframe.hpp>

#include <wx/wx.h>
#include <wx/mstream.h>
#include <wx/webview.h>
#include <wx/uri.h>

Expand Down
48 changes: 37 additions & 11 deletions src/runtimes/desktop/response.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
#include <desktop.hpp>

class response_body_writer : public wxWebViewHandlerResponseData
{
public:
response_body_writer() = default;
~response_body_writer() = default;

wxInputStream *GetStream() override
{
if (!_stream)
{
_stream = std::make_unique<wxMemoryInputStream>(_buffer.data(), _buffer.size());
}
return _stream.get();
}

void write(const uint8_t *data, size_t size)
{
_buffer.insert(_buffer.end(), data, data + size);
}

private:
std::vector<uint8_t> _buffer;
std::unique_ptr<wxMemoryInputStream> _stream;
};


namespace webframe
{
namespace desktop
Expand All @@ -20,27 +46,27 @@ namespace webframe

void response::set_body(const uint8_t *data, size_t size)
{
_response->Finish(std::string(reinterpret_cast<const char *>(data), size));
std::unique_ptr<response_body_writer> body_writer = std::make_unique<response_body_writer>();
body_writer->write(data, size);
_response->Finish(wxSharedPtr<wxWebViewHandlerResponseData>(body_writer.release()));
_sent = true;
}

void response::write_body(const std::function<bool(std::pair<const uint8_t *, size_t> &)> &callback)
{
std::vector<uint8_t> buffer;
bool has_more_data = true;
while (has_more_data)
std::unique_ptr<response_body_writer> body_writer = std::make_unique<response_body_writer>();
bool has_more(true);
while(has_more)
{
std::pair<const uint8_t *, size_t> data;
if (callback(data))
{
buffer.insert(buffer.end(), data.first, data.first + data.second);
}
else
has_more = callback(data);
if (data.first && data.second)
{
has_more_data = false;
body_writer->write(data.first, data.second);
}
}
set_body(buffer.data(), buffer.size());
_response->Finish(wxSharedPtr<wxWebViewHandlerResponseData>(body_writer.release()));
_sent = true;
}
}
}
Loading