Recent

Author Topic: [SOLVED] TStringgrid popup menu overridden by default popup if cell selected  (Read 9094 times)

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
In my stringgrid I set different PopupMenus in an OnContextPopup event depending on which cell is selected.  This pops up the correct menu when right-clicking on unselected cells, but on selected cells the default menu pops up.  I've tried trapping the right-click in other events with no luck.  I suspect the cell editor is causing this behavior.  Is my suspicion correct?  If so, how do I create and assign a different text editor?  There are a couple of additional features I'd like to have anyway.

Gary
« Last Edit: July 10, 2015, 11:28:43 pm by Gary Randall »
Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #1 on: December 15, 2014, 11:46:56 pm »
The default cell editor is based on the underlying OS widgetset editor. So when the mouse is within the widgetset editor in the currently selected cell, the OS widgetset editor swallows the right-click before Lazarus even sees it, and shows the OS editor context menu.
Although you can set alternative cell editors in a Lazarus grid, you will probably find they are all ultimately based on the same OS widget, and so will all exhibit the same behaviour.
Maybe a Lazarus developer (Bart? Jesus?) who maintains these controls will know a way to alter this behaviour without having to write an OS-independent custom-drawn editor that could be an alternative cell editor for you to use.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #2 on: December 16, 2014, 03:38:34 am »
I suspect the cell editor is causing this behavior.  Is my suspicion correct? 
Yes.

If so, how do I create and assign a different text editor?
Use OnSelectEditor event of the grid to change the pop-up menu of the default Editor, or assign your customized editor to it.

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #3 on: December 16, 2014, 05:29:58 am »
Thanks Howard and engkin.  I studied up on OnSelectEditor and custom editors.  Easier to implement than I thought it would be.  A TMemo has all the editing features I need, including a PopupMenu, - but when I implemented it the default popup overrode the TMemo popup.  So it appears Howard's thoughts are right on.  No matter what event I tested to capture the right-click, they all failed if the cell was previously selected.

Any solution will have to work on cross-platforms.  That will probably make it difficult.  Should I enter this as a bug?

Gary

Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #4 on: December 16, 2014, 04:32:45 pm »
I don't seem to have the problem on my computer. My grids.pas file is dated May 7, 2013. I suggest you upload a sample app here so other members can confirm the problem, then the same example could be used in a bug report.

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #5 on: December 17, 2014, 04:47:15 am »
Thanks engkin for testing this on your system.  I'm encouraged that it works for you.  I'll make a little test program that we can try.  It may take a few days with the Christmas season on us.

Gary
Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #6 on: December 17, 2014, 11:20:24 am »
I opened a bugreport for it.
http://bugs.freepascal.org/view.php?id=27171

Bart

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #7 on: December 17, 2014, 01:08:02 pm »
Thanks Bart.

Quote
function TCustomGrid.GetDefaultEditor(Column: Integer): TWinControl;
...
    // by default do the editor setup here
    // if user wants to change our setup, this can
    // be done in OnSelectEditor
...

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #8 on: December 17, 2014, 11:11:07 pm »
See the disccussion in the bugtracker.

Bart

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #9 on: December 18, 2014, 02:58:58 am »
Thank you, Bart.

Shouldn't any changes be before calling OnSelectEditor, and specifically inside GetDefaultEditor as explained in the comment quoted above?

Preparing the editor before calling OnSelectEditor makes it possible to customize everything, including the pop-up menu used in the editor.
« Last Edit: December 18, 2014, 03:03:35 am by engkin »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #10 on: December 18, 2014, 08:31:25 pm »
Pleas post comments/suggestions in the bugreport (make my life a little easier  O:-) )

Bart

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
This bug was fixed in Version 1.4.0
Thanks everyone!
Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

Mr.Paul

  • New Member
  • *
  • Posts: 29
  • 一次编写,到处编译
Re: TStringgrid popup menu overridden by default popup if cell selected
« Reply #12 on: November 26, 2017, 06:14:55 am »
I think this topic is related to my problem, the bug was fixed in 1.4, but I did not understand how to solve my problem at Lazarus 1.8RC4.

I made a new post here: http://forum.lazarus.freepascal.org/index.php/topic,39069.0.html

The default cell editor is based on the underlying OS widgetset editor. So when the mouse is within the widgetset editor in the currently selected cell, the OS widgetset editor swallows the right-click before Lazarus even sees it, and shows the OS editor context menu.
Although you can set alternative cell editors in a Lazarus grid, you will probably find they are all ultimately based on the same OS widget, and so will all exhibit the same behaviour.
Maybe a Lazarus developer (Bart? Jesus?) who maintains these controls will know a way to alter this behaviour without having to write an OS-independent custom-drawn editor that could be an alternative cell editor for you to use.
« Last Edit: November 26, 2017, 06:32:43 am by Mr.Paul »

jamie

  • Hero Member
  • *****
  • Posts: 6131
I just noticed a Context popup that wasn't there in one of my other programs today, after testing The

fix is to implement the OnContextPopUp and set the Handled Property to True.

 In my case it was the Tscrollbar was poping up the Windows 10 Context Menu that wasn't there
before in the past.
 
 The Grid, Edit, ScrollBars ect have this property, you should try it out.

EDIT:
 I did find a work around for your specific issue of the CellEditor not showing the default
context menu if you have a Popup menu assigned while in Editing mode.
 If involves a couple of steps to indentify editor in use during the OnContextPopup event
return as HANDLED and make your choice of popping up the menu..

 Check back if you still have issues.

« Last Edit: November 26, 2017, 05:44:14 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018