Freeze/Thaw Behavior in 3.1.4 (GTK3)

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
shatch
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jun 21, 2021 5:10 pm

Freeze/Thaw Behavior in 3.1.4 (GTK3)

Post by shatch »

Hi,

We’re seeing an issue with Window::Freeze and Window::Thaw in wxWidgets 3.1.4 on CentOS 8.3. The gtk version is 3.22.30; I can provide other versions if needed.

The following “hello world” application demonstrates the issue:

Code: Select all

// wxWidgets "Hello world" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

class MyApp: public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    wxDECLARE_EVENT_TABLE();
};
enum
{
    ID_Hello = 1
};
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(ID_Hello,   MyFrame::OnHello)
    EVT_MENU(wxID_EXIT,  MyFrame::OnExit)
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) );
    frame->Show( true );
    return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
        : wxFrame(NULL, wxID_ANY, title, pos, size)
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
                     "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);
    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, "&File" );
    menuBar->Append( menuHelp, "&Help" );
    SetMenuBar( menuBar );
    CreateStatusBar();
    SetStatusText( "Welcome to wxWidgets!" );

}
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close( true );
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
	// Freeze used here.  The update to the status bar below is not expected to display until after the 
	// message box is dismissed.
	
	this->Freeze();
	SetStatusText( "New text!" );
	
        wxMessageBox( "This is a wxWidgets' Hello world sample",
                  "About Hello World", wxOK | wxICON_INFORMATION );
				  
	this->Thaw();
}
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}
When the app is run, and I click Help > About, I see the following:

3.1.4-frozen.png
3.1.4-frozen.png (11.98 KiB) Viewed 4564 times

In older versions of wxWidgets (for example, 3.0.0), freezing a window doesn’t cause it to turn black as shown above. For example, in 3.0.0, we see the following after clicking Help > About:

3.0.0-frozen.png
3.0.0-frozen.png (16.16 KiB) Viewed 4564 times

This is the behavior I expect (though I’m not sure this exact behavior is specified). We lean on this mechanism quite heavily to make updates to child windows but hold off on displaying them until I call Thaw(), just like MyFrame::OnAbout in the example code.

For both versions, after “OK” is clicked, the main/background window is redrawn and "New text!" shows up in the status bar as expected.

We also get the expected behavior (what's shown in 3.0.0-frozen.png) when using wxWidgets 3.1.4 with GTK2 instead of GTK3.

For reference, it looks like there have been at least a few updates to the freeze/thaw code for GTK since 3.0.0, though I’m not familiar enough with GTK to fully understand them. For example:
- Avoid using gdk_window_freeze_updates() to implement Freeze() (https://github.com/wxWidgets/wxWidgets/ ... 774284e1a6)
- Avoid freeze count mismatches with GTK 2.18+ when impl_window changes ... (https://github.com/wxWidgets/wxWidgets/ ... 298e7ec683)

Is this behavior demonstrated in the first image expected behavior? If not, does anyone know what might be causing the window to turn black while it’s frozen?
Last edited by shatch on Thu Jun 24, 2021 4:17 pm, edited 2 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Freeze/Thaw Behavior in 3.1.4 (GTK3)

Post by doublemax »

That's not what Freeze/Thaw is intended for anyway. What are you trying to achieve?
Use the source, Luke!
shatch
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jun 21, 2021 5:10 pm

Re: Freeze/Thaw Behavior in 3.1.4 (GTK3)

Post by shatch »

The basic idea we're trying to accomplish is something in between a modal and modeless dialog.

For example, imagine you you have a main window with child windows A and B and both A and B have text that's always changing. Now say the main window spawns a message box, and you want A to stop updating (modal like behavior), but B to continue updating (more like a modeless dialog). Assuming one thread, we couldn't do modal since B wouldn't update, so we have something more like a modeless dialog, and Freeze A, and Thaw A when the dialog is dismissed.

Is there a better design for this idea?

Additionally, we do use Freeze/Thaw more closely to its intended use elsewhere, so even if we find a better way to do the above, I'm still interested in a solution to the problem described in the original post.
Post Reply