SearchGadget (SearchField) for OSX, Windows and Linux

Share your advanced PureBasic knowledge/code with the community.
empty
User
User
Posts: 27
Joined: Sat Apr 12, 2014 11:31 am

SearchGadget (SearchField) for OSX, Windows and Linux

Post by empty »

There's a nice Control in OSX called SearchField, a text field gadget optimized for text searches.
This library creates a NSSearchField on OSX and a gadget that simulates its behaviour on the other two systems.

Put XInclude "%FilePath%SearchGadget.pbi" at the top of your code and replace %FilePath% with the path to the files contained in the zip.

Usage
Return = SearchGadget(Gadget, x, y, Width, Height)

Return value
Returns nonzero on success and zero on failure. If #PB_Any was used as the #Gadget parameter then the return-value is the auto-generated gadget number on success.

Remarks
A 'mini help' can be added to this gadget using GadgetToolTip().

The following functions can be used to control the gadget:

- SetGadgetText(): Changes the text of the SearchGadget.
- GetGadgetText(): Returns the text of the SearchGadget.
- SetGadgetState(), GetGadgetState():
Possible values to set and get:
#SearchGadget_Mode_Delayed: This is the default setting. The Gadget sends the messages after a brief pause.
#SearchGadget_Mode_Immediate: With this setting the Gadget sends messages as soon as there are changes in the text field
#SearchGadget_Mode_Explicit: The Gadget sends messages only if the user clicks on the search icon or presses return/enter

Messages
The Gadget sends the message #PB_EventType_Input if there are changes in the text field (depending on the state value)

Download (with example)

Screenshot
Image
Last edited by empty on Thu Sep 25, 2014 12:17 pm, edited 2 times in total.
deesko
User
User
Posts: 39
Joined: Fri Sep 21, 2012 11:40 pm
Location: Portugal

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by deesko »

Nice job, thanks! Very useful.
empty wrote: Usage
Return = StringGadget(Gadget, x, y, Width, Height)
I didn't had a go yet, but maybe you wrote a mistake there? Shouldn't it be called SearchGadget() instead?
empty
User
User
Posts: 27
Joined: Sat Apr 12, 2014 11:31 am

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by empty »

Ouuuh, yes. Corrected. Thank you. :)
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by idle »

looks good thanks for sharing
think your missing a file "gadgetEx.pbi"
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by Derren »

Can't get it to work properly. First of all, you could have mentioned that you need the pbi from the other thread. If I hadn't already seen and commented the other thread I might have been at a loss.

Then the "X" button doesn't appear, only the magnifying glass button. But there doesn't seem to be any function.

#PB_EventType_Input, apart from not being a PB constant (a user defined event? Then you shouldn't be using the #PB prefix, imo), doesn't even fire as an eventType. When I change it to EventType_Change, nothing happened either, except that that the word list get filled anew.
empty
User
User
Posts: 27
Joined: Sat Apr 12, 2014 11:31 am

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by empty »

First of all, you could have mentioned that you need the pbi from the other thread. If I hadn't already seen and commented the other thread I might have been at a loss.
Sorry, it should have been in the zip (it's an updated version) but I seem to have forgotten it. I've reuploaded the zip
Then the "X" button doesn't appear, only the magnifying glass button.
It will only appear if there is text in the text field,
however...
But there doesn't seem to be any function.

#PB_EventType_Input, apart from not being a PB constant (a user defined event? Then you shouldn't be using the #PB prefix, imo), doesn't even fire as an eventType. When I change it to EventType_Change, nothing happened either, except that that the word list get filled anew.
... this has only been used and tested with v5.31 which is the version we use. Ishould have mentioned that.
V5.3+ (at least) has a constant named #PB_EventType_Input.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by Derren »

Oh man, I just downloaded 5.30 3 days or so ago (edit: I see, the 5.31 is still beta, that's why)
That's probably why the X button doesn't appear either, if that non-existing constant isn't triggered.
I'll update and check again. Although the constant seems to be present in 5.30 as well (if you didn't implement it with a CompilerSwitch).
but same result. Nothing happens. No X-button, the list is not altered in anyway or whatever is supposed to happen.

OK, re-downloaded the zip file. Seems that the pbi you posted in the other thread is different from the one you included here.
Works now, but I must say it's a bit slow. Takes at least 500ms until the list is updated, not sure why that is.
empty
User
User
Posts: 27
Joined: Sat Apr 12, 2014 11:31 am

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by empty »

#SearchGadget_Mode_Delayed: This is the default setting. The Gadget sends the messages after a brief pause.
#SearchGadget_Mode_Immediate: With this setting the Gadget sends messages as soon as there are changes in the text field
#SearchGadget_Mode_Explicit: The Gadget sends messages only if the user clicks on the search icon or presses return/enter

The delayed mode is the default one (as it is on OSX). For immidate updates use the second constant
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by Derren »

RTFM, sorry my fault. Works like a charm now :D
empty
User
User
Posts: 27
Joined: Sat Apr 12, 2014 11:31 am

Re: SearchGadget (SearchField) for OSX, Windows and Linux

Post by empty »

:)
Post Reply