# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1671892119 0 # Node ID fe31d45352706f4933e87aef22f3cef8382300ad # Parent 425dc0126818ba581fe604038e0f4367a4acea81 C++: Implement Event and Mutex classes. diff -r 425dc0126818 -r fe31d4535270 dw.hpp --- a/dw.hpp Sat Dec 24 01:43:38 2022 +0000 +++ b/dw.hpp Sat Dec 24 14:28:39 2022 +0000 @@ -60,13 +60,7 @@ HWND hwnd; public: HWND GetHWND() { return hwnd; } - int Unpack() { return dw_box_unpack(hwnd); } - void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); } - void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); } - int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); } - void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); } - void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); } - void SetPointer(int cursortype) { dw_window_set_pointer(hwnd, cursortype); } + int Destroy() { int retval = dw_window_destroy(hwnd); delete this; return retval; } Widget *FromID(int id) { HWND child = dw_window_from_id(hwnd, id); if(child) { @@ -75,6 +69,13 @@ return DW_NULL; } void GetPreferredSize(int *width, int *height) { dw_window_get_preferred_size(hwnd, width, height); } + int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); } + void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); } + void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); } + void SetPointer(int cursortype) { dw_window_set_pointer(hwnd, cursortype); } + void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); } + void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); } + int Unpack() { return dw_box_unpack(hwnd); } }; // Box class is a packable object @@ -1338,6 +1339,36 @@ int Dismiss() { return dw_dialog_dismiss(dialog, NULL); } }; +class Mutex : public Handle +{ +private: + HMTX mutex; +public: + // Constructors + Mutex() { mutex = dw_mutex_new(); SetHandle(reinterpret_cast(mutex)); } + + // User functions + void Close() { dw_mutex_close(mutex); delete this; } + void Lock() { dw_mutex_lock(mutex); } + int TryLock() { return dw_mutex_trylock(mutex); } + void Unlock() { dw_mutex_unlock(mutex); } +}; + +class Event : public Handle +{ +private: + HEV event; +public: + // Constructors + Event() { event = dw_event_new(); SetHandle(reinterpret_cast(event)); } + + // User functions + int Close() { int retval = dw_event_close(&event); delete this; return retval; } + int Post() { return dw_event_post(event); } + int Reset() { return dw_event_reset(event); } + int Wait(unsigned long timeout) { return dw_event_wait(event, timeout); } +}; + class App { protected: