EditorGadget scroll to bottom

Just starting out? Need help? Post your questions and find answers here.
danwinslow
New User
New User
Posts: 7
Joined: Mon Feb 01, 2021 11:52 pm

EditorGadget scroll to bottom

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6240
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: EditorGadget scroll to bottom

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: EditorGadget scroll to bottom

Post 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.

:wink:
danwinslow
New User
New User
Posts: 7
Joined: Mon Feb 01, 2021 11:52 pm

Re: EditorGadget scroll to bottom

Post by danwinslow »

Ah, thanks. I was wondering what that Scintilla bit was about. Will look into it.

Thanks
Dan
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: EditorGadget scroll to bottom

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2739
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: EditorGadget scroll to bottom

Post 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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: EditorGadget scroll to bottom

Post 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.
User_Russian
Addict
Addict
Posts: 1522
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: EditorGadget scroll to bottom

Post by User_Russian »

Is there a similar code for the qt subsystem?
Post Reply