Cursor position in WebGadget

Just starting out? Need help? Post your questions and find answers here.
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Cursor position in WebGadget

Post 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) ...
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Cursor position in WebGadget

Post 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().
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Re: Cursor position in WebGadget

Post 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.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Cursor position in WebGadget

Post 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
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Re: Cursor position in WebGadget

Post 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).
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Cursor position in WebGadget

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Re: Cursor position in WebGadget

Post by alver »

Yes... :D Sorry...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Cursor position in WebGadget

Post by RASHAD »

Provide some code to help in solving your problem
Egypt my love
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Re: Cursor position in WebGadget

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Cursor position in WebGadget

Post 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)
Egypt my love
alver
User
User
Posts: 21
Joined: Mon Aug 03, 2009 8:38 am
Location: Italy

Re: Cursor position in WebGadget

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