# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1672351018 0 # Node ID 969cc3b8bec227accab37808ff31c4ff902a511b # Parent 0919c2b8210966f663fa0403a5a12181c8d5c59c C++: Include the old style function support even when lambdas are available. This allows old style applications to compile unmodified on lambda supported compilers. Also include the original extremely simple test program in dwtestoo.cpp so non-lambda compilers will see something besides a build failure. Add a message to the old sample to upgrade to a lambda supported compiler to see the full sample application. diff -r 0919c2b82109 -r 969cc3b8bec2 dw.hpp --- a/dw.hpp Thu Dec 29 10:10:48 2022 +0000 +++ b/dw.hpp Thu Dec 29 21:56:58 2022 +0000 @@ -135,16 +135,23 @@ bool ClickedConnected; #ifdef DW_LAMBDA std::function _ConnectClicked; -#else - int (*_ConnectClicked)(); #endif + int (*_ConnectClickedOld)(Clickable *); static int _OnClicked(HWND window, void *data) { - if(reinterpret_cast(data)->_ConnectClicked) - return reinterpret_cast(data)->_ConnectClicked(); - return reinterpret_cast(data)->OnClicked(); } + Clickable *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectClicked) + return classptr->_ConnectClicked(); +#endif + if(classptr->_ConnectClickedOld) + return classptr->_ConnectClickedOld(classptr); + return classptr->OnClicked(); } protected: void Setup() { +#ifdef DW_LAMBDA _ConnectClicked = 0; +#endif + _ConnectClickedOld = 0; if(IsOverridden(Clickable::OnClicked, this)) { dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this); ClickedConnected = true; @@ -163,9 +170,6 @@ public: #ifdef DW_LAMBDA void ConnectClicked(std::function userfunc) -#else - void ConnectClicked(int (*userfunc)()) -#endif { _ConnectClicked = userfunc; if(!ClickedConnected) { @@ -173,6 +177,15 @@ ClickedConnected = true; } } +#endif + void ConnectClicked(int (*userfunc)(Clickable *)) + { + _ConnectClickedOld = userfunc; + if(!ClickedConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this); + ClickedConnected = true; + } + } }; class Menus : public Handle @@ -264,13 +277,16 @@ #ifdef DW_LAMBDA std::function _ConnectDelete; std::function _ConnectConfigure; -#else - int (*_ConnectDelete)(); - int (*_ConnectConfigure)(int width, int height); #endif + int (*_ConnectDeleteOld)(Window *); + int (*_ConnectConfigureOld)(Window *, int width, int height); void Setup() { +#ifdef DW_LAMBDA _ConnectDelete = 0; _ConnectConfigure = 0; +#endif + _ConnectDeleteOld = 0; + _ConnectConfigureOld = 0; menu = DW_NULL; if(IsOverridden(Window::OnDelete, this)) { dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); @@ -285,14 +301,24 @@ ConfigureConnected = false; } } - static int _OnDelete(HWND window, void *data) { - if(reinterpret_cast(data)->_ConnectDelete) - return reinterpret_cast(data)->_ConnectDelete(); - return reinterpret_cast(data)->OnDelete(); } + static int _OnDelete(HWND window, void *data) { + Window *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectDelete) + return classptr->_ConnectDelete(); +#endif + if(classptr->_ConnectDeleteOld) + return classptr->_ConnectDeleteOld(classptr); + return classptr->OnDelete(); } static int _OnConfigure(HWND window, int width, int height, void *data) { - if(reinterpret_cast(data)->_ConnectConfigure) - return reinterpret_cast(data)->_ConnectConfigure(width, height); - return reinterpret_cast(data)->OnConfigure(width, height); } + Window *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectConfigure) + return classptr->_ConnectConfigure(width, height); +#endif + if(classptr->_ConnectConfigureOld) + return classptr->_ConnectConfigureOld(classptr, width, height); + return classptr->OnConfigure(width, height); } MenuBar *menu; public: // Constructors @@ -338,9 +364,6 @@ } #ifdef DW_LAMBDA void ConnectDelete(std::function userfunc) -#else - void ConnectDelete(int (*userfunc)()) -#endif { _ConnectDelete = userfunc; if(!DeleteConnected) { @@ -350,11 +373,19 @@ DeleteConnected = false; } } +#endif + void ConnectDelete(int (*userfunc)(Window *)) + { + _ConnectDeleteOld = userfunc; + if(!DeleteConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); + DeleteConnected = true; + } else { + DeleteConnected = false; + } + } #ifdef DW_LAMBDA void ConnectConfigure(std::function userfunc) -#else - void ConnectConfigure(int (*userfunc)(int, int)) -#endif { _ConnectConfigure = userfunc; if(!ConfigureConnected) { @@ -364,6 +395,17 @@ ConfigureConnected = false; } } +#endif + void ConnectConfigure(int (*userfunc)(Window *, int, int)) + { + _ConnectConfigureOld = userfunc; + if(!ConfigureConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); + ConfigureConnected = true; + } else { + ConfigureConnected = false; + } + } protected: // Our signal handler functions to be overriden... // If they are not overridden and an event is generated, remove the unused handler @@ -563,21 +605,28 @@ std::function _ConnectButtonPress; std::function _ConnectButtonRelease; std::function _ConnectMotionNotify; -#else - int (*_ConnectExpose)(DWExpose *); - int (*_ConnectConfigure)(int width, int height); - int (*_ConnectKeyPress)(char c, int vk, int state, char *utf8); - int (*_ConnectButtonPress)(int x, int y, int buttonmask); - int (*_ConnectButtonRelease)(int x, int y, int buttonmask); - int (*_ConnectMotionNotify)(int x, int y, int buttonmask); #endif + int (*_ConnectExposeOld)(Render *, DWExpose *); + int (*_ConnectConfigureOld)(Render *, int width, int height); + int (*_ConnectKeyPressOld)(Render *, char c, int vk, int state, char *utf8); + int (*_ConnectButtonPressOld)(Render *, int x, int y, int buttonmask); + int (*_ConnectButtonReleaseOld)(Render *, int x, int y, int buttonmask); + int (*_ConnectMotionNotifyOld)(Render *, int x, int y, int buttonmask); void Setup() { +#ifdef DW_LAMBDA _ConnectExpose = 0; _ConnectConfigure = 0; _ConnectKeyPress = 0; _ConnectButtonPress = 0; _ConnectButtonRelease = 0; _ConnectMotionNotify = 0; +#endif + _ConnectExposeOld = 0; + _ConnectConfigureOld = 0; + _ConnectKeyPressOld = 0; + _ConnectButtonPressOld = 0; + _ConnectButtonReleaseOld = 0; + _ConnectMotionNotifyOld = 0; if(IsOverridden(Render::OnExpose, this)) { dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this); ExposeConnected = true; @@ -616,29 +665,59 @@ } } static int _OnExpose(HWND window, DWExpose *exp, void *data) { - if(reinterpret_cast(data)->_ConnectExpose) - return reinterpret_cast(data)->_ConnectExpose(exp); - return reinterpret_cast(data)->OnExpose(exp); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectExpose) + return classptr->_ConnectExpose(exp); +#endif + if(classptr->_ConnectExposeOld) + return classptr->_ConnectExposeOld(classptr, exp); + return classptr->OnExpose(exp); } static int _OnConfigure(HWND window, int width, int height, void *data) { - if(reinterpret_cast(data)->_ConnectConfigure) - return reinterpret_cast(data)->_ConnectConfigure(width, height); - return reinterpret_cast(data)->OnConfigure(width, height); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectConfigure) + return classptr->_ConnectConfigure(width, height); +#endif + if(classptr->_ConnectConfigureOld) + return classptr->_ConnectConfigureOld(classptr, width, height); + return classptr->OnConfigure(width, height); } static int _OnKeyPress(HWND window, char c, int vk, int state, void *data, char *utf8) { - if(reinterpret_cast(data)->_ConnectKeyPress) - return reinterpret_cast(data)->_ConnectKeyPress(c, vk, state, utf8); - return reinterpret_cast(data)->OnKeyPress(c, vk, state, utf8); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectKeyPress) + return classptr->_ConnectKeyPress(c, vk, state, utf8); +#endif + if(classptr->_ConnectKeyPressOld) + return classptr->_ConnectKeyPressOld(classptr, c, vk, state, utf8); + return classptr->OnKeyPress(c, vk, state, utf8); } static int _OnButtonPress(HWND window, int x, int y, int buttonmask, void *data) { - if(reinterpret_cast(data)->_ConnectButtonPress) - return reinterpret_cast(data)->_ConnectButtonPress(x, y, buttonmask); - return reinterpret_cast(data)->OnButtonPress(x, y, buttonmask); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectButtonPress) + return classptr->_ConnectButtonPress(x, y, buttonmask); +#endif + if(classptr->_ConnectButtonPressOld) + return classptr->_ConnectButtonPressOld(classptr, x, y, buttonmask); + return classptr->OnButtonPress(x, y, buttonmask); } static int _OnButtonRelease(HWND window, int x, int y, int buttonmask, void *data) { - if(reinterpret_cast(data)->_ConnectButtonRelease) - return reinterpret_cast(data)->_ConnectButtonRelease(x, y, buttonmask); - return reinterpret_cast(data)->OnButtonRelease(x, y, buttonmask); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectButtonRelease) + return classptr->_ConnectButtonRelease(x, y, buttonmask); +#endif + if(classptr->_ConnectButtonReleaseOld) + return classptr->_ConnectButtonReleaseOld(classptr, x, y, buttonmask); + return classptr->OnButtonRelease(x, y, buttonmask); } static int _OnMotionNotify(HWND window, int x, int y, int buttonmask, void *data) { - if(reinterpret_cast(data)->_ConnectMotionNotify) - return reinterpret_cast(data)->_ConnectMotionNotify(x, y, buttonmask); - return reinterpret_cast(data)->OnMotionNotify(x, y, buttonmask); } + Render *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectMotionNotify) + return classptr->_ConnectMotionNotify(x, y, buttonmask); +#endif + if(classptr->_ConnectMotionNotifyOld) + return classptr->_ConnectMotionNotifyOld(classptr, x, y, buttonmask); + return classptr->OnMotionNotify(x, y, buttonmask); } public: // Constructors Render(unsigned long id) { SetHWND(dw_render_new(id)); Setup(); } @@ -666,9 +745,6 @@ void Flush() { dw_flush(); } #ifdef DW_LAMBDA void ConnectExpose(std::function userfunc) -#else - void ConnectExpose(int (*userfunc)(DWExpose *)) -#endif { _ConnectExpose = userfunc; if(!ExposeConnected) { @@ -676,11 +752,17 @@ ExposeConnected = true; } } +#endif + void ConnectExpose(int (*userfunc)(Render *, DWExpose *)) + { + _ConnectExposeOld = userfunc; + if(!ExposeConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this); + ExposeConnected = true; + } + } #ifdef DW_LAMBDA void ConnectConfigure(std::function userfunc) -#else - void ConnectConfigure(int (*userfunc)(int, int)) -#endif { _ConnectConfigure = userfunc; if(!ConfigureConnected) { @@ -688,11 +770,17 @@ ConfigureConnected = true; } } +#endif + void ConnectConfigure(int (*userfunc)(Render *, int, int)) + { + _ConnectConfigureOld = userfunc; + if(!ConfigureConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); + ConfigureConnected = true; + } + } #ifdef DW_LAMBDA void ConnectKeyPress(std::function userfunc) -#else - void ConnectKeyPress(int (*userfunc)(char, int, int, char *)) -#endif { _ConnectKeyPress = userfunc; if(!KeyPressConnected) { @@ -700,11 +788,17 @@ KeyPressConnected = true; } } +#endif + void ConnectKeyPress(int (*userfunc)(Render *, char, int, int, char *)) + { + _ConnectKeyPressOld = userfunc; + if(!KeyPressConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_OnKeyPress), this); + KeyPressConnected = true; + } + } #ifdef DW_LAMBDA void ConnectButtonPress(std::function userfunc) -#else - void ConnectButtonPress(int (*userfunc)(int, int, int)) -#endif { _ConnectButtonPress = userfunc; if(!KeyPressConnected) { @@ -712,11 +806,17 @@ ButtonPressConnected = true; } } +#endif + void ConnectButtonPress(int (*userfunc)(Render *, int, int, int)) + { + _ConnectButtonPressOld = userfunc; + if(!KeyPressConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_OnButtonPress), this); + ButtonPressConnected = true; + } + } #ifdef DW_LAMBDA void ConnectButtonRelease(std::function userfunc) -#else - void ConnectButtonRelease(int (*userfunc)(int, int, int)) -#endif { _ConnectButtonRelease = userfunc; if(!KeyPressConnected) { @@ -724,11 +824,17 @@ ButtonReleaseConnected = true; } } +#endif + void ConnectButtonRelease(int (*userfunc)(Render *, int, int, int)) + { + _ConnectButtonReleaseOld = userfunc; + if(!KeyPressConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_RELEASE, DW_SIGNAL_FUNC(_OnButtonRelease), this); + ButtonReleaseConnected = true; + } + } #ifdef DW_LAMBDA void ConnectMotionNotify(std::function userfunc) -#else - void ConnectMotionNotify(int (*userfunc)(int, int, int)) -#endif { _ConnectMotionNotify = userfunc; if(!MotionNotifyConnected) { @@ -736,6 +842,15 @@ MotionNotifyConnected = true; } } +#endif + void ConnectMotionNotify(int (*userfunc)(Render *, int, int, int)) + { + _ConnectMotionNotifyOld = userfunc; + if(!MotionNotifyConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_MOTION_NOTIFY, DW_SIGNAL_FUNC(_OnMotionNotify), this); + MotionNotifyConnected = true; + } + } protected: // Our signal handler functions to be overriden... // If they are not overridden and an event is generated, remove the unused handler @@ -854,13 +969,16 @@ #ifdef DW_LAMBDA std::function _ConnectChanged; std::function _ConnectResult; -#else - int (*_ConnectChanged)(int status, char *url); - int (*_ConnectResult)(int status, char *result, void *scriptdata); #endif + int (*_ConnectChangedOld)(HTML *, int status, char *url); + int (*_ConnectResultOld)(HTML *, int status, char *result, void *scriptdata); void Setup() { +#ifdef DW_LAMBDA _ConnectChanged = 0; _ConnectResult = 0; +#endif + _ConnectChangedOld = 0; + _ConnectResultOld = 0; if(IsOverridden(HTML::OnChanged, this)) { dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); ChangedConnected = true; @@ -875,13 +993,23 @@ } } static int _OnChanged(HWND window, int status, char *url, void *data) { - if(reinterpret_cast(data)->_ConnectChanged) - return reinterpret_cast(data)->_ConnectChanged(status, url); - return reinterpret_cast(data)->OnChanged(status, url); } + HTML *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectChanged) + return classptr->_ConnectChanged(status, url); +#endif + if(classptr->_ConnectChangedOld) + return classptr->_ConnectChangedOld(classptr, status, url); + return classptr->OnChanged(status, url); } static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) { - if(reinterpret_cast(data)->_ConnectResult) - return reinterpret_cast(data)->_ConnectResult(status, result, scriptdata); - return reinterpret_cast(data)->OnResult(status, result, scriptdata); } + HTML *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectResult) + return classptr->_ConnectResult(status, result, scriptdata); +#endif + if(classptr->_ConnectResultOld) + return classptr->_ConnectResultOld(classptr, status, result, scriptdata); + return classptr->OnResult(status, result, scriptdata); } public: // Constructors HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); } @@ -894,9 +1022,6 @@ int URL(const char *url) { return dw_html_url(hwnd, url); } #ifdef DW_LAMBDA void ConnectChanged(std::function userfunc) -#else - void ConnectChanged(int (*userfunc)(int, char *)) -#endif { _ConnectChanged = userfunc; if(!ChangedConnected) { @@ -904,11 +1029,17 @@ ChangedConnected = true; } } +#endif + void ConnectChanged(int (*userfunc)(HTML *, int, char *)) + { + _ConnectChangedOld = userfunc; + if(!ChangedConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); + ChangedConnected = true; + } + } #ifdef DW_LAMBDA void ConnectResult(std::function userfunc) -#else - void ConnectResult(int (*userfunc)(int, char *, void *)) -#endif { _ConnectResult = userfunc; if(!ResultConnected) { @@ -916,6 +1047,15 @@ ResultConnected = true; } } +#endif + void ConnectResult(int (*userfunc)(HTML *, int, char *, void *)) + { + _ConnectResultOld = userfunc; + if(!ResultConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this); + ResultConnected = true; + } + } protected: // Our signal handler functions to be overriden... // If they are not overridden and an event is generated, remove the unused handler @@ -967,20 +1107,27 @@ bool ListSelectConnected; #ifdef DW_LAMBDA std::function _ConnectListSelect; -#else - int (*_ConnectListSelect)(int index); #endif + int (*_ConnectListSelectOld)(ListBoxes *, int index); void Setup() { +#ifdef DW_LAMBDA _ConnectListSelect = 0; +#endif + _ConnectListSelectOld = 0; if(IsOverridden(ListBoxes::OnListSelect, this)) { dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this); ListSelectConnected = true; } } static int _OnListSelect(HWND window, int index, void *data) { - if(reinterpret_cast(data)->_ConnectListSelect) - return reinterpret_cast(data)->_ConnectListSelect(index); - return reinterpret_cast(data)->OnListSelect(index); + ListBoxes *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectListSelect) + return classptr->_ConnectListSelect(index); +#endif + if(classptr->_ConnectListSelectOld) + return classptr->_ConnectListSelectOld(classptr, index); + return classptr->OnListSelect(index); } public: // User functions @@ -998,9 +1145,6 @@ void SetTop(int top) { dw_listbox_set_top(hwnd, top); } #ifdef DW_LAMBDA void ConnectListSelect(std::function userfunc) -#else - void ConnectListSelect(int (*userfunc)(int)) -#endif { _ConnectListSelect = userfunc; if(!ListSelectConnected) { @@ -1008,6 +1152,15 @@ ListSelectConnected = true; } } +#endif + void ConnectListSelect(int (*userfunc)(ListBoxes *, int)) + { + _ConnectListSelectOld = userfunc; + if(!ListSelectConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this); + ListSelectConnected = true; + } + } protected: // Our signal handler functions to be overriden... // If they are not overridden and an event is generated, remove the unused handler @@ -1045,13 +1198,17 @@ bool ValueChangedConnected; #ifdef DW_LAMBDA std::function _ConnectValueChanged; -#else - int (*_ConnectValueChanged)(int value); #endif + int (*_ConnectValueChangedOld)(Ranged *, int value); static int _OnValueChanged(HWND window, int value, void *data) { - if(reinterpret_cast(data)->_ConnectValueChanged) - return reinterpret_cast(data)->_ConnectValueChanged(value); - return reinterpret_cast(data)->OnValueChanged(value); + Ranged *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectValueChanged) + return classptr->_ConnectValueChanged(value); +#endif + if(classptr->_ConnectValueChangedOld) + return classptr->_ConnectValueChangedOld(classptr, value); + return classptr->OnValueChanged(value); } protected: void Setup() { @@ -1073,9 +1230,6 @@ public: #ifdef DW_LAMBDA void ConnectValueChanged(std::function userfunc) -#else - void ConnectValueChanged(int (*userfunc)(int)) -#endif { _ConnectValueChanged = userfunc; if(!ValueChangedConnected) { @@ -1083,6 +1237,15 @@ ValueChangedConnected = true; } } +#endif + void ConnectValueChanged(int (*userfunc)(Ranged *, int)) + { + _ConnectValueChangedOld = userfunc; + if(!ValueChangedConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this); + ValueChangedConnected = true; + } + } }; class Slider : public Ranged @@ -1155,13 +1318,17 @@ bool SwitchPageConnected; #ifdef DW_LAMBDA std::function _ConnectSwitchPage; -#else - int (*_ConnectSwitchPage)(unsigned long); #endif + int (*_ConnectSwitchPageOld)(Notebook *, unsigned long); static int _OnSwitchPage(HWND window, unsigned long pageid, void *data) { - if(reinterpret_cast(data)->_ConnectSwitchPage) - return reinterpret_cast(data)->_ConnectSwitchPage(pageid); - return reinterpret_cast(data)->OnSwitchPage(pageid); + Notebook *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectSwitchPage) + return classptr->_ConnectSwitchPage(pageid); +#endif + if(classptr->_ConnectSwitchPageOld) + return classptr->_ConnectSwitchPageOld(classptr, pageid); + return classptr->OnSwitchPage(pageid); } protected: void Setup() { @@ -1198,9 +1365,6 @@ void PageSetText(unsigned long pageid, const char *text) { dw_notebook_page_set_text(hwnd, pageid, text); } #ifdef DW_LAMBDA void ConnectSwitchPage(std::function userfunc) -#else - void ConnectSwitchPage(int (*userfunc)(unsigned long)) -#endif { _ConnectSwitchPage = userfunc; if(!SwitchPageConnected) { @@ -1208,6 +1372,15 @@ SwitchPageConnected = true; } } +#endif + void ConnectSwitchPage(int (*userfunc)(Notebook *, unsigned long)) + { + _ConnectSwitchPageOld = userfunc; + if(!SwitchPageConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_SWITCH_PAGE, DW_SIGNAL_FUNC(_OnSwitchPage), this); + SwitchPageConnected = true; + } + } }; class ObjectView : virtual public Widget @@ -1217,24 +1390,37 @@ #ifdef DW_LAMBDA std::function _ConnectItemSelect; std::function _ConnectItemContext; -#else - int (*_ConnectItemSelect)(HTREEITEM, char *, void *); - int (*_ConnectItemContext)(char *, int, int, void *); #endif + int (*_ConnectItemSelectOld)(ObjectView *, HTREEITEM, char *, void *); + int (*_ConnectItemContextOld)(ObjectView *, char *, int, int, void *); static int _OnItemSelect(HWND window, HTREEITEM item, char *text, void *itemdata, void *data) { - if(reinterpret_cast(data)->_ConnectItemSelect) - return reinterpret_cast(data)->_ConnectItemSelect(item, text, itemdata); - return reinterpret_cast(data)->OnItemSelect(item, text, itemdata); + ObjectView *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectItemSelect) + return classptr->_ConnectItemSelect(item, text, itemdata); +#endif + if(classptr->_ConnectItemSelectOld) + return classptr->_ConnectItemSelectOld(classptr, item, text, itemdata); + return classptr->OnItemSelect(item, text, itemdata); } static int _OnItemContext(HWND window, char *text, int x, int y, void *itemdata, void *data) { - if(reinterpret_cast(data)->_ConnectItemContext) - return reinterpret_cast(data)->_ConnectItemContext(text, x, y, itemdata); - return reinterpret_cast(data)->OnItemContext(text, x, y, itemdata); + ObjectView *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectItemContext) + return classptr->_ConnectItemContext(text, x, y, itemdata); +#endif + if(classptr->_ConnectItemContextOld) + return classptr->_ConnectItemContextOld(classptr, text, x, y, itemdata); + return classptr->OnItemContext(text, x, y, itemdata); } protected: void SetupObjectView() { +#ifdef DW_LAMBDA _ConnectItemSelect = 0; _ConnectItemContext = 0; +#endif + _ConnectItemSelectOld = 0; + _ConnectItemContextOld = 0; if(IsOverridden(ObjectView::OnItemSelect, this)) { dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); ItemSelectConnected = true; @@ -1263,9 +1449,6 @@ public: #ifdef DW_LAMBDA void ConnectItemSelect(std::function userfunc) -#else - void ConnectItemSelect(int (*userfunc)(HTREEITEM, char *, void *)) -#endif { _ConnectItemSelect = userfunc; if(!ItemSelectConnected) { @@ -1273,11 +1456,17 @@ ItemSelectConnected = true; } } +#endif + void ConnectItemSelect(int (*userfunc)(ObjectView *, HTREEITEM, char *, void *)) + { + _ConnectItemSelectOld = userfunc; + if(!ItemSelectConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); + ItemSelectConnected = true; + } + } #ifdef DW_LAMBDA void ConnectItemContext(std::function userfunc) -#else - void ConnectItemContext(int (*userfunc)(char *, int, int, void *)) -#endif { _ConnectItemContext = userfunc; if(!ItemContextConnected) { @@ -1285,6 +1474,15 @@ ItemContextConnected = true; } } +#endif + void ConnectItemContext(int (*userfunc)(ObjectView *, char *, int, int, void *)) + { + _ConnectItemContextOld = userfunc; + if(!ItemContextConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); + ItemContextConnected = true; + } + } }; class Containers : virtual public Focusable, virtual public ObjectView @@ -1294,26 +1492,39 @@ #ifdef DW_LAMBDA std::function _ConnectItemEnter; std::function _ConnectColumnClick; -#else - int (*_ConnectItemEnter)(char *); - int (*_ConnectColumnClick)(int); #endif + int (*_ConnectItemEnterOld)(Containers *, char *); + int (*_ConnectColumnClickOld)(Containers *, int); static int _OnItemEnter(HWND window, char *text, void *data) { - if(reinterpret_cast(data)->_ConnectItemEnter) - return reinterpret_cast(data)->_ConnectItemEnter(text); - return reinterpret_cast(data)->OnItemEnter(text); + Containers *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectItemEnter) + return classptr->_ConnectItemEnter(text); +#endif + if(classptr->_ConnectItemEnterOld) + return classptr->_ConnectItemEnterOld(classptr, text); + return classptr->OnItemEnter(text); } static int _OnColumnClick(HWND window, int column, void *data) { - if(reinterpret_cast(data)->_ConnectColumnClick) - return reinterpret_cast(data)->_ConnectColumnClick(column); - return reinterpret_cast(data)->OnColumnClick(column); + Containers *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectColumnClick) + return classptr->_ConnectColumnClick(column); +#endif + if(classptr->_ConnectColumnClickOld) + return classptr->_ConnectColumnClickOld(classptr, column); + return classptr->OnColumnClick(column); } protected: void *allocpointer; int allocrowcount; void SetupContainer() { +#ifdef DW_LAMBDA _ConnectItemEnter = 0; _ConnectColumnClick = 0; +#endif + _ConnectItemEnterOld = 0; + _ConnectColumnClickOld = 0; if(IsOverridden(Container::OnItemEnter, this)) { dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); ItemEnterConnected = true; @@ -1361,9 +1572,6 @@ void SetStripe(unsigned long oddcolor, unsigned long evencolor) { dw_container_set_stripe(hwnd, oddcolor, evencolor); } #ifdef DW_LAMBDA void ConnectItemEnter(std::function userfunc) -#else - void ConnectItemEnter(int (*userfunc)(char *)) -#endif { _ConnectItemEnter = userfunc; if(!ItemEnterConnected) { @@ -1371,11 +1579,17 @@ ItemEnterConnected = true; } } +#endif + void ConnectItemEnter(int (*userfunc)(Containers *, char *)) + { + _ConnectItemEnterOld = userfunc; + if(!ItemEnterConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); + ItemEnterConnected = true; + } + } #ifdef DW_LAMBDA void ConnecColumnClick(std::function userfunc) -#else - void ConnectColumnClick(int (*userfunc)(int)) -#endif { _ConnectColumnClick = userfunc; if(!ColumnClickConnected) { @@ -1383,6 +1597,15 @@ ColumnClickConnected = true; } } +#endif + void ConnectColumnClick(int (*userfunc)(Containers *, int)) + { + _ConnectColumnClickOld = userfunc; + if(!ColumnClickConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_COLUMN_CLICK, DW_SIGNAL_FUNC(_OnColumnClick), this); + ColumnClickConnected = true; + } + } }; class Container : public Containers @@ -1424,16 +1647,23 @@ bool TreeExpandConnected; #ifdef DW_LAMBDA std::function _ConnectTreeExpand; -#else - int (*_ConnectTreeExpand)(HTREEITEM); #endif + int (*_ConnectTreeExpandOld)(Tree *, HTREEITEM); static int _OnTreeExpand(HWND window, HTREEITEM item, void *data) { - if(reinterpret_cast(data)->_ConnectTreeExpand) - return reinterpret_cast(data)->_ConnectTreeExpand(item); - return reinterpret_cast(data)->OnTreeExpand(item); + Tree *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectTreeExpand) + return classptr->_ConnectTreeExpand(item); +#endif + if(classptr->_ConnectTreeExpandOld) + return classptr->_ConnectTreeExpandOld(classptr, item); + return classptr->OnTreeExpand(item); } void SetupTree() { +#ifdef DW_LAMBDA _ConnectTreeExpand = 0; +#endif + _ConnectTreeExpandOld = 0; if(IsOverridden(Tree::OnTreeExpand, this)) { dw_signal_connect(hwnd, DW_SIGNAL_TREE_EXPAND, DW_SIGNAL_FUNC(_OnTreeExpand), this); TreeExpandConnected = true; @@ -1469,9 +1699,6 @@ void SetData(HTREEITEM item, void *itemdata) { dw_tree_item_set_data(hwnd, item, itemdata); } #ifdef DW_LAMBDA void ConnectTreeExpand(std::function userfunc) -#else - void ConnectTreeExpand(int (*userfunc)(HTREEITEM)) -#endif { _ConnectTreeExpand = userfunc; if(!TreeExpandConnected) { @@ -1479,6 +1706,15 @@ TreeExpandConnected = true; } } +#endif + void ConnectTreeExpandOld(int (*userfunc)(Tree *, HTREEITEM)) + { + _ConnectTreeExpandOld = userfunc; + if(!TreeExpandConnected) { + dw_signal_connect(hwnd, DW_SIGNAL_TREE_EXPAND, DW_SIGNAL_FUNC(_OnTreeExpand), this); + TreeExpandConnected = true; + } + } }; class SplitBar : public Widget @@ -1571,24 +1807,34 @@ HTIMER timer; #ifdef DW_LAMBDA std::function _ConnectTimer; -#else - int (*_ConnectTimer)(); #endif + int (*_ConnectTimerOld)(Timer *); static int _OnTimer(void *data) { - if(reinterpret_cast(data)->_ConnectTimer) - return reinterpret_cast(data)->_ConnectTimer(); - return reinterpret_cast(data)->OnTimer(); + Timer *classptr = reinterpret_cast(data); +#ifdef DW_LAMBDA + if(classptr->_ConnectTimer) + return classptr->_ConnectTimer(); +#endif + if(classptr->_ConnectTimerOld) + return classptr->_ConnectTimerOld(classptr); + return classptr->OnTimer(); } public: // Constructors Timer(int interval) { _ConnectTimer = 0; timer = dw_timer_connect(interval, DW_SIGNAL_FUNC(_OnTimer), this); SetHandle(reinterpret_cast(timer)); } #ifdef DW_LAMBDA - Timer(int interval, std::function userfunc) -#else - Timer(int interval, int (*userfunc)()) + Timer(int interval, std::function userfunc) { + _ConnectTimer = userfunc; + _ConnectTimerOld = 0; + timer = dw_timer_connect(interval, DW_SIGNAL_FUNC(_OnTimer), this); + SetHandle(reinterpret_cast(timer)); + } #endif - { - _ConnectTimer = userfunc; + Timer(int interval, int (*userfunc)(Timer *)) { + _ConnectTimerOld = userfunc; +#ifdef DW_LAMBDA + _ConnectTimer = 0; +#endif timer = dw_timer_connect(interval, DW_SIGNAL_FUNC(_OnTimer), this); SetHandle(reinterpret_cast(timer)); } @@ -1627,17 +1873,22 @@ HPRINT print; #ifdef DW_LAMBDA std::function _ConnectDrawPage; -#else - int (*_ConnectDrawPage)(Pixmap *, int); #endif + int (*_ConnectDrawPageOld)(Print *, Pixmap *, int); static int _OnDrawPage(HPRINT print, HPIXMAP hpm, int page_num, void *data) { int retval; Pixmap *pixmap = new Pixmap(hpm); + Print *classptr = reinterpret_cast(data); - if(reinterpret_cast(data)->_ConnectDrawPage) - retval = reinterpret_cast(data)->_ConnectDrawPage(pixmap, page_num); +#ifdef DW_LAMBDA + if(classptr->_ConnectDrawPage) + retval = classptr->_ConnectDrawPage(pixmap, page_num); else - retval = reinterpret_cast(data)->OnDrawPage(pixmap, page_num); +#endif + if(classptr->_ConnectDrawPageOld) + retval = classptr->_ConnectDrawPageOld(classptr, pixmap, page_num); + else + retval = classptr->OnDrawPage(pixmap, page_num); delete pixmap; return retval; @@ -1649,14 +1900,17 @@ print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this); SetHandle(reinterpret_cast(print)); _ConnectDrawPage = userfunc; + _ConnectDrawPageOld = 0; } -#else - Print(const char *jobname, unsigned long flags, unsigned int pages, int (*userfunc)(Pixmap *, int)) { +#endif + Print(const char *jobname, unsigned long flags, unsigned int pages, int (*userfunc)(Print *, Pixmap *, int)) { print = dw_print_new(jobname, flags, pages, DW_SIGNAL_FUNC(_OnDrawPage), this); SetHandle(reinterpret_cast(print)); - _ConnectDrawPage = userfunc; + _ConnectDrawPageOld = userfunc; +#ifdef DW_LAMBDA + _ConnectDrawPage = 0; +#endif } -#endif // Destructor virtual ~Print() { if(print) dw_print_cancel(print); print = 0; } diff -r 0919c2b82109 -r 969cc3b8bec2 dwtestoo.cpp --- a/dwtestoo.cpp Thu Dec 29 10:10:48 2022 +0000 +++ b/dwtestoo.cpp Thu Dec 29 21:56:58 2022 +0000 @@ -1,9 +1,9 @@ -/* - * Simple C++ Dynamic Windows Example - */ +// An example Dynamic Windows application and testing +// ground for Dynamic Windows features in C++. +// By: Brian Smith and Mark Hessling #include "dw.hpp" -/* Select a fixed width font for our platform */ +// Select a fixed width font for our platform #ifdef __OS2__ #define FIXEDFONT "5.System VIO" #define PLATFORMFOLDER "os2\\" @@ -31,6 +31,80 @@ #define APP_TITLE "Dynamic Windows C++" #define APP_EXIT "Are you sure you want to exit?" +// Handle the case of very old compilers by using +// A simple non-lambda example instead. +#ifndef DW_LAMBDA + +// Simple C++ Dynamic Windows Example + +class DWTest : public DW::Window +{ +public: + DW::App *app; + + DWTest() { + app = DW::App::Init(); + + SetText(APP_TITLE); + SetSize(200, 200); + } + int OnDelete() override { + if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { + app->MainQuit(); + } + return FALSE; + } +}; + +int button_clicked(Clickable *classptr) +{ + DW::App *app = DW::App::Init(); + app->MessageBox("Button", DW_MB_OK | DW_MB_INFORMATION, "Clicked!"); + return TRUE; +} + +int exit_handler(Clickable *classptr) +{ + DW::App *app = DW::App::Init(); + if(app->MessageBox(APP_TITLE, DW_MB_YESNO | DW_MB_QUESTION, APP_EXIT) != 0) { + app->MainQuit(); + } + return TRUE; +} + +int dwmain(int argc, char* argv[]) +{ + DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo"); + + app->MessageBox(APP_TITLE, DW_MB_OK | DW_MB_INFORMATION, + "Warning: You are viewing the simplified version of this sample program.\n\n" \ + "This is because your compiler does not have lambda support.\n\n" \ + "Please upgrade to Clang, GCC 4.5 or Visual Studio 2010 to see the full sample."); + + DWTest *window = new DWTest(); + DW::Button *button = new DW::Button("Test window"); + + window->PackStart(button, DW_SIZE_AUTO, DW_SIZE_AUTO, TRUE, TRUE, 0); + button->ConnectClicked(&button_clicked); + + DW::MenuBar *mainmenubar = window->MenuBarNew(); + + // add menus to the menubar + DW::Menu *menu = new DW::Menu(); + DW::MenuItem *menuitem = menu->AppendItem("~Quit"); + menuitem->ConnectClicked(&exit_handler); + + // Add the "File" menu to the menubar... + mainmenubar->AppendItem("~File", menu); + + window->Show(); + + app->Main(); + app->Exit(0); + + return 0; +} +#else class DWTest : public DW::Window { private: @@ -1000,7 +1074,7 @@ } }; -/* Pretty list of features corresponding to the DWFEATURE enum in dw.h */ +// Pretty list of features corresponding to the DWFEATURE enum in dw.h const char *DWFeatureList[] = { "Supports the HTML Widget", "Supports the DW_SIGNAL_HTML_RESULT callback", @@ -1021,24 +1095,22 @@ "Supports alternate container view modes", NULL }; -/* - * Let's demonstrate the functionality of this library. :) - */ +// Let's demonstrate the functionality of this library. :) int dwmain(int argc, char* argv[]) { - /* Initialize the Dynamic Windows engine */ + // Initialize the Dynamic Windows engine DW::App *app = DW::App::Init(argc, argv, "org.dbsoft.dwindows.dwtestoo", "Dynamic Windows Test C++"); - /* Enable full dark mode on platforms that support it */ + // Enable full dark mode on platforms that support it if(getenv("DW_DARK_MODE")) app->SetFeature(DW_FEATURE_DARK_MODE, DW_DARK_MODE_FULL); #ifdef DW_MOBILE - /* Enable multi-line container display on Mobile platforms */ + // Enable multi-line container display on Mobile platforms app->SetFeature(DW_FEATURE_CONTAINER_MODE, DW_CONTAINER_MODE_MULTI); #endif - /* Test all the features and display the results */ + // Test all the features and display the results for(int intfeat=DW_FEATURE_HTML; intfeat(intfeat); @@ -1061,3 +1133,4 @@ return 0; } +#endif