Attention: Starting with version 4.7, Pure Basic began using the Cocoa system as the default for drawing gadgets (etc.). If you want to use the Carbon system (like for old code) you can set the subsystem in "Compiler/Compiler Options.../Library Subsystem:" to "Carbon". Doing this will allow you to use the carbon gadget api below. Carbon will not work at all in x64 (64 bit)! To see how to use Cocoa and many examples of gadget modifications see [PB Cocoa] Methods, Tips & Tricks which is moderated by wilbert.

This is a list of the API usages for the Mac that I have found on the forum along with many other items of interest that are entirely in PureBasic. Although PureBasic has gone to Cocoa, with version 4.7, I am still adding any Carbon code that is contributed and I am also adding information of interest that is not in Cocoa (if there a Cocoa equivalent of an existing Carbon API I will try to post the link to it) . (see update date and red asterisk for newest addition)

ImportC "" - used to import and declare external functions (in this case for functions are already used by pb)ImportC "/System/Library/Frameworks/Carbon.framework/Carbon" - long form of 'ImportC ""' showing the complete path to Carbon

williaml wrote: I am puzzled of where 'ImportC "" ' actually is and what other commands might be available at this location.freak wrote:The required libraries for these commands are already linked to the executable because the Gadget commands themselves use them too, so you can just leave that part blank. This should work with most Carbon commands as long as you use some PB gui commands as well. My approach here is to just leave the string blank and only worry where things are if i get a linker error.

Just put it in such an ImportC and call it with GadgetID() as the first parameter like the others above. The ListIconGadget, ListViewGadget, TreeGadget, ExplorerListGadget and ExplorerTreeGadget all use the databrowser control with different settings, so the above reference can be useful for them.

In general, if you are looking for API commands to import, look in the Carbon and Core Foundation documentation. These are mostly used by PB commands internally (among some others). I usually use the XCode help as documentation. It makes searching simpler than using the web. For using PB objects with API commands, these are the most important object types returned from the [...]ID() functions:

WindowID() returns a WindowRefGadgetID() returns a ControlRefMenuID() returns a MenuRefImageID() returns a CGImageRefStatusBarID() returns a ControlRef (its an ordinary userpane control)ToolBarID() returns a HIToolbarRefFontID() actually returns a PB internal pointer because a FontRef only specifies a name, not a size (so you have to load a font yourself if you need it for API stuff)

[/list]Attention! freak has compiled a list of the underlying objects behind the PB gadgets. This should be a starting point for finding API commands in Carbon. http://www.purebasic.fr/blog/?p=336

2) Make files double-click able (associate with app)freak provides the code that will make a file associate with an app and if a file is double-clicked the app will open. I've also noted that a file that is double-clicked while the app is running will also be received by the app. You will have to define the extensions in the plist and examples are given with this example too.

-Detailed step-by-step instructions by J. Baker of how to submit your program.-More hints to streamline the process by adding a shell script by jamirokwai.-A suggestion on sandboxing and naming by J. Baker.

5) Gadget colors using Carbon (pre 4.7)There has been some discussion of which gadgets show color. Shardik has made a chart showing all the gadgets and whether colors or fonts can be set for each, he has also made a picture showing all the gadgets with their colors. Colors can be added to some gadgets with the API above. Note that Mac API uses words instead of bytes for the color values. See conversion here.

6) Window - add a non-window dependent timerThis code will let you install a timer either with or without a window with API. Thanks to Shardik for the example. viewtopic.php?f=19&t=37698#p347707

7) Size gadget automatically to font selected freak has posted an example viewtopic.php?f=12&t=38349 of how to have a gadget (see which are affected in code comments) size itself to the font/size you've selected. The gadgets that can be changed are the Button, Checkbox, Option, Text, String, ComboBox, Image gadget.

8) TextGadget() - change fore/background color, justification, styleThis is an example of complete control of the TextGadget including color, justification, and style with all the necessary constants. Now your textgadet background can match your window color background! Thanks to Shardik for this code at viewtopic.php?f=24&t=44901&p=344872#p344872 . Shardik has posted another short example of changing the background with a procedure to convert the color values to the API requirement. viewtopic.php?f=13&t=45685#p348353

9) ListView/IconGadget - auto alternating line colorShardik writes: Although the ListViewGadget and ListIconGadget (because of the underlying DataBrowser API) don't support colors, they nevertheless support the alternating coloring of rows. But it isn't possible to change the predefined colors. So if you can live with the predefined alternating row background colors white and light blue, the detection of the clicked item becomes quite easy.viewtopic.php?f=19&t=44206#p345712

19) EditorGadget - change font()There has been some discussion about not being able to change the font in the EditorGadget() this may be a bug and fixed in future versions of PB. Shardik has provided a way to change the font using the API in this thread . He has also gives this explanation about scroll bar behaviors [i]The EditorGadget on MacOS uses a user pane rendering a TXN Object (PB blog). The underlying MLTE API (Multi Language Text Engine, deprecated since MacOS X 10.6) doesn't provide the option to hide the scroll bars. The only option provided is to change their activity states when obtaining or losing focus...

23) StringGadget - using colorI find I have to put the gadget and color commands in this order to keep the font the right size but I have noticed that the width of the text in the gadget is not being calculated correctly and sometimes the text is shifted off to the right when not necessary.

25) ProgressBarGadget - intermediate stateShardik shows how to set the ProgressBar to the undefined state that is used when the fill time cannot be determined. Apple describes it as The so called "indeterminate" state of the ProgressBar does in principle not represent a ProgressBar at all. It "misuses" the ProgressBar to indicate that the program is performing some action and that the program doesn't know how long that action may take. One other example: when trying to connect to a busy server, the program cannot display a progress bar because it can't estimate at which time the connection will finally be established.

27) TrackBarGadget - show tick marksShardik shows how create custom TrackBarGagets in this thread. These gadgets show the missing division (hash) marks but custom TrackBars lose the ability to get the gadget state with the pb command so he shows how to get the gadget state with API. A new version that doesn't require you to create a custom gadget is shown here. With this code you can add tick marks, change pointer to up or down, or make it a non-pointer.

28) Mouse -get mouse up/downThis API requires a callback and the code shows how to set it up. Thanks to Niffo for the code.

29) Mouse - get left/right mouse click when not on gadgetShardik has provided an example of getting a right/middle/left click of the mouse when the cursor is not over a gadget (otherwise the gadget will return the mouse click type).

30) Mouse - discriminate between right click on Window or Gadget Shardik has posted the code to discriminate between right click on Window or Gadget on the German forum. If you don't read German this is his explanation in English. This example installs an EventHandler for a contextual menu click (right click) for a Window and for a ButtonGadget and calls the EventHandler with the handle of the window or gadget with the UserData parameter, so that the EventHandler can discriminate whether the right click was carried out on an empty window space or on the ButtonGadget. If the right click occured in the window, a variable in the EventHandler is set to #True and if this is detected in the event loop, the popup menu is displayed.

31) Mouse - get mouse click/movement when on a gadgetNiffo has made an example of getting mouse events when the cursor is over a gadget (see his second example in the eighth entry). The code will provide moving on to the gadget, off of it, mouse up, and mouse down. You can use this code on many gadgets. I have used this code to get EditorGadget() clicks. viewtopic.php?f=19&t=36625

Using 33) Cocoa guidedevulder has worked on creating a userlib here and wilbert has a userlib here with instruction of where to put the library here. Wilbert has also listed some of the Cocoa procedures here.

#34) Is the Debugger running?Not API but a good tip. If the debugger is used in compiling the code then DisableDebugger and EnableDebugger can be used (for time sensitive code).

#35 CalendarGadgetThis is not API but an attempt to use the (new) CanvasGadget to create a colorful CanvasCalendarGadget for the Mac (which is just B&W text). jesperbrannmark has also contributed a calendar replacement in this thread.

#36 Track Selection Gadgetnetmaestro has made a selection gadget that presents a bar that you can select the beginning and ending point anywhere along the bar, similar to audio editing. I have changed his code so that it will run on a Mac (should be cross-platform).

But I would forbid to use API in PureBasic. The exchangeability of the code between platforms is lost... And that is the key feature of PB.

No exchangeability is lost if cross-platform code examples contain the API functions for Windows, Linux and MacOS. I have already posted several examples with API functions for all 3 platforms. In some of these examples I needed special functions missing in PB to proceed in programming a cross-platform project.

It would be good if some of the examples where all three platforms had their own code would be added. Maybe there should be a special bit of the forum where you can post API code that works on all three platforms that Fred & co can consider for inclusion in the main code core?

Maybe there should be a special bit of the forum where you can post API code that works on all three platforms that Fred & co can consider for inclusion in the main code core?

It would be nice to have a subforum for cross-platform API code...

^ This! (again! still! why not!?)

and thankyou Shardik, your Center Text demo works well

Shardik ps. in your demo if the OS is <= XP you "overwrite" the Gadget by recreating another one with the same ID (neat trick for re-styling! ) ... so, the equivalent of StringWindow(0, ... StringWindow(0, ...

Im just wondering IS IT SAFE to use this overwrite trick that way, or should there be a FREEGADGET() call between those two? It seems to work fine without FreeGadget but im wondering if its a resource leak, though when i checked in Windows Task Manager it showed the same number of Handles both with and without the FreeGadget call so perhaps internally FreeGadget is already being called, i dont know! but i dont know how to test for handle leak in linux or mac

_________________Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.

_________________Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.

I try Shardik's excellent example for listing processes - viewtopic.php?p=375953#p375953it gets the Process ID list fine (not anywhere near as many as 'ps -x' though?) but is crashing (PB v5.31-64/Mac 10.10-64) getting the process name with invalid memory access in this function:

The code isn't ready for 64 bit. Also some things can be done easier now we got Cocoa support.Here's some workarounds.

1. Code from Shardik adapted to support 64 bit and use Cocoa to retrieve the string