Crafter.CppDOM/interfaces/Crafter.CppDOM-HtmlElement.cppm

235 lines
No EOL
10 KiB
C++

/*
Crafter.CppDOM
Copyright (C) 2025 Catcrafts
Catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
export module Crafter.CppDOM:HtmlElement;
import std;
import :BindingsExport;
import :BindingsImport;
import :EventTypes;
namespace Crafter {
export class HtmlElementPtr {
public:
std::int32_t ptr;
HtmlElementPtr(const std::string_view id);
HtmlElementPtr(const std::string_view id, const std::string_view html);
HtmlElementPtr(HtmlElementPtr&&);
HtmlElementPtr(const HtmlElementPtr&) = delete;
HtmlElementPtr& operator=(const HtmlElementPtr&) = delete;
~HtmlElementPtr();
void SetInnerHTML(const std::string_view html);
void SetStyle(const std::string_view style);
void SetProperty(const std::string_view property, const std::string_view value);
void AddClass(const std::string_view className);
void RemoveClass(const std::string_view className);
void ToggleClass(const std::string_view className);
bool HasClass(const std::string_view className);
std::string GetValue();
void SetValue(const std::string_view value);
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveClickListener(std::int32_t id);
std::int32_t AddMouseOverListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOverListener(std::int32_t id);
std::int32_t AddMouseOutListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOutListener(std::int32_t id);
std::int32_t AddMouseMoveListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseMoveListener(std::int32_t id);
std::int32_t AddMouseDownListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseDownListener(std::int32_t id);
std::int32_t AddMouseUpListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseUpListener(std::int32_t id);
std::int32_t AddFocusListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveFocusListener(std::int32_t id);
std::int32_t AddBlurListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveBlurListener(std::int32_t id);
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyDownListener(std::int32_t id);
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyUpListener(std::int32_t id);
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyPressListener(std::int32_t id);
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback);
void RemoveChangeListener(std::int32_t id);
std::int32_t AddSubmitListener(std::function<void(void)> callback);
void RemoveSubmitListener(std::int32_t id);
std::int32_t AddInputListener(std::function<void(InputEvent)> callback);
void RemoveInputListener(std::int32_t id);
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback);
void RemoveResizeListener(std::int32_t id);
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback);
void RemoveScrollListener(std::int32_t id);
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback);
void RemoveContextMenuListener(std::int32_t id);
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback);
void RemoveDragStartListener(std::int32_t id);
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback);
void RemoveDragEndListener(std::int32_t id);
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback);
void RemoveDropListener(std::int32_t id);
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback);
void RemoveDragOverListener(std::int32_t id);
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback);
void RemoveDragEnterListener(std::int32_t id);
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback);
void RemoveDragLeaveListener(std::int32_t id);
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback);
void RemoveWheelListener(std::int32_t id);
};
export class HtmlElementView : public HtmlElementPtr {
public:
HtmlElementView(const std::string_view id);
HtmlElementView(const std::string_view id, const std::string_view html);
HtmlElementView(HtmlElementView&&);
~HtmlElementView();
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveClickListener(std::int32_t id);
std::int32_t AddMouseOverListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOverListener(std::int32_t id);
std::int32_t AddMouseOutListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseOutListener(std::int32_t id);
std::int32_t AddMouseMoveListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseMoveListener(std::int32_t id);
std::int32_t AddMouseDownListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseDownListener(std::int32_t id);
std::int32_t AddMouseUpListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveMouseUpListener(std::int32_t id);
std::int32_t AddFocusListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveFocusListener(std::int32_t id);
std::int32_t AddBlurListener(std::function<void(Crafter::FocusEvent)> callback);
void RemoveBlurListener(std::int32_t id);
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyDownListener(std::int32_t id);
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyUpListener(std::int32_t id);
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback);
void RemoveKeyPressListener(std::int32_t id);
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback);
void RemoveChangeListener(std::int32_t id);
std::int32_t AddSubmitListener(std::function<void(void)> callback);
void RemoveSubmitListener(std::int32_t id);
std::int32_t AddInputListener(std::function<void(InputEvent)> callback);
void RemoveInputListener(std::int32_t id);
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback);
void RemoveResizeListener(std::int32_t id);
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback);
void RemoveScrollListener(std::int32_t id);
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback);
void RemoveContextMenuListener(std::int32_t id);
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback);
void RemoveDragStartListener(std::int32_t id);
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback);
void RemoveDragEndListener(std::int32_t id);
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback);
void RemoveDropListener(std::int32_t id);
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback);
void RemoveDragOverListener(std::int32_t id);
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback);
void RemoveDragEnterListener(std::int32_t id);
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback);
void RemoveDragLeaveListener(std::int32_t id);
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback);
void RemoveWheelListener(std::int32_t id);
private:
std::vector<std::int32_t> clickHandlers;
std::vector<std::int32_t> mouseOverHandlers;
std::vector<std::int32_t> mouseOutHandlers;
std::vector<std::int32_t> mouseMoveHandlers;
std::vector<std::int32_t> mouseDownHandlers;
std::vector<std::int32_t> mouseUpHandlers;
std::vector<std::int32_t> focusHandlers;
std::vector<std::int32_t> blurHandlers;
std::vector<std::int32_t> keyDownHandlers;
std::vector<std::int32_t> keyUpHandlers;
std::vector<std::int32_t> keyPressHandlers;
std::vector<std::int32_t> changeHandlers;
std::vector<std::int32_t> submitHandlers;
std::vector<std::int32_t> inputHandlers;
std::vector<std::int32_t> resizeHandlers;
std::vector<std::int32_t> scrollHandlers;
std::vector<std::int32_t> contextMenuHandlers;
std::vector<std::int32_t> dragStartHandlers;
std::vector<std::int32_t> dragEndHandlers;
std::vector<std::int32_t> dropHandlers;
std::vector<std::int32_t> dragOverHandlers;
std::vector<std::int32_t> dragEnterHandlers;
std::vector<std::int32_t> dragLeaveHandlers;
std::vector<std::int32_t> wheelHandlers;
};
export class HtmlElement : public HtmlElementView {
public:
HtmlElement(const std::string_view id);
HtmlElement(const std::string_view id, const std::string_view html);
HtmlElement(HtmlElement&&);
~HtmlElement();
};
}