Silverfrost Forums

Welcome to our forums

How to scroll to end of string in edit box automatically?

29 Apr 2011 12:48 #8147

I have an edit box I'm using as a status-reporting box in FTN95. I implement it by using: [color=blue:83bb4297fe] CHARACTER*32000 statstg

  i=winio@('%64.10eb[hscrollbar,vscrollbar]',statstg,32000)

[/color:83bb4297fe]

As the program runs, every now and then I post new messages in this box. To do this, I remove any NULL (CHAR(0)) from the end of statstg, append a linefeed (CHAR(10)), then append the new message, and finally append a NULL. Then I call window_update@(statstg) to display the entire string of messages, including the new message.

This is working well, for the first ten sentences or so. But then the sentences start scrolling off the visible area in the box. I can bring them back by clicking and dragging the vertical scroll bar, and that works too.

But is there a way I can have the system automatically 'drag the scroll bar', so that each time a message is posted then entire string moves up until the new message is visible at the bottom of the box, without the user having to click and drag the scrollbar manually each time?

I'd imagine the solution might (or might not) involve doing an ADJUSTR(statstg) to move all the sentences to the end of that (very long) statstg, and then simply scroll all the way to the bottom each time somehow. A good solution, but not a perfect one - the scrollbar at the right side of the edit box, would become really teeny, and moving it even a millimeter would cause huge jumps in the string, as though the string contained many hundreds of sentences.

I guess I have two questions:

1.) How do I make the system scroll the vertical scrollbar automatically, to the very end of the 32,000-character string if necessary (i.e. if the characters are right-justified in the string)?

2.) How do I make the system scroll only to the end of the printing characters in the string, if they are left-justified in the string? Currently they are terminated with a CHAR(0) - does that help?

Thanks, all!

29 Apr 2011 7:11 #8148

Hi, here is just an alternative but very easy way for what you want to do - I use this method in several applications:

handle = create_window@('Info',100,100,700,500)
call open_to_window@(6,handle)
.
.
.
write(6,'(A)')'message text'
.
.
.
call destroy_window@(handle)  ! at the end of the programme

Regards - Wilfried

29 Apr 2011 7:16 #8149

If you want to store the report, then expand the code like following:

open(77, file='report.txt,err=...,status='unknown')
handle = create_window@('Info',100,100,700,500) 
call open_to_window@(6,handle) 
. 
. 
. 
write(6,'(A)')'message text' 
write(77,'(A)')'message text' 
. 
. 
. 
call destroy_window@(handle)  ! at the end of the programme
close(77)

Regards, Wilfried

29 Apr 2011 2:04 #8150

Of course, the simplest way of doing this (a 'hack') is to just WRITE(,).

You could also try what is confusingly termed a 'Clearwin window', generated with the format code %N.Mcw rather than by Wilfried's create_window@ route (although they get you to the same place eventually, %cw is more versatile and more compatible with winio@). One of the problems with your %eb is that the contents can be edited by a user - the contents of a clearwin window can be copied, but not changed, which is more in line with your description of what you are doing. You can embed the %cw in a window with other contents, or put it in its own movable window with a %ca caption (and %ww and %sy etc). Clearwin windows within a more complicated window can have a pivot attached to them (%pv%cw) so that they are resizable.

I've only used a clearwin window once, but it does always scroll to the end when you write to it, and, because you can attach a Fortran unit to it, you don't have to bother with the complexities of adding text to the end - just do a Fortran formatted write - as Wilfried suggests.

Some time ago, text facilities in clearwin windows were enhanced, which you will find in the log of updates.

If you read the FTN95.CHM file, you will be confused (possibly - I was!). Basically, the description of clearwin windows reads as though it has survived, largely unmodified, since the origins of Clearwin, when the acme of converting a Fortran program to Windows was to be able to run it with output going to a standard Windows text window! Skip the stuff on 'clearwin windows' until you have mastered %cw, and then read it understanding what the description is (i.e. a bit of archaeology!).

Eddie

29 Apr 2011 8:23 #8153

Quoted from Wilfried Linder Hi, here is just an alternative but very easy way for what you want to do - I use this method in several applications:

handle = create_window@('Info',100,100,700,500)
call open_to_window@(6,handle)
.
.
.
write(6,'(A)')'message text'
.
.
.
call destroy_window@(handle)  ! at the end of the programme

Regards - Wilfried

Aw, that's SO sweet.... does everything I've been trying to do for months with that window.

Text in this window comes out in System font. Is there a way to make it Arial font? I tried [color=blue:140b0aacb2] i=winio@('%fn[Arial]&') [/color:140b0aacb2] followed later by [color=blue:140b0aacb2] i=winio@('%sf&') [/color:140b0aacb2] ....but no luck, it's still in System font. I tried this both before and after the 'create_window@ - open_to_window@' group, and also before and after the actual WRITE statement. Neither changed the font successfully.

But boy, is it nice to have a workable Status window! Thank you!

29 Apr 2011 8:24 (Edited: 29 Apr 2011 8:26) #8154

Oops, duplicate post, sorry

29 Apr 2011 8:24 #8155

Triplicate post! Now I'm really sorry!

(I kept getting a strange 'DEBUG' response from the system when posting, so I thought it hadn't accepted my post, and tried a few more times)

29 Apr 2011 8:54 #8156

Yup, you can always ignore them in my experience, they have always gotten through appearances notwithstanding ...

30 Apr 2011 8:39 #8157

From v 5.50:

ClearWin+: A new option has been added for %cw called [local_font] that causes %cw to use the current %fn and %ts.

Regards

Eddie

30 Apr 2011 11:46 #8158

If you want to have the output in a proportional font like Arial, just add the following line before (!) the create_window@ command:

call set_default_proportional_font@()

You can find some more information about the so-called Clearwin windows in the Clearwin manual.

Regards - Wilfried

30 Apr 2011 2:54 #8159

Quoted from Wilfried Linder If you want to have the output in a proportional font like Arial, just add the following line before (!) the create_window@ command:

call set_default_proportional_font@()

You can find some more information about the so-called Clearwin windows in the Clearwin manual.

Regards - Wilfried

Thanks, Wilfried! I'll try that on Monday.

After that command, then should the winio@('%fn[Arial]&') command work? Or does that set_default command merely start using its own proportional font, that I may or may not be able to change (Arial vs. Calibri vs. etc.)?

30 Apr 2011 4:24 #8161

As far as I know, there are two main possibilities for Clearwin windows:

set_default_to_fixed_font@() sets the 'system fixed' font set_default_proportional_font@() sets the 'system' font

There is also a subroutine set_default_font@(hfont) with hfont is a handle to an existing font, but I've never used this possibility and no idea about it, sorry...

Regards - Wilfried

30 Apr 2011 5:09 #8162

Hey - I tried what Eddie mentioned before, and it seems that something like this may help you:

integer*4   ctrl
.
.
.
j = winio@('%lw%sy[3d_thin]%fn[ARIAL]%ts%120.40cw[local_font]',ctrl,.96D0,6)

%lw is to leave the window open - you can close it with ctrl = 0. %fn sets the font, %ts the text size %cw opens the Clearwin window, '6' is the Fortran standard output unit

Have a nice weekend - Wilfried

2 May 2011 5:13 #8164

... and also (from v6.00):

ClearWin+: The standard callback COPY has now been implemented for %cw

which is even better news.

Eddie

4 May 2011 9:57 #8172

Quoted from Little-Acorn

Quoted from Wilfried Linder If you want to have the output in a proportional font like Arial, just add the following line before (!) the create_window@ command:

call set_default_proportional_font@()

You can find some more information about the so-called Clearwin windows in the Clearwin manual.

Regards - Wilfried

Thanks, Wilfried! I'll try that on Monday.

After that command, then should the winio@('%fn[Arial]&') command work? Or does that set_default command merely start using its own proportional font, that I may or may not be able to change (Arial vs. Calibri vs. etc.)?

Hmmm, it didn't work.

I put: [color=blue:aed32dead9] CALL set_default_proportional_font@() [/color:aed32dead9] just before the create_window@ command. No change, the box appears as before, but still its text is in System font. I guess System font is a proportional font.

Then I added the statement: [color=blue:aed32dead9] CALL set_default_font@('Arial') [/color:aed32dead9] ...after the set_proportional_font@ subroutine call, thinking that might persuade it to use Arial font. But that didn't work either: the box's text is still in System font.

Also tried those two statements before the actual WRITE( command to the new box. Still no luck: Text comes out in System font.

My biggest problem with System font, is that it is (or appears to be) boldfaced. This is very distracting. I hope to use a font (such as Arial) which is not boldfaced unless I tell it to be boldfaced.

I'll dig thru the manuals on these new subroutines. But I guess I'm open to suggestions. 😃

ON EDIT: I even tried erasing the above statements and putting in: [color=blue:aed32dead9] CALL SET_DEFAULT_TO_FIXED_FONT@ [/color:aed32dead9] ....before the create_window@ command, just to see if I could change ANYTHING about the text inside the new status box. Still no luck: Its text still comes out in System font, which is apparently a proportional font.

5 May 2011 8:40 #8175

OK, please test the following:

WINAPP
OPTIONS(INTL)

PROGRAM TEST

IMPLICIT NONE
INCLUDE <WINDOWS.INS>

integer*4      j,handle

handle = -1

j = winio@('%lw%sy[3d_thin]%fn[ARIAL]%ts%120.40cw[local_font]',handle,1.5D0,6)
write(6,'(A)')'hello'

call sleep@(3.)
write(6,'(A)')'... back again after some work'

call sleep@(3.)
write(6,'(A)')'window will be closed soon'

call sleep@(3.)
handle = 0
call window_update@(handle)

end

'sleep' just simulates some work of the programme. May be that this is more like what you are looking for?

Regards - Wilfried

5 May 2011 8:58 #8176

Sorry, I forgot two things:

(a) add %ww[no_border] after j = winio@('%lw (b) set the text size to 1.D0

This looks better 😉 Regards - Wilfried

5 May 2011 7:49 (Edited: 5 May 2011 8:05) #8178

Tried it.

I got a run-time exception saying 'local_font is an invalid CLEARWIN option'.

I then replaced the words [color=blue:bee47dda5d]local_font[/color:bee47dda5d] with the word [color=blue:bee47dda5d] vscroll[/color:bee47dda5d] . Now the program ran, a window came up, and the messages you put here, appeared one after the other every few seconds... but they were in System font, not Arial.

Hmmm....

BTW, I converted the program to fixed-format, and had to put in a continuation line in the longest statement. I don't believe the continuation line affected the program. Is it possible that going to fixed-format, did affect the program somehow?

I am also using Plato with Silverfrost FORTRAN. When I click on 'Help' and then 'About Plato', I get a small banner saying 'Plato Version 4.10 - Copyright c Silverfrost Ltd 2011' across the top.

My version of this program: [color=blue:bee47dda5d] WINAPP OPTIONS(INTL)

  PROGRAM TEST 

  IMPLICIT NONE 
  INCLUDE <WINDOWS.INS> 

  integer*4      j,handle 

  handle = -1 

  j = winio@
 1('%lw%ww[no_border]%sy[3d_thin]%fn[ARIAL]%ts%120.40cw[local_font]'
 2  ,handle,1.0D0,6) 
  write(6,'(A)')'hello' 

  call sleep@(3.) 
  write(6,'(A)')'... back again after some work' 

  call sleep@(3.) 
  write(6,'(A)')'window will be closed soon' 

  call sleep@(3.) 
  handle = 0 
  call window_update@(handle) 

  end

[/color:bee47dda5d]

5 May 2011 7:54 #8179

Hi Little Acorn,

Then you had better tell us what version you are using: some of the updates to %cw are comparatively recent, and require the appropriate version of FTN95. This is less of a problem if you are using the Personal Edition than if you are the proud possessor of a licence: in the former case, updating to the latest version is free, in the latter, it isn't!

Eddie

5 May 2011 8:01 #8180

Hmmm... really funny. I've written and tested exactly that code today. Are you sure that you have an actual version of FTN95/ClearWin?

Please login to reply.