home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / MENU.PR_ / MENU.PR
Text File  |  1995-06-20  |  6KB  |  233 lines

  1. /***
  2. *
  3. *  Menu.prg
  4. *
  5. *  Sample menu handling functions
  6. *
  7. *  Copyright (c) 1990-1995, Computer Associates International Inc.
  8. *  All rights reserved.
  9. *
  10. *  This is not meant to run as a standalone file.  There are function
  11. *  calls from within this file (such as MyCreateFile()) that do not
  12. *  exist.  This code can be modified, however, for your use.  If it
  13. *  is modified, use the /n switch when compiling.
  14. *
  15. *  Compile: CLIPPER menu /n
  16. *  Link: EXOSPACE FI menu
  17. *
  18. ***/
  19.  
  20.    #include "button.ch"   // Menu definitions
  21.    #include "inkey.ch"    // Key definitions
  22.  
  23.  
  24. // This function sets up the environment and then calls MENU_Create() to
  25. // create the menu.  Finally, it waits for a menu event to occur by calling
  26. // the MenuModal() function.
  27.  
  28. function MENU_Test()
  29.    local oInfo
  30.  
  31.    // Allow mouse actions to take place
  32.    SET( _SET_EVENTMASK, INKEY_ALL )
  33.  
  34.    // Make the mouse cursor visible
  35.    msetcursor(.T.)
  36.  
  37.    // Clear the screen
  38.    cls
  39.  
  40.    // Create the menu
  41.    oInfo=MENU_Create()
  42.  
  43.    // Wait for a menu event and do not exit until File/Exit is chosen
  44.    DO WHILE MenuModal(oInfo,1,24,1,79,"r/w") <> 999
  45.    ENDDO
  46.  
  47.    return(NIL)
  48.  
  49.  
  50.  
  51. // This function will create the menu and return the newly created
  52. // MenuObject as its return value.  This menu consists of three "Main Menu choices" ..
  53. // File, Edit, and Options.  Additionally, the Edit TopBarMenu item has a secondary menu for
  54. // one of its menu items.
  55.  
  56. function MENU_Create()
  57.    local oTopBar, oPopUp, oPopUp1, oItem
  58.  
  59.  
  60.       // TopBar() creates the menu at the very top of the screen
  61.       oTopBar := TopBar( 0, 0, 78)
  62.       oTopBar:ColorSpec :="b/w,gr+/rb,r/w,g/rb,n+/w,w+/b"
  63.  
  64.  
  65.       // Create a new popup menu named FILE and add it to the TopBar object
  66.       oPopUp := PopUp()
  67.       oPopUp :ColorSpec:= "b/w,gr+/rb,r/w,g/rb,n+/w,w+/b"
  68.       oTopBar:AddItem( MenuItem ( "&File",oPopUp) )
  69.  
  70.  
  71.       // Add some menu items to the newly created File popup
  72.       oItem :=MenuItem( "&New" ,{|| MyCreateFile() }, K_CTRL_N,"Create a new file", 101)
  73.       oPopUp:AddItem( oItem)
  74.  
  75.  
  76.       oItem :=MenuItem( "&Open..." ,{|| MyOpenFile() }, K_CTRL_O,"Open a file")
  77.       oPopUp:AddItem( oItem)
  78.  
  79.  
  80.       oItem :=MenuItem( "&Save" ,{|| MySaveFile() }, K_CTRL_S,"Save a file")
  81.  
  82.       // Disable this menu item
  83.       oItem:Enabled := .f.
  84.       oPopUp:AddItem( oItem)
  85.  
  86.  
  87.       // Add a separator
  88.       oPopUp:AddItem( MenuItem( MENU_SEPARATOR ) )
  89.  
  90.  
  91.       oItem :=MenuItem( "&Print..." ,{|| MyPrintFile() }, K_CTRL_P,"Print a file")
  92.       // Disable this menu item
  93.       oItem:Enabled := .f.
  94.       oPopUp:AddItem( oItem)
  95.  
  96.  
  97.       // Another separator
  98.       oPopUp:AddItem( MenuItem( MENU_SEPARATOR ) )
  99.  
  100.  
  101.       oItem :=MenuItem( "E&xit" ,{|| .t. }, K_ALT_F4,"End of application", 999)
  102.       oPopUp:AddItem( oItem)
  103.  
  104.  
  105.       // Create a second popup menu named EDIT and attach it to oTopBar
  106.       oPopUp := PopUp()
  107.       oPopUp :ColorSpec:= "b/w,gr+/rb,r/w,g/rb,n+/w,w+/b"
  108.       oTopBar:AddItem( MenuItem ( "&Edit",oPopUp) )
  109.  
  110.       // Add some menu items to this EDIT popup menu
  111.       oItem :=MenuItem( "&Undo" ,{|| MyUndo() }, K_CTRL_Z,"Reverse changes made to this file")
  112.       oPopUp:AddItem( oItem)
  113.  
  114.  
  115.       oItem :=MenuItem( "Cu&t" ,{|| MyCut() }, K_CTRL_X,"Cut to clipboard")
  116.       oPopUp:AddItem( oItem)
  117.  
  118.  
  119.       oItem :=MenuItem( "&Copy" ,{|| MyCopy() }, K_CTRL_C,"Copy to clipboard")
  120.       oPopUp:AddItem( oItem)
  121.  
  122.  
  123.       oItem :=MenuItem( "&Paste" ,{|| MyPaste() }, K_CTRL_V,"Paste from clipboard")
  124.       oPopUp:AddItem( oItem)
  125.  
  126.       // Another separator
  127.       oPopUp:AddItem( MenuItem( MENU_SEPARATOR ) )
  128.  
  129.  
  130.       // Create a new popup menu on the EDIT popup menu named Go.  (This is also
  131.       // known as a "Cascading" menu.)
  132.       oPopUp1 := PopUp()
  133.       oPopUp1 :ColorSpec:= "b/w,gr+/rb,r/w,g/rb,n+/w,w+/b"
  134.       oItem :=MenuItem( "&Go",oPopUp1 )
  135.  
  136.       oPopup:AddItem( oItem )
  137.  
  138.       // Add some items to the Go cascading menu
  139.       oItem :=MenuItem( "&Go To..." ,{|| MyGoToLine() }, K_F5,"Go to a specific line number")
  140.       oPopUp1:AddItem( oItem)
  141.  
  142.  
  143.       oItem :=MenuItem( "G&o To Top" ,{|| MyGoTop() }, K_CTRL_HOME,"Go to top of file")
  144.       oPopUp1:AddItem( oItem)
  145.  
  146.  
  147.       oItem :=MenuItem( "Go To &Bottom" ,{|| MyGoBottom() }, K_CTRL_END,"Go to bottom of file")
  148.       oPopUp1:AddItem( oItem)
  149.  
  150.       // Change the style of the GO popup menu.  The second character in
  151.       // the string below represents the arrow that will be displayed next
  152.       // to the word GO.  The default is a "", but I have changed it to
  153.       // a ">".  I have kept the check mark ("√") the same as the default.
  154.       oItem :Style = "√>"
  155.  
  156.       // Add yet another separator
  157.       oPopUp:AddItem( MenuItem( MENU_SEPARATOR ) )
  158.  
  159.  
  160.       // Add one final menu item to the EDIT popup menu
  161.       oItem :=MenuItem( "&Find..." ,{|| MySearch() }, K_ALT_F3,"Search for text")
  162.       oPopUp:AddItem( oItem)
  163.  
  164.       //Create a 3rd PopUpMenu called OPTIONS and attatch it to oTopBar
  165.       oPopUp := PopUp()
  166.       oPopUp :ColorSpec:= "b/w,gr+/rb,r/w,g/rb,n+/w,w+/b"
  167.       oTopBar:AddItem( MenuItem ( "&Options",oPopUp) )
  168.  
  169.  
  170.       // Add the first item to the OPTIONS popup menu
  171.       oItem :=MenuItem( "AutoSave" ,{|| MyAutoSave() },,"Toggle auto save preference")
  172.  
  173.  
  174.       // Place a check mark next to this new item
  175.       oItem:Checked := .t.
  176.       oPopUp:AddItem( oItem)
  177.  
  178.  
  179.       // Add a second item to the OPTIONS popup menu.
  180.       oItem :=MenuItem( "Tab Stops..." ,{|| MyTabStops() },,"Set number of spaces for tab stops")
  181.       oPopUp:AddItem( oItem)
  182.  
  183.  
  184.    // Return our TopBar object back to MENU_Test()
  185.    return ( oTopBar)
  186.  
  187.  
  188. // The following are dummy functions which do not do anything
  189. // These functions are here to avoid receiving Unresolved External
  190. // Errors
  191.  
  192. FUNCTION MyCreateFile()
  193. RETURN NIL
  194.  
  195. FUNCTION MyOpenFile()
  196. RETURN NIL
  197.  
  198. FUNCTION MySaveFile()
  199. RETURN NIL
  200.  
  201. FUNCTION MyPrintFile()
  202. RETURN NIL
  203.  
  204. FUNCTION MyUndo()
  205. RETURN NIL
  206.  
  207. FUNCTION MyCut()
  208. RETURN NIL
  209.  
  210. FUNCTION MyCopy()
  211. RETURN NIL
  212.  
  213. FUNCTION MyPaste()
  214. RETURN NIL
  215.  
  216. FUNCTION MyGoToLine()
  217. RETURN NIL
  218.  
  219. FUNCTION MyGoTop()
  220. RETURN NIL
  221.  
  222. FUNCTION MyGoBottom()
  223. RETURN NIL
  224.  
  225. FUNCTION MySearch()
  226. RETURN NIL
  227.  
  228. FUNCTION MyAutoSave()
  229. RETURN NIL
  230.  
  231. FUNCTION MyTabStops()
  232. RETURN NIL
  233.