WWDC2001 Session 112
Transcript
Kind: captions Language: en you've all had a good nap and you're ready to learn about the great new features we've added to the window manager and the menu manager to make your applications look great on Mac OS 10 and to introduce you to all that groovy new stuff let me bring out the manager of the high level toolbox team ed Bose right that's me all right so the window when the many managers are actually pretty important to every car of an application you need windows you need menus so what we're planning to do in this session is kind of lead you through an overview of all the different things that we've added to the carbon window and menu managers here's a list on this slide but we're gonna hit each one of the points individually first sheets sheets are one of the most visible features of aqua and one of those features which you actually need to adopt it doesn't come for free the whole point of a sheet is to provide a document model experience this means that the sheet makes the document that the sheet is bound to go modal the user can't interact with the document any longer they must interact with the sheet instead but the user can still deal with other documents other windows and the rest of your application in general to get sheets the easy way we have a few api's the first is called create standard sheet and if you're familiar with standard alert or create standard alert this is the equivalent in the world of sheets you can also get sheets for free through navigation services and print panels bypassing the appropriate parameters to the calls and that in those two components or you can create sheets yourself to do that you have to create a window of Kay sheet window class and this is actually enforced by the window manager once you have this sheet you should install a carbon event handler to handle the kay event window draw content event this is important because we actually need to render the content before we put the sheet on screen because we need to do the animation so all the bits need to be in place before we can run that animation so it's important to install that handler once you have your sheet and you've installed your handler you probably want to see it on screen and the easy way to do that is just call show sheet window and that API basically takes the parent window that you want to bind the sheet to and when you call this function we do the animation we make the sheet appear and the carbon event model then knows oh we're in a sheet mode document moodle situation and it knows how to deal with clicks appropriately once you're done with the sheet user is interacted with it you call hide sheet window we will do the inverse animation make the sheet kind of get sucked back up into the title bar and then you have to remember that once you've hidden it it's just hidden it still exists you still need to dispose that window transparent sheets are actually part of the human interface guidelines you're actually supposed to be able to see through sheets now that's supported in cocoa and the first release of Mac OS 10 but not in carbon but it is something we're working on and I'm just making you aware of this because there's a few rules that you should follow in order for us to try to turn this feature on for free in most situations in general you will probably need to switch this on manually however for api's like create standard sheet we want to be able to turn this on and just have it work for free so you don't have to do anything you get all the benefits of transparent sheets but in order to do that we actually have to make changes to the control manager as you know the control manager likes to erase behind controls and this presents problems because when we erase we use quick draw and quick draw does not deal with alpha and transparency means alpha so it did have to make some changes there so the goal is that create standard sheet will just work however create standard sheet actually returns to dialogue ref to you and at that point you can actually take that dialogue rapid start inserting dialogue items so that may actually work against the goal of us being able to turn it on automatically so what we ask is that if you are going to do that make sure you should add standard controls cuz all of the standard controls that are supplied by the toolbox will automatically work in this new transparent sheet mode and if you're running custom controls be aware that because sheets of transparent alpha that whole thing you will have you will have to actually render your controls with core graphics courts and not quick-draw so historically we've supported three types of people of an alert the note the caution and the stop alert you'll notice on Mac OS 10 now when you call these api's or specify these types of alerts you actually don't see the correct icon at the very least you should see the caution icon that's part of our human interface guidelines we are working on fixing that and doing the right thing so it's important for your applications to not try to replace the icon yourselves just keep using the constants as you always have and we'll do the right thing in a future release window groups are a brand-new feature to the window manager historically people have done many evil things with the window manager by manipulating the window list themselves doing things that would probably scare your grandmother so the problem with that isn't that they were really doing anything evil the problem was that the toolbox couldn't actually rely on what it thought the correct state was so in carbon we actually want to be able to have both the tool box and your application play in the same sandbox and always know the correct state so it allows you to actually change window layering it also allows you to change the way you do at a window activation but the most important thing is that the toolbox is still in the loop and we can we can always we can continue to do the right thing for example if you click on a applications icon in the dock up comes a pop-up menu and then that pop-up menu is a list of all the document windows well we need to be able to just call select window on that window or activate window and have it actually do something correct that your application can deal with and we don't trip up your application so one of the most common uses for window groups is to actually move windows between groups and in you can actually think of groups as layers so we have a document layer we have a floating window layer we have like a modal layer there are times when applications want to take a document window and make it float or make a floating window not float and you could do that through the window group API actually if you were here yesterday for the carbon event talk we showed an application called magnify and part of the Preferences there was a checkbox to allow the window to actually float above all windows or just be a floating window in that application and the way that we actually make that switch is to the window groups so that's one aspect of it the other aspect is the activation aspect there are actually times and in certain applications where they want to make a window active and that window is not the frontmost window to accommodate this you've implemented a new API called activate window this basically does the mechanics of select select window yeah select window and that it actually posts and activate event to the window but it doesn't actually change the see order so it will deactivate whatever the currently active window is and make the window that you specify active to go along with that we have active non floating window this is what you should probably use in place of front non floating window or front window in fact it's actually a bad thing to just use front window at all unless you really really know what you're doing and you know how to walk through the window list there may be times when the system has windows in your window lists like for example an input method has a window up and if you call front window you're not going to get your document window you're gonna end up getting the input method window so you need to be able to code in such a way that you can deal with these situations and one of the best parts about window groups is that you can create your own you can create your own group put your windows in it and then you can actually do interesting things like make them move together or Z order together so treat them in almost as one window sheets actually use this so when the sheet is bound to its document window it creates a window group and then that pairing of windows acts as one when you move the parent the sheet moves with it when you click on one or the other window they both come forward or they both go backward overlay windows are our solution to be to allow you to actually draw on the screen but you're really not drawing on the screen what you're drawing into is a transparent window at a very high window level meaning that it is above the menu bar and above the dock now this is really cool I could draw a little screen that's great but it does have its implications for one a window that is the size of the screen at 32-bit on a 10 by 7 display is going to take 3 Meg just because you can't see it doesn't mean it doesn't exist we actually have a back buffer for it so it's important to actually size your windows appropriately for whatever you're doing it also requires core graphics to do your drawing again quick-draw doesn't deal well with an alpha channel so you have to use CG and the last thing is it can have nasty effects on classic windows classic windows are what we term non retained there is no back buffer for them if something obscures it it will actually tend to erase itself so you may have noticed that if you're dragging something from the finer and you go over a classic window you actually watch the classic window get a race and then it kind of updates itself as it goes along overlay windows will actually have the same effect so they need to be careful with them one thing that we've added is the concept of automatic window positioning whenever the monitor size changes or a monitor size changes or maybe the doc appears because you have it done you know you turn it on so you want it to show up or you've resized the dock we will actually go and move windows around if their title bars have become obscured now sometimes you don't want that to happen and you can actually override that we send out a que event window constrain event to all windows when we're about to do this and you can intercept that event by installing a carbon event handler on the window and just return no we're saying oh no don't do anything you know I handle this even though you really didn't do anything and with the advent of the dock it's a little tougher to actually find out where you can put your windows it used to be if you were on the main monitor you say alright I'll subtract out the menu bar height from the top but now we have this dock how big is that how do I you know how do I subtract this height where do I get the dock rectangle well you can't but what you can do is call get available window positioning bounce this is a new API that we've added for any monitor for any G device that you hand it it will hand you back a rectangle which is the legal space that a window can live in so it's important to start using that some of the API is that we have actually already take the dock into consideration so for example resize window or zoom window so you don't need to deal with in that situation will automatically handle it for you the window menu is something new and it's completely supported by the toolbox it automatically tracks document class windows and you add it to you menu bar by calling create standard window menu and hands you back a menu you then take the menu and insert it into menu bar yourself the reason that we don't insert it for you is you might have different requirements for where it lives with with your particular menu bar all the menu items in it in the standard menu are handled automatically by the toolbox but you can actually add items to this menu and not affect the menu adversely we drive it completely by menu commands so as long as you don't steal our commands you know we'll just handle it for you so you can add your own commands to growing you know maybe you want to add a menu item to do like tiling or stacking or whatever you want another thing that we've added though is this concept of alternate titles we have API to set a windows alternate title and what we use this for we use it for like three things the first is we will show it in the window menu the second thing we'll use it for is when you minimize a window its alternate title will show up when you roll over it with the mouse on in the dock and the third place you'll see it is actually the dock pop-up when it shows the window list the reason for this particular alternate title concept is that you may have windows in your application that all have the actual same title but maybe they're showing different animal parts of the file system or whatever it is you can actually leave the window titles alone but specify an alternate title and that's what will show up in the window menu certainly when you're looking at a window you can pretty much tell oh this is for that you know I'm looking at you know whatever part of the file system where that part file system or whatever the case might be but if you're looking in the window menu there's no way to just you know discriminate between the two or between all of your windows so alternate titles allow you to specify a different titles so we have a lot of default behavior in the toolbox and we don't allow you to patch these days but we do have carbon events so you can actually customize the window manager to you into whatever needs you know to your own desire by doing by installing carbon event handlers and there are if you look at carbon events now th there are a lot of events that we send out for windows I wanted to point out some of the more common ones that you would tend to override the first is K event window bounce change whenever you are dragging a window or resizing the window we will send out K event window bounds change and that should actually be changing but little typo there and you can actually use this to do window gridding snap to behavior we can have pallet snap together or to the edges of the screen that would be the most common use for that the next one is K event window get click activation this allows you to do click through whenever the toolbox detects it click on a window that is not the front window not the active window in your application we will send this event to it asking it what should we do how do you want to handle this we just got to click should we bring you forward or not and there are a couple of results that you can return but to do click through you would basically say don't activate me but I do want to handle the click and this is how you can accomplish background dragging so dragging from a window that's in the background onto some window that's in the foreground without that window coming forward first the next event is K event window handle content click if you're using the standard window handler this is the way you would in to intercept clicks on your own custom content this is essentially what it does is it represents a click that is not in any toolbox entity that we know of it's in effectively some other region of the window so if you have like custom views but you have standard controls but standard controls would actually be handle by the toolbox but you can handle your custom views just by intercepting this event and it's effectively a mouse down event it has all the same parameters now the toolbox as I said has a lot of default behaviors and for example we will actually zoom windows for you when we do that we need to know information like what is the ideal size of the window so when a zoom is detected we were about to do a zoom we will actually send the window a Kate event window get ideal size event in response to that your applications to say oh I should be so big store that back into the event and then the tool box can do the right thing likewise for a resize window while we were when we were about to resize we will send out a key event window get minimum and get maximum size you just tell us what those constraints are and we'll do the right thing with it this next slide is about a feature that we're going to attempt to turn on in the next major release Mac OS 10 the reason that I'm bringing it up though is because I want to kind of get you ready for it server side window dragging what that means is that the window servers in control of dragging the windows around Coco already does this we're going to turn this on in carbon the advantages are first that we don't actually have to keep talking to the windows server so right now what happens is we get a mouse move we're tracking a window anyway say okay move the window we tell the window server move the window it sends us another mouse to move event and we keep this back-and-forth traffic as you're dragging a window around it's kind of a lot of crosstalk so we want to eliminate that the next thing is that if your application is just stopped dead something's happen you're in a tight loop or you just went away for a while the user can still move the windows of your application you don't have to be actually handling that and this is kind of useful at times this also has an effect that it actually makes your application seem much more responsive the reason is let's say your application was swapped out cuz he got a lot of applications open and we had to swap your app out click on it he needs to swap it back in and normally we'd have to swap back in all the code that had to deal with dragging and all of that fun stuff but because the Windows servers in control we can actually start to drag the window immediately so rather than seeing a big delay before the windows started to follow the mouse the window would actually start moving immediately and this has a profound impact on the user because they feel like they're in control you know the system is keeping up with them and it's rather important now the reason that I'm talking about this at all is because it's going to require changes to wdesk what we want to do is give a window definition a coordinate system that starts at zero zero not at the global coordinates set the windows so if you are writing W depths you will need to be aware of this when this happens now we're not going to break any existing wdesk but it will mean that if the W def does not support this server-side dragon we can't turn it on for your application now you're going to have to turn this on manually if you're doing the window dragon yourself if you are using the standard window handler this will be turned on for free again provided that your the WF supports it custom W deaths still supported for any W deaf that we need to reference in a resource like a wind resource you can register the resource ID with the tool box along with the proc pointer which implements the DEF proc with register window definition if you happen to have where you happen to start writing a carbon event based def proc you would use register toolbox object and then you just use create custom window in your custom window runs and it's all good now I'd like to do is show you a little bit about the stuff that we just talked about and to do that I like to bring up guy full it in but I do have to remind ads that I won the last game last night so not always a target first anymore I want to show you guys has to do with window groups when possible you might have four window groups is if you have just a window that happens to split to display little sub windows for editing purposes like let's say this is a very very primitive mail application that needs a way to add an address and add a name to an address book and it happens to pop up a little sub window here which is implemented as another window manager window now you can type in there and all but with window groups we actually allow you to tie those two windows together so that you can drag them around together and have them z-order get together properly and another cool thing about window groups is they're totally arbitrary you can set up whatever groups you like and you can include or remove windows from them as you wish so I've got these four windows that as you saw just then as I was clicking on each of them they activated separately now that I have them all grouped together they activate together just as you would expect and you can drag them together just as you would expect and they minimize together just as you would expect [Applause] so the next thing I want to show you is some of the overlay windows support one things you might one thing you might want to do with overlay windows is give the user a way to sort of draw on arbitrary parts of the screen so this event horizon application has overlay support built into it and I just turned on the overlay window for this app so I can start to scribble wherever I want over the screen like it scribble over the dock I can scribble over finder icons do whatever I want you could even use it as sort of a primitive coach marking mechanism if you wanted to oh we might have just gotten ourselves in trouble well I guess that would be me too got in trouble I don't know okay it worked up let's close that window now another use for overlay windows might be if you're an alien race that wants to invade the planet and you need to throw a message up on somebody's screen you could also do that just a shot so one of the other things I'd mentioned is we've been working on transparent sheets support for carbon and what I'm running here isn't exactly Mac OS 10 GM we've got some bleeding edge pieces in there and I want to show you the progress we've been making this application is simpler text I showed this off yesterday it's just a replacement for simple text and it uses the standard nav services save don't save dialog but on the system we've enabled transparent sheets so if I try to close the window you can see that the sheet really is transparent uses all the standard control manager controls and it just works when we turn that on now I showed it's I showed this app yesterday this is live buttons the cool thing about this actually has to do with the fact that we install Carbon event handlers to allow you to manipulate an otherwise static user interface and what we were writing this application it brought to the forefront one of the really major problems with the Control Manager and that is that if you have peer controls that happen to overlap you get let's do this too you get some really strange behaviors with the interface where whatever control you happen to click on last is what sort of owns the draw area and you get really ugly looking graphics and in fact let's say you try to throw a picture into the background of that window not only do you get the the normal compositing issue you might expect but as soon as the picture tries to draw it totally obliterates all the rest of the controls well the coolest bit about the support we did for transparent sheets is that it enables us to allow proper control compositing so we can draw layered controls just as you would expect you can click on controls and they will highlight in the proper peer order this picture happens to be behind other controls so when I click on it oh you know what I'm clicking on text at that point if I click on it over here you can see that just the picture highlights none of the other controls highlight all the animation just works you still have a spinning progress their arrows drawing on top of the ok button so this is something that you can look forward to in a future release of Mac OS 10 and now I'm gonna send it back to Ed to talk a little bit about the menu manager all right [Applause] so obviously the first bit of that that you'll see would be two transparent sheets and later on and we'll actually make that a general-purpose thing that anybody can use so the menu manager made quite a few changes to the menu manager as well first you can have icons for menu titles you know yes believe it next thing is we support invitation and menu section support a good example of this is the recent items menu which is under the Apple menu in mechanist and you can actually do this we support it fully in them in the menu manager you don't have to write a custom em death we have much better command ID access so command IDs are a way to identify a menu item which is a position independent method of doing so and that's great but you actually want to manipulate those menu items using the command ID as well and we have full support for doing so with carbon we support ref counting dynamic items this would be if you have a particular menu accelerator in your in a menu and you want it to actually change the text depending on what modifier keys it down we support that we actually have and we also have much better hierarchical support historically what you've done is you insert your menu your hierarchical menu into the hierarchical menu list using you know insert menu negative one and then you reference that by putting the ID of that menu into the actual parent item well we've come up with a slightly better way which is you just take the menu ref and you've set it on the parent item and you've done you want to play those games anymore we also support certain carbon events the first is begin and then tracking whenever the mouse goes down in the menu bar and we were about to call or basically when many selectors called what it comes down to when we start menu select we send out begin tracking when we end menu selector we call end tracking and we send that event out and this might be useful if you have timers which are firing but you don't want them to fire while the menus are down you can actually disable them by looking for this this notification we also have a really cool event called cave event menu opening and you can do this for lazy construction of menus let's say you had a hierarchical menu and it showed part of the file system or something you don't necessarily want to populate it you know all up at once that might be kind of intensive so what you can do is wait from K event menu opening and then go out to the file system fill in the menu and then it will be display with those contents and lastly we have what is the direct replacement for the menu hook function K event menu target item so whenever you are rolling over an item will send this event out and you can use that notification to maybe put up some contextual help or whatever you need to do the menu manager truly supports Carbon events and it supports commands like I said we have much better command ID support part of that involves dealing with enabling and disabling menu items whenever a menu is about to be shown for every item in the menu we send out K event command update status events that's your time to say update the text add a check mark whatever you want to do now like I said we do that for every item in the menu so that could potentially be a lot of different update status commands that we're sending around your application might want to do it all at once and you can do that by intercepting the K event menu enable items event in fact the default toolbox response to an unhandled enable items event is to send out update status for every for every item in the menu so maybe your application architecture only works based on a per menu enabling strategy so that's the event that you would tap in for that it's actually important that wait next event based apps respond to these events as well as pure carbon event based apps and the reason is that if you happen to have event handlers in your application they will be they will be called while you were inside wait next event typically what would happen in the past is you exit from wait next event find out you had a keyboard event or maybe a mouse event that happened to be in a menu bar and then you would go and update the status of your menu items well because we're dispatching this inside of the way next event you don't necessarily get that chance so it might be that it usually hits a command key that item is enabled currently in the menu bar we will actually go and call a command handler for that might not even be the effect that you want because it might actually be the quick command so your application may end up getting a quit apple event and you didn't expect it to so in those cases you need to make sure that you're dealing with enabling and disabling the items appropriately back in Mac OS traditional Mac OS we dealt with the Edit menu in a very interesting manner basically we had this thing which kind of looked for any window as they were coming up it was like a JG any filter and we'd see a new window and go oh new window is it a dialog and we say oh yeah it's a dialog and is there add edit text field ago yes oh good great then let's deal with the Edit menu where is it oh I don't know go scan the menu bar for anything with a you know an X or a V next to it and we'll what that must be the yet menu that has some negative connotations in that it first off it pulls like crazy and we don't want to do that Mac os10 second office just bad code we don't want that so we already have this mechanism which was the command ID mechanism it's the right mechanism so it's actually important that for your edit menus in carbene you use the standard command IDs that we've put into carmen advantage it doesn't hurt anything if you're not using the command for your application at all it doesn't hurt you but it allows us to at least find them in the menu bar and this is important particularly when we put up dialogues because the dialogue manager still wants to deal with the Edit menu appropriately and actually it's not even the dialogue manager these days it's the individual edit text controls because they are the focus they get to control the Edit menu appropriately and lastly it's important to note that these update status commands can actually be sent out at any time it's not just oh there was a key down or there was a mouse down in the menu bar it might have been some programmatic change of the window ordering or something maybe somebody calls select window like the tool box when that happens if you had a focused edit text control which was owning the edit menu and now you're in a window which has no focus the Edit menu should actually be disabled so the tool box will actually in that case detect oh I need to you know the focus has changed I need to go and dirty the menu bar so when it sees that it's dirty he will actually send out these process I mean these update status commands so be aware that they could be flying at you at any time the Apple and application menus are one in the same on Mac OS 9 but they're different on Mac OS 10 the Apple menu just exists on Mac OS 10 it's always there omnipresent staring at you watching you but the Apple menu on Mac OS 9 is the Apple menu that you always knew while on Mac OS 10 it becomes what we termed the application menu it's the menu with the name of your application you should continue to insert your Apple menu into the menu bar just like you always have basically it's the placeholder it's a place that you put your about item and whatever other items that you've historically put there so you want to keep doing that and like I said on nine it just is the Apple menu like like you always knew it and on 10 it's the application menu most of the items in these menus are handled automatically the exceptions are really quit and preferences these are commands that you need to deal with obviously if the user selects command Q they want to quit your app you should probably respond and quit being so stubborn for preferences you know the user wants to change some aspect of your application the way it works or whatever you need to respond to that by default the Preferences item is disabled so it's actually up to your application to enable it and you can do it by command ID we supply the command ID and carbon of NSH and you can also enable and disable the quit menu item however you need to be a command ID as well now don't let the first bullet scare you I mean we don't by default have a help menu there however if you call HM get help menu we will automatically insert one if your application happens to specify a help book in your info dot P list we will all and we will automatically create to help menu for you as well as in the past you can just add menu items as you see fit to this menu for any menu items that you add you will get the commands for them you can just install a command handler for any items that the system has installed will handle them automatically well that was short that's because they drop a couple of my slides out either that or I talk too fast so the bottom line here is we've done a lot of work in the menu manager we've done a lot of work in the window manager the window manager just think about it I mean we've taken it from a system where everything was you know non retained we had to deal with damage repair ourselves all of these other things to a system where we actually have you know window buffering which was the slide that was missing by the way and I mean we've just added window groups we have overlay windows and the window manager is actually in such a state these days that we can start adding new window classes at a very fast pace the entire code base of the high-level tool is in great shape these days and we're making constant improvements and especially with the advent of carbon events with you know mixing in with that we can actually just start going wild now so now it's time that's really getting exciting should look at carbon events that H as always if you're looking to override a lot of the window behaviors many behaviors and it's important to go and port your application that's why you're here you're trying to learn about Mac os10 we're trying to tell you all we can try to help you along so that I'd like to bring mark Turner back out and take you through roadmap and then we'll do Q&A thanks Thank You ed so coming up tomorrow morning we have controls and appearance 1 & 2 back to back hope you can make those 2 and then carbon performance tuning at 2 p.m. that's gonna be a great one for learning about the different performance characteristics of your api's as you run on Mac OS 10 vs Mac OS 9 and this is me my job is to help you adopt carbon and get your apps to Mac OS 10 so if you have questions either today or after WWDC email me you