Opened 5 years ago

Closed 5 years ago

#14958 closed defect (fixed)

wxGrid editor broken in latest SVN

Reported by: hackish Owned by: vadz
Priority: blocker Milestone: 2.9.5
Component: wxGrid Version: stable-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no


I'm not sure when this was broken but I updated my build to SVN revision 73350 and noticed that the MSW wxGrid editor no longer displays. I built the wxgrid sample to verify and indeed it is broken there too.

Steps to reproduce:
build from latest SVN version.
build wxgrid sample
run wxgrid sample

Click cell, 2,1 twice
You will see Cell editor shown. Even though nothing is visible.
Type some random text and hit enter. You can see that the editor is doing something just not displaying.

I also had someone on IRC build/test using GTK/Linux and reported no issues so I believe this is MSW specific.

Change History (10)

comment:1 Changed 5 years ago by hackish

I have verified that the 2.9.4 release works correctly. I also tried pulling down revision 72696 which contained the last set of changes committed to grideditors.h/cpp but the problem was still present in that version.

Since I don't understand the GUI code well enough I'm not really able to make additional headway in narrowing down why it's not working.

comment:2 Changed 5 years ago by vadz

  • Milestone set to 2.9.5
  • Status changed from new to confirmed

Removing wxTE_RICH2 (see r64646) does show the text control but the caret in it is still not shown so it's not really a solution neither. Moreover, I'm pretty sure that it did work since that change.

It would be really nice if someone could run a bisection since 2.9.4 to find out which revision broke this exactly because right now I have absolutely no clue. TIA for your help!

comment:3 Changed 5 years ago by johnr

I didn't bisect but adding grid->SetDefaultEditor( new wxGridCellAutoWrapStringEditor ) works so wxTextCtrl seemed the logical place to look for single line control problems.

src/msw/textctrl.cpp revision 73126 is the problem.
Regards, John

comment:4 follow-up: Changed 5 years ago by vadz

Thanks John! Pretty weird that setting margins breaks it like this but at least now we know we can revert r73126 to fix it. I wonder if calling SetMargins(0) could be enough to fix the problem in wxGrid?

comment:5 in reply to: ↑ 4 ; follow-up: Changed 5 years ago by johnr

Replying to vadz:

I wonder if calling SetMargins(0) could be enough to fix the problem in wxGrid?

Debugging this isn't helped by the text written to sample cell 0,0 containing x 2 "\n" and then being edited in a non wrap editor. Bad idea as we lose anything after the first "\n" instance when editing.

Using SetMargins(0) call in wxGridCellTextEditor::DoCreate after the textbox is created is no help. It is marginally improved if used in wxGridCellTextEditor::DoBeginEdit in that the first line (pre "\n") in sample cell 0,0 shows and is highlighted. Try it in a cell where the text width <= cell width and see the edited text is not visible. Scroll the cursor left and the text comes into view ? implying a negative left margin, large right margin or odd cursor position. Text is also truncated.

Seems to work better but still not well when called after control size and position is determined.

There is another pre-existing problem. When the editor is shown for both the single line editor and the wrap editor, the text is selected as expected, but the cursor is not shown until the text is deselected, at least in MSW.

In fact in DoBeginEdit, using


results in the cursor showing at the beginning of the edited text for the standard text editor in sample cell 0,0 because wxTextEntry::GetLastPosition() always returns 0.

comment:6 in reply to: ↑ 5 Changed 5 years ago by johnr

After spending a little more time on this I see in src/msw/textctrl.cpp that using

::SendMessage(GetHwnd(), EM_SETMARGINS,
                      EC_LEFTMARGIN | EC_RIGHTMARGIN,

works just fine. Edited grid cell text is highlighted and remains on screen with caret movements left or right.

Using MAKELPARAM(EC_USEFONTINFO,MAKELPARAM) sets large margins at least in the grid editor.

SetMargins( 3 ) results in text scrolling rather than the caret. The cause of all this when using SetMargins( 3 ) or SetMargins( wxPoint(3,3)) is that textentry.cpp 952 wxTextEntry::DoSetMargins only sets the left margin so SetMargins(3) helps but leaves the large right margin.

comment:7 Changed 5 years ago by vadz

  • Owner set to vadz
  • Status changed from confirmed to accepted

I see the problem. In spite of what the documentation says, EC_USEFONTINFO can't be used in lParam with rich edit controls. So we just need to use EM_SETMARGINS differently for them and this does fix the problem for me.

The default margin is too big for the grid in place editor though so I'll also add SetMargins(0) call. But it's just cosmetic, it works even without it.

Sorry for the bug and thanks for debugging it!

comment:8 Changed 5 years ago by VZ

(In [73390]) Set both left and right wxTextEntry margins in wxMSW.

Use the horizontal margin argument of SetMargins() to set both left and right
margins in wxMSW and not just the left one.

See #14958.

comment:9 Changed 5 years ago by VZ

(In [73392]) Don't use margins for wxGrid in place text editor controls.

The default non-zero (at least under MSW) margins don't look well inside
wxGrid, don't waste space on them.

See #14958.

comment:10 Changed 5 years ago by vadz

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

Fixed by r73391 (which used the wrong ticket number so it wasn't closed automatically).

Note: See TracTickets for help on using tickets.