X Review Mac OS X Roots: Next

X Review Mac OS X Roots: Next

X Review Application • Distributed window system Widget Set • Server is the user’s Terminal WM Xt Intrinsics • Client runs the application Xlib Xlib • Highly modular • (exchange WM, Widget Set) X Server BWS • Available for virtually every OS HW • Very successful in the UNIX world (with Motif) • Many Open Source implementations available • Xt intrinsics already allow OO GUI application programming Jan Borchers 1 media computing group Jan Borchers 2 media computing group Mac OS X Roots: NeXT • 1985 Apple kicks out Jobs, who founds NeXT • 1988 NeXTSTEP 0.8: 68k, Mach kernel, 4.3BSD, Display PostScript, new Objective-C, platform for first web browser at CERN • 1990 NeXTSTEP 2.0: Interface Builder (OO) • 1993 Intel, SPARC, HP PA-RISC support (fat binaries), NeXT hardware dead • NeXT&Sun: OPENSTEP, used by SunOS, HP-UX, MacOS, also on Windows NT, GNUstep Jan Borchers 3 media computing group Jan Borchers 4 media computing group Mac OS X Roots: It’s spelled “Ten” NeXT Mac OS X: Architecture Apps UITK Cocoa, Carbon, Java • 1996 Apple purchases NeXT, Jobs back at Apple, begins replacing Mac OS towards NeXTSTEP WM WindowServer (user-level process) • 1999 Apple releases Mac OS X Preview BWS ! Mac OS X is directly derived from NeXTSTEP/ OPENSTEP (Mach/BSD, Objective-C, Cocoa, Interface GEL Quartz 2D / Core Graphics, IOKit Builder, NetInfo), and combines this with other Apple HW technologies (UI, Multimedia) 6 Jan Borchers 5 media computing group Jan Borchers media computing group Base Operating System Graphics and Event Library • Quartz 2D / Core Graphics, Display PDF • Roots: NeWS, NeXTSTEP (Display PostScript) • Vector-based, resolution-independent • Darwin (Open Source for PowerPC+Intel) • Quartz Extreme: GPU-based compositing (pipe • Based on a Mach microkernel + BSD Unix entire screen through OpenGL if available) • Protected memory, preemptive multitasking • Quartz Extreme 2D / QuartzGL: GPU-based UI • Single application cannot corrupt/freeze entire system rendering (still experimental) • Vista’s XPS is similar to (Display) PDF • The Event Library is contained in IO Kit Jan Borchers 7 media computing group Jan Borchers 8 media computing group User Interface Toolkit Demo: Quartz Extreme • Cocoa AppKit, OO framework • Implements Aqua Look&Feel • Other part of Cocoa (Foundation framework) contains threads, sockets, etc. • Written in Objective-C Jan Borchers 9 media computing group Jan Borchers 10 media computing group Java Carbon Cocoa BSD (JDK) QuickTime Application Services * Multi-API Problems Core Services Kernel Environment • Mac OS X has tried to please everyone • Problem: High cost for supporting many APIs • Cocoa is the recommended API for Mac OS X • Consequences in 2006: • Can be used with Objective-C or Java* • No new Java bindings for new Cocoa features in Mac OS X 10.5 • Java SE 6 SDK is used for 100% Java/Swing applications and beyond (= “Use Objective-C!”) • Carbon is an updated version of the old Macintosh Toolbox • New Intel Macs do not support Classic Mac OS emulation anymore (= “Classic’s dead!”) • Used to easily port existing applications • Carbon apps run on Mac OS 9 and Mac OS X • But: New bridges for Ruby and Python since Leopard • BSD is used for existing standard Unix applications • WebObjects for web-based services Jan Borchers 11 media computing group Jan Borchers 12 media computing group Event Handling • Similar to our Reference Model • Window Server distributes events to per-application (really per- process) queues Steve Jobs burying Mac OS 9 at WWDC 2002 (personal photo) Jan Borchers 13 media computing group Jan Borchers 14 media computing group Objective-C: Objective-C New C Language Constructs • Implementation language of the Cocoa framework • Created in 1983 to combine OO principles with C • status = [socket connectToAddress:127.0.0.1 withPort:80] is analogous to Java’s • Inspired by Smalltalk status = socket.connectToAddressWithPort(127.0.0.1, 80) • In its concepts very similar to Java, unlike C++ • — for instance methods, + for class methods • Dynamic typing, binding, and loading • id corresponds to Object, self corresponds to this • Protocols are analogous to Java’s interfaces • @ compiler directives • Classes are objects of type Class • Reflection possible (not in C++) • @interface..@end, @implementation..@end,… • Introduces few new language constructs to C • Interface categories allow transparent subclassing Jan Borchers 15 media computing group Jan Borchers 16 media computing group Dynamic Typing/Binding/Loading • C++ is a static language, Java and Obj-C are dynamic • Calling known methods of a subclass • Example: Building objects from data read from a file • In C++, you cannot directly call a method defined in a subclass Demo: Dynamic Binding - You would have to do a dynamic_cast<> • Obj-C (and Java) move this check to run-time • Fragile Base Class Problem • To add a method to a superclass, all subclasses must be recompiled • In C++, a superclass must contain all methods any subclass will use • Dynamic Binding avoids bloated superclasses, and minimizes recompilation due to this problem Jan Borchers 17 media computing group Jan Borchers 18 media computing group Objective-C 2.0 (since Leopard) Manual Memory Management • Supports automatic accessor method generation for • Reference counting object properties • Each object stores how often it is referenced by other objects • Allows Java-like short-hand syntax to access • If it is not used anymore, call dealloc (free memory) properties • Only five methods affect reference counts • [object setName:newName]; • alloc—allocate object and set reference count to 1 object.name = newName; • copy—copy an object. Copy will have reference count 1 • Features an optional garbage collection • retain—increment reference count • only works for Objective-C Objects • release—decrement reference count • you still have to manage any C pointers yourself • autorelease—automatically decrement reference count sometime • Supports fast enumeration of collections after the current method • for (object in list) [object doSomething]; Jan Borchers 19 media computing group Jan Borchers 20 media computing group Cocoa Cocoa Class Hierarchy NSObject •! Fairly flat hierarchy • The UITK (and general toolkit) of Mac OS X NSEvent • Evolved out of NeXTSTEP NSResponder •! Reason: Delegates, and • Cocoa’s class names still give away its heritage (NSObject,…) NSWindow ! categories can be used to mix NSView ! in functionality • Two main parts NSControl • Foundation: Basic programming support NSButton etc. →!no deep subclassing NSApplication ! required - NSObject, values, strings, collections, OS services, notifications, archiving, NSCell (lightweight controls) Objective-C language services, scripting, distributed objects • Full hierarchy: NSMenu • AppKit: Aqua interface NSMenuItem ! see Online Help in Xcode - Interface, fonts, graphics, color, documents, printing, OS support, international support, InterfaceBuilder support etc. - Largest part (over 100) are interface widgets Jan Borchers 21 media computing group Jan Borchers 22 media computing group Example: NSTableView Delegate Methods Delegates Moving and resizing columns Editing a cell – tableView:didDragTableColumn: – tableView: shouldEditTableColumn:row: – tableViewColumnDidMove: Displaying a cell – tableViewColumnDidResize: • Similar to Listeners in Java – tableView: • A delegate is a class whose methods are called from Selecting in table willDisplayCell:forTableColumn:row: Displaying tooltips another class that wants to plan for extending its – selectionShouldChangeInTableView: – tableView:shouldSelectRow: – tableView: functionality toolTipForCell:rect:tableColumn: – tableView:shouldSelectTableColumn: row:mouseLocation: • E.g., you can write a delegate class for NSTableView that will get – tableViewSelectionIsChanging: Allowing variable height rows called when the user changes the width of a column – tableViewSelectionDidChange: – tableView:heightOfRow: • Delegates solve the fragile base class problem Responding to mouse events • If NSTableView is changed, the delegate class doesn’t need to be – tableView:didClickTableColumn: recompiled – tableView: mouseDownInHeaderOfTableColumn: Jan Borchers 23 media computing group Jan Borchers 24 media computing group Categories: Extending a class Protocols without subclassing • Example: Add a “find&replace” method to NSString • Could subclass “MyNSString”—but then have to change all code to use that new class • Could change NSString itself—but that would require access to the source code for that class (and recompiling, rebinding any code using it,…) • Similar to Java’s interfaces • Instead: Create a category “NSStringExtensions”: • Mostly replace the need for multiple inheritance @interface NSString (NSStringExtensions) - (NSString *)find:(NSString *)findString replaceWith:(NSString *)replaceString; @end • Any code using NSString can now use the find:replaceWith: method • An advantage of the Dynamic Loading possible with Objective-C Jan Borchers 25 media computing group Jan Borchers 26 media computing group Events and Actions • Events are generated by user or system (e.g., periodic events) Demo: Categories • Corresponds to input “I” from our formal widget model • Actions are generated by objects (e.g., menus) in response to lower-level events • Corresponds to actions “A” from our formal widget model • InterfaceBuilder lets developer connect actions to custom objects (e.g., from a button to a custom class), using “IBAction” constant in the source Jan Borchers 27 media computing group Jan Borchers 28

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us