How Syncronize scroll in two gadgets?

Just starting out? Need help? Post your questions and find answers here.
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?
pablov
User
User
Posts: 19
Joined: Mon Apr 06, 2009 11:55 am

Re: How Syncronize scroll in two gadgets?

Post by pablov »

Fluid Byte
Image thank you
pablov
User
User
Posts: 19
Joined: Mon Apr 06, 2009 11:55 am

Re: How Syncronize scroll in two gadgets?

Post by pablov »

One more question.
How syncronize scroll in two ScintillaGadget?

Thank you
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re:

Post by Kwai chang caine »

chen wrote:Battle at the top :wink:
Yes exactely....SROD against NETMAESTRO....incredible....it's so great :shock: 8)
It's the battle of TITANS, like when i was young and buy the "Strange" book 8)
But a kind battle :? .......because i love them both :D

Image
ImageThe happiness is a road...
Not a destination
pablov
User
User
Posts: 19
Joined: Mon Apr 06, 2009 11:55 am

Re: How Syncronize scroll in two gadgets?

Post by pablov »

pablov wrote: How syncronize scroll in two ScintillaGadget?
Here is so works :wink:

Code: Select all

Global hSci0.l, hSci1.l, scroll_0.l, scroll_1.l
Enumeration 0 
  #Sci0
  #Sci1
EndEnumeration 

If InitScintilla("Scintilla.dll")=0
   MessageRequester("File not found", "   File " + Chr(34) + "Scintilla.dll" + Chr(34) + " not found!", #MB_OK|#MB_ICONERROR) 
   End 
EndIf
   
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification) 
          scroll_0 = ScintillaSendMessage(#Sci0, #SCI_GETFIRSTVISIBLELINE)  
          scroll_1 = ScintillaSendMessage(#Sci1, #SCI_GETFIRSTVISIBLELINE)  
          If scroll_0 <> scroll_1
            Select *scinotify\nmhdr\HwndFrom
             Case hSci0
               ScintillaSendMessage(#Sci1, #SCI_LINESCROLL, 0, scroll_0 - scroll_1)
             Case hSci1
               ScintillaSendMessage(#Sci0, #SCI_LINESCROLL, 0, scroll_1 - scroll_0)
            EndSelect   
         EndIf
EndProcedure 

If OpenWindow(0, 200, 10, 400, 470, "Scintilla exemple", #PB_Window_SystemMenu ) 
      If UseGadgetList(WindowID(0)) 
            hSci0 = ScintillaGadget(#Sci0, 0,   0, 400, 227, @ScintillaCallBack()) 
            hSci1 = ScintillaGadget(#Sci1, 0, 234, 400, 227, @ScintillaCallBack()) 
            ScintillaSendMessage(#Sci0,#SCI_SETHSCROLLBAR,0)
            ScintillaSendMessage(#Sci1,#SCI_SETHSCROLLBAR,0)
            ; Set caret line colour 
            ScintillaSendMessage(#Sci0, #SCI_SETCARETLINEBACK, $eeeeff)  
            ScintillaSendMessage(#Sci0, #SCI_SETCARETLINEVISIBLE, #True) 
            ScintillaSendMessage(#Sci1, #SCI_SETCARETLINEBACK, $eeeeff)  
            ScintillaSendMessage(#Sci1, #SCI_SETCARETLINEVISIBLE, #True) 
            ; Margins 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)  ; 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINWIDTHN, 0, 50) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINWIDTHN, 2, 0) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINSENSITIVEN, 2, #True) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)  ; 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINWIDTHN, 0, 50) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINWIDTHN, 2, 0) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINSENSITIVEN, 2, #True) 
            For i = 1 To 1000
              txt.s + Str(i)+Str(i)+Str(i)+Str(i)+Str(i)+Str(i)+#LF$
            Next i  
            ScintillaSendMessage(#Sci0, #SCI_SETTEXT, #Null, @txt) 
            ScintillaSendMessage(#Sci1, #SCI_SETTEXT, #Null, @txt) 
      EndIf 
EndIf      
      
;{- Event loop
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = 0
        CloseWindow(0)
        Break
      EndIf
  EndSelect
ForEver
;}
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: How Syncronize scroll in two gadgets?

Post by PureLust »

pablov wrote:Here is so works :wink:
Thanks for this helpful code. :D

Here is a little update including both - vertical and horizontal synchronization:

Code: Select all

Global hSci0.l, hSci1.l, scroll_0.l, scroll_1.l
Enumeration 0 
  #Sci0
  #Sci1
EndEnumeration 

If InitScintilla("Scintilla.dll")=0
   MessageRequester("File not found", "   File " + Chr(34) + "Scintilla.dll" + Chr(34) + " not found!", #MB_OK|#MB_ICONERROR) 
   End 
EndIf
   
ProcedureDLL ScintillaCallBack(Gadget, *scinotify.SCNotification) 
          scroll_0 = ScintillaSendMessage(#Sci0, #SCI_GETFIRSTVISIBLELINE)  
          scroll_1 = ScintillaSendMessage(#Sci1, #SCI_GETFIRSTVISIBLELINE)  
          If scroll_0 <> scroll_1
            Select *scinotify\nmhdr\HwndFrom
             Case hSci0
               ScintillaSendMessage(#Sci1, #SCI_LINESCROLL, 0, scroll_0 - scroll_1)
             Case hSci1
               ScintillaSendMessage(#Sci0, #SCI_LINESCROLL, 0, scroll_1 - scroll_0)
            EndSelect   
         EndIf
          xscroll_0 = ScintillaSendMessage(#Sci0, #SCI_GETXOFFSET)  
          xscroll_1 = ScintillaSendMessage(#Sci1, #SCI_GETXOFFSET)  
          If xscroll_0 <> xscroll_1
            Select *scinotify\nmhdr\HwndFrom
             Case hSci0
               ScintillaSendMessage(#Sci1, #SCI_SETXOFFSET, xscroll_0)
             Case hSci1
               ScintillaSendMessage(#Sci0, #SCI_SETXOFFSET, xscroll_1)
            EndSelect   
         EndIf
EndProcedure 

If OpenWindow(0, 200, 10, 400, 470, "Scintilla exemple", #PB_Window_SystemMenu ) 
      If UseGadgetList(WindowID(0)) 
            hSci0 = ScintillaGadget(#Sci0, 0,   0, 400, 227, @ScintillaCallBack()) 
            hSci1 = ScintillaGadget(#Sci1, 0, 234, 400, 227, @ScintillaCallBack()) 
;             ScintillaSendMessage(#Sci0,#SCI_SETHSCROLLBAR,0)
;             ScintillaSendMessage(#Sci1,#SCI_SETHSCROLLBAR,0)
            ; Set caret line colour 
            ScintillaSendMessage(#Sci0, #SCI_SETCARETLINEBACK, $eeeeff)  
            ScintillaSendMessage(#Sci0, #SCI_SETCARETLINEVISIBLE, #True) 
            ScintillaSendMessage(#Sci1, #SCI_SETCARETLINEBACK, $eeeeff)  
            ScintillaSendMessage(#Sci1, #SCI_SETCARETLINEVISIBLE, #True) 
            ; Margins 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)  ; 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINWIDTHN, 0, 50) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINWIDTHN, 2, 0) 
            ScintillaSendMessage(#Sci0, #SCI_SETMARGINSENSITIVEN, 2, #True) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINTYPEN, 0, #SC_MARGIN_NUMBER)  ; 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINMASKN, 2, #SC_MASK_FOLDERS) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINWIDTHN, 0, 50) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINWIDTHN, 2, 0) 
            ScintillaSendMessage(#Sci1, #SCI_SETMARGINSENSITIVEN, 2, #True) 
            For n = 1 To 200
              linetxt.s + Chr(n+63)
            Next n
            For i = 1 To 1000
              txt.s + Mid(linetxt,Random(50),100+Random(50))+#LF$
            Next i  
            ScintillaSendMessage(#Sci0, #SCI_SETTEXT, #Null, @txt) 
            ScintillaSendMessage(#Sci1, #SCI_SETTEXT, #Null, @txt) 
      EndIf 
EndIf      
      
;{- Event loop
Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = 0
        CloseWindow(0)
        Break
      EndIf
  EndSelect
ForEver
;}
Greetz, PL.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
Post Reply