# What is FrontEndAttachedCell?

Perhaps it's not accessible from the front end, but what is this so-called attached cell?

In[91]:= Names["**AttachedCell*"]

Out[91]= {"FrontEndAttachedCellParent", \
"PredictiveInterfaceDump$UseAttachedCells", \ "WebPredictionsPrivate$UseAttachedCells"}

-
The title of your question does not seem to be related in any way to body of your question. The title is too broad to be a good question. The body is obscure; what motivated you to search on "**AttachedCell*"? – m_goldberg Nov 13 '15 at 4:15
Oh I was just guessing from some spelunking that attachedcells are the mechanism it uses. – M.R. Nov 13 '15 at 4:23
@m_goldberg fixed the title. – Kuba Nov 13 '15 at 9:10

## Intro

One day I was playing with Developer package and found DateSetter which uses some kind of floating elements that I found useful.

After taking a look at a source code I found out it was FrontEndAttachedCell. From the code one could learn enough to create something useful:

## Usage

FrontEndAttachCell[
parentObject,             (*Box or Cell Object*)
attachedCellBoxes,
{Automatic, {Left, Bottom}}, (*1*)
{Left, Top},                 (*2*)
"ClosingActions" -> {...}    (*3*)
]

1. I don't know what an Automatic is there for but the second part is setting alignment anchor point in the parentBoxObject
2. alignment anchor point in the attached cell
3. "The ClosingActions determines actions which automatically dismiss the attached cells". Available actions: "ParentChanged", "EvaluatorQuit", "OutsideMouseClick", "SelectionDeparture", "MouseExit".

I couldn't figure everything out by myself so let's quote John Fultz whom I've asked about details:

• Kuba:

[...]

1. I'm aware it is undocumented but I'm curious if it is stable. [...]

2. Can you give me any insight in "ClosingActions"? [...]

3. Can I AttachCell for DockedCells elements? [...]

• John Fultz:

1. Yes, this functionality is used all over the place. At some point, it'll graduate to a System level function, but even when it does, we'll probably maintain backward compatibility with the current stuff.

2. The "ClosingActions" determines actions which automatically dismiss the attached cells. You can manually dismiss a cell by doing NotebookDelete on the attached cell's CellObject. But there are some circumstances where it's much easier to let the system do it for you. It can be a list of any of the following:

"SelectionDeparture" -- if the selection leaves the parent, the attached cell, or any of the attached cell's children (the selection might be in the attached cell if the attached cell has InputFields).

"ParentChanged" -- if any change is made to the parent of the attached cell

"MouseExit" -- if the mouse leaves the region of the attached cell

"OutsideMouseClick" -- if a click happens anywhere outside of the attached cell. This includes clicks of the right and middle mouse buttons.

1. Yes, that works, too. Except that the docked view will clip attached cells, so if the attached cell doesn't live fully within the docked view, it may not be very useful.

## My example:

attachTo[parentbox_] := MathLinkCallFrontEnd[
FrontEndAttachCell[
parentbox,
ToBoxes[ExpressionCell[
EventHandler[Panel["floating panel"],
"MouseExited" :> (NotebookDelete[ParentCell[EvaluationBox[]]];)
],
StripOnInput -> True, Background -> White,
CellFrameColor -> LightBlue, CellFrameMargins -> 0, CellFrame -> 2
]],
{Automatic, {Right, Bottom}},
{Left, Top},
"ClosingActions" -> {"ParentChanged", "EvaluatorQuit",  "OutsideMouseClick"}
]]

DynamicModule[{parentBox, attachedCell},
EventHandler[
Panel["test"],
{ "MouseEntered" :> (
NotebookDelete @ attachedCell;
attachedCell = attachTo[parentBox];
)}
],
Initialization :> ( parentBox = EvaluationBox[]; )
]


Notice that I'm not using "MouseExit" closing action but an EventHandler + NotebookDelete. That's because if the initial position of the attached cell is away from cursor then it won't appear at all.

## Possible issues

• the tricky thing is to get the parentBoxObject.
• it's not the same as e.g. menu in PopupMenu since attached cell is restricted to notebook area only while the menu is able to be outside.
-
Thank you very much for the canonical answer (as always) :) – M.R. Nov 13 '15 at 21:34
@M.R. You are welcome, and thanks for another interesting question :) – Kuba Nov 13 '15 at 22:00
+1 Thanks for the digging Kuba! I was waiting for this kind of interactive floating element for years now. Didn't realize that DateSetter had it. – István Zachar Nov 14 '15 at 9:21
@IstvánZachar No problem, I have just recently found it too. I hope this post will generate many topics with nice GUI based on this. – Kuba Nov 14 '15 at 9:25
Aren't you missing an assignment as attachedCell = attachTo[parentBox] within the parent's EventHandler? – István Zachar Dec 13 '15 at 16:25