WWDC2001 Session 123

Transcript

Kind: captions
Language: en
just a little bit of what we're going to
cover today we're going to build on the
overview and the using cocoa session
that you just saw and just dig a little
bit deeper for these issues drag and
drop printing services things that Ollie
mentioned before so I'm not gonna waste
any more time please help me bring to
the stage cocoa frameworks engineer Marc
Pizzarelli
[Applause]
hello the first thing we're gonna talk
about is drag and drop because an
important part of so many programs user
interfaces and because cocoa has good
straightforward support for it
we'll talk about how you register drag
targets in your application how you
provide drag feedback when the user
drags things over your programs windows
how you handle drops when the user
actually drops something how you
initiate drag-and-drop operations in
response to user events in one of your
programs use and for those who you have
you have been programming after for a
while I'll briefly mention some of the
new drag and drop features in Mac OS 10
so before the user can drag anything on
to your program you have to register the
program's drop targets now you can
register windows as route targets but
more typically you register specific
views in the windows of your program to
do this you call NSPS register for drag
types method passing it an array of
pasteboard data type names indicating
exactly what types the user can drop on
to your programs use for example if you
subclass NS view you should call
register for drag types in the views
initializer method if you do this it's
also a good idea to call unregistered
drag types in the views D Alec method
now views that you registered me drag
and drop targets must implement methods
of the NS dragging destination protocol
the first one of these methods you have
to worry about is dragging entered when
the user drags something into one of
your programs views cocoa will send the
view a dragon entered message this is
your opportunity to draw visual feedback
something like an insertion pointer if
the view is displaying text
and your view should also determine what
sort of drag operation this is going to
be as copying being done is moving being
done or if it's applicable as nothing
being done because it's not allowed
right now the information that the view
needs to determine these kind of things
is available in an NS dragging info
object an object that implements the
methods of the NS dragon info protocol
every one of the methods in the NS
dragging destination protocol is passed
an instance of one of these objects so
I'll briefly talk about this other
protocol before bouncing back to NS
dragging destination so as I mentioned
an NS dragging info object is passed to
each of your NS dragging destination
methods now remember what I mentioned
before about how your drop target he has
to determine exactly what sort of drop
operation this is part of the
information it needs to figure that out
is based on what drag operations the
dragging source supports and your drop
target can find that out by consulting
the dragon source operation mask method
of the NS dragon info protocol it also
might need access to the data that's
actually being dragged and they can get
access to that using the dragging
pasteboard method back to the methods of
the NS dragging destination protocol
which again each one of them has passed
an NS dragging info object dragging
updated unlike dragging entered which is
called just once when the user drags
something on 20 reviews it's called over
and over again as the user drags things
around over your view you should be
redrawing the visual feedback you're
providing offending and if you do this
be efficient because this method is
called over and over again as the mouse
moves so any flickering or delays will
be very noticeable one thing you don't
have to worry about one nice thing that
Koko provides for you is auto scrolling
if you've worked in other systems you
know it's a lot of work to deal with the
issue of the user dragging something off
the bottom of the view you have to move
the scroll bars around it's a lot of
work sometimes in cocoa it's not a lot
of work if your view is a sub view of NS
scroll view and a scroll view will take
care of all this for you and the other
method that's involved in providing
direct feedback it's dragging exited
if the user drags something away from
your view not actually dropping it
you're dragging the exited method will
be invoked this is your opportunity to
clear the visual feedback that you've
been drawing now if the user actually
does drop something your drop target
will be sent a sequence of methods
prepare for drag operation perform drag
operation and conclude drag operation or
if everything goes well all three of
them will be sent so you're wondering
why are there three of them why isn't it
just one method well you really should
do all the main stuff and perform drag
operation but its necessary to split a
few things off from the other things for
example in the case of a drag and drop
operation that implies moving the source
has to do things to once the dragging
destination has copied the drag data
into its stuff the dragging source has
to delete it and the way we make sure
that all this occurs safely is breaking
this up like this so perform drag
operation you're dragging destination
that's called then the dragging source
is told that it can delete any
information that was dragged if it needs
to and then you're dragging destinations
conclude drag operation method is called
the other half of providing drag and
drop support in your cocoa application
is initiating drag and drops in response
to user events when they pick something
up in one of your views well
historically the case of the user
picking up file icons or something like
that has been common enough that we
provide a specific method for it that
you can see there for everything else an
s view has a convenience function drag
image add offset event pasteboard source
slide back and I won't get into all
those arguments there's a bunch of them
they're all very well documented too but
I will to bring up two things that are
important we get a lot of questions
about from developers who need to take a
snapshot of a piece of their view to
provide is that image that gets dragged
around I can't give you the entire
answer because it's pretty long but the
hardest guest part of it is to call NS
bitmap in
in it with focused director so that's
that's your hint about how to get that
another thing you can do
oh and just as there is an NS dragging
destination protocol KOCO has an NS
dragging source protocol
I won't go ahead get into it in too much
detail here because it's much less
common they have to customize the
operation of the Dragon source source
but it's it's there so and if you've
been working with app kit for a long
time say pre Mac OS ten point oh you
should be aware that there are two new
operations in this drag operation
movement and its drag operation delete
that list that showed up on a few slides
ago included these you might've been
wondering where they came from they
provide a little bit richer semantics
and just plain old and it's drag
operation generic which was used before
and also we now have drag and drop in
our text subsystem so our text
subsystems classes have a few new
methods that you can override and also
the text subsystem classes the delegate
methods have a few additions to
so the next thing I'll go into is ina
stable view because it's a good example
of one of the sophisticated controls
that Coco provides you've seen them all
over they display data in a table and
allow the user to edit values if you
want to let them do that and resize and
rearrange columns and real quick I'll go
into what you have to do to provide the
data that the table view displays some
of the things you can do to handle the
user events that can occur in a table
view and if you really need to do
serious customization I'll introduce the
concept of table view cells so providing
table view data another protocol another
thing that defines a set of methods that
you can implement if need be the one for
NS table data source and then this table
data source is what an NS table view
consults to get the data it displays
includes two methods that you almost
certainly have to implement number of
rows in table view and table view object
for table column row now you can pretty
much guess what the first one is
supposed to return the second one can
return pretty much any object within the
limitations of what the table of you can
handle a standard and it's table view
can handle strings and numbers with no
trouble and if you're letting the user
edit the the data that shows up in a
table view you can implement table view
set object value for a table column row
which is pretty easy too so Kaling table
view events just as table view well and
it's table view is unique in that it
provides it depends on these data
sources it is very common among cocoa
classes however to depend on delegates
and then this table view defines a set
of delegate methods much like many other
cocoa classes do while single one out
because it's a good example of cocoa
providing flexibility without too much
complexity and that's table view will
display self or table column row and
that is sent to your table views
delegate right before each kind of a
table view is about to display a cell
and that's your option that's your
opportunity to do simple things like
setting up fonts or colors for drawing
and things like that affecting the
display of the cell without having to do
anything too clever
and then the tableview delegate methods
include a bunch of other things for
controlling selection and editing
policies whether or not you're letting
the user select you know many different
rows at one time or just one whether or
not you're letting the user edit things
or not so stuff like that and there's
also methods that provide one of the way
is that your table view delegate can
find out about user events that occur in
a table view the next step of table view
customization is to provide your own
kind of cells to the table view so as I
mentioned on an earlier slide by default
then it's table views can display
numbers and strings without any trouble
and that's because they use instances of
one of our classes called NS text field
cells well you can fry to other cells if
you need to and as you can see on the
slide there's more than one way to do it
you can do it by overriding or by
setting things up after the table views
been instantiated so if you do this if
you're willing to provide your own kind
of cells you can take total control of
all the displaying of you know custom
drawing highlighting and you can even
have your table view display objects
other than numbers and strings whatever
you need so one thing you don't need to
provide new cells for is simple things
like determining policy if you just want
to affect the Edit ability of an NS
table view cells
well the delegate can do that you don't
have to you know provide new cells for
that and no discussion of NS table view
would be complete without mentioning its
most well-known subclass and its outline
view which displays pretty much the same
stuff but we can display hierarchical
data I'm sure you've all seen these
around and programs like mail and
project builder and other places so very
quickly and this outline view is not
surprisingly a subclass of NS table view
it follows a lot of the same patterns
the biggest difference is that instead
of getting this data from an NS table
datasource it depends on an NS outline
view datasource sorts data and then its
outline view datasource the interface
that's declared by it is very similar to
NS table data sources with an important
difference because the data can be
hierarchically organized
it provides a few other methods for
determining whether or not an item has
child items and if so how many there are
another important distinction is the
fact that an astable view or an astable
datasource identifies rows with a simple
integer and that why not that's the
simplest way to do it that's really not
an option with outline views because the
row indices things like that are
changing while the user is playing with
a little disclosure triangles and things
like that so all the items that are
displayed in an outline view are and
passed across the NSL line view
datasource protocol are identified by
object references so next topic I want
to talk to you about is printing I want
you to know what you get for free in
cocoa it's a bunch I also want you to
know the limits of what you get for free
because some people have trouble finding
them and I also want you to know that
when you go past those limits even very
advanced printing in cocoa is still
pretty easy so real quick I'll go
through what views do automatically
what sort of printing they support
without much effort at all on your part
I'll talk about what you have to do if
you want to take control of the page
setup that's involved in printing I'll
introduce the concept of print
operations and quickly summarize the
things we do as far as pagination goes
so simple printing the views views can
print themselves without any trouble at
all your review has a print method for
example if you have a file menu with a
print item in it and it's hooked up to
the print action and it's sending the
print action down the responder chain
the first view on the responder chain
will print itself when it sees that so
it'll take care of putting up to print
dialogue and things like that for its
print setting it will use a shared and S
print info object moron and it's print
info in a second before I go on to more
advanced customization let me just point
out really quick if the only difference
in your view the only customization
you're considering is that you might
want to do things a little differently
on the screen from what you see on the
printer well there's a very easy way to
find out
which of you is
to the printer of the screen and that's
the current context drawing to screen
method
so page setup very simple applications
can just depend on what KOCO already has
built into it but if you're doing a more
full-featured application you're gonna
have to know a few classes the first one
of which is an S print info which
encapsulates all the parameters of a
print job it includes among other things
all the things that the user can set up
in a print panel or a print dialog
rather like page size and orientation
and scaling the Coco class that actually
presents the print dialog or sheet
whichever is called NS page layout and
you can see there the the two methods
that you use to do that if your
application is document based if you're
using NS document you don't really have
to worry about too much of this I try
and start and going to what you don't
get into get for free but I immediately
run into what you do get for free again
and it's document will take care of all
this for you so if it's a document based
app you're nearly off the hook
print operations when you start taking
control of printing you know not just
lady in a view print itself you have to
learn this class and it's print
operation and then it's print operation
is as the name implies what actually
does printing so when you create it you
specify an NS print info that can change
the parameters of printing and the view
that's to be printed and eventually
you'll run it now which view should be
printed well you have a couple of
options TextEdit for example and I do
mean for example you have the source
code so you can check this out
prints one of the views that's already
on the screen the one that you see in
the window is just the same view that
gets printed by the print operation
sketch on the other hand another sample
program creates a view just for printing
and this view only lives for the
lifetime of the print job so there's
advantages and disadvantages to both
ways I suggest you check out the source
code for those two and there's plenty of
pointers in there so and it's document
and this document can't do everything
for you so if you're providing printing
in a document based application it does
provide the obvious place for you to do
the printing it's in the print showing
print panel method which you should
override and if you do that and you
create a print operation in there you
take the NS print in
that the NS document was maintaining for
you keeping around and you set up your
view when you actually run the operation
you should run it using the run modal
print operation delegate did run
selector context info method and that
will take care of presenting the sheet
because of course we always prefer
sheets when it's reasonable it'll take
care of presenting the sheet on the
proper document window so and one more
thing you should know about printing
this pagination we have very flexible
pagination for simple cases even for
cases that aren't so simple you can set
margins in the NS print info and then
set a few pagination modes that we
support on a horizontal and vertical
basis fit pagination for instance will
scale a view to fit within one page clip
pagination will just clip it right there
an automatic pagination will split up
the view into pieces and put them on a
range of pages for more complex
situations when you have to take over
you can override the nose page range
method of the view that's being printed
and returned yes you also have to return
the range of pages that's being printed
and then you should also override NSU
rect for page and Coco's printing system
will call that repeatedly finding out
what piece of the view should be drawn
for each page and during the printing
process it will tell the view to draw
that piece on that page so one last
thing I want to mention is file wrappers
and its file wrapper classifiers what is
it it holds the contents and attributes
of a file or a directories or the files
in memory why is this worth mentioning
well because it's such an easy way to
manage file attachments when you drag a
file into TextEdit or into a mail
message for instance and the icon
appears that's an S file wrapper
managing all that for you making the
icon available taking care of things
like that it's also an easy way to read
file packages if you're not familiar
with the concept of file packages yet
the file package is a directory on a Mac
os10 system that looks at just like a
document to the you
in the finder so it's a convenient way
to get a few things done and file
wrapper to support them very nicely it
does this because a file wrapper can
actually wrap a directory also and when
it does that you into it with a
hierarchy of these NS file route file
wrapper objects and you get to the sub
file wrapper ease sub file wrappers
using directory entry or dictionary
entries as is common in cocoa and the
operations on a file wrapper are
recursive so if you're doing something
like copying an NS power app or all the
sub file wrappers inside will be copied
also so one other kind of things can you
do with the power ever as you might
guess you might want to get the data
that corresponds to the file that's
being wrapped and you do that and of
course it provides a method for that and
it returns one of our NS data objects
for that you can get and set the file
attributes on a file wrapper and get the
icon also for displaying in places like
TextEdit or a mail message wherever
you're doing a file attachment or
something like that one neat feature is
that if a fire effort has been
instantiated by just copying the
contents of something off of disk into
memory file wrapper will keep track of
that and if you need to you can ask the
file wrapper to check to see if the copy
on disk has changed and if so you can
ask it to update to that copy on disk
also and the last good thing you can do
is power a pers is you can serialize you
can flatten them for putting places like
the pasteboard so at this point please
welcome to the stage dog dancing so you
can talk about services okay thanks mark
now we had a tantalizing glimpse of
services in the last session so I'm here
to tell you something more about them
and to do that I want to start by
describing services by comparison with
something that's not a service and that
is the bold menu item in an application
now when the user picks the bold menu
item you can think of what is happening
as in effect the current selection is
being copied transform so it is bold
and then paste it back in place now
that's a very simple operation it's
built into every application but suppose
you have some custom operation that your
application knows how to perform and you
think it's so great that you want to
provide it not only in your application
but in every other application as well
now if you want to do that you can use a
service in a way it works is that when
that service is requested the current
selection is copied put on a special
paste board shipped off to your
application your application will be
launched if it's not already running and
you perform your special operation on it
put the result back on the pasteboard
gets shipped back to the originating
application and then that's pasted back
in now not every service has to follow
this exact pattern for example the the
magic typer the last session didn't take
any data it just returned some data on
the pasteboard or there can be services
that just take data and don't return
anything and the thing that the service
takes for return it doesn't have to be
text it can be any sort of thing that
could be copied and pasted so what does
an application have to do to support use
of services well this is cocoa the
answer is absolutely nothing the use of
services is automatic your standard
cocoa menu main menu will have a
services menu in it the app kit will
automatically populate it with entries
for all the services available on the
system the user just picks it and the
rest happens automatically there are a
couple of things you might want to do it
is possible to invoke services
programmatically if you want to also if
you have a custom view the things you
need to do to support the use of
services on it are essentially the same
sort of things that you need to do to
support copy and paste you need to be
able to take the current selection put
it on the pasteboard or take something
from the pasteboard and put it in
transfection also if you have a custom
paste board type then you have to
register that in order the VSO
can know to check for any services that
might take or return that type so the
interesting question is what does your
application have to do in order to
provide a service now in order to
provide a service there are three things
you have to do first one is to implement
one single method it looks something
like this and you'll be handed a
pasteboard optionally some extra data
you take what comes in on the pasteboard
transform it put it back and send it
back and you if there's an error you can
return an error string there are some
examples for example there's a simple
service example and you're just TextEdit
off also provides a service here is just
the basic skeleton of what that service
providing method might look like well
online that take to take the string off
the pasteboard one line to perform your
operation and then two more lines to say
what type you're putting back on the
pasteboard and put the value back on the
pasteboard that's all that's point
number one
so the second thing you need to do is
that when your application is launched
you need to register the object that
implements this method as the service
provider for your application there's
one service provider per application
that's point number two and point number
three is that you add need to add an
entry to the info.plist in your
application bundle and what that does is
to describe the service or possibly
multiple services that your application
provides saying what the name is what
types it will take what types of work
turn menu items and possibly keyboard
equivalents okay
now next I'd like to discuss a few
topics down at the foundation level
first of all the run loop cocoa
applications are fundamentally
event-driven that is events come in
they're handled and we go back and wait
for the next event to come in now the
underlying machinery that supports this
is a run loop NS run loop foundation and
we call it a run loop because we say
that it runs and that a loops but mainly
what a run loop does is it waits it
waits for something interesting to
happen then it tells you about it you
handle it
it goes back and it waits again and the
things that waits for can be any of a
wide variety of things might be the
arrival of a mock message might be the
arrival of a network packet it might
just be the arrival of some specific
time but what the run loop can do is to
wait for all of these things together
efficiently without pulling without
using any processor resources and that
turns out to be a very powerful thing
now there's just one run loop per thread
that does all the waiting for that
thread typically in a napkin based
application the app kit will run the run
loop for you in the main thread you
wouldn't have to do that but under other
circumstances you may wish to run the
run loop for your thread by yourself now
run loops can have modes it may be that
you don't want to wait for every
possible thing every time you run the
run loop for example you might not want
to have a certain time or fire why you
are let us say tracking mouse moves so
it is possible to run a run loop and any
in a number of different modes and when
you add a source to the run loop you
register it for a single mode or set of
modes and only those run loops that are
registered for the particular mode that
is running are actually active there's a
default run loop that you would use most
of the time
that probably will be used most of the
time on the run if it's running the app
kit has a couple of others that you'll
see for example one that's used when a
modal panel is up and another that's
used typically when it's tracking Mouse
moves in a widget and you could register
for all these together as the common
modes now run loop by itself is not
terribly interesting what's interesting
is what you can do with it that is the
things you can wait for and one of the
things I said you would wait for was the
arrival of a certain time to do that you
use an NS timer and as timer could wait
for a single time or a repeating
sequence of times for example that silly
worm in the last session was animated
using a timer that waited for feeding
sequence of times and the way this works
is that when this timer is added to a
run loop in a particular mode if the run
loop is running in that mode it checks
to see if the time for that timer to
fire has arrived and if it has then it
tells you that is you will be an object
of your choice will be sent a method of
your choice when that occurs and if you
of course if you have a one-shot timer
it's automatically invalidated after it
has fired if you have a repeating timer
then you would have to invalidate it
yourself when you no longer want it to
be used among the other things you could
wait for I said were mock messages
Network back as things like that now if
you really want to wait for raw mock
messages or raw network packets you can
do that at the core foundation level
with some core foundation web sources
and I'll probably mention that tomorrow
and the core foundation session at the
foundation level we have a somewhat more
abstract 'add object based on those and
that is NS port and one NS port allows
you to do is to send what's called an NS
port message from one Coco process to
another and the contents of a port mess
mainly just an NS data bag of bytes it
can also optionally include some
references to ports that can be sent
across and an NS port message is sent to
an NS port and then in the receiving
process or what you want to do is make
yourself the delegate of that receiving
port and then you will be notified you
will get a message when that port
message arrives you would give them the
important message and you get to decode
it and do whatever you want with it
that's a fairly fairly simple easy to
use but rather low-level get a process
communication mechanism a more
interesting thing about NS ports is that
they're the foundation of what's known
as distributed objects and what
distributed objects allows you to do is
to send method calls to objects
transparently across thread process and
machine boundaries what do I mean by
that a means for example you can have
safe inter thread communication because
you can send a message that will be
delivered to an object and be delivered
in another thread or you can send a
method to an object in another process
maybe even a process running on a
different machine and it will be
delivered there and the fundamental
object in distributed objects is an NS
connection which runs from 1 NS port to
another in this port and the message is
sent across the connection now one thing
about NS port is an abstraction there
are different subclasses of NS port to
refer to different transport mechanisms
for example there's one there's sub
class that uses mock messages for
communication on the local machine
there's another sub class that uses
tcp/ip for transport from one machine to
another across the network and depending
on how you which subclass you use when
you create your connection you can get
either means of
and when you set up a connection one
side which is going to be the server
sets an object one of its objects as the
wood object for the connection that's
bending that out the other side the
client gets a proxy for that object with
its connection and then it can send
methods to the proxy as if it were
sending them to the real object the
methods are forwarded across the
connection and delivered to that road
object at the receiving end and the way
the two sides hook up also depends on
what sort of transport mechanism you're
using if you're on the local machine you
can register connections by name if
you're going over tcp/ip you usually
rendezvous based on a TCP port and an IP
address now there are a number of
examples of this in the documentation on
Ana's connection and exactly how use it
depends a little on what you're doing
but let me just give one brief example
of a connection that's used for in a
thread communication so on one side the
main thread what we're doing is first
creating a port and then we create a
connection that will receive with that
port we set ourselves as it happens as
the root object for that connection that
means we're bending ourselves out we're
going to get the messages and then we
create another thread and that other
thread is going to send us messages on
this connection so we give it the port
now in that other thread we use that
port to recreate action to send to that
port and we do whatever calculation we
want to in this threat maybe it takes a
long time to do this calculation and
then when we're done with that
calculation we ask this connection for
the route proxy and that gets a proxy
for that route object the self on the
other side and then we just send a
method talk to its server report result
result just normal objective-c message
and except that in this
it's going to be delivered to that other
object in its thread in the main thread
the result is safe inter thread
communication okay
and I also like to talk about a few
other things in foundation that are
enabled directly by the run loop
mechanism so nsurl in foundation the
basic use of nsurl is to encapsulate a
URL so you can have the scheme and the
path and all the other components of URL
and analyze those and pass that around
but another thing you can do within s
URL is you can do simple fetching of the
contents of URL by default built in for
file colon HTTP colon schemes and this
is a rather simple mechanism and some
limitations but you can get notified
when the download starts or when various
interesting things happen during it
there's also a slightly more complicated
mechanism if you want more detailed
control over what's happening there's an
nsurl handle that can give you somewhat
finer control and you can also subclass
this if you want to handle other schemes
if you know how to handle another thing
has to do with Apple events it's been
mentioned earlier that cocoa provides a
lot of support for Apple script for
scripting but it's also possible to
receive individual Apple events and it's
very simple there's a shared NS apple
event manager one object and all you do
is register a particular object and
method to be called when a particular
Apple event type arrives and then you'll
be called with a selector be given the
Apple event and then we give them a
reply then you fill in the reply
and send it back very simple okay and
finally I'd like to talk a little bit
about exceptions in foundation now the
objective-c language does not have a
built in exception mechanism but the
foundation provides one that is an
exception object an S exception and the
means of raising exceptions and a means
of handling them and this these ennis
exceptions they have a name a string
name that's used to identify them and a
reason which is some reason that's
supposed to be intelligible to a
programmer now in your own code you can
use exceptions however you like but as
Coco uses them typically we use them
only for really truly exceptional
conditions things that can't really be
handled usually the result of some
programming error we don't want you to
have to use exception handling context
all over the place only in special cases
and of course they can be handled at
multiple levels for example typically
the app kit will catch exceptions
occurring in its main event Luke if they
are not caught at some lower level if an
exception really is not handled at all
at any level then there's a default
exception handler that basically just
exits a process or you can install your
own if you want some other behavior so
how do you raise an exception the
simplest way is by calling a class
method on NS exception to raise with a
name you give it the named exception and
format which is printf style format
string and arguments to produce the
reason which is as I said it's supposed
to be intelligible to a programmer and
there's a slightly more complicated way
you have you can attach essentially
arbitrary a user info data to the
exception so you if you want to do that
you can create the exception and then go
ahead and raise it
how do you handle an exception the way
you do it is first of all you start with
an NS during and then comes the block
where an you try to perform the
operation that might raise an exception
and an S Handler and then comes
exception handling context where you
would be sent to if the exception if an
exception was raised and then as handler
Enza block now once you get into this
exception handling context when an
exception was raised there are four ways
you can get out
one is you can just fall through to the
end just keep going as if nothing
happened or you can re raise the
exception that was raised just send it
on or maybe you have a new exception you
want to raise that covers that or you
can exit the method altogether and there
is an NS value return that's used if
you're returning something from the
method or as void return if the method
returns void and the way that you know
what the exception was that was raised
is that there's a local variable whose
context is this exception handling block
local exception and you can take that
and then say that if you want to use it
later or possibly re-raise it and let's
see the only one other thing I wanted to
mention about these exceptions is that
Java they're wrapped as I believe a
subclass of the runtime exception and so
next I want to turn the stage over to
Chuck pessoa
[Applause]
okay this is the section of the talk
where basically everyone's on the same
foot because we're talking about new
features which even experienced people
haven't seen before so and mathematics
you're kind of lying a little bit
because some of these new features are
really things that we had before hadn't
been working for a while and they're now
back so let's get into these first of
all let's talk about XML until now
cocoa used to store what we call P lists
in an ASCII format we still start an
ASCII format but that formats defined
using XML and when we did this we also
added support for a number of toys for a
number of types that developers have
been asking for for a while so we can
now do things like array data date some
various other standard types that you
want and if you need to do anything
that's not in the standard list you can
always convert to an NS string or Ananas
data koknal
also has support for dealing with HFS
file types now we added this support by
without modifying any of our API that
uses extension based parameters so for
instance if you want to bring up an open
panel and tell it what types you're
allowing it to open you can pass in
strings which represent HFS file types
and we've again we've done this without
modifying the API so if you want to
allow the open panel to open some sort
of HFS file type you'd use one of the
functions like NS HFS file for type code
you'd convert the OS type code to an NS
string and pass that into the extension
based API so you can mix extensions
along with HFS file types
and it's workspace is back and mostly
functional again so there are parts that
hadn't been functioning for a while the
parts that still aren't functioning are
mostly OS specific those are the few
exceptions we've also added some new
methods methods to open your ELLs check
whether or not something's a file
package and even methods to check for
local mounted volumes we now have
support for custom window shapes the
things you see like the clock up there
we're done using a custom window shape
and what you the support that's needed
to do this is the ability to first set
the alpha value of a window
tella window that it's opaque then what
you would do is fill its content with
clear color and anywhere you fill it
with non clear color would then be the
window so in this example above I
initially told the window that it's not
opaque filled it with clear color and
then Drew using a clock image and then
of course put the hands on top of it and
we've also added support for you to turn
off shadows now if you do your own
custom window shapes
you're of course gonna have to handle
your own window dragging we now have
small controls a number of controls that
you're used to seeing in cocoa come in
both flavors buttons and checkboxes
larger things even like the tab view
like the example above have normal and
small variants to choose small controls
typically you're going to do it when you
layout your UI so an interface builder
you're gonna check one box that says use
small control but you can also do this
programmatically by sending these set
set control size method using the small
control size typically the set control
size message will be sent actually to
the cell of the control so those whom
you're familiar with controls know that
controls display using cells and so the
cell typically will be the one that
receives this message
and a status bar is back and has no new
API status items are really pretty
simple
sort of like the toolbar they have many
similar attributes you can set a target
action a title and image you can
associate a drop-down menu and they can
have tooltips and also similar to the
toolbar you can have your own custom
views up there so if you want to install
your own custom sort of status view you
can't use the set view method method
typically you want to make sure that
these status items are very are small
things and you should use them sparingly
because there might not be a lot of
space to display them currently these
things are displayed in the menu in the
top menu of Mac OS 10 and it's movie
View is back and it's movie view is a
control in cocoa that you can use to
play QuickTime movies it encapsulates a
movie object which is the QuickTime
structure for movies this movie object
is now stored in an NS movie and can be
accessed from the from the NS movie
object if you want to do complicated
things and also the movie controller is
stored by the NS movie view the and if
the movie controller is the little
controls at the bottom that allow you to
drag your position the movie press play
or pause and you can access that
directly if you want to do more complex
things than Anna's movie allows you to
do as I said and it's movie now wraps a
movie the QuickTime movie structure
however it's not an objective-c wrapper
for all QuickTime api's so typically if
you need to do something specific with
your movie you'll access the movie
directly and use QuickTime calls you can
initialize the NS movie in a number of
ways either from a QuickTime already
created QuickTime movie object by URL or
from the pasteboard and and its movies
main role in life is to make sure that
well we have an object wrapper for for
the movie and object and it controls
disposing of the
the QuickTime movie when it's delicated
currently there's no support for doing
for allocating from a streaming type of
source if you need to do that you should
create your quicktime movie object using
new movie from data ref and then hand it
off to the NS movie NS opengl has a
couple new methods in particular update
and reshape these are methods that those
familiar with OpenGL programming know
that if this say the size of your
viewport changes you need to update
certain viewing parameters this is where
you'll do that another note of interest
if you're doing fullscreen OpenGL
applications in order to prevent the doc
or possibly the application menu from
receiving mouth clicks or other things
potentially you might need to provide a
cover window what you would do is make a
window make and give it a window level
which is higher than anything else so
that it would intercept the mouse events
and the window level you want to give it
is kcg overlay window level okay the
toolbar is a completely new class it
comes along with a and its toolbar item
class which is also brand-new the basic
idea here is that the tool bar
represents the NS toolbar represents the
whole toolbar and it takes care of a
number of tasks for you like
synchronizing toolbars if you make a
change in one toolbar you want it to be
reflected in all other toolbars with the
same identifier again mail has three
different kinds of toolbars so if I
change the ordering of my items in my
compose window I want it to be reflected
in any other compose when I currently
have up immediately and as toolbar also
takes care of archiving the
configuration out to disk and making
sure when you create new toolbars they
come up with that same configuration in
addition and this toolbar also will run
the customization sheet that you've seen
drop down for mail and will control the
display of that all you need to
typically do is provide is provide those
delegate methods that if you're in the
last session you heard about each item
in the toolbars resumption
represented by an NS toolbar item object
and again this is very similar to status
bar items they have some some standard
attributes like images labels menus that
can be associated when you're in text
only mode and they have again targeted
action because target action is
typically how controls communicate in
Cocoa and again if you if you need to
provide your own kind of item that's not
simply a sort of standard button
something like the search field and mail
can be provided as a custom view now we
don't in Cocoa again we give you lots
for free so we also have some standard
items that you can get for free
separator toolbar item one that will pop
up the color panel and so forth and a
stepper is a new class it's these small
up and down arrows that you see here and
basically something that you'll use if
you want to have an incrementer and you
can set things like a min and Max value
the increments step size and whether it
wraps or auto repeats and this image has
a couple new methods and the reason that
we have these new methods is that
existing methods and Ennis image
typically did not pay attention respect
the current transform they were they
simply blit the image to the screen now
the new methods draw at point and draw
in rect will pay attention to the
current transform so if you want to do
things like scale or flip your image
things like that and the additional
parameters that you see are for
specifying the part of the source image
that you want to draw to the screen you
don't have to use the whole image you
could use just use the whole image you
know 0 0 to width by height and then the
remaining parameters are the operation
you can specify a simple copy type of
compositing operation or a source over
so on and the fractional amount of the
image that you want to draw so it can be
anywhere from 0 to 1 1 being fully
opaque 0 being fully transparent
there are a couple new graphics features
that we have that provide you finer
control over some of the display
operations in particular you can turn on
and off anti-aliasing and you can
control the granularity of image
interpolation and the types of values
that you can use for image interpolation
or either none low high or the Cocos
default and this bitmap image rep also
has some new support for using color
sync data and the particulars of this go
like this and this bitmap image rep has
a dictionary of sort of arbitrary
information that can be attached to it
one piece of information that can now be
attached to it is this color sync
information and the color sync
information is simply an NS data object
and the key that you use to attach it is
NS image color sync profile data if you
look at the NS bitmap image rep
documentation you'll see that there's
this business about properties that can
be associated with the bitmap image rep
okay so we shipped Mac OS 10 ten point
oh now we have to worry about things
like versioning so this isn't this is
new in that sense but we've always sort
of had versioning the important thing
here is always test your applications
against old versions of the app kit and
old versions of Mac OS 10 and you may
potentially need to check against what
version number of the Coco frameworks
you have and the value you'll need to
check is this value called and it's app
kit version number for 10.0 the version
number of the Coco frameworks or app kit
sometimes we refer to it but I'm sorry
the version number of app kit was 577
dotto Foundation would have its own
version number and in 10.0 we did not we
didn't declare the variable anywhere so
you're gonna have to make sure you
declare yourself if you want to
reference it and it's it's a double so
you'd declare X turn double
and a SAP kit version number and the
important thing here is that when you're
checking for say a new bug fix we may
have said the you know bug fix for super
widget a came out in the next release of
the app kit and you don't want to check
for greater than or equal to five cents
well greater than five seventy seven to
know whether or not the fix is there
because the next release next major
release may be five eighty seven and
this bug fix may have come along
somewhere in between say on a software
update even you want to make sure that
you compare against the specific number
of where that fixes because you want it
to work on the in between releases not
just its you don't it's sort of hard to
explain but there there would be a
window or if you're just checking
greater than 577 word the fix is not
actually there but you thought it was so
you want to check against specific
version numbers for bug fixes or
features in fact that can be solely
described by whether or not an object
has a method through the beauty of
Objective C is very fast introspection
you can actually just ask whether or not
the object responds to the method if the
object responds to method well then the
features there for all these things
check the release notes and it should be
clear what what you need to use for any
particular situation finally we have the
slide you've seen many times
documentation there's release notes you
should always look to see of course one
of those bug fixes were put in what
potentially what behaviors changed
overview documentation so on and so
forth
example code again you've pricing this
many times I'm just gonna flip through
the roadmap well basically you've missed
it all except the feedback form however
you've got the DVDs if you haven't seen
the coke overview talk and you're new to
cocoa you should check that out the
using cocoa talk those of you who aren't
here the previous hour really missed out
it's full of lots of great demos and the
feedback form so if you have anything to
say come to that tomorrow finally
Heather is always your person to contact
we have a feedback address if you have
comments or suggestions and I'd highly
recommend subscribing to Apple's new
cocoa development list
you