home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22208 < prev    next >
Encoding:
Text File  |  1993-01-27  |  3.6 KB  |  85 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!nih-csl!FAXCSL!FIXER
  3. From: fixer@faxcsl.dcrt.nih.gov (Chris Bearded Guacamole Tate)
  4. Subject: Re: Modeless Dialogs - Newbie
  5. Message-ID: <1993Jan26.235133.7605@alw.nih.gov>
  6. Sender: postman@alw.nih.gov (AMDS Postmaster)
  7. Reply-To: fixer@faxcsl.dcrt.nih.gov
  8. Organization: Computer Systems Laboratory, DCRT, NIH
  9. References: <25JAN199314121566@vx.cis.umn.edu>
  10. Date: Tue, 26 Jan 1993 23:51:33 GMT
  11. Lines: 72
  12.  
  13. In article <25JAN199314121566@vx.cis.umn.edu>, soc1070 writes:
  14. >I am trying to write a small app that uses a single modless dialog as
  15. >an interface. According to IM 1, if you have a modeless dialog, regardless
  16. >of what (Get)WaitNextEvent returns, you have to call IsDialogItem (and
  17. >SelectDialogItem (?), I can't remember the third function and don't have
  18. >the book in front of me) in order to get the caret to blink properly.
  19. >
  20. >I can't seem to get my event loop to track properly, either I can't hit
  21. >the menus & command keys, or my radios don't switch. I know the control
  22. >code is good (things work ok if I use a modal dialog, but the menus are
  23. >disabled).
  24.  
  25. Yes, you need to call IsDialogEvent() and DialogSelect() even if GetNextEvent()
  26. (or WaitNextEvent()) returns false, *if* your modeless dialog contains editable
  27. text items.
  28.  
  29. As for command keys and menus... 
  30.  
  31. You need to check for command-key combinations *before* calling DialogSelect(),
  32. otherwise they will be treated as normal key presses by DialogSelect() (i.e. it
  33. doesn't call MenuKey() or any such function for you).  Also, IsDialogEvent()
  34. will return FALSE for menu clicks other than those in enabled items in the
  35. dialog - this includes clicks in the menu bar.  The code that I use, although
  36. probably not perfect, looks something like this (in C):
  37.  
  38. Boolean didEvent, isDlgEvent;
  39. ...
  40. didEvent = WaitNextEvent(everyEvent, &theEvent);
  41. if (didEvent)
  42. {
  43.    isDlgEvent = IsDialogEvent(&theEvent);
  44.    if (isDlgEvent)        // is this a modeless-dialog event?
  45.    {
  46.       switch (theEvent.what)
  47.       {
  48.          case keyDown:
  49.          case autoKey:
  50.             if (theEvent.modifiers & cmdKey)
  51.                HandleMenuEvent(MenuKey(theEvent.message & charCodeMask));
  52.             break;
  53.          ...
  54.          case mouseDown:
  55.             // use FindWindow() to check for clicks in non-dialog stuff
  56.       }
  57.  
  58.       if (DialogSelect(&theEvent, &itemHit))
  59.       {
  60.          // handle as you would handle stuff after calling ModalDialog()
  61.       }
  62.    }
  63. }
  64.  
  65. This is pretty sketchy, but I hope it illustrates the general idea. 
  66. DialogSelect() will call userItems etc. for you, doing all the updating that
  67. ModalDialog() does, but can't handle special-purpose stuff, such as resizing,
  68. zooming, menus, command keys, etc.  Note that you need to write your own
  69. command key handling in modal dialogs anyway, so this isn't too much of a
  70. headache.
  71.  
  72. I've run into problems involving activate/update handling when using both
  73. windows and modeless dialogs at the same time, and when using more than one
  74. modeless dialog simultaneously.  If I had the time, I'd go back and rewrite
  75. everything to use pure windows instead of modeless dialogs.  The new edition of
  76. Inside Macintosh - Toolbox Essentials recommends that if you need to be able to
  77. resize your dialog or handle non-item-related events, you should make it a
  78. window instead.  I think this is good advice.
  79.  
  80. ------------------------------------------------------------------------------
  81. Christopher Tate             | Return of the CryptoSig (tm):
  82. Management Systems Designers |    XHGVMFCV GBGNKJ KJ LFJG X CXZB, KG GBXIVBJ
  83.                              |    DMF GVKJ: QVXGBTBN DMF AM, AMP'G ZKJJ.
  84. fixer@faxcsl.dcrt.nih.gov    |    
  85.