From 77c1116497e29142c42de27221e0d4e22a60fdf5 Mon Sep 17 00:00:00 2001 From: lcgamboa Date: Sun, 4 Feb 2024 21:42:08 -0300 Subject: [PATCH] chg: Code refactor - Remove direct use of CFileDialog on boards !minor --- src/boards/board_C3_DevKitC.cc | 78 ++++++++--------- src/boards/board_DevKitC.cc | 78 ++++++++--------- src/lib/board.h | 7 +- src/lib/picsimlab.cc | 10 +-- src/lib/picsimlab.h | 8 +- src/lib/spareparts.cc | 21 +++-- src/lib/spareparts.h | 10 +-- src/lib/types.h | 12 +++ src/parts/other_MI2C_24CXXX.cc | 47 ++++++----- src/parts/other_sdcard.cc | 21 +++-- src/parts/virtual_VCD_Play.cc | 18 ++-- src/parts/virtual_vterm.cc | 118 +++++++++++++------------- src/picsimlab1.cc | 26 +++++- src/picsimlab1.h | 4 +- src/picsimlab1_d.cc | 2 + src/picsimlab5.cc | 150 ++++++++++++++++++--------------- src/picsimlab5.h | 4 +- src/picsimlab5_d.cc | 5 +- 18 files changed, 341 insertions(+), 278 deletions(-) diff --git a/src/boards/board_C3_DevKitC.cc b/src/boards/board_C3_DevKitC.cc index 9c150364..31712ff8 100644 --- a/src/boards/board_C3_DevKitC.cc +++ b/src/boards/board_C3_DevKitC.cc @@ -263,7 +263,7 @@ cboard_C3_DevKitC::cboard_C3_DevKitC(void) { PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_ADD, (void*)"Config Qemu"); - wconfigId = PICSimLab.ExtraWindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); + wconfigId = PICSimLab.WindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); } // Destructor called once on board destruction @@ -271,7 +271,7 @@ cboard_C3_DevKitC::cboard_C3_DevKitC(void) { cboard_C3_DevKitC::~cboard_C3_DevKitC(void) { PICSimLab.UpdateGUI(MIPS, GT_COMBO, GA_DEL, NULL); PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_DEL, NULL); - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL); bitbang_pwm_end(&pwm_out); } @@ -672,7 +672,7 @@ void cboard_C3_DevKitC::board_ButtonEvent(const char* controlname, uint button, "/config.lxrad"; if (lxFileExists(fname)) { - if (PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { + if (PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { char buff[2048]; char line[1024]; strncpy(buff, (const char*)cmdline.c_str(), 2047); @@ -684,17 +684,17 @@ void cboard_C3_DevKitC::board_ButtonEvent(const char* controlname, uint button, if (!line[0]) { strcpy(line, arg); if (line[0] != '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); line[0] = 0; } } else { if (arg[0] == '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); strcpy(line, arg); } else { strcat(line, " "); strcat(line, arg); - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); line[0] = 0; } } @@ -711,70 +711,70 @@ void cboard_C3_DevKitC::board_ButtonEvent(const char* controlname, uint button, if (!line[0]) { strcpy(line, arg); if (line[0] != '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); line[0] = 0; } } else { if (arg[0] == '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); strcpy(line, arg); } else { strcat(line, " "); strcat(line, arg); - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); line[0] = 0; } } arg = strtok(NULL, " \n"); } } else { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTCLEAR, NULL); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTCLEAR, NULL); } - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableWifi).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXSETCHECK, - std::to_string(ConfDisableWdt).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXSETCHECK, - std::to_string(use_cmdline_extra).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableEthernet).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableSerial).c_str()); - - PICSimLab.ExtraWindowCmd(wconfigId, "button1", PWA_BUTTONBOARDEV, "1"); - PICSimLab.ExtraWindowCmd(wconfigId, "button2", PWA_BUTTONBOARDEV, "1"); - - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_SETX, - std::to_string(PICSimLab.GetWindow()->GetX() + 50).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_SETY, - std::to_string(PICSimLab.GetWindow()->GetY() + 50).c_str()); - - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWSHOWEX, NULL); + PICSimLab.WindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableWifi).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXSETCHECK, + std::to_string(ConfDisableWdt).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXSETCHECK, + std::to_string(use_cmdline_extra).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableEthernet).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableSerial).c_str()); + + PICSimLab.WindowCmd(wconfigId, "button1", PWA_BUTTONBOARDEV, "1"); + PICSimLab.WindowCmd(wconfigId, "button2", PWA_BUTTONBOARDEV, "1"); + + PICSimLab.WindowCmd(wconfigId, NULL, PWA_SETX, + std::to_string(PICSimLab.GetWindow()->GetX() + 50).c_str()); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_SETY, + std::to_string(PICSimLab.GetWindow()->GetY() + 50).c_str()); + + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWSHOWEX, NULL); } } else { PICSimLab.RegisterError("File " + fname + " not found!"); } } else if (!strcmp(controlname, "button1")) { - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableWifi); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXGETCHECK, NULL, &ConfDisableWdt); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXGETCHECK, NULL, &use_cmdline_extra); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableEthernet); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableSerial); + PICSimLab.WindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableWifi); + PICSimLab.WindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXGETCHECK, NULL, &ConfDisableWdt); + PICSimLab.WindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXGETCHECK, NULL, &use_cmdline_extra); + PICSimLab.WindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableEthernet); + PICSimLab.WindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableSerial); cmdline_extra = ""; unsigned int lc; - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTGETLINECOUNT, NULL, &lc); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTGETLINECOUNT, NULL, &lc); for (unsigned int i = 0; i < lc; i++) { char buff[256]; - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTGETLINE, std::to_string(i).c_str(), buff); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTGETLINE, std::to_string(i).c_str(), buff); cmdline_extra += buff; cmdline_extra += " "; } - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); PICSimLab.EndSimulation(); } else if (!strcmp(controlname, "button2")) { - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); } } diff --git a/src/boards/board_DevKitC.cc b/src/boards/board_DevKitC.cc index a53cfd00..1c59f340 100644 --- a/src/boards/board_DevKitC.cc +++ b/src/boards/board_DevKitC.cc @@ -322,7 +322,7 @@ cboard_DevKitC::cboard_DevKitC(void) { PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_ADD, (void*)"Config Qemu"); - wconfigId = PICSimLab.ExtraWindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); + wconfigId = PICSimLab.WindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); } // Destructor called once on board destruction @@ -330,7 +330,7 @@ cboard_DevKitC::cboard_DevKitC(void) { cboard_DevKitC::~cboard_DevKitC(void) { PICSimLab.UpdateGUI(MIPS, GT_COMBO, GA_DEL, NULL); PICSimLab.UpdateGUI(CONFIG, GT_BUTTON, GA_DEL, NULL); - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWDESTROY, NULL); bitbang_pwm_end(&pwm_out); } @@ -728,7 +728,7 @@ void cboard_DevKitC::board_ButtonEvent(const char* controlname, uint button, uin "/config.lxrad"; if (lxFileExists(fname)) { - if (PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { + if (PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { char buff[2048]; char line[1024]; strncpy(buff, (const char*)cmdline.c_str(), 2047); @@ -740,17 +740,17 @@ void cboard_DevKitC::board_ButtonEvent(const char* controlname, uint button, uin if (!line[0]) { strcpy(line, arg); if (line[0] != '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); line[0] = 0; } } else { if (arg[0] == '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); strcpy(line, arg); } else { strcat(line, " "); strcat(line, arg); - PICSimLab.ExtraWindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text1", PWA_TEXTADDLINE, line); line[0] = 0; } } @@ -767,70 +767,70 @@ void cboard_DevKitC::board_ButtonEvent(const char* controlname, uint button, uin if (!line[0]) { strcpy(line, arg); if (line[0] != '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); line[0] = 0; } } else { if (arg[0] == '-') { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); strcpy(line, arg); } else { strcat(line, " "); strcat(line, arg); - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTADDLINE, line); line[0] = 0; } } arg = strtok(NULL, " \n"); } } else { - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTCLEAR, NULL); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTCLEAR, NULL); } - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableWifi).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXSETCHECK, - std::to_string(ConfDisableWdt).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXSETCHECK, - std::to_string(use_cmdline_extra).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableEthernet).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXSETCHECK, - std::to_string(ConfEnableSerial).c_str()); - - PICSimLab.ExtraWindowCmd(wconfigId, "button1", PWA_BUTTONBOARDEV, "1"); - PICSimLab.ExtraWindowCmd(wconfigId, "button2", PWA_BUTTONBOARDEV, "1"); - - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_SETX, - std::to_string(PICSimLab.GetWindow()->GetX() + 50).c_str()); - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_SETY, - std::to_string(PICSimLab.GetWindow()->GetY() + 50).c_str()); - - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWSHOWEX, NULL); + PICSimLab.WindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableWifi).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXSETCHECK, + std::to_string(ConfDisableWdt).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXSETCHECK, + std::to_string(use_cmdline_extra).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableEthernet).c_str()); + PICSimLab.WindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXSETCHECK, + std::to_string(ConfEnableSerial).c_str()); + + PICSimLab.WindowCmd(wconfigId, "button1", PWA_BUTTONBOARDEV, "1"); + PICSimLab.WindowCmd(wconfigId, "button2", PWA_BUTTONBOARDEV, "1"); + + PICSimLab.WindowCmd(wconfigId, NULL, PWA_SETX, + std::to_string(PICSimLab.GetWindow()->GetX() + 50).c_str()); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_SETY, + std::to_string(PICSimLab.GetWindow()->GetY() + 50).c_str()); + + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWSHOWEX, NULL); } } else { PICSimLab.RegisterError("File " + fname + " not found!"); } } else if (!strcmp(controlname, "button1")) { - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableWifi); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXGETCHECK, NULL, &ConfDisableWdt); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXGETCHECK, NULL, &use_cmdline_extra); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableEthernet); - PICSimLab.ExtraWindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableSerial); + PICSimLab.WindowCmd(wconfigId, "checkbox1", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableWifi); + PICSimLab.WindowCmd(wconfigId, "checkbox2", PWA_CHECKBOXGETCHECK, NULL, &ConfDisableWdt); + PICSimLab.WindowCmd(wconfigId, "checkbox3", PWA_CHECKBOXGETCHECK, NULL, &use_cmdline_extra); + PICSimLab.WindowCmd(wconfigId, "checkbox4", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableEthernet); + PICSimLab.WindowCmd(wconfigId, "checkbox5", PWA_CHECKBOXGETCHECK, NULL, &ConfEnableSerial); cmdline_extra = ""; unsigned int lc; - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTGETLINECOUNT, NULL, &lc); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTGETLINECOUNT, NULL, &lc); for (unsigned int i = 0; i < lc; i++) { char buff[256]; - PICSimLab.ExtraWindowCmd(wconfigId, "text2", PWA_TEXTGETLINE, std::to_string(i).c_str(), buff); + PICSimLab.WindowCmd(wconfigId, "text2", PWA_TEXTGETLINE, std::to_string(i).c_str(), buff); cmdline_extra += buff; cmdline_extra += " "; } - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); PICSimLab.EndSimulation(); } else if (!strcmp(controlname, "button2")) { - PICSimLab.ExtraWindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); + PICSimLab.WindowCmd(wconfigId, NULL, PWA_WINDOWHIDEEX, NULL); } } diff --git a/src/lib/board.h b/src/lib/board.h index b0df5a8b..2a6a8f98 100644 --- a/src/lib/board.h +++ b/src/lib/board.h @@ -33,17 +33,14 @@ #include #include -/* class CControl; class CWindow; -class CPWindow; class CThread; -class CFileDialog; class CToggleButton; class lxMutex; class lxCondition; -*/ -#include //FIXME remove lxrad + +// #include //FIXME remove lxrad #define INCOMPLETE \ printf("Incomplete: %s -> %s :%i\n", __func__, __FILE__, __LINE__); \ diff --git a/src/lib/picsimlab.cc b/src/lib/picsimlab.cc index eb73524c..312a2e2f 100644 --- a/src/lib/picsimlab.cc +++ b/src/lib/picsimlab.cc @@ -95,7 +95,7 @@ CPICSimLab::CPICSimLab() { OnUpdateGUI = NULL; OnConfigMenuGUI = NULL; OnCanvasCmd = NULL; - OnExtraWindowCmd = NULL; + OnWindowCmd = NULL; } void CPICSimLab::Init(CWindow* w) { @@ -1221,10 +1221,10 @@ void* CPICSimLab::UpdateGUI(const int id, const PICSimlabGUIType type, const PIC return NULL; } -int CPICSimLab::ExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff) { - if (PICSimLab.OnExtraWindowCmd) { - return (*PICSimLab.OnExtraWindowCmd)(id, ControlName, action, Value, ReturnBuff); +int CPICSimLab::WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff) { + if (PICSimLab.OnWindowCmd) { + return (*PICSimLab.OnWindowCmd)(id, ControlName, action, Value, ReturnBuff); } return -1; } \ No newline at end of file diff --git a/src/lib/picsimlab.h b/src/lib/picsimlab.h index f4779bc2..be75bfe3 100644 --- a/src/lib/picsimlab.h +++ b/src/lib/picsimlab.h @@ -255,8 +255,8 @@ class CPICSimLab { static int CanvasCmd(const CanvasCmd_t cmd); - static int ExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff = NULL); + static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff = NULL); #ifndef _NOTHREAD lxCondition* cpu_cond; @@ -284,8 +284,8 @@ class CPICSimLab { void* (*OnUpdateGUI)(const int id, const PICSimlabGUIType type, const PICSimlabGUIAction action, const void* arg); void (*OnConfigMenuGUI)(const PICSimlabGUIMenu type); int (*OnCanvasCmd)(const CanvasCmd_t cmd); - int (*OnExtraWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff); + int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff); private: void StartRControl(void); diff --git a/src/lib/spareparts.cc b/src/lib/spareparts.cc index 16ee736d..763bca6f 100644 --- a/src/lib/spareparts.cc +++ b/src/lib/spareparts.cc @@ -46,14 +46,11 @@ CSpareParts::CSpareParts() { PartOnDraw = -1; OnCanvasCmd = NULL; - OnExtraWindowCmd = NULL; + OnWindowCmd = NULL; } void CSpareParts::Init(CWindow* win) { Window = win; - if (Window) { - filedialog = (CFileDialog*)win->GetChildByName("filedialog1"); - } } void CSpareParts::UpdateAll(const int force) { @@ -662,7 +659,9 @@ bool CSpareParts::SaveConfig(std::string fname) { void CSpareParts::Setfdtype(int value) { fdtype = value; - oldfname = filedialog->GetFileName(); + char buff[512]; + WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETFNAME, NULL, buff); + oldfname = buff; } void CSpareParts::SetfdOldFilename(const std::string ofn) { @@ -678,16 +677,16 @@ int CSpareParts::CanvasCmd(const CanvasCmd_t cmd) { int CSpareParts::WPropCmd(const char* ControlName, const PICSimLabWindowAction action, const char* Value, void* ReturnBuff) { - if (SpareParts.OnExtraWindowCmd) { - return (*SpareParts.OnExtraWindowCmd)(0, ControlName, action, Value, ReturnBuff); + if (SpareParts.OnWindowCmd) { + return (*SpareParts.OnWindowCmd)(PW_WPROP, ControlName, action, Value, ReturnBuff); } return -1; } -int CSpareParts::ExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff) { - if (SpareParts.OnExtraWindowCmd) { - return (*SpareParts.OnExtraWindowCmd)(id, ControlName, action, Value, ReturnBuff); +int CSpareParts::WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff) { + if (SpareParts.OnWindowCmd) { + return (*SpareParts.OnWindowCmd)(id, ControlName, action, Value, ReturnBuff); } return -1; } \ No newline at end of file diff --git a/src/lib/spareparts.h b/src/lib/spareparts.h index 0eba424d..bb26d495 100644 --- a/src/lib/spareparts.h +++ b/src/lib/spareparts.h @@ -93,7 +93,6 @@ class CSpareParts { float GetScale(void) { return scale; }; void SetScale(float s) { scale = s; }; CWindow* GetWindow(void) { return Window; } - CFileDialog* GetFileDialog(void) { return filedialog; } void Reset(void); void Setfdtype(int value); @@ -119,19 +118,18 @@ class CSpareParts { static int WPropCmd(const char* ControlName, const PICSimLabWindowAction action, const char* Value, void* ReturnBuff = NULL); - static int ExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff = NULL); + static int WindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff = NULL); int (*OnCanvasCmd)(const CanvasCmd_t cmd); - int (*OnExtraWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff); + int (*OnWindowCmd)(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff); private: float scale; board* pboard; CWindow* Window; - CFileDialog* filedialog; std::string PinNames[256]; std::string PinAlias[256]; std::string alias_fname; diff --git a/src/lib/types.h b/src/lib/types.h index 39e8a710..3831f9ce 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -94,7 +94,19 @@ enum PICSimLabWindowAction { PWA_BUTTONPARTEV, PWA_BUTTONBOARDEV, + PWA_FILEDIALOGGETFNAME, + PWA_FILEDIALOGSETFNAME, + PWA_FILEDIALOGSETFILTER, + PWA_FILEDIALOGSETTYPE, + PWA_FILEDIALOGRUN, + PWA_FILEDIALOGGETTYPE, + PWA_LAST, }; +enum PICSimLabWindows { + PW_MAIN = 0, + PW_WPROP, +}; + #endif // TYPES_H \ No newline at end of file diff --git a/src/parts/other_MI2C_24CXXX.cc b/src/parts/other_MI2C_24CXXX.cc index 3b4ca7de..cd6fe980 100644 --- a/src/parts/other_MI2C_24CXXX.cc +++ b/src/parts/other_MI2C_24CXXX.cc @@ -274,18 +274,22 @@ void cpart_MI2C_24CXXX::Process(void) { void cpart_MI2C_24CXXX::OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) { switch (inputId) { case I_LOAD: - SpareParts.GetFileDialog()->SetType(lxFD_OPEN | lxFD_CHANGE_DIR); - SpareParts.GetFileDialog()->SetFilter("PICSimLab Binary File (*.bin)|*.bin"); - SpareParts.GetFileDialog()->SetFileName("untitled.bin"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETTYPE, + std::to_string(lxFD_OPEN | lxFD_CHANGE_DIR).c_str()); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFILTER, + "PICSimLab Binary File (*.bin)|*.bin"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, "untitled.bin"); SpareParts.Setfdtype(id); - SpareParts.GetFileDialog()->Run(); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGRUN, NULL); break; case I_SAVE: - SpareParts.GetFileDialog()->SetType(lxFD_SAVE | lxFD_CHANGE_DIR); - SpareParts.GetFileDialog()->SetFilter("PICSimLab Binary File (*.bin)|*.bin"); - SpareParts.GetFileDialog()->SetFileName("untitled.bin"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETTYPE, + std::to_string(lxFD_SAVE | lxFD_CHANGE_DIR).c_str()); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFILTER, + "PICSimLab Binary File (*.bin)|*.bin"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, "untitled.bin"); SpareParts.Setfdtype(id); - SpareParts.GetFileDialog()->Run(); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGRUN, NULL); break; case I_VIEW: FILE* fout; @@ -332,34 +336,37 @@ void cpart_MI2C_24CXXX::OnMouseButtonPress(uint inputId, uint button, uint x, ui void cpart_MI2C_24CXXX::filedialog_EvOnClose(int retId) { if (retId) { - if ((SpareParts.GetFileDialog()->GetType() == (lxFD_SAVE | lxFD_CHANGE_DIR))) { - if (lxFileExists(SpareParts.GetFileDialog()->GetFileName())) { - if (!Dialog_sz(std::string("Overwriting file: ") + - ((const char*)basename(SpareParts.GetFileDialog()->GetFileName()).c_str()) + "?", - 400, 200)) + int type; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETTYPE, NULL, &type); + if ((type == (lxFD_OPEN | lxFD_CHANGE_DIR))) { + char buff[256]; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETFNAME, NULL, buff); + if (lxFileExists(buff)) { + if (!Dialog_sz(std::string("Overwriting file: ") + ((const char*)basename(buff)) + "?", 400, 200)) return; } FILE* fout; - fout = fopen_UTF8(SpareParts.GetFileDialog()->GetFileName(), "wb"); + fout = fopen_UTF8(buff, "wb"); if (fout) { fwrite(mi2c.data, mi2c.SIZE, 1, fout); fclose(fout); - strncpy(f_mi2c_name, SpareParts.GetFileDialog()->GetFileName(), 199); + strncpy(f_mi2c_name, buff, 199); } else { - printf("Error saving to file: %s \n", (const char*)SpareParts.GetFileDialog()->GetFileName().c_str()); + printf("Error saving to file: %s \n", (const char*)buff); } } - if ((SpareParts.GetFileDialog()->GetType() == (lxFD_OPEN | lxFD_CHANGE_DIR))) { + if (type == (lxFD_OPEN | lxFD_CHANGE_DIR)) { FILE* fout; - fout = fopen_UTF8(SpareParts.GetFileDialog()->GetFileName(), "rb"); + char buff[256]; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETFNAME, NULL, buff); + fout = fopen_UTF8(buff, "rb"); if (fout) { fread(mi2c.data, mi2c.SIZE, 1, fout); fclose(fout); } else { - printf("Error loading from file: %s \n", - (const char*)SpareParts.GetFileDialog()->GetFileName().c_str()); + printf("Error loading from file: %s \n", buff); } } } diff --git a/src/parts/other_sdcard.cc b/src/parts/other_sdcard.cc index 9a4211d6..a5fd2bb8 100644 --- a/src/parts/other_sdcard.cc +++ b/src/parts/other_sdcard.cc @@ -234,24 +234,29 @@ void cpart_SDCard::Process(void) { void cpart_SDCard::OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) { switch (inputId) { case I_CONN: - SpareParts.GetFileDialog()->SetType(lxFD_OPEN | lxFD_CHANGE_DIR); - SpareParts.GetFileDialog()->SetFilter("SD Card image (*.img)|*.img"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETTYPE, + std::to_string(lxFD_OPEN | lxFD_CHANGE_DIR).c_str()); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFILTER, "SD Card image (*.img)|*.img"); if (sdcard_fname[0] == '*') { - SpareParts.GetFileDialog()->SetFileName("untitled.img"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, "untitled.img"); } else { - SpareParts.GetFileDialog()->SetFileName(sdcard_fname); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, sdcard_fname); } SpareParts.Setfdtype(id); - SpareParts.GetFileDialog()->Run(); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGRUN, NULL); break; } } void cpart_SDCard::filedialog_EvOnClose(int retId) { if (retId) { - if ((SpareParts.GetFileDialog()->GetType() == (lxFD_OPEN | lxFD_CHANGE_DIR))) { - if (lxFileExists(SpareParts.GetFileDialog()->GetFileName())) { - strncpy(sdcard_fname, SpareParts.GetFileDialog()->GetFileName().c_str(), 199); + int type; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETTYPE, NULL, &type); + if ((type == (lxFD_OPEN | lxFD_CHANGE_DIR))) { + char buff[256]; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETFNAME, NULL, buff); + if (lxFileExists(buff)) { + strcpy(sdcard_fname, buff); sdcard_set_filename(&sd, sdcard_fname); sdcard_set_card_present(&sd, 1); } else { diff --git a/src/parts/virtual_VCD_Play.cc b/src/parts/virtual_VCD_Play.cc index 60a77cd9..1307f6e0 100644 --- a/src/parts/virtual_VCD_Play.cc +++ b/src/parts/virtual_VCD_Play.cc @@ -329,15 +329,17 @@ void cpart_VCD_Play::PostProcess(void) { void cpart_VCD_Play::OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) { switch (inputId) { case I_LOAD: - SpareParts.GetFileDialog()->SetType(lxFD_OPEN | lxFD_CHANGE_DIR); - SpareParts.GetFileDialog()->SetFilter("Value change dump (*.vcd)|*.vcd"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETTYPE, + std::to_string(lxFD_OPEN | lxFD_CHANGE_DIR).c_str()); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFILTER, "Value change dump (*.vcd)|*.vcd"); + if (f_vcd_name[0] == '*') { - SpareParts.GetFileDialog()->SetFileName("untitled.vcd"); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, "untitled.vcd"); } else { - SpareParts.GetFileDialog()->SetFileName(f_vcd_name); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGSETFNAME, f_vcd_name); } SpareParts.Setfdtype(id); - SpareParts.GetFileDialog()->Run(); + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGRUN, NULL); break; case I_PLAY: if (f_vcd_name[0] != '*') { @@ -378,8 +380,10 @@ void cpart_VCD_Play::OnMouseButtonPress(uint inputId, uint button, uint x, uint void cpart_VCD_Play::filedialog_EvOnClose(int retId) { if (retId) { - if ((SpareParts.GetFileDialog()->GetType() == (lxFD_OPEN | lxFD_CHANGE_DIR))) { - strncpy(f_vcd_name, SpareParts.GetFileDialog()->GetFileName().c_str(), 199); + int type; + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETTYPE, NULL, &type); + if ((type == (lxFD_OPEN | lxFD_CHANGE_DIR))) { + SpareParts.WindowCmd(PW_MAIN, "filedialog1", PWA_FILEDIALOGGETFNAME, NULL, f_vcd_name); LoadVCD(f_vcd_name); } output_ids[O_NAME]->update = 1; diff --git a/src/parts/virtual_vterm.cc b/src/parts/virtual_vterm.cc index ab389574..5a3a3c60 100644 --- a/src/parts/virtual_vterm.cc +++ b/src/parts/virtual_vterm.cc @@ -61,37 +61,37 @@ cpart_vterm::cpart_vterm(const unsigned x, const unsigned y, const char* name, c lending = LE_NL; - wvtermId = SpareParts.ExtraWindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); + wvtermId = SpareParts.WindowCmd(-1, "window1", PWA_WINDOWCREATE, NULL); std::string fname = (const char*)lxGetLocalFile(PICSimLab.GetSharePath() + "parts/Virtual/IO Virtual Term/terminal_1.lxrad") .c_str(); - if (SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETVISIBLE, "0"); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); - - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWPARTEV, "1"); - SpareParts.ExtraWindowCmd(wvtermId, "button1", PWA_BUTTONPARTEV, "1"); - SpareParts.ExtraWindowCmd(wvtermId, "button2", PWA_BUTTONPARTEV, "1"); - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOPARTEV, "1"); - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_COMBOPARTEV, "1"); - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_EDITPARTEV, "1"); - - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_TEXTTELETYPE, NULL); - - SpareParts.ExtraWindowCmd(wvtermId, "button1", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "button2", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_SETTAG, std::to_string(id).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETTAG, std::to_string(id).c_str()); + if (SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWLOADXML, fname.c_str())) { + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETVISIBLE, "0"); + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); + + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWPARTEV, "1"); + SpareParts.WindowCmd(wvtermId, "button1", PWA_BUTTONPARTEV, "1"); + SpareParts.WindowCmd(wvtermId, "button2", PWA_BUTTONPARTEV, "1"); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOPARTEV, "1"); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_COMBOPARTEV, "1"); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_EDITPARTEV, "1"); + + SpareParts.WindowCmd(wvtermId, "text1", PWA_TEXTTELETYPE, NULL); + + SpareParts.WindowCmd(wvtermId, "button1", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, "button2", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, "text1", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_SETTAG, std::to_string(id).c_str()); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETTAG, std::to_string(id).c_str()); } else { printf("PICSimLab: Vterm error loading file %s\n", (const char*)fname.c_str()); PICSimLab.RegisterError("Vterm error loading file:\n" + fname); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETVISIBLE, "0"); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETVISIBLE, "0"); + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); } SetPCWProperties(pcwprop); @@ -110,7 +110,7 @@ cpart_vterm::~cpart_vterm(void) { SpareParts.CanvasCmd({CC_DESTROY}); vterm_end(&vt); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWDESTROY, NULL); + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWDESTROY, NULL); wvtermId = -1; count--; @@ -126,12 +126,12 @@ void cpart_vterm::RegisterRemoteControl(void) { void cpart_vterm::ButtonEvent(const char* controlname, uint button, uint x, uint y, uint state) { if (!strcmp(controlname, "button1")) { char buff[256]; - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_EDITGETTEXT, NULL, buff); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_EDITGETTEXT, NULL, buff); text_to_send = buff; - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_EDITSETTEXT, ""); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_EDITSETTEXT, ""); send_text = 1; } else if (!strcmp(controlname, "button2")) { - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_TEXTCLEAR, NULL); + SpareParts.WindowCmd(wvtermId, "text1", PWA_TEXTCLEAR, NULL); } } @@ -139,9 +139,9 @@ void cpart_vterm::KeyEvent(const char* controlname, uint keysym, uint ukeysym, u if (!strcmp(controlname, "edit1")) { if (ukeysym == 13) { char buff[256]; - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_EDITGETTEXT, NULL, buff); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_EDITGETTEXT, NULL, buff); text_to_send = buff; - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_EDITSETTEXT, ""); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_EDITSETTEXT, ""); send_text = 1; } } @@ -150,12 +150,12 @@ void cpart_vterm::KeyEvent(const char* controlname, uint keysym, uint ukeysym, u void cpart_vterm::Event(const char* controlname) { if (!strcmp(controlname, "combo2")) { char buff[32]; - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_COMBOGETTEXT, NULL, buff); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_COMBOGETTEXT, NULL, buff); vterm_speed = std::stoi(buff); vterm_set_speed(&vt, vterm_speed); } else if (!strcmp(controlname, "combo1")) { char buff[32]; - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOGETTEXT, NULL, buff); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOGETTEXT, NULL, buff); if (!strcmp(buff, "No line ending")) { lending = LE_NONE; @@ -168,22 +168,22 @@ void cpart_vterm::Event(const char* controlname) { } } else if (!strcmp(controlname, "window1")) { int w, h; - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETWIDTH, NULL, &w); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETHEIGHT, NULL, &h); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETWIDTH, NULL, &w); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETHEIGHT, NULL, &h); - SpareParts.ExtraWindowCmd(wvtermId, "edit1", PWA_SETWIDTH, std::to_string(w - 100).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_SETWIDTH, std::to_string(w - 29).c_str()); + SpareParts.WindowCmd(wvtermId, "edit1", PWA_SETWIDTH, std::to_string(w - 100).c_str()); + SpareParts.WindowCmd(wvtermId, "text1", PWA_SETWIDTH, std::to_string(w - 29).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "button1", PWA_SETX, std::to_string(w - 87).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "button2", PWA_SETX, std::to_string(w - 90).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_SETX, std::to_string(w - 405).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_SETX, std::to_string(w - 215).c_str()); + SpareParts.WindowCmd(wvtermId, "button1", PWA_SETX, std::to_string(w - 87).c_str()); + SpareParts.WindowCmd(wvtermId, "button2", PWA_SETX, std::to_string(w - 90).c_str()); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_SETX, std::to_string(w - 405).c_str()); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_SETX, std::to_string(w - 215).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_SETHEIGHT, std::to_string(h - 119).c_str()); + SpareParts.WindowCmd(wvtermId, "text1", PWA_SETHEIGHT, std::to_string(h - 119).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "button2", PWA_SETY, std::to_string(h - 74).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_SETY, std::to_string(h - 73).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_SETY, std::to_string(h - 73).c_str()); + SpareParts.WindowCmd(wvtermId, "button2", PWA_SETY, std::to_string(h - 74).c_str()); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_SETY, std::to_string(h - 73).c_str()); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_SETY, std::to_string(h - 73).c_str()); } } @@ -191,20 +191,20 @@ void cpart_vterm::Reset(void) { vterm_rst(&vt); vterm_set_speed(&vt, vterm_speed); - SpareParts.ExtraWindowCmd(wvtermId, "combo2", PWA_COMBOSETTEXT, std::to_string(vterm_speed).c_str()); + SpareParts.WindowCmd(wvtermId, "combo2", PWA_COMBOSETTEXT, std::to_string(vterm_speed).c_str()); switch (lending) { case LE_NONE: - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "No line ending"); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "No line ending"); break; case LE_NL: - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "New line"); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "New line"); break; case LE_CR: - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "Carriage return"); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "Carriage return"); break; case LE_NL_CR: - SpareParts.ExtraWindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "Both NL and CR"); + SpareParts.WindowCmd(wvtermId, "combo1", PWA_COMBOSETTEXT, "Both NL and CR"); break; } } @@ -228,9 +228,9 @@ void cpart_vterm::DrawOutput(const unsigned int i) { if (show & 0x80) { if (show & 0x01) { - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWSHOW, NULL); + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWSHOW, NULL); } else { - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); + SpareParts.WindowCmd(wvtermId, NULL, PWA_WINDOWHIDE, NULL); } show &= ~0x80; } @@ -242,7 +242,7 @@ void cpart_vterm::DrawOutput(const unsigned int i) { // printf("Data recv: \n[\n%s]\n", str); vt.inMutex->Unlock(); - SpareParts.ExtraWindowCmd(wvtermId, "text1", PWA_TEXTAPPEND, str); + SpareParts.WindowCmd(wvtermId, "text1", PWA_TEXTAPPEND, str); break; default: SpareParts.CanvasCmd({CC_SETFONTSIZE, .SetFontSize{8}}); @@ -305,10 +305,10 @@ std::string cpart_vterm::WritePreferences(void) { int x, y, w, h; - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETX, NULL, &x); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETY, NULL, &y); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETWIDTH, NULL, &w); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_GETHEIGHT, NULL, &h); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETX, NULL, &x); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETY, NULL, &y); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETWIDTH, NULL, &w); + SpareParts.WindowCmd(wvtermId, NULL, PWA_GETHEIGHT, NULL, &h); sprintf(prefs, "%hhu,%hhu,%hhu,%u,%hhu,%i,%i,%i,%i", pins[0], pins[1], lending, vterm_speed, show, x, y, w, h); @@ -321,8 +321,8 @@ void cpart_vterm::ReadPreferences(std::string value) { &show, &x, &y, &w, &h); show |= 0x80; - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETX, std::to_string(x).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETY, std::to_string(y).c_str()); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETX, std::to_string(x).c_str()); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETY, std::to_string(y).c_str()); if (ret != 9) { // for compatibility with older versions w = 530; @@ -334,8 +334,8 @@ void cpart_vterm::ReadPreferences(std::string value) { if (h < 100) { h = 100; } - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETWIDTH, std::to_string(w).c_str()); - SpareParts.ExtraWindowCmd(wvtermId, NULL, PWA_SETHEIGHT, std::to_string(h).c_str()); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETWIDTH, std::to_string(w).c_str()); + SpareParts.WindowCmd(wvtermId, NULL, PWA_SETHEIGHT, std::to_string(h).c_str()); Reset(); } diff --git a/src/picsimlab1.cc b/src/picsimlab1.cc index 650a6d0d..ff150294 100644 --- a/src/picsimlab1.cc +++ b/src/picsimlab1.cc @@ -682,7 +682,7 @@ void CPWindow1::_EvOnCreate(CControl* control) { PICSimLab.OnUpdateGUI = &CPWindow1::OnUpdateGUI; PICSimLab.OnConfigMenuGUI = &CPWindow1::OnConfigMenuGUI; PICSimLab.OnCanvasCmd = &CPWindow1::OnCanvasCmd; - PICSimLab.OnExtraWindowCmd = &CPWindow1::OnExtraWindowCmd; + PICSimLab.OnWindowCmd = &CPWindow1::OnWindowCmd; PICSimLab.Init(this); @@ -1956,8 +1956,8 @@ void file_ready(const char* fname, const char* dir) { } } -int CPWindow1::OnExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff) { +int CPWindow1::OnWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff) { CControl* ctrl = NULL; int wid = -1; @@ -2192,6 +2192,26 @@ int CPWindow1::OnExtraWindowCmd(const int id, const char* ControlName, const PIC } break; + case PWA_FILEDIALOGGETFNAME: + strcpy((char*)ReturnBuff, ((CFileDialog*)ctrl)->GetFileName().utf8_str()); + return strlen((char*)ReturnBuff); + break; + case PWA_FILEDIALOGSETFNAME: + ((CFileDialog*)ctrl)->SetFileName(lxString::FromUTF8(Value)); + break; + case PWA_FILEDIALOGSETFILTER: + ((CFileDialog*)ctrl)->SetFilter(Value); + break; + case PWA_FILEDIALOGSETTYPE: + ((CFileDialog*)ctrl)->SetType(std::stoi(Value)); + break; + case PWA_FILEDIALOGRUN: + ((CFileDialog*)ctrl)->Run(); + break; + case PWA_FILEDIALOGGETTYPE: + *((int*)ReturnBuff) = ((CFileDialog*)ctrl)->GetType(); + break; + default: return -1; break; diff --git a/src/picsimlab1.h b/src/picsimlab1.h index e96886c1..871b37dd 100644 --- a/src/picsimlab1.h +++ b/src/picsimlab1.h @@ -170,8 +170,8 @@ class CPWindow1 : public CPWindow { const void* arg); static void OnConfigMenuGUI(const PICSimlabGUIMenu type); static int OnCanvasCmd(const CanvasCmd_t cmd); - static int OnExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff); + static int OnWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff); void Configure(void); int GetNeedClkUpdate(void) { return need_clkupdate; }; diff --git a/src/picsimlab1_d.cc b/src/picsimlab1_d.cc index 949f4f3b..81ae0a64 100644 --- a/src/picsimlab1_d.cc +++ b/src/picsimlab1_d.cc @@ -500,4 +500,6 @@ CPWindow1::CPWindow1(void) { memset(Bitmaps, 0, sizeof(Bitmaps)); memset(Windows, 0, sizeof(Windows)); + + Windows[PW_MAIN] = this; } diff --git a/src/picsimlab5.cc b/src/picsimlab5.cc index 761ff857..d5fe8a0e 100644 --- a/src/picsimlab5.cc +++ b/src/picsimlab5.cc @@ -25,8 +25,6 @@ // Spare parts -#define WPROP 0 - #include "lib/oscilloscope.h" #include "lib/picsimlab.h" #include "lib/spareparts.h" @@ -46,7 +44,7 @@ CPWindow5 Window5; // Implementation CPWindow5::~CPWindow5(void) { - delete Windows[WPROP]; + delete Windows[PW_WPROP]; } static void Setfdtype(int value) {} @@ -76,7 +74,7 @@ void CPWindow5::menu1_EvMenuActive(CControl* control) { void CPWindow5::_EvOnCreate(CControl* control) { SpareParts.OnCanvasCmd = &CPWindow5::OnCanvasCmd; - SpareParts.OnExtraWindowCmd = &CPWindow5::OnExtraWindowCmd; + SpareParts.OnWindowCmd = &CPWindow5::OnWindowCmd; if (SpareParts.GetLoadConfigFile().length() > 0) SpareParts.LoadConfig(SpareParts.GetLoadConfigFile()); @@ -166,11 +164,11 @@ void CPWindow5::pmenu2_Properties_EvMenuActive(CControl* control) { int itemc = SpareParts.GetPart(PartSelected)->GetPCWCount(); if (itemc) { const PCWProp* items = SpareParts.GetPart(PartSelected)->GetPCWProperties(); - Windows[WPROP]->SetName("window1"); // must be the same as in xml - Application->ACreateWindow(Windows[WPROP]); - Windows[WPROP]->DestroyChilds(); - Windows[WPROP]->SetTitle(SpareParts.GetPart(PartSelected)->GetName()); - Windows[WPROP]->SetWidth(370); + Windows[PW_WPROP]->SetName("window1"); // must be the same as in xml + Application->ACreateWindow(Windows[PW_WPROP]); + Windows[PW_WPROP]->DestroyChilds(); + Windows[PW_WPROP]->SetTitle(SpareParts.GetPart(PartSelected)->GetName()); + Windows[PW_WPROP]->SetWidth(370); CLabel* label; CCombo* combo; @@ -189,23 +187,23 @@ void CPWindow5::pmenu2_Properties_EvMenuActive(CControl* control) { sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(items[i].label); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "combo%i", i + 1); combo = new CCombo; combo->SetName(name); - combo->SetFOwner(Windows[WPROP]); + combo->SetFOwner(Windows[PW_WPROP]); combo->SetWidth(200); combo->SetHeight(26); combo->SetX(x + 68); combo->SetY(y); - Windows[WPROP]->CreateChild(combo); + Windows[PW_WPROP]->CreateChild(combo); break; case PCW_LABEL: { char lb[21]; @@ -217,136 +215,136 @@ void CPWindow5::pmenu2_Properties_EvMenuActive(CControl* control) { sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(lb1); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "label_%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(lb2); label->SetWidth(200); label->SetHeight(20); label->SetX(x + 76); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); } break; case PCW_SPIND: sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(items[i].label); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "spind%i", i + 1); spind = new CSpind; spind->SetName(name); - spind->SetFOwner(Windows[WPROP]); + spind->SetFOwner(Windows[PW_WPROP]); spind->SetWidth(200); spind->SetHeight(30); spind->SetX(x + 68); spind->SetY(y); - Windows[WPROP]->CreateChild(spind); + Windows[PW_WPROP]->CreateChild(spind); break; case PCW_SPIN: sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(items[i].label); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "spin%i", i + 1); spin = new CSpin; spin->SetName(name); - spin->SetFOwner(Windows[WPROP]); + spin->SetFOwner(Windows[PW_WPROP]); spin->SetWidth(200); spin->SetHeight(30); spin->SetX(x + 68); spin->SetY(y); - Windows[WPROP]->CreateChild(spin); + Windows[PW_WPROP]->CreateChild(spin); break; case PCW_EDIT: sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(items[i].label); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "edit%i", i + 1); edit = new CEdit; edit->SetName(name); - edit->SetFOwner(Windows[WPROP]); + edit->SetFOwner(Windows[PW_WPROP]); edit->SetWidth(200); edit->SetHeight(26); edit->SetX(x + 68); edit->SetY(y); - Windows[WPROP]->CreateChild(edit); + Windows[PW_WPROP]->CreateChild(edit); break; case PCW_TEXT: sprintf(name, "text%i", i + 1); text = new CText; text->SetName(name); - text->SetFOwner(Windows[WPROP]); + text->SetFOwner(Windows[PW_WPROP]); text->SetWidth(340); text->SetHeight(128); text->SetX(x - 44); text->SetY(y); - Windows[WPROP]->CreateChild(text); + Windows[PW_WPROP]->CreateChild(text); y += 110; break; case PCW_DCOMBO: sprintf(name, "label%i", i + 1); label = new CLabel; label->SetName(name); - label->SetFOwner(Windows[WPROP]); + label->SetFOwner(Windows[PW_WPROP]); label->SetText(items[i].label); label->SetWidth(60); label->SetHeight(20); label->SetX(x); label->SetY(y + 3); - Windows[WPROP]->CreateChild(label); + Windows[PW_WPROP]->CreateChild(label); sprintf(name, "combo%i", i + 1); combo = new CCombo; combo->SetName(name); - combo->SetFOwner(Windows[WPROP]); + combo->SetFOwner(Windows[PW_WPROP]); combo->SetWidth(200); combo->SetHeight(26); combo->SetX(x + 68); combo->SetY(y); - Windows[WPROP]->CreateChild(combo); + Windows[PW_WPROP]->CreateChild(combo); sprintf(name, "combo_%i", i + 1); combo = new CCombo; combo->SetName(name); - combo->SetFOwner(Windows[WPROP]); + combo->SetFOwner(Windows[PW_WPROP]); combo->SetWidth(150); combo->SetHeight(26); combo->SetX(x + 278); combo->SetY(y); - Windows[WPROP]->CreateChild(combo); + Windows[PW_WPROP]->CreateChild(combo); - Windows[WPROP]->SetWidth(540); + Windows[PW_WPROP]->SetWidth(540); break; default: printf("PICSimLab: Unknown PCW type number %i\n", items[i].pcw_type); @@ -359,73 +357,73 @@ void CPWindow5::pmenu2_Properties_EvMenuActive(CControl* control) { dual = 2 * itemc; y = 32; x = 54 + 370; - Windows[WPROP]->SetWidth(370 * 2); + Windows[PW_WPROP]->SetWidth(370 * 2); } } CButton* button; button = new CButton; button->SetName("button1"); - button->SetFOwner(Windows[WPROP]); + button->SetFOwner(Windows[PW_WPROP]); button->SetText("Ok"); button->SetWidth(65); button->SetHeight(28); - button->SetX((Windows[WPROP]->GetWidth() / 2) - 75); + button->SetX((Windows[PW_WPROP]->GetWidth() / 2) - 75); button->SetY(y + 32); button->SetTag(1); button->EvMouseButtonRelease = EVMOUSEBUTTONRELEASE & CPWindow5::PropButtonRelease; - Windows[WPROP]->CreateChild(button); + Windows[PW_WPROP]->CreateChild(button); button = new CButton; button->SetName("button2"); - button->SetFOwner(Windows[WPROP]); + button->SetFOwner(Windows[PW_WPROP]); button->SetText("Cancel"); button->SetWidth(65); button->SetHeight(28); - button->SetX((Windows[WPROP]->GetWidth() / 2) + 10); + button->SetX((Windows[PW_WPROP]->GetWidth() / 2) + 10); button->SetY(y + 32); button->EvMouseButtonRelease = EVMOUSEBUTTONRELEASE & CPWindow5::PropButtonRelease; - Windows[WPROP]->CreateChild(button); + Windows[PW_WPROP]->CreateChild(button); - Windows[WPROP]->SetHeight(y + 130); + Windows[PW_WPROP]->SetHeight(y + 130); SpareParts.GetPart(PartSelected)->ConfigurePropertiesWindow(); - Windows[WPROP]->SetX(SpareParts.GetPart(PartSelected)->GetX() + GetX() - offsetx); - Windows[WPROP]->SetY(SpareParts.GetPart(PartSelected)->GetY() + GetY() - offsety); + Windows[PW_WPROP]->SetX(SpareParts.GetPart(PartSelected)->GetX() + GetX() - offsetx); + Windows[PW_WPROP]->SetY(SpareParts.GetPart(PartSelected)->GetY() + GetY() - offsety); - Windows[WPROP]->Draw(); - Windows[WPROP]->ShowExclusive(); + Windows[PW_WPROP]->Draw(); + Windows[PW_WPROP]->ShowExclusive(); } else { std::string fname = PICSimLab.GetSharePath() + "parts/" + SpareParts.GetPart(PartSelected)->GetPropertiesWindowFile(); if (lxFileExists(fname)) { CButton* button; - Windows[WPROP]->SetName("window1"); // must be the same as in xml - Application->ACreateWindow(Windows[WPROP]); - Windows[WPROP]->DestroyChilds(); - if (Windows[WPROP]->LoadXMLContextAndCreateChilds(fname)) { + Windows[PW_WPROP]->SetName("window1"); // must be the same as in xml + Application->ACreateWindow(Windows[PW_WPROP]); + Windows[PW_WPROP]->DestroyChilds(); + if (Windows[PW_WPROP]->LoadXMLContextAndCreateChilds(fname)) { // Windows[WPROP]->SetCanDestroy (false); SpareParts.GetPart(PartSelected)->ConfigurePropertiesWindow(); - button = (CButton*)Windows[WPROP]->GetChildByName("button1"); + button = (CButton*)Windows[PW_WPROP]->GetChildByName("button1"); if (button) { button->EvMouseButtonRelease = EVMOUSEBUTTONRELEASE & CPWindow5::PropButtonRelease; button->SetTag(1); } - button = (CButton*)Windows[WPROP]->GetChildByName("button2"); + button = (CButton*)Windows[PW_WPROP]->GetChildByName("button2"); if (button) { button->EvMouseButtonRelease = EVMOUSEBUTTONRELEASE & CPWindow5::PropButtonRelease; } - Windows[WPROP]->SetX(SpareParts.GetPart(PartSelected)->GetX() + GetX() - offsetx); - Windows[WPROP]->SetY(SpareParts.GetPart(PartSelected)->GetY() + GetY() - offsety); + Windows[PW_WPROP]->SetX(SpareParts.GetPart(PartSelected)->GetX() + GetX() - offsetx); + Windows[PW_WPROP]->SetY(SpareParts.GetPart(PartSelected)->GetY() + GetY() - offsety); - Windows[WPROP]->Draw(); - Windows[WPROP]->ShowExclusive(); + Windows[PW_WPROP]->Draw(); + Windows[PW_WPROP]->ShowExclusive(); } } else { @@ -440,9 +438,9 @@ void CPWindow5::PropClose(int tag) { if (tag) { SpareParts.GetPart(PartSelected)->ReadPropertiesWindow(); } - Windows[WPROP]->HideExclusive(); + Windows[PW_WPROP]->HideExclusive(); // Windows[WPROP]->SetCanDestroy (true); - Windows[WPROP]->WDestroy(); + Windows[PW_WPROP]->WDestroy(); update_all = 1; } @@ -462,8 +460,8 @@ void CPWindow5::PropButtonRelease(CControl* control, uint button, uint x, uint y } void CPWindow5::PropComboChange(CCombo* control) { - Window5.Windows[WPROP]->HideExclusive(); - Window5.Windows[WPROP]->WDestroy(); + Window5.Windows[PW_WPROP]->HideExclusive(); + Window5.Windows[PW_WPROP]->WDestroy(); SpareParts.GetPart(Window5.PartSelected) ->ComboChange(control->GetName().c_str(), (const char*)control->GetText().c_str()); @@ -1082,8 +1080,8 @@ int CPWindow5::OnCanvasCmd(const CanvasCmd_t cmd) { return -1; } -int CPWindow5::OnExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff) { +int CPWindow5::OnWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff) { CControl* ctrl = NULL; int wid = -1; @@ -1315,6 +1313,26 @@ int CPWindow5::OnExtraWindowCmd(const int id, const char* ControlName, const PIC } break; + case PWA_FILEDIALOGGETFNAME: + strcpy((char*)ReturnBuff, ((CFileDialog*)ctrl)->GetFileName().utf8_str()); + return strlen((char*)ReturnBuff); + break; + case PWA_FILEDIALOGSETFNAME: + ((CFileDialog*)ctrl)->SetFileName(lxString::FromUTF8(Value)); + break; + case PWA_FILEDIALOGSETFILTER: + ((CFileDialog*)ctrl)->SetFilter(Value); + break; + case PWA_FILEDIALOGSETTYPE: + ((CFileDialog*)ctrl)->SetType(std::stoi(Value)); + break; + case PWA_FILEDIALOGRUN: + ((CFileDialog*)ctrl)->Run(); + break; + case PWA_FILEDIALOGGETTYPE: + *((int*)ReturnBuff) = ((CFileDialog*)ctrl)->GetType(); + break; + default: return -1; break; diff --git a/src/picsimlab5.h b/src/picsimlab5.h index ff31b0e7..ba0bf8d6 100644 --- a/src/picsimlab5.h +++ b/src/picsimlab5.h @@ -118,8 +118,8 @@ class CPWindow5 : public CPWindow { void DeleteParts(void); static int OnCanvasCmd(const CanvasCmd_t cmd); - static int OnExtraWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, - const char* Value, void* ReturnBuff); + static int OnWindowCmd(const int id, const char* ControlName, const PICSimLabWindowAction action, const char* Value, + void* ReturnBuff); CCanvas Canvas[MAX_PARTS]; lxBitmap* Bitmaps[MAX_PARTS * 2]; diff --git a/src/picsimlab5_d.cc b/src/picsimlab5_d.cc index 042bb0ee..7d367ba7 100644 --- a/src/picsimlab5_d.cc +++ b/src/picsimlab5_d.cc @@ -326,6 +326,7 @@ CPWindow5::CPWindow5(void) { memset(Bitmaps, 0, sizeof(Bitmaps)); memset(Windows, 0, sizeof(Windows)); - Windows[WPROP] = new CPWindow; - Windows[WPROP]->SetCanDestroy(false); + Windows[PW_MAIN] = this; + Windows[PW_WPROP] = new CPWindow; + Windows[PW_WPROP]->SetCanDestroy(false); }