Page 1 of 1

ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOINTER

Posted: Thu Jun 27, 2019 6:41 pm
by RSBasic
Hello

I have a problem. I have two ScintillaGadgets and I want to connect both ScintillaGadgets with #SCI_GETDOCPOINTER and #SCI_SETDOCPOINTER.
This code works:

Code: Select all

EnableExplicit

InitScintilla()

Define PBScintillaPointer

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(1, 0, 0, 500, 200, 0)
  ScintillaGadget(2, 0, 200, 500, 200, 0)
  
  PBScintillaPointer = SendMessage_(GadgetID(1), #SCI_GETDOCPOINTER, 0, 0)
  
  SendMessage_(GadgetID(2), #SCI_SETDOCPOINTER, 0, PBScintillaPointer)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
But if I have two programs, it won't work.

Program 1:

Code: Select all

EnableExplicit

InitScintilla()

Define PBScintillaPointer

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(1, 0, 0, 500, 400, 0)
  
  SendMessage_(GadgetID(1), #SCI_GETDOCPOINTER, 0, 0)
  
  PBScintillaPointer = SendMessage_(GadgetID(1), #SCI_GETDOCPOINTER, 0, 0)
  Debug PBScintillaPointer ;-Please copy the handle
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Program 2:

Code: Select all

EnableExplicit

InitScintilla()

Define PBScintillaPointer

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(1, 0, 0, 500, 400, 0)
  
  PBScintillaPointer = 4552448 ;-Please insert the handle here.
  
  SendMessage_(GadgetID(1), #SCI_SETDOCPOINTER, 0, PBScintillaPointer)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
When I start program 1, copy and paste the handle and start program 2, there is a crash. :!:
Can you help me? :(

It should be a new tool "SplitView" for PureBasic.

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Thu Jun 27, 2019 7:42 pm
by fryquez
The pointer return by SCI_GETDOCPOINTER is properly a memory address in program 1, so it's not valid for program 2.

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Thu Jun 27, 2019 7:58 pm
by RSBasic
Thanks for your answer. Yes, you're right.
Is there another way to connect two ScintillaGadgets over two processes?

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Thu Jun 27, 2019 8:12 pm
by RASHAD
Hi RSBasic
for one process :)

Code: Select all

InitScintilla()

Procedure WinCallback(hWnd, uMsg, WParam, LParam) 
 result = #PB_ProcessPureBasicEvents    
  Select uMsg
    Case #WM_NCPAINT
        ProcedureReturn 1
     
    Case #WM_NCACTIVATE
        ProcedureReturn 1
  EndSelect
  
  ProcedureReturn Result
EndProcedure 

If OpenWindow(0, 0, 0, 500, 400, "Window #1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScintillaGadget(1, 0, 0, 500, 400, 0) 
  PBScintillaPointer = SendMessage_(GadgetID(1), #SCI_GETDOCPOINTER, 0, 0)
  OpenWindow(1, 100, 100, 500, 400, "Window #2", #PB_Window_SystemMenu )
  UseGadgetList(WindowID(1))
  ScintillaGadget(2, 0, 0, 500, 400, 0)
  SendMessage_(GadgetID(2), #SCI_SETDOCPOINTER, 0, PBScintillaPointer)
  SetActiveWindow(0)
  SetWindowCallback(@WinCallback(),0)
  SetActiveWindow(1)
  SetWindowCallback(@WinCallback(),1)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver 
EndIf

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Thu Jun 27, 2019 8:15 pm
by RSBasic
Hi RASHAD
Thank you for your answer.
Unfortunately this must be two processes, because I would like to develop a tool for PureBasic: SplitView
My tool creates its own ScintillaGadget and the ScintillaGadget is inserted into the PB window with SetParent_().
I would like to connect my ScintillaGadget with the PB-ScintillaGadget. Do you have an idea?

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Thu Jun 27, 2019 8:34 pm
by RASHAD
I tried already AddGlobalAtom but I failed and that proof what fryquez said
Next I will try WM_COPYDATA
If failed we should try buffer application in between
Keep going

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 8:10 am
by #NULL
Could you open a new tab, hijack the scintilla gadget and hide or close the tab? So the gadget already belongs to the IDE process. Just an idea, I don't know if that could work at all.

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 8:39 am
by RSBasic
Hello #NULL

That's a good idea. That would work, but the problem is that the new temporary tab for SplitView must remain open, otherwise PB will release my ScintillaGadget.
Because the TabBar is a CanvasGadget ( viewtopic.php?f=12&t=47588 ), I can hide the tab because I don't have access.
I'll test it.

Maybe there is an internal PB function in the PB process to create a new ScintillaGadget? ( For example, calling a procedure from PB with a pointer: https://www.purebasic.fr/german/viewtop ... 43#p319043 )

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 11:47 am
by RSBasic
@#NULL
Thanks again for your idea. This works very well:
Image

Now I just have to check how to create a new ScintillaGadget or create and hide a new tab.

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 12:11 pm
by #NULL
But I could imagine even a hidden tab might mess with the IDEs tab/session management and/or with undo/redo or other things.

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 5:49 pm
by chi
RSBasic wrote:Now I just have to check how to create a new ScintillaGadget...
Why don't you just unhide and resize the original ScintillaGadget(s)? No need for additional ones.

Image
RSBasic wrote:... or create and hide a new tab.
The IDE uses STARGĂ…TE's excellent TabBarGadget, which is made of a CanvasGadget. So there is no way to just SendMessage_(..) to create/remove or show/hide a tab, you have to inject a dll and hijack the callback. Which should/could work, but I bet the IDE will not be very happy about it. I've tried similar things before, had some random crashes... Also what #NULL said ^^


I really hope @Fred will pick up the task to properly implement SplitView (on all platforms). Should be much easier for him ;)

Re: ScintillaGadget - #SCI_GETDOCPOINTER and #SCI_SETDOCPOIN

Posted: Fri Jun 28, 2019 5:54 pm
by RSBasic
chi wrote:Why don't you just unhide and resize the original ScintillaGadget(s)? No need for additional ones.
I've already done that. :)
Image

Only a new tab must exist. I'll see if I can do it without an extra tab. Therefore I want to create a ScintillaGadget.