forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding focus to edit boxes

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
kdangel



Joined: 31 Dec 2008
Posts: 6

PostPosted: Tue Jan 13, 2009 1:42 am    Post subject: Adding focus to edit boxes Reply with quote

I have check boxes followed by edit boxes (respectively) using %rs. How do I add a cursor or focus to an edit box?

When a user checks a box I want the corresponding edit box or input box to gain focus.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Jan 13, 2009 10:29 am    Post subject: Reply with quote

A control should automatically get the focus when a user clicks on it.

You can use %if to specify which control should have the initial focus.
Back to top
View user's profile Send private message AIM Address
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Tue Jan 13, 2009 1:25 pm    Post subject: Reply with quote

Paul,

I think he means he wants to force focus to a specific control by a callback attached to another. Pehaps an bit like SET_HIGHLIGHTED@.

And in a similar vein, imagine a set of %rs/%rd%rf etc boxes. Initially on window creation, the first has focus. If another of the edit boxes is selected for entry and the user switches to a completely different application, and then returns to the Clearwin+ window, the first control has gained the focus, and the "current" has lost focus. Is it possible to retain the focus and edit cursor position?

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Jan 13, 2009 1:40 pm    Post subject: Reply with quote

It may be possible to use %lc to get the handle (hwnd) of a control and then to use this in a callback that calls SetFocus(hwnd).

SetFocus is a Windows API function that sets the focus to a given control for keyboard input.
Back to top
View user's profile Send private message AIM Address
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Tue Jan 13, 2009 2:44 pm    Post subject: Reply with quote

Paul,

Yes it is possible, but set_highlighted@ has exactly the same effect, see below. Of course, you can manually select an edit box, and the check boxes will then be out of line. Manual selection would require a focus_monitor to determine the control with focus and scan the ihandle list to determine which check box should be checked.

Can you solve the problem whereby the wrong focus is restored after Alt-Tabbing around the applications, without the monstrous overhead of a focus monitor to record the last window and a restore by using a gain focus callback arrangement. Try it on this program, the top %rf always regains the focus

Regards

ian

Code:

      winapp
      real*8 a,b,c,d
      common/handles/ihandle(4),irb(4)
      external iselect1,iselect2,iselect3,iselect4
      common/data/a,b,c,d
      irb(1) = 1
      irb(2) = 0
      irb(3) = 0
      irb(4) = 0
      a = 0d0
      b = 0d0
      c = 0d0
      d = 0d0
      i=winio@('%ca[Test SetFocus]&')
      i=winio@('%ffa=%rf%lc%ffb=%rf%lc&',a,ihandle(1),b,ihandle(2))
      i=winio@('%ff%`^rb[Select 1]&',irb(1),iselect1)
      i=winio@('%ff%`^rb[Select 2]&',irb(2),iselect2)
      i=winio@('%ffc=%rf%lc%ffd=%rf%lc&',c,ihandle(3),d,ihandle(4))
      i=winio@('%ff%`^rb[Select 3]&',irb(3),iselect3)
      i=winio@('%ff%`^rb[Select 4]&',irb(4),iselect4)
      i=winio@('%4`ga',irb(1),irb(2),irb(3),irb(4))
      end
      integer*4 function iselect1()
      C_EXTERNAL SETFOCUS 'SetFocus' (VAL):INTEGER*2
      common/handles/ihandle(4),irb(4)
      iselect1 = 2
      i = setfocus(ihandle(1))
      end
      integer*4 function iselect2()
      C_EXTERNAL SETFOCUS 'SetFocus' (VAL):INTEGER*2
      common/handles/ihandle(4),irb(4)
      iselect2 = 2
      i =  setfocus(ihandle(2))
      end
     
      integer*4 function iselect3()
      include <windows.ins>
      common/handles/ihandle(4),irb(4)
      iselect3 = 2
      call set_highlighted@(ihandle(3))
      end
      integer*4 function iselect4()
      include <windows.ins>
      common/handles/ihandle(4),irb(4)
      iselect4 = 2
      call set_highlighted@(ihandle(4))
      end
     
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Tue Jan 13, 2009 3:07 pm    Post subject: Reply with quote

OK. I will aim to have a look at this.
However, there are a few things that are more urgent and need a higher priority.
Back to top
View user's profile Send private message AIM Address
kdangel



Joined: 31 Dec 2008
Posts: 6

PostPosted: Thu Jan 15, 2009 3:22 am    Post subject: Reply with quote

I want to add focus w/o the user manually selecting the edit box. For instance, I have 12 check boxes associated with 12 options. The edit boxes are used to enter file names, and they are invisible until the user clicks a check box. %if doesn't work. Everytime a check box is chosen, the dialog window is redrawn to display the appropriate edit box on the same line as the check box and option string. Also, a file may be entered in the edit box from the file-open dialog. Therefore, I want the user to be able to click on the file menu button and enter a file w/o actually clicking on the edit box. I have a focus window to determine which edit box has the focus when the user clicks on the box. However, when the user clicks the check I want the appropriate edit box to gain focus automatically. I hope this clarifies it a bit.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Jan 15, 2009 8:12 am    Post subject: Reply with quote

I think that you can probably do this using SetFocus in the right way.
If you will post a short sample I will aim to modify it to do this.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Jan 15, 2009 6:14 pm    Post subject: Reply with quote

If it doesn't seem all that easy to do something in ClearWin, it is sometimes because you are trying to do something in a "non-Windows" way. I usually find a prototype from some other application, and follow the logic from that. When you try it in Clearwin it is then easier to work out what to do.

For example, you speak of keeping your filename edit boxes invisible until they are "checked". If you keep them visible, but greyed out, you have a more "standard" paradigm. Even better, even though they are greyed out, the boxes can have some meaningful text displayed, even if it is "Check the box on the left to select this" or "No file selected" (etc).

Doing things in an unconventional way sometimes enrages users. For example, try replacing "You selected exit, do you want to save your work first?" with "Do you really want to exit" (which transposes the "Yes" answers). The second approach almost inevitably loses the user's work!

If menus and some windows are "too dynamic", users get lost. If, on the other hand, they can see they are in the right window, because what they want to change is there, they know that all they need to do is to find the way of enabling (un-greying) it, and they don't have to go to a different window.

Since you can handle the controls in a window through their call-back function or through the exit code (button number) that winio@ returns, it is possible to leave a window and redraw it with a different format, as you suggest. However, reading between the lines of what your aims are, it looks to me as though you really should be doing it through callback functions (which can be easily attached to far more types of control than exit codes), especially as in your case you are exitting after checking a check box, for which you are having to write a callback function to (in effect) set the exit code, then exit the window, then redraw the window differently. Doing precisely that turned my hair grey before I pulled it all out in frustration....

Changing the grey code is a much simpler proposition, as indeed is shifting the focus to an extant control.

Regards

Eddie
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 16, 2009 4:08 pm    Post subject: Reply with quote

Use a mixture of set_highlighted@ and set_visibility@

Last edited by IanLambley on Sat Jan 17, 2009 7:58 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 16, 2009 4:10 pm    Post subject: Reply with quote

Use a mixture of set_highlighted@ and set_visibility@

See code below
Code:

      winapp
      include 'winio.inc'
      common/radio_buttons/irb(4)
      external iselect1,iselect2,iselect3,iselect4,istart_callback
      nwinio_data = 4
c
c intialise some text data
      winio_text(1) = 'Text 1'
      winio_text(2) = 'Text 2'
      winio_text(3) = 'Text 3'
      winio_text(4) = 'Text 4'
c
c set for only the first text box to be visible
      iwinio_visible_control(1) = 1
      iwinio_visible_control(2) = 0
      iwinio_visible_control(3) = 0
      iwinio_visible_control(4) = 0
c
c check the first box
      irb(1) = 1
      irb(2) = 0
      irb(3) = 0
      irb(4) = 0
      i=winio@('%ca[Test visibility]&')
c
c put out a title followed by four overlying text boxes
      i=winio@('%apFilename=&',0,0)
      i=winio@('%ap%16rs%lc&',12,0,winio_text(1),iwinio_control_id(1))
      i=winio@('%ap%16rs%lc&',12,0,winio_text(2),iwinio_control_id(2))
      i=winio@('%ap%16rs%lc&',12,0,winio_text(3),iwinio_control_id(3))
      i=winio@('%ap%16rs%lc&',12,0,winio_text(4),iwinio_control_id(4))
c
c four ganged check boxes
      i=winio@('%ff%`^rb[Select 1]&',irb(1),iselect1)
      i=winio@('%ff%`^rb[Select 2]&',irb(2),iselect2)
      i=winio@('%ff%`^rb[Select 3]&',irb(3),iselect3)
      i=winio@('%ff%`^rb[Select 4]&',irb(4),iselect4)
      i=winio@('%4`ga&',irb(1),irb(2),irb(3),irb(4))
      i=winio@('%sc',istart_callback)
      end



Continued in next post

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 16, 2009 4:12 pm    Post subject: Reply with quote

The functions and subroutines
Code:

      integer*4 function istart_callback()
      istart_callback = 1
      call winio_set_visibility
      end
      integer*4 function iselect1()
      include <windows.ins>
      include 'winio.inc'
      common/radio_buttons/irb(4)
      iselect1 = 2
c
c set the visibility to be equal to the radio buttons, 1 for on - 0 for off
      do i=1,4
        iwinio_visible_control(i) = irb(i)
      enddo
      call set_highlighted@(iwinio_control_id(1))
      call winio_set_visibility
      end
      integer*4 function iselect2()
      include <windows.ins>
      include 'winio.inc'
      common/radio_buttons/irb(4)
      iselect2 = 2
      do i=1,4
        iwinio_visible_control(i) = irb(i)
      enddo
      call set_highlighted@(iwinio_control_id(2))
      call winio_set_visibility
      end
     
      integer*4 function iselect3()
      include <windows.ins>
      include 'winio.inc'
      common/radio_buttons/irb(4)
      iselect3 = 2
      do i=1,4
        iwinio_visible_control(i) = irb(i)
      enddo
      call set_highlighted@(iwinio_control_id(3))
      call winio_set_visibility
      end
      integer*4 function iselect4()
      include <windows.ins>
      include 'winio.inc'
      common/radio_buttons/irb(4)
      iselect4 = 2
      do i=1,4
        iwinio_visible_control(i) = irb(i)
      enddo
      call set_highlighted@(iwinio_control_id(4))
      call winio_set_visibility
      end
      subroutine winio_set_visibility
      implicit real*8 (a-h,o-z)
      include 'winio.inc'
      include <windows.ins>
c parameters are  none
c        print *,'set visibility'
      do i=1,nwinio_data
c        print *,i,iwinio_control_id(i),
c     &            iwinio_visible_control(i)
        if(iwinio_control_id(i) .ne. 0)then
          call SET_CONTROL_VISIBILITY@(iwinio_control_id(i),
     &                          iwinio_visible_control(i))
        endif
      enddo
      end


Continued
Back to top
View user's profile Send private message Send e-mail
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Fri Jan 16, 2009 4:13 pm    Post subject: Reply with quote

Include common block file "winio.inc"
Code:

c=============================================================================
c common block for WINIO controls
      character*256 winio_text
      real*8 winio_data
      integer*4 nwinio_data,iwindow_ref,iwinio_data,iwinio_control_id,
     &          iwinio_grey_control,iwinio_visible_control
      common/winio_data_t/winio_text(1000)
      common/winio_data_n/nwinio_data,
     &                    iwinio_data(1000),winio_data(1000),
     &                    iwinio_visible_control(1000),
     &                    iwinio_control_id(1000),
     &                    iwinio_grey_control(1000)
c=============================================================================
c Name                 Description
c=============================================================================
c winio_text          Text for a text type item
c nwinio_data         Number of controls
c iwindow_ref         The result of WINIO function calls, that will return the exit
c                     status of a window, e.g. the button number pressed to exit
c iwinio_data         Integer data
c winio_data          Real/floating point data
c iwinio_control_id   Handle of control determined from %lc
c iwinio_grey_control Control variable foir use with tilde character in control
c iwinio_visible_control   Desired state of visibility of control
c=============================================================================

Finished

Regards

Ian
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Jan 17, 2009 4:10 pm    Post subject: Reply with quote

I have had a look at Ian's alt-tab problem but a fix within ClearWin+ is not immediate or obvious.

You may be able to do something for yourself by using %mg, first to intercept WM_KILLFOCUS where you can get the current focus via GetFocus, then to intercept WM_SETFOCUS where you restore the previous focus using SetFocus.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group