Getting placeholder text from StringGadget?

Mac OSX specific forum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Getting placeholder text from StringGadget?

Post by wilbert »

I only have 10.10.5. Does this make a difference on older OSX versions ?

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_entry_set_placeholder_text(*entry, text.p-utf8)
    gtk_entry_get_placeholder_text(*entry)
  EndImport
CompilerEndIf

Procedure SetGadgetPlaceholder(Gadget.i, Text.s)
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    SendMessage_(GadgetID(Gadget), #EM_SETCUEBANNER, #True, Text)
  CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
    gtk_entry_set_placeholder_text(GadgetID(Gadget), Text)
  CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
    CocoaMessage(0, CocoaMessage(0, GadgetID(Gadget), "cell"), "setPlaceholderString:$", @Text)
  CompilerEndIf
  ProcedureReturn
EndProcedure

Procedure.s GetGadgetPlaceholder(Gadget.i)
  Protected.s Text = Space(1024)
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    SendMessage_(GadgetID(Gadget), #EM_GETCUEBANNER, @Text, StringByteLength(Text))
  CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
    Text = PeekS(gtk_entry_get_placeholder_text(GadgetID(Gadget)), -1, #PB_UTF8)
  CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
    Text = PeekS(CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, GadgetID(Gadget), "cell"), "placeholderString"), "UTF8String"), -1, #PB_UTF8)
  CompilerEndIf
  ProcedureReturn Text
EndProcedure

If OpenWindow(0, 0, 0, 220, 50, "Placeholder example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(1, 10, 10, 200, 20, "")
  SetGadgetPlaceholder(1, "Your Placeholder")
  Debug GetGadgetPlaceholder(1)
  Repeat : Event = WaitWindowEvent(1) : Until Event = #PB_Event_CloseWindow
EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: Getting placeholder text from StringGadget?

Post by Wolfram »

Yup, it works.

…it's not magic, it Wilbert ;-)
macOS Catalina 10.15.7
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Getting placeholder text from StringGadget?

Post by Shardik »

It works now also on Snow Leopard and should also work on the other versions. Thank you, Wilbert!
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Getting placeholder text from StringGadget?

Post by davido »

Very nice.

Thank you. :D
DE AA EB
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Getting placeholder text from StringGadget?

Post by Shardik »

Bruno,

thank you very much for your nice and useful cross-platform example! Sorry for not having put my thanks into my first posting in this thread where it would have belonged to of course... :oops:

I have also added the link to your example (with Wilbert's Mac bugfix) to my collection of cross-platfrom API code examples.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Getting placeholder text from StringGadget?

Post by bbanelli »

Shardik wrote:Bruno,

thank you very much for your nice and useful cross-platform example! Sorry for not having put my thanks into my first posting in this thread where it would have belonged to of course... :oops:

I have also added the link to your example (with Wilbert's Mac bugfix) to my collection of cross-platfrom API code examples.
Hi Shardik,

trust me, I am the one to be grateful to both PB team and its whole community (not mentioning names because I would surely miss someone; but including yourself per se, particularly in Linux/OS X field) since I've learned so much here that I've (mostly :D) successfully started programming in development suits and languages other than PB! :)
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply