Opened 4 years ago

Closed 16 months ago

Last modified 12 months ago

#11681 closed defect (fixed)

Text edit cursor disappears

Reported by: smh Owned by:
Priority: normal Milestone: 2.9.5
Component: wxGrid Version: stable-latest
Keywords: Text editing cursor Cc:
Blocked By: Blocking:
Patch: no

Description

The text edit cursor is present when the first cell is selected but disappears when a different cell is selected.
Happens on Windows Vista and W7 in the grid sample.
Compiled with MSVC 2008 express.

Change History (18)

comment:1 Changed 4 years ago by vadz

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

Thanks for reporting, I see this too. Really no idea why does this happen but it definitely looks very bad and needs to be fixed. Any help with debugging where does the cursor go would be very welcome.

comment:2 Changed 4 years ago by VZ

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

(In [63383]) Extract wxSTOCK_WITHOUT_ELLIPSIS from wxSTOCK_FOR_BUTTON.

Make it possible to use this flag on its own, without wxSTOCK_WITH_MNEMONIC
which is also part of wxSTOCK_FOR_BUTTON. This can be useful for e.g. toolbar
buttons.

Closes #11681, #11682.

comment:3 Changed 4 years ago by vadz

  • Resolution fixed deleted
  • Status changed from closed to reopened

Sorry, please disregard the previous comment, I made a typo in a ticket number, this commit doesn't apply to this bug.

comment:4 Changed 4 years ago by vadz

  • Status changed from reopened to confirmed

comment:5 Changed 4 years ago by _Cool-

If I understand correctly, this bug can be solved by adding a flag wxTE_RICH2 in style | = wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER in wxGridCellTextEditor::DoCreate

comment:6 Changed 4 years ago by smh

Yes, that clears the problem for me

comment:7 Changed 4 years ago by vadz

  • Milestone changed from 3.0 to 2.9.1

Thanks for finding this work around! We'll probably do this just because this really needs to be fixed but if anybody could just also tell me why does this work (and the current code doesn't), it would be really great...

comment:8 Changed 4 years ago by VZ

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

(In [64646]) Use wxTE_RICH2 for in-place wxGrid text editor control.

This works around a bug with the plain text edit control under MSW which seems
to totally lose its caret when we hide it and show it again for another cell.

This is not a proper fix for the problem, of course, but at least it does
allow to edit wxGrid cells in the meanwhile.

Closes #11681.

comment:9 Changed 16 months ago by bouke

  • Resolution fixed deleted
  • Status changed from closed to reopened

Adding wxTE_RICH2 on OSX produces a TextCtrl with a scrollbar, also the blue-ish highlight is missing. As the workaround is targeted for Windows, can it only be applied on that platform? I tested it without wxTE_RICH2 on OSX, and the result is a much nicer text input.

With wxTE_RICH2: http://i.imgur.com/t7Bfr.png

Without wxTE_RICH2: http://i.imgur.com/J8ajb.png

comment:10 Changed 16 months ago by fsenore

This is related to
http://trac.wxwidgets.org/ticket/14042

It might be a matter of taste, but please do not restore the blue focus ring around a grid cell. No other program does it.

comment:11 follow-up: Changed 16 months ago by vadz

  • Milestone changed from 2.9.1 to 2.9.5

OK, I'll make r64646 MSW-only.

Concerning the focus rectangle under OS X, I do think it should be shown when editing it, why not?

comment:12 in reply to: ↑ 11 Changed 16 months ago by fsenore

Replying to vadz:

OK, I'll make r64646 MSW-only.

Concerning the focus rectangle under OS X, I do think it should be shown when editing it, why not?

Because spreadsheets do not show a focus ring when editing a cell, and from a user's point of view wxGrid is a small spreadsheet.

wxWidgets is all about using native controls and having a native look. IMHO having a focus ring when editing a cell is a really alien thing, not a native one: it screams "not a standard Mac app!" and it looks like Mac users are very sensible to those arguments.

comment:13 Changed 16 months ago by VZ

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

(In [73294]) Don't assume that wxTE_RICH(2) implies wxTE_MULTILINE for wxTextCtrl in wxOSX.

Under MSW single line text controls can still use these styles, so don't
assume that the control should be made multi-line just because one of them is
specified.

This fixes the appearance of the in-place text control in wxGridCellTextEditor
which is created with wxTE_RICH2 style to work around some wxMSW problem.

Closes #11681.

comment:14 Changed 12 months ago by vadz

Unfortunately r64646 results in other problems, see #15162, so we really need to find another solution to the original problem.

Does anybody know when did this happen for the first time? I.e. had it worked before? And if so, what was the last version that worked?

comment:15 Changed 12 months ago by vadz

The really annoying thing is that I can't reproduce the problem outside of wxGrid, e.g. with this patch

  • samples/minimal/minimal.cpp

    a b bool MyApp::OnInit() 
    141141// main frame 
    142142// ---------------------------------------------------------------------------- 
    143143 
     144#include "wx/tglbtn.h" 
     145 
     146wxTextCtrl* g_text; 
     147 
     148void OnToggleVisibility(wxCommandEvent&) 
     149{ 
     150    if ( g_text->IsShown() ) 
     151        g_text->Hide(); 
     152    else 
     153    { 
     154        g_text->SetSize(5, 5, 100, 25); 
     155        g_text->Show(); 
     156        g_text->SetValue("Shown back"); 
     157        g_text->SetInsertionPointEnd(); 
     158        g_text->SelectAll(); 
     159        g_text->SetFocus(); 
     160    } 
     161} 
     162 
    144163// frame constructor 
    145164MyFrame::MyFrame(const wxString& title) 
    146165       : wxFrame(NULL, wxID_ANY, title) 
    bool MyApp::OnInit() 
    167186    SetMenuBar(menuBar); 
    168187#endif // wxUSE_MENUS 
    169188 
     189    g_text = new wxTextCtrl(this, -1, "Text", wxPoint(5, 5), wxDefaultSize, 
     190                            wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | 
     191                            wxNO_BORDER); 
     192    g_text->SetMargins(0, 0); 
     193    new wxToggleButton(this, -1, "Show/hide", wxPoint(5, 40)); 
     194    Bind(wxEVT_TOGGLEBUTTON, OnToggleVisibility); 
     195 
    170196#if wxUSE_STATUSBAR 
    171197    // create a status bar just for fun (by default with 1 pane only) 
    172198    CreateStatusBar(2); 

everything works just fine even though I tried to call exactly the same wxTextCtrl methods as the grid code calls. I wonder what am I missing here...

comment:16 Changed 12 months ago by mmarsan

I think the problem has nothing to do with wxTextCtrl. IMHO it's a wxGrid feature.

When you change the cell, only the ring around the current cell is drawn, but the [new] editor is not shown. Because there's no editor active, there's no cursor for a non-editable window.

Perhaps some sort of ShowEditorOnArriveToCell(false/true) may be added, like any other attribute for cells/columns/rows.

comment:17 Changed 12 months ago by vadz

OK, the real culprit is r58969, we need to let the native control have WM_KILLFOCUS. The trouble is that the comment added by this revision there hints that just calling event.Skip() can result in a crash so I'll need to do something more complex to fix it, but at least now I know what the problem is.

comment:18 Changed 12 months ago by VZ

(In [73876]) Really fix the problem with caret in wxGrid text editor under MSW.

The problem (see #11681) was due to not allowing the native control handle the
focus loss event. This, in turn, was due to the changes of r58969 which tried
to work around a crash which happened if the grid was destroyed from the code
of one of the user-defined event handlers called during the editor dismissal.

Fix both problems at once by calling event.Skip() in OnKillFocus() to let the
native handler have the event too and postponing the editor dismissal a little
by calling DisableCellEditControl() indirectly from a posted event handler
instead of immediately.

As this reverts the now unnecessary changes of r64646, it closes #15162.

Note: See TracTickets for help on using tickets.