Setting Input Focus

Discussions related to mouse, keyboard, fonts and Graphical User Interface
circe
Posts: 16
Joined: Wed 07 May 2025, 09:26

Setting Input Focus

Post by circe »

In a dialogue, while there is a function for testing which input has focus, there does not seem to be one for setting which text box has initial focus.

I have a dialog (called from another dialog) which has some static lines and a single Textbox for input. The first time it is called Newdialog is run and the single textbox has focus, but if called a second time (without Newdialog) the single textbox does not have focus.

This is just annoying! But I feel there should be a solution, but I cannot find it in the documentation.
Or have I missed something?
Richard Russell
Posts: 692
Joined: Tue 18 Jun 2024, 09:32

Re: Setting Input Focus

Post by Richard Russell »

circe wrote: Tue 28 Apr 2026, 09:57 In a dialogue, while there is a function for testing which input has focus, there does not seem to be one for setting which text box has initial focus.
The control which has the initial focus is the first suitable control listed in the dialogue template, i.e. the first to have been created.
The first time it is called Newdialog is run and the single textbox has focus, but if called a second time (without Newdialog) the single textbox does not have focus.
Can you please create a Minimal Reproducible Example which demonstrates this problem? Using SDLIDE.bbc as a test bed, each time I open (for example) the Find or Replace dialogue box the first text box has the input focus, which is what I would expect.
circe
Posts: 16
Joined: Wed 07 May 2025, 09:26

Re: Setting Input Focus

Post by circe »

Thank you for your reply.

A demo program is at http://www.newportpeace.co.uk/temp/focusdemo.bbc.

The problem occurs in FNearth. To show problem load program and press function key f2. This opens a second Dialogue. This does have focus on the Textbox, and default entry is provided for you. Press OK. A map will be opened from the internet.

Close that Window and press f2 again. The Textbox now has no focus (assuming that I have not misunderstood what you mean by focus). Clicking in the Textbox will regain focus, but it is annoying to have to do this.
Richard Russell
Posts: 692
Joined: Tue 18 Jun 2024, 09:32

Re: Setting Input Focus

Post by Richard Russell »

circe wrote: Tue 28 Apr 2026, 20:37 A demo program is at http://www.newportpeace.co.uk/temp/focusdemo.bbc.
That program is over 900 lines long, by no stretch of the imagination is it a "minimal" example, and I can't offer to plough through it! :(

One worrying feature, though, is that FN_newdialog is called in a function (FNearth) which is seemingly called multiple times. Obviously, for any given dialogue box, FN_newdialog must be called only once; apart from anything else if it ends up being called multiple times there would be a serious memory leak, and I would expect other things to break too.

The manual says this: "Before you can use a dialogue box, you must first specify its size and title. This should be done only once, typically in an initialisation routine, for each dialogue box your program contains (the dialogue box can subsequently be displayed as many times as you like)".

It's not necessarily the cause of the issue you raised, but this fault needs to be be fixed before any other investigations are warranted.
circe
Posts: 16
Joined: Wed 07 May 2025, 09:26

Re: Setting Input Focus

Post by circe »

With respect, newdialog is only called once. dlg% is initially zero. but after running newdialog, it becomes non-zero, so as it is called with the line: IF dlg%=0 dlg% = FN_newdialog(Credit$, 180, 240), it is only called once. PROCmain is only called once anyway and it is outside the repeat loop.

I take your point about the file size, and have found the problem exists for the first dialogue box, which has enabled me to greatly reduce the file size. Look in PROCmain. The updated file is at the same URL.

After loading, just click on OK. Exit the error message produced and the Dialog box has now lost focus.
Richard Russell
Posts: 692
Joined: Tue 18 Jun 2024, 09:32

Re: Setting Input Focus

Post by Richard Russell »

circe wrote: Wed 29 Apr 2026, 10:25 With respect, newdialog is only called once.
Pedantically you are right, but here is the relevant code. FN_newdialog() is called only once but PROC_static(), PROC_textbox() and PROC_button() are called every time, adding more and more controls to the dialogue box, stacked on top of each other at the same locations!

Code: Select all

 3100 IF dlg1% = 0 dlg1% = FN_newdialog(Credit$, 140, 120)
 3110 PROC_static(dlg1%, STRING$(7,space$)+"Paste Lat/Long in 'Google' Format"+\
 3120 \crlf$+STRING$(5,space$)+"e.g. 46°30'55.2"+quote$+"N 6°36'33.9"+quote$+"E"\
 3130 \+crlf$+STRING$(2,space$)+"('*' may be used as a substitute for "+CHR$(degree%)+")", \
 3140 \           100, 2, 20, 135, 36, 0)
 3150 clipboard$=""
 3160 PROC_textbox(dlg1%, save$, 101, 15, 60, 110, 12, 0):REM:or save$
 3170 PROC_button(dlg1%, "OK", 1, 20, 100, 26, 14, WS_GROUP)
 3180 PROC_button(dlg1%, "QUIT", 2, 95, 100, 26, 14, WS_GROUP)
This is actually worse than had you called FN_newdialog multiple times! It shares all the disadvantages - a serious memory leak and likely misbehaviour of the dialogue box - without benefitting from the initialisation that FN_newdialog performs. :o

I would prefer the dialogue box template to be created in an initialisation routine, guaranteeing that it is only ever done once, but if you want to do it in a function called multiple times then you must ensure that it only happens on the first call. For example this would work:

Code: Select all

 3095 IF dlg1% = 0 THEN
 3100   dlg1% = FN_newdialog(Credit$, 140, 120)
 3110   PROC_static(dlg1%, STRING$(7,space$)+"Paste Lat/Long in 'Google' Format"+\
 3120   \crlf$+STRING$(5,space$)+"e.g. 46°30'55.2"+quote$+"N 6°36'33.9"+quote$+"E"\
 3130   \+crlf$+STRING$(2,space$)+"('*' may be used as a substitute for "+CHR$(degree%)+")", \
 3140   \           100, 2, 20, 135, 36, 0)
 3150   clipboard$=""
 3160   PROC_textbox(dlg1%, save$, 101, 15, 60, 110, 12, 0):REM:or save$
 3170   PROC_button(dlg1%, "OK", 1, 20, 100, 26, 14, WS_GROUP)
 3180   PROC_button(dlg1%, "QUIT", 2, 95, 100, 26, 14, WS_GROUP)
 3185 ENDIF
Some of the supplied diagnostic tools can help you here. For example the Memory monitor utility should make it obvious that every time FNearth is called more heap is consumed, eventually - if you run the program for long enough - using up all the available memory. Also the Cross reference utility will warn you that the dlg1% variable is shared between multiple routines without being a global (which might be deliberate, but at least draws attention to it).
circe
Posts: 16
Joined: Wed 07 May 2025, 09:26

Re: Setting Input Focus

Post by circe »

Thank you Richard.
I will use that.
There was also an incorrect use of showdlgitem which was apparently the cause of loss of focus.
Cheers,
AndrewCool
Posts: 1
Joined: Wed 29 Apr 2026, 23:11

Re: Setting Input Focus

Post by AndrewCool »

Even using your supplied examples of Longitude and Latitude I get an error of 'ill formed Latitude" and "ill formed Longitude" :-(

Whichever example I enter, I can't get past he ill formed error.

Input focus is a minor worry for you...

v1.44a WIN11

Andrew