From 98624a9bfabac7237d5b4acb5fb75f0ade83a787 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 20 Apr 2026 00:09:23 +0900 Subject: [PATCH] more handler --- include/MwCXX/Widget/Window.h | 8 ++++++++ src/widget/window.cc | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/MwCXX/Widget/Window.h b/include/MwCXX/Widget/Window.h index d82f30e..907cc7d 100644 --- a/include/MwCXX/Widget/Window.h +++ b/include/MwCXX/Widget/Window.h @@ -27,6 +27,14 @@ namespace MwCXX { void SetHasBorder(int value); int GetInverted(); void SetInverted(int value); + + virtual void OnColorChosen(MwRGB value) {}; + virtual void OnFileChosen(MwCXX::String value) {}; + virtual void OnDirectoryChosen(MwCXX::String value) {}; + + void (*ColorChosenHandler)(MwCXX::Window* widget, MwRGB value); + void (*FileChosenHandler)(MwCXX::Window* widget, MwCXX::String value); + void (*DirectoryChosenHandler)(MwCXX::Window* widget, MwCXX::String value); }; }; // namespace MwCXX diff --git a/src/widget/window.cc b/src/widget/window.cc index f0e85d0..c8885fb 100644 --- a/src/widget/window.cc +++ b/src/widget/window.cc @@ -62,5 +62,27 @@ void MwCXX::Window::SetInverted(int value) { MwSetInteger(this->widget, MwNinverted, (int)value); } -void MwCXX::Window::RegisterHandlers() { +static void __OnColorChosen(MwWidget handle, void* user, void* call) { + ((MwCXX::Window*)user)->OnColorChosen(*(MwRGB*)call); + if(((MwCXX::Window*)user)->ColorChosenHandler != NULL) ((MwCXX::Window*)user)->ColorChosenHandler((MwCXX::Window*)user, *(MwRGB*)call); +} + +static void __OnFileChosen(MwWidget handle, void* user, void* call) { + ((MwCXX::Window*)user)->OnFileChosen((MwCXX::String)(char*)call); + if(((MwCXX::Window*)user)->FileChosenHandler != NULL) ((MwCXX::Window*)user)->FileChosenHandler((MwCXX::Window*)user, (MwCXX::String)(char*)call); +} + +static void __OnDirectoryChosen(MwWidget handle, void* user, void* call) { + ((MwCXX::Window*)user)->OnDirectoryChosen((MwCXX::String)(char*)call); + if(((MwCXX::Window*)user)->DirectoryChosenHandler != NULL) ((MwCXX::Window*)user)->DirectoryChosenHandler((MwCXX::Window*)user, (MwCXX::String)(char*)call); +} + +void MwCXX::Window::RegisterHandlers() { + MwAddUserHandler(this->widget, MwNcolorChosenHandler, __OnColorChosen, (void*)this); + MwAddUserHandler(this->widget, MwNfileChosenHandler, __OnFileChosen, (void*)this); + MwAddUserHandler(this->widget, MwNdirectoryChosenHandler, __OnDirectoryChosen, (void*)this); + + this->ColorChosenHandler = NULL; + this->FileChosenHandler = NULL; + this->DirectoryChosenHandler = NULL; }