home *** CD-ROM | disk | FTP | other *** search
- /***
- * Odemo2.prg
- * Demonstrate proper usage of OMENU menu system
- *
- * Copyright (c) 1990 Nantucket Corp. All rights reserved.
- * Craig Ogg
- *
- */
-
- #include "Omenu.ch"
- #include "Inkey.ch"
- #include "Memoedit.ch"
-
- /* Definitions for all of the menus and menu prompts */
-
- // Menu definitions
- #define F_GET 10
- #define F_MEMO 11
- #define F_SAVE 12
- #define F_SAVEAS 13
- #define F_PRINT 14
- #define F_EXIT 15
-
- // Prompt definitions
- #define SA_NORM 131
- #define SA_WK1 132
- #define SA_DBF 133
-
- #define DB_CLIP 1331
- #define DB_III 1332
- #define DB_IV 1333
-
- #define E_UNDO 20
- #define E_CUT 21
- #define E_COPY 22
- #define E_PASTE 23
- #define E_CLEAR 24
-
- #define S_BELL 30
- #define S_WRAP 31
- #define S_CONFIRM 32
-
- STATIC hBar, hFileMenu, hEditMenu, hSetMenu, hSaveSubMenu, hdBASESub
-
- FUNCTION Odemo2()
- LOCAL nChoice
-
- // Function to show how menus are created (see below)
- CreateBar()
-
- CLS
- @ 12, 0 SAY "Press <F10> or Alt-<highlighted letter> to activate menu..."
-
- // Initially give bar complete control
- BarActivate( hBar )
- nChoice := BarMenuChoice( hBar )
- DO WHILE nChoice != F_EXIT
- DO CASE
- CASE nChoice == F_GET
- DO GetProc
- CASE nChoice == F_MEMO
- DO MemoProc
- CASE nChoice == F_PRINT
- DummyProc("Print option.")
- CASE nChoice == SA_NORM
- DummyProc("Save normal file option.")
- CASE nChoice == SA_WK1
- DummyProc("Save Lotus file option.")
- CASE nChoice == DB_CLIP
- DummyProc("Save Clipper file option.")
- CASE nChoice == DB_III
- DummyProc("Save dBASE III+ file option.")
- CASE nChoice == DB_IV
- DummyProc("Save dBASE IV file option.")
- OTHERWISE
- BarActivate( hBar )
- ENDCASE
- nChoice := BarMenuChoice( hBar )
- ENDDO
-
- RETURN NIL
-
-
- /***
- * CreateBar() --> NIL
- * This functions creates the menus, grays certain prompts, checks other
- * prompts
- *
- */
- STATIC FUNCTION CreateBar()
-
- // Create empty bar menu
- hBar := BarNew()
-
- // Create empty menus
- hEditMenu := MenuNew( "~Edit" )
- hFileMenu := MenuNew( "~File" )
- hSetMenu := MenuNew( "~Toggles" )
-
- // Create empty submenus
- hSaveSubMenu := MenuNew( "Save ~As " )
- hdBASESub := MenuNew( "~dBASE (DBF) " )
-
- // Add prompts
- // Edit Menu
- PromptAdd( hEditMenu, E_UNDO, "~Undo " )
- PromptAdd( hEditMenu, E_CUT, "Cu~t" )
- PromptAdd( hEditMenu, E_COPY, "~Copy" )
- PromptAdd( hEditMenu, E_PASTE, "~Paste" )
- PromptAdd( hEditMenu, E_CLEAR, "C~lear" )
-
- // File Menu
- PromptAdd ( hFileMenu, F_GET, "~Get Test " )
- PromptAdd ( hFileMenu, F_MEMO, "~Memoedit() Test " )
- PromptAdd ( hFileMenu, F_SAVE, "~Save Alt-S" )
-
- // Add submenu
- PromptAddSub( hFileMenu, F_SAVEAS, hSaveSubMenu )
- PromptAddLine( hFileMenu )
- PromptAdd ( hFileMenu, F_PRINT, "~Print Alt-P" )
- PromptAdd ( hFileMenu, F_EXIT, "E~xit Alt-X" )
-
- // Toggles Menu
- // Code block is passed a true (.T.) if item is checked, false (.F.)
- // otherwise
- //
- PromptAddToggle( hSetMenu, S_BELL, "~Bell", ;
- {|lChecked| SET(_SET_BELL, lChecked) } )
- PromptAddToggle( hSetMenu, S_WRAP, "~Wrap", ;
- {|lChecked| SET(_SET_WRAP, lChecked) } )
- PromptAddToggle( hSetMenu, S_CONFIRM, "~Confirm ", ;
- {|lChecked| SET(_SET_CONFIRM, lChecked) } )
-
- // Save As submenu
- PromptAdd ( hSaveSubMenu, SA_NORM, "Normal ~Text (TXT) " )
- PromptAdd ( hSaveSubMenu, SA_WK1, "~Lotus (WK1) " )
- PromptAddSub( hSaveSubMenu, SA_DBF, hdBASESub )
-
- // dBASE submenu
- PromptAdd( hdBASESub, DB_CLIP, "~Clipper " )
- PromptAdd( hdBASESub, DB_III, "dBASE III~+ " )
- PromptAdd( hdBASESub, DB_IV, "~dBASE IV " )
-
- // Gray out unaccessible options
- PromptGray( hFileMenu, F_SAVE )
- PromptGray( hFileMenu, F_SAVEAS )
-
- // Check prompts that should have checks next to them
- IF SET(_SET_BELL)
- PromptCheck( hSetMenu, S_BELL )
- ENDIF
- IF SET(_SET_WRAP)
- PromptCheck( hSetMenu, S_WRAP )
- ENDIF
- IF SET(_SET_CONFIRM)
- PromptCheck( hSetMenu, S_CONFIRM )
- ENDIF
-
- // Add menus to menubar
- MenuAdd( hBar, hFileMenu )
- MenuAdd( hBar, hEditMenu )
- MenuAdd( hBar, hSetMenu )
-
- // Add quick keys or shortcuts
- PromptQuickKey( hBar, hFileMenu, F_SAVE, K_ALT_S )
- PromptQuickKey( hBar, hFileMenu, F_EXIT, K_ALT_X )
- PromptQuickKey( hBar, hFileMenu, F_PRINT, K_ALT_P )
-
- RETURN NIL
-
- /***
- * GetProc() --> NIL
- * Function to demonstrate menus within a READ
- *
- */
- STATIC FUNCTION GetProc
- LOCAL GetList := {}
- LOCAL cInput := SPACE(10)
- LOCAL cInput2 := SPACE(10)
-
- // Enable appropriate prompt items
- PromptEnable( hFileMenu, F_SAVE )
- PromptEnable( hFileMenu, F_SAVEAS )
-
- PromptAction( hFileMenu, F_SAVE, {|| ForceGetExit()} )
-
- PromptEnable( hEditMenu, E_UNDO )
- PromptEnable( hEditMenu, E_CUT )
- PromptEnable( hEditMenu, E_COPY )
- PromptEnable( hEditMenu, E_PASTE )
- PromptEnable( hEditMenu, E_CLEAR )
-
- PostExitBlock({|| ForceGetExit()})
- BarInstall(hBar)
-
- CLS
- SET SCOREBOARD OFF
- BarDisplay(hBar)
-
- @ 4,0 SAY "Hello"
- @ 5,0 SAY "Input " get cInput
- @ 6,0 SAY "Input2" get cInput2
- READ
-
- BarDeInstall(hBar)
- PostExitBlock()
-
- IF LASTKEY() != 27
- @ MAXROW(), 0 SAY "Saving..."
- INKEY(2)
- ENDIF
- CLEAR SCREEN
- BarDisplay(hBar)
-
- RETURN NIL
-
- /***
- * ForceGetExit() --> NIL
- * Force an exit from a READ; called from menu exit block
- *
- */
- STATIC FUNCTION ForceGetExit
-
- KEYBOARD CHR(K_CTRL_W)
-
- RETURN NIL
-
- /***
- * MemoProc() --> NIL
- * Demonstrates how to access the OMENU system in combination with
- * MEMOEDIT()
- *
- */
- STATIC FUNCTION MemoProc
- STATIC cString := "Edit this, the menu still works."
-
- CLS
- BarDisplay( hBar )
- @ 1, 0 to MAXROW(), 78
- cString := MEMOEDIT( cString, 2, 2, MAXROW()-2, 77, .T., "EditIt" )
-
- RETURN NIL
-
- /***
- * EditIt( nMode, nLine, nCol ) --> ME_DEFAULT
- * MEMOEDIT() user function containing calls to the OMENU system
- *
- */
- FUNCTION EditIt( nMode, nLine, nCol )
-
- // Handle keystroke exception
- IF nMode == ME_UNKEY .OR. nMode == ME_UNKEYX
- // Check to see if it is a menu key
- BarActivate(hBar, LASTKEY())
-
- // If their is a request to change through the menu
- IF BarMenuChoice(hBar) != F_MEMO
- RETURN K_CTRL_W
- ENDIF
- ENDIF
-
- RETURN ME_DEFAULT
-
-
- /***
- * DummyProc( <cString> ) --> NIL
- * Used to just verify that the menu prompt worked
- *
- */
- STATIC FUNCTION DummyProc( cString )
-
- CLS
- BarDisplay( hBar )
-
- // Disable appropriate prompt items
- PromptGray( hFileMenu, F_SAVE )
- PromptGray( hFileMenu, F_SAVEAS )
-
- PromptGray( hEditMenu, E_UNDO )
- PromptGray( hEditMenu, E_CUT )
- PromptGray( hEditMenu, E_COPY )
- PromptGray( hEditMenu, E_PASTE )
- PromptGray( hEditMenu, E_CLEAR )
-
- BarInstall(hBar)
- PostExitBlock( {|| ForceGetExit()} )
-
- @ 12,0 SAY cString
- InKeyWait(0)
-
- PostExitBlock()
- BarDeInstall(hBar)
-
- RETURN NIL
-
-