It is currently Mon Apr 06, 2020 10:18 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Thu Mar 26, 2020 12:26 am 
Online
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 547
When you click one of the menu items, the menu reappears.
Code:
If CreatePopupMenu(0)
  MenuItem(0, "Item 1")
  MenuItem(1, "Item 2")
  MenuBar()
  MenuItem(2, "Item 3")
EndIf

Procedure OnScintillaRightClick()
  DisplayPopupMenu(0, WindowID(0))
EndProcedure

If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
    If InitScintilla()
      ScintillaGadget(0, 10, 10, 320, 70, 0)
      ScintillaSendMessage(0, #SCI_USEPOPUP, 0, 0)
      BindGadgetEvent(0, @OnScintillaRightClick(), #PB_EventType_RightClick)
    EndIf
   
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Thu Mar 26, 2020 3:34 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1768
I will try to confirm on Mac later today, but in the meantime, a timeout workaround might prevent it:

Code:
Procedure OnScintillaRightClick()
  Static LastMenuTime.i
  If (ElapsedMilliseconds() - LastMenuTime > 20) Or (LastMenuTime = 0)
    DisplayPopupMenu(0, WindowID(0))
    LastMenuTime = ElapsedMilliseconds()
  EndIf
EndProcedure

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Tue Mar 31, 2020 6:14 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1697
Location: Germany
wombats wrote:
When you click one of the menu items, the menu reappears.

Confirmed on MacOS 10.14.6 'Mojave' and MacOS 10.15.4 'Catalina' with PB 5.72 x64 final. With kenmo's workaround it works like a charm.


Last edited by Shardik on Tue Mar 31, 2020 8:10 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Tue Mar 31, 2020 6:44 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2343
Location: Germany
Same on Catalina
Very strange..

Solution without Timer and RightDoubleClick...
Code:
If CreatePopupMenu(0)
  MenuItem(0, "Item 1")
  MenuItem(1, "Item 2")
  MenuBar()
  MenuItem(2, "Item 3")
EndIf

Procedure OnScintillaRightClick()
  Static cnt
  cnt + 1
  If cnt = 3
    Select EventType()
      Case #PB_EventType_RightClick
        Debug "RightClick "
        ;DisplayPopupMenu(0, WindowID(0))
      Case #PB_EventType_RightDoubleClick
        Debug "RightDoubleClick "
        DisplayPopupMenu(0, WindowID(0))
       
    EndSelect
    cnt = 0
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 330, 90, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  If InitScintilla()
    ScintillaGadget(0, 10, 10, 320, 70, 0)
    BindGadgetEvent(0, @OnScintillaRightClick())
  EndIf
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Tue Mar 31, 2020 8:22 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1697
Location: Germany
When using a standard event loop instead of BindGadgetEvent() the bug doesn't occur:
Code:
If CreatePopupMenu(0)
  MenuItem(0, "Item 1")
  MenuItem(1, "Item 2")
  MenuBar()
  MenuItem(2, "Item 3")
EndIf

OpenWindow(0, 270, 100, 330, 90, "ScintillaGadget")
ScintillaGadget(0, 10, 10, 320, 70, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0
        If EventType() = #PB_EventType_RightClick
          DisplayPopupMenu(0, WindowID(0))
        EndIf
      EndIf
  EndSelect
ForEver


By the way, InitScintilla() is only necessary on Windows, not on MacOS or Linux:
Remarks

This command is useful only on Windows, as on the other OS, the scintilla library is linked statically with the executable and therefore does not need to be loaded or distributed with the program.

And ScintillaSendMessage() in wombat's code example is not necessary because DisplayPopupMenu() is sufficient.


Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Thu Apr 02, 2020 12:55 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Dec 23, 2003 3:54 am
Posts: 1768
Shardik wrote:
And ScintillaSendMessage() in wombat's code example is not necessary because DisplayPopupMenu() is sufficient.


I could be wrong (cannot test right now) but doesn't Scintilla display its own default right-click menu if you don't turn USEPOPUP off?

_________________
On GitHub: PB Includes - IDE Tools - Color Themes


Top
 Profile  
Reply with quote  
 Post subject: Re: [5.72 Beta 3] Custom menu with Scintilla
PostPosted: Thu Apr 02, 2020 6:33 pm 
Online
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 547
kenmo wrote:
Shardik wrote:
And ScintillaSendMessage() in wombat's code example is not necessary because DisplayPopupMenu() is sufficient.


I could be wrong (cannot test right now) but doesn't Scintilla display its own default right-click menu if you don't turn USEPOPUP off?

Yes, it does. That's why I used #SCI_USEPOPUP, so I could display my custom menu.

Thanks for the workarounds.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye