IonicWind Software

IWBasic => GUI Central => Topic started by: Dogge on June 03, 2007, 04:43:47 AM

Title: TAB'ing between controls in a window which is a child to a dialog
Post by: Dogge on June 03, 2007, 04:43:47 AM
I'm having trouble to get TAB to work in a window which is a child to a dialog.
I've been trying to play with the available styles and command but it seems that TAB will have my control lose its focus but the next control in order in the window will not receive focus. Any better way to solve this than capturing @ENKillFocus for edits? That approach didn't work for buttons so I researched MSDN for notifications for buttons and there was a BN_KILLFOCUS, it worked when I added BS_NOTIFY style to the button. None of these are defined in windows.inc so I got them from WinUser.h from the Microsoft SDK's.

Here is my original code where it doesn't work. and the code with the workaround. I would rather have another solution than manually writing the killfocus/setfocus code for each control. Any ideas?


DIALOG d1
Window w1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
domodal d1
end

sub opentabtestw()
openwindow w1, 0, 0, 280, 180, @nocaption, d1, "window", &w1_handler
CONTROL w1,@EDIT,"Edit1",44,27,70,20,0x50810000,1
CONTROL w1,@EDIT,"Edit2",47,68,70,20,0x50810000,2
CONTROL w1,@SYSBUTTON,"Button1",62,115,70,20,0x50010000,3
enabletabs w1, 1
setfocus w1, 1
return
endsub

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
opentabtestw()
CASE @IDCLOSEWINDOW
closewindow d1
CLOSEDIALOG d1,@IDOK
ENDSELECT
RETURN
ENDSUB

SUB w1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEWINDOW d1
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
CASE 2
CASE 3
IF @NOTIFYCODE = 0
ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB


Workaround

const BS_NOTIFY    =       0x00004000
const BN_KILLFOCUS    =    7
DIALOG d1
Window w1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
domodal d1
end

sub opentabtestw()
openwindow w1, 0, 0, 280, 180, @nocaption, d1, "window", &w1_handler
CONTROL w1,@EDIT,"",44,27,70,20,0x50810000,1
CONTROL w1,@EDIT,"",47,68,70,20,0x50810000,2
CONTROL w1,@SYSBUTTON,"Button1",62,115,70,20,0x50010000 | BS_NOTIFY,3
enabletabs w1, 1
setfocus w1, 1
return
endsub

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
opentabtestw()
setfocus w1,1
CASE @IDCLOSEWINDOW
closewindow d1
CLOSEDIALOG d1,@IDOK
ENDSELECT
RETURN
ENDSUB

SUB w1_handler
SELECT @MESSAGE
CASE @IDCLOSEWINDOW
CLOSEWINDOW d1
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1 : if @notifycode=@enkillfocus then setfocus w1, 2
CASE 2 : if @notifycode=@enkillfocus then setfocus w1, 3
CASE 3
IF @NOTIFYCODE = 0
ENDIF
if @notifycode=bn_killfocus then setfocus w1, 1
ENDSELECT
ENDSELECT
RETURN
ENDSUB

...with a small problem left, can't get focus to the first control

Any ideas of what I can do to get it working without the workaround or if the workaround is the best solution how can I fix the last annoying thing about putting focus where it should be?

/Douglas

Title: Re: TAB'ing between controls in a window which is a child to a dialog
Post by: Ionic Wind Support Team on June 03, 2007, 06:55:39 AM
Use a non-modal dialog as the parent instead of a modal one.  In other words use ShowDialog instead of DoModal and your own message loop with WAITUNTIL.

ENABLETABS has no effect if your program isn't processing it's own messages with WAIT or WAITUNTIL.  There is special processing that happens to allow tabs to work in a window and that processing isn't part of Microsoft's default message loop used for modal dialogs. 

In other words A modal dialog uses a message processing loop that is internal to the Windows API and which bypasses the code generated by Emergence for handling things like tabs in a window, accelarator bindings, special notifications, etc.

Paul.
Title: Re: TAB'ing between controls in a window which is a child to a dialog
Post by: Dogge on June 04, 2007, 12:27:22 PM
Thanks for the information, I'll do it the Q&D way until I have time to do a proper implementation.
/Douglas
Title: Re: TAB'ing between controls in a window which is a child to a dialog
Post by: jerryclement on June 04, 2007, 03:52:14 PM
 ;D Thanks also for the info on non-modal dialogs Paul. It so happens I couldn't SetControlText for an Edit control that was a child to a window.  I took a break and read your message to Dogge and the lights turned on!!  That also fixed my problem.

Thanks again,
Jerry Clement