# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1672535695 0 # Node ID 60e90b783cb1d8a93a535f599238fec57afdc9b3 # Parent ebbc5b16899eb38ee60d217cca119ce051be6bb9 C++: ListBox and ComboBoxes need to call Setup() to configure the handlers. diff -r ebbc5b16899e -r 60e90b783cb1 dw.hpp --- a/dw.hpp Sun Jan 01 00:23:39 2023 +0000 +++ b/dw.hpp Sun Jan 01 01:14:55 2023 +0000 @@ -1,7 +1,6 @@ -/* Dynamic Windows C++ Language Bindings - * Copyright 2022 Brian Smith - * Recommends a C++11 compatible compiler. - */ +// Dynamic Windows C++ Language Bindings +// Copyright 2022 Brian Smith +// Recommends a C++11 compatible compiler. #ifndef _HPP_DW #define _HPP_DW @@ -1125,16 +1124,6 @@ std::function _ConnectListSelect; #endif int (*_ConnectListSelectOld)(ListBoxes *, unsigned 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) { ListBoxes *classptr = reinterpret_cast(data); #ifdef DW_LAMBDA @@ -1178,6 +1167,16 @@ } } protected: + 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; + } + } // Our signal handler functions to be overriden... // If they are not overridden and an event is generated, remove the unused handler virtual int OnListSelect(unsigned int index) { @@ -1191,20 +1190,20 @@ { public: // Constructors - ComboBox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); } - ComboBox(unsigned long id) { SetHWND(dw_combobox_new("", id)); } - ComboBox(const char *text) { SetHWND(dw_combobox_new(text, 0)); } - ComboBox() { SetHWND(dw_combobox_new("", 0)); } + ComboBox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); Setup(); } + ComboBox(unsigned long id) { SetHWND(dw_combobox_new("", id)); Setup(); } + ComboBox(const char *text) { SetHWND(dw_combobox_new(text, 0)); Setup(); } + ComboBox() { SetHWND(dw_combobox_new("", 0)); Setup(); } }; class ListBox : public ListBoxes { public: // Constructors - ListBox(unsigned long id, int multi) { SetHWND(dw_listbox_new(id, multi)); } - ListBox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); } - ListBox(int multi) { SetHWND(dw_listbox_new(0, multi)); } - ListBox() { SetHWND(dw_listbox_new(0, FALSE)); } + ListBox(unsigned long id, int multi) { SetHWND(dw_listbox_new(id, multi)); Setup(); } + ListBox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); Setup(); } + ListBox(int multi) { SetHWND(dw_listbox_new(0, multi)); Setup(); } + ListBox() { SetHWND(dw_listbox_new(0, FALSE)); Setup(); } }; // Base class for several ranged type widgets @@ -2137,5 +2136,5 @@ // Static singleton reference declared outside of the class App* App::_app = DW_NULL; -} /* namespace DW */ +} // namespace DW #endif diff -r ebbc5b16899e -r 60e90b783cb1 dwtestoo.cpp --- a/dwtestoo.cpp Sun Jan 01 00:23:39 2023 +0000 +++ b/dwtestoo.cpp Sun Jan 01 01:14:55 2023 +0000 @@ -211,8 +211,7 @@ else return "none"; } - char *ReadFile(char *filename) - { + char *ReadFile(char *filename) { char *errors = NULL; FILE *fp=NULL; #ifdef __ANDROID__ @@ -263,8 +262,7 @@ } // When hpm is not NULL we are printing.. so handle things differently - void DrawFile(int row, int col, int nrows, int fheight, DW::Pixmap *hpm) - { + void DrawFile(int row, int col, int nrows, int fheight, DW::Pixmap *hpm) { DW::Pixmap *pixmap = hpm ? hpm : pixmap2; char buf[16] = {0}; int i,y,fileline; @@ -294,8 +292,7 @@ } // When hpm is not NULL we are printing.. so handle things differently - void DrawShapes(int direct, DW::Pixmap *hpm) - { + void DrawShapes(int direct, DW::Pixmap *hpm) { DW::Pixmap *pixmap = hpm ? hpm : pixmap2; int width = (int)pixmap->GetWidth(), height = (int)pixmap->GetHeight(); int x[7] = { 20, 180, 180, 230, 180, 180, 20 }; @@ -332,8 +329,7 @@ } } - void UpdateRender(void) - { + void UpdateRender(void) { switch(render_type) { case SHAPES_DOUBLE_BUFFERED: @@ -361,8 +357,7 @@ render2->Redraw(); } - DW::Menu *ItemContextMenu(DW::StatusText *status_text, const char *text) - { + DW::Menu *ItemContextMenu(DW::StatusText *status_text, const char *text) { DW::Menu *menu = new DW::Menu(); DW::Menu *submenu = new DW::Menu(); DW::MenuItem *menuitem = submenu->AppendItem("File", 0L, TRUE); @@ -394,8 +389,7 @@ return menu; } - DW::ComboBox *ColorCombobox(void) - { + DW::ComboBox *ColorCombobox(void) { DW::ComboBox *combobox = new DW::ComboBox("DW_CLR_DEFAULT"); combobox->Append("DW_CLR_DEFAULT"); @@ -418,8 +412,7 @@ return combobox; } - unsigned long ComboboxColor(const char *colortext) - { + unsigned long ComboboxColor(const char *colortext) { unsigned long color = DW_CLR_DEFAULT; if(strcmp(colortext, "DW_CLR_BLACK") == 0) @@ -458,8 +451,7 @@ return color; } - void MLESetFont(DW::MLE *mle, int fontsize, char *fontname) - { + void MLESetFont(DW::MLE *mle, int fontsize, char *fontname) { char font[101] = {0}; if(fontname) @@ -468,8 +460,7 @@ } // Thread and Event functions - void UpdateMLE(DW::MLE *threadmle, const char *text, DW::Mutex *mutex) - { + void UpdateMLE(DW::MLE *threadmle, const char *text, DW::Mutex *mutex) { static unsigned int pos = 0; // Protect pos from being changed by different threads @@ -648,8 +639,7 @@ } // Notebook page 1 - void CreateInput(DW::Box *notebookbox) - { + void CreateInput(DW::Box *notebookbox) { DW::Box *lbbox = new DW::Box(DW_VERT, 10); notebookbox->PackStart(lbbox, 150, 70, TRUE, TRUE, 0); @@ -1170,8 +1160,7 @@ } // Notebook page 3 - void CreateTree(DW::Box *notebookbox) - { + void CreateTree(DW::Box *notebookbox) { // create a box to pack into the notebook page DW::ListBox *listbox = new DW::ListBox(TRUE); notebookbox->PackStart(listbox, 500, 200, TRUE, TRUE, 0); @@ -1234,8 +1223,7 @@ } // Page 4 - Container - void CreateContainer(DW::Box *notebookbox) - { + void CreateContainer(DW::Box *notebookbox) { char buffer[101] = {0}; CTIME time; CDATE date; @@ -1496,8 +1484,7 @@ } // Page 5 - Buttons - void CreateButtons(DW::Box *notebookbox) - { + void CreateButtons(DW::Box *notebookbox) { // create a box to pack into the notebook page DW::Box *buttonsbox = new DW::Box(DW_VERT, 2); notebookbox->PackStart(buttonsbox, 25, 200, TRUE, TRUE, 0); @@ -1658,8 +1645,7 @@ } // Page 6 - HTML - void CreateHTML(DW::Box *notebookbox) - { + void CreateHTML(DW::Box *notebookbox) { DW::HTML *rawhtml = new DW::HTML(); if(rawhtml && rawhtml->GetHWND()) { @@ -1757,8 +1743,7 @@ } // Page 7 - ScrollBox - void CreateScrollBox(DW::Box *notebookbox) - { + void CreateScrollBox(DW::Box *notebookbox) { char buf[101] = {0}; // create a box to pack into the notebook page @@ -1789,8 +1774,7 @@ } // Page 8 - Thread and Event - void CreateThreadEvent(DW::Box *notebookbox) - { + void CreateThreadEvent(DW::Box *notebookbox) { // create a box to pack into the notebook page DW::Box *tmpbox = new DW::Box(DW_VERT, 0); notebookbox->PackStart(tmpbox, 0, 0, TRUE, TRUE, 1);