How Syncronize scroll in two gadgets?

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Dammit Srod!! where you buying your holster oil? [edit] Ha - tweaked my code to be 4 lines shorter than yours! :twisted:

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 20 
      AddGadgetItem(0, a, Str(a)) 
      AddGadgetItem(1, a, "Line "+Str(a)) 
   Next 
   Repeat : Until WaitWindowEvent()=#WM_CLOSE 
EndIf 
End
Last edited by netmaestro on Wed Aug 09, 2006 12:33 am, edited 2 times in total.
BERESHEIT
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

chen wrote:Ok...
Im testing your code and I see this:

If you scroll down line by line the line number are sincronized with the data
But?
If you advance by page there are no one-one relation.... for example

65 point to line 66

Code: Select all

< snip snip >
DO I need to consider something else...?

Anyway Im going to try by myself.... thanks indeed...
It's checking the first visible line item and including anything that's even partially visible. Using a callback and checking for the scroll message rather than watching the line number of the edit control is much better - a la srod's code. That way they match exactly and you aren't constrained by PB's limitation of not providing events while moving the little scrollbar itself.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I like your code netmaestro. Pretty slick! :)

Which notification message corresponds to 1024?
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Gotcha srod - my code works with the mousewheel and yours doesnt :D :D :D
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Pah, who needs a mousewheel? :lol:
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

1024 is #EN_UPDATE:
MSDN wrote:The EN_UPDATE notification message is sent when an edit control is about to redraw itself.
Sorry, I really should have used the constant instead of the value, it would've been easier to read. I'm bad for that. :oops:
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yep, your's is definitely the best way. Very nice.
I may look like a mule, but I'm not a complete ass.
chen
Enthusiast
Enthusiast
Posts: 338
Joined: Fri Dec 23, 2005 2:20 pm
Location: Quebec, Canada
Contact:

Post by chen »

Battle at the top :wink:

Help a lot thanks.....
RegisLG
New User
New User
Posts: 3
Joined: Mon Jul 04, 2005 4:16 pm
Location: France

Post by RegisLG »

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 ?
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.
Post Reply