Having trouble #PB_EventType_LeftDoubleClick

Just starting out? Need help? Post your questions and find answers here.
vmars316
Enthusiast
Enthusiast
Posts: 464
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Having trouble #PB_EventType_LeftDoubleClick

Post by vmars316 »

Hello ,
Actually I am having trouble with 'Goto'
Error says "Garbage at end of line" .
Sometimes that means something is wrong with preceding line , but I can't see error .

Code: Select all

Procedure ValidateLink()
MessageRequester("ValidateLink()" , "ValidateLink()") 
  Goto Exit-Validate
Exit-Validate:
MessageRequester("Exit-Validate:" , "Exit-Validate:")  
EndProcedure ; ValidateLink()
Also Having trouble '#PB_EventType_LeftDoubleClick' .
I '#PB_EventType_LeftDoubleClick' isn't recognized .
I need another set of eyes , Thanks

Code: Select all


Global ThisLinkOkLV , ThisSiteOkLV , currentLine$ , currentListElement$ ,
       NewList ThisLink.s() , NewList ThisSite.s() , LinkEntered , LinkEntered$ ,
        suri$ = "http://vmars.us"                              

; ==============================
Declare ValidateLink()
; ==============================

Procedure OpenWindow_0(x = 0, y = 0, width = 580 , height = 634)
  Window_0 = OpenWindow(#PB_Any, 0, 0, width, height, "Load-Files-Validate-Link", #PB_Window_SystemMenu | #PB_Window_TitleBar)
 ContainerGadget(#PB_Any, 8, 8, 572, 626, #PB_Container_Raised)
  ThisLinkOkLV = EditorGadget(#PB_Any,10,10,250,565)
  ThisSiteOkLV = EditorGadget(#PB_Any,280,10,250,565)
  LinkEntered = StringGadget (#PB_Any , 190 , 586 , 150 , 25 , "http://vmars.us") ; How Focus
 CloseGadgetList()
EndProcedure  ; Procedure OpenWindow_0

; ==============================

Procedure ValidateLink()
MessageRequester("ValidateLink()" , "ValidateLink()") 
  Goto Exit-Validate
Exit-Validate:
MessageRequester("Exit-Validate:" , "Exit-Validate:")  
EndProcedure ; ValidateLink()

; ==============================  

OpenWindow_0()
;SendMessage_(WindowID(Window_0), #WM_SETICON, 0, vmResult)
Repeat
   Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
         Select EventGadget()
           Case LinkEntered
             If EventType() = #PB_EventType_LeftDoubleClick  ;  
               ValidateLink()
             EndIf             
         EndSelect           
     EndSelect ; EventGadget()
Until Event = #PB_Event_CloseWindow ; Repeat
End    
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by Marc56us »

Simple typing error

Code: Select all

Exit-Validate    ; =  Exit - Validate

; Yes
Exit_Validate
:wink:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by infratec »

One more reason for ....

Code: Select all

EnableExplicit
It shows you that the variables Exit and Validate are not defined.

And if you look in the help of StringGadget, then you will see that there is no EventType #PB_EventType_LeftDoubleClick is listed.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by Marc56us »

Also Having trouble '#PB_EventType_LeftDoubleClick' .
#PB_EventType_LeftDoubleClick is already used by the operating system in these gadgets (EditorGadget, StringGadget (ie: double-clik select full text, right click show popupmenu))
There is (I think) a way to override the system function and place the PB function instead.
:wink:
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by mk-soft »

That is the case with windows. Not all mouse events arrive at the main window when a control is in the way.

Edit: Own Left Double Click on Gadget to Window

Code: Select all

;-TOP

EnableExplicit

;- Constant
Enumeration Windows
  #Main
EndEnumeration

Enumeration Menus
  #Menu
EndEnumeration

Enumeration MenuItems
  #MenuExitApplication
EndEnumeration
  
Enumeration Gadgets
  #List
EndEnumeration

Enumeration Statusbar
  #Status
EndEnumeration

Enumeration Images
  
EndEnumeration

;- Global Variable
Global ExitApplication

;- Functions
Procedure UpdateWindow()
  
  Protected x, y, dx, dy, menu, status
  
  menu = MenuHeight()
  If IsStatusBar(#Status)
    status = StatusBarHeight(#Status)
  Else
    status = 0
  EndIf
  x = 0
  y = 0
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - menu - status
  dy / 2
  ResizeGadget(#List, x, y, dx, dy)
  
EndProcedure

Procedure WindowCB(hWnd, uMsg, wParam, lParam)
  Static last_hWnd, last_time
  
  Protected r1 = #PB_ProcessPureBasicEvents
  Protected *nmhdr.NMHDR
  ;Debug uMsg
  Select uMsg
    Case #WM_LBUTTONDBLCLK
      Debug "#WM_LBUTTONDBLCLK"
      
    Case #WM_LBUTTONDOWN
      Debug "#WM_LBUTTONDOWN"
      
    Case #WM_LBUTTONUP
      Debug "#WM_LBUTTONUP"
      
    Case #WM_NOTIFY
      *nmhdr = lParam
      Debug "Notify Code " + *nmhdr\code
      
    Case #WM_PARENTNOTIFY
      Debug "Parent Notify Code " + Hex(wParam)
      Select (wParam & $FFFF)
        Case #WM_LBUTTONDOWN
          Debug "- Left Mouse Down"
          ; Own left double click
          If last_time = 0
            last_time = ElapsedMilliseconds()
          Else
            If ElapsedMilliseconds() <= last_time + DoubleClickTime()
              ;PostEvent(#PB_Event_LeftDoubleClick)
              PostEvent(#PB_Event_FirstCustomValue)
              last_time = 0
            Else
              last_time = ElapsedMilliseconds()
            EndIf
          EndIf
          
        Case #WM_MBUTTONDOWN
          Debug "- Mittel Mouse Down"
        Case #WM_RBUTTONDOWN
          Debug "- right Mouse Down"
          
      EndSelect
      
  EndSelect
  
  ProcedureReturn r1
  
EndProcedure

;- Main
Procedure Main()
  
  Protected event, dx, dy, i
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
  dx = 800
  dy = 600 / 2
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main Window", #WinStyle)
    
    ; Menu
    CreateMenu(#Menu, WindowID(#Main))
    MenuTitle("File")
    MenuItem(#MenuExitApplication, "E&xit")
    ; Gadgets
    ListViewGadget(#List, 0, 0, dx, dy)
    For i = 1 To 10
      AddGadgetItem(#List, -1, "Item " + i)
    Next
    
    ; Statusbar
    CreateStatusBar(#Status, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Init
    UpdateWindow()
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    SetWindowCallback(@WindowCB())
    
    ; Main Loop
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                ExitApplication = #True
                
            CompilerEndIf
              
            Case #MenuExitApplication
              ExitApplication = #True
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #List
              
          EndSelect
          
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              ExitApplication = #True
              
          EndSelect
          
        Case #PB_Event_LeftDoubleClick
          Debug "PB Left Double Click on Window"
          
        Case #PB_Event_FirstCustomValue
          Debug "Own Left Double Click on Gadget"
          
      EndSelect
      
    Until ExitApplication
    
  EndIf
  
EndProcedure : Main()

End
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by mk-soft »

Solution with SetGagetCallback

Code: Select all

;-TOP

; Comment : Module SetGadgetCallback (Windows Only)
; Author  : mk-soft
; Version : v0.03
; Created : 10.06.2018
; Updated : 16.02.2020
; Link    : https://www.purebasic.fr/english/viewtopic.php?f=12&t=70842
;
; Syntax Callback:
;           Procedure GadgetCB(hWnd,uMsg,wParam,lParam)
;             Select uMsg
;               ;TODO
;             EndSelect
;             ; Call previous gadget procedure
;             ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
;           EndProcedure
;
; *****************************************************************************

DeclareModule GadgetCallback
  
  Declare SetGadgetCallback(Gadget, *lpNewFunc) 
  Declare CallGadgetProc(hWnd, uMsg, wParam, lParam)
  
EndDeclareModule

Module GadgetCallback
  
  EnableExplicit
  
  ; ---------------------------------------------------------------------------
  
  Procedure SetGadgetCallback(Gadget, *lpNewFunc)
    Protected hWnd, *lpPrevFunc
    
    hWnd = GadgetID(Gadget)
    *lpPrevFunc = GetProp_(hWnd, "PB_PrevFunc")
    ; Remove exists Callback
    If *lpPrevFunc
      SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *lpPrevFunc)
      RemoveProp_(hWnd, "PB_PrevFunc")
    EndIf
    ; Set new Callback  
    If *lpNewFunc
      *lpPrevFunc = SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *lpNewFunc)
      SetProp_(hWnd, "PB_PrevFunc", *lpPrevFunc)
      ProcedureReturn *lpPrevFunc
    EndIf
    ProcedureReturn 0
  EndProcedure
  
  ; ---------------------------------------------------------------------------
  
  Procedure CallGadgetProc(hWnd, uMsg, wParam, lParam)
    Protected result, *lpPrevFunc
    
    *lpPrevFunc = GetProp_(hWnd, "PB_PrevFunc")
    If *lpPrevFunc
      result = CallWindowProc_(*lpPrevFunc, hWnd, uMsg, wParam, lParam)
    EndIf
    ProcedureReturn result
  EndProcedure
EndModule

; *****************************************************************************

; Example

CompilerIf #PB_Compiler_IsMainFile
  
  EnableExplicit
  
  UseModule GadgetCallback
  
  ;- Constant
  Enumeration Windows
    #Main
  EndEnumeration
  
  Enumeration Menus
    #Menu
  EndEnumeration
  
  Enumeration MenuItems
    #MenuExitApplication
  EndEnumeration
  
  Enumeration Gadgets
    #Splitter
    #List
    #Edit
  EndEnumeration
  
  Enumeration Statusbar
    #Status
  EndEnumeration
  
  ;- Global Variable
  Global ExitApplication
  
  ;- Functions
  Procedure UpdateWindow()
    
    Protected x, y, dx, dy, menu, status
    
    menu = MenuHeight()
    If IsStatusBar(#Status)
      status = StatusBarHeight(#Status)
    Else
      status = 0
    EndIf
    x = 0
    y = 0
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - menu - status
    ResizeGadget(#Splitter, x, y, dx, dy)
    
  EndProcedure
  
  ; ----
  
  Procedure ListGadgetProc(hWnd,uMsg,wParam,lParam)
    Select uMsg
      Case #WM_LBUTTONDBLCLK
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetProp_(hWnd, "pb_id"), #PB_EventType_LeftDoubleClick)
        ProcedureReturn 1
        
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure
  
  Procedure EditGadgetProc(hWnd,uMsg,wParam,lParam)
    Select uMsg
      Case #WM_LBUTTONDBLCLK
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetProp_(hWnd, "pb_id"), #PB_EventType_LeftDoubleClick)
        ProcedureReturn 1
        
      Case #WM_RBUTTONDOWN
        PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetProp_(hWnd, "pb_id"), #PB_EventType_RightClick)
        ProcedureReturn 1
      
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure
  
  ;- Main
  
  Procedure Main()
    
    Protected event, dx, dy
    
    #WinStyle = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
    dx = 800
    dy = 600
    
    If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, dx, dy, "Main Window", #WinStyle)
      
      ; Menu
      CreateMenu(#Menu, WindowID(#Main))
      MenuTitle("Ablage")
      MenuItem(#MenuExitApplication, "Be&enden")
      
      ; Gadgets
      ListViewGadget(#List, 0, 0, 0, 0)
      EditorGadget(#Edit, 0, 0, 0, 0)
      SplitterGadget(#Splitter, 0, 0, dx ,dy, #List, #Edit)
      SetGadgetState(#Splitter, dy * 2 / 3)
      
      ; Statusbar
      CreateStatusBar(#Status, WindowID(#Main))
      AddStatusBarField(#PB_Ignore)
      
      ; For Mac
      CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
        If Not IsMenu(#Menu)
          CreateMenu(#Menu, WindowID(#Main))
        EndIf
        MenuItem(#PB_Menu_About, "")
        MenuItem(#PB_Menu_Preferences, "")
      CompilerEndIf
      
      ; Init
      UpdateWindow()
      BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
      
      ; Callback
      SetGadgetCallback(#List, @ListGadgetProc()) ; <- Not used
      SetGadgetCallback(#Edit, @EditGadgetProc())
      
      ; Main Loop
      Repeat
        event = WaitWindowEvent()
        Select event
          Case #PB_Event_Menu
            Select EventMenu()
                CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
                Case #PB_Menu_About
                  MessageRequester("Info", "Main Window v1.01")
                  
                Case #PB_Menu_Preferences
                  
                Case #PB_Menu_Quit
                  ExitApplication = #True
                  
                CompilerEndIf
                
              Case #MenuExitApplication
                ExitApplication = #True
                
            EndSelect
            
            
          Case #PB_Event_Gadget
            Select EventGadget()
              Case #List
                Select EventType()
                  Case #PB_EventType_LeftDoubleClick
                    Debug "Left Double Click on ListViewGadget"
                EndSelect
                
              Case #Edit
                Select EventType()
                  Case #PB_EventType_LeftDoubleClick
                    Debug "Left Double Click on EditorGadget"
                    
                  Case #PB_EventType_RightClick
                    Debug "Right Click on EditorGadget"
                  
                EndSelect
                
            EndSelect
            
          Case #PB_Event_CloseWindow
            Select EventWindow()
              Case #Main
                ExitApplication = #True
                
            EndSelect
            
        EndSelect
        
      Until ExitApplication
      
    EndIf
    
  EndProcedure : Main()
  
  End
  
CompilerEndIf

;- BOTTOM
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
vmars316
Enthusiast
Enthusiast
Posts: 464
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Having trouble #PB_EventType_LeftDoubleClick

Post by vmars316 »

Thanks Folks ,
Turns out that I needed something inside the LinkEnteredEditor :

Code: Select all

  LinkEnteredEditor = ListViewGadget (#PB_Any , 190 , 586 , 150 , 25 ,  #PB_ListView_ClickSelect | #LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS)
  CloseGadgetList()
[b] AddGadgetItem(LinkEnteredEditor, 0 , "www.google.com")[/b]
EndProcedure  ; Procedure OpenWindow_0
Else it doesn't work .
Hmm... imagine that .
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Post Reply