kenk@sunHd.tellabs.com (Ken Konecki) (01/03/91)
I'm having trouble getting dialogs to work inside of a desk accessory. I keep the item list as an owned resource and do a GetResource() call to get a handle to it. When I create the dialog, I use NewDialog() and pass the handle of the item list obtained from GetResource() as the item list parameter. I do the dialogging and then call CloseDialog() at the end of the routine. Everything works as I expect it to but only on the first time I bring up the dialog. The second time I try, I get an address error and get dropped into Macsbug. Stepping through the routine with Macsbug, I've found that the call to NewDialog() returns a valid dialog record, but the control list is NIL. As you would expect, the first time through the routine, the control list of the dialog window is not NIL. This is of course why it the routine bombs the second time but not the first. The big question is: Why is the control list NIL the second time I call NewDialog()? I have enclosed the offending routine at the end of this post. The desk accessory I'm writing is a simple calendar display. The dialog is used to set the month and year that is being displayed. I'm using Think C 4.0 on a Mac SE. Thanks in advance for any help. Cheers, -Ken K #define ITEMS_ID 1 #define JAN_BTN 3 #define YEAR_ITEM JAN_BTN + 12 #define OFF 0 #define ON 1 static rsrcID(id) int id; { return (0xc000 + (~dce->dCtlRefNum << 5) + id); } static Handle dlogItems; int checkItems() { return ((dlogItems = GetResource('DITL', rsrcID(ITEMS_ID))) != NULL); } void setMonth(month, year) unsigned *month, *year; { int itemHit; register DialogPtr monthDlog; Str255 text; int oldMonth; Rect box; int itemType; Handle item, yearItem; long newYear; int dlogDone = FALSE; Debugger(); dlogItems = GetResource('DITL', rsrcID(ITEMS_ID)); SetRect(&box, 110, 68, 400, 200); monthDlog = NewDialog(NULL, &box, "\pSet Month", FALSE, 1, PUT_IN_FRONT, FALSE, 0L, dlogItems); /* * Unhilite the old button and hilite the new */ oldMonth = *month; GetDItem(monthDlog, oldMonth + JAN_BTN - 1, &itemType, &item, &box); SetCtlValue((ControlHandle) item, ON); /* * Set the current year as the default year */ NumToString((long) (*year), text); GetDItem(monthDlog, YEAR_ITEM, &itemType, &yearItem, &box); SetIText(yearItem, text); SelIText(monthDlog, YEAR_ITEM, 0, 32767); ShowWindow(monthDlog); /* DrawControls(monthDlog); */ /* * Do the dialogging */ while (!dlogDone) { ModalDialog(NULL, &itemHit); if (itemHit == 1) { /* * Ok button */ *month = oldMonth; GetIText(yearItem, text); StringToNum(text, &newYear); *year = (int) newYear; /* * Do some error checking */ dlogDone = TRUE; } else if (itemHit == 2) { /* * Cancel Button */ dlogDone = TRUE; } else if ((itemHit >= JAN_BTN) && (itemHit < YEAR_ITEM)) { /* * One of the radio buttons was hit */ GetDItem(monthDlog, oldMonth + JAN_BTN - 1, &itemType, &item, &box); SetCtlValue((ControlHandle) item, OFF); oldMonth = itemHit - JAN_BTN + 1; GetDItem(monthDlog, itemHit, &itemType, &item, &box); SetCtlValue((ControlHandle) item, ON); } } updateCalendar(); CloseDialog(monthDlog); } -- Ken Konecki "Eat well, stay fit, and die anyway" e-mail:kenk@tellabs.com -or- ...!uunet!tellab5!kenk
stevec@Apple.COM (Steve Christensen) (01/03/91)
kenk@sunHd.tellabs.com (Ken Konecki) writes: >I'm having trouble getting dialogs to work inside of a desk accessory. I >keep the item list as an owned resource and do a GetResource() call to get >a handle to it. When I create the dialog, I use NewDialog() and pass the >handle of the item list obtained from GetResource() as the item list >parameter. I do the dialogging and then call CloseDialog() at the end of >the routine. Everything works as I expect it to but only on the first time >I bring up the dialog. The second time I try, I get an address error and >get dropped into Macsbug. Stepping through the routine with Macsbug, I've >found that the call to NewDialog() returns a valid dialog record, but the >control list is NIL. As you would expect, the first time through the >routine, the control list of the dialog window is not NIL. This is of >course why it the routine bombs the second time but not the first. The big >question is: Why is the control list NIL the second time I call >NewDialog()? > >I have enclosed the offending routine at the end of this post. The desk >accessory I'm writing is a simple calendar display. The dialog is used to >set the month and year that is being displayed. I'm using Think C 4.0 on a >Mac SE. > > [code snippet deleted] I guess my first question would be "why aren't you just using a dialog template (DLOG) as well as the item list (DITL)?". You can then just call GetNewDialog() which will return a non-nil pointer if everything is setup OK. I don't know exactly why your way is failing, but this seems a whole lot simpler... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen | Apple Computer, Inc. | Disclaimer: | 20525 Mariani Ave, MS-81CS | the above may be stevec@apple.com | Cupertino, CA 95014 | a lie...or not.
kenk@tellabs.com (Ken Konecki) (01/03/91)
In article <47695@apple.Apple.COM> stevec@Apple.COM (Steve Christensen) writes: >I guess my first question would be "why aren't you just using a dialog >template (DLOG) as well as the item list (DITL)?". You can then just >call GetNewDialog() which will return a non-nil pointer if everything >is setup OK. I don't know exactly why your way is failing, but this >seems a whole lot simpler... I was wondering when someone was going to ask me this. I was having trouble with Font/DA mover renumbering the DITL resource. Consequently, when I would call GetNewDialog(), the DITL resource number within the DLOG template would be wrong. Is it possible to make the DITL resource owned by the DLOG resource and have Font/DA mover put it in the system file correctly? Thanks, -Ken K -- Ken Konecki "Eat well, stay fit, and die anyway" e-mail:kenk@tellabs.com -or- ...!uunet!tellab5!kenk
stevec@Apple.COM (Steve Christensen) (01/04/91)
kenk@tellabs.com (Ken Konecki) writes: >stevec@Apple.COM (Steve Christensen) writes: >>I guess my first question would be "why aren't you just using a dialog >>template (DLOG) as well as the item list (DITL)?". You can then just >>call GetNewDialog() which will return a non-nil pointer if everything >>is setup OK. I don't know exactly why your way is failing, but this >>seems a whole lot simpler... > >I was wondering when someone was going to ask me this. I was having >trouble with Font/DA mover renumbering the DITL resource. Consequently, >when I would call GetNewDialog(), the DITL resource number within the DLOG >template would be wrong. Is it possible to make the DITL resource owned by >the DLOG resource and have Font/DA mover put it in the system file >correctly? Use an owned resource ID for both the DLOG and DITL. For example, if your DA has an ID of 20, you should use an ID of (-15744 + offset), where, I believe, offset is in the range of something like 0 to 15, and -15744 is the base resource ID. Then Font/DA Mover should renumber everything correctly, and all your DA has to do is dynamically calculate the base resource ID from its new ID and add on the appropriate offset... steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen | Apple Computer, Inc. | Disclaimer: | 20525 Mariani Ave, MS-81CS | the above may be stevec@apple.com | Cupertino, CA 95014 | a lie...or not.
rad@genco.bungi.com (Bob Daniel) (01/05/91)
In article <4927@tellab5.tellabs.com> kenk@sunHd.tellabs.com (Ken Konecki) writes: >I'm having trouble getting dialogs to work inside of a desk accessory. I >keep the item list as an owned resource and do a GetResource() call to get >a handle to it. When I create the dialog, I use NewDialog() and pass the >handle of the item list obtained from GetResource() as the item list >parameter. I do the dialogging and then call CloseDialog() at the end of >the routine. Everything works as I expect it to but only on the first time >I bring up the dialog. The second time I try, I get an address error and >get dropped into Macsbug. Stepping through the routine with Macsbug, I've >found that the call to NewDialog() returns a valid dialog record, but the >checkItems() (code deleted) First of all, you will probably want to use a DLOG resource and load that. Second, you should do a GetPort(&savePort) before a modal dialog and SetPort(savePort) after any modal dialog. I just deleted the code, but did you setup globals within you filter? In DA's, you need to setup and restore globals within the filter proc (atleast in Think Pascal you do). _________ moof moof
rad@genco.bungi.com (Bob Daniel) (01/06/91)
In article <4932@tellab5.tellabs.com> kenk@tellabs.com (Ken Konecki) writes: >I was wondering when someone was going to ask me this. I was having >trouble with Font/DA mover renumbering the DITL resource. Consequently, >when I would call GetNewDialog(), the DITL resource number within the DLOG >template would be wrong. Is it possible to make the DITL resource owned by >the DLOG resource and have Font/DA mover put it in the system file >correctly? Doesn't sound like you are using owned resources. Your resources should be numbered starting at -16000 (and then increment each after). Which is a DRVR owner of ID 12. Increment the SubID for each DLOG/DITL. When loading the DLOG, load the ID based on the resource base passed in from the device control entry and add the SubID of the DLOG you want. TheDialog := GetNewDialog(rsrcBase + 1, nil, Pointer(-1)); where: rsrcBase := BOr($C000, BSL(Abs(theDevCtlEnt^.dCtlRefNum) - 1, 5)); See Mac Revealed Volume 3 When you use owned resourced owned by DRVR, the F/DA mover will properly move all resources. _________ moof moof