Jump to content


Photo

Strange behaviour with SelectRow and Modal forms


  • Please log in to reply
25 replies to this topic

#21 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 01 February 2007 - 11:41 PM

Hello Deon,

I have other issues on my to-do list and as you may see one by one is solved. I have work on your issues, but I have stuck on it and have to go on other until I return on it. This issue is connected on very strange way with other parts of components and this give me a trouble.

I will take a one more look on it.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#22 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 02 February 2007 - 12:47 PM

Hi Boki

I have sent fixes for all the following issues to your e-mail.

The following changes are included:

Missing MouseUp Events:
These problems are due to the fact that the grid sometimes misses the second MouseUp of a DblClick. This happens if a modal form is opened in the DblClick procedure.

My thinking here is simple: Never assume that you will get a MouseUp after a double-click.

Double-clicks are obviously four clicks. The first MouseDown should set anything that needs to be set on the grid state etc., and the first MouseUp should unset it all again. The second MouseDown is only there to initiate a double-click. The second MouseUp serves absolutely no purpose at all and should be treated like it doesn’t exist.

Since there is no guarantee that you will ever get the second MouseUp, you should never set any state information in the second MouseDown in the first place.

The sequence should be:

MouseDown: Set anything you need to set
MouseUp: Unset anything that was previously set.
MouseDown: Initiate DblClick (and nothing else)
MouseUp: Nothing to do.

I have changed the MouseDown procedure in NxCustomGrid.pas accordingly, and now everything works fine.
The grid will always get at least one MouseUp to unset state information, but will never set any state information in the second MouseDown.

If you now show a modal form in the DblCLick event:

headers are repainted properly
any state information that was set is first unset
after the modal form is closed, headers will react to the first click (not the second like they used to)
DblCLicks on the header will now also only sort the column once (like they're supposed to) since the second MouseDown is ignored.
DblClicks on the header will not fire the HeaderDblClick event is the user is double-clicking on the header to AutoSize the column.

Repainting of Headers:
The headers are painted “Hot� if the FHoverColumn is assigned. FHoverColumn is set in the MouseMove event and is unset again in either the CMMouseLeave or WMKillFocus events. If you double-click on a header that is already “hot� and you then open a modal form, the mouse never "leaves" the header, so the CMMouseLeave is never called and the header stays “hot� even though the mouse is now on another form. WMKillFocus only unsets the FHoverColumn but does not repaint the headers.

This is easily fixed simply by calling RefreshColumn(Index, gaHeader) for each of the columns at the end of the WMKillFocus procedure.

HeaderDblClick
The procedure you have in HeaderDblClick will not work if you open a modal form in the DblClick event. If you DblClick on the header, the “inherited� DblClick will fire first. If you open a modal window in the DblCLick event the mouse is no longer over the header (it is now on the modal form). After the inherited DblClick (when you check to see if the mouse is in the header) the mouse has already moved, and the HeaderDblClick is therefore never called.

This is fixed by moving the checking of the mouse position to the MouseDown event. If ssDouble is in the Shift state, we can check where the mouse is and call either the DblClick or HeaderDblClick procedure directly, and then exit from the MouseDown procedure immediately.

If the programmer wants the two events to be linked (as was your original intention) he can link them in the object inspector, or he can just call the DblClick procedure himself before executing his own code in the HeaderDblClick procedure.

Hope this helps

Regards,

Deon

#23 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 05 February 2007 - 02:39 PM

Hi Boki

I have downloaded the newer version of V3.9.7 and it is a lot better now. Thanks.

I see that you have included some of my changes, but not all of them. There are still some problems with the way you have it now.

1. The OnDblClick event will be triggered if a user tries to AutoSize the column be double-clicking on the seperator between two columns in the header. If there is any code in the OnDblClick procedure, that code will execute first before the column is auto-sized (I guarantee you this is going to cause problems).

2. The OnDblClick event will still be triggered before the OnheaderDblClick event is triggered. The programmer will have to write his own code in the DblClick procedure to check if the mouse is in the header area, and suppress the DblClick event manually. To me, this contradicts the whole purpose of having a OnHeaderDblClick event in the first place.

I still thnik that you should override the inherited DblClick procedure and then use the following logic:

CODE
procedure NxCustomGrid.DblClick;
begin
  if (mouse is on column divider) then
    //autosize column only - don't execute dblclick code
  else if (mouse is on column header) then
    //execute only headerdblclick
  else
    inherited; //execute normal (body) dblclick
end;


This last one is not critical - it's is only cosmetic.

3. The header of a column that was double-clicked still stays "hot" if the grid loses focus. At least now it is only one column, but it is still not right. I understand that you don't want to repaint all the headers every time the grid loses focus. Why not add a 1-byte "state" variable to each column then? When the grid loses focus you can run through all the columns and check if any were left "hot", and then repaint only those ones.

CODE
  if Columns.Count > 0 then
    for I := 0 to Pred(Columns.Count) do
      if Columns[I].State in [csHot, csDown] then
        begin
          Columns[I].State := csNormal;
          RefreshColumn(Columns[I], gaHeader);
        end;


Regards,

Deon

#24 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,195 posts
  • Gender:Male

Posted 22 February 2007 - 02:39 AM

Hello Deon,

I am again on this problem.

About DblClick logic;

What do you think about having one more event named OnRowDblClick and then let a DblClick clean?

About refresh issue;

I have use next code:

CODE
  if goHeader in Options then
  begin
    if Assigned(FHoverColumn) then
    begin
      FOldHoverColumn := FHoverColumn;
      FHoverColumn := nil;
      FOldHoverColumn.Refresh(gaHeader);
    end;
  end;


It seems that it work fine.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#25 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 22 February 2007 - 01:37 PM

Hi Boki

Do you mean that you want to remove the inherited DblClick completely, and then have a DoHeaderDblClick and DoRowDblClick procedure that is called from the OnMouseDown?

I guess that will also work fine. Just remember that you must not call OnHeaderDblClick if the user is double-clicking on the header to auto-size a column.

The new FHoverColumn routine also looks like it should work fine. I will test it again completely when I get the new version.

Thanks

Deon

#26 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 15 March 2007 - 10:47 AM

Hi Boki

I have checked the latest version - it's still the same.

1) The OnDblClick event is still triggered when you double-click on the header.
2) The OnDblClick event is still triggered when you auto-size a column by double-clicking on the header (big, big problem).

Why do you want the OnDblClick to be triggered when the user double-clicks on the header? I have thought about it, but I can't think of any reason why someone would want it like that. Can you explain to me a bit more what your thinking is around this?

Thanks

Deon




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users