# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1677299121 0 # Node ID e6072eb914ce73af3ff2d5a2855d0fe8c3b167ac # Parent b9bd130f438aba8f9a65975fc515fc7ac89422e6 C++: Step 4 of the std::string transition. Remove C style string lambda support due to limitations of std::function. std::function due to its template definition cannot differentiate parameters. This causes std::function parameters to be indistiguishable despite different signatures. Use the C style function pointer instead if you want C style strings, not lambdas. Convert KeyPress lambda to use std::string, this was missed in the last commit. diff -r b9bd130f438a -r e6072eb914ce dw.hpp --- a/dw.hpp Thu Feb 23 15:24:36 2023 +0000 +++ b/dw.hpp Sat Feb 25 04:25:21 2023 +0000 @@ -703,7 +703,6 @@ #ifdef DW_LAMBDA std::function _ConnectExpose; std::function _ConnectConfigure; - std::function _ConnectCKeyPress; std::function _ConnectKeyPress; std::function _ConnectButtonPress; std::function _ConnectButtonRelease; @@ -720,7 +719,6 @@ #ifdef DW_LAMBDA _ConnectExpose = 0; _ConnectConfigure = 0; - _ConnectCKeyPress = 0; _ConnectKeyPress = 0; _ConnectButtonPress = 0; _ConnectButtonRelease = 0; @@ -792,9 +790,7 @@ Render *classptr = reinterpret_cast(data); std::string utf8string = utf8 ? std::string(utf8) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCKeyPress) - return classptr->_ConnectCKeyPress(c, vk, state, utf8); - else if(classptr->_ConnectKeyPress) + if(classptr->_ConnectKeyPress) return classptr->_ConnectKeyPress(c, vk, state, utf8string); #endif if(classptr->_ConnectCKeyPressOld) @@ -898,14 +894,6 @@ } } #ifdef DW_LAMBDA - void ConnectKeyPress(std::function userfunc) - { - _ConnectCKeyPress = userfunc; - if(!KeyPressConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_OnKeyPress), this); - KeyPressConnected = true; - } - } void ConnectKeyPress(std::function userfunc) { _ConnectKeyPress = userfunc; @@ -1110,8 +1098,6 @@ private: bool ChangedConnected, ResultConnected; #ifdef DW_LAMBDA - std::function _ConnectCChanged; - std::function _ConnectCResult; std::function _ConnectChanged; std::function _ConnectResult; #endif @@ -1121,8 +1107,6 @@ int (*_ConnectResultOld)(HTML *, int status, std::string result, void *scriptdata); void Setup() { #ifdef DW_LAMBDA - _ConnectCChanged = 0; - _ConnectCResult = 0; _ConnectChanged = 0; _ConnectResult = 0; #endif @@ -1147,9 +1131,7 @@ HTML *classptr = reinterpret_cast(data); std::string utf8string = url ? std::string(url) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCChanged) - return classptr->_ConnectCChanged(status, url); - else if(classptr->_ConnectChanged) + if(classptr->_ConnectChanged) return classptr->_ConnectChanged(status, utf8string); #endif if(classptr->_ConnectCChangedOld) @@ -1161,9 +1143,7 @@ HTML *classptr = reinterpret_cast(data); std::string utf8string = result ? std::string(result) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCResult) - return classptr->_ConnectResult(status, result, scriptdata); - else if(classptr->_ConnectResult) + if(classptr->_ConnectResult) return classptr->_ConnectResult(status, utf8string, scriptdata); #endif if(classptr->_ConnectCResultOld) @@ -1187,14 +1167,6 @@ int Raw(std::string buffer) { return dw_html_raw(hwnd, buffer.c_str()); } int URL(std::string url) { return dw_html_url(hwnd, url.c_str()); } #ifdef DW_LAMBDA - void ConnectChangedC(std::function userfunc) - { - _ConnectCChanged = userfunc; - if(!ChangedConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); - ChangedConnected = true; - } - } void ConnectChanged(std::function userfunc) { _ConnectChanged = userfunc; @@ -1221,14 +1193,6 @@ } } #ifdef DW_LAMBDA - void ConnectResultC(std::function userfunc) - { - _ConnectCResult = userfunc; - if(!ResultConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_HTML_RESULT, DW_SIGNAL_FUNC(_OnResult), this); - ResultConnected = true; - } - } void ConnectResult(std::function userfunc) { _ConnectResult = userfunc; @@ -1657,8 +1621,6 @@ private: bool ItemSelectConnected, ItemContextConnected; #ifdef DW_LAMBDA - std::function _ConnectCItemSelect; - std::function _ConnectCItemContext; std::function _ConnectItemSelect; std::function _ConnectItemContext; #endif @@ -1670,9 +1632,7 @@ ObjectView *classptr = reinterpret_cast(data); std::string utf8string = text ? std::string(text) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCItemSelect) - return classptr->_ConnectCItemSelect(item, text, itemdata); - else if(classptr->_ConnectItemSelect) + if(classptr->_ConnectItemSelect) return classptr->_ConnectItemSelect(item, utf8string, itemdata); #endif if(classptr->_ConnectItemSelectOld) @@ -1685,9 +1645,7 @@ ObjectView *classptr = reinterpret_cast(data); std::string utf8string = text ? std::string(text) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCItemContext) - return classptr->_ConnectCItemContext(text, x, y, itemdata); - else if(classptr->_ConnectItemContext) + if(classptr->_ConnectItemContext) return classptr->_ConnectItemContext(utf8string, x, y, itemdata); #endif if(classptr->_ConnectCItemContextOld) @@ -1699,8 +1657,6 @@ protected: void SetupObjectView() { #ifdef DW_LAMBDA - _ConnectCItemSelect = 0; - _ConnectCItemContext = 0; _ConnectItemSelect = 0; _ConnectItemContext = 0; #endif @@ -1735,14 +1691,6 @@ } public: #ifdef DW_LAMBDA - void ConnectItemSelectC(std::function userfunc) - { - _ConnectCItemSelect = userfunc; - if(!ItemSelectConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); - ItemSelectConnected = true; - } - } void ConnectItemSelect(std::function userfunc) { _ConnectItemSelect = userfunc; @@ -1769,14 +1717,6 @@ } } #ifdef DW_LAMBDA - void ConnectItemContextC(std::function userfunc) - { - _ConnectCItemContext = userfunc; - if(!ItemContextConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); - ItemContextConnected = true; - } - } void ConnectItemContext(std::function userfunc) { _ConnectItemContext = userfunc; @@ -1809,7 +1749,6 @@ private: bool ItemEnterConnected, ColumnClickConnected; #ifdef DW_LAMBDA - std::function _ConnectCItemEnter; std::function _ConnectItemEnter; std::function _ConnectColumnClick; #endif @@ -1820,9 +1759,7 @@ Containers *classptr = reinterpret_cast(data); std::string utf8string = text ? std::string(text) : std::string(); #ifdef DW_LAMBDA - if(classptr->_ConnectCItemEnter) - return classptr->_ConnectCItemEnter(text, itemdata); - else if(classptr->_ConnectItemEnter) + if(classptr->_ConnectItemEnter) return classptr->_ConnectItemEnter(utf8string, itemdata); #endif if(classptr->_ConnectCItemEnterOld) @@ -1846,7 +1783,6 @@ int allocrowcount; void SetupContainer() { #ifdef DW_LAMBDA - _ConnectCItemEnter = 0; _ConnectItemEnter = 0; _ConnectColumnClick = 0; #endif @@ -1911,14 +1847,6 @@ void SetRowTitle(int row, const std::string title) { dw_container_set_row_title(allocpointer, row, title.c_str()); } void SetStripe(unsigned long oddcolor, unsigned long evencolor) { dw_container_set_stripe(hwnd, oddcolor, evencolor); } #ifdef DW_LAMBDA - void ConnectItemEnterC(std::function userfunc) - { - _ConnectCItemEnter = userfunc; - if(!ItemEnterConnected) { - dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); - ItemEnterConnected = true; - } - } void ConnectItemEnter(std::function userfunc) { _ConnectItemEnter = userfunc; diff -r b9bd130f438a -r e6072eb914ce dwtestoo.cpp --- a/dwtestoo.cpp Thu Feb 23 15:24:36 2023 +0000 +++ b/dwtestoo.cpp Sat Feb 25 04:25:21 2023 +0000 @@ -112,8 +112,8 @@ class DWTest : public DW::Window { private: - const char *ResolveKeyName(int vk) { - const char *keyname; + std::string ResolveKeyName(int vk) { + std::string keyname; switch(vk) { case VK_LBUTTON : keyname = "VK_LBUTTON"; break; case VK_RBUTTON : keyname = "VK_RBUTTON"; break; @@ -194,7 +194,7 @@ return keyname; } - const char *ResolveKeyModifiers(int mask) { + std::string ResolveKeyModifiers(int mask) { if((mask & KC_CTRL) && (mask & KC_SHIFT) && (mask & KC_ALT)) return "KC_CTRL KC_SHIFT KC_ALT"; else if((mask & KC_CTRL) && (mask & KC_SHIFT)) @@ -986,14 +986,18 @@ return TRUE; }); - render2->ConnectKeyPress([this, status1](char ch, int vk, int state, char *utf8) -> int + render2->ConnectKeyPress([this, status1](char ch, int vk, int state, std::string utf8) -> int { - char tmpbuf[101] = {0}; + std::string buf = "Key: "; + if(ch) - snprintf(tmpbuf, 100, "Key: %c(%d) Modifiers: %s(%d) utf8 %s", ch, ch, this->ResolveKeyModifiers(state), state, utf8); + buf += std::string(1, ch) + "(" + std::to_string((int)ch) + ")"; else - snprintf(tmpbuf, 100, "Key: %s(%d) Modifiers: %s(%d) utf8 %s", this->ResolveKeyName(vk), vk, ResolveKeyModifiers(state), state, utf8); - status1->SetText(tmpbuf); + buf += ResolveKeyName(vk) + "(" + std::to_string(vk) + ")"; + + buf += " Modifiers: " + ResolveKeyModifiers(state) + "(" + std::to_string(state) + ") utf8 " + utf8; + + status1->SetText(buf); return FALSE; });