Page 1 of 2

EditorGadget auto scroll to last line ...

Posted: Fri Sep 19, 2025 9:25 pm
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

Re: EditorGadget auto scroll to last line ...

Posted: Fri Sep 19, 2025 9:42 pm
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

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 1:29 am
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

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 3:53 am
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)

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 4:38 am
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

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 10:08 am
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.

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 8:50 pm
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.

Re: EditorGadget auto scroll to last line ...

Posted: Sat Sep 20, 2025 8:56 pm
by Olli
Hello Shardik !

Thank you for this recall !

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 1:26 pm
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

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 2:37 pm
by Mindphazer
Hi Rashed,

it doesn't work on MacOS : Last line is indeed selected, but the first line are still displayed...

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 3:20 pm
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

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 3:56 pm
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 

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 4:23 pm
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)

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 5:37 pm
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

Re: EditorGadget auto scroll to last line ...

Posted: Sun Sep 21, 2025 5:38 pm
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