Send EditorGadget() to bottom line?
Send EditorGadget() to bottom line?
Hi all.
Just wondered if it was possible (natively or using GTK 2 API) to force the EditorGadget to jump straight down the bottom of it's contents?
I've found some info here...
http://developer.gnome.org/doc/API/2.0/ ... table.html
...but have no idea quite how to work with it. Any assistance would be much appreciated
Just wondered if it was possible (natively or using GTK 2 API) to force the EditorGadget to jump straight down the bottom of it's contents?
I've found some info here...
http://developer.gnome.org/doc/API/2.0/ ... table.html
...but have no idea quite how to work with it. Any assistance would be much appreciated
Sorry, i overlooked this one.
The EditorGadget (in gtk2) is a GtkTextView which is contained inside a
GtkScrolledWindow to handle the scrolling. So you have to get the parent
of the widget returned by GadgetID(), and then you can work with the
GtkScrolledWindow related functions (here i get the vertical adjustment and change it)
I think i will add native scrolling functions to the EditorGadget so there is a crossplatform way for it.
The EditorGadget (in gtk2) is a GtkTextView which is contained inside a
GtkScrolledWindow to handle the scrolling. So you have to get the parent
of the widget returned by GadgetID(), and then you can work with the
GtkScrolledWindow related functions (here i get the vertical adjustment and change it)
Code: Select all
; Note: In the PB definitions, gdouble is defined as a structure of 2 longs,
; due to the missing double support in pre-4.00 versions. We will have
; to change this now that doubles are supported.
;
; For now, just use this redefined structure instead:
;
Structure _GtkAdjustment
parent_instance.GtkObject
lower.d
upper.d
value.d
step_increment.d
page_increment.d
page_size.d
EndStructure
#Button = 0
#Editor = 1
If OpenWindow(0, 0, 0, 400, 200, "editor scroll", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(#Button, 10, 10, 150, 30, "add line")
EditorGadget(#Editor, 10, 50, 380, 140)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = #Button
AddGadgetItem(#Editor, -1, "New line: " + Str(LineCount))
LineCount + 1
; get the vertical adjustment of the scrolled window
*Adjustment._GtkAdjustment = gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(#Editor)))
; change the value to the max
*Adjustment\value = *Adjustment\upper
; notify the scrolled window of the change
gtk_adjustment_value_changed_(*Adjustment)
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
quidquid Latine dictum sit altum videtur
-
- User
- Posts: 71
- Joined: Thu May 02, 2019 3:57 am
- Location: USA
- Contact:
Re: Send EditorGadget() to bottom line?
When I try the code that Freak posted, I get an error: Structure not found: GtkObject.
Need help.
Thanks,
Robert
Need help.
Thanks,
Robert
Re: Send EditorGadget() to bottom line?
In order to use freak's code you have to activate subsystem GTK2 (Menu > Compiler > Compiler Options... > Library Subsystem: gtk2). In PureBasic's default subsystem GTK3 the structure GtkAdjustment has been changed to be private, so in GTK3 it isn't possible anymore to access the structure members.
You may therefore try the following alternative example which works with both GTK2 and GTK3 (tested successfully with Xubuntu 18.04 x86 and PB 5.46 x86 in ASCII and Unicode mode):
You may therefore try the following alternative example which works with both GTK2 and GTK3 (tested successfully with Xubuntu 18.04 x86 and PB 5.46 x86 in ASCII and Unicode mode):
Code: Select all
EnableExplicit
Define i.I
Define Iter.GtkTextIter
Define *TextBuffer.GtkTextBuffer
OpenWindow(0, 100, 100, 180, 120, "EditorGadget", #PB_Window_SystemMenu)
EditorGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 45)
ButtonGadget(1, WindowWidth(0) / 2 - 60, WindowHeight(0) - 33, 120, 25, "Scroll to last line")
For i = 1 To 20
AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1 And EventType() = #PB_EventType_LeftClick
*TextBuffer = gtk_text_view_get_buffer_(GadgetID(0))
gtk_text_buffer_get_iter_at_line_(*TextBuffer, @Iter, CountGadgetItems(0) - 1)
gtk_text_view_scroll_to_iter_(GadgetID(0), Iter, 0.0, #False, 0.0, 0.0)
EndIf
EndSelect
ForEver
Re: Send EditorGadget() to bottom line?
Can anyone answer if native scrolling has been implemented? I am wanting EditorGadget() to go to the bottom line also...freak wrote:Sorry, i overlooked this one.
The EditorGadget (in gtk2) is a GtkTextView which is contained inside a
GtkScrolledWindow to handle the scrolling. So you have to.......
I think i will add native scrolling functions to the EditorGadget so there is a crossplatform way for it.
Linux Debian 9, PB 5.62 (x64)
Thanks.
Re: Send EditorGadget() to bottom line?
Sorry, I don't understand your question. I just tried my last example on Linux Mint 19.3 'Tricia' x64 with Cinnamon using PB 5.72 x64 with subsystem empty (default Gtk3) and subsystem gtk2. After clicking onto the button "Scroll to last line" the text is scrolled to the bottom displaying "Line number 20".Jimbob81 wrote:I am wanting EditorGadget() to go to the bottom line also...
Doesn't it work with your Debian 9? What desktop environment are you using? Do you get any error message?
Re: Send EditorGadget() to bottom line?
OK, I was able to reproduce your possible problems with Debian 10 'Buster' x86 and LXDE using PB 5.72 x86. When setting the subsystem in my example from above to gtk2, the program stopped compiling with the following error message:
In order to work equally well with GTK2 and GTK3 I had to import all 3 API functions:
The compilation with GTK3 worked like a charm and scrolling to the last line worked.PureBasic error message wrote:[WARNING] Gtk (ERROR): GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
In order to work equally well with GTK2 and GTK3 I had to import all 3 API functions:
Code: Select all
EnableExplicit
ImportC ""
gtk_text_buffer_get_iter_at_line(*TextBuffer.GtkTextBuffer, *Iter, LineNumber.L)
gtk_text_view_get_buffer(*TextView.GtkTextView)
gtk_text_view_scroll_to_iter(*TextView.GtkTextView, *Iter, WithinMargin.D, UseAlign.I, xAlign.D, yAlign.D)
EndImport
Define i.I
Define Iter.GtkTextIter
Define *TextBuffer.GtkTextBuffer
OpenWindow(0, 100, 100, 180, 120, "EditorGadget", #PB_Window_SystemMenu)
EditorGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 45)
ButtonGadget(1, WindowWidth(0) / 2 - 60, WindowHeight(0) - 33, 120, 25, "Scroll to last line")
For i = 1 To 20
AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1 And EventType() = #PB_EventType_LeftClick
*TextBuffer = gtk_text_view_get_buffer(GadgetID(0))
gtk_text_buffer_get_iter_at_line(*TextBuffer, @Iter, CountGadgetItems(0) - 1)
gtk_text_view_scroll_to_iter(GadgetID(0), Iter, 0.0, #False, 0.0, 0.0)
EndIf
EndSelect
ForEver
Re: Send EditorGadget() to bottom line?
Thanks @Shardik. Your new example also works for me with either GTK2 or GTK3 subsystem option.
I find it interesting that you don't need to specify a library filename in the ImportC "" statement and it just works...
I'm guessing that PB is using the gtk.imp library in the /purelibraries/linux folder as the Import file to make this work.
I'm getting an idea that if you choose the GTK3 subsystem then the gtk.imp library at /purelibraries/linux is used to compile against but if you choose GTK2 then this file is not accessed but instead /gtk2/purelibraries/linux gtk.imp is. If both were accessible then both GTK2 and 3 commands would be available without importing... maybe.
*edit*
Nop I could be way off here!
I find it interesting that you don't need to specify a library filename in the ImportC "" statement and it just works...
I'm guessing that PB is using the gtk.imp library in the /purelibraries/linux folder as the Import file to make this work.
I'm getting an idea that if you choose the GTK3 subsystem then the gtk.imp library at /purelibraries/linux is used to compile against but if you choose GTK2 then this file is not accessed but instead /gtk2/purelibraries/linux gtk.imp is. If both were accessible then both GTK2 and 3 commands would be available without importing... maybe.
*edit*
Nop I could be way off here!
Re: Send EditorGadget() to bottom line?
How to do this for a ListViewGadget (and others like TreeGadget, ComboBoxGadget) ?
Just changing the gadget type is not working.
Thanks.
Just changing the gadget type is not working.
Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Send EditorGadget() to bottom line?
I discovered, for listview gadgets, this still works :
SetGadgetState(ListView,CountGadgetItems(ListView)-1)
if the listview is not set in Multiselect mode.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.