Re: EUGrid and trapping lostFocus event
Tony Steward wrote:
>
> Hi Phil or anyone who can help,
> I know EUGrid traps most events its self but I do not see a lost focus
> event.
> If I use win32lib's on lostFocus, it is triggered when the grid looses
> focus but, it is also triggered when I click on a different cell in the
> grid.
> I need to run a procedure when a grid truely looses focus.
>
> --
> Regards
> Tony Steward
> <a
> href="http://home.exetel.com.au/steward/">http://home.exetel.com.au/steward/</a>
>
Hi Tony,
This is difficult to solve cleanly at the moment because EuGrid has a number of
internal windows which are not registered with win32lib. I have come up with a
workaround which involves a) recording whenever the grid gets the focus
and b) checking if any other window subsequently gets the focus.
Here is an example:
--
-- Grid lost-focus sample for Tony Steward
--
-- Phil Russell May 2005
without warning
include win32lib.ew
include eugrid.ew
atom void
integer Grid, colEditable, colName, colDOB, colPhone
integer grid_has_focus grid_has_focus=0
constant GridData =
{
{ 0, "Nobby Wombat", "23-04-66", "01273 772244" },
{ 0, "Benny Bear", "01-05-77", "0181 123456" },
{ 0, "Carl Cat", "22-07-92", "01273 665544" },
{ 0, "Winnie Wallaby", "20-05-54", "0208 6772555" },
{ 0, "Sid Snake", "17-09-01", "01273 998877" },
{ 0, "Fred Frog", "05-12-95", "01273 010101" },
{ 0, "Steve Sheep", "17-09-01", "01273 498857" },
{ 0, "Dennis Dog", "12-09-55", "01273 999999" },
{ 0, "Bjorn Badger", "02-11-88", "09191 224455" },
{ 0, "Pete Platypus", "02-02-77", "0208 1996678" },
{ 0, "Velma Vole", "10-09-43", "01273 121212" },
{ 0, "Eric Bison", "17-12-66", "01273 202020" },
{ 0, "Percy Pig", "23-09-49", "01273 554433" },
{ 0, "Bill Beetle", "13-10-84", "01203 191919" }
}
--*------------------------------------------------------*
-- Windows
--*------------------------------------------------------*
constant MainWin = create( Window, "EuGrid Demo", 0, 50, 50, 480, 400, 0 )
constant Edit1 = create( EditText, "Edit1", MainWin, 10, 325, 50, 20, 0)
constant Edit2 = create( EditText, "Edit2", MainWin, 60, 325, 50, 20, 0)
--*------------------------------------------------------*
-- Define grid window
--*------------------------------------------------------*
-- Create grid, create parms=(parent, x, y, width, height, show_window)
Grid = EGW_CreateGrid( MainWin, 10, 15, 450, 300, EGW_True )
-- Name column
colName = EGW_AddColumn( Grid, "Name", 100, EGW_LAST, EGW_EDIT, 2 )
-- Date of Birth column
colDOB = EGW_AddColumn( Grid, "DOB", 50, EGW_LAST, EGW_EDIT, 3 )
void = EGW_SetColumnProperty( Grid, colDOB, EGW_COL_ALIGN, EGW_RIGHT )
-- Phone Number column
colPhone = EGW_AddColumn( Grid, "Phone", 100, EGW_LAST, EGW_EDIT, 4 )
void = EGW_SetColumnProperty( Grid, colPhone, EGW_COL_ALIGN, EGW_CENTER )
-- Load dataset into grid
void = EGW_LoadData( Grid, GridData, EGW_REPLACE )
-- ***Set initial focus to grid
setFocus(Grid)
-- ***Record the fact
grid_has_focus=1
--*------------------------------------------------------*
-- Grid message handler
--*------------------------------------------------------*
procedure Grid_onGotFocus (integer self, integer event, sequence params)
grid_has_focus=1
end procedure
setHandler( Grid, w32HGotFocus, routine_id("Grid_onGotFocus"))
--*------------------------------------------------------*
-- Other windows message handler
--*------------------------------------------------------*
procedure OtherWin_onGotFocus (integer self, integer event, sequence params)
if grid_has_focus=1 then
grid_has_focus=0
printf(1, "the grid lost the focus\n", {})
end if
end procedure
-- ***Add all other windows on form to handler list
setHandler( {Edit1,Edit2}, w32HGotFocus, routine_id("OtherWin_onGotFocus"))
--*------------------------------------------------------*
-- Open main window
--*------------------------------------------------------*-----------------------------------------------------------------------------
WinMain( MainWin, Normal )
Hopefully this will help. The important bits are the two procedures and the
lines
marked with ***.
A caveat: it's late here and I've just got back from the pub - treat with
caution!!
I will be away for the next week - let me know if you still have a problem
and I will have another look when I get back.
HTH,
Phil
|
Not Categorized, Please Help
|
|