How Syncronize scroll in two gadgets?

Just starting out? Need help? Post your questions and find answers here.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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
Tranquil
RegisLG
New User
New User
Posts: 3
Joined: Mon Jul 04, 2005 4:16 pm
Location: France

Post by RegisLG »

:oops: 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 ?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

.point is a structure predefined in the PB-residents. Most common structures of Windows are defined in there.
Tranquil
RegisLG
New User
New User
Posts: 3
Joined: Mon Jul 04, 2005 4:16 pm
Location: France

Post 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 :)
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :)
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 :twisted:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

OK, OK, so it's ugly as sin - it works
:)

What if there are different font sizes in different lines etc?
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It's all yours this time! :)
I may look like a mule, but I'm not a complete ass.
omit59
User
User
Posts: 63
Joined: Fri Mar 11, 2005 8:41 am
Location: Finland

Post by omit59 »

@Srod,
yes, thats really my problem...:lol:

@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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

an ugly solution, but seems to work.
Pretty much sums up my wife's opinon of me... :roll:
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

:lol:
Dare2 cut down to size
pablov
User
User
Posts: 19
Joined: Mon Apr 06, 2009 11:55 am

Re: How Syncronize scroll in two gadgets?

Post 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.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: How Syncronize scroll in two gadgets?

Post 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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply