Show Emoji picker

Mac OSX specific forum
mrbungle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Dec 30, 2020 3:18 am

Show Emoji picker

Post by mrbungle »

Code: Select all

Procedure ShowEmojiPicker()
  Protected NSApp = CocoaMessage(0, 0, "NSApplication sharedApplication")
  If NSApp
    CocoaMessage(0, NSApp, "orderFrontCharacterPalette:")
  EndIf
EndProcedure


If OpenWindow(0, 0, 0, 400, 200, "Emoji Picker", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  ButtonGadget(1, 150, 80, 120, 30, "Show Emoji Picker")
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = 1
          ShowEmojiPicker() 
        EndIf
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf
User avatar
Piero
Addict
Addict
Posts: 1172
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Show Emoji picker

Post by Piero »

Thanks!
Seems that PB (so also PB apps) inhibits fn-E (🌐-E); I wonder if it's related to not having services menu…
…or maybe to a "bad keyboard hook"…
Some PB gadgets have services menu (you can get it by right-clicking on them after selecting text)…

FREEEED! ;)
User avatar
mk-soft
Always Here
Always Here
Posts: 6500
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Show Emoji picker

Post by mk-soft »

Nice ;)

Per drag and drop to textview ;)

Code: Select all

;-TOP

Procedure ShowEmojiPicker()
  Protected NSApp = CocoaMessage(0, 0, "NSApplication sharedApplication")
  If NSApp
    CocoaMessage(0, NSApp, "orderFrontCharacterPalette:", #nil)
  EndIf
EndProcedure


Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
  ResizeGadget(0, 5, 5, dx-10, dy-10-50)
  ResizeGadget(1, 5, dy-40, 200, 25)
    
EndProcedure

Procedure Main()
  Protected dx, dy, text.s
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("&File")
    MenuItem(99, "E&xit")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    EditorGadget(0, 5, 5, dx-10, dy-10-50)
    ButtonGadget(1, 5, dy-40, 200, 25, "Show Emoji Picker")
    
    EnableGadgetDrop(0, #PB_Drop_Text, #PB_Drag_Copy)
    CocoaMessage(0, GadgetID(0), "setUsesInspectorBar:", #True)
    CocoaMessage(0, GadgetID(0), "setRulerVisible:", #True)
    
    UpdateWindow()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case 99
              PostEvent(#PB_Event_CloseWindow, 0, 0)
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              SetActiveGadget(0)
              ShowEmojiPicker()
          EndSelect
          
        Case #PB_Event_GadgetDrop
          Select EventGadget()
            Case 0
              text = EventDropText()
              CocoaMessage(0,GadgetID(0),"insertText:$", @text)
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Last edited by mk-soft on Thu Dec 11, 2025 9:32 pm, edited 1 time in total.
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
mrbungle
Enthusiast
Enthusiast
Posts: 178
Joined: Wed Dec 30, 2020 3:18 am

Re: Show Emoji picker

Post by mrbungle »

Looks good, thank you for the addition.
User avatar
Piero
Addict
Addict
Posts: 1172
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Show Emoji picker

Post by Piero »

mk-soft wrote: Sat Dec 06, 2025 4:32 pmdrag and drop
I HATE to "criticize" my Idols but, being SO OLD here :wink: :lol:, you probably remember when the gadget didn't work:
no problem to drag emojis on TextView! (at least here, Sequoia M1 PB 6.30b5)

EDIT: I'm almost sure it worked on a test I made (PB 6.30b4) but now it works only by double-clicking the emoj! :oops: :oops: :oops:
User avatar
mk-soft
Always Here
Always Here
Posts: 6500
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Show Emoji picker

Post by mk-soft »

The editor gadget must be active for double-clicking to work ...

Code: Select all

Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              SetActiveGadget(0)
              ShowEmojiPicker()
          EndSelect
          
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
Post Reply