Page 1 of 1
EditorGadget scroll to bottom
Posted: Sat Feb 06, 2021 5:54 pm
by danwinslow
Hi Folks -
Another newbie question: I am dumping a lot of text to an Editor gadget, and the scroll is not advancing with the added lines. I did a lot of searching and reading about this, and saw many references to sendmessage_ which works great on windows, as well as a couple solutions for Linux that were also platform-dependent. Is there any truly platform-independent way to do this?
Purebasic seems so great, it's really odd to me that this basic capability seems missing, so I thought I'd ask. It seems like it should even be a default action...I can't think of many reasons why you wouldn't want this behavior. The other option I suppose would be to use compilerif's and just have custom for each platform.
Thanks
Dan
Re: EditorGadget scroll to bottom
Posted: Sat Feb 06, 2021 7:33 pm
by mk-soft
Many functions are programmed according to the OS. There is no commonality between OS platforms. Therefore, the compiler option has to be solved depending on the OS.
Some solutions from the community have already been implemented in Purebasic.
Re: EditorGadget scroll to bottom
Posted: Sat Feb 06, 2021 10:12 pm
by Marc56us
danwinslow wrote:Another newbie question: I am dumping a lot of text to an Editor gadget, and the scroll is not advancing with the added lines[...]
Editor gadget is a lite gadget. For extended usage of text, we use
Scintilla library.
Many functions, example:
Scrolling and automatic scrolling
Only one DLL to provide with your program.

Re: EditorGadget scroll to bottom
Posted: Sun Feb 07, 2021 1:29 am
by danwinslow
Ah, thanks. I was wondering what that Scintilla bit was about. Will look into it.
Thanks
Dan
Re: EditorGadget scroll to bottom
Posted: Sun Feb 07, 2021 2:15 am
by Tenaja
It looks intimidating at first, because there are so many commands. If you use editors, however, the learning curve is worth it. I'm now so comfortable with scintilla that I use it even for simple editors... It's faster for me, and if I just just want one feature, it's there.
Re: EditorGadget scroll to bottom
Posted: Sun Feb 07, 2021 9:56 am
by TI-994A
The thread title warrants a working example. So, here's one for the
EditorGadget(), and an alternative approach with the
ScintillaGadget().
API calls to scroll the EditorGadget() to the bottom (Windows & MacOS only)Code: Select all
InitNetwork()
; download html text from the PureBasic website
*httpBuffer = ReceiveHTTPMemory("https://www.purebasic.com/index.php")
If *httpBuffer
httpText$ = PeekS(*httpBuffer, MemorySize(*httpBuffer), #PB_UTF8 | #PB_ByteLength)
FreeMemory(*httpBuffer)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Ignore, #PB_Ignore, 400, 350, "EditorGadget Scroll", wFlags)
EditorGadget(0, 10, 10, 380, 280, #PB_Editor_WordWrap)
ButtonGadget(1, 10, 305, 380, 35, "add more text")
SetGadgetText(0, httpText$)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetText(0, GetGadgetText(0) + httpText$)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(GadgetID(0), #EM_SETSEL, -1, -1)
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @range)
CompilerEndIf
SetActiveGadget(0)
EndSelect
EndSelect
Until appQuit = 1
EndIf
native approach to scroll the ScintillaGadget() to the bottom (tested on Windows & MacOS only)Code: Select all
InitNetwork()
Enumeration
#window
#scintilla
#button
EndEnumeration
; download html text from the PureBasic website
*httpText = ReceiveHTTPMemory("https://www.purebasic.com/index.php")
*httpText = UTF8(PeekS(*httpText, MemorySize(*httpText), #PB_UTF8 | #PB_ByteLength))
httpTextLen = MemorySize(*httpText) - 1
If *httpText And InitScintilla()
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#window, #PB_Ignore, #PB_Ignore, 400, 350, "Scintilla Example", wFlags)
ScintillaGadget(#scintilla, 10, 10, 380, 280, 0)
ScintillaSendMessage(#scintilla, #SCI_SETMARGINWIDTHN, 1, 0)
ScintillaSendMessage(#scintilla, #SCI_SETWRAPMODE, #True)
ScintillaSendMessage(#scintilla, #SCI_SETTEXT, 0, *httpText)
ButtonGadget(#button, 10, 310, 380, 30, "add more text")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case #button
ScintillaSendMessage(#scintilla, #SCI_APPENDTEXT, httpTextLen, *httpText)
ScintillaSendMessage(#scintilla, #SCI_DOCUMENTEND)
SetActiveGadget(#scintilla)
EndSelect
EndSelect
Until appQuit
FreeMemory(*httpText)
EndIf
Re: EditorGadget scroll to bottom
Posted: Sun Feb 07, 2021 12:14 pm
by Shardik
danwinslow wrote:Is there any truly platform-independent way to do this?
You may try
this cross-platform example (tested successfully on MacOS, Linux GTK2/GTK3 and Windows) which uses OS-specific functions to always keep the last line in an EditorGadget visible.
When looking for cross-platform examples which are not available in PureBasic natively, you should always take a look into
this list in which I have collected many of these examples.
Re: EditorGadget scroll to bottom
Posted: Fri Mar 19, 2021 1:14 pm
by User_Russian
Is there a similar code for the qt subsystem?