Page 1 of 1

Cursor position in WebGadget

Posted: Tue Apr 30, 2013 10:54 am
by alver
Hello to all,
maybe the question is a bit strange. Does anyone know if you can place, with a function, the mouse cursor to a certain point (x, y) of a WebGadget? Obviously the WebGadget is in edit mode.
Case Study The truth is this: when I save the contents of the WebGadget, the cursor is always at the beginning and not where it was before me to save. (I spit as I only raised the issue) ...

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 11:38 am
by IdeasVacuum
If your app is Windows only, then the API SetCursorPos_(x,y) can be used. It's actually a screen position, so to set the position of x15, y15 you would do something like this:

Code: Select all

            iX = WindowX(#MyWin) + GadgetX(#MyWebGt) + 15
            iY = WindowY(#MyWin) + GadgetY(#MyWebGt) + 15
            SetCursorPos_(iX,iY)
For greater precision, PB now has mode flags for the likes of WindowX().

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 12:25 pm
by alver
Thanks for the reply IdeasVacuum. I had already tried with this solution, but unfortunately it does not work. When I write in a WebGadget the cursor is located at a certain position. When I save the content I would like the cursor stays where it was before you save, instead always moves to the beginning of the WebGadget. This is the problem.

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 1:38 pm
by Shardik
Please try the following example: when clicking onto the button, the cursor is positioned in the middle of the WebGadget using SetCursorPosition_() as proposed by IdeasVacuum.

Code: Select all

If OpenWindow(0, 0, 0, 600, 350, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  WebGadget(0, 10, 10, 580, 300, "http://www.purebasic.com")
  ButtonGadget(1, 190, 320, 200, 20, "Position cursor in WebGadget's middle")
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        If EventGadget() = 1
          If EventType() = #PB_EventType_LeftClick
            SetCursorPos_(WindowX(0, #PB_Window_InnerCoordinate) + GadgetX(0) + GadgetWidth(0) / 2, WindowY(0, #PB_Window_InnerCoordinate) + GadgetY(0) + GadgetHeight(0) / 2)
          EndIf
        EndIf
    EndSelect
  ForEver
EndIf

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 2:02 pm
by alver
Thanks to you too Shardik. I apologize because I may have exposed the problem of evil. In fact I'm using the WebGadget as WYSIWYG editor, then the cursor is blinking where I'm inserting a character and moves accordingly. If I had added 10 characters, the cursor would be just after the last character entered. When I save the content I want the cursor to remain where it is, rather than to the beginning of WebGadget (the character 0.0 for instance).

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 5:07 pm
by IdeasVacuum
ah, you want to know where the caret is in the text, and keep it there. I wondered what you meant by 'edit mode', I have no experience of doing that with the webgadget.

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 5:37 pm
by alver
Yes... :D Sorry...

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 6:09 pm
by RASHAD
Provide some code to help in solving your problem

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 6:22 pm
by alver
Hello RASHAD. The code is too long, but I'll explain briefly.
1 - I write within a WebGadget;
2 - Save the contents of the WebGadget with GetGadgetItemText (gadgets, #Pb_Web_Html)
3 - Reloading WebGadget in the newly saved page with SetGadgetText (...).

At this point, having reloaded the page, the Caret is positioned at the beginning of WebGadget, but I have the need to place it at the end of the text that I had just entered. I hope I explained well. I'm sorry.

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 6:34 pm
by RASHAD
OK
Try and give us the results

Code: Select all

Global p.POINT

;Now before saving
GetCaretPos_(p.POINT)
.
.
.
.;After loading the page
SetCaretPos_(p\x,p\y)

Re: Cursor position in WebGadget

Posted: Tue Apr 30, 2013 11:05 pm
by alver
RASHAD Hello, thank you very much for your trouble. :? Unfortunately, all I'm trying but the cursor does not want to know. When I save and reload the page to give him any information he, damn, you are always placed at the beginning of the page. I do not give up, if I find the solution I will put the current. Thank you all for the help. Hello :D