Adds code in `initWithData` to infer document format for RTF, HTML, and plaintext documents.
Additionally refactors NSAttributedString to use the correct attribute types as described in Apple's documentation.
Fix issue where a layout manager's NSTextStorage could be `nil` at initialization
but later set by introducing the `_setTextStorage:` method to NSTextView.
Add stubs a for missing properties in NSTextView.
Refactor `firstTextView` to properly find and return the first text view,
or `nil` if there are no text views.
Use 64-bit ready types where applicable.
Relocate unrelated code from _setTextStorage
The refactoring to use NSMapTables isn't arbitrary, it's required for
Xcode: Xcode accesses these map tables via the `*Table` properties and
inserts and removes objects in them at its discretion.
Note this means the map tables also have to use the same key and value
options that Apple uses in order to remain compatible,
so don't change these without a good reason.
This fixes the massive memory leak that was presented with the old code
that could cause the memory usage to reach over 2GiB in under 5 seconds
(while running at 60fps). There still seems to be another memory leak
present, but it's much smaller by comparison (increases by about 0.3MiB
every second when running at 60fps).
In its current state, I consider this code to be experimental and
unstable. The biggest problem is that there's currently a HUGE memory
leak somewhere (over 2GiB in under 5 seconds at 60fps). I'm committing
what I have now since I don't feel like debugging that right now and it
*does* technically work as-is.
The current approach is not great for performance: first, we render to a Metal/Vulkan
texture in the desired format then blit that to an RGBA Metal/Vulkan
texture shared with
OpenGL. Then, we copy *that* to another OpenGL texture in CAMetalLayer
to use as the content for the layer (we can't keep the drawable's OpenGL
texture, since that has to be recycled). Finally, this is rendered to a
subwindow by CARenderer/CALayerContext. We cannot get rid of the last copy
since we must render to the subwindow somehow and it's the easiest
way to play nice with sublayers. I also don't think we can get rid of the
first copy since OpenGL doesn't support some of Metal/Vulkan's texture
formats; plus, we can't share optimally tiled images between Vulkan and
OpenGL with some vendors' drivers (e.g. AMD).
We *could* get rid of the second copy if we were able to accurately
determine when the content is finally presented; then we could simply
keep the drawable in-use, render it to the subwindow when asked to, and
release it once we know the render is complete.
Those types of alerts have a different set of NSModalResponse.
This fix alerts not working in The Blockheads Server and any other app also using that method.