Recently I was told I did not know what I was talking about when I noticed a change in focus seemingly could not occur while a file drag was happening in Cocoa. Ignorance is not a sin, and only idiots could pretend knowing everything. So the only conclusion was that I needed to learn more about that wondrous aspect of things.
I maintain that it is impossible to change the focus in a Cocoa app while a file is dragged, after numerous experiments setting the focus to different controls while the file drag was happening, both in DragEnter and via a timer or via MouseMove or MouseEnter. In all these cases, the Focus Ring did not appear before the file was actually dropped and the file drag operation ended.
Nevertheless, I recall having witnessed applications showing a box around a control when a file drag occurred, as soon as the dragged object hovered over the control. Lately, I noticed the App Wrapper window showed a blue frame when an app was dragged over.
I had made the hypothesis that the Focus Ring not switching was a Cocoa issue, so I ran the same project I had made for Cocoa in Carbon mode and made two discoveries.
- SetFocus in DragEnter immediately creates a focus ring around the focused control : Canvas, TextField
- Even without any additional code but an AcceptFileDrop, a Canvas or a BevelButton shows a box around the frame the instant a file is dragged over. But it is not a focus ring ! It is a 2 pixels wide GREY rectangle along the border of the canvas, akin to what I used to do in DragEnter as workaround. I tried to look around for the exact terminology, but could not find anything so I call that “drag border”. Here is how it looks. Once again, no code in DragEnter at all. It is obvious this is not a focus ring, as the Textfield above the canvas exhibits a splendid Focus Ring, while the canvas shows the drag box.
Cocoa does not have a drag border, at least in Xojo. Some brilliant minds may locate in Apple documentation that feature, but in the meantime, applying a workaround to emulate Carbon behavior looks fair to my modest comprehension… I may not know much, but I place providing appropriate functionalities to the user above being always right.