Page 1 of 1

Re: Getting placeholder text from StringGadget?

Posted: Wed Sep 30, 2015 9:29 pm
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

Re: Getting placeholder text from StringGadget?

Posted: Wed Sep 30, 2015 11:00 pm
by Wolfram
Yup, it works.

…it's not magic, it Wilbert ;-)

Re: Getting placeholder text from StringGadget?

Posted: Thu Oct 01, 2015 3:00 pm
by Shardik
It works now also on Snow Leopard and should also work on the other versions. Thank you, Wilbert!

Re: Getting placeholder text from StringGadget?

Posted: Thu Oct 01, 2015 6:40 pm
by davido
Very nice.

Thank you. :D

Re: Getting placeholder text from StringGadget?

Posted: Thu Oct 01, 2015 7:58 pm
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.

Re: Getting placeholder text from StringGadget?

Posted: Thu Oct 01, 2015 10:08 pm
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! :)