Mercurial > dwindows
comparison dw.hpp @ 2903:9fd16f694a77
C++: MSVC does not seem to initialize the class fields...
and in DEBUG mode sets it all to a pattern so things crash.
So in Setup*() initialize all our variables to the defaults.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 25 Dec 2022 05:00:32 +0000 |
parents | 761b7a12b079 |
children | 0f5008c05134 |
comparison
equal
deleted
inserted
replaced
2902:cb9e8494f534 | 2903:9fd16f694a77 |
---|---|
133 static int _OnClicked(HWND window, void *data) { | 133 static int _OnClicked(HWND window, void *data) { |
134 if(reinterpret_cast<Clickable *>(data)->_ConnectClicked) | 134 if(reinterpret_cast<Clickable *>(data)->_ConnectClicked) |
135 return reinterpret_cast<Clickable *>(data)->_ConnectClicked(); | 135 return reinterpret_cast<Clickable *>(data)->_ConnectClicked(); |
136 return reinterpret_cast<Clickable *>(data)->OnClicked(); } | 136 return reinterpret_cast<Clickable *>(data)->OnClicked(); } |
137 protected: | 137 protected: |
138 void Setup() { | 138 void Setup() { |
139 _ConnectClicked = 0; | |
139 if(IsOverridden(Clickable::OnClicked, this)) { | 140 if(IsOverridden(Clickable::OnClicked, this)) { |
140 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this); | 141 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this); |
141 ClickedConnected = true; | 142 ClickedConnected = true; |
142 } | 143 } |
143 } | 144 } |
239 std::function<int(int, int)> _ConnectConfigure; | 240 std::function<int(int, int)> _ConnectConfigure; |
240 #else | 241 #else |
241 int (*_ConnectDelete)(); | 242 int (*_ConnectDelete)(); |
242 int (*_ConnectConfigure)(int width, int height); | 243 int (*_ConnectConfigure)(int width, int height); |
243 #endif | 244 #endif |
244 void Setup() { | 245 void Setup() { |
246 _ConnectDelete = 0; | |
247 _ConnectConfigure = 0; | |
248 menu = DW_NULL; | |
245 if(IsOverridden(Window::OnDelete, this)) { | 249 if(IsOverridden(Window::OnDelete, this)) { |
246 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); | 250 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); |
247 DeleteConnected = true; | 251 DeleteConnected = true; |
252 } else { | |
253 DeleteConnected = false; | |
248 } | 254 } |
249 if(IsOverridden(Window::OnConfigure, this)) { | 255 if(IsOverridden(Window::OnConfigure, this)) { |
250 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); | 256 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); |
251 ConfigureConnected = true; | 257 ConfigureConnected = true; |
252 } | 258 } else { |
259 ConfigureConnected = false; | |
260 } | |
253 } | 261 } |
254 static int _OnDelete(HWND window, void *data) { | 262 static int _OnDelete(HWND window, void *data) { |
255 if(reinterpret_cast<Window *>(data)->_ConnectDelete) | 263 if(reinterpret_cast<Window *>(data)->_ConnectDelete) |
256 return reinterpret_cast<Window *>(data)->_ConnectDelete(); | 264 return reinterpret_cast<Window *>(data)->_ConnectDelete(); |
257 return reinterpret_cast<Window *>(data)->OnDelete(); } | 265 return reinterpret_cast<Window *>(data)->OnDelete(); } |
310 { | 318 { |
311 _ConnectDelete = userfunc; | 319 _ConnectDelete = userfunc; |
312 if(!DeleteConnected) { | 320 if(!DeleteConnected) { |
313 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); | 321 dw_signal_connect(hwnd, DW_SIGNAL_DELETE, DW_SIGNAL_FUNC(_OnDelete), this); |
314 DeleteConnected = true; | 322 DeleteConnected = true; |
323 } else { | |
324 DeleteConnected = false; | |
315 } | 325 } |
316 } | 326 } |
317 #ifdef DW_LAMBDA | 327 #ifdef DW_LAMBDA |
318 void ConnectConfigure(std::function<int(int, int)> userfunc) | 328 void ConnectConfigure(std::function<int(int, int)> userfunc) |
319 #else | 329 #else |
322 { | 332 { |
323 _ConnectConfigure = userfunc; | 333 _ConnectConfigure = userfunc; |
324 if(!ConfigureConnected) { | 334 if(!ConfigureConnected) { |
325 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); | 335 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); |
326 ConfigureConnected = true; | 336 ConfigureConnected = true; |
337 } else { | |
338 ConfigureConnected = false; | |
327 } | 339 } |
328 } | 340 } |
329 protected: | 341 protected: |
330 // Our signal handler functions to be overriden... | 342 // Our signal handler functions to be overriden... |
331 // If they are not overridden and an event is generated, remove the unused handler | 343 // If they are not overridden and an event is generated, remove the unused handler |
531 int (*_ConnectKeyPress)(char c, int vk, int state, char *utf8); | 543 int (*_ConnectKeyPress)(char c, int vk, int state, char *utf8); |
532 int (*_ConnectButtonPress)(int x, int y, int buttonmask); | 544 int (*_ConnectButtonPress)(int x, int y, int buttonmask); |
533 int (*_ConnectButtonRelease)(int x, int y, int buttonmask); | 545 int (*_ConnectButtonRelease)(int x, int y, int buttonmask); |
534 int (*_ConnectMotionNotify)(int x, int y, int buttonmask); | 546 int (*_ConnectMotionNotify)(int x, int y, int buttonmask); |
535 #endif | 547 #endif |
536 void Setup() { | 548 void Setup() { |
549 _ConnectExpose = 0; | |
550 _ConnectConfigure = 0; | |
551 _ConnectKeyPress = 0; | |
552 _ConnectButtonPress = 0; | |
553 _ConnectButtonRelease = 0; | |
554 _ConnectMotionNotify = 0; | |
537 if(IsOverridden(Render::OnExpose, this)) { | 555 if(IsOverridden(Render::OnExpose, this)) { |
538 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this); | 556 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this); |
539 ExposeConnected = true; | 557 ExposeConnected = true; |
558 } else { | |
559 ExposeConnected = false; | |
540 } | 560 } |
541 if(IsOverridden(Render::OnConfigure, this)) { | 561 if(IsOverridden(Render::OnConfigure, this)) { |
542 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); | 562 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); |
543 ConfigureConnected = true; | 563 ConfigureConnected = true; |
564 } else { | |
565 ConfigureConnected = false; | |
544 } | 566 } |
545 if(IsOverridden(Render::OnKeyPress, this)) { | 567 if(IsOverridden(Render::OnKeyPress, this)) { |
546 dw_signal_connect(hwnd, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_OnKeyPress), this); | 568 dw_signal_connect(hwnd, DW_SIGNAL_KEY_PRESS, DW_SIGNAL_FUNC(_OnKeyPress), this); |
547 KeyPressConnected = true; | 569 KeyPressConnected = true; |
570 } else { | |
571 KeyPressConnected = false; | |
548 } | 572 } |
549 if(IsOverridden(Render::OnButtonPress, this)) { | 573 if(IsOverridden(Render::OnButtonPress, this)) { |
550 dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_OnButtonPress), this); | 574 dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_PRESS, DW_SIGNAL_FUNC(_OnButtonPress), this); |
551 ButtonPressConnected = true; | 575 ButtonPressConnected = true; |
576 } else { | |
577 ButtonPressConnected = false; | |
552 } | 578 } |
553 if(IsOverridden(Render::OnButtonRelease, this)) { | 579 if(IsOverridden(Render::OnButtonRelease, this)) { |
554 dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_RELEASE, DW_SIGNAL_FUNC(_OnButtonRelease), this); | 580 dw_signal_connect(hwnd, DW_SIGNAL_BUTTON_RELEASE, DW_SIGNAL_FUNC(_OnButtonRelease), this); |
555 ButtonReleaseConnected = true; | 581 ButtonReleaseConnected = true; |
582 } else { | |
583 ButtonReleaseConnected = false; | |
556 } | 584 } |
557 if(IsOverridden(Render::OnMotionNotify, this)) { | 585 if(IsOverridden(Render::OnMotionNotify, this)) { |
558 dw_signal_connect(hwnd, DW_SIGNAL_MOTION_NOTIFY, DW_SIGNAL_FUNC(_OnMotionNotify), this); | 586 dw_signal_connect(hwnd, DW_SIGNAL_MOTION_NOTIFY, DW_SIGNAL_FUNC(_OnMotionNotify), this); |
559 MotionNotifyConnected = true; | 587 MotionNotifyConnected = true; |
588 } else { | |
589 MotionNotifyConnected = false; | |
560 } | 590 } |
561 } | 591 } |
562 static int _OnExpose(HWND window, DWExpose *exp, void *data) { | 592 static int _OnExpose(HWND window, DWExpose *exp, void *data) { |
563 if(reinterpret_cast<Render *>(data)->_ConnectExpose) | 593 if(reinterpret_cast<Render *>(data)->_ConnectExpose) |
564 return reinterpret_cast<Render *>(data)->_ConnectExpose(exp); | 594 return reinterpret_cast<Render *>(data)->_ConnectExpose(exp); |
772 std::function<int(int, char *, void *)> _ConnectResult; | 802 std::function<int(int, char *, void *)> _ConnectResult; |
773 #else | 803 #else |
774 int (*_ConnectChanged)(int status, char *url); | 804 int (*_ConnectChanged)(int status, char *url); |
775 int (*_ConnectResult)(int status, char *result, void *scriptdata); | 805 int (*_ConnectResult)(int status, char *result, void *scriptdata); |
776 #endif | 806 #endif |
777 void Setup() { | 807 void Setup() { |
808 _ConnectChanged = 0; | |
809 _ConnectResult = 0; | |
778 if(IsOverridden(HTML::OnChanged, this)) { | 810 if(IsOverridden(HTML::OnChanged, this)) { |
779 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); | 811 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this); |
780 ChangedConnected = true; | 812 ChangedConnected = true; |
813 } else { | |
814 ChangedConnected = false; | |
781 } | 815 } |
782 if(IsOverridden(HTML::OnResult, this)) { | 816 if(IsOverridden(HTML::OnResult, this)) { |
783 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this); | 817 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this); |
784 ResultConnected = true; | 818 ResultConnected = true; |
785 } | 819 } else { |
820 ResultConnected = false; | |
821 } | |
786 } | 822 } |
787 static int _OnChanged(HWND window, int status, char *url, void *data) { | 823 static int _OnChanged(HWND window, int status, char *url, void *data) { |
788 if(reinterpret_cast<HTML *>(data)->_ConnectChanged) | 824 if(reinterpret_cast<HTML *>(data)->_ConnectChanged) |
789 return reinterpret_cast<HTML *>(data)->_ConnectChanged(status, url); | 825 return reinterpret_cast<HTML *>(data)->_ConnectChanged(status, url); |
790 return reinterpret_cast<HTML *>(data)->OnChanged(status, url); } | 826 return reinterpret_cast<HTML *>(data)->OnChanged(status, url); } |
877 #ifdef DW_LAMBDA | 913 #ifdef DW_LAMBDA |
878 std::function<int(int)> _ConnectListSelect; | 914 std::function<int(int)> _ConnectListSelect; |
879 #else | 915 #else |
880 int (*_ConnectListSelect)(int index); | 916 int (*_ConnectListSelect)(int index); |
881 #endif | 917 #endif |
882 void Setup() { | 918 void Setup() { |
919 _ConnectListSelect = 0; | |
883 if(IsOverridden(ListBoxes::OnListSelect, this)) { | 920 if(IsOverridden(ListBoxes::OnListSelect, this)) { |
884 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this); | 921 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this); |
885 ListSelectConnected = true; | 922 ListSelectConnected = true; |
886 } | 923 } |
887 } | 924 } |
960 if(reinterpret_cast<Ranged *>(data)->_ConnectValueChanged) | 997 if(reinterpret_cast<Ranged *>(data)->_ConnectValueChanged) |
961 return reinterpret_cast<Ranged *>(data)->_ConnectValueChanged(value); | 998 return reinterpret_cast<Ranged *>(data)->_ConnectValueChanged(value); |
962 return reinterpret_cast<Ranged *>(data)->OnValueChanged(value); | 999 return reinterpret_cast<Ranged *>(data)->OnValueChanged(value); |
963 } | 1000 } |
964 protected: | 1001 protected: |
965 void Setup() { | 1002 void Setup() { |
1003 _ConnectValueChanged = 0; | |
966 if(IsOverridden(Ranged::OnValueChanged, this)) { | 1004 if(IsOverridden(Ranged::OnValueChanged, this)) { |
967 dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this); | 1005 dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this); |
968 ValueChangedConnected = true; | 1006 ValueChangedConnected = true; |
1007 } else { | |
1008 ValueChangedConnected = false; | |
969 } | 1009 } |
970 } | 1010 } |
971 // Our signal handler functions to be overriden... | 1011 // Our signal handler functions to be overriden... |
972 // If they are not overridden and an event is generated, remove the unused handler | 1012 // If they are not overridden and an event is generated, remove the unused handler |
973 virtual int OnValueChanged(int value) { | 1013 virtual int OnValueChanged(int value) { |
1074 if(reinterpret_cast<ObjectView *>(data)->_ConnectItemContext) | 1114 if(reinterpret_cast<ObjectView *>(data)->_ConnectItemContext) |
1075 return reinterpret_cast<ObjectView *>(data)->_ConnectItemContext(text, x, y, itemdata); | 1115 return reinterpret_cast<ObjectView *>(data)->_ConnectItemContext(text, x, y, itemdata); |
1076 return reinterpret_cast<ObjectView *>(data)->OnItemContext(text, x, y, itemdata); | 1116 return reinterpret_cast<ObjectView *>(data)->OnItemContext(text, x, y, itemdata); |
1077 } | 1117 } |
1078 protected: | 1118 protected: |
1079 void SetupObjectView() { | 1119 void SetupObjectView() { |
1120 _ConnectItemSelect = 0; | |
1121 _ConnectItemContext = 0; | |
1080 if(IsOverridden(ObjectView::OnItemSelect, this)) { | 1122 if(IsOverridden(ObjectView::OnItemSelect, this)) { |
1081 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); | 1123 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_SELECT, DW_SIGNAL_FUNC(_OnItemSelect), this); |
1082 ItemSelectConnected = true; | 1124 ItemSelectConnected = true; |
1125 } else { | |
1126 ItemSelectConnected = false; | |
1083 } | 1127 } |
1084 if(IsOverridden(ObjectView::OnItemContext, this)) { | 1128 if(IsOverridden(ObjectView::OnItemContext, this)) { |
1085 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); | 1129 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_CONTEXT, DW_SIGNAL_FUNC(_OnItemContext), this); |
1086 ItemContextConnected = true; | 1130 ItemContextConnected = true; |
1131 } else { | |
1132 ItemContextConnected = false; | |
1087 } | 1133 } |
1088 } | 1134 } |
1089 // Our signal handler functions to be overriden... | 1135 // Our signal handler functions to be overriden... |
1090 // If they are not overridden and an event is generated, remove the unused handler | 1136 // If they are not overridden and an event is generated, remove the unused handler |
1091 virtual int OnItemSelect(HTREEITEM item, char *text, void *itemdata) { | 1137 virtual int OnItemSelect(HTREEITEM item, char *text, void *itemdata) { |
1147 return reinterpret_cast<Containers *>(data)->OnColumnClick(column); | 1193 return reinterpret_cast<Containers *>(data)->OnColumnClick(column); |
1148 } | 1194 } |
1149 protected: | 1195 protected: |
1150 void *allocpointer; | 1196 void *allocpointer; |
1151 int allocrowcount; | 1197 int allocrowcount; |
1152 void SetupContainer() { | 1198 void SetupContainer() { |
1199 _ConnectItemEnter = 0; | |
1200 _ConnectColumnClick = 0; | |
1153 if(IsOverridden(Container::OnItemEnter, this)) { | 1201 if(IsOverridden(Container::OnItemEnter, this)) { |
1154 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); | 1202 dw_signal_connect(hwnd, DW_SIGNAL_ITEM_ENTER, DW_SIGNAL_FUNC(_OnItemEnter), this); |
1155 ItemEnterConnected = true; | 1203 ItemEnterConnected = true; |
1204 } else { | |
1205 ItemEnterConnected = false; | |
1156 } | 1206 } |
1157 if(IsOverridden(Container::OnColumnClick, this)) { | 1207 if(IsOverridden(Container::OnColumnClick, this)) { |
1158 dw_signal_connect(hwnd, DW_SIGNAL_COLUMN_CLICK, DW_SIGNAL_FUNC(_OnColumnClick), this); | 1208 dw_signal_connect(hwnd, DW_SIGNAL_COLUMN_CLICK, DW_SIGNAL_FUNC(_OnColumnClick), this); |
1159 ColumnClickConnected = true; | 1209 ColumnClickConnected = true; |
1210 } else { | |
1211 ColumnClickConnected = false; | |
1160 } | 1212 } |
1161 } | 1213 } |
1162 // Our signal handler functions to be overriden... | 1214 // Our signal handler functions to be overriden... |
1163 // If they are not overridden and an event is generated, remove the unused handler | 1215 // If they are not overridden and an event is generated, remove the unused handler |
1164 virtual int OnItemEnter(char *text) { | 1216 virtual int OnItemEnter(char *text) { |
1262 static int _OnTreeExpand(HWND window, HTREEITEM item, void *data) { | 1314 static int _OnTreeExpand(HWND window, HTREEITEM item, void *data) { |
1263 if(reinterpret_cast<Tree *>(data)->_ConnectTreeExpand) | 1315 if(reinterpret_cast<Tree *>(data)->_ConnectTreeExpand) |
1264 return reinterpret_cast<Tree *>(data)->_ConnectTreeExpand(item); | 1316 return reinterpret_cast<Tree *>(data)->_ConnectTreeExpand(item); |
1265 return reinterpret_cast<Tree *>(data)->OnTreeExpand(item); | 1317 return reinterpret_cast<Tree *>(data)->OnTreeExpand(item); |
1266 } | 1318 } |
1267 void SetupTree() { | 1319 void SetupTree() { |
1320 _ConnectTreeExpand = 0; | |
1268 if(IsOverridden(Tree::OnTreeExpand, this)) { | 1321 if(IsOverridden(Tree::OnTreeExpand, this)) { |
1269 dw_signal_connect(hwnd, DW_SIGNAL_TREE_EXPAND, DW_SIGNAL_FUNC(_OnTreeExpand), this); | 1322 dw_signal_connect(hwnd, DW_SIGNAL_TREE_EXPAND, DW_SIGNAL_FUNC(_OnTreeExpand), this); |
1270 TreeExpandConnected = true; | 1323 TreeExpandConnected = true; |
1324 } else { | |
1325 TreeExpandConnected = false; | |
1271 } | 1326 } |
1272 } | 1327 } |
1273 protected: | 1328 protected: |
1274 // Our signal handler functions to be overriden... | 1329 // Our signal handler functions to be overriden... |
1275 // If they are not overridden and an event is generated, remove the unused handler | 1330 // If they are not overridden and an event is generated, remove the unused handler |