home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Pict2Ascii 1.03 / Panes / LDynamicPopupMenu / LDynamicPopupMenu.doc < prev    next >
Encoding:
Text File  |  1995-01-08  |  4.3 KB  |  77 lines  |  [TEXT/CWIE]

  1. class LDynamicPopupMenu v 1.0
  2.     1/8/95 written by Constantine Spathis
  3.     
  4. What it does:
  5.     This class creates a dynamic pop-up menu from a stream in a PPob resource, it disregards
  6.     the menu id you specify in the PPob popupmenu field and instead it creates a menu with ID
  7.     starting at 20000 and increments upwards from there. (NOTE: You must make sure that the 
  8.     number you pick is far from the numbers of any other possible menus, I suggest that they
  9.     be below the menu id's you use for your dynamic pop-ups)
  10.  
  11. Why is it needed:
  12.     The problem is that in powerplant when using the (PPob) stream based constructors you
  13.     must specify the menu_ID of the popup menu you want to create. You unfortunately won't
  14.     know the menuid until runtime and then all pop-ups read in from that particular ppob are
  15.     connected to that one menu and when one goes away all go away. An example may help to 
  16.     explain the problem better.
  17.     
  18.     Suppose your program uses Windows that have pop-up menus in them. Since you are supporting
  19.     multiple windows created from the same PPob all will work well, except when you want to add
  20.     a menu item to one of the windows only. Because of the Control Manager/Menu Manager 
  21.     structure the item will be added to all the pop-up menu's because all the pop-up menu's 
  22.     point to the same MenuHandle. Even worse when you close one window it disposes of the pop-up 
  23.     control and the Control Manager    disposes of the Menu. That menu no-longer exists and when 
  24.     the control in another window goes to re-draw the menu the mac will likely crash because
  25.     the menu was disposed of when the earlier control was disposed. The way LDynamicPopupMenu
  26.     gets around this is to disregard the control PowerPlant made (it disposes of it so you
  27.     don't get a memory leak) and to first create a NewMenu with a unique menu id, insert that 
  28.     menu into the menu list and recreate the control, making sure that text traits are taken 
  29.     care of properly.
  30.  
  31. How to use it:
  32.     First register the stream based creator function in the app constructor by:
  33.             URegistrar::RegisterClass('LDPM',
  34.                  (ClassCreatorFunc) LDynamicPopupMenu::CreateLDynamicPopupMenuStream);
  35.  
  36.     In your PPob create the pop-up menu exactly the way you want it to appear (including text
  37.     traits)    and alias it to class type 'LPDM'. Also in the Menu id field specify a menu resource
  38.     and make a menu of that resource number, it doesn't have to contain any items though.
  39.     I generally title these as stubs.
  40.     
  41.     Then after the menu is created (either by a direct call or because it was in a window)
  42.     begin adding Items to the menu using the member functions:
  43.                             AddPMenuItem(pstr) or
  44.                             AddCMenuItem(cstr)
  45.     I hate translating between pascal & c strings so these do it. If the item you want to add
  46.     to the menu is a c string call the member function AddCMenuItem passing it a c-string, if 
  47.     instead the item you want to add to the menu is a pascal string call the member function 
  48.     AddPMenuItem passing it a pascal string.
  49.     
  50.     After you are finished adding menu items it is crucial that you call the member function:
  51.  
  52.                         FinishedCreatingMenu(Int32 in_initialItem)    //    Initial Menu Item to show
  53.     
  54.     It puts stuff right, the parameter to pass is the number of the item you want displayed.
  55.     You can still add and modify items after this but call it before the menu gets drawn. If
  56.     you notice that the menu is coming up blank but when you mouse down the menu is correct
  57.     you probably forgot to call this member function.
  58.     
  59.     You'll probably want to modify the included BroadcastValueMessage in the LDynamicPopupMenu
  60.     class it does really bad things now for the demo program included.
  61.     
  62.     Note this class LDynamicPopupMenu is derived from LStdPopupMenu and you can call whatever member
  63.     functions you could call in LStdPopupMenu.
  64.  
  65. Who is Responsible:
  66.     Not me, this is total freeware, no rights are reserved, use it and abuse it at will. If you find
  67.     bugs or if you come up with some cool modifications I would love to hear about them.
  68.     I have tested this stuff and all appears well though.
  69.     
  70. Who to thank:
  71.     Greg Dow for coming up with such a nifty framework, Ron Liechty    (hope I spelled that one 
  72.     correct) who must really be 10 guys from the way he    keeps ontop of answering questions,
  73.     and of course all the gang at Metrowerks for the coolest compilers (not to mention geekware).
  74.     
  75.     
  76.     Constantine Spathis
  77.     MadHack@aol.com