Editor_Scroll To Bottomline crash works not

Just starting out? Need help? Post your questions and find answers here.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Editor_Scroll To Bottomline crash works not

Post by walbus »

Tested PB 5.40 b10 Mint 64

Code: Select all

;======================================================================
; Module/File:     Editor_ScrollToBottomline.pb
; Function:        scrollt zur letzten Zeile - Linux
; Author:          freak
; Date:            July 30, 2014
; Version:         0.1
; Target Compiler: PureBasic 5.22, 5.30
; Target OS:       (X/K)ubuntu 32/64, Ascii/Uni
; License:         Free, unrestricted, no warranty
;======================================================================

ImportC ""
	gtk_adjustment_get_page_size.d(*adjustment.GtkAdjustment)
	gtk_adjustment_get_upper.d(*adjustment.GtkAdjustment)
	gtk_adjustment_get_step_increment.d(*adjustment.GtkAdjustment)
EndImport

EnableExplicit

; Object constants
#MainWin= 0
#Button = 0
#Editor = 1

#WinX=300
#WinY=200
#WinW=400
#WinH=200

Global.i gEvent, gLineCount
Global *Adjustment.GtkAdjustment


If OpenWindow(0, #WinX, #WinY, #WinW, #WinH, "editor scroll", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	
	ButtonGadget(#Button, 10, 10, 150, 30, "add line")
	EditorGadget(#Editor, 10, 50, 380, 140)
	
	Repeat
		gEvent = WaitWindowEvent()
		
		If gEvent = #PB_Event_Gadget And EventGadget() = #Button
			AddGadgetItem(#Editor, -1, "New line: " + Str(gLineCount))
			gLineCount+ 1
			
			; get the vertical adjustment of the scrolled window ...
			*Adjustment= gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(#Editor)))
			
			; some Adjustment-values to debug ...
			Debug "Page-Size     : " + Str(gtk_adjustment_get_page_size(*Adjustment))
			Debug "rel. upper pos: " + Str(gtk_adjustment_get_upper(*Adjustment))
			Debug "step increment: " + Str(gtk_adjustment_get_step_increment(*Adjustment))
			
			; change the value to the max ...
			*Adjustment\value= *Adjustment\upper
			
			; notify the scrolled window of the change ...
			gtk_adjustment_value_changed_(*Adjustment)     
		EndIf
		
	Until gEvent = #PB_Event_CloseWindow 
EndIf
; IDE Options = PureBasic 5.30 (Linux - x64)
; CursorPosition = 10
; EnableUnicode
; EnableXP
; CurrentDirectory = /home/charly-xubuntu/Programming/PureBasic/purebasic/
Fred
Administrator
Administrator
Posts: 16685
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Editor_Scroll To Bottomline crash works not

Post by Fred »

This is not a PB function, it's not granted to work on all futur PB version.
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Editor_Scroll To Bottomline crash works not

Post by Oma »

Hello walbus,

this method doesn't work very reliable and makes problems an gtk2 too. (And it's no PureBasic-Bug.)
The examples in the Linux-API-Lib aren't prepared for gtk3 at the moment. Please wait for the update after the PureBasic-Betas with fixes, news or marked codes.

Maybe you can use one of the new examples for EditorGadget-scrolling...

Code: Select all

ImportC ""
	gtk_adjustment_get_page_size.d(*adjustment.GtkAdjustment)
	gtk_adjustment_get_upper.d(*adjustment.GtkAdjustment)
	gtk_adjustment_set_value(*adjustment.GtkAdjustment, value.d)
EndImport

; Object constants
#MainWin= 0
#Edt1   = 0
#Bt1    = 1
#Bt2    = 2

#WinX= 300
#WinY= 200
#WinW= 300
#WinH= 200

Global.i gEvent, gQuit, I
Global *gAdjustment.GtkAdjustment
Global.d EdtPageSize, EdtUpper
Global.s EditString1= "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. " + 
                      " Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."


If OpenWindow(#MainWin, #WinX, #WinY, #WinW, #WinH, "EditorGadget - to bottom/top", #PB_Window_SystemMenu)
	ButtonGadget(#Bt1, 5, 5, 100, 25, "to bottomline")
	ButtonGadget(#Bt2, 105, 5, 100, 25, "to topline")
	EditorGadget(#Edt1, 5, 35, #WinW-10, #WinH-39, #PB_Editor_WordWrap)
	AddGadgetItem(#Edt1, -1, EditString1)
	
	gtk_text_view_set_wrap_mode_(GadgetID(#Edt1), #GTK_WRAP_WORD)
	*gAdjustment= gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(#Edt1)))
	
	
	Repeat
		gEvent= WaitWindowEvent()
		
		Select gEvent
			Case #PB_Event_CloseWindow
				gQuit= #True
				
			Case #PB_Event_Gadget
				Select EventGadget()
					Case #Bt1
							EdtPageSize= gtk_adjustment_get_page_size(*gAdjustment)
							EdtUpper= gtk_adjustment_get_upper(*gAdjustment)
							gtk_adjustment_set_value(*gAdjustment, EdtUpper-EdtPageSize);  to bottomline
							
					Case #Bt2
							;EdtPageSize= gtk_adjustment_get_page_size(*gAdjustment)
							;EdtUpper= gtk_adjustment_get_upper(*gAdjustment)
							gtk_adjustment_set_value(*gAdjustment, 0);                     to topline
						
				EndSelect

		EndSelect
		
	Until gQuit
EndIf
Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Editor_Scroll To Bottomline crash works not

Post by walbus »

Many thanks Charly, its very helpful.
Regards Wernerl
Post Reply