magiblot / tvision

A modern port of Turbo Vision 2.0, the classical framework for text-based user interfaces. Now cross-platform and with Unicode support.
Other
1.99k stars 150 forks source link

2 bugs.... #72

Closed IngvarRiga closed 1 year ago

IngvarRiga commented 2 years ago

Good day! Found 2 errors:

  1. If there is an incomplete submenu in the program menu that does not contain items, then when you double-click on Esc and close the active dialog (the second press after closing), the program crashes in the function that searches for short menu keys. It turns out that it requests a list of sub-items that is null_ptr and tries to scan it

  2. If in the file saving dialog box you immediately specify the file name without jokers (*), then double-click on the link to the top directory .. (and possibly the lower one, I didn't check it) leads to automatic confirmation of saving and as a result saving the file in the top-level directory, although the dialog should just go to that directory.

magiblot commented 2 years ago

Hi Alexey!

I'm very grateful that you found these two bugs. Thank you for reporting them.

I've tried to fix the first one. Try it again and tell me if it's solved.

However, I am unable to reproduce the second bug. Is this how you do it? If not, please share a screen recording showing the issue.

https://user-images.githubusercontent.com/20713561/162300590-b3603e20-ab56-4d88-bd3e-5ae6ae68281d.mp4

Cheers!

IngvarRiga commented 2 years ago

Hi! No, the screenshot you provided does not reflect the error. In simple words, before saving, I specify the file name not *.json (for example) and fully TNewDialog.json, of course programmatically, see the code just below. And if, as in the picture, I clicked on "..\" then the dialog box closes with the command "cmOK" and the file is immediately saved in the folder level above, i.e. the one pointed to. ".\", which is not right! The window should close only after clicking OK. That is, I can first set the file name and only then navigate through the folders by choosing the save path. Is that clear? As an example, you can use the dialog editor, that's where I encountered this error.

err

code from src:

void TTrialDialog::saveDialogToJSON() { //-- формируем имя диалога из его названия класса char fileNameMask[maxLineLength]; memset(fileNameMask, 0x0, maxLineLength); strcat(fileNameMask, class_name); strcat(fileNameMask, ".json"); auto fd = new TFileDialog(fileNameMask, txt_dlg_SaveAsCaption, txt_dlg_SaveAsName, fdOKButton, 100); if (fd != 0 && owner->execView(fd) != cmCancel) { std::string serialized_string = DialogToJSON().dump();

    char fileName[MAXPATH];
    fd->getFileName(fileName);
    ofstream os;
    os.open(fileName);
    os << serialized_string;
    os.close();
    DialSaved = true;
}
destroy(fd);

}

IngvarRiga commented 2 years ago

1st bug fixed ))

magiblot commented 2 years ago

Okay. The second problem is not a TFileDialog bug, although it may be a flaw in its design. From TFileDialog's perspective, it is the same whether you double-click an entry, you press enter or you click on the Ok button. If in the first constructor parameter you provide a complete file name without wildcards (*), TFileDialog will behave the same as if you wanted to save the file with that name. So, the most you can do is the following:

-   auto fd = new TFileDialog(fileNameMask, txt_dlg_SaveAsCaption, txt_dlg_SaveAsName, fdOKButton, 100);
+   auto fd = new TFileDialog("*.dlg", txt_dlg_SaveAsCaption, txt_dlg_SaveAsName, fdOKButton, 100);

    if (fd != 0)
    {
+       fd->setData(fileNameMask);
        auto res = owner->execView(fd);

Then the dialog will initially have the name you suggested: photo1

But it will go away when clicking on a file list entry: photo2

That's what the original behaviour allows. I'm not sure how it could be improved.

IngvarRiga commented 2 years ago

Ok, i`m try. Thanks.

magiblot commented 2 years ago

By the way, if it may interest you, Turbo Vision already provides a popupMenu function which takes care of positioning and executing context menus:

diff --git a/tvdd/common.cpp b/tvdd/common.cpp
index 38738b2..aef683f 100644
--- a/tvdd/common.cpp
+++ b/tvdd/common.cpp
@@ -275,24 +275,21 @@ void generateDialogJSON(TView* obj, void* _src)
        }
 }

-TMenuBox* dialogMenu()
+TMenuItem& dialogMenu()
 {
        //-- создание контекстного меню диалога
-       TMenuBox* contextMenu = new TMenuBox(TRect(0, 0, 0, 0),
-                                                                                new TMenu(
-                                                                                        *new TMenuItem(txt_PropertyDialogCaption, cmOption_Dialog, kbCtrlEnter, hcNoContext, "Ctrl+Enter") +
-                                                                                        newLine() +
-                                                                                        *new TMenuItem(txt_mnu_StaticText, cm_ed_InsertStaticText, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_Button, cm_ed_InsertButton, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_InputLine, cm_ed_InsertInputLine, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_RadioButtons, cm_ed_InsertRadioButtons, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_CheckBoxes, cm_ed_InsertCheckBoxes, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_ListBox, cm_ed_InsertListBox, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_Memo, cm_ed_InsertMemo, kbNoKey)+
-                                                                                        newLine() +
-                                                                                        *new TMenuItem(txt_mnu_Copy, cm_ed_Copy, kbNoKey) +
-                                                                                        *new TMenuItem(txt_mnu_Paste, cm_ed_Paste, kbNoKey) 
-                                                                                ), nullptr);
-       return contextMenu;
+       return
+               *new TMenuItem(txt_PropertyDialogCaption, cmOption_Dialog, kbCtrlEnter, hcNoContext, "Ctrl+Enter") +
+               newLine() +
+               *new TMenuItem(txt_mnu_StaticText, cm_ed_InsertStaticText, kbNoKey) +
+               *new TMenuItem(txt_mnu_Button, cm_ed_InsertButton, kbNoKey) +
+               *new TMenuItem(txt_mnu_InputLine, cm_ed_InsertInputLine, kbNoKey) +
+               *new TMenuItem(txt_mnu_RadioButtons, cm_ed_InsertRadioButtons, kbNoKey) +
+               *new TMenuItem(txt_mnu_CheckBoxes, cm_ed_InsertCheckBoxes, kbNoKey) +
+               *new TMenuItem(txt_mnu_ListBox, cm_ed_InsertListBox, kbNoKey) +
+               *new TMenuItem(txt_mnu_Memo, cm_ed_InsertMemo, kbNoKey) +
+               newLine() +
+               *new TMenuItem(txt_mnu_Copy, cm_ed_Copy, kbNoKey) +
+               *new TMenuItem(txt_mnu_Paste, cm_ed_Paste, kbNoKey);
 }

diff --git a/tvdd/common.h b/tvdd/common.h
index e2da991..53cf4b5 100644
--- a/tvdd/common.h
+++ b/tvdd/common.h
@@ -156,7 +157,7 @@ void scanComponentsSize(TView* obj, void* val);
 /// Создание контекстного меню редактируемого диалогового окна
 /// </summary>
 /// <returns></returns>
-TMenuBox* dialogMenu();
+TMenuItem& dialogMenu();
 /// <summary>
 /// Перечень типов объектов, которые могут сохраняться в JSON
 /// </summary>
diff --git a/tvdd/trialdialog.cpp b/tvdd/trialdialog.cpp
index a599f0b..a403668 100644
--- a/tvdd/trialdialog.cpp
+++ b/tvdd/trialdialog.cpp
@@ -167,19 +167,7 @@ void TTrialDialog::handleEvent(TEvent& event)
                     tmp.y = ((TPoint*)event.message.infoPtr)->y;
                     clearEvent(event);

-                    auto contextMenu = dialogMenu();
-                    //-- смещаем левую верхнюю точку меню в точку клика мышкой на экране
-                    auto b = contextMenu->getBounds();
-                    auto dx = b.b.x - b.a.x;
-                    auto dy = b.b.y - b.a.y;
-                    b.a.x = tmp.x;
-                    b.a.y = tmp.y - 1;
-                    b.b.x = b.a.x + dx;
-                    b.b.y = b.a.y + dy;
-                    contextMenu->setBounds(b);
-                    //---------------------------------------------------------------------
-                    auto res = this->owner->execView(contextMenu);
-                    destroy(contextMenu);
+                    auto res = popupMenu(tmp, dialogMenu());
                     //-- рассылаем команды
                     if (res != 0)
                         //-- в качестве параметра передаем точку клика мышки, так можно будет указывать точное место вставки компонента
diff --git a/tvdd/ttrialdialogbackground.cpp b/tvdd/ttrialdialogbackground.cpp
index 4c90e41..eee2939 100644
--- a/tvdd/ttrialdialogbackground.cpp
+++ b/tvdd/ttrialdialogbackground.cpp
@@ -66,7 +66,7 @@ void TTrialDialogBackground::handleEvent(TEvent& event)
                        clearEvent(event);
                }

-               if (event.what == evMouseUp)
+               if (event.what == evMouseDown)
                {
                        //-- вызов контекстного меню для диалога
                        if (event.mouse.buttons == mbRightButton)
IngvarRiga commented 2 years ago

a small request: when compiling MSVC 2019, it throws out a bunch of warnings about possible data loss at the point:

scrncell.h

inline TScreenCell::TScreenCell(ushort bios) { memset(this, 0, sizeof(*this)); _ch.moveChar(bios); << Warning position here attr = uchar(bios >> 8); }

.......\scrncell.h(201,18): warning C4244: arg....: conversion from "ushort" to "char", possible data lost

IngvarRiga commented 2 years ago

By the way, if it may interest you, Turbo Vision already provides a popupMenu function which takes care of positioning and executing context menus:

thank you, I will correct my code on occasion.

magiblot commented 2 years ago

a small request: when compiling MSVC 2019, it throws out a bunch of warnings about possible data loss

Fixed! Thanks for letting me know.

IngvarRiga commented 2 years ago

non-critical build warn in 2019 revision 16.11.15 with last version TV:

1>D:\GIT\TurboVision-dialog-designer\tvdd\include\tvision\objects.h(277,1): warning C4250: TSortedCollection: наследуется "TNSSortedCollection::TNSSortedCollection::insert" через превосходство 1>D:\GIT\TurboVision-dialog-designer\tvdd\include\tvision\tvobjs.h(130): message : см. объявление "TNSSortedCollection::insert" 1>D:\GIT\TurboVision-dialog-designer\tvdd\include\tvision\resource.h(53,1): warning C4250: TStringCollection: наследуется "TNSSortedCollection::TNSSortedCollection::indexOf" через превосходство

magiblot commented 2 years ago

Thanks! It should be fixed now.