diff options
Diffstat (limited to 'include/cru/platform')
-rw-r--r-- | include/cru/platform/gui/UiApplication.h | 4 | ||||
-rw-r--r-- | include/cru/platform/gui/xcb/Base.h | 23 | ||||
-rw-r--r-- | include/cru/platform/gui/xcb/UiApplication.h | 64 | ||||
-rw-r--r-- | include/cru/platform/gui/xcb/Window.h | 10 |
4 files changed, 99 insertions, 2 deletions
diff --git a/include/cru/platform/gui/UiApplication.h b/include/cru/platform/gui/UiApplication.h index 88aa3e20..3f36c26c 100644 --- a/include/cru/platform/gui/UiApplication.h +++ b/include/cru/platform/gui/UiApplication.h @@ -64,12 +64,12 @@ struct CRU_PLATFORM_GUI_API IUiApplication : public virtual IPlatformResource { virtual IMenu* GetApplicationMenu(); /** - * \todo Implement on Windows. + * \todo Implement on Windows/X11. */ virtual std::optional<String> ShowSaveDialog(SaveDialogOptions options); /** - * \todo Implement on Windows. + * \todo Implement on Windows/X11. */ virtual std::optional<std::vector<String>> ShowOpenDialog( OpenDialogOptions options); diff --git a/include/cru/platform/gui/xcb/Base.h b/include/cru/platform/gui/xcb/Base.h new file mode 100644 index 00000000..f3bcfd01 --- /dev/null +++ b/include/cru/platform/gui/xcb/Base.h @@ -0,0 +1,23 @@ +#pragma once + +#include <cru/base/Exception.h> + +#include "../../Resource.h" + +namespace cru::platform::gui::xcb { +class XcbResource : public Object, public virtual IPlatformResource { + public: + static String kPlatformId; + + protected: + XcbResource() = default; + + public: + String GetPlatformId() const final { return kPlatformId; } +}; + +class XcbException : public PlatformException { + public: + using PlatformException::PlatformException; +}; +} // namespace cru::platform::gui::xcb diff --git a/include/cru/platform/gui/xcb/UiApplication.h b/include/cru/platform/gui/xcb/UiApplication.h new file mode 100644 index 00000000..a58a538f --- /dev/null +++ b/include/cru/platform/gui/xcb/UiApplication.h @@ -0,0 +1,64 @@ +#pragma once +#include "../UiApplication.h" +#include "Base.h" + +#include <xcb/xcb.h> + +namespace cru::platform::gui::xcb { +class XcbUiApplication : public XcbResource, public virtual IUiApplication { + public: + XcbUiApplication(); + ~XcbUiApplication(); + + void CheckXcbConnectionError(); + + virtual int Run() = 0; + + // Post a quit message with given quit code. + virtual void RequestQuit(int quit_code) = 0; + + virtual void AddOnQuitHandler(std::function<void()> handler) = 0; + + virtual bool IsQuitOnAllWindowClosed() = 0; + virtual void SetQuitOnAllWindowClosed(bool quit_on_all_window_closed) = 0; + + // Timer id should always be positive (not 0) and never the same. So it's ok + // to use negative value (or 0) to represent no timer. + virtual long long SetImmediate(std::function<void()> action) = 0; + virtual long long SetTimeout(std::chrono::milliseconds milliseconds, + std::function<void()> action) = 0; + virtual long long SetInterval(std::chrono::milliseconds milliseconds, + std::function<void()> action) = 0; + // Implementation should guarantee calls on timer id already canceled have no + // effects and do not crash. Also canceling negative id or 0 should always + // result in no-op. + virtual void CancelTimer(long long id) = 0; + + virtual std::vector<INativeWindow*> GetAllWindow() = 0; + + virtual INativeWindow* CreateWindow() = 0; + + virtual cru::platform::graphics::IGraphicsFactory* GetGraphicsFactory() = 0; + + virtual ICursorManager* GetCursorManager() = 0; + + virtual IClipboard* GetClipboard() = 0; + + // If return nullptr, it means the menu is not supported. + virtual IMenu* GetApplicationMenu(); + + /** + * \todo Implement on Windows. + */ + virtual std::optional<String> ShowSaveDialog(SaveDialogOptions options); + + /** + * \todo Implement on Windows. + */ + virtual std::optional<std::vector<String>> ShowOpenDialog( + OpenDialogOptions options); + + private: + xcb_connection_t* xcb_; +}; +} // namespace cru::platform::gui::xcb diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h new file mode 100644 index 00000000..94f5d350 --- /dev/null +++ b/include/cru/platform/gui/xcb/Window.h @@ -0,0 +1,10 @@ + +#pragma once +#include "../Window.h" +#include "Base.h" + +namespace cru::platform::gui::xcb { +class XcbWindow : public XcbResource, public virtual INativeWindow { + +}; +} // namespace cru::platform::gui::x11 |