SP_BUNGEE

BUNGEE()                             *new*

  Short:
  ------
  BUNGEE() Mouseable, multi-level dropdown menu with triggers

  Returns:
  --------
  NIL

  Syntax:
  -------

  BUNGEE(<nTop>,<nLeft>,<nRight>,<aMenu>,[aColumns],;
         [aColors],[aHotMice],[aHotKeys],[bExitCheck],;
         [lImmediate],[lDropped],[nHideLevel],[nShadowPos],;
         [nShadowAtt],[lHandleAlt] )

  Description:
  ------------
  Creates and activates a dropdown menu (bungee style)

  <nTop>          Row of menu bar
  <nLeft>         Left side of menu bar
  <nRight>        Right side of menu bar
  <aMenu>         A menu definition array of arrays

                  You  use the BUNGEE() menu array definition functions:
                  BUNGSTART(), BUNGEND(), BUNGOPTION(),BUNGDROP(),
                  BUNGUNDROP() together to create a menu definition array
                  for BUNGEE( ). This basically defines the menu options,
                  boxes and actions

  [aColumns]      An array of columns to determine the column
                  positions for the top bar options. Optional, as
                  this is automatically determined otherwise.

  [aColors]       An array of seven elements describing 6 colors
                  and the box drawing frame string

                  BACKGROUND COLOR         1
                  SELECTED OPTION COLOR    2
                  UNSELECTED OPTION COLOR  3
                  INACTIVE OPTION COLOR    4
                  SELECTED TRIGGER COLOR   5
                  UNSELECTED TRIGGER COLOR 6
                  BOX FRAME STRING         7   (as in "+-+|+-+| ")

                  Defaults are extracted from the current
                  values in SETCOLOR(), and adjusted to
                  account for trigger letters and inactive
                  colors.

  [aHotMice]      An array of hot areas where, should the
                  mouse click, a codeblock will be evaluated.
                  The array is an array of arrays, where each
                  sub-array is in the form:
                      {nTop,nLeft,nBottom,nRight,bCodeblock}
                  Where nTop..nRight refer to the screen
                  coordinates of the hot area.
                  i.e.
                  @24,0 say "<Help>"
                  aHotMice := { {24,0,24,5,{||dohelp}}  }

  [aHotKeys]      An array of hotkey values, which, if one of
                  the keys is pressed, a codeblock will be
                  evaluated on the spot.
                  The array is an array of arrays, where each
                  sub-array is of the form:
                      {nASCIIValue,bCodeblock}

                  @24,0 say "<Help>"
                  aHotKeys := { {K_F1,{||dohelp()}  }  }

  [bExitBlock]    This is a codeblock which returns a LOGICAL
                  which is evaluated before a menu exit is
                  allowed. If it returns .f., a menu exit will
                  not be allowed.
                  i.e. {||MESSYN("Really exit?")}

  [lImmediate]    Do mouse clicks or hot keys on options other
                  than current option cause an immediate action
                  request? Default = True

  [lDropped]      Should the menu start up in dropped mode (boxes
                  are already dropped from top bar) Default is
                  True.

  [nHideLevel]    This indicates the level to which the menu hides
                  itself when executing an option action, a mouse
                  hot button or a hot key.
                  0 - does not hide itself at all
                  1 - hides everything except the top bar  (default)
                  2 - hides everything

  [nShadowPos]    Optional shadow position for menu dropdown boxes.
                  Valid options are:
                       1. Lower left
                       3. Lower right
                       0. None
                  Upper left and upper right shadow positions are not
                  allowed. (they can overwrite parts of the menu bar)
                  Default is SLS_SHADPOS(), unless SLS_SHADPOS() is
                  upper left or upper right (7,9), in which case it
                  is set to 0 (none).

                  To force no shadows for the menu, pass 0.

                  Boxes may not always have shadows, if the shadow would
                  be drawn offscreen.

  [nShadowAtt]   Numeric shadow attribute. Default is SLS_SHADATT(), whose
                 default is 8. (grey on black)

  [lHandleAlt]   Allow ALT+trigger letter combinations (ALT-A through ALT-Z)
                 to select menu options

  Examples:
  ---------

  (Also see S3META2.PRG in the sample files for a good example)

  bungstart()
  bungoption("Files")
  bungdrop()
          bungoption("Open" ,{} ,{||!lFileIsOpen} )
          bungoption("Close",{||nil},{||lFileIsOpen } )
  bungundrop()
  bungoption("Edit")
  bungdrop()
          bungoption("DBF"  ,{||nil},nil )
          bungoption("Ascii",{||nil},nil )
  bungundrop()
  bungoption("Quit",{||bungeequit()},nil)

  aMenu := bungend()

  @24,0 say "[ALT-X=exit]"   // set up Alt-X as a hotkey exit also
  aHotKeys := { {K_ALT_X,{||bungeequit()}           }
  aHotMice := {  {24,0,24,11,{||bungeequit()}     }  }

  bungee(0,0,79,aMenu,nil,nil,aHotMice,aHotKeys, { ||messyn("Exit now?") }   )

  Example 2
  ---------

  bungstart()
  bungoption("Next",{||dbskip(1)})
  bungoption("Prev",{||dbskip(-1)})
  bungoption("Edit",{||doedit()})
  bungoption("Add ",{||doadd()})
  bungoption("Delete",{||dodelete()})
  bungoption("Table",{||editdb(.t.)})
  bungoption("Search")
       bungdrop()
       bungoption("Field Search",{||searchme()} )
       bungoption("Key Search",{||SPOPSEEK()} )
       bungoption("Query ",{||query()} )
       bungundrop()
  bungoption("Memo")
       bungdrop()
       bungoption("View",{||viewmemo()} )
       bungoption("Edit",{||editmemo()} )
       bungundrop()
  bungoption("Hardcopy")
       bungdrop()
       bungoption("Record",{||hcrecord()})
       bungoption("Memo",{||hcmemo()})
       bungundrop()
  bungoption("Quit",{||bungeequit()},nil)

  aMenu := bungend()
  bungee(0,0,79,aMenu)

  Notes:
  ------
  Notes: Dropdown boxes will adjust for 'too far right' or 'too far down',
  but there is no adjustment for 'too many options in the box to fit on
  screen'

---------------------------------------------------------------------
  Source:
  -------
  S_BUNGEE.PRG, S_BUNGDE.PRG

 

SP_BUNGDROP

BUNGDROP()

  Short:
  ------
  BUNGDROP() Causes dropdown during BUNGEE() menu def sequence

  Returns:
  --------
  NIL

  Syntax:
  -------
  BUNGDROP([nDown],[nOver])

  Description:
  ------------
  BUNGDROP() causes a dropdown to occur during a BUNGEE() menu
  definition sequence. This is followed by a series of BUNGOPTION()
  and then BUNGUNDROP() to end the dropdown.

  [nDown] Number of rows down from row of current option (default 1)
  [nOver] Number of columns over from column of current option
          (default is 0 for bar options, 1 for dropdown options)

  Use BUNGSTART(), BUNGEND(), BUNGOPTION(),
  BUNGDROP(), BUNGUNDROP() together to create a menu definition
  array for BUNGEE(). While it is not necessary to use these
  functions to create the array, it is helpful when you have
  a complex, multi-level dropdown structure.

  See BUNGEE for more information.

  Examples:
  ---------

  bungstart()

     bungoption("Files")
     bungdrop()
          bungoption("Open" ,{} ,{||!lFileIsOpen} )
          bungoption("Close",{||nil},{||lFileIsOpen } )
     bungundrop()
     bungoption("Edit")
     bungdrop()
          bungoption("DBF"  ,{||nil},nil )
          bungoption("Ascii",{||nil},nil )
     bungundrop()
     bungoption("Quit",{||bungeequit()},nil)

  aMenu := bungend()
  bungee(0,0,79,aMenu)

  Source:
  -------
  S_BUNGDEF.PRG

 

The secrets of array handling, part 1.

The secrets of array handling Part – 1

User Interface Terms

Background Color :

The color that appears behind displayed text of another color (the foreground color).

See Also: Foreground Color

Column :

A numeric value that represents a position on the display screen or on the printed page.

Console Input/Output :

A style of operation of the keyboard and display that emulates a simple typewriter-like interface. Console input echoes each key typed and provides processing for the backspace and return keys. Console output wraps to the next line when the output reaches the right edge of the visible display, and scrolls the display when the output reaches the bottom of the visible display.

See Also: Full-screen Input/Output

Cursor :

An onscreen indicator used to show the current keyboard input focus and is displayed as a block or underline character. The cursor moves in response to characters or control keys typed by the user.

Enhanced Color :

The color used to display GETs or PROMPTs (if INTENSITY is ON).

See Also: Standard Color

Foreground Color :

The color of text appearing on the screen, usually on a different colored background.

See Also: Background Color

Full-screen Input/Output :

A style of operation of the keyboard and display used for complex data entry and display tasks. Full-screen input and output are generally performed using the @..SAY, @..GET and READ commands. Full-screen output is distinguished from console-style output by the fact that control characters (e.g., backspace, carriage return) are not processed, and wrapping and scrolling do not occur at the boundaries of the visible display area.

See Also: Console Input/Output

Highlight :

Indicates input focus for menus, browsers, or GETs. With menus and browsers, the currently selected item or cell has input focus and is displayed in the current enhanced color or inverse video. With GETs, the current GET is highlighted in the current enhanced color or inverse video while the other GETs are displayed in the current standard color if an unselected color setting is active.

See Also: Cell, Enhanced Color, Input Focus, Standard Color

Input Focus :

The GET, browse cell, or menu item where user interaction can take place is said to have input focus. The item with input focus usually is displayed in enhanced color or inverse video.

Insert Mode :

A data entry mode entered when the user presses the insert key. When this mode is active, characters are inserted at the cursor position. Text to the right of the cursor is shifted right.

See Also: Overstrike Mode

Keyboard Buffer :

An area of memory dedicated to storing input from the keyboard while a program is unable to process the input. When the program is able to accept the input, the keyboard buffer is emptied.

Menu :

An onscreen list of choices from which the user selects. Menus range from simple to elaborate forms. Two examples are menus that pull down from the top of the screen (an elaborate type requiring more programming), or a simple list of numbered items from which the user selects by entering the appropriate number.

Overstrike Mode :

A data entry mode entered when the user presses the insert key. When this mode is active, characters are entered at the cursor position and text to the right of the cursor remains stationary.

Picture :

A string that defines the format for data entry or display in a GET, SAY, or the return value of TRANSFORM(). Picture strings are comprised of functions which affect the formatting as a whole and a series of template characters that affect formatting on a character by character basis.

See Also: Template

Prompt :

A series of characters displayed on the screen indicating that input from the keyboard is expected.

Relative Addressing :

To refer to a memory address, array element, screen location, or printer location with respect to another value, rather than referring to a specific address or element.

Row :

A numeric expression that evaluates to an integer identifying a screen or printer row position.

See Also: Column, Field, Record

Scoreboard :

An area of the display on line 0 beginning at column 60 that displays status information during certain data entry operations.

Scrolling :

The action that takes place when the user attempts to move the cursor or highlight beyond the window boundary to access information not currently displayed.

See Also: Window

Standard Color :

The color pair definition that is used by all output options (such as SAY and ?), with the exception of GETs and PROMPTs, that use the enhanced color pair.

See Also : Enhanced Color

Template :

A mask that specifies the format in which data should be displayed. For example, you might want to store phone numbers as “9999999999” to save space, but use a template to display the number to the user as “(999) 999-9999.”

Typeahead Buffer :

See : Keyboard Buffer

Unselected Color :

The color pair definition used to display all but the current GET or the GET that has input focus. If this color setting is specified, the current GET is displayed using the current enhanced color.

See Also: Enhanced Color

User Function :

A user-defined function called by ACHOICE(), DBEDIT(), or MEMOEDIT() to handle key exceptions. A user function is supplied to one of these functions by passing a parameter consisting of a string containing the function’s name.

User Interface :

The way a program interacts with its user (i.e., menu operation and selection, data input methods, etc.)

Wait State :

A wait state is any mode that extracts keys from the keyboard except for INKEY(). These modes include ACHOICE(), DBEDIT(), MEMOEDIT(), ACCEPT, INPUT, READ and WAIT.

Window :

A rectangular screen region used for display. A window may be the same size or smaller than the physical screen. Attempting to display information that extends beyond the specified boundaries of the window clips the output at the window edge.

Word Wrapping :

The process of continuing the current text on the next line of a display when a boundary is reached and breaking the text on a word boundary.

Main Menu

HMG Tutor 2

Adding The Main Menu

We add a main menu to the program now:

#include "hmg.ch"
Function Main
DEFINE WINDOW Win_1 ;
   AT 0,0 ;
   WIDTH 400 ;
   HEIGHT 200 ;
   TITLE 'Tutor 02 - Main Menu Test' ;
   MAIN
   DEFINE MAIN MENU
      POPUP "First Popup"
         ITEM 'Change Window Title' ACTION  Win_1.Title := 'New Title'
         ITEM 'Retrieve Window Title' ACTION  MsgInfo ( Win_1.Title )
      END POPUP
   END MENU
END WINDOW
ACTIVATE WINDOW Win_1
Return

As you can see it is pretty easy and intuitive.

All the main menu stuff will be between DEFINE MAIN MENU / END MENU statements.
Each individual menu popup will be between POPUP / END POPUP statements.
Each individual menu item will be coded via the ITEM statement.

You can use as popups as you need and you can nest it without any limit.

By the way, another handy feature, a Message function used here :

The MsgInfo() Function

This is a very useful function. It will show a little message window (with the system information icon) and a message (character type) passed as parameter.

You can optionally add a title (passed as the second parameter).

Note: By nature, Message function uses options in local language. Here “Tamam” means “Ok” in my language ( Turkish).