Page 2 of 3
Posted: Fri Oct 20, 2006 3:32 pm
by Tranquil
In my program i have the EnableExplicit activated.
I wanted to use netmastro's code, but i need to know the variable declation i must write in the procedure.
Can someone help me please ?
Code: Select all
EnableExplicit
Procedure Callback(hwnd, msg, wparam, lparam)
Protected result.l
Protected pt.point
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
Global a.b
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 20
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
Posted: Fri Oct 20, 2006 3:49 pm
by RegisLG

seems so easy ! Thank you !
Where is the "point" type declared ? is it a structure, part of the API, that we don't have to declare ?
Posted: Fri Oct 20, 2006 4:23 pm
by Tranquil
.point is a structure predefined in the PB-residents. Most common structures of Windows are defined in there.
Posted: Fri Oct 20, 2006 5:18 pm
by RegisLG
I finally finished my little tool (had to synchronize/translate 2 subtitles) with your help. I only had to modify the callback to manage 2 editor gadgets and to move the setwindowcallback after the lines that create the editor gadgets, cause i had a "#gadget not initialised" error instead.
Thanks tranquil for the explanations and coders for sharing their hints

Posted: Tue Nov 07, 2006 4:51 pm
by omit59
Hello!
I've been trying to use this and had strange problem when using many lines. When POINT structure from #EM_GETSCROLLPOS reaches value of 65535, #EM_SETSCROLLPOS doesn't give right value to the other editor any more! Mayby someone could explain what is happening?
Code: Select all
Procedure Callback(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 10000
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
Timo
Posted: Tue Nov 07, 2006 5:20 pm
by srod
I will have a guess that the #WM_SETSCROLL message is using (internally) #WM_VSCROLL and #WM_HSCROLL messages etc. Now both of these only use 16 bit scroll positions (hence the 65535) max range etc.
To use 32 bit scroll ranges you will perhaps need to adopt a different method.
I am not certain that this is the root cause of your problem, but it sounds a likely candidate!

Posted: Tue Nov 07, 2006 6:35 pm
by netmaestro
Code: Select all
Procedure Callback(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
If msg=#WM_COMMAND
If IsGadget(1)
If lparam = GadgetID(1)
If wparam >> 16 = 1024 ; EN_UPDATE
SendMessage_(GadgetID(1), #EM_GETSCROLLPOS, 0, @pt.point)
lines = SendMessage_(GadgetID(0),#EM_GETLINECOUNT,0,0)
totpx = 13 * lines ; assumes px height of system gui font - change this if you change the gadget font
factor.d = totpx /65535
If factor < 1: factor = 1 : EndIf
pt\y = Int(pt\y*factor)
SendMessage_(GadgetID(0), #EM_SETSCROLLPOS, 0, @pt)
EndIf
EndIf
EndIf
result = 0
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
SetWindowCallback(@Callback())
ContainerGadget(2,5,5,50,133)
EditorGadget(0, 5, 5, 65, 133)
CloseGadgetList()
EditorGadget(1, 60, 10, 250, 133)
For a = 0 To 10000
AddGadgetItem(0, a, Str(a))
AddGadgetItem(1, a, "Line "+Str(a))
Next
Repeat : Until WaitWindowEvent()=#WM_CLOSE
EndIf
End
OK, OK, so it's ugly as sin - it works

Posted: Tue Nov 07, 2006 6:50 pm
by srod
OK, OK, so it's ugly as sin - it works
What if there are different font sizes in different lines etc?
Posted: Tue Nov 07, 2006 6:55 pm
by netmaestro
Yeah, this solution won't handle that case. This is just my first kick at the cat, I'm sure there's a better approach. Whatcha think - can you find it before I do?
Posted: Tue Nov 07, 2006 7:05 pm
by srod
It's all yours this time!

Posted: Wed Nov 08, 2006 6:20 am
by omit59
@Srod,
yes, thats really my problem...
@Netmaestro,
might be an ugly solution, but seems to work.
Font sizes are not a big problem, making just a simple editor which uses one font, no RTF stuff.
Thanks to both of You!!
Timo
Posted: Wed Nov 08, 2006 6:43 am
by netmaestro
an ugly solution, but seems to work.
Pretty much sums up my wife's opinon of me... :roll:
Posted: Wed Nov 08, 2006 7:36 am
by Dare
Re: How Syncronize scroll in two gadgets?
Posted: Wed Oct 14, 2009 12:19 pm
by pablov
The code netmaestro well works with the EditorGadget, but does not work with the ListViewGadget and the ListIconGadget. Somebody can will correct for the ListViewGadget and the ListIconGadget.
Re: How Syncronize scroll in two gadgets?
Posted: Wed Oct 14, 2009 5:31 pm
by Fluid Byte
Some dirrrrty hacks for j000 ...
ListViewGadget
Code: Select all
OpenWindow(0,0,0,415,320,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0,5,5,200 - 2 - 17,310)
ListViewGadget(1,0,0,200,310)
CloseGadgetList()
ListViewGadget(2,190,5,200,310)
For i=1 To 500
AddGadgetItem(1,-1,"Gadget Item #" + RSet(Str(i),3,"0"))
AddGadgetItem(2,-1,"Gadget Item #" + RSet(Str(i),3,"0"))
Next
Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_CTLCOLORLISTBOX
If lParam = GadgetID(2)
SendMessage_(GadgetID(1),#LB_SETTOPINDEX,GetScrollPos_(GadgetID(2),#SB_VERT),0)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
SetWindowCallback(@WindowCallback())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
ListIconGadget
Code: Select all
OpenWindow(0,0,0,415,320,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ContainerGadget(0,5,5,200 - 2 - 17,310)
ListIconGadget(1,0,0,200,310,"Name",170)
CloseGadgetList()
ListIconGadget(2,190,5,200,310,"Name",170)
For i=1 To 500
AddGadgetItem(1,-1,"Gadget Item #" + RSet(Str(i),3,"0"))
AddGadgetItem(2,-1,"Gadget Item #" + RSet(Str(i),3,"0"))
Next
Structure NMLVSCROLL
hdr.NMHDR
dx.l
dy.l
EndStructure
Procedure WindowCallback(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_NOTIFY
Protected *pnmh.NMHDR = lParam
If *pnmh\hwndFrom = GadgetID(2)
If *pnmh\code = #LVN_ENDSCROLL
Protected *pnms.NMLVSCROLL = lParam
Protected LVTI = SendMessage_(GadgetID(2),#LVM_GETTOPINDEX,0,0)
Protected LVCP = SendMessage_(GadgetID(2),#LVM_GETCOUNTPERPAGE,0,0)
If *pnms\dy < 0
SendMessage_(GadgetID(1),#LVM_ENSUREVISIBLE,LVTI,0)
ElseIf *pnms\dy > 0
SendMessage_(GadgetID(1),#LVM_ENSUREVISIBLE,LVTI + LVCP - 1,0)
EndIf
EndIf
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
SetWindowCallback(@WindowCallback())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend