home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 6.ddi / SAMPLE.LIF / ODEMO2.PRG < prev    next >
Encoding:
Text File  |  1991-04-14  |  7.2 KB  |  296 lines

  1. /***
  2. *  Odemo2.prg
  3. *  Demonstrate proper usage of OMENU menu system
  4. *  
  5. *  Copyright (c) 1990 Nantucket Corp.  All rights reserved.
  6. *  Craig Ogg
  7. *
  8. */
  9.  
  10. #include "Omenu.ch"
  11. #include "Inkey.ch"
  12. #include "Memoedit.ch"
  13.  
  14. /* Definitions for all of the menus and menu prompts */
  15.  
  16. // Menu definitions
  17. #define F_GET     10
  18. #define F_MEMO    11
  19. #define F_SAVE    12
  20. #define F_SAVEAS  13
  21. #define F_PRINT   14
  22. #define F_EXIT    15
  23.  
  24. // Prompt definitions
  25. #define SA_NORM   131
  26. #define SA_WK1    132
  27. #define SA_DBF    133
  28.  
  29. #define DB_CLIP   1331
  30. #define DB_III    1332
  31. #define DB_IV     1333
  32.  
  33. #define E_UNDO    20
  34. #define E_CUT     21
  35. #define E_COPY    22
  36. #define E_PASTE   23
  37. #define E_CLEAR   24
  38.  
  39. #define S_BELL    30
  40. #define S_WRAP    31
  41. #define S_CONFIRM 32
  42.  
  43. STATIC hBar, hFileMenu, hEditMenu, hSetMenu, hSaveSubMenu, hdBASESub
  44.  
  45. FUNCTION Odemo2()
  46.    LOCAL nChoice
  47.  
  48.    // Function to show how menus are created (see below)
  49.    CreateBar()
  50.  
  51.    CLS
  52.    @ 12, 0 SAY "Press <F10> or Alt-<highlighted letter> to activate menu..."
  53.  
  54.    // Initially give bar complete control
  55.    BarActivate( hBar )
  56.    nChoice := BarMenuChoice( hBar )
  57.    DO WHILE nChoice != F_EXIT
  58.       DO CASE
  59.       CASE nChoice == F_GET   
  60.           DO GetProc
  61.       CASE nChoice == F_MEMO
  62.           DO MemoProc
  63.       CASE nChoice == F_PRINT
  64.           DummyProc("Print option.")
  65.       CASE nChoice == SA_NORM
  66.           DummyProc("Save normal file option.")
  67.       CASE nChoice == SA_WK1
  68.           DummyProc("Save Lotus file option.")
  69.       CASE nChoice == DB_CLIP
  70.           DummyProc("Save Clipper file option.")
  71.       CASE nChoice == DB_III
  72.           DummyProc("Save dBASE III+ file option.")
  73.       CASE nChoice == DB_IV
  74.           DummyProc("Save dBASE IV file option.")
  75.       OTHERWISE
  76.           BarActivate( hBar )
  77.       ENDCASE
  78.       nChoice := BarMenuChoice( hBar )
  79.    ENDDO
  80.  
  81.    RETURN NIL
  82.  
  83.  
  84. /***
  85. *  CreateBar() --> NIL
  86. *  This functions creates the menus, grays certain prompts, checks other
  87. *  prompts
  88. *
  89. */
  90. STATIC FUNCTION CreateBar()
  91.  
  92.    // Create empty bar menu
  93.    hBar := BarNew()
  94.  
  95.    // Create empty menus
  96.    hEditMenu    := MenuNew( "~Edit" )
  97.    hFileMenu    := MenuNew( "~File" )
  98.    hSetMenu     := MenuNew( "~Toggles" )
  99.  
  100.    // Create empty submenus
  101.    hSaveSubMenu := MenuNew( "Save ~As       " )
  102.    hdBASESub    := MenuNew( "~dBASE       (DBF)  " )
  103.  
  104.    // Add prompts
  105.    // Edit Menu
  106.    PromptAdd( hEditMenu, E_UNDO,  "~Undo   " )
  107.    PromptAdd( hEditMenu, E_CUT,   "Cu~t" )
  108.    PromptAdd( hEditMenu, E_COPY,  "~Copy" )
  109.    PromptAdd( hEditMenu, E_PASTE, "~Paste" )
  110.    PromptAdd( hEditMenu, E_CLEAR, "C~lear" )
  111.  
  112.    // File Menu
  113.    PromptAdd   ( hFileMenu, F_GET,    "~Get Test         " ) 
  114.    PromptAdd   ( hFileMenu, F_MEMO,   "~Memoedit() Test  " ) 
  115.    PromptAdd   ( hFileMenu, F_SAVE,   "~Save        Alt-S" ) 
  116.  
  117.    // Add submenu
  118.    PromptAddSub( hFileMenu, F_SAVEAS, hSaveSubMenu ) 
  119.    PromptAddLine( hFileMenu )
  120.    PromptAdd   ( hFileMenu, F_PRINT,  "~Print       Alt-P" )
  121.    PromptAdd   ( hFileMenu, F_EXIT,   "E~xit        Alt-X" )
  122.  
  123.    // Toggles Menu
  124.    // Code block is passed a true (.T.) if item is checked, false (.F.) 
  125.    // otherwise
  126.    //
  127.    PromptAddToggle( hSetMenu,  S_BELL,   "~Bell", ;
  128.                     {|lChecked| SET(_SET_BELL, lChecked) } )
  129.    PromptAddToggle( hSetMenu,  S_WRAP,   "~Wrap", ;
  130.                     {|lChecked| SET(_SET_WRAP, lChecked) } )
  131.    PromptAddToggle( hSetMenu,  S_CONFIRM,  "~Confirm  ", ;
  132.                     {|lChecked| SET(_SET_CONFIRM, lChecked) } )
  133.  
  134.    // Save As submenu
  135.    PromptAdd   ( hSaveSubMenu, SA_NORM,  "Normal ~Text (TXT)  " )
  136.    PromptAdd   ( hSaveSubMenu, SA_WK1,   "~Lotus       (WK1)  " )
  137.    PromptAddSub( hSaveSubMenu, SA_DBF, hdBASESub )
  138.  
  139.    // dBASE submenu
  140.    PromptAdd( hdBASESub, DB_CLIP, "~Clipper     " )
  141.    PromptAdd( hdBASESub, DB_III,  "dBASE III~+  " )
  142.    PromptAdd( hdBASESub, DB_IV,   "~dBASE IV    " )
  143.  
  144.    // Gray out unaccessible options
  145.    PromptGray( hFileMenu, F_SAVE )
  146.    PromptGray( hFileMenu, F_SAVEAS )
  147.  
  148.    // Check prompts that should have checks next to them
  149.    IF SET(_SET_BELL)
  150.       PromptCheck( hSetMenu, S_BELL )
  151.    ENDIF
  152.    IF SET(_SET_WRAP)
  153.       PromptCheck( hSetMenu, S_WRAP )
  154.    ENDIF
  155.    IF SET(_SET_CONFIRM)
  156.       PromptCheck( hSetMenu, S_CONFIRM )
  157.    ENDIF
  158.  
  159.    // Add menus to menubar
  160.    MenuAdd( hBar, hFileMenu )
  161.    MenuAdd( hBar, hEditMenu )
  162.    MenuAdd( hBar, hSetMenu )
  163.  
  164.    // Add quick keys or shortcuts
  165.    PromptQuickKey( hBar, hFileMenu, F_SAVE, K_ALT_S )
  166.    PromptQuickKey( hBar, hFileMenu, F_EXIT, K_ALT_X )
  167.    PromptQuickKey( hBar, hFileMenu, F_PRINT, K_ALT_P )
  168.  
  169.    RETURN NIL
  170.  
  171. /***
  172. *  GetProc() --> NIL
  173. *  Function to demonstrate menus within a READ
  174. *
  175. */
  176. STATIC FUNCTION GetProc
  177.    LOCAL GetList := {}
  178.    LOCAL cInput  := SPACE(10)
  179.    LOCAL cInput2 := SPACE(10)
  180.  
  181.    // Enable appropriate prompt items
  182.    PromptEnable( hFileMenu, F_SAVE )
  183.    PromptEnable( hFileMenu, F_SAVEAS )
  184.  
  185.    PromptAction( hFileMenu, F_SAVE, {|| ForceGetExit()} )
  186.  
  187.    PromptEnable( hEditMenu, E_UNDO )
  188.    PromptEnable( hEditMenu, E_CUT )
  189.    PromptEnable( hEditMenu, E_COPY )
  190.    PromptEnable( hEditMenu, E_PASTE )
  191.    PromptEnable( hEditMenu, E_CLEAR )
  192.  
  193.    PostExitBlock({|| ForceGetExit()})
  194.    BarInstall(hBar)
  195.  
  196.    CLS
  197.    SET SCOREBOARD OFF
  198.    BarDisplay(hBar)
  199.  
  200.    @ 4,0 SAY "Hello"
  201.    @ 5,0 SAY "Input " get cInput
  202.    @ 6,0 SAY "Input2" get cInput2
  203.    READ
  204.  
  205.    BarDeInstall(hBar)
  206.    PostExitBlock()
  207.  
  208.    IF LASTKEY() != 27
  209.       @ MAXROW(), 0 SAY "Saving..."
  210.       INKEY(2)
  211.    ENDIF
  212.    CLEAR SCREEN
  213.    BarDisplay(hBar)
  214.  
  215.    RETURN NIL
  216.  
  217. /***
  218. *  ForceGetExit() --> NIL
  219. *  Force an exit from a READ; called from menu exit block
  220. *
  221. */
  222. STATIC FUNCTION ForceGetExit
  223.  
  224.    KEYBOARD CHR(K_CTRL_W)
  225.  
  226.    RETURN NIL
  227.  
  228. /***
  229. *  MemoProc() --> NIL
  230. *  Demonstrates how to access the OMENU system in combination with 
  231. *  MEMOEDIT()
  232. *
  233. */
  234. STATIC FUNCTION MemoProc
  235.    STATIC cString := "Edit this, the menu still works."
  236.  
  237.    CLS
  238.    BarDisplay( hBar )
  239.    @ 1, 0 to MAXROW(), 78
  240.    cString := MEMOEDIT( cString, 2, 2, MAXROW()-2, 77, .T., "EditIt" )
  241.  
  242.    RETURN NIL
  243.  
  244. /***
  245. *  EditIt( nMode, nLine, nCol ) --> ME_DEFAULT
  246. *  MEMOEDIT() user function containing calls to the OMENU system
  247. *
  248. */
  249. FUNCTION EditIt( nMode, nLine, nCol )
  250.  
  251.    // Handle keystroke exception
  252.    IF nMode == ME_UNKEY .OR. nMode == ME_UNKEYX
  253.       // Check to see if it is a menu key
  254.       BarActivate(hBar, LASTKEY()) 
  255.  
  256.       // If their is a request to change through the menu
  257.       IF BarMenuChoice(hBar) != F_MEMO
  258.          RETURN K_CTRL_W
  259.       ENDIF
  260.    ENDIF
  261.  
  262.    RETURN ME_DEFAULT
  263.  
  264.  
  265. /***
  266. *  DummyProc( <cString> ) --> NIL
  267. *  Used to just verify that the menu prompt worked
  268. *
  269. */
  270. STATIC FUNCTION DummyProc( cString )
  271.  
  272.    CLS
  273.    BarDisplay( hBar )
  274.  
  275.    // Disable appropriate prompt items
  276.    PromptGray( hFileMenu, F_SAVE )
  277.    PromptGray( hFileMenu, F_SAVEAS )
  278.  
  279.    PromptGray( hEditMenu, E_UNDO )
  280.    PromptGray( hEditMenu, E_CUT )
  281.    PromptGray( hEditMenu, E_COPY )
  282.    PromptGray( hEditMenu, E_PASTE )
  283.    PromptGray( hEditMenu, E_CLEAR )
  284.  
  285.    BarInstall(hBar)
  286.    PostExitBlock( {|| ForceGetExit()} )
  287.  
  288.    @ 12,0 SAY cString
  289.    InKeyWait(0)
  290.  
  291.    PostExitBlock()
  292.    BarDeInstall(hBar)
  293.  
  294.    RETURN NIL
  295.  
  296.