Mercurial > dwindows
comparison dw.hpp @ 2961:b9bd130f438a
C++: Step 3 of the std::string transition.
Convert the class overrides to use std::string instead of char*.
Implement functions that take arrays of strings to std::vector<std::string>.
Begin converting dwtestoo to use std::string instead of C style strings.
Temporarily rename C style Connect functions to have a C at the end.
It isn't clear to me why, but clang is telling me they are ambiguous.
Even though the lambda explicitly specifies std::string it can't decide
between the std::string or char* versions of the functions.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 23 Feb 2023 15:24:36 +0000 |
parents | 1dabe9c6c67b |
children | e6072eb914ce |
comparison
equal
deleted
inserted
replaced
2960:1dabe9c6c67b | 2961:b9bd130f438a |
---|---|
5 #ifndef _HPP_DW | 5 #ifndef _HPP_DW |
6 #define _HPP_DW | 6 #define _HPP_DW |
7 #include <dw.h> | 7 #include <dw.h> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
10 | 11 |
11 // Attempt to support compilers without nullptr type literal | 12 // Attempt to support compilers without nullptr type literal |
12 #if __cplusplus >= 201103L | 13 #if __cplusplus >= 201103L |
13 #define DW_CPP11 | 14 #define DW_CPP11 |
14 #define DW_NULL nullptr | 15 #define DW_NULL nullptr |
787 if(classptr->_ConnectConfigureOld) | 788 if(classptr->_ConnectConfigureOld) |
788 return classptr->_ConnectConfigureOld(classptr, width, height); | 789 return classptr->_ConnectConfigureOld(classptr, width, height); |
789 return classptr->OnConfigure(width, height); } | 790 return classptr->OnConfigure(width, height); } |
790 static int _OnKeyPress(HWND window, char c, int vk, int state, void *data, char *utf8) { | 791 static int _OnKeyPress(HWND window, char c, int vk, int state, void *data, char *utf8) { |
791 Render *classptr = reinterpret_cast<Render *>(data); | 792 Render *classptr = reinterpret_cast<Render *>(data); |
793 std::string utf8string = utf8 ? std::string(utf8) : std::string(); | |
792 #ifdef DW_LAMBDA | 794 #ifdef DW_LAMBDA |
793 if(classptr->_ConnectCKeyPress) | 795 if(classptr->_ConnectCKeyPress) |
794 return classptr->_ConnectCKeyPress(c, vk, state, utf8); | 796 return classptr->_ConnectCKeyPress(c, vk, state, utf8); |
795 else if(classptr->_ConnectKeyPress) { | 797 else if(classptr->_ConnectKeyPress) |
796 std::string utf8string = utf8 ? std::string(utf8) : std::string(); | |
797 return classptr->_ConnectKeyPress(c, vk, state, utf8string); | 798 return classptr->_ConnectKeyPress(c, vk, state, utf8string); |
798 } | |
799 #endif | 799 #endif |
800 if(classptr->_ConnectCKeyPressOld) | 800 if(classptr->_ConnectCKeyPressOld) |
801 return classptr->_ConnectCKeyPressOld(classptr, c, vk, state, utf8); | 801 return classptr->_ConnectCKeyPressOld(classptr, c, vk, state, utf8); |
802 else if(classptr->_ConnectKeyPressOld) { | 802 else if(classptr->_ConnectKeyPressOld) |
803 std::string utf8string = utf8 ? std::string(utf8) : std::string(); | |
804 return classptr->_ConnectKeyPressOld(classptr, c, vk, state, utf8string); | 803 return classptr->_ConnectKeyPressOld(classptr, c, vk, state, utf8string); |
805 } | 804 return classptr->OnKeyPress(c, vk, state, utf8string); } |
806 return classptr->OnKeyPress(c, vk, state, utf8); } | |
807 static int _OnButtonPress(HWND window, int x, int y, int buttonmask, void *data) { | 805 static int _OnButtonPress(HWND window, int x, int y, int buttonmask, void *data) { |
808 Render *classptr = reinterpret_cast<Render *>(data); | 806 Render *classptr = reinterpret_cast<Render *>(data); |
809 #ifdef DW_LAMBDA | 807 #ifdef DW_LAMBDA |
810 if(classptr->_ConnectButtonPress) | 808 if(classptr->_ConnectButtonPress) |
811 return classptr->_ConnectButtonPress(x, y, buttonmask); | 809 return classptr->_ConnectButtonPress(x, y, buttonmask); |
998 virtual int OnConfigure(int width, int height) { | 996 virtual int OnConfigure(int width, int height) { |
999 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); | 997 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); |
1000 ConfigureConnected = false; | 998 ConfigureConnected = false; |
1001 return FALSE; | 999 return FALSE; |
1002 }; | 1000 }; |
1003 virtual int OnKeyPress(char c, int vk, int state, char *utf8) { | 1001 virtual int OnKeyPress(char c, int vk, int state, std::string utf8) { |
1004 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_KEY_PRESS); | 1002 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_KEY_PRESS); |
1005 KeyPressConnected = false; | 1003 KeyPressConnected = false; |
1006 return FALSE; | 1004 return FALSE; |
1007 }; | 1005 }; |
1008 virtual int OnButtonPress(char x, int y, int buttonmask) { | 1006 virtual int OnButtonPress(char x, int y, int buttonmask) { |
1145 ResultConnected = false; | 1143 ResultConnected = false; |
1146 } | 1144 } |
1147 } | 1145 } |
1148 static int _OnChanged(HWND window, int status, char *url, void *data) { | 1146 static int _OnChanged(HWND window, int status, char *url, void *data) { |
1149 HTML *classptr = reinterpret_cast<HTML *>(data); | 1147 HTML *classptr = reinterpret_cast<HTML *>(data); |
1148 std::string utf8string = url ? std::string(url) : std::string(); | |
1150 #ifdef DW_LAMBDA | 1149 #ifdef DW_LAMBDA |
1151 if(classptr->_ConnectCChanged) | 1150 if(classptr->_ConnectCChanged) |
1152 return classptr->_ConnectCChanged(status, url); | 1151 return classptr->_ConnectCChanged(status, url); |
1153 else if(classptr->_ConnectChanged) { | 1152 else if(classptr->_ConnectChanged) |
1154 std::string utf8string = url ? std::string(url) : std::string(); | |
1155 return classptr->_ConnectChanged(status, utf8string); | 1153 return classptr->_ConnectChanged(status, utf8string); |
1156 } | |
1157 #endif | 1154 #endif |
1158 if(classptr->_ConnectCChangedOld) | 1155 if(classptr->_ConnectCChangedOld) |
1159 return classptr->_ConnectCChangedOld(classptr, status, url); | 1156 return classptr->_ConnectCChangedOld(classptr, status, url); |
1160 else if(classptr->_ConnectChangedOld) { | 1157 else if(classptr->_ConnectChangedOld) |
1161 std::string utf8string = url ? std::string(url) : std::string(); | |
1162 return classptr->_ConnectChangedOld(classptr, status, utf8string); | 1158 return classptr->_ConnectChangedOld(classptr, status, utf8string); |
1163 } | 1159 return classptr->OnChanged(status, utf8string); } |
1164 return classptr->OnChanged(status, url); } | |
1165 static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) { | 1160 static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) { |
1166 HTML *classptr = reinterpret_cast<HTML *>(data); | 1161 HTML *classptr = reinterpret_cast<HTML *>(data); |
1162 std::string utf8string = result ? std::string(result) : std::string(); | |
1167 #ifdef DW_LAMBDA | 1163 #ifdef DW_LAMBDA |
1168 if(classptr->_ConnectCResult) | 1164 if(classptr->_ConnectCResult) |
1169 return classptr->_ConnectResult(status, result, scriptdata); | 1165 return classptr->_ConnectResult(status, result, scriptdata); |
1170 else if(classptr->_ConnectResult) { | 1166 else if(classptr->_ConnectResult) |
1171 std::string utf8string = result ? std::string(result) : std::string(); | |
1172 return classptr->_ConnectResult(status, utf8string, scriptdata); | 1167 return classptr->_ConnectResult(status, utf8string, scriptdata); |
1173 } | |
1174 #endif | 1168 #endif |
1175 if(classptr->_ConnectCResultOld) | 1169 if(classptr->_ConnectCResultOld) |
1176 return classptr->_ConnectCResultOld(classptr, status, result, scriptdata); | 1170 return classptr->_ConnectCResultOld(classptr, status, result, scriptdata); |
1177 else if(classptr->_ConnectResultOld) { | 1171 else if(classptr->_ConnectResultOld) |
1178 std::string utf8string = result ? std::string(result) : std::string(); | |
1179 return classptr->_ConnectResultOld(classptr, status, utf8string, scriptdata); | 1172 return classptr->_ConnectResultOld(classptr, status, utf8string, scriptdata); |
1180 } | 1173 return classptr->OnResult(status, utf8string, scriptdata); } |
1181 return classptr->OnResult(status, result, scriptdata); } | |
1182 public: | 1174 public: |
1183 // Constructors | 1175 // Constructors |
1184 HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); } | 1176 HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); } |
1185 HTML() { SetHWND(dw_html_new(0)); Setup(); } | 1177 HTML() { SetHWND(dw_html_new(0)); Setup(); } |
1186 | 1178 |
1193 int JavascriptRun(std::string script, void *scriptdata) { return dw_html_javascript_run(hwnd, script.c_str(), scriptdata); } | 1185 int JavascriptRun(std::string script, void *scriptdata) { return dw_html_javascript_run(hwnd, script.c_str(), scriptdata); } |
1194 int JavascriptRun(std::string script) { return dw_html_javascript_run(hwnd, script.c_str(), NULL); } | 1186 int JavascriptRun(std::string script) { return dw_html_javascript_run(hwnd, script.c_str(), NULL); } |
1195 int Raw(std::string buffer) { return dw_html_raw(hwnd, buffer.c_str()); } | 1187 int Raw(std::string buffer) { return dw_html_raw(hwnd, buffer.c_str()); } |
1196 int URL(std::string url) { return dw_html_url(hwnd, url.c_str()); } | 1188 int URL(std::string url) { return dw_html_url(hwnd, url.c_str()); } |
1197 #ifdef DW_LAMBDA | 1189 #ifdef DW_LAMBDA |
1198 void ConnectChanged(std::function<int(int, char *)> userfunc) | 1190 void ConnectChangedC(std::function<int(int, char *)> userfunc) |
1199 { | 1191 { |
1200 _ConnectCChanged = userfunc; | 1192 _ConnectCChanged = userfunc; |
1201 if(!ChangedConnected) { | 1193 if(!ChangedConnected) { |
1202 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); | 1194 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); |
1203 ChangedConnected = true; | 1195 ChangedConnected = true; |
1227 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); | 1219 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); |
1228 ChangedConnected = true; | 1220 ChangedConnected = true; |
1229 } | 1221 } |
1230 } | 1222 } |
1231 #ifdef DW_LAMBDA | 1223 #ifdef DW_LAMBDA |
1232 void ConnectResult(std::function<int(int, char *, void *)> userfunc) | 1224 void ConnectResultC(std::function<int(int, char *, void *)> userfunc) |
1233 { | 1225 { |
1234 _ConnectCResult = userfunc; | 1226 _ConnectCResult = userfunc; |
1235 if(!ResultConnected) { | 1227 if(!ResultConnected) { |
1236 dw_signal_connect(hwnd, DW_SIGNAL_HTML_RESULT, DW_SIGNAL_FUNC(_OnResult), this); | 1228 dw_signal_connect(hwnd, DW_SIGNAL_HTML_RESULT, DW_SIGNAL_FUNC(_OnResult), this); |
1237 ResultConnected = true; | 1229 ResultConnected = true; |
1263 } | 1255 } |
1264 } | 1256 } |
1265 protected: | 1257 protected: |
1266 // Our signal handler functions to be overriden... | 1258 // Our signal handler functions to be overriden... |
1267 // If they are not overridden and an event is generated, remove the unused handler | 1259 // If they are not overridden and an event is generated, remove the unused handler |
1268 virtual int OnChanged(int status, char *url) { | 1260 virtual int OnChanged(int status, std::string url) { |
1269 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED); | 1261 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED); |
1270 ChangedConnected = false; | 1262 ChangedConnected = false; |
1271 return FALSE; | 1263 return FALSE; |
1272 } | 1264 } |
1273 virtual int OnResult(int status, char *result, void *scriptdata) { | 1265 virtual int OnResult(int status, std::string result, void *scriptdata) { |
1274 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT); | 1266 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT); |
1275 ResultConnected = false; | 1267 ResultConnected = false; |
1276 return FALSE; | 1268 return FALSE; |
1277 }; | 1269 }; |
1278 }; | 1270 }; |
1335 void Append(std::string text) { dw_listbox_append(hwnd, text.c_str()); } | 1327 void Append(std::string text) { dw_listbox_append(hwnd, text.c_str()); } |
1336 void Clear() { dw_listbox_clear(hwnd); } | 1328 void Clear() { dw_listbox_clear(hwnd); } |
1337 int Count() { return dw_listbox_count(hwnd); } | 1329 int Count() { return dw_listbox_count(hwnd); } |
1338 void Delete(int index) { dw_listbox_delete(hwnd, index); } | 1330 void Delete(int index) { dw_listbox_delete(hwnd, index); } |
1339 void GetListText(unsigned int index, char *buffer, unsigned int length) { dw_listbox_get_text(hwnd, index, buffer, length); } | 1331 void GetListText(unsigned int index, char *buffer, unsigned int length) { dw_listbox_get_text(hwnd, index, buffer, length); } |
1332 std::string GetListText(unsigned int index) { | |
1333 int length = 1025; | |
1334 char *buffer = (char *)alloca(length); | |
1335 | |
1336 if(buffer) { | |
1337 memset(buffer, 0, length); | |
1338 dw_listbox_get_text(hwnd, index, buffer, length); | |
1339 return std::string(buffer); | |
1340 } | |
1341 return std::string(); | |
1342 } | |
1340 void SetListText(unsigned int index, char *buffer) { dw_listbox_set_text(hwnd, index, buffer); } | 1343 void SetListText(unsigned int index, char *buffer) { dw_listbox_set_text(hwnd, index, buffer); } |
1341 void SetListText(unsigned int index, std::string buffer) { dw_listbox_set_text(hwnd, index, buffer.c_str()); } | 1344 void SetListText(unsigned int index, std::string buffer) { dw_listbox_set_text(hwnd, index, buffer.c_str()); } |
1342 void Insert(const char *text, int pos) { dw_listbox_insert(hwnd, text, pos); } | 1345 void Insert(const char *text, int pos) { dw_listbox_insert(hwnd, text, pos); } |
1343 void Insert(std::string text, int pos) { dw_listbox_insert(hwnd, text.c_str(), pos); } | 1346 void Insert(std::string text, int pos) { dw_listbox_insert(hwnd, text.c_str(), pos); } |
1344 void ListAppend(char **text, int count) { dw_listbox_list_append(hwnd, text, count); } | 1347 void ListAppend(char **text, int count) { dw_listbox_list_append(hwnd, text, count); } |
1348 void ListAppend(std::vector<std::string> text) { | |
1349 int count = (int)text.size(); | |
1350 const char **ctext = (const char **)alloca(sizeof(char *) * count); | |
1351 | |
1352 if(count > 0 && ctext) { | |
1353 for(int z=0; z<count; z++) { | |
1354 ctext[z] = text[z].c_str(); | |
1355 } | |
1356 dw_listbox_list_append(hwnd, (char **)ctext, count); | |
1357 } | |
1358 } | |
1345 void Select(int index, int state) { dw_listbox_select(hwnd, index, state); } | 1359 void Select(int index, int state) { dw_listbox_select(hwnd, index, state); } |
1346 int Selected() { return dw_listbox_selected(hwnd); } | 1360 int Selected() { return dw_listbox_selected(hwnd); } |
1347 int Selected(int where) { return dw_listbox_selected_multi(hwnd, where); } | 1361 int Selected(int where) { return dw_listbox_selected_multi(hwnd, where); } |
1348 void SetTop(int top) { dw_listbox_set_top(hwnd, top); } | 1362 void SetTop(int top) { dw_listbox_set_top(hwnd, top); } |
1349 #ifdef DW_LAMBDA | 1363 #ifdef DW_LAMBDA |
1531 void Freeze() { dw_mle_freeze(hwnd); } | 1545 void Freeze() { dw_mle_freeze(hwnd); } |
1532 void Thaw() { dw_mle_thaw(hwnd); } | 1546 void Thaw() { dw_mle_thaw(hwnd); } |
1533 void Clear() { dw_mle_clear(hwnd); } | 1547 void Clear() { dw_mle_clear(hwnd); } |
1534 void Delete(int startpoint, int length) { dw_mle_delete(hwnd, startpoint, length); } | 1548 void Delete(int startpoint, int length) { dw_mle_delete(hwnd, startpoint, length); } |
1535 void Export(char *buffer, int startpoint, int length) { dw_mle_export(hwnd, buffer, startpoint, length); } | 1549 void Export(char *buffer, int startpoint, int length) { dw_mle_export(hwnd, buffer, startpoint, length); } |
1550 std::string Export(int startpoint, int length) { | |
1551 char *buffer = (char *)alloca(length + 1); | |
1552 | |
1553 if(buffer) { | |
1554 memset(buffer, 0, length + 1); | |
1555 dw_mle_export(hwnd, buffer, startpoint, length); | |
1556 return std::string(buffer); | |
1557 } | |
1558 return std::string(); | |
1559 } | |
1536 int Import(const char *buffer, int startpoint) { return dw_mle_import(hwnd, buffer, startpoint); } | 1560 int Import(const char *buffer, int startpoint) { return dw_mle_import(hwnd, buffer, startpoint); } |
1537 int Import(std::string buffer, int startpoint) { return dw_mle_import(hwnd, buffer.c_str(), startpoint); } | 1561 int Import(std::string buffer, int startpoint) { return dw_mle_import(hwnd, buffer.c_str(), startpoint); } |
1538 void GetSize(unsigned long *bytes, unsigned long *lines) { dw_mle_get_size(hwnd, bytes, lines); } | 1562 void GetSize(unsigned long *bytes, unsigned long *lines) { dw_mle_get_size(hwnd, bytes, lines); } |
1539 void Search(const char *text, int point, unsigned long flags) { dw_mle_search(hwnd, text, point, flags); } | 1563 void Search(const char *text, int point, unsigned long flags) { dw_mle_search(hwnd, text, point, flags); } |
1540 void Search(std::string text, int point, unsigned long flags) { dw_mle_search(hwnd, text.c_str(), point, flags); } | 1564 void Search(std::string text, int point, unsigned long flags) { dw_mle_search(hwnd, text.c_str(), point, flags); } |
1642 int (*_ConnectCItemContextOld)(ObjectView *, char *, int, int, void *); | 1666 int (*_ConnectCItemContextOld)(ObjectView *, char *, int, int, void *); |
1643 int (*_ConnectItemSelectOld)(ObjectView *, HTREEITEM, std::string, void *); | 1667 int (*_ConnectItemSelectOld)(ObjectView *, HTREEITEM, std::string, void *); |
1644 int (*_ConnectItemContextOld)(ObjectView *, std::string, int, int, void *); | 1668 int (*_ConnectItemContextOld)(ObjectView *, std::string, int, int, void *); |
1645 static int _OnItemSelect(HWND window, HTREEITEM item, char *text, void *data, void *itemdata) { | 1669 static int _OnItemSelect(HWND window, HTREEITEM item, char *text, void *data, void *itemdata) { |
1646 ObjectView *classptr = reinterpret_cast<ObjectView *>(data); | 1670 ObjectView *classptr = reinterpret_cast<ObjectView *>(data); |
1671 std::string utf8string = text ? std::string(text) : std::string(); | |
1647 #ifdef DW_LAMBDA | 1672 #ifdef DW_LAMBDA |
1648 if(classptr->_ConnectCItemSelect) | 1673 if(classptr->_ConnectCItemSelect) |
1649 return classptr->_ConnectCItemSelect(item, text, itemdata); | 1674 return classptr->_ConnectCItemSelect(item, text, itemdata); |
1650 else if(classptr->_ConnectItemSelect) { | 1675 else if(classptr->_ConnectItemSelect) |
1651 std::string utf8string = text ? std::string(text) : std::string(); | |
1652 return classptr->_ConnectItemSelect(item, utf8string, itemdata); | 1676 return classptr->_ConnectItemSelect(item, utf8string, itemdata); |
1653 } | |
1654 #endif | 1677 #endif |
1655 if(classptr->_ConnectItemSelectOld) | 1678 if(classptr->_ConnectItemSelectOld) |
1656 return classptr->_ConnectItemSelectOld(classptr, item, text, itemdata); | 1679 return classptr->_ConnectItemSelectOld(classptr, item, text, itemdata); |
1657 else if(classptr->_ConnectItemSelectOld) { | 1680 else if(classptr->_ConnectItemSelectOld) |
1658 std::string utf8string = text ? std::string(text) : std::string(); | |
1659 return classptr->_ConnectItemSelectOld(classptr, item, utf8string, itemdata); | 1681 return classptr->_ConnectItemSelectOld(classptr, item, utf8string, itemdata); |
1660 } | 1682 return classptr->OnItemSelect(item, utf8string, itemdata); |
1661 return classptr->OnItemSelect(item, text, itemdata); | |
1662 } | 1683 } |
1663 static int _OnItemContext(HWND window, char *text, int x, int y, void *data, void *itemdata) { | 1684 static int _OnItemContext(HWND window, char *text, int x, int y, void *data, void *itemdata) { |
1664 ObjectView *classptr = reinterpret_cast<ObjectView *>(data); | 1685 ObjectView *classptr = reinterpret_cast<ObjectView *>(data); |
1686 std::string utf8string = text ? std::string(text) : std::string(); | |
1665 #ifdef DW_LAMBDA | 1687 #ifdef DW_LAMBDA |
1666 if(classptr->_ConnectCItemContext) | 1688 if(classptr->_ConnectCItemContext) |
1667 return classptr->_ConnectCItemContext(text, x, y, itemdata); | 1689 return classptr->_ConnectCItemContext(text, x, y, itemdata); |
1668 else if(classptr->_ConnectItemContext) { | 1690 else if(classptr->_ConnectItemContext) |
1669 std::string utf8string = text ? std::string(text) : std::string(); | |
1670 return classptr->_ConnectItemContext(utf8string, x, y, itemdata); | 1691 return classptr->_ConnectItemContext(utf8string, x, y, itemdata); |
1671 } | |
1672 #endif | 1692 #endif |
1673 if(classptr->_ConnectCItemContextOld) | 1693 if(classptr->_ConnectCItemContextOld) |
1674 return classptr->_ConnectCItemContextOld(classptr, text, x, y, itemdata); | 1694 return classptr->_ConnectCItemContextOld(classptr, text, x, y, itemdata); |
1675 else if(classptr->_ConnectItemContextOld) { | 1695 else if(classptr->_ConnectItemContextOld) |
1676 std::string utf8string = text ? std::string(text) : std::string(); | |
1677 return classptr->_ConnectItemContextOld(classptr, utf8string, x, y, itemdata); | 1696 return classptr->_ConnectItemContextOld(classptr, utf8string, x, y, itemdata); |
1678 } | 1697 return classptr->OnItemContext(utf8string, x, y, itemdata); |
1679 return classptr->OnItemContext(text, x, y, itemdata); | |
1680 } | 1698 } |
1681 protected: | 1699 protected: |
1682 void SetupObjectView() { | 1700 void SetupObjectView() { |
1683 #ifdef DW_LAMBDA | 1701 #ifdef DW_LAMBDA |
1684 _ConnectCItemSelect = 0; | 1702 _ConnectCItemSelect = 0; |
1703 ItemContextConnected = false; | 1721 ItemContextConnected = false; |
1704 } | 1722 } |
1705 } | 1723 } |
1706 // Our signal handler functions to be overriden... | 1724 // Our signal handler functions to be overriden... |
1707 // If they are not overridden and an event is generated, remove the unused handler | 1725 // If they are not overridden and an event is generated, remove the unused handler |
1708 virtual int OnItemSelect(HTREEITEM item, char *text, void *itemdata) { | 1726 virtual int OnItemSelect(HTREEITEM item, std::string text, void *itemdata) { |
1709 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_SELECT); | 1727 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_SELECT); |
1710 ItemSelectConnected = false; | 1728 ItemSelectConnected = false; |
1711 return FALSE; | 1729 return FALSE; |
1712 } | 1730 } |
1713 virtual int OnItemContext(char *text, int x, int y, void *itemdata) { | 1731 virtual int OnItemContext(std::string text, int x, int y, void *itemdata) { |
1714 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_CONTEXT); | 1732 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_CONTEXT); |
1715 ItemContextConnected = false; | 1733 ItemContextConnected = false; |
1716 return FALSE; | 1734 return FALSE; |
1717 } | 1735 } |
1718 public: | 1736 public: |
1719 #ifdef DW_LAMBDA | 1737 #ifdef DW_LAMBDA |
1720 void ConnectItemSelect(std::function<int(HTREEITEM, char *, void *)> userfunc) | 1738 void ConnectItemSelectC(std::function<int(HTREEITEM, char *, void *)> userfunc) |
1721 { | 1739 { |
1722 _ConnectCItemSelect = userfunc; | 1740 _ConnectCItemSelect = userfunc; |
1723 if(!ItemSelectConnected) { | 1741 if(!ItemSelectConnected) { |
1724 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); | 1742 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); |
1725 ItemSelectConnected = true; | 1743 ItemSelectConnected = true; |
1749 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); | 1767 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); |
1750 ItemSelectConnected = true; | 1768 ItemSelectConnected = true; |
1751 } | 1769 } |
1752 } | 1770 } |
1753 #ifdef DW_LAMBDA | 1771 #ifdef DW_LAMBDA |
1754 void ConnectItemContext(std::function<int(char *, int, int, void *)> userfunc) | 1772 void ConnectItemContextC(std::function<int(char *, int, int, void *)> userfunc) |
1755 { | 1773 { |
1756 _ConnectCItemContext = userfunc; | 1774 _ConnectCItemContext = userfunc; |
1757 if(!ItemContextConnected) { | 1775 if(!ItemContextConnected) { |
1758 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); | 1776 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); |
1759 ItemContextConnected = true; | 1777 ItemContextConnected = true; |
1798 int (*_ConnectCItemEnterOld)(Containers *, char *, void *); | 1816 int (*_ConnectCItemEnterOld)(Containers *, char *, void *); |
1799 int (*_ConnectItemEnterOld)(Containers *, std::string, void *); | 1817 int (*_ConnectItemEnterOld)(Containers *, std::string, void *); |
1800 int (*_ConnectColumnClickOld)(Containers *, int); | 1818 int (*_ConnectColumnClickOld)(Containers *, int); |
1801 static int _OnItemEnter(HWND window, char *text, void *data, void *itemdata) { | 1819 static int _OnItemEnter(HWND window, char *text, void *data, void *itemdata) { |
1802 Containers *classptr = reinterpret_cast<Containers *>(data); | 1820 Containers *classptr = reinterpret_cast<Containers *>(data); |
1821 std::string utf8string = text ? std::string(text) : std::string(); | |
1803 #ifdef DW_LAMBDA | 1822 #ifdef DW_LAMBDA |
1804 if(classptr->_ConnectCItemEnter) | 1823 if(classptr->_ConnectCItemEnter) |
1805 return classptr->_ConnectCItemEnter(text, itemdata); | 1824 return classptr->_ConnectCItemEnter(text, itemdata); |
1806 else if(classptr->_ConnectItemEnter) { | 1825 else if(classptr->_ConnectItemEnter) |
1807 std::string utf8string = text ? std::string(text) : std::string(); | |
1808 return classptr->_ConnectItemEnter(utf8string, itemdata); | 1826 return classptr->_ConnectItemEnter(utf8string, itemdata); |
1809 } | |
1810 #endif | 1827 #endif |
1811 if(classptr->_ConnectCItemEnterOld) | 1828 if(classptr->_ConnectCItemEnterOld) |
1812 return classptr->_ConnectCItemEnterOld(classptr, text, itemdata); | 1829 return classptr->_ConnectCItemEnterOld(classptr, text, itemdata); |
1813 else if(classptr->_ConnectItemEnterOld) { | 1830 else if(classptr->_ConnectItemEnterOld) |
1814 std::string utf8string = text ? std::string(text) : std::string(); | |
1815 return classptr->_ConnectItemEnterOld(classptr, utf8string, itemdata); | 1831 return classptr->_ConnectItemEnterOld(classptr, utf8string, itemdata); |
1816 } | 1832 return classptr->OnItemEnter(utf8string, itemdata); |
1817 return classptr->OnItemEnter(text, itemdata); | |
1818 } | 1833 } |
1819 static int _OnColumnClick(HWND window, int column, void *data) { | 1834 static int _OnColumnClick(HWND window, int column, void *data) { |
1820 Containers *classptr = reinterpret_cast<Containers *>(data); | 1835 Containers *classptr = reinterpret_cast<Containers *>(data); |
1821 #ifdef DW_LAMBDA | 1836 #ifdef DW_LAMBDA |
1822 if(classptr->_ConnectColumnClick) | 1837 if(classptr->_ConnectColumnClick) |
1851 ColumnClickConnected = false; | 1866 ColumnClickConnected = false; |
1852 } | 1867 } |
1853 } | 1868 } |
1854 // Our signal handler functions to be overriden... | 1869 // Our signal handler functions to be overriden... |
1855 // If they are not overridden and an event is generated, remove the unused handler | 1870 // If they are not overridden and an event is generated, remove the unused handler |
1856 virtual int OnItemEnter(char *text, void *itemdata) { | 1871 virtual int OnItemEnter(std::string text, void *itemdata) { |
1857 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_ENTER); | 1872 dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_ENTER); |
1858 ItemEnterConnected = false; | 1873 ItemEnterConnected = false; |
1859 return FALSE; | 1874 return FALSE; |
1860 } | 1875 } |
1861 virtual int OnColumnClick(int column) { | 1876 virtual int OnColumnClick(int column) { |
1877 void DeleteRow(char *title) { dw_container_delete_row(hwnd, title); } | 1892 void DeleteRow(char *title) { dw_container_delete_row(hwnd, title); } |
1878 void DeleteRow(std::string title) { dw_container_delete_row(hwnd, title.c_str()); } | 1893 void DeleteRow(std::string title) { dw_container_delete_row(hwnd, title.c_str()); } |
1879 void DeleteRow(void *data) { dw_container_delete_row_by_data(hwnd, data); } | 1894 void DeleteRow(void *data) { dw_container_delete_row_by_data(hwnd, data); } |
1880 void Insert() { dw_container_insert(hwnd, allocpointer, allocrowcount); } | 1895 void Insert() { dw_container_insert(hwnd, allocpointer, allocrowcount); } |
1881 void Optimize() { dw_container_optimize(hwnd); } | 1896 void Optimize() { dw_container_optimize(hwnd); } |
1882 char *QueryNext(unsigned long flags) { return dw_container_query_next(hwnd, flags); } | 1897 char *QueryCNext(unsigned long flags) { return dw_container_query_next(hwnd, flags); } |
1883 char *QueryStart(unsigned long flags) { return dw_container_query_start(hwnd, flags); } | 1898 char *QueryCStart(unsigned long flags) { return dw_container_query_start(hwnd, flags); } |
1899 std::string QueryNext(unsigned long flags) { | |
1900 char *retval = dw_container_query_next(hwnd, flags); | |
1901 return retval ? std::string(retval) : std::string(); | |
1902 } | |
1903 std::string QueryStart(unsigned long flags) { | |
1904 char *retval = dw_container_query_start(hwnd, flags); | |
1905 return retval ? std::string(retval) : std::string(); | |
1906 } | |
1884 void Scroll(int direction, long rows) { dw_container_scroll(hwnd, direction, rows); } | 1907 void Scroll(int direction, long rows) { dw_container_scroll(hwnd, direction, rows); } |
1885 void SetColumnWidth(int column, int width) { dw_container_set_column_width(hwnd, column, width); } | 1908 void SetColumnWidth(int column, int width) { dw_container_set_column_width(hwnd, column, width); } |
1886 void SetRowData(int row, void *data) { dw_container_set_row_data(allocpointer, row, data); } | 1909 void SetRowData(int row, void *data) { dw_container_set_row_data(allocpointer, row, data); } |
1887 void SetRowTitle(int row, const char *title) { dw_container_set_row_title(allocpointer, row, title); } | 1910 void SetRowTitle(int row, const char *title) { dw_container_set_row_title(allocpointer, row, title); } |
1888 void SetRowTitle(int row, const std::string title) { dw_container_set_row_title(allocpointer, row, title.c_str()); } | 1911 void SetRowTitle(int row, const std::string title) { dw_container_set_row_title(allocpointer, row, title.c_str()); } |
1889 void SetStripe(unsigned long oddcolor, unsigned long evencolor) { dw_container_set_stripe(hwnd, oddcolor, evencolor); } | 1912 void SetStripe(unsigned long oddcolor, unsigned long evencolor) { dw_container_set_stripe(hwnd, oddcolor, evencolor); } |
1890 #ifdef DW_LAMBDA | 1913 #ifdef DW_LAMBDA |
1891 void ConnectItemEnter(std::function<int(char *, void *)> userfunc) | 1914 void ConnectItemEnterC(std::function<int(char *, void *)> userfunc) |
1892 { | 1915 { |
1893 _ConnectCItemEnter = userfunc; | 1916 _ConnectCItemEnter = userfunc; |
1894 if(!ItemEnterConnected) { | 1917 if(!ItemEnterConnected) { |
1895 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); | 1918 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); |
1896 ItemEnterConnected = true; | 1919 ItemEnterConnected = true; |
1969 Filesystem() { SetHWND(dw_container_new(0, FALSE)); SetupObjectView(); SetupContainer(); } | 1992 Filesystem() { SetHWND(dw_container_new(0, FALSE)); SetupObjectView(); SetupContainer(); } |
1970 | 1993 |
1971 // User functions | 1994 // User functions |
1972 int Setup(unsigned long *flags, const char *titles[], int count) { | 1995 int Setup(unsigned long *flags, const char *titles[], int count) { |
1973 int retval = dw_filesystem_setup(hwnd, flags, (char **)titles, count); | 1996 int retval = dw_filesystem_setup(hwnd, flags, (char **)titles, count); |
1997 SetupObjectView(); SetupContainer(); | |
1998 return retval; | |
1999 } | |
2000 int Setup(std::vector<unsigned long> flags, std::vector<std::string> titles) { | |
2001 int count = (int)flags.size(); | |
2002 | |
2003 // Use the smallest of the two lists | |
2004 if(count > titles.size()) { | |
2005 count = (int)titles.size(); | |
2006 } | |
2007 // Convert our vectors into a arrays of unsigned long and C strings | |
2008 const char **ctitles = (const char **)alloca(sizeof(char *) * count); | |
2009 unsigned long *cflags = (unsigned long *)alloca(sizeof(unsigned long) * count); | |
2010 for(int z=0; z<count; z++) { | |
2011 ctitles[z] = titles[z].c_str(); | |
2012 cflags[z] = flags[z]; | |
2013 } | |
2014 int retval = dw_filesystem_setup(hwnd, cflags, (char **)ctitles, count); | |
1974 SetupObjectView(); SetupContainer(); | 2015 SetupObjectView(); SetupContainer(); |
1975 return retval; | 2016 return retval; |
1976 } | 2017 } |
1977 void ChangeFile(int row, const char *filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename, icon); } | 2018 void ChangeFile(int row, const char *filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename, icon); } |
1978 void ChangeFile(int row, std::string filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename.c_str(), icon); } | 2019 void ChangeFile(int row, std::string filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename.c_str(), icon); } |