IsModified, MarkDirty do not work when SetHint is given

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

IsModified, MarkDirty do not work when SetHint is given

Post by Harsh »

Select all text press Delete or Backspace and on FocusOut check if IsModified(), returns false.

Try MarkDirty in condition to overcome bug, but even MarkDirty do not work for above condition.

Remove SetHint and Repeat above step, IsModified works fine.

Code: Select all

#include<wx/wx.h>

class MyFrame : public wxFrame{
	wxPanel *panel;
    wxBoxSizer *vbox;
	wxTextCtrl *txt,*txt1;
	wxDialog *dlg;
	
	void OnChar(wxKeyEvent &event){
		event.Skip();
		if(event.GetKeyCode()==13){
			txt->Navigate(wxNavigationKeyEvent::IsForward);
		}else if(event.GetKeyCode()==127){
			if(txt->GetStringSelection()==txt->GetValue())txt->MarkDirty();
		}
	}
	void OnFocusOut(wxFocusEvent &event){
		event.Skip();
		if(txt->IsModified())txt->ChangeValue("Modified.");
		else txt->ChangeValue("Not Modified.");
	}
public : 
	MyFrame():wxFrame(NULL,wxID_ANY,"Child Focus"){

		panel=new wxPanel(this);
		panel->Bind(wxEVT_CHAR_HOOK,&MyFrame::OnChar,this);
		vbox=new wxBoxSizer(wxVERTICAL);

		txt=new wxTextCtrl(panel,wxID_ANY,wxT(""));
		txt->SetHint(wxT("Hint1"));
		txt->Bind(wxEVT_KILL_FOCUS,&MyFrame::OnFocusOut,this);
		vbox->Add(txt,0,wxEXPAND|wxALL,5);

		txt1=new wxTextCtrl(panel,wxID_ANY,wxT(""));
		txt1->SetHint(wxT("Hint2"));
		vbox->Add(txt1,0,wxEXPAND|wxALL,5);

		panel->SetSizer(vbox);
	}
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};
IMPLEMENT_APP(MyApp);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: IsModified, MarkDirty do not work when SetHint is given

Post by ONEEYEMAN »

Hi,
What OS?
What wx version?
Can you reproduce in a text sample?

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: IsModified, MarkDirty do not work when SetHint is given

Post by Harsh »

ONEEYEMAN wrote: Tue Jun 08, 2021 12:32 pm Hi,
What OS?
What wx version?
Can you reproduce in a text sample?

Thank you.
OS : WINDOWS10
VERSION : 3.1.5
CODE SAMPLE IS ABOVE IN QUESTION.
Otherwise do not know what you mean by 'Text Sample'
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: IsModified, MarkDirty do not work when SetHint is given

Post by ONEEYEMAN »

Hi,
text sample can be found in wxWidgets/samples/text.
If you use precompiled libraries you will need to download source code and check the sample.
Otherwise - just open the source, add the call to IsModified() (possibly to the Help menu handler) build and run it.
I also presume you are using MSVC. So just open the appropriate sln file, modify the source, build and run.

Thank you.
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: IsModified, MarkDirty do not work when SetHint is given

Post by Harsh »

ONEEYEMAN wrote: Tue Jun 08, 2021 2:24 pm Hi,
text sample can be found in wxWidgets/samples/text.
If you use precompiled libraries you will need to download source code and check the sample.
Otherwise - just open the source, add the call to IsModified() (possibly to the Help menu handler) build and run it.
I also presume you are using MSVC. So just open the appropriate sln file, modify the source, build and run.

Thank you.
Compiler : MINGW 8.0.1
EDITOR : Code Blocks 20.03

I will download source and try samples
Harsh
Experienced Solver
Experienced Solver
Posts: 70
Joined: Tue Apr 13, 2021 5:03 am

Re: IsModified, MarkDirty do not work when SetHint is given

Post by Harsh »

ONEEYEMAN wrote: Tue Jun 08, 2021 2:24 pm Hi,
text sample can be found in wxWidgets/samples/text.
If you use precompiled libraries you will need to download source code and check the sample.
Otherwise - just open the source, add the call to IsModified() (possibly to the Help menu handler) build and run it.
I also presume you are using MSVC. So just open the appropriate sln file, modify the source, build and run.

Thank you.
Same in the sample too.
Which text field has SetHint, IsModified and MarkDirty do not work on them, on select all then delete condition.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: IsModified, MarkDirty do not work when SetHint is given

Post by ONEEYEMAN »

Hi,
Congratulations! You found a bug.
You should create a ticket at trac.wxwidgets.org and then see if you can find a solution.

When you do - mention you OS version, wx version, steps you take in the sample to reproduce the bug and attach the patch to the sample (do not attach the whole source).
Then you will need to either trace it to find a fix for the bug or wait until someone else will.

Hopefully someone could give a workarouind for the time being.

Thank you.
Post Reply