1. Tabbing problem in Child Window

Hi,

Say I have following 7 fields to be accepted in a Child Window:

====================================
Emp. Code : [     ]
Name      : [                      ]
Address   : [                      ]
            [                      ]
            [                      ]
Date of   : [  /  /    ]
Birth 
Tel.No.   : [                      ]
====================================

Now the ENTER/TAB key moves the focus to next field in circular way.

My problem starts when I validate the Date field, in fact for any field which is
validated.
If invalid date is encountered, I am displaying an error message using
message_box()
and focusing back on Date field using setFocus().

E.g. First time I enter invalid date by mistake, and then enter valid date after
error message.
When I enter a valid date and press ENTER, focus jumps to Emp.Code instead of
Tel.No. field.
If I enter invalid date 3 times in a row before entering a valid date, focus
jumps to first
line of the Address field.

How to stop/rectify this behaviour?
How to set the correct Tab sequence?

Regards,
Rad.

new topic     » topic index » view message » categorize

2. Re: Tabbing problem in Child Window

Rad wrote:
> 
> Hi,
> 
> Say I have following 7 fields to be accepted in a Child Window:
> 
> ====================================
> Emp. Code : [     ]
> Name      : [                      ]
> Address   : [                      ]
>             [                      ]
>             [                      ]
> Date of   : [  /  /    ]
> Birth 
> Tel.No.   : [                      ]
> ====================================
> 
> Now the ENTER/TAB key moves the focus to next field in circular way.
> 
> My problem starts when I validate the Date field, in fact for any field which
> is validated.
> If invalid date is encountered, I am displaying an error message using
> message_box()
> and focusing back on Date field using setFocus().
> 
> E.g. First time I enter invalid date by mistake, and then enter valid date
> after
> error message.
> When I enter a valid date and press ENTER, focus jumps to Emp.Code instead of
> Tel.No. field.
> If I enter invalid date 3 times in a row before entering a valid date, focus
> jumps to first
> line of the Address field.
> 
> How to stop/rectify this behaviour?
> How to set the correct Tab sequence?
> 
> Regards,
> Rad.

First, let me answer your last question.  The tab order is based on the order
the controls are created.

Now as for the weird cursor positioning, perhaps if we had a look at your code
we could help.

Jonas Temple
http://www.innovativesys.net

new topic     » goto parent     » topic index » view message » categorize

3. Re: Tabbing problem in Child Window

I am using following code for nagivation -
(picked up & modified from win32lib example for Group Tabbing)

--#============================================================================================
--#Move to next or previous control in the screen on pressing Enter/Down or Up
key respectively.
--#============================================================================================
------------------------------------------------
procedure GotFocus_Box(integer self, integer event, sequence params)
------------------------------------------------
    -- Remember which control has currently got focus in each group.
    setUserProperty( findParent(self), "infocus", self)
end procedure

-- Set initial focus and handlers for all children inside groups.
------------------------------------------------
global procedure SetGroupNavigator(integer pID, integer Set)
------------------------------------------------
    sequence lKids
    integer lSet

    lKids = getControlInfo(pID, CONTROLINFO_group)
    lSet = 0 
    for i = 1 to length(lKids) do
        if getControlInfo(lKids[i], CONTROLINFO_type) != Group then
            if lSet = 0 then
                -- The first non-group child has initial focus.
                if Set then
	                setUserProperty( pID, "infocus", lKids[i])
                else
	                deleteUserProperty( pID, "infocus")
                end if
                lSet = 1
            end if
            if Set then
	            setHandler(lKids[i], w32HGotFocus, routine_id("GotFocus_Box"))
	        else
	            removeHandler(lKids[i], w32HGotFocus, routine_id("GotFocus_Box"))
            end if
        else
            SetGroupNavigator(lKids[i], Set)
        end if
    end for
end procedure

procedure TrapNavigation(integer self, integer event, sequence params)--params
is ( atom scanCode, atom shift )
	sequence	checkLists, checkButns, checkEdits, idName, className
    integer		nextgroup, inc, lParent, lGrandParent, lMainWin, lEnd, lStart
    object		nextcid
    sequence	lKeyState, lKids

	checkLists = {"ComboBox", "SysListView32", "SysTreeView32"}
	checkEdits = {"Edit"}
	checkButns = {"Button"}

	if not (params[1] = VK_ENTER or params[1] = VK_RETURN or
			params[1] = VK_DOWN or params[1] = VK_UP) then
		return
	end if

	if params[1] = VK_DOWN or params[1] = VK_UP then
		className = getClassName(self)
if find(className, checkLists) then -- normal processing for
Combo/List/TreeViews
			return
		end if
		lParent = findParent(self)        
		lMainWin = findParentWindow(self)
		lGrandParent = findParent(lParent)
    
    	if lGrandParent = 0 then
			lGrandParent = lMainWin
		end if
        
        if params[1] = VK_DOWN then
			-- Move to the focus item inside the next group on my level.

			-- Get all my parent's siblings.
			lKids = getControlInfo(lGrandParent, CONTROLINFO_group)
			if lGrandParent = lParent then
				lKids = lParent & lKids
			end if

			-- Find my parent in its sibling list
			nextgroup = find(lParent, lKids)

			-- Direction depends on the Shift key state.
			if and_bits(params[2], ShiftMask) = 0 then
				inc = 1
			else
				inc = -1
			end if

			if inc > 0 then
				lEnd  = length(lKids)
			else
				lEnd = 1
			end if

			lStart = nextgroup
			nextcid = 0
			while lStart != lEnd do
				lStart += inc
				if getControlInfo(lKids[lStart], CONTROLINFO_type) = Group then
					nextcid = lKids[lStart]
					exit
				end if
			end while

			if nextcid = 0 then
				lEnd = nextgroup
				if lStart = 1 then
					lStart = length(lKids) + 1
				else
					lStart = 0
				end if
				while lStart != lEnd do
					lStart += inc
					if getControlInfo(lKids[lStart], CONTROLINFO_type) = Group then
						nextcid = lKids[lStart]
						exit
					end if
				end while
			end if

			if nextcid != 0 then            
				nextcid = getUserProperty(nextcid, "infocus")
				if length(nextcid) > 0 then
					setFocus(nextcid[1])
				end if
			end if

		elsif params[1] = VK_UP then
			-- If my parent is a group, then move to my grandparent's focus item.
			nextcid = getUserProperty(lGrandParent, "infocus")
			if length(nextcid) > 0 then
				setFocus(nextcid[1])
			end if
		end if
	else
		className = getClassName(self)
		if find(className, checkLists) or
--			find(className, checkEdits) or
			find(className, checkButns) then
			if params[1] = VK_RETURN and and_bits(params[2], ShiftMask) = 0 then
				tab_direction(self, 1)
			end if
		end if
	end if

	-- Hide this Key press from Windows.
	returnValue(0)
	return
end procedure
setHandler(Screen, w32HKeyDown, routine_id("TrapNavigation"))
--#============================================================================================



I suspect the portion at the end of TrapNagigation-

className = getClassName(self)
		if find(className, checkLists) or
--			find(className, checkEdits) or
			find(className, checkButns) then
			if params[1] = VK_RETURN and and_bits(params[2], ShiftMask) = 0 then
				tab_direction(self, 1)
			end if
		end if


is responsible for this behaviour, but otherwise how to move out of
ListView/TreeView with
ENTER key (or any other key)?

Regards,
Rad.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu