EditorGadget scroll
EditorGadget scroll
As in EditorGadget to make the text scroll down automatically when you add the line AddGadgetItem(#EDITOR, number_editor,Output$)?
Re: EditorGadget scroll
For Windows
Scroll per each line
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))
Next
SendMessage_(GadgetID(0), #EM_SETSEL, -1,-1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
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)
Next
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
Re: EditorGadget scroll
I use this usually:
Code: Select all
Procedure LogIT(Text.s, GadgetID = -1)
If Text
Text = FormatDate("%hh:%ii:%ss", Date()) + " " + Text
EndIf
If GadgetID <> -1
AddGadgetItem(GadgetID, -1, Text)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Select GadgetType(GadgetID)
Case #PB_GadgetType_ListView
SendMessage_(GadgetID(GadgetID), #LB_SETTOPINDEX, CountGadgetItems(GadgetID) - 1, #Null)
Case #PB_GadgetType_ListIcon
SendMessage_(GadgetID(GadgetID), #LVM_ENSUREVISIBLE, CountGadgetItems(GadgetID) - 1, #False)
Case #PB_GadgetType_Editor
SendMessage_(GadgetID(GadgetID), #EM_SCROLLCARET, #SB_BOTTOM, 0)
EndSelect
CompilerCase #PB_OS_Linux
Protected *Adjustment.GtkAdjustment
*Adjustment = gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(Gadget)))
*Adjustment\value = *Adjustment\upper
gtk_adjustment_value_changed_(*Adjustment)
CompilerEndSelect
EndIf
EndProcedure{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}
Re: EditorGadget scroll
it is necessary for Linux, this code does not work, it gives an error on the line
error: memory access invalid
Code: Select all
gtk_adjustment_value_changed_(*Adjustment)Re: EditorGadget scroll
Mac:
Code: Select all
Range.NSRange\location = Len(GetGadgetText(0))
CocoaMessage(0, GadgetID(0), "scrollRangeToVisible:@", @Range)Re: EditorGadget scroll
Works for merndrei wrote: Thu Jul 11, 2024 6:43 pm it is necessary for Linux, this code does not work, it gives an error on the lineerror: memory access invalidCode: Select all
gtk_adjustment_value_changed_(*Adjustment)
PB v6.11, Mint Linux LMDE 6
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: EditorGadget scroll
Could it have something to do with the fact that the function depends on the version of the subsystem?
GTK Docu wrote this (?)
GTK Docu wrote this (?)
Deprecated since: 3.18
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: EditorGadget scroll
Linux not work ...
Code: Select all
ImportC ""
gtk_adjustment_get_lower(*GtkAdjustment)
gtk_adjustment_get_upper(*GtkAdjustment)
gtk_adjustment_get_page_size(*GtkAdjustment)
gtk_adjustment_set_value(*GtkAdjustment, value)
EndImport
Procedure LogIT(Text.s, GadgetID = -1)
If Text
Text = FormatDate("%hh:%ii:%ss", Date()) + " " + Text
EndIf
If GadgetID <> -1
AddGadgetItem(GadgetID, -1, Text)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Select GadgetType(GadgetID)
Case #PB_GadgetType_ListView
SendMessage_(GadgetID(GadgetID), #LB_SETTOPINDEX, CountGadgetItems(GadgetID) - 1, #Null)
Case #PB_GadgetType_ListIcon
SendMessage_(GadgetID(GadgetID), #LVM_ENSUREVISIBLE, CountGadgetItems(GadgetID) - 1, #False)
Case #PB_GadgetType_Editor
SendMessage_(GadgetID(GadgetID), #EM_SCROLLCARET, #SB_BOTTOM, 0)
EndSelect
CompilerCase #PB_OS_Linux
Protected *Adjustment.GtkAdjustment, value.d, parent
parent = gtk_widget_get_parent_(GadgetID(GadgetID))
Debug Hex(parent)
*Adjustment = gtk_scrolled_window_get_vadjustment_(parent)
value = gtk_adjustment_get_lower(*Adjustment)
Debug value
value = gtk_adjustment_get_page_size(*Adjustment)
Debug value
value = gtk_adjustment_get_upper(*Adjustment)
Debug value
gtk_adjustment_set_value(*Adjustment, value)
CompilerEndSelect
EndIf
EndProcedure
;-TOP
#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuAbout
#MainMenuExit
EndEnumeration
Enumeration Gadgets
#MainList
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainList, 0, 0, dx, dy)
EndProcedure
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
MenuItem(#PB_Menu_About, "")
CompilerElse
MenuItem(#MainMenuAbout, "About")
CompilerEndIf
; Menu File Items
CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
MenuBar()
MenuItem(#MainMenuExit, "E&xit")
CompilerEndIf
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
ListViewGadget(#MainList, 0, 0, dx, dy)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
For a = 0 To 1000
AddGadgetItem(0, a, "Line "+Str(a))
Next
While WindowEvent() : Wend
LogIT("Hello", #MainList)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
Case #MainMenuAbout
MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainList
Select EventType()
Case #PB_EventType_Change
;
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure : Main()
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: EditorGadget scroll
Example, what's above, doesn't automatically scroll to the bottom of the Editor Gadget!?
GTK version 3.24.38
GTK version 3.24.38
Re: EditorGadget scroll
I have searched for gtk c++ examples. It looks like you have to do a lot more.
Maybe you or I can find something in the examples and convert it to purebasic
Maybe you or I can find something in the examples and convert it to 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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: EditorGadget scroll
The function gtk_scrolled_window_get_vadjustment does not return any values, as it is probably set to automatic (which is correct)
Take a ListView as trace output.
ThreadSafe Trace ...
Take a ListView as trace output.
ThreadSafe Trace ...
Code: Select all
;-TOP
CompilerIf Not #PB_Compiler_Thread
CompilerError "Use Compiler Option ThreadSage!"
CompilerEndIf
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuItemExit
EndEnumeration
Enumeration Gadgets
#MainTraceList
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
; ----
Enumeration CustomEvent #PB_Event_FirstCustomValue
#MyEvent_Trace
EndEnumeration
; ---- String Helper ----
Procedure AllocateString(String.s) ; Result = Pointer
Protected *mem.string = AllocateStructure(String)
If *mem
*mem\s = String
EndIf
ProcedureReturn *mem
EndProcedure
Procedure.s FreeString(*mem.string) ; Result String
Protected r1.s
If *mem
r1 = *mem\s
FreeStructure(*mem)
EndIf
ProcedureReturn r1
EndProcedure
; ----
Procedure DoEventTrace()
Protected *data, cnt
*data = EventData()
If *data
cnt = CountGadgetItems(#MainTraceList)
AddGadgetItem(#MainTraceList, -1, FreeString(*data))
SetGadgetState(#MainTraceList, cnt)
SetGadgetState(#MainTraceList, -1)
If cnt >= 1000
RemoveGadgetItem(#MainTraceList, 0)
EndIf
EndIf
EndProcedure : BindEvent(#MyEvent_Trace, @DoEventTrace())
Procedure __Trace(Info.s, Modul.s, Proc.s, Line)
Protected Text.s
If Modul = ""
Modul = "Main"
EndIf
Text = FormatDate("[%HH:%II:%SS] ", Date())
Text + "[Module " + Modul + "; Proc " + Proc + "; Line " + Line + "] " + Info
PostEvent(#MyEvent_Trace, 0, 0, 0, AllocateString(Text))
EndProcedure
Macro Trace(Info, Modul = #PB_Compiler_Module, Proc = #PB_Compiler_Procedure, Line = #PB_Compiler_Line)
__Trace(Info, Modul, Proc, Line)
EndMacro
; ----
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainTraceList, 0, 0, dx, dy)
EndProcedure
Procedure Main()
Protected dx, dy
Protected ExitTime
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
MenuItem(#MainMenuItemExit, "E&xit")
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
ListViewGadget(#MainTraceList, 0, 0, dx, dy)
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
For i = 1 To 10
Trace("Count " + i)
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuItemExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ForEver
;-- ExitProgram
Trace("Exit Program (Wait 1 Seconds)")
ExitTime = ElapsedMilliseconds()
Repeat
WaitWindowEvent(10)
If ElapsedMilliseconds() - ExitTime >= 1000
Break
EndIf
ForEver
EndIf
EndProcedure : Main()
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: EditorGadget scroll
Yes, thank you works!
Re: EditorGadget scroll
Another question is how to set the background color?
this does not work!
Code: Select all
SetGadgetItemColor(#MainTraceList,1,#PB_Gadget_BackColor, RGB(255,0,0),#PB_All)
Re: EditorGadget scroll
Hi,
the code line works as expected. What do you expect?
The background color of Line 1 has changed to red.
See the running code (borrowed from help)
the code line works as expected. What do you expect?
The background color of Line 1 has changed to red.
See the running code (borrowed from help)
Code: Select all
; Help Example (adapted to your line ....) !! Working on Win11 and Ubuntu 22.04 !!
#MainTraceList = 0
; Help Example (original)
If OpenWindow(0, 0, 0, 300, 300, "SetGadgetItemColor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 280, 280, "Column 0", 100)
AddGadgetColumn(0, 1, "Column 1", 100)
For i = 1 To 10
AddGadgetItem(0, -1, "Text 1"+Chr(10)+"Text 2")
Next
SetGadgetItemColor(0, #PB_All, #PB_Gadget_FrontColor, $0000FF, 1)
SetGadgetItemColor(0, 3, #PB_Gadget_BackColor, $00FFFF, #PB_All)
SetGadgetItemColor(0, 9, #PB_Gadget_BackColor, $FFFF00, 1)
; Help Example (add your line ....)
SetGadgetItemColor(#MainTraceList, 1, #PB_Gadget_BackColor, RGB(255,0,0), #PB_All)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).



