It is currently Wed Aug 21, 2019 3:34 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Fri Apr 24, 2015 2:09 am 
Offline
New User
New User

Joined: Tue Mar 31, 2015 9:44 pm
Posts: 7
Location: Ottawa, ON Canada
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Fri Apr 24, 2015 2:25 am 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Hi. If I haven't misunderstood, the below is what you want. :wink:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Fri Apr 24, 2015 1:45 pm 
Offline
New User
New User

Joined: Tue Mar 31, 2015 9:44 pm
Posts: 7
Location: Ottawa, ON Canada
Thank you. That worked great!


Top
 Profile  
Reply with quote  
 Post subject: Re: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Sun May 31, 2015 9:20 pm 
Offline
New User
New User

Joined: Sun May 31, 2015 9:08 pm
Posts: 5
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Mon Jun 01, 2015 7:17 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1642
Location: Germany
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:
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Force vertical scrollbar to bottom on EditorGadget
PostPosted: Tue Jun 25, 2019 9:33 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1642
Location: Germany
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:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: applePi, kenmo, Sirius-2337 and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye