Interface TextControl::setHighlightOnFocus

 


Description

In BBj 7.0 and higher, this method sets the behavior of controls implementing the TextControl interface when receiving focus via the keyboard, mouse, or BBjControl::focus() method FOCUS mnemonic.

Syntax

Return Value

Method

void

setHighlightOnFocus(int behavior)

Parameters

Variable

Description

behavior

Value should be one of the HIGHLIGHT_constants in the TextControl interface.

Return Value

None.

Remarks

None.

Example

REM Demonstration of the values for TextControl::get/setHighlightOnFocus()

REM DECLARE variables

DECLARE BBjAPI myAPI!
DECLARE BBjSysGui mySysGui!
DECLARE BBjTopLevelWindow myWindow!
DECLARE BBjStaticText myLabel!
DECLARE BBjFont font!
DECLARE BBjEditBox myEditBox!
DECLARE BBjToolButton myToolButton!
DECLARE BBjControl myControl!
DECLARE EventHandler myEventHandler!

REM Open sysgui channel

sysgui = UNT
OPEN(sysgui)"X0"

REM Initialize variables
myAPI! = BBJAPI()
mySysGui! = myAPI!.getSysGui()

REM Create demonstration window

myWindow! = mySysGui!.addWindow(100, 100, 250, 350, "Highlight On Focus", $00010002$)

REM Create column label describing row labels.

myLabel! = myWindow!.addStaticText(101, 10, 10, 120, 30, "KEY/MOUSE/FOCUS")
font! = myLabel!.getFont()
font! = mySysGui!.makeFont(font!.getName(), font!.getSize() + 1, mySysGui!.BOLD)
myLabel!.setFont(font!)

REM Create edit box for TextControl.getHighlightOnFocus() name.
myEditBox! = myWindow!.addEditBox(100, 140, 10, 100, 25, $$)

REM Create EventHandler custom object
myEventHandler! = new EventHandler(myWindow!, myEditBox!)

REM
REM Create individual row labels
REM

myWindow!.addStaticText(102, 10, 45, 40, 25, "&1. 0/0/0")
myWindow!.addStaticText(104, 10, 80, 40, 25, "&2. 0/0/1")
myWindow!.addStaticText(106, 10, 115, 40, 25, "&3. 0/1/0")
myWindow!.addStaticText(108, 10, 150, 40, 25, "&4. 0/1/1")
myWindow!.addStaticText(110, 10, 185, 40, 25, "&5. 1/0/0")
myWindow!.addStaticText(112, 10, 220, 40, 25, "&6. 1/0/1")
myWindow!.addStaticText(114, 10, 255, 40, 25, "&7. 1/1/0")
myWindow!.addStaticText(116, 10, 290, 40, 25, "&8. 1/1/1")

REM
REM Create edit boxes, set highlight on focus values, and set callbacks to event handler
REM

myEditBox! = myWindow!.addEditBox(103, 60, 45, 100, 25, "None")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_NONE)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(105, 60, 80, 100, 25, "Focus")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_FOCUS)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(107, 60, 115, 100, 25, "Mouse")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_MOUSE)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(109, 60, 150, 100, 25, "Mouse/Focus")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_MOUSE + TextControl.HIGHLIGHT_FOCUS)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(111, 60, 185, 100, 25, "Key")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_KEY)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(113, 60, 220, 100, 25, "Key/Focus")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_KEY + TextControl.HIGHLIGHT_FOCUS)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(115, 60, 255, 100, 25, "Key/Mouse")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_KEY + TextControl.HIGHLIGHT_MOUSE)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

myEditBox! = myWindow!.addEditBox(117, 60, 290, 100, 25, "Key/Mouse/Focus")
myEditBox!.setHighlightOnFocus(TextControl.HIGHLIGHT_KEY + TextControl.HIGHLIGHT_MOUSE + TextControl.HIGHLIGHT_FOCUS)
myEditBox!.setCallback(myEditBox!.ON_GAINED_FOCUS, myEventHandler!, "editFocusGained")

REM
REM Create tool buttons to do programmatic focus and set callbacks
REM

myToolButton! = myWindow!.addToolButton(203, 170, 45, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(205, 170, 85, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(207, 170, 115, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(209, 170, 150, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(211, 170, 185, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(213, 170, 220, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(215, 170, 255, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

myToolButton! = myWindow!.addToolButton(217, 170, 290, 40, 25, "Focus")
myToolButton!.setCallback(myToolButton!.ON_TOOL_BUTTON_PUSH, myEventHandler!, "toolButtonPushed")

REM
REM Set callback for window close box
REM

myWindow!.setCallback(myWindow!.ON_CLOSE, myEventHandler!, "windowClose")

REM Begin processing events
PROCESS_EVENTS

REM EventHandler class has methods for custom object event callbacks
CLASS PUBLIC EventHandler
    FIELD PUBLIC BBjTopLevelWindow Window!
    FIELD PUBLIC BBjEditBox Status!

    REM Constructor needs the window and the status edit box
    METHOD PUBLIC EventHandler(BBjTopLevelWindow p_window!, BBjEditBox p_status!)
        #Window! = p_window!
        #Status! = p_status!
    METHODEND

    REM Callback method for window close.
    METHOD PUBLIC VOID windowClose(BBjCloseEvent p_ev!)
        RELEASE
    METHODEND

    REM Callback method for an edit box gaining focus
    METHOD PUBLIC VOID editFocusGained(BBjGainedFocusEvent p_ev!)
        DECLARE BBjEditBox myEditBox!
        DECLARE BBjString text$
        DECLARE BBjString hofString$

        myEditBox! = p_ev!.getEditBox()

        REM Produce binary string from the getHighlightOnFocus() value
        hofString$ = BIN(myEditBox!.getHighlightOnFocus(), 1)
        text$ = $$

        REM Check the values in the binary string and set up the text$ variable
        IF DEC(AND(BIN(TextControl.HIGHLIGHT_KEY, 1), hofString$))
            text$ = "Key"
        ENDIF
        IF DEC(AND(BIN(TextControl.HIGHLIGHT_MOUSE, 1), hofString$))
            IF LEN(text$) <> 0
                text$ = text$ + "/"
            ENDIF
            text$ = text$ + "Mouse"
        ENDIF
        IF DEC(AND(BIN(TextControl.HIGHLIGHT_FOCUS, 1), hofString$))
            IF LEN(text$) <> 0
                text$ = text$ + "/"
            ENDIF
            text$ = text$ + "Focus"
        ENDIF

        REM Add a special case for none, since text$ is empty.
        IF (LEN(text$) = 0)
            text$ = "(None)"
       ENDIF

        REM Set the text on the status edit box
        #Status!.setText(text$)
    METHODEND

    REM Callback method for a tool button being pushed
    METHOD PUBLIC VOID toolButtonPushed(BBjToolButtonPushEvent p_ev!)
        DECLARE BBjControl myControl!
        myControl! = p_ev!.getControl()

        REM Programmatically focus the appropriate edit box.
        #Window!.getControl(myControl!.getID() - 100).focus()
    METHODEND
CLASSEND

See Also

BBjAPI

BBjSysGui

BBjControl

TextControl::getHighlightOnFocus

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.