Passing mouse related events broken by Deploy / Deployed->True

The problem seems to be that a TagBox that is generated is handled incorrectly by the front end. The TagBox has the form TagBox[bigExpr, Deploy, DefaultBaseStyle -> "Deploy"]. In this expression the second argument Deploy is quite meaningless. I couldn't trace any further than this TagBox as I cannot see how the front end handles it.

How the kernel handles Deploy is not secret. You can remove the attribute ReadProtected from Deploy to see how it is handled. The definition is quite simple. It refers to WrappersDump'WrapperToBoxes, which always continues using the following definition

WrappersDump`WrapperToBoxes[Deploy[BoxForm`e_],BoxForm`fmt_]:=
TagBox[MakeBoxes[BoxForm`e,BoxForm`fmt],Deploy,DefaultBaseStyle->"Deploy"]

This is where the evil TagBox is created. The way this is coded also seems to generate some unnecessary tests, but that is a different matter.

Workaround

Anyway, a workaround is to never generate such TagBoxes and generate inline cells instead. You can use deploy below instead of Deploy.

deploy /: MakeBoxes[deploy[expr_], form_] := 
 Cell[BoxData[MakeBoxes[expr, form]], Selectable -> False, Deployed -> True]

This then gives you what you want

deploy@
 Graphics[{Dynamic[{If[CurrentValue["MouseOver"], Red, Blue], 
     [email protected], Line[{{0, 0}, {.5, 0}}]}], 
   Dynamic[{If[CurrentValue["MouseOver"], Red, Blue], 
     Disk[{.5, 0}, .2]}]}, PlotRange -> {{0, .6}, {-.3, .3}}]

It is basically doing what you were doing you were doing yourself :), maybe you thought of inline cells already.

By the way, because the definitions of Deploy are known, redefining Deploy by Unprotecting it should be quite predictable. Note that not every symbol that is ReadProtected shows all of its code, but I think Deploy does.


Quick fix is to add

 ContentSelectable -> False, ImageSize -> Dynamic[Automatic, None]

to Graphics options. Now the it is behaving well with exeption of orange frame that appears to allow you to change ImageSize, which is supressed by Dynamic[#, None].


More generic approach

Something strange is happening. When we set Deployed -> True and Selectable -> False for the cell it is working like one is expected. Why not with Deployed then?

Keep in mind it is not general solution since you can Deploy individual parts of the cell while this will set those options for the whole cell.

Composition[
  CellPrint,
  Cell[#, "Output", Deployed -> True, Selectable -> False] &,
  BoxData,
  MakeBoxes
  ][
    Graphics[
     {Dynamic[{If[CurrentValue["MouseOver"], Red, Blue], 
               [email protected], Line[{{0, 0}, {.5, 0}}]}], 
      Dynamic[{If[CurrentValue["MouseOver"], Red, Blue], Disk[{.5, 0}, .2]}]}, 
      PlotRange -> {{0, .6}, {-.3, .3}}]
   ]

I reported this to WRI tech support on March 9th and, finally received an answer today. As I promised in a comment to the question, here it is (somewhat edited).

My apologies for the delay in getting back to you.

Just wanted to let you know that I was unable to find a resolution for this issue and have forwarded an incident report to the development team.

We will keep you posted if a resolution becomes available in a future release of Mathematica. Sorry we could not offer a more satisfactory resolution.

It appears to me the tech support person who handled my report thought that Kuba's finding was a correctable error or had a simple work around and tried to come up with a solution, but failed, and finally reported the problem to the developers as a bug, which is what my report suggested.