Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004732 [JEDI VCL] 00 JVCL Components minor always 2009-04-06 15:16 2009-08-05 16:05
Reporter gpcaretti View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version 3.36
Summary 0004732: TJvDesignSurface: when you click on the surface panel it does not focus
Description With D2007 when you click on a TJvDesignSurface surface panel it often does not focus on it.

Test case:
1. Run your application containing a TJvDesignPanel with the surface active
(eg. the JVCL official JvDesignerDemo app.)
2. Click in the surface form.
3. Check the value of the TJvDesignPanel.focused properrty. It is still False.
4. Soon after switch to another application window (e.g. switch from the demo
application to the Delphi IDE using Alt+Tab) and soon after switch again to
the demo application. Now the SetFocus works.

Additional Information Unfortunately the standard Delphi SetFocus not always works. I found several reference via google about it, but I didn't understand well the reason yet.

When you click on the panel of the TJvDesignPanel, the below procedure present in the JvDesignImp unit is correctly invoked but the "Surface.Container.SetFocus" instruction does not really set the focus on the panel

procedure FocusSurface;
begin
  if not Surface.Container.Focused and Surface.Container.CanFocus then
    Surface.Container.SetFocus;
end;

To verify it check via debugger the value of the properties JvDesignPanel.Focused or JvDesignPanel.Surface.Container.Focused:

To solve the problem I wrote a workaround for the above FocusSurface
procedure patching by myself the current 3.36 release:


  procedure FocusSurface;
  var
    WasActive: Boolean;
  begin
    if not Surface.Container.Focused and Surface.Container.CanFocus then
    begin
      // Gp added - Start
      // deactivate the container otherwise SetFocus does not work
      WasActive := TJvDesignPanel(Surface.Container).Active;
      if WasActive then TJvDesignPanel(Surface.Container).Active := False;
      Surface.Container.SetFocus; // original code line
      if WasActive then TJvDesignPanel(Surface.Container).Active := True;
      // Gp added - end
    end;
  end;

In the code I first force the deactivatation of the panel to be focused, then I focus it (invoking SetFocus) and later I reactivate it.
This trick is necessary because the standard method:
    TWinControl.SetFocus
calls the other standard method:
    TCustomForm.SetActiveControl(Control: TWinControl);
which skips to focus the control if it is already the current active one:
    if FActiveControl <> Control ...

Fell free to use this code if you need it.
Tags No tags attached.
Attached Files ? file icon JvDesignImp.pas [^] (38,287 bytes) 2009-04-06 15:16

- Relationships

-  Notes
(0015466)
obones (administrator)
2009-04-29 14:37

Why do you need the focus?
(0015503)
gpcaretti (reporter)
2009-04-30 10:52

The focus on the "Surface.Container" should be a normal behaviour when in Design mode: you click on one of the object into the panel, then you start to operate on it either with the mouse or the keyboard.
This was also the intention of your original source code at lines 854..858:

procedure FocusSurface;
begin
  if not Surface.Container.Focused and Surface.Container.CanFocus then
    Surface.Container.SetFocus;
end;

The problem is that the above code does not work well. To prove it do this test on Windows XP:

1. display a sourface with one or more object onto it
2. set it in Design mode (JvDesignPanel.Active := True)
3. Click on one of its objects (e.g. an image). A frame will appear around it.
4. Try to drag the object using the keyboard (Eg. Ctrl-Left).

You will see it does not work.

5. Leaving the test application running in the same status of pt. 4, switch to any other app. (e.g. pressing Alt-Tab)
6. Switch again to you test application (e.g. pressing again Alt-Tab).
7. Try again pt. 4.

Now the application works: you are able to drag!

The code I proposed attached to this issue, has the intention to fix this problem.
(0015746)
obones (administrator)
2009-07-03 11:44

I just tried with the latest release and I'm not seeing any problems under Delphi 2009. Could you confirm it now works?
(0015774)
gpcaretti (reporter)
2009-07-07 15:27

I re-tested it both with D2007 and D2009 on XP-SP3 env. and unfortunately it continues to work in the same wrong way.
To verify it follow the test modality explained above and, really important, never switch to another app. during the test until you do not arrive to pt. 5 of the test.

Modifying the source code changing the FocusSurface procedure with the code here below it works:

<--- CUT HERE --->
procedure FocusSurface;
var
  WasActive: Boolean;
begin
  if not Surface.Container.Focused and Surface.Container.CanFocus then
  begin
    // deactivate the container otherwise SetFocus does not work (WindoZe bug)
    WasActive := TJvDesignPanel(Surface.Container).Active;
    if WasActive then TJvDesignPanel(Surface.Container).Active := False;
    // now focus it
    Surface.Container.SetFocus;
    if WasActive then TJvDesignPanel(Surface.Container).Active := True;
  end;
end;
<--- CUT HERE --->
(0015804)
obones (administrator)
2009-07-09 13:47

Ok, there was an issue with moving any non handle control (TImage for instance) in the latest revision which I just fixed.
But I followed your steps exactly, not switching to any application in the mean time, I'm sorry, I'm not seeing the problem. Are you sure you are using the very latest SVN version?
(0015882)
gpcaretti (reporter)
2009-07-23 11:08

I don't know what to say. I just took the very last SVN version (yesterday).
So maybe it is a problem of my machine.

Anyhow I created a SWF demo using this very last SVN version.
Try to look at it:
 http://www.jurisweb.it/gp/JvDesignerDemo.htm [^]

Then, applying the above 'patch' it works even onto my machine.
(0015938)
obones (administrator)
2009-08-05 16:05

This is now in SVN

- Issue History
Date Modified Username Field Change
2009-04-06 15:16 gpcaretti New Issue
2009-04-06 15:16 gpcaretti File Added: JvDesignImp.pas
2009-04-06 15:17 gpcaretti Issue Monitored: gpcaretti
2009-04-29 14:37 obones Note Added: 0015466
2009-04-29 14:37 obones Status new => feedback
2009-04-30 10:52 gpcaretti Note Added: 0015503
2009-07-03 11:44 obones Note Added: 0015746
2009-07-07 15:27 gpcaretti Note Added: 0015774
2009-07-09 13:47 obones Note Added: 0015804
2009-07-23 11:08 gpcaretti Note Added: 0015882
2009-08-05 16:05 obones Note Added: 0015938
2009-08-05 16:05 obones Status feedback => resolved
2009-08-05 16:05 obones Fixed in Version => Daily / SVN
2009-08-05 16:05 obones Resolution open => fixed
2009-08-05 16:05 obones Assigned To => obones
2009-08-06 10:08 gpcaretti Issue End Monitor: gpcaretti


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker