Force vertical scrollbar to bottom on EditorGadget

Just starting out? Need help? Post your questions and find answers here.
dchisholm
New User
New User
Posts: 7
Joined: Tue Mar 31, 2015 9:44 pm
Location: Ottawa, ON Canada
Contact:

Force vertical scrollbar to bottom on EditorGadget

Post by dchisholm »

Folks,

I am using the EditorGadget to display the progress of a lengthy processing job. It works great and the scroll bars are generated as I fill the window BUT once the last line scrolls off the screen the user can no longer see it without clicking on the scroll bar.

I always want the bottom line (the most recent event) to be visible on the screen and have the older stuff scroll off the top of the screen. Essentially I would like the vertical scroll bar to be always on the bottom (thus showing the last entry posted to the editor window). Is there an easy to do this?

I am coding in the windows platform only.

Thanks.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Force vertical scrollbar to bottom on EditorGadget

Post by Thunder93 »

Hi. If I haven't misunderstood, the below is what you want. :wink:

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 1000
      AddGadgetItem(0, a, "Line "+Str(a))      
      SendMessage_(GadgetID(0), #EM_SETSEL, -1, -1) 
      Delay(1)
    Next
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
dchisholm
New User
New User
Posts: 7
Joined: Tue Mar 31, 2015 9:44 pm
Location: Ottawa, ON Canada
Contact:

Re: Force vertical scrollbar to bottom on EditorGadget

Post by dchisholm »

Thank you. That worked great!
DirkVW
New User
New User
Posts: 5
Joined: Sun May 31, 2015 9:08 pm

Re: Force vertical scrollbar to bottom on EditorGadget

Post by DirkVW »

This works great for only Windows. The MacOSX App I am developing does not allow "SendMessage_". Is there any in a mac application to always scroll to the bottom of an EditorGadget automatically?
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Force vertical scrollbar to bottom on EditorGadget

Post by Shardik »

Wilbert has already demonstrated here how to scroll to the end of an EditorGadget on MacOS.

For your conveniance I have put together an example for MacOS which dynamically adds a line to an EditorGadget and always keeps the last line visible:

Code: Select all

EnableExplicit

#MaxLines = 20

Define LastLine.I

Procedure AddLine(EditorGadgetID.I, Line.I)
  Protected Range.NSRange

  AddGadgetItem(EditorGadgetID, -1, "Line " + Str(Line))
  Range.NSRange\location = Len(GetGadgetText(EditorGadgetID))
  CocoaMessage(0, GadgetID(EditorGadgetID), "scrollRangeToVisible:@", @Range)
EndProcedure

OpenWindow(0, 270, 100, 220, 150, "EditorGadget")
EditorGadget(0, 10, 10, 200, 130)
AddWindowTimer(0, 0, 500)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Timer
      If LastLine < #MaxLines
        LastLine + 1
        AddLine(0, LastLine)
      Else
        RemoveWindowTimer(0, 0)
      EndIf
  EndSelect
ForEver
This is a cross-platform example which works on Linux, MacOS and Windows:

Code: Select all

EnableExplicit

#MaxLines = 20

Define LastLine.I

Procedure AddLine(EditorGadgetID.I, Line.I)
  AddGadgetItem(EditorGadgetID, -1, "Line " + Str(Line))
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected *Adjustment.GtkAdjustment

      *Adjustment.GtkAdjustment = gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(EditorGadgetID)))
      *Adjustment\value = *Adjustment\upper
      gtk_adjustment_value_changed_(*Adjustment)     
    CompilerCase #PB_OS_MacOS
      Protected Range.NSRange

      Range.NSRange\location = Len(GetGadgetText(EditorGadgetID))
      CocoaMessage(0, GadgetID(EditorGadgetID), "scrollRangeToVisible:@", @Range)
    CompilerCase #PB_OS_Windows
      SendMessage_(GadgetID(EditorGadgetID), #EM_SETSEL, -1, -1) 
  CompilerEndSelect
EndProcedure

OpenWindow(0, 270, 100, 220, 150, "EditorGadget")
EditorGadget(0, 10, 10, 200, 130)
AddWindowTimer(0, 0, 500)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Timer
      If LastLine < #MaxLines
        LastLine + 1
        AddLine(0, LastLine)
      Else
        RemoveWindowTimer(0, 0)
      EndIf
  EndSelect
ForEver
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Force vertical scrollbar to bottom on EditorGadget

Post by Shardik »

I had to modify my multi-platform example for Linux because it doesn't work with GTK3. The modified version works in Linux with both GTK2 and GTK3:

Code: Select all

EnableExplicit

#MaxLines = 20

Define LastLine.I

Procedure AddLine(EditorGadgetID.I, Line.I)
  AddGadgetItem(EditorGadgetID, -1, "Line " + Str(Line))
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux
      Protected EndMark.I
      Protected TextBuffer.I
      Protected EndIter.GtkTextIter

      TextBuffer = gtk_text_view_get_buffer_(GadgetID(EditorGadgetID))
      gtk_text_buffer_get_end_iter_(TextBuffer, @EndIter)
      EndMark = gtk_text_buffer_create_mark_(TextBuffer, "end_mark",
        @EndIter, #False)
      gtk_text_view_scroll_mark_onscreen_(GadgetID(EditorGadgetID), EndMark)
    CompilerCase #PB_OS_MacOS
      Protected Range.NSRange

      Range.NSRange\location = Len(GetGadgetText(EditorGadgetID))
      CocoaMessage(0, GadgetID(EditorGadgetID), "scrollRangeToVisible:@", @Range)
    CompilerCase #PB_OS_Windows
      SendMessage_(GadgetID(EditorGadgetID), #EM_SETSEL, -1, -1) 
  CompilerEndSelect
EndProcedure

OpenWindow(0, 270, 100, 220, 150, "EditorGadget")
EditorGadget(0, 10, 10, 200, 130)
AddWindowTimer(0, 0, 500)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Timer
      If LastLine < #MaxLines
        LastLine + 1
        AddLine(0, LastLine)
      Else
        RemoveWindowTimer(0, 0)
      EndIf
  EndSelect
ForEver
Post Reply