Marking backwards with mouse problem

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Marking backwards with mouse problem

Post by infratec »

Hi,

I need to manipulate text selections and want to restore the old state at the end.
So I saved the old state with EM_EXGETSEL and at the end I set it again with EM_EXSETSEL.

Now the problem:
If I mark a part of the text with the mouse from left to right everything is fine.
If I mark it from right to left I loose the end point of the marking.
:cry:

Code to test:

Code: Select all

EnableExplicit


Define.i Event, Selection.CHARRANGE


OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 380, 280)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog")

AddWindowTimer(0, 1, 250)

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Timer
      If EventTimer() = 1
        SendMessage_(GadgetID(0), #EM_EXGETSEL, 0, @Selection)
        
        Debug "Selection from " + Str(Selection\cpMin) + " to " + Str(Selection\cpMax)
        ; I do some stuff here with #EM_EXSETSEL
        
        SendMessage_(GadgetID(0), #EM_EXSETSEL, 0, @Selection)
      EndIf
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow
Any idea for a solution?

Btw.: PB 5.61 x86 on Win 10 x64

Bernd
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Marking backwards with mouse problem

Post by IdeasVacuum »

Hi Bernd

I might be being dumb, but don't you just need to determine which is the higher value when comparing cp/Min and cp/Max and reverse them if necessary?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Marking backwards with mouse problem

Post by Dude »

Your code works perfectly here? Doesn't matter which direction I select.

Example 1: Select "brown" from left to right, debug shows 10 to 15.
Example 2: Select "brown" from right to left, debug also shows 10 to 15.

I did notice, however, that your timer is de-selecting the mouse if you drag the mouse too slowly, so try this instead:

Code: Select all

Define.i Event, Selection.CHARRANGE

OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 380, 280)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog")

Repeat
  
  Event = WaitWindowEvent()
  
  If Event=#WM_LBUTTONUP
    
    
    SendMessage_(GadgetID(0), #EM_EXGETSEL, 0, @Selection)
    
    Debug "Selection from " + Str(Selection\cpMin) + " to " + Str(Selection\cpMax)
    ; I do some stuff here with #EM_EXSETSEL
    
    SendMessage_(GadgetID(0), #EM_EXSETSEL, 0, @Selection)
    
  EndIf
  
Until Event = #PB_Event_CloseWindow
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Marking backwards with mouse problem

Post by infratec »

@IdeasVacuum
your idea is not working, because cpMin is always lower than cpMax. It has nothing to do with the direction.

@Dude
Which OS do you use?
And I need the timer, because I have to check something in 'realtime', which has nothing to do with mouse actions.
That the right to left mouse marking fails (for me) is an unwanted side effect.

Bernd
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Marking backwards with mouse problem

Post by Dude »

I have Win 7, and using PureBasic v5.61 (x86) on a 64-bit machine.

If you click and drag a selection from right to left in <250 ms, it works.

What about this:

Code: Select all

Define.i Event, Selection.CHARRANGE

OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 10, 10, 380, 280)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog")

AddWindowTimer(0, 1, 250)

Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
  
    Case #PB_Event_Timer
      
      If EventTimer() = 1 And GetAsyncKeyState_(#VK_LBUTTON) = 0
        SendMessage_(GadgetID(0), #EM_EXGETSEL, 0, @Selection)
        SetWindowTitle(0, Str(Selection\cpMin) + " to " + Str(Selection\cpMax))
        SendMessage_(GadgetID(0), #EM_EXSETSEL, 0, @Selection)
      EndIf
      
  EndSelect
  
Until Event = #PB_Event_CloseWindow
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Marking backwards with mouse problem

Post by infratec »

@Dude
you are right. It seems that this is the only working solution.

Bernd
Post Reply