nextstep 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. This file summarizes primary aspects of the NS port architecture. If
  2. possible, it should be updated for changes.
  3. Currently it summarizes the state as of:
  4. summer 2008 shortly after merging to trunk
  5. Startup
  6. -------
  7. Init sequence:
  8. emacs.c: ns_alloc_autorelease_pool() nsterm.m
  9. emacs.c: ns_init_paths() nsterm.m
  10. - override EMACSLOADPATH, etc. so resources can be found in-bundle
  11. emacs.c: init_display() dispnew.c
  12. - sets Vwindow_system (window-system) to 'ns
  13. emacs.c: loadup.el -> startup.el -> ns-initialize-window-system
  14. -> x-open-connection (nsfns.m)
  15. - ns-list-services
  16. -> nsterm.m: ns_term_init()
  17. - EmacsApp sharedApplication
  18. - read NS defaults (org.gnu.Emacs.plist)
  19. - init X-style color list
  20. - ns_create_terminal()
  21. - NSApp run (goes to applicationDidFinishLaunching which terminates
  22. event loop -- see below)
  23. Event Loop
  24. ----------
  25. In an NS application, the event loop is normally managed by system and all
  26. user code is event-driven. [NSApp run] is called by user and never returns.
  27. In Emacs, the event loop is managed by emacs itself.
  28. The NS port mediates between these two styles by intercepting the NS event
  29. dispatch at [NSApp sendEvent]. If a special event is detected, the event loop
  30. is broken, and control returned to Emacs. This special event is sent by
  31. ns_send_appdefined, which is called under these circumstances:
  32. - if a user input event is received
  33. - when a timeout fires
  34. NS event processing is instigated from Emacs through ns_select() and
  35. ns_read_socket() in nsterm.m. Parts of the codepaths leading to these
  36. functions are:
  37. keyboard.c:read_avail_input()
  38. -> ns_read_socket (ns_send_appdefined) -> [NSApp run]
  39. process.c:wait_reading_process_output()
  40. -> ns_select -> gobble_input (global inNsSelect=1)
  41. -> ns_read_socket (ns_send_appdefined if !expected) -> [NSApp run]
  42. sysdep.c:sys_select() -> read_input_waiting()
  43. -> ns_read_socket (send_appdefined) -> [NSApp run]
  44. [this codepath may not be used]
  45. Currently ctrl-g is not detected in as many circumstances as other emacsen.
  46. It is not certain whether this is due to the means of event loop integration,
  47. or errors of omission in the NS code. This is an area for improvement.
  48. Also, see the article here and its containing thread:
  49. http://article.gmane.org/gmane.emacs.devel/92021/match=handling%5fsignal
  50. Text Rendering and Font Handling
  51. --------------------------------
  52. nsfont.m implements the font driver, responsible for managing fonts and
  53. rendering text. Fonts are obtained through NSFontManager. Rendering must be
  54. done at a low level due to emacs' fine control over this process, therefore
  55. there are different approaches under Cocoa and GNUstep. Under GNUstep, the
  56. original NeXT Display PostScript (DPS) APIs are available and used. Under
  57. Cocoa, these were removed and Quartz drawing functions replaced them.
  58. In both cases, font glyphs are accessed through UTF8 character
  59. representations. It would be preferable to use Unicode indices, but prior
  60. attempts at this have failed.
  61. Multi-script fontsets are auto-created in nsfont_make_fontset_for_font() using
  62. the facilities of NSTextStorage and NSLayoutManager.
  63. Object Architecture
  64. -------------------
  65. Unlike the other GUIs, the NS interface is based on a high-level and
  66. object-oriented API. This creates some tension in the code because emacs
  67. itself has been architected around the low-level Xlib and Xt APIs. The NS
  68. port tries to strike a balance between simplifying code on its side using OO
  69. features, and keeping code as similar as possible to other ports to ease
  70. maintenance. The following are the main classes (see nsterm.h):
  71. EmacsApp : NSApplication
  72. - event loop integration, interapp comms point for Finder (NSWorkspace) msgs,
  73. Services
  74. - one global instance (NSApp)
  75. - nsterm.m
  76. EmacsView : NSView <TextInput>
  77. - handles rendering of text and fringe, interapp comms for drag/drop
  78. - instance for each frame
  79. - child of window's content view
  80. - nsterm.m
  81. EmacsWindow : NSWindow
  82. - utility override for resize handling
  83. EmacsScroller : NSScroller
  84. - instance for each emacs window, renders scrollbar
  85. - child of window's content view
  86. - nsterm.m
  87. EmacsImage : NSImage
  88. - image rendering, toolbar icons, stippling, fringe bitmaps
  89. - instance for each image
  90. - nsimage.m
  91. EmacsMenu : NSMenu
  92. - menu management
  93. - one tree of instances for menubar, one instance for each popup menu
  94. - nsmenu.m
  95. EmacsToolbar : NSToolbar
  96. - toolbar management, one instance for each frame
  97. - nsmenu.m
  98. EmacsDialogPanel : NSPanel
  99. - popup dialogs, one instance for each
  100. - nsmenu.m
  101. EmacsTooltip : NSObject
  102. - tooltip popups, one instance for each
  103. - nsmenu.m
  104. EmacsGlyphStorage : NSObject <NSGlyphStorage>
  105. - utility for text rendering
  106. - nsfont.m
  107. EmacsPrefsController : NSObject
  108. - utility for preferences panel management, one global instance
  109. - nsterm.m
  110. - nextstep/Cocoa/Emacs.base/Contents/Resources/preferences.nib
  111. - nextstep/GNUstep/Emacs.base/Resources/preferences.gorm
  112. EmacsSavePanel : NSSavePanel
  113. EmacsOpenPanel : NSOpenPanel
  114. - utility override for panel notifications