changeset 2900:fe31d4535270

C++: Implement Event and Mutex classes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 24 Dec 2022 14:28:39 +0000
parents 425dc0126818
children 761b7a12b079
files dw.hpp
diffstat 1 files changed, 38 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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<void *>(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<void *>(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: