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;
  if not Surface.Container.Focused and Surface.Container.CanFocus then

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;
    WasActive: Boolean;
    if not Surface.Container.Focused and Surface.Container.CanFocus then
      // 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

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:
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
obones (administrator)
2009-04-29 14:37

Why do you need the focus?
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;
  if not Surface.Container.Focused and Surface.Container.CanFocus then

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.
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?
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;
  WasActive: Boolean;
  if not Surface.Container.Focused and Surface.Container.CanFocus then
    // 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
    if WasActive then TJvDesignPanel(Surface.Container).Active := True;
<--- CUT HERE --->
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?
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: [^]

Then, applying the above 'patch' it works even onto my machine.
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