comparison dw.hpp @ 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
comparison
equal deleted inserted replaced
2899:425dc0126818 2900:fe31d4535270
58 dw_window_set_data(hwnd, "_dw_classptr", this); 58 dw_window_set_data(hwnd, "_dw_classptr", this);
59 } 59 }
60 HWND hwnd; 60 HWND hwnd;
61 public: 61 public:
62 HWND GetHWND() { return hwnd; } 62 HWND GetHWND() { return hwnd; }
63 int Unpack() { return dw_box_unpack(hwnd); } 63 int Destroy() { int retval = dw_window_destroy(hwnd); delete this; return retval; }
64 void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); } 64 Widget *FromID(int id) {
65 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); } 65 HWND child = dw_window_from_id(hwnd, id);
66 if(child) {
67 return reinterpret_cast<Widget *>(dw_window_get_data(child, "_dw_classptr"));
68 }
69 return DW_NULL;
70 }
71 void GetPreferredSize(int *width, int *height) { dw_window_get_preferred_size(hwnd, width, height); }
66 int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); } 72 int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); }
67 void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); } 73 void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); }
68 void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); } 74 void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); }
69 void SetPointer(int cursortype) { dw_window_set_pointer(hwnd, cursortype); } 75 void SetPointer(int cursortype) { dw_window_set_pointer(hwnd, cursortype); }
70 Widget *FromID(int id) { 76 void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); }
71 HWND child = dw_window_from_id(hwnd, id); 77 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); }
72 if(child) { 78 int Unpack() { return dw_box_unpack(hwnd); }
73 return reinterpret_cast<Widget *>(dw_window_get_data(child, "_dw_classptr"));
74 }
75 return DW_NULL;
76 }
77 void GetPreferredSize(int *width, int *height) { dw_window_get_preferred_size(hwnd, width, height); }
78 }; 79 };
79 80
80 // Box class is a packable object 81 // Box class is a packable object
81 class Boxes : virtual public Widget 82 class Boxes : virtual public Widget
82 { 83 {
1336 void *Wait() { void *retval = dw_dialog_wait(dialog); delete this; return retval; } 1337 void *Wait() { void *retval = dw_dialog_wait(dialog); delete this; return retval; }
1337 int Dismiss(void *data) { return dw_dialog_dismiss(dialog, data); } 1338 int Dismiss(void *data) { return dw_dialog_dismiss(dialog, data); }
1338 int Dismiss() { return dw_dialog_dismiss(dialog, NULL); } 1339 int Dismiss() { return dw_dialog_dismiss(dialog, NULL); }
1339 }; 1340 };
1340 1341
1342 class Mutex : public Handle
1343 {
1344 private:
1345 HMTX mutex;
1346 public:
1347 // Constructors
1348 Mutex() { mutex = dw_mutex_new(); SetHandle(reinterpret_cast<void *>(mutex)); }
1349
1350 // User functions
1351 void Close() { dw_mutex_close(mutex); delete this; }
1352 void Lock() { dw_mutex_lock(mutex); }
1353 int TryLock() { return dw_mutex_trylock(mutex); }
1354 void Unlock() { dw_mutex_unlock(mutex); }
1355 };
1356
1357 class Event : public Handle
1358 {
1359 private:
1360 HEV event;
1361 public:
1362 // Constructors
1363 Event() { event = dw_event_new(); SetHandle(reinterpret_cast<void *>(event)); }
1364
1365 // User functions
1366 int Close() { int retval = dw_event_close(&event); delete this; return retval; }
1367 int Post() { return dw_event_post(event); }
1368 int Reset() { return dw_event_reset(event); }
1369 int Wait(unsigned long timeout) { return dw_event_wait(event, timeout); }
1370 };
1371
1341 class App 1372 class App
1342 { 1373 {
1343 protected: 1374 protected:
1344 App() { } 1375 App() { }
1345 static App *_app; 1376 static App *_app;