Opened 10 years ago

Closed 2 years ago

#2628 closed defect (fixed)

Can't close the parent frame when wxGridCellChoiceEditor is shown in wxGTK

Reported by: mkab Owned by:
Priority: normal Milestone:
Component: wxGTK Version:
Keywords: wxGrid Cc: mkab
Blocked By: Blocking:
Patch: no

Description

wxGridCellChoiceEditor misbehaves in two issues under
wxGTK.

  1. If one binds an editor to a cell with SetEditor()

the first string in the wxString[] is selected
automatically.
But if one creates a wxGridCellAttr and sets the Editor
as attribute, and then assign it to a column or row
using SetColAttr() , there is nothing selected on
initialization.

  1. The choicebox dissapears when the mouse button is

released. Even keeping the mouse button pressed and
moving to select an item fails.
One might expect to work as a normal wxChoice.
Instead, when you click on the arrow that appears, if
you leave the mouse button, the choice folds back in.

All these are true in wxGTK-2.6.1 unicode build, with
gtk2-2.4.9

Change History (13)

comment:1 Changed 7 years ago by wojdyr

  • Keywords wxGrid added

comment:2 Changed 7 years ago by wxsite

  • Component changed from GUI-generic to wxGrid

comment:3 Changed 3 years ago by oneeyeman

I am currently testing the grid sample under GTK.
Issue #2 is gone. The list stays when the mouse button is released.

For testing issue #1 I used following changes to the grid sample:

+ wxGridCellAttr *atrib = new wxGridCellAttr;
+ atrib->SetEditor( new wxGridCellChoiceEditor(WXSIZEOF(choices) ) );
+ grid->SetColAttr( 0, atrib );

  • grid->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices));

When run I received this output:
Program received signal SIGSEGV, Segmentation fault.
0xb6ac01d4 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

() from /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libstdc++.so.6

(gdb) bt
#0 0xb6ac01d4 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/gcc/i686-pc-linux-gnu/4.4.5/libstdc++.so.6
#1 0xb7e83a1c in wxString::wxString (this=0xbfffdc08, stringSrc=...) at ../include/wx/string.h:1257
#2 0xb7e9564c in wxArrayString::Add (this=0x81d1a8c, string=..., copies=1) at ../include/wx/arrstr.h:67
#3 0xb7f09e1d in wxGridCellChoiceEditor::wxGridCellChoiceEditor (this=0x81d1a40, count=3, choices=0x0, allowOthers=false) at ../src/generic/grideditors.cpp:1385
#4 0x08067375 in GridFrame::GridFrame (this=0x8117f98) at ../../../samples/grid/griddemo.cpp:477
#5 0x0805db06 in GridApp::OnInit (this=0x80c3118) at ../../../samples/grid/griddemo.cpp:141
#6 0x080752d9 in wxAppConsoleBase::CallOnInit (this=0x80c3118) at ../../../include/wx/app.h:94
#7 0xb7687d39 in wxEntry (argc=@0xb782d714, argv=0x80c2ed0) at ../src/common/init.cpp:456
#8 0xb7687e35 in wxEntry (argc=@0xbfffef00, argv=0xbfffefa4) at ../src/common/init.cpp:484
#9 0x0805da70 in main (argc=1, argv=0xbfffefa4) at ../../../samples/grid/griddemo.cpp:129

Also I guess it's a new issue.
When I start the sample then clicked on the cell A5 4 times: to select the cell, show the editor drop the list and fold the list and then tried to close the program I wasn't able to. No method worked. Clicking on "x", using Alt+F4, clicking on the icon and selecting "Close" - program was still running. Then I selected the cell A3 and the program finished.

I don't know if this is something new or not, but that's what was discovered.
Maybe it's just worst a new ticket?

comment:4 Changed 3 years ago by vadz

You're creating wxGridCellChoiceEditor with a NULL pointer instead of choices and the stack trace you pasted in even shows as much...

comment:5 Changed 3 years ago by oneeyeman

After fixing the error everything works correctly.
The selection is set properly.

I guess the first issue is also gone.

What about my comments about not be able to close the frame? Is it something known? Do we need a new bug?

comment:6 Changed 3 years ago by vadz

  • Component changed from wxGrid to wxGTK
  • Status changed from new to confirmed
  • Summary changed from wxGridCellChoiceEditor misbehaves on wxGTK 2.6.1 to Can't close the parent frame when wxGridCellChoiceEditor is shown in wxGTK

I can indeed confirm that the frame can't be closed. This looks like a wxGTK bug.

comment:7 Changed 3 years ago by oneeyeman

In fact this is even reproducible in the widgets sample.

comment:8 Changed 3 years ago by vadz

How exactly? It's not like it has a wxGridCellChoiceEditor in it...

comment:9 Changed 3 years ago by oneeyeman

Vadim,
The widget sample has a combo box/choice page.

Try to open a combo box list in the widgets sample and then close the main frame.

However, what weird is that when you do this logic:

  1. Start the sample.
  2. Pull down the list from the combo box.
  3. Click on the "X" to close the main frame.

At this point nothing happens.

  1. Click on the combo box button to hide the list box.

At this point frame closes.

It looks like the event is being eaten somewhere or wxGTK needs to resume to the idle processing when the list box of the combo is in the dropped stage.

However I just don't know how wxGTK is doing the idle processing so I will leave this for the person more familiar with it.

comment:10 follow-ups: Changed 2 years ago by pcor

The frame does not close because Refresh() is called from a paint event, causing continuous painting and blocking idle processing.

#2  0x00007ffff73a42fb in wxWindow::Refresh (this=0x85fc00, rect=0x0) at ../src/gtk/window.cpp:3717
#3  0x00007ffff75d9159 in wxGridCellEditor::PaintBackground (this=0x7e2a60, rectCell=..., attr=0x7e29c0) at ../src/generic/grideditors.cpp:263
#4  0x00007ffff75bdbec in wxGrid::DrawCell (this=0x772800, dc=..., coords=...) at ../src/generic/grid.cpp:5564
#5  0x00007ffff75bd80d in wxGrid::DrawGridCellArea (this=0x772800, dc=..., cells=...) at ../src/generic/grid.cpp:5497
#6  0x00007ffff75b138e in wxGridWindow::OnPaint (this=0x7a8e00) at ../src/generic/grid.cpp:1773

comment:11 in reply to: ↑ 10 Changed 2 years ago by oneeyeman

Replying to pcor:

The frame does not close because Refresh() is called from a paint event, causing continuous painting and blocking idle processing.

#2  0x00007ffff73a42fb in wxWindow::Refresh (this=0x85fc00, rect=0x0) at ../src/gtk/window.cpp:3717
#3  0x00007ffff75d9159 in wxGridCellEditor::PaintBackground (this=0x7e2a60, rectCell=..., attr=0x7e29c0) at ../src/generic/grideditors.cpp:263
#4  0x00007ffff75bdbec in wxGrid::DrawCell (this=0x772800, dc=..., coords=...) at ../src/generic/grid.cpp:5564
#5  0x00007ffff75bd80d in wxGrid::DrawGridCellArea (this=0x772800, dc=..., cells=...) at ../src/generic/grid.cpp:5497
#6  0x00007ffff75b138e in wxGridWindow::OnPaint (this=0x7a8e00) at ../src/generic/grid.cpp:1773

Paul,
Do you have a fix?

comment:12 in reply to: ↑ 10 Changed 2 years ago by vadz

Replying to pcor:

The frame does not close because Refresh() is called from a paint event, causing continuous painting and blocking idle processing.

We really need some way of detecting this in wx to prevent it from happening as this is not the first time we're bitten by this :-(

I must admit that in this particular case I don't quite understand how does it happen, looking at:

> #2  0x00007ffff73a42fb in wxWindow::Refresh (this=0x85fc00, rect=0x0) at ../src/gtk/window.cpp:3717
> #3  0x00007ffff75d9159 in wxGridCellEditor::PaintBackground (this=0x7e2a60, rectCell=..., attr=0x7e29c0) at ../src/generic/grideditors.cpp:263
> #4  0x00007ffff75bdbec in wxGrid::DrawCell (this=0x772800, dc=..., coords=...) at ../src/generic/grid.cpp:5564
> #5  0x00007ffff75bd80d in wxGrid::DrawGridCellArea (this=0x772800, dc=..., cells=...) at ../src/generic/grid.cpp:5497
> #6  0x00007ffff75b138e in wxGridWindow::OnPaint (this=0x7a8e00) at ../src/generic/grid.cpp:1773

Refresh() in the frame 2 is called on a different window, so why does invalidating a child results in a new call to the parent window OnPaint()? I do see that it does result in this, I just don't understand why.

Anyhow, I'll fix this by changing PaintBackground().

comment:13 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [72697]) Fix wxGrid editors background painting.

There were two fundamental problems: first, we painted on a separately created
wxClientDC instead of using the wxPaintDC already available in wxGrid. Second,
we invalidated the control while painting, resulting in endless repainting, at
least under wxGTK.

Fix the first problem by passing wxDC to wxGridCellEditor::PaintBackground()
and the second one by not refreshing the control from there as it just seems
unnecessary.

Also pass the attribute by reference for consistency with
wxGridCellRenderer::Draw() and because this pointer can never be NULL.

Closes #2628.

Note: See TracTickets for help on using tickets.