EditorGadget auto scroll to last line ...

Just starting out? Need help? Post your questions and find answers here.
marc_256
Addict
Addict
Posts: 855
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

EditorGadget auto scroll to last line ...

Post by marc_256 »

Hi,

For the communications with one of my older robots,
I use my terminal program I created in PB 5.73 x64 / win 10.

Works since yesterday, but I have some problem.

For the transmitter and receiver side I use [EditorGadgets]
and this works very well.

Only I need to move my mouse over it and scroll down manually.
Is there a setting to scroll automatically to the EditorGadget last line ?


Thanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 7639
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: EditorGadget auto scroll to last line ...

Post by infratec »

2 possibilities:

1. Add the line in pos 0 and not -1 (order is switched)
2. There was already a solution for your question :wink:
viewtopic.php?p=593643#p593643
marc_256
Addict
Addict
Posts: 855
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: EditorGadget auto scroll to last line ...

Post by marc_256 »

Hi infratec,

due to some circumstances in my life,
I didn't touched my old robots for some time now.

Sorry, I forgot I asked this already.

? is this the beginning of "dementia" ? :mrgreen:

thanks
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Randy Walker
Addict
Addict
Posts: 1077
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: EditorGadget auto scroll to last line ...

Post by Randy Walker »

marc_256 wrote: Fri Sep 19, 2025 9:25 pm Is there a setting to scroll automatically to the EditorGadget last line ?
Thanks,
marc
Hi marc... I've always used sendmessage to do that. Unfortunately not cross platform, but works well enough for me in Windows:

Code: Select all

bottom = Len(GetGadgetText(YourGadget))
SendMessage_(GadgetID(YourGadget), #EM_SETSEL, bottom, bottom)
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
BarryG
Addict
Addict
Posts: 4194
Joined: Thu Apr 18, 2019 8:17 am

Re: EditorGadget auto scroll to last line ...

Post by BarryG »

@Randy, you don't need to calculate the bottom. Just use -1 for wParam and lParam, which means to select the end:

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  For a = 0 To 100
    AddGadgetItem(0, a, "Line "+Str(a))
  Next
  SendMessage_(GadgetID(0), #EM_SETSEL, -1, -1)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
User avatar
Shardik
Addict
Addict
Posts: 2061
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: EditorGadget auto scroll to last line ...

Post by Shardik »

Those who need a cross-platform solution may take a look into my 13 years old code example which demonstrates how to add and select line after line in an EditorGadget and always keep the last line visible.
Collection of cross-platform examples with API functions to extend PureBasic
Randy Walker
Addict
Addict
Posts: 1077
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA

Re: EditorGadget auto scroll to last line ...

Post by Randy Walker »

BarryG wrote: Sat Sep 20, 2025 4:38 am @Randy, you don't need to calculate the bottom. Just use -1 for wParam and lParam, which means to select the end:
Even Better yet for this purpose. Important to know though, EM_SETSEL is used to SELect text, with wParam as starting point and lparam as ending point. And when these two values match it places the cursor at that point.
Last edited by Randy Walker on Sat Sep 20, 2025 10:24 pm, edited 1 time in total.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Olli
Addict
Addict
Posts: 1246
Joined: Wed May 27, 2020 12:26 pm

Re: EditorGadget auto scroll to last line ...

Post by Olli »

Hello Shardik !

Thank you for this recall !
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4961
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget auto scroll to last line ...

Post by RASHAD »

Just for fun :)
It could be OK with Windows,Mac and Linux
I tested only with Windows

Code: Select all

Procedure SelectItem(gadget)
  no = CountGadgetItems(gadget)
  AddGadgetItem(gadget,-1,"")
  RemoveGadgetItem(gadget, no)
  SetActiveGadget(gadget)
EndProcedure

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133)
  For a = 0 To 100
    AddGadgetItem(0, a, "Line "+Str(a))
  Next
  SelectItem(0)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 468
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: EditorGadget auto scroll to last line ...

Post by Mindphazer »

Hi Rashed,

it doesn't work on MacOS : Last line is indeed selected, but the first line are still displayed...
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4961
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget auto scroll to last line ...

Post by RASHAD »

Hi Mindphazer
Sorry,I don't have Mac to test
But try the next it may make a difference

Code: Select all

Procedure SelectItem(gadget)
  SetActiveGadget(gadget)
  no = CountGadgetItems(gadget)
  AddGadgetItem(gadget,-1,"")
  RemoveGadgetItem(gadget, no)  
EndProcedure
Egypt my love
Axolotl
Addict
Addict
Posts: 861
Joined: Wed Dec 31, 2008 3:36 pm

Re: EditorGadget auto scroll to last line ...

Post by Axolotl »

For windows and acc. to MSDN: WM_VSCROLL message

Code: Select all

  SendMessage_(GadgetID(0), #WM_VSCROLL, #SB_BOTTOM, 0) 
BTW: This checks whether the last line is visible or not.

Code: Select all

Procedure IsGadgetLastItemVisible(Gadget) 
  Protected si.SCROLLINFO 

  si\cbSize = SizeOf(SCROLLINFO)
  si\fMask = #SIF_ALL 
  If GetScrollInfo_(GadgetID(Gadget), #SB_VERT, @si) 
    ProcedureReturn Bool(si\nPos = (si\nMax - si\nPage)) 
  EndIf 
  ProcedureReturn -1 ; failure 
EndProcedure 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Piero
Addict
Addict
Posts: 992
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: EditorGadget auto scroll to last line ...

Post by Piero »

Mindphazer wrote: Sun Sep 21, 2025 2:37 pmon MacOS

Code: Select all

Range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 468
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: EditorGadget auto scroll to last line ...

Post by Mindphazer »

RASHAD wrote: Sun Sep 21, 2025 3:20 pm Hi Mindphazer
Sorry,I don't have Mac to test
But try the next it may make a difference

Code: Select all

Procedure SelectItem(gadget)
  SetActiveGadget(gadget)
  no = CountGadgetItems(gadget)
  AddGadgetItem(gadget,-1,"")
  RemoveGadgetItem(gadget, no)  
EndProcedure
Nope, same result
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 468
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: EditorGadget auto scroll to last line ...

Post by Mindphazer »

Piero wrote: Sun Sep 21, 2025 4:23 pm
Mindphazer wrote: Sun Sep 21, 2025 2:37 pmon MacOS

Code: Select all

Range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)
I know
Rashad was trying to write a code without API calls
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply